import { jsx as e, jsxs as U, Fragment as I } from "@emotion/react/jsx-runtime";
import { useFormContext as L, Controller as y } from "react-hook-form";
import H from "./subcomponents/UploadSingleFile/index.js";
import { RHFUploadSingleFileRootStyled as N, LabelStyled as R, HelperErrorStyled as h } from "./slots/RHFUploadSingleFileSlots.js";
import { useComponentSize as j } from "../../../../hooks/useComponentSize/index.js";
import C from "clsx";
import { DEFAULT_MAX_FILE_SIZE as M, RHF_UPLOAD_SINGLE_FILE_KEY_COMPONENT as O } from "./constants.js";
import { getPropDataTestId as T } from "../../../../test/getNameDataTestId.js";
import { RHFUploadSingleFileSlots as w } from "./slots/RHFUploadSingleFileEnum.js";
function Z(s) {
  const { control: m } = L(), { name: n, label: r, skeletonWidth: d, size: p, className: c, helperMessage: S, mandatory: f, mandatoryMessage: F, maxFileSize: g = M, dataTestId: u, accept: x = "*/*", disabled: l } = s, { currentSize: o } = j(p), t = o === "small" || o === "medium" ? o : "medium", z = {
    [x]: []
  };
  return /* @__PURE__ */ e(
    N,
    {
      role: "textbox",
      "aria-label": "upload-single-file",
      ownerState: {},
      className: C(c),
      ...T(O, w.root, u),
      children: /* @__PURE__ */ e(
        y,
        {
          name: n,
          control: m,
          render: ({ field: { value: E, onChange: _ }, fieldState: { error: a }, formState: { isSubmitting: b } }) => {
            const i = !!a;
            return /* @__PURE__ */ U(I, { children: [
              r && /* @__PURE__ */ e(
                R,
                {
                  ownerState: {},
                  error: i,
                  label: r,
                  mandatory: f,
                  mandatoryMessage: F,
                  helperMessage: S,
                  size: t,
                  skeletonWidth: d,
                  disabled: l
                }
              ),
              /* @__PURE__ */ e(
                H,
                {
                  maxFileSize: g,
                  accept: z,
                  file: E,
                  onChange: _,
                  size: t,
                  disabled: l || b
                }
              ),
              i && /* @__PURE__ */ e(
                h,
                {
                  message: a?.message,
                  size: t,
                  ownerState: {}
                }
              )
            ] });
          }
        }
      )
    }
  );
}
export {
  Z as RHFUploadSingleFile
};
