@loykin/datetime-range 0.0.1-dev.0

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1666 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var lucideReact = require('lucide-react');
5
+ var clsx = require('clsx');
6
+ var button = require('@base-ui/react/button');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var popover = require('@base-ui/react/popover');
9
+ var tabs = require('@base-ui/react/tabs');
10
+ var classVarianceAuthority = require('class-variance-authority');
11
+ var input = require('@base-ui/react/input');
12
+ var select = require('@base-ui/react/select');
13
+ var react = require('@hugeicons/react');
14
+ var coreFreeIcons = require('@hugeicons/core-free-icons');
15
+ var _switch = require('@base-ui/react/switch');
16
+ var separator = require('@base-ui/react/separator');
17
+ var dateFns = require('date-fns');
18
+ var reactDayPicker = require('react-day-picker');
19
+ var setMonth = require('date-fns/setMonth');
20
+ var scrollArea = require('@base-ui/react/scroll-area');
21
+ var chrono = require('chrono-node');
22
+
23
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
+
25
+ function _interopNamespace(e) {
26
+ if (e && e.__esModule) return e;
27
+ var n = Object.create(null);
28
+ if (e) {
29
+ Object.keys(e).forEach(function (k) {
30
+ if (k !== 'default') {
31
+ var d = Object.getOwnPropertyDescriptor(e, k);
32
+ Object.defineProperty(n, k, d.get ? d : {
33
+ enumerable: true,
34
+ get: function () { return e[k]; }
35
+ });
36
+ }
37
+ });
38
+ }
39
+ n.default = e;
40
+ return Object.freeze(n);
41
+ }
42
+
43
+ var React__default = /*#__PURE__*/_interopDefault(React);
44
+ var chrono__namespace = /*#__PURE__*/_interopNamespace(chrono);
45
+
46
+ // src/DatetimeRange.tsx
47
+ function cn(...inputs) {
48
+ return clsx.clsx(inputs);
49
+ }
50
+ function buttonVariants({
51
+ variant = "default",
52
+ size = "default",
53
+ className
54
+ } = {}) {
55
+ return cn("dr-btn", className, variant && `dr-btn--${variant}`, size && `dr-btn--${size}`);
56
+ }
57
+ function Button({
58
+ className,
59
+ variant = "default",
60
+ size = "default",
61
+ ...props
62
+ }) {
63
+ return /* @__PURE__ */ jsxRuntime.jsx(
64
+ button.Button,
65
+ {
66
+ "data-slot": "button",
67
+ "data-variant": variant,
68
+ "data-size": size,
69
+ className: buttonVariants({ variant, size, className: typeof className === "string" ? className : void 0 }),
70
+ ...props
71
+ }
72
+ );
73
+ }
74
+ function Popover({ ...props }) {
75
+ return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Root, { "data-slot": "popover", ...props });
76
+ }
77
+ function PopoverTrigger({ ...props }) {
78
+ return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Trigger, { "data-slot": "popover-trigger", ...props });
79
+ }
80
+ function PopoverContent({
81
+ className,
82
+ align = "center",
83
+ alignOffset = 0,
84
+ side = "bottom",
85
+ sideOffset = 4,
86
+ disableAnchorTracking,
87
+ collisionAvoidance,
88
+ ...props
89
+ }) {
90
+ return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
91
+ popover.Popover.Positioner,
92
+ {
93
+ align,
94
+ alignOffset,
95
+ side,
96
+ sideOffset,
97
+ disableAnchorTracking,
98
+ collisionAvoidance,
99
+ className: "isolate z-50",
100
+ children: /* @__PURE__ */ jsxRuntime.jsx(
101
+ popover.Popover.Popup,
102
+ {
103
+ "data-slot": "popover-content",
104
+ className: cn(
105
+ "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-[var(--bk-radius)] bg-[var(--bk-popover)] p-2.5 text-xs text-[var(--bk-popover-foreground)] shadow-md ring-1 ring-[var(--bk-foreground)]/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
106
+ className
107
+ ),
108
+ ...props
109
+ }
110
+ )
111
+ }
112
+ ) });
113
+ }
114
+ function Tabs({
115
+ className,
116
+ orientation = "horizontal",
117
+ ...props
118
+ }) {
119
+ return /* @__PURE__ */ jsxRuntime.jsx(
120
+ tabs.Tabs.Root,
121
+ {
122
+ "data-slot": "tabs",
123
+ "data-orientation": orientation,
124
+ className: cn("group/tabs flex gap-2 data-horizontal:flex-col", className),
125
+ ...props
126
+ }
127
+ );
128
+ }
129
+ var tabsListVariants = classVarianceAuthority.cva(
130
+ "group/tabs-list inline-flex w-fit items-center justify-center rounded-[var(--bk-radius)] p-[3px] text-[var(--bk-muted-foreground)] group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",
131
+ {
132
+ variants: {
133
+ variant: {
134
+ default: "bg-[var(--bk-muted)]",
135
+ line: "gap-1 bg-transparent"
136
+ }
137
+ },
138
+ defaultVariants: {
139
+ variant: "default"
140
+ }
141
+ }
142
+ );
143
+ function TabsList({
144
+ className,
145
+ variant = "default",
146
+ ...props
147
+ }) {
148
+ return /* @__PURE__ */ jsxRuntime.jsx(
149
+ tabs.Tabs.List,
150
+ {
151
+ "data-slot": "tabs-list",
152
+ "data-variant": variant,
153
+ className: cn(tabsListVariants({ variant }), className),
154
+ ...props
155
+ }
156
+ );
157
+ }
158
+ function TabsTrigger({ className, ...props }) {
159
+ return /* @__PURE__ */ jsxRuntime.jsx(
160
+ tabs.Tabs.Tab,
161
+ {
162
+ "data-slot": "tabs-trigger",
163
+ className: cn(
164
+ "relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-[max(0px,calc(var(--bk-radius)-3px))] border border-transparent px-1.5 py-0.5 text-xs font-medium whitespace-nowrap text-[var(--bk-muted-foreground)] transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start group-data-vertical/tabs:py-[calc(--spacing(1.25))] hover:text-[var(--bk-foreground)] focus-visible:border-[var(--bk-ring)] focus-visible:ring-[3px] focus-visible:ring-[var(--bk-ring)]/50 focus-visible:outline-1 focus-visible:outline-[var(--bk-ring)] disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
165
+ "group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent",
166
+ "data-active:bg-[var(--bk-background)] data-active:text-[var(--bk-foreground)]",
167
+ "after:absolute after:bg-[var(--bk-foreground)] after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
168
+ className
169
+ ),
170
+ ...props
171
+ }
172
+ );
173
+ }
174
+ function TabsContent({ className, ...props }) {
175
+ return /* @__PURE__ */ jsxRuntime.jsx(
176
+ tabs.Tabs.Panel,
177
+ {
178
+ "data-slot": "tabs-content",
179
+ className: cn("flex-1 text-xs/relaxed outline-none", className),
180
+ ...props
181
+ }
182
+ );
183
+ }
184
+ function Input({ className, type, ...props }) {
185
+ return /* @__PURE__ */ jsxRuntime.jsx(
186
+ input.Input,
187
+ {
188
+ type,
189
+ "data-slot": "input",
190
+ className: cn(
191
+ "dr-input",
192
+ className
193
+ ),
194
+ ...props
195
+ }
196
+ );
197
+ }
198
+ var Select = select.Select.Root;
199
+ function SelectValue({ className, ...props }) {
200
+ return /* @__PURE__ */ jsxRuntime.jsx(
201
+ select.Select.Value,
202
+ {
203
+ "data-slot": "select-value",
204
+ className: cn("flex flex-1 text-left", className),
205
+ ...props
206
+ }
207
+ );
208
+ }
209
+ function SelectTrigger({
210
+ className,
211
+ size = "default",
212
+ children,
213
+ ...props
214
+ }) {
215
+ return /* @__PURE__ */ jsxRuntime.jsxs(
216
+ select.Select.Trigger,
217
+ {
218
+ "data-slot": "select-trigger",
219
+ "data-size": size,
220
+ className: cn(
221
+ "flex w-fit items-center justify-between gap-1.5 rounded-[var(--bk-radius)] border border-[var(--bk-input)] bg-transparent py-2 pr-2 pl-2.5 text-xs whitespace-nowrap transition-colors outline-none select-none focus-visible:border-[var(--bk-ring)] focus-visible:ring-1 focus-visible:ring-[var(--bk-ring)]/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-[var(--bk-destructive)] aria-invalid:ring-1 aria-invalid:ring-[var(--bk-destructive)]/20 data-placeholder:text-[var(--bk-muted-foreground)] data-[size=default]:h-8 data-[size=sm]:h-7 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
222
+ className
223
+ ),
224
+ ...props,
225
+ children: [
226
+ children,
227
+ /* @__PURE__ */ jsxRuntime.jsx(
228
+ select.Select.Icon,
229
+ {
230
+ render: /* @__PURE__ */ jsxRuntime.jsx(
231
+ react.HugeiconsIcon,
232
+ {
233
+ icon: coreFreeIcons.UnfoldMoreIcon,
234
+ strokeWidth: 2,
235
+ className: "pointer-events-none size-4 text-[var(--bk-muted-foreground)]"
236
+ }
237
+ )
238
+ }
239
+ )
240
+ ]
241
+ }
242
+ );
243
+ }
244
+ function SelectContent({
245
+ className,
246
+ children,
247
+ side = "bottom",
248
+ sideOffset = 4,
249
+ align = "center",
250
+ alignOffset = 0,
251
+ alignItemWithTrigger = true,
252
+ ...props
253
+ }) {
254
+ return /* @__PURE__ */ jsxRuntime.jsx(select.Select.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
255
+ select.Select.Positioner,
256
+ {
257
+ side,
258
+ sideOffset,
259
+ align,
260
+ alignOffset,
261
+ alignItemWithTrigger,
262
+ className: "isolate z-50",
263
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
264
+ select.Select.Popup,
265
+ {
266
+ "data-slot": "select-content",
267
+ "data-align-trigger": alignItemWithTrigger,
268
+ className: cn(
269
+ "isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-[var(--bk-radius)] bg-[var(--bk-popover)] text-[var(--bk-popover-foreground)] shadow-md ring-1 ring-[var(--bk-foreground)]/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 animate-none!",
270
+ className
271
+ ),
272
+ ...props,
273
+ children: [
274
+ /* @__PURE__ */ jsxRuntime.jsx(SelectScrollUpButton, {}),
275
+ /* @__PURE__ */ jsxRuntime.jsx(select.Select.List, { children }),
276
+ /* @__PURE__ */ jsxRuntime.jsx(SelectScrollDownButton, {})
277
+ ]
278
+ }
279
+ )
280
+ }
281
+ ) });
282
+ }
283
+ function SelectItem({
284
+ className,
285
+ children,
286
+ ...props
287
+ }) {
288
+ return /* @__PURE__ */ jsxRuntime.jsxs(
289
+ select.Select.Item,
290
+ {
291
+ "data-slot": "select-item",
292
+ className: cn(
293
+ "relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none focus:bg-[var(--bk-accent)] focus:text-[var(--bk-accent-foreground)] data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
294
+ className
295
+ ),
296
+ ...props,
297
+ children: [
298
+ /* @__PURE__ */ jsxRuntime.jsx(select.Select.ItemText, { className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap", children }),
299
+ /* @__PURE__ */ jsxRuntime.jsx(
300
+ select.Select.ItemIndicator,
301
+ {
302
+ render: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center" }),
303
+ children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.Tick02Icon, strokeWidth: 2, className: "pointer-events-none" })
304
+ }
305
+ )
306
+ ]
307
+ }
308
+ );
309
+ }
310
+ function SelectScrollUpButton({
311
+ className,
312
+ ...props
313
+ }) {
314
+ return /* @__PURE__ */ jsxRuntime.jsx(
315
+ select.Select.ScrollUpArrow,
316
+ {
317
+ "data-slot": "select-scroll-up-button",
318
+ className: cn(
319
+ "top-0 z-10 flex w-full cursor-default items-center justify-center bg-[var(--bk-popover)] py-1 [&_svg:not([class*='size-'])]:size-4",
320
+ className
321
+ ),
322
+ ...props,
323
+ children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.ArrowUp01Icon, strokeWidth: 2 })
324
+ }
325
+ );
326
+ }
327
+ function SelectScrollDownButton({
328
+ className,
329
+ ...props
330
+ }) {
331
+ return /* @__PURE__ */ jsxRuntime.jsx(
332
+ select.Select.ScrollDownArrow,
333
+ {
334
+ "data-slot": "select-scroll-down-button",
335
+ className: cn(
336
+ "bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-[var(--bk-popover)] py-1 [&_svg:not([class*='size-'])]:size-4",
337
+ className
338
+ ),
339
+ ...props,
340
+ children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.ArrowDown01Icon, strokeWidth: 2 })
341
+ }
342
+ );
343
+ }
344
+ function Switch({
345
+ className,
346
+ size = "default",
347
+ ...props
348
+ }) {
349
+ return /* @__PURE__ */ jsxRuntime.jsx(
350
+ _switch.Switch.Root,
351
+ {
352
+ "data-slot": "switch",
353
+ "data-size": size,
354
+ className: cn(
355
+ "peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-[var(--bk-ring)] focus-visible:ring-1 focus-visible:ring-[var(--bk-ring)]/50 aria-invalid:border-[var(--bk-destructive)] aria-invalid:ring-1 aria-invalid:ring-[var(--bk-destructive)]/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] data-checked:bg-[var(--bk-primary)] data-unchecked:bg-[var(--bk-input)] data-disabled:cursor-not-allowed data-disabled:opacity-50",
356
+ className
357
+ ),
358
+ ...props,
359
+ children: /* @__PURE__ */ jsxRuntime.jsx(
360
+ _switch.Switch.Thumb,
361
+ {
362
+ "data-slot": "switch-thumb",
363
+ className: "pointer-events-none block rounded-full bg-[var(--bk-switch-thumb)] ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0"
364
+ }
365
+ )
366
+ }
367
+ );
368
+ }
369
+ function Separator({
370
+ className,
371
+ orientation = "horizontal",
372
+ ...props
373
+ }) {
374
+ return /* @__PURE__ */ jsxRuntime.jsx(
375
+ separator.Separator,
376
+ {
377
+ "data-slot": "separator",
378
+ orientation,
379
+ className: cn(
380
+ "shrink-0 bg-[var(--bk-border)] data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",
381
+ className
382
+ ),
383
+ ...props
384
+ }
385
+ );
386
+ }
387
+ function ScrollArea({
388
+ className,
389
+ style,
390
+ children,
391
+ viewportRef,
392
+ ...props
393
+ }) {
394
+ return /* @__PURE__ */ jsxRuntime.jsxs(
395
+ scrollArea.ScrollArea.Root,
396
+ {
397
+ "data-slot": "scroll-area",
398
+ style: { position: "relative", ...style },
399
+ className: cn("w-full", className),
400
+ ...props,
401
+ children: [
402
+ /* @__PURE__ */ jsxRuntime.jsx(
403
+ scrollArea.ScrollArea.Viewport,
404
+ {
405
+ ref: viewportRef,
406
+ "data-slot": "scroll-area-viewport",
407
+ className: "size-full outline-none rounded-[inherit]",
408
+ children
409
+ }
410
+ ),
411
+ /* @__PURE__ */ jsxRuntime.jsx(ScrollBar, { orientation: "vertical" }),
412
+ /* @__PURE__ */ jsxRuntime.jsx(ScrollBar, { orientation: "horizontal" }),
413
+ /* @__PURE__ */ jsxRuntime.jsx(scrollArea.ScrollArea.Corner, {})
414
+ ]
415
+ }
416
+ );
417
+ }
418
+ function ScrollBar({
419
+ className,
420
+ orientation = "vertical",
421
+ ...props
422
+ }) {
423
+ return /* @__PURE__ */ jsxRuntime.jsx(
424
+ scrollArea.ScrollArea.Scrollbar,
425
+ {
426
+ "data-slot": "scroll-area-scrollbar",
427
+ orientation,
428
+ className: cn(
429
+ "flex touch-none select-none p-px transition-opacity z-[11]",
430
+ orientation === "vertical" && "h-full w-2.5",
431
+ orientation === "horizontal" && "h-2.5 flex-col",
432
+ className
433
+ ),
434
+ ...props,
435
+ children: /* @__PURE__ */ jsxRuntime.jsx(
436
+ scrollArea.ScrollArea.Thumb,
437
+ {
438
+ "data-slot": "scroll-area-thumb",
439
+ className: "relative flex-1 rounded-full bg-[var(--bk-muted-foreground)]/30 hover:bg-[var(--bk-muted-foreground)]/50 transition-colors"
440
+ }
441
+ )
442
+ }
443
+ );
444
+ }
445
+ var AM_VALUE = 0;
446
+ var PM_VALUE = 1;
447
+ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, className }) {
448
+ const yearRef = React.useRef(null);
449
+ const years = React.useMemo(() => {
450
+ const result = [];
451
+ for (let i = 1912; i < 2100; i++) {
452
+ let disabled = false;
453
+ const startY = dateFns.startOfYear(dateFns.setYear(value, i));
454
+ const endY = dateFns.endOfYear(dateFns.setYear(value, i));
455
+ if (minDate && endY < minDate) disabled = true;
456
+ if (maxDate && startY > maxDate) disabled = true;
457
+ result.push({ value: i, label: i.toString(), disabled });
458
+ }
459
+ return result;
460
+ }, [value, minDate, maxDate]);
461
+ const months = React.useMemo(() => {
462
+ const result = [];
463
+ for (let i = 0; i < 12; i++) {
464
+ let disabled = false;
465
+ const startM = dateFns.startOfMonth(setMonth.setMonth(value, i));
466
+ const endM = dateFns.endOfMonth(setMonth.setMonth(value, i));
467
+ if (minDate && endM < minDate) disabled = true;
468
+ if (maxDate && startM > maxDate) disabled = true;
469
+ result.push({ value: i, label: dateFns.format(new Date(0, i), "MMM"), disabled });
470
+ }
471
+ return result;
472
+ }, [value, minDate, maxDate]);
473
+ const onYearChange = React.useCallback(
474
+ (v) => {
475
+ let newDate = dateFns.setYear(value, v.value);
476
+ if (minDate && newDate < minDate) newDate = setMonth.setMonth(newDate, dateFns.getMonth(minDate));
477
+ if (maxDate && newDate > maxDate) newDate = setMonth.setMonth(newDate, dateFns.getMonth(maxDate));
478
+ onChange(newDate, "year");
479
+ },
480
+ [onChange, value, minDate, maxDate]
481
+ );
482
+ React.useEffect(() => {
483
+ if (mode === "year") {
484
+ yearRef.current?.scrollIntoView({ behavior: "auto", block: "center" });
485
+ }
486
+ }, [mode, value]);
487
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(className), children: /* @__PURE__ */ jsxRuntime.jsxs(ScrollArea, { className: "h-full", children: [
488
+ mode === "year" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-4", children: years.map((year) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref: year.value === dateFns.getYear(value) ? yearRef : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(
489
+ Button,
490
+ {
491
+ disabled: year.disabled,
492
+ variant: dateFns.getYear(value) === year.value ? "default" : "ghost",
493
+ className: "rounded-none",
494
+ onClick: () => onYearChange(year),
495
+ children: year.label
496
+ }
497
+ ) }, year.value)) }),
498
+ mode === "month" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-3 gap-4 mt-7", children: months.map((month) => /* @__PURE__ */ jsxRuntime.jsx(
499
+ Button,
500
+ {
501
+ size: "lg",
502
+ disabled: month.disabled,
503
+ variant: dateFns.getMonth(value) === month.value ? "default" : "ghost",
504
+ className: "rounded-none",
505
+ onClick: () => onChange(setMonth.setMonth(value, month.value), "month"),
506
+ children: month.label
507
+ },
508
+ month.value
509
+ )) })
510
+ ] }) });
511
+ }
512
+ function TimeItem({ option, selected, onSelect, className, disabled }) {
513
+ return /* @__PURE__ */ jsxRuntime.jsxs(
514
+ Button,
515
+ {
516
+ variant: "ghost",
517
+ className: cn("flex justify-center px-1 pe-2 ps-1", className),
518
+ onClick: () => onSelect(option),
519
+ disabled,
520
+ children: [
521
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-4", children: selected && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, { className: "my-auto size-4" }) }),
522
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ms-2", children: option.label })
523
+ ]
524
+ }
525
+ );
526
+ }
527
+ function buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm }) {
528
+ if (use12HourFormat) {
529
+ const raw = dateFns.format(value, formatStr);
530
+ let s = raw.slice(0, 11) + hour.toString().padStart(2, "0") + raw.slice(13);
531
+ s = s.slice(0, 14) + minute.toString().padStart(2, "0") + s.slice(16);
532
+ s = s.slice(0, 17) + second.toString().padStart(2, "0") + s.slice(19);
533
+ s = s.slice(0, 24) + (ampm === AM_VALUE ? "AM" : "PM") + s.slice(26);
534
+ return dateFns.parse(s, formatStr, value);
535
+ }
536
+ return dateFns.setHours(dateFns.setMinutes(dateFns.setSeconds(value, second), minute), hour);
537
+ }
538
+ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker }) {
539
+ const formatStr = React.useMemo(
540
+ () => use12HourFormat ? "yyyy-MM-dd hh:mm:ss.SSS a xxxx" : "yyyy-MM-dd HH:mm:ss.SSS xxxx",
541
+ [use12HourFormat]
542
+ );
543
+ const [ampm, setAmpm] = React.useState(dateFns.format(value, "a") === "AM" ? AM_VALUE : PM_VALUE);
544
+ const [hour, setHour] = React.useState(use12HourFormat ? +dateFns.format(value, "hh") : value.getHours());
545
+ const [minute, setMinute] = React.useState(value.getMinutes());
546
+ const [second, setSecond] = React.useState(value.getSeconds());
547
+ React.useEffect(() => {
548
+ onChange(buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm }));
549
+ }, [hour, minute, second, ampm, formatStr, use12HourFormat]);
550
+ const hourIn24h = React.useMemo(
551
+ () => use12HourFormat ? hour % 12 + ampm * 12 : hour,
552
+ [hour, use12HourFormat, ampm]
553
+ );
554
+ const hours = React.useMemo(
555
+ () => Array.from({ length: use12HourFormat ? 12 : 24 }, (_, i) => {
556
+ const hourValue = use12HourFormat ? i === 0 ? 12 : i : i;
557
+ const hDate = dateFns.setHours(value, use12HourFormat ? i + ampm * 12 : i);
558
+ let disabled = false;
559
+ if (min && dateFns.endOfHour(hDate) < min) disabled = true;
560
+ if (max && dateFns.startOfHour(hDate) > max) disabled = true;
561
+ return { value: hourValue, label: hourValue.toString().padStart(2, "0"), disabled };
562
+ }),
563
+ [value, min, max, use12HourFormat, ampm]
564
+ );
565
+ const minutes = React.useMemo(() => {
566
+ const anchor = dateFns.setHours(value, hourIn24h);
567
+ return Array.from({ length: 60 }, (_, i) => {
568
+ const mDate = dateFns.setMinutes(anchor, i);
569
+ let disabled = false;
570
+ if (min && dateFns.endOfMinute(mDate) < min) disabled = true;
571
+ if (max && dateFns.startOfMinute(mDate) > max) disabled = true;
572
+ return { value: i, label: i.toString().padStart(2, "0"), disabled };
573
+ });
574
+ }, [value, min, max, hourIn24h]);
575
+ const seconds = React.useMemo(() => {
576
+ const anchor = dateFns.setMilliseconds(dateFns.setMinutes(dateFns.setHours(value, hourIn24h), minute), 0);
577
+ const _min = min ? dateFns.setMilliseconds(min, 0) : void 0;
578
+ const _max = max ? dateFns.setMilliseconds(max, 0) : void 0;
579
+ return Array.from({ length: 60 }, (_, i) => {
580
+ const sDate = dateFns.setSeconds(anchor, i);
581
+ let disabled = false;
582
+ if (_min && sDate < _min) disabled = true;
583
+ if (_max && sDate > _max) disabled = true;
584
+ return { value: i, label: i.toString().padStart(2, "0"), disabled };
585
+ });
586
+ }, [value, minute, min, max, hourIn24h]);
587
+ const ampmOptions = React.useMemo(() => {
588
+ const startD = dateFns.startOfDay(value);
589
+ const endD = dateFns.endOfDay(value);
590
+ return [
591
+ { value: AM_VALUE, label: "AM" },
592
+ { value: PM_VALUE, label: "PM" }
593
+ ].map((v) => {
594
+ let disabled = false;
595
+ const start = dateFns.addHours(startD, v.value * 12);
596
+ const end = dateFns.subHours(endD, (1 - v.value) * 12);
597
+ if (min && end < min) disabled = true;
598
+ if (max && start > max) disabled = true;
599
+ return { ...v, disabled };
600
+ });
601
+ }, [value, min, max]);
602
+ const [open, setOpen] = React.useState(false);
603
+ const hourViewportRef = React.useRef(null);
604
+ const minuteViewportRef = React.useRef(null);
605
+ const secondViewportRef = React.useRef(null);
606
+ React.useEffect(() => {
607
+ const id = setTimeout(() => {
608
+ if (open) {
609
+ const ITEM_H = 32;
610
+ const hourIdx = hours.findIndex((h) => h.value === hour);
611
+ if (hourViewportRef.current) hourViewportRef.current.scrollTop = hourIdx * ITEM_H;
612
+ if (minuteViewportRef.current) minuteViewportRef.current.scrollTop = minute * ITEM_H;
613
+ if (secondViewportRef.current) secondViewportRef.current.scrollTop = second * ITEM_H;
614
+ }
615
+ }, 1);
616
+ return () => clearTimeout(id);
617
+ }, [open, hours, hour, minute, second]);
618
+ const onHourChange = React.useCallback(
619
+ (v) => {
620
+ if (min) {
621
+ const t = buildTime({ use12HourFormat, value, formatStr, hour: v.value, minute, second, ampm });
622
+ if (t < min) {
623
+ setMinute(min.getMinutes());
624
+ setSecond(min.getSeconds());
625
+ }
626
+ }
627
+ if (max) {
628
+ const t = buildTime({ use12HourFormat, value, formatStr, hour: v.value, minute, second, ampm });
629
+ if (t > max) {
630
+ setMinute(max.getMinutes());
631
+ setSecond(max.getSeconds());
632
+ }
633
+ }
634
+ setHour(v.value);
635
+ },
636
+ [use12HourFormat, value, formatStr, minute, second, ampm, min, max]
637
+ );
638
+ const onMinuteChange = React.useCallback(
639
+ (v) => {
640
+ if (min) {
641
+ const t = buildTime({ use12HourFormat, value, formatStr, hour, minute: v.value, second, ampm });
642
+ if (t < min) setSecond(min.getSeconds());
643
+ }
644
+ if (max) {
645
+ const t = buildTime({ use12HourFormat, value, formatStr, hour, minute: v.value, second, ampm });
646
+ if (t > max) setSecond(max.getSeconds());
647
+ }
648
+ setMinute(v.value);
649
+ },
650
+ [use12HourFormat, value, formatStr, hour, second, ampm, min, max]
651
+ );
652
+ const onAmpmChange = React.useCallback(
653
+ (v) => {
654
+ if (min) {
655
+ const t = buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm: v.value });
656
+ if (t < min) {
657
+ const h = min.getHours() % 12;
658
+ setHour(h === 0 ? 12 : h);
659
+ setMinute(min.getMinutes());
660
+ setSecond(min.getSeconds());
661
+ }
662
+ }
663
+ if (max) {
664
+ const t = buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm: v.value });
665
+ if (t > max) {
666
+ const h = max.getHours() % 12;
667
+ setHour(h === 0 ? 12 : h);
668
+ setMinute(max.getMinutes());
669
+ setSecond(max.getSeconds());
670
+ }
671
+ }
672
+ setAmpm(v.value);
673
+ },
674
+ [use12HourFormat, value, formatStr, hour, minute, second, min, max]
675
+ );
676
+ const display = React.useMemo(() => {
677
+ const parts = [];
678
+ for (const el of ["hour", "minute", "second"]) {
679
+ if (!timePicker || timePicker[el]) {
680
+ parts.push(el === "hour" ? use12HourFormat ? "hh" : "HH" : el === "minute" ? "mm" : "ss");
681
+ }
682
+ }
683
+ return dateFns.format(value, parts.join(":") + (use12HourFormat ? " a" : ""));
684
+ }, [value, use12HourFormat, timePicker]);
685
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: setOpen, children: [
686
+ /* @__PURE__ */ jsxRuntime.jsx(
687
+ PopoverTrigger,
688
+ {
689
+ render: (props) => /* @__PURE__ */ jsxRuntime.jsxs(
690
+ Button,
691
+ {
692
+ ...props,
693
+ variant: "ghost",
694
+ role: "combobox",
695
+ "aria-label": "Select time",
696
+ "aria-expanded": open,
697
+ className: "w-full justify-between px-2",
698
+ children: [
699
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "mr-2 size-4" }),
700
+ display,
701
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { className: "ml-2 size-4 shrink-0 opacity-50" })
702
+ ]
703
+ }
704
+ )
705
+ }
706
+ ),
707
+ /* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "p-0", side: "top", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-col gap-2 p-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-56 grow", children: [
708
+ (!timePicker || timePicker.hour) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "h-full grow", viewportRef: hourViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: hours.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === hour, onSelect: onHourChange, className: "h-8", disabled: v.disabled }, v.value)) }) }),
709
+ (!timePicker || timePicker.minute) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "h-full grow", viewportRef: minuteViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: minutes.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === minute, onSelect: onMinuteChange, className: "h-8", disabled: v.disabled }, v.value)) }) }),
710
+ (!timePicker || timePicker.second) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "h-full grow", viewportRef: secondViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: seconds.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === second, onSelect: (v2) => setSecond(v2.value), className: "h-8", disabled: v.disabled }, v.value)) }) }),
711
+ use12HourFormat && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "h-full grow", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2", children: ampmOptions.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === ampm, onSelect: onAmpmChange, className: "h-8", disabled: v.disabled }, v.value)) }) })
712
+ ] }) }) })
713
+ ] });
714
+ }
715
+ function precisionToTimePicker(precision) {
716
+ if (precision === "date") return void 0;
717
+ return {
718
+ hour: true,
719
+ minute: precision === "minute" || precision === "second",
720
+ second: precision === "second"
721
+ };
722
+ }
723
+ function DateTimePanel({
724
+ value,
725
+ onChangeAction,
726
+ min,
727
+ max,
728
+ timezone,
729
+ precision = "second",
730
+ use12HourFormat,
731
+ immediate = false,
732
+ isError,
733
+ compareValue,
734
+ title,
735
+ validateDateRange,
736
+ getRangeErrorMessage,
737
+ ...props
738
+ }) {
739
+ const [monthYearPicker, setMonthYearPicker] = React.useState(false);
740
+ const initDate = React.useMemo(() => new reactDayPicker.TZDate(value || /* @__PURE__ */ new Date(), timezone), [value, timezone]);
741
+ const [month, setMonth] = React.useState(initDate);
742
+ const [date, setDate] = React.useState(initDate);
743
+ const [errorType, setErrorType] = React.useState(null);
744
+ const [previousDate, setPreviousDate] = React.useState(initDate);
745
+ const endMonth = React.useMemo(() => dateFns.setYear(month, dateFns.getYear(month) + 1), [month]);
746
+ const minDate = React.useMemo(() => min ? new reactDayPicker.TZDate(min, timezone) : void 0, [min, timezone]);
747
+ const maxDate = React.useMemo(() => max ? new reactDayPicker.TZDate(max, timezone) : void 0, [max, timezone]);
748
+ const validate = React.useCallback(
749
+ (cur, cmp) => {
750
+ if (validateDateRange) return validateDateRange(cur, cmp);
751
+ if (!cmp) return { isValid: true, errorType: null };
752
+ if (title === "Start Date" && cur >= cmp) return { isValid: false, errorType: "validation" };
753
+ if (title === "End Date" && cur <= cmp) return { isValid: false, errorType: "validation" };
754
+ return { isValid: true, errorType: null };
755
+ },
756
+ [validateDateRange, title]
757
+ );
758
+ const onDayChanged = React.useCallback(
759
+ (d) => {
760
+ d.setHours(date.getHours(), date.getMinutes(), date.getSeconds());
761
+ if (min && d < min) d.setHours(min.getHours(), min.getMinutes(), min.getSeconds());
762
+ if (max && d > max) d.setHours(max.getHours(), max.getMinutes(), max.getSeconds());
763
+ setDate(d);
764
+ if (immediate) onChangeAction(new Date(d), true);
765
+ },
766
+ [date, immediate, onChangeAction, min, max]
767
+ );
768
+ const onTimeChanged = React.useCallback(
769
+ (d) => {
770
+ setDate(d);
771
+ if (immediate) onChangeAction(new Date(d), true);
772
+ },
773
+ [immediate, onChangeAction]
774
+ );
775
+ const onSubmit = React.useCallback(() => {
776
+ const result = validate(date, compareValue);
777
+ setErrorType(result.isValid ? null : result.errorType);
778
+ if (result.isValid) {
779
+ onChangeAction(new Date(date), true);
780
+ setPreviousDate(new Date(date));
781
+ }
782
+ }, [date, onChangeAction, compareValue, validate]);
783
+ const onCancel = React.useCallback(() => {
784
+ setDate(previousDate);
785
+ setMonth(previousDate);
786
+ setErrorType(null);
787
+ onChangeAction(void 0, false);
788
+ }, [previousDate, onChangeAction]);
789
+ const onMonthYearChanged = React.useCallback((d, mode) => {
790
+ setMonth(d);
791
+ setMonthYearPicker(mode === "year" ? "month" : false);
792
+ }, []);
793
+ const onNextMonth = React.useCallback(() => setMonth(dateFns.addMonths(month, 1)), [month]);
794
+ const onPrevMonth = React.useCallback(() => setMonth(dateFns.subMonths(month, 1)), [month]);
795
+ React.useEffect(() => {
796
+ setDate(initDate);
797
+ setMonth(initDate);
798
+ setMonthYearPicker(false);
799
+ setPreviousDate(initDate);
800
+ }, [initDate]);
801
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
802
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-3 pt-3", children: [
803
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-md font-bold flex gap-2 items-center cursor-pointer", children: [
804
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
805
+ /* @__PURE__ */ jsxRuntime.jsx("span", { onClick: () => setMonthYearPicker(monthYearPicker === "month" ? false : "month"), children: dateFns.format(month, "MMMM") }),
806
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ms-1", onClick: () => setMonthYearPicker(monthYearPicker === "year" ? false : "year"), children: dateFns.format(month, "yyyy") })
807
+ ] }),
808
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", size: "icon", className: "w-7 h-7", onClick: () => setMonthYearPicker(monthYearPicker ? false : "year"), children: monthYearPicker ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { className: "w-4 h-4 stroke-muted-foreground" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { className: "w-4 h-4 stroke-muted-foreground" }) })
809
+ ] }),
810
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex space-x-2", monthYearPicker ? "hidden" : ""), children: [
811
+ /* @__PURE__ */ jsxRuntime.jsx(
812
+ Button,
813
+ {
814
+ variant: "ghost",
815
+ size: "icon",
816
+ className: "w-7 h-7",
817
+ "aria-label": "Previous month",
818
+ onClick: onPrevMonth,
819
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, { className: "w-4 h-4 stroke-muted-foreground" })
820
+ }
821
+ ),
822
+ /* @__PURE__ */ jsxRuntime.jsx(
823
+ Button,
824
+ {
825
+ variant: "ghost",
826
+ size: "icon",
827
+ className: "w-7 h-7",
828
+ "aria-label": "Next month",
829
+ onClick: onNextMonth,
830
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRightIcon, { className: "w-4 h-4 stroke-muted-foreground" })
831
+ }
832
+ )
833
+ ] })
834
+ ] }),
835
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative overflow-hidden px-3", children: [
836
+ /* @__PURE__ */ jsxRuntime.jsx(
837
+ reactDayPicker.DayPicker,
838
+ {
839
+ timeZone: timezone,
840
+ mode: "single",
841
+ selected: date,
842
+ modifiers: {
843
+ selected: (sel) => {
844
+ const a = new Date(sel);
845
+ const b = new Date(date);
846
+ return a.setHours(0, 0, 0, 0) === b.setHours(0, 0, 0, 0);
847
+ },
848
+ range_middle: (cur) => {
849
+ const d = new Date(date);
850
+ const c = new Date(cur);
851
+ return !!max && cur < max && c > d || !!min && cur > min && c < d;
852
+ }
853
+ },
854
+ onSelect: (d) => d && onDayChanged(d),
855
+ month,
856
+ endMonth,
857
+ disabled: [max ? { after: max } : null, min ? { before: min } : null].filter(Boolean),
858
+ onMonthChange: setMonth,
859
+ classNames: {
860
+ dropdowns: "flex w-full gap-2",
861
+ months: "flex w-full h-fit",
862
+ month: "flex flex-col w-full",
863
+ month_caption: "hidden",
864
+ button_previous: "hidden",
865
+ button_next: "hidden",
866
+ month_grid: "w-full border-collapse",
867
+ weekdays: "flex justify-between mt-2",
868
+ weekday: "text-[var(--bk-muted-foreground)] rounded-md w-9 font-normal text-[0.8rem]",
869
+ week: "flex w-full justify-between mt-2",
870
+ day: "h-9 w-9 text-center text-sm p-0 relative flex items-center justify-center focus-within:relative focus-within:z-20 [&[aria-selected]>button:hover]:bg-[var(--bk-primary)] [&[aria-selected]>button:hover]:text-[var(--bk-primary-foreground)]",
871
+ day_button: cn(buttonVariants({ variant: "ghost" }), "size-9 p-0 font-normal"),
872
+ range_end: "day-range-end bg-[var(--bk-primary)]",
873
+ selected: "bg-[var(--bk-primary)] text-[var(--bk-primary-foreground)] hover:bg-[var(--bk-primary)] hover:text-[var(--bk-primary-foreground)] focus:bg-[var(--bk-primary)] focus:text-[var(--bk-primary-foreground)]",
874
+ today: "bg-[var(--bk-accent)] text-[var(--bk-accent-foreground)]",
875
+ outside: "day-outside text-[var(--bk-muted-foreground)]/80 aria-selected:bg-[var(--bk-primary)] aria-selected:text-[var(--bk-primary-foreground)]",
876
+ disabled: "text-[var(--bk-muted-foreground)] opacity-50",
877
+ range_middle: "w-full bg-[var(--bk-secondary)] aria-selected:bg-[var(--bk-primary)] aria-selected:text-[var(--bk-primary-foreground)]",
878
+ hidden: "invisible"
879
+ },
880
+ showOutsideDays: true,
881
+ ...props
882
+ }
883
+ ),
884
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("absolute top-0 left-0 bottom-0 right-0", monthYearPicker ? "bg-[var(--bk-popover)]" : "hidden") }),
885
+ /* @__PURE__ */ jsxRuntime.jsx(
886
+ MonthYearPicker,
887
+ {
888
+ value: month,
889
+ mode: monthYearPicker,
890
+ onChange: onMonthYearChanged,
891
+ minDate,
892
+ maxDate,
893
+ className: cn("absolute top-0 left-0 bottom-0 right-0", monthYearPicker ? "" : "hidden")
894
+ }
895
+ )
896
+ ] }),
897
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 px-3 pb-2", children: [
898
+ precision !== "date" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 border-t border-[var(--bk-border)] pt-2", children: /* @__PURE__ */ jsxRuntime.jsx(
899
+ TimePicker,
900
+ {
901
+ timePicker: precisionToTimePicker(precision),
902
+ value: date,
903
+ onChange: onTimeChanged,
904
+ use12HourFormat,
905
+ min: minDate,
906
+ max: maxDate
907
+ }
908
+ ) }),
909
+ (isError || errorType !== null) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-3 px-4 border border-[var(--bk-destructive)] max-w-full", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-[var(--bk-destructive)] leading-snug block", children: getRangeErrorMessage?.(errorType, title) ?? "Invalid date range." }) }),
910
+ !immediate && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-2", children: [
911
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", onClick: onCancel, children: "Cancel" }),
912
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "sm", onClick: onSubmit, children: "Done" })
913
+ ] })
914
+ ] })
915
+ ] });
916
+ }
917
+ var SEGMENTS = [
918
+ { key: "year", min: 1900, max: 2099, digits: 4, label: "YYYY" },
919
+ { key: "month", min: 1, max: 12, digits: 2, label: "MM" },
920
+ { key: "day", min: 1, max: 31, digits: 2, label: "DD" },
921
+ { key: "hour", min: 0, max: 23, digits: 2, label: "HH" },
922
+ { key: "minute", min: 0, max: 59, digits: 2, label: "mm" },
923
+ { key: "second", min: 0, max: 59, digits: 2, label: "ss" }
924
+ ];
925
+ function getSegmentValue(date, key) {
926
+ switch (key) {
927
+ case "year":
928
+ return date.getFullYear();
929
+ case "month":
930
+ return date.getMonth() + 1;
931
+ case "day":
932
+ return date.getDate();
933
+ case "hour":
934
+ return date.getHours();
935
+ case "minute":
936
+ return date.getMinutes();
937
+ case "second":
938
+ return date.getSeconds();
939
+ }
940
+ }
941
+ function applySegment(date, key, value) {
942
+ const d = new Date(date);
943
+ switch (key) {
944
+ case "year":
945
+ d.setFullYear(value);
946
+ break;
947
+ case "month":
948
+ d.setMonth(value - 1);
949
+ break;
950
+ case "day":
951
+ d.setDate(value);
952
+ break;
953
+ case "hour":
954
+ d.setHours(value);
955
+ break;
956
+ case "minute":
957
+ d.setMinutes(value);
958
+ break;
959
+ case "second":
960
+ d.setSeconds(value);
961
+ break;
962
+ }
963
+ return d;
964
+ }
965
+ function clamp(value, min, max) {
966
+ return Math.max(min, Math.min(max, value));
967
+ }
968
+ function DatetimeSegmentInput({
969
+ value,
970
+ onChange,
971
+ disabled = false,
972
+ className,
973
+ isError = false,
974
+ precision = "second"
975
+ }) {
976
+ const containerRef = React.useRef(null);
977
+ const spanRefs = React.useRef({
978
+ year: null,
979
+ month: null,
980
+ day: null,
981
+ hour: null,
982
+ minute: null,
983
+ second: null
984
+ });
985
+ const [typing, setTyping] = React.useState({
986
+ year: null,
987
+ month: null,
988
+ day: null,
989
+ hour: null,
990
+ minute: null,
991
+ second: null
992
+ });
993
+ const date = React.useMemo(
994
+ () => !Number.isNaN(value.getTime()) ? value : /* @__PURE__ */ new Date(),
995
+ [value]
996
+ );
997
+ const focusSegment = React.useCallback((key) => {
998
+ spanRefs.current[key]?.focus();
999
+ }, []);
1000
+ const commitTyping = React.useCallback((key, buf) => {
1001
+ const num = parseInt(buf, 10);
1002
+ const seg = SEGMENTS.find((s) => s.key === key);
1003
+ if (!Number.isNaN(num)) {
1004
+ const clamped = clamp(num, seg.min, seg.max);
1005
+ onChange(applySegment(date, key, clamped));
1006
+ }
1007
+ setTyping((prev) => ({ ...prev, [key]: null }));
1008
+ }, [date, onChange]);
1009
+ const activeSegments = React.useMemo(() => {
1010
+ const count = precision === "date" ? 3 : precision === "hour" ? 4 : precision === "minute" ? 5 : 6;
1011
+ return SEGMENTS.slice(0, count);
1012
+ }, [precision]);
1013
+ const handleKeyDown = React.useCallback((e, seg) => {
1014
+ if (disabled) return;
1015
+ const { key } = seg;
1016
+ const idx = activeSegments.findIndex((s) => s.key === key);
1017
+ const cur = typing[key];
1018
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
1019
+ e.preventDefault();
1020
+ if (cur !== null) commitTyping(key, cur);
1021
+ const delta = e.key === "ArrowUp" ? 1 : -1;
1022
+ const current = getSegmentValue(date, key);
1023
+ const next = clamp(current + delta, seg.min, seg.max);
1024
+ onChange(applySegment(date, key, next));
1025
+ return;
1026
+ }
1027
+ if (e.key === "ArrowLeft" || e.key === "Tab" && e.shiftKey) {
1028
+ e.preventDefault();
1029
+ if (cur !== null) commitTyping(key, cur);
1030
+ if (idx > 0) focusSegment(activeSegments[idx - 1].key);
1031
+ return;
1032
+ }
1033
+ if (e.key === "ArrowRight" || e.key === "Tab" && !e.shiftKey) {
1034
+ e.preventDefault();
1035
+ if (cur !== null) commitTyping(key, cur);
1036
+ if (idx < activeSegments.length - 1) focusSegment(activeSegments[idx + 1].key);
1037
+ return;
1038
+ }
1039
+ if (e.key === "Backspace" || e.key === "Delete") {
1040
+ e.preventDefault();
1041
+ setTyping((prev) => ({ ...prev, [key]: null }));
1042
+ return;
1043
+ }
1044
+ if (/^\d$/.test(e.key)) {
1045
+ e.preventDefault();
1046
+ const next = (cur === null ? "" : cur) + e.key;
1047
+ if (next.length >= seg.digits) {
1048
+ commitTyping(key, next);
1049
+ if (idx < activeSegments.length - 1) {
1050
+ setTimeout(() => focusSegment(activeSegments[idx + 1].key), 0);
1051
+ }
1052
+ } else {
1053
+ setTyping((prev) => ({ ...prev, [key]: next }));
1054
+ }
1055
+ return;
1056
+ }
1057
+ }, [disabled, typing, date, onChange, commitTyping, focusSegment, activeSegments]);
1058
+ const handleBlur = React.useCallback((key) => {
1059
+ const buf = typing[key];
1060
+ if (buf !== null) commitTyping(key, buf);
1061
+ }, [typing, commitTyping]);
1062
+ const displayValue = (seg) => {
1063
+ const buf = typing[seg.key];
1064
+ if (buf !== null) return buf.padStart(seg.digits, "_").slice(-seg.digits);
1065
+ const val = getSegmentValue(date, seg.key);
1066
+ return String(val).padStart(seg.digits, "0");
1067
+ };
1068
+ return /* @__PURE__ */ jsxRuntime.jsx(
1069
+ "div",
1070
+ {
1071
+ ref: containerRef,
1072
+ className: cn(
1073
+ "inline-flex h-8 px-2.5 rounded-[var(--bk-radius)] border border-[var(--bk-input)] bg-transparent text-xs transition-colors",
1074
+ "focus-within:border-[var(--bk-ring)] focus-within:ring-1 focus-within:ring-[var(--bk-ring)]/50 items-center",
1075
+ isError && "border-[var(--bk-destructive)] ring-1 ring-[var(--bk-destructive)]/20",
1076
+ disabled && "opacity-50 cursor-not-allowed pointer-events-none bg-[var(--bk-input)]/50",
1077
+ className
1078
+ ),
1079
+ onMouseDown: (e) => {
1080
+ const target = e.target;
1081
+ if (target.tagName === "SPAN") {
1082
+ e.preventDefault();
1083
+ focusSegment(precision === "date" ? "year" : "hour");
1084
+ }
1085
+ },
1086
+ children: activeSegments.map((seg, idx) => {
1087
+ const sep = idx === 0 ? null : idx === 3 ? "\xA0" : idx < 3 ? "-" : ":";
1088
+ const isFocused = typing[seg.key] !== null;
1089
+ return /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
1090
+ sep !== null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[var(--bk-muted-foreground)] select-none items-center", "aria-hidden": true, children: sep }),
1091
+ /* @__PURE__ */ jsxRuntime.jsx(
1092
+ "div",
1093
+ {
1094
+ ref: (el) => {
1095
+ spanRefs.current[seg.key] = el;
1096
+ },
1097
+ role: "spinbutton",
1098
+ "aria-label": seg.label,
1099
+ "aria-valuenow": getSegmentValue(date, seg.key),
1100
+ "aria-valuemin": seg.min,
1101
+ "aria-valuemax": seg.max,
1102
+ tabIndex: disabled ? -1 : 0,
1103
+ className: cn(
1104
+ "outline-none rounded-sm px-1 cursor-default select-none",
1105
+ "focus:bg-[var(--bk-primary)] focus:text-[var(--bk-primary-foreground)]",
1106
+ isFocused && "bg-[var(--bk-primary)]/20"
1107
+ ),
1108
+ style: { height: "24px", lineHeight: "24px" },
1109
+ onKeyDown: (e) => handleKeyDown(e, seg),
1110
+ onBlur: () => handleBlur(seg.key),
1111
+ children: displayValue(seg)
1112
+ }
1113
+ )
1114
+ ] }, seg.key);
1115
+ })
1116
+ }
1117
+ );
1118
+ }
1119
+
1120
+ // src/types.ts
1121
+ var DEFAULT_LABELS = {
1122
+ start: "Start",
1123
+ end: "End",
1124
+ quickRanges: "Quick ranges",
1125
+ apply: "Apply",
1126
+ cancel: "Cancel",
1127
+ absolute: "Absolute",
1128
+ relative: "Relative",
1129
+ amount: "Amount",
1130
+ now: "Now",
1131
+ nowDescription: "Set to current time"
1132
+ };
1133
+ var RELATIVE_FORMATS = [
1134
+ "Seconds ago",
1135
+ "Minutes ago",
1136
+ "Hours ago",
1137
+ "Days ago",
1138
+ "Weeks ago",
1139
+ "Months ago"
1140
+ ];
1141
+ var QUICK_PRESETS = [
1142
+ { label: "Last 5 minutes", start: { type: "relative", relativeValue: "5", relativeFormat: "Minutes ago" }, end: { type: "relative", relativeNow: true } },
1143
+ { label: "Last 15 minutes", start: { type: "relative", relativeValue: "15", relativeFormat: "Minutes ago" }, end: { type: "relative", relativeNow: true } },
1144
+ { label: "Last 30 minutes", start: { type: "relative", relativeValue: "30", relativeFormat: "Minutes ago" }, end: { type: "relative", relativeNow: true } },
1145
+ { label: "Last 1 hour", start: { type: "relative", relativeValue: "1", relativeFormat: "Hours ago" }, end: { type: "relative", relativeNow: true } },
1146
+ { label: "Last 3 hours", start: { type: "relative", relativeValue: "3", relativeFormat: "Hours ago" }, end: { type: "relative", relativeNow: true } },
1147
+ { label: "Last 6 hours", start: { type: "relative", relativeValue: "6", relativeFormat: "Hours ago" }, end: { type: "relative", relativeNow: true } },
1148
+ { label: "Last 12 hours", start: { type: "relative", relativeValue: "12", relativeFormat: "Hours ago" }, end: { type: "relative", relativeNow: true } },
1149
+ { label: "Last 24 hours", start: { type: "relative", relativeValue: "24", relativeFormat: "Hours ago" }, end: { type: "relative", relativeNow: true } },
1150
+ { label: "Last 2 days", start: { type: "relative", relativeValue: "2", relativeFormat: "Days ago" }, end: { type: "relative", relativeNow: true } },
1151
+ { label: "Last 7 days", start: { type: "relative", relativeValue: "7", relativeFormat: "Days ago" }, end: { type: "relative", relativeNow: true } },
1152
+ { label: "Last 30 days", start: { type: "relative", relativeValue: "30", relativeFormat: "Days ago" }, end: { type: "relative", relativeNow: true } },
1153
+ { label: "Last 90 days", start: { type: "relative", relativeValue: "90", relativeFormat: "Days ago" }, end: { type: "relative", relativeNow: true } },
1154
+ { label: "Last 6 months", start: { type: "relative", relativeValue: "6", relativeFormat: "Months ago" }, end: { type: "relative", relativeNow: true } },
1155
+ { label: "Last 1 year", start: { type: "relative", relativeValue: "12", relativeFormat: "Months ago" }, end: { type: "relative", relativeNow: true } }
1156
+ ];
1157
+ function toDate(value) {
1158
+ if (value.type === "absolute") {
1159
+ if (value.absoluteValue instanceof Date) return value.absoluteValue;
1160
+ if (value.absoluteValue) return new Date(value.absoluteValue);
1161
+ return /* @__PURE__ */ new Date();
1162
+ }
1163
+ if (value.relativeNow) return /* @__PURE__ */ new Date();
1164
+ let relStr;
1165
+ if (value.relativeFormat) {
1166
+ relStr = `${value.relativeValue} ${value.relativeFormat}`;
1167
+ } else {
1168
+ relStr = String(value.relativeValue ?? "");
1169
+ }
1170
+ const parsed = chrono__namespace.parseDate(relStr);
1171
+ return parsed ?? /* @__PURE__ */ new Date();
1172
+ }
1173
+ function toTimestampMs(value) {
1174
+ return toDate(value).getTime();
1175
+ }
1176
+ function toTimestamp(value) {
1177
+ return Math.floor(toTimestampMs(value) / 1e3);
1178
+ }
1179
+ function toDisplayString(value, options) {
1180
+ if (value.type === "absolute") {
1181
+ if (!value.absoluteValue) return "None";
1182
+ const p = options?.precision ?? "second";
1183
+ const fmt = { year: "numeric", month: "2-digit", day: "2-digit" };
1184
+ if (p === "hour" || p === "minute" || p === "second") fmt.hour = "2-digit";
1185
+ if (p === "minute" || p === "second") fmt.minute = "2-digit";
1186
+ if (p === "second") fmt.second = "2-digit";
1187
+ return value.absoluteValue.toLocaleString(navigator.language, fmt);
1188
+ }
1189
+ if (value.relativeNow) return "now";
1190
+ return `${value.relativeValue ?? ""}${value.relativeFormat ? " " + value.relativeFormat : ""}`;
1191
+ }
1192
+ function toUrlString(value) {
1193
+ if (value.type === "absolute") {
1194
+ const date = value.absoluteValue instanceof Date ? value.absoluteValue : value.absoluteValue ? new Date(value.absoluteValue) : /* @__PURE__ */ new Date();
1195
+ return date.getTime().toString();
1196
+ }
1197
+ if (value.relativeNow) return "now";
1198
+ if (typeof value.relativeValue === "string" && !value.relativeFormat) {
1199
+ return value.relativeValue.startsWith("now") ? value.relativeValue : `now${value.relativeValue}`;
1200
+ }
1201
+ const unitMap = {
1202
+ "Seconds ago": "s",
1203
+ "Minutes ago": "m",
1204
+ "Hours ago": "h",
1205
+ "Days ago": "d",
1206
+ "Weeks ago": "w",
1207
+ "Months ago": "M",
1208
+ "Years ago": "y"
1209
+ };
1210
+ const unit = value.relativeFormat ? unitMap[value.relativeFormat] : "h";
1211
+ const amount = value.relativeValue ?? 1;
1212
+ return `now-${amount}${unit}`;
1213
+ }
1214
+ function fromUrlString(urlString) {
1215
+ if (urlString === "now") return { type: "relative", relativeNow: true };
1216
+ if (urlString.startsWith("now")) {
1217
+ const match = urlString.match(/^now([+-]?)(\d+)([smhdwMy])$/);
1218
+ if (match) {
1219
+ const [, sign, amount, unit] = match;
1220
+ const unitToFormat = {
1221
+ s: "Seconds ago",
1222
+ m: "Minutes ago",
1223
+ h: "Hours ago",
1224
+ d: "Days ago",
1225
+ w: "Weeks ago",
1226
+ M: "Months ago",
1227
+ y: "Years ago"
1228
+ };
1229
+ const relativeFormat = unitToFormat[unit];
1230
+ if (relativeFormat && sign !== "+") {
1231
+ return { type: "relative", relativeValue: amount, relativeFormat, relativeNow: false };
1232
+ }
1233
+ return { type: "relative", relativeValue: `${sign}${amount}${unit}`, relativeNow: false };
1234
+ }
1235
+ return { type: "relative", relativeNow: true };
1236
+ }
1237
+ const timestamp = parseInt(urlString, 10);
1238
+ if (!isNaN(timestamp)) return { type: "absolute", absoluteValue: new Date(timestamp) };
1239
+ return { type: "relative", relativeNow: true };
1240
+ }
1241
+ function relativeNow() {
1242
+ return { type: "relative", relativeNow: true };
1243
+ }
1244
+ function relativeAgo(value, format3) {
1245
+ return { type: "relative", relativeValue: String(value), relativeFormat: format3 };
1246
+ }
1247
+ function absoluteDate(date) {
1248
+ return { type: "absolute", absoluteValue: date };
1249
+ }
1250
+ function validateRange(start, end) {
1251
+ const startDate = toDate(start);
1252
+ const endDate = toDate(end);
1253
+ if (startDate >= endDate) return "validation";
1254
+ return null;
1255
+ }
1256
+ function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }) {
1257
+ const [numValue, setNumValue] = React.useState(
1258
+ value.relativeValue !== void 0 ? String(value.relativeValue) : "5"
1259
+ );
1260
+ const [format3, setFormat] = React.useState(
1261
+ value.relativeFormat ?? relativeFormats[0] ?? "Minutes ago"
1262
+ );
1263
+ const [isNow, setIsNow] = React.useState(value.relativeNow ?? false);
1264
+ React.useEffect(() => {
1265
+ if (value.relativeNow) {
1266
+ setIsNow(true);
1267
+ } else {
1268
+ setIsNow(false);
1269
+ if (value.relativeValue !== void 0) setNumValue(String(value.relativeValue));
1270
+ if (value.relativeFormat) setFormat(value.relativeFormat);
1271
+ }
1272
+ }, [value]);
1273
+ const emit = (next) => {
1274
+ if (next.isNow) {
1275
+ onChange({ type: "relative", relativeNow: true });
1276
+ } else {
1277
+ onChange({
1278
+ type: "relative",
1279
+ relativeValue: next.numValue,
1280
+ relativeFormat: next.format,
1281
+ relativeNow: false
1282
+ });
1283
+ }
1284
+ };
1285
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 mt-3", children: [
1286
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1287
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[11px] text-muted-foreground mb-1.5", children: labels.amount }),
1288
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row gap-1.5", children: [
1289
+ /* @__PURE__ */ jsxRuntime.jsx(
1290
+ Input,
1291
+ {
1292
+ type: "text",
1293
+ inputMode: "numeric",
1294
+ pattern: "[0-9]*",
1295
+ className: "h-8 w-20 text-xs",
1296
+ disabled: isNow,
1297
+ value: numValue,
1298
+ onChange: (e) => {
1299
+ const val = e.target.value;
1300
+ if (/^\d*$/.test(val)) {
1301
+ setNumValue(val);
1302
+ emit({ numValue: val, format: format3, isNow });
1303
+ }
1304
+ },
1305
+ onWheel: (e) => e.currentTarget.blur(),
1306
+ onKeyDown: (e) => {
1307
+ if (["e", "E", "+", "-", "."].includes(e.key)) e.preventDefault();
1308
+ }
1309
+ }
1310
+ ),
1311
+ /* @__PURE__ */ jsxRuntime.jsxs(
1312
+ Select,
1313
+ {
1314
+ disabled: isNow,
1315
+ value: format3,
1316
+ onValueChange: (v) => {
1317
+ const f = v;
1318
+ setFormat(f);
1319
+ emit({ numValue, format: f, isNow });
1320
+ },
1321
+ children: [
1322
+ /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 text-xs text-left leading-tight", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { children: format3 }) }),
1323
+ /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: relativeFormats.map((f) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: f, className: "text-xs", children: f }, f)) })
1324
+ ]
1325
+ }
1326
+ )
1327
+ ] })
1328
+ ] }),
1329
+ showNow && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row gap-2 items-center pt-0.5", children: [
1330
+ /* @__PURE__ */ jsxRuntime.jsx(
1331
+ Switch,
1332
+ {
1333
+ checked: isNow,
1334
+ onCheckedChange: (checked) => {
1335
+ setIsNow(checked);
1336
+ emit({ numValue, format: format3, isNow: checked });
1337
+ }
1338
+ }
1339
+ ),
1340
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
1341
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-xs font-medium", children: labels.now }),
1342
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] text-muted-foreground", children: labels.nowDescription })
1343
+ ] })
1344
+ ] })
1345
+ ] });
1346
+ }
1347
+ function AbsoluteContent({
1348
+ value,
1349
+ compareValue,
1350
+ title,
1351
+ onChange,
1352
+ precision,
1353
+ min,
1354
+ max,
1355
+ timezone,
1356
+ use12HourFormat
1357
+ }) {
1358
+ const compareDate = compareValue ? toDate(compareValue) : void 0;
1359
+ const absoluteDate_ = value.type === "absolute" ? toDate(value) : /* @__PURE__ */ new Date();
1360
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 mt-3", children: [
1361
+ /* @__PURE__ */ jsxRuntime.jsx(
1362
+ DatetimeSegmentInput,
1363
+ {
1364
+ value: absoluteDate_,
1365
+ onChange: (d) => onChange(absoluteDate(d)),
1366
+ className: "flex-1",
1367
+ precision
1368
+ }
1369
+ ),
1370
+ /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
1371
+ /* @__PURE__ */ jsxRuntime.jsx(
1372
+ PopoverTrigger,
1373
+ {
1374
+ render: (triggerProps) => /* @__PURE__ */ jsxRuntime.jsx(
1375
+ Button,
1376
+ {
1377
+ ...triggerProps,
1378
+ type: "button",
1379
+ variant: "outline",
1380
+ size: "icon",
1381
+ className: "h-8 w-8 shrink-0",
1382
+ title: "Pick from calendar",
1383
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14 })
1384
+ }
1385
+ )
1386
+ }
1387
+ ),
1388
+ /* @__PURE__ */ jsxRuntime.jsx(
1389
+ PopoverContent,
1390
+ {
1391
+ className: "p-0 w-auto",
1392
+ side: "bottom",
1393
+ align: "start",
1394
+ sideOffset: 6,
1395
+ disableAnchorTracking: true,
1396
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1397
+ DateTimePanel,
1398
+ {
1399
+ value: value.type === "absolute" ? toDate(value) : void 0,
1400
+ compareValue: compareDate,
1401
+ title,
1402
+ immediate: true,
1403
+ precision,
1404
+ min,
1405
+ max,
1406
+ timezone,
1407
+ use12HourFormat,
1408
+ onChangeAction: (d) => {
1409
+ if (!d) return;
1410
+ onChange(absoluteDate(d));
1411
+ }
1412
+ }
1413
+ )
1414
+ }
1415
+ )
1416
+ ] })
1417
+ ] });
1418
+ }
1419
+ function SidePanel({
1420
+ title,
1421
+ value,
1422
+ compareValue,
1423
+ onChange,
1424
+ showAbsolute,
1425
+ showRelative,
1426
+ precision,
1427
+ relativeFormats,
1428
+ showNow,
1429
+ min,
1430
+ max,
1431
+ timezone,
1432
+ use12HourFormat,
1433
+ labels
1434
+ }) {
1435
+ React.useEffect(() => {
1436
+ if (!showRelative && value.type === "relative") {
1437
+ onChange(absoluteDate(/* @__PURE__ */ new Date()));
1438
+ } else if (!showAbsolute && value.type === "absolute") {
1439
+ onChange({ type: "relative", relativeValue: "5", relativeFormat: relativeFormats[0] ?? "Minutes ago" });
1440
+ }
1441
+ }, [showRelative, showAbsolute]);
1442
+ const hasBothModes = showAbsolute && showRelative;
1443
+ const absoluteContent = /* @__PURE__ */ jsxRuntime.jsx(
1444
+ AbsoluteContent,
1445
+ {
1446
+ value,
1447
+ compareValue,
1448
+ title,
1449
+ onChange,
1450
+ precision,
1451
+ min,
1452
+ max,
1453
+ timezone,
1454
+ use12HourFormat
1455
+ }
1456
+ );
1457
+ const relativeContent = /* @__PURE__ */ jsxRuntime.jsx(
1458
+ RelativeSidePanel,
1459
+ {
1460
+ value,
1461
+ onChange,
1462
+ relativeFormats,
1463
+ showNow,
1464
+ labels
1465
+ }
1466
+ );
1467
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col w-[268px]", children: [
1468
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-widest pb-2", children: title }),
1469
+ hasBothModes ? /* @__PURE__ */ jsxRuntime.jsxs(
1470
+ Tabs,
1471
+ {
1472
+ value: value.type,
1473
+ className: "flex-col",
1474
+ onValueChange: (t) => {
1475
+ if (t === "absolute") {
1476
+ onChange(absoluteDate(value.type === "absolute" ? toDate(value) : /* @__PURE__ */ new Date()));
1477
+ } else if (value.type !== "relative") {
1478
+ onChange({ type: "relative", relativeValue: "5", relativeFormat: relativeFormats[0] ?? "Minutes ago" });
1479
+ }
1480
+ },
1481
+ children: [
1482
+ /* @__PURE__ */ jsxRuntime.jsxs(TabsList, { className: "grid w-full grid-cols-2", children: [
1483
+ /* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "absolute", children: labels.absolute }),
1484
+ /* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "relative", children: labels.relative })
1485
+ ] }),
1486
+ /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "absolute", children: absoluteContent }),
1487
+ /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "relative", children: relativeContent })
1488
+ ]
1489
+ }
1490
+ ) : showAbsolute ? absoluteContent : relativeContent
1491
+ ] });
1492
+ }
1493
+ function DatetimeRange({
1494
+ startTime,
1495
+ endTime,
1496
+ onChange,
1497
+ quickPresets = QUICK_PRESETS,
1498
+ showQuickRanges = true,
1499
+ showAbsolute = true,
1500
+ showRelative = true,
1501
+ precision = "second",
1502
+ relativeFormats = RELATIVE_FORMATS,
1503
+ min,
1504
+ max,
1505
+ timezone,
1506
+ use12HourFormat = false,
1507
+ showNow = true,
1508
+ disabled = false,
1509
+ labels: labelsProp,
1510
+ popoverAlign = "start",
1511
+ popoverSide = "bottom",
1512
+ renderTrigger,
1513
+ className
1514
+ }) {
1515
+ const labels = { ...DEFAULT_LABELS, ...labelsProp };
1516
+ const [isOpen, setIsOpen] = React.useState(false);
1517
+ const [draftStart, setDraftStart] = React.useState(startTime);
1518
+ const [draftEnd, setDraftEnd] = React.useState(endTime);
1519
+ const [error, setError] = React.useState(null);
1520
+ React.useEffect(() => {
1521
+ if (isOpen) {
1522
+ setDraftStart(startTime);
1523
+ setDraftEnd(endTime);
1524
+ setError(null);
1525
+ }
1526
+ }, [isOpen, startTime, endTime]);
1527
+ const handleApply = () => {
1528
+ const err = validateRange(draftStart, draftEnd);
1529
+ if (err) {
1530
+ setError(err);
1531
+ return;
1532
+ }
1533
+ onChange(draftStart, draftEnd);
1534
+ setIsOpen(false);
1535
+ };
1536
+ const handleCancel = () => {
1537
+ setDraftStart(startTime);
1538
+ setDraftEnd(endTime);
1539
+ setError(null);
1540
+ setIsOpen(false);
1541
+ };
1542
+ const handlePreset = (preset) => {
1543
+ onChange(preset.start, preset.end);
1544
+ setIsOpen(false);
1545
+ };
1546
+ const sidePanelProps = {
1547
+ showAbsolute,
1548
+ showRelative,
1549
+ precision,
1550
+ relativeFormats,
1551
+ showNow,
1552
+ min,
1553
+ max,
1554
+ timezone,
1555
+ use12HourFormat,
1556
+ labels
1557
+ };
1558
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: isOpen, onOpenChange: disabled ? void 0 : setIsOpen, children: [
1559
+ /* @__PURE__ */ jsxRuntime.jsx(
1560
+ PopoverTrigger,
1561
+ {
1562
+ disabled,
1563
+ render: (triggerProps) => renderTrigger ? renderTrigger(triggerProps, { open: isOpen, startTime, endTime }) : /* @__PURE__ */ jsxRuntime.jsxs(
1564
+ Button,
1565
+ {
1566
+ ...triggerProps,
1567
+ variant: "outline",
1568
+ disabled,
1569
+ className: cn(
1570
+ "h-8 px-3 gap-2 text-xs font-normal justify-start",
1571
+ isOpen && "border-[var(--bk-foreground)]",
1572
+ className
1573
+ ),
1574
+ children: [
1575
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14, className: "text-muted-foreground shrink-0" }),
1576
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: toDisplayString(startTime, { precision }) }),
1577
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "\u2192" }),
1578
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: toDisplayString(endTime, { precision }) })
1579
+ ]
1580
+ }
1581
+ )
1582
+ }
1583
+ ),
1584
+ /* @__PURE__ */ jsxRuntime.jsx(
1585
+ PopoverContent,
1586
+ {
1587
+ className: "p-0 w-auto",
1588
+ align: popoverAlign,
1589
+ side: popoverSide,
1590
+ sideOffset: 4,
1591
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", children: [
1592
+ showQuickRanges && quickPresets.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shrink-0 border-r w-40 relative", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute inset-0 flex flex-col overflow-hidden", children: [
1593
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3 pt-2.5 pb-1 text-[11px] font-semibold text-muted-foreground uppercase tracking-widest shrink-0", children: labels.quickRanges }),
1594
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-y-auto", children: quickPresets.map((preset) => /* @__PURE__ */ jsxRuntime.jsx(
1595
+ "button",
1596
+ {
1597
+ type: "button",
1598
+ className: "block w-full text-left text-xs px-3 py-1.5 hover:bg-accent hover:text-accent-foreground transition-colors",
1599
+ onClick: () => handlePreset(preset),
1600
+ children: preset.label
1601
+ },
1602
+ preset.label
1603
+ )) })
1604
+ ] }) }),
1605
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col justify-between relative", children: [
1606
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute top-0 bottom-0 left-1/2 w-px bg-border" }),
1607
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex", children: [
1608
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 pb-4 pt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1609
+ SidePanel,
1610
+ {
1611
+ title: labels.start,
1612
+ value: draftStart,
1613
+ compareValue: draftEnd,
1614
+ onChange: (v) => {
1615
+ setDraftStart(v);
1616
+ setError(null);
1617
+ },
1618
+ ...sidePanelProps
1619
+ }
1620
+ ) }),
1621
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 pb-4 pt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1622
+ SidePanel,
1623
+ {
1624
+ title: labels.end,
1625
+ value: draftEnd,
1626
+ compareValue: draftStart,
1627
+ onChange: (v) => {
1628
+ setDraftEnd(v);
1629
+ setError(null);
1630
+ },
1631
+ ...sidePanelProps
1632
+ }
1633
+ ) })
1634
+ ] }),
1635
+ /* @__PURE__ */ jsxRuntime.jsx(Separator, {}),
1636
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2 gap-4", children: [
1637
+ error === "validation" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-destructive", children: "Start must be earlier than end." }) : /* @__PURE__ */ jsxRuntime.jsx("span", {}),
1638
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
1639
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", onClick: handleCancel, children: labels.cancel }),
1640
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "sm", onClick: handleApply, children: labels.apply })
1641
+ ] })
1642
+ ] })
1643
+ ] })
1644
+ ] })
1645
+ }
1646
+ )
1647
+ ] });
1648
+ }
1649
+
1650
+ exports.DateTimePanel = DateTimePanel;
1651
+ exports.DatetimeRange = DatetimeRange;
1652
+ exports.DatetimeSegmentInput = DatetimeSegmentInput;
1653
+ exports.QUICK_PRESETS = QUICK_PRESETS;
1654
+ exports.RELATIVE_FORMATS = RELATIVE_FORMATS;
1655
+ exports.absoluteDate = absoluteDate;
1656
+ exports.fromUrlString = fromUrlString;
1657
+ exports.relativeAgo = relativeAgo;
1658
+ exports.relativeNow = relativeNow;
1659
+ exports.toDate = toDate;
1660
+ exports.toDisplayString = toDisplayString;
1661
+ exports.toTimestamp = toTimestamp;
1662
+ exports.toTimestampMs = toTimestampMs;
1663
+ exports.toUrlString = toUrlString;
1664
+ exports.validateRange = validateRange;
1665
+ //# sourceMappingURL=index.cjs.map
1666
+ //# sourceMappingURL=index.cjs.map