import { jsx as n, jsxs as S } from "react/jsx-runtime";
import { useOutsideCallback as z } from "./index-use-outside-callback.js";
import { getDatePatternFromLocale as A } from "./index-locale.js";
import { datePickerValueParser as p } from "./index-date-picker-value-parser.js";
import { Icon as F } from "./index-Icon.js";
import { IconNames as L } from "./index-IconNames.js";
import { Input as j } from "./index-Input.js";
import a from "./index-moment.js";
import { useState as f, useRef as q, useMemo as P } from "react";
import i from "./index-DatePicker.module.scss.js";
import { LocalizationProvider as R } from "./index-LocalizationProvider.js";
import U from "./index-index.esm.js";
import { DatePicker as $ } from "./index-DatePicker2.js";
const ee = (k) => {
  const {
    closeOnCLickAway: C,
    onChange: s,
    value: l = null,
    label: D,
    required: x,
    formconfig: M,
    minDate: c,
    maxDate: d,
    disablePast: I,
    locale: b
  } = k, h = A(b), [v, g] = f(p(l)), [m, o] = f(!1), t = q(null), u = (e) => {
    if (e)
      return e.toString().length === 13 ? Math.floor(e / 1e3) : e;
  }, O = P(() => {
    const e = u(c);
    return e && a.unix(e).isValid() ? a.unix(e) : void 0;
  }, [c]), y = P(() => {
    const e = u(d);
    return e && a.unix(e).isValid() ? a.unix(e) : void 0;
  }, [d]);
  return z(t, (e) => {
    const r = e.target;
    if (!C)
      return !1;
    ![
      "MuiCalendarPicker-root",
      "MuiPickersCalendarHeader-root",
      "MuiPickersDay-root",
      "MuiPickersArrowSwitcher-root",
      "MuiDayPicker-weekContainer"
      // Add more classes here if needed
    ].some((N) => r == null ? void 0 : r.closest(`.${N}`)) && t.current && !t.current.contains(r) && o(!1);
  }), n(R, {
    dateAdapter: U,
    children: S("div", {
      ref: t,
      className: i.container,
      children: [n(F, {
        className: i.icon,
        color: "--n500",
        children: L.calendar
      }), n($, {
        inputFormat: h,
        open: m,
        onOpen: () => o(!0),
        onClose: () => o(!1),
        PopperProps: {
          popperOptions: {
            placement: "bottom-end"
          }
        },
        PaperProps: {
          className: i.paper
        },
        disablePast: I,
        value: l,
        minDate: O,
        maxDate: y,
        onChange: (e) => {
          g(p(e)), s && s(e == null ? void 0 : e.valueOf());
        },
        renderInput: (e) => {
          const r = e;
          return r.autoComplete = "off", r.focused = m, delete r.label, delete r.InputProps, n(j, {
            formconfig: M,
            textFieldProps: r,
            disabled: e.disabled,
            required: x,
            value: v,
            onClick: () => o(!0),
            label: D
          });
        }
      })]
    })
  });
};
export {
  ee as DatePicker
};
