import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/MessageModel/util/message_date.dart';
import 'package:gmalpha_flutter/commonModel/base/AppBase.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';


messageTitle(String text) {
  return Text(
    text,
    style: TextStyle(
      color: ALColors.Color323232,
      fontSize: ScreenUtil().setSp(20)
    )
  );
}

var width = ScreenUtil().setWidth(16);

Widget messageTop(imgUrl, title, content, count) {
  var height = ScreenUtil().setHeight(12);
  return Container(
    padding: EdgeInsets.only(left: width, right: width),
    width: double.infinity,
    child: Stack(
      children: <Widget>[
        Container(
          padding: EdgeInsets.only(left: ScreenUtil().setWidth(28)),
          margin: EdgeInsets.only(left: ScreenUtil().setWidth(4), top: height, bottom: height),
          width: double.infinity,
          decoration: BoxDecoration(
            color: ALColors.ColorFFFFFF,
            image: DecorationImage(
              image: AssetImage(imgUrl),
              alignment: Alignment.centerLeft
            )
          ),
          child: Row(
            children: <Widget>[
              Text(
                title,
                style: TextStyle(
                  color: ALColors.Color323232,
                  fontSize: ScreenUtil().setSp(13),
                  fontWeight: FontWeight.bold
                )
              ),
              SizedBox(
                width: ScreenUtil().setWidth(16),
              ),
              Container(
                width: ScreenUtil().setWidth(200),
                child: Text(
                  content,
                  style: TextStyle(
                    color: ALColors.Color8E8E8E,
                    fontSize: ScreenUtil().setSp(13)
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis
                )
              )
            ],
          ),
        ),
        getNum(count),
        Positioned(
          right: ScreenUtil().setWidth(14),
          top: ScreenUtil().setHeight(12),
          child: Hero(
              tag: "arrow_right",
              child: SvgPicture.asset(
                "images/arrow_right.svg",
                color: ALColors.Color323232,
              )),
        )
      ],
    )
  );
}

Widget getNum([int count]) {
  if(count > 0) {
    return Positioned(
      right: 0,
      top: ScreenUtil().setHeight(12),
      child: Container(
        padding: EdgeInsets.only(top: ScreenUtil().setHeight(2), bottom: ScreenUtil().setHeight(2), left: ScreenUtil().setWidth(7), right: ScreenUtil().setWidth(7)),
        decoration: BoxDecoration(
          color: ALColors.Color323232,
          borderRadius: BorderRadius.circular(22.0)
        ),
        child: Text(
          count.toString(),
          style: TextStyle(
            color: ALColors.ColorFFFFFF,
            fontSize: ScreenUtil().setSp(11),
            height: 1.0
          ),
        )
      ),
    );
  } else {
    return Container();
  }
}

Widget messageList(list) {
  var content = {
    1: {'showText': '评论了你', 'opeUrl': 'topic_detail?call_keyboard=1&open_comment=0&topic_id=${list.repliedContent.topicId}&reply_id=${list.id}'}, 
    2: {'showText': '评论了你的评论', 'opeUrl': 'topic_detail?call_keyboard=1&open_comment=0&topic_id=${list.repliedContent.topicId}&reply_id=${list.id}'},
    3: {'showText': '评论了你', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}&reply_id=${list.id}&show_reply=${false}'},
    4: {'showText': '评论了你的评论', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}&reply_id=${list.id}&show_reply=${false}'},
    5: {'showText': '关注了你的问题', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}'}
  };
  return Container(
    padding: EdgeInsets.only(left: width, right: width),
    margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(25)),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            GestureDetector(
              onTap: (){
                onClickButton('head_photo', {'business_id': list.userId.toString()});
                jumpToNative('message_home', {"url": 'alpha://user_detail?user_id=${list.userId}'});
              },
              child: Container(
                width: 42.0,
                height: 42.0,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  image: DecorationImage(
                    image: NetworkImage(list.icon)
                  )
                )
              )
            ),
            SizedBox(width: ScreenUtil().setWidth(10)),
            GestureDetector(
              onTap: (){
                onClickButton('comment');
              },
              child: Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          list.name,
                          style: TextStyle(
                            color: ALColors.Color323232,
                            fontSize: ScreenUtil().setSp(13),
                            fontWeight: FontWeight.bold
                          )
                        ),
                        SizedBox(width: ScreenUtil().setWidth(10)),
                        Text(
                          content[list.repliedContent?.type]['showText'],
                          style: TextStyle(
                            color: ALColors.Color323232,
                            fontSize: ScreenUtil().setSp(13)
                          )
                        )
                      ],
                    ),
                    Container(
                      width: ScreenUtil().setWidth(210),
                      child: Text(
                        list.content,
                        style: TextStyle(
                          color: ALColors.Color323232,
                          fontSize: ScreenUtil().setSp(13)
                        ),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis
                      ),
                    ),
                    Text(
                      MessageDate(list.time).diffTime(),
                      style: TextStyle(
                        color: Color(0xfff8e8e8e),
                        fontSize: ScreenUtil().setSp(10)
                      )
                    )
                  ]
                )
              )
            )
          ]
        ),
        GestureDetector(
          onTap: () {
            onClickButton('photo', {'business_id': list.repliedContent.id.toString()});
            jumpToNative('message_home', {"url": 'alpha://${content[list.repliedContent?.type]['openUrl']}'});
          },
          child: Image.network(
            list.repliedContent.content,
            width: ScreenUtil().setWidth(48),
            fit: BoxFit.fill,
          )
        )
      ],
    )
  );
}


void onClickButton(buttonName, [params]) {
  RouterCenterImpl()
  .findBuriedRouter()
  ?.onEvent('on_click_button', {
    'page_name': 'message_home',
    'button_name': buttonName,
    ...?params
  });
}

void onClickLike(buttonName, [params]) {
  RouterCenterImpl()
  .findBuriedRouter()
  ?.onEvent('on_click_button', {
    'page_name': 'like_list',
    'button_name': buttonName,
    ...?params
  });
}