import { jsx as t, jsxs as k, Fragment as W } from "@emotion/react/jsx-runtime";
import j from "clsx";
import { RHFSELECT_CLASSES as n, RHFSELECT_COMPONENT_KEY as M } from "./constants.js";
import { RHFSelectEnum as _ } from "./slots/RHFSelectEnum.js";
import { RootStyled as B, LabelStyled as O, SelectStyled as P, HelperErrorStyled as $ } from "./slots/RHFSlots.js";
import { useFormContext as v, Controller as D } from "react-hook-form";
import { getPropDataTestId as K } from "../../../test/getNameDataTestId.js";
import { useComponentSize as Y } from "../../../hooks/useComponentSize/index.js";
import { useId as q } from "react";
const te = (c) => {
  const {
    id: S,
    name: f,
    multiple: m,
    options: p,
    label: i,
    labelSkeletonWidth: u,
    helperErrorSkeletonWidth: h,
    helperMessage: y,
    mandatory: E,
    mandatoryMessage: b,
    placeholder: F,
    disabled: d,
    size: g = "medium",
    variant: z = "outlined",
    className: C,
    dataTestId: I
  } = c, x = q(), l = S || x, { currentSize: o } = Y(g), s = o === "small" || o === "medium" ? o : "medium", { control: A } = v();
  return /* @__PURE__ */ t(B, { className: j(n.root, C), children: /* @__PURE__ */ t(
    D,
    {
      name: f,
      control: A,
      render: ({ field: { value: H, onChange: a, ref: L }, fieldState: { error: r }, formState: { isSubmitting: N } }) => {
        const R = (e) => {
          if (!e) {
            a(null);
            return;
          }
          m && Array.isArray(e) ? a(e.map((T) => T.id)) : Array.isArray(e) || a(e.id);
        };
        return /* @__PURE__ */ k(W, { children: [
          i && /* @__PURE__ */ t(
            O,
            {
              id: `${l}-label`,
              htmlFor: l,
              label: i,
              mandatory: E,
              mandatoryMessage: b,
              helperMessage: y,
              size: s,
              skeletonWidth: u,
              error: !!r,
              disabled: d
            }
          ),
          /* @__PURE__ */ t(
            P,
            {
              labelId: `${l}-label`,
              ref: L,
              options: p,
              multiple: m,
              size: s,
              variant: z,
              value: H,
              onChange: R,
              disabled: d || N,
              className: n.select,
              error: !!r,
              placeholder: F,
              ...K(M, _.select, I)
            }
          ),
          r?.message && /* @__PURE__ */ t($, { size: s, message: r.message, skeletonWidth: h })
        ] });
      }
    }
  ) });
};
export {
  te as RHFSelect
};
