'use client'
import { useMemo } from 'react'
import Link from 'next/link'
import { ArrowLeft } from 'lucide-react'
import AgentChat, { attachStagedOperations, normalizeStoredMessages } from './AgentChat'
import type { StoredStagedOperation } from '@/types'
import AgentAvatar from './AgentAvatar'
import ContextChip from './ContextChip'
import SandboxAgentPreview from './SandboxAgentPreview'
import { useAgentSheet } from './AgentSheetProvider'
import { useCompanyOptional } from '@/contexts/CompanyContext'
interface Props {
conversationId: string
intentId: string
contextRef: string | null
title: string
rawMessages: { role: string; content: unknown; hidden?: boolean }[]
// Proposals this conversation staged that are still awaiting an answer, so
// the approval card reappears on resume instead of the proposal silently
// waiting out its expiry in Granskning.
stagedOperations?: StoredStagedOperation[]
}
// Full-page conversation view. Wraps AgentChat with a header that shows the
// title (or intent label). AgentChat handles the streaming + input + render.
export default function ChatConversationView({
conversationId,
intentId,
contextRef,
title,
rawMessages,
stagedOperations,
}: Props) {
const initialMessages = useMemo(
() => attachStagedOperations(normalizeStoredMessages(rawMessages), stagedOperations ?? []),
[rawMessages, stagedOperations],
)
const { identity } = useAgentSheet()
const companyCtx = useCompanyOptional()
const isSandbox = companyCtx?.isSandbox ?? false
const agentName = identity.displayName?.trim() || null
return (
<>
{title}
{/* Was printing context_ref raw, so the subtitle read
"invoice:5f3a-9c21-...": a database identifier, shown to an
accountant, under the title of their own conversation. */}