'use strict';

var React = require('react');
var Modal = require('@bigbinary/neetoui/Modal');
var Typography = require('@bigbinary/neetoui/Typography');
var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
var Form = require('@bigbinary/neetoui/formik/Form');
var Input = require('@bigbinary/neetoui/formik/Input');
var ramda = require('ramda');
var reactI18next = require('react-i18next');
var yup = require('yup');
var jsxRuntime = require('react/jsx-runtime');

function _interopNamespaceDefault(e) {
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);

var INITIAL_VALUES = {
  confirmationText: ""
};

var deletionValidationSchema = function deletionValidationSchema(confirmationText) {
  return yup__namespace.object({
    confirmationText: yup__namespace.string().required("").oneOf([confirmationText], "")
  });
};

var ConfirmationModal = function ConfirmationModal(_ref) {
  var buttonLabel = _ref.buttonLabel,
    confirmationText = _ref.confirmationText,
    _ref$description = _ref.description,
    description = _ref$description === void 0 ? "" : _ref$description,
    _ref$isOpen = _ref.isOpen,
    isOpen = _ref$isOpen === void 0 ? true : _ref$isOpen,
    _ref$isSubmitting = _ref.isSubmitting,
    isSubmitting = _ref$isSubmitting === void 0 ? false : _ref$isSubmitting,
    _ref$title = _ref.title,
    title = _ref$title === void 0 ? "" : _ref$title,
    onClose = _ref.onClose,
    onSubmit = _ref.onSubmit,
    deleteConfirmationMessage = _ref.deleteConfirmationMessage;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var formikProps = {
    initialValues: INITIAL_VALUES,
    validationSchema: deletionValidationSchema(confirmationText),
    onSubmit: onSubmit
  };
  var deleteInputLabel = deleteConfirmationMessage || /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
    components: {
      strong: /*#__PURE__*/jsxRuntime.jsx("strong", {})
    },
    i18nKey: "neetoMolecules.confirmationModal.deleteConfirmationMessage",
    values: {
      value: confirmationText
    }
  });
  var initialFocusRef = React.useRef(null);
  return /*#__PURE__*/jsxRuntime.jsxs(Modal, {
    initialFocusRef: initialFocusRef,
    isOpen: isOpen,
    onClose: onClose,
    "data-testid": "confirmation-modal",
    children: [/*#__PURE__*/jsxRuntime.jsx(Modal.Header, {
      children: /*#__PURE__*/jsxRuntime.jsx(Typography, {
        "data-cy": "confirmation-modal",
        style: "h2",
        children: title
      })
    }), /*#__PURE__*/jsxRuntime.jsx(Form, {
      formikProps: formikProps,
      children: function children(_ref2) {
        var values = _ref2.values;
        return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [/*#__PURE__*/jsxRuntime.jsxs(Modal.Body, {
            className: "flex flex-col gap-y-4",
            children: [ramda.type(description) === "String" ? /*#__PURE__*/jsxRuntime.jsx(Typography, {
              style: "body2",
              children: description
            }) : description, /*#__PURE__*/jsxRuntime.jsx(Input, {
              "data-testid": "confirmation-modal-input",
              label: deleteInputLabel,
              labelProps: {
                className: "block"
              },
              name: "confirmationText",
              ref: initialFocusRef,
              type: "text"
            })]
          }), /*#__PURE__*/jsxRuntime.jsx(Modal.Footer, {
            children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
              className: "flex items-center gap-x-2",
              cancelButtonProps: {
                label: t("neetoMolecules.common.actions.cancel"),
                style: "text",
                onClick: onClose,
                disabled: false,
                type: "button"
              },
              submitButtonProps: {
                "data-cy": "delete-continue-button",
                label: buttonLabel,
                loading: isSubmitting,
                style: "danger",
                disabled: isSubmitting || confirmationText !== values.confirmationText
              }
            })
          })]
        });
      }
    })]
  });
};

module.exports = ConfirmationModal;
//# sourceMappingURL=ConfirmationModal.js.map
