import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:location/utils/common_expand.dart';

import '../../resource/assets.gen.dart';
import '../../resource/colors.gen.dart';

class MemberFirstWeekDiscountDialog {
  static void show({
    VoidCallback? confirmOnTap,
    VoidCallback? onPrivacyPolicyClick,
    VoidCallback? onTermOfServiceClick,
  }) {
    Get.dialog(
        SimpleDialog(
          titlePadding: EdgeInsets.zero,
          contentPadding: EdgeInsets.zero,
          insetPadding: EdgeInsets.zero,
          backgroundColor:Colors.transparent,
          children: [
            MemberFirstWeekDiscountDialogTipView(
                onPrivacyPolicyClick: onPrivacyPolicyClick,
                onTermOfServiceClick: onTermOfServiceClick,
                confirmOnTap: confirmOnTap)
          ],
        )
    );
  }
}


class MemberFirstWeekDiscountDialogTipView extends StatefulWidget {
  final VoidCallback? onPrivacyPolicyClick;
  final VoidCallback? onTermOfServiceClick;
  final VoidCallback? confirmOnTap;


  const MemberFirstWeekDiscountDialogTipView({
    super.key,
    this.onPrivacyPolicyClick,
    this.onTermOfServiceClick,
    required this.confirmOnTap,
  });

  @override
  State<MemberFirstWeekDiscountDialogTipView> createState() => _MemberPaymentCompletedTipViewState();
}

class _MemberPaymentCompletedTipViewState extends State<MemberFirstWeekDiscountDialogTipView> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: 1.sw,
      margin: EdgeInsets.only(left: 25.w ,right: 13.w),
      child: IntrinsicHeight(
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.only(right: 12.w,),
              decoration: BoxDecoration(
                  color: Colors.transparent,
                  image: DecorationImage(
                    image: Assets.images.imgMemberFirstWeekDiscountContainer.provider(),
                    //fit: BoxFit.fill,
                  )
              ),
              child: Column(
                children: [
                  SizedBox(
                    height: 337.w,
                  ),
                  GestureDetector(
                    onTap: () {
                      Get.back();
                      widget.confirmOnTap!();
                    },
                    child: Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.centerLeft, // 90度相当于从左到右
                          end: Alignment.centerRight,
                          colors: [
                            Color(0xFF7B7DFF), // #7B7DFF
                            Color(0xFF6365FF), // #6365FF
                          ],
                          stops: [0.0, 1.0],
                          // 从0%到100%
                        ),
                        borderRadius: BorderRadius.circular(40.w / 2.0),
                      ),
                      margin: EdgeInsets.symmetric(horizontal: 25.w),
                      height: 40.w,
                      alignment: Alignment.center,
                      child: Text("¥48 立即开通",
                          style: TextStyle(
                              fontSize: 14.sp,
                              color: '#FFFFFF'.color,
                              fontWeight: FontWeight.w500)
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 12.w,
                  ),
                  buildPrivacyPolicyView(),
                  SizedBox(
                    height: 19.w,
                  ),
                ],
              ),
            ),
            SizedBox(height: 20.w,),
            Center(
              child: GestureDetector(
                onTap: () {
                  Get.back();
                },
                child: Assets.images.iconMemberRetainClose
                    .image(width: 32.w, height: 32.w),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildPrivacyPolicyView() {
    return Padding(
      padding: EdgeInsets.only(left: 12.w),
      child: RichText(
          text: TextSpan(
              style: TextStyle(fontSize: 12.sp, color: ColorName.black40),
              children: [
                TextSpan(text: '购买前请先阅读'),
                TextSpan(
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        widget.onPrivacyPolicyClick!();
                      },
                    text: '隐私政策',
                    style: TextStyle(
                        color: ColorName.black60,
                        decoration: TextDecoration.underline)),
                TextSpan(text: '&'),
                TextSpan(
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        widget.onTermOfServiceClick!();
                      },
                    text: '服务条款',
                    style: TextStyle(
                        color: ColorName.black60,
                        decoration: TextDecoration.underline)),
              ])),
    );
  }
}