'use strict';

var core = require('@linaria/core');
var SmallDialog = require('../../../core/SmallDialog/SmallDialog.js');
var index = require('../../../core/Typo/index.js');
var useParrotTranslation = require('../../../hooks/useParrotTranslation.js');
var React = require('react');
var RejectDialog_type = require('./RejectDialog.type.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;
};
const ContentList = "E_4100_0_7_c1ss4prm";
const MultiRejectContentList = "E_4100_0_7_ms3tlei";
const Description = "E_4100_0_7_du44iy7";
const PartialDescription = "E_4100_0_7_p1qmhanr";
const SecondaryDesc = "E_4100_0_7_srje1h0";
const Divider = "E_4100_0_7_di3zi7v";
const SingleRejectContent = ({
  content,
  listType = "ordered",
  resourceIcon
}) => {
  if (listType === "resource" && Array.isArray(content)) {
    return /* @__PURE__ */React__default.default.createElement("div", {
      className: core.cx(MultiRejectContentList)
    }, content.map((name, index$1) => /* @__PURE__ */React__default.default.createElement("li", {
      className: index.Typo.Label.l4_regular,
      key: index$1
    }, resourceIcon, /* @__PURE__ */React__default.default.createElement("span", null, name))));
  }
  if (Array.isArray(content) && content.length > 1) {
    if (listType === "ordered") {
      return /* @__PURE__ */React__default.default.createElement("ol", {
        className: core.cx(ContentList)
      }, content.map((reason, index$1) => /* @__PURE__ */React__default.default.createElement("li", {
        className: index.Typo.Label.l4_regular,
        key: index$1
      }, reason)));
    }
    return /* @__PURE__ */React__default.default.createElement("ul", {
      className: core.cx(ContentList)
    }, content.map((reason, index$1) => /* @__PURE__ */React__default.default.createElement("li", {
      className: index.Typo.Label.l4_regular,
      key: index$1
    }, reason)));
  }
  return /* @__PURE__ */React__default.default.createElement("div", {
    className: core.cx(ContentList, index.Typo.Label.l4_regular)
  }, content);
};
const MultiRejectContent = ({
  content,
  resourceIcon
}) => {
  const {
    t
  } = useParrotTranslation();
  return /* @__PURE__ */React__default.default.createElement("div", {
    className: core.cx(MultiRejectContentList)
  }, Object.entries(content).map(([name, reasons], index$1) => /* @__PURE__ */React__default.default.createElement("li", {
    className: index.Typo.Label.l4_regular,
    key: index$1
  }, resourceIcon, /* @__PURE__ */React__default.default.createElement("span", null, name + t("common.colon_with_space") + reasons.join(t("common.semicolon_with_space"))))));
};
const RejectDialog = props => {
  const {
    title,
    cancelText,
    beforeDescription,
    description,
    className,
    footerClassName,
    okButtonProps
  } = props;
  const renderContent = () => {
    switch (props.type) {
      case RejectDialog_type.RejectDialogType.Single:
        return /* @__PURE__ */React__default.default.createElement(React__default.default.Fragment, null, props.secondaryDesc && /* @__PURE__ */React__default.default.createElement("div", {
          className: core.cx(SecondaryDesc, index.Typo.Label.l4_regular)
        }, props.secondaryDesc), /* @__PURE__ */React__default.default.createElement(SingleRejectContent, {
          content: props.content,
          listType: props.listType,
          resourceIcon: props.resourceIcon
        }));
      case RejectDialog_type.RejectDialogType.All:
      case RejectDialog_type.RejectDialogType.Part:
        return /* @__PURE__ */React__default.default.createElement(React__default.default.Fragment, null, props.secondaryDesc && /* @__PURE__ */React__default.default.createElement("div", {
          className: core.cx(SecondaryDesc, index.Typo.Label.l4_regular)
        }, props.secondaryDesc), props.type === RejectDialog_type.RejectDialogType.Part && /* @__PURE__ */React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */React__default.default.createElement("div", {
          className: Divider
        }), /* @__PURE__ */React__default.default.createElement("div", {
          className: core.cx(PartialDescription, index.Typo.Label.l3_regular)
        }, props.partialDescription)), /* @__PURE__ */React__default.default.createElement(MultiRejectContent, {
          content: props.content,
          resourceIcon: props.resourceIcon
        }));
      case RejectDialog_type.RejectDialogType.Custom:
        return props.customContent;
    }
  };
  return /* @__PURE__ */React__default.default.createElement(SmallDialog.SmallDialog, {
    title,
    cancelText,
    showOk: props.type === RejectDialog_type.RejectDialogType.Part,
    okText: props.type === RejectDialog_type.RejectDialogType.Part ? props.okText : void 0,
    onOk: props.type === RejectDialog_type.RejectDialogType.Part ? props.onOk : void 0,
    okButtonProps: __spreadValues({
      danger: props.type === RejectDialog_type.RejectDialogType.Part
    }, okButtonProps),
    onCancel: props.onCancel,
    className,
    footerClassName
  }, beforeDescription, description && /* @__PURE__ */React__default.default.createElement("div", {
    className: core.cx(Description, index.Typo.Label.l3_regular)
  }, description), renderContent());
};

exports.RejectDialog = RejectDialog;
