import { jsx as e, jsxs as H, Fragment as E } from "@emotion/react/jsx-runtime";
import I from "clsx";
import { useId as b } from "react";
import { useFormContext as M, Controller as N } from "react-hook-form";
import { useFormatter as P } from "@m4l/graphics";
import { useComponentSize as _ } from "../../../hooks/useComponentSize/index.js";
import { getComponentClasses as j } from "../../../utils/getComponentSlotRoot.js";
import { getPropDataTestId as y } from "../../../test/getNameDataTestId.js";
import { DateTimePicker as O } from "../../extended/mui/DateTimePicker/DateTimePicker.js";
import { RHFDateTimeRootStyled as k } from "./slots/RHFDateTimeSlots.js";
import { RHF_DATE_TIME_KEY_COMPONENT as i } from "./constants.js";
import { RHFDateTimeSlots as n } from "./slots/RHFDateTimeEnum.js";
import { Label as v } from "../../Label/Label.js";
import { HelperError as A } from "../../HelperError/HelperError.js";
function $(l) {
  const {
    name: d,
    disabled: s,
    size: p = "medium",
    variant: f,
    label: a,
    helperMessage: c,
    mandatory: F,
    mandatoryMessage: u,
    className: g,
    dataTestId: T
  } = l, { control: z } = M(), t = b(), {
    dateFormatter: { datetimeFormat: R }
  } = P(), { currentSize: o } = _(p), r = o === "small" || o === "medium" ? o : "medium", S = j(i, n);
  return /* @__PURE__ */ e(
    k,
    {
      className: I(g, S.root),
      ...y(i, n.root, T),
      children: /* @__PURE__ */ e(
        N,
        {
          name: d,
          control: z,
          render: ({ field: { value: h, onChange: x, ref: C }, fieldState: { error: m }, formState: { isSubmitting: D } }) => /* @__PURE__ */ H(E, { children: [
            a && /* @__PURE__ */ e(
              v,
              {
                disabled: s,
                htmlFor: t,
                size: r,
                label: a,
                mandatory: F,
                mandatoryMessage: u,
                helperMessage: c
              }
            ),
            /* @__PURE__ */ e(
              O,
              {
                variant: f,
                size: r,
                disabled: s || D,
                inputRef: C,
                slotProps: {
                  field: {
                    format: R
                  },
                  textField: {
                    id: t
                  }
                },
                value: h,
                onChange: x,
                error: !!m?.message
              }
            ),
            m?.message && /* @__PURE__ */ e(A, { size: r, htmlFor: t, message: m?.message + "" })
          ] })
        }
      )
    }
  );
}
export {
  $ as RHFDateTime
};
