import { jsx as o } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import I from "classnames";
import { useResponsiveContainer as A, containerQueries as E } from "../../../../../hooks/useResponsiveContainer.js";
import _ from "../../../../internal/Typography/Typography.js";
import { TypographyElement as g, TypographyVariant as h } from "../../../../internal/Typography/types.js";
import { FileInput as F } from "../../../../internal/FormFields/FileInput/FileInput.js";
import { useDisputeFlow as L } from "../../context/dispute/context.js";
import { getDefenseDocumentContent as B } from "../../utils/index.js";
import { useMemo as M, useCallback as v, useEffect as N } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import O from "../../../../internal/Button/Button.js";
import { ButtonVariant as P } from "../../../../internal/Button/types.js";
import { ALLOWED_FILE_TYPES as R, DOCUMENT_MAX_SIZE as Y } from "./constants.js";
import V from "../../../../../core/Context/preact/useCoreContext.js";
import { Icon as k } from "../../../../internal/Icon/Icon.js";
import U from "../../../../internal/FormFields/Select/Select.js";
const a = "adyen-pe-defend-dispute-document-upload-box", n = {
  deleteButton: a + "__delete-button-container",
  dropdownList: a + "__dropdown-list",
  dropdownListMobile: a + "__dropdown-list--mobile",
  extraDocuments: a + "__extra-documents-selector",
  extraDocumentsTitle: a + "__extra-documents-selector-title"
}, re = ({
  items: m,
  selection: t,
  setSelection: p,
  disabled: i,
  required: C,
  title: S,
  index: l,
  onRemoveOption: c,
  mapError: T
}) => {
  const { i18n: r } = V(), { addFileToDefendPayload: b, moveFieldInDefendPayload: u, removeFieldFromDefendPayload: f, defenseDocumentConfig: D } = L(), y = M(() => r.get("disputes.management.defend.common.inputs.documentSelect.a11y.label"), [r]), w = A(E.down.xs), x = v(
    (e) => B(D, r, e),
    [D, r]
  ), d = v(
    (e) => {
      t && u(t, e), p(e, l);
    },
    [l, u, t, p]
  );
  return N(() => {
    const e = m.filter(({ disabled: s }) => s !== !0);
    e.length === 1 && !t && d(e[0].id);
  }, [m, t, d]), /* @__PURE__ */ o("div", { className: n.extraDocuments, children: [
    /* @__PURE__ */ o("div", { className: n.deleteButton, children: [
      /* @__PURE__ */ o(_, { strongest: !0, className: n.extraDocumentsTitle, variant: h.BODY, el: g.DIV, children: S }),
      c && /* @__PURE__ */ o(
        O,
        {
          disabled: i,
          "aria-label": r.get("disputes.management.defend.common.actions.deleteOptionalDocument"),
          onClick: () => l !== void 0 && !i && c(l),
          variant: P.TERTIARY,
          fullWidth: !1,
          align: "center",
          children: /* @__PURE__ */ o(k, { name: "trash-can" })
        }
      )
    ] }),
    /* @__PURE__ */ o("div", { children: [
      /* @__PURE__ */ o(
        U,
        {
          onChange: (e) => {
            const s = e.target.value;
            d(s);
          },
          items: m,
          filterable: !1,
          multiSelect: !1,
          showOverlay: !1,
          selected: t,
          readonly: i,
          "aria-label": y,
          placeholder: y,
          popoverClassNameModifiers: [I(n.dropdownList, { [n.dropdownListMobile]: w })]
        }
      ),
      t && x(t)?.primaryDescriptionItems?.map((e) => /* @__PURE__ */ o(
        _,
        {
          className: "adyen-pe-defend-dispute-document-upload__description",
          variant: h.BODY,
          el: g.PARAGRAPH,
          children: e
        },
        e
      ))
    ] }),
    /* @__PURE__ */ o(
      F,
      {
        maxFileSize: (e) => Y[e],
        allowedFileTypes: R,
        mapError: T,
        onDelete: () => {
          t && f(t);
        },
        disabled: i || !t,
        required: C,
        onChange: (e) => {
          t && (e[0] ? b(t, e[0]) : f(t));
        }
      }
    )
  ] });
};
export {
  re as default
};
