import { jsx as e, jsxs as y, Fragment as H } from "@emotion/react/jsx-runtime";
import { useFormContext as O, Controller as C } from "react-hook-form";
import { useFormFocus as E } from "../../../hooks/useFormFocus/index.js";
import { useModuleSkeleton as M } from "@m4l/core";
import { Label as N } from "../../Label/Label.js";
import { RHFPeriodRootStyled as I } from "./slots/RHFPeriodSlots.js";
import { Period as K } from "./subcomponents/Period/Period.js";
import { RHF_PERIOD_KEY_COMPONENT as d } from "./constants.js";
import _ from "clsx";
import { getPropDataTestId as j } from "../../../test/getNameDataTestId.js";
import { getComponentSlotRoot as k } from "../../../utils/getComponentSlotRoot.js";
import { HelperError as B } from "../../HelperError/HelperError.js";
import { RHFPeriodSlots as D } from "./slots/RHFPeriodEnum.js";
const X = (n) => {
  const {
    name: s,
    label: m,
    mandatory: p,
    mandatoryMessage: f,
    helperMessage: c,
    disabled: r,
    size: t = "medium",
    dataTestId: u,
    className: F
  } = n, { control: a } = O(), l = M(), { isFocus: S, isTabSelected: P, handlerFocus: b, handlerOnKeyUp: g, handlerOnBlur: h } = E(), R = {
    isFocus: l ? !1 : S,
    isTabSelected: l ? !1 : P
  };
  return /* @__PURE__ */ e(
    I,
    {
      className: _(k(d), F),
      ...j(d, D.root, u),
      role: "rhf-period",
      ownerState: R,
      onFocus: b,
      onBlur: h,
      onKeyUp: g,
      "aria-disabled": r ? "true" : void 0,
      children: /* @__PURE__ */ e(
        C,
        {
          name: s || "",
          control: a,
          defaultValue: { selPeriodTime: "", singleValue: "" },
          render: ({ field: { onChange: T, value: x }, fieldState: { error: o }, formState: { isSubmitting: i } }) => /* @__PURE__ */ y(H, { children: [
            m && /* @__PURE__ */ e(
              N,
              {
                size: t,
                label: m,
                mandatory: p,
                mandatoryMessage: f,
                helperMessage: c,
                disabled: r || i,
                error: !!o
              }
            ),
            /* @__PURE__ */ e(
              K,
              {
                name: s,
                control: a,
                disabled: r || i,
                value: x,
                onChange: T,
                size: t,
                error: !!o
              }
            ),
            o && /* @__PURE__ */ e(B, { message: o.message || "", size: t })
          ] })
        }
      )
    }
  );
};
export {
  X as RHFPeriod
};
