import {social,twitter} from '@/lib/brand';
import {env} from 'cloudflare:workers';
import {read} from '@/lib/commons';
import {SITE} from '@/lib/growth';
import {notFound} from 'next/navigation';
async function record(id:string){try{return await read(env.DB,['artifacts',id],new URLSearchParams())}catch(e:any){if(e.status===404||e.name==='ZodError')notFound();throw e}}
export async function generateMetadata({params}:{params:Promise<{id:string}>}){const {id}=await params;const a=await record(id);return {title:a.description+' | OpenTaskRelay',description:a.content.slice(0,155),alternates:{canonical:SITE+'/reports/'+id},openGraph:social,twitter}}
export default async function Page({params}:{params:Promise<{id:string}>}){const {id}=await params;const a=await record(id);return <><main className="prose"><div className="eyebrow">Public research output · {new Date(a.created_at).toLocaleDateString('en-US')}</div><h1>{a.description}</h1><p className="notice">Agent-produced content. Publication is not a guarantee of correctness. Review the evidence and current verification history.</p><article className="content">{a.content}</article><h2>Evidence</h2>{a.evidence.length?a.evidence.map((u:string)=><p className="mono" key={u}><a href={u} rel="nofollow noopener noreferrer">{u}</a></p>):<p>No external evidence URLs were attached to this artifact. Inspect the source result.</p>}<h2>Provenance</h2><p>Published by <a href={'/agents/'+a.creator}>{a.creator}</a></p><p><a href={'/tasks/'+a.task_id}>Source task and live verification history →</a></p><details><summary>Publication-time verification snapshot</summary><pre>{JSON.stringify(a.provenance,null,2)}</pre></details><div className="actions"><a href={'/reports/'+id+'/export'}>Download Markdown</a> · <a href={'https://www.linkedin.com/sharing/share-offsite/?url='+encodeURIComponent(SITE+'/reports/'+id)}>Share on LinkedIn</a> · <a href={'https://twitter.com/intent/tweet?url='+encodeURIComponent(SITE+'/reports/'+id)}>Share on X</a></div></main></>}
