"use client" import { useEffect, useRef, type RefObject } from "react" import { Camera, ChevronDown, ChevronUp, LogOut, Plus, X } from "lucide-react" import { AccountAvatar } from "@/components/gmail/account-avatar" import { Button } from "@/components/ui/button" import type { ApiMailAccount } from "@/lib/api/types" import { useMailAccounts } from "@/lib/api/hooks/use-mail-queries" import { useAccountStore, useActiveAccount, useSignOutAll, } from "@/lib/stores/account-store" interface AccountSwitcherDropdownProps { open: boolean onOpenChange: (open: boolean) => void containerRef: RefObject } function AccountRow({ account, onSelect, }: { account: ApiMailAccount 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 setActiveAccountId = useAccountStore((s) => s.setActiveAccountId) const toggleOtherAccountsExpanded = useAccountStore( (s) => s.toggleOtherAccountsExpanded, ) const signOutAll = useSignOutAll() const { data: accounts } = useMailAccounts() const otherAccounts = (accounts ?? []).filter((a) => a.id !== activeAccountId) const firstName = activeAccount?.name.split(" ")[0] ?? "" 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 || !activeAccount) return null const handleSelectAccount = (id: string) => { setActiveAccountId(id) onOpenChange(false) } return (

{activeAccount.email}

Bonjour {firstName} !

{otherAccountsExpanded && (
{otherAccounts.map((account) => ( handleSelectAccount(account.id)} /> ))}
)}
·
) }