import 'package:chat/chat/dollar_text.dart';
import 'package:extended_text_library/extended_text_library.dart';
import 'package:flutter/material.dart';

import 'emoji_gif_text.dart';
import 'emoji_text.dart';

class MySpecialTextSpanBuilder extends SpecialTextSpanBuilder {
  /// whether show background for @somebody
  final bool showAtBackground;
  final bool isShowGif;
  final double emojiSize;
  MySpecialTextSpanBuilder({this.showAtBackground: false,this.isShowGif=true,this.emojiSize=20.0});

  @override
  TextSpan build(String data, {TextStyle textStyle, onTap}) {
    var textSpan = super.build(data, textStyle: textStyle, onTap: onTap);
    return textSpan;
  }

  @override
  SpecialText createSpecialText(String flag,
      {TextStyle textStyle, SpecialTextGestureTapCallback onTap, int index}) {
    if (flag == null || flag == "") return null;

    ///index is end index of start flag, so text start index should be index-(flag.length-1)
//    if (isStart(flag, AtText.flag)) {
//      return AtText(
//        textStyle,
//        onTap,
//        start: index - (AtText.flag.length - 1),
//        showAtBackground: showAtBackground,
//      );
//    } else if (isStart(flag, EmojiText.flag)) {
//      return EmojiText(textStyle, start: index - (EmojiText.flag.length - 1));
//    } else if (isStart(flag, DollarText.flag)) {
//      return DollarText(textStyle, onTap,
//          start: index - (DollarText.flag.length - 1));
//    }
    if (isStart(flag, EmojiText.flag)) {
      return EmojiText(textStyle, start: index - (EmojiText.flag.length - 1),emojiSize: emojiSize);
    }
    else if (isStart(flag, EmojiGifText.flag)) {
      print('EmojiGifText ----');
      return EmojiGifText(textStyle, start: index - (EmojiGifText.flag.length - 1),isShowGif: isShowGif);
    }else if (isStart(flag, DollarText.flag)) {
      print('DollarText ----');
      return DollarText(textStyle,onTap,start:index - (DollarText.flag.length - 1));
    }
    return null;
  }
}
