import 'package:cpt_auth/modules/sing_up_success/sign_up_success_view_model.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:cs_resources/generated/l10n.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:plugin_basic/provider/user_config/user_config_service.dart';
import 'package:router/ext/auto_router_extensions.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_appbar.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_view.dart';
import '../../router/page/auth_page_router.dart';
import 'estate_upload_success_view_model.dart';

@RoutePage()
class EstateUploadSuccessPage extends HookConsumerWidget {
  final String? sm;
  final String? contactNumber;
  final String? email;

  const EstateUploadSuccessPage({
    Key? key,
    @PathParam() required this.sm,
    @PathParam() required this.contactNumber,
    @PathParam() required this.email,
  }) : super(key: key);

  //登录页面进入
  static void startPop2Login({
    required String? sm,
    required String? contactNumber,
    required String? email,
  }) {
    appRouter.pushAndPopUntil(
      EstateUploadSuccessPageRoute(sm: sm, contactNumber: contactNumber, email: email),
      predicate: (route) {
        return route.settings.name == "AuthLoginPageRoute";
      },
    );
  }

  //Me页面进入
  static void startPop2Estate({
    required String? sm,
    required String? contactNumber,
    required String? email,
  }) {
    appRouter.pushAndPopUntil(
      EstateUploadSuccessPageRoute(sm: sm, contactNumber: contactNumber, email: email),
      predicate: (route) {
        return route.settings.name == "MyEstatePageRoute";
      },
    );
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final viewModel = ref.watch(estateUploadSuccessViewModelProvider.notifier);
    final userConfig = UserConfigService.getState(ref: ref);

    return Scaffold(
      appBar: MyAppBar.appBar(context, ""),
      backgroundColor: context.appColors.backgroundDefault,
      body: Container(
        padding: const EdgeInsets.symmetric(horizontal: 18),
        width: double.infinity,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SingleChildScrollView(
                scrollDirection: Axis.vertical,
                physics: const BouncingScrollPhysics(),
                child: Column(
                  children: [
                    //顶部图片
                    const MyAssetImage(
                      Assets.authYyHomeSuccess,
                      width: 264,
                      height: 180,
                    ).alignCenter().marginOnly(top: 12),

                    MyTextView(
                      S.current.thank_you_name(userConfig.userName ?? ""),
                      fontSize: 23,
                      marginTop: 30,
                      isFontMedium: true,
                      textColor: context.appColors.textBlack,
                    ),

                    RichText(
                      text: TextSpan(
                        children: [
                          // "SN: " 部分（黑色文本）
                          TextSpan(
                            text: "SN: ",
                            style: TextStyle(
                              fontSize: 15,
                              fontWeight: FontWeight.w500,
                              color: context.appColors.textBlack,
                            ),
                          ),
                          // 后面的值部分（红色文本）
                          TextSpan(
                            text: sm, // 假设 sm 是 String 类型的变量
                            style: const TextStyle(
                              fontSize: 15,
                              fontWeight: FontWeight.w500, // 保持与前面一致的字重
                              color: Colors.red, // 红色
                            ),
                          ),
                        ],
                      ),
                      textAlign: TextAlign.start,
                    ).marginOnly(top: 10),

                    MyTextView(
                      S.current.estate_upload_success_desc,
                      fontSize: 15,
                      marginTop: 15,
                      isFontMedium: true,
                      textColor: context.appColors.textBlack,
                    ),
                  ],
                )).expanded(),
            Row(
              children: [
                MyButton(
                  onPressed: () {
                    viewModel.callEmail(email);
                  },
                  text: S.current.send_email,
                  textColor: Colors.white,
                  backgroundColor: context.appColors.btnBgDefault,
                  fontWeight: FontWeight.w500,
                  type: ClickType.throttle,
                  fontSize: 16,
                  minHeight: 50,
                  radius: 5,
                ).expanded(),
                MyButton(
                  onPressed: () {
                    viewModel.callPhone(contactNumber);
                  },
                  text: S.current.call_phone,
                  textColor: Colors.white,
                  backgroundColor: context.appColors.btnBgDefault,
                  fontWeight: FontWeight.w500,
                  type: ClickType.throttle,
                  fontSize: 16,
                  minHeight: 50,
                  radius: 5,
                ).marginOnly(left: 10).expanded(),
              ],
            ).marginOnly(top: 50, bottom: 50, left: 18, right: 18),
          ],
        ),
      ),
    );
  }
}
