import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wgshare/main.dart';
import 'package:wgshare/pages/userPage/user_logic.dart';
import '../../common/store/user_store.dart';
import '../../routes/app_routes.dart';
import '../../utils/color_util.dart';
import '../../utils/hint_dialog.dart';
import '../../utils/storage.dart';

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

  @override
  State<UserPage> createState() => UserPageState();
}

class UserPageState extends State<UserPage>  {

  final logic = Get.put(UserLogic());
  final state = Get.find<UserLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          surfaceTintColor: Colors.white,
          elevation: 0,
          toolbarHeight: 0,
          systemOverlayStyle: const SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            systemNavigationBarColor: Color(0xFF000000),
            systemNavigationBarIconBrightness: Brightness.light,
            statusBarIconBrightness: Brightness.dark,
            statusBarBrightness: Brightness.light,
          ),
          backgroundColor: Colors.white,
        ),
        body: Container(
          color: ColorUtil.Color_244_244_244,
          child: Column(
            children: [
              Container(
                width: double.infinity,
                height: 44.h,
                color: Colors.white,
                alignment: Alignment.center,
                child: Text(
                  '我的',
                  style: TextStyle(
                      fontSize: 16.sp,
                      color: ColorUtil.Color_51_51_51,
                      fontWeight: FontWeight.w500
                  ),
                ),
              ),
              Container(
                width: double.infinity,
                child: Container(
                  width: double.infinity,
                  color: Colors.white,
                  margin: const EdgeInsets.only(top: 1),
                  padding: const EdgeInsets.only(bottom: 60),
                  child: Column(
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(top: 20, bottom: 6),
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(100),
                            color: ColorUtil.Color_85_117_242
                          ),
                          width: 132.w,
                          height: 132.h,
                          alignment: Alignment.center,
                          child: Text(
                              UserStore.to.userInfoEntity.value!.userName.length >= 3
                                  ? UserStore.to.userInfoEntity.value!.userName.substring(UserStore.to.userInfoEntity.value!.userName.length - 2,UserStore.to.userInfoEntity.value!.userName.length)
                                  : UserStore.to.userInfoEntity.value!.userName,
                              style: TextStyle(
                                fontSize: 30.sp,
                                color: ColorUtil.Color_244_244_244
                              ),
                          ),
                        ),
                      ),
                      Text(
                        UserStore.to.userInfoEntity.value!.userName,
                        style: TextStyle(
                            fontSize: 16.sp,
                            fontWeight: FontWeight.w500,
                            color: ColorUtil.Color_85_117_242
                        ),
                      ),
                      Container(
                          padding: const EdgeInsets.only(left: 16, right: 16),
                          margin: const EdgeInsets.only(top: 30),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '名称',
                                style: TextStyle(
                                    fontSize: 12.sp,
                                    color: ColorUtil.Color_134_134_134
                                ),
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    UserStore.to.userInfoEntity.value!.userName,
                                    style: TextStyle(
                                        fontSize: 12.sp,
                                        color: ColorUtil.Color_51_51_51
                                    ),
                                  ),
                                  SizedBox(width: 12.w),
                                  Image.asset(
                                    'assets/images/user_right.png',
                                    width: 10.w,
                                    height: 10.h,
                                  )
                                ],
                              ),
                            ],
                          )
                      ),
                      Container(
                        width: double.infinity,
                        height: 1.h,
                        color: ColorUtil.Color_230_230_230,
                        margin: const EdgeInsets.only(top: 12, left: 16, right: 16),
                      ),
                      Container(
                          padding: const EdgeInsets.only(left: 16, right: 16),
                          margin: const EdgeInsets.only(top: 20),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '登录密码',
                                style: TextStyle(
                                    fontSize: 12.sp,
                                    color: ColorUtil.Color_134_134_134
                                ),
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '********',
                                    style: TextStyle(
                                        fontSize: 12.sp,
                                        color: ColorUtil.Color_51_51_51
                                    ),
                                  ),
                                  SizedBox(width: 12.w),
                                  Image.asset(
                                    'assets/images/user_right.png',
                                    width: 10.w,
                                    height: 10.h,
                                  )
                                ],
                              ),
                            ],
                          )
                      ),
                      Container(
                        width: double.infinity,
                        height: 1.h,
                        color: ColorUtil.Color_230_230_230,
                        margin: const EdgeInsets.only(top: 12, left: 16, right: 16),
                      ),
                    ],
                  ),
                ),
              ),

              GestureDetector(
                onTap: (){
                  UserStore.to.erase();
                  Get.offAllNamed(Routes.loginPage);
                },
                child: Container(
                  width: 280.w,
                  height: 44.h,
                  margin: const EdgeInsets.only(top: 40),
                  decoration: const BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(99)),
                    color: ColorUtil.Color_85_117_242,
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    '退出登录',
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: Colors.white,
                    ),
                  ),
                ),
              )
            ],
          ),
        )
    );
  }
}
