import { jsx as n, jsxs as j } from "@emotion/react/jsx-runtime";
import { IconButtonStyled as u, CalendarHeaderStyled as T, ActionsContainerStyled as Y, PickersLayoutStyled as _, DesktopPaperStyled as E, TextFieldStyled as q } from "../../slots/DatePickerSlots.js";
import { useFormatter as G, useIsMobile as J } from "@m4l/graphics";
import s, { useMemo as i, useCallback as I } from "react";
import { useModuleDictionary as K } from "@m4l/core";
import { datePickerStyles as Q } from "../../DatePicker.styles.js";
import { useComponentSize as U } from "../../../../../../hooks/useComponentSize/index.js";
import { ArrowChevronSmLeftOutlined as W, ArrowChevronSmRightOutlined as X, ArrowChevronSmDownOutlined as Z, DateTimeCreatedOutlined as $ } from "@m4l/icons";
import { Button as O } from "../../../Button/Button.js";
const lt = (V) => {
  const {
    error: d,
    size: D = "medium",
    disabled: o,
    slots: f,
    variant: w = "outlined",
    readOnly: c,
    id: S
  } = V, { dateFormatter: M } = G(), { getLabel: l } = K(), p = J(), { currentSize: e } = U(D), { dateFormat: N } = M, a = i(() => ({
    size: e,
    error: !!d,
    disabled: !!o
  }), [e, d, o]), C = i(() => ({
    ...a,
    isInputAdornment: !0
  }), [a]), B = i(() => s.forwardRef((t, r) => /* @__PURE__ */ n(
    u,
    {
      ref: r,
      ...t,
      ownerState: a,
      size: e,
      disabled: o,
      icon: /* @__PURE__ */ n(W, {})
    }
  )), [e, o, a]), y = i(() => s.forwardRef((t, r) => /* @__PURE__ */ n(
    u,
    {
      ref: r,
      ...t,
      ownerState: a,
      size: e,
      disabled: o,
      icon: /* @__PURE__ */ n(X, {})
    }
  )), [e, o, a]), b = i(() => s.forwardRef((t, r) => {
    const m = t?.ownerState?.view === "year" ? 180 : 0;
    return /* @__PURE__ */ n(
      u,
      {
        ref: r,
        ...t,
        ownerState: a,
        size: e,
        disabled: o,
        rotationAngle: m,
        icon: /* @__PURE__ */ n(Z, {})
      }
    );
  }), [e, o, a]), k = I((t) => /* @__PURE__ */ n(T, { ...t, ownerState: a }), [a]), v = i(() => s.forwardRef((t, r) => /* @__PURE__ */ n(
    O,
    {
      ref: r,
      ...t,
      variant: "text",
      color: "default",
      size: e,
      label: l("common_actions.cancel"),
      disabled: o
    }
  )), [e, o, l]), x = i(() => s.forwardRef((t, r) => /* @__PURE__ */ n(
    O,
    {
      ref: r,
      ...t,
      variant: "contained",
      color: "primary",
      size: e,
      label: l("common_actions.intro"),
      disabled: o
    }
  )), [e, o, l]), z = i(() => s.forwardRef((t, r) => {
    const { onAccept: g, onCancel: F, className: m } = t;
    return /* @__PURE__ */ j(
      Y,
      {
        ref: r,
        className: m,
        children: [
          /* @__PURE__ */ n(v, { onClick: F }),
          /* @__PURE__ */ n(x, { onClick: g })
        ]
      }
    );
  }), [v, x]), A = i(() => p && f?.actionBar === void 0 ? { actionBar: z } : {}, [p, f?.actionBar, z]), h = I((t) => /* @__PURE__ */ n(
    u,
    {
      ...t,
      ownerState: C,
      icon: /* @__PURE__ */ n($, {}),
      size: e,
      disabled: c || o
    }
  ), [e, o, C, c]), H = i(() => ({
    textField: q,
    openPickerButton: h,
    // Popper component
    desktopPaper: E,
    calendarHeader: k,
    previousIconButton: B,
    nextIconButton: y,
    switchViewButton: b,
    layout: _,
    ...A
  }), [
    k,
    y,
    B,
    b,
    A,
    h
  ]), P = !!d, R = i(() => {
    const t = Q?.dialog;
    if (!(!t || typeof t != "function"))
      return (r) => t({ theme: r });
  }, []), L = i(() => ({
    textField: {
      id: S,
      error: P,
      size: e,
      variant: w,
      label: null,
      readOnly: c
    },
    dialog: {
      sx: R
    }
  }), [S, P, e, w, c, R]);
  return {
    ownerState: a,
    defaultSlots: H,
    defaultSlotProps: L,
    dateFormat: N
  };
};
export {
  lt as useDatePicker
};
