import 'package:flutter/material.dart';
import '../../../../app/theme/app_colors.dart';
import '../../../../app/theme/app_typography.dart';

/// 设置页面
///
/// 账号安全、通知、支付管理、语言、关于
class SettingsPage extends StatelessWidget {
  const SettingsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('设置')),
      body: ListView(
        children: [
          // Account & Security
          _buildSection('账号与安全', [
            _buildTile('手机号', subtitle: '138****8888', icon: Icons.phone_rounded),
            _buildTile('邮箱', subtitle: 'u***@email.com', icon: Icons.email_rounded),
            _buildTile('修改密码', icon: Icons.lock_rounded),
            _buildTile('身份认证', subtitle: 'L1 基础认证', icon: Icons.verified_user_rounded, onTap: () {
              Navigator.pushNamed(context, '/kyc');
            }),
          ]),

          // Payment
          _buildSection('支付管理', [
            _buildTile('支付方式', subtitle: 'Visa •••• 4242', icon: Icons.credit_card_rounded),
            _buildTile('银行账户', subtitle: 'BoA •••• 6789', icon: Icons.account_balance_rounded),
            _buildTile('支付密码', icon: Icons.password_rounded),
          ]),

          // Notifications
          _buildSection('通知设置', [
            _buildSwitchTile('交易通知', true),
            _buildSwitchTile('到期提醒', true),
            _buildSwitchTile('行情变动', false),
            _buildSwitchTile('营销推送', false),
          ]),

          // General
          _buildSection('通用', [
            _buildTile('语言', subtitle: '简体中文', icon: Icons.language_rounded),
            _buildTile('货币', subtitle: 'USD', icon: Icons.attach_money_rounded),
            _buildTile('清除缓存', icon: Icons.cleaning_services_rounded),
          ]),

          // About
          _buildSection('关于', [
            _buildTile('版本', subtitle: 'v1.0.0', icon: Icons.info_outline_rounded),
            _buildTile('用户协议', icon: Icons.description_rounded),
            _buildTile('隐私政策', icon: Icons.privacy_tip_rounded),
            _buildTile('帮助中心', icon: Icons.help_outline_rounded),
          ]),

          // Logout
          Padding(
            padding: const EdgeInsets.all(20),
            child: OutlinedButton(
              onPressed: () {
                Navigator.of(context).pushNamedAndRemoveUntil('/', (_) => false);
              },
              style: OutlinedButton.styleFrom(
                foregroundColor: AppColors.error,
                side: const BorderSide(color: AppColors.error),
                minimumSize: const Size(double.infinity, 48),
              ),
              child: const Text('退出登录'),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSection(String title, List<Widget> children) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(20, 20, 20, 8),
          child: Text(title, style: AppTypography.labelSmall),
        ),
        Container(
          color: AppColors.surface,
          child: Column(children: children),
        ),
      ],
    );
  }

  Widget _buildTile(String title, {String? subtitle, IconData? icon, VoidCallback? onTap}) {
    return ListTile(
      leading: icon != null ? Icon(icon, size: 22, color: AppColors.textSecondary) : null,
      title: Text(title, style: AppTypography.bodyMedium),
      subtitle: subtitle != null ? Text(subtitle, style: AppTypography.caption) : null,
      trailing: const Icon(Icons.chevron_right_rounded, size: 20, color: AppColors.textTertiary),
      onTap: onTap ?? () {},
    );
  }

  Widget _buildSwitchTile(String title, bool value) {
    return SwitchListTile(
      title: Text(title, style: AppTypography.bodyMedium),
      value: value,
      onChanged: (_) {},
      activeColor: AppColors.primary,
    );
  }
}
