import { useEffect, useState } from "react";
import { User, LogOut } from "lucide-react";
import { cn } from "@/lib/utils";
import { Props } from "./props";
import { authList, authRemove, authCreateLink } from "@/lib/auth";
interface Account {
uuid: string;
username: string;
}
function UserComponent({
username,
uuid,
onClick,
}: {
username: string;
uuid: string;
onClick?: () => void;
}) {
return (
);
}
export default function AccountDropdown({
isAccountDropdownOpen,
setIsAccountDropdownOpen,
accountRef,
}: Props) {
const [accounts, setAccounts] = useState([]);
const [active, setActive] = useState(null);
// Load accounts
useEffect(() => {
loadAccounts();
}, []);
async function loadAccounts() {
const accs = await authList();
setAccounts(accs);
if (accs.length && !active) {
setActive(accs[0]); // default
}
}
// Switch account
function switchAccount(acc: Account) {
setActive(acc);
setIsAccountDropdownOpen(false);
}
// Logout (remove account)
async function logout() {
if (!active) return;
await authRemove(active.uuid);
const updated = await authList();
setAccounts(updated);
setActive(updated[0] || null);
}
// Add account (open Microsoft login)
async function addAccount() {
const url = await authCreateLink();
console.log("Opening auth URL:", url);
}
const otherAccounts = accounts.filter((a) => a.uuid !== active?.uuid);
return (
{/* Glow */}
{/* Button */}
{/* Dropdown */}
{/* Current account */}
{active && (
)}
{/* Other accounts */}
{otherAccounts.map((acc) => (
switchAccount(acc)}
/>
))}
{/* Actions */}
);
}