"use client";
import { useEffect as E } from "react";
import { getDates as I } from "./helpers/getDates.js";
import { getDays as N } from "./helpers/getDays.js";
import { getDisplayMonths as k } from "./helpers/getDisplayMonths.js";
import { getInitialMonth as g } from "./helpers/getInitialMonth.js";
import { getMonths as O } from "./helpers/getMonths.js";
import { getNavMonths as q } from "./helpers/getNavMonth.js";
import { getNextMonth as F } from "./helpers/getNextMonth.js";
import { getPreviousMonth as P } from "./helpers/getPreviousMonth.js";
import { getWeeks as S } from "./helpers/getWeeks.js";
import { useControlledValue as V } from "./helpers/useControlledValue.js";
function X(t, n) {
  const [i, o] = q(t, n), { startOfMonth: r, endOfMonth: u } = n, f = g(t, i, o, n), [m, h] = V(
    f,
    // initialMonth is always computed from props.month if provided
    t.month ? f : void 0
  );
  E(() => {
    const e = g(t, i, o, n);
    h(e);
  }, [t.timeZone]);
  const c = k(m, o, t, n), d = I(c, t.endMonth ? u(t.endMonth) : void 0, t, n), a = O(c, d, t, n), M = S(a), y = N(a), v = P(m, i, t, n), D = F(m, o, t, n), { disableNavigation: C, onMonthChange: T } = t, w = (e) => M.some((s) => s.days.some((x) => x.isEqualTo(e))), l = (e) => {
    if (C)
      return;
    let s = r(e);
    i && s < r(i) && (s = r(i)), o && s > r(o) && (s = r(o)), h(s), T?.(s);
  };
  return {
    months: a,
    weeks: M,
    days: y,
    navStart: i,
    navEnd: o,
    previousMonth: v,
    nextMonth: D,
    goToMonth: l,
    goToDay: (e) => {
      w(e) || l(e.date);
    }
  };
}
export {
  X as useCalendar
};
