import { jsx as e, jsxs as x, Fragment as U } from "@emotion/react/jsx-runtime";
import { useFormContext as h, Controller as F } from "react-hook-form";
import { useComponentSize as y } from "../../../../hooks/useComponentSize/index.js";
import { RHFUploadImageRootStyled as H } from "./slots/RHFUploadImageSlots.js";
import { UploadImage as I } from "./subcomponents/UploadImage/UploadImage.js";
import { Label as L } from "../../../Label/Label.js";
import { HelperError as v } from "../../../HelperError/HelperError.js";
function A(n) {
  const {
    name: l,
    size: d,
    accept: C,
    label: i,
    mandatory: c,
    mandatoryMessage: p,
    maxSize: f,
    helperMessage: u,
    disabled: g,
    ...z
  } = n, { currentSize: r } = y(d), o = r === "small" || r === "medium" ? r : "medium", { control: S } = h();
  return /* @__PURE__ */ e(H, { children: /* @__PURE__ */ e(
    F,
    {
      name: l,
      control: S,
      render: ({ field: { value: b, onChange: s }, fieldState: { error: a }, formState: { isSubmitting: R } }) => {
        const t = !!a;
        return /* @__PURE__ */ x(U, { children: [
          i && /* @__PURE__ */ e(
            L,
            {
              error: t,
              label: i,
              mandatory: c,
              mandatoryMessage: p,
              helperMessage: u,
              size: o
            }
          ),
          /* @__PURE__ */ e(
            I,
            {
              onDrop: (j) => {
                const m = j[0];
                m && s(
                  Object.assign(m, {
                    preview: URL.createObjectURL(m)
                  })
                );
              },
              onRemove: () => {
                s(null);
              },
              error: t,
              disabled: g || R,
              ...z,
              file: b,
              size: o,
              maxSize: f
            }
          ),
          t && /* @__PURE__ */ e(
            v,
            {
              message: a?.message,
              size: o
            }
          )
        ] });
      }
    }
  ) });
}
export {
  A as RHFUploadImage
};
