import { jsx as n, jsxs as J } from "react/jsx-runtime";
import { createContext as R, useState as Q, useContext as V } from "react";
import { DayPicker as g, DayButton as T } from "react-day-picker";
import O from "../../utils/classNames.js";
import { isSingleDayPickerProps as U, isMultipleDayPickerProps as X, isRangeDayPickerProps as Y } from "./dayPickerTypes.js";
import { createCustomRangeModifiers as Z, getCustomRangeValue as p } from "./dayPickerRangeSelectionUtils.js";
import { resolveLocale as ee } from "./dayPickerUtils.js";
const B = R(null), ne = (e) => Object.hasOwn(e, "value"), ue = (e) => {
  const {
    locale: m = "en-GB",
    className: d,
    size: l = "md",
    numberOfMonths: D = 1,
    defaultMonth: y,
    month: L,
    onMonthChange: j,
    startMonth: _,
    endMonth: z,
    disabledDays: I,
    hiddenDays: K,
    showOutsideDays: E = !0,
    fixedWeeks: G = !0,
    showWeekNumber: $ = !1,
    weekStartsOn: q,
    modifiers: S,
    modifiersClassNames: A,
    renderDayContent: h
  } = e, r = ne(e), [v, C] = Q(e.defaultValue), x = ee(m), M = O("DayPicker display-block", `DayPicker--${l}`, d), P = h ? { DayButton: te } : void 0, k = {
    defaultMonth: y,
    month: L,
    onMonthChange: j,
    locale: x,
    numberOfMonths: D,
    captionLayout: "dropdown",
    animate: !0,
    navLayout: "around",
    startMonth: _,
    endMonth: z,
    disabled: I,
    hidden: K,
    modifiers: S,
    modifiersClassNames: A,
    showOutsideDays: E,
    fixedWeeks: G,
    showWeekNumber: $,
    weekStartsOn: q,
    className: M,
    components: P
  };
  if (U(e)) {
    const t = r ? e.value : v, s = (o, b, a) => {
      r || C(o), e.onChange?.(o, a);
    };
    return /* @__PURE__ */ n(f.Provider, { value: h || null, children: /* @__PURE__ */ n(g, { ...k, mode: "single", selected: t, onSelect: s }) });
  }
  if (X(e)) {
    const t = r ? e.value : v, s = (o, b, a) => {
      r || C(o), e.onChange?.(o, a);
    };
    return /* @__PURE__ */ n(f.Provider, { value: h || null, children: /* @__PURE__ */ n(g, { ...k, mode: "multiple", selected: t, onSelect: s }) });
  }
  if (Y(e)) {
    const { selectionVariant: t = "default", rollingDays: s = 7 } = e, o = r ? e.value : v;
    if (t !== "default") {
      const a = Number.isInteger(s) && s > 0 ? s : 7, W = Z(o), N = {
        ...S,
        ...W
      }, w = (i, c) => {
        if (c.disabled || c.hidden)
          return;
        const u = p({
          day: i,
          selectionVariant: t,
          rollingDays: a,
          locale: x,
          currentValue: o
        });
        r || C(u), e.onChange?.(u, c);
      }, F = (i, c) => {
        w(i, c);
      }, H = (i, c, u) => {
        u.key !== " " && u.key !== "Enter" || (u.preventDefault(), w(i, c));
      };
      return /* @__PURE__ */ n(B.Provider, { value: (i) => w(i, {}), children: /* @__PURE__ */ n(f.Provider, { value: h || null, children: /* @__PURE__ */ n(
        g,
        {
          ...k,
          className: O(
            M,
            t === "week" && "DayPicker-week-selection",
            t === "month" && "DayPicker-month-selection"
          ),
          modifiers: N,
          onDayClick: F,
          onDayKeyDown: H,
          components: t === "week" ? { ...P, WeekNumber: oe } : P
        }
      ) }) });
    }
    const b = (a, W, N) => {
      r || C(a), e.onChange?.(a, N);
    };
    return /* @__PURE__ */ n(f.Provider, { value: h || null, children: /* @__PURE__ */ n(g, { ...k, mode: "range", selected: o, onSelect: b }) });
  }
  return null;
}, f = R(null), te = ({ children: e, className: m, day: d, ...l }) => {
  const y = V(f)?.(d.date, l.modifiers);
  return /* @__PURE__ */ J(T, { ...l, day: d, className: m, children: [
    e,
    y && y
  ] });
}, oe = ({ week: e, ...m }) => {
  const d = V(B), l = e.days[0]?.date;
  return /* @__PURE__ */ n("th", { ...m, children: /* @__PURE__ */ n(
    "button",
    {
      type: "button",
      className: "btn btn-muted-filled text-color-darkest btn-block btn-sm",
      onClick: (D) => {
        D.preventDefault(), l && d?.(l);
      },
      children: e.weekNumber
    }
  ) });
};
export {
  ue as default
};
//# sourceMappingURL=DayPickerCalendar.js.map
