import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:chat/configs/app_colors.dart';
import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/views/home/widgets/action_button.dart';
import 'package:chat/views/home/widgets/action_item.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class UserSettingPage extends StatefulWidget {
  const UserSettingPage({Key? key}) : super(key: key);

  @override
  _UserSettingPageState createState() => _UserSettingPageState();
}

class _UserSettingPageState extends State<UserSettingPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('设置中心'),
      ),
      body: Column(
        children: [
          ActionItem(
            '账号与安全',
            isFirst: true,
            isLast: true,
            onTap: () {
              Get.toNamed(UserRoutes.settingSafe);
            },
          ),
          const SizedBox(height: 8),
          ActionItem(
            '新消息通知',
            isFirst: true,
            onTap: () {
              Get.toNamed(UserRoutes.settingSafe);
            },
          ),
          ActionItem(
            '隐私权限',
            isLast: true,
            onTap: () {
              Get.toNamed(UserRoutes.settingPrivacy);
            },
          ),
          const SizedBox(height: 8),
          ActionItem(
            '关于ZH-CHAT',
            isFirst: true,
            onTap: () {
              Get.toNamed(UserRoutes.settingAbout);
            },
          ),
          ActionItem(
            '帮助与反馈',
            onTap: () {
              Get.toNamed(UserRoutes.settingSugguest);
            },
          ),
          const SizedBox(height: 8),
          ActionItem(
            '版本更新',
            isFirst: true,
            isLast: true,
            onTap: () {},
          ),
          const SizedBox(height: 8),
          ActionButton(
            '退出',
            hasTop: true,
            hasBottom: true,
            color: AppColors.red,
            onTap: () async {
              OkCancelResult result = await showOkCancelAlertDialog(
                style: AdaptiveStyle.iOS,
                context: context,
                title: '退出登录',
                message: '确认您已备份助记词并保存好了么？退出登录后助记词将无法导出。',
                okLabel: '确定',
                cancelLabel: '取消',
                defaultType: OkCancelAlertDefaultType.cancel,
              );
              if (result == OkCancelResult.ok) {
                AuthService.to.logout();
              }
            },
          ),
        ],
      ),
    );
  }
}
