import pe from "./index-extends.js";
import * as T from "react";
import { clsx as he } from "./index-clsx.m.js";
import e from "./index-_virtual16.js";
import { Clock as ge } from "./index-Clock3.js";
import { useLocaleText as Ce, useNow as fe, useUtils as be } from "./index-useUtils.js";
import { buildDeprecatedPropsWarning as we } from "./index-warning.js";
import { getMinutesNumbers as z, getHourNumbers as Te } from "./index-ClockNumbers.js";
import { PickersArrowSwitcher as ke } from "./index-PickersArrowSwitcher.js";
import { convertValueToMeridiem as Y, createIsAfterIgnoreDatePart as xe } from "./index-time-utils.js";
import { useViews as Ne } from "./index-useViews.js";
import { useMeridiemMode as Se } from "./index-date-helpers-hooks.js";
import { getClockPickerUtilityClass as Me } from "./index-clockPickerClasses.js";
import { jsxs as Pe, jsx as G } from "react/jsx-runtime";
import ve from "./index-useThemeProps.js";
import Ae from "./index-useId2.js";
import Ve from "./index-composeClasses.js";
import J from "./index-styled.js";
import { PickerViewRoot as De } from "./index-PickerViewRoot.js";
const ye = (b) => {
  const {
    classes: u
  } = b;
  return Ve({
    root: ["root"],
    arrowSwitcher: ["arrowSwitcher"]
  }, Me, u);
}, He = J(De, {
  name: "MuiClockPicker",
  slot: "Root",
  overridesResolver: (b, u) => u.root
})({
  display: "flex",
  flexDirection: "column"
}), Be = J(ke, {
  name: "MuiClockPicker",
  slot: "ArrowSwitcher",
  overridesResolver: (b, u) => u.arrowSwitcher
})({
  position: "absolute",
  right: 12,
  top: 15
}), Oe = we("Props for translation are deprecated. See https://mui.com/x/react-date-pickers/localization for more information."), Re = /* @__PURE__ */ T.forwardRef(function(u, O) {
  const R = ve({
    props: u,
    name: "MuiClockPicker"
  }), {
    ampm: a = !1,
    ampmInClock: K = !1,
    autoFocus: Q,
    components: X,
    componentsProps: Z,
    date: d,
    disableIgnoringDatePartForTimeValidation: I,
    getClockLabelText: k,
    getHoursClockNumberText: x,
    getMinutesClockNumberText: N,
    getSecondsClockNumberText: S,
    leftArrowButtonText: M,
    maxTime: P,
    minTime: v,
    minutesStep: A = 1,
    rightArrowButtonText: V,
    shouldDisableTime: D,
    showViewSwitcher: $,
    onChange: ee,
    view: oe,
    views: te = ["hours", "minutes"],
    openTo: se,
    onViewChange: re,
    className: ne,
    disabled: p,
    readOnly: ie
  } = R;
  Oe({
    leftArrowButtonText: M,
    rightArrowButtonText: V,
    getClockLabelText: k,
    getHoursClockNumberText: x,
    getMinutesClockNumberText: N,
    getSecondsClockNumberText: S
  });
  const m = Ce(), ce = M ?? m.openPreviousView, le = V ?? m.openNextView, ue = k ?? m.clockLabelText, L = x ?? m.hoursClockNumberText, W = N ?? m.minutesClockNumberText, j = S ?? m.secondsClockNumberText, {
    openView: y,
    setOpenView: F,
    nextView: E,
    previousView: U,
    handleChangeAndOpenNext: h
  } = Ne({
    view: oe,
    views: te,
    openTo: se,
    onViewChange: re,
    onChange: ee
  }), q = fe(), o = be(), s = T.useMemo(() => d || o.setSeconds(o.setMinutes(o.setHours(q, 0), 0), 0), [d, q, o]), {
    meridiemMode: g,
    handleMeridiemChange: ae
  } = Se(s, a, h), C = T.useCallback((r, l) => {
    const n = xe(I, o), i = ({
      start: t,
      end: c
    }) => !(v && n(v, c) || P && n(t, P)), B = (t, c = 1) => t % c !== 0 ? !1 : D ? !D(t, l) : !0;
    switch (l) {
      case "hours": {
        const t = Y(r, g, a), c = o.setHours(s, t), w = o.setSeconds(o.setMinutes(c, 0), 0), de = o.setSeconds(o.setMinutes(c, 59), 59);
        return !i({
          start: w,
          end: de
        }) || !B(t);
      }
      case "minutes": {
        const t = o.setMinutes(s, r), c = o.setSeconds(t, 0), w = o.setSeconds(t, 59);
        return !i({
          start: c,
          end: w
        }) || !B(r, A);
      }
      case "seconds": {
        const t = o.setSeconds(s, r);
        return !i({
          start: t,
          end: t
        }) || !B(r);
      }
      default:
        throw new Error("not supported");
    }
  }, [a, s, I, P, g, v, A, D, o]), f = Ae(), me = T.useMemo(() => {
    switch (y) {
      case "hours":
        return {
          onChange: (l, n) => {
            const i = Y(l, g, a);
            h(o.setHours(s, i), n);
          },
          value: o.getHours(s),
          children: Te({
            date: d,
            utils: o,
            ampm: a,
            getClockNumberText: L,
            isDisabled: (l) => p || C(l, "hours"),
            selectedId: f
          })
        };
      case "minutes": {
        const r = o.getMinutes(s);
        return {
          value: r,
          onChange: (n, i) => {
            h(o.setMinutes(s, n), i);
          },
          children: z({
            utils: o,
            value: r,
            getClockNumberText: W,
            isDisabled: (n) => p || C(n, "minutes"),
            selectedId: f
          })
        };
      }
      case "seconds": {
        const r = o.getSeconds(s);
        return {
          value: r,
          onChange: (n, i) => {
            h(o.setSeconds(s, n), i);
          },
          children: z({
            utils: o,
            value: r,
            getClockNumberText: j,
            isDisabled: (n) => p || C(n, "seconds"),
            selectedId: f
          })
        };
      }
      default:
        throw new Error("You must provide the type for ClockView");
    }
  }, [y, o, d, a, L, W, j, g, h, s, C, f, p]), H = R, _ = ye(H);
  return /* @__PURE__ */ Pe(He, {
    ref: O,
    className: he(_.root, ne),
    ownerState: H,
    children: [$ && /* @__PURE__ */ G(Be, {
      className: _.arrowSwitcher,
      leftArrowButtonText: ce,
      rightArrowButtonText: le,
      components: X,
      componentsProps: Z,
      onLeftClick: () => F(U),
      onRightClick: () => F(E),
      isLeftDisabled: !U,
      isRightDisabled: !E,
      ownerState: H
    }), /* @__PURE__ */ G(ge, pe({
      autoFocus: Q,
      date: d,
      ampmInClock: K,
      type: y,
      ampm: a,
      getClockLabelText: ue,
      minutesStep: A,
      isTimeDisabled: C,
      meridiemMode: g,
      handleMeridiemChange: ae,
      selectedId: f,
      disabled: p,
      readOnly: ie
    }, me))]
  });
});
process.env.NODE_ENV !== "production" && (Re.propTypes = {
  // ----------------------------- Warning --------------------------------
  // | These PropTypes are generated from the TypeScript type definitions |
  // | To update them edit the TypeScript types and run "yarn proptypes"  |
  // ----------------------------------------------------------------------
  /**
   * 12h/24h view for hour selection clock.
   * @default false
   */
  ampm: e.bool,
  /**
   * Display ampm controls under the clock (instead of in the toolbar).
   * @default false
   */
  ampmInClock: e.bool,
  /**
   * Set to `true` if focus should be moved to clock picker.
   */
  autoFocus: e.bool,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: e.object,
  className: e.string,
  /**
   * Overrideable components.
   * @default {}
   */
  components: e.object,
  /**
   * The props used for each component slot.
   * @default {}
   */
  componentsProps: e.object,
  /**
   * Selected date @DateIOType.
   */
  date: e.any,
  /**
   * If `true`, the picker and text field are disabled.
   * @default false
   */
  disabled: e.bool,
  /**
   * Do not ignore date part when validating min/max time.
   * @default false
   */
  disableIgnoringDatePartForTimeValidation: e.bool,
  /**
   * Accessible text that helps user to understand which time and view is selected.
   * @template TDate
   * @param {ClockPickerView} view The current view rendered.
   * @param {TDate | null} time The current time.
   * @param {MuiPickersAdapter<TDate>} adapter The current date adapter.
   * @returns {string} The clock label.
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   * @default <TDate extends any>(
   *   view: ClockView,
   *   time: TDate | null,
   *   adapter: MuiPickersAdapter<TDate>,
   * ) =>
   *   `Select ${view}. ${
   *     time === null ? 'No time selected' : `Selected time is ${adapter.format(time, 'fullTime')}`
   *   }`
   */
  getClockLabelText: e.func,
  /**
   * Get clock number aria-text for hours.
   * @param {string} hours The hours to format.
   * @returns {string} the formatted hours text.
   * @default (hours: string) => `${hours} hours`
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  getHoursClockNumberText: e.func,
  /**
   * Get clock number aria-text for minutes.
   * @param {string} minutes The minutes to format.
   * @returns {string} the formatted minutes text.
   * @default (minutes: string) => `${minutes} minutes`
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  getMinutesClockNumberText: e.func,
  /**
   * Get clock number aria-text for seconds.
   * @param {string} seconds The seconds to format.
   * @returns {string} the formatted seconds text.
   * @default (seconds: string) => `${seconds} seconds`
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  getSecondsClockNumberText: e.func,
  /**
   * Left arrow icon aria-label text.
   * @default 'open previous view'
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  leftArrowButtonText: e.string,
  /**
   * Max time acceptable time.
   * For input validation date part of passed object will be ignored if `disableIgnoringDatePartForTimeValidation` not specified.
   */
  maxTime: e.any,
  /**
   * Min time acceptable time.
   * For input validation date part of passed object will be ignored if `disableIgnoringDatePartForTimeValidation` not specified.
   */
  minTime: e.any,
  /**
   * Step over minutes.
   * @default 1
   */
  minutesStep: e.number,
  /**
   * On change callback @DateIOType.
   */
  onChange: e.func.isRequired,
  /**
   * Callback fired on view change.
   * @param {ClockPickerView} view The new view.
   */
  onViewChange: e.func,
  /**
   * Initially open view.
   * @default 'hours'
   */
  openTo: e.oneOf(["hours", "minutes", "seconds"]),
  /**
   * Make picker read only.
   * @default false
   */
  readOnly: e.bool,
  /**
   * Right arrow icon aria-label text.
   * @default 'open next view'
   * @deprecated Use the `localeText` prop of `LocalizationProvider` instead, see https://mui.com/x/react-date-pickers/localization/.
   */
  rightArrowButtonText: e.string,
  /**
   * Dynamically check if time is disabled or not.
   * If returns `false` appropriate time point will ot be acceptable.
   * @param {number} timeValue The value to check.
   * @param {ClockPickerView} clockType The clock type of the timeValue.
   * @returns {boolean} Returns `true` if the time should be disabled
   */
  shouldDisableTime: e.func,
  showViewSwitcher: e.bool,
  /**
   * Controlled open view.
   */
  view: e.oneOf(["hours", "minutes", "seconds"]),
  /**
   * Views for calendar picker.
   * @default ['hours', 'minutes']
   */
  views: e.arrayOf(e.oneOf(["hours", "minutes", "seconds"]).isRequired)
});
export {
  Re as ClockPicker
};
