import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:keyboard/module/user_info/user_info_controller.dart';
import 'package:get/get.dart';
import 'package:keyboard/resource/string.gen.dart';
import 'package:keyboard/utils/styles.dart';
import '../../base/base_page.dart';
import '../../resource/assets.gen.dart';
import '../../router/app_pages.dart';
import '../../widget/commonAppBar.dart';

class UserInfoPage extends BasePage<UserInfoController> {
  const UserInfoPage({super.key});

  /// 跳转
  static start() {
    Get.toNamed(RoutePath.userInfo);
  }

  @override
  bool immersive() {
    return false;
  }

  @override
  statusBarDarkFont() {
    return true;
  }

  @override
  Color backgroundColor() {
    return const Color(0xFFF6F5FA);
  }

  @override
  Widget buildBody(BuildContext context) {
    return Scaffold(
      backgroundColor: backgroundColor(),
      appBar: CommonAppBar(
        title: StringName.userInfo,
        backgroundColor: () {
          return Colors.transparent;
        },
        onBack: () {
          controller.clickBack();
        },
      ),
      body: Column(
        children: [
          Container(
            margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 20.w),
            padding: EdgeInsets.all(16.w),
            decoration: ShapeDecoration(
              color: Colors.white,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(12.r),
              ),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  StringName.personalInfo,
                  style: TextStyle(
                    color: const Color(0xFFBBBCCC),
                    fontSize: 14.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(height: 24.h),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      StringName.loginAccount,
                      style: Styles.getTextStyleBlack204W400(14.sp),
                    ),
                    Text(
                      controller.userInfo?.account ?? "",
                      style: TextStyle(
                        color: Colors.black.withAlpha(102),
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(height: 8.h),

          _buildDeprecateButton(),
          const Spacer(),

          _buildLogoutButton(),
        ],
      ),
    );
  }

  Widget _buildLogoutButton() {
    return Row(
      children: [
        Expanded(
          child: Container(
            margin: EdgeInsets.only(bottom: 20.w, left: 16.w, right: 16.w),
            height: 48.h,
            child: Material(
              color: const Color(0xFFEDE8FF),
              borderRadius: BorderRadius.circular(50.r),
              child: InkWell(
                splashColor: Color(0xFFB983FF),
                borderRadius: BorderRadius.circular(50.r),
                onTap: () {
                  controller.clickLogout();
                },
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      width: 22.w,
                      height: 22.w,
                      margin: EdgeInsets.only(right: 6.w),
                      child: Assets.images.iconUserInfoLogout.image(
                        width: 22.w,
                        height: 22.w,
                        fit: BoxFit.contain,
                      ),
                    ),
                    Text(
                      StringName.logout,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: const Color(0xFF7D46FC),
                        fontSize: 16.sp,
                        fontWeight: FontWeight.w500,
                        height: 1.25,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }

  Widget _buildDeprecateButton() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Material(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12.r),
        child: InkWell(
          borderRadius: BorderRadius.circular(12.r),
          onTap: () {
            controller.clickDeprecate();
          },
          child: Padding(
            padding: EdgeInsets.all(16.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  StringName.loginDeleteAccount,
                  style: Styles.getTextStyleBlack204W400(14.sp),
                ),
                Assets.images.iconUserInfoArrowLeft.image(
                  width: 20.w,
                  height: 20.w,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
