import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/border_text.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/round_button.dart';

class LogoutPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _LogoutPage();
  }
}

class _LogoutPage extends State<LogoutPage> {
  var controller = new ScrollController();
  var checkStatus = false;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        title: S.of(context).zhanghaozhuxiaoshuoming,
        titleColor: Colors.black,
        titleSize: 18.sp,
        background: Colors.transparent,
        leadingColor: Colors.black,
      ),
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          // child: Column(
          //   children: [
          //     WebView(
          //       initialUrl: 'http://huixiang.lotus-wallet.com/user.html',
          //     ),
          //   ],
          // ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(top: 5),
                child: Align(
                  alignment: Alignment.center,
                  child: Text(
                    "注销协议",
                    style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: MyFontWeight.semi_bold,
                      color: Color(0xFF1A1A1A),
                    ),
                  ),
                ),
              ),
              Padding(
                padding:
                    EdgeInsets.only(top: 16, bottom: 8, right: 20, left: 20),
                child: Text(
                  "特别提示",
                  style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: MyFontWeight.semi_bold,
                    color: Color(0xFF1A1A1A),
                  ),
                ),
              ),
              _textRich(
                  "您在申请注销流程中点击同意前,应当认真阅读《帐号注销协议》(以下简称“本协议”)。特别提醒您,当您成功提交注销申请后,即表示您已充分阅读、理解并接受本协议的全部内容。阅读本协议的过程中,如果您不同意相关任何条款,请您立即停止帐号注销程序"),
              Padding(
                padding:
                    EdgeInsets.only(top: 12, bottom: 8, right: 20, left: 20),
                child: Text(
                  "您已了解并同意帐号注销后,将要自行承担以下后果:",
                  style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: MyFontWeight.semi_bold,
                    height: 1.5,
                    color: Color(0xFF1A1A1A),
                  ),
                ),
              ),
              _textRich(
                  "1.账号一旦注销,您将无法登录、使用该账号(也包括无法再使用该账号作为第三方账号登录其他产品),也就是说您将无法再以此账号登录/使用/继续使用海峡姐妹集团旗下的相关产品与服务"),
              _textRich(
                  "2.帐号注销说明我们将删除您的相关信息。您在该帐号下的个人信息、交易记录、业务数据、历史信息等删除后均将无法找回。"),
              _textRich(
                  "3.账号一旦注销,您曾通过该账号登录、使用的海峡姐妹集团旗下的产品与服务下的所有内容、信息、数据、记录将会被删除,您也无法再检索、访问、获取、继续使用和找回,也无权要求我们找回(但法律法规另有规定或监管部门另有要求的除外),包括:"
                  "\n   •该账号下的个人资料(例如:头像、昵称等)及绑定信息(例如:绑定手机号);"
                  "\n   •该账号下的您的个人信息(同时您亦不再享有《海峡姐妹隐私政策》中约定的您的用户权利,但法律法规另有规定的除外);"
                  "\n   •该账号曾发表的所有内容(例如:音频、图片、照片、评论、互动、点赞等);"
                  "\n   •该账号所登录的门店小程序也将无法使用。同时,小程序内的个人信息,账户信息等也将删除"),
              _textRich(
                  "4.您理解并同意,注销帐号后,您曾获得的充值余额、积分、优惠券及其他虚拟财产等将视为您自愿、主动放弃,无法继续使用,由此引起一切纠纷由您自行处理,我们不承担任何责任。"),
              _textRich("5.请注意,注销您的帐号并不代表本帐号注销前的帐号行为和相关责任得到豁免或减轻。"),
              Padding(
                padding:
                    EdgeInsets.only(top: 12, bottom: 8, right: 20, left: 20),
                child: Text(
                  "注销流程:",
                  style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: MyFontWeight.semi_bold,
                    color: Color(0xFF1A1A1A),
                  ),
                ),
              ),
              _textRich("1.首先,保在您开始注销操作前,请先进行以下确认,保证帐号、财产完全:"
                  "\n   •帐号处于安全状态;"
                  "\n   •请确认平台余额以及清零,否则将不予注销;"
                  "\n   •请确认当下无正在进行中的交易,否则无法进行注销操作;。"),
              _textRich(
                  "2.勾选《海峡姐妹账号注销协议》,点击注销后,系统将判定帐号是否符合注销条件,符合后进行手机号验证,输入正确验证码后既注销完成。"),
              Padding(
                padding:
                    EdgeInsets.only(top: 12, bottom: 8, right: 20, left: 20),
                child: Text(
                  "协议附则:",
                  style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: MyFontWeight.semi_bold,
                    color: Color(0xFF1A1A1A),
                  ),
                ),
              ),
              _textRich(
                  "1.海峡姐妹有权在必要时修改本协议,您可以在相关页面查阅最新的本协议。您的任何使用本功能的行为,即视为您已经阅读并同意本协议及相应更新。"),
              _textRich(
                  "2.本协议的拟定、解释均以中文为准。除双方另有约定外,任何有关本协议的翻译不得作为解释本协议或判定双方当事人意图之依据。"),
              SizedBox(
                height: 24.h,
              ),
              Container(
                width: double.infinity,
                margin: EdgeInsets.only(bottom: 20),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Checkbox(
                      value: checkStatus,
                      onChanged: (a) {
                        setState(() {
                          checkStatus = !checkStatus;
                        });
                      },
                      checkColor: Color(0xFFFFFFFF),
                      fillColor: MaterialStateProperty.all(Color(0xFF32A060)),
                    ),
                    Text(
                      "已了解《海峡姐妹账号注销协议》,并自行承担相关后果",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        fontSize: 11.sp,
                        fontWeight: MyFontWeight.medium,
                        color: Color(0xFF010101),
                      ),
                    )
                  ],
                ),
              ),
              GestureDetector(
                onTap: () {
                  if (!checkStatus) {
                    SmartDialog.showToast("请勾选同意《海峡姐妹账号注销协议》",
                        alignment: Alignment.center);
                    return;
                  }
                  showDeleteDialog();
                },
                child: Container(
                    width: double.infinity,
                    height: 54.h,
                    alignment: Alignment.center,
                    margin:EdgeInsets.only(left:20.w,right:20.w,bottom: 25.h),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(45),
                      color: checkStatus ? Color(0xFF32A060) : Color(0xFFD8D8D8),
                    ),
                    child: Text(
                      "注销",
                      style: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: MyFontWeight.semi_bold,
                        color: Color(0xFFFFFFFF),
                      ),
                    )),
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget _textRich(var text) {
    return Padding(
      padding: EdgeInsets.only(bottom: 8, right: 20, left: 20),
      child: Text(
        text,
        style: TextStyle(
            fontSize: 16.sp,
            fontWeight: MyFontWeight.regular,
            height: 1.7,
            color: Colors.black),
      ),
    );
  }

  ///注销账户弹窗
  showDeleteDialog() {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          content: Container(
            width: MediaQuery.of(context).size.width - 84,
            height: 130.h,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  "注销账户会清空所有的信息和数据,确认要进行注销吗?",
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 17.sp,
                    height: 1.2,
                    fontWeight: MyFontWeight.medium,
                    color: Colors.black,
                  ),
                ),
                SizedBox(
                  height: 20.h,
                ),
                Row(
                  children: [
                    Expanded(
                      child: InkWell(
                        child: BorderText(
                          text: S.of(context).querenzhuxiao,
                          textColor: Color(0xFF32A060),
                          fontSize: 16.sp,
                          fontWeight: FontWeight.bold,
                          borderColor: Color(0xFF32A060),
                          radius: 4,
                          padding: EdgeInsets.all(12),
                          borderWidth: 1,
                        ),
                        onTap: () {
                          Navigator.of(context).popAndPushNamed(
                              '/router/logout_ing');
                        },
                      ),
                      flex: 1,
                    ),
                    SizedBox(
                      width: 16.w,
                    ),
                    Expanded(
                      child: InkWell(
                        child: RoundButton(
                          text: "我再想想",
                          textColor: Colors.white,
                          radius: 4,
                          padding: EdgeInsets.all(12),
                          backgroup: Color(0xFF32A060),
                          fontSize: 16.sp,
                          fontWeight: FontWeight.bold,
                        ),
                        onTap: () {
                          Navigator.of(context).pop();
                        },
                      ),
                      flex: 1,
                    ),
                  ],
                )
              ],
            ),
          ),
        );
      },
    );
  }
}