import { ExclamationErrorCircleFill16RedIcon, XmarkCloseBold24TertiaryIcon, XmarkCloseBold24SecondaryIcon } from '@cloudtower/icons-react';
import { cx } from '@linaria/core';
import Button from '../Button/index.js';
import Icon from '../Icon/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 cs from 'classnames';
import React__default, { useMemo } from 'react';
import { ModelTitleSkeleton, ModelContentSkeleton, ModelInitializingError } from '../SmallDialog/SmallDialog.widget.js';
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,
    leftClassName,
    rightClassName,
    closeIcon,
    footer,
    showCancel = true,
    showOk = true,
    confirmLoading,
    okButtonProps,
    cancelButtonProps,
    okText,
    cancelText,
    error,
    hideFooter = false,
    showFooterErrorIcon = true,
    visible = true,
    isContentFull,
    onCancel,
    onOk,
    initializing,
    initializingError
  } = _a, restProps = __objRest(_a, [
    "className",
    "title",
    "children",
    "footerLeftAction",
    "left",
    "right",
    "leftClassName",
    "rightClassName",
    "closeIcon",
    "footer",
    "showCancel",
    "showOk",
    "confirmLoading",
    "okButtonProps",
    "cancelButtonProps",
    "okText",
    "cancelText",
    "error",
    "hideFooter",
    "showFooterErrorIcon",
    "visible",
    "isContentFull",
    "onCancel",
    "onOk",
    "initializing",
    "initializingError"
  ]);
  const { t } = useParrotTranslation();
  const popModal = usePopModal();
  const defaultTitle = initializingError ? t("common.load_failed") : "";
  const defaultCancelText = showOk ? t("common.cancel") : t("common.close");
  const defaultOkText = initializingError ? t("common.retry") : t("common.confirm");
  const _cancelText = useMemo(() => {
    let text = cancelText || defaultCancelText;
    return text;
  }, [cancelText, defaultCancelText]);
  const _confirmText = useMemo(() => {
    let text = okText || defaultOkText;
    return text;
  }, [okText, defaultOkText]);
  const finalFooter = useMemo(() => {
    if (initializing) {
      return null;
    }
    if (hideFooter)
      return /* @__PURE__ */ React__default.createElement("div", null);
    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) }, showFooterErrorIcon && /* @__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({
        size: "large",
        type: "quiet",
        className: CancelButtonStyle,
        onMouseDown: (e) => {
          e.preventDefault();
        },
        onClick: (e) => {
          popModal();
          onCancel == null ? void 0 : onCancel(e);
        }
      }, cancelButtonProps),
      /* @__PURE__ */ React__default.createElement("span", { className: Typo.Label.l1_bold_title }, _cancelText)
    ) : null, showOk ? /* @__PURE__ */ React__default.createElement(
      Button,
      __spreadValues({
        size: "large",
        onClick: (e) => {
          onOk == null ? void 0 : onOk(e);
        },
        type: "primary",
        loading: confirmLoading
      }, okButtonProps),
      _confirmText
    ) : null));
  }, [
    initializing,
    hideFooter,
    footer,
    footerLeftAction,
    error,
    showFooterErrorIcon,
    showCancel,
    cancelButtonProps,
    _cancelText,
    showOk,
    confirmLoading,
    okButtonProps,
    _confirmText,
    popModal,
    onCancel,
    onOk
  ]);
  return /* @__PURE__ */ React__default.createElement(
    Modal,
    __spreadValues({
      width: "calc(100% - 20px)",
      title: initializing ? /* @__PURE__ */ React__default.createElement(ModelTitleSkeleton, null) : /* @__PURE__ */ React__default.createElement("span", { className: cx(Typo.Display.d1_bold_title, TitleStyle) }, title || defaultTitle),
      className: cs(
        ImmersiveDialogStyle,
        isContentFull ? FullContentStyle : MultiAreaStyle,
        className,
        {
          "initializing-error": initializingError,
          "no-footer": hideFooter
        }
      ),
      closeIcon: closeIcon != null ? closeIcon : /* @__PURE__ */ React__default.createElement(
        Icon,
        {
          src: XmarkCloseBold24TertiaryIcon,
          className: CloseIconStyle,
          iconHeight: 24,
          iconWidth: 24,
          hoverSrc: XmarkCloseBold24SecondaryIcon
        }
      ),
      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) }, initializing || initializingError ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("div", { className: "middle" }, initializing ? /* @__PURE__ */ React__default.createElement(ModelContentSkeleton, { num: 4 }) : /* @__PURE__ */ React__default.createElement(ModelInitializingError, { error: initializingError }))) : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, isContentFull ? null : /* @__PURE__ */ React__default.createElement("div", { className: cx("left", leftClassName) }, left), /* @__PURE__ */ React__default.createElement("div", { className: "middle" }, children), isContentFull ? null : /* @__PURE__ */ React__default.createElement("div", { className: cx("right", rightClassName) }, right)))
  );
}

export { ImmersiveDialog };
