"use client" import { Badge } from "@/components/reui/badge" import { IconTile } from "@/components/reui/icon-tile" import { Flag } from "@/components/flag" import { cn } from "@/lib/utils" import { ALL_SECTIONS, groupBindingsByServer, IFACE_TYPE_LABEL, summarizeUserAccess, type AppUser, type InterfaceType, } from "@/lib/users" import { CableIcon, KeyRoundIcon, LockIcon, NetworkIcon, ShieldIcon } from "lucide-react" const TYPE_VARIANT: Record = { ether: "outline", gre: "info-light", wg: "success-light", ipsec: "info-light", other: "secondary", } const TYPE_ICON: Record = { ether: { icon: CableIcon, className: "text-muted-foreground" }, gre: { icon: NetworkIcon, className: "text-info" }, wg: { icon: ShieldIcon, className: "text-success" }, ipsec: { icon: LockIcon, className: "text-info" }, other: { icon: CableIcon, className: "text-muted-foreground" }, } interface UsersExpandedDetailProps { user: AppUser serversCount: number allSectionsCount?: number } function UsersExpandedDetail({ user, serversCount, allSectionsCount = ALL_SECTIONS.length, }: UsersExpandedDetailProps) { const access = summarizeUserAccess(user, serversCount, allSectionsCount) const groups = groupBindingsByServer(user.bindings) return (
Разделы:{" "} {access.sectionsGranted}/{access.sectionsTotal} Серверы:{" "} {access.serversGranted}/{access.serversTotal} {access.writeKind === "full" ? ( Полный доступ ) : access.writeKind === "none" ? ( Только просмотр ) : ( {access.writeSections.map((section) => ( {section} ))} )}
{groups.length === 0 ? (

Нет привязанных интерфейсов

) : ( groups.map((g) => { const items = g.types.flatMap((tg) => tg.items) return (

{g.serverName}

{g.serverSite}
{items.map((b) => { const meta = TYPE_ICON[b.interfaceType] const Icon = b.interfaceType === "wg" && b.peerPublicKey ? KeyRoundIcon : meta.icon const iconClass = b.interfaceType === "wg" && b.peerPublicKey ? "text-success" : meta.className return (

{b.interfaceType === "wg" && (b.peerName || b.peerPublicKey) ? `${b.peerName || "peer"} · ${b.interfaceName}` : b.interfaceName}

{IFACE_TYPE_LABEL[b.interfaceType]} {b.interfaceType === "wg" && !(b.peerPublicKey ?? "") ? ( весь интерфейс ) : null} {b.comment ? ( {b.comment} ) : null}
) })}
) }) )}
) } export { UsersExpandedDetail, TYPE_VARIANT, type UsersExpandedDetailProps }