'use client' import { useEffect, useState } from 'react' import { X, Expand } from 'lucide-react' import Link from 'next/link' import AgentChat from './AgentChat' import AgentAvatar from './AgentAvatar' import SandboxAgentPreview from './SandboxAgentPreview' import { useAgentSheet } from './AgentSheetProvider' import { useCompanyOptional } from '@/contexts/CompanyContext' // Undimmed non-modal side sheet — sits above the page on a hairline border + // shadow, but the page underneath stays fully interactive. Plan §3b. // // The sheet is a thin wrapper around AgentChat: it owns the title bar, close // button, and "expand to /chat/[id]" affordance. All message rendering and // streaming live in AgentChat so the full-page chat view can reuse them. interface Props { intentId: string intentArgs?: Record contextRef?: string seedUserMessage?: string onClose: () => void } export default function AgentSheet({ intentId, intentArgs, contextRef, seedUserMessage, onClose, }: Props) { const [conversationId, setConversationId] = useState(null) const { identity } = useAgentSheet() const companyCtx = useCompanyOptional() const isSandbox = companyCtx?.isSandbox ?? false const agentName = identity.displayName?.trim() || null const sheetTitle = intentToTitle(intentId, agentName) // Esc closes the sheet. useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) return (

{sheetTitle}

{conversationId && !isSandbox && ( )}
{isSandbox ? ( ) : ( setConversationId(id)} /> )}
) } function intentToTitle(intentId: string, agentName: string | null): string { switch (intentId) { case 'general.help': return agentName ? `Fråga ${agentName}` : 'Fråga din assistent' case 'transaction.categorization': return 'Hjälp med transaktion' case 'invoice.draft': return 'Hjälp med faktura' case 'supplier_invoice.review': return 'Granska leverantörsfaktura' default: return agentName ? `Fråga ${agentName}` : 'Fråga din assistent' } }