"use client";
import { j as t } from "../../../node_modules/.pnpm/react@19.1.0/node_modules/react/jsx-runtime.mjs";
import { useRef as j, useState as r } from "react";
import { ActionIcon as x, Image as I, Center as f } from "@mantine/core";
import b from "../ImageInput/index.mjs";
import n from "./GalleryInput.module.scss.mjs";
import v from "../../../node_modules/.pnpm/@tabler_icons-react@3.34.0_react@19.1.0/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.mjs";
import C from "../../../node_modules/.pnpm/@tabler_icons-react@3.34.0_react@19.1.0/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.mjs";
function L(a) {
  const i = j(null), [o, d] = r(a.value ?? []), [l, c] = r(0), m = (e) => {
    d(e), a.onChange(e);
  }, u = (e) => {
    if (e === void 0)
      throw "Updating undefined file!";
    const s = [...o];
    l >= o.length ? s.push(e) : s[l] = e, m(s);
  }, p = () => {
    var e;
    console.log({ files: o }), c(o.length), (e = i.current) == null || e.call(i);
  }, h = (e) => {
    const s = o.filter((N, g) => g !== e);
    m(s), c(Math.max(0, e - 1));
  };
  return /* @__PURE__ */ t.jsxs("div", { className: n.container, children: [
    /* @__PURE__ */ t.jsx(
      b,
      {
        value: o[l],
        onImageDropped: (e) => u(e),
        openRef: i,
        disabled: a.disabled,
        classNames: { root: n.imageInputRoot },
        imageComponent: a.imageComponent,
        ...a.imageInputProps
      }
    ),
    /* @__PURE__ */ t.jsxs("div", { className: n.actionButtonContainer, children: [
      o.map((e, s) => /* @__PURE__ */ t.jsxs("div", { className: n.thumbnailPreviewContainer, children: [
        /* @__PURE__ */ t.jsx(x, { className: n.remove, onClick: () => h(s), children: /* @__PURE__ */ t.jsx(v, { className: n.trashIcon }) }),
        /* @__PURE__ */ t.jsx(
          "button",
          {
            className: n.preview,
            onClick: () => c(s),
            type: "button",
            children: /* @__PURE__ */ t.jsx(
              I,
              {
                className: n.addedImageThumbnail,
                src: typeof e == "string" ? e : URL.createObjectURL(e),
                alt: "",
                component: a.imageComponent
              }
            )
          }
        )
      ] }, s)),
      /* @__PURE__ */ t.jsx(
        "button",
        {
          className: n.preview,
          onClick: p,
          disabled: a.disabled,
          type: "button",
          children: /* @__PURE__ */ t.jsx(f, { children: /* @__PURE__ */ t.jsx(C, { className: n.plusIcon }) })
        }
      )
    ] })
  ] });
}
export {
  L as default
};
//# sourceMappingURL=index.mjs.map
