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/colors.gen.dart';
import 'package:location/utils/common_expand.dart';

class CommonAlertDialog {
  static const String _tag = "CommonAlertDialog";

  static void show(
      {required Widget titleWidget,
      required Widget descWidget,
      required String cancelText,
      required String confirmText,
      required VoidCallback cancelOnTap,
      required VoidCallback confirmOnTap,
      String tag = _tag}) {
    SmartDialog.show(
        tag: _tag,
        builder: (_) {
          return _CommonAlertDialog(
              titleWidget: titleWidget,
              descWidget: descWidget,
              cancelText: cancelText,
              confirmText: confirmText,
              cancelOnTap: cancelOnTap,
              confirmOnTap: confirmOnTap);
        });
  }

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

class _CommonAlertDialog extends Dialog {
  final Widget titleWidget;
  final Widget descWidget;
  final String cancelText;
  final String confirmText;
  final VoidCallback cancelOnTap;
  final VoidCallback confirmOnTap;

  const _CommonAlertDialog({
    required this.titleWidget,
    required this.descWidget,
    required this.cancelText,
    required this.confirmText,
    required this.cancelOnTap,
    required this.confirmOnTap,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 300.w,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.w),
      ),
      child: IntrinsicHeight(
        child: Column(
          children: [
            SizedBox(height: 27.w),
            titleWidget,
            SizedBox(height: 15.w),
            Container(
              margin: EdgeInsets.symmetric(horizontal: 28.w),
              child: descWidget,
            ),
            SizedBox(height: 32.w),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                GestureDetector(
                  onTap: () => cancelOnTap(),
                  child: Container(
                    width: 109.w,
                    height: 43.w,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(57.w)),
                      border: Border.all(color: ColorName.black15, width: 1.w),
                    ),
                    child: Center(
                      child: Text(cancelText,
                          style: TextStyle(
                              fontSize: 14.sp,
                              color: '#333333'.color,
                              fontWeight: FontWeight.bold)),
                    ),
                  ),
                ),
                SizedBox(width: 30.w),
                GestureDetector(
                  onTap: () => confirmOnTap(),
                  child: Container(
                    width: 109.w,
                    height: 43.w,
                    decoration: BoxDecoration(
                      color: ColorName.colorPrimary,
                      borderRadius: BorderRadius.all(Radius.circular(57.w)),
                    ),
                    child: Center(
                      child: Text(confirmText,
                          style: TextStyle(
                              fontSize: 14.sp,
                              color: Colors.white,
                              fontWeight: FontWeight.bold)),
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(height: 20.w),
          ],
        ),
      ),
    );
  }
}
