import { jsx as e, jsxs as k, Fragment as z } from "@emotion/react/jsx-runtime";
import { useFormContext as x, Controller as E } from "react-hook-form";
import { clsx as R } from "clsx";
import { useModuleSkeleton as b } from "@m4l/core";
import { useComponentSize as y } from "../../../hooks/useComponentSize/index.js";
import { getComponentClasses as D } from "../../../utils/getComponentSlotRoot.js";
import { RHF_DATE_PICKER_KEY_COMPONENT as H } from "./constants.js";
import { RHFDatePickerSlots as M } from "./slots/RHFDatePickerEnum.js";
import { useId as N } from "react";
import { RootStyled as _ } from "./slots/RHFDatePickerSlots.js";
import { Label as I } from "../../Label/Label.js";
import { DatePicker as O } from "../../extended/mui/DatePicker/DatePicker.js";
import { HelperError as j } from "../../HelperError/HelperError.js";
const U = (i) => {
  const {
    name: l,
    size: a,
    label: s,
    mandatory: n,
    mandatoryMessage: d,
    helperMessage: p,
    disabled: c,
    readOnly: f,
    className: m,
    ...u
  } = i, { control: F } = x(), S = b(), { currentSize: o } = y(a), g = D(H, M), r = N();
  return /* @__PURE__ */ e(
    _,
    {
      className: R(m, g.root),
      role: S ? "presentation" : void 0,
      children: /* @__PURE__ */ e(
        E,
        {
          name: l,
          control: F,
          defaultValue: null,
          render: ({ field: { value: C, onChange: P }, fieldState: { error: t }, formState: { isSubmitting: h } }) => /* @__PURE__ */ k(z, { children: [
            s && /* @__PURE__ */ e(
              I,
              {
                htmlFor: r,
                size: o,
                label: s,
                mandatory: n,
                mandatoryMessage: d,
                helperMessage: p
              }
            ),
            /* @__PURE__ */ e(
              O,
              {
                ...u,
                value: C,
                id: r,
                onChange: P,
                readOnly: f,
                error: t,
                size: o,
                disabled: c || h,
                className: m
              }
            ),
            t?.message && /* @__PURE__ */ e(
              j,
              {
                size: o,
                htmlFor: r,
                message: t?.message + ""
              }
            )
          ] })
        }
      )
    }
  );
};
export {
  U as RHFDatePicker
};
