@helsenorge/datepicker 9.4.1 → 9.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +1,74 @@
1
- import { jsx as s, jsxs as L, Fragment as A } from "react/jsx-runtime";
2
- import J, { createContext as ne, forwardRef as Ut, useContext as re, useState as B, useEffect as z, useLayoutEffect as Xt, useRef as oe } from "react";
3
- import { isSameDay as N, subDays as Ce, addDays as W, differenceInCalendarDays as U, startOfMonth as S, endOfMonth as Fe, startOfDay as rt, addMonths as j, differenceInCalendarMonths as le, isSameMonth as Ae, isBefore as He, isAfter as ge, getUnixTime as Zt, getWeeksInMonth as Gt, addWeeks as Ee, isSameYear as $t, setMonth as Pe, setYear as at, startOfYear as qt, max as Jt, min as Qt, endOfISOWeek as ht, endOfWeek as pt, startOfISOWeek as Ye, startOfWeek as je, getISOWeek as zt, getWeek as en, format as O, isDate as yt, addYears as tn, isValid as se, parse as ie, isWithinInterval as nn } from "date-fns";
4
- import { enUS as rn, nb as an } from "date-fns/locale";
5
- import on from "@helsenorge/designsystem-react/components/Button";
6
- import ln from "@helsenorge/designsystem-react/components/Icon";
7
- import sn from "@helsenorge/designsystem-react/components/Icons/Calendar";
8
- import Re from "@helsenorge/designsystem-react/components/Input";
9
- import { PopOverVariant as F } from "@helsenorge/designsystem-react/components/PopOver";
10
- import { ZIndex as dn, KeyboardEventKey as ot } from "@helsenorge/designsystem-react/constants";
11
- import { useKeyboardEvent as it } from "@helsenorge/designsystem-react/hooks/useKeyboardEvent";
12
- import { useOutsideEvent as un } from "@helsenorge/designsystem-react/hooks/useOutsideEvent";
13
- import { usePseudoClasses as bt } from "@helsenorge/designsystem-react/hooks/usePseudoClasses";
14
- import { isMobileUA as cn } from "@helsenorge/designsystem-react/utils/mobile";
15
- import { isMutableRefObject as gt, mergeRefs as _t } from "@helsenorge/designsystem-react/utils/refs";
16
- import Be from "classnames";
17
- import fn from "react-day-picker/dist/style.module.css";
18
- import { useFocusTrap as vn } from "@helsenorge/designsystem-react/hooks/useFocusTrap";
19
- import { useInterval as mn } from "@helsenorge/designsystem-react/hooks/useInterval";
20
- import { useIsVisible as hn } from "@helsenorge/designsystem-react/hooks/useIsVisible";
21
- import { useLayoutEvent as pn } from "@helsenorge/designsystem-react/hooks/useLayoutEvent";
22
- import { useSize as yn } from "@helsenorge/designsystem-react/hooks/useSize";
23
- import { getSpacer as bn } from "@helsenorge/designsystem-react/theme/currys/spacing";
24
- import P from "./styles.module.scss";
25
- import gn from "@helsenorge/designsystem-react/components/ErrorWrapper";
26
- import { useUuid as _n } from "@helsenorge/designsystem-react/hooks/useUuid";
27
- import { isComponent as lt } from "@helsenorge/designsystem-react/utils/component";
28
- var g = function() {
29
- return g = Object.assign || function(t) {
30
- for (var n, r = 1, a = arguments.length; r < a; r++) {
31
- n = arguments[r];
32
- for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import React, { createContext, forwardRef, useContext, useState, useEffect, useLayoutEffect, useRef } from "react";
3
+ import { isSameDay, subDays, addDays, differenceInCalendarDays, startOfMonth, endOfMonth, startOfDay, addMonths, differenceInCalendarMonths, isSameMonth, isBefore, isAfter, getUnixTime, getWeeksInMonth, addWeeks, isSameYear, setMonth, setYear, startOfYear, max, min, endOfISOWeek, endOfWeek, startOfISOWeek, startOfWeek, getISOWeek, getWeek, format, isDate, addYears, isValid, parse, isWithinInterval } from "date-fns";
4
+ import { enUS, nb } from "date-fns/locale";
5
+ import Button$1 from "@helsenorge/designsystem-react/components/Button";
6
+ import Icon from "@helsenorge/designsystem-react/components/Icon";
7
+ import Calendar from "@helsenorge/designsystem-react/components/Icons/Calendar";
8
+ import Input from "@helsenorge/designsystem-react/components/Input";
9
+ import { PopOverVariant } from "@helsenorge/designsystem-react/components/PopOver";
10
+ import { ZIndex, KeyboardEventKey } from "@helsenorge/designsystem-react/constants";
11
+ import { useKeyboardEvent } from "@helsenorge/designsystem-react/hooks/useKeyboardEvent";
12
+ import { useOutsideEvent } from "@helsenorge/designsystem-react/hooks/useOutsideEvent";
13
+ import { usePseudoClasses } from "@helsenorge/designsystem-react/hooks/usePseudoClasses";
14
+ import { isMobileUA } from "@helsenorge/designsystem-react/utils/mobile";
15
+ import { isMutableRefObject, mergeRefs } from "@helsenorge/designsystem-react/utils/refs";
16
+ import classNames from "classnames";
17
+ import reactdaypickerstyles from "react-day-picker/dist/style.module.css";
18
+ import { useFocusTrap } from "@helsenorge/designsystem-react/hooks/useFocusTrap";
19
+ import { useInterval } from "@helsenorge/designsystem-react/hooks/useInterval";
20
+ import { useIsVisible } from "@helsenorge/designsystem-react/hooks/useIsVisible";
21
+ import { useLayoutEvent } from "@helsenorge/designsystem-react/hooks/useLayoutEvent";
22
+ import { useSize } from "@helsenorge/designsystem-react/hooks/useSize";
23
+ import { getSpacer } from "@helsenorge/designsystem-react/theme/currys/spacing";
24
+ import styles from "./styles.module.scss";
25
+ import ErrorWrapper from "@helsenorge/designsystem-react/components/ErrorWrapper";
26
+ import { useUuid } from "@helsenorge/designsystem-react/hooks/useUuid";
27
+ import { isComponent } from "@helsenorge/designsystem-react/utils/component";
28
+ var __assign = function() {
29
+ __assign = Object.assign || function __assign2(t) {
30
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
31
+ s = arguments[i];
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
33
33
  }
34
34
  return t;
35
- }, g.apply(this, arguments);
35
+ };
36
+ return __assign.apply(this, arguments);
36
37
  };
37
- function wn(e, t) {
38
- var n = {};
39
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
40
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
41
- for (var a = 0, r = Object.getOwnPropertySymbols(e); a < r.length; a++)
42
- t.indexOf(r[a]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[a]) && (n[r[a]] = e[r[a]]);
43
- return n;
38
+ function __rest(s, e) {
39
+ var t = {};
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
+ t[p] = s[p];
42
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
+ t[p[i]] = s[p[i]];
46
+ }
47
+ return t;
44
48
  }
45
- function wt(e, t, n) {
46
- for (var r = 0, a = t.length, o; r < a; r++)
47
- (o || !(r in t)) && (o || (o = Array.prototype.slice.call(t, 0, r)), o[r] = t[r]);
48
- return e.concat(o || Array.prototype.slice.call(t));
49
+ function __spreadArray(to, from, pack) {
50
+ for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
49
57
  }
50
- function de(e) {
51
- return e.mode === "multiple";
58
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
59
+ var e = new Error(message);
60
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
61
+ };
62
+ function isDayPickerMultiple(props) {
63
+ return props.mode === "multiple";
52
64
  }
53
- function ue(e) {
54
- return e.mode === "range";
65
+ function isDayPickerRange(props) {
66
+ return props.mode === "range";
55
67
  }
56
- function we(e) {
57
- return e.mode === "single";
68
+ function isDayPickerSingle(props) {
69
+ return props.mode === "single";
58
70
  }
59
- var Dn = {
71
+ var defaultClassNames = {
60
72
  root: "rdp",
61
73
  multiple_months: "rdp-multiple_months",
62
74
  with_weeknumber: "rdp-with_weeknumber",
@@ -99,348 +111,532 @@ var Dn = {
99
111
  day_range_end: "rdp-day_range_end",
100
112
  day_range_middle: "rdp-day_range_middle"
101
113
  };
102
- function Mn(e, t) {
103
- return O(e, "LLLL y", t);
114
+ function formatCaption(month, options) {
115
+ return format(month, "LLLL y", options);
104
116
  }
105
- function kn(e, t) {
106
- return O(e, "d", t);
117
+ function formatDay(day, options) {
118
+ return format(day, "d", options);
107
119
  }
108
- function Nn(e, t) {
109
- return O(e, "LLLL", t);
120
+ function formatMonthCaption(month, options) {
121
+ return format(month, "LLLL", options);
110
122
  }
111
- function Cn(e) {
112
- return "".concat(e);
123
+ function formatWeekNumber(weekNumber) {
124
+ return "".concat(weekNumber);
113
125
  }
114
- function Pn(e, t) {
115
- return O(e, "cccccc", t);
126
+ function formatWeekdayName(weekday, options) {
127
+ return format(weekday, "cccccc", options);
116
128
  }
117
- function xn(e, t) {
118
- return O(e, "yyyy", t);
129
+ function formatYearCaption(year, options) {
130
+ return format(year, "yyyy", options);
119
131
  }
120
- var On = /* @__PURE__ */ Object.freeze({
132
+ var formatters = /* @__PURE__ */ Object.freeze({
121
133
  __proto__: null,
122
- formatCaption: Mn,
123
- formatDay: kn,
124
- formatMonthCaption: Nn,
125
- formatWeekNumber: Cn,
126
- formatWeekdayName: Pn,
127
- formatYearCaption: xn
128
- }), In = function(e, t, n) {
129
- return O(e, "do MMMM (EEEE)", n);
130
- }, Wn = function() {
134
+ formatCaption,
135
+ formatDay,
136
+ formatMonthCaption,
137
+ formatWeekNumber,
138
+ formatWeekdayName,
139
+ formatYearCaption
140
+ });
141
+ var labelDay = function(day, activeModifiers, options) {
142
+ return format(day, "do MMMM (EEEE)", options);
143
+ };
144
+ var labelMonthDropdown = function() {
131
145
  return "Month: ";
132
- }, Sn = function() {
146
+ };
147
+ var labelNext = function() {
133
148
  return "Go to next month";
134
- }, Ln = function() {
149
+ };
150
+ var labelPrevious = function() {
135
151
  return "Go to previous month";
136
- }, En = function(e, t) {
137
- return O(e, "cccc", t);
138
- }, Rn = function(e) {
139
- return "Week n. ".concat(e);
140
- }, Bn = function() {
152
+ };
153
+ var labelWeekday = function(day, options) {
154
+ return format(day, "cccc", options);
155
+ };
156
+ var labelWeekNumber = function(n) {
157
+ return "Week n. ".concat(n);
158
+ };
159
+ var labelYearDropdown = function() {
141
160
  return "Year: ";
142
- }, Tn = /* @__PURE__ */ Object.freeze({
161
+ };
162
+ var labels = /* @__PURE__ */ Object.freeze({
143
163
  __proto__: null,
144
- labelDay: In,
145
- labelMonthDropdown: Wn,
146
- labelNext: Sn,
147
- labelPrevious: Ln,
148
- labelWeekNumber: Rn,
149
- labelWeekday: En,
150
- labelYearDropdown: Bn
164
+ labelDay,
165
+ labelMonthDropdown,
166
+ labelNext,
167
+ labelPrevious,
168
+ labelWeekNumber,
169
+ labelWeekday,
170
+ labelYearDropdown
151
171
  });
152
- function Fn() {
153
- var e = "buttons", t = Dn, n = rn, r = {}, a = {}, o = 1, i = {}, l = /* @__PURE__ */ new Date();
172
+ function getDefaultContextValues() {
173
+ var captionLayout = "buttons";
174
+ var classNames2 = defaultClassNames;
175
+ var locale = enUS;
176
+ var modifiersClassNames = {};
177
+ var modifiers = {};
178
+ var numberOfMonths = 1;
179
+ var styles2 = {};
180
+ var today = /* @__PURE__ */ new Date();
154
181
  return {
155
- captionLayout: e,
156
- classNames: t,
157
- formatters: On,
158
- labels: Tn,
159
- locale: n,
160
- modifiersClassNames: r,
161
- modifiers: a,
162
- numberOfMonths: o,
163
- styles: i,
164
- today: l,
182
+ captionLayout,
183
+ classNames: classNames2,
184
+ formatters,
185
+ labels,
186
+ locale,
187
+ modifiersClassNames,
188
+ modifiers,
189
+ numberOfMonths,
190
+ styles: styles2,
191
+ today,
165
192
  mode: "default"
166
193
  };
167
194
  }
168
- function An(e) {
169
- var t = e.fromYear, n = e.toYear, r = e.fromMonth, a = e.toMonth, o = e.fromDate, i = e.toDate;
170
- return r ? o = S(r) : t && (o = new Date(t, 0, 1)), a ? i = Fe(a) : n && (i = new Date(n, 11, 31)), {
171
- fromDate: o ? rt(o) : void 0,
172
- toDate: i ? rt(i) : void 0
195
+ function parseFromToProps(props) {
196
+ var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
197
+ var fromDate = props.fromDate, toDate = props.toDate;
198
+ if (fromMonth) {
199
+ fromDate = startOfMonth(fromMonth);
200
+ } else if (fromYear) {
201
+ fromDate = new Date(fromYear, 0, 1);
202
+ }
203
+ if (toMonth) {
204
+ toDate = endOfMonth(toMonth);
205
+ } else if (toYear) {
206
+ toDate = new Date(toYear, 11, 31);
207
+ }
208
+ return {
209
+ fromDate: fromDate ? startOfDay(fromDate) : void 0,
210
+ toDate: toDate ? startOfDay(toDate) : void 0
173
211
  };
174
212
  }
175
- var Dt = ne(void 0);
176
- function Hn(e) {
177
- var t, n = e.initialProps, r = Fn(), a = An(n), o = a.fromDate, i = a.toDate, l = (t = n.captionLayout) !== null && t !== void 0 ? t : r.captionLayout;
178
- l !== "buttons" && (!o || !i) && (l = "buttons");
179
- var d;
180
- (we(n) || de(n) || ue(n)) && (d = n.onSelect);
181
- var u = g(g(g({}, r), n), { captionLayout: l, classNames: g(g({}, r.classNames), n.classNames), components: g({}, n.components), formatters: g(g({}, r.formatters), n.formatters), fromDate: o, labels: g(g({}, r.labels), n.labels), mode: n.mode || r.mode, modifiers: g(g({}, r.modifiers), n.modifiers), modifiersClassNames: g(g({}, r.modifiersClassNames), n.modifiersClassNames), onSelect: d, styles: g(g({}, r.styles), n.styles), toDate: i });
182
- return s(Dt.Provider, { value: u, children: e.children });
183
- }
184
- function k() {
185
- var e = re(Dt);
186
- if (!e)
213
+ var DayPickerContext = createContext(void 0);
214
+ function DayPickerProvider(props) {
215
+ var _a;
216
+ var initialProps = props.initialProps;
217
+ var defaultContextValues = getDefaultContextValues();
218
+ var _b = parseFromToProps(initialProps), fromDate = _b.fromDate, toDate = _b.toDate;
219
+ var captionLayout = (_a = initialProps.captionLayout) !== null && _a !== void 0 ? _a : defaultContextValues.captionLayout;
220
+ if (captionLayout !== "buttons" && (!fromDate || !toDate)) {
221
+ captionLayout = "buttons";
222
+ }
223
+ var onSelect;
224
+ if (isDayPickerSingle(initialProps) || isDayPickerMultiple(initialProps) || isDayPickerRange(initialProps)) {
225
+ onSelect = initialProps.onSelect;
226
+ }
227
+ var value = __assign(__assign(__assign({}, defaultContextValues), initialProps), { captionLayout, classNames: __assign(__assign({}, defaultContextValues.classNames), initialProps.classNames), components: __assign({}, initialProps.components), formatters: __assign(__assign({}, defaultContextValues.formatters), initialProps.formatters), fromDate, labels: __assign(__assign({}, defaultContextValues.labels), initialProps.labels), mode: initialProps.mode || defaultContextValues.mode, modifiers: __assign(__assign({}, defaultContextValues.modifiers), initialProps.modifiers), modifiersClassNames: __assign(__assign({}, defaultContextValues.modifiersClassNames), initialProps.modifiersClassNames), onSelect, styles: __assign(__assign({}, defaultContextValues.styles), initialProps.styles), toDate });
228
+ return jsx(DayPickerContext.Provider, { value, children: props.children });
229
+ }
230
+ function useDayPicker() {
231
+ var context = useContext(DayPickerContext);
232
+ if (!context) {
187
233
  throw new Error("useDayPicker must be used within a DayPickerProvider.");
188
- return e;
189
- }
190
- function Mt(e) {
191
- var t = k(), n = t.locale, r = t.classNames, a = t.styles, o = t.formatters.formatCaption;
192
- return s("div", { className: r.caption_label, style: a.caption_label, "aria-live": "polite", role: "presentation", id: e.id, children: o(e.displayMonth, { locale: n }) });
193
- }
194
- function Yn(e) {
195
- return s("svg", g({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, e, { children: s("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" }) }));
196
- }
197
- function kt(e) {
198
- var t, n, r = e.onChange, a = e.value, o = e.children, i = e.caption, l = e.className, d = e.style, u = k(), c = (n = (t = u.components) === null || t === void 0 ? void 0 : t.IconDropdown) !== null && n !== void 0 ? n : Yn;
199
- return L("div", { className: l, style: d, children: [s("span", { className: u.classNames.vhidden, children: e["aria-label"] }), s("select", { name: e.name, "aria-label": e["aria-label"], className: u.classNames.dropdown, style: u.styles.dropdown, value: a, onChange: r, children: o }), L("div", { className: u.classNames.caption_label, style: u.styles.caption_label, "aria-hidden": "true", children: [i, s(c, { className: u.classNames.dropdown_icon, style: u.styles.dropdown_icon })] })] });
200
- }
201
- function jn(e) {
202
- var t, n = k(), r = n.fromDate, a = n.toDate, o = n.styles, i = n.locale, l = n.formatters.formatMonthCaption, d = n.classNames, u = n.components, c = n.labels.labelMonthDropdown;
203
- if (!r)
204
- return s(A, {});
205
- if (!a)
206
- return s(A, {});
207
- var f = [];
208
- if ($t(r, a))
209
- for (var v = S(r), m = r.getMonth(); m <= a.getMonth(); m++)
210
- f.push(Pe(v, m));
211
- else
212
- for (var v = S(/* @__PURE__ */ new Date()), m = 0; m <= 11; m++)
213
- f.push(Pe(v, m));
214
- var y = function(p) {
215
- var D = Number(p.target.value), M = Pe(S(e.displayMonth), D);
216
- e.onChange(M);
217
- }, _ = (t = u == null ? void 0 : u.Dropdown) !== null && t !== void 0 ? t : kt;
218
- return s(_, { name: "months", "aria-label": c(), className: d.dropdown_month, style: o.dropdown_month, onChange: y, value: e.displayMonth.getMonth(), caption: l(e.displayMonth, { locale: i }), children: f.map(function(p) {
219
- return s("option", { value: p.getMonth(), children: l(p, { locale: i }) }, p.getMonth());
234
+ }
235
+ return context;
236
+ }
237
+ function CaptionLabel(props) {
238
+ var _a = useDayPicker(), locale = _a.locale, classNames2 = _a.classNames, styles2 = _a.styles, formatCaption2 = _a.formatters.formatCaption;
239
+ return jsx("div", { className: classNames2.caption_label, style: styles2.caption_label, "aria-live": "polite", role: "presentation", id: props.id, children: formatCaption2(props.displayMonth, { locale }) });
240
+ }
241
+ function IconDropdown(props) {
242
+ return jsx("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props, { children: jsx("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" }) }));
243
+ }
244
+ function Dropdown(props) {
245
+ var _a, _b;
246
+ var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
247
+ var dayPicker = useDayPicker();
248
+ var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
249
+ return jsxs("div", { className, style, children: [jsx("span", { className: dayPicker.classNames.vhidden, children: props["aria-label"] }), jsx("select", { name: props.name, "aria-label": props["aria-label"], className: dayPicker.classNames.dropdown, style: dayPicker.styles.dropdown, value, onChange, children }), jsxs("div", { className: dayPicker.classNames.caption_label, style: dayPicker.styles.caption_label, "aria-hidden": "true", children: [caption, jsx(IconDropdownComponent, { className: dayPicker.classNames.dropdown_icon, style: dayPicker.styles.dropdown_icon })] })] });
250
+ }
251
+ function MonthsDropdown(props) {
252
+ var _a;
253
+ var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, styles2 = _b.styles, locale = _b.locale, formatMonthCaption2 = _b.formatters.formatMonthCaption, classNames2 = _b.classNames, components = _b.components, labelMonthDropdown2 = _b.labels.labelMonthDropdown;
254
+ if (!fromDate)
255
+ return jsx(Fragment, {});
256
+ if (!toDate)
257
+ return jsx(Fragment, {});
258
+ var dropdownMonths = [];
259
+ if (isSameYear(fromDate, toDate)) {
260
+ var date = startOfMonth(fromDate);
261
+ for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
262
+ dropdownMonths.push(setMonth(date, month));
263
+ }
264
+ } else {
265
+ var date = startOfMonth(/* @__PURE__ */ new Date());
266
+ for (var month = 0; month <= 11; month++) {
267
+ dropdownMonths.push(setMonth(date, month));
268
+ }
269
+ }
270
+ var handleChange = function(e) {
271
+ var selectedMonth = Number(e.target.value);
272
+ var newMonth = setMonth(startOfMonth(props.displayMonth), selectedMonth);
273
+ props.onChange(newMonth);
274
+ };
275
+ var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
276
+ return jsx(DropdownComponent, { name: "months", "aria-label": labelMonthDropdown2(), className: classNames2.dropdown_month, style: styles2.dropdown_month, onChange: handleChange, value: props.displayMonth.getMonth(), caption: formatMonthCaption2(props.displayMonth, { locale }), children: dropdownMonths.map(function(m) {
277
+ return jsx("option", { value: m.getMonth(), children: formatMonthCaption2(m, { locale }) }, m.getMonth());
220
278
  }) });
221
279
  }
222
- function Vn(e) {
223
- var t, n = e.displayMonth, r = k(), a = r.fromDate, o = r.toDate, i = r.locale, l = r.styles, d = r.classNames, u = r.components, c = r.formatters.formatYearCaption, f = r.labels.labelYearDropdown, v = [];
224
- if (!a)
225
- return s(A, {});
226
- if (!o)
227
- return s(A, {});
228
- for (var m = a.getFullYear(), y = o.getFullYear(), _ = m; _ <= y; _++)
229
- v.push(at(qt(/* @__PURE__ */ new Date()), _));
230
- var p = function(M) {
231
- var I = at(S(n), Number(M.target.value));
232
- e.onChange(I);
233
- }, D = (t = u == null ? void 0 : u.Dropdown) !== null && t !== void 0 ? t : kt;
234
- return s(D, { name: "years", "aria-label": f(), className: d.dropdown_year, style: l.dropdown_year, onChange: p, value: n.getFullYear(), caption: c(n, { locale: i }), children: v.map(function(M) {
235
- return s("option", { value: M.getFullYear(), children: c(M, { locale: i }) }, M.getFullYear());
280
+ function YearsDropdown(props) {
281
+ var _a;
282
+ var displayMonth = props.displayMonth;
283
+ var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, locale = _b.locale, styles2 = _b.styles, classNames2 = _b.classNames, components = _b.components, formatYearCaption2 = _b.formatters.formatYearCaption, labelYearDropdown2 = _b.labels.labelYearDropdown;
284
+ var years = [];
285
+ if (!fromDate)
286
+ return jsx(Fragment, {});
287
+ if (!toDate)
288
+ return jsx(Fragment, {});
289
+ var fromYear = fromDate.getFullYear();
290
+ var toYear = toDate.getFullYear();
291
+ for (var year = fromYear; year <= toYear; year++) {
292
+ years.push(setYear(startOfYear(/* @__PURE__ */ new Date()), year));
293
+ }
294
+ var handleChange = function(e) {
295
+ var newMonth = setYear(startOfMonth(displayMonth), Number(e.target.value));
296
+ props.onChange(newMonth);
297
+ };
298
+ var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
299
+ return jsx(DropdownComponent, { name: "years", "aria-label": labelYearDropdown2(), className: classNames2.dropdown_year, style: styles2.dropdown_year, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption2(displayMonth, { locale }), children: years.map(function(year2) {
300
+ return jsx("option", { value: year2.getFullYear(), children: formatYearCaption2(year2, { locale }) }, year2.getFullYear());
236
301
  }) });
237
302
  }
238
- function Kn(e, t) {
239
- var n = B(e), r = n[0], a = n[1], o = t === void 0 ? r : t;
240
- return [o, a];
303
+ function useControlledValue(defaultValue, controlledValue) {
304
+ var _a = useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
305
+ var value = controlledValue === void 0 ? uncontrolledValue : controlledValue;
306
+ return [value, setValue];
307
+ }
308
+ function getInitialMonth(context) {
309
+ var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
310
+ var initialMonth = month || defaultMonth || today || /* @__PURE__ */ new Date();
311
+ var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
312
+ if (toDate && differenceInCalendarMonths(toDate, initialMonth) < 0) {
313
+ var offset = -1 * (numberOfMonths - 1);
314
+ initialMonth = addMonths(toDate, offset);
315
+ }
316
+ if (fromDate && differenceInCalendarMonths(initialMonth, fromDate) < 0) {
317
+ initialMonth = fromDate;
318
+ }
319
+ return startOfMonth(initialMonth);
320
+ }
321
+ function useNavigationState() {
322
+ var context = useDayPicker();
323
+ var initialMonth = getInitialMonth(context);
324
+ var _a = useControlledValue(initialMonth, context.month), month = _a[0], setMonth2 = _a[1];
325
+ var goToMonth = function(date) {
326
+ var _a2;
327
+ if (context.disableNavigation)
328
+ return;
329
+ var month2 = startOfMonth(date);
330
+ setMonth2(month2);
331
+ (_a2 = context.onMonthChange) === null || _a2 === void 0 ? void 0 : _a2.call(context, month2);
332
+ };
333
+ return [month, goToMonth];
334
+ }
335
+ function getDisplayMonths(month, _a) {
336
+ var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
337
+ var start = startOfMonth(month);
338
+ var end = startOfMonth(addMonths(start, numberOfMonths));
339
+ var monthsDiff = differenceInCalendarMonths(end, start);
340
+ var months = [];
341
+ for (var i = 0; i < monthsDiff; i++) {
342
+ var nextMonth = addMonths(start, i);
343
+ months.push(nextMonth);
344
+ }
345
+ if (reverseMonths)
346
+ months = months.reverse();
347
+ return months;
241
348
  }
242
- function Un(e) {
243
- var t = e.month, n = e.defaultMonth, r = e.today, a = t || n || r || /* @__PURE__ */ new Date(), o = e.toDate, i = e.fromDate, l = e.numberOfMonths, d = l === void 0 ? 1 : l;
244
- if (o && le(o, a) < 0) {
245
- var u = -1 * (d - 1);
246
- a = j(o, u);
349
+ function getNextMonth(startingMonth, options) {
350
+ if (options.disableNavigation) {
351
+ return void 0;
352
+ }
353
+ var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
354
+ var offset = pagedNavigation ? numberOfMonths : 1;
355
+ var month = startOfMonth(startingMonth);
356
+ if (!toDate) {
357
+ return addMonths(month, offset);
247
358
  }
248
- return i && le(a, i) < 0 && (a = i), S(a);
359
+ var monthsDiff = differenceInCalendarMonths(toDate, startingMonth);
360
+ if (monthsDiff < numberOfMonths) {
361
+ return void 0;
362
+ }
363
+ return addMonths(month, offset);
249
364
  }
250
- function Xn() {
251
- var e = k(), t = Un(e), n = Kn(t, e.month), r = n[0], a = n[1], o = function(i) {
252
- var l;
253
- if (!e.disableNavigation) {
254
- var d = S(i);
255
- a(d), (l = e.onMonthChange) === null || l === void 0 || l.call(e, d);
365
+ function getPreviousMonth(startingMonth, options) {
366
+ if (options.disableNavigation) {
367
+ return void 0;
368
+ }
369
+ var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
370
+ var offset = pagedNavigation ? numberOfMonths : 1;
371
+ var month = startOfMonth(startingMonth);
372
+ if (!fromDate) {
373
+ return addMonths(month, -offset);
374
+ }
375
+ var monthsDiff = differenceInCalendarMonths(month, fromDate);
376
+ if (monthsDiff <= 0) {
377
+ return void 0;
378
+ }
379
+ return addMonths(month, -offset);
380
+ }
381
+ var NavigationContext = createContext(void 0);
382
+ function NavigationProvider(props) {
383
+ var dayPicker = useDayPicker();
384
+ var _a = useNavigationState(), currentMonth = _a[0], goToMonth = _a[1];
385
+ var displayMonths = getDisplayMonths(currentMonth, dayPicker);
386
+ var nextMonth = getNextMonth(currentMonth, dayPicker);
387
+ var previousMonth = getPreviousMonth(currentMonth, dayPicker);
388
+ var isDateDisplayed = function(date) {
389
+ return displayMonths.some(function(displayMonth) {
390
+ return isSameMonth(date, displayMonth);
391
+ });
392
+ };
393
+ var goToDate = function(date, refDate) {
394
+ if (isDateDisplayed(date)) {
395
+ return;
396
+ }
397
+ if (refDate && isBefore(date, refDate)) {
398
+ goToMonth(addMonths(date, 1 + dayPicker.numberOfMonths * -1));
399
+ } else {
400
+ goToMonth(date);
256
401
  }
257
402
  };
258
- return [r, o];
259
- }
260
- function Zn(e, t) {
261
- for (var n = t.reverseMonths, r = t.numberOfMonths, a = S(e), o = S(j(a, r)), i = le(o, a), l = [], d = 0; d < i; d++) {
262
- var u = j(a, d);
263
- l.push(u);
264
- }
265
- return n && (l = l.reverse()), l;
266
- }
267
- function Gn(e, t) {
268
- if (!t.disableNavigation) {
269
- var n = t.toDate, r = t.pagedNavigation, a = t.numberOfMonths, o = a === void 0 ? 1 : a, i = r ? o : 1, l = S(e);
270
- if (!n)
271
- return j(l, i);
272
- var d = le(n, e);
273
- if (!(d < o))
274
- return j(l, i);
275
- }
276
- }
277
- function $n(e, t) {
278
- if (!t.disableNavigation) {
279
- var n = t.fromDate, r = t.pagedNavigation, a = t.numberOfMonths, o = a === void 0 ? 1 : a, i = r ? o : 1, l = S(e);
280
- if (!n)
281
- return j(l, -i);
282
- var d = le(l, n);
283
- if (!(d <= 0))
284
- return j(l, -i);
285
- }
286
- }
287
- var Nt = ne(void 0);
288
- function qn(e) {
289
- var t = k(), n = Xn(), r = n[0], a = n[1], o = Zn(r, t), i = Gn(r, t), l = $n(r, t), d = function(f) {
290
- return o.some(function(v) {
291
- return Ae(f, v);
292
- });
293
- }, u = function(f, v) {
294
- d(f) || (v && He(f, v) ? a(j(f, 1 + t.numberOfMonths * -1)) : a(f));
295
- }, c = {
296
- currentMonth: r,
297
- displayMonths: o,
298
- goToMonth: a,
299
- goToDate: u,
300
- previousMonth: l,
301
- nextMonth: i,
302
- isDateDisplayed: d
403
+ var value = {
404
+ currentMonth,
405
+ displayMonths,
406
+ goToMonth,
407
+ goToDate,
408
+ previousMonth,
409
+ nextMonth,
410
+ isDateDisplayed
303
411
  };
304
- return s(Nt.Provider, { value: c, children: e.children });
412
+ return jsx(NavigationContext.Provider, { value, children: props.children });
305
413
  }
306
- function ce() {
307
- var e = re(Nt);
308
- if (!e)
414
+ function useNavigation() {
415
+ var context = useContext(NavigationContext);
416
+ if (!context) {
309
417
  throw new Error("useNavigation must be used within a NavigationProvider");
310
- return e;
311
- }
312
- function st(e) {
313
- var t, n = k(), r = n.classNames, a = n.styles, o = n.components, i = ce().goToMonth, l = function(c) {
314
- i(j(c, e.displayIndex ? -e.displayIndex : 0));
315
- }, d = (t = o == null ? void 0 : o.CaptionLabel) !== null && t !== void 0 ? t : Mt, u = s(d, { id: e.id, displayMonth: e.displayMonth });
316
- return L("div", { className: r.caption_dropdowns, style: a.caption_dropdowns, children: [s("div", { className: r.vhidden, children: u }), s(jn, { onChange: l, displayMonth: e.displayMonth }), s(Vn, { onChange: l, displayMonth: e.displayMonth })] });
418
+ }
419
+ return context;
420
+ }
421
+ function CaptionDropdowns(props) {
422
+ var _a;
423
+ var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
424
+ var goToMonth = useNavigation().goToMonth;
425
+ var handleMonthChange = function(newMonth) {
426
+ goToMonth(addMonths(newMonth, props.displayIndex ? -props.displayIndex : 0));
427
+ };
428
+ var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
429
+ var captionLabel = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
430
+ return jsxs("div", { className: classNames2.caption_dropdowns, style: styles2.caption_dropdowns, children: [jsx("div", { className: classNames2.vhidden, children: captionLabel }), jsx(MonthsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth }), jsx(YearsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth })] });
317
431
  }
318
- function Jn(e) {
319
- return s("svg", g({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, e, { children: s("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" }) }));
432
+ function IconLeft(props) {
433
+ return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" }) }));
320
434
  }
321
- function Qn(e) {
322
- return s("svg", g({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, e, { children: s("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" }) }));
435
+ function IconRight(props) {
436
+ return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" }) }));
323
437
  }
324
- var _e = Ut(function(e, t) {
325
- var n = k(), r = n.classNames, a = n.styles, o = [r.button_reset, r.button];
326
- e.className && o.push(e.className);
327
- var i = o.join(" "), l = g(g({}, a.button_reset), a.button);
328
- return e.style && Object.assign(l, e.style), s("button", g({}, e, { ref: t, type: "button", className: i, style: l }));
438
+ var Button = forwardRef(function(props, ref) {
439
+ var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
440
+ var classNamesArr = [classNames2.button_reset, classNames2.button];
441
+ if (props.className) {
442
+ classNamesArr.push(props.className);
443
+ }
444
+ var className = classNamesArr.join(" ");
445
+ var style = __assign(__assign({}, styles2.button_reset), styles2.button);
446
+ if (props.style) {
447
+ Object.assign(style, props.style);
448
+ }
449
+ return jsx("button", __assign({}, props, { ref, type: "button", className, style }));
329
450
  });
330
- function zn(e) {
331
- var t, n, r = k(), a = r.dir, o = r.locale, i = r.classNames, l = r.styles, d = r.labels, u = d.labelPrevious, c = d.labelNext, f = r.components;
332
- if (!e.nextMonth && !e.previousMonth)
333
- return s(A, {});
334
- var v = u(e.previousMonth, { locale: o }), m = [
335
- i.nav_button,
336
- i.nav_button_previous
337
- ].join(" "), y = c(e.nextMonth, { locale: o }), _ = [
338
- i.nav_button,
339
- i.nav_button_next
340
- ].join(" "), p = (t = f == null ? void 0 : f.IconRight) !== null && t !== void 0 ? t : Qn, D = (n = f == null ? void 0 : f.IconLeft) !== null && n !== void 0 ? n : Jn;
341
- return L("div", { className: i.nav, style: l.nav, children: [!e.hidePrevious && s(_e, { name: "previous-month", "aria-label": v, className: m, style: l.nav_button_previous, disabled: !e.previousMonth, onClick: e.onPreviousClick, children: a === "rtl" ? s(p, { className: i.nav_icon, style: l.nav_icon }) : s(D, { className: i.nav_icon, style: l.nav_icon }) }), !e.hideNext && s(_e, { name: "next-month", "aria-label": y, className: _, style: l.nav_button_next, disabled: !e.nextMonth, onClick: e.onNextClick, children: a === "rtl" ? s(D, { className: i.nav_icon, style: l.nav_icon }) : s(p, { className: i.nav_icon, style: l.nav_icon }) })] });
342
- }
343
- function dt(e) {
344
- var t = k().numberOfMonths, n = ce(), r = n.previousMonth, a = n.nextMonth, o = n.goToMonth, i = n.displayMonths, l = i.findIndex(function(y) {
345
- return Ae(e.displayMonth, y);
346
- }), d = l === 0, u = l === i.length - 1, c = t > 1 && (d || !u), f = t > 1 && (u || !d), v = function() {
347
- r && o(r);
348
- }, m = function() {
349
- a && o(a);
451
+ function Navigation(props) {
452
+ var _a, _b;
453
+ var _c = useDayPicker(), dir = _c.dir, locale = _c.locale, classNames2 = _c.classNames, styles2 = _c.styles, _d = _c.labels, labelPrevious2 = _d.labelPrevious, labelNext2 = _d.labelNext, components = _c.components;
454
+ if (!props.nextMonth && !props.previousMonth) {
455
+ return jsx(Fragment, {});
456
+ }
457
+ var previousLabel = labelPrevious2(props.previousMonth, { locale });
458
+ var previousClassName = [
459
+ classNames2.nav_button,
460
+ classNames2.nav_button_previous
461
+ ].join(" ");
462
+ var nextLabel = labelNext2(props.nextMonth, { locale });
463
+ var nextClassName = [
464
+ classNames2.nav_button,
465
+ classNames2.nav_button_next
466
+ ].join(" ");
467
+ var IconRightComponent = (_a = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _a !== void 0 ? _a : IconRight;
468
+ var IconLeftComponent = (_b = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _b !== void 0 ? _b : IconLeft;
469
+ return jsxs("div", { className: classNames2.nav, style: styles2.nav, children: [!props.hidePrevious && jsx(Button, { name: "previous-month", "aria-label": previousLabel, className: previousClassName, style: styles2.nav_button_previous, disabled: !props.previousMonth, onClick: props.onPreviousClick, children: dir === "rtl" ? jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) }), !props.hideNext && jsx(Button, { name: "next-month", "aria-label": nextLabel, className: nextClassName, style: styles2.nav_button_next, disabled: !props.nextMonth, onClick: props.onNextClick, children: dir === "rtl" ? jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) })] });
470
+ }
471
+ function CaptionNavigation(props) {
472
+ var numberOfMonths = useDayPicker().numberOfMonths;
473
+ var _a = useNavigation(), previousMonth = _a.previousMonth, nextMonth = _a.nextMonth, goToMonth = _a.goToMonth, displayMonths = _a.displayMonths;
474
+ var displayIndex = displayMonths.findIndex(function(month) {
475
+ return isSameMonth(props.displayMonth, month);
476
+ });
477
+ var isFirst = displayIndex === 0;
478
+ var isLast = displayIndex === displayMonths.length - 1;
479
+ var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
480
+ var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
481
+ var handlePreviousClick = function() {
482
+ if (!previousMonth)
483
+ return;
484
+ goToMonth(previousMonth);
350
485
  };
351
- return s(zn, { displayMonth: e.displayMonth, hideNext: c, hidePrevious: f, nextMonth: a, previousMonth: r, onPreviousClick: v, onNextClick: m });
352
- }
353
- function er(e) {
354
- var t, n = k(), r = n.classNames, a = n.disableNavigation, o = n.styles, i = n.captionLayout, l = n.components, d = (t = l == null ? void 0 : l.CaptionLabel) !== null && t !== void 0 ? t : Mt, u;
355
- return a ? u = s(d, { id: e.id, displayMonth: e.displayMonth }) : i === "dropdown" ? u = s(st, { displayMonth: e.displayMonth, id: e.id }) : i === "dropdown-buttons" ? u = L(A, { children: [s(st, { displayMonth: e.displayMonth, displayIndex: e.displayIndex, id: e.id }), s(dt, { displayMonth: e.displayMonth, displayIndex: e.displayIndex, id: e.id })] }) : u = L(A, { children: [s(d, { id: e.id, displayMonth: e.displayMonth, displayIndex: e.displayIndex }), s(dt, { displayMonth: e.displayMonth, id: e.id })] }), s("div", { className: r.caption, style: o.caption, children: u });
356
- }
357
- function tr(e) {
358
- var t = k(), n = t.footer, r = t.styles, a = t.classNames.tfoot;
359
- return n ? s("tfoot", { className: a, style: r.tfoot, children: s("tr", { children: s("td", { colSpan: 8, children: n }) }) }) : s(A, {});
360
- }
361
- function nr(e, t, n) {
362
- for (var r = n ? Ye(/* @__PURE__ */ new Date()) : je(/* @__PURE__ */ new Date(), { locale: e, weekStartsOn: t }), a = [], o = 0; o < 7; o++) {
363
- var i = W(r, o);
364
- a.push(i);
486
+ var handleNextClick = function() {
487
+ if (!nextMonth)
488
+ return;
489
+ goToMonth(nextMonth);
490
+ };
491
+ return jsx(Navigation, { displayMonth: props.displayMonth, hideNext, hidePrevious, nextMonth, previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick });
492
+ }
493
+ function Caption(props) {
494
+ var _a;
495
+ var _b = useDayPicker(), classNames2 = _b.classNames, disableNavigation = _b.disableNavigation, styles2 = _b.styles, captionLayout = _b.captionLayout, components = _b.components;
496
+ var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
497
+ var caption;
498
+ if (disableNavigation) {
499
+ caption = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
500
+ } else if (captionLayout === "dropdown") {
501
+ caption = jsx(CaptionDropdowns, { displayMonth: props.displayMonth, id: props.id });
502
+ } else if (captionLayout === "dropdown-buttons") {
503
+ caption = jsxs(Fragment, { children: [jsx(CaptionDropdowns, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id })] });
504
+ } else {
505
+ caption = jsxs(Fragment, { children: [jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id })] });
365
506
  }
366
- return a;
507
+ return jsx("div", { className: classNames2.caption, style: styles2.caption, children: caption });
508
+ }
509
+ function Footer(props) {
510
+ var _a = useDayPicker(), footer = _a.footer, styles2 = _a.styles, tfoot = _a.classNames.tfoot;
511
+ if (!footer)
512
+ return jsx(Fragment, {});
513
+ return jsx("tfoot", { className: tfoot, style: styles2.tfoot, children: jsx("tr", { children: jsx("td", { colSpan: 8, children: footer }) }) });
514
+ }
515
+ function getWeekdays(locale, weekStartsOn, ISOWeek) {
516
+ var start = ISOWeek ? startOfISOWeek(/* @__PURE__ */ new Date()) : startOfWeek(/* @__PURE__ */ new Date(), { locale, weekStartsOn });
517
+ var days = [];
518
+ for (var i = 0; i < 7; i++) {
519
+ var day = addDays(start, i);
520
+ days.push(day);
521
+ }
522
+ return days;
367
523
  }
368
- function rr() {
369
- var e = k(), t = e.classNames, n = e.styles, r = e.showWeekNumber, a = e.locale, o = e.weekStartsOn, i = e.ISOWeek, l = e.formatters.formatWeekdayName, d = e.labels.labelWeekday, u = nr(a, o, i);
370
- return L("tr", { style: n.head_row, className: t.head_row, children: [r && s("td", { style: n.head_cell, className: t.head_cell }), u.map(function(c, f) {
371
- return s("th", { scope: "col", className: t.head_cell, style: n.head_cell, "aria-label": d(c, { locale: a }), children: l(c, { locale: a }) }, f);
524
+ function HeadRow() {
525
+ var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, weekStartsOn = _a.weekStartsOn, ISOWeek = _a.ISOWeek, formatWeekdayName2 = _a.formatters.formatWeekdayName, labelWeekday2 = _a.labels.labelWeekday;
526
+ var weekdays = getWeekdays(locale, weekStartsOn, ISOWeek);
527
+ return jsxs("tr", { style: styles2.head_row, className: classNames2.head_row, children: [showWeekNumber && jsx("td", { style: styles2.head_cell, className: classNames2.head_cell }), weekdays.map(function(weekday, i) {
528
+ return jsx("th", { scope: "col", className: classNames2.head_cell, style: styles2.head_cell, "aria-label": labelWeekday2(weekday, { locale }), children: formatWeekdayName2(weekday, { locale }) }, i);
372
529
  })] });
373
530
  }
374
- function ar() {
375
- var e, t = k(), n = t.classNames, r = t.styles, a = t.components, o = (e = a == null ? void 0 : a.HeadRow) !== null && e !== void 0 ? e : rr;
376
- return s("thead", { style: r.head, className: n.head, children: s(o, {}) });
531
+ function Head() {
532
+ var _a;
533
+ var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
534
+ var HeadRowComponent = (_a = components === null || components === void 0 ? void 0 : components.HeadRow) !== null && _a !== void 0 ? _a : HeadRow;
535
+ return jsx("thead", { style: styles2.head, className: classNames2.head, children: jsx(HeadRowComponent, {}) });
377
536
  }
378
- function or(e) {
379
- var t = k(), n = t.locale, r = t.formatters.formatDay;
380
- return s(A, { children: r(e.date, { locale: n }) });
537
+ function DayContent(props) {
538
+ var _a = useDayPicker(), locale = _a.locale, formatDay2 = _a.formatters.formatDay;
539
+ return jsx(Fragment, { children: formatDay2(props.date, { locale }) });
381
540
  }
382
- var Ve = ne(void 0);
383
- function ir(e) {
384
- if (!de(e.initialProps)) {
385
- var t = {
541
+ var SelectMultipleContext = createContext(void 0);
542
+ function SelectMultipleProvider(props) {
543
+ if (!isDayPickerMultiple(props.initialProps)) {
544
+ var emptyContextValue = {
386
545
  selected: void 0,
387
546
  modifiers: {
388
547
  disabled: []
389
548
  }
390
549
  };
391
- return s(Ve.Provider, { value: t, children: e.children });
392
- }
393
- return s(lr, { initialProps: e.initialProps, children: e.children });
394
- }
395
- function lr(e) {
396
- var t = e.initialProps, n = e.children, r = t.selected, a = t.min, o = t.max, i = function(u, c, f) {
397
- var v, m;
398
- (v = t.onDayClick) === null || v === void 0 || v.call(t, u, c, f);
399
- var y = !!(c.selected && a && (r == null ? void 0 : r.length) === a);
400
- if (!y) {
401
- var _ = !!(!c.selected && o && (r == null ? void 0 : r.length) === o);
402
- if (!_) {
403
- var p = r ? wt([], r) : [];
404
- if (c.selected) {
405
- var D = p.findIndex(function(M) {
406
- return N(u, M);
407
- });
408
- p.splice(D, 1);
409
- } else
410
- p.push(u);
411
- (m = t.onSelect) === null || m === void 0 || m.call(t, p, u, c, f);
412
- }
550
+ return jsx(SelectMultipleContext.Provider, { value: emptyContextValue, children: props.children });
551
+ }
552
+ return jsx(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children });
553
+ }
554
+ function SelectMultipleProviderInternal(_a) {
555
+ var initialProps = _a.initialProps, children = _a.children;
556
+ var selected = initialProps.selected, min2 = initialProps.min, max2 = initialProps.max;
557
+ var onDayClick = function(day, activeModifiers, e) {
558
+ var _a2, _b;
559
+ (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
560
+ var isMinSelected = Boolean(activeModifiers.selected && min2 && (selected === null || selected === void 0 ? void 0 : selected.length) === min2);
561
+ if (isMinSelected) {
562
+ return;
413
563
  }
414
- }, l = {
564
+ var isMaxSelected = Boolean(!activeModifiers.selected && max2 && (selected === null || selected === void 0 ? void 0 : selected.length) === max2);
565
+ if (isMaxSelected) {
566
+ return;
567
+ }
568
+ var selectedDays = selected ? __spreadArray([], selected) : [];
569
+ if (activeModifiers.selected) {
570
+ var index = selectedDays.findIndex(function(selectedDay) {
571
+ return isSameDay(day, selectedDay);
572
+ });
573
+ selectedDays.splice(index, 1);
574
+ } else {
575
+ selectedDays.push(day);
576
+ }
577
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, selectedDays, day, activeModifiers, e);
578
+ };
579
+ var modifiers = {
415
580
  disabled: []
416
581
  };
417
- r && l.disabled.push(function(u) {
418
- var c = o && r.length > o - 1, f = r.some(function(v) {
419
- return N(v, u);
582
+ if (selected) {
583
+ modifiers.disabled.push(function(day) {
584
+ var isMaxSelected = max2 && selected.length > max2 - 1;
585
+ var isSelected = selected.some(function(selectedDay) {
586
+ return isSameDay(selectedDay, day);
587
+ });
588
+ return Boolean(isMaxSelected && !isSelected);
420
589
  });
421
- return !!(c && !f);
422
- });
423
- var d = {
424
- selected: r,
425
- onDayClick: i,
426
- modifiers: l
590
+ }
591
+ var contextValue = {
592
+ selected,
593
+ onDayClick,
594
+ modifiers
427
595
  };
428
- return s(Ve.Provider, { value: d, children: n });
596
+ return jsx(SelectMultipleContext.Provider, { value: contextValue, children });
429
597
  }
430
- function Ke() {
431
- var e = re(Ve);
432
- if (!e)
598
+ function useSelectMultiple() {
599
+ var context = useContext(SelectMultipleContext);
600
+ if (!context) {
433
601
  throw new Error("useSelectMultiple must be used within a SelectMultipleProvider");
434
- return e;
602
+ }
603
+ return context;
435
604
  }
436
- function sr(e, t) {
437
- var n = t || {}, r = n.from, a = n.to;
438
- return r && a ? N(a, e) && N(r, e) ? void 0 : N(a, e) ? { from: a, to: void 0 } : N(r, e) ? void 0 : ge(r, e) ? { from: e, to: a } : { from: r, to: e } : a ? ge(e, a) ? { from: a, to: e } : { from: e, to: a } : r ? He(e, r) ? { from: e, to: r } : { from: r, to: e } : { from: e, to: void 0 };
605
+ function addToRange(day, range) {
606
+ var _a = range || {}, from = _a.from, to = _a.to;
607
+ if (from && to) {
608
+ if (isSameDay(to, day) && isSameDay(from, day)) {
609
+ return void 0;
610
+ }
611
+ if (isSameDay(to, day)) {
612
+ return { from: to, to: void 0 };
613
+ }
614
+ if (isSameDay(from, day)) {
615
+ return void 0;
616
+ }
617
+ if (isAfter(from, day)) {
618
+ return { from: day, to };
619
+ }
620
+ return { from, to: day };
621
+ }
622
+ if (to) {
623
+ if (isAfter(day, to)) {
624
+ return { from: to, to: day };
625
+ }
626
+ return { from: day, to };
627
+ }
628
+ if (from) {
629
+ if (isBefore(day, from)) {
630
+ return { from: day, to: from };
631
+ }
632
+ return { from, to: day };
633
+ }
634
+ return { from: day, to: void 0 };
439
635
  }
440
- var Ue = ne(void 0);
441
- function dr(e) {
442
- if (!ue(e.initialProps)) {
443
- var t = {
636
+ var SelectRangeContext = createContext(void 0);
637
+ function SelectRangeProvider(props) {
638
+ if (!isDayPickerRange(props.initialProps)) {
639
+ var emptyContextValue = {
444
640
  selected: void 0,
445
641
  modifiers: {
446
642
  range_start: [],
@@ -449,866 +645,1439 @@ function dr(e) {
449
645
  disabled: []
450
646
  }
451
647
  };
452
- return s(Ue.Provider, { value: t, children: e.children });
648
+ return jsx(SelectRangeContext.Provider, { value: emptyContextValue, children: props.children });
453
649
  }
454
- return s(ur, { initialProps: e.initialProps, children: e.children });
455
- }
456
- function ur(e) {
457
- var t = e.initialProps, n = e.children, r = t.selected, a = r || {}, o = a.from, i = a.to, l = t.min, d = t.max, u = function(m, y, _) {
458
- var p, D;
459
- (p = t.onDayClick) === null || p === void 0 || p.call(t, m, y, _);
460
- var M = sr(m, r);
461
- (D = t.onSelect) === null || D === void 0 || D.call(t, M, m, y, _);
462
- }, c = {
650
+ return jsx(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children });
651
+ }
652
+ function SelectRangeProviderInternal(_a) {
653
+ var initialProps = _a.initialProps, children = _a.children;
654
+ var selected = initialProps.selected;
655
+ var _b = selected || {}, selectedFrom = _b.from, selectedTo = _b.to;
656
+ var min2 = initialProps.min;
657
+ var max2 = initialProps.max;
658
+ var onDayClick = function(day, activeModifiers, e) {
659
+ var _a2, _b2;
660
+ (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
661
+ var newRange = addToRange(day, selected);
662
+ (_b2 = initialProps.onSelect) === null || _b2 === void 0 ? void 0 : _b2.call(initialProps, newRange, day, activeModifiers, e);
663
+ };
664
+ var modifiers = {
463
665
  range_start: [],
464
666
  range_end: [],
465
667
  range_middle: [],
466
668
  disabled: []
467
669
  };
468
- if (o ? (c.range_start = [o], i ? (c.range_end = [i], N(o, i) || (c.range_middle = [
469
- {
470
- after: o,
471
- before: i
472
- }
473
- ])) : c.range_end = [o]) : i && (c.range_start = [i], c.range_end = [i]), l && (o && !i && c.disabled.push({
474
- after: Ce(o, l - 1),
475
- before: W(o, l - 1)
476
- }), o && i && c.disabled.push({
477
- after: o,
478
- before: W(o, l - 1)
479
- }), !o && i && c.disabled.push({
480
- after: Ce(i, l - 1),
481
- before: W(i, l - 1)
482
- })), d) {
483
- if (o && !i && (c.disabled.push({
484
- before: W(o, -d + 1)
485
- }), c.disabled.push({
486
- after: W(o, d - 1)
487
- })), o && i) {
488
- var f = U(i, o) + 1, v = d - f;
489
- c.disabled.push({
490
- before: Ce(o, v)
491
- }), c.disabled.push({
492
- after: W(i, v)
670
+ if (selectedFrom) {
671
+ modifiers.range_start = [selectedFrom];
672
+ if (!selectedTo) {
673
+ modifiers.range_end = [selectedFrom];
674
+ } else {
675
+ modifiers.range_end = [selectedTo];
676
+ if (!isSameDay(selectedFrom, selectedTo)) {
677
+ modifiers.range_middle = [
678
+ {
679
+ after: selectedFrom,
680
+ before: selectedTo
681
+ }
682
+ ];
683
+ }
684
+ }
685
+ } else if (selectedTo) {
686
+ modifiers.range_start = [selectedTo];
687
+ modifiers.range_end = [selectedTo];
688
+ }
689
+ if (min2) {
690
+ if (selectedFrom && !selectedTo) {
691
+ modifiers.disabled.push({
692
+ after: subDays(selectedFrom, min2 - 1),
693
+ before: addDays(selectedFrom, min2 - 1)
694
+ });
695
+ }
696
+ if (selectedFrom && selectedTo) {
697
+ modifiers.disabled.push({
698
+ after: selectedFrom,
699
+ before: addDays(selectedFrom, min2 - 1)
700
+ });
701
+ }
702
+ if (!selectedFrom && selectedTo) {
703
+ modifiers.disabled.push({
704
+ after: subDays(selectedTo, min2 - 1),
705
+ before: addDays(selectedTo, min2 - 1)
706
+ });
707
+ }
708
+ }
709
+ if (max2) {
710
+ if (selectedFrom && !selectedTo) {
711
+ modifiers.disabled.push({
712
+ before: addDays(selectedFrom, -max2 + 1)
713
+ });
714
+ modifiers.disabled.push({
715
+ after: addDays(selectedFrom, max2 - 1)
716
+ });
717
+ }
718
+ if (selectedFrom && selectedTo) {
719
+ var selectedCount = differenceInCalendarDays(selectedTo, selectedFrom) + 1;
720
+ var offset = max2 - selectedCount;
721
+ modifiers.disabled.push({
722
+ before: subDays(selectedFrom, offset)
723
+ });
724
+ modifiers.disabled.push({
725
+ after: addDays(selectedTo, offset)
726
+ });
727
+ }
728
+ if (!selectedFrom && selectedTo) {
729
+ modifiers.disabled.push({
730
+ before: addDays(selectedTo, -max2 + 1)
731
+ });
732
+ modifiers.disabled.push({
733
+ after: addDays(selectedTo, max2 - 1)
493
734
  });
494
735
  }
495
- !o && i && (c.disabled.push({
496
- before: W(i, -d + 1)
497
- }), c.disabled.push({
498
- after: W(i, d - 1)
499
- }));
500
736
  }
501
- return s(Ue.Provider, { value: { selected: r, onDayClick: u, modifiers: c }, children: n });
737
+ return jsx(SelectRangeContext.Provider, { value: { selected, onDayClick, modifiers }, children });
502
738
  }
503
- function Xe() {
504
- var e = re(Ue);
505
- if (!e)
739
+ function useSelectRange() {
740
+ var context = useContext(SelectRangeContext);
741
+ if (!context) {
506
742
  throw new Error("useSelectRange must be used within a SelectRangeProvider");
507
- return e;
508
- }
509
- function be(e) {
510
- return Array.isArray(e) ? wt([], e) : e !== void 0 ? [e] : [];
743
+ }
744
+ return context;
745
+ }
746
+ function matcherToArray(matcher) {
747
+ if (Array.isArray(matcher)) {
748
+ return __spreadArray([], matcher);
749
+ } else if (matcher !== void 0) {
750
+ return [matcher];
751
+ } else {
752
+ return [];
753
+ }
511
754
  }
512
- function cr(e) {
513
- var t = {};
514
- return Object.entries(e).forEach(function(n) {
515
- var r = n[0], a = n[1];
516
- t[r] = be(a);
517
- }), t;
518
- }
519
- var H;
520
- (function(e) {
521
- e.Outside = "outside", e.Disabled = "disabled", e.Selected = "selected", e.Hidden = "hidden", e.Today = "today", e.RangeStart = "range_start", e.RangeEnd = "range_end", e.RangeMiddle = "range_middle";
522
- })(H || (H = {}));
523
- var fr = H.Selected, K = H.Disabled, vr = H.Hidden, mr = H.Today, xe = H.RangeEnd, Oe = H.RangeMiddle, Ie = H.RangeStart, hr = H.Outside;
524
- function pr(e, t, n) {
525
- var r, a = (r = {}, r[fr] = be(e.selected), r[K] = be(e.disabled), r[vr] = be(e.hidden), r[mr] = [e.today], r[xe] = [], r[Oe] = [], r[Ie] = [], r[hr] = [], r);
526
- return e.fromDate && a[K].push({ before: e.fromDate }), e.toDate && a[K].push({ after: e.toDate }), de(e) ? a[K] = a[K].concat(t.modifiers[K]) : ue(e) && (a[K] = a[K].concat(n.modifiers[K]), a[Ie] = n.modifiers[Ie], a[Oe] = n.modifiers[Oe], a[xe] = n.modifiers[xe]), a;
527
- }
528
- var Ct = ne(void 0);
529
- function yr(e) {
530
- var t = k(), n = Ke(), r = Xe(), a = pr(t, n, r), o = cr(t.modifiers), i = g(g({}, a), o);
531
- return s(Ct.Provider, { value: i, children: e.children });
532
- }
533
- function Pt() {
534
- var e = re(Ct);
535
- if (!e)
755
+ function getCustomModifiers(dayModifiers) {
756
+ var customModifiers = {};
757
+ Object.entries(dayModifiers).forEach(function(_a) {
758
+ var modifier = _a[0], matcher = _a[1];
759
+ customModifiers[modifier] = matcherToArray(matcher);
760
+ });
761
+ return customModifiers;
762
+ }
763
+ var InternalModifier;
764
+ (function(InternalModifier2) {
765
+ InternalModifier2["Outside"] = "outside";
766
+ InternalModifier2["Disabled"] = "disabled";
767
+ InternalModifier2["Selected"] = "selected";
768
+ InternalModifier2["Hidden"] = "hidden";
769
+ InternalModifier2["Today"] = "today";
770
+ InternalModifier2["RangeStart"] = "range_start";
771
+ InternalModifier2["RangeEnd"] = "range_end";
772
+ InternalModifier2["RangeMiddle"] = "range_middle";
773
+ })(InternalModifier || (InternalModifier = {}));
774
+ var Selected = InternalModifier.Selected, Disabled = InternalModifier.Disabled, Hidden = InternalModifier.Hidden, Today = InternalModifier.Today, RangeEnd = InternalModifier.RangeEnd, RangeMiddle = InternalModifier.RangeMiddle, RangeStart = InternalModifier.RangeStart, Outside = InternalModifier.Outside;
775
+ function getInternalModifiers(dayPicker, selectMultiple, selectRange) {
776
+ var _a;
777
+ var internalModifiers = (_a = {}, _a[Selected] = matcherToArray(dayPicker.selected), _a[Disabled] = matcherToArray(dayPicker.disabled), _a[Hidden] = matcherToArray(dayPicker.hidden), _a[Today] = [dayPicker.today], _a[RangeEnd] = [], _a[RangeMiddle] = [], _a[RangeStart] = [], _a[Outside] = [], _a);
778
+ if (dayPicker.fromDate) {
779
+ internalModifiers[Disabled].push({ before: dayPicker.fromDate });
780
+ }
781
+ if (dayPicker.toDate) {
782
+ internalModifiers[Disabled].push({ after: dayPicker.toDate });
783
+ }
784
+ if (isDayPickerMultiple(dayPicker)) {
785
+ internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectMultiple.modifiers[Disabled]);
786
+ } else if (isDayPickerRange(dayPicker)) {
787
+ internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectRange.modifiers[Disabled]);
788
+ internalModifiers[RangeStart] = selectRange.modifiers[RangeStart];
789
+ internalModifiers[RangeMiddle] = selectRange.modifiers[RangeMiddle];
790
+ internalModifiers[RangeEnd] = selectRange.modifiers[RangeEnd];
791
+ }
792
+ return internalModifiers;
793
+ }
794
+ var ModifiersContext = createContext(void 0);
795
+ function ModifiersProvider(props) {
796
+ var dayPicker = useDayPicker();
797
+ var selectMultiple = useSelectMultiple();
798
+ var selectRange = useSelectRange();
799
+ var internalModifiers = getInternalModifiers(dayPicker, selectMultiple, selectRange);
800
+ var customModifiers = getCustomModifiers(dayPicker.modifiers);
801
+ var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
802
+ return jsx(ModifiersContext.Provider, { value: modifiers, children: props.children });
803
+ }
804
+ function useModifiers() {
805
+ var context = useContext(ModifiersContext);
806
+ if (!context) {
536
807
  throw new Error("useModifiers must be used within a ModifiersProvider");
537
- return e;
538
- }
539
- function br(e) {
540
- return !!(e && typeof e == "object" && "before" in e && "after" in e);
541
- }
542
- function gr(e) {
543
- return !!(e && typeof e == "object" && "from" in e);
544
- }
545
- function _r(e) {
546
- return !!(e && typeof e == "object" && "after" in e);
547
- }
548
- function wr(e) {
549
- return !!(e && typeof e == "object" && "before" in e);
550
- }
551
- function Dr(e) {
552
- return !!(e && typeof e == "object" && "dayOfWeek" in e);
553
- }
554
- function Mr(e, t) {
555
- var n, r = t.from, a = t.to;
556
- if (r && a) {
557
- var o = U(a, r) < 0;
558
- o && (n = [a, r], r = n[0], a = n[1]);
559
- var i = U(e, r) >= 0 && U(a, e) >= 0;
560
- return i;
561
- }
562
- return a ? N(a, e) : r ? N(r, e) : !1;
563
- }
564
- function kr(e) {
565
- return yt(e);
566
- }
567
- function Nr(e) {
568
- return Array.isArray(e) && e.every(yt);
569
- }
570
- function Cr(e, t) {
571
- return t.some(function(n) {
572
- if (typeof n == "boolean")
573
- return n;
574
- if (kr(n))
575
- return N(e, n);
576
- if (Nr(n))
577
- return n.includes(e);
578
- if (gr(n))
579
- return Mr(e, n);
580
- if (Dr(n))
581
- return n.dayOfWeek.includes(e.getDay());
582
- if (br(n)) {
583
- var r = U(n.before, e), a = U(n.after, e), o = r > 0, i = a < 0, l = ge(n.before, n.after);
584
- return l ? i && o : o || i;
585
- }
586
- return _r(n) ? U(e, n.after) > 0 : wr(n) ? U(n.before, e) > 0 : typeof n == "function" ? n(e) : !1;
808
+ }
809
+ return context;
810
+ }
811
+ function isDateInterval(matcher) {
812
+ return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
813
+ }
814
+ function isDateRange(value) {
815
+ return Boolean(value && typeof value === "object" && "from" in value);
816
+ }
817
+ function isDateAfterType(value) {
818
+ return Boolean(value && typeof value === "object" && "after" in value);
819
+ }
820
+ function isDateBeforeType(value) {
821
+ return Boolean(value && typeof value === "object" && "before" in value);
822
+ }
823
+ function isDayOfWeekType(value) {
824
+ return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
825
+ }
826
+ function isDateInRange(date, range) {
827
+ var _a;
828
+ var from = range.from, to = range.to;
829
+ if (from && to) {
830
+ var isRangeInverted = differenceInCalendarDays(to, from) < 0;
831
+ if (isRangeInverted) {
832
+ _a = [to, from], from = _a[0], to = _a[1];
833
+ }
834
+ var isInRange = differenceInCalendarDays(date, from) >= 0 && differenceInCalendarDays(to, date) >= 0;
835
+ return isInRange;
836
+ }
837
+ if (to) {
838
+ return isSameDay(to, date);
839
+ }
840
+ if (from) {
841
+ return isSameDay(from, date);
842
+ }
843
+ return false;
844
+ }
845
+ function isDateType(value) {
846
+ return isDate(value);
847
+ }
848
+ function isArrayOfDates(value) {
849
+ return Array.isArray(value) && value.every(isDate);
850
+ }
851
+ function isMatch(day, matchers) {
852
+ return matchers.some(function(matcher) {
853
+ if (typeof matcher === "boolean") {
854
+ return matcher;
855
+ }
856
+ if (isDateType(matcher)) {
857
+ return isSameDay(day, matcher);
858
+ }
859
+ if (isArrayOfDates(matcher)) {
860
+ return matcher.includes(day);
861
+ }
862
+ if (isDateRange(matcher)) {
863
+ return isDateInRange(day, matcher);
864
+ }
865
+ if (isDayOfWeekType(matcher)) {
866
+ return matcher.dayOfWeek.includes(day.getDay());
867
+ }
868
+ if (isDateInterval(matcher)) {
869
+ var diffBefore = differenceInCalendarDays(matcher.before, day);
870
+ var diffAfter = differenceInCalendarDays(matcher.after, day);
871
+ var isDayBefore = diffBefore > 0;
872
+ var isDayAfter = diffAfter < 0;
873
+ var isClosedInterval = isAfter(matcher.before, matcher.after);
874
+ if (isClosedInterval) {
875
+ return isDayAfter && isDayBefore;
876
+ } else {
877
+ return isDayBefore || isDayAfter;
878
+ }
879
+ }
880
+ if (isDateAfterType(matcher)) {
881
+ return differenceInCalendarDays(day, matcher.after) > 0;
882
+ }
883
+ if (isDateBeforeType(matcher)) {
884
+ return differenceInCalendarDays(matcher.before, day) > 0;
885
+ }
886
+ if (typeof matcher === "function") {
887
+ return matcher(day);
888
+ }
889
+ return false;
587
890
  });
588
891
  }
589
- function Ze(e, t, n) {
590
- var r = Object.keys(t).reduce(function(o, i) {
591
- var l = t[i];
592
- return Cr(e, l) && o.push(i), o;
593
- }, []), a = {};
594
- return r.forEach(function(o) {
595
- return a[o] = !0;
596
- }), n && !Ae(e, n) && (a.outside = !0), a;
597
- }
598
- function Pr(e, t) {
599
- for (var n = S(e[0]), r = Fe(e[e.length - 1]), a, o, i = n; i <= r; ) {
600
- var l = Ze(i, t), d = !l.disabled && !l.hidden;
601
- if (!d) {
602
- i = W(i, 1);
603
- continue;
892
+ function getActiveModifiers(day, modifiers, displayMonth) {
893
+ var matchedModifiers = Object.keys(modifiers).reduce(function(result, key) {
894
+ var modifier = modifiers[key];
895
+ if (isMatch(day, modifier)) {
896
+ result.push(key);
604
897
  }
605
- if (l.selected)
606
- return i;
607
- l.today && !o && (o = i), a || (a = i), i = W(i, 1);
608
- }
609
- return o || a;
610
- }
611
- var xr = 365;
612
- function xt(e, t) {
613
- var n = t.moveBy, r = t.direction, a = t.context, o = t.modifiers, i = t.retry, l = i === void 0 ? { count: 0, lastFocused: e } : i, d = a.weekStartsOn, u = a.fromDate, c = a.toDate, f = a.locale, v = {
614
- day: W,
615
- week: Ee,
616
- month: j,
617
- year: tn,
618
- startOfWeek: function(p) {
619
- return a.ISOWeek ? Ye(p) : je(p, { locale: f, weekStartsOn: d });
620
- },
621
- endOfWeek: function(p) {
622
- return a.ISOWeek ? ht(p) : pt(p, { locale: f, weekStartsOn: d });
623
- }
624
- }, m = v[n](e, r === "after" ? 1 : -1);
625
- r === "before" && u ? m = Jt([u, m]) : r === "after" && c && (m = Qt([c, m]));
626
- var y = !0;
627
- if (o) {
628
- var _ = Ze(m, o);
629
- y = !_.disabled && !_.hidden;
630
- }
631
- return y ? m : l.count > xr ? l.lastFocused : xt(m, {
632
- moveBy: n,
633
- direction: r,
634
- context: a,
635
- modifiers: o,
636
- retry: g(g({}, l), { count: l.count + 1 })
898
+ return result;
899
+ }, []);
900
+ var activeModifiers = {};
901
+ matchedModifiers.forEach(function(modifier) {
902
+ return activeModifiers[modifier] = true;
637
903
  });
904
+ if (displayMonth && !isSameMonth(day, displayMonth)) {
905
+ activeModifiers.outside = true;
906
+ }
907
+ return activeModifiers;
908
+ }
909
+ function getInitialFocusTarget(displayMonths, modifiers) {
910
+ var firstDayInMonth = startOfMonth(displayMonths[0]);
911
+ var lastDayInMonth = endOfMonth(displayMonths[displayMonths.length - 1]);
912
+ var firstFocusableDay;
913
+ var today;
914
+ var date = firstDayInMonth;
915
+ while (date <= lastDayInMonth) {
916
+ var activeModifiers = getActiveModifiers(date, modifiers);
917
+ var isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
918
+ if (!isFocusable) {
919
+ date = addDays(date, 1);
920
+ continue;
921
+ }
922
+ if (activeModifiers.selected) {
923
+ return date;
924
+ }
925
+ if (activeModifiers.today && !today) {
926
+ today = date;
927
+ }
928
+ if (!firstFocusableDay) {
929
+ firstFocusableDay = date;
930
+ }
931
+ date = addDays(date, 1);
932
+ }
933
+ if (today) {
934
+ return today;
935
+ } else {
936
+ return firstFocusableDay;
937
+ }
638
938
  }
639
- var Ot = ne(void 0);
640
- function Or(e) {
641
- var t = ce(), n = Pt(), r = B(), a = r[0], o = r[1], i = B(), l = i[0], d = i[1], u = Pr(t.displayMonths, n), c = a ?? (l && t.isDateDisplayed(l)) ? l : u, f = function() {
642
- d(a), o(void 0);
643
- }, v = function(p) {
644
- o(p);
645
- }, m = k(), y = function(p, D) {
646
- if (a) {
647
- var M = xt(a, {
648
- moveBy: p,
649
- direction: D,
650
- context: m,
651
- modifiers: n
652
- });
653
- N(a, M) || (t.goToDate(M, a), v(M));
939
+ var MAX_RETRY = 365;
940
+ function getNextFocus(focusedDay, options) {
941
+ var moveBy = options.moveBy, direction = options.direction, context = options.context, modifiers = options.modifiers, _a = options.retry, retry = _a === void 0 ? { count: 0, lastFocused: focusedDay } : _a;
942
+ var weekStartsOn = context.weekStartsOn, fromDate = context.fromDate, toDate = context.toDate, locale = context.locale;
943
+ var moveFns = {
944
+ day: addDays,
945
+ week: addWeeks,
946
+ month: addMonths,
947
+ year: addYears,
948
+ startOfWeek: function(date) {
949
+ return context.ISOWeek ? startOfISOWeek(date) : startOfWeek(date, { locale, weekStartsOn });
950
+ },
951
+ endOfWeek: function(date) {
952
+ return context.ISOWeek ? endOfISOWeek(date) : endOfWeek(date, { locale, weekStartsOn });
654
953
  }
655
- }, _ = {
656
- focusedDay: a,
657
- focusTarget: c,
658
- blur: f,
659
- focus: v,
954
+ };
955
+ var newFocusedDay = moveFns[moveBy](focusedDay, direction === "after" ? 1 : -1);
956
+ if (direction === "before" && fromDate) {
957
+ newFocusedDay = max([fromDate, newFocusedDay]);
958
+ } else if (direction === "after" && toDate) {
959
+ newFocusedDay = min([toDate, newFocusedDay]);
960
+ }
961
+ var isFocusable = true;
962
+ if (modifiers) {
963
+ var activeModifiers = getActiveModifiers(newFocusedDay, modifiers);
964
+ isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
965
+ }
966
+ if (isFocusable) {
967
+ return newFocusedDay;
968
+ } else {
969
+ if (retry.count > MAX_RETRY) {
970
+ return retry.lastFocused;
971
+ }
972
+ return getNextFocus(newFocusedDay, {
973
+ moveBy,
974
+ direction,
975
+ context,
976
+ modifiers,
977
+ retry: __assign(__assign({}, retry), { count: retry.count + 1 })
978
+ });
979
+ }
980
+ }
981
+ var FocusContext = createContext(void 0);
982
+ function FocusProvider(props) {
983
+ var navigation = useNavigation();
984
+ var modifiers = useModifiers();
985
+ var _a = useState(), focusedDay = _a[0], setFocusedDay = _a[1];
986
+ var _b = useState(), lastFocused = _b[0], setLastFocused = _b[1];
987
+ var initialFocusTarget = getInitialFocusTarget(navigation.displayMonths, modifiers);
988
+ var focusTarget = (focusedDay !== null && focusedDay !== void 0 ? focusedDay : lastFocused && navigation.isDateDisplayed(lastFocused)) ? lastFocused : initialFocusTarget;
989
+ var blur = function() {
990
+ setLastFocused(focusedDay);
991
+ setFocusedDay(void 0);
992
+ };
993
+ var focus = function(date) {
994
+ setFocusedDay(date);
995
+ };
996
+ var context = useDayPicker();
997
+ var moveFocus = function(moveBy, direction) {
998
+ if (!focusedDay)
999
+ return;
1000
+ var nextFocused = getNextFocus(focusedDay, {
1001
+ moveBy,
1002
+ direction,
1003
+ context,
1004
+ modifiers
1005
+ });
1006
+ if (isSameDay(focusedDay, nextFocused))
1007
+ return void 0;
1008
+ navigation.goToDate(nextFocused, focusedDay);
1009
+ focus(nextFocused);
1010
+ };
1011
+ var value = {
1012
+ focusedDay,
1013
+ focusTarget,
1014
+ blur,
1015
+ focus,
660
1016
  focusDayAfter: function() {
661
- return y("day", "after");
1017
+ return moveFocus("day", "after");
662
1018
  },
663
1019
  focusDayBefore: function() {
664
- return y("day", "before");
1020
+ return moveFocus("day", "before");
665
1021
  },
666
1022
  focusWeekAfter: function() {
667
- return y("week", "after");
1023
+ return moveFocus("week", "after");
668
1024
  },
669
1025
  focusWeekBefore: function() {
670
- return y("week", "before");
1026
+ return moveFocus("week", "before");
671
1027
  },
672
1028
  focusMonthBefore: function() {
673
- return y("month", "before");
1029
+ return moveFocus("month", "before");
674
1030
  },
675
1031
  focusMonthAfter: function() {
676
- return y("month", "after");
1032
+ return moveFocus("month", "after");
677
1033
  },
678
1034
  focusYearBefore: function() {
679
- return y("year", "before");
1035
+ return moveFocus("year", "before");
680
1036
  },
681
1037
  focusYearAfter: function() {
682
- return y("year", "after");
1038
+ return moveFocus("year", "after");
683
1039
  },
684
1040
  focusStartOfWeek: function() {
685
- return y("startOfWeek", "before");
1041
+ return moveFocus("startOfWeek", "before");
686
1042
  },
687
1043
  focusEndOfWeek: function() {
688
- return y("endOfWeek", "after");
1044
+ return moveFocus("endOfWeek", "after");
689
1045
  }
690
1046
  };
691
- return s(Ot.Provider, { value: _, children: e.children });
1047
+ return jsx(FocusContext.Provider, { value, children: props.children });
692
1048
  }
693
- function Ge() {
694
- var e = re(Ot);
695
- if (!e)
1049
+ function useFocusContext() {
1050
+ var context = useContext(FocusContext);
1051
+ if (!context) {
696
1052
  throw new Error("useFocusContext must be used within a FocusProvider");
697
- return e;
1053
+ }
1054
+ return context;
698
1055
  }
699
- function Ir(e, t) {
700
- var n = Pt(), r = Ze(e, n, t);
701
- return r;
1056
+ function useActiveModifiers(day, displayMonth) {
1057
+ var modifiers = useModifiers();
1058
+ var activeModifiers = getActiveModifiers(day, modifiers, displayMonth);
1059
+ return activeModifiers;
702
1060
  }
703
- var $e = ne(void 0);
704
- function Wr(e) {
705
- if (!we(e.initialProps)) {
706
- var t = {
1061
+ var SelectSingleContext = createContext(void 0);
1062
+ function SelectSingleProvider(props) {
1063
+ if (!isDayPickerSingle(props.initialProps)) {
1064
+ var emptyContextValue = {
707
1065
  selected: void 0
708
1066
  };
709
- return s($e.Provider, { value: t, children: e.children });
1067
+ return jsx(SelectSingleContext.Provider, { value: emptyContextValue, children: props.children });
710
1068
  }
711
- return s(Sr, { initialProps: e.initialProps, children: e.children });
712
- }
713
- function Sr(e) {
714
- var t = e.initialProps, n = e.children, r = function(o, i, l) {
715
- var d, u, c;
716
- if ((d = t.onDayClick) === null || d === void 0 || d.call(t, o, i, l), i.selected && !t.required) {
717
- (u = t.onSelect) === null || u === void 0 || u.call(t, void 0, o, i, l);
1069
+ return jsx(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children });
1070
+ }
1071
+ function SelectSingleProviderInternal(_a) {
1072
+ var initialProps = _a.initialProps, children = _a.children;
1073
+ var onDayClick = function(day, activeModifiers, e) {
1074
+ var _a2, _b, _c;
1075
+ (_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
1076
+ if (activeModifiers.selected && !initialProps.required) {
1077
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, void 0, day, activeModifiers, e);
718
1078
  return;
719
1079
  }
720
- (c = t.onSelect) === null || c === void 0 || c.call(t, o, o, i, l);
721
- }, a = {
722
- selected: t.selected,
723
- onDayClick: r
1080
+ (_c = initialProps.onSelect) === null || _c === void 0 ? void 0 : _c.call(initialProps, day, day, activeModifiers, e);
1081
+ };
1082
+ var contextValue = {
1083
+ selected: initialProps.selected,
1084
+ onDayClick
724
1085
  };
725
- return s($e.Provider, { value: a, children: n });
1086
+ return jsx(SelectSingleContext.Provider, { value: contextValue, children });
726
1087
  }
727
- function It() {
728
- var e = re($e);
729
- if (!e)
1088
+ function useSelectSingle() {
1089
+ var context = useContext(SelectSingleContext);
1090
+ if (!context) {
730
1091
  throw new Error("useSelectSingle must be used within a SelectSingleProvider");
731
- return e;
732
- }
733
- function Lr(e, t) {
734
- var n = k(), r = It(), a = Ke(), o = Xe(), i = Ge(), l = i.focusDayAfter, d = i.focusDayBefore, u = i.focusWeekAfter, c = i.focusWeekBefore, f = i.blur, v = i.focus, m = i.focusMonthBefore, y = i.focusMonthAfter, _ = i.focusYearBefore, p = i.focusYearAfter, D = i.focusStartOfWeek, M = i.focusEndOfWeek, I = function(b) {
735
- var h, $, T, te;
736
- we(n) ? (h = r.onDayClick) === null || h === void 0 || h.call(r, e, t, b) : de(n) ? ($ = a.onDayClick) === null || $ === void 0 || $.call(a, e, t, b) : ue(n) ? (T = o.onDayClick) === null || T === void 0 || T.call(o, e, t, b) : (te = n.onDayClick) === null || te === void 0 || te.call(n, e, t, b);
737
- }, E = function(b) {
738
- var h;
739
- v(e), (h = n.onDayFocus) === null || h === void 0 || h.call(n, e, t, b);
740
- }, X = function(b) {
741
- var h;
742
- f(), (h = n.onDayBlur) === null || h === void 0 || h.call(n, e, t, b);
743
- }, x = function(b) {
744
- var h;
745
- (h = n.onDayMouseEnter) === null || h === void 0 || h.call(n, e, t, b);
746
- }, C = function(b) {
747
- var h;
748
- (h = n.onDayMouseLeave) === null || h === void 0 || h.call(n, e, t, b);
749
- }, Y = function(b) {
750
- var h;
751
- (h = n.onDayPointerEnter) === null || h === void 0 || h.call(n, e, t, b);
752
- }, Z = function(b) {
753
- var h;
754
- (h = n.onDayPointerLeave) === null || h === void 0 || h.call(n, e, t, b);
755
- }, Me = function(b) {
756
- var h;
757
- (h = n.onDayTouchCancel) === null || h === void 0 || h.call(n, e, t, b);
758
- }, ke = function(b) {
759
- var h;
760
- (h = n.onDayTouchEnd) === null || h === void 0 || h.call(n, e, t, b);
761
- }, fe = function(b) {
762
- var h;
763
- (h = n.onDayTouchMove) === null || h === void 0 || h.call(n, e, t, b);
764
- }, G = function(b) {
765
- var h;
766
- (h = n.onDayTouchStart) === null || h === void 0 || h.call(n, e, t, b);
767
- }, ee = function(b) {
768
- var h;
769
- (h = n.onDayKeyUp) === null || h === void 0 || h.call(n, e, t, b);
770
- }, Ne = function(b) {
771
- var h;
772
- switch (b.key) {
1092
+ }
1093
+ return context;
1094
+ }
1095
+ function useDayEventHandlers(date, activeModifiers) {
1096
+ var dayPicker = useDayPicker();
1097
+ var single = useSelectSingle();
1098
+ var multiple = useSelectMultiple();
1099
+ var range = useSelectRange();
1100
+ var _a = useFocusContext(), focusDayAfter = _a.focusDayAfter, focusDayBefore = _a.focusDayBefore, focusWeekAfter = _a.focusWeekAfter, focusWeekBefore = _a.focusWeekBefore, blur = _a.blur, focus = _a.focus, focusMonthBefore = _a.focusMonthBefore, focusMonthAfter = _a.focusMonthAfter, focusYearBefore = _a.focusYearBefore, focusYearAfter = _a.focusYearAfter, focusStartOfWeek = _a.focusStartOfWeek, focusEndOfWeek = _a.focusEndOfWeek;
1101
+ var onClick = function(e) {
1102
+ var _a2, _b, _c, _d;
1103
+ if (isDayPickerSingle(dayPicker)) {
1104
+ (_a2 = single.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(single, date, activeModifiers, e);
1105
+ } else if (isDayPickerMultiple(dayPicker)) {
1106
+ (_b = multiple.onDayClick) === null || _b === void 0 ? void 0 : _b.call(multiple, date, activeModifiers, e);
1107
+ } else if (isDayPickerRange(dayPicker)) {
1108
+ (_c = range.onDayClick) === null || _c === void 0 ? void 0 : _c.call(range, date, activeModifiers, e);
1109
+ } else {
1110
+ (_d = dayPicker.onDayClick) === null || _d === void 0 ? void 0 : _d.call(dayPicker, date, activeModifiers, e);
1111
+ }
1112
+ };
1113
+ var onFocus = function(e) {
1114
+ var _a2;
1115
+ focus(date);
1116
+ (_a2 = dayPicker.onDayFocus) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1117
+ };
1118
+ var onBlur = function(e) {
1119
+ var _a2;
1120
+ blur();
1121
+ (_a2 = dayPicker.onDayBlur) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1122
+ };
1123
+ var onMouseEnter = function(e) {
1124
+ var _a2;
1125
+ (_a2 = dayPicker.onDayMouseEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1126
+ };
1127
+ var onMouseLeave = function(e) {
1128
+ var _a2;
1129
+ (_a2 = dayPicker.onDayMouseLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1130
+ };
1131
+ var onPointerEnter = function(e) {
1132
+ var _a2;
1133
+ (_a2 = dayPicker.onDayPointerEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1134
+ };
1135
+ var onPointerLeave = function(e) {
1136
+ var _a2;
1137
+ (_a2 = dayPicker.onDayPointerLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1138
+ };
1139
+ var onTouchCancel = function(e) {
1140
+ var _a2;
1141
+ (_a2 = dayPicker.onDayTouchCancel) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1142
+ };
1143
+ var onTouchEnd = function(e) {
1144
+ var _a2;
1145
+ (_a2 = dayPicker.onDayTouchEnd) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1146
+ };
1147
+ var onTouchMove = function(e) {
1148
+ var _a2;
1149
+ (_a2 = dayPicker.onDayTouchMove) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1150
+ };
1151
+ var onTouchStart = function(e) {
1152
+ var _a2;
1153
+ (_a2 = dayPicker.onDayTouchStart) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1154
+ };
1155
+ var onKeyUp = function(e) {
1156
+ var _a2;
1157
+ (_a2 = dayPicker.onDayKeyUp) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1158
+ };
1159
+ var onKeyDown = function(e) {
1160
+ var _a2;
1161
+ switch (e.key) {
773
1162
  case "ArrowLeft":
774
- b.preventDefault(), b.stopPropagation(), n.dir === "rtl" ? l() : d();
1163
+ e.preventDefault();
1164
+ e.stopPropagation();
1165
+ dayPicker.dir === "rtl" ? focusDayAfter() : focusDayBefore();
775
1166
  break;
776
1167
  case "ArrowRight":
777
- b.preventDefault(), b.stopPropagation(), n.dir === "rtl" ? d() : l();
1168
+ e.preventDefault();
1169
+ e.stopPropagation();
1170
+ dayPicker.dir === "rtl" ? focusDayBefore() : focusDayAfter();
778
1171
  break;
779
1172
  case "ArrowDown":
780
- b.preventDefault(), b.stopPropagation(), u();
1173
+ e.preventDefault();
1174
+ e.stopPropagation();
1175
+ focusWeekAfter();
781
1176
  break;
782
1177
  case "ArrowUp":
783
- b.preventDefault(), b.stopPropagation(), c();
1178
+ e.preventDefault();
1179
+ e.stopPropagation();
1180
+ focusWeekBefore();
784
1181
  break;
785
1182
  case "PageUp":
786
- b.preventDefault(), b.stopPropagation(), b.shiftKey ? _() : m();
1183
+ e.preventDefault();
1184
+ e.stopPropagation();
1185
+ e.shiftKey ? focusYearBefore() : focusMonthBefore();
787
1186
  break;
788
1187
  case "PageDown":
789
- b.preventDefault(), b.stopPropagation(), b.shiftKey ? p() : y();
1188
+ e.preventDefault();
1189
+ e.stopPropagation();
1190
+ e.shiftKey ? focusYearAfter() : focusMonthAfter();
790
1191
  break;
791
1192
  case "Home":
792
- b.preventDefault(), b.stopPropagation(), D();
1193
+ e.preventDefault();
1194
+ e.stopPropagation();
1195
+ focusStartOfWeek();
793
1196
  break;
794
1197
  case "End":
795
- b.preventDefault(), b.stopPropagation(), M();
1198
+ e.preventDefault();
1199
+ e.stopPropagation();
1200
+ focusEndOfWeek();
796
1201
  break;
797
1202
  }
798
- (h = n.onDayKeyDown) === null || h === void 0 || h.call(n, e, t, b);
799
- }, ae = {
800
- onClick: I,
801
- onFocus: E,
802
- onBlur: X,
803
- onKeyDown: Ne,
804
- onKeyUp: ee,
805
- onMouseEnter: x,
806
- onMouseLeave: C,
807
- onPointerEnter: Y,
808
- onPointerLeave: Z,
809
- onTouchCancel: Me,
810
- onTouchEnd: ke,
811
- onTouchMove: fe,
812
- onTouchStart: G
1203
+ (_a2 = dayPicker.onDayKeyDown) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
1204
+ };
1205
+ var eventHandlers = {
1206
+ onClick,
1207
+ onFocus,
1208
+ onBlur,
1209
+ onKeyDown,
1210
+ onKeyUp,
1211
+ onMouseEnter,
1212
+ onMouseLeave,
1213
+ onPointerEnter,
1214
+ onPointerLeave,
1215
+ onTouchCancel,
1216
+ onTouchEnd,
1217
+ onTouchMove,
1218
+ onTouchStart
813
1219
  };
814
- return ae;
815
- }
816
- function Er() {
817
- var e = k(), t = It(), n = Ke(), r = Xe(), a = we(e) ? t.selected : de(e) ? n.selected : ue(e) ? r.selected : void 0;
818
- return a;
819
- }
820
- function Rr(e) {
821
- return Object.values(H).includes(e);
822
- }
823
- function Br(e, t) {
824
- var n = [e.classNames.day];
825
- return Object.keys(t).forEach(function(r) {
826
- var a = e.modifiersClassNames[r];
827
- if (a)
828
- n.push(a);
829
- else if (Rr(r)) {
830
- var o = e.classNames["day_".concat(r)];
831
- o && n.push(o);
832
- }
833
- }), n;
834
- }
835
- function Tr(e, t) {
836
- var n = g({}, e.styles.day);
837
- return Object.keys(t).forEach(function(r) {
838
- var a;
839
- n = g(g({}, n), (a = e.modifiersStyles) === null || a === void 0 ? void 0 : a[r]);
840
- }), n;
841
- }
842
- function Fr(e, t, n) {
843
- var r, a, o, i = k(), l = Ge(), d = Ir(e, t), u = Lr(e, d), c = Er(), f = !!(i.onDayClick || i.mode !== "default");
844
- z(function() {
845
- var x;
846
- d.outside || l.focusedDay && f && N(l.focusedDay, e) && ((x = n.current) === null || x === void 0 || x.focus());
1220
+ return eventHandlers;
1221
+ }
1222
+ function useSelectedDays() {
1223
+ var dayPicker = useDayPicker();
1224
+ var single = useSelectSingle();
1225
+ var multiple = useSelectMultiple();
1226
+ var range = useSelectRange();
1227
+ var selectedDays = isDayPickerSingle(dayPicker) ? single.selected : isDayPickerMultiple(dayPicker) ? multiple.selected : isDayPickerRange(dayPicker) ? range.selected : void 0;
1228
+ return selectedDays;
1229
+ }
1230
+ function isInternalModifier(modifier) {
1231
+ return Object.values(InternalModifier).includes(modifier);
1232
+ }
1233
+ function getDayClassNames(dayPicker, activeModifiers) {
1234
+ var classNames2 = [dayPicker.classNames.day];
1235
+ Object.keys(activeModifiers).forEach(function(modifier) {
1236
+ var customClassName = dayPicker.modifiersClassNames[modifier];
1237
+ if (customClassName) {
1238
+ classNames2.push(customClassName);
1239
+ } else if (isInternalModifier(modifier)) {
1240
+ var internalClassName = dayPicker.classNames["day_".concat(modifier)];
1241
+ if (internalClassName) {
1242
+ classNames2.push(internalClassName);
1243
+ }
1244
+ }
1245
+ });
1246
+ return classNames2;
1247
+ }
1248
+ function getDayStyle(dayPicker, activeModifiers) {
1249
+ var style = __assign({}, dayPicker.styles.day);
1250
+ Object.keys(activeModifiers).forEach(function(modifier) {
1251
+ var _a;
1252
+ style = __assign(__assign({}, style), (_a = dayPicker.modifiersStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
1253
+ });
1254
+ return style;
1255
+ }
1256
+ function useDayRender(day, displayMonth, buttonRef) {
1257
+ var _a;
1258
+ var _b, _c;
1259
+ var dayPicker = useDayPicker();
1260
+ var focusContext = useFocusContext();
1261
+ var activeModifiers = useActiveModifiers(day, displayMonth);
1262
+ var eventHandlers = useDayEventHandlers(day, activeModifiers);
1263
+ var selectedDays = useSelectedDays();
1264
+ var isButton = Boolean(dayPicker.onDayClick || dayPicker.mode !== "default");
1265
+ useEffect(function() {
1266
+ var _a2;
1267
+ if (activeModifiers.outside)
1268
+ return;
1269
+ if (!focusContext.focusedDay)
1270
+ return;
1271
+ if (!isButton)
1272
+ return;
1273
+ if (isSameDay(focusContext.focusedDay, day)) {
1274
+ (_a2 = buttonRef.current) === null || _a2 === void 0 ? void 0 : _a2.focus();
1275
+ }
847
1276
  }, [
848
- l.focusedDay,
849
- e,
850
- n,
851
- f,
852
- d.outside
1277
+ focusContext.focusedDay,
1278
+ day,
1279
+ buttonRef,
1280
+ isButton,
1281
+ activeModifiers.outside
853
1282
  ]);
854
- var v = Br(i, d).join(" "), m = Tr(i, d), y = !!(d.outside && !i.showOutsideDays || d.hidden), _ = (o = (a = i.components) === null || a === void 0 ? void 0 : a.DayContent) !== null && o !== void 0 ? o : or, p = s(_, { date: e, displayMonth: t, activeModifiers: d }), D = {
855
- style: m,
856
- className: v,
857
- children: p,
1283
+ var className = getDayClassNames(dayPicker, activeModifiers).join(" ");
1284
+ var style = getDayStyle(dayPicker, activeModifiers);
1285
+ var isHidden = Boolean(activeModifiers.outside && !dayPicker.showOutsideDays || activeModifiers.hidden);
1286
+ var DayContentComponent = (_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent;
1287
+ var children = jsx(DayContentComponent, { date: day, displayMonth, activeModifiers });
1288
+ var divProps = {
1289
+ style,
1290
+ className,
1291
+ children,
858
1292
  role: "gridcell"
859
- }, M = l.focusTarget && N(l.focusTarget, e) && !d.outside, I = l.focusedDay && N(l.focusedDay, e), E = g(g(g({}, D), (r = { disabled: d.disabled, role: "gridcell" }, r["aria-selected"] = d.selected, r.tabIndex = I || M ? 0 : -1, r)), u), X = {
860
- isButton: f,
861
- isHidden: y,
862
- activeModifiers: d,
863
- selectedDays: c,
864
- buttonProps: E,
865
- divProps: D
866
1293
  };
867
- return X;
868
- }
869
- function Ar(e) {
870
- var t = oe(null), n = Fr(e.date, e.displayMonth, t);
871
- return n.isHidden ? s("div", { role: "gridcell" }) : n.isButton ? s(_e, g({ name: "day", ref: t }, n.buttonProps)) : s("div", g({}, n.divProps));
872
- }
873
- function Hr(e) {
874
- var t = e.number, n = e.dates, r = k(), a = r.onWeekNumberClick, o = r.styles, i = r.classNames, l = r.locale, d = r.labels.labelWeekNumber, u = r.formatters.formatWeekNumber, c = u(Number(t), { locale: l });
875
- if (!a)
876
- return s("span", { className: i.weeknumber, style: o.weeknumber, children: c });
877
- var f = d(Number(t), { locale: l }), v = function(m) {
878
- a(t, n, m);
1294
+ var isFocusTarget = focusContext.focusTarget && isSameDay(focusContext.focusTarget, day) && !activeModifiers.outside;
1295
+ var isFocused = focusContext.focusedDay && isSameDay(focusContext.focusedDay, day);
1296
+ var buttonProps = __assign(__assign(__assign({}, divProps), (_a = { disabled: activeModifiers.disabled, role: "gridcell" }, _a["aria-selected"] = activeModifiers.selected, _a.tabIndex = isFocused || isFocusTarget ? 0 : -1, _a)), eventHandlers);
1297
+ var dayRender = {
1298
+ isButton,
1299
+ isHidden,
1300
+ activeModifiers,
1301
+ selectedDays,
1302
+ buttonProps,
1303
+ divProps
879
1304
  };
880
- return s(_e, { name: "week-number", "aria-label": f, className: i.weeknumber, style: o.weeknumber, onClick: v, children: c });
1305
+ return dayRender;
881
1306
  }
882
- function Yr(e) {
883
- var t, n, r = k(), a = r.styles, o = r.classNames, i = r.showWeekNumber, l = r.components, d = (t = l == null ? void 0 : l.Day) !== null && t !== void 0 ? t : Ar, u = (n = l == null ? void 0 : l.WeekNumber) !== null && n !== void 0 ? n : Hr, c;
884
- return i && (c = s("td", { className: o.cell, style: a.cell, children: s(u, { number: e.weekNumber, dates: e.dates }) })), L("tr", { className: o.row, style: a.row, children: [c, e.dates.map(function(f) {
885
- return s("td", { className: o.cell, style: a.cell, role: "presentation", children: s(d, { displayMonth: e.displayMonth, date: f }) }, Zt(f));
1307
+ function Day(props) {
1308
+ var buttonRef = useRef(null);
1309
+ var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
1310
+ if (dayRender.isHidden) {
1311
+ return jsx("div", { role: "gridcell" });
1312
+ }
1313
+ if (!dayRender.isButton) {
1314
+ return jsx("div", __assign({}, dayRender.divProps));
1315
+ }
1316
+ return jsx(Button, __assign({ name: "day", ref: buttonRef }, dayRender.buttonProps));
1317
+ }
1318
+ function WeekNumber(props) {
1319
+ var weekNumber = props.number, dates = props.dates;
1320
+ var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles2 = _a.styles, classNames2 = _a.classNames, locale = _a.locale, labelWeekNumber2 = _a.labels.labelWeekNumber, formatWeekNumber2 = _a.formatters.formatWeekNumber;
1321
+ var content = formatWeekNumber2(Number(weekNumber), { locale });
1322
+ if (!onWeekNumberClick) {
1323
+ return jsx("span", { className: classNames2.weeknumber, style: styles2.weeknumber, children: content });
1324
+ }
1325
+ var label = labelWeekNumber2(Number(weekNumber), { locale });
1326
+ var handleClick = function(e) {
1327
+ onWeekNumberClick(weekNumber, dates, e);
1328
+ };
1329
+ return jsx(Button, { name: "week-number", "aria-label": label, className: classNames2.weeknumber, style: styles2.weeknumber, onClick: handleClick, children: content });
1330
+ }
1331
+ function Row(props) {
1332
+ var _a, _b;
1333
+ var _c = useDayPicker(), styles2 = _c.styles, classNames2 = _c.classNames, showWeekNumber = _c.showWeekNumber, components = _c.components;
1334
+ var DayComponent = (_a = components === null || components === void 0 ? void 0 : components.Day) !== null && _a !== void 0 ? _a : Day;
1335
+ var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
1336
+ var weekNumberCell;
1337
+ if (showWeekNumber) {
1338
+ weekNumberCell = jsx("td", { className: classNames2.cell, style: styles2.cell, children: jsx(WeeknumberComponent, { number: props.weekNumber, dates: props.dates }) });
1339
+ }
1340
+ return jsxs("tr", { className: classNames2.row, style: styles2.row, children: [weekNumberCell, props.dates.map(function(date) {
1341
+ return jsx("td", { className: classNames2.cell, style: styles2.cell, role: "presentation", children: jsx(DayComponent, { displayMonth: props.displayMonth, date }) }, getUnixTime(date));
886
1342
  })] });
887
1343
  }
888
- function ut(e, t, n) {
889
- for (var r = n != null && n.ISOWeek ? ht(t) : pt(t, n), a = n != null && n.ISOWeek ? Ye(e) : je(e, n), o = U(r, a), i = [], l = 0; l <= o; l++)
890
- i.push(W(a, l));
891
- var d = i.reduce(function(u, c) {
892
- var f = n != null && n.ISOWeek ? zt(c) : en(c, n), v = u.find(function(m) {
893
- return m.weekNumber === f;
1344
+ function daysToMonthWeeks(fromDate, toDate, options) {
1345
+ var toWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? endOfISOWeek(toDate) : endOfWeek(toDate, options);
1346
+ var fromWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? startOfISOWeek(fromDate) : startOfWeek(fromDate, options);
1347
+ var nOfDays = differenceInCalendarDays(toWeek, fromWeek);
1348
+ var days = [];
1349
+ for (var i = 0; i <= nOfDays; i++) {
1350
+ days.push(addDays(fromWeek, i));
1351
+ }
1352
+ var weeksInMonth = days.reduce(function(result, date) {
1353
+ var weekNumber = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? getISOWeek(date) : getWeek(date, options);
1354
+ var existingWeek = result.find(function(value) {
1355
+ return value.weekNumber === weekNumber;
1356
+ });
1357
+ if (existingWeek) {
1358
+ existingWeek.dates.push(date);
1359
+ return result;
1360
+ }
1361
+ result.push({
1362
+ weekNumber,
1363
+ dates: [date]
894
1364
  });
895
- return v ? (v.dates.push(c), u) : (u.push({
896
- weekNumber: f,
897
- dates: [c]
898
- }), u);
1365
+ return result;
899
1366
  }, []);
900
- return d;
901
- }
902
- function jr(e, t) {
903
- var n = ut(S(e), Fe(e), t);
904
- if (t != null && t.useFixedWeeks) {
905
- var r = Gt(e, t);
906
- if (r < 6) {
907
- var a = n[n.length - 1], o = a.dates[a.dates.length - 1], i = Ee(o, 6 - r), l = ut(Ee(o, 1), i, t);
908
- n.push.apply(n, l);
909
- }
910
- }
911
- return n;
912
- }
913
- function Vr(e) {
914
- var t, n, r, a = k(), o = a.locale, i = a.classNames, l = a.styles, d = a.hideHead, u = a.fixedWeeks, c = a.components, f = a.weekStartsOn, v = a.firstWeekContainsDate, m = a.ISOWeek, y = jr(e.displayMonth, {
915
- useFixedWeeks: !!u,
916
- ISOWeek: m,
917
- locale: o,
918
- weekStartsOn: f,
919
- firstWeekContainsDate: v
920
- }), _ = (t = c == null ? void 0 : c.Head) !== null && t !== void 0 ? t : ar, p = (n = c == null ? void 0 : c.Row) !== null && n !== void 0 ? n : Yr, D = (r = c == null ? void 0 : c.Footer) !== null && r !== void 0 ? r : tr;
921
- return L("table", { id: e.id, className: i.table, style: l.table, role: "grid", "aria-labelledby": e["aria-labelledby"], children: [!d && s(_, {}), s("tbody", { className: i.tbody, style: l.tbody, children: y.map(function(M) {
922
- return s(p, { displayMonth: e.displayMonth, dates: M.dates, weekNumber: M.weekNumber }, M.weekNumber);
923
- }) }), s(D, { displayMonth: e.displayMonth })] });
924
- }
925
- function Kr() {
926
- return !!(typeof window < "u" && window.document && window.document.createElement);
927
- }
928
- var Ur = Kr() ? Xt : z, We = !1, Xr = 0;
929
- function ct() {
930
- return "react-day-picker-".concat(++Xr);
931
- }
932
- function Zr(e) {
933
- var t, n = e ?? (We ? ct() : null), r = B(n), a = r[0], o = r[1];
934
- return Ur(function() {
935
- a === null && o(ct());
936
- }, []), z(function() {
937
- We === !1 && (We = !0);
938
- }, []), (t = e ?? a) !== null && t !== void 0 ? t : void 0;
939
- }
940
- function Gr(e) {
941
- var t, n, r = k(), a = r.dir, o = r.classNames, i = r.styles, l = r.components, d = ce().displayMonths, u = Zr(r.id ? "".concat(r.id, "-").concat(e.displayIndex) : void 0), c = r.id ? "".concat(r.id, "-grid-").concat(e.displayIndex) : void 0, f = [o.month], v = i.month, m = e.displayIndex === 0, y = e.displayIndex === d.length - 1, _ = !m && !y;
942
- a === "rtl" && (t = [m, y], y = t[0], m = t[1]), m && (f.push(o.caption_start), v = g(g({}, v), i.caption_start)), y && (f.push(o.caption_end), v = g(g({}, v), i.caption_end)), _ && (f.push(o.caption_between), v = g(g({}, v), i.caption_between));
943
- var p = (n = l == null ? void 0 : l.Caption) !== null && n !== void 0 ? n : er;
944
- return L("div", { className: f.join(" "), style: v, children: [s(p, { id: u, displayMonth: e.displayMonth, displayIndex: e.displayIndex }), s(Vr, { id: c, "aria-labelledby": u, displayMonth: e.displayMonth })] }, e.displayIndex);
945
- }
946
- function $r(e) {
947
- var t = k(), n = t.classNames, r = t.styles;
948
- return s("div", { className: n.months, style: r.months, children: e.children });
949
- }
950
- function qr(e) {
951
- var t, n, r = e.initialProps, a = k(), o = Ge(), i = ce(), l = B(!1), d = l[0], u = l[1];
952
- z(function() {
953
- a.initialFocus && o.focusTarget && (d || (o.focus(o.focusTarget), u(!0)));
1367
+ return weeksInMonth;
1368
+ }
1369
+ function getMonthWeeks(month, options) {
1370
+ var weeksInMonth = daysToMonthWeeks(startOfMonth(month), endOfMonth(month), options);
1371
+ if (options === null || options === void 0 ? void 0 : options.useFixedWeeks) {
1372
+ var nrOfMonthWeeks = getWeeksInMonth(month, options);
1373
+ if (nrOfMonthWeeks < 6) {
1374
+ var lastWeek = weeksInMonth[weeksInMonth.length - 1];
1375
+ var lastDate = lastWeek.dates[lastWeek.dates.length - 1];
1376
+ var toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks);
1377
+ var extraWeeks = daysToMonthWeeks(addWeeks(lastDate, 1), toDate, options);
1378
+ weeksInMonth.push.apply(weeksInMonth, extraWeeks);
1379
+ }
1380
+ }
1381
+ return weeksInMonth;
1382
+ }
1383
+ function Table(props) {
1384
+ var _a, _b, _c;
1385
+ var _d = useDayPicker(), locale = _d.locale, classNames2 = _d.classNames, styles2 = _d.styles, hideHead = _d.hideHead, fixedWeeks = _d.fixedWeeks, components = _d.components, weekStartsOn = _d.weekStartsOn, firstWeekContainsDate = _d.firstWeekContainsDate, ISOWeek = _d.ISOWeek;
1386
+ var weeks = getMonthWeeks(props.displayMonth, {
1387
+ useFixedWeeks: Boolean(fixedWeeks),
1388
+ ISOWeek,
1389
+ locale,
1390
+ weekStartsOn,
1391
+ firstWeekContainsDate
1392
+ });
1393
+ var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
1394
+ var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
1395
+ var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
1396
+ return jsxs("table", { id: props.id, className: classNames2.table, style: styles2.table, role: "grid", "aria-labelledby": props["aria-labelledby"], children: [!hideHead && jsx(HeadComponent, {}), jsx("tbody", { className: classNames2.tbody, style: styles2.tbody, children: weeks.map(function(week) {
1397
+ return jsx(RowComponent, { displayMonth: props.displayMonth, dates: week.dates, weekNumber: week.weekNumber }, week.weekNumber);
1398
+ }) }), jsx(FooterComponent, { displayMonth: props.displayMonth })] });
1399
+ }
1400
+ function canUseDOM() {
1401
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
1402
+ }
1403
+ var useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
1404
+ var serverHandoffComplete = false;
1405
+ var id = 0;
1406
+ function genId() {
1407
+ return "react-day-picker-".concat(++id);
1408
+ }
1409
+ function useId(providedId) {
1410
+ var _a;
1411
+ var initialId = providedId !== null && providedId !== void 0 ? providedId : serverHandoffComplete ? genId() : null;
1412
+ var _b = useState(initialId), id2 = _b[0], setId = _b[1];
1413
+ useIsomorphicLayoutEffect(function() {
1414
+ if (id2 === null) {
1415
+ setId(genId());
1416
+ }
1417
+ }, []);
1418
+ useEffect(function() {
1419
+ if (serverHandoffComplete === false) {
1420
+ serverHandoffComplete = true;
1421
+ }
1422
+ }, []);
1423
+ return (_a = providedId !== null && providedId !== void 0 ? providedId : id2) !== null && _a !== void 0 ? _a : void 0;
1424
+ }
1425
+ function Month(props) {
1426
+ var _a;
1427
+ var _b;
1428
+ var dayPicker = useDayPicker();
1429
+ var dir = dayPicker.dir, classNames2 = dayPicker.classNames, styles2 = dayPicker.styles, components = dayPicker.components;
1430
+ var displayMonths = useNavigation().displayMonths;
1431
+ var captionId = useId(dayPicker.id ? "".concat(dayPicker.id, "-").concat(props.displayIndex) : void 0);
1432
+ var tableId = dayPicker.id ? "".concat(dayPicker.id, "-grid-").concat(props.displayIndex) : void 0;
1433
+ var className = [classNames2.month];
1434
+ var style = styles2.month;
1435
+ var isStart = props.displayIndex === 0;
1436
+ var isEnd = props.displayIndex === displayMonths.length - 1;
1437
+ var isCenter = !isStart && !isEnd;
1438
+ if (dir === "rtl") {
1439
+ _a = [isStart, isEnd], isEnd = _a[0], isStart = _a[1];
1440
+ }
1441
+ if (isStart) {
1442
+ className.push(classNames2.caption_start);
1443
+ style = __assign(__assign({}, style), styles2.caption_start);
1444
+ }
1445
+ if (isEnd) {
1446
+ className.push(classNames2.caption_end);
1447
+ style = __assign(__assign({}, style), styles2.caption_end);
1448
+ }
1449
+ if (isCenter) {
1450
+ className.push(classNames2.caption_between);
1451
+ style = __assign(__assign({}, style), styles2.caption_between);
1452
+ }
1453
+ var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
1454
+ return jsxs("div", { className: className.join(" "), style, children: [jsx(CaptionComponent, { id: captionId, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(Table, { id: tableId, "aria-labelledby": captionId, displayMonth: props.displayMonth })] }, props.displayIndex);
1455
+ }
1456
+ function Months(props) {
1457
+ var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
1458
+ return jsx("div", { className: classNames2.months, style: styles2.months, children: props.children });
1459
+ }
1460
+ function Root(_a) {
1461
+ var _b, _c;
1462
+ var initialProps = _a.initialProps;
1463
+ var dayPicker = useDayPicker();
1464
+ var focusContext = useFocusContext();
1465
+ var navigation = useNavigation();
1466
+ var _d = useState(false), hasInitialFocus = _d[0], setHasInitialFocus = _d[1];
1467
+ useEffect(function() {
1468
+ if (!dayPicker.initialFocus)
1469
+ return;
1470
+ if (!focusContext.focusTarget)
1471
+ return;
1472
+ if (hasInitialFocus)
1473
+ return;
1474
+ focusContext.focus(focusContext.focusTarget);
1475
+ setHasInitialFocus(true);
954
1476
  }, [
955
- a.initialFocus,
956
- d,
957
- o.focus,
958
- o.focusTarget,
959
- o
1477
+ dayPicker.initialFocus,
1478
+ hasInitialFocus,
1479
+ focusContext.focus,
1480
+ focusContext.focusTarget,
1481
+ focusContext
960
1482
  ]);
961
- var c = [a.classNames.root, a.className];
962
- a.numberOfMonths > 1 && c.push(a.classNames.multiple_months), a.showWeekNumber && c.push(a.classNames.with_weeknumber);
963
- var f = g(g({}, a.styles.root), a.style), v = Object.keys(r).filter(function(y) {
964
- return y.startsWith("data-");
965
- }).reduce(function(y, _) {
966
- var p;
967
- return g(g({}, y), (p = {}, p[_] = r[_], p));
968
- }, {}), m = (n = (t = r.components) === null || t === void 0 ? void 0 : t.Months) !== null && n !== void 0 ? n : $r;
969
- return s("div", g({ className: c.join(" "), style: f, dir: a.dir, id: a.id, nonce: r.nonce, title: r.title, lang: r.lang }, v, { children: s(m, { children: i.displayMonths.map(function(y, _) {
970
- return s(Gr, { displayIndex: _, displayMonth: y }, _);
1483
+ var classNames2 = [dayPicker.classNames.root, dayPicker.className];
1484
+ if (dayPicker.numberOfMonths > 1) {
1485
+ classNames2.push(dayPicker.classNames.multiple_months);
1486
+ }
1487
+ if (dayPicker.showWeekNumber) {
1488
+ classNames2.push(dayPicker.classNames.with_weeknumber);
1489
+ }
1490
+ var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
1491
+ var dataAttributes = Object.keys(initialProps).filter(function(key) {
1492
+ return key.startsWith("data-");
1493
+ }).reduce(function(attrs, key) {
1494
+ var _a2;
1495
+ return __assign(__assign({}, attrs), (_a2 = {}, _a2[key] = initialProps[key], _a2));
1496
+ }, {});
1497
+ var MonthsComponent = (_c = (_b = initialProps.components) === null || _b === void 0 ? void 0 : _b.Months) !== null && _c !== void 0 ? _c : Months;
1498
+ return jsx("div", __assign({ className: classNames2.join(" "), style, dir: dayPicker.dir, id: dayPicker.id, nonce: initialProps.nonce, title: initialProps.title, lang: initialProps.lang }, dataAttributes, { children: jsx(MonthsComponent, { children: navigation.displayMonths.map(function(month, i) {
1499
+ return jsx(Month, { displayIndex: i, displayMonth: month }, i);
971
1500
  }) }) }));
972
1501
  }
973
- function Jr(e) {
974
- var t = e.children, n = wn(e, ["children"]);
975
- return s(Hn, { initialProps: n, children: s(qn, { children: s(Wr, { initialProps: n, children: s(ir, { initialProps: n, children: s(dr, { initialProps: n, children: s(yr, { children: s(Or, { children: t }) }) }) }) }) }) });
976
- }
977
- function Qr(e) {
978
- return s(Jr, g({}, e, { children: s(qr, { initialProps: e }) }));
979
- }
980
- const zr = 329, Q = 12, De = 26, Wt = 20, Te = 9, ft = 12, St = (e, t, n) => n !== F.positionautomatic && n !== void 0 ? n : e.top > t.height + De ? F.positionabove : F.positionbelow, ea = (e) => e.left + e.width / 4, ta = (e) => document.documentElement.clientWidth - e.right + e.width / 4, na = (e, t) => e.left + t.width, ra = (e) => e.left > Q, aa = (e, t) => na(e, t) < document.documentElement.clientWidth - Q, oa = (e, t) => aa(e, t) ? ra(e) ? "floating" : "left" : "right", Se = (e, t) => e.top - De - t.height, Le = (e) => e.bottom + De, ia = () => document.documentElement.clientWidth - Q * 2, la = () => document.documentElement.clientWidth > zr + Q * 2, vt = (e) => e.top - De - Te + 5, sa = (e) => ea(e) - Wt / 2, da = (e) => ta(e) - Wt / 2, ua = (e, t, n) => {
981
- const r = oa(e, t), a = St(e, t, n);
982
- return r === "left" ? a === F.positionabove ? "leftabove" : "leftbelow" : r === "right" ? a === F.positionabove ? "rightabove" : "rightbelow" : a === F.positionabove ? "floatingabove" : "floatingbelow";
983
- }, ca = (e, t, n) => {
984
- const r = ua(e, t, n), a = la() ? void 0 : ia();
985
- return r === "leftabove" ? {
986
- left: Q,
987
- top: Se(e, t),
988
- width: a
989
- } : r === "leftbelow" ? { left: Q, top: Le(e), width: a } : r === "rightabove" ? { right: Q, top: Se(e, t), width: a } : r === "rightbelow" ? { right: Q, top: Le(e), width: a } : r === "floatingbelow" ? { left: mt(e, t), top: Le(e), width: a } : { left: mt(e, t), top: Se(e, t), width: a };
990
- }, mt = (e, t) => fa(e) - t.width / 2, fa = (e) => e.left + e.width / 2, va = (e, t, n) => {
991
- const r = sa(t), a = da(t), o = e.left + ft, i = e.right + ft;
992
- return e.right ? n === F.positionabove ? {
993
- right: a > i ? a : i,
994
- top: vt(t)
995
- } : {
996
- right: a > i ? a : i,
997
- top: t.bottom + Te
998
- } : n === F.positionabove ? {
999
- left: r > o ? r : o,
1000
- top: vt(t)
1001
- } : {
1002
- left: r > o ? r : o,
1003
- top: t.bottom + Te
1502
+ function RootProvider(props) {
1503
+ var children = props.children, initialProps = __rest(props, ["children"]);
1504
+ return jsx(DayPickerProvider, { initialProps, children: jsx(NavigationProvider, { children: jsx(SelectSingleProvider, { initialProps, children: jsx(SelectMultipleProvider, { initialProps, children: jsx(SelectRangeProvider, { initialProps, children: jsx(ModifiersProvider, { children: jsx(FocusProvider, { children }) }) }) }) }) }) });
1505
+ }
1506
+ function DayPicker(props) {
1507
+ return jsx(RootProvider, __assign({}, props, { children: jsx(Root, { initialProps: props }) }));
1508
+ }
1509
+ const BUBBLE_WIDTH_PX = 329;
1510
+ const WINDOW_MARGIN_PX = 12;
1511
+ const BUBBLE_VERTICAL_OFFSET_PX = 26;
1512
+ const ARROW_WIDTH_PX = 20;
1513
+ const ARROW_VERTICAL_OFFSET_PX = 9;
1514
+ const ARROW_HORIZONTAL_MARGIN_PX = 12;
1515
+ const getVerticalPosition = (controllerSize, bubbleSize, variant) => {
1516
+ if (variant !== PopOverVariant.positionautomatic && variant !== void 0) {
1517
+ return variant;
1518
+ }
1519
+ if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {
1520
+ return PopOverVariant.positionabove;
1521
+ } else {
1522
+ return PopOverVariant.positionbelow;
1523
+ }
1524
+ };
1525
+ const getControllerLeftEdgePx = (controllerSize) => controllerSize.left + controllerSize.width / 4;
1526
+ const getControllerRightEdgePx = (controllerSize) => document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 4;
1527
+ const getBubbleRightPx = (controllerSize, bubbleSize) => {
1528
+ return controllerSize.left + bubbleSize.width;
1529
+ };
1530
+ const getBubbleLeftVisible = (controllerSize) => {
1531
+ return controllerSize.left > WINDOW_MARGIN_PX;
1532
+ };
1533
+ const getBubbleRightIsVisible = (controllerSize, bubbleSize) => {
1534
+ const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);
1535
+ return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;
1536
+ };
1537
+ const getHorizontalPosition = (controllerSize, bubbleSize) => {
1538
+ if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {
1539
+ return "right";
1540
+ }
1541
+ if (!getBubbleLeftVisible(controllerSize)) {
1542
+ return "left";
1543
+ }
1544
+ return "floating";
1545
+ };
1546
+ const getBubbleAbovePx = (controllerSize, bubbleSize) => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;
1547
+ const getBubbleBelowPx = (controllerSize) => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;
1548
+ const getBubbleWidth = () => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;
1549
+ const getBubbleFitsInWindow = () => {
1550
+ return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;
1551
+ };
1552
+ const getArrowTopxPx = (controllerSize) => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX + 5;
1553
+ const getArrowLeftPx = (controllerSize) => getControllerLeftEdgePx(controllerSize) - ARROW_WIDTH_PX / 2;
1554
+ const getArrowRightPx = (controllerSize) => getControllerRightEdgePx(controllerSize) - ARROW_WIDTH_PX / 2;
1555
+ const getBubblePosition = (controllerSize, bubbleSize, variant) => {
1556
+ const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);
1557
+ const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);
1558
+ if (horizontalPosition === "left") {
1559
+ if (verticalPosition === PopOverVariant.positionabove) {
1560
+ return "leftabove";
1561
+ }
1562
+ return "leftbelow";
1563
+ }
1564
+ if (horizontalPosition === "right") {
1565
+ if (verticalPosition === PopOverVariant.positionabove) {
1566
+ return "rightabove";
1567
+ }
1568
+ return "rightbelow";
1569
+ }
1570
+ if (verticalPosition === PopOverVariant.positionabove) {
1571
+ return "floatingabove";
1572
+ }
1573
+ return "floatingbelow";
1574
+ };
1575
+ const getBubbleStyle = (controllerSize, bubbleSize, variant) => {
1576
+ const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);
1577
+ const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : void 0;
1578
+ if (bubblePosition === "leftabove") {
1579
+ return {
1580
+ left: WINDOW_MARGIN_PX,
1581
+ top: getBubbleAbovePx(controllerSize, bubbleSize),
1582
+ width: bubbleWidth
1583
+ };
1584
+ }
1585
+ if (bubblePosition === "leftbelow") {
1586
+ return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
1587
+ }
1588
+ if (bubblePosition === "rightabove") {
1589
+ return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };
1590
+ }
1591
+ if (bubblePosition === "rightbelow") {
1592
+ return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
1593
+ }
1594
+ if (bubblePosition === "floatingbelow") {
1595
+ return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
1596
+ }
1597
+ return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };
1598
+ };
1599
+ const getBubbleLeftPx = (controllerSize, bubbleSize) => {
1600
+ const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);
1601
+ return controllerHorizontalCenterPx - bubbleSize.width / 2;
1602
+ };
1603
+ const getControllerLeftCenterPx = (controllerSize) => controllerSize.left + controllerSize.width / 2;
1604
+ const getArrowStyle = (bubbleStyle, controllerSize, verticalPosition) => {
1605
+ const leftPx = getArrowLeftPx(controllerSize);
1606
+ const rightPx = getArrowRightPx(controllerSize);
1607
+ const minLeftPx = bubbleStyle.left + ARROW_HORIZONTAL_MARGIN_PX;
1608
+ const minRightPx = bubbleStyle.right + ARROW_HORIZONTAL_MARGIN_PX;
1609
+ if (bubbleStyle.right) {
1610
+ if (verticalPosition === PopOverVariant.positionabove) {
1611
+ return {
1612
+ right: rightPx > minRightPx ? rightPx : minRightPx,
1613
+ top: getArrowTopxPx(controllerSize)
1614
+ };
1615
+ }
1616
+ return {
1617
+ right: rightPx > minRightPx ? rightPx : minRightPx,
1618
+ top: controllerSize.bottom + ARROW_VERTICAL_OFFSET_PX
1619
+ };
1620
+ }
1621
+ if (verticalPosition === PopOverVariant.positionabove) {
1622
+ return {
1623
+ left: leftPx > minLeftPx ? leftPx : minLeftPx,
1624
+ top: getArrowTopxPx(controllerSize)
1625
+ };
1626
+ }
1627
+ return {
1628
+ left: leftPx > minLeftPx ? leftPx : minLeftPx,
1629
+ top: controllerSize.bottom + ARROW_VERTICAL_OFFSET_PX
1004
1630
  };
1005
- }, ma = (e) => {
1006
- const { datepickerWrapperRef: t, footer: n, inputRef: r, testId: a, variant: o, zIndex: i, ...l } = e, d = oe(null), [u, c] = B(), f = yn(t), v = hn(r, 0);
1007
- vn(t, !0);
1008
- const m = () => {
1009
- var E;
1010
- c((E = r.current) == null ? void 0 : E.getBoundingClientRect());
1631
+ };
1632
+ const DatePickerPopup = (props) => {
1633
+ const { datepickerWrapperRef, footer, inputRef, testId, variant, zIndex, ...rest } = props;
1634
+ const arrowRef = useRef(null);
1635
+ const [controllerSize, setControllerSize] = useState();
1636
+ const bubbleSize = useSize(datepickerWrapperRef);
1637
+ const controllerisVisible = useIsVisible(inputRef, 0);
1638
+ useFocusTrap(datepickerWrapperRef, true);
1639
+ const updateControllerSize = () => {
1640
+ var _a;
1641
+ setControllerSize((_a = inputRef.current) == null ? void 0 : _a.getBoundingClientRect());
1011
1642
  };
1012
- J.useEffect(() => {
1013
- m();
1014
- }, []), mn(m, 500), pn(m, ["scroll", "resize"], 10);
1015
- const y = Be(P["datepicker-popup-container"], {
1016
- [P["datepicker-popup-container--visible"]]: v
1017
- }), _ = u && f && St(u, f, o), p = Be(P["datepicker-popup-arrow"], {
1018
- [P["datepicker-popup-arrow--visible"]]: v,
1019
- [P["datepicker-popup-arrow--over"]]: _ === F.positionbelow,
1020
- [P["datepicker-popup-arrow--under"]]: _ === F.positionabove
1021
- }), D = u && f && ca(u, f, o), M = D && u && _ && va(D, u, _), I = {
1022
- ...fn,
1023
- ...P
1643
+ React.useEffect(() => {
1644
+ updateControllerSize();
1645
+ }, []);
1646
+ useInterval(updateControllerSize, 500);
1647
+ useLayoutEvent(updateControllerSize, ["scroll", "resize"], 10);
1648
+ const datepickerPopupContainerClasses = classNames(styles["datepicker-popup-container"], {
1649
+ [styles["datepicker-popup-container--visible"]]: controllerisVisible
1650
+ });
1651
+ const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);
1652
+ const popupArrowClasses = classNames(styles["datepicker-popup-arrow"], {
1653
+ [styles["datepicker-popup-arrow--visible"]]: controllerisVisible,
1654
+ [styles["datepicker-popup-arrow--over"]]: verticalPosition === PopOverVariant.positionbelow,
1655
+ [styles["datepicker-popup-arrow--under"]]: verticalPosition === PopOverVariant.positionabove
1656
+ });
1657
+ const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);
1658
+ const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);
1659
+ const datePickerClassNames = {
1660
+ ...reactdaypickerstyles,
1661
+ ...styles
1024
1662
  };
1025
- return /* @__PURE__ */ L(A, { children: [
1026
- /* @__PURE__ */ s("div", { className: y, "data-testid": a, ref: t, style: { ...D, zIndex: i }, children: /* @__PURE__ */ s(
1027
- Qr,
1663
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1664
+ /* @__PURE__ */ jsx("div", { className: datepickerPopupContainerClasses, "data-testid": testId, ref: datepickerWrapperRef, style: { ...bubbleStyle, zIndex }, children: /* @__PURE__ */ jsx(
1665
+ DayPicker,
1028
1666
  {
1029
1667
  captionLayout: "dropdown-buttons",
1030
- classNames: I,
1668
+ classNames: datePickerClassNames,
1031
1669
  mode: "single",
1032
- style: { "--rdp-cell-size": bn("l") },
1033
- modifiersClassNames: { today: P["day--today"], selected: P.day_selected, disabled: P["day--disabled"] },
1034
- footer: /* @__PURE__ */ s("span", { className: P["footer-wrapper"], children: n }),
1035
- fixedWeeks: !0,
1036
- ...l
1670
+ style: { "--rdp-cell-size": getSpacer("l") },
1671
+ modifiersClassNames: { today: styles["day--today"], selected: styles["day_selected"], disabled: styles["day--disabled"] },
1672
+ footer: /* @__PURE__ */ jsx("span", { className: styles["footer-wrapper"], children: footer }),
1673
+ fixedWeeks: true,
1674
+ ...rest
1037
1675
  }
1038
1676
  ) }),
1039
- /* @__PURE__ */ s("div", { ref: d, className: p, style: { ...M, zIndex: i } })
1677
+ /* @__PURE__ */ jsx("div", { ref: arrowRef, className: popupArrowClasses, style: { ...arrowStyle, zIndex } })
1040
1678
  ] });
1041
- }, Lt = J.forwardRef((e, t) => {
1679
+ };
1680
+ const DatePicker = React.forwardRef((props, ref) => {
1042
1681
  const {
1043
- className: n,
1044
- dateButtonAriaLabel: r,
1045
- dateFormat: a = "dd.MM.yyyy",
1046
- dateValue: o,
1047
- defaultMonth: i,
1048
- dir: l,
1049
- disabled: d,
1050
- disableDays: u = [],
1051
- disableWeekends: c,
1052
- error: f,
1053
- errorText: v,
1054
- errorTextId: m,
1055
- errorWrapperClassName: y,
1056
- footerContent: _,
1057
- label: p,
1058
- inputId: D,
1059
- locale: M = an,
1060
- maxDate: I,
1061
- minDate: E,
1062
- onBlur: X,
1063
- onChange: x,
1064
- onDatePopupClosed: C,
1065
- testId: Y,
1066
- autoComplete: Z = "off",
1067
- variant: Me = F.positionautomatic,
1068
- zIndex: ke = dn.PopOver,
1069
- ...fe
1070
- } = e, [G, ee] = B(o), [Ne, ae] = B(G ? O(G, a) : ""), [b, h] = B(i), [$, T] = B(!1), [te, qe] = B(!1), Bt = {
1682
+ className,
1683
+ dateButtonAriaLabel,
1684
+ dateFormat = "dd.MM.yyyy",
1685
+ dateValue,
1686
+ defaultMonth,
1687
+ dir,
1688
+ disabled,
1689
+ disableDays = [],
1690
+ disableWeekends,
1691
+ error,
1692
+ errorText,
1693
+ errorTextId,
1694
+ errorWrapperClassName,
1695
+ footerContent,
1696
+ label,
1697
+ inputId,
1698
+ locale = nb,
1699
+ maxDate,
1700
+ minDate,
1701
+ onBlur,
1702
+ onChange,
1703
+ onDatePopupClosed,
1704
+ testId,
1705
+ autoComplete = "off",
1706
+ variant = PopOverVariant.positionautomatic,
1707
+ zIndex = ZIndex.PopOver,
1708
+ ...rest
1709
+ } = props;
1710
+ const [dateState, setDateState] = useState(dateValue);
1711
+ const [inputValue, setInputValue] = useState(dateState ? format(dateState, dateFormat) : "");
1712
+ const [month, setMonth2] = useState(defaultMonth);
1713
+ const [datePickerOpen, setDatePickerOpen] = useState(false);
1714
+ const [returnInputFocus, setReturnInputFocus] = useState(false);
1715
+ const weekendMatcher = {
1071
1716
  dayOfWeek: [0, 6]
1072
- }, Tt = c ? [...u, Bt] : u, Je = oe(null), ve = oe(null), me = oe(null), { refObject: R } = bt(gt(t) ? t : null), Qe = _t([t, R]), he = oe(!1);
1073
- un(ve, (w) => {
1074
- ve.current && me.current && !(w != null && w.composedPath().includes(ve.current)) && !(w != null && w.composedPath().includes(me.current)) && T(!1);
1075
- }), z(() => {
1076
- se(o) ? (ae(o ? O(o, a) : ""), ee(o), h(o)) : (ae(""), ee(void 0), h(void 0));
1077
- }, [o, a]), z(() => {
1078
- te && R.current && R.current.focus();
1079
- }, [te]);
1080
- const ze = () => {
1081
- R != null && R.current && R.current.focus(), T(!1);
1082
1717
  };
1083
- it(me, ze, [ot.Escape]), it(Je, ze, [ot.Escape]);
1084
- const et = (w, V) => {
1085
- ae(w.currentTarget.value);
1086
- const q = ie(w.currentTarget.value, V, /* @__PURE__ */ new Date());
1087
- se(q) ? (ee(q), h(q)) : ee(void 0), x && x(w, w.currentTarget.value);
1088
- }, Ft = () => {
1089
- te ? qe(!1) : T(!0);
1090
- }, At = (w, V, q, nt) => {
1091
- if (qe(!0), !w) {
1092
- T(!1);
1718
+ const disabledDays = disableWeekends ? [...disableDays, weekendMatcher] : disableDays;
1719
+ const inputWrapperRef = useRef(null);
1720
+ const inputContainerRef = useRef(null);
1721
+ const datepickerWrapperRef = useRef(null);
1722
+ const { refObject } = usePseudoClasses(isMutableRefObject(ref) ? ref : null);
1723
+ const mergedRefs = mergeRefs([ref, refObject]);
1724
+ const isTyping = useRef(false);
1725
+ useOutsideEvent(inputContainerRef, (e) => {
1726
+ if (inputContainerRef.current && datepickerWrapperRef.current && !(e == null ? void 0 : e.composedPath().includes(inputContainerRef.current)) && !(e == null ? void 0 : e.composedPath().includes(datepickerWrapperRef.current))) {
1727
+ setDatePickerOpen(false);
1728
+ }
1729
+ });
1730
+ useEffect(() => {
1731
+ if (isValid(dateValue)) {
1732
+ setInputValue(dateValue ? format(dateValue, dateFormat) : "");
1733
+ setDateState(dateValue);
1734
+ setMonth2(dateValue);
1735
+ } else {
1736
+ setInputValue("");
1737
+ setDateState(void 0);
1738
+ setMonth2(void 0);
1739
+ }
1740
+ }, [dateValue, dateFormat]);
1741
+ useEffect(() => {
1742
+ if (returnInputFocus && refObject.current) {
1743
+ refObject.current.focus();
1744
+ }
1745
+ }, [returnInputFocus]);
1746
+ const handleEscapeKeyDown = () => {
1747
+ (refObject == null ? void 0 : refObject.current) && refObject.current.focus();
1748
+ setDatePickerOpen(false);
1749
+ };
1750
+ useKeyboardEvent(datepickerWrapperRef, handleEscapeKeyDown, [KeyboardEventKey.Escape]);
1751
+ useKeyboardEvent(inputWrapperRef, handleEscapeKeyDown, [KeyboardEventKey.Escape]);
1752
+ const handleInputChange = (event, inputFormat) => {
1753
+ setInputValue(event.currentTarget.value);
1754
+ const newDate = parse(event.currentTarget.value, inputFormat, /* @__PURE__ */ new Date());
1755
+ if (isValid(newDate)) {
1756
+ setDateState(newDate);
1757
+ setMonth2(newDate);
1758
+ } else {
1759
+ setDateState(void 0);
1760
+ }
1761
+ onChange && onChange(event, event.currentTarget.value);
1762
+ };
1763
+ const handleInputFocus = () => {
1764
+ if (!returnInputFocus) {
1765
+ setDatePickerOpen(true);
1766
+ } else {
1767
+ setReturnInputFocus(false);
1768
+ }
1769
+ };
1770
+ const handleSingleDatePickerSelect = (date, _selectedDay, _activeModifiers, e) => {
1771
+ setReturnInputFocus(true);
1772
+ if (!date) {
1773
+ setDatePickerOpen(false);
1093
1774
  return;
1094
1775
  }
1095
- ee(w), R.current && (ae(O(w, a)), T(!1)), x && x(nt, w), Ht(R, O(w, a), w), C && C(w);
1096
- }, Ht = (w, V, q, nt) => {
1097
- if (w.current) {
1098
- w.current.value = V;
1099
- const pe = new Event("change", { bubbles: !0 });
1100
- Object.defineProperty(pe, "target", {
1101
- value: w.current,
1102
- writable: !1,
1103
- enumerable: !0,
1104
- configurable: !0
1105
- }), Object.defineProperty(pe, "currentTarget", {
1106
- value: w.current,
1107
- writable: !1,
1108
- enumerable: !0,
1109
- configurable: !0
1110
- }), w.current.dispatchEvent(pe), x && x(pe, q);
1111
- }
1112
- }, tt = (w) => {
1113
- !$ && (typeof C > "u" || he.current) && X && X(w), he.current = !1;
1114
- }, Yt = (w) => {
1115
- w == null || w.stopPropagation(), T(!$);
1776
+ setDateState(date);
1777
+ if (refObject.current) {
1778
+ setInputValue(format(date, dateFormat));
1779
+ setDatePickerOpen(false);
1780
+ }
1781
+ onChange && onChange(e, date);
1782
+ triggerSyntheticInputEvents(refObject, format(date, dateFormat), date);
1783
+ onDatePopupClosed && onDatePopupClosed(date);
1784
+ };
1785
+ const triggerSyntheticInputEvents = (inputRef, value, date, _onChange) => {
1786
+ if (inputRef.current) {
1787
+ inputRef.current.value = value;
1788
+ const inputEvent = new Event("change", { bubbles: true });
1789
+ Object.defineProperty(inputEvent, "target", {
1790
+ value: inputRef.current,
1791
+ writable: false,
1792
+ enumerable: true,
1793
+ configurable: true
1794
+ });
1795
+ Object.defineProperty(inputEvent, "currentTarget", {
1796
+ value: inputRef.current,
1797
+ writable: false,
1798
+ enumerable: true,
1799
+ configurable: true
1800
+ });
1801
+ inputRef.current.dispatchEvent(inputEvent);
1802
+ if (onChange) {
1803
+ onChange(inputEvent, date);
1804
+ }
1805
+ }
1116
1806
  };
1117
- z(() => {
1118
- const w = (q) => {
1119
- ["Escape", "Enter", "Tab"].includes(q.key) || (he.current = !0, T(!1));
1120
- }, V = R.current;
1121
- return V && V.addEventListener("keydown", w), () => {
1122
- V && V.removeEventListener("keydown", w);
1807
+ const handleInputBlur = (e) => {
1808
+ if (!datePickerOpen && (typeof onDatePopupClosed === "undefined" || isTyping.current)) {
1809
+ onBlur && onBlur(e);
1810
+ }
1811
+ isTyping.current = false;
1812
+ };
1813
+ const handleButtonClick = (e) => {
1814
+ e == null ? void 0 : e.stopPropagation();
1815
+ setDatePickerOpen(!datePickerOpen);
1816
+ };
1817
+ useEffect(() => {
1818
+ const handleKeyDown = (e) => {
1819
+ if (!["Escape", "Enter", "Tab"].includes(e.key)) {
1820
+ isTyping.current = true;
1821
+ setDatePickerOpen(false);
1822
+ }
1823
+ };
1824
+ const inputElement = refObject.current;
1825
+ if (inputElement) {
1826
+ inputElement.addEventListener("keydown", handleKeyDown);
1827
+ }
1828
+ return () => {
1829
+ if (inputElement) {
1830
+ inputElement.removeEventListener("keydown", handleKeyDown);
1831
+ }
1123
1832
  };
1124
- }, [R]);
1125
- const jt = (w) => {
1126
- et(w, "yyyy-MM-dd"), he.current || C && C(G);
1127
- }, Vt = /* @__PURE__ */ s(
1128
- Re,
1833
+ }, [refObject]);
1834
+ const handleMobileInputChange = (e) => {
1835
+ handleInputChange(e, "yyyy-MM-dd");
1836
+ if (!isTyping.current) {
1837
+ onDatePopupClosed && onDatePopupClosed(dateState);
1838
+ }
1839
+ };
1840
+ const renderMobile = /* @__PURE__ */ jsx(
1841
+ Input,
1129
1842
  {
1130
- disabled: d,
1131
- error: f,
1132
- errorText: v,
1133
- errorTextId: m,
1134
- inputId: D,
1135
- label: p,
1136
- max: I ? O(I, "yyyy-MM-dd") : "",
1137
- min: E ? O(E, "yyyy-MM-dd") : "",
1843
+ disabled,
1844
+ error,
1845
+ errorText,
1846
+ errorTextId,
1847
+ inputId,
1848
+ label,
1849
+ max: maxDate ? format(maxDate, "yyyy-MM-dd") : "",
1850
+ min: minDate ? format(minDate, "yyyy-MM-dd") : "",
1138
1851
  type: "date",
1139
- ref: Qe,
1140
- value: G ? O(G, "yyyy-MM-dd") : "",
1852
+ ref: mergedRefs,
1853
+ value: dateState ? format(dateState, "yyyy-MM-dd") : "",
1141
1854
  width: 14,
1142
- ...fe,
1143
- onBlur: tt,
1144
- onChange: jt,
1145
- autoComplete: Z || void 0
1146
- }
1147
- ), Kt = /* @__PURE__ */ L(A, { children: [
1148
- /* @__PURE__ */ s("div", { children: /* @__PURE__ */ s(
1149
- Re,
1855
+ ...rest,
1856
+ onBlur: handleInputBlur,
1857
+ onChange: handleMobileInputChange,
1858
+ autoComplete: autoComplete ? autoComplete : void 0
1859
+ }
1860
+ );
1861
+ const renderDesktop = /* @__PURE__ */ jsxs(Fragment, { children: [
1862
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1863
+ Input,
1150
1864
  {
1151
- errorWrapperClassName: y,
1152
- disabled: d,
1153
- error: f,
1154
- errorText: v,
1155
- errorTextId: m,
1156
- inputId: D,
1157
- inputContainerRef: ve,
1158
- inputWrapperRef: Je,
1159
- label: p,
1160
- onFocus: Ft,
1865
+ errorWrapperClassName,
1866
+ disabled,
1867
+ error,
1868
+ errorText,
1869
+ errorTextId,
1870
+ inputId,
1871
+ inputContainerRef,
1872
+ inputWrapperRef,
1873
+ label,
1874
+ onFocus: handleInputFocus,
1161
1875
  type: "text",
1162
- ref: Qe,
1163
- value: Ne,
1876
+ ref: mergedRefs,
1877
+ value: inputValue,
1164
1878
  width: 12,
1165
- ...fe,
1166
- onBlur: tt,
1167
- onChange: (w) => et(w, "yyyy-MM-dd"),
1168
- rightOfInput: /* @__PURE__ */ s(
1169
- on,
1879
+ ...rest,
1880
+ onBlur: handleInputBlur,
1881
+ onChange: (e) => handleInputChange(e, "yyyy-MM-dd"),
1882
+ rightOfInput: /* @__PURE__ */ jsx(
1883
+ Button$1,
1170
1884
  {
1171
- disabled: d,
1172
- ariaLabel: r ?? "Velg dato",
1173
- onClick: Yt,
1174
- tabIndex: $ ? -1 : 0,
1885
+ disabled,
1886
+ ariaLabel: dateButtonAriaLabel ?? "Velg dato",
1887
+ onClick: handleButtonClick,
1888
+ tabIndex: datePickerOpen ? -1 : 0,
1175
1889
  variant: "borderless",
1176
- wrapperClassName: P["date-button"],
1177
- className: P["date-button__inner"],
1178
- children: /* @__PURE__ */ s(ln, { color: "black", svgIcon: sn })
1890
+ wrapperClassName: styles["date-button"],
1891
+ className: styles["date-button__inner"],
1892
+ children: /* @__PURE__ */ jsx(Icon, { color: "black", svgIcon: Calendar })
1179
1893
  }
1180
1894
  ),
1181
- autoComplete: Z || void 0
1895
+ autoComplete: autoComplete ? autoComplete : void 0
1182
1896
  }
1183
1897
  ) }),
1184
- $ && !d && /* @__PURE__ */ s(
1185
- ma,
1898
+ datePickerOpen && !disabled && /* @__PURE__ */ jsx(
1899
+ DatePickerPopup,
1186
1900
  {
1187
- dir: l,
1188
- disabled: Tt,
1189
- datepickerWrapperRef: me,
1190
- footer: _,
1191
- fromDate: E,
1192
- toDate: I,
1193
- inputRef: R,
1194
- locale: M,
1195
- month: b,
1196
- selected: G,
1197
- onSelect: At,
1198
- onMonthChange: h,
1199
- variant: Me,
1200
- zIndex: ke
1901
+ dir,
1902
+ disabled: disabledDays,
1903
+ datepickerWrapperRef,
1904
+ footer: footerContent,
1905
+ fromDate: minDate,
1906
+ toDate: maxDate,
1907
+ inputRef: refObject,
1908
+ locale,
1909
+ month,
1910
+ selected: dateState,
1911
+ onSelect: handleSingleDatePickerSelect,
1912
+ onMonthChange: setMonth2,
1913
+ variant,
1914
+ zIndex
1201
1915
  }
1202
1916
  )
1203
1917
  ] });
1204
- return /* @__PURE__ */ s("div", { className: n, "data-testid": Y, children: cn() ? Vt : Kt });
1918
+ return /* @__PURE__ */ jsx("div", { className, "data-testid": testId, children: isMobileUA() ? renderMobile : renderDesktop });
1205
1919
  });
1206
- Lt.displayName = "DatePicker";
1207
- const ye = (e) => {
1208
- const t = String(e);
1209
- return t.length === 1 ? "0" + t : t;
1210
- }, ha = (e) => !e || /^\d+$/.test(e) && e.length <= 2, Et = J.forwardRef((e, t) => {
1920
+ DatePicker.displayName = "DatePicker";
1921
+ const formatAsTwoDigits = (value) => {
1922
+ const stringValue = String(value);
1923
+ return stringValue.length === 1 ? "0" + stringValue : stringValue;
1924
+ };
1925
+ const isNumericString = (str) => {
1926
+ return !str || /^\d+$/.test(str) && str.length <= 2;
1927
+ };
1928
+ const DateTime = React.forwardRef((props, ref) => {
1211
1929
  const {
1212
- error: n,
1213
- errorText: r,
1214
- errorTextId: a,
1215
- errorWrapperClassName: o,
1216
- label: i,
1217
- onBlur: l,
1218
- onChange: d,
1219
- timeUnit: u,
1220
- testId: c,
1221
- inputId: f,
1222
- value: v,
1223
- autoComplete: m = "off",
1224
- ...y
1225
- } = e, [_, p] = B(
1226
- typeof v < "u" ? ye(v) : void 0
1227
- ), { refObject: D } = bt(gt(t) ? t : null), M = _t([t, D]);
1228
- z(() => {
1229
- p(v ? ye(v) : void 0);
1230
- }, [v]);
1231
- const I = (C) => {
1232
- const Y = C.target.value;
1233
- ha(Y) && (p(Y), d && d(C));
1234
- }, E = (C) => {
1235
- const Y = ye(C.target.value);
1236
- p(Y), d && d(C), l && l(C);
1237
- }, X = (C) => {
1238
- const Y = /[0-9]/, Z = ["Backspace", " ", "Enter", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
1239
- !Y.test(C.key) && !Z.includes(C.key) && C.preventDefault();
1240
- }, x = () => u === "hours" && /* @__PURE__ */ s("span", { className: P["time-separator"], children: ":" });
1241
- return /* @__PURE__ */ s("div", { "data-testid": c, children: /* @__PURE__ */ s(
1242
- Re,
1930
+ error,
1931
+ errorText,
1932
+ errorTextId,
1933
+ errorWrapperClassName,
1934
+ label,
1935
+ onBlur,
1936
+ onChange,
1937
+ timeUnit,
1938
+ testId,
1939
+ inputId,
1940
+ value,
1941
+ autoComplete = "off",
1942
+ ...rest
1943
+ } = props;
1944
+ const [inputValue, setInputValue] = useState(
1945
+ typeof value !== "undefined" ? formatAsTwoDigits(value) : void 0
1946
+ );
1947
+ const { refObject } = usePseudoClasses(isMutableRefObject(ref) ? ref : null);
1948
+ const mergedRefs = mergeRefs([ref, refObject]);
1949
+ useEffect(() => {
1950
+ setInputValue(value ? formatAsTwoDigits(value) : void 0);
1951
+ }, [value]);
1952
+ const handleInputChange = (event) => {
1953
+ const value2 = event.target.value;
1954
+ if (isNumericString(value2)) {
1955
+ setInputValue(value2);
1956
+ onChange && onChange(event);
1957
+ }
1958
+ };
1959
+ const handleInputBlur = (event) => {
1960
+ const formattedValue = formatAsTwoDigits(event.target.value);
1961
+ setInputValue(formattedValue);
1962
+ onChange && onChange(event);
1963
+ onBlur && onBlur(event);
1964
+ };
1965
+ const handleInputOnKeyDown = (event) => {
1966
+ const validChars = /[0-9]/;
1967
+ const allowedKeys = ["Backspace", " ", "Enter", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
1968
+ if (!validChars.test(event.key) && !allowedKeys.includes(event.key)) {
1969
+ event.preventDefault();
1970
+ }
1971
+ };
1972
+ const renderTimeSeparator = () => {
1973
+ return timeUnit === "hours" && /* @__PURE__ */ jsx("span", { className: styles["time-separator"], children: ":" });
1974
+ };
1975
+ return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: /* @__PURE__ */ jsx(
1976
+ Input,
1243
1977
  {
1244
- inputId: f,
1245
- error: n,
1246
- errorText: r,
1247
- errorTextId: a,
1248
- errorWrapperClassName: o,
1249
- label: i,
1250
- max: u === "hours" ? 23 : 59,
1978
+ inputId,
1979
+ error,
1980
+ errorText,
1981
+ errorTextId,
1982
+ errorWrapperClassName,
1983
+ label,
1984
+ max: timeUnit === "hours" ? 23 : 59,
1251
1985
  min: 0,
1252
1986
  type: "number",
1253
- ref: M,
1254
- value: _,
1987
+ ref: mergedRefs,
1988
+ value: inputValue,
1255
1989
  width: 5,
1256
- defaultValue: typeof e.defaultValue < "u" ? ye(e.defaultValue) : void 0,
1257
- ...y,
1258
- onChange: I,
1259
- onBlur: E,
1260
- rightOfInput: x(),
1261
- onKeyDown: X,
1262
- autoComplete: m || void 0
1990
+ defaultValue: typeof props.defaultValue !== "undefined" ? formatAsTwoDigits(props.defaultValue) : void 0,
1991
+ ...rest,
1992
+ onChange: handleInputChange,
1993
+ onBlur: handleInputBlur,
1994
+ rightOfInput: renderTimeSeparator(),
1995
+ onKeyDown: handleInputOnKeyDown,
1996
+ autoComplete: autoComplete ? autoComplete : void 0
1263
1997
  }
1264
1998
  ) });
1265
1999
  });
1266
- Et.displayName = "DateTime";
1267
- const pa = J.forwardRef((e, t) => {
1268
- const { children: n, errorWrapperClassName: r, errorText: a, legend: o, testId: i } = e, l = _n(), d = (u) => lt(u, Lt) ? J.cloneElement(u, {
1269
- className: Be(P["date-time-picker-wrapper__date-picker"]),
1270
- error: !!a,
1271
- errorTextId: l
1272
- }) : lt(u, Et) ? J.cloneElement(u, {
1273
- error: !!a,
1274
- errorTextId: l
1275
- }) : u;
1276
- return /* @__PURE__ */ s("div", { ref: t, tabIndex: -1, children: /* @__PURE__ */ s(gn, { className: r, errorText: a, errorTextId: l, children: e.legend ? /* @__PURE__ */ L("fieldset", { className: P["date-time-picker-wrapper"], "data-testid": i, children: [
1277
- e.legend && /* @__PURE__ */ s("legend", { className: P["date-time-picker-wrapper__legend"], children: o }),
1278
- J.Children.map(n, d)
1279
- ] }) : /* @__PURE__ */ s("div", { className: P["date-time-picker-wrapper"], children: J.Children.map(n, d) }) }) });
2000
+ DateTime.displayName = "DateTime";
2001
+ const DateTimePickerWrapper = React.forwardRef((props, ref) => {
2002
+ const { children, errorWrapperClassName, errorText, legend, testId } = props;
2003
+ const errorTextId = useUuid();
2004
+ const mapDateComponents = (child) => {
2005
+ if (isComponent(child, DatePicker)) {
2006
+ return React.cloneElement(child, {
2007
+ className: classNames(styles["date-time-picker-wrapper__date-picker"]),
2008
+ error: !!errorText,
2009
+ errorTextId
2010
+ });
2011
+ } else if (isComponent(child, DateTime)) {
2012
+ return React.cloneElement(child, {
2013
+ error: !!errorText,
2014
+ errorTextId
2015
+ });
2016
+ }
2017
+ return child;
2018
+ };
2019
+ return /* @__PURE__ */ jsx("div", { ref, tabIndex: -1, children: /* @__PURE__ */ jsx(ErrorWrapper, { className: errorWrapperClassName, errorText, errorTextId, children: props.legend ? /* @__PURE__ */ jsxs("fieldset", { className: styles["date-time-picker-wrapper"], "data-testid": testId, children: [
2020
+ props.legend && /* @__PURE__ */ jsx("legend", { className: styles["date-time-picker-wrapper__legend"], children: legend }),
2021
+ React.Children.map(children, mapDateComponents)
2022
+ ] }) : /* @__PURE__ */ jsx("div", { className: styles["date-time-picker-wrapper"], children: React.Children.map(children, mapDateComponents) }) }) });
1280
2023
  });
1281
- pa.displayName = "DateTimePickerWrapper";
1282
- const Rt = (e) => {
1283
- const t = ["yyyy-MM-dd", "dd.MM.yyyy"];
1284
- for (const n of t) {
1285
- const r = ie(e, n, /* @__PURE__ */ new Date());
1286
- if (se(r))
1287
- return r;
2024
+ DateTimePickerWrapper.displayName = "DateTimePickerWrapper";
2025
+ const parseInputDate = (dateString) => {
2026
+ const possibleFormats = ["yyyy-MM-dd", "dd.MM.yyyy"];
2027
+ for (const format2 of possibleFormats) {
2028
+ const parsedDate = parse(dateString, format2, /* @__PURE__ */ new Date());
2029
+ if (isValid(parsedDate)) {
2030
+ return parsedDate;
2031
+ }
1288
2032
  }
1289
2033
  return null;
1290
- }, Ka = (e) => {
1291
- const t = new Date(e);
1292
- return t instanceof Date && !isNaN(t.getTime());
1293
- }, Ua = (e, t, n, r, a) => {
1294
- const o = Rt(e), i = typeof r < "u", l = typeof a < "u";
1295
- return !o || i && !se(r) || l && !se(a) ? n || "Invalid date format" : i && !l && (N(o, r) || ge(o, r)) || l && !i && (N(o, a) || He(o, a)) || i && l && (N(o, r) || N(o, a) || nn(o, { start: r, end: a })) ? !0 : t;
1296
- }, Xa = (e, t, n, r) => {
1297
- const a = Rt(e);
1298
- return a ? t.some((o) => N(o, a)) ? n : !0 : r || "Invalid date format";
1299
- }, Za = (e, t, n, r) => {
1300
- const a = ie((e.hour + ":" + e.minute).toString(), "HH:mm", /* @__PURE__ */ new Date()), o = ie(((n == null ? void 0 : n.hour) + ":" + (n == null ? void 0 : n.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date()), i = ie(((r == null ? void 0 : r.hour) + ":" + (r == null ? void 0 : r.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date());
1301
- return (typeof n > "u" || a >= o) && (typeof r > "u" || a <= i) ? !0 : t;
2034
+ };
2035
+ const isValidDate = (dateString) => {
2036
+ const date = new Date(dateString);
2037
+ return date instanceof Date && !isNaN(date.getTime());
2038
+ };
2039
+ const validateMinMaxDate = (date, outsideRangeErrorMessage, invalidFormatErrorMessage, minDate, maxDate) => {
2040
+ const formattedDate = parseInputDate(date);
2041
+ const hasMinDate = typeof minDate !== "undefined";
2042
+ const hasMaxDate = typeof maxDate !== "undefined";
2043
+ if (!formattedDate || hasMinDate && !isValid(minDate) || hasMaxDate && !isValid(maxDate)) {
2044
+ return invalidFormatErrorMessage || "Invalid date format";
2045
+ }
2046
+ if (hasMinDate && !hasMaxDate && (isSameDay(formattedDate, minDate) || isAfter(formattedDate, minDate))) return true;
2047
+ else if (hasMaxDate && !hasMinDate && (isSameDay(formattedDate, maxDate) || isBefore(formattedDate, maxDate))) return true;
2048
+ else if (hasMinDate && hasMaxDate && (isSameDay(formattedDate, minDate) || isSameDay(formattedDate, maxDate) || isWithinInterval(formattedDate, { start: minDate, end: maxDate }))) {
2049
+ return true;
2050
+ }
2051
+ return outsideRangeErrorMessage;
2052
+ };
2053
+ const validateDisabledDates = (date, disabledDates, isDisabledErrorMessage, invalidFormatErrorMessage) => {
2054
+ const formattedDate = parseInputDate(date);
2055
+ if (!formattedDate) {
2056
+ return invalidFormatErrorMessage || "Invalid date format";
2057
+ }
2058
+ if (!disabledDates.some((d) => isSameDay(d, formattedDate))) {
2059
+ return true;
2060
+ }
2061
+ return isDisabledErrorMessage;
2062
+ };
2063
+ const validateMinTimeMaxTime = (time, errorMessage, minTime, maxTime) => {
2064
+ const timeParsed = parse((time.hour + ":" + time.minute).toString(), "HH:mm", /* @__PURE__ */ new Date());
2065
+ const minTimeParsed = parse(((minTime == null ? void 0 : minTime.hour) + ":" + (minTime == null ? void 0 : minTime.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date());
2066
+ const maxTimeParsed = parse(((maxTime == null ? void 0 : maxTime.hour) + ":" + (maxTime == null ? void 0 : maxTime.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date());
2067
+ if ((typeof minTime === "undefined" || timeParsed >= minTimeParsed) && (typeof maxTime === "undefined" || timeParsed <= maxTimeParsed)) {
2068
+ return true;
2069
+ }
2070
+ return errorMessage;
1302
2071
  };
1303
2072
  export {
1304
- Lt as DatePicker,
1305
- Et as DateTime,
1306
- pa as DateTimePickerWrapper,
1307
- Lt as default,
1308
- Ka as isValidDate,
1309
- Rt as parseInputDate,
1310
- Xa as validateDisabledDates,
1311
- Ua as validateMinMaxDate,
1312
- Za as validateMinTimeMaxTime
2073
+ DatePicker,
2074
+ DateTime,
2075
+ DateTimePickerWrapper,
2076
+ DatePicker as default,
2077
+ isValidDate,
2078
+ parseInputDate,
2079
+ validateDisabledDates,
2080
+ validateMinMaxDate,
2081
+ validateMinTimeMaxTime
1313
2082
  };
1314
2083
  //# sourceMappingURL=index.js.map