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 C } from "../../../HelperError/HelperError.js";
function A(l) {
  const {
    name: d,
    size: c,
    accept: E,
    label: i,
    mandatory: p,
    mandatoryMessage: f,
    maxSize: u,
    helperMessage: g,
    disabled: z,
    ...S
  } = l, { currentSize: r } = y(c), o = r === "small" || r === "medium" ? r : "medium", { control: b } = h();
  return /* @__PURE__ */ e(H, { children: /* @__PURE__ */ e(
    F,
    {
      name: d,
      control: b,
      render: ({ field: { value: s, onChange: a }, fieldState: { error: n }, formState: { isSubmitting: R } }) => {
        const t = !!n && !s;
        return /* @__PURE__ */ x(U, { children: [
          i && /* @__PURE__ */ e(
            L,
            {
              error: t,
              label: i,
              mandatory: p,
              mandatoryMessage: f,
              helperMessage: g,
              size: o
            }
          ),
          /* @__PURE__ */ e(
            I,
            {
              onDrop: (j) => {
                const m = j[0];
                m && a(
                  Object.assign(m, {
                    preview: URL.createObjectURL(m)
                  })
                );
              },
              onRemove: () => {
                a(null);
              },
              error: t,
              disabled: z || R,
              ...S,
              file: s,
              size: o,
              maxSize: u
            }
          ),
          t && /* @__PURE__ */ e(
            C,
            {
              message: n?.message,
              size: o
            }
          )
        ] });
      }
    }
  ) });
}
export {
  A as RHFUploadImage
};
