xertica-ui 2.5.2 → 2.5.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.
@@ -0,0 +1,2890 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
3
+ import { c as cn, B as Button } from './button-DZHzN1Gd.js';
4
+ import * as React from 'react';
5
+ import { useRef, useState, useCallback, useEffect } from 'react';
6
+ import * as RechartsPrimitive from 'recharts';
7
+ import { cva } from 'class-variance-authority';
8
+ import { XCircle, AlertTriangle, Info, CheckCircle, RefreshCw, BarChart3, WifiOff, XIcon, Undo, Redo, ChevronDown, Type, Heading1, Heading2, Heading3, Bold, Italic, Underline, AlignLeft, AlignCenter, AlignRight, List, ListOrdered, Link, X, Search, ChevronUp } from 'lucide-react';
9
+ import { C as Card, e as CardHeader, f as CardTitle, c as CardDescription, a as CardAction, b as CardContent, d as CardFooter, S as Skeleton } from './skeleton-DtR5tkYe.js';
10
+ import { S as Select, h as SelectTrigger, i as SelectValue, a as SelectContent, c as SelectItem } from './select-D-xvCZK2.js';
11
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
12
+ import { D as DropdownMenu, n as DropdownMenuTrigger, b as DropdownMenuContent, d as DropdownMenuItem } from './dropdown-menu-Dn_eV2Xb.js';
13
+ import { P as Popover, c as PopoverTrigger, b as PopoverContent, I as Input } from './input-B0_vbA3g.js';
14
+
15
+ function ScrollArea({
16
+ className,
17
+ children,
18
+ ...props
19
+ }) {
20
+ return /* @__PURE__ */ jsxs(
21
+ ScrollAreaPrimitive.Root,
22
+ {
23
+ "data-slot": "scroll-area",
24
+ className: cn("relative", className),
25
+ ...props,
26
+ children: [
27
+ /* @__PURE__ */ jsx(
28
+ ScrollAreaPrimitive.Viewport,
29
+ {
30
+ "data-slot": "scroll-area-viewport",
31
+ tabIndex: 0,
32
+ role: "region",
33
+ "aria-label": "Região rolável",
34
+ className: "focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",
35
+ children
36
+ }
37
+ ),
38
+ /* @__PURE__ */ jsx(ScrollBar, {}),
39
+ /* @__PURE__ */ jsx(ScrollAreaPrimitive.Corner, {})
40
+ ]
41
+ }
42
+ );
43
+ }
44
+ function ScrollBar({
45
+ className,
46
+ orientation = "vertical",
47
+ ...props
48
+ }) {
49
+ return /* @__PURE__ */ jsx(
50
+ ScrollAreaPrimitive.ScrollAreaScrollbar,
51
+ {
52
+ "data-slot": "scroll-area-scrollbar",
53
+ orientation,
54
+ className: cn(
55
+ "flex touch-none p-px transition-colors select-none",
56
+ orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent",
57
+ orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent",
58
+ className
59
+ ),
60
+ ...props,
61
+ children: /* @__PURE__ */ jsx(
62
+ ScrollAreaPrimitive.ScrollAreaThumb,
63
+ {
64
+ "data-slot": "scroll-area-thumb",
65
+ className: "bg-border relative flex-1 rounded-full"
66
+ }
67
+ )
68
+ }
69
+ );
70
+ }
71
+
72
+ const alertVariants = cva(
73
+ "relative w-full rounded-[var(--radius)] border-l-4 px-4 py-3 grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-5 [&>svg]:translate-y-0.5 [&>svg]:text-current",
74
+ {
75
+ variants: {
76
+ variant: {
77
+ default: "bg-muted/50 border-l-border text-foreground [&>svg]:text-muted-foreground",
78
+ success: "bg-[color:var(--success)]/10 dark:bg-[color:var(--success)]/20 border-l-[color:var(--success)] text-foreground [&>svg]:text-[color:var(--success)]",
79
+ info: "bg-[color:var(--info)]/10 dark:bg-[color:var(--info)]/20 border-l-[color:var(--info)] text-foreground [&>svg]:text-[color:var(--info)]",
80
+ warning: "bg-[color:var(--warning)]/10 dark:bg-[color:var(--warning)]/20 border-l-[color:var(--warning)] text-foreground [&>svg]:text-[color:var(--warning)]",
81
+ destructive: "bg-[color:var(--destructive)]/10 dark:bg-[color:var(--destructive)]/20 border-l-[color:var(--destructive)] text-foreground [&>svg]:text-[color:var(--destructive)]"
82
+ }
83
+ },
84
+ defaultVariants: {
85
+ variant: "default"
86
+ }
87
+ }
88
+ );
89
+ const alertIcons = {
90
+ default: Info,
91
+ success: CheckCircle,
92
+ info: Info,
93
+ warning: AlertTriangle,
94
+ destructive: XCircle
95
+ };
96
+ function Alert({ className, variant, icon, children, ...props }) {
97
+ const alertVariant = variant && variant in alertIcons ? variant : "default";
98
+ const DefaultIcon = alertIcons[alertVariant];
99
+ return /* @__PURE__ */ jsxs(
100
+ "div",
101
+ {
102
+ "data-slot": "alert",
103
+ role: "alert",
104
+ className: cn(alertVariants({ variant }), className),
105
+ ...props,
106
+ children: [
107
+ icon !== void 0 ? icon : /* @__PURE__ */ jsx(DefaultIcon, { className: "flex-shrink-0" }),
108
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children })
109
+ ]
110
+ }
111
+ );
112
+ }
113
+ function AlertTitle({ className, ...props }) {
114
+ return /* @__PURE__ */ jsx(
115
+ "div",
116
+ {
117
+ "data-slot": "alert-title",
118
+ className: cn("font-medium mb-1 leading-tight", className),
119
+ ...props
120
+ }
121
+ );
122
+ }
123
+ function AlertDescription({ className, ...props }) {
124
+ return /* @__PURE__ */ jsx("div", { "data-slot": "alert-description", className: cn("leading-relaxed", className), ...props });
125
+ }
126
+
127
+ const Empty = React.forwardRef(
128
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
129
+ "div",
130
+ {
131
+ ref,
132
+ className: cn(
133
+ "flex min-h-[400px] flex-col items-center justify-center rounded-[var(--radius-card)] border border-dashed border-border p-8 text-center animate-in fade-in-50",
134
+ className
135
+ ),
136
+ ...props
137
+ }
138
+ )
139
+ );
140
+ Empty.displayName = "Empty";
141
+ const EmptyIcon = React.forwardRef(
142
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
143
+ "div",
144
+ {
145
+ ref,
146
+ className: cn(
147
+ "mx-auto flex h-20 w-20 items-center justify-center rounded-full bg-muted",
148
+ className
149
+ ),
150
+ ...props
151
+ }
152
+ )
153
+ );
154
+ EmptyIcon.displayName = "EmptyIcon";
155
+ const EmptyImage = React.forwardRef(
156
+ ({ className, alt, ...props }, ref) => /* @__PURE__ */ jsx(
157
+ "img",
158
+ {
159
+ ref,
160
+ alt,
161
+ className: cn("mx-auto mb-4 h-48 w-48 object-contain opacity-50", className),
162
+ ...props
163
+ }
164
+ )
165
+ );
166
+ EmptyImage.displayName = "EmptyImage";
167
+ const EmptyTitle = React.forwardRef(
168
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("h3", { ref, className: cn("mt-4 font-semibold text-foreground", className), ...props })
169
+ );
170
+ EmptyTitle.displayName = "EmptyTitle";
171
+ const EmptyDescription = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
172
+ "p",
173
+ {
174
+ ref,
175
+ className: cn("mt-2 text-sm text-muted-foreground max-w-sm mx-auto", className),
176
+ ...props
177
+ }
178
+ ));
179
+ EmptyDescription.displayName = "EmptyDescription";
180
+ const EmptyAction = React.forwardRef(
181
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
182
+ "div",
183
+ {
184
+ ref,
185
+ className: cn("mt-6 flex flex-col gap-2 sm:flex-row sm:gap-4", className),
186
+ ...props
187
+ }
188
+ )
189
+ );
190
+ EmptyAction.displayName = "EmptyAction";
191
+
192
+ const THEMES = { light: "", dark: ".dark" };
193
+ const defaultPeriods = [
194
+ { value: "7d", label: "7 days" },
195
+ { value: "30d", label: "30 days" },
196
+ { value: "90d", label: "90 days" }
197
+ ];
198
+ const defaultChartColors = [
199
+ "var(--chart-1)",
200
+ "var(--chart-2)",
201
+ "var(--chart-3)",
202
+ "var(--chart-4)",
203
+ "var(--chart-5)",
204
+ "var(--chart-6)",
205
+ "var(--chart-7)",
206
+ "var(--chart-8)"
207
+ ];
208
+ const chartBarSizes = {
209
+ sm: 8,
210
+ md: 14,
211
+ lg: 22,
212
+ xl: 32
213
+ };
214
+ const ChartContext = React.createContext(null);
215
+ function useChart() {
216
+ const context = React.useContext(ChartContext);
217
+ if (!context) {
218
+ throw new Error("useChart must be used within a <ChartContainer />");
219
+ }
220
+ return context;
221
+ }
222
+ function ChartContainer({
223
+ id,
224
+ className,
225
+ children,
226
+ config,
227
+ ...props
228
+ }) {
229
+ const uniqueId = React.useId();
230
+ const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
231
+ return /* @__PURE__ */ jsx(ChartContext.Provider, { value: { config }, children: /* @__PURE__ */ jsxs(
232
+ "div",
233
+ {
234
+ "data-slot": "chart",
235
+ "data-chart": chartId,
236
+ className: cn(
237
+ "[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border relative h-[300px] min-h-[200px] w-full min-w-0 overflow-hidden text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
238
+ className
239
+ ),
240
+ ...props,
241
+ children: [
242
+ /* @__PURE__ */ jsx(ChartStyle, { id: chartId, config }),
243
+ /* @__PURE__ */ jsx(RechartsPrimitive.ResponsiveContainer, { width: "100%", height: "100%", children })
244
+ ]
245
+ }
246
+ ) });
247
+ }
248
+ const ChartStyle = ({ id, config }) => {
249
+ const colorConfig = Object.entries(config).filter(([, config2]) => config2.theme || config2.color);
250
+ if (!colorConfig.length) {
251
+ return null;
252
+ }
253
+ return /* @__PURE__ */ jsx(
254
+ "style",
255
+ {
256
+ dangerouslySetInnerHTML: {
257
+ __html: Object.entries(THEMES).map(
258
+ ([theme, prefix]) => `
259
+ ${prefix} [data-chart=${id}] {
260
+ ${colorConfig.map(([key, itemConfig]) => {
261
+ const color = itemConfig.theme?.[theme] || itemConfig.color;
262
+ return color ? ` --color-${key}: ${color};` : null;
263
+ }).join("\n")}
264
+ }
265
+ `
266
+ ).join("\n")
267
+ }
268
+ }
269
+ );
270
+ };
271
+ const ChartTooltip = RechartsPrimitive.Tooltip;
272
+ function ChartTooltipContent({
273
+ active,
274
+ payload,
275
+ className,
276
+ indicator = "dot",
277
+ hideLabel = false,
278
+ hideIndicator = false,
279
+ label,
280
+ labelFormatter,
281
+ labelClassName,
282
+ formatter,
283
+ color,
284
+ nameKey,
285
+ labelKey
286
+ }) {
287
+ const { config } = useChart();
288
+ const tooltipLabel = React.useMemo(() => {
289
+ if (hideLabel || !payload?.length) {
290
+ return null;
291
+ }
292
+ const [item] = payload;
293
+ const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
294
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
295
+ const value = !labelKey && typeof label === "string" ? config[label]?.label || label : itemConfig?.label;
296
+ if (labelFormatter) {
297
+ return /* @__PURE__ */ jsx("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
298
+ }
299
+ if (!value) {
300
+ return null;
301
+ }
302
+ return /* @__PURE__ */ jsx("div", { className: cn("font-medium", labelClassName), children: value });
303
+ }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
304
+ if (!active || !payload?.length) {
305
+ return null;
306
+ }
307
+ const nestLabel = payload.length === 1 && indicator !== "dot";
308
+ return /* @__PURE__ */ jsxs(
309
+ "div",
310
+ {
311
+ className: cn(
312
+ "border-border/50 bg-background/95 backdrop-blur-sm grid min-w-[8rem] items-start gap-1.5 rounded-xl border px-3 py-2 text-xs shadow-xl",
313
+ className
314
+ ),
315
+ children: [
316
+ !nestLabel ? tooltipLabel : null,
317
+ /* @__PURE__ */ jsx("div", { className: "grid gap-1.5", children: payload.map((item, index) => {
318
+ const key = `${nameKey || item.name || item.dataKey || "value"}`;
319
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
320
+ const indicatorColor = color || item.payload?.fill || item.color;
321
+ return /* @__PURE__ */ jsx(
322
+ "div",
323
+ {
324
+ className: cn(
325
+ "[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
326
+ indicator === "dot" && "items-center"
327
+ ),
328
+ children: formatter && item?.value !== void 0 && item.name ? formatter(item.value, item.name, item, index, item.payload) : /* @__PURE__ */ jsxs(Fragment, { children: [
329
+ itemConfig?.icon ? /* @__PURE__ */ jsx(itemConfig.icon, {}) : !hideIndicator && /* @__PURE__ */ jsx(
330
+ "div",
331
+ {
332
+ className: cn(
333
+ "shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
334
+ {
335
+ "h-2.5 w-2.5": indicator === "dot",
336
+ "w-1": indicator === "line",
337
+ "w-0 border-[1.5px] border-dashed bg-transparent": indicator === "dashed",
338
+ "my-0.5": nestLabel && indicator === "dashed"
339
+ }
340
+ ),
341
+ style: {
342
+ "--color-bg": indicatorColor,
343
+ "--color-border": indicatorColor
344
+ }
345
+ }
346
+ ),
347
+ /* @__PURE__ */ jsxs(
348
+ "div",
349
+ {
350
+ className: cn(
351
+ "flex flex-1 justify-between leading-none",
352
+ nestLabel ? "items-end" : "items-center"
353
+ ),
354
+ children: [
355
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
356
+ nestLabel ? tooltipLabel : null,
357
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: itemConfig?.label || item.name })
358
+ ] }),
359
+ item.value && /* @__PURE__ */ jsx("span", { className: "text-foreground font-mono font-semibold tabular-nums", children: item.value.toLocaleString() })
360
+ ]
361
+ }
362
+ )
363
+ ] })
364
+ },
365
+ `${item.dataKey ?? index}`
366
+ );
367
+ }) })
368
+ ]
369
+ }
370
+ );
371
+ }
372
+ const ChartLegend = RechartsPrimitive.Legend;
373
+ function ChartLegendContent({
374
+ className,
375
+ hideIcon = false,
376
+ payload,
377
+ verticalAlign = "bottom",
378
+ nameKey
379
+ }) {
380
+ const { config } = useChart();
381
+ if (!payload?.length) {
382
+ return null;
383
+ }
384
+ return /* @__PURE__ */ jsx(
385
+ "div",
386
+ {
387
+ className: cn(
388
+ "flex items-center justify-center gap-4",
389
+ verticalAlign === "top" ? "pb-3" : "pt-3",
390
+ className
391
+ ),
392
+ children: payload.map((item) => {
393
+ const key = `${nameKey ? item.value : item.dataKey || item.value || "value"}`;
394
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
395
+ return /* @__PURE__ */ jsxs(
396
+ "div",
397
+ {
398
+ className: cn(
399
+ "[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
400
+ ),
401
+ children: [
402
+ itemConfig?.icon && !hideIcon ? /* @__PURE__ */ jsx(itemConfig.icon, {}) : /* @__PURE__ */ jsx(
403
+ "div",
404
+ {
405
+ className: "h-2 w-2 shrink-0 rounded-full bg-(--color-bg)",
406
+ style: {
407
+ "--color-bg": item.color || `var(--color-${key})`
408
+ }
409
+ }
410
+ ),
411
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: itemConfig?.label || item.value })
412
+ ]
413
+ },
414
+ item.value
415
+ );
416
+ })
417
+ }
418
+ );
419
+ }
420
+ function getPayloadConfigFromPayload(config, payload, key) {
421
+ if (typeof payload !== "object" || payload === null) {
422
+ return void 0;
423
+ }
424
+ const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null ? payload.payload : void 0;
425
+ let configLabelKey = key;
426
+ if (key in payload && typeof payload[key] === "string") {
427
+ configLabelKey = payload[key];
428
+ } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key] === "string") {
429
+ configLabelKey = payloadPayload[key];
430
+ }
431
+ return configLabelKey in config ? config[configLabelKey] : config[key];
432
+ }
433
+ function getChartSeries(config, series) {
434
+ if (series?.length) {
435
+ return series;
436
+ }
437
+ return Object.entries(config).map(([key, item]) => ({
438
+ key,
439
+ label: item.label
440
+ }));
441
+ }
442
+ function getSeriesColor(key, index, colors) {
443
+ if (Array.isArray(colors)) {
444
+ return colors[index] || defaultChartColors[index % defaultChartColors.length];
445
+ }
446
+ return colors?.[key] || defaultChartColors[index % defaultChartColors.length];
447
+ }
448
+ function getChartConfigWithColors(config, keys, colors) {
449
+ return keys.reduce((nextConfig, key, index) => {
450
+ const item = config[key];
451
+ if (item?.theme && !colors) {
452
+ nextConfig[key] = item;
453
+ return nextConfig;
454
+ }
455
+ nextConfig[key] = {
456
+ label: item?.label || key,
457
+ icon: item?.icon,
458
+ color: colors ? getSeriesColor(key, index, colors) : item?.color || getSeriesColor(key, index)
459
+ };
460
+ return nextConfig;
461
+ }, {});
462
+ }
463
+ function buildChartConfig(keys, colors) {
464
+ return keys.reduce((cfg, key, index) => {
465
+ cfg[key] = {
466
+ label: key,
467
+ color: getSeriesColor(key, index, colors)
468
+ };
469
+ return cfg;
470
+ }, {});
471
+ }
472
+ function formatTick(value) {
473
+ if (typeof value !== "number") {
474
+ return value;
475
+ }
476
+ return Intl.NumberFormat("en", {
477
+ notation: "compact",
478
+ maximumFractionDigits: 1
479
+ }).format(value);
480
+ }
481
+ function defaultFilterData(data, period) {
482
+ const match = period.match(/^(\d+)/);
483
+ if (!match) {
484
+ return data;
485
+ }
486
+ const limit = Number(match[1]);
487
+ return data.slice(Math.max(data.length - limit, 0));
488
+ }
489
+ function getErrorDescription(error) {
490
+ if (typeof error === "string") {
491
+ return error;
492
+ }
493
+ if (error instanceof Error) {
494
+ return error.message;
495
+ }
496
+ return void 0;
497
+ }
498
+ function getBarSize(barSize = "md") {
499
+ return typeof barSize === "number" ? barSize : chartBarSizes[barSize];
500
+ }
501
+ function hasChartData(data, series) {
502
+ if (!data.length || !series.length) {
503
+ return false;
504
+ }
505
+ return data.some(
506
+ (item) => series.some((serie) => {
507
+ const value = item[serie.key];
508
+ return value !== null && value !== void 0 && value !== "";
509
+ })
510
+ );
511
+ }
512
+ function hasPieData(data, nameKey, valueKey) {
513
+ return data.some((item) => {
514
+ const name = item[nameKey];
515
+ const value = item[valueKey];
516
+ return name !== null && name !== void 0 && name !== "" && value !== null && value !== void 0 && value !== "";
517
+ });
518
+ }
519
+ function ChartState({
520
+ type,
521
+ className,
522
+ error,
523
+ onRetry,
524
+ retryLabel = "Try again",
525
+ emptyTitle = "No data available",
526
+ emptyDescription = "There is no data available for this chart yet.",
527
+ errorTitle = "Connection error",
528
+ errorDescription,
529
+ loadingLabel = "Loading chart data"
530
+ }) {
531
+ if (type === "loading") {
532
+ return /* @__PURE__ */ jsxs(
533
+ "div",
534
+ {
535
+ className: cn(
536
+ "flex min-h-[240px] flex-col justify-end gap-3 rounded-[var(--radius-card)] border border-border p-6",
537
+ className
538
+ ),
539
+ "aria-label": typeof loadingLabel === "string" ? loadingLabel : void 0,
540
+ children: [
541
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-2/5" }),
542
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-14 w-3/5" }),
543
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-24 w-4/5" }),
544
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-36 w-full" })
545
+ ]
546
+ }
547
+ );
548
+ }
549
+ if (type === "error") {
550
+ return /* @__PURE__ */ jsx(
551
+ "div",
552
+ {
553
+ className: cn(
554
+ "flex min-h-[240px] items-center justify-center rounded-[var(--radius-card)] border border-border p-6",
555
+ className
556
+ ),
557
+ children: /* @__PURE__ */ jsxs(Alert, { variant: "destructive", className: "max-w-xl", children: [
558
+ /* @__PURE__ */ jsx(AlertTitle, { children: errorTitle }),
559
+ /* @__PURE__ */ jsx(AlertDescription, { children: errorDescription || getErrorDescription(error) || "Unable to load chart data. Check your connection and try again." }),
560
+ onRetry ? /* @__PURE__ */ jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outline", onClick: onRetry, children: [
561
+ /* @__PURE__ */ jsx(RefreshCw, { className: "size-4" }),
562
+ retryLabel
563
+ ] }) }) : null
564
+ ] })
565
+ }
566
+ );
567
+ }
568
+ return /* @__PURE__ */ jsxs(Empty, { className: cn("min-h-[240px]", className), children: [
569
+ /* @__PURE__ */ jsx(EmptyIcon, { children: /* @__PURE__ */ jsx(BarChart3, { className: "size-10 text-muted-foreground" }) }),
570
+ /* @__PURE__ */ jsx(EmptyTitle, { children: emptyTitle }),
571
+ /* @__PURE__ */ jsx(EmptyDescription, { children: emptyDescription }),
572
+ onRetry ? /* @__PURE__ */ jsx(EmptyAction, { children: /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outline", onClick: onRetry, children: [
573
+ /* @__PURE__ */ jsx(WifiOff, { className: "size-4" }),
574
+ retryLabel
575
+ ] }) }) : null
576
+ ] });
577
+ }
578
+ function getChartState(state, hasData, className) {
579
+ if (state.isLoading) {
580
+ return /* @__PURE__ */ jsx(ChartState, { ...state, type: "loading", className });
581
+ }
582
+ if (state.error) {
583
+ return /* @__PURE__ */ jsx(ChartState, { ...state, type: "error", className });
584
+ }
585
+ if (!hasData) {
586
+ return /* @__PURE__ */ jsx(ChartState, { ...state, type: "empty", className });
587
+ }
588
+ return null;
589
+ }
590
+ function ChartCard({
591
+ title,
592
+ description,
593
+ action,
594
+ footer,
595
+ children,
596
+ className,
597
+ contentClassName,
598
+ ...props
599
+ }) {
600
+ return /* @__PURE__ */ jsxs(Card, { className: cn("w-full min-w-0 overflow-hidden", className), ...props, children: [
601
+ /* @__PURE__ */ jsxs(CardHeader, { children: [
602
+ /* @__PURE__ */ jsx(CardTitle, { children: title }),
603
+ description ? /* @__PURE__ */ jsx(CardDescription, { children: description }) : null,
604
+ action ? /* @__PURE__ */ jsx(CardAction, { children: action }) : null
605
+ ] }),
606
+ /* @__PURE__ */ jsx(CardContent, { className: contentClassName, children }),
607
+ footer ? /* @__PURE__ */ jsx(CardFooter, { children: footer }) : null
608
+ ] });
609
+ }
610
+ function AreaGradientDefs({
611
+ seriesKeys,
612
+ opacity = 0.3
613
+ }) {
614
+ return /* @__PURE__ */ jsx("defs", { children: seriesKeys.map((key) => /* @__PURE__ */ jsxs("linearGradient", { id: `gradient-${key}`, x1: "0", y1: "0", x2: "0", y2: "1", children: [
615
+ /* @__PURE__ */ jsx("stop", { offset: "5%", stopColor: `var(--color-${key})`, stopOpacity: opacity }),
616
+ /* @__PURE__ */ jsx("stop", { offset: "95%", stopColor: `var(--color-${key})`, stopOpacity: 0 })
617
+ ] }, key)) });
618
+ }
619
+ function DashboardBarChart({
620
+ data,
621
+ config,
622
+ indexKey = "name",
623
+ series,
624
+ colors,
625
+ barSize = "md",
626
+ stacked = false,
627
+ showGrid = true,
628
+ showLegend = true,
629
+ valueFormatter = formatTick,
630
+ isLoading,
631
+ error,
632
+ onRetry,
633
+ retryLabel,
634
+ emptyTitle,
635
+ emptyDescription,
636
+ errorTitle,
637
+ errorDescription,
638
+ loadingLabel,
639
+ stateClassName,
640
+ className,
641
+ ...props
642
+ }) {
643
+ const chartSeries = getChartSeries(config, series);
644
+ const chartConfig = getChartConfigWithColors(
645
+ config,
646
+ chartSeries.map((item) => item.key),
647
+ colors
648
+ );
649
+ const chartState = getChartState(
650
+ {
651
+ isLoading,
652
+ error,
653
+ onRetry,
654
+ retryLabel,
655
+ emptyTitle,
656
+ emptyDescription,
657
+ errorTitle,
658
+ errorDescription,
659
+ loadingLabel
660
+ },
661
+ hasChartData(data, chartSeries),
662
+ cn("h-[320px] w-full", stateClassName)
663
+ );
664
+ const barElements = React.useMemo(() => {
665
+ const topOfStack = /* @__PURE__ */ new Set();
666
+ if (stacked) {
667
+ const lastByStack = /* @__PURE__ */ new Map();
668
+ chartSeries.forEach((s) => lastByStack.set(s.stackId || "total", s.key));
669
+ lastByStack.forEach((key) => topOfStack.add(key));
670
+ }
671
+ return chartSeries.map((item) => {
672
+ const isTop = !stacked || topOfStack.has(item.key);
673
+ return /* @__PURE__ */ jsx(
674
+ RechartsPrimitive.Bar,
675
+ {
676
+ dataKey: item.key,
677
+ fill: `var(--color-${item.key})`,
678
+ radius: isTop ? [4, 4, 0, 0] : [0, 0, 0, 0],
679
+ barSize: getBarSize(barSize),
680
+ stackId: stacked ? item.stackId || "total" : item.stackId,
681
+ isAnimationActive: true,
682
+ animationDuration: 600,
683
+ animationEasing: "ease-out"
684
+ },
685
+ item.key
686
+ );
687
+ });
688
+ }, [stacked, chartSeries]);
689
+ if (chartState) {
690
+ return chartState;
691
+ }
692
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[320px] w-full", className), ...props, children: /* @__PURE__ */ jsxs(RechartsPrimitive.BarChart, { data, accessibilityLayer: true, barGap: 4, children: [
693
+ showGrid ? /* @__PURE__ */ jsx(
694
+ RechartsPrimitive.CartesianGrid,
695
+ {
696
+ vertical: false,
697
+ strokeDasharray: "3 3",
698
+ stroke: "var(--border)",
699
+ strokeOpacity: 0.5
700
+ }
701
+ ) : null,
702
+ /* @__PURE__ */ jsx(
703
+ RechartsPrimitive.XAxis,
704
+ {
705
+ dataKey: indexKey,
706
+ tickLine: false,
707
+ axisLine: false,
708
+ tickMargin: 8
709
+ }
710
+ ),
711
+ /* @__PURE__ */ jsx(
712
+ RechartsPrimitive.YAxis,
713
+ {
714
+ tickLine: false,
715
+ axisLine: false,
716
+ tickMargin: 8,
717
+ tickFormatter: valueFormatter
718
+ }
719
+ ),
720
+ /* @__PURE__ */ jsx(
721
+ ChartTooltip,
722
+ {
723
+ cursor: { fill: "var(--muted)", opacity: 0.4, radius: 4 },
724
+ content: /* @__PURE__ */ jsx(ChartTooltipContent, {})
725
+ }
726
+ ),
727
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }) : null,
728
+ barElements
729
+ ] }) });
730
+ }
731
+ function DashboardLineChart({
732
+ data,
733
+ config,
734
+ indexKey = "name",
735
+ series,
736
+ colors,
737
+ showDots = false,
738
+ showGrid = true,
739
+ showLegend = true,
740
+ curveType = "monotone",
741
+ strokeWidth = 2,
742
+ valueFormatter = formatTick,
743
+ isLoading,
744
+ error,
745
+ onRetry,
746
+ retryLabel,
747
+ emptyTitle,
748
+ emptyDescription,
749
+ errorTitle,
750
+ errorDescription,
751
+ loadingLabel,
752
+ stateClassName,
753
+ className,
754
+ ...props
755
+ }) {
756
+ const chartSeries = getChartSeries(config, series);
757
+ const chartConfig = getChartConfigWithColors(
758
+ config,
759
+ chartSeries.map((item) => item.key),
760
+ colors
761
+ );
762
+ const chartState = getChartState(
763
+ {
764
+ isLoading,
765
+ error,
766
+ onRetry,
767
+ retryLabel,
768
+ emptyTitle,
769
+ emptyDescription,
770
+ errorTitle,
771
+ errorDescription,
772
+ loadingLabel
773
+ },
774
+ hasChartData(data, chartSeries),
775
+ cn("h-[320px] w-full", stateClassName)
776
+ );
777
+ if (chartState) {
778
+ return chartState;
779
+ }
780
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[320px] w-full", className), ...props, children: /* @__PURE__ */ jsxs(RechartsPrimitive.LineChart, { data, accessibilityLayer: true, children: [
781
+ showGrid ? /* @__PURE__ */ jsx(
782
+ RechartsPrimitive.CartesianGrid,
783
+ {
784
+ vertical: false,
785
+ strokeDasharray: "3 3",
786
+ stroke: "var(--border)",
787
+ strokeOpacity: 0.5
788
+ }
789
+ ) : null,
790
+ /* @__PURE__ */ jsx(
791
+ RechartsPrimitive.XAxis,
792
+ {
793
+ dataKey: indexKey,
794
+ tickLine: false,
795
+ axisLine: false,
796
+ tickMargin: 8
797
+ }
798
+ ),
799
+ /* @__PURE__ */ jsx(
800
+ RechartsPrimitive.YAxis,
801
+ {
802
+ tickLine: false,
803
+ axisLine: false,
804
+ tickMargin: 8,
805
+ tickFormatter: valueFormatter
806
+ }
807
+ ),
808
+ /* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, { indicator: "line" }) }),
809
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }) : null,
810
+ chartSeries.map((item) => /* @__PURE__ */ jsx(
811
+ RechartsPrimitive.Line,
812
+ {
813
+ type: curveType,
814
+ dataKey: item.key,
815
+ stroke: `var(--color-${item.key})`,
816
+ strokeWidth,
817
+ dot: showDots ? { r: 3, fill: `var(--color-${item.key})`, strokeWidth: 0 } : false,
818
+ activeDot: { r: 5, strokeWidth: 0 },
819
+ yAxisId: item.yAxisId,
820
+ isAnimationActive: true,
821
+ animationDuration: 600,
822
+ animationEasing: "ease-out"
823
+ },
824
+ item.key
825
+ ))
826
+ ] }) });
827
+ }
828
+ function HorizontalBarChart({
829
+ data,
830
+ config,
831
+ indexKey = "name",
832
+ series,
833
+ colors,
834
+ barSize = "md",
835
+ stacked = false,
836
+ categoryWidth = 96,
837
+ showGrid = true,
838
+ showLegend = true,
839
+ valueFormatter = formatTick,
840
+ isLoading,
841
+ error,
842
+ onRetry,
843
+ retryLabel,
844
+ emptyTitle,
845
+ emptyDescription,
846
+ errorTitle,
847
+ errorDescription,
848
+ loadingLabel,
849
+ stateClassName,
850
+ className,
851
+ ...props
852
+ }) {
853
+ const chartSeries = getChartSeries(config, series);
854
+ const chartConfig = getChartConfigWithColors(
855
+ config,
856
+ chartSeries.map((item) => item.key),
857
+ colors
858
+ );
859
+ const chartState = getChartState(
860
+ {
861
+ isLoading,
862
+ error,
863
+ onRetry,
864
+ retryLabel,
865
+ emptyTitle,
866
+ emptyDescription,
867
+ errorTitle,
868
+ errorDescription,
869
+ loadingLabel
870
+ },
871
+ hasChartData(data, chartSeries),
872
+ cn("h-[320px] w-full", stateClassName)
873
+ );
874
+ if (chartState) {
875
+ return chartState;
876
+ }
877
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[320px] w-full", className), ...props, children: /* @__PURE__ */ jsxs(
878
+ RechartsPrimitive.BarChart,
879
+ {
880
+ data,
881
+ layout: "vertical",
882
+ accessibilityLayer: true,
883
+ margin: { left: 8, right: 16 },
884
+ children: [
885
+ showGrid ? /* @__PURE__ */ jsx(
886
+ RechartsPrimitive.CartesianGrid,
887
+ {
888
+ horizontal: false,
889
+ strokeDasharray: "3 3",
890
+ stroke: "var(--border)",
891
+ strokeOpacity: 0.5
892
+ }
893
+ ) : null,
894
+ /* @__PURE__ */ jsx(
895
+ RechartsPrimitive.XAxis,
896
+ {
897
+ type: "number",
898
+ tickLine: false,
899
+ axisLine: false,
900
+ tickMargin: 8,
901
+ tickFormatter: valueFormatter
902
+ }
903
+ ),
904
+ /* @__PURE__ */ jsx(
905
+ RechartsPrimitive.YAxis,
906
+ {
907
+ dataKey: indexKey,
908
+ type: "category",
909
+ tickLine: false,
910
+ axisLine: false,
911
+ tickMargin: 8,
912
+ width: categoryWidth
913
+ }
914
+ ),
915
+ /* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
916
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }) : null,
917
+ chartSeries.map((item) => /* @__PURE__ */ jsx(
918
+ RechartsPrimitive.Bar,
919
+ {
920
+ dataKey: item.key,
921
+ fill: `var(--color-${item.key})`,
922
+ radius: [0, 4, 4, 0],
923
+ barSize: getBarSize(barSize),
924
+ stackId: stacked ? item.stackId || "total" : item.stackId,
925
+ isAnimationActive: true,
926
+ animationDuration: 600,
927
+ animationEasing: "ease-out"
928
+ },
929
+ item.key
930
+ ))
931
+ ]
932
+ }
933
+ ) });
934
+ }
935
+ function InteractiveTimeSeriesChart({
936
+ data,
937
+ config,
938
+ indexKey = "date",
939
+ series,
940
+ colors,
941
+ periods = defaultPeriods,
942
+ defaultPeriod = periods[1]?.value || periods[0]?.value || "30d",
943
+ defaultSeries,
944
+ filterData = defaultFilterData,
945
+ showGrid = true,
946
+ showLegend = false,
947
+ showDots = false,
948
+ gradientFill = true,
949
+ curveType = "monotone",
950
+ strokeWidth = 2,
951
+ valueFormatter = formatTick,
952
+ isLoading,
953
+ error,
954
+ onRetry,
955
+ retryLabel,
956
+ emptyTitle,
957
+ emptyDescription,
958
+ errorTitle,
959
+ errorDescription,
960
+ loadingLabel,
961
+ stateClassName,
962
+ className,
963
+ ...props
964
+ }) {
965
+ const chartSeries = getChartSeries(config, series);
966
+ const chartConfig = getChartConfigWithColors(
967
+ config,
968
+ chartSeries.map((item) => item.key),
969
+ colors
970
+ );
971
+ const [period, setPeriod] = React.useState(defaultPeriod);
972
+ const [activeSeries, setActiveSeries] = React.useState(
973
+ defaultSeries || chartSeries[0]?.key || ""
974
+ );
975
+ const filteredData = React.useMemo(() => filterData(data, period), [data, filterData, period]);
976
+ const visibleSeries = chartSeries.length > 1 ? chartSeries.filter((item) => item.key === activeSeries) : chartSeries;
977
+ const chartState = getChartState(
978
+ {
979
+ isLoading,
980
+ error,
981
+ onRetry,
982
+ retryLabel,
983
+ emptyTitle,
984
+ emptyDescription,
985
+ errorTitle,
986
+ errorDescription,
987
+ loadingLabel
988
+ },
989
+ hasChartData(filteredData, visibleSeries),
990
+ cn("h-[320px] w-full", stateClassName)
991
+ );
992
+ return /* @__PURE__ */ jsxs("div", { className: "w-full space-y-4", children: [
993
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [
994
+ chartSeries.length > 1 ? /* @__PURE__ */ jsx(
995
+ "div",
996
+ {
997
+ className: "inline-flex h-10 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
998
+ role: "group",
999
+ "aria-label": "Selecionar metrica do grafico",
1000
+ children: chartSeries.map((item) => {
1001
+ const label = item.label || config[item.key]?.label || item.key;
1002
+ return /* @__PURE__ */ jsx(
1003
+ Button,
1004
+ {
1005
+ type: "button",
1006
+ variant: "ghost",
1007
+ size: "sm",
1008
+ "aria-pressed": activeSeries === item.key,
1009
+ onClick: () => setActiveSeries(item.key),
1010
+ className: cn(
1011
+ "h-8 px-3 text-sm font-medium transition-all",
1012
+ activeSeries === item.key ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
1013
+ ),
1014
+ children: label
1015
+ },
1016
+ item.key
1017
+ );
1018
+ })
1019
+ }
1020
+ ) : /* @__PURE__ */ jsx("div", {}),
1021
+ /* @__PURE__ */ jsxs(Select, { value: period, onValueChange: setPeriod, children: [
1022
+ /* @__PURE__ */ jsx(
1023
+ SelectTrigger,
1024
+ {
1025
+ className: "w-full sm:w-[160px]",
1026
+ size: "sm",
1027
+ "aria-label": "Selecionar periodo do grafico",
1028
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Period" })
1029
+ }
1030
+ ),
1031
+ /* @__PURE__ */ jsx(SelectContent, { children: periods.map((item) => /* @__PURE__ */ jsx(SelectItem, { value: item.value, children: item.label }, item.value)) })
1032
+ ] })
1033
+ ] }),
1034
+ chartState || /* @__PURE__ */ jsx(
1035
+ ChartContainer,
1036
+ {
1037
+ config: chartConfig,
1038
+ className: cn("h-[320px] w-full", className),
1039
+ ...props,
1040
+ children: /* @__PURE__ */ jsxs(RechartsPrimitive.AreaChart, { data: filteredData, accessibilityLayer: true, children: [
1041
+ gradientFill && /* @__PURE__ */ jsx(AreaGradientDefs, { seriesKeys: visibleSeries.map((s) => s.key), opacity: 0.4 }),
1042
+ showGrid ? /* @__PURE__ */ jsx(
1043
+ RechartsPrimitive.CartesianGrid,
1044
+ {
1045
+ vertical: false,
1046
+ strokeDasharray: "3 3",
1047
+ stroke: "var(--border)",
1048
+ strokeOpacity: 0.5
1049
+ }
1050
+ ) : null,
1051
+ /* @__PURE__ */ jsx(
1052
+ RechartsPrimitive.XAxis,
1053
+ {
1054
+ dataKey: indexKey,
1055
+ tickLine: false,
1056
+ axisLine: false,
1057
+ tickMargin: 8
1058
+ }
1059
+ ),
1060
+ /* @__PURE__ */ jsx(
1061
+ RechartsPrimitive.YAxis,
1062
+ {
1063
+ tickLine: false,
1064
+ axisLine: false,
1065
+ tickMargin: 8,
1066
+ tickFormatter: valueFormatter
1067
+ }
1068
+ ),
1069
+ /* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, { indicator: "line" }) }),
1070
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }) : null,
1071
+ visibleSeries.map((item) => /* @__PURE__ */ jsx(
1072
+ RechartsPrimitive.Area,
1073
+ {
1074
+ type: curveType,
1075
+ dataKey: item.key,
1076
+ stroke: `var(--color-${item.key})`,
1077
+ fill: gradientFill ? `url(#gradient-${item.key})` : `var(--color-${item.key})`,
1078
+ fillOpacity: gradientFill ? 1 : 0.16,
1079
+ strokeWidth,
1080
+ dot: showDots ? { r: 3, fill: `var(--color-${item.key})`, strokeWidth: 0 } : false,
1081
+ activeDot: { r: 5, strokeWidth: 0 },
1082
+ isAnimationActive: true,
1083
+ animationDuration: 600,
1084
+ animationEasing: "ease-out"
1085
+ },
1086
+ item.key
1087
+ ))
1088
+ ] })
1089
+ }
1090
+ )
1091
+ ] });
1092
+ }
1093
+ function ComboMetricChart({
1094
+ data,
1095
+ config,
1096
+ indexKey = "name",
1097
+ series,
1098
+ colors,
1099
+ barSize = "md",
1100
+ showGrid = true,
1101
+ showLegend = true,
1102
+ gradientFill = false,
1103
+ curveType = "monotone",
1104
+ valueFormatter = formatTick,
1105
+ isLoading,
1106
+ error,
1107
+ onRetry,
1108
+ retryLabel,
1109
+ emptyTitle,
1110
+ emptyDescription,
1111
+ errorTitle,
1112
+ errorDescription,
1113
+ loadingLabel,
1114
+ stateClassName,
1115
+ className,
1116
+ ...props
1117
+ }) {
1118
+ const chartSeries = getChartSeries(config, series);
1119
+ const chartConfig = getChartConfigWithColors(
1120
+ config,
1121
+ chartSeries.map((item) => item.key),
1122
+ colors
1123
+ );
1124
+ const chartState = getChartState(
1125
+ {
1126
+ isLoading,
1127
+ error,
1128
+ onRetry,
1129
+ retryLabel,
1130
+ emptyTitle,
1131
+ emptyDescription,
1132
+ errorTitle,
1133
+ errorDescription,
1134
+ loadingLabel
1135
+ },
1136
+ hasChartData(data, chartSeries),
1137
+ cn("h-[340px] w-full", stateClassName)
1138
+ );
1139
+ if (chartState) {
1140
+ return chartState;
1141
+ }
1142
+ const areaSeries = gradientFill ? chartSeries.filter((s) => s.type === "area").map((s) => s.key) : [];
1143
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[340px] w-full", className), ...props, children: /* @__PURE__ */ jsxs(RechartsPrimitive.ComposedChart, { data, accessibilityLayer: true, children: [
1144
+ gradientFill && areaSeries.length > 0 && /* @__PURE__ */ jsx(AreaGradientDefs, { seriesKeys: areaSeries, opacity: 0.35 }),
1145
+ showGrid ? /* @__PURE__ */ jsx(
1146
+ RechartsPrimitive.CartesianGrid,
1147
+ {
1148
+ vertical: false,
1149
+ strokeDasharray: "3 3",
1150
+ stroke: "var(--border)",
1151
+ strokeOpacity: 0.5
1152
+ }
1153
+ ) : null,
1154
+ /* @__PURE__ */ jsx(
1155
+ RechartsPrimitive.XAxis,
1156
+ {
1157
+ dataKey: indexKey,
1158
+ tickLine: false,
1159
+ axisLine: false,
1160
+ tickMargin: 8
1161
+ }
1162
+ ),
1163
+ /* @__PURE__ */ jsx(
1164
+ RechartsPrimitive.YAxis,
1165
+ {
1166
+ tickLine: false,
1167
+ axisLine: false,
1168
+ tickMargin: 8,
1169
+ tickFormatter: valueFormatter
1170
+ }
1171
+ ),
1172
+ /* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
1173
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }) : null,
1174
+ chartSeries.map(
1175
+ (item) => item.type === "line" ? /* @__PURE__ */ jsx(
1176
+ RechartsPrimitive.Line,
1177
+ {
1178
+ type: curveType,
1179
+ dataKey: item.key,
1180
+ stroke: `var(--color-${item.key})`,
1181
+ strokeWidth: 2,
1182
+ dot: false,
1183
+ activeDot: { r: 5, strokeWidth: 0 },
1184
+ yAxisId: item.yAxisId,
1185
+ isAnimationActive: true,
1186
+ animationDuration: 600,
1187
+ animationEasing: "ease-out"
1188
+ },
1189
+ item.key
1190
+ ) : item.type === "area" ? /* @__PURE__ */ jsx(
1191
+ RechartsPrimitive.Area,
1192
+ {
1193
+ type: curveType,
1194
+ dataKey: item.key,
1195
+ stroke: `var(--color-${item.key})`,
1196
+ fill: gradientFill ? `url(#gradient-${item.key})` : `var(--color-${item.key})`,
1197
+ fillOpacity: gradientFill ? 1 : 0.12,
1198
+ strokeWidth: 2,
1199
+ dot: false,
1200
+ activeDot: { r: 5, strokeWidth: 0 },
1201
+ yAxisId: item.yAxisId,
1202
+ isAnimationActive: true,
1203
+ animationDuration: 600,
1204
+ animationEasing: "ease-out"
1205
+ },
1206
+ item.key
1207
+ ) : /* @__PURE__ */ jsx(
1208
+ RechartsPrimitive.Bar,
1209
+ {
1210
+ dataKey: item.key,
1211
+ fill: `var(--color-${item.key})`,
1212
+ radius: [4, 4, 0, 0],
1213
+ barSize: getBarSize(barSize),
1214
+ yAxisId: item.yAxisId,
1215
+ isAnimationActive: true,
1216
+ animationDuration: 600,
1217
+ animationEasing: "ease-out"
1218
+ },
1219
+ item.key
1220
+ )
1221
+ )
1222
+ ] }) });
1223
+ }
1224
+ function DonutBreakdownChart({
1225
+ data,
1226
+ config,
1227
+ nameKey = "name",
1228
+ valueKey = "value",
1229
+ colors,
1230
+ centerLabel,
1231
+ centerValue,
1232
+ showLegend = true,
1233
+ innerRadius = "58%",
1234
+ outerRadius = "82%",
1235
+ isLoading,
1236
+ error,
1237
+ onRetry,
1238
+ retryLabel,
1239
+ emptyTitle,
1240
+ emptyDescription,
1241
+ errorTitle,
1242
+ errorDescription,
1243
+ loadingLabel,
1244
+ stateClassName,
1245
+ className,
1246
+ ...props
1247
+ }) {
1248
+ const [activeIndex, setActiveIndex] = React.useState(0);
1249
+ const chartKeys = data.map((entry, index) => String(entry[nameKey] || `segment-${index}`));
1250
+ const chartConfig = getChartConfigWithColors(config, chartKeys, colors);
1251
+ const chartState = getChartState(
1252
+ {
1253
+ isLoading,
1254
+ error,
1255
+ onRetry,
1256
+ retryLabel,
1257
+ emptyTitle,
1258
+ emptyDescription,
1259
+ errorTitle,
1260
+ errorDescription,
1261
+ loadingLabel
1262
+ },
1263
+ hasPieData(data, nameKey, valueKey),
1264
+ cn("h-[320px] w-full", stateClassName)
1265
+ );
1266
+ if (chartState) {
1267
+ return chartState;
1268
+ }
1269
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[320px] w-full", className), ...props, children: /* @__PURE__ */ jsxs(RechartsPrimitive.PieChart, { accessibilityLayer: true, children: [
1270
+ /* @__PURE__ */ jsx(
1271
+ ChartTooltip,
1272
+ {
1273
+ cursor: false,
1274
+ content: /* @__PURE__ */ jsx(ChartTooltipContent, { hideLabel: true, nameKey })
1275
+ }
1276
+ ),
1277
+ showLegend ? /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, { nameKey }), verticalAlign: "bottom" }) : null,
1278
+ /* @__PURE__ */ jsxs(
1279
+ RechartsPrimitive.Pie,
1280
+ {
1281
+ data,
1282
+ dataKey: valueKey,
1283
+ nameKey,
1284
+ innerRadius,
1285
+ outerRadius,
1286
+ paddingAngle: 3,
1287
+ onMouseEnter: (_, index) => setActiveIndex(index),
1288
+ isAnimationActive: true,
1289
+ animationDuration: 600,
1290
+ animationEasing: "ease-out",
1291
+ children: [
1292
+ data.map((entry, index) => {
1293
+ const key = String(entry[nameKey] || `segment-${index}`);
1294
+ return /* @__PURE__ */ jsx(
1295
+ RechartsPrimitive.Cell,
1296
+ {
1297
+ fill: `var(--color-${key})`,
1298
+ opacity: index === activeIndex ? 1 : 0.7,
1299
+ stroke: "transparent"
1300
+ },
1301
+ key
1302
+ );
1303
+ }),
1304
+ centerValue || centerLabel ? /* @__PURE__ */ jsx(
1305
+ RechartsPrimitive.Label,
1306
+ {
1307
+ position: "center",
1308
+ content: ({ viewBox }) => {
1309
+ if (!viewBox || !("cx" in viewBox) || !("cy" in viewBox)) {
1310
+ return null;
1311
+ }
1312
+ return /* @__PURE__ */ jsxs("text", { x: viewBox.cx, y: viewBox.cy, textAnchor: "middle", dominantBaseline: "middle", children: [
1313
+ centerValue ? /* @__PURE__ */ jsx(
1314
+ "tspan",
1315
+ {
1316
+ x: viewBox.cx,
1317
+ y: viewBox.cy,
1318
+ className: "fill-foreground text-2xl font-semibold",
1319
+ children: centerValue
1320
+ }
1321
+ ) : null,
1322
+ centerLabel ? /* @__PURE__ */ jsx(
1323
+ "tspan",
1324
+ {
1325
+ x: viewBox.cx,
1326
+ y: Number(viewBox.cy) + 22,
1327
+ className: "fill-muted-foreground text-xs",
1328
+ children: centerLabel
1329
+ }
1330
+ ) : null
1331
+ ] });
1332
+ }
1333
+ }
1334
+ ) : null
1335
+ ]
1336
+ }
1337
+ )
1338
+ ] }) });
1339
+ }
1340
+ function SparklineChart({
1341
+ data,
1342
+ dataKey,
1343
+ color = "var(--chart-1)",
1344
+ filled = true,
1345
+ showEndDot = true,
1346
+ curveType = "monotone",
1347
+ strokeWidth = 2,
1348
+ className
1349
+ }) {
1350
+ const sparkId = React.useId().replace(/:/g, "");
1351
+ const lastPoint = data[data.length - 1];
1352
+ const lastValue = lastPoint ? lastPoint[dataKey] : void 0;
1353
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative h-12 w-full min-w-0", className), children: [
1354
+ /* @__PURE__ */ jsx(RechartsPrimitive.ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
1355
+ RechartsPrimitive.AreaChart,
1356
+ {
1357
+ data,
1358
+ margin: { top: 4, right: showEndDot ? 8 : 0, bottom: 0, left: 0 },
1359
+ children: [
1360
+ filled && /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: `spark-gradient-${sparkId}`, x1: "0", y1: "0", x2: "0", y2: "1", children: [
1361
+ /* @__PURE__ */ jsx("stop", { offset: "5%", stopColor: color, stopOpacity: 0.3 }),
1362
+ /* @__PURE__ */ jsx("stop", { offset: "95%", stopColor: color, stopOpacity: 0 })
1363
+ ] }) }),
1364
+ /* @__PURE__ */ jsx(
1365
+ RechartsPrimitive.Area,
1366
+ {
1367
+ type: curveType,
1368
+ dataKey,
1369
+ stroke: color,
1370
+ strokeWidth,
1371
+ fill: filled ? `url(#spark-gradient-${sparkId})` : "none",
1372
+ fillOpacity: 1,
1373
+ dot: false,
1374
+ activeDot: false,
1375
+ isAnimationActive: true,
1376
+ animationDuration: 600,
1377
+ animationEasing: "ease-out"
1378
+ }
1379
+ )
1380
+ ]
1381
+ }
1382
+ ) }),
1383
+ showEndDot && lastValue !== void 0 && lastValue !== null && /* @__PURE__ */ jsx(
1384
+ "div",
1385
+ {
1386
+ className: "pointer-events-none absolute right-0 top-1/2 h-2.5 w-2.5 -translate-y-1/2 rounded-full ring-2 ring-background",
1387
+ style: { backgroundColor: color }
1388
+ }
1389
+ )
1390
+ ] });
1391
+ }
1392
+ function RadarMetricChart({
1393
+ data,
1394
+ labelKey,
1395
+ series,
1396
+ colors,
1397
+ filled = true,
1398
+ fillOpacity = 0.25,
1399
+ showDots = false,
1400
+ showGrid = true,
1401
+ showLegend,
1402
+ valueFormatter,
1403
+ isLoading,
1404
+ error,
1405
+ onRetry,
1406
+ retryLabel,
1407
+ emptyTitle,
1408
+ emptyDescription,
1409
+ errorTitle,
1410
+ errorDescription,
1411
+ loadingLabel,
1412
+ stateClassName,
1413
+ className
1414
+ }) {
1415
+ const chartConfig = React.useMemo(
1416
+ () => buildChartConfig(
1417
+ series.map((s) => s.key),
1418
+ colors
1419
+ ),
1420
+ [series, colors]
1421
+ );
1422
+ const hasData = data.length > 0 && series.length > 0;
1423
+ const chartState = getChartState(
1424
+ {
1425
+ isLoading,
1426
+ error,
1427
+ emptyTitle,
1428
+ emptyDescription,
1429
+ errorTitle,
1430
+ errorDescription,
1431
+ loadingLabel,
1432
+ stateClassName,
1433
+ onRetry,
1434
+ retryLabel
1435
+ },
1436
+ hasData
1437
+ );
1438
+ const displayLegend = showLegend ?? series.length > 1;
1439
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[300px] w-full", className), children: chartState ?? /* @__PURE__ */ jsxs(RechartsPrimitive.RadarChart, { data, accessibilityLayer: true, children: [
1440
+ showGrid && /* @__PURE__ */ jsx(RechartsPrimitive.PolarGrid, { stroke: "var(--border)", strokeOpacity: 0.6 }),
1441
+ /* @__PURE__ */ jsx(
1442
+ RechartsPrimitive.PolarAngleAxis,
1443
+ {
1444
+ dataKey: labelKey,
1445
+ tick: { fill: "var(--muted-foreground)", fontSize: 12 }
1446
+ }
1447
+ ),
1448
+ /* @__PURE__ */ jsx(
1449
+ RechartsPrimitive.PolarRadiusAxis,
1450
+ {
1451
+ tick: false,
1452
+ axisLine: false,
1453
+ tickFormatter: valueFormatter
1454
+ }
1455
+ ),
1456
+ /* @__PURE__ */ jsx(
1457
+ ChartTooltip,
1458
+ {
1459
+ content: /* @__PURE__ */ jsx(
1460
+ ChartTooltipContent,
1461
+ {
1462
+ formatter: valueFormatter ? (v) => valueFormatter(v) : void 0
1463
+ }
1464
+ )
1465
+ }
1466
+ ),
1467
+ displayLegend && /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }),
1468
+ series.map((s) => /* @__PURE__ */ jsx(
1469
+ RechartsPrimitive.Radar,
1470
+ {
1471
+ name: s.label ?? s.key,
1472
+ dataKey: s.key,
1473
+ stroke: `var(--color-${s.key})`,
1474
+ fill: filled ? `var(--color-${s.key})` : "none",
1475
+ fillOpacity: filled ? fillOpacity : 0,
1476
+ dot: showDots ? { r: 3, fill: `var(--color-${s.key})` } : false,
1477
+ isAnimationActive: true,
1478
+ animationDuration: 600,
1479
+ animationEasing: "ease-out"
1480
+ },
1481
+ s.key
1482
+ ))
1483
+ ] }) });
1484
+ }
1485
+ function PieMetricChart({
1486
+ data,
1487
+ nameKey,
1488
+ valueKey,
1489
+ colors,
1490
+ outerRadius = "80%",
1491
+ innerRadius = 0,
1492
+ showLabels = false,
1493
+ showLegend = true,
1494
+ explodeIndex,
1495
+ explodeOffset = 12,
1496
+ valueFormatter,
1497
+ isLoading,
1498
+ error,
1499
+ onRetry,
1500
+ retryLabel,
1501
+ emptyTitle,
1502
+ emptyDescription,
1503
+ errorTitle,
1504
+ errorDescription,
1505
+ loadingLabel,
1506
+ stateClassName,
1507
+ className
1508
+ }) {
1509
+ const names = React.useMemo(() => data.map((d) => String(d[nameKey] ?? "")), [data, nameKey]);
1510
+ const chartConfig = React.useMemo(() => buildChartConfig(names, colors), [names, colors]);
1511
+ const hasData = hasPieData(data, nameKey, valueKey);
1512
+ const chartState = getChartState(
1513
+ {
1514
+ isLoading,
1515
+ error,
1516
+ emptyTitle,
1517
+ emptyDescription,
1518
+ errorTitle,
1519
+ errorDescription,
1520
+ loadingLabel,
1521
+ stateClassName,
1522
+ onRetry,
1523
+ retryLabel
1524
+ },
1525
+ hasData
1526
+ );
1527
+ return /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: cn("h-[300px] w-full", className), children: chartState ?? /* @__PURE__ */ jsxs(RechartsPrimitive.PieChart, { accessibilityLayer: true, children: [
1528
+ /* @__PURE__ */ jsx(
1529
+ ChartTooltip,
1530
+ {
1531
+ content: /* @__PURE__ */ jsx(
1532
+ ChartTooltipContent,
1533
+ {
1534
+ nameKey,
1535
+ formatter: valueFormatter ? (v) => valueFormatter(v) : void 0
1536
+ }
1537
+ )
1538
+ }
1539
+ ),
1540
+ showLegend && /* @__PURE__ */ jsx(ChartLegend, { content: /* @__PURE__ */ jsx(ChartLegendContent, { nameKey }) }),
1541
+ /* @__PURE__ */ jsx(
1542
+ RechartsPrimitive.Pie,
1543
+ {
1544
+ data,
1545
+ dataKey: valueKey,
1546
+ nameKey,
1547
+ outerRadius,
1548
+ innerRadius,
1549
+ paddingAngle: 2,
1550
+ label: showLabels ? ({ cx, cy, midAngle, innerRadius: ir, outerRadius: or, percent }) => {
1551
+ if (midAngle == null || percent == null) return null;
1552
+ const RADIAN = Math.PI / 180;
1553
+ const radius = Number(ir) + (Number(or) - Number(ir)) * 1.35;
1554
+ const x = Number(cx) + radius * Math.cos(-midAngle * RADIAN);
1555
+ const y = Number(cy) + radius * Math.sin(-midAngle * RADIAN);
1556
+ return percent > 0.04 ? /* @__PURE__ */ jsx(
1557
+ "text",
1558
+ {
1559
+ x,
1560
+ y,
1561
+ fill: "var(--foreground)",
1562
+ textAnchor: x > Number(cx) ? "start" : "end",
1563
+ dominantBaseline: "central",
1564
+ fontSize: 12,
1565
+ fontWeight: 500,
1566
+ children: `${(percent * 100).toFixed(0)}%`
1567
+ }
1568
+ ) : null;
1569
+ } : false,
1570
+ labelLine: false,
1571
+ isAnimationActive: true,
1572
+ animationDuration: 600,
1573
+ animationEasing: "ease-out",
1574
+ children: data.map((entry, index) => {
1575
+ const name = String(entry[nameKey] ?? "");
1576
+ const isExploded = index === explodeIndex;
1577
+ return /* @__PURE__ */ jsx(
1578
+ RechartsPrimitive.Cell,
1579
+ {
1580
+ fill: chartConfig[name]?.color ?? `var(--chart-${index % 8 + 1})`,
1581
+ stroke: "var(--background)",
1582
+ strokeWidth: 2,
1583
+ style: isExploded ? {
1584
+ filter: `drop-shadow(0 4px 8px color-mix(in srgb, ${chartConfig[name]?.color ?? "var(--chart-1)"} 40%, transparent))`
1585
+ } : void 0
1586
+ },
1587
+ `cell-${index}`
1588
+ );
1589
+ })
1590
+ }
1591
+ )
1592
+ ] }) });
1593
+ }
1594
+ function RadialBarMetricChart({
1595
+ data,
1596
+ dataKey = "value",
1597
+ nameKey = "name",
1598
+ colors,
1599
+ innerRadius = "30%",
1600
+ outerRadius = "100%",
1601
+ startAngle = 90,
1602
+ endAngle = -270,
1603
+ showBackground = true,
1604
+ showLegend = true,
1605
+ valueFormatter,
1606
+ isLoading,
1607
+ error,
1608
+ onRetry,
1609
+ retryLabel,
1610
+ emptyTitle,
1611
+ emptyDescription,
1612
+ errorTitle,
1613
+ errorDescription,
1614
+ loadingLabel,
1615
+ stateClassName,
1616
+ className
1617
+ }) {
1618
+ const names = React.useMemo(() => data.map((d) => String(d[nameKey] ?? "")), [data, nameKey]);
1619
+ const chartConfig = React.useMemo(() => buildChartConfig(names, colors), [names, colors]);
1620
+ const hasData = data.length > 0;
1621
+ const chartState = getChartState(
1622
+ {
1623
+ isLoading,
1624
+ error,
1625
+ emptyTitle,
1626
+ emptyDescription,
1627
+ errorTitle,
1628
+ errorDescription,
1629
+ loadingLabel,
1630
+ stateClassName,
1631
+ onRetry,
1632
+ retryLabel
1633
+ },
1634
+ hasData
1635
+ );
1636
+ const coloredData = React.useMemo(
1637
+ () => data.map((item, index) => {
1638
+ const name = String(item[nameKey] ?? "");
1639
+ return {
1640
+ ...item,
1641
+ fill: chartConfig[name]?.color ?? `var(--chart-${index % 8 + 1})`
1642
+ };
1643
+ }),
1644
+ [data, nameKey, chartConfig]
1645
+ );
1646
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex w-full flex-col gap-3", className), children: [
1647
+ /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: "h-[260px] w-full", children: chartState ?? /* @__PURE__ */ jsxs(
1648
+ RechartsPrimitive.RadialBarChart,
1649
+ {
1650
+ data: coloredData,
1651
+ innerRadius,
1652
+ outerRadius,
1653
+ startAngle,
1654
+ endAngle,
1655
+ accessibilityLayer: true,
1656
+ children: [
1657
+ /* @__PURE__ */ jsx(
1658
+ ChartTooltip,
1659
+ {
1660
+ cursor: false,
1661
+ content: /* @__PURE__ */ jsx(
1662
+ ChartTooltipContent,
1663
+ {
1664
+ nameKey,
1665
+ formatter: valueFormatter ? (v) => valueFormatter(v) : void 0
1666
+ }
1667
+ )
1668
+ }
1669
+ ),
1670
+ /* @__PURE__ */ jsx(
1671
+ RechartsPrimitive.RadialBar,
1672
+ {
1673
+ dataKey,
1674
+ background: showBackground ? { fill: "var(--muted)" } : false,
1675
+ cornerRadius: 6,
1676
+ isAnimationActive: true,
1677
+ animationDuration: 700,
1678
+ animationEasing: "ease-out"
1679
+ }
1680
+ )
1681
+ ]
1682
+ }
1683
+ ) }),
1684
+ showLegend && !chartState && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap justify-center gap-x-4 gap-y-1.5 px-2", children: coloredData.map((item, index) => {
1685
+ const d = item;
1686
+ const name = String(d[nameKey] ?? "");
1687
+ const fillColor = d.fill ?? `var(--chart-${index % 8 + 1})`;
1688
+ const val = d[dataKey];
1689
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
1690
+ /* @__PURE__ */ jsx(
1691
+ "span",
1692
+ {
1693
+ className: "inline-block h-2.5 w-2.5 shrink-0 rounded-full",
1694
+ style: { backgroundColor: fillColor }
1695
+ }
1696
+ ),
1697
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
1698
+ name,
1699
+ val !== void 0 && val !== null && /* @__PURE__ */ jsx("span", { className: "ml-1 font-medium text-foreground", children: valueFormatter ? valueFormatter(val) : String(val) })
1700
+ ] })
1701
+ ] }, name);
1702
+ }) })
1703
+ ] });
1704
+ }
1705
+ function GaugeChart({
1706
+ value,
1707
+ min = 0,
1708
+ max = 100,
1709
+ thresholds,
1710
+ label,
1711
+ valueFormatter,
1712
+ showNeedle = true,
1713
+ className
1714
+ }) {
1715
+ const percent = Math.min(1, Math.max(0, (value - min) / (max - min)));
1716
+ const percentInt = Math.round(percent * 100);
1717
+ const activeColor = React.useMemo(() => {
1718
+ if (!thresholds || thresholds.length === 0) return "var(--chart-1)";
1719
+ for (const t of thresholds) {
1720
+ if (percentInt <= t.value) return t.color;
1721
+ }
1722
+ return thresholds[thresholds.length - 1].color;
1723
+ }, [thresholds, percentInt]);
1724
+ const displayText = valueFormatter ? valueFormatter(value, percentInt) : `${percentInt}%`;
1725
+ const cx = 100;
1726
+ const cy = 100;
1727
+ const R = 80;
1728
+ const r = 54;
1729
+ const polar = (angleDeg, radius) => {
1730
+ const rad = angleDeg * Math.PI / 180;
1731
+ return {
1732
+ x: cx + radius * Math.cos(rad),
1733
+ y: cy - radius * Math.sin(rad)
1734
+ };
1735
+ };
1736
+ const trackStart = polar(180, R);
1737
+ const trackEnd = polar(0, R);
1738
+ const trackStartI = polar(180, r);
1739
+ const trackEndI = polar(0, r);
1740
+ const trackPath = [
1741
+ `M ${trackStart.x} ${trackStart.y}`,
1742
+ `A ${R} ${R} 0 0 1 ${trackEnd.x} ${trackEnd.y}`,
1743
+ `L ${trackEndI.x} ${trackEndI.y}`,
1744
+ `A ${r} ${r} 0 0 0 ${trackStartI.x} ${trackStartI.y}`,
1745
+ "Z"
1746
+ ].join(" ");
1747
+ const valueAngle = 180 - percent * 180;
1748
+ const valueEnd = polar(valueAngle, R);
1749
+ const valueEndI = polar(valueAngle, r);
1750
+ const valuePath = percent <= 0 ? "" : percent >= 1 ? trackPath : [
1751
+ `M ${trackStart.x} ${trackStart.y}`,
1752
+ `A ${R} ${R} 0 0 1 ${valueEnd.x} ${valueEnd.y}`,
1753
+ `L ${valueEndI.x} ${valueEndI.y}`,
1754
+ `A ${r} ${r} 0 0 0 ${trackStartI.x} ${trackStartI.y}`,
1755
+ "Z"
1756
+ ].join(" ");
1757
+ const needleAngle = 180 - percent * 180;
1758
+ const needleTip = polar(needleAngle, r - 6);
1759
+ const needleBase1 = polar(needleAngle + 90, 5);
1760
+ const needleBase2 = polar(needleAngle - 90, 5);
1761
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col items-center gap-2", className), children: [
1762
+ /* @__PURE__ */ jsx("div", { className: "relative w-full max-w-[260px]", children: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 200 130", className: "w-full", "aria-label": `Gauge: ${displayText}`, children: [
1763
+ /* @__PURE__ */ jsx("path", { d: trackPath, fill: "var(--muted)" }),
1764
+ valuePath && /* @__PURE__ */ jsx("path", { d: valuePath, fill: activeColor }),
1765
+ showNeedle && /* @__PURE__ */ jsxs("g", { children: [
1766
+ /* @__PURE__ */ jsx(
1767
+ "polygon",
1768
+ {
1769
+ points: `${needleTip.x},${needleTip.y} ${needleBase1.x},${needleBase1.y} ${needleBase2.x},${needleBase2.y}`,
1770
+ fill: "var(--foreground)",
1771
+ opacity: 0.85
1772
+ }
1773
+ ),
1774
+ /* @__PURE__ */ jsx("circle", { cx, cy, r: 5, fill: "var(--foreground)" })
1775
+ ] }),
1776
+ /* @__PURE__ */ jsx(
1777
+ "text",
1778
+ {
1779
+ x: cx,
1780
+ y: cy + 18,
1781
+ textAnchor: "middle",
1782
+ dominantBaseline: "middle",
1783
+ fontSize: 22,
1784
+ fontWeight: 700,
1785
+ fill: "currentColor",
1786
+ className: "fill-foreground",
1787
+ children: displayText
1788
+ }
1789
+ ),
1790
+ label && /* @__PURE__ */ jsx(
1791
+ "text",
1792
+ {
1793
+ x: cx,
1794
+ y: cy + 36,
1795
+ textAnchor: "middle",
1796
+ dominantBaseline: "middle",
1797
+ fontSize: 10,
1798
+ fill: "currentColor",
1799
+ className: "fill-muted-foreground",
1800
+ children: label
1801
+ }
1802
+ )
1803
+ ] }) }),
1804
+ thresholds && thresholds.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap justify-center gap-x-3 gap-y-1", children: thresholds.map((t, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
1805
+ /* @__PURE__ */ jsx(
1806
+ "span",
1807
+ {
1808
+ className: "inline-block h-2 w-2 shrink-0 rounded-full",
1809
+ style: { backgroundColor: t.color }
1810
+ }
1811
+ ),
1812
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t.label })
1813
+ ] }, i)) })
1814
+ ] });
1815
+ }
1816
+
1817
+ function Table({ className, ...props }) {
1818
+ return /* @__PURE__ */ jsx("div", { "data-slot": "table-container", className: "relative w-full overflow-x-auto", children: /* @__PURE__ */ jsx(
1819
+ "table",
1820
+ {
1821
+ "data-slot": "table",
1822
+ className: cn("w-full caption-bottom text-sm", className),
1823
+ ...props
1824
+ }
1825
+ ) });
1826
+ }
1827
+ function TableHeader({ className, ...props }) {
1828
+ return /* @__PURE__ */ jsx("thead", { "data-slot": "table-header", className: cn("[&_tr]:border-b", className), ...props });
1829
+ }
1830
+ function TableBody({ className, ...props }) {
1831
+ return /* @__PURE__ */ jsx(
1832
+ "tbody",
1833
+ {
1834
+ "data-slot": "table-body",
1835
+ className: cn("[&_tr:last-child]:border-0", className),
1836
+ ...props
1837
+ }
1838
+ );
1839
+ }
1840
+ function TableFooter({ className, ...props }) {
1841
+ return /* @__PURE__ */ jsx(
1842
+ "tfoot",
1843
+ {
1844
+ "data-slot": "table-footer",
1845
+ className: cn("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0", className),
1846
+ ...props
1847
+ }
1848
+ );
1849
+ }
1850
+ function TableRow({ className, ...props }) {
1851
+ return /* @__PURE__ */ jsx(
1852
+ "tr",
1853
+ {
1854
+ "data-slot": "table-row",
1855
+ className: cn(
1856
+ "hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
1857
+ className
1858
+ ),
1859
+ ...props
1860
+ }
1861
+ );
1862
+ }
1863
+ function TableHead({ className, ...props }) {
1864
+ return /* @__PURE__ */ jsx(
1865
+ "th",
1866
+ {
1867
+ "data-slot": "table-head",
1868
+ className: cn(
1869
+ "text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
1870
+ className
1871
+ ),
1872
+ ...props
1873
+ }
1874
+ );
1875
+ }
1876
+ function TableCell({ className, ...props }) {
1877
+ return /* @__PURE__ */ jsx(
1878
+ "td",
1879
+ {
1880
+ "data-slot": "table-cell",
1881
+ className: cn(
1882
+ "p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
1883
+ className
1884
+ ),
1885
+ ...props
1886
+ }
1887
+ );
1888
+ }
1889
+ function TableCaption({ className, ...props }) {
1890
+ return /* @__PURE__ */ jsx(
1891
+ "caption",
1892
+ {
1893
+ "data-slot": "table-caption",
1894
+ className: cn("text-muted-foreground mt-4 text-sm", className),
1895
+ ...props
1896
+ }
1897
+ );
1898
+ }
1899
+
1900
+ const Textarea = React.forwardRef(
1901
+ ({ className, size = "md", ...props }, ref) => {
1902
+ const sizeClasses = {
1903
+ sm: "px-2 py-1 text-sm",
1904
+ md: "px-3 py-2 text-base",
1905
+ lg: "px-4 py-3 text-base"
1906
+ };
1907
+ return /* @__PURE__ */ jsx(
1908
+ "textarea",
1909
+ {
1910
+ "data-slot": "textarea",
1911
+ className: cn(
1912
+ "flex min-h-16 w-full bg-background rounded-[var(--radius)] border border-border transition-colors outline-none resize-none text-foreground",
1913
+ "placeholder:text-muted-foreground",
1914
+ "focus:ring-2 focus:ring-primary focus:border-transparent",
1915
+ "disabled:cursor-not-allowed disabled:opacity-50",
1916
+ sizeClasses[size],
1917
+ className
1918
+ ),
1919
+ ref,
1920
+ ...props
1921
+ }
1922
+ );
1923
+ }
1924
+ );
1925
+ Textarea.displayName = "Textarea";
1926
+
1927
+ function Dialog({ ...props }) {
1928
+ return /* @__PURE__ */ jsx(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
1929
+ }
1930
+ function DialogTrigger({ ...props }) {
1931
+ return /* @__PURE__ */ jsx(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
1932
+ }
1933
+ function DialogPortal({ ...props }) {
1934
+ return /* @__PURE__ */ jsx(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
1935
+ }
1936
+ function DialogClose({ ...props }) {
1937
+ return /* @__PURE__ */ jsx(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
1938
+ }
1939
+ const DialogOverlay = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1940
+ DialogPrimitive.Overlay,
1941
+ {
1942
+ ref,
1943
+ "data-slot": "dialog-overlay",
1944
+ className: cn(
1945
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/40 backdrop-blur-sm",
1946
+ className
1947
+ ),
1948
+ ...props
1949
+ }
1950
+ ));
1951
+ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
1952
+ const dialogVariants = cva(
1953
+ "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 flex flex-col w-full translate-x-[-50%] translate-y-[-50%] border shadow-elevation-sm duration-200 rounded-[var(--radius-card)] overflow-hidden max-h-[calc(100dvh-2rem)]",
1954
+ {
1955
+ variants: {
1956
+ size: {
1957
+ sm: "max-w-sm",
1958
+ md: "max-w-md",
1959
+ lg: "max-w-lg",
1960
+ xl: "max-w-xl",
1961
+ "2xl": "max-w-2xl",
1962
+ "3xl": "max-w-3xl",
1963
+ "4xl": "max-w-4xl",
1964
+ "5xl": "max-w-5xl",
1965
+ full: "max-w-[calc(100vw-2rem)] h-[calc(100dvh-2rem)]"
1966
+ }
1967
+ },
1968
+ defaultVariants: {
1969
+ size: "lg"
1970
+ }
1971
+ }
1972
+ );
1973
+ const DialogContent = React.forwardRef(({ className, children, size, showClose = true, ...props }, ref) => /* @__PURE__ */ jsxs(DialogPortal, { "data-slot": "dialog-portal", children: [
1974
+ /* @__PURE__ */ jsx(DialogOverlay, {}),
1975
+ /* @__PURE__ */ jsxs(
1976
+ DialogPrimitive.Content,
1977
+ {
1978
+ ref,
1979
+ "data-slot": "dialog-content",
1980
+ className: cn(dialogVariants({ size }), className),
1981
+ ...props,
1982
+ children: [
1983
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4 p-6 overflow-y-auto flex-1 min-h-0", children }),
1984
+ showClose && /* @__PURE__ */ jsxs(DialogPrimitive.Close, { className: "absolute top-4 right-4 z-10 rounded-full p-2 opacity-70 transition-all hover:opacity-100 hover:bg-accent focus:ring-2 focus:ring-primary focus:ring-offset-2 focus:outline-none disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", children: [
1985
+ /* @__PURE__ */ jsx(XIcon, {}),
1986
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
1987
+ ] })
1988
+ ]
1989
+ }
1990
+ )
1991
+ ] }));
1992
+ DialogContent.displayName = DialogPrimitive.Content.displayName;
1993
+ function DialogHeader({ className, ...props }) {
1994
+ return /* @__PURE__ */ jsx(
1995
+ "div",
1996
+ {
1997
+ "data-slot": "dialog-header",
1998
+ className: cn("flex flex-col gap-2 text-left shrink-0", className),
1999
+ ...props
2000
+ }
2001
+ );
2002
+ }
2003
+ function DialogBody({ className, ...props }) {
2004
+ return /* @__PURE__ */ jsx(
2005
+ "div",
2006
+ {
2007
+ "data-slot": "dialog-body",
2008
+ className: cn("flex-1 overflow-y-auto min-h-0 -mx-6 px-6", className),
2009
+ ...props
2010
+ }
2011
+ );
2012
+ }
2013
+ function DialogFooter({ className, ...props }) {
2014
+ return /* @__PURE__ */ jsx(
2015
+ "div",
2016
+ {
2017
+ "data-slot": "dialog-footer",
2018
+ className: cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end shrink-0", className),
2019
+ ...props
2020
+ }
2021
+ );
2022
+ }
2023
+ function DialogTitle({ className, ...props }) {
2024
+ return /* @__PURE__ */ jsx(
2025
+ DialogPrimitive.Title,
2026
+ {
2027
+ "data-slot": "dialog-title",
2028
+ className: cn(
2029
+ "text-foreground font-semibold leading-tight text-[length:var(--text-h4)]",
2030
+ className
2031
+ ),
2032
+ ...props
2033
+ }
2034
+ );
2035
+ }
2036
+ function DialogDescription({
2037
+ className,
2038
+ ...props
2039
+ }) {
2040
+ return /* @__PURE__ */ jsx(
2041
+ DialogPrimitive.Description,
2042
+ {
2043
+ "data-slot": "dialog-description",
2044
+ className: cn("text-muted-foreground", className),
2045
+ ...props
2046
+ }
2047
+ );
2048
+ }
2049
+
2050
+ function useRichTextEditor({
2051
+ value,
2052
+ onChange
2053
+ }) {
2054
+ const editorRef = useRef(null);
2055
+ const searchInputRef = useRef(null);
2056
+ const linkInputRef = useRef(null);
2057
+ const savedSelection = useRef(null);
2058
+ const [wordCount, setWordCount] = useState(0);
2059
+ const [characterCount, setCharacterCount] = useState(0);
2060
+ const [activeFormats, setActiveFormats] = useState({
2061
+ bold: false,
2062
+ italic: false,
2063
+ underline: false,
2064
+ justifyLeft: false,
2065
+ justifyCenter: false,
2066
+ justifyRight: false,
2067
+ insertUnorderedList: false,
2068
+ insertOrderedList: false,
2069
+ link: false,
2070
+ h1: false,
2071
+ h2: false,
2072
+ h3: false,
2073
+ p: true
2074
+ });
2075
+ const [isSearchOpen, setIsSearchOpen] = useState(false);
2076
+ const [searchQuery, setSearchQuery] = useState("");
2077
+ const [linkUrl, setLinkUrl] = useState("https://");
2078
+ const [isLinkOpen, setIsLinkOpen] = useState(false);
2079
+ const [hasSavedSelection, setHasSavedSelection] = useState(false);
2080
+ const findParentTag = useCallback((node, tagName) => {
2081
+ let current = node;
2082
+ while (current && current !== editorRef.current) {
2083
+ if (current.nodeName === tagName) return current;
2084
+ current = current.parentNode;
2085
+ }
2086
+ return null;
2087
+ }, []);
2088
+ const updateActiveFormats = useCallback(() => {
2089
+ let formatBlock = "";
2090
+ try {
2091
+ formatBlock = document.queryCommandValue("formatBlock");
2092
+ } catch (_e) {
2093
+ }
2094
+ const selection = window.getSelection();
2095
+ const anchorNode = selection?.anchorNode;
2096
+ const focusNode = selection?.focusNode;
2097
+ setActiveFormats({
2098
+ bold: document.queryCommandState("bold"),
2099
+ italic: document.queryCommandState("italic"),
2100
+ underline: document.queryCommandState("underline"),
2101
+ justifyLeft: document.queryCommandState("justifyLeft"),
2102
+ justifyCenter: document.queryCommandState("justifyCenter"),
2103
+ justifyRight: document.queryCommandState("justifyRight"),
2104
+ insertUnorderedList: document.queryCommandState("insertUnorderedList"),
2105
+ insertOrderedList: document.queryCommandState("insertOrderedList"),
2106
+ link: !!(findParentTag(anchorNode || null, "A") || findParentTag(focusNode || null, "A")),
2107
+ h1: formatBlock === "h1" || formatBlock === "H1",
2108
+ h2: formatBlock === "h2" || formatBlock === "H2",
2109
+ h3: formatBlock === "h3" || formatBlock === "H3",
2110
+ p: formatBlock === "p" || formatBlock === "P" || formatBlock === "div" || formatBlock === "DIV" || formatBlock === ""
2111
+ });
2112
+ }, [findParentTag]);
2113
+ const updateActiveFormatsRef = useRef(updateActiveFormats);
2114
+ useEffect(() => {
2115
+ updateActiveFormatsRef.current = updateActiveFormats;
2116
+ }, [updateActiveFormats]);
2117
+ useEffect(() => {
2118
+ if (editorRef.current && editorRef.current.innerHTML !== value) {
2119
+ editorRef.current.innerHTML = value;
2120
+ }
2121
+ const handleSelectionChange = () => {
2122
+ if (document.activeElement === editorRef.current) {
2123
+ updateActiveFormatsRef.current();
2124
+ }
2125
+ };
2126
+ document.addEventListener("selectionchange", handleSelectionChange);
2127
+ return () => document.removeEventListener("selectionchange", handleSelectionChange);
2128
+ }, []);
2129
+ useEffect(() => {
2130
+ const text = editorRef.current?.innerText || "";
2131
+ setWordCount(text.trim() ? text.trim().split(/\s+/).length : 0);
2132
+ setCharacterCount(text.trim() ? text.length : 0);
2133
+ }, [value]);
2134
+ const handleInput = useCallback(() => {
2135
+ if (editorRef.current) {
2136
+ onChange?.(editorRef.current.innerHTML);
2137
+ updateActiveFormats();
2138
+ const text = editorRef.current.innerText || "";
2139
+ setWordCount(text.trim() ? text.trim().split(/\s+/).length : 0);
2140
+ setCharacterCount(text.trim() ? text.length : 0);
2141
+ }
2142
+ }, [onChange, updateActiveFormats]);
2143
+ const execCommand = useCallback(
2144
+ (command, val = "") => {
2145
+ document.execCommand(command, false, val);
2146
+ updateActiveFormats();
2147
+ editorRef.current?.focus();
2148
+ if (editorRef.current) {
2149
+ onChange?.(editorRef.current.innerHTML);
2150
+ }
2151
+ },
2152
+ [onChange, updateActiveFormats]
2153
+ );
2154
+ const performSearch = useCallback((text, backward = false) => {
2155
+ if (!text || !editorRef.current) return;
2156
+ const editor = editorRef.current;
2157
+ const selection = window.getSelection();
2158
+ if (!selection) return;
2159
+ const walker = document.createTreeWalker(editor, NodeFilter.SHOW_TEXT);
2160
+ const segments = [];
2161
+ let offset = 0;
2162
+ let node;
2163
+ while (node = walker.nextNode()) {
2164
+ segments.push({ node, start: offset });
2165
+ offset += node.length;
2166
+ }
2167
+ const fullText = segments.reduce((acc, s) => acc + (s.node.textContent ?? ""), "");
2168
+ let searchFrom = 0;
2169
+ if (selection.rangeCount > 0) {
2170
+ const range2 = selection.getRangeAt(0);
2171
+ if (editor.contains(range2.startContainer)) {
2172
+ const seg = segments.find((s) => s.node === range2.startContainer);
2173
+ if (seg) {
2174
+ searchFrom = backward ? seg.start + range2.startOffset - 1 : seg.start + range2.endOffset;
2175
+ }
2176
+ }
2177
+ }
2178
+ const lowerFull = fullText.toLowerCase();
2179
+ const lowerQuery = text.toLowerCase();
2180
+ let matchStart = -1;
2181
+ if (backward) {
2182
+ matchStart = lowerFull.lastIndexOf(lowerQuery, Math.max(0, searchFrom));
2183
+ if (matchStart === -1) matchStart = lowerFull.lastIndexOf(lowerQuery);
2184
+ } else {
2185
+ matchStart = lowerFull.indexOf(lowerQuery, searchFrom);
2186
+ if (matchStart === -1) matchStart = lowerFull.indexOf(lowerQuery);
2187
+ }
2188
+ if (matchStart === -1) return;
2189
+ const matchEnd = matchStart + text.length;
2190
+ const range = document.createRange();
2191
+ let startSet = false;
2192
+ let endSet = false;
2193
+ for (let i = 0; i < segments.length && !endSet; i++) {
2194
+ const seg = segments[i];
2195
+ const segEnd = seg.start + seg.node.length;
2196
+ if (!startSet && matchStart < segEnd && matchStart >= seg.start) {
2197
+ range.setStart(seg.node, matchStart - seg.start);
2198
+ startSet = true;
2199
+ }
2200
+ if (startSet && matchEnd <= segEnd) {
2201
+ range.setEnd(seg.node, matchEnd - seg.start);
2202
+ endSet = true;
2203
+ }
2204
+ }
2205
+ if (startSet && endSet) {
2206
+ selection.removeAllRanges();
2207
+ selection.addRange(range);
2208
+ range.startContainer.parentElement?.scrollIntoView?.({ block: "nearest" });
2209
+ }
2210
+ }, []);
2211
+ const handleCreateLink = useCallback(() => {
2212
+ if (savedSelection.current) {
2213
+ const selection2 = window.getSelection();
2214
+ selection2?.removeAllRanges();
2215
+ selection2?.addRange(savedSelection.current);
2216
+ }
2217
+ const selection = window.getSelection();
2218
+ const anchorNode = selection?.anchorNode;
2219
+ const existingLink = findParentTag(anchorNode || null, "A");
2220
+ if (existingLink) {
2221
+ if (linkUrl) {
2222
+ existingLink.setAttribute("href", linkUrl);
2223
+ existingLink.setAttribute("target", "_blank");
2224
+ existingLink.setAttribute("rel", "noopener noreferrer");
2225
+ existingLink.style.color = "hsl(var(--primary))";
2226
+ existingLink.style.textDecoration = "underline";
2227
+ existingLink.style.cursor = "pointer";
2228
+ }
2229
+ handleInput();
2230
+ setIsLinkOpen(false);
2231
+ savedSelection.current = null;
2232
+ return;
2233
+ }
2234
+ if (!selection || selection.rangeCount === 0 || selection.isCollapsed) {
2235
+ return;
2236
+ }
2237
+ if (linkUrl) {
2238
+ document.execCommand("createLink", false, linkUrl);
2239
+ setTimeout(() => {
2240
+ const anchor = findParentTag(window.getSelection()?.anchorNode || null, "A");
2241
+ if (anchor) {
2242
+ anchor.setAttribute("target", "_blank");
2243
+ anchor.setAttribute("rel", "noopener noreferrer");
2244
+ anchor.style.color = "hsl(var(--primary))";
2245
+ anchor.style.textDecoration = "underline";
2246
+ anchor.style.cursor = "pointer";
2247
+ }
2248
+ handleInput();
2249
+ }, 10);
2250
+ setIsLinkOpen(false);
2251
+ savedSelection.current = null;
2252
+ }
2253
+ }, [linkUrl, findParentTag, handleInput]);
2254
+ const handleUnlink = useCallback(() => {
2255
+ const selection = window.getSelection();
2256
+ const anchorNode = selection?.anchorNode;
2257
+ const existingLink = findParentTag(anchorNode || null, "A");
2258
+ if (existingLink) {
2259
+ const parent = existingLink.parentNode;
2260
+ while (existingLink.firstChild) {
2261
+ parent?.insertBefore(existingLink.firstChild, existingLink);
2262
+ }
2263
+ parent?.removeChild(existingLink);
2264
+ handleInput();
2265
+ } else {
2266
+ document.execCommand("unlink", false, "");
2267
+ }
2268
+ }, [findParentTag, handleInput]);
2269
+ const onLinkPopoverOpenChange = useCallback(
2270
+ (open) => {
2271
+ if (open) {
2272
+ const selection = window.getSelection();
2273
+ const anchorNode = selection?.anchorNode;
2274
+ const focusNode = selection?.focusNode;
2275
+ const existingLink = findParentTag(anchorNode || null, "A") || findParentTag(focusNode || null, "A");
2276
+ if (existingLink) {
2277
+ setLinkUrl(existingLink.getAttribute("href") || "https://");
2278
+ } else {
2279
+ setLinkUrl("https://");
2280
+ }
2281
+ if (selection && selection.rangeCount > 0 && (!selection.isCollapsed || existingLink)) {
2282
+ savedSelection.current = selection.getRangeAt(0).cloneRange();
2283
+ setHasSavedSelection(true);
2284
+ } else {
2285
+ savedSelection.current = null;
2286
+ setHasSavedSelection(false);
2287
+ }
2288
+ setTimeout(() => linkInputRef.current?.focus(), 100);
2289
+ } else {
2290
+ setHasSavedSelection(false);
2291
+ }
2292
+ setIsLinkOpen(open);
2293
+ },
2294
+ [findParentTag]
2295
+ );
2296
+ return {
2297
+ // Refs
2298
+ editorRef,
2299
+ searchInputRef,
2300
+ linkInputRef,
2301
+ // State
2302
+ activeFormats,
2303
+ isSearchOpen,
2304
+ setIsSearchOpen,
2305
+ searchQuery,
2306
+ setSearchQuery,
2307
+ linkUrl,
2308
+ setLinkUrl,
2309
+ isLinkOpen,
2310
+ hasSavedSelection,
2311
+ // Computed
2312
+ wordCount,
2313
+ characterCount,
2314
+ // Handlers
2315
+ updateActiveFormats,
2316
+ execCommand,
2317
+ handleInput,
2318
+ performSearch,
2319
+ handleCreateLink,
2320
+ handleUnlink,
2321
+ onLinkPopoverOpenChange
2322
+ };
2323
+ }
2324
+
2325
+ function RichTextEditor({
2326
+ value,
2327
+ onChange,
2328
+ placeholder,
2329
+ className,
2330
+ actionButton,
2331
+ allowSearch = true,
2332
+ allowLinks = true,
2333
+ allowUndoRedo = true,
2334
+ allowHeadings = true,
2335
+ allowFormatting = true,
2336
+ allowAlignment = true,
2337
+ allowLists = true,
2338
+ showWordCount = true,
2339
+ showCharacterCount = true,
2340
+ disabled = false,
2341
+ readOnly = false,
2342
+ onFocus,
2343
+ onBlur,
2344
+ minHeight,
2345
+ maxHeight
2346
+ }) {
2347
+ const isEditable = !disabled && !readOnly;
2348
+ const showToolbar = isEditable;
2349
+ const {
2350
+ editorRef,
2351
+ searchInputRef,
2352
+ linkInputRef,
2353
+ activeFormats,
2354
+ isSearchOpen,
2355
+ setIsSearchOpen,
2356
+ searchQuery,
2357
+ setSearchQuery,
2358
+ linkUrl,
2359
+ setLinkUrl,
2360
+ isLinkOpen,
2361
+ hasSavedSelection,
2362
+ wordCount,
2363
+ characterCount,
2364
+ updateActiveFormats,
2365
+ execCommand,
2366
+ handleInput,
2367
+ performSearch,
2368
+ handleCreateLink,
2369
+ handleUnlink,
2370
+ onLinkPopoverOpenChange
2371
+ } = useRichTextEditor({ value, onChange });
2372
+ const getCurrentBlockLabel = () => {
2373
+ if (activeFormats.h1)
2374
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2375
+ /* @__PURE__ */ jsx(Heading1, { className: "w-4 h-4 mr-1 shrink-0" }),
2376
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: "Título 1" })
2377
+ ] });
2378
+ if (activeFormats.h2)
2379
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2380
+ /* @__PURE__ */ jsx(Heading2, { className: "w-4 h-4 mr-1 shrink-0" }),
2381
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: "Título 2" })
2382
+ ] });
2383
+ if (activeFormats.h3)
2384
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2385
+ /* @__PURE__ */ jsx(Heading3, { className: "w-4 h-4 mr-1 shrink-0" }),
2386
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: "Título 3" })
2387
+ ] });
2388
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2389
+ /* @__PURE__ */ jsx(Type, { className: "w-4 h-4 mr-1 shrink-0" }),
2390
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: "Parágrafo" })
2391
+ ] });
2392
+ };
2393
+ return /* @__PURE__ */ jsxs(
2394
+ "div",
2395
+ {
2396
+ className: cn(
2397
+ "flex flex-col h-full w-full bg-background sm:border border-border sm:shadow-sm sm:rounded-lg overflow-hidden",
2398
+ disabled && "opacity-50 pointer-events-none",
2399
+ className
2400
+ ),
2401
+ children: [
2402
+ /* @__PURE__ */ jsx("style", { children: `
2403
+ [contenteditable]:empty:before {
2404
+ content: attr(data-placeholder);
2405
+ color: hsl(var(--muted-foreground));
2406
+ pointer-events: none;
2407
+ display: block;
2408
+ }
2409
+ .prose-editor ul {
2410
+ list-style-type: disc !important;
2411
+ padding-left: 1.5rem !important;
2412
+ margin-top: 0.5rem !important;
2413
+ margin-bottom: 0.5rem !important;
2414
+ }
2415
+ .prose-editor ol {
2416
+ list-style-type: decimal !important;
2417
+ padding-left: 1.5rem !important;
2418
+ margin-top: 0.5rem !important;
2419
+ margin-bottom: 0.5rem !important;
2420
+ }
2421
+ .prose-editor b, .prose-editor strong {
2422
+ font-weight: 600 !important;
2423
+ }
2424
+ .prose-editor i, .prose-editor em {
2425
+ font-style: italic !important;
2426
+ }
2427
+ .prose-editor u {
2428
+ text-decoration: underline !important;
2429
+ }
2430
+ .prose-editor h1 {
2431
+ font-size: 2.25rem !important;
2432
+ font-weight: 700 !important;
2433
+ margin-bottom: 1.25rem !important;
2434
+ line-height: 1.2 !important;
2435
+ margin-top: 2rem !important;
2436
+ color: hsl(var(--foreground));
2437
+ }
2438
+ .prose-editor h2 {
2439
+ font-size: 1.75rem !important;
2440
+ font-weight: 600 !important;
2441
+ margin-bottom: 1rem !important;
2442
+ margin-top: 1.5rem !important;
2443
+ color: hsl(var(--foreground));
2444
+ }
2445
+ .prose-editor h3 {
2446
+ font-size: 1.35rem !important;
2447
+ font-weight: 600 !important;
2448
+ margin-bottom: 0.75rem !important;
2449
+ margin-top: 1.25rem !important;
2450
+ color: hsl(var(--foreground));
2451
+ }
2452
+ .prose-editor p {
2453
+ margin-bottom: 1rem !important;
2454
+ line-height: 1.6 !important;
2455
+ }
2456
+ .prose-editor a {
2457
+ color: var(--info) !important;
2458
+ text-decoration: underline !important;
2459
+ cursor: pointer !important;
2460
+ }
2461
+ .prose-editor h1:first-child, .prose-editor h2:first-child, .prose-editor h3:first-child, .prose-editor p:first-child {
2462
+ margin-top: 0 !important;
2463
+ }
2464
+ .prose-editor {
2465
+ outline: none !important;
2466
+ }
2467
+ ` }),
2468
+ showToolbar && /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 border-b border-border bg-muted/30 flex items-center gap-1 flex-wrap shrink-0", children: [
2469
+ allowUndoRedo && /* @__PURE__ */ jsxs(Fragment, { children: [
2470
+ /* @__PURE__ */ jsx(
2471
+ Button,
2472
+ {
2473
+ variant: "ghost",
2474
+ size: "icon",
2475
+ className: "h-8 w-8 text-muted-foreground",
2476
+ onClick: () => execCommand("undo"),
2477
+ title: "Desfazer",
2478
+ "aria-label": "Desfazer",
2479
+ children: /* @__PURE__ */ jsx(Undo, { className: "w-4 h-4" })
2480
+ }
2481
+ ),
2482
+ /* @__PURE__ */ jsx(
2483
+ Button,
2484
+ {
2485
+ variant: "ghost",
2486
+ size: "icon",
2487
+ className: "h-8 w-8 text-muted-foreground",
2488
+ onClick: () => execCommand("redo"),
2489
+ title: "Refazer",
2490
+ "aria-label": "Refazer",
2491
+ children: /* @__PURE__ */ jsx(Redo, { className: "w-4 h-4" })
2492
+ }
2493
+ ),
2494
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2495
+ ] }),
2496
+ allowHeadings && /* @__PURE__ */ jsxs(Fragment, { children: [
2497
+ /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
2498
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
2499
+ Button,
2500
+ {
2501
+ variant: "ghost",
2502
+ size: "sm",
2503
+ className: "h-8 gap-0 text-muted-foreground w-[120px] justify-start px-2",
2504
+ children: [
2505
+ getCurrentBlockLabel(),
2506
+ /* @__PURE__ */ jsx(ChevronDown, { className: "w-3 h-3 ml-auto opacity-50 shrink-0" })
2507
+ ]
2508
+ }
2509
+ ) }),
2510
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", className: "w-[160px]", style: { zIndex: 9999 }, children: [
2511
+ /* @__PURE__ */ jsxs(
2512
+ DropdownMenuItem,
2513
+ {
2514
+ onPointerDown: (e) => e.preventDefault(),
2515
+ onClick: () => execCommand("formatBlock", "P"),
2516
+ className: "gap-2",
2517
+ children: [
2518
+ /* @__PURE__ */ jsx(Type, { className: "w-4 h-4 text-muted-foreground" }),
2519
+ " Parágrafo"
2520
+ ]
2521
+ }
2522
+ ),
2523
+ /* @__PURE__ */ jsxs(
2524
+ DropdownMenuItem,
2525
+ {
2526
+ onPointerDown: (e) => e.preventDefault(),
2527
+ onClick: () => execCommand("formatBlock", "H1"),
2528
+ className: "gap-2",
2529
+ children: [
2530
+ /* @__PURE__ */ jsx(Heading1, { className: "w-4 h-4 text-muted-foreground" }),
2531
+ " Título 1"
2532
+ ]
2533
+ }
2534
+ ),
2535
+ /* @__PURE__ */ jsxs(
2536
+ DropdownMenuItem,
2537
+ {
2538
+ onPointerDown: (e) => e.preventDefault(),
2539
+ onClick: () => execCommand("formatBlock", "H2"),
2540
+ className: "gap-2",
2541
+ children: [
2542
+ /* @__PURE__ */ jsx(Heading2, { className: "w-4 h-4 text-muted-foreground" }),
2543
+ " Título 2"
2544
+ ]
2545
+ }
2546
+ ),
2547
+ /* @__PURE__ */ jsxs(
2548
+ DropdownMenuItem,
2549
+ {
2550
+ onPointerDown: (e) => e.preventDefault(),
2551
+ onClick: () => execCommand("formatBlock", "H3"),
2552
+ className: "gap-2",
2553
+ children: [
2554
+ /* @__PURE__ */ jsx(Heading3, { className: "w-4 h-4 text-muted-foreground" }),
2555
+ " Título 3"
2556
+ ]
2557
+ }
2558
+ )
2559
+ ] })
2560
+ ] }),
2561
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2562
+ ] }),
2563
+ allowFormatting && /* @__PURE__ */ jsxs(Fragment, { children: [
2564
+ /* @__PURE__ */ jsx(
2565
+ Button,
2566
+ {
2567
+ variant: "ghost",
2568
+ size: "icon",
2569
+ className: cn(
2570
+ "h-8 w-8 text-muted-foreground",
2571
+ activeFormats.bold && "bg-muted text-foreground"
2572
+ ),
2573
+ onClick: () => execCommand("bold"),
2574
+ title: "Negrito",
2575
+ "aria-label": "Negrito",
2576
+ children: /* @__PURE__ */ jsx(Bold, { className: "w-4 h-4" })
2577
+ }
2578
+ ),
2579
+ /* @__PURE__ */ jsx(
2580
+ Button,
2581
+ {
2582
+ variant: "ghost",
2583
+ size: "icon",
2584
+ className: cn(
2585
+ "h-8 w-8 text-muted-foreground",
2586
+ activeFormats.italic && "bg-muted text-foreground"
2587
+ ),
2588
+ onClick: () => execCommand("italic"),
2589
+ title: "Itálico",
2590
+ "aria-label": "Itálico",
2591
+ children: /* @__PURE__ */ jsx(Italic, { className: "w-4 h-4" })
2592
+ }
2593
+ ),
2594
+ /* @__PURE__ */ jsx(
2595
+ Button,
2596
+ {
2597
+ variant: "ghost",
2598
+ size: "icon",
2599
+ className: cn(
2600
+ "h-8 w-8 text-muted-foreground",
2601
+ activeFormats.underline && "bg-muted text-foreground"
2602
+ ),
2603
+ onClick: () => execCommand("underline"),
2604
+ title: "Sublinhado",
2605
+ "aria-label": "Sublinhado",
2606
+ children: /* @__PURE__ */ jsx(Underline, { className: "w-4 h-4" })
2607
+ }
2608
+ ),
2609
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2610
+ ] }),
2611
+ allowAlignment && /* @__PURE__ */ jsxs(Fragment, { children: [
2612
+ /* @__PURE__ */ jsx(
2613
+ Button,
2614
+ {
2615
+ variant: "ghost",
2616
+ size: "icon",
2617
+ className: cn(
2618
+ "h-8 w-8 text-muted-foreground",
2619
+ activeFormats.justifyLeft && "bg-muted text-foreground"
2620
+ ),
2621
+ onClick: () => execCommand("justifyLeft"),
2622
+ title: "Alinhar à esquerda",
2623
+ "aria-label": "Alinhar à esquerda",
2624
+ children: /* @__PURE__ */ jsx(AlignLeft, { className: "w-4 h-4" })
2625
+ }
2626
+ ),
2627
+ /* @__PURE__ */ jsx(
2628
+ Button,
2629
+ {
2630
+ variant: "ghost",
2631
+ size: "icon",
2632
+ className: cn(
2633
+ "h-8 w-8 text-muted-foreground",
2634
+ activeFormats.justifyCenter && "bg-muted text-foreground"
2635
+ ),
2636
+ onClick: () => execCommand("justifyCenter"),
2637
+ title: "Centralizar",
2638
+ "aria-label": "Centralizar",
2639
+ children: /* @__PURE__ */ jsx(AlignCenter, { className: "w-4 h-4" })
2640
+ }
2641
+ ),
2642
+ /* @__PURE__ */ jsx(
2643
+ Button,
2644
+ {
2645
+ variant: "ghost",
2646
+ size: "icon",
2647
+ className: cn(
2648
+ "h-8 w-8 text-muted-foreground",
2649
+ activeFormats.justifyRight && "bg-muted text-foreground"
2650
+ ),
2651
+ onClick: () => execCommand("justifyRight"),
2652
+ title: "Alinhar à direita",
2653
+ "aria-label": "Alinhar à direita",
2654
+ children: /* @__PURE__ */ jsx(AlignRight, { className: "w-4 h-4" })
2655
+ }
2656
+ ),
2657
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2658
+ ] }),
2659
+ allowLists && /* @__PURE__ */ jsxs(Fragment, { children: [
2660
+ /* @__PURE__ */ jsx(
2661
+ Button,
2662
+ {
2663
+ variant: "ghost",
2664
+ size: "icon",
2665
+ className: cn(
2666
+ "h-8 w-8 text-muted-foreground",
2667
+ activeFormats.insertUnorderedList && "bg-muted text-foreground"
2668
+ ),
2669
+ onClick: () => execCommand("insertUnorderedList"),
2670
+ title: "Lista com marcadores",
2671
+ "aria-label": "Lista com marcadores",
2672
+ children: /* @__PURE__ */ jsx(List, { className: "w-4 h-4" })
2673
+ }
2674
+ ),
2675
+ /* @__PURE__ */ jsx(
2676
+ Button,
2677
+ {
2678
+ variant: "ghost",
2679
+ size: "icon",
2680
+ className: cn(
2681
+ "h-8 w-8 text-muted-foreground",
2682
+ activeFormats.insertOrderedList && "bg-muted text-foreground"
2683
+ ),
2684
+ onClick: () => execCommand("insertOrderedList"),
2685
+ title: "Lista numerada",
2686
+ "aria-label": "Lista numerada",
2687
+ children: /* @__PURE__ */ jsx(ListOrdered, { className: "w-4 h-4" })
2688
+ }
2689
+ ),
2690
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2691
+ ] }),
2692
+ allowLinks && /* @__PURE__ */ jsxs(Fragment, { children: [
2693
+ /* @__PURE__ */ jsxs(Popover, { open: isLinkOpen, onOpenChange: onLinkPopoverOpenChange, modal: false, children: [
2694
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
2695
+ Button,
2696
+ {
2697
+ variant: "ghost",
2698
+ size: "icon",
2699
+ className: cn(
2700
+ "h-8 w-8 text-muted-foreground",
2701
+ (activeFormats.link || isLinkOpen) && "bg-muted text-foreground"
2702
+ ),
2703
+ title: "Inserir link",
2704
+ "aria-label": "Inserir link",
2705
+ children: /* @__PURE__ */ jsx(Link, { className: "w-4 h-4" })
2706
+ }
2707
+ ) }),
2708
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-80 p-3", align: "start", style: { zIndex: 9999 }, children: !activeFormats.link && !hasSavedSelection ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground py-1", children: "Selecione um texto para criar um link." }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
2709
+ /* @__PURE__ */ jsx("div", { className: "text-xs font-medium", children: activeFormats.link ? "Editar Link" : "Inserir Link" }),
2710
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2711
+ /* @__PURE__ */ jsx(
2712
+ Input,
2713
+ {
2714
+ ref: linkInputRef,
2715
+ placeholder: "https://...",
2716
+ value: linkUrl,
2717
+ onChange: (e) => setLinkUrl(e.target.value),
2718
+ onKeyDown: (e) => {
2719
+ if (e.key === "Enter") {
2720
+ e.preventDefault();
2721
+ e.stopPropagation();
2722
+ handleCreateLink();
2723
+ }
2724
+ },
2725
+ className: "h-8 text-xs"
2726
+ }
2727
+ ),
2728
+ /* @__PURE__ */ jsx(Button, { size: "sm", className: "h-8", onClick: handleCreateLink, children: "Aplicar" })
2729
+ ] })
2730
+ ] }) })
2731
+ ] }),
2732
+ /* @__PURE__ */ jsx(
2733
+ Button,
2734
+ {
2735
+ variant: "ghost",
2736
+ size: "icon",
2737
+ className: "h-8 w-8 text-muted-foreground",
2738
+ onClick: handleUnlink,
2739
+ title: "Remover link",
2740
+ "aria-label": "Remover link",
2741
+ children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
2742
+ }
2743
+ ),
2744
+ /* @__PURE__ */ jsx("div", { className: "w-px h-6 bg-border mx-1 hidden sm:block" })
2745
+ ] }),
2746
+ (allowFormatting || allowHeadings || allowAlignment || allowLists || allowLinks) && /* @__PURE__ */ jsx(
2747
+ Button,
2748
+ {
2749
+ variant: "ghost",
2750
+ size: "icon",
2751
+ className: "h-8 w-8 text-muted-foreground",
2752
+ onClick: () => execCommand("removeFormat"),
2753
+ title: "Limpar formatação",
2754
+ "aria-label": "Limpar formatação",
2755
+ children: /* @__PURE__ */ jsx(Type, { className: "w-4 h-4" })
2756
+ }
2757
+ ),
2758
+ allowSearch && /* @__PURE__ */ jsx(
2759
+ Button,
2760
+ {
2761
+ variant: "ghost",
2762
+ size: "icon",
2763
+ className: cn(
2764
+ "h-8 w-8 text-muted-foreground",
2765
+ isSearchOpen && "bg-muted text-foreground"
2766
+ ),
2767
+ onClick: () => {
2768
+ setIsSearchOpen(!isSearchOpen);
2769
+ if (!isSearchOpen) setTimeout(() => searchInputRef.current?.focus(), 100);
2770
+ },
2771
+ title: "Buscar",
2772
+ "aria-label": "Buscar",
2773
+ children: /* @__PURE__ */ jsx(Search, { className: "w-4 h-4" })
2774
+ }
2775
+ ),
2776
+ actionButton && /* @__PURE__ */ jsxs(Fragment, { children: [
2777
+ /* @__PURE__ */ jsx("div", { className: "flex-1" }),
2778
+ actionButton
2779
+ ] })
2780
+ ] }),
2781
+ isSearchOpen && /* @__PURE__ */ jsxs("div", { className: "px-3 py-1.5 border-b border-border bg-muted/20 flex items-center gap-2", children: [
2782
+ /* @__PURE__ */ jsxs("div", { className: "relative flex-1 max-w-sm", children: [
2783
+ /* @__PURE__ */ jsx(Search, { className: "absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground" }),
2784
+ /* @__PURE__ */ jsx(
2785
+ Input,
2786
+ {
2787
+ ref: searchInputRef,
2788
+ placeholder: "Buscar no texto...",
2789
+ value: searchQuery,
2790
+ onChange: (e) => setSearchQuery(e.target.value),
2791
+ onKeyDown: (e) => {
2792
+ if (e.key === "Enter") {
2793
+ e.preventDefault();
2794
+ performSearch(searchQuery, e.shiftKey);
2795
+ }
2796
+ if (e.key === "Escape") {
2797
+ setIsSearchOpen(false);
2798
+ }
2799
+ },
2800
+ className: "h-8 pl-8 text-xs bg-background"
2801
+ }
2802
+ )
2803
+ ] }),
2804
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
2805
+ /* @__PURE__ */ jsx(
2806
+ Button,
2807
+ {
2808
+ variant: "ghost",
2809
+ size: "icon",
2810
+ className: "h-7 w-7",
2811
+ onMouseDown: (e) => e.preventDefault(),
2812
+ onClick: () => performSearch(searchQuery, true),
2813
+ title: "Anterior",
2814
+ children: /* @__PURE__ */ jsx(ChevronUp, { className: "w-4 h-4" })
2815
+ }
2816
+ ),
2817
+ /* @__PURE__ */ jsx(
2818
+ Button,
2819
+ {
2820
+ variant: "ghost",
2821
+ size: "icon",
2822
+ className: "h-7 w-7",
2823
+ onMouseDown: (e) => e.preventDefault(),
2824
+ onClick: () => performSearch(searchQuery, false),
2825
+ title: "Próximo",
2826
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "w-4 h-4" })
2827
+ }
2828
+ ),
2829
+ /* @__PURE__ */ jsx("div", { className: "w-px h-4 bg-border mx-1" }),
2830
+ /* @__PURE__ */ jsx(
2831
+ Button,
2832
+ {
2833
+ variant: "ghost",
2834
+ size: "icon",
2835
+ className: "h-7 w-7 text-muted-foreground hover:text-foreground",
2836
+ onClick: () => setIsSearchOpen(false),
2837
+ title: "Fechar busca",
2838
+ children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
2839
+ }
2840
+ )
2841
+ ] }),
2842
+ /* @__PURE__ */ jsx("div", { className: "hidden sm:block text-[10px] text-muted-foreground ml-auto uppercase tracking-wider font-medium", children: "Pressione Enter para buscar" })
2843
+ ] }),
2844
+ /* @__PURE__ */ jsx(
2845
+ "div",
2846
+ {
2847
+ className: "flex-1 overflow-y-auto p-4 sm:p-8 bg-background scrollbar-thin",
2848
+ style: { minHeight, maxHeight },
2849
+ children: /* @__PURE__ */ jsx(
2850
+ "div",
2851
+ {
2852
+ ref: editorRef,
2853
+ contentEditable: isEditable,
2854
+ role: "textbox",
2855
+ "aria-multiline": "true",
2856
+ "aria-label": placeholder || "Editor de texto",
2857
+ "aria-readonly": readOnly,
2858
+ "aria-disabled": disabled,
2859
+ onInput: handleInput,
2860
+ onSelect: isEditable ? updateActiveFormats : void 0,
2861
+ onFocus: () => {
2862
+ updateActiveFormats();
2863
+ onFocus?.();
2864
+ },
2865
+ onBlur,
2866
+ className: "prose-editor min-h-full max-w-none focus:outline-none",
2867
+ "data-placeholder": placeholder
2868
+ }
2869
+ )
2870
+ }
2871
+ ),
2872
+ (showWordCount || showCharacterCount) && /* @__PURE__ */ jsx("div", { className: "px-4 py-2 border-t border-border bg-muted/20 flex items-center justify-between", children: /* @__PURE__ */ jsxs("div", { className: "text-[10px] sm:text-xs text-muted-foreground font-medium uppercase tracking-wider flex items-center gap-2", children: [
2873
+ showWordCount && /* @__PURE__ */ jsxs("span", { children: [
2874
+ wordCount,
2875
+ " ",
2876
+ wordCount === 1 ? "palavra" : "palavras"
2877
+ ] }),
2878
+ showWordCount && showCharacterCount && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "•" }),
2879
+ showCharacterCount && /* @__PURE__ */ jsxs("span", { children: [
2880
+ characterCount,
2881
+ " ",
2882
+ characterCount === 1 ? "caractere" : "caracteres"
2883
+ ] })
2884
+ ] }) })
2885
+ ]
2886
+ }
2887
+ );
2888
+ }
2889
+
2890
+ export { Alert as A, EmptyTitle as B, ChartCard as C, DashboardBarChart as D, Empty as E, RadialBarMetricChart as F, GaugeChart as G, HorizontalBarChart as H, InteractiveTimeSeriesChart as I, RichTextEditor as J, ScrollBar as K, SparklineChart as L, TableBody as M, TableCaption as N, TableCell as O, PieMetricChart as P, TableFooter as Q, RadarMetricChart as R, ScrollArea as S, Table as T, TableHead as U, TableHeader as V, TableRow as W, Textarea as X, useChart as Y, useRichTextEditor as Z, AlertDescription as a, AlertTitle as b, ChartContainer as c, ChartLegend as d, ChartLegendContent as e, ChartStyle as f, ChartTooltip as g, ChartTooltipContent as h, ComboMetricChart as i, DashboardLineChart as j, Dialog as k, DialogBody as l, DialogClose as m, DialogContent as n, DialogDescription as o, DialogFooter as p, DialogHeader as q, DialogOverlay as r, DialogPortal as s, DialogTitle as t, DialogTrigger as u, DonutBreakdownChart as v, EmptyAction as w, EmptyDescription as x, EmptyIcon as y, EmptyImage as z };