import { jsx as e, jsxs as y, Fragment as z } from "@emotion/react/jsx-runtime";
import x from "clsx";
import { useFormContext as R, Controller as T } from "react-hook-form";
import { useId as N } from "react";
import { useComponentSize as W } from "../../../hooks/useComponentSize/index.js";
import { getPropDataTestId as A } from "../../../test/getNameDataTestId.js";
import { RHF_CHECKABLE_LIST_COMPONENT_KEY as B, RHF_CHECKABLE_LIST_CLASSES as K } from "./constants.js";
import { RHFCheckableListEnum as M } from "./slots/RHFCheckableListEnum.js";
import { RootStyled as j, LabelStyled as O, CheckableListStyled as P, HelperErrorStyled as v } from "./slots/RHFCheckableListSlots.js";
const V = (a) => {
  const {
    id: m,
    name: i,
    items: n,
    groups: d,
    label: r,
    labelSkeletonWidth: c,
    helperErrorSkeletonWidth: h,
    helperMessage: p,
    mandatory: C,
    mandatoryMessage: S,
    disabled: s,
    size: f = "medium",
    className: L,
    dataTestId: g,
    width: u = "100%",
    ...E
  } = a, b = N(), l = m || b, { currentSize: t } = W(f), { control: k } = R();
  return /* @__PURE__ */ e(j, { className: x(K.root, L), children: /* @__PURE__ */ e(
    T,
    {
      name: i,
      control: k,
      render: ({ field: { value: F, onChange: H }, fieldState: { error: o } }) => {
        const I = (_) => {
          H(_ || []);
        };
        return /* @__PURE__ */ y(z, { children: [
          r && /* @__PURE__ */ e(
            O,
            {
              id: `${l}-label`,
              htmlFor: l,
              label: r,
              mandatory: C,
              mandatoryMessage: S,
              helperMessage: p,
              size: t,
              skeletonWidth: c,
              error: !!o,
              disabled: s
            }
          ),
          /* @__PURE__ */ e(
            P,
            {
              items: n,
              groups: d,
              value: F || [],
              onChange: I,
              disabled: s,
              size: t,
              width: u,
              ...A(
                B,
                M.checkableList,
                g
              ),
              ...E
            }
          ),
          o?.message && /* @__PURE__ */ e(
            v,
            {
              size: t,
              message: o.message,
              skeletonWidth: h
            }
          )
        ] });
      }
    }
  ) });
};
export {
  V as RHFCheckableList
};
