import 'package:chat/data/UserData.dart';
import 'package:chat/home/realtimehelper/translation_butler_page.dart';
import 'package:chat/home/realtimehelper/travel_butler_page.dart';
import 'package:chat/models/group_info_model.dart';
import 'package:chat/utils/HttpUtil.dart';
import 'package:chat/utils/screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';

import '../../data/constants.dart';
import '../../generated/i18n.dart';
import '../../r.dart';

class RealTimeHelperPage extends StatefulWidget {
  final GroupInfoModel groupInfoModel;

  RealTimeHelperPage({Key key, this.groupInfoModel}) : super(key: key);

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

class RealTimeHelperPageState extends State<RealTimeHelperPage> {

  bool isTranslateHKLogin = true;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
//    MessageMgr().off('Update Group Info', updateGroupInfo);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Widget appBar = AppBar(
      backgroundColor: Colors.white,
      title: Text(
        I18n.of(context).real_time_helper,
        textScaleFactor: 1.0,
        style: TextStyle(color: AppColors.NewAppbarTextColor),
      ),
//      leading: CustomUI.buildCustomLeading(context),
      centerTitle: false,
    );


    return UserData().isTranslateUser?Scaffold(
//      appBar: appBar,
      body: Container(
        color: Color(0xffE8EAF0),
        child: Stack(
          children: <Widget>[
            Container(
              child: Image.asset(
                R.assetsImagesImgRealtimeBg2,
                width: MediaQuery.of(context).size.width,
                height:250,
                fit: BoxFit.cover,
              ),
            ),
            Container(
              child: Image.asset(
                R.assetsImagesImgRealtimeBg1,
                width: MediaQuery.of(context).size.width,
                height:MediaQuery.of(context).padding.top+80,
                fit: BoxFit.cover,
              ),
            ),
            Container(
              child: SafeArea(
                  child: ListView(
                children: <Widget>[
                  Container(
                    alignment: Alignment.center,
                    child: fixedText('大神专属', color: Colors.white, fontSize: 21),
                  ),
                 UnconstrainedBox(child:  InkWell(onTap: (){

                   HttpUtil().translateHKloginRecord(!isTranslateHKLogin,(){

                     isTranslateHKLogin = !isTranslateHKLogin;
                     setState(() {
                     });
                   });



                 },child: Container(
                   alignment: Alignment.center,
                   padding: EdgeInsets.only(left: 11,right: 11,top: 3,bottom: 3),
                   decoration: BoxDecoration(
                       border: Border.all(color: isTranslateHKLogin?Color(0xFFFEE645):Colors.white, width: 1),
                       borderRadius: BorderRadius.circular(11)),
                   child: fixedText(isTranslateHKLogin?'开启接单':'未开启接单', color: isTranslateHKLogin?Color(0xFFFEE645):Colors.white, fontSize: 15),
                 ),),),
                  Container(
                    padding: EdgeInsets.only(left: 13,top: 20),
                    child: fixedText('实时帮', color: Colors.white, fontSize: 22,fontWeight: FontWeight.w700),
                  ),
                  helperCard(I18n.of(context).translation_butler,
                      R.assetsImagesImgTranslationButler, () {
                    if (UserData().isTranslateUser) {
                      showToast('翻译人员无法进入创建订单');
                    } else {
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (_) => TranslationButlerPage(),
                        ),
                      );
                    }
                  }, textColor: Color(0xff2685FA)),
                  helperCard(I18n.of(context).travel_butler,
                      R.assetsImagesImgTravelButler, () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (_) => TravelButlerPage(),
                      ),
                    );
                  }, textColor: Color(0xffff682d)),
                  SizedBox(
                    height: 15,
                  ),
                ],
              )),
            )
          ],
        ),
      ),
    ):Scaffold(
      appBar: appBar,
      body: SafeArea(
        child: Container(
          color: Color(0xffE8EAF0),
          child: ListView(
            children: <Widget>[
              helperCard(I18n.of(context).translation_butler,
                  R.assetsImagesImgTranslationButler, () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (_) => TranslationButlerPage(),
                      ),
                    );
                  },textColor: Color(0xff2685FA)),
              helperCard(
                  I18n.of(context).travel_butler, R.assetsImagesImgTravelButler,
                      () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (_) => TravelButlerPage(),
                      ),
                    );
                  },textColor: Color(0xffff682d)),
              SizedBox(
                height: 15,
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget helperCard(String title, String assets, Function callBack,
      {Color textColor}) {
    return InkWell(
      child: Container(
        margin: EdgeInsets.all(10),
        child: Card(
          elevation: 2, // 阴影
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
//              side: BorderSide(color: Colors.green,width: 25),
          ),
          child: Container(
            padding: EdgeInsets.all(10),
            child: Column(
              children: <Widget>[
                Image.asset(
                  assets,
                ),
                Padding(
                  padding: EdgeInsets.only(top: 15, bottom: 15),
                  child: Text(
                    title + ' >>',
                    textScaleFactor: 1.0,
                    style: TextStyle(color: textColor, fontSize: 20),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
      onTap: callBack,
    );
  }
}
