import { useState } from "react"; import { useLocation } from "wouter"; import { useTranslation } from "react-i18next"; import { useAuth } from "@/hooks/use-auth"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; import { PasswordInput } from "@/components/password-input"; import { GuideHelp } from "@/components/guide-help"; import { useToast } from "@/hooks/use-toast"; import { useChangeMyPassword, useGetPasswordRedirect, getGetPasswordRedirectQueryKey } from "@workspace/api-client-react"; import { useQueryClient } from "@tanstack/react-query"; import { Bookmark, LogIn, LogOut, Trash2, KeyRound } from "lucide-react"; import { cn } from "@/lib/utils"; function initials(name?: string | null): string { if (!name) return "?"; const parts = name.trim().split(/\s+/).filter(Boolean); if (parts.length === 0) return "?"; return parts .slice(0, 2) .map((p) => p[0]?.toUpperCase() ?? "") .join(""); } export function UserMenu() { const [location, navigate] = useLocation(); const { t } = useTranslation(); const { user, isLoading, isAuthenticated, isAdmin, tier, hasFeature, login, logout } = useAuth(); const [open, setOpen] = useState(false); const [pwOpen, setPwOpen] = useState(false); const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const { toast } = useToast(); const queryClient = useQueryClient(); const changePassword = useChangeMyPassword(); const { data: passwordRedirect } = useGetPasswordRedirect({ query: { queryKey: getGetPasswordRedirectQueryKey(), enabled: isAuthenticated && !!user && !user.isLocal }, }); const showWatchlist = hasFeature("watchlist"); const showTrash = hasFeature("trash"); const displayName = user?.name || user?.preferredUsername || "User"; if (isLoading) { return (