import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/const_text.dart';
import 'package:making_school_asignment_app/common/job/user_info_detail.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';
import 'package:making_school_asignment_app/common/store/user_store.dart';
import 'package:making_school_asignment_app/common/utils/storage.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
// 其他页面

class OhterPage extends StatefulWidget {
  const OhterPage({super.key});

  @override
  State<OhterPage> createState() => _OhterPageState();
}

class _OhterPageState extends State<OhterPage> with RequestToolMixin {
  late Rx<UserInfoDetail?> userInfo = UserStore.to.userDetailInfo;
  RxString localVersion = ''.obs;

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

  // 获取当前版本号
  getPageInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    localVersion.value = packageInfo.version;
  }

  // 确认对话框
  _showAlertDialog(context1) async {
    await showDialog(
        // 表示点击灰色背景的时候是否消失弹出框
        barrierDismissible: false,
        context: context1,
        builder: (context) {
          return AlertDialog(title: quickText("提示信息"), content: quickText("账户注销无法恢复，您确定要注销账户吗?"), actions: <Widget>[
            TextButton(
              child: quickText("取消"),
              onPressed: () {
                Navigator.pop(context, 'Cancle');
              },
            ),
            TextButton(
                child: quickText("确定"),
                onPressed: () async {
                  /*  ref.read(markingKeyboardProvider.notifier).clean();
                   ref.read(markingSubtopicSwitchingProvider.notifier).clean();
                   ref.read(userTokenProvider.notifier).clean();
                   ref.read(userProvider.notifier).clean();*/
                  await getClient().toUserLogout(userInfo.value!.id);
                  try {
                    UserStore.to.erase();
                    var msg = await StorageService.to.erase();
                    print(msg);
                    Navigator.pop(context, "Ok");
                    Get.offAllNamed(Routes.login);
                  } catch (e) {
                    print(e);
                  }
                })
          ]);
        });
  }

  @override
  Widget build(BuildContext context) {
    final personalInfoTitleStly = TextStyle(
      color: const Color.fromRGBO(80, 87, 103, 1),
      fontSize: 16.sp,
    );

    return Scaffold(
        backgroundColor: const Color.fromRGBO(248, 248, 248, 1),
        appBar: AppBar(
          backgroundColor: Theme.of(context).primaryColor,
          title: quickText('其他', color: Colors.white),
        ),
        body: Stack(
          alignment: const FractionalOffset(0.5, 0.98),
          children: [
            ListView(
              children: [
                Container(
                  margin: EdgeInsets.symmetric(vertical: 22.h, horizontal: 16.w),
                  padding: EdgeInsets.symmetric(vertical: 22.h, horizontal: 16.w),
                  height: 130.h,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(6.w)),
                    color: Colors.white,
                    boxShadow: const [
                      BoxShadow(
                        color: Color.fromRGBO(46, 91, 255, 0.1),
                        offset: Offset.zero, //阴影y轴偏移量
                        blurRadius: 20, //阴影模糊程度
                        spreadRadius: 10, //阴影扩散程度
                      )
                    ],
                  ),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () {
                          Get.toNamed(Routes.agreementPage, arguments: {"type": AGREEMENT_KEY.PRIVACY_GREEMENT.name});
                        },
                        child: Container(
                          padding: EdgeInsets.only(bottom: 4.h),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text('用户隐私协议', style: personalInfoTitleStly),
                              Icon(
                                Icons.arrow_forward_ios,
                                color: const Color.fromRGBO(80, 87, 103, 1),
                                size: 16.sp,
                              )
                            ],
                          ),
                        ),
                      ),
                      Container(
                        height: 1.w,
                        color: const Color.fromRGBO(240, 243, 255, 1),
                      ),
                      SizedBox(height: 8.h),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('APP版本', style: personalInfoTitleStly),
                          Obx(() {
                            return quickText(localVersion);
                          })
                        ],
                      )
                    ],
                  ),
                ),
              ],
            ),
            Positioned(
              bottom: 50.h,
              child: InkWell(
                child: Container(
                  height: 46.h,
                  width: ScreenUtil().screenWidth - 60.w,
                  padding: EdgeInsets.symmetric(vertical: 14.h),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(6.w),
                    ),
                    color: Colors.white,
                    boxShadow: [
                      BoxShadow(
                        color: const Color.fromRGBO(46, 91, 255, 0.2),
                        offset: Offset(2.w, 2.h), //阴影y轴偏移量
                        blurRadius: 14, //阴影模糊程度
                        spreadRadius: 0.5, //阴影扩散程度
                      )
                    ],
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(
                        Icons.exit_to_app_outlined,
                        size: 13.sp,
                        color: const Color.fromRGBO(148, 163, 182, 1),
                      ),
                      Container(
                        width: 6.w,
                      ),
                      Text(
                        '账户注销',
                        style: TextStyle(color: const Color.fromRGBO(148, 163, 182, 1), fontSize: 13.sp),
                      ),
                    ],
                  ),
                ),
                onTap: () => _showAlertDialog(context),
              ),
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [Text('APP备案号: ', style: personalInfoTitleStly), quickText('渝ICP备17007225号-4A', size: 14.sp)],
            ),
          ],
        ));
  }
}
