import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ConfirmDialog {
  final BuildContext? context;

  final title;
  final confirmMessage;
  final okText;
  final cancelText;
  final VoidCallback okFunction;
  final Function? cancelFunction;
  final isDissmissable;

  ConfirmDialog({required this.context, this.title, required this.confirmMessage, required this.okText, required this.cancelText, required this.okFunction, required this.cancelFunction, this.isDissmissable = true});

  showAlertDialog(BuildContext context) {
    Dialog alert = Dialog(
      child: Container(
        color: Colors.transparent,
        child: Mdialog(
          context,
          title != null ? title : TranslationBase.of(context).confirm,
          confirmMessage,
          okText,
          cancelText,
          cancelFunction: cancelFunction,
          okFunction: okFunction,
        ),
      ),
    );

    // show the dialog
    showDialog(
      barrierDismissible: isDissmissable,
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

  static closeAlertDialog(BuildContext context) {
    Navigator.of(context).pop();
  }
}

class Mdialog extends StatelessWidget {
  String? title;
  String? description;
  final VoidCallback? okFunction;
  final Function? cancelFunction;
  final okText;
  final cancelText;
  BuildContext? _context;

  Mdialog(this._context, this.title, this.description, this.okText, this.cancelText, {this.okFunction, this.cancelFunction});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: containerRadius(Colors.white, 12),
      padding: EdgeInsets.all(20),
      clipBehavior: Clip.antiAlias,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            // title != null ? title : TranslationBase.of(context).confirm,
            title!,

            style: TextStyle(

              fontSize: 24,
              letterSpacing: -0.94,
              fontWeight: FontWeight.w600,
            ),
          ),
          Text(
            // this.confirmMessage,
            description!,

            style: TextStyle(
              fontSize: 12,
              letterSpacing: -0.48,
              color: CustomColors.grey,
              fontWeight: FontWeight.w600,
            ),
          ),
          mHeight(16),
          Row(
            children: [
              Expanded(
                child: InkWell(
                  onTap: () {
                    Navigator.of(_context!).pop();
                    cancelFunction!();
                  },
                  child: Container(
                    decoration: containerRadius(CustomColors.accentColor, 12),
                    padding: EdgeInsets.only(top: 8,bottom: 8),
                    child: Center(child: Texts(cancelText, textAlign: TextAlign.center, variant: "caption3", color: CustomColors.white,)),
                  ),
                ),
              ),
              mWidth(8),
              Expanded(
                child: InkWell(
                  onTap: okFunction,
                  child: Container(
                    decoration: containerRadius(CustomColors.green, 12),
                    padding: EdgeInsets.only(top: 8,bottom: 8),
                    child: Center(
                      child: Texts(
                        okText,
                        textAlign: TextAlign.center,
                        color: Colors.white,
                        variant: "caption3",
                      ),
                    ),
                  ),
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
