import { jsx as o, jsxs as C, Fragment as I } from "@emotion/react/jsx-runtime";
import { useId as a } from "react";
import { useFormContext as L, Controller as R } from "react-hook-form";
import { ActionsGroup as j } from "../../ActionsGroup/ActionsGroup.js";
import { rhfActionsGroupClasses as v } from "./constants.js";
import { useComponentSize as H } from "../../../hooks/useComponentSize/index.js";
import M from "clsx";
import { ActionsGroupRootStyled as N } from "./slots/RHFActionsGroupSlots.js";
import { Label as V } from "../../Label/Label.js";
import { HelperError as k } from "../../HelperError/HelperError.js";
const U = (n) => {
  const {
    name: i,
    actions: l,
    label: e,
    disabled: t,
    className: c,
    ariaLabel: d,
    ariaLabelledBy: p,
    size: s = "medium",
    variant: u,
    mandatory: f,
    mandatoryMessage: h,
    helperMessage: b,
    id: g
  } = n, { control: F } = L(), { currentSize: m } = H(s), x = a(), z = a(), G = g || z;
  return /* @__PURE__ */ o(
    N,
    {
      className: M(c, v.actionsGroupRoot),
      children: /* @__PURE__ */ o(
        R,
        {
          name: i,
          control: F,
          render: ({ field: { value: S, onChange: y }, fieldState: { error: r }, formState: { isSubmitting: A } }) => /* @__PURE__ */ C(I, { children: [
            e && /* @__PURE__ */ o(
              V,
              {
                size: m,
                label: e,
                htmlFor: G,
                mandatory: f,
                mandatoryMessage: h,
                helperMessage: b,
                disabled: t,
                error: !!r
              }
            ),
            /* @__PURE__ */ o(
              j,
              {
                actions: l,
                value: S ?? null,
                onChange: y,
                disabled: t || A,
                ariaLabel: d,
                ariaLabelledBy: p,
                size: s,
                variant: u
              }
            ),
            r?.message && /* @__PURE__ */ o(
              k,
              {
                htmlFor: x,
                size: m,
                message: r.message
              }
            )
          ] })
        }
      )
    }
  );
};
export {
  U as RHFActionsGroup
};
