"use client" import { useMemo, type ReactNode } from "react" import { Clock, Inbox, Send, FileEdit, ShieldAlert, Trash2, } from "lucide-react" import { DropdownMenuItem, DropdownMenuSeparator, } from "@/components/ui/dropdown-menu" import type { FolderTreeNode } from "@/lib/sidebar-nav-data" export type MailMoveTargets = { recents: MoveTarget[] system: MoveTarget[] folders: MoveTarget[] } export type MoveTarget = { id: string label: string icon?: ReactNode depth: number isFolder?: boolean isRecent?: boolean color?: string } const SYSTEM_DESTINATIONS: MoveTarget[] = [ { id: "inbox", label: "Boîte de réception", icon: , depth: 0 }, { id: "sent", label: "Messages envoyés", icon: , depth: 0 }, { id: "drafts", label: "Brouillons", icon: , depth: 0 }, { id: "spam", label: "Spam", icon: , depth: 0 }, { id: "trash", label: "Corbeille", icon: , depth: 0 }, ] function flattenFolderTree( nodes: FolderTreeNode[], depth: number = 0 ): MoveTarget[] { const out: MoveTarget[] = [] for (const n of nodes) { out.push({ id: n.id, label: n.label, icon: ( ), depth, isFolder: true, color: n.color, }) if (n.children?.length) { out.push(...flattenFolderTree(n.children, depth + 1)) } } return out } export function useMoveTargets({ folderTree, recentMoveTargets, currentFolderId, }: { folderTree: FolderTreeNode[] recentMoveTargets: string[] currentFolderId: string }): { recents: MoveTarget[]; system: MoveTarget[]; folders: MoveTarget[] } { return useMemo(() => { const allSystem = SYSTEM_DESTINATIONS.filter((d) => d.id !== currentFolderId) const allFolders = flattenFolderTree(folderTree).filter( (f) => f.id !== currentFolderId ) const allById = new Map() for (const t of allSystem) allById.set(t.id, t) for (const t of allFolders) allById.set(t.id, t) const recents: MoveTarget[] = [] for (const rid of recentMoveTargets) { if (rid === currentFolderId) continue const target = allById.get(rid) if (target) recents.push({ ...target, isRecent: true, depth: 0 }) } return { recents, system: allSystem, folders: allFolders } }, [folderTree, recentMoveTargets, currentFolderId]) } export function MoveToDropdownItems({ targets, onMoveTo, }: { targets: MailMoveTargets onMoveTo: (targetId: string) => void }) { return ( <> {targets.recents.length > 0 && ( <>
Récents
{targets.recents.map((t) => ( onMoveTo(t.id)}> {t.icon} {t.label} ))} )} {targets.system.map((t) => ( onMoveTo(t.id)}> {t.icon} {t.label} ))} {targets.folders.length > 0 && ( <>
Dossiers
{targets.folders.map((t) => ( onMoveTo(t.id)} style={{ paddingLeft: `${12 + t.depth * 16}px` }} > {t.icon} {t.label} ))} )} ) } export { SYSTEM_DESTINATIONS, flattenFolderTree }