"use client" import { useMemo, useState, type ReactNode } from "react" import { Folder, Tag, type LucideIcon } from "lucide-react" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { useMailAccounts } from "@/lib/api/hooks/use-mail-queries" import { useLabels } from "@/lib/api/hooks/use-folder-label-queries" import { useCreateUnifiedFolder, useUnifiedFolders } from "@/lib/api/hooks/use-unified-folder-queries" import { useImapFoldersForAccount } from "@/lib/api/hooks/use-imap-folders" import { buildImapFolderSettingsTree } from "@/lib/mail-settings/imap-folder-tree" import { SettingsSectionHeader } from "@/components/gmail/settings/settings-section-header" import { SettingsSyncBanner } from "@/components/gmail/settings/settings-sync-banner" import { useAuthReady } from "@/lib/api/use-auth-ready" import { buildFolderTreeFromUnified } from "@/lib/mail-settings/unified-folder-tree" import { useSidebarNav } from "@/lib/sidebar-nav-context" import { isSystemNavLabelId } from "@/lib/sidebar-nav-data" import { NavColorPickerTrigger } from "@/components/gmail/nav/nav-color-picker-trigger" import { DEFAULT_NAV_COLOR } from "@/lib/nav-color" import { flattenLabelRowsForSettings, FolderSettingsTree, ImapFolderSettingsTree, NavLabelSettingsCard, } from "@/components/gmail/settings/nav-item-settings-card" import { MAIL_SETTINGS_TABS_LIST_CLASS } from "@/lib/mail-chrome-classes" function SettingsFormHeading({ icon: Icon, children, }: { icon: LucideIcon children: ReactNode }) { return (
{children}
) } function NavSettingsListPanel({ title, icon: Icon, loading, emptyTitle, emptyDescription, children, }: { title: string icon?: LucideIcon loading: boolean emptyTitle: string emptyDescription?: string children?: ReactNode }) { return (
{Icon ? : null}

{title}

{loading ? (
) : children ? ( children ) : (

{emptyTitle}

{emptyDescription ? (

{emptyDescription}

) : null}
)}
) } export function LabelsFoldersSettingsSection() { return ( <> Libellés Dossiers globaux Dossiers par compte ) } function LabelsPanel() { const { ready, authenticated } = useAuthReady() const nav = useSidebarNav() const { isPending } = useLabels() const [name, setName] = useState("") const [color, setColor] = useState(DEFAULT_NAV_COLOR) const userLabels = useMemo( () => flattenLabelRowsForSettings( nav.labelRows.filter((row) => !isSystemNavLabelId(row.id)) ), [nav.labelRows] ) const listLoading = ready && authenticated && isPending && userLabels.length === 0 return (

Cliquez sur un libellé pour modifier couleur, visibilité et sous-libellés — comme le menu clic droit dans la barre latérale.

Nouveau libellé
setName(e.target.value)} className="flex-1" />
{userLabels.length > 0 ? (
    {userLabels.map((row) => (
  • ))}
) : null}
) } function UnifiedFoldersPanel() { const { ready, authenticated } = useAuthReady() const createFolder = useCreateUnifiedFolder() const { data: folders = [], isFetching, isError, refetch, isPending } = useUnifiedFolders("global") const [name, setName] = useState("") const [color, setColor] = useState(DEFAULT_NAV_COLOR) const [parentId, setParentId] = useState("__root__") const visible = folders.filter((f) => f.scope === "global") const tree = useMemo(() => buildFolderTreeFromUnified(visible), [visible]) const parentOptions = useMemo(() => { const opts: { value: string; label: string }[] = [{ value: "__root__", label: "Racine" }] const walk = (nodes: typeof tree, depth: number) => { for (const n of nodes) { opts.push({ value: n.id, label: `${"\u2003".repeat(depth * 2)}${n.label}`, }) if (n.children?.length) walk(n.children, depth + 1) } } walk(tree, 0) return opts }, [tree]) const listLoading = ready && authenticated && isPending && visible.length === 0 return (

Dossiers Ultimail globaux — organisation virtuelle cross-comptes.

refetch()} />
Nouveau dossier
setName(e.target.value)} className="flex-1" />
{visible.length > 0 ? : null}
) } function ImapAccountFoldersPanel() { const { ready, authenticated } = useAuthReady() const { data: accounts = [] } = useMailAccounts() const [accountId, setAccountId] = useState("") const selectedAccountId = accountId || accounts[0]?.id const { data: folders = [], isFetching, isError, refetch, isPending, } = useImapFoldersForAccount(selectedAccountId) const tree = useMemo( () => selectedAccountId ? buildImapFolderSettingsTree(folders, selectedAccountId) : [], [folders, selectedAccountId] ) const listLoading = ready && authenticated && isPending && folders.length === 0 return (

Dossiers synchronisés depuis vos serveurs mail (IMAP). Masquez ceux que vous ne voulez pas voir dans la barre latérale.

refetch()} />
{tree.length > 0 ? : null}
) }