"use client" import * as React from 'react' import { Check, ShieldAlert } from 'lucide-react' import { cn } from '@open-mercato/shared/lib/utils' import { useT, useLocale } from '@open-mercato/shared/lib/i18n/context' import type { AgentFactView, GuardCheckView } from './types' import { deriveFactsFromInput, deriveProposedFields, deriveReasoning, resolveDeclaredFacts, type FactSources, type ResolvedFact, } from './proposalFactsData' /** * Real-data panels for a proposal awaiting disposition. `FactsGrid` shows the * case facts behind the proposal — the agent's declared facts (FACTS.json / * defineAgent `facts`) when present, else a generic derivation from the run * input — plus the flat fields of the proposed action itself. `ReasoningList` * shows the persisted rationale(s) and the actual guardrail verdicts. * Sections render nothing when there is no data — no placeholders. */ export function FactsGrid({ facts, sources, className, }: { facts?: AgentFactView[] sources: FactSources className?: string }) { const locale = useLocale() const declared = facts && facts.length > 0 ? resolveDeclaredFacts(facts, sources, locale) : [] const rows = declared.length > 0 ? declared : deriveFactsFromInput(sources.input, locale) if (rows.length === 0) return null return (
{rows.map((fact) => (

{fact.label}

{fact.value}

))}
) } export function ProposedFields({ payload, selectedOptionId = null, className, }: { payload: unknown /** Show the CHOSEN option's fields; falls back to the leader when null. */ selectedOptionId?: string | null className?: string }) { const t = useT() const locale = useLocale() const fields: ResolvedFact[] = deriveProposedFields(payload, locale, selectedOptionId) if (fields.length === 0) return null return (

{t('agent_orchestrator.caseload.inbox.proposed')}

{fields.map((field) => (

{field.label}

{field.value}

))}
) } export function ReasoningList({ rationale, input, guardResults, className, }: { rationale: string | null input: unknown guardResults: GuardCheckView[] className?: string }) { const t = useT() const items = deriveReasoning(rationale, input) const failedGuards = guardResults.filter((check) => check.result !== 'pass') const hasGuards = guardResults.length > 0 if (items.length === 0 && !hasGuards) return null return (

{t('agent_orchestrator.caseload.inbox.reasoning')}

{items.map((item, index) => (
{item.label ? {item.label}: : null} {item.text}
))} {hasGuards ? ( failedGuards.length === 0 ? (
{t('agent_orchestrator.caseload.inbox.guardrails')}
) : ( failedGuards.map((check, index) => (
{t('agent_orchestrator.caseload.inbox.guardrailFlagged', undefined, { kind: check.kind, result: check.result, })}
)) ) ) : null}
) }