import { ExclamationErrorCircleFill16RedIcon, XmarkClose24BoldSecondaryIcon } from '@cloudtower/icons-react';
import { cx } from '@linaria/core';
import Button from '../Button/index.js';
import { usePopModal } from '../KitStoreProvider/index.js';
import { Typo } from '../Typo/index.js';
import OverflowTooltip from '../../coreX/OverflowTooltip/index.js';
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import { Modal } from 'antd';
import React__default, { useMemo } from 'react';
import { FooterStyle, FooterButtonStyle, ErrorStyle, ErrorIconStyle, ErrorTextStyle, FooterButtonRightStyle, TitleStyle, ImmersiveDialogStyle, FullContentStyle, MultiAreaStyle, CloseIconStyle, BodyStyle, MultiAreaBodyStyle, CancelButtonStyle } from './styles.js';

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 = usePopModal();
  const _confirmText = useMemo(() => {
    let text = okText || t("common.confirm");
    return text;
  }, [okText, t]);
  const finalFooter = useMemo(() => {
    return footer || /* @__PURE__ */ React__default.createElement("div", { className: FooterStyle }, /* @__PURE__ */ React__default.createElement("div", { className: FooterButtonStyle }, footerLeftAction, error && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("span", { className: cx(ErrorStyle, Typo.Label.l2_regular) }, /* @__PURE__ */ React__default.createElement(
      ExclamationErrorCircleFill16RedIcon,
      {
        className: ErrorIconStyle
      }
    ), /* @__PURE__ */ React__default.createElement(
      OverflowTooltip,
      {
        className: ErrorTextStyle,
        multiLines: 3,
        content: error,
        tooltip: error
      }
    )))), /* @__PURE__ */ React__default.createElement("div", { className: FooterButtonRightStyle }, showCancel ? /* @__PURE__ */ React__default.createElement(
      Button,
      __spreadValues({
        type: "quiet",
        className: CancelButtonStyle,
        onMouseDown: (e) => {
          e.preventDefault();
        },
        onClick: (e) => {
          popModal();
          onCancel == null ? void 0 : onCancel(e);
        }
      }, cancelButtonProps),
      cancelText || t("common.cancel")
    ) : null, showOk ? /* @__PURE__ */ React__default.createElement(
      Button,
      __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.createElement(
    Modal,
    __spreadValues({
      width: "calc(100% - 20px)",
      title: /* @__PURE__ */ React__default.createElement("span", { className: cx(Typo.Display.d1_bold_title, TitleStyle) }, title),
      className: cx(
        ImmersiveDialogStyle,
        isContentFull ? FullContentStyle : MultiAreaStyle,
        className
      ),
      closeIcon: closeIcon != null ? closeIcon : /* @__PURE__ */ React__default.createElement("span", { className: CloseIconStyle }, /* @__PURE__ */ React__default.createElement(XmarkClose24BoldSecondaryIcon, null)),
      footer: finalFooter,
      onCancel: (e) => {
        popModal();
        onCancel == null ? void 0 : onCancel(e);
      },
      visible,
      destroyOnClose: true
    }, restProps),
    /* @__PURE__ */ React__default.createElement("div", { className: cx(BodyStyle, isContentFull ? "" : MultiAreaBodyStyle) }, isContentFull ? null : /* @__PURE__ */ React__default.createElement("div", { className: "left" }, left), /* @__PURE__ */ React__default.createElement("div", { className: "middle" }, children), isContentFull ? null : /* @__PURE__ */ React__default.createElement("div", { className: "right" }, right))
  );
}

export { ImmersiveDialog };
