import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/team_details_page/model/team_details_style_model.dart';
import 'package:zhiying_base_widget/widgets/team/fans_list/model/team_fans_list_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'dart:ui' as ui show PlaceholderAlignment;

class TeamDetailsReferrerWidget extends StatelessWidget {
  TeamDetailsStyleModelHeaderReferrer styleModel;
  TeamFansListItemModel dataModel;

  TeamDetailsReferrerWidget(this.styleModel, this.dataModel);

  /// 复制文字
  void _copyText(String text) {
    if (!EmptyUtil.isEmpty(text)) {
      Fluttertoast.showToast(msg: '复制成功~');
    } else {
      Fluttertoast.showToast(msg: '内容不能为空');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        color: HexColor.fromHex('#FFFFFF'),
        borderRadius: BorderRadius.circular(10),
      ),
      margin: const EdgeInsets.only(left: 12.5, right: 12.5, top: 12.5),
      padding: const EdgeInsets.only(left: 9.5, right: 20, bottom: 10),
      child: Column(
        children: <Widget>[
          /// 推荐人图片
          _getLeftTopWidget(),

          const SizedBox(height: 15),

          /// 头像
          Padding(padding: const EdgeInsets.only(left: 11.5), child: _getFansInfoWidget()),
          const SizedBox(height: 10),

          /// 微信号码
          Padding(padding: const EdgeInsets.only(left: 11.5), child: _getWXNumberInfoWidget()),
        ],
      ),
    );
  }

  /// 推荐人左上角Icon
  Widget _getLeftTopWidget() {
    return Align(
      alignment: Alignment.topLeft,
      child: Transform.translate(
        offset: Offset(0, -5),
        child: Container(
          // width: 80,
          // height: 23.5,
          padding: const EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4.5),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4),
              gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [
                HexColor.fromHex(styleModel?.title_bg_color ?? '#FF5E5E'),
                HexColor.fromHex(styleModel?.title_bg_color_t ?? '#FF5252'),
              ])),
          child: Text(styleModel?.title ?? 'TA的推荐人', style: TextStyle(color: HexColor.fromHex(styleModel?.title_color ?? '#FFFFFF'), fontSize: 11)),
        ),
      ),
    );
  }

  /// 粉丝头像信息等
  Widget _getFansInfoWidget() {
    return Row(
      children: <Widget>[
        /// 头像
        Container(
          width: 50,
          height: 50,
          child: CachedNetworkImage(
            imageUrl: dataModel?.avatar ?? '',
          ),
        ),
        const SizedBox(width: 10),

        /// 信息
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            /// 会员等级 关系 昵称
            RichText(
              textAlign: TextAlign.center,
              text: TextSpan(children: [
                /// 等级
                WidgetSpan(
                  alignment: ui.PlaceholderAlignment.middle,
                  child: Container(
                    margin: const EdgeInsets.only(right: 4),
                    padding: const EdgeInsets.only(left: 3, right: 2, top: 2, bottom: 2),
                    decoration: BoxDecoration(
                      color: HexColor.fromHex(dataModel?.levelBgColor),
                      borderRadius: BorderRadius.circular(2.5),
                    ),
                    alignment: Alignment.center,
                    child: Row(
                      children: <Widget>[
                        CachedNetworkImage(
                          imageUrl: dataModel?.levelIcon ?? '',
                          width: 11,
                        ),
                        const SizedBox(width: 2.5),
                        Text(
                          dataModel?.levelName ?? '黑钻会员',
                          style: TextStyle(color: HexColor.fromHex(styleModel?.lv_text_color ?? 'FFFFFF'), fontSize: 8),
                        ),
                      ],
                    ),
                  ),
                ),

                /// 会员关系
                // WidgetSpan(alignment: ui.PlaceholderAlignment.middle, child: Container(width: 13, height: 13, color: Colors.red, margin: const EdgeInsets.only(left: 3, right: 3))),

                /// 会员名称
                TextSpan(
                    text: dataModel?.blurUserName ?? '',
                    style: TextStyle(color: HexColor.fromHex(styleModel?.username_color ?? '#333333'), fontSize: 12, fontWeight: FontWeight.bold))
              ]),
            ),
            const SizedBox(height: 2.5),

            /// 手机号码
            RichText(
              textAlign: TextAlign.center,
              text: TextSpan(children: [
                /// 手机号码
                TextSpan(text: styleModel?.phone_text ?? '手机号：', style: TextStyle(color: HexColor.fromHex(styleModel?.phone_color ?? '#333333'), fontSize: 11)),
                TextSpan(
                    text: dataModel?.blurMobile ?? '',
                    style: TextStyle(color: HexColor.fromHex(styleModel?.phone_color ?? '#333333'), fontSize: 11, fontFamily: 'Din', package: 'zhiying_base_widget')),

                /// 复制按钮
                _getCopyWidget(dataModel?.phone),
                // _getCopyWidget(),
              ]),
            ),
          ],
        )
      ],
    );
  }

  /// 复制按钮
  InlineSpan _getCopyWidget(String text) {
    return WidgetSpan(
        alignment: ui.PlaceholderAlignment.middle,
        child: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () => _copyText(text),
          child: Container(
            width: 15,
            padding: const EdgeInsets.only(left: 3),
            child: CachedNetworkImage(
              imageUrl: styleModel?.copy_btn_icon ?? '',
            ),
          ),
        ));
  }

  /// 微信号码信息
  Widget _getWXNumberInfoWidget() {
    return Container(
      padding: const EdgeInsets.only(left: 9, right: 10, bottom: 6.5, top: 6.5),
      decoration: BoxDecoration(
        color: HexColor.fromHex(styleModel?.bar_color ?? '#F7F7F7'),
        borderRadius: BorderRadius.circular(5),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          /// 微信号码
          RichText(
            textAlign: TextAlign.center,
            text: TextSpan(children: [
              TextSpan(
                  text: styleModel?.wx_text ?? '微信号:', style: TextStyle(color: HexColor.fromHex(styleModel?.wx_color ?? '#999999'), fontSize: 11, fontWeight: FontWeight.bold)),
              TextSpan(
                  text: dataModel?.blurWeChat ?? '',
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: HexColor.fromHex(styleModel?.wx_value_color ?? '#333333'),
                      fontSize: 11,
                      fontFamily: 'Din',
                      package: 'zhiying_base_widget')),
              _getCopyWidget(dataModel?.wechat),
            ]),
          ),

          /// 最近登陆时间
          RichText(
            textAlign: TextAlign.center,
            text: TextSpan(children: [
              TextSpan(
                  text: styleModel?.last_login_text ?? '最近登陆',
                  style: TextStyle(color: HexColor.fromHex(styleModel?.last_login_text_color ?? '#909090'), fontSize: 11, fontFamily: 'Din', package: 'zhiying_base_widget')),
              TextSpan(
                  text: dataModel?.lastLogin ?? '',
                  style: TextStyle(color: HexColor.fromHex(styleModel?.last_login_value_color ?? '#909090'), fontSize: 11, fontFamily: 'Din', package: 'zhiying_base_widget')),
            ]),
          ),
        ],
      ),
    );
  }
}
