import 'package:chat/data/constants.dart';
import 'package:chat/data/translate_hk_data_mgr.dart';
import 'package:chat/generated/i18n.dart';
import 'package:chat/r.dart';
import 'package:chat/utils/HttpUtil.dart';
import 'package:chat/utils/MessageMgr.dart';
import 'package:chat/utils/count_down_button.dart';
import 'package:chat/utils/msgHandler.dart';
import 'package:chat/utils/screen.dart';
import 'package:flutter/material.dart';

///翻译管家-结束后评论弹窗
class TranslateOrderPushPage extends StatefulWidget {
  bool isUser;
  String orderId;
  int scenes;

  String desc;
  Function userStartChat;
  int createTime;

  TranslateOrderPushPage(this.isUser,
      {this.orderId,
      this.scenes,
      this.desc,
      this.userStartChat,
      this.createTime});

  @override
  State<StatefulWidget> createState() {
    return TranslateOrderPushPageState();
  }
}

class TranslateOrderPushPageState extends State<TranslateOrderPushPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    MessageMgr().on(MessageMgr.TRANSLATE_HK_CANCEL_ORDER, cancelOrder);
  }



  cancelOrder(args){
    Navigator.pop(context);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    MessageMgr().off(MessageMgr.TRANSLATE_HK_CANCEL_ORDER, cancelOrder);
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    var scenesList = [
      I18n.of(context).translation_scenes_1,
      I18n.of(context).translation_scenes_2,
      I18n.of(context).translation_scenes_3,
      I18n.of(context).translation_scenes_4,
    ];

    String translateStr= '时间：今天11:45         时长：5${I18n.of(context).minute}';
    String userStr= '下单时间:今天11:45 等待时长:10分钟';

    return UnconstrainedBox(
      alignment: Alignment.topCenter,
      child: InkWell(
        onTap: () {},
        child: Container(
          alignment: Alignment.topCenter,

//         height: 180,
          width: Screen.width - 20,
          margin: EdgeInsets.all(10),
          child: Card(
            elevation: 2, // 阴影
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10),
//              side: BorderSide(color: Colors.green,width: 25),
            ),
            child: Container(
//             color: Colors.yellow,
              width: double.maxFinite,
              padding: EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(bottom: 15),
                    child: Text(
                      I18n.of(context).translation_butler_dialog_title,
                      textScaleFactor: 1.0,
                      textAlign: TextAlign.left,
                      style: TextStyle(
                          fontWeight: FontWeight.w500,
                          color: AppColors.NewAppbarTextColor,
                          fontSize: 17),
                    ),
                  ),
                  Text(
                    I18n.of(context).translation_butler_dialog_order.replaceAll(
                        '/s1', widget.isUser ? I18n.of(context).you : 'xxx'),
                    textScaleFactor: 1.0,
                    textAlign: TextAlign.left,
                    style: TextStyle(
                        color: AppColors.NewAppbarTextColor, fontSize: 14),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Text(
                    widget.isUser?userStr: translateStr,
                    textScaleFactor: 1.0,
                    textAlign: TextAlign.left,
                    style: TextStyle(color: Color(0xFF797979), fontSize: 11),
                  ),

                  widget.isUser
                      ? Container()
                      : Text(
                          '场景:${scenesList[widget.scenes]}',
                          textScaleFactor: 1.0,
                          textAlign: TextAlign.left,
                          style:
                              TextStyle(color: Color(0xFF797979), fontSize: 11),
                        ),

                  widget.isUser
                      ? Container()
                      : Text(
                          '更多描述:${widget.desc}',
                          textScaleFactor: 1.0,
                          textAlign: TextAlign.left,
                          style:
                              TextStyle(color: Color(0xFF797979), fontSize: 11),
                        ),
//
                  Container(
                    margin: EdgeInsets.only(
                        left: 30, right: 30, top: 20, bottom: 10),
                    child: widget.isUser
                        ? Container(
                            margin: EdgeInsets.only(top: 10),
                            height: 36,
                            alignment: Alignment.center,
                            child: RaisedButton(
                                color: Color(0xff3875E9),
                                shape: RoundedRectangleBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(10))),
                                child: Padding(
                                  padding: EdgeInsets.only(left: 10, right: 10),
                                  child: Text(
                                    I18n.of(context)
                                        .translation_butler_dialog_start_chat,
                                    textScaleFactor: 1.0,
                                    style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 15,
                                        fontWeight: FontWeight.w500),
                                  ),
                                ),
                                onPressed: () {
                                  Navigator.of(context).pop();
                                  widget.userStartChat();
                                }),
                          )
                        : CountDownButton(
                            I18n.of(context)
                                .translation_butler_dialog_start_service,
                            () {
                              ///倒计时结束自动关闭
                              Navigator.of(context).pop();
                            },
                            onPress: () {
                              ///发送确认接单
                              MsgHandler.sendReceiveOrder();
                              Navigator.of(context).pop();
                            },
                          ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
