import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/color/app_uri_status.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/mh_controller/mh_language_controller.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/model/api_response.dart';

class SettingPage extends StatefulWidget {
  @override
  _SettingPageState createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  MHLanguageController languageController = Get.find();
  UserInfoController userInfoController = Get.find();
  @override
  void initState() {
    languageController.initLanuageList();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, bodySize) {
      return GestureDetector(
        onTap: () => FocusScope.of(context).unfocus(),
        child: Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/new_background.png'), // 本地图片
                fit: BoxFit.fill, // 填满整个 Container
              ),
            ),
            child: Scaffold(
              backgroundColor: Colors.transparent,
              appBar: AppBar(
                backgroundColor: Colors.transparent,
                iconTheme: const IconThemeData(color: Colors.white),
                titleSpacing: 0,
                automaticallyImplyLeading: false,
                title: SizedBox(
                  width: double.infinity,
                  height: 180.rpx,
                  child: Stack(
                    alignment: Alignment.center,
                    children: [
                      // 中间居中的标题
                      Text(
                        '设置',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 30.rpx,
                        ),
                      ),
                      // 左侧图标
                      Positioned(
                        left: 0.rpx,
                        child: returnIconButtomNew,
                      ),
                    ],
                  ),
                ),
                centerTitle: false,
              ),
              body: SafeArea(
                top: true,
                child: Padding(
                  padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
                  child: SingleChildScrollView(
                    child: Column(
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        Padding(
                          padding: EdgeInsetsDirectional.fromSTEB(
                              0.rpx, 25.rpx, 0.rpx, 0),
                          child: Container(
                            width: double.infinity,
                            decoration: BoxDecoration(
                              color: Color(0xFF003058),
                              borderRadius: BorderRadius.circular(
                                  AppConstants().normal_container_radius),
                            ),
                            child: Padding(
                              padding: EdgeInsetsDirectional.fromSTEB(
                                  0.rpx, 0, 0.rpx, 0),
                              child: Column(
                                mainAxisSize: MainAxisSize.max,
                                children: [
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        40.rpx, 0.rpx, 40.rpx, 0.rpx),
                                    onTap: () {
                                      Get.toNamed("/updatePasswordPage");
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            0.rpx, 30.rpx, 0.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text('修改密码',
                                                    style: TextStyle(
                                                        fontSize: 30.rpx,
                                                        color: Colors.white,
                                                        height: 1)),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            SvgPicture.asset(
                                              'assets/img/icon/arrow_right.svg',
                                              width: 8.rpx,
                                              height: 15
                                                  .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                              color: themeController
                                                  .currentColor.sc3,
                                            ),
                                            // Row(
                                            //   mainAxisSize: MainAxisSize.max,
                                            //   children: [
                                            //     Text(
                                            //       '深色',
                                            //       style: FlutterFlowTheme.of(
                                            //               context)
                                            //           .bodyMedium
                                            //           .override(
                                            //             fontFamily: 'Inter',
                                            //             color:
                                            //                 Color(0xFFD9E3EB),
                                            //             fontSize: 26.rpx,
                                            //             letterSpacing: 0.0,
                                            //           ),
                                            //     ),

                                            //   ].divide(SizedBox(width: 28.rpx)),
                                            // ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        0.rpx, 0.rpx, 0.rpx, 0.rpx),
                                    onTap: () {
                                      print('点击了容器');
                                      Get.toNamed("/aboutUsPage");
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            40.rpx, 30.rpx, 40.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text(
                                                  '当前版本',
                                                  style: TextStyle(
                                                    fontFamily: 'Inter',
                                                    color: Colors.white,
                                                    fontSize: AppConstants()
                                                        .title_text_fontSize,
                                                    letterSpacing: 0.0,
                                                    // height: 1.0,
                                                  ),
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            Text('SWES3.513.4',
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 26.rpx,
                                                    height: 1)),
                                            // SvgPicture.asset(
                                            //   'assets/img/icon/arrow_right.svg',
                                            //   width: 8.rpx,
                                            //   height: 14
                                            //       .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                            //   color: themeController
                                            //       .currentColor.sc3,
                                            // ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        40.rpx, 0.rpx, 40.rpx, 0.rpx),
                                    onTap: () {
                                      // TopSlideNotification.show(context,
                                      //     text: "待开发功能".tr);
                                      Get.toNamed("/languagePage");
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            0.rpx, 30.rpx, 0.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text(
                                                  '切换语言',
                                                  style: TextStyle(
                                                    fontFamily: 'Inter',
                                                    color: Colors.white,
                                                    fontSize: AppConstants()
                                                        .title_text_fontSize,
                                                    letterSpacing: 0.0,
                                                    // height: 1.0,
                                                  ),
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Obx(() {
                                                  return Text(
                                                    languageController
                                                            .selectLanguage
                                                            .value
                                                            ?.language_name ??
                                                        '简体中文',
                                                    style: TextStyle(
                                                      fontFamily: 'Inter',
                                                      color: Color(0xFFD9E3EB),
                                                      fontSize: 26.rpx,
                                                      letterSpacing: 0.0,
                                                      // height: 1.0,
                                                    ),
                                                  );
                                                }),
                                                SvgPicture.asset(
                                                  'assets/img/icon/arrow_right.svg',
                                                  width: 8.rpx,
                                                  height: 15
                                                      .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                                  color: themeController
                                                      .currentColor.sc3,
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        0.rpx, 0.rpx, 0.rpx, 0.rpx),
                                    onTap: () {
                                      Get.toNamed('/aboutUs');
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            40.rpx, 30.rpx, 40.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text(
                                                  '设置页.关于我们'.tr,
                                                  style: TextStyle(
                                                    fontFamily: 'Inter',
                                                    color: Colors.white,
                                                    fontSize: AppConstants()
                                                        .title_text_fontSize,
                                                    letterSpacing: 0.0,
                                                    // height: 1.0,
                                                  ),
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            SvgPicture.asset(
                                              'assets/img/icon/arrow_right.svg',
                                              width: 8.rpx,
                                              height: 14
                                                  .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                              color: themeController
                                                  .currentColor.sc3,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        40.rpx, 0.rpx, 40.rpx, 0.rpx),
                                    onTap: () {
                                      Get.toNamed("/userAgreementPage");
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            0.rpx, 30.rpx, 0.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text(
                                                  '设置页.用户协议'.tr,
                                                  style: TextStyle(
                                                    fontFamily: 'Inter',
                                                    color: Colors.white,
                                                    fontSize: AppConstants()
                                                        .title_text_fontSize,
                                                    letterSpacing: 0.0,
                                                    // height: 1.0,
                                                  ),
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            SvgPicture.asset(
                                              'assets/img/icon/arrow_right.svg',
                                              width: 8.rpx,
                                              height: 15
                                                  .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                              color: themeController
                                                  .currentColor.sc3,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                  ClickableContainer(
                                    backgroundColor:
                                        Colors.transparent, // 容器背景色
                                    highlightColor: themeController
                                        .currentColor.sc21, // 点击时的背景色
                                    padding: EdgeInsetsDirectional.fromSTEB(
                                        0.rpx, 0.rpx, 0.rpx, 0.rpx),
                                    onTap: () {
                                      Get.toNamed("/privacyPolicyPage");
                                    },
                                    child: Container(
                                      child: Padding(
                                        padding: EdgeInsetsDirectional.fromSTEB(
                                            40.rpx, 30.rpx, 40.rpx, 30.rpx),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.max,
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              mainAxisSize: MainAxisSize.max,
                                              children: [
                                                Text(
                                                  '设置页.隐私协议'.tr,
                                                  style: TextStyle(
                                                    fontFamily: 'Inter',
                                                    color: Colors.white,
                                                    fontSize: AppConstants()
                                                        .title_text_fontSize,
                                                    letterSpacing: 0.0,
                                                    // height: 1.0,
                                                  ),
                                                ),
                                              ].divide(SizedBox(width: 22.rpx)),
                                            ),
                                            SvgPicture.asset(
                                              'assets/img/icon/arrow_right.svg',
                                              width: 8.rpx,
                                              height: 14
                                                  .rpx, // 如果 SVG 中没有固定颜色，可以这样设置
                                              color: themeController
                                                  .currentColor.sc3,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                ]
                                    .divide(SizedBox(height: 0.rpx))
                                    .addToStart(SizedBox(height: 30.rpx))
                                    .addToEnd(SizedBox(height: 30.rpx)),
                              ),
                            ),
                          ),
                        ),
                        Padding(
                          padding: EdgeInsetsDirectional.fromSTEB(
                              0.rpx, 174.rpx, 0.rpx, 0),
                          child: CustomCard(
                            borderRadius: 16.rpx,

                            onTap: () {
                              ApiResponse apiResponse =
                                  userInfoController.logOut();
                              TopSlideNotification.show(
                                context,
                                text: apiResponse.msg!,
                                textColor:
                                    apiResponse.code == HttpStatusCodes.ok
                                        ? themeController.currentColor.sc2
                                        : themeController.currentColor.sc9,
                              );
                              if (apiResponse.code == HttpStatusCodes.ok) {
                                Get.offAllNamed("/mianPageBottomChange");
                              }
                            },
                            colors: [
                              Color(0XFF84F5FF),
                            ], // 渐变色是同一个色，也可以根据需要调整
                            child: Container(
                              width:
                                  // MediaQuery.sizeOf(context).width * 0.66,
                                  bodySize.maxWidth,
                              height: MediaQuery.sizeOf(context).height * 0.055,
                              constraints: BoxConstraints(
                                minWidth: 500.rpx,
                                minHeight: 90.rpx,
                              ),
                              child: Row(
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '设置页.退出登录'.tr,
                                    style: TextStyle(
                                      color: Color(0xFF003058),
                                      fontFamily: 'Inter',
                                      fontSize:
                                          AppConstants().normal_text_fontSize,
                                      letterSpacing: 0.0,
                                    ),
                                  ),
                                ].divide(SizedBox(
                                  width: 17.rpx,
                                )),
                              ),
                            ),
                          ),
                        ),
                        Padding(
                          padding: EdgeInsetsDirectional.fromSTEB(
                              100.rpx, 20.rpx, 100.rpx, 0),
                          child: CustomCard(
                            borderRadius:
                                AppConstants().button_container_radius, // 圆角半径
                            onTap: () {
                              TopSlideNotification.show(
                                context,
                                text: "待开发功能".tr,
                              );
                            },
                            colors: [
                              Colors.transparent,
                            ], // 渐变色是同一个色，也可以根据需要调整
                            child: Container(
                              width:
                                  // MediaQuery.sizeOf(context).width * 0.66,
                                  bodySize.maxWidth,
                              height: MediaQuery.sizeOf(context).height * 0.055,
                              constraints: BoxConstraints(
                                minWidth: 500.rpx,
                                minHeight: 90.rpx,
                              ),
                              child: Row(
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '设置页.注销账号'.tr,
                                    style: TextStyle(
                                      color: themeController.currentColor.sc9,
                                      fontFamily: 'Inter',
                                      fontSize:
                                          AppConstants().normal_text_fontSize,
                                      letterSpacing: 0.0,
                                    ),
                                  ),
                                ].divide(SizedBox(
                                  width: 17.rpx,
                                )),
                              ),
                            ),
                          ),
                        ),
                        Padding(
                          padding: EdgeInsetsDirectional.fromSTEB(
                              0.rpx, 135.rpx, 0.rpx, 0),
                          child: ClickableContainer(
                            borderRadius:
                                AppConstants().button_container_radius, // 圆角半径
                            onTap: () {},
                            backgroundColor:
                                Colors.transparent, // 渐变色是同一个色，也可以根据需要调整
                            highlightColor: themeController.currentColor.sc5,
                            padding: EdgeInsetsDirectional.fromSTEB(
                                0.rpx, 0.rpx, 0.rpx, 0),
                            child: Container(
                              width:
                                  // MediaQuery.sizeOf(context).width * 0.66,
                                  bodySize.maxWidth,
                              height: MediaQuery.sizeOf(context).height * 0.055,
                              constraints: BoxConstraints(
                                minWidth: 500.rpx,
                                minHeight: 90.rpx,
                              ),
                              child: Column(
                                  mainAxisSize: MainAxisSize.max,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      'ICP备案号:浙ICP备2023000785号-1'.tr,
                                      style: TextStyle(
                                        color: themeController.currentColor.sc4,
                                        fontFamily: 'Inter',
                                        fontSize: AppConstants()
                                            .smaller_text_fontSize,
                                        letterSpacing: 0.0,
                                      ),
                                    ),
                                    Text(
                                      AppConstants().ent_type == 1
                                          ? 'Copyright © 202-2025 嘉兴太和信息技术有限责任公司 版权所有'
                                              .tr
                                          : "Copyright © 202-2025 杭州欢睡科技有限公司 版权所有",
                                      style: TextStyle(
                                        color: themeController.currentColor.sc4,
                                        fontFamily: 'Inter',
                                        fontSize: AppConstants()
                                            .smaller_text_fontSize,
                                        letterSpacing: 0.0,
                                      ),
                                    ),
                                  ].divide(SizedBox(
                                    height: 17.rpx,
                                  ))),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            )),
      );
    });
  }
}
