import J from "./index-objectWithoutPropertiesLoose.js";
import v from "./index-extends.js";
import * as a from "react";
import t from "./index-_virtual16.js";
import { clsx as Q } from "./index-clsx.m.js";
import { PickersMonth as X } from "./index-PickersMonth.js";
import { useUtils as A, useNow as Z, useDefaultDates as $ } from "./index-useUtils.js";
import { getMonthPickerUtilityClass as ee } from "./index-monthPickerClasses.js";
import { parseNonNullablePickerDate as T } from "./index-date-utils.js";
import { jsx as Y } from "react/jsx-runtime";
import te from "./index-useTheme2.js";
import oe from "./index-useControlled2.js";
import se from "./index-useEventCallback2.js";
import ne from "./index-useThemeProps.js";
import ae from "./index-composeClasses.js";
import re from "./index-styled.js";
const le = ["className", "date", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange"], ce = (h) => {
  const {
    classes: r
  } = h;
  return ae({
    root: ["root"]
  }, ee, r);
};
function ie(h, r) {
  const f = A(), o = $(), s = ne({
    props: h,
    name: r
  });
  return v({
    disableFuture: !1,
    disablePast: !1
  }, s, {
    minDate: T(f, s.minDate, o.minDate),
    maxDate: T(f, s.maxDate, o.maxDate)
  });
}
const ue = re("div", {
  name: "MuiMonthPicker",
  slot: "Root",
  overridesResolver: (h, r) => r.root
})({
  width: 310,
  display: "flex",
  flexWrap: "wrap",
  alignContent: "stretch",
  margin: "0 4px"
}), he = /* @__PURE__ */ a.forwardRef(function(r, f) {
  const o = A(), s = Z(), p = ie(r, "MuiMonthPicker"), {
    className: S,
    date: l,
    disabled: E,
    disableFuture: w,
    disablePast: P,
    maxDate: M,
    minDate: D,
    onChange: j,
    shouldDisableMonth: g,
    readOnly: H,
    disableHighlightToday: x,
    autoFocus: B = !1,
    onMonthFocus: y,
    hasFocus: U,
    onFocusedViewChange: F
  } = p, V = J(p, le), C = p, _ = ce(C), I = te(), d = a.useMemo(() => l ?? o.startOfMonth(s), [s, o, l]), c = a.useMemo(() => l != null ? o.getMonth(l) : x ? null : o.getMonth(s), [s, l, o, x]), [i, O] = a.useState(() => c || o.getMonth(s)), k = a.useCallback((e) => {
    const n = o.startOfMonth(P && o.isAfter(s, D) ? s : D), m = o.startOfMonth(w && o.isBefore(s, M) ? s : M);
    return o.isBefore(e, n) || o.isAfter(e, m) ? !0 : g ? g(e) : !1;
  }, [w, P, M, D, s, g, o]), K = (e) => {
    if (H)
      return;
    const n = o.setMonth(d, e);
    j(n, "finish");
  }, [L, N] = oe({
    name: "MonthPicker",
    state: "hasFocus",
    controlled: U,
    default: B
  }), b = a.useCallback((e) => {
    N(e), F && F(e);
  }, [N, F]), u = a.useCallback((e) => {
    k(o.setMonth(d, e)) || (O(e), b(!0), y && y(e));
  }, [k, o, d, b, y]);
  a.useEffect(() => {
    O((e) => c !== null && e !== c ? c : e);
  }, [c]);
  const W = se((e) => {
    switch (e.key) {
      case "ArrowUp":
        u((12 + i - 3) % 12), e.preventDefault();
        break;
      case "ArrowDown":
        u((12 + i + 3) % 12), e.preventDefault();
        break;
      case "ArrowLeft":
        u((12 + i + (I.direction === "ltr" ? -1 : 1)) % 12), e.preventDefault();
        break;
      case "ArrowRight":
        u((12 + i + (I.direction === "ltr" ? 1 : -1)) % 12), e.preventDefault();
        break;
    }
  }), q = a.useCallback((e, n) => {
    u(n);
  }, [u]), z = a.useCallback(() => {
    b(!1);
  }, [b]), G = o.getMonth(s);
  return /* @__PURE__ */ Y(ue, v({
    ref: f,
    className: Q(_.root, S),
    ownerState: C,
    onKeyDown: W
  }, V, {
    children: o.getMonthArray(d).map((e) => {
      const n = o.getMonth(e), m = o.format(e, "monthShort"), R = E || k(e);
      return /* @__PURE__ */ Y(X, {
        value: n,
        selected: n === c,
        tabIndex: n === i && !R ? 0 : -1,
        hasFocus: L && n === i,
        onSelect: K,
        onFocus: q,
        onBlur: z,
        disabled: R,
        "aria-current": G === n ? "date" : void 0,
        children: m
      }, m);
    })
  }));
});
process.env.NODE_ENV !== "production" && (he.propTypes = {
  // ----------------------------- Warning --------------------------------
  // | These PropTypes are generated from the TypeScript type definitions |
  // | To update them edit the TypeScript types and run "yarn proptypes"  |
  // ----------------------------------------------------------------------
  autoFocus: t.bool,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: t.object,
  /**
   * className applied to the root element.
   */
  className: t.string,
  /**
   * Date value for the MonthPicker
   */
  date: t.any,
  /**
   * If `true` picker is disabled
   */
  disabled: t.bool,
  /**
   * If `true` future days are disabled.
   * @default false
   */
  disableFuture: t.bool,
  /**
   * If `true`, today's date is rendering without highlighting with circle.
   * @default false
   */
  disableHighlightToday: t.bool,
  /**
   * If `true` past days are disabled.
   * @default false
   */
  disablePast: t.bool,
  hasFocus: t.bool,
  /**
   * Maximal selectable date. @DateIOType
   */
  maxDate: t.any,
  /**
   * Minimal selectable date. @DateIOType
   */
  minDate: t.any,
  /**
   * Callback fired on date change.
   */
  onChange: t.func.isRequired,
  onFocusedViewChange: t.func,
  onMonthFocus: t.func,
  /**
   * If `true` picker is readonly
   */
  readOnly: t.bool,
  /**
   * Disable specific months dynamically.
   * Works like `shouldDisableDate` but for month selection view @DateIOType.
   * @template TDate
   * @param {TDate} month The month to check.
   * @returns {boolean} If `true` the month will be disabled.
   */
  shouldDisableMonth: t.func,
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: t.oneOfType([t.arrayOf(t.oneOfType([t.func, t.object, t.bool])), t.func, t.object])
});
export {
  he as MonthPicker,
  ie as useMonthPickerDefaultizedProps
};
