import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:keyboard/data/repository/account_repository.dart';
import 'package:keyboard/resource/string.gen.dart';

import '../data/bean/goods_info.dart';
import '../resource/assets.gen.dart';
import '../resource/colors.gen.dart';
import '../utils/date_util.dart';
import '../utils/styles.dart';
import 'package:get/get.dart';

// 支付成功
class PaymentSuccessDialog {
  static const String tag = 'PaymentSuccessDialog';

  static void show({
    required Function? btnConfirm,
    required GoodsInfo goodsInfo,
  }) {
    SmartDialog.show(
      tag: tag,
      backType: SmartBackType.block,
      clickMaskDismiss: true,
      maskColor: ColorName.black70,
      builder: (_) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: double.infinity,
              margin: EdgeInsets.symmetric(horizontal: 31.w),
              decoration: ShapeDecoration(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20.r),
                ),
              ),
              child: Stack(
                children: [
                  Container(
                    width: double.infinity,
                    padding: EdgeInsets.symmetric(
                      horizontal: 16.w,
                      vertical: 16.h,
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Assets.images.iconDialogPaySuccess.image(
                          width: 88.w,
                          height: 88.h,
                        ),
                        SizedBox(height: 8.h),
                        Text(
                          StringName.paySuccessDialogTitle,
                          style: Styles.getTextStyleBlack204W500(16.sp),
                        ),
                        Obx(() {
                          return Text(
                            AccountRepository.getInstance()
                                        .memberStatusInfo
                                        .value
                                        ?.permanent ==
                                    true
                                ? StringName.paySuccessDialogPermanent
                                : "${goodsInfo.name}${DateUtil.fromMillisecondsSinceEpoch('yyyy年MM月dd日', AccountRepository.getInstance().memberStatusInfo.value?.endTimestamp ?? 0)}${StringName.paySuccessDialogDesc}",
                            style: Styles.getTextStyleBlack153W400(14.sp),
                          );
                        }),
                        SizedBox(height: 24.h),

                        SizedBox(
                          width: double.infinity,
                          child: GestureDetector(
                            onTap: () {
                              SmartDialog.dismiss();
                              btnConfirm?.call();
                            },
                            child: Container(
                              height: 40.h,
                              decoration: Styles.getActivateButtonDecoration(
                                22.r,
                              ),
                              child: Center(
                                child: Text(
                                  StringName.paySuccessDialogConfirm,
                                  style: Styles.getTextStyleWhiteW500(16.sp),
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Positioned(
                    right: 14.w,
                    top: 14.h,
                    child: GestureDetector(
                      onTap: () {
                        SmartDialog.dismiss();
                        btnConfirm?.call();
                      },
                      child: Assets.images.iconCustomDialogClose.image(
                        width: 24.w,
                        height: 24.h,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        );
      },
    );
  }
}
