@logickernel/bridge 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1312 @@
1
+ import * as React2 from 'react';
2
+ import { useState, useEffect } from 'react';
3
+ import { Slot } from '@radix-ui/react-slot';
4
+ import { cva } from 'class-variance-authority';
5
+ import * as LucideIcons from 'lucide-react';
6
+ import { ChevronRight, ChevronsUpDown, BadgeCheck, LogOut, GalleryVerticalEnd, Check, PanelLeftIcon, XIcon } from 'lucide-react';
7
+ import { clsx } from 'clsx';
8
+ import { twMerge } from 'tailwind-merge';
9
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
10
+ import * as SheetPrimitive from '@radix-ui/react-dialog';
11
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
12
+ import { usePathname, useRouter } from 'next/navigation';
13
+ import Link from 'next/link';
14
+ import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
15
+ import { signOut } from 'next-auth/react';
16
+ import * as AvatarPrimitive from '@radix-ui/react-avatar';
17
+ import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
18
+
19
+ // src/next/components/ui/sidebar.tsx
20
+ var MOBILE_BREAKPOINT = 768;
21
+ function useIsMobile() {
22
+ const [isMobile, setIsMobile] = React2.useState(void 0);
23
+ React2.useEffect(() => {
24
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
25
+ const onChange = () => {
26
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
27
+ };
28
+ mql.addEventListener("change", onChange);
29
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
30
+ return () => mql.removeEventListener("change", onChange);
31
+ }, []);
32
+ return !!isMobile;
33
+ }
34
+ function cn(...inputs) {
35
+ return twMerge(clsx(inputs));
36
+ }
37
+ var buttonVariants = cva(
38
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
39
+ {
40
+ variants: {
41
+ variant: {
42
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
43
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
44
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
45
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
46
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
47
+ link: "text-primary underline-offset-4 hover:underline"
48
+ },
49
+ size: {
50
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
51
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
52
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
53
+ icon: "size-9",
54
+ "icon-sm": "size-8",
55
+ "icon-lg": "size-10"
56
+ }
57
+ },
58
+ defaultVariants: {
59
+ variant: "default",
60
+ size: "default"
61
+ }
62
+ }
63
+ );
64
+ function Button({
65
+ className,
66
+ variant,
67
+ size,
68
+ asChild = false,
69
+ ...props
70
+ }) {
71
+ const Comp = asChild ? Slot : "button";
72
+ return /* @__PURE__ */ jsx(
73
+ Comp,
74
+ {
75
+ "data-slot": "button",
76
+ className: cn(buttonVariants({ variant, size, className })),
77
+ ...props
78
+ }
79
+ );
80
+ }
81
+ function Sheet({ ...props }) {
82
+ return /* @__PURE__ */ jsx(SheetPrimitive.Root, { "data-slot": "sheet", ...props });
83
+ }
84
+ function SheetPortal({
85
+ ...props
86
+ }) {
87
+ return /* @__PURE__ */ jsx(SheetPrimitive.Portal, { "data-slot": "sheet-portal", ...props });
88
+ }
89
+ function SheetOverlay({
90
+ className,
91
+ ...props
92
+ }) {
93
+ return /* @__PURE__ */ jsx(
94
+ SheetPrimitive.Overlay,
95
+ {
96
+ "data-slot": "sheet-overlay",
97
+ className: cn(
98
+ "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/50",
99
+ className
100
+ ),
101
+ ...props
102
+ }
103
+ );
104
+ }
105
+ function SheetContent({
106
+ className,
107
+ children,
108
+ side = "right",
109
+ ...props
110
+ }) {
111
+ return /* @__PURE__ */ jsxs(SheetPortal, { children: [
112
+ /* @__PURE__ */ jsx(SheetOverlay, {}),
113
+ /* @__PURE__ */ jsxs(
114
+ SheetPrimitive.Content,
115
+ {
116
+ "data-slot": "sheet-content",
117
+ className: cn(
118
+ "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
119
+ side === "right" && "data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
120
+ side === "left" && "data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
121
+ side === "top" && "data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
122
+ side === "bottom" && "data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
123
+ className
124
+ ),
125
+ ...props,
126
+ children: [
127
+ children,
128
+ /* @__PURE__ */ jsxs(SheetPrimitive.Close, { className: "ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none", children: [
129
+ /* @__PURE__ */ jsx(XIcon, { className: "size-4" }),
130
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
131
+ ] })
132
+ ]
133
+ }
134
+ )
135
+ ] });
136
+ }
137
+ function SheetHeader({ className, ...props }) {
138
+ return /* @__PURE__ */ jsx(
139
+ "div",
140
+ {
141
+ "data-slot": "sheet-header",
142
+ className: cn("flex flex-col gap-1.5 p-4", className),
143
+ ...props
144
+ }
145
+ );
146
+ }
147
+ function SheetTitle({
148
+ className,
149
+ ...props
150
+ }) {
151
+ return /* @__PURE__ */ jsx(
152
+ SheetPrimitive.Title,
153
+ {
154
+ "data-slot": "sheet-title",
155
+ className: cn("text-foreground font-semibold", className),
156
+ ...props
157
+ }
158
+ );
159
+ }
160
+ function SheetDescription({
161
+ className,
162
+ ...props
163
+ }) {
164
+ return /* @__PURE__ */ jsx(
165
+ SheetPrimitive.Description,
166
+ {
167
+ "data-slot": "sheet-description",
168
+ className: cn("text-muted-foreground text-sm", className),
169
+ ...props
170
+ }
171
+ );
172
+ }
173
+ function Skeleton({ className, ...props }) {
174
+ return /* @__PURE__ */ jsx(
175
+ "div",
176
+ {
177
+ "data-slot": "skeleton",
178
+ className: cn("bg-accent animate-pulse rounded-md", className),
179
+ ...props
180
+ }
181
+ );
182
+ }
183
+ function TooltipProvider({
184
+ delayDuration = 0,
185
+ ...props
186
+ }) {
187
+ return /* @__PURE__ */ jsx(
188
+ TooltipPrimitive.Provider,
189
+ {
190
+ "data-slot": "tooltip-provider",
191
+ delayDuration,
192
+ ...props
193
+ }
194
+ );
195
+ }
196
+ function Tooltip({
197
+ ...props
198
+ }) {
199
+ return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
200
+ }
201
+ function TooltipTrigger({
202
+ ...props
203
+ }) {
204
+ return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
205
+ }
206
+ function TooltipContent({
207
+ className,
208
+ sideOffset = 0,
209
+ children,
210
+ ...props
211
+ }) {
212
+ return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
213
+ TooltipPrimitive.Content,
214
+ {
215
+ "data-slot": "tooltip-content",
216
+ sideOffset,
217
+ className: cn(
218
+ "bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
219
+ className
220
+ ),
221
+ ...props,
222
+ children: [
223
+ children,
224
+ /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
225
+ ]
226
+ }
227
+ ) });
228
+ }
229
+ var SIDEBAR_COOKIE_NAME = "sidebar_state";
230
+ var SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
231
+ var SIDEBAR_WIDTH = "16rem";
232
+ var SIDEBAR_WIDTH_MOBILE = "18rem";
233
+ var SIDEBAR_WIDTH_ICON = "3rem";
234
+ var SIDEBAR_KEYBOARD_SHORTCUT = "b";
235
+ var SidebarContext = React2.createContext(null);
236
+ function useSidebar() {
237
+ const context = React2.useContext(SidebarContext);
238
+ if (!context) {
239
+ throw new Error("useSidebar must be used within a SidebarProvider.");
240
+ }
241
+ return context;
242
+ }
243
+ function SidebarProvider({
244
+ defaultOpen = true,
245
+ open: openProp,
246
+ onOpenChange: setOpenProp,
247
+ className,
248
+ style,
249
+ children,
250
+ ...props
251
+ }) {
252
+ const isMobile = useIsMobile();
253
+ const [openMobile, setOpenMobile] = React2.useState(false);
254
+ const [_open, _setOpen] = React2.useState(defaultOpen);
255
+ const open = openProp ?? _open;
256
+ const setOpen = React2.useCallback(
257
+ (value) => {
258
+ const openState = typeof value === "function" ? value(open) : value;
259
+ if (setOpenProp) {
260
+ setOpenProp(openState);
261
+ } else {
262
+ _setOpen(openState);
263
+ }
264
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
265
+ },
266
+ [setOpenProp, open]
267
+ );
268
+ const toggleSidebar = React2.useCallback(() => {
269
+ return isMobile ? setOpenMobile((open2) => !open2) : setOpen((open2) => !open2);
270
+ }, [isMobile, setOpen, setOpenMobile]);
271
+ React2.useEffect(() => {
272
+ const handleKeyDown = (event) => {
273
+ if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
274
+ event.preventDefault();
275
+ toggleSidebar();
276
+ }
277
+ };
278
+ window.addEventListener("keydown", handleKeyDown);
279
+ return () => window.removeEventListener("keydown", handleKeyDown);
280
+ }, [toggleSidebar]);
281
+ const state = open ? "expanded" : "collapsed";
282
+ const contextValue = React2.useMemo(
283
+ () => ({
284
+ state,
285
+ open,
286
+ setOpen,
287
+ isMobile,
288
+ openMobile,
289
+ setOpenMobile,
290
+ toggleSidebar
291
+ }),
292
+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
293
+ );
294
+ return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 0, children: /* @__PURE__ */ jsx(
295
+ "div",
296
+ {
297
+ "data-slot": "sidebar-wrapper",
298
+ style: {
299
+ "--sidebar-width": SIDEBAR_WIDTH,
300
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
301
+ ...style
302
+ },
303
+ className: cn(
304
+ "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
305
+ className
306
+ ),
307
+ ...props,
308
+ children
309
+ }
310
+ ) }) });
311
+ }
312
+ function Sidebar({
313
+ side = "left",
314
+ variant = "sidebar",
315
+ collapsible = "offcanvas",
316
+ className,
317
+ children,
318
+ ...props
319
+ }) {
320
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
321
+ if (collapsible === "none") {
322
+ return /* @__PURE__ */ jsx(
323
+ "div",
324
+ {
325
+ "data-slot": "sidebar",
326
+ className: cn(
327
+ "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
328
+ className
329
+ ),
330
+ ...props,
331
+ children
332
+ }
333
+ );
334
+ }
335
+ if (isMobile) {
336
+ return /* @__PURE__ */ jsx(Sheet, { open: openMobile, onOpenChange: setOpenMobile, ...props, children: /* @__PURE__ */ jsxs(
337
+ SheetContent,
338
+ {
339
+ "data-sidebar": "sidebar",
340
+ "data-slot": "sidebar",
341
+ "data-mobile": "true",
342
+ className: "bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden",
343
+ style: {
344
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE
345
+ },
346
+ side,
347
+ children: [
348
+ /* @__PURE__ */ jsxs(SheetHeader, { className: "sr-only", children: [
349
+ /* @__PURE__ */ jsx(SheetTitle, { children: "Sidebar" }),
350
+ /* @__PURE__ */ jsx(SheetDescription, { children: "Displays the mobile sidebar." })
351
+ ] }),
352
+ /* @__PURE__ */ jsx("div", { className: "flex h-full w-full flex-col", children })
353
+ ]
354
+ }
355
+ ) });
356
+ }
357
+ return /* @__PURE__ */ jsxs(
358
+ "div",
359
+ {
360
+ className: "group peer text-sidebar-foreground hidden md:block",
361
+ "data-state": state,
362
+ "data-collapsible": state === "collapsed" ? collapsible : "",
363
+ "data-variant": variant,
364
+ "data-side": side,
365
+ "data-slot": "sidebar",
366
+ children: [
367
+ /* @__PURE__ */ jsx(
368
+ "div",
369
+ {
370
+ "data-slot": "sidebar-gap",
371
+ className: cn(
372
+ "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
373
+ "group-data-[collapsible=offcanvas]:w-0",
374
+ "group-data-[side=right]:rotate-180",
375
+ variant === "floating" || variant === "inset" ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]" : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
376
+ )
377
+ }
378
+ ),
379
+ /* @__PURE__ */ jsx(
380
+ "div",
381
+ {
382
+ "data-slot": "sidebar-container",
383
+ className: cn(
384
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
385
+ side === "left" ? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]" : "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
386
+ // Adjust the padding for floating and inset variants.
387
+ variant === "floating" || variant === "inset" ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]" : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
388
+ className
389
+ ),
390
+ ...props,
391
+ children: /* @__PURE__ */ jsx(
392
+ "div",
393
+ {
394
+ "data-sidebar": "sidebar",
395
+ "data-slot": "sidebar-inner",
396
+ className: "bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm",
397
+ children
398
+ }
399
+ )
400
+ }
401
+ )
402
+ ]
403
+ }
404
+ );
405
+ }
406
+ function SidebarTrigger({
407
+ className,
408
+ onClick,
409
+ ...props
410
+ }) {
411
+ const { toggleSidebar } = useSidebar();
412
+ return /* @__PURE__ */ jsxs(
413
+ Button,
414
+ {
415
+ "data-sidebar": "trigger",
416
+ "data-slot": "sidebar-trigger",
417
+ variant: "ghost",
418
+ size: "icon",
419
+ className: cn("size-7", className),
420
+ onClick: (event) => {
421
+ onClick?.(event);
422
+ toggleSidebar();
423
+ },
424
+ ...props,
425
+ children: [
426
+ /* @__PURE__ */ jsx(PanelLeftIcon, {}),
427
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Toggle Sidebar" })
428
+ ]
429
+ }
430
+ );
431
+ }
432
+ function SidebarRail({ className, ...props }) {
433
+ const { toggleSidebar } = useSidebar();
434
+ return /* @__PURE__ */ jsx(
435
+ "button",
436
+ {
437
+ "data-sidebar": "rail",
438
+ "data-slot": "sidebar-rail",
439
+ "aria-label": "Toggle Sidebar",
440
+ tabIndex: -1,
441
+ onClick: toggleSidebar,
442
+ title: "Toggle Sidebar",
443
+ className: cn(
444
+ "hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
445
+ "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
446
+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
447
+ "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
448
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
449
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
450
+ className
451
+ ),
452
+ ...props
453
+ }
454
+ );
455
+ }
456
+ function SidebarInset({ className, ...props }) {
457
+ return /* @__PURE__ */ jsx(
458
+ "main",
459
+ {
460
+ "data-slot": "sidebar-inset",
461
+ className: cn(
462
+ "bg-background relative flex w-full flex-1 flex-col",
463
+ "px-4",
464
+ "md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
465
+ className
466
+ ),
467
+ ...props
468
+ }
469
+ );
470
+ }
471
+ function SidebarHeader({ className, ...props }) {
472
+ return /* @__PURE__ */ jsx(
473
+ "div",
474
+ {
475
+ "data-slot": "sidebar-header",
476
+ "data-sidebar": "header",
477
+ className: cn("flex flex-col gap-2 p-2", className),
478
+ ...props
479
+ }
480
+ );
481
+ }
482
+ function SidebarFooter({ className, ...props }) {
483
+ return /* @__PURE__ */ jsx(
484
+ "div",
485
+ {
486
+ "data-slot": "sidebar-footer",
487
+ "data-sidebar": "footer",
488
+ className: cn("flex flex-col gap-2 p-2", className),
489
+ ...props
490
+ }
491
+ );
492
+ }
493
+ function SidebarContent({ className, ...props }) {
494
+ return /* @__PURE__ */ jsx(
495
+ "div",
496
+ {
497
+ "data-slot": "sidebar-content",
498
+ "data-sidebar": "content",
499
+ className: cn(
500
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
501
+ className
502
+ ),
503
+ ...props
504
+ }
505
+ );
506
+ }
507
+ function SidebarGroup({ className, ...props }) {
508
+ return /* @__PURE__ */ jsx(
509
+ "div",
510
+ {
511
+ "data-slot": "sidebar-group",
512
+ "data-sidebar": "group",
513
+ className: cn("relative flex w-full min-w-0 flex-col p-2", className),
514
+ ...props
515
+ }
516
+ );
517
+ }
518
+ function SidebarGroupLabel({
519
+ className,
520
+ asChild = false,
521
+ ...props
522
+ }) {
523
+ const Comp = asChild ? Slot : "div";
524
+ return /* @__PURE__ */ jsx(
525
+ Comp,
526
+ {
527
+ "data-slot": "sidebar-group-label",
528
+ "data-sidebar": "group-label",
529
+ className: cn(
530
+ "text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
531
+ "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
532
+ className
533
+ ),
534
+ ...props
535
+ }
536
+ );
537
+ }
538
+ function SidebarMenu({ className, ...props }) {
539
+ return /* @__PURE__ */ jsx(
540
+ "ul",
541
+ {
542
+ "data-slot": "sidebar-menu",
543
+ "data-sidebar": "menu",
544
+ className: cn("flex w-full min-w-0 flex-col gap-1", className),
545
+ ...props
546
+ }
547
+ );
548
+ }
549
+ function SidebarMenuItem({ className, ...props }) {
550
+ return /* @__PURE__ */ jsx(
551
+ "li",
552
+ {
553
+ "data-slot": "sidebar-menu-item",
554
+ "data-sidebar": "menu-item",
555
+ className: cn("group/menu-item relative", className),
556
+ ...props
557
+ }
558
+ );
559
+ }
560
+ var sidebarMenuButtonVariants = cva(
561
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
562
+ {
563
+ variants: {
564
+ variant: {
565
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
566
+ outline: "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"
567
+ },
568
+ size: {
569
+ default: "h-8 text-sm",
570
+ sm: "h-7 text-xs",
571
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!"
572
+ }
573
+ },
574
+ defaultVariants: {
575
+ variant: "default",
576
+ size: "default"
577
+ }
578
+ }
579
+ );
580
+ function SidebarMenuButton({
581
+ asChild = false,
582
+ isActive = false,
583
+ variant = "default",
584
+ size = "default",
585
+ tooltip,
586
+ className,
587
+ ...props
588
+ }) {
589
+ const Comp = asChild ? Slot : "button";
590
+ const { isMobile, state } = useSidebar();
591
+ const button = /* @__PURE__ */ jsx(
592
+ Comp,
593
+ {
594
+ "data-slot": "sidebar-menu-button",
595
+ "data-sidebar": "menu-button",
596
+ "data-size": size,
597
+ "data-active": isActive,
598
+ className: cn(sidebarMenuButtonVariants({ variant, size }), className),
599
+ ...props
600
+ }
601
+ );
602
+ if (!tooltip) {
603
+ return button;
604
+ }
605
+ if (typeof tooltip === "string") {
606
+ tooltip = {
607
+ children: tooltip
608
+ };
609
+ }
610
+ return /* @__PURE__ */ jsxs(Tooltip, { children: [
611
+ /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: button }),
612
+ /* @__PURE__ */ jsx(
613
+ TooltipContent,
614
+ {
615
+ side: "right",
616
+ align: "center",
617
+ hidden: state !== "collapsed" || isMobile,
618
+ ...tooltip
619
+ }
620
+ )
621
+ ] });
622
+ }
623
+ function SidebarMenuSub({ className, ...props }) {
624
+ return /* @__PURE__ */ jsx(
625
+ "ul",
626
+ {
627
+ "data-slot": "sidebar-menu-sub",
628
+ "data-sidebar": "menu-sub",
629
+ className: cn(
630
+ "border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
631
+ "group-data-[collapsible=icon]:hidden",
632
+ className
633
+ ),
634
+ ...props
635
+ }
636
+ );
637
+ }
638
+ function SidebarMenuSubItem({
639
+ className,
640
+ ...props
641
+ }) {
642
+ return /* @__PURE__ */ jsx(
643
+ "li",
644
+ {
645
+ "data-slot": "sidebar-menu-sub-item",
646
+ "data-sidebar": "menu-sub-item",
647
+ className: cn("group/menu-sub-item relative", className),
648
+ ...props
649
+ }
650
+ );
651
+ }
652
+ function SidebarMenuSubButton({
653
+ asChild = false,
654
+ size = "md",
655
+ isActive = false,
656
+ className,
657
+ ...props
658
+ }) {
659
+ const Comp = asChild ? Slot : "a";
660
+ return /* @__PURE__ */ jsx(
661
+ Comp,
662
+ {
663
+ "data-slot": "sidebar-menu-sub-button",
664
+ "data-sidebar": "menu-sub-button",
665
+ "data-size": size,
666
+ "data-active": isActive,
667
+ className: cn(
668
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
669
+ "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
670
+ size === "sm" && "text-xs",
671
+ size === "md" && "text-sm",
672
+ "group-data-[collapsible=icon]:hidden",
673
+ className
674
+ ),
675
+ ...props
676
+ }
677
+ );
678
+ }
679
+ function Collapsible({
680
+ ...props
681
+ }) {
682
+ return /* @__PURE__ */ jsx(CollapsiblePrimitive.Root, { "data-slot": "collapsible", ...props });
683
+ }
684
+ function CollapsibleTrigger2({
685
+ ...props
686
+ }) {
687
+ return /* @__PURE__ */ jsx(
688
+ CollapsiblePrimitive.CollapsibleTrigger,
689
+ {
690
+ "data-slot": "collapsible-trigger",
691
+ ...props
692
+ }
693
+ );
694
+ }
695
+ function CollapsibleContent2({
696
+ ...props
697
+ }) {
698
+ return /* @__PURE__ */ jsx(
699
+ CollapsiblePrimitive.CollapsibleContent,
700
+ {
701
+ "data-slot": "collapsible-content",
702
+ ...props
703
+ }
704
+ );
705
+ }
706
+ var ICON_MAP = {
707
+ Home: LucideIcons.Home,
708
+ Users: LucideIcons.Users,
709
+ GalleryVerticalEnd: LucideIcons.GalleryVerticalEnd,
710
+ Settings: LucideIcons.Settings,
711
+ CreditCard: LucideIcons.CreditCard,
712
+ Building2: LucideIcons.Building2,
713
+ Check: LucideIcons.Check,
714
+ ChevronsUpDown: LucideIcons.ChevronsUpDown,
715
+ ChevronRight: LucideIcons.ChevronRight,
716
+ BadgeCheck: LucideIcons.BadgeCheck,
717
+ LogOut: LucideIcons.LogOut
718
+ // Add more icons as needed
719
+ };
720
+ function getIconComponent(icon) {
721
+ if (!icon) {
722
+ return void 0;
723
+ }
724
+ if (typeof icon !== "string") {
725
+ return icon;
726
+ }
727
+ return ICON_MAP[icon];
728
+ }
729
+ function NavMain({ items }) {
730
+ const pathname = usePathname();
731
+ const groups = [];
732
+ let currentGroup = {
733
+ items: []
734
+ };
735
+ items.forEach((item) => {
736
+ const iconComponent = getIconComponent(item.icon);
737
+ if (!item.url) {
738
+ if (currentGroup.items.length > 0 || currentGroup.label) {
739
+ groups.push(currentGroup);
740
+ }
741
+ currentGroup = {
742
+ label: { title: item.title, icon: iconComponent },
743
+ items: []
744
+ };
745
+ } else {
746
+ currentGroup.items.push({
747
+ title: item.title,
748
+ url: item.url,
749
+ icon: iconComponent,
750
+ isActive: item.isActive,
751
+ items: item.items
752
+ });
753
+ }
754
+ });
755
+ if (currentGroup.items.length > 0 || currentGroup.label) {
756
+ groups.push(currentGroup);
757
+ }
758
+ return /* @__PURE__ */ jsx(Fragment, { children: groups.map((group, groupIndex) => /* @__PURE__ */ jsxs(SidebarGroup, { children: [
759
+ group.label && /* @__PURE__ */ jsxs(SidebarGroupLabel, { children: [
760
+ group.label.icon && /* @__PURE__ */ jsx(group.label.icon, { className: "mr-2" }),
761
+ group.label.title
762
+ ] }),
763
+ group.items.length > 0 && /* @__PURE__ */ jsx(SidebarMenu, { children: group.items.map((item) => {
764
+ const isActive = pathname === item.url || item.isActive;
765
+ const hasSubItems = item.items && item.items.length > 0;
766
+ if (hasSubItems) {
767
+ return /* @__PURE__ */ jsx(
768
+ Collapsible,
769
+ {
770
+ asChild: true,
771
+ defaultOpen: isActive,
772
+ className: "group/collapsible",
773
+ children: /* @__PURE__ */ jsxs(SidebarMenuItem, { children: [
774
+ /* @__PURE__ */ jsx(CollapsibleTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs(
775
+ SidebarMenuButton,
776
+ {
777
+ tooltip: item.title,
778
+ isActive,
779
+ children: [
780
+ item.icon && /* @__PURE__ */ jsx(item.icon, {}),
781
+ /* @__PURE__ */ jsx("span", { children: item.title }),
782
+ /* @__PURE__ */ jsx(ChevronRight, { className: "ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" })
783
+ ]
784
+ }
785
+ ) }),
786
+ /* @__PURE__ */ jsx(CollapsibleContent2, { children: /* @__PURE__ */ jsx(SidebarMenuSub, { children: item.items?.map((subItem) => /* @__PURE__ */ jsx(SidebarMenuSubItem, { children: /* @__PURE__ */ jsx(SidebarMenuSubButton, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: subItem.url, children: /* @__PURE__ */ jsx("span", { children: subItem.title }) }) }) }, subItem.title)) }) })
787
+ ] })
788
+ },
789
+ item.title
790
+ );
791
+ }
792
+ return /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsx(
793
+ SidebarMenuButton,
794
+ {
795
+ asChild: true,
796
+ tooltip: item.title,
797
+ isActive,
798
+ children: /* @__PURE__ */ jsxs(Link, { href: item.url, children: [
799
+ item.icon && /* @__PURE__ */ jsx(item.icon, {}),
800
+ /* @__PURE__ */ jsx("span", { children: item.title })
801
+ ] })
802
+ }
803
+ ) }, item.title);
804
+ }) })
805
+ ] }, groupIndex)) });
806
+ }
807
+ function Avatar({
808
+ className,
809
+ ...props
810
+ }) {
811
+ return /* @__PURE__ */ jsx(
812
+ AvatarPrimitive.Root,
813
+ {
814
+ "data-slot": "avatar",
815
+ className: cn(
816
+ "relative flex size-8 shrink-0 overflow-hidden rounded-full",
817
+ className
818
+ ),
819
+ ...props
820
+ }
821
+ );
822
+ }
823
+ function AvatarImage({
824
+ className,
825
+ ...props
826
+ }) {
827
+ return /* @__PURE__ */ jsx(
828
+ AvatarPrimitive.Image,
829
+ {
830
+ "data-slot": "avatar-image",
831
+ className: cn("aspect-square size-full", className),
832
+ ...props
833
+ }
834
+ );
835
+ }
836
+ function AvatarFallback({
837
+ className,
838
+ ...props
839
+ }) {
840
+ return /* @__PURE__ */ jsx(
841
+ AvatarPrimitive.Fallback,
842
+ {
843
+ "data-slot": "avatar-fallback",
844
+ className: cn(
845
+ "bg-muted flex size-full items-center justify-center rounded-full",
846
+ className
847
+ ),
848
+ ...props
849
+ }
850
+ );
851
+ }
852
+ function DropdownMenu({
853
+ ...props
854
+ }) {
855
+ return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
856
+ }
857
+ function DropdownMenuTrigger({
858
+ ...props
859
+ }) {
860
+ return /* @__PURE__ */ jsx(
861
+ DropdownMenuPrimitive.Trigger,
862
+ {
863
+ "data-slot": "dropdown-menu-trigger",
864
+ ...props
865
+ }
866
+ );
867
+ }
868
+ function DropdownMenuContent({
869
+ className,
870
+ sideOffset = 4,
871
+ ...props
872
+ }) {
873
+ return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(
874
+ DropdownMenuPrimitive.Content,
875
+ {
876
+ "data-slot": "dropdown-menu-content",
877
+ sideOffset,
878
+ className: cn(
879
+ "bg-popover text-popover-foreground 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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
880
+ className
881
+ ),
882
+ ...props
883
+ }
884
+ ) });
885
+ }
886
+ function DropdownMenuGroup({
887
+ ...props
888
+ }) {
889
+ return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Group, { "data-slot": "dropdown-menu-group", ...props });
890
+ }
891
+ function DropdownMenuItem({
892
+ className,
893
+ inset,
894
+ variant = "default",
895
+ ...props
896
+ }) {
897
+ return /* @__PURE__ */ jsx(
898
+ DropdownMenuPrimitive.Item,
899
+ {
900
+ "data-slot": "dropdown-menu-item",
901
+ "data-inset": inset,
902
+ "data-variant": variant,
903
+ className: cn(
904
+ "focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
905
+ className
906
+ ),
907
+ ...props
908
+ }
909
+ );
910
+ }
911
+ function DropdownMenuLabel({
912
+ className,
913
+ inset,
914
+ ...props
915
+ }) {
916
+ return /* @__PURE__ */ jsx(
917
+ DropdownMenuPrimitive.Label,
918
+ {
919
+ "data-slot": "dropdown-menu-label",
920
+ "data-inset": inset,
921
+ className: cn(
922
+ "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
923
+ className
924
+ ),
925
+ ...props
926
+ }
927
+ );
928
+ }
929
+ function DropdownMenuSeparator({
930
+ className,
931
+ ...props
932
+ }) {
933
+ return /* @__PURE__ */ jsx(
934
+ DropdownMenuPrimitive.Separator,
935
+ {
936
+ "data-slot": "dropdown-menu-separator",
937
+ className: cn("bg-border -mx-1 my-1 h-px", className),
938
+ ...props
939
+ }
940
+ );
941
+ }
942
+ function getInitials(name, email) {
943
+ if (name) {
944
+ const parts = name.trim().split(/\s+/);
945
+ if (parts.length >= 2) {
946
+ const first = parts[0];
947
+ const last = parts[parts.length - 1];
948
+ if (first && last && first[0] && last[0]) {
949
+ return (first[0] + last[0]).toUpperCase();
950
+ }
951
+ }
952
+ const firstChar2 = name[0];
953
+ if (firstChar2) {
954
+ return firstChar2.toUpperCase();
955
+ }
956
+ }
957
+ const firstChar = email[0];
958
+ if (firstChar) {
959
+ return firstChar.toUpperCase();
960
+ }
961
+ return "?";
962
+ }
963
+ function NavUser({ user }) {
964
+ const sidebar = useSidebar();
965
+ const isMobile = sidebar?.isMobile ?? false;
966
+ const router = useRouter();
967
+ const initials = getInitials(user.name, user.email);
968
+ const displayName = user.name || user.email;
969
+ const handleSignOut = async () => {
970
+ await signOut({ redirect: false });
971
+ router.push("/auth/signin");
972
+ router.refresh();
973
+ };
974
+ return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
975
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
976
+ SidebarMenuButton,
977
+ {
978
+ size: "lg",
979
+ className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
980
+ children: [
981
+ /* @__PURE__ */ jsxs(Avatar, { className: "h-8 w-8 rounded-lg", children: [
982
+ /* @__PURE__ */ jsx(AvatarImage, { src: user.image || void 0, alt: displayName }),
983
+ /* @__PURE__ */ jsx(AvatarFallback, { className: "rounded-lg", children: initials })
984
+ ] }),
985
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
986
+ /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: displayName }),
987
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: user.email })
988
+ ] }),
989
+ /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto size-4" })
990
+ ]
991
+ }
992
+ ) }),
993
+ /* @__PURE__ */ jsxs(
994
+ DropdownMenuContent,
995
+ {
996
+ className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
997
+ side: isMobile ? "bottom" : "right",
998
+ align: "end",
999
+ sideOffset: 4,
1000
+ children: [
1001
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-1 py-1.5 text-left text-sm", children: [
1002
+ /* @__PURE__ */ jsxs(Avatar, { className: "h-8 w-8 rounded-lg", children: [
1003
+ /* @__PURE__ */ jsx(AvatarImage, { src: user.image || void 0, alt: displayName }),
1004
+ /* @__PURE__ */ jsx(AvatarFallback, { className: "rounded-lg", children: initials })
1005
+ ] }),
1006
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1007
+ /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: displayName }),
1008
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: user.email })
1009
+ ] })
1010
+ ] }) }),
1011
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1012
+ /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsxs(DropdownMenuItem, { children: [
1013
+ /* @__PURE__ */ jsx(BadgeCheck, {}),
1014
+ "Account"
1015
+ ] }) }),
1016
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1017
+ /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: handleSignOut, children: [
1018
+ /* @__PURE__ */ jsx(LogOut, {}),
1019
+ "Log out"
1020
+ ] })
1021
+ ]
1022
+ }
1023
+ )
1024
+ ] }) }) });
1025
+ }
1026
+ function TeamSwitcher({
1027
+ teams,
1028
+ organizationId
1029
+ }) {
1030
+ const sidebar = useSidebar();
1031
+ const isMobile = sidebar?.isMobile ?? false;
1032
+ const pathname = usePathname();
1033
+ const router = useRouter();
1034
+ const pathSegments = pathname.split("/");
1035
+ const isAppOrgRoute = pathname.startsWith("/app/") && pathSegments.length > 2 && pathSegments[2] !== "user";
1036
+ const pathOrgId = isAppOrgRoute ? pathSegments[2] : null;
1037
+ const currentOrgId = organizationId || (pathOrgId && teams.some((team) => team.id === pathOrgId) ? pathOrgId : null);
1038
+ const activeTeam = currentOrgId ? teams.find((team) => team.id === currentOrgId) : null;
1039
+ const handleTeamChange = (teamId) => {
1040
+ router.push(`/app/${teamId}/home`);
1041
+ router.refresh();
1042
+ };
1043
+ const teamsWithLogo = teams.map((org) => {
1044
+ const logoIcon = org.logo ? getIconComponent(org.logo) : GalleryVerticalEnd;
1045
+ return {
1046
+ id: org.id,
1047
+ name: org.name,
1048
+ logo: logoIcon || GalleryVerticalEnd,
1049
+ plan: org.plan || "Member"
1050
+ };
1051
+ });
1052
+ if (teamsWithLogo.length === 0) {
1053
+ return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(SidebarMenuButton, { size: "lg", className: "cursor-default", children: [
1054
+ /* @__PURE__ */ jsx("div", { className: "bg-muted flex aspect-square size-8 items-center justify-center rounded-lg", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4 text-muted-foreground" }) }),
1055
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1056
+ /* @__PURE__ */ jsx("span", { className: "truncate font-medium text-muted-foreground", children: "No organizations" }),
1057
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs text-muted-foreground", children: "Join or create one" })
1058
+ ] })
1059
+ ] }) }) });
1060
+ }
1061
+ if (!activeTeam) {
1062
+ return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
1063
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1064
+ SidebarMenuButton,
1065
+ {
1066
+ size: "lg",
1067
+ className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
1068
+ children: [
1069
+ /* @__PURE__ */ jsx("div", { className: "bg-muted flex aspect-square size-8 items-center justify-center rounded-lg", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4 text-muted-foreground" }) }),
1070
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1071
+ /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: "Organizations" }),
1072
+ /* @__PURE__ */ jsxs("span", { className: "truncate text-xs text-muted-foreground", children: [
1073
+ teamsWithLogo.length,
1074
+ " available"
1075
+ ] })
1076
+ ] }),
1077
+ /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto" })
1078
+ ]
1079
+ }
1080
+ ) }),
1081
+ /* @__PURE__ */ jsxs(
1082
+ DropdownMenuContent,
1083
+ {
1084
+ className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
1085
+ align: "start",
1086
+ side: isMobile ? "bottom" : "right",
1087
+ sideOffset: 4,
1088
+ children: [
1089
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { className: "text-muted-foreground text-xs", children: "Select an organization" }),
1090
+ teamsWithLogo.map((team) => /* @__PURE__ */ jsxs(
1091
+ DropdownMenuItem,
1092
+ {
1093
+ onClick: () => handleTeamChange(team.id),
1094
+ className: "gap-2 p-2",
1095
+ children: [
1096
+ /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border", children: /* @__PURE__ */ jsx(team.logo, { className: "size-3.5 shrink-0" }) }),
1097
+ team.name
1098
+ ]
1099
+ },
1100
+ team.id
1101
+ )),
1102
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1103
+ /* @__PURE__ */ jsxs(
1104
+ DropdownMenuItem,
1105
+ {
1106
+ className: "gap-2 p-2",
1107
+ onClick: () => router.push("/app/user/organizations"),
1108
+ children: [
1109
+ /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border bg-transparent", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4" }) }),
1110
+ /* @__PURE__ */ jsx("div", { className: "text-muted-foreground font-medium", children: "Manage organizations" })
1111
+ ]
1112
+ }
1113
+ )
1114
+ ]
1115
+ }
1116
+ )
1117
+ ] }) }) });
1118
+ }
1119
+ const activeTeamWithLogo = teamsWithLogo.find(
1120
+ (team) => team.id === currentOrgId
1121
+ );
1122
+ if (!activeTeamWithLogo) {
1123
+ return null;
1124
+ }
1125
+ return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
1126
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1127
+ SidebarMenuButton,
1128
+ {
1129
+ size: "lg",
1130
+ className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
1131
+ children: [
1132
+ /* @__PURE__ */ jsx("div", { className: "bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg", children: /* @__PURE__ */ jsx(activeTeamWithLogo.logo, { className: "size-4" }) }),
1133
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1134
+ /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: activeTeamWithLogo.name }),
1135
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: activeTeamWithLogo.plan })
1136
+ ] }),
1137
+ /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto" })
1138
+ ]
1139
+ }
1140
+ ) }),
1141
+ /* @__PURE__ */ jsxs(
1142
+ DropdownMenuContent,
1143
+ {
1144
+ className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
1145
+ align: "start",
1146
+ side: isMobile ? "bottom" : "right",
1147
+ sideOffset: 4,
1148
+ children: [
1149
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { className: "text-muted-foreground text-xs", children: "Organizations" }),
1150
+ teamsWithLogo.map((team) => /* @__PURE__ */ jsxs(
1151
+ DropdownMenuItem,
1152
+ {
1153
+ onClick: () => handleTeamChange(team.id),
1154
+ className: "gap-2 p-2",
1155
+ children: [
1156
+ /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border", children: /* @__PURE__ */ jsx(team.logo, { className: "size-3.5 shrink-0" }) }),
1157
+ team.name,
1158
+ team.id === currentOrgId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-4 w-4" })
1159
+ ]
1160
+ },
1161
+ team.id
1162
+ )),
1163
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1164
+ /* @__PURE__ */ jsxs(
1165
+ DropdownMenuItem,
1166
+ {
1167
+ className: "gap-2 p-2",
1168
+ onClick: () => router.push("/app/user/organizations"),
1169
+ children: [
1170
+ /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border bg-transparent", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4" }) }),
1171
+ /* @__PURE__ */ jsx("div", { className: "text-muted-foreground font-medium", children: "Manage organizations" })
1172
+ ]
1173
+ }
1174
+ )
1175
+ ]
1176
+ }
1177
+ )
1178
+ ] }) }) });
1179
+ }
1180
+ function useNavigation({
1181
+ organizationId,
1182
+ apiBaseUrl = "/api",
1183
+ enabled = true
1184
+ } = {}) {
1185
+ const [items, setItems] = useState([]);
1186
+ const [organizations, setOrganizations] = useState([]);
1187
+ const [user, setUser] = useState(null);
1188
+ const [loading, setLoading] = useState(false);
1189
+ const [error, setError] = useState(null);
1190
+ useEffect(() => {
1191
+ if (!enabled || !organizationId) {
1192
+ setItems([]);
1193
+ setOrganizations([]);
1194
+ setUser(null);
1195
+ return;
1196
+ }
1197
+ const fetchNavigation = async () => {
1198
+ setLoading(true);
1199
+ setError(null);
1200
+ try {
1201
+ const response = await fetch(
1202
+ `${apiBaseUrl}/navigation/${organizationId}`,
1203
+ {
1204
+ credentials: "include"
1205
+ // Include cookies for auth
1206
+ }
1207
+ );
1208
+ if (!response.ok) {
1209
+ if (response.status === 401) {
1210
+ throw new Error("Unauthorized");
1211
+ }
1212
+ if (response.status === 404) {
1213
+ throw new Error("Organization not found");
1214
+ }
1215
+ throw new Error(`Failed to fetch navigation: ${response.statusText}`);
1216
+ }
1217
+ const data = await response.json();
1218
+ setItems(data.items || []);
1219
+ setOrganizations(data.organizations || []);
1220
+ setUser(data.user || null);
1221
+ } catch (err) {
1222
+ const error2 = err instanceof Error ? err : new Error("Unknown error");
1223
+ setError(error2);
1224
+ setItems([]);
1225
+ setOrganizations([]);
1226
+ setUser(null);
1227
+ } finally {
1228
+ setLoading(false);
1229
+ }
1230
+ };
1231
+ fetchNavigation();
1232
+ }, [organizationId, apiBaseUrl, enabled]);
1233
+ return { items, organizations, user, loading, error };
1234
+ }
1235
+ function AppSidebar({
1236
+ user: userProp,
1237
+ organizationId,
1238
+ apiBaseUrl,
1239
+ ...props
1240
+ }) {
1241
+ const currentPathname = usePathname();
1242
+ const pathSegments = currentPathname.split("/");
1243
+ const isAppOrgRoute = currentPathname.startsWith("/app/") && pathSegments.length > 2 && pathSegments[2] !== "user";
1244
+ const pathOrgId = isAppOrgRoute ? pathSegments[2] : null;
1245
+ const {
1246
+ items: apiNavigationItems,
1247
+ organizations: apiOrganizations,
1248
+ user: navigationUser,
1249
+ loading: navigationLoading
1250
+ } = useNavigation({
1251
+ organizationId: organizationId || pathOrgId || void 0,
1252
+ apiBaseUrl,
1253
+ enabled: true
1254
+ });
1255
+ const user = navigationUser || userProp;
1256
+ const currentOrgId = organizationId || (pathOrgId && apiOrganizations.some((org) => org.id === pathOrgId) ? pathOrgId : void 0);
1257
+ let navigationItems = apiNavigationItems;
1258
+ if (currentOrgId && navigationItems.length > 0) {
1259
+ navigationItems = navigationItems.map((item) => ({
1260
+ ...item,
1261
+ url: item.url?.replace("{organizationId}", currentOrgId),
1262
+ items: item.items?.map((subItem) => ({
1263
+ ...subItem,
1264
+ url: subItem.url.replace("{organizationId}", currentOrgId)
1265
+ }))
1266
+ }));
1267
+ }
1268
+ const displayNavigationItems = currentOrgId ? navigationItems : [];
1269
+ return /* @__PURE__ */ jsxs(Sidebar, { collapsible: "icon", ...props, children: [
1270
+ /* @__PURE__ */ jsx(SidebarHeader, { children: /* @__PURE__ */ jsx(
1271
+ TeamSwitcher,
1272
+ {
1273
+ teams: apiOrganizations,
1274
+ organizationId: currentOrgId || void 0
1275
+ }
1276
+ ) }),
1277
+ /* @__PURE__ */ jsx(SidebarContent, { children: navigationLoading ? /* @__PURE__ */ jsx("div", { className: "p-4 text-sm text-muted-foreground", children: "Loading..." }) : /* @__PURE__ */ jsx(NavMain, { items: displayNavigationItems }) }),
1278
+ /* @__PURE__ */ jsx(SidebarFooter, { children: user ? /* @__PURE__ */ jsx(NavUser, { user }) : /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(SidebarMenuButton, { size: "lg", disabled: true, children: [
1279
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-8 rounded-lg" }),
1280
+ /* @__PURE__ */ jsxs("div", { className: "grid flex-1 gap-1 text-left text-sm", children: [
1281
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" }),
1282
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-32" })
1283
+ ] })
1284
+ ] }) }) }) }),
1285
+ /* @__PURE__ */ jsx(SidebarRail, {})
1286
+ ] });
1287
+ }
1288
+ function AppLayout({
1289
+ user,
1290
+ organizationId,
1291
+ apiBaseUrl,
1292
+ children
1293
+ }) {
1294
+ return /* @__PURE__ */ jsxs(SidebarProvider, { children: [
1295
+ /* @__PURE__ */ jsx(
1296
+ AppSidebar,
1297
+ {
1298
+ user,
1299
+ organizationId,
1300
+ apiBaseUrl
1301
+ }
1302
+ ),
1303
+ /* @__PURE__ */ jsxs(SidebarInset, { children: [
1304
+ /* @__PURE__ */ jsx(SidebarTrigger, {}),
1305
+ children
1306
+ ] })
1307
+ ] });
1308
+ }
1309
+
1310
+ export { AppLayout, AppSidebar, NavMain, NavUser, TeamSwitcher, getIconComponent, useNavigation };
1311
+ //# sourceMappingURL=components.js.map
1312
+ //# sourceMappingURL=components.js.map