'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { useToast } from '@/components/ui/use-toast' import { AlertCircle } from 'lucide-react' import Link from 'next/link' import type { AgentInboxItemView } from '@/app/(dashboard)/agent-inbox/page' import type { AIRequestType } from '@/types' interface RequestCardProps { item: AgentInboxItemView onDismiss: () => void } const REQUEST_LABEL: Record = { reupload_document: 'Oläslig bild', pick_transaction: 'Saknar matchning', specify_vat: 'Momssats', clarify_business_private: 'Privat eller business?', needs_manual: 'Hantera manuellt', } export default function RequestCard({ item, onDismiss }: RequestCardProps) { const req = item.request! const { toast } = useToast() const [busy, setBusy] = useState(false) const handleResolve = async () => { setBusy(true) try { const res = await fetch(`/api/ai/requests/${req.id}/resolve`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({}), }) if (!res.ok) { const body = await res.json() toast({ title: 'Fel', description: body.error, variant: 'destructive' }) return } toast({ title: 'Markerad som hanterad' }) onDismiss() } finally { setBusy(false) } } // Guidance varies by request type. let action: React.ReactNode = null if (req.request_type === 'reupload_document') { action = ( ) } else if (req.request_type === 'pick_transaction' || req.request_type === 'needs_manual') { action = ( ) } return (
{REQUEST_LABEL[req.request_type]} {item.inbox_item.document && ( {item.inbox_item.document.file_name} )}

{req.message}

{action}
) }