import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:nomo/app/base/base_view.dart';
import 'package:nomo/app/widgets/submit_btn.dart';
import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';

import '../../../../../config/theme/dark_theme_colors.dart';
import '../../../../constants/assets.dart';
import '../../../../constants/iconfont/iconfont.dart';
import '../../../../widgets/info_card.dart';
import '../../../../widgets/ix_app_bar.dart';
import '../../../../widgets/ix_image.dart';
import '../../../../widgets/ix_text_field.dart';
import '../controllers/precode_sendemail_controller.dart';

class PrecodeSendemailView extends BaseView<PrecodeSendemailController> {
  const PrecodeSendemailView({super.key});

  @override
  PreferredSizeWidget? get appBar => IXAppBar(title: 'Send Pre Code to Email');

  @override
  Widget buildContent(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 14.w),
      child: SingleChildScrollView(
        child: Column(
          children: [
            10.verticalSpaceFromWidth,

            // 邮箱输入框
            _buildEmailInput(),

            20.verticalSpaceFromWidth,

            // 发送按钮
            _buildSendButton(),

            12.verticalSpaceFromWidth,

            // 说明文字
            Text(
              'Your code will be backed up to this email.',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 14.sp,
                color: Get.reactiveTheme.hintColor.withOpacity(0.6),
              ),
            ),
            // 信息卡片列表
            _buildInfoCardList(),
          ],
        ),
      ),
    );
  }

  /// 邮箱输入框
  Widget _buildEmailInput() {
    return IXTextField(
      hintText: 'Enter your email',
      controller: controller.emailController,
      focusNode: controller.emailFocusNode,
      keyboardType: TextInputType.emailAddress,
      textInputAction: TextInputAction.done,
      onChanged: (value) => controller.email.value = value,
    );
  }

  /// 发送按钮
  Widget _buildSendButton() {
    return Obx(() {
      final canSend = controller.canSend;
      final isSending = controller.isSending.value;
      return SubmitButton(
        prefixIcon: IXImage(
          source: Assets.preCodeEmailTipWhite,
          width: 20.w,
          height: 20.w,
          sourceType: ImageSourceType.asset,
        ),
        enabled: canSend,
        isLoading: isSending,
        text: 'Send your Email',
        onPressed: controller.sendEmail,
      );
    });
  }

  /// 信息卡片列表（带连接线）
  Widget _buildInfoCardList() {
    return InfoCard(
      title: '',
      items: [
        InfoItem(
          icon: IconFont.icon23,
          title: 'Your Pre Credential',
          description:
              'This is your VIP credential. Please store it securely and do not share it with anyone.',
          iconColor: DarkThemeColors.primaryColor,
        ),
        InfoItem(
          imageSource: Assets.preCodeEmailTipBlue,
          title: 'Secure Email Backup',
          description:
              'We will send an email containing this credential to your specified email address for safekeeping.',
          iconColor: DarkThemeColors.primaryColor,
        ),
        InfoItem(
          icon: IconFont.icon43,
          title: 'Send and Save',
          description:
              'After the email is sent, we recommend you also save this credential to a secure location on your device.',
          iconColor: DarkThemeColors.primaryColor,
        ),
      ],
    );
  }
}
