"use client" import { useEffect } from "react" import Link from "next/link" import { useRouter } from "next/navigation" import type { LucideIcon } from "lucide-react" import { ChevronRight, HardDrive, Users } from "lucide-react" import { DRIVE_DROP_TARGET_CLASS } from "@/components/drive/drive-file-context-menu" import { DriveFolderIcon } from "@/lib/drive/drive-file-icon" import { DRIVE_ICON_BTN, DRIVE_SIDEBAR_CARET_SLOT_CLASS, DRIVE_SIDEBAR_ROW_BODY_CLASS, DRIVE_SIDEBAR_ROW_CLASS, } from "@/lib/drive/drive-chrome-classes" import { mailNavRowClass } from "@/lib/mail-chrome-classes" import { cn } from "@/lib/utils" import { useDriveRouteRoot } from "@/lib/drive/drive-route-context" import type { DriveView } from "@/lib/drive/drive-url" import { driveRouteBase, folderPathFromSegments } from "@/lib/drive/drive-url" import { useDriveList, useDriveSharedWithMe } from "@/lib/api/hooks/use-drive-queries" import type { DriveFileInfo } from "@/lib/api/types" import { displayFileName } from "@/lib/drive/display-file-name" import { ancestorFolderPaths, driveFolderHref, isSharedRootSelected, normalizeDriveFolderPath, selectedFolderPath, } from "@/lib/drive/drive-sidebar-tree" import { useIsMobile } from "@/hooks/use-mobile" import { useDriveDropTarget } from "@/lib/hooks/use-drive-drop-target" import { useDriveUIStore } from "@/lib/stores/drive-ui-store" const INDENT_PX = 16 function useFolderChildren(folderPath: string, enabled: boolean, sharedRoot: boolean) { const list = useDriveList(folderPath, 1, "", enabled && !sharedRoot) const shared = useDriveSharedWithMe(1, "", enabled && sharedRoot) const active = sharedRoot ? shared : list const directories = active.data?.files.filter((file) => file.type === "directory") ?? [] return { directories } } function SidebarTreeCaret({ visible, expanded, onToggle, label, }: { visible: boolean expanded: boolean onToggle: () => void label: string }) { if (!visible) { return } return ( ) } function SidebarFolderNode({ folder, depth, view, currentPath, active, routeRoot, }: { folder: DriveFileInfo depth: number view: DriveView currentPath: string active: boolean routeRoot: string }) { const router = useRouter() const isMobile = useIsMobile() const folderPath = normalizeDriveFolderPath(folder.path) const expandedPaths = useDriveUIStore((s) => s.expandedSidebarPaths) const toggleSidebarPath = useDriveUIStore((s) => s.toggleSidebarPath) const ensureSidebarPathsExpanded = useDriveUIStore((s) => s.ensureSidebarPathsExpanded) const isExpanded = expandedPaths.has(folderPath) const isSelected = active && currentPath === folderPath const { directories } = useFolderChildren(folderPath, true, false) const hasChildFolders = directories.length > 0 const href = driveFolderHref(view, folderPath, undefined, routeRoot) const label = displayFileName(folder.name) const { dropProps, canDrop, isOver } = useDriveDropTarget({ folderPath, disabled: isMobile, hasChildFolders, onExpandRequest: () => { if (!isExpanded) ensureSidebarPathsExpanded([folderPath]) }, }) return (