import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/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 Function okFunction;
  final Function cancelFunction;

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

  showAlertDialog(BuildContext context) {
    // set up the buttons
    Widget cancelButton = FlatButton(
        child: Texts(this.cancelText),
        onPressed: () {
          Navigator.of(context).pop();
          cancelFunction();
        });
    Widget continueButton = FlatButton(child: Texts(okText), onPressed: okFunction);

    // set up the AlertDialog
    AlertDialog alert = AlertDialog(
      title: title != null ? Text(title) : Text(TranslationBase.of(context).confirm),
      content: Text(this.confirmMessage),
      actions: [
        cancelButton,
        continueButton,
      ],
    );

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

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

}
