import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:location/resource/assets.gen.dart';
import 'package:location/resource/string.gen.dart';

class MemberRetainDialog {
  static final String _tag = 'MemberRetainDialog';

  static void show(
      {required VoidCallback payClick, required VoidCallback cancelClick}) {
    SmartDialog.show(
        tag: _tag,
        backDismiss: false,
        keepSingle: true,
        clickMaskDismiss: false,
        builder: (_) {
          return _MemberRetainDialogWidget(
              payClick: payClick,
              cancelClick: cancelClick);
        });
  }

  static void dismiss() {
    SmartDialog.dismiss(tag: _tag);
  }
}

class _MemberRetainDialogWidget extends Dialog {
  final VoidCallback payClick;
  final VoidCallback cancelClick;

  const _MemberRetainDialogWidget(
      {required this.payClick, required this.cancelClick});

  @override
  Widget build(BuildContext context) {
    return IntrinsicHeight(
      child: Column(
        children: [
          Stack(
            children: [
              Positioned(
                top: 0,
                left: 10.w,
                child: SizedBox(
                  width: 300.w,
                  child: AspectRatio(
                      aspectRatio: 987 / 543,
                      child: Assets.images.imgMemberRetainHeader.image()),
                ),
              ),
              Column(
                children: [
                  SizedBox(height: 110.w),
                  SizedBox(
                    width: 294.w,
                    child: AspectRatio(
                        aspectRatio: 882 / 966,
                        child: Assets.images.imgMemberRetainContainer.image()),
                  )
                ],
              ),
              Positioned(
                bottom: 22.w,
                left: 36.w,
                right: 36.w,
                child: GestureDetector(
                  onTap: () {
                    MemberRetainDialog.dismiss();
                    payClick();
                  },
                  child: Container(
                    height: 40.w,
                    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),
                    ),
                    //getPrimaryBtnDecoration(100.w),
                    child: Center(
                      child: Text(
                          Platform.isAndroid
                              ? StringName.memberContinuePay
                              : StringName.memberContinuePayIos,
                          style:
                              TextStyle(fontSize: 15.sp, color: Colors.white)),
                    ),
                  ),
                ),
              )
            ],
          ),
          SizedBox(
            height: 24.w,
          ),
          Center(
            child: GestureDetector(
              onTap: () {
                MemberRetainDialog.dismiss();
                cancelClick();
              },
              child: Assets.images.iconMemberRetainClose
                  .image(width: 32.w, height: 32.w),
            ),
          )
        ],
      ),
    );
  }
}
