"use client" import { useEffect, useRef, type RefObject } from "react" import { Icon, addCollection } from "@iconify/react" import { icons as mdiIcons } from "@iconify-json/mdi" import { Camera, ChevronDown, ChevronUp, LogOut, Plus, X } from "lucide-react" import { AccountAvatar } from "@/components/gmail/account-avatar" import { Button } from "@/components/ui/button" import { MOCK_USER_ACCOUNTS, STORAGE_USAGE } from "@/lib/accounts/mock-accounts" import type { UserAccount } from "@/lib/accounts/types" import { useAccountStore, useActiveAccount, } from "@/lib/stores/account-store" addCollection(mdiIcons) interface AccountSwitcherDropdownProps { open: boolean onOpenChange: (open: boolean) => void /** Clicks inside this node (e.g. avatar trigger) do not close the panel. */ containerRef: RefObject } function AccountRow({ account, onSelect, }: { account: UserAccount onSelect: () => void }) { return ( ) } export function AccountSwitcherDropdown({ open, onOpenChange, containerRef, }: AccountSwitcherDropdownProps) { const panelRef = useRef(null) const activeAccount = useActiveAccount() const activeAccountId = useAccountStore((s) => s.activeAccountId) const otherAccountsExpanded = useAccountStore((s) => s.otherAccountsExpanded) const setActiveAccount = useAccountStore((s) => s.setActiveAccount) const toggleOtherAccountsExpanded = useAccountStore( (s) => s.toggleOtherAccountsExpanded, ) const signOutAll = useAccountStore((s) => s.signOutAll) const otherAccounts = MOCK_USER_ACCOUNTS.filter((a) => a.id !== activeAccountId) useEffect(() => { if (!open) return function handleClickOutside(event: MouseEvent) { if ( containerRef.current && !containerRef.current.contains(event.target as Node) ) { onOpenChange(false) } } function handleEscape(event: KeyboardEvent) { if (event.key === "Escape") onOpenChange(false) } document.addEventListener("mousedown", handleClickOutside) document.addEventListener("keydown", handleEscape) return () => { document.removeEventListener("mousedown", handleClickOutside) document.removeEventListener("keydown", handleEscape) } }, [open, onOpenChange, containerRef]) if (!open) return null const handleSelectAccount = (id: string) => { setActiveAccount(id) onOpenChange(false) } return (
{/* Current account header */}

{activeAccount.email}

Bonjour {activeAccount.firstName} !

{/* Other accounts + actions */}
{otherAccountsExpanded && (
{otherAccounts.map((account) => ( handleSelectAccount(account.id)} /> ))}
)}
{/* Storage */}
{STORAGE_USAGE.percentUsed} % utilisé(s) sur {STORAGE_USAGE.totalLabel}
{/* Footer links */}
·
) }