import { Button } from '@/components/ui/button'; import { Check, Loader2, ShieldAlert, X } from 'lucide-react'; import { useEffect, useState } from 'react'; import { toast } from 'sonner'; interface RoomAiAuthRequest { auth_uid: string; tool_name: string; created_at: string; } interface RoomAiAuthBannerProps { pendingAuthRequests: RoomAiAuthRequest[]; isAdmin: boolean; onDecide: (authUid: string, approved: boolean) => Promise | void; } function formatTimeLeft(createdAt: string): string { const created = new Date(createdAt).getTime(); const now = Date.now(); const elapsed = Math.floor((now - created) / 1000); const remaining = Math.max(0, 300 - elapsed); const minutes = Math.floor(remaining / 60); const seconds = remaining % 60; return `${minutes}:${seconds.toString().padStart(2, '0')}`; } function AuthRequestItem({ request, isAdmin, onDecide, }: { request: RoomAiAuthRequest; isAdmin: boolean; onDecide: (authUid: string, approved: boolean) => Promise | void; }) { const [timeLeft, setTimeLeft] = useState(() => formatTimeLeft(request.created_at)); const [isPending, setIsPending] = useState(false); useEffect(() => { const interval = setInterval(() => { setTimeLeft(formatTimeLeft(request.created_at)); }, 1000); return () => clearInterval(interval); }, [request.created_at]); const handleDecide = async (approved: boolean) => { setIsPending(true); try { await onDecide(request.auth_uid, approved); toast.success(approved ? 'Function call approved' : 'Function call denied'); } catch { toast.error(approved ? 'Failed to approve' : 'Failed to deny'); } finally { setIsPending(false); } }; return (

AI wants to call{' '} {request.tool_name}

{!isAdmin && (

Waiting for admin approval...

)}
{timeLeft} {isAdmin && (
)}
); } export function RoomAiAuthBanner({ pendingAuthRequests, isAdmin, onDecide, }: RoomAiAuthBannerProps) { if (pendingAuthRequests.length === 0) return null; return (
{pendingAuthRequests.map((request) => ( ))}
); }