'use strict';

var iconsReact = require('@cloudtower/icons-react');
var core = require('@linaria/core');
var index$3 = require('../Button/index.js');
var index = require('../KitStoreProvider/index.js');
var index$1 = require('../Typo/index.js');
var index$2 = require('../../coreX/OverflowTooltip/index.js');
var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var antd = require('antd');
var React = require('react');
var styles = require('./styles.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function ImmersiveDialog(props) {
  const _a = props, {
    className,
    title,
    children,
    footerLeftAction,
    left,
    right,
    closeIcon,
    footer,
    showCancel = true,
    showOk = true,
    okLoading,
    okButtonProps,
    cancelButtonProps,
    okText,
    cancelText,
    error,
    visible = true,
    isContentFull,
    onCancel,
    onOk
  } = _a, restProps = __objRest(_a, [
    "className",
    "title",
    "children",
    "footerLeftAction",
    "left",
    "right",
    "closeIcon",
    "footer",
    "showCancel",
    "showOk",
    "okLoading",
    "okButtonProps",
    "cancelButtonProps",
    "okText",
    "cancelText",
    "error",
    "visible",
    "isContentFull",
    "onCancel",
    "onOk"
  ]);
  const { t } = useParrotTranslation();
  const popModal = index.usePopModal();
  const _confirmText = React.useMemo(() => {
    let text = okText || t("common.confirm");
    return text;
  }, [okText, t]);
  const finalFooter = React.useMemo(() => {
    return footer || /* @__PURE__ */ React__default.default.createElement("div", { className: styles.FooterStyle }, /* @__PURE__ */ React__default.default.createElement("div", { className: styles.FooterButtonStyle }, footerLeftAction, error && /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx(styles.ErrorStyle, index$1.Typo.Label.l2_regular) }, /* @__PURE__ */ React__default.default.createElement(
      iconsReact.ExclamationErrorCircleFill16RedIcon,
      {
        className: styles.ErrorIconStyle
      }
    ), /* @__PURE__ */ React__default.default.createElement(
      index$2,
      {
        className: styles.ErrorTextStyle,
        multiLines: 3,
        content: error,
        tooltip: error
      }
    )))), /* @__PURE__ */ React__default.default.createElement("div", { className: styles.FooterButtonRightStyle }, showCancel ? /* @__PURE__ */ React__default.default.createElement(
      index$3,
      __spreadValues({
        type: "quiet",
        className: styles.CancelButtonStyle,
        onMouseDown: (e) => {
          e.preventDefault();
        },
        onClick: (e) => {
          popModal();
          onCancel == null ? void 0 : onCancel(e);
        }
      }, cancelButtonProps),
      cancelText || t("common.cancel")
    ) : null, showOk ? /* @__PURE__ */ React__default.default.createElement(
      index$3,
      __spreadValues({
        onClick: (e) => {
          onOk == null ? void 0 : onOk(e);
        },
        type: "primary",
        loading: okLoading
      }, okButtonProps),
      _confirmText
    ) : null));
  }, [
    footerLeftAction,
    _confirmText,
    cancelButtonProps,
    cancelText,
    error,
    footer,
    okButtonProps,
    okLoading,
    onCancel,
    onOk,
    popModal,
    showCancel,
    showOk,
    t
  ]);
  return /* @__PURE__ */ React__default.default.createElement(
    antd.Modal,
    __spreadValues({
      width: "calc(100% - 20px)",
      title: /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx(index$1.Typo.Display.d1_bold_title, styles.TitleStyle) }, title),
      className: core.cx(
        styles.ImmersiveDialogStyle,
        isContentFull ? styles.FullContentStyle : styles.MultiAreaStyle,
        className
      ),
      closeIcon: closeIcon != null ? closeIcon : /* @__PURE__ */ React__default.default.createElement("span", { className: styles.CloseIconStyle }, /* @__PURE__ */ React__default.default.createElement(iconsReact.XmarkClose24BoldSecondaryIcon, null)),
      footer: finalFooter,
      onCancel: (e) => {
        popModal();
        onCancel == null ? void 0 : onCancel(e);
      },
      visible,
      destroyOnClose: true
    }, restProps),
    /* @__PURE__ */ React__default.default.createElement("div", { className: core.cx(styles.BodyStyle, isContentFull ? "" : styles.MultiAreaBodyStyle) }, isContentFull ? null : /* @__PURE__ */ React__default.default.createElement("div", { className: "left" }, left), /* @__PURE__ */ React__default.default.createElement("div", { className: "middle" }, children), isContentFull ? null : /* @__PURE__ */ React__default.default.createElement("div", { className: "right" }, right))
  );
}

exports.ImmersiveDialog = ImmersiveDialog;
