import { jsx as o, jsxs as E } from "react/jsx-runtime";
import { useEffect as G } from "react";
import { a as S } from "./index.CfQlFjZU.js";
import { S as k } from "./shared.EdGf6tcG.js";
import { a as b } from "./TextArea.slboc5OS.js";
import { a as v } from "./TextInput.63vMRxAK.js";
import { U as D } from "./Upload.X0oU32lw.js";
import { a as T } from "./Button.CpTwUWVr.js";
import { F as x, I as A } from "./FormInputIcon.D-QBOOZ2.js";
import { u as h, M as F } from "./modal.BZAvb1Nx.js";
import { u as N } from "./useId.7P31viIO.js";
const U = "creator_mediaGalleryContainer_VZWJ-", O = { mediaGalleryContainer: U }, V = ({
  onSubmit: s,
  onCancel: l,
  onMediaChange: i,
  onCaptionChange: r,
  onLinkChange: d,
  suggestedAllowedMediaTypes: p,
  mediaUploading: u,
  media: c,
  caption: f,
  link: M,
  helpers: y,
  errors: R,
  disabled: t,
  visible: e = !0,
  linkTypeFixed: n
}) => {
  const I = N(), { Modal: C, openModal: m, closeModal: a } = h();
  return G(() => {
    e ? m() : a();
  }, [e, m, a]), {
    onSubmit: (g) => {
      g.preventDefault(), s(g);
    },
    onCancel: l,
    onMediaChange: i,
    onMediaRemove: () => {
      i(null);
    },
    onCaptionChange: r,
    onLinkChange: d,
    media: c,
    caption: f || "",
    link: M || "",
    suggestedAllowedMediaTypes: p,
    mediaUploading: u,
    disabled: t,
    helpers: y,
    errors: R,
    formId: I,
    containerClassName: O.mediaGalleryContainer,
    Modal: C,
    linkTypeFixed: n
  };
}, j = ({
  onSubmit: s,
  onCancel: l,
  onMediaChange: i,
  onMediaRemove: r,
  onCaptionChange: d,
  onLinkChange: p,
  media: u,
  caption: c,
  link: f,
  suggestedAllowedMediaTypes: M,
  mediaUploading: y,
  disabled: R,
  helpers: t,
  errors: e,
  formId: n,
  containerClassName: I,
  Modal: C,
  linkTypeFixed: m
}) => /* @__PURE__ */ o(
  C,
  {
    type: F.ADVANCED,
    heading: "Add to Media Gallery",
    buttons: [
      {
        label: "Done",
        semantic: k.PRIMARY,
        type: T.SUBMIT,
        form: n,
        disabled: R
      },
      {
        label: "Cancel",
        semantic: k.SECONDARY,
        onClick: () => l()
      }
    ],
    onDismiss: () => l(),
    children: /* @__PURE__ */ E("form", { id: n, className: I, onSubmit: s, children: [
      /* @__PURE__ */ o(
        D,
        {
          label: "Upload media",
          helper: e?.media || t?.media,
          error: !!e?.media,
          suggestedAllowedTypes: M,
          onFileSelect: (a) => i(a),
          onFileRemove: () => r(),
          file: u,
          uploading: y
        }
      ),
      /* @__PURE__ */ o(
        b,
        {
          label: "Caption",
          helper: e?.caption || t?.caption,
          isError: !!e?.caption,
          suffixIcon: e?.caption ? /* @__PURE__ */ o(x, { status: A.ERROR }) : void 0,
          value: c,
          onChange: (a) => d(a.target.value)
        }
      ),
      /* @__PURE__ */ o(
        v,
        {
          type: m ? "url" : void 0,
          label: "Link",
          helper: e?.link || t?.link,
          isError: !!e?.link,
          suffixIcon: e?.link ? /* @__PURE__ */ o(x, { status: A.ERROR }) : void 0,
          value: f,
          onChange: (a) => p(a.target.value)
        }
      )
    ] })
  }
), H = S(
  j,
  V
);
export {
  H as M
};
