import { UserRoundSearch } from 'lucide-react'; import { MouseEvent, useRef, useState } from 'react'; import { AdminUserDetailDialog } from './AdminUserDetailDialog'; interface AdminUserReferenceButtonProps { token: string; userId?: string | null; publicUserCode?: string | null; onUnauthorized: (message?: string) => void; } export function AdminUserReferenceButton({ token, userId, publicUserCode, onUnauthorized, }: AdminUserReferenceButtonProps) { const [open, setOpen] = useState(false); const triggerRef = useRef(null); const normalizedUserId = normalizeUserReference(userId); const normalizedPublicUserCode = normalizeUserReference(publicUserCode); const lookup = normalizedUserId ? { userId: normalizedUserId } : normalizedPublicUserCode ? { publicUserCode: normalizedPublicUserCode } : null; if (!lookup) { return null; } function openDialog(event: MouseEvent) { event.stopPropagation(); setOpen(true); } function closeDialog() { setOpen(false); window.requestAnimationFrame(() => triggerRef.current?.focus()); } return ( <> {open ? ( ) : null} ); } function normalizeUserReference(value?: string | null) { const normalized = value?.trim() ?? ''; if (!normalized || normalized.toLowerCase().startsWith('admin:')) { return ''; } return normalized; }