@logickernel/bridge 0.6.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.
@@ -1,24 +1,6 @@
1
1
  import { cookies } from 'next/headers';
2
2
  import { decode } from '@auth/core/jwt';
3
3
  import { NextResponse } from 'next/server';
4
- import * as React2 from 'react';
5
- import { useState, useEffect } from 'react';
6
- import { Slot } from '@radix-ui/react-slot';
7
- import { cva } from 'class-variance-authority';
8
- import * as LucideIcons from 'lucide-react';
9
- import { ChevronRight, ChevronsUpDown, BadgeCheck, LogOut, GalleryVerticalEnd, Check, PanelLeftIcon, XIcon } from 'lucide-react';
10
- import { clsx } from 'clsx';
11
- import { twMerge } from 'tailwind-merge';
12
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
13
- import '@radix-ui/react-separator';
14
- import * as SheetPrimitive from '@radix-ui/react-dialog';
15
- import * as TooltipPrimitive from '@radix-ui/react-tooltip';
16
- import { usePathname, useRouter } from 'next/navigation';
17
- import Link from 'next/link';
18
- import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
19
- import { signOut } from 'next-auth/react';
20
- import * as AvatarPrimitive from '@radix-ui/react-avatar';
21
- import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
22
4
 
23
5
  // src/next/session.ts
24
6
  function getBaseCookieName() {
@@ -422,1296 +404,7 @@ var defaultProxyConfig = {
422
404
  "/((?!_next/static|_next/image|favicon.ico|public).*)"
423
405
  ]
424
406
  };
425
- var MOBILE_BREAKPOINT = 768;
426
- function useIsMobile() {
427
- const [isMobile, setIsMobile] = React2.useState(void 0);
428
- React2.useEffect(() => {
429
- const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
430
- const onChange = () => {
431
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
432
- };
433
- mql.addEventListener("change", onChange);
434
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
435
- return () => mql.removeEventListener("change", onChange);
436
- }, []);
437
- return !!isMobile;
438
- }
439
- function cn(...inputs) {
440
- return twMerge(clsx(inputs));
441
- }
442
- var buttonVariants = cva(
443
- "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",
444
- {
445
- variants: {
446
- variant: {
447
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
448
- destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
449
- 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",
450
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
451
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
452
- link: "text-primary underline-offset-4 hover:underline"
453
- },
454
- size: {
455
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
456
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
457
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
458
- icon: "size-9",
459
- "icon-sm": "size-8",
460
- "icon-lg": "size-10"
461
- }
462
- },
463
- defaultVariants: {
464
- variant: "default",
465
- size: "default"
466
- }
467
- }
468
- );
469
- function Button({
470
- className,
471
- variant,
472
- size,
473
- asChild = false,
474
- ...props
475
- }) {
476
- const Comp = asChild ? Slot : "button";
477
- return /* @__PURE__ */ jsx(
478
- Comp,
479
- {
480
- "data-slot": "button",
481
- className: cn(buttonVariants({ variant, size, className })),
482
- ...props
483
- }
484
- );
485
- }
486
- function Sheet({ ...props }) {
487
- return /* @__PURE__ */ jsx(SheetPrimitive.Root, { "data-slot": "sheet", ...props });
488
- }
489
- function SheetPortal({
490
- ...props
491
- }) {
492
- return /* @__PURE__ */ jsx(SheetPrimitive.Portal, { "data-slot": "sheet-portal", ...props });
493
- }
494
- function SheetOverlay({
495
- className,
496
- ...props
497
- }) {
498
- return /* @__PURE__ */ jsx(
499
- SheetPrimitive.Overlay,
500
- {
501
- "data-slot": "sheet-overlay",
502
- className: cn(
503
- "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",
504
- className
505
- ),
506
- ...props
507
- }
508
- );
509
- }
510
- function SheetContent({
511
- className,
512
- children,
513
- side = "right",
514
- ...props
515
- }) {
516
- return /* @__PURE__ */ jsxs(SheetPortal, { children: [
517
- /* @__PURE__ */ jsx(SheetOverlay, {}),
518
- /* @__PURE__ */ jsxs(
519
- SheetPrimitive.Content,
520
- {
521
- "data-slot": "sheet-content",
522
- className: cn(
523
- "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",
524
- 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",
525
- 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",
526
- 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",
527
- 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",
528
- className
529
- ),
530
- ...props,
531
- children: [
532
- children,
533
- /* @__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: [
534
- /* @__PURE__ */ jsx(XIcon, { className: "size-4" }),
535
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
536
- ] })
537
- ]
538
- }
539
- )
540
- ] });
541
- }
542
- function SheetHeader({ className, ...props }) {
543
- return /* @__PURE__ */ jsx(
544
- "div",
545
- {
546
- "data-slot": "sheet-header",
547
- className: cn("flex flex-col gap-1.5 p-4", className),
548
- ...props
549
- }
550
- );
551
- }
552
- function SheetTitle({
553
- className,
554
- ...props
555
- }) {
556
- return /* @__PURE__ */ jsx(
557
- SheetPrimitive.Title,
558
- {
559
- "data-slot": "sheet-title",
560
- className: cn("text-foreground font-semibold", className),
561
- ...props
562
- }
563
- );
564
- }
565
- function SheetDescription({
566
- className,
567
- ...props
568
- }) {
569
- return /* @__PURE__ */ jsx(
570
- SheetPrimitive.Description,
571
- {
572
- "data-slot": "sheet-description",
573
- className: cn("text-muted-foreground text-sm", className),
574
- ...props
575
- }
576
- );
577
- }
578
- function Skeleton({ className, ...props }) {
579
- return /* @__PURE__ */ jsx(
580
- "div",
581
- {
582
- "data-slot": "skeleton",
583
- className: cn("bg-accent animate-pulse rounded-md", className),
584
- ...props
585
- }
586
- );
587
- }
588
- function TooltipProvider({
589
- delayDuration = 0,
590
- ...props
591
- }) {
592
- return /* @__PURE__ */ jsx(
593
- TooltipPrimitive.Provider,
594
- {
595
- "data-slot": "tooltip-provider",
596
- delayDuration,
597
- ...props
598
- }
599
- );
600
- }
601
- function Tooltip({
602
- ...props
603
- }) {
604
- return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
605
- }
606
- function TooltipTrigger({
607
- ...props
608
- }) {
609
- return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
610
- }
611
- function TooltipContent({
612
- className,
613
- sideOffset = 0,
614
- children,
615
- ...props
616
- }) {
617
- return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
618
- TooltipPrimitive.Content,
619
- {
620
- "data-slot": "tooltip-content",
621
- sideOffset,
622
- className: cn(
623
- "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",
624
- className
625
- ),
626
- ...props,
627
- children: [
628
- children,
629
- /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
630
- ]
631
- }
632
- ) });
633
- }
634
- var SIDEBAR_COOKIE_NAME = "sidebar_state";
635
- var SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
636
- var SIDEBAR_WIDTH = "16rem";
637
- var SIDEBAR_WIDTH_MOBILE = "18rem";
638
- var SIDEBAR_WIDTH_ICON = "3rem";
639
- var SIDEBAR_KEYBOARD_SHORTCUT = "b";
640
- var SidebarContext = React2.createContext(null);
641
- function useSidebar() {
642
- const context = React2.useContext(SidebarContext);
643
- if (!context) {
644
- throw new Error("useSidebar must be used within a SidebarProvider.");
645
- }
646
- return context;
647
- }
648
- function SidebarProvider({
649
- defaultOpen = true,
650
- open: openProp,
651
- onOpenChange: setOpenProp,
652
- className,
653
- style,
654
- children,
655
- ...props
656
- }) {
657
- const isMobile = useIsMobile();
658
- const [openMobile, setOpenMobile] = React2.useState(false);
659
- const [_open, _setOpen] = React2.useState(defaultOpen);
660
- const open = openProp ?? _open;
661
- const setOpen = React2.useCallback(
662
- (value) => {
663
- const openState = typeof value === "function" ? value(open) : value;
664
- if (setOpenProp) {
665
- setOpenProp(openState);
666
- } else {
667
- _setOpen(openState);
668
- }
669
- document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
670
- },
671
- [setOpenProp, open]
672
- );
673
- const toggleSidebar = React2.useCallback(() => {
674
- return isMobile ? setOpenMobile((open2) => !open2) : setOpen((open2) => !open2);
675
- }, [isMobile, setOpen, setOpenMobile]);
676
- React2.useEffect(() => {
677
- const handleKeyDown = (event) => {
678
- if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
679
- event.preventDefault();
680
- toggleSidebar();
681
- }
682
- };
683
- window.addEventListener("keydown", handleKeyDown);
684
- return () => window.removeEventListener("keydown", handleKeyDown);
685
- }, [toggleSidebar]);
686
- const state = open ? "expanded" : "collapsed";
687
- const contextValue = React2.useMemo(
688
- () => ({
689
- state,
690
- open,
691
- setOpen,
692
- isMobile,
693
- openMobile,
694
- setOpenMobile,
695
- toggleSidebar
696
- }),
697
- [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
698
- );
699
- return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 0, children: /* @__PURE__ */ jsx(
700
- "div",
701
- {
702
- "data-slot": "sidebar-wrapper",
703
- style: {
704
- "--sidebar-width": SIDEBAR_WIDTH,
705
- "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
706
- ...style
707
- },
708
- className: cn(
709
- "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
710
- className
711
- ),
712
- ...props,
713
- children
714
- }
715
- ) }) });
716
- }
717
- function Sidebar({
718
- side = "left",
719
- variant = "sidebar",
720
- collapsible = "offcanvas",
721
- className,
722
- children,
723
- ...props
724
- }) {
725
- const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
726
- if (collapsible === "none") {
727
- return /* @__PURE__ */ jsx(
728
- "div",
729
- {
730
- "data-slot": "sidebar",
731
- className: cn(
732
- "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
733
- className
734
- ),
735
- ...props,
736
- children
737
- }
738
- );
739
- }
740
- if (isMobile) {
741
- return /* @__PURE__ */ jsx(Sheet, { open: openMobile, onOpenChange: setOpenMobile, ...props, children: /* @__PURE__ */ jsxs(
742
- SheetContent,
743
- {
744
- "data-sidebar": "sidebar",
745
- "data-slot": "sidebar",
746
- "data-mobile": "true",
747
- className: "bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden",
748
- style: {
749
- "--sidebar-width": SIDEBAR_WIDTH_MOBILE
750
- },
751
- side,
752
- children: [
753
- /* @__PURE__ */ jsxs(SheetHeader, { className: "sr-only", children: [
754
- /* @__PURE__ */ jsx(SheetTitle, { children: "Sidebar" }),
755
- /* @__PURE__ */ jsx(SheetDescription, { children: "Displays the mobile sidebar." })
756
- ] }),
757
- /* @__PURE__ */ jsx("div", { className: "flex h-full w-full flex-col", children })
758
- ]
759
- }
760
- ) });
761
- }
762
- return /* @__PURE__ */ jsxs(
763
- "div",
764
- {
765
- className: "group peer text-sidebar-foreground hidden md:block",
766
- "data-state": state,
767
- "data-collapsible": state === "collapsed" ? collapsible : "",
768
- "data-variant": variant,
769
- "data-side": side,
770
- "data-slot": "sidebar",
771
- children: [
772
- /* @__PURE__ */ jsx(
773
- "div",
774
- {
775
- "data-slot": "sidebar-gap",
776
- className: cn(
777
- "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
778
- "group-data-[collapsible=offcanvas]:w-0",
779
- "group-data-[side=right]:rotate-180",
780
- variant === "floating" || variant === "inset" ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]" : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
781
- )
782
- }
783
- ),
784
- /* @__PURE__ */ jsx(
785
- "div",
786
- {
787
- "data-slot": "sidebar-container",
788
- className: cn(
789
- "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
790
- 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)]",
791
- // Adjust the padding for floating and inset variants.
792
- 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",
793
- className
794
- ),
795
- ...props,
796
- children: /* @__PURE__ */ jsx(
797
- "div",
798
- {
799
- "data-sidebar": "sidebar",
800
- "data-slot": "sidebar-inner",
801
- 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",
802
- children
803
- }
804
- )
805
- }
806
- )
807
- ]
808
- }
809
- );
810
- }
811
- function SidebarTrigger({
812
- className,
813
- onClick,
814
- ...props
815
- }) {
816
- const { toggleSidebar } = useSidebar();
817
- return /* @__PURE__ */ jsxs(
818
- Button,
819
- {
820
- "data-sidebar": "trigger",
821
- "data-slot": "sidebar-trigger",
822
- variant: "ghost",
823
- size: "icon",
824
- className: cn("size-7", className),
825
- onClick: (event) => {
826
- onClick?.(event);
827
- toggleSidebar();
828
- },
829
- ...props,
830
- children: [
831
- /* @__PURE__ */ jsx(PanelLeftIcon, {}),
832
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Toggle Sidebar" })
833
- ]
834
- }
835
- );
836
- }
837
- function SidebarRail({ className, ...props }) {
838
- const { toggleSidebar } = useSidebar();
839
- return /* @__PURE__ */ jsx(
840
- "button",
841
- {
842
- "data-sidebar": "rail",
843
- "data-slot": "sidebar-rail",
844
- "aria-label": "Toggle Sidebar",
845
- tabIndex: -1,
846
- onClick: toggleSidebar,
847
- title: "Toggle Sidebar",
848
- className: cn(
849
- "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",
850
- "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
851
- "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
852
- "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
853
- "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
854
- "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
855
- className
856
- ),
857
- ...props
858
- }
859
- );
860
- }
861
- function SidebarInset({ className, ...props }) {
862
- return /* @__PURE__ */ jsx(
863
- "main",
864
- {
865
- "data-slot": "sidebar-inset",
866
- className: cn(
867
- "bg-background relative flex w-full flex-1 flex-col",
868
- "px-4",
869
- "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",
870
- className
871
- ),
872
- ...props
873
- }
874
- );
875
- }
876
- function SidebarHeader({ className, ...props }) {
877
- return /* @__PURE__ */ jsx(
878
- "div",
879
- {
880
- "data-slot": "sidebar-header",
881
- "data-sidebar": "header",
882
- className: cn("flex flex-col gap-2 p-2", className),
883
- ...props
884
- }
885
- );
886
- }
887
- function SidebarFooter({ className, ...props }) {
888
- return /* @__PURE__ */ jsx(
889
- "div",
890
- {
891
- "data-slot": "sidebar-footer",
892
- "data-sidebar": "footer",
893
- className: cn("flex flex-col gap-2 p-2", className),
894
- ...props
895
- }
896
- );
897
- }
898
- function SidebarContent({ className, ...props }) {
899
- return /* @__PURE__ */ jsx(
900
- "div",
901
- {
902
- "data-slot": "sidebar-content",
903
- "data-sidebar": "content",
904
- className: cn(
905
- "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
906
- className
907
- ),
908
- ...props
909
- }
910
- );
911
- }
912
- function SidebarGroup({ className, ...props }) {
913
- return /* @__PURE__ */ jsx(
914
- "div",
915
- {
916
- "data-slot": "sidebar-group",
917
- "data-sidebar": "group",
918
- className: cn("relative flex w-full min-w-0 flex-col p-2", className),
919
- ...props
920
- }
921
- );
922
- }
923
- function SidebarGroupLabel({
924
- className,
925
- asChild = false,
926
- ...props
927
- }) {
928
- const Comp = asChild ? Slot : "div";
929
- return /* @__PURE__ */ jsx(
930
- Comp,
931
- {
932
- "data-slot": "sidebar-group-label",
933
- "data-sidebar": "group-label",
934
- className: cn(
935
- "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",
936
- "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
937
- className
938
- ),
939
- ...props
940
- }
941
- );
942
- }
943
- function SidebarMenu({ className, ...props }) {
944
- return /* @__PURE__ */ jsx(
945
- "ul",
946
- {
947
- "data-slot": "sidebar-menu",
948
- "data-sidebar": "menu",
949
- className: cn("flex w-full min-w-0 flex-col gap-1", className),
950
- ...props
951
- }
952
- );
953
- }
954
- function SidebarMenuItem({ className, ...props }) {
955
- return /* @__PURE__ */ jsx(
956
- "li",
957
- {
958
- "data-slot": "sidebar-menu-item",
959
- "data-sidebar": "menu-item",
960
- className: cn("group/menu-item relative", className),
961
- ...props
962
- }
963
- );
964
- }
965
- var sidebarMenuButtonVariants = cva(
966
- "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",
967
- {
968
- variants: {
969
- variant: {
970
- default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
971
- 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))]"
972
- },
973
- size: {
974
- default: "h-8 text-sm",
975
- sm: "h-7 text-xs",
976
- lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!"
977
- }
978
- },
979
- defaultVariants: {
980
- variant: "default",
981
- size: "default"
982
- }
983
- }
984
- );
985
- function SidebarMenuButton({
986
- asChild = false,
987
- isActive = false,
988
- variant = "default",
989
- size = "default",
990
- tooltip,
991
- className,
992
- ...props
993
- }) {
994
- const Comp = asChild ? Slot : "button";
995
- const { isMobile, state } = useSidebar();
996
- const button = /* @__PURE__ */ jsx(
997
- Comp,
998
- {
999
- "data-slot": "sidebar-menu-button",
1000
- "data-sidebar": "menu-button",
1001
- "data-size": size,
1002
- "data-active": isActive,
1003
- className: cn(sidebarMenuButtonVariants({ variant, size }), className),
1004
- ...props
1005
- }
1006
- );
1007
- if (!tooltip) {
1008
- return button;
1009
- }
1010
- if (typeof tooltip === "string") {
1011
- tooltip = {
1012
- children: tooltip
1013
- };
1014
- }
1015
- return /* @__PURE__ */ jsxs(Tooltip, { children: [
1016
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: button }),
1017
- /* @__PURE__ */ jsx(
1018
- TooltipContent,
1019
- {
1020
- side: "right",
1021
- align: "center",
1022
- hidden: state !== "collapsed" || isMobile,
1023
- ...tooltip
1024
- }
1025
- )
1026
- ] });
1027
- }
1028
- function SidebarMenuSub({ className, ...props }) {
1029
- return /* @__PURE__ */ jsx(
1030
- "ul",
1031
- {
1032
- "data-slot": "sidebar-menu-sub",
1033
- "data-sidebar": "menu-sub",
1034
- className: cn(
1035
- "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",
1036
- "group-data-[collapsible=icon]:hidden",
1037
- className
1038
- ),
1039
- ...props
1040
- }
1041
- );
1042
- }
1043
- function SidebarMenuSubItem({
1044
- className,
1045
- ...props
1046
- }) {
1047
- return /* @__PURE__ */ jsx(
1048
- "li",
1049
- {
1050
- "data-slot": "sidebar-menu-sub-item",
1051
- "data-sidebar": "menu-sub-item",
1052
- className: cn("group/menu-sub-item relative", className),
1053
- ...props
1054
- }
1055
- );
1056
- }
1057
- function SidebarMenuSubButton({
1058
- asChild = false,
1059
- size = "md",
1060
- isActive = false,
1061
- className,
1062
- ...props
1063
- }) {
1064
- const Comp = asChild ? Slot : "a";
1065
- return /* @__PURE__ */ jsx(
1066
- Comp,
1067
- {
1068
- "data-slot": "sidebar-menu-sub-button",
1069
- "data-sidebar": "menu-sub-button",
1070
- "data-size": size,
1071
- "data-active": isActive,
1072
- className: cn(
1073
- "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",
1074
- "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
1075
- size === "sm" && "text-xs",
1076
- size === "md" && "text-sm",
1077
- "group-data-[collapsible=icon]:hidden",
1078
- className
1079
- ),
1080
- ...props
1081
- }
1082
- );
1083
- }
1084
- function Collapsible({
1085
- ...props
1086
- }) {
1087
- return /* @__PURE__ */ jsx(CollapsiblePrimitive.Root, { "data-slot": "collapsible", ...props });
1088
- }
1089
- function CollapsibleTrigger2({
1090
- ...props
1091
- }) {
1092
- return /* @__PURE__ */ jsx(
1093
- CollapsiblePrimitive.CollapsibleTrigger,
1094
- {
1095
- "data-slot": "collapsible-trigger",
1096
- ...props
1097
- }
1098
- );
1099
- }
1100
- function CollapsibleContent2({
1101
- ...props
1102
- }) {
1103
- return /* @__PURE__ */ jsx(
1104
- CollapsiblePrimitive.CollapsibleContent,
1105
- {
1106
- "data-slot": "collapsible-content",
1107
- ...props
1108
- }
1109
- );
1110
- }
1111
- var ICON_MAP = {
1112
- Home: LucideIcons.Home,
1113
- Users: LucideIcons.Users,
1114
- GalleryVerticalEnd: LucideIcons.GalleryVerticalEnd,
1115
- Settings: LucideIcons.Settings,
1116
- CreditCard: LucideIcons.CreditCard,
1117
- Building2: LucideIcons.Building2,
1118
- Check: LucideIcons.Check,
1119
- ChevronsUpDown: LucideIcons.ChevronsUpDown,
1120
- ChevronRight: LucideIcons.ChevronRight,
1121
- BadgeCheck: LucideIcons.BadgeCheck,
1122
- LogOut: LucideIcons.LogOut
1123
- // Add more icons as needed
1124
- };
1125
- function getIconComponent(icon) {
1126
- if (!icon) {
1127
- return void 0;
1128
- }
1129
- if (typeof icon !== "string") {
1130
- return icon;
1131
- }
1132
- return ICON_MAP[icon];
1133
- }
1134
- function NavMain({ items }) {
1135
- const pathname = usePathname();
1136
- const groups = [];
1137
- let currentGroup = {
1138
- items: []
1139
- };
1140
- items.forEach((item) => {
1141
- const iconComponent = getIconComponent(item.icon);
1142
- if (!item.url) {
1143
- if (currentGroup.items.length > 0 || currentGroup.label) {
1144
- groups.push(currentGroup);
1145
- }
1146
- currentGroup = {
1147
- label: { title: item.title, icon: iconComponent },
1148
- items: []
1149
- };
1150
- } else {
1151
- currentGroup.items.push({
1152
- title: item.title,
1153
- url: item.url,
1154
- icon: iconComponent,
1155
- isActive: item.isActive,
1156
- items: item.items
1157
- });
1158
- }
1159
- });
1160
- if (currentGroup.items.length > 0 || currentGroup.label) {
1161
- groups.push(currentGroup);
1162
- }
1163
- return /* @__PURE__ */ jsx(Fragment, { children: groups.map((group, groupIndex) => /* @__PURE__ */ jsxs(SidebarGroup, { children: [
1164
- group.label && /* @__PURE__ */ jsxs(SidebarGroupLabel, { children: [
1165
- group.label.icon && /* @__PURE__ */ jsx(group.label.icon, { className: "mr-2" }),
1166
- group.label.title
1167
- ] }),
1168
- group.items.length > 0 && /* @__PURE__ */ jsx(SidebarMenu, { children: group.items.map((item) => {
1169
- const isActive = pathname === item.url || item.isActive;
1170
- const hasSubItems = item.items && item.items.length > 0;
1171
- if (hasSubItems) {
1172
- return /* @__PURE__ */ jsx(
1173
- Collapsible,
1174
- {
1175
- asChild: true,
1176
- defaultOpen: isActive,
1177
- className: "group/collapsible",
1178
- children: /* @__PURE__ */ jsxs(SidebarMenuItem, { children: [
1179
- /* @__PURE__ */ jsx(CollapsibleTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs(
1180
- SidebarMenuButton,
1181
- {
1182
- tooltip: item.title,
1183
- isActive,
1184
- children: [
1185
- item.icon && /* @__PURE__ */ jsx(item.icon, {}),
1186
- /* @__PURE__ */ jsx("span", { children: item.title }),
1187
- /* @__PURE__ */ jsx(ChevronRight, { className: "ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" })
1188
- ]
1189
- }
1190
- ) }),
1191
- /* @__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)) }) })
1192
- ] })
1193
- },
1194
- item.title
1195
- );
1196
- }
1197
- return /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsx(
1198
- SidebarMenuButton,
1199
- {
1200
- asChild: true,
1201
- tooltip: item.title,
1202
- isActive,
1203
- children: /* @__PURE__ */ jsxs(Link, { href: item.url, children: [
1204
- item.icon && /* @__PURE__ */ jsx(item.icon, {}),
1205
- /* @__PURE__ */ jsx("span", { children: item.title })
1206
- ] })
1207
- }
1208
- ) }, item.title);
1209
- }) })
1210
- ] }, groupIndex)) });
1211
- }
1212
- function Avatar({
1213
- className,
1214
- ...props
1215
- }) {
1216
- return /* @__PURE__ */ jsx(
1217
- AvatarPrimitive.Root,
1218
- {
1219
- "data-slot": "avatar",
1220
- className: cn(
1221
- "relative flex size-8 shrink-0 overflow-hidden rounded-full",
1222
- className
1223
- ),
1224
- ...props
1225
- }
1226
- );
1227
- }
1228
- function AvatarImage({
1229
- className,
1230
- ...props
1231
- }) {
1232
- return /* @__PURE__ */ jsx(
1233
- AvatarPrimitive.Image,
1234
- {
1235
- "data-slot": "avatar-image",
1236
- className: cn("aspect-square size-full", className),
1237
- ...props
1238
- }
1239
- );
1240
- }
1241
- function AvatarFallback({
1242
- className,
1243
- ...props
1244
- }) {
1245
- return /* @__PURE__ */ jsx(
1246
- AvatarPrimitive.Fallback,
1247
- {
1248
- "data-slot": "avatar-fallback",
1249
- className: cn(
1250
- "bg-muted flex size-full items-center justify-center rounded-full",
1251
- className
1252
- ),
1253
- ...props
1254
- }
1255
- );
1256
- }
1257
- function DropdownMenu({
1258
- ...props
1259
- }) {
1260
- return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
1261
- }
1262
- function DropdownMenuTrigger({
1263
- ...props
1264
- }) {
1265
- return /* @__PURE__ */ jsx(
1266
- DropdownMenuPrimitive.Trigger,
1267
- {
1268
- "data-slot": "dropdown-menu-trigger",
1269
- ...props
1270
- }
1271
- );
1272
- }
1273
- function DropdownMenuContent({
1274
- className,
1275
- sideOffset = 4,
1276
- ...props
1277
- }) {
1278
- return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(
1279
- DropdownMenuPrimitive.Content,
1280
- {
1281
- "data-slot": "dropdown-menu-content",
1282
- sideOffset,
1283
- className: cn(
1284
- "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",
1285
- className
1286
- ),
1287
- ...props
1288
- }
1289
- ) });
1290
- }
1291
- function DropdownMenuGroup({
1292
- ...props
1293
- }) {
1294
- return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Group, { "data-slot": "dropdown-menu-group", ...props });
1295
- }
1296
- function DropdownMenuItem({
1297
- className,
1298
- inset,
1299
- variant = "default",
1300
- ...props
1301
- }) {
1302
- return /* @__PURE__ */ jsx(
1303
- DropdownMenuPrimitive.Item,
1304
- {
1305
- "data-slot": "dropdown-menu-item",
1306
- "data-inset": inset,
1307
- "data-variant": variant,
1308
- className: cn(
1309
- "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",
1310
- className
1311
- ),
1312
- ...props
1313
- }
1314
- );
1315
- }
1316
- function DropdownMenuLabel({
1317
- className,
1318
- inset,
1319
- ...props
1320
- }) {
1321
- return /* @__PURE__ */ jsx(
1322
- DropdownMenuPrimitive.Label,
1323
- {
1324
- "data-slot": "dropdown-menu-label",
1325
- "data-inset": inset,
1326
- className: cn(
1327
- "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
1328
- className
1329
- ),
1330
- ...props
1331
- }
1332
- );
1333
- }
1334
- function DropdownMenuSeparator({
1335
- className,
1336
- ...props
1337
- }) {
1338
- return /* @__PURE__ */ jsx(
1339
- DropdownMenuPrimitive.Separator,
1340
- {
1341
- "data-slot": "dropdown-menu-separator",
1342
- className: cn("bg-border -mx-1 my-1 h-px", className),
1343
- ...props
1344
- }
1345
- );
1346
- }
1347
- function getInitials(name, email) {
1348
- if (name) {
1349
- const parts = name.trim().split(/\s+/);
1350
- if (parts.length >= 2) {
1351
- const first = parts[0];
1352
- const last = parts[parts.length - 1];
1353
- if (first && last && first[0] && last[0]) {
1354
- return (first[0] + last[0]).toUpperCase();
1355
- }
1356
- }
1357
- const firstChar2 = name[0];
1358
- if (firstChar2) {
1359
- return firstChar2.toUpperCase();
1360
- }
1361
- }
1362
- const firstChar = email[0];
1363
- if (firstChar) {
1364
- return firstChar.toUpperCase();
1365
- }
1366
- return "?";
1367
- }
1368
- function NavUser({ user }) {
1369
- const sidebar = useSidebar();
1370
- const isMobile = sidebar?.isMobile ?? false;
1371
- const router = useRouter();
1372
- const initials = getInitials(user.name, user.email);
1373
- const displayName = user.name || user.email;
1374
- const handleSignOut = async () => {
1375
- await signOut({ redirect: false });
1376
- router.push("/auth/signin");
1377
- router.refresh();
1378
- };
1379
- return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
1380
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1381
- SidebarMenuButton,
1382
- {
1383
- size: "lg",
1384
- className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
1385
- children: [
1386
- /* @__PURE__ */ jsxs(Avatar, { className: "h-8 w-8 rounded-lg", children: [
1387
- /* @__PURE__ */ jsx(AvatarImage, { src: user.image || void 0, alt: displayName }),
1388
- /* @__PURE__ */ jsx(AvatarFallback, { className: "rounded-lg", children: initials })
1389
- ] }),
1390
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1391
- /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: displayName }),
1392
- /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: user.email })
1393
- ] }),
1394
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto size-4" })
1395
- ]
1396
- }
1397
- ) }),
1398
- /* @__PURE__ */ jsxs(
1399
- DropdownMenuContent,
1400
- {
1401
- className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
1402
- side: isMobile ? "bottom" : "right",
1403
- align: "end",
1404
- sideOffset: 4,
1405
- children: [
1406
- /* @__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: [
1407
- /* @__PURE__ */ jsxs(Avatar, { className: "h-8 w-8 rounded-lg", children: [
1408
- /* @__PURE__ */ jsx(AvatarImage, { src: user.image || void 0, alt: displayName }),
1409
- /* @__PURE__ */ jsx(AvatarFallback, { className: "rounded-lg", children: initials })
1410
- ] }),
1411
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1412
- /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: displayName }),
1413
- /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: user.email })
1414
- ] })
1415
- ] }) }),
1416
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1417
- /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsxs(DropdownMenuItem, { children: [
1418
- /* @__PURE__ */ jsx(BadgeCheck, {}),
1419
- "Account"
1420
- ] }) }),
1421
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1422
- /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: handleSignOut, children: [
1423
- /* @__PURE__ */ jsx(LogOut, {}),
1424
- "Log out"
1425
- ] })
1426
- ]
1427
- }
1428
- )
1429
- ] }) }) });
1430
- }
1431
- function TeamSwitcher({
1432
- teams,
1433
- organizationId
1434
- }) {
1435
- const sidebar = useSidebar();
1436
- const isMobile = sidebar?.isMobile ?? false;
1437
- const pathname = usePathname();
1438
- const router = useRouter();
1439
- const pathSegments = pathname.split("/");
1440
- const isAppOrgRoute = pathname.startsWith("/app/") && pathSegments.length > 2 && pathSegments[2] !== "user";
1441
- const pathOrgId = isAppOrgRoute ? pathSegments[2] : null;
1442
- const currentOrgId = organizationId || (pathOrgId && teams.some((team) => team.id === pathOrgId) ? pathOrgId : null);
1443
- const activeTeam = currentOrgId ? teams.find((team) => team.id === currentOrgId) : null;
1444
- const handleTeamChange = (teamId) => {
1445
- router.push(`/app/${teamId}/home`);
1446
- router.refresh();
1447
- };
1448
- const teamsWithLogo = teams.map((org) => {
1449
- const logoIcon = org.logo ? getIconComponent(org.logo) : GalleryVerticalEnd;
1450
- return {
1451
- id: org.id,
1452
- name: org.name,
1453
- logo: logoIcon || GalleryVerticalEnd,
1454
- plan: org.plan || "Member"
1455
- };
1456
- });
1457
- if (teamsWithLogo.length === 0) {
1458
- return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(SidebarMenuButton, { size: "lg", className: "cursor-default", children: [
1459
- /* @__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" }) }),
1460
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1461
- /* @__PURE__ */ jsx("span", { className: "truncate font-medium text-muted-foreground", children: "No organizations" }),
1462
- /* @__PURE__ */ jsx("span", { className: "truncate text-xs text-muted-foreground", children: "Join or create one" })
1463
- ] })
1464
- ] }) }) });
1465
- }
1466
- if (!activeTeam) {
1467
- return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
1468
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1469
- SidebarMenuButton,
1470
- {
1471
- size: "lg",
1472
- className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
1473
- children: [
1474
- /* @__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" }) }),
1475
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1476
- /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: "Organizations" }),
1477
- /* @__PURE__ */ jsxs("span", { className: "truncate text-xs text-muted-foreground", children: [
1478
- teamsWithLogo.length,
1479
- " available"
1480
- ] })
1481
- ] }),
1482
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto" })
1483
- ]
1484
- }
1485
- ) }),
1486
- /* @__PURE__ */ jsxs(
1487
- DropdownMenuContent,
1488
- {
1489
- className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
1490
- align: "start",
1491
- side: isMobile ? "bottom" : "right",
1492
- sideOffset: 4,
1493
- children: [
1494
- /* @__PURE__ */ jsx(DropdownMenuLabel, { className: "text-muted-foreground text-xs", children: "Select an organization" }),
1495
- teamsWithLogo.map((team) => /* @__PURE__ */ jsxs(
1496
- DropdownMenuItem,
1497
- {
1498
- onClick: () => handleTeamChange(team.id),
1499
- className: "gap-2 p-2",
1500
- children: [
1501
- /* @__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" }) }),
1502
- team.name
1503
- ]
1504
- },
1505
- team.id
1506
- )),
1507
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1508
- /* @__PURE__ */ jsxs(
1509
- DropdownMenuItem,
1510
- {
1511
- className: "gap-2 p-2",
1512
- onClick: () => router.push("/app/user/organizations"),
1513
- children: [
1514
- /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border bg-transparent", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4" }) }),
1515
- /* @__PURE__ */ jsx("div", { className: "text-muted-foreground font-medium", children: "Manage organizations" })
1516
- ]
1517
- }
1518
- )
1519
- ]
1520
- }
1521
- )
1522
- ] }) }) });
1523
- }
1524
- const activeTeamWithLogo = teamsWithLogo.find(
1525
- (team) => team.id === currentOrgId
1526
- );
1527
- if (!activeTeamWithLogo) {
1528
- return null;
1529
- }
1530
- return /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
1531
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1532
- SidebarMenuButton,
1533
- {
1534
- size: "lg",
1535
- className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
1536
- children: [
1537
- /* @__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" }) }),
1538
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 text-left text-sm leading-tight", children: [
1539
- /* @__PURE__ */ jsx("span", { className: "truncate font-medium", children: activeTeamWithLogo.name }),
1540
- /* @__PURE__ */ jsx("span", { className: "truncate text-xs", children: activeTeamWithLogo.plan })
1541
- ] }),
1542
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-auto" })
1543
- ]
1544
- }
1545
- ) }),
1546
- /* @__PURE__ */ jsxs(
1547
- DropdownMenuContent,
1548
- {
1549
- className: "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg",
1550
- align: "start",
1551
- side: isMobile ? "bottom" : "right",
1552
- sideOffset: 4,
1553
- children: [
1554
- /* @__PURE__ */ jsx(DropdownMenuLabel, { className: "text-muted-foreground text-xs", children: "Organizations" }),
1555
- teamsWithLogo.map((team) => /* @__PURE__ */ jsxs(
1556
- DropdownMenuItem,
1557
- {
1558
- onClick: () => handleTeamChange(team.id),
1559
- className: "gap-2 p-2",
1560
- children: [
1561
- /* @__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" }) }),
1562
- team.name,
1563
- team.id === currentOrgId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-4 w-4" })
1564
- ]
1565
- },
1566
- team.id
1567
- )),
1568
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
1569
- /* @__PURE__ */ jsxs(
1570
- DropdownMenuItem,
1571
- {
1572
- className: "gap-2 p-2",
1573
- onClick: () => router.push("/app/user/organizations"),
1574
- children: [
1575
- /* @__PURE__ */ jsx("div", { className: "flex size-6 items-center justify-center rounded-md border bg-transparent", children: /* @__PURE__ */ jsx(GalleryVerticalEnd, { className: "size-4" }) }),
1576
- /* @__PURE__ */ jsx("div", { className: "text-muted-foreground font-medium", children: "Manage organizations" })
1577
- ]
1578
- }
1579
- )
1580
- ]
1581
- }
1582
- )
1583
- ] }) }) });
1584
- }
1585
- function useNavigation({
1586
- organizationId,
1587
- apiBaseUrl = "/api",
1588
- enabled = true
1589
- } = {}) {
1590
- const [items, setItems] = useState([]);
1591
- const [organizations, setOrganizations] = useState([]);
1592
- const [user, setUser] = useState(null);
1593
- const [loading, setLoading] = useState(false);
1594
- const [error, setError] = useState(null);
1595
- useEffect(() => {
1596
- if (!enabled || !organizationId) {
1597
- setItems([]);
1598
- setOrganizations([]);
1599
- setUser(null);
1600
- return;
1601
- }
1602
- const fetchNavigation = async () => {
1603
- setLoading(true);
1604
- setError(null);
1605
- try {
1606
- const response = await fetch(
1607
- `${apiBaseUrl}/navigation/${organizationId}`,
1608
- {
1609
- credentials: "include"
1610
- // Include cookies for auth
1611
- }
1612
- );
1613
- if (!response.ok) {
1614
- if (response.status === 401) {
1615
- throw new Error("Unauthorized");
1616
- }
1617
- if (response.status === 404) {
1618
- throw new Error("Organization not found");
1619
- }
1620
- throw new Error(`Failed to fetch navigation: ${response.statusText}`);
1621
- }
1622
- const data = await response.json();
1623
- setItems(data.items || []);
1624
- setOrganizations(data.organizations || []);
1625
- setUser(data.user || null);
1626
- } catch (err) {
1627
- const error2 = err instanceof Error ? err : new Error("Unknown error");
1628
- setError(error2);
1629
- setItems([]);
1630
- setOrganizations([]);
1631
- setUser(null);
1632
- } finally {
1633
- setLoading(false);
1634
- }
1635
- };
1636
- fetchNavigation();
1637
- }, [organizationId, apiBaseUrl, enabled]);
1638
- return { items, organizations, user, loading, error };
1639
- }
1640
- function AppSidebar({
1641
- user: userProp,
1642
- organizationId,
1643
- apiBaseUrl,
1644
- ...props
1645
- }) {
1646
- const currentPathname = usePathname();
1647
- const pathSegments = currentPathname.split("/");
1648
- const isAppOrgRoute = currentPathname.startsWith("/app/") && pathSegments.length > 2 && pathSegments[2] !== "user";
1649
- const pathOrgId = isAppOrgRoute ? pathSegments[2] : null;
1650
- const {
1651
- items: apiNavigationItems,
1652
- organizations: apiOrganizations,
1653
- user: navigationUser,
1654
- loading: navigationLoading
1655
- } = useNavigation({
1656
- organizationId: organizationId || pathOrgId || void 0,
1657
- apiBaseUrl,
1658
- enabled: true
1659
- });
1660
- const user = navigationUser || userProp;
1661
- const currentOrgId = organizationId || (pathOrgId && apiOrganizations.some((org) => org.id === pathOrgId) ? pathOrgId : void 0);
1662
- let navigationItems = apiNavigationItems;
1663
- if (currentOrgId && navigationItems.length > 0) {
1664
- navigationItems = navigationItems.map((item) => ({
1665
- ...item,
1666
- url: item.url?.replace("{organizationId}", currentOrgId),
1667
- items: item.items?.map((subItem) => ({
1668
- ...subItem,
1669
- url: subItem.url.replace("{organizationId}", currentOrgId)
1670
- }))
1671
- }));
1672
- }
1673
- const displayNavigationItems = currentOrgId ? navigationItems : [];
1674
- return /* @__PURE__ */ jsxs(Sidebar, { collapsible: "icon", ...props, children: [
1675
- /* @__PURE__ */ jsx(SidebarHeader, { children: /* @__PURE__ */ jsx(
1676
- TeamSwitcher,
1677
- {
1678
- teams: apiOrganizations,
1679
- organizationId: currentOrgId || void 0
1680
- }
1681
- ) }),
1682
- /* @__PURE__ */ jsx(SidebarContent, { children: navigationLoading ? /* @__PURE__ */ jsx("div", { className: "p-4 text-sm text-muted-foreground", children: "Loading..." }) : /* @__PURE__ */ jsx(NavMain, { items: displayNavigationItems }) }),
1683
- /* @__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: [
1684
- /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-8 rounded-lg" }),
1685
- /* @__PURE__ */ jsxs("div", { className: "grid flex-1 gap-1 text-left text-sm", children: [
1686
- /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" }),
1687
- /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-32" })
1688
- ] })
1689
- ] }) }) }) }),
1690
- /* @__PURE__ */ jsx(SidebarRail, {})
1691
- ] });
1692
- }
1693
- function AppLayout({
1694
- user,
1695
- organizationId,
1696
- apiBaseUrl,
1697
- children
1698
- }) {
1699
- return /* @__PURE__ */ jsxs(SidebarProvider, { children: [
1700
- /* @__PURE__ */ jsx(
1701
- AppSidebar,
1702
- {
1703
- user,
1704
- organizationId,
1705
- apiBaseUrl
1706
- }
1707
- ),
1708
- /* @__PURE__ */ jsxs(SidebarInset, { children: [
1709
- /* @__PURE__ */ jsx(SidebarTrigger, {}),
1710
- children
1711
- ] })
1712
- ] });
1713
- }
1714
407
 
1715
- export { AppLayout, AppSidebar, NavMain, NavUser, TeamSwitcher, checkPageAuth, createProxyHandler, defaultProxyConfig, getBaseUrl, getIconComponent, getSession, getSessionCookie, getSessionFromRequest, getSessionToken, getUserRoles, hasRequiredRole, isSecureCookie, requireAuth, useNavigation, withAuth };
408
+ export { checkPageAuth, createProxyHandler, defaultProxyConfig, getBaseUrl, getSession, getSessionCookie, getSessionFromRequest, getSessionToken, getUserRoles, hasRequiredRole, isSecureCookie, requireAuth, withAuth };
1716
409
  //# sourceMappingURL=index.js.map
1717
410
  //# sourceMappingURL=index.js.map