import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.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);

messageTop(imgUrl, title, content, count) {
  var height = ScreenUtil().setHeight(12);
  return Container(
    padding: EdgeInsets.only(left: width, right: width),
    margin: EdgeInsets.only(right: ScreenUtil().setWidth(26)),
    width: double.infinity,
    decoration: BoxDecoration(
      color: ALColors.ColorFFFFFF,
      image: DecorationImage(
        image: AssetImage('images/arrow_right.png'),
        alignment: Alignment.centerRight
      )
    ),
    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)
      ],
    )
  );
}

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();
  }
}

messageList(list) {
  var contentText = {1: '评论了你', 2: '评论了你的评论', 3: '评论了你', 4: '评论了你的评论', 5: '关注了你的问题'};
  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>[
            Container(
              width: 42.0,
              height: 42.0,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                  image: NetworkImage(list.icon)
                ),
              ),
            ),
            SizedBox(width: ScreenUtil().setWidth(10)),
            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(
                        contentText[list.repliedContent?.type],
                        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(
                    dataFormat(list.time),
                    // list.time.toString(),
                    style: TextStyle(
                      color: Color(0xfff8e8e8e),
                      fontSize: ScreenUtil().setSp(10)
                    )
                  )
                ],
              ),
            )
          ],
        ),
        Image.network(
          list.repliedContent.content,
          width: ScreenUtil().setWidth(48),
          fit: BoxFit.fill,
        )
      ],
    )
  );
}

dataFormat(timestamp) {
  return TimelineUtil.format((timestamp * 1000).toInt(),
                        locTimeMillis: DateTime.now().millisecondsSinceEpoch,
                        locale: 'zh',
                        dayFormat: DayFormat.Full);
}
