import React from "react"; import { Button } from "@/components/ui/button.tsx"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table.tsx"; import { UserPlus, Edit, Trash2, Link2, Unlink } from "lucide-react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; import { useConfirmation } from "@/hooks/use-confirmation.ts"; import { deleteUser } from "@/ui/main-axios.ts"; interface User { id: string; username: string; is_admin: boolean; is_oidc: boolean; password_hash?: string; } interface UserManagementTabProps { users: User[]; usersLoading: boolean; allowPasswordLogin: boolean; fetchUsers: () => void; onCreateUser: () => void; onEditUser: (user: User) => void; onLinkOIDCUser: (user: { id: string; username: string }) => void; onUnlinkOIDC: (userId: string, username: string) => void; } export function UserManagementTab({ users, usersLoading, allowPasswordLogin, fetchUsers, onCreateUser, onEditUser, onLinkOIDCUser, onUnlinkOIDC, }: UserManagementTabProps): React.ReactElement { const { t } = useTranslation(); const { confirmWithToast } = useConfirmation(); const getAuthTypeDisplay = (user: User): string => { if (user.is_oidc && user.password_hash) { return t("admin.dualAuth"); } else if (user.is_oidc) { return t("admin.externalOIDC"); } else { return t("admin.localPassword"); } }; const handleDeleteUserQuick = async (username: string) => { confirmWithToast( t("admin.deleteUser", { username }), async () => { try { await deleteUser(username); toast.success(t("admin.userDeletedSuccessfully", { username })); fetchUsers(); } catch { toast.error(t("admin.failedToDeleteUser")); } }, "destructive", ); }; return (