import pe from "./index-objectWithoutPropertiesLoose.js";
import F from "./index-extends.js";
import * as f from "react";
import e from "./index-_virtual16.js";
import { clsx as Ce } from "./index-clsx.m.js";
import { MonthPicker as be } from "./index-MonthPicker.js";
import { useCalendarState as De } from "./index-useCalendarState.js";
import { useUtils as $, useDefaultDates as ge } from "./index-useUtils.js";
import { PickersFadeTransitionGroup as ye } from "./index-PickersFadeTransitionGroup.js";
import { DayPicker as we } from "./index-DayPicker.js";
import { useViews as Pe } from "./index-useViews.js";
import { PickersCalendarHeader as Me } from "./index-PickersCalendarHeader.js";
import { YearPicker as Fe } from "./index-YearPicker.js";
import { findClosestEnabledDate as z, parseNonNullablePickerDate as G } from "./index-date-utils.js";
import { defaultReduceAnimations as Ve } from "./index-defaultReduceAnimations.js";
import { getCalendarPickerUtilityClass as ke } from "./index-calendarPickerClasses.js";
import { jsxs as K, jsx as b } from "react/jsx-runtime";
import xe from "./index-useId2.js";
import Oe from "./index-useControlled2.js";
import Te from "./index-useEventCallback2.js";
import ve from "./index-useThemeProps.js";
import Ae from "./index-composeClasses.js";
import J from "./index-styled.js";
import { PickerViewRoot as Ye } from "./index-PickerViewRoot.js";
const Re = ["autoFocus", "onViewChange", "date", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange", "classes"], Ne = (p) => {
  const {
    classes: r
  } = p;
  return Ae({
    root: ["root"],
    viewTransitionContainer: ["viewTransitionContainer"]
  }, ke, r);
};
function Ee(p, r) {
  const D = $(), a = ge(), g = ve({
    props: p,
    name: r
  });
  return F({
    loading: !1,
    disablePast: !1,
    disableFuture: !1,
    openTo: "day",
    views: ["year", "day"],
    reduceAnimations: Ve,
    renderLoading: () => /* @__PURE__ */ b("span", {
      children: "..."
    })
  }, g, {
    minDate: G(D, g.minDate, a.minDate),
    maxDate: G(D, g.maxDate, a.maxDate)
  });
}
const Se = J(Ye, {
  name: "MuiCalendarPicker",
  slot: "Root",
  overridesResolver: (p, r) => r.root
})({
  display: "flex",
  flexDirection: "column"
}), je = J(ye, {
  name: "MuiCalendarPicker",
  slot: "ViewTransitionContainer",
  overridesResolver: (p, r) => r.viewTransitionContainer
})({}), Be = /* @__PURE__ */ f.forwardRef(function(r, D) {
  const a = $(), g = xe(), v = Ee(r, "MuiCalendarPicker"), {
    autoFocus: V,
    onViewChange: Q,
    date: n,
    disableFuture: m,
    disablePast: h,
    defaultCalendarMonth: X,
    onChange: c,
    onYearChange: A,
    onMonthChange: k,
    reduceAnimations: x,
    shouldDisableDate: j,
    shouldDisableMonth: Z,
    shouldDisableYear: ee,
    view: oe,
    views: B,
    openTo: ae,
    className: I,
    disabled: O,
    readOnly: ne,
    minDate: l,
    maxDate: d,
    disableHighlightToday: te,
    focusedView: se,
    onFocusedViewChange: L
  } = v, Y = pe(v, Re), {
    openView: t,
    setOpenView: ie,
    openNext: T
  } = Pe({
    view: oe,
    views: B,
    openTo: ae,
    onChange: c,
    onViewChange: Q
  }), {
    calendarState: W,
    changeFocusedDay: y,
    changeMonth: w,
    handleChangeMonth: re,
    isDateDisabled: C,
    onMonthSwitchingAnimationEnd: le
  } = De({
    date: n,
    defaultCalendarMonth: X,
    reduceAnimations: x,
    onMonthChange: k,
    minDate: l,
    maxDate: d,
    shouldDisableDate: j,
    disablePast: h,
    disableFuture: m
  }), de = f.useCallback((o, s) => {
    const i = a.startOfMonth(o), M = a.endOfMonth(o), u = C(o) ? z({
      utils: a,
      date: o,
      minDate: a.isBefore(l, i) ? i : l,
      maxDate: a.isAfter(d, M) ? M : d,
      disablePast: h,
      disableFuture: m,
      isDateDisabled: C
    }) : o;
    u ? (c(u, s), k == null || k(i)) : (T(), w(i)), y(u, !0);
  }, [y, m, h, C, d, l, c, k, w, T, a]), ce = f.useCallback((o, s) => {
    const i = a.startOfYear(o), M = a.endOfYear(o), u = C(o) ? z({
      utils: a,
      date: o,
      minDate: a.isBefore(l, i) ? i : l,
      maxDate: a.isAfter(d, M) ? M : d,
      disablePast: h,
      disableFuture: m,
      isDateDisabled: C
    }) : o;
    u ? (c(u, s), A == null || A(u)) : (T(), w(i)), y(u, !0);
  }, [y, m, h, C, d, l, c, A, T, a, w]), ue = f.useCallback((o, s) => c(n && o ? a.mergeDateAndTime(o, n) : o, s), [a, n, c]);
  f.useEffect(() => {
    n && w(n);
  }, [n]);
  const R = v, _ = Ne(R), N = {
    disablePast: h,
    disableFuture: m,
    maxDate: d,
    minDate: l
  }, me = O && n || l, he = O && n || d, E = {
    disableHighlightToday: te,
    readOnly: ne,
    disabled: O
  }, H = `${g}-grid-label`, [fe, U] = Oe({
    name: "DayPicker",
    state: "focusedView",
    controlled: se,
    default: V ? t : null
  }), S = fe !== null, P = Te((o) => (s) => {
    if (L) {
      L(o)(s);
      return;
    }
    U(s ? o : (i) => i === o ? null : i);
  }), q = f.useRef(t);
  return f.useEffect(() => {
    q.current !== t && (q.current = t, P(t)(!0));
  }, [t, P]), /* @__PURE__ */ K(Se, {
    ref: D,
    className: Ce(_.root, I),
    ownerState: R,
    children: [/* @__PURE__ */ b(Me, F({}, Y, {
      views: B,
      openView: t,
      currentMonth: W.currentMonth,
      onViewChange: ie,
      onMonthChange: (o, s) => re({
        newMonth: o,
        direction: s
      }),
      minDate: me,
      maxDate: he,
      disabled: O,
      disablePast: h,
      disableFuture: m,
      reduceAnimations: x,
      labelId: H
    })), /* @__PURE__ */ b(je, {
      reduceAnimations: x,
      className: _.viewTransitionContainer,
      transKey: t,
      ownerState: R,
      children: /* @__PURE__ */ K("div", {
        children: [t === "year" && /* @__PURE__ */ b(Fe, F({}, Y, N, E, {
          autoFocus: V,
          date: n,
          onChange: ce,
          shouldDisableYear: ee,
          hasFocus: S,
          onFocusedViewChange: P("year")
        })), t === "month" && /* @__PURE__ */ b(be, F({}, N, E, {
          autoFocus: V,
          hasFocus: S,
          className: I,
          date: n,
          onChange: de,
          shouldDisableMonth: Z,
          onFocusedViewChange: P("month")
        })), t === "day" && /* @__PURE__ */ b(we, F({}, Y, W, N, E, {
          autoFocus: V,
          onMonthSwitchingAnimationEnd: le,
          onFocusedDayChange: y,
          reduceAnimations: x,
          selectedDays: [n],
          onSelectedDaysChange: ue,
          shouldDisableDate: j,
          hasFocus: S,
          onFocusedViewChange: P("day"),
          gridLabelId: H
        }))]
      })
    })]
  });
});
process.env.NODE_ENV !== "production" && (Be.propTypes = {
  // ----------------------------- Warning --------------------------------
  // | These PropTypes are generated from the TypeScript type definitions |
  // | To update them edit the TypeScript types and run "yarn proptypes"  |
  // ----------------------------------------------------------------------
  autoFocus: e.bool,
  classes: e.object,
  className: e.string,
  /**
   * Overrideable components.
   * @default {}
   */
  components: e.object,
  /**
   * The props used for each component slot.
   * @default {}
   */
  componentsProps: e.object,
  date: e.any,
  /**
   * Formats the day of week displayed in the calendar header.
   * @param {string} day The day of week provided by the adapter's method `getWeekdays`.
   * @returns {string} The name to display.
   * @default (day) => day.charAt(0).toUpperCase()
   */
  dayOfWeekFormatter: e.func,
  /**
   * Default calendar month displayed when `value={null}`.
   */
  defaultCalendarMonth: e.any,
  /**
   * If `true`, the picker and text field are disabled.
   * @default false
   */
  disabled: e.bool,
  /**
   * If `true` future days are disabled.
   * @default false
   */
  disableFuture: e.bool,
  /**
   * If `true`, today's date is rendering without highlighting with circle.
   * @default false
   */
  disableHighlightToday: e.bool,
  /**
   * If `true` past days are disabled.
   * @default false
   */
  disablePast: e.bool,
  focusedView: e.oneOf(["day", "month", "year"]),
  /**
   * Get aria-label text for switching between views button.
   * @param {CalendarPickerView} currentView The view from which we want to get the button text.
   * @returns {string} The label of the view.
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  getViewSwitchingButtonText: e.func,
  /**
   * Left arrow icon aria-label text.
   * @deprecated
   */
  leftArrowButtonText: e.string,
  /**
   * If `true` renders `LoadingComponent` in calendar instead of calendar view.
   * Can be used to preload information and show it in calendar.
   * @default false
   */
  loading: e.bool,
  /**
   * Maximal selectable date. @DateIOType
   */
  maxDate: e.any,
  /**
   * Minimal selectable date. @DateIOType
   */
  minDate: e.any,
  /**
   * Callback fired on date change
   */
  onChange: e.func.isRequired,
  onFocusedViewChange: e.func,
  /**
   * Callback firing on month change @DateIOType.
   * @template TDate
   * @param {TDate} month The new month.
   * @returns {void|Promise} -
   */
  onMonthChange: e.func,
  /**
   * Callback fired on view change.
   * @param {CalendarPickerView} view The new view.
   */
  onViewChange: e.func,
  /**
   * Callback firing on year change @DateIOType.
   * @template TDate
   * @param {TDate} year The new year.
   */
  onYearChange: e.func,
  /**
   * Initially open view.
   * @default 'day'
   */
  openTo: e.oneOf(["day", "month", "year"]),
  /**
   * Make picker read only.
   * @default false
   */
  readOnly: e.bool,
  /**
   * Disable heavy animations.
   * @default typeof navigator !== 'undefined' && /(android)/i.test(navigator.userAgent)
   */
  reduceAnimations: e.bool,
  /**
   * Custom renderer for day. Check the [PickersDay](https://mui.com/x/api/date-pickers/pickers-day/) component.
   * @template TDate
   * @param {TDate} day The day to render.
   * @param {Array<TDate | null>} selectedDays The days currently selected.
   * @param {PickersDayProps<TDate>} pickersDayProps The props of the day to render.
   * @returns {JSX.Element} The element representing the day.
   */
  renderDay: e.func,
  /**
   * Component displaying when passed `loading` true.
   * @returns {React.ReactNode} The node to render when loading.
   * @default () => <span data-mui-test="loading-progress">...</span>
   */
  renderLoading: e.func,
  /**
   * Right arrow icon aria-label text.
   * @deprecated
   */
  rightArrowButtonText: e.string,
  /**
   * Disable specific date. @DateIOType
   * @template TDate
   * @param {TDate} day The date to test.
   * @returns {boolean} Returns `true` if the date should be disabled.
   */
  shouldDisableDate: e.func,
  /**
   * 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: e.func,
  /**
   * Disable specific years dynamically.
   * Works like `shouldDisableDate` but for year selection view @DateIOType.
   * @template TDate
   * @param {TDate} year The year to test.
   * @returns {boolean} Returns `true` if the year should be disabled.
   */
  shouldDisableYear: e.func,
  /**
   * If `true`, days that have `outsideCurrentMonth={true}` are displayed.
   * @default false
   */
  showDaysOutsideCurrentMonth: e.bool,
  /**
   * Controlled open view.
   */
  view: e.oneOf(["day", "month", "year"]),
  /**
   * Views for calendar picker.
   * @default ['year', 'day']
   */
  views: e.arrayOf(e.oneOf(["day", "month", "year"]).isRequired)
});
export {
  Be as CalendarPicker
};
