1import{j as e,a as Ve,r as b,u as Je,b as Ue}from"./vendor-query-CVWBAYQN.js";import{D as Kt,p as zt,t as Vt,c as w,s as T,B as $,L as V,a4 as Jt,a5 as Ut,a6 as Wt,h as We,l as Xe,u as Xt,J as Yt,G as Zt,K as er,bL as tr,P as z,H as he}from"./index-DJLejKcN.js";import{R as rr}from"./RequestExpertViewButton-lZzjC-8d.js";import{E as ne}from"./ExportFormatButton-ClLJ1XtD.js";import{B}from"./badge-CtvL8b_T.js";import{T as sr}from"./ToolLoadingState-B6nB0p0M.js";import{S as nr}from"./switch-DK1JlUxA.js";import{h as ar,u as ir,c as or}from"./useOutputs-Cj92hpm8.js";import{O as dr}from"./OutputCompare-Vf0LSRdk.js";import{b as lr,u as cr}from"./useAssertions-CSG4x_JW.js";import{u as mr}from"./useBoardPackApprovals-DIiqd1Q0.js";import{A as Ye}from"./AiLimitsLabel-DpJZMm4B.js";import{C as ur,f as Ze}from"./CitationChip-DUPWmEYe.js";import{N as et}from"./NonRelianceFooter-BU8qapNe.js";import{R as pr}from"./reviewState-Gdnc_cv_.js";import{c as xr,t as hr}from"./reviewSplit-CJOZUJqo.js";import{d as fr}from"./aiLimits-DFiZw-wq.js";import{c as gr}from"./collectSources-C1Kb4aY7.js";import{r as br,h as yr,j as $e}from"./docxExport-M_Pj_yss.js";import{C as ae}from"./citationRenderer-CS25dHAB.js";import{c as tt,e as jr,O as vr}from"./outputReadiness-wR5WsLqB.js";import{R as _r}from"./ReadinessBadge-ClLvUmgc.js";import{a7 as wr,O as rt,S as Nr,ah as kr,L as ye,aN as st,A as Sr,bJ as Cr,a5 as Ar,aC as Fe,X as Er}from"./vendor-icons-BJ-Rh-HN.js";import{e as Rr}from"./htmlExport-oRYz9WBR.js";import{b as Tr}from"./comparableAnalysisDocx-DZdFzYrc.js";import{m as Ir,a as Pr,I as Lr}from"./industryBenchmarks-BmEN5e0d.js";import{a as Dr}from"./maParsers-CLBPs6Bz.js";import{e as Or}from"./pptxExport-lr2isJwO.js";import{R as qe}from"./reportTemplates-BNMwBqOz.js";import{M as Mr}from"./Markdown-CrcTLPo_.js";import{C as nt,a as at,b as it}from"./collapsible-Cx1cM-fT.js";import{e as fe}from"./emit-CbVlanyi.js";import{u as Br,l as Qe}from"./GammaPreferences-BVYIRjRg.js";import{u as $r,c as Fr,p as qr,S as Qr,g as Gr}from"./BrainstormQuadrantViewer-BPMIvmbx.js";import{A as ot,h as Hr,a as dt,b as lt,c as ct,f as mt,d as ut,e as pt,g as xt}from"./alert-dialog-C7f-X0uR.js";import{S as Kr,a as zr,b as Vr,c as Jr}from"./sheet-Cr4H-otA.js";import{G as Ur}from"./GammaOutputActions-9O8nd4hn.js";import{E as je}from"./ErrorState-De3uL_pY.js";import{f as ht,a as ge}from"./vendor-datefns-BmjLTXHn.js";import{A as Ge,b as He}from"./alert-CvCQHsjB.js";import{P as Wr}from"./PortersRadarChart-DOlbLg3S.js";import{r as Xr,e as Yr}from"./porterExport-BHUYEf_W.js";import{i as be}from"./riskOutputGuards-Dq7KcuyX.js";import{u as Zr}from"./useAdminEnabled-CWcvke8Z.js";import{u as es}from"./useReportTokenCeilings-B4BN2XPA.js";import{p as ts,M as rs}from"./parseMandateAlignment-D_QgzUm9.js";import"./vendor-supabase-DhFQUKws.js";import"./vendor-motion-8aOieDHp.js";import"./ExpertRequestDialog-kxWMhL9E.js";import"./textarea-Tq7jsQdy.js";import"./select-BvxMsBnz.js";import"./index-BdQq_4o_.js";import"./index-DuqMQ53p.js";import"./useExpertEngagements-9--t61tM.js";import"./FileTypeIcon-GYuVn306.js";import"./aiErrorTaxonomy-DleRkU-P.js";import"./edgeInvokeFailureBody-AV6SLBoL.js";import"./chunkArray-DMouHHwM.js";import"./AssertionSourceBadge-DIZPNiJZ.js";import"./popover-DlY3f6pv.js";import"./disclaimers-B-eqlQ6j.js";import"./DocumentChip-B-7GDEda.js";import"./coverPage-baR8xeE4.js";import"./exportTypography-AnKeipZl.js";import"./brandPalette-DeMGb5dI.js";import"./waterfallGeometry-x7pIuIcB.js";import"./index-CaxBzNJn.js";import"./jszip.min-BsVKgAUs.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./financialEngine-e4BxNIom.js";import"./dcfEngine-eBtmB-P1.js";import"./reportCategories-Cl_ta-7o.js";import"./accentTone-B1MD0lV9.js";import"./index-CqPtnVtP.js";import"./index-CfMy7Hxv.js";import"./config-CMpTVYH3.js";import"./useAIInvoke-LNVUoQSQ.js";import"./useAIQuota-BYj0JUQV.js";import"./useStakeholders-COUlRvy5.js";import"./stakeholderTypes-BI_BrWzy.js";import"./scroll-area-D3g7iJZ6.js";import"./useReviewRequests-CngN8onH.js";import"./useSendFeedbackRequest-BM-gcM_L.js";import"./ChartDefaults-DqEEHsoY.js";import"./generateCategoricalChart-BIdW9stL.js";import"./band-CquvqAHh.js";import"./init-Dmth1JHB.js";import"./ordinal-DILIJJjt.js";import"./linear-BjTN5enB.js";import"./string-dheu8l3x.js";import"./value-C0akyTYb.js";import"./defaultLocale-C4B-KCzX.js";import"./time-BQOLM0jw.js";import"./ScatterChart-gFZ3oc2R.js";import"./Scatter-DMANhe91.js";import"./YAxis-4qnzHttu.js";import"./CartesianGrid-dhTQ_vRt.js";import"./AICta-CW9IvAIV.js";import"./AiSparkIcon-CI_4QK7B.js";import"./aiPersonas-DRZibXAQ.js";import"./dropdown-menu-O6oNpBQ3.js";import"./index-CYh4Bhy3.js";import"./GroundingChip-DF0xicmp.js";import"./tabs-qNXxdrrk.js";import"./subnavTabs-CaHuUDS9.js";import"./RadarChart-BZVMuwaD.js";import"./PolarAngleAxis-DNuMVhB5.js";function ss({open:r,onOpenChange:a,outputs:o,outputType:n,assertions:i,campaignId:d}){return e.jsx(Kt,{open:r,onOpenChange:a,children:e.jsxs(zt,{className:"max-h-[90vh] max-w-5xl overflow-y-auto p-2 sm:p-3",children:[e.jsx(Vt,{className:"sr-only",children:"Compare report versions"}),e.jsx(dr,{outputs:o,outputType:n,assertions:i,campaignId:d,onClose:()=>a(!1)})]})})}function ns({label:r,className:a}){return r?e.jsx("span",{className:w("print:hidden inline-flex max-w-[28rem] items-center rounded-full border border-[var(--gold-dark)]/40 bg-accent px-2 py-0.5 text-step-caption font-medium leading-snug text-[var(--navy-deep)] dark:text-foreground",a),children:r}):null}function as(r,a){return!r||!a?!1:new Date(a).getTime()>
1new Date(r).getTime()}function is(r){return r.length===0?null:r.reduce((a,o)=>o.approved_at>a?o.approved_at:a,r[0].approved_at)}const os="border-amber-500/50 bg-amber-500/10 text-amber-900 dark:text-amber-100";function ds(r){return`[${r.tier}#${r.hex}]`}function ls({sources:r,limits:a,assertions:o,campaignId:n}){return e.jsxs("section",{id:"report-sources","aria-labelledby":"report-sources-heading",className:"mt-10 max-w-[70ch] print:text-black",children:[e.jsx("h2",{id:"report-sources-heading",className:"font-display text-lg font-semibold text-foreground print:text-black",children:"Sources and limits"}),e.jsx(Ye,{variant:"block",limits:a,className:"mt-3"}),r.hasAny?e.jsx("ol",{className:"mt-4 list-none space-y-0 p-0",children:r.entries.map((i,d)=>{var u;return e.jsxs("li",{className:"break-inside-avoid border-t border-border py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"font-data text-xs text-muted-foreground",children:[d+1,"."]}),i.kind==="fact"?e.jsx(ur,{assertionId:i.hex,assertions:o,campaignId:n}):e.jsx("span",{className:"font-data text-xs text-foreground",children:ds(i)})]}),i.kind==="fact"&&i.claim?e.jsx("p",{className:"mt-1 line-clamp-3 text-sm text-foreground",children:i.claim}):null,i.kind==="fact"&&(i.documentName||i.pageLabel)?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:[i.documentName,i.pageLabel].filter(Boolean).join(", ")}):null,i.kind==="fact"?e.jsx("p",{className:"mt-1 text-xs text-foreground",children:pr[i.review]}):null,i.kind==="document"?e.jsx("p",{className:"mt-1 text-xs text-foreground",children:"Raw document, unverified."}):null,i.kind==="decision"?e.jsx("p",{className:"mt-1 text-sm text-foreground",children:((u=i.decision)==null?void 0:u.title)??"Decision"}):null]},`${i.tier}-${i.hex}`)})}):e.jsx("p",{className:"mt-4 text-sm text-foreground",children:"No confirmed source cited. Treat this report as a draft."}),e.jsx(et,{campaignId:n,limits:a})]})}function cs({title:r,companyName:a,reportType:o,versionLabel:n,dateLabel:i,freshnessLine:d}){return e.jsxs("header",{className:"mb-6 print:text-black",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-foreground print:text-black",children:r}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground print:text-black",children:[e.jsx("span",{className:"font-medium text-foreground print:text-black",children:a})," · ",o,n?` · ${n}`:""," · ",i,d?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"print:hidden text-foreground",children:d})]}):null]})]})}function ms({readinessLabel:r,citationCount:a,densityPerKw:o,sectionCount:n,skillsCount:i,stage:d}){const u=[r];if((a??0)>0){const v=o!=null&&o>0?` (${o.toFixed(1)}/1k words)`:"";u.push(`Citations: ${a}${v}`)}return n>0&&u.push(`Sections: ${n}`),i>0&&u.push(`Shaped by: ${i} skill${i===1?"":"s"}`),u.push(d==="double"?"Double pass":"Single pass"),e.jsxs("div",{className:"mb-6 flex flex-wrap items-center gap-x-2 gap-y-1 rounded-md border border-border bg-muted/20 px-4 py-2 text-xs text-muted-foreground print:hidden",children:[e.jsx(wr,{className:"h-3.5 w-3.5 shrink-0 text-[var(--gold-dark)] dark:text-[var(--gold-dark)]","aria-hidden":!0}),e.jsx("span",{className:"font-medium uppercase tracking-wide text-step-caption text-foreground/70",children:"Quality"}),e.jsx("span",{children:u.join(" · ")})]})}function us({className:r}){return e.jsxs("p",{className:w("flex flex-wrap items-center gap-x-2 gap-y-1 text-step-caption text-muted-foreground print:hidden",r),children:[e.jsx("span",{className:"citation-chip cursor-default","aria-hidden":!0,children:"A#"}),e.jsx("span",{children:"reviewed by a person"}),e.jsx("span",{"aria-hidden":!0,className:"text-border",children:"·"}),e.jsx("span",{className:"citation-chip cursor-default","data-review":"auto","aria-hidden":!0,children:"A#"}),e.jsx("span",{children:"auto-confirmed from a high-confidence extraction, not yet read"})]})}function ps(r){return Ve({queryKey:["output-backreferences",r],queryFn:async()=>{if(!r)return[];const{data:a,error:o}=await T.rpc("output_backreferences",{p_output_id:r});if(o)throw o;return a??[]},enabled:!!r,staleTime:6e4})}const xs={draft:"Draft",proposed:"Proposed",approved:"Approved",reversed:"Reversed"};function hs({campaignId:r,outputId:a}){const{data:o=[],isLoading:n,isError:i,refetch:d}=ps(a),[u,v]=b.useState(!0),x=o.length,m=b.useMemo(()=>n?"â¦":x===0?"not yet":`${x} decision${x===1?"":"s"}`,[x,n]);return i?e.jsx(je,{compact:!0,noun:"decision links",onRetry:()=>void d()}):!n&&x===0?null:e.jsxs(nt,{open:u,onOpenChange:v,className:"rounded-lg border border-chart-gold/25 bg-accent print:hidden",children:[e.jsx(at,{asChild:!0,children:e.jsxs($,{type:"button",variant:"ghost",className:"flex h-auto w-full items-center justify-between gap-2 px-3 py-2 text-left hover:bg-accent",children:[e.jsxs("span",{className:"text-step-caption font-semibold uppercase tracking-wide text-muted-foreground",children:["Referenced by / ",m]}
1),e.jsx(rt,{className:w("h-4 w-4 shrink-0 text-muted-foreground transition-transform",u&&"rotate-180")})]})}),e.jsx(it,{className:"border-t border-chart-gold/15 px-3 pb-3 pt-1",children:n?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loadingâ¦"}):e.jsx("ul",{className:"space-y-2",children:o.map(h=>e.jsxs("li",{className:"rounded-md border border-border bg-background/80 p-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(V,{to:`/campaigns/${r}?tab=overview&overviewView=decisions#decision-${h.decision_id}`,className:"text-sm font-medium text-primary underline-offset-4 hover:underline",children:h.decision_title}),e.jsx(B,{variant:"secondary",className:"text-step-caption",children:xs[h.decision_status]??h.decision_status})]}),e.jsxs("p",{className:"mt-1 text-step-caption text-muted-foreground",children:["Decided ",ht(new Date(h.decided_at),{addSuffix:!0})]})]},h.decision_id))})})]})}function fs(r){return Ve({queryKey:["ai-ledger-entry",r],enabled:!!r,queryFn:async()=>{if(!r)return null;const{data:a,error:o}=await T.rpc("member_ai_run_summary",{p_model_run_id:r});if(o)throw o;const n=a==null?void 0:a[0];return n?{created_at:n.created_at,pass_type:n.pass_type,cost_usd:Number(n.cost_usd)}:null}})}function gs({sectionId:r,ledgerEntryId:a,className:o}){const{data:n,isLoading:i}=fs(a),{isAdmin:d}=Zr();if(i||!n)return null;const u=n.pass_type==="double"?"Double Pass":"Single Pass",v=ht(new Date(n.created_at),{addSuffix:!0}),x=d&&n.cost_usd?`$${Number(n.cost_usd).toFixed(4)}`:null;return e.jsx("div",{className:w("flex items-center gap-2 text-step-caption text-muted-foreground print:hidden",o),children:e.jsxs(Jt,{children:[e.jsx(Ut,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-default",children:[e.jsx(Nr,{className:"h-3 w-3 text-oposgold"}),e.jsx("span",{className:"font-medium",children:u}),e.jsx("span",{className:"opacity-50",children:"·"}),e.jsx(kr,{className:"h-3 w-3 opacity-70"}),e.jsx("span",{children:v})]})}),e.jsx(Wt,{side:"top",align:"start",className:"text-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Section:"})," ",r]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Generated:"})," ",new Date(n.created_at).toLocaleString()]}),x&&e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Est. Cost:"})," ",x]})]})})]})})}function bs(){const{user:r}=We(),a=Je(),{toast:o}=Xe();return Ue({mutationFn:async n=>{var v;if(!r)throw new Error("Not authenticated");const{data:i}=await T.auth.getSession();if(!((v=i.session)!=null&&v.access_token))throw new Error("No session token");const d=await fetch("https://zkcphkiykfjokeqcofpy.supabase.co/functions/v1/generate-output",{method:"POST",headers:{Authorization:`Bearer ${i.session.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({campaignId:n.campaignId,outputType:n.outputType,section_id:n.sectionId,stage:n.stage,length:n.length,tone:n.tone})});if(!d.ok){const x=await d.json().catch(()=>null),m=x==null?void 0:x.error,h=m&&typeof m=="object"&&typeof m.message=="string"&&m.message||m&&typeof m=="object"&&typeof m.code=="string"&&m.code||typeof m=="string"&&m||typeof(x==null?void 0:x.message)=="string"&&x.message||`Generation failed (HTTP ${d.status})`;throw new Error(h)}const u=await d.json();return{section:u.section,modelRunId:u.model_run_id,payload:n}},onMutate:async n=>(await a.cancelQueries({queryKey:["output",n.outputId]}),{previousOutput:a.getQueryData(["output",n.outputId])}),onSuccess:async(n,i,d)=>{const{section:u,modelRunId:v,payload:x}=n,{previousOutput:m}=d;if(!m)return;const h=JSON.parse(JSON.stringify(m.content_json));if(h&&Array.isArray(h.sections)){const _=h.sections.findIndex(I=>I.heading===x.sectionId);_>=0&&(h.sections[_]=u)}const p=JSON.parse(JSON.stringify(m.metadata||{}));p.section_runs||(p.section_runs={}),p.section_runs[x.sectionId]=v,p.section_fresh_at||(p.section_fresh_at={}),p.section_fresh_at[x.sectionId]=new Date().toISOString(),a.setQueryData(["output",x.outputId],{...m,content_json:h,metadata:p});const{error:N}=await T.from("outputs").update({content_json:h,metadata:p}).eq("id",x.outputId);if(N){a.setQueryData(["output",x.outputId],m),o({title:"Failed to save",description:N.message,variant:"destructive"});return}a.invalidateQueries({queryKey:["outputs"]}),a.invalidateQueries({queryKey:["all-outputs"]}),o({title:"Section regenerated",description:"The section has been updated with new AI content.",action:e.jsx("button",{onClick:async()=>{a.setQueryData(["output",x.outputId],m),await T.from("outputs").update({content_json:m.content_json,metadata:m.metadata}).eq("id",x.outputId),o({title:"Regeneration undone"})},className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",children:"Undo"}),duration:1e4})},onError:(n,i,d)=>{d!=null&&d.previousOutput&&a.setQueryData(["output",i.outputId],d.previousOutput),o({title:"Regeneration failed",description:n instanceof Error?n.message:"Unknown error",variant:"destructive"})}})}const ys=[{value:"balanced",label:"Balanced",hint:"Keep the current voice and length"},{value:"conservative",label:"More conservative",hint:"Measured, analytical framing"},{value:"direct",label:"More direct",hint:"Crisp, board-executive framing"},{value:"shorter",label:"Shorter",hint:"Tighten to a brief length"}];function js(r){switch(r){case"conservative":return{tone:"analytical"};case"direct":return{tone:"board_executive"};case"shorter":return{length:"brief"};default:return{}}}function vs({campaignId:r,outputId:a,outputType:o,sectionId:n,stage:i}){const d=bs(),u=es(!0),[v,x]=b.useState("balanced"),m=b.useMemo(()=>
1{if(!u.data)return null;const p=u.data.find(_=>_.output_type===o)||u.data.find(_=>_.output_type==="__default__");if(!p)return null;let N=p.token_ceiling*15/1e6/5;return i==="double"&&(N*=5),N},[o,u.data,i]),h=()=>{d.mutate({campaignId:r,outputId:a,outputType:o,sectionId:n,stage:i,...js(v)})};return e.jsxs(ot,{children:[e.jsx(Hr,{asChild:!0,children:e.jsxs($,{variant:"ghost",size:"sm",className:"h-7 text-xs text-muted-foreground hover:text-foreground print:hidden",disabled:d.isPending,children:[d.isPending?e.jsx(ye,{className:"mr-1.5 h-3 w-3 animate-spin"}):e.jsx(st,{className:"mr-1.5 h-3 w-3"}),"Regenerate"]})}),e.jsxs(dt,{children:[e.jsxs(lt,{children:[e.jsx(ct,{children:"Regenerate section?"}),e.jsxs(mt,{children:["This will use AI (",i==="double"?"Double Pass":"Single Pass",') to rewrite the "',n,'" section.',m!==null&&e.jsxs("span",{className:"mt-2 block font-medium text-foreground",children:["Regenerating this section will cost ~$",m.toFixed(2)," (",i==="double"?"Double Pass":"Single Pass",")."]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Angle"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ys.map(p=>e.jsxs("button",{type:"button",onClick:()=>
1x(p.value),className:w("rounded-lg border px-3 py-2 text-left text-xs transition-colors",v===p.value?"border-[var(--gold-dark)] bg-accent":"border-border hover:bg-muted/60"),"aria-pressed":v===p.value,children:[e.jsx("span",{className:"block font-semibold text-foreground",children:p.label}),e.jsx("span",{className:"block text-step-caption text-muted-foreground",children:p.hint})]},p.value))})]}),e.jsxs(ut,{children:[e.jsx(pt,{children:"Cancel"}),e.jsx(xt,{onClick:h,children:"Regenerate"})]})]})]})}function ve(r){if(!r)return null;const a=Date.parse(r);return Number.isFinite(a)?a:null}function _s(r,a){const o=r.status??"";if(o==="rejected")return"rejected";if(o==="superseded")return"superseded";if(o==="pending")return"backInReview";if(o==="edited"&&a!=null){const n=ve(r.updated_at);if(n!=null&&n>a)return"changed"}return"current"}function Y(r,a,o){return r===1?`1 ${a}`:`${r} ${o}`}function ws(r){const a=[];return r.rejected>0&&a.push(Y(r.rejected,"cited fact rejected","cited facts rejected")),r.superseded>0&&a.push(Y(r.superseded,"cited fact superseded","cited facts superseded")),r.changed>0&&(a.length===0?a.push(Y(r.changed,"cited fact changed since this was generated","cited facts changed since this was generated")):a.push(r.changed===1?"1 changed":`${r.changed} changed`)),r.backInReview>0&&(a.length===0?a.push(Y(r.backInReview,"cited fact is back in review","cited facts are back in review")):a.push(r.backInReview===1?"1 back in review":`${r.backInReview} back in review`)),r.unresolved>0&&a.push(Y(r.unresolved,"citation could not be matched","citations could not be matched")),a.join(" · ")}function Ns(r,a,o,n){const i=tt(r),d=ve(n)??ve(o),u={unresolved:0,rejected:0,superseded:0,backInReview:0,changed:0,current:0,cited:i.length};for(const m of i){const h=Ze(a,m);if(!h){u.unresolved+=1;continue}u[_s(h,d)]+=1}const x=u.rejected+u.superseded+u.backInReview+u.changed>0;return{...u,hasDrift:x,showBadge:x||u.unresolved>0,label:ws(u)}}function ks(r,a){if(!r||typeof r!="object"||Array.isArray(r))return null;const o=r.section_fresh_at;if(!o||typeof o!="object"||Array.isArray(o))return null;const n=o[a];return typeof n=="string"&&n.trim()?n:null}function Ss(r,a,o){if(r.length===0)return null;const n=r.filter(i=>i.hasDrift).length;return n===0?`Fresh as of ${o(a)}`:n===1?"1 section cites facts that moved.":`${n} sections cite facts that moved.`}function Cs(r){return r==null||Number.isNaN(r)?"":r>=16?"text-red-700 dark:text-red-300 font-semibold tabular-nums":r>=10?"text-orange-700 dark:text-orange-300 font-semibold tabular-nums":r>=5?"text-amber-700 dark:text-amber-300 font-semibold tabular-nums":"text-emerald-700 dark:text-emerald-300 font-semibold tabular-nums"}function As(r,a){if(!r||typeof r!="object"||Array.isArray(r))return null;const o=r,n=o.section_runs;if(n&&typeof n=="object"&&!Array.isArray(n)){const d=n[a];if(typeof d=="string"||typeof d=="number")return String(d)}const i=o.model_run_id;return typeof i=="string"||typeof i=="number"?String(i):null}function Ke(r){return!r||typeof r!="object"||Array.isArray(r)?"single":r.generation_stage==="double"?"double":"single"}function ze(r){if(!r||typeof r!="object"||Array.isArray(r))return[];const a=r.skills_injected;return Array.isArray(a)?a.filter(o=>typeof o=="string"&&o.trim().length>0):[]}function Es({body:r,assertions:a,campaignId:o}){const n=r.split(/\n\n+/).filter(i=>i.trim().length>0);return e.jsx("div",{className:"space-y-4 text-[15px] leading-relaxed text-foreground print:text-black",children:n.map((i,d)=>e.jsx(Rs,{block:i,assertions:a,campaignId:o},d))})}function Rs({block:r,assertions:a,campaignId:o}){const i=r.split(/\n/).map(m=>m.trimEnd()),d=i.filter(m=>m.trim().length>0);if(d.length===0)return null;if(d.length>=1&&d.every(m=>/^[-*â¢]\s+/.test(m.trim())||/^[-*]\s/.test(m.trim())))return e.jsx("ul",{className:"list-disc space-y-1 pl-5 marker:text-oposgold dark:marker:text-oposgold",children:d.map((m,h)=>{const p=m.replace(/^[-*â¢]\s+/,"").trim();return e.jsx("li",{className:"pl-1",children:e.jsx(ae,{text:p,assertions:a,campaignId:o,layout:"inline"})},h)})});if(d[0].includes("|")&&d.length>=2){const m=p=>/^\|[\s\-:|]+\|$/.test(p.trim())||/^[\s\-:|]+$/.test(p.trim()),h=d.filter(p=>!m(p)).map(p=>p.split("|").map(N=>N.trim()).filter((N,_,I)=>!(_===0&&N==="")&&!(_===I.length-1&&N===""))).filter(p=>p.length>0);if(h.length>=2&&h.every(p=>
1p.length===h[0].length)){const p=h[0],N=h.slice(1);return e.jsx("div",{className:"vt-paper overflow-x-auto rounded-md border border-border print:border print:text-black",children:e.jsxs("table",{className:"w-full min-w-[360px] border-collapse text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b bg-[var(--navy-deep)] text-left text-white",children:p.map((_,I)=>e.jsx("th",{className:"p-2 font-medium",children:e.jsx(ae,{text:_,assertions:a,campaignId:o,layout:"inline"})},I))})}),e.jsx("tbody",{children:N.map((_,I)=>e.jsx("tr",{className:"border-b border-border/80 last:border-0",children:_.map((Z,ie)=>e.jsx("td",{className:"p-2 align-top text-foreground",children:e.jsx(ae,{text:Z,assertions:a,campaignId:o,layout:"inline"})},ie))},I))})]})})}}const x=i.join(` 2`);return e.jsx("div",{className:"whitespace-pre-wrap",children:e.jsx(ae,{text:x,assertions:a,campaignId:o,layout:"inline"})})}function Ta(){var Me;const{id:r}=Xt(),o=(Me=Yt().state)==null?void 0:Me.from,{toast:n}=Xe(),{user:i}=We(),d=Je(),[u,v]=b.useState(!0),[x,m]=b.useState(!1),[h,p]=b.useState(!1),[N,_]=b.useState(!1),[I,Z]=b.useState(!1),[ie,q]=b.useState(!1),[ee,Q]=b.useState(null),[ft,gt]=b.useState(()=>localStorage.getItem("opos-citation-hint-seen")==="true"),{exportToGamma:_e,exportingId:bt}=Br(),[yt,we]=b.useState(!1),{data:t,isLoading:jt,isError:vt,refetch:_t}=ar(r),{data:l}=Zt(t==null?void 0:t.campaign_id),oe=(t==null?void 0:t.output_type)==="board_pack"||(t==null?void 0:t.output_type)==="monthly_board_pack",{data:Ne=[]}=mr(t==null?void 0:t.campaign_id,oe?t==null?void 0:t.id:void 0),wt=b.useMemo(()=>{if(!oe||!l)return!1;const s=l.financial_assumptions_updated_at;return as(is(Ne),s)},[Ne,l,oe]),{data:k=[],isPending:ke,isError:F,refetch:Nt}=lr(t==null?void 0:t.campaign_id),{data:Se=[]}=ir(t==null?void 0:t.campaign_id),Ce=b.useMemo(()=>t?Se.filter(s=>s.output_type===t.output_type):[],[Se,t]),{data:de}=cr(t==null?void 0:t.campaign_id),kt=(de==null?void 0:de.total)??k.length,Ae=jr((t==null?void 0:t.content_json)??null),J=b.useMemo(()=>tt(Ae).map(c=>Ze(k,c)).filter(c=>!!c),[Ae,k]),St=!ft&&J.length>0,Ct=()=>{localStorage.setItem("opos-citation-hint-seen","true"),gt(!0)},Ee=b.useMemo(()=>{const s=t==null?void 0:t.output_type;if(!(s==="board_pack"||s==="monthly_board_pack"))return{truthLayerChip:void 0,boardPack:void 0};const f=xr(k);return{truthLayerChip:hr(f),boardPack:{enabled:!0}}},[t==null?void 0:t.output_type,k]),E=(t==null?void 0:t.readiness_state)??"draft",U=vr[E],At=E==="weak_evidence"||E==="contradiction_risk"||E==="needs_sponsor_review",le=or(t==null?void 0:t.campaign_id),Re=Ue({mutationFn:async()=>{if(!t)throw new Error("Missing output");const{data:s,error:c}=await T.rpc("mark_output_complete",{p_output_id:t.id});if(c)throw c;return s},onSuccess:()=>{d.invalidateQueries({queryKey:["output",r]}),d.invalidateQueries({queryKey:["outputs",t==null?void 0:t.campaign_id]}),n({title:"Marked complete",description:"Sponsor completion recorded. Export-ready applies when all readiness rules pass."})},onError:s=>{n({title:"Could not mark complete",description:s instanceof Error?s.message:"Error",variant:"destructive"})}}),{stakeholders:Et}=$r((t==null?void 0:t.campaign_id)??null),{data:Rt=[]}=Fr(t==null?void 0:t.campaign_id),S=(t==null?void 0:t.output_type)==="brainstorm_quadrant",W=b.useMemo(()=>(t==null?void 0:t.output_type)==="brainstorm_quadrant"?qr(t.content_json??null):null,[t==null?void 0:t.output_type,t==null?void 0:t.content_json]),{canUseExpertInTheLoop:Tt,isLoading:It}=er(),Pt=!!(i&&l&&i.id===l.sponsor_id&&!It&&Tt),te=!!i&&!!l&&i.id===l.sponsor_id;b.useEffect(()=>{if(!(t!=null&&t.metadata)||typeof t.metadata!="object"||Array.isArray(t.metadata)){m(!1);return}const s=t.metadata;m(s.included_in_context===!0)},[t==null?void 0:t.metadata,t==null?void 0:t.id]);const C=b.useMemo(()=>{const s=t==null?void 0:t.content_json,c=s&&typeof s=="object"&&!Array.isArray(s)?s:{title:(t==null?void 0:t.title)??"Report",sections:[]};if(t&&l&&be(t)){const{title:f,sections:j}=Xr(t,l.company_name);return{...c,title:f,sections:j}}return c},[t,l]),Te=b.useMemo(()=>{var s;return!t||!be(t)?null:((s=Yr(t.content_json))==null?void 0:s.ratings)??null},[t]),ce=b.useMemo(()=>{const s=C;return Array.isArray(s.risks)?s.risks.filter(c=>c!=null&&typeof c=="object"):null},[C]),D=b.useMemo(()=>{const s=l==null?void 0:l.deal_thesis;return!s||typeof s!="object"||Array.isArray(s)?null:s},[l==null?void 0:l.deal_thesis]),Ie=D&&typeof D.summary=="string"?D.summary:"",me=b.useMemo(()=>{const s=D==null?void 0:D.hypotheses;return Array.isArray(s)?s.map(c=>
2String(c)).filter(Boolean):[]},[D]),Lt=!!D&&(Ie.length>0||me.length>0),R=C.sections??[],O=b.useMemo(()=>ke||F?null:gr(br(R),{assertions:k}),[k,F,ke,R]),G=O?fr(O):void 0,Dt=tr("reportViewerV2"),ue=b.useMemo(()=>!t||F?[]:R.map(s=>Ns(s.body??"",k,t.created_at,ks(t.metadata,s.heading??""))),[k,F,t,R]),pe=b.useMemo(()=>!t||F||R.length===0?null:Ss(ue,t.created_at,s=>ge(new Date(s),"MMM d, yyyy")),[F,t,ue,R.length]),re=(t==null?void 0:t.output_type)==="risk_register"&&ce&&ce.length>0,Ot=!!t&&be(t),Pe=R.length>3&&!re,P=Dt&&!S&&!re,Le=async()=>{if(!(!t||!l))try{let s;if(t.output_type==="comparable_analysis_report"){const f=Ir(l.sector??null),j=Pr(f),y=Dr(l.comparable_analysis),A=(y==null?void 0:y.ebitda_m)??null,L=j.multiples.evEbitda;let M=(y==null?void 0:y.implied_ev_low_m)??null,H=(y==null?void 0:y.implied_ev_high_m)??null,X=null;A!=null&&Number.isFinite(A)&&(X=A*L.median,M=M??A*L.p25,H=H??A*L.p75);const xe=k.filter(K=>K.status==="confirmed"||K.status==="edited").slice(0,15).map(K=>({content:K.content}));s=await Tr({companyName:l.company_name,industryLabel:Lr[f],snapshot:y,benchmarks:j,ebitdaM:A,impliedEvM:{low:M,mid:X,high:H},aiSections:C.sections??[],qoeAssertions:xe})}else s=await yr(t,l,{readinessLabel:U,sources:O});const c=(t.title||t.output_type).replace(/[^\w-]+/g,"_");$e(s,`${c}_v${t.version??1}.docx`),await he({campaignId:t.campaign_id,actionType:"output_downloaded",description:`Downloaded ${t.title||t.output_type}`}),d.invalidateQueries({queryKey:["activity-log",t.campaign_id]}),fe("report_exported")}catch(s){n({title:"Export failed",description:s instanceof Error?s.message:"Error",variant:"destructive"})}},De=async()=>{if(!(!t||!l))try{const s=Rr(t,l,{readinessLabel:U,sources:O}),c=(t.title||t.output_type).replace(/[^\w-]+/g,"_");$e(s,`${c}_v${t.version??1}.html`),await he({campaignId:t.campaign_id,actionType:"output_downloaded",description:`Downloaded ${t.title||t.output_type} (HTML)`}),d.invalidateQueries({queryKey:["activity-log",t.campaign_id]}),fe("report_exported")}catch(s){n({title:"Export failed",description:s instanceof Error?s.message:"Error",variant:"destructive"})}},Oe=async()=>{if(!t||!l)return;const s=qe[t.output_type];Or({companyName:l.company_name,reportTitle:C.title||t.title||(s==null?void 0:s.name)||"Report",reportType:(s==null?void 0:s.name)??t.output_type.replace(/_/g," "),sections:(C.sections??[]).filter(c=>{var f,j;return((f=c.heading)==null?void 0:f.trim())&&((j=c.body)==null?void 0:j.trim())}),readinessFooter:`Readiness: ${U}`,truthLayerChip:Ee.truthLayerChip,boardPack:Ee.boardPack,sources:O}),n({title:"PowerPoint downloaded",description:"Check your downloads folder."}),await he({campaignId:t.campaign_id,actionType:"output_downloaded",description:`Downloaded ${t.title||t.output_type} (PPTX)`}),d.invalidateQueries({queryKey:["activity-log",t.campaign_id]}),fe("report_exported")},Mt=async()=>{if(!(!t||!l)){if(E!=="export_ready"){Q("docx"),q(!0);return}await Le()}},Bt=()=>window.print(),$t=async()=>{if(!(!t||!l)){if(E!=="export_ready"){Q("html"),q(!0);return}await De()}},Ft=()=>{if(!(!t||!l)){if(E!=="export_ready"){Q("pptx"),q(!0);return}Oe()}},qt=async()=>{try{ee==="docx"?await Le():ee==="html"?await De():ee==="pptx"?await Oe():ee==="gamma"&&t&&l&&await _e(t.id,Qe(l.id,l.company_name??void 0))}finally{q(!1),Q(null)}},Qt=async()=>{if(!t)return;const s=t.output_type;try{await le.mutateAsync({outputType:s,stage:"single"}),n({title:"Report regenerated",description:"A new version was created."}),d.invalidateQueries({queryKey:["output",r]}),d.invalidateQueries({queryKey:["outputs",t.campaign_id]})}catch(c){n({title:"Regeneration failed",description:c instanceof Error?c.message:"Error",variant:"destructive"})}},Gt=async s=>{var c;if(!(!t||!l||!te)){p(!0);try{const f=t.metadata&&typeof t.metadata=="object"&&!Array.isArray(t.metadata)?{...t.metadata}:{};if(s){const j=C.sections??[],y=[];for(let M=0;M<j.length;M++){const H=j[M],X=((c=H.body)==null?void 0:c.trim())??"";if(X.length<20)continue;const xe=t.title||t.output_type,K=X.slice(0,500),{data:se,error:Be}=await T.from("assertions").insert({campaign_id:l.id,content:`[From ${xe}] ${H.heading}: ${K}`,category:"strategic",source_type:"report",actor_role:"system",status:"pending",confidence:.75,metadata:{source:"report_output",output_id:t.id,section_index:M}}).select("id").single();if(Be)throw Be;se!=null&&se.id&&y.push(se.id)}const A={...f,included_in_context:!0,context_assertion_ids:y},{error:L}=await T.from("outputs").update({metadata:A}).eq("id",t.id);if(L)throw L;m(!0),n({title:"Report linked to campaign context",description:`${y.length} section(s) added to the Insight Layer as pending insights.`})}else{const j=Array.isArray(f.context_assertion_ids)?f.context_assertion_ids:[];if(j.length>0){const{error:L}=await T.from("assertions").delete().in("id",j);if(L)throw L}const y={...f,included_in_context:!1,context_assertion_ids:[]},{error:A}=await T.from("outputs").update({metadata:y}).eq("id",t.id);if(A)throw A;m(!1),n({title:"Removed from campaign context",description:"Report-sourced insights were removed."})}
2d.invalidateQueries({queryKey:["assertions",l.id]}),d.invalidateQueries({queryKey:["assertion-counts",l.id]}),d.invalidateQueries({queryKey:["output",r]}),d.invalidateQueries({queryKey:["outputs",l.id]})}catch(f){n({title:"Could not update context",description:f instanceof Error?f.message:"Error",variant:"destructive"})}finally{p(!1)}}};if(jt)return e.jsx("div",{className:"print:hidden",children:e.jsx(sr,{})});if(vt)return e.jsx("div",{className:w(z,"py-12 print:hidden"),children:e.jsx(je,{noun:"this report",description:"We could not reach the server. The report itself is unaffected - this is a read error, not a permissions problem.",onRetry:()=>void _t()})});if(!t||!l)return e.jsxs("div",{className:w(z,"py-12 text-center print:hidden"),children:[e.jsx("p",{className:"text-muted-foreground",children:"Report not found or you don't have access."}),e.jsx($,{variant:"outline",className:"mt-4",asChild:!0,children:e.jsx(V,{to:"/reports/repository",children:"Back to Reports"})})]});const g=qe[t.output_type],Ht=C.title||t.title||(g==null?void 0:g.name)||"Report";return e.jsxs("div",{className:"min-h-screen bg-background print:bg-white print:p-0",children:[e.jsx(Qr,{open:N,onOpenChange:_,campaignId:t.campaign_id,outputId:t.id,reportLabel:Ht,stakeholders:Et,recentShares:Rt}),e.jsx(ss,{open:yt,onOpenChange:we,outputs:Ce,outputType:t.output_type,assertions:k,campaignId:t.campaign_id}),e.jsx(ot,{open:ie,onOpenChange:q,children:e.jsxs(dt,{children:[e.jsxs(lt,{children:[e.jsx(ct,{children:"Export with current readiness?"}),e.jsxs(mt,{children:['This output is at state "',U,'". Board-pack-grade exports recommend the Export-ready state. Cancel to review, or proceed to export anyway.']})]}),e.jsxs(ut,{children:[e.jsx(pt,{onClick:()=>{Q(null)},children:"Cancel"}),e.jsx(xt,{onClick:()=>void qt(),children:"Export anyway"})]})]})}),e.jsx(Kr,{open:I,onOpenChange:Z,children:e.jsxs(zr,{side:"right",className:"w-full sm:max-w-md overflow-y-auto","aria-describedby":void 0,children:[e.jsx(Vr,{children:e.jsx(Jr,{children:"Readiness detail"})}),e.jsxs("div",{className:"mt-4 space-y-3 text-sm",children:[e.jsx("p",{className:"text-muted-foreground",children:"Cited assertions in this output (jump to the Insight Layer to confirm or edit):"}),J.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No cited assertions parsed from this output body."}):e.jsx("ul",{className:"space-y-2",children:J.map(s=>e.jsxs("li",{className:"rounded-md border border-border p-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(B,{variant:"outline",children:s.status??"-"}),e.jsx(V,{className:"text-xs font-medium text-primary underline-offset-4 hover:underline",to:`/campaigns/${l.id}?tab=truth-layer&assertion=${s.id}`,children:"Open in Insight Layer"})]}),e.jsx("p",{className:"mt-1 line-clamp-5 text-xs text-foreground",children:s.content})]},s.id))})]})]})}),e.jsxs("div",{className:"border-b bg-card px-4 py-3 print:hidden",children:[e.jsxs("div",{className:w(z,"flex flex-wrap items-center gap-2"),children:[e.jsx($,{variant:"ghost",size:"icon",asChild:!0,"aria-label":"Back",children:e.jsx(V,{to:o??"/reports/repository",children:e.jsx(Sr,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1 text-xs text-muted-foreground sm:text-sm",children:[e.jsx(V,{to:"/reports/repository",className:"hover:text-foreground transition-colors shrink-0",children:"Reports"}),e.jsx("span",{className:"shrink-0",children:"/"}),e.jsx(V,{to:`/campaigns/${l.id}?tab=outputs`,className:"font-medium text-muted-foreground hover:text-foreground transition-colors truncate max-w-[140px] sm:max-w-[220px]",children:l.company_name}),e.jsx("span",{className:"shrink-0",children:"/"}),e.jsx("span",{className:"font-medium text-foreground truncate max-w-[200px]",children:C.title||t.title||(g==null?void 0:g.name)})]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsx(_r,{state:E,size:"sm",onClick:At?()=>Z(!0):void 0}),!S&&(t.citation_violation||(t.citation_token_count??0)>0)?t.citation_violation?e.jsx(B,{variant:"outline",className:"border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100",title:"A few more cited sources will strengthen this for the board.",children:"Add evidence"}):e.jsxs(B,{variant:"outline",className:"border-emerald-300 bg-emerald-50 text-emerald-800 dark:border-emerald-800 dark:bg-emerald-950/30 dark:text-emerald-200",title:`${t.citation_token_count} inline citation${t.citation_token_count===1?"":"s"} ground this output.`,children:["Grounding: ",t.citation_token_count," cited"]}):null,te&&E==="reviewed"&&!S?e.jsx($,{type:"button",size:"sm",variant:"secondary",disabled:Re.isPending,onClick:()=>void Re.mutate(),children:"Mark export-ready"}):null,e.jsx(B,{variant:"secondary",children:(g==null?void 0:g.name)??t.output_type}),wt?e.jsx(B,{variant:"outline",className:os,title:"Financial assumptions changed after this pack was approved.",children:"Assumptions moved"}):null,t.version!=null?e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",t.version]}):null]})]}),e.jsxs("div",{className:w(z,"mt-3 flex flex-wrap gap-2"),children:[S?null:e.jsxs(e.Fragment,{children:[e.jsx(ne,{format:"word",label:"Download DOCX",onClick:()=>void Mt()}),e.jsx(ne,{format:"html",label:"Download HTML",onClick:()=>void $t()}),e.jsx(ne,{format:"ppt",label:"Export PPT",onClick:Ft})]}),e.jsx(ne,{format:"pdf",label:"Print",onClick:Bt}),S?null:e.jsxs($,{type:"button",size:"sm",variant:"outline",disabled:le.isPending,onClick:()=>void Qt(),children:[le.isPending?e.jsx(ye,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(st,{className:"mr-2 h-4 w-4"}),"Regenerate"]}),!S&&Ce.length>=2?e.jsxs($,{type:"button",size:"sm",variant:"outline",onClick:()=>we(!0),title:"See what changed between versions of this report",children:[e.jsx(Cr,{className:"mr-2 h-4 w-4"}),"Compare versions"]}):null,Pt?e.jsxs($,{type:"button",size:"sm",variant:"outline",className:"gap-2 border-chart-gold/50 text-foreground hover:bg-accent",onClick:()=>_(!0),title:"Share this report with stakeholders in your circle",children:[e.jsx(Ar,{className:"h-4 w-4 shrink-0"}
2),"Share with stakeholders"]}):null,t.campaign_id?e.jsx(rr,{campaignId:t.campaign_id,campaignName:l==null?void 0:l.company_name,sourceRef:{type:"output",id:t.id,label:t.title||t.output_type},defaultTopic:t.title||t.output_type,defaultQuestion:`Please review this ${t.output_type.replace(/_/g," ")}: ${t.title??""}`.trim()}):null,S?null:e.jsx(Ur,{metadata:t.metadata,exporting:bt===t.id,downloadBaseName:(l==null?void 0:l.company_name)??t.title??"report",onExport:()=>{if(E!=="export_ready"){Q("gamma"),q(!0);return}_e(t.id,l?Qe(l.id,l.company_name??void 0):void 0)},emptyExportLabel:"Export to Gamma",savedOpenLabel:"Open Gamma",buttonSize:"sm"})]}),S?null:e.jsx("div",{className:w(z,"mt-2 max-w-3xl print:hidden"),children:e.jsx(Ge,{className:"border-border bg-muted/20 py-2",children:e.jsxs(He,{className:"text-step-caption leading-snug text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Export PPT"})," above builds slides in-browser from this report.",e.jsx("strong",{className:"text-foreground",children:" Gamma"})," uses gamma.app; the split button offers Open Gamma, Gamma PPT, and Gamma PDF (saved links on this report - downloads use your browser folder)."]})})})]}),e.jsxs("div",{className:w(z,"py-6 print:py-0 print:max-w-none"),children:[P?e.jsx(cs,{title:C.title||t.title||(g==null?void 0:g.name)||"Report",companyName:l.company_name,reportType:(g==null?void 0:g.name)??t.output_type,versionLabel:t.version!=null?`v${t.version}`:null,dateLabel:ge(new Date(t.created_at),"MMM d, yyyy HH:mm"),freshnessLine:pe}):e.jsxs("div",{className:"mb-6 rounded-md border bg-muted/30 px-4 py-2 text-xs text-muted-foreground print:border-0 print:bg-transparent",children:[e.jsx("span",{className:"font-medium text-foreground",children:l.company_name})," · ",(g==null?void 0:g.name)??t.output_type," · ",t.version!=null?`v${t.version} · `:"",ge(new Date(t.created_at),"MMM d, yyyy HH:mm")," · ",kt," insights in campaign",pe&&!re?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"print:hidden text-foreground",children:pe})]}):null]}),F?e.jsx("div",{className:"mb-4 print:hidden",children:e.jsx(je,{compact:!0,noun:"cited facts",description:"Citation freshness could not be checked â the report itself is unchanged.",onRetry:()=>void Nt()})}):null,S?null:e.jsxs(e.Fragment,{children:[e.jsx(ms,{readinessLabel:U,citationCount:t.citation_token_count,densityPerKw:t.citation_density_per_kw,sectionCount:R.filter(s=>{var c,f;return((c=s.heading)==null?void 0:c.trim())&&((f=s.body)==null?void 0:f.trim())}).length,skillsCount:ze(t.metadata??void 0).length,stage:Ke(t.metadata??void 0)}),(t.citation_token_count??0)>0?e.jsx(us,{className:"-mt-3 mb-6 px-1"}):null,P&&G?e.jsx(Ye,{variant:"block",limits:G,className:"mb-6"}):null]}),(()=>{const s=ze(t.metadata??void 0);return s.length===0?null:e.jsxs("div",{className:"mb-6 flex flex-wrap items-center gap-1.5 print:hidden",children:[e.jsx("span",{className:"text-step-caption font-medium uppercase tracking-wide text-muted-foreground",children:"Shaped by"}),s.slice(0,8).map(c=>e.jsx(B,{variant:"outline",className:"text-step-caption font-normal text-muted-foreground",children:c},c))]})})(),e.jsx("div",{className:"mb-6 print:hidden",children:e.jsx(hs,{campaignId:l.id,outputId:t.id})}),S?null:e.jsxs("div",{className:"mb-6 print:hidden",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-dashed border-amber-500/40 bg-amber-50/50 p-3 dark:bg-amber-950/20 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Fe,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700 dark:text-amber-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Include in campaign context"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"When enabled, each section becomes a pending insight for sponsor review - future AI can reference confirmed items. Only the campaign sponsor can enable this."})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 self
2-end sm:self-center",children:[h?e.jsx(ye,{className:"h-4 w-4 animate-spin text-muted-foreground"}):null,e.jsx(nr,{checked:x,disabled:!te||h,onCheckedChange:s=>void Gt(s),"aria-label":"Include report in campaign context"})]})]}),te?null:e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Only the campaign sponsor can import report sections into the Insight Layer."}),x?e.jsx(B,{variant:"outline",className:"mt-2 border-amber-500/50 text-amber-900 dark:text-amber-100",children:"Included in campaign context"}):null]}),Lt&&!S?e.jsxs(nt,{open:u,onOpenChange:v,className:"mb-6 rounded-lg border border-border bg-card shadow-sm print:hidden",children:[e.jsxs(at,{className:"flex w-full items-center justify-between gap-2 px-4 py-3 text-left hover:bg-muted/40",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Thesis alignment"}),e.jsx(rt,{className:w("h-4 w-4 shrink-0 text-muted-foreground transition-transform",u&&"rotate-180")})]}),e.jsxs(it,{className:"border-t border-border px-4 pb-4 pt-2",children:[e.jsx(Mr,{className:"text-sm leading-relaxed text-foreground",children:Ie||"-"}),me.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:me.slice(0,12).map((s,c)=>e.jsx("span",{className:"rounded-md border border-border bg-muted/50 px-2 py-0.5 text-xs text-foreground",children:s},c))}):null]})]}):null,S?W?e.jsxs("article",{className:"report-viewer-content mx-auto max-w-5xl print:max-w-none",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-foreground print:text-black",children:t.title||(g==null?void 0:g.name)||"Brainstorm"}),W.problem_statement?e.jsx("p",{className:"mt-2 max-w-3xl text-sm leading-relaxed text-muted-foreground",children:W.problem_statement}):null,e.jsx("div",{className:"mt-8",children:e.jsx(Gr,{sessionSummary:W.session_summary,ideas:W.ideas,interactive:!1,refiningId:null,recommendationBusyId:null,onRefine:()=>{},onMarkRecommendation:()=>{}})})]}):e.jsx(Ge,{variant:"destructive",className:"max-w-3xl",children:e.jsx(He,{children:"This brainstorm artifact is missing structured quadrant data. Ask the sponsor to re-share from the Brainstorm Engine."})}):re?e.jsxs("article",{className:"report-viewer-content mx-auto max-w-3xl print:max-w-none",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-foreground print:text-black",children:C.title||t.title||(g==null?void 0:g.name)||"Report"}),e.jsx("div",{className:"mt-8 vt-paper overflow-x-auto rounded-md border border-border print:border print:text-black",children:e.jsxs("table",{className:"w-full min-w-[640px] border-collapse text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50 text-left text-muted-foreground dark:bg-muted/30",children:[e.jsx("th",{className:"p-2 font-medium",children:"Risk"}),e.jsx("th",{className:"p-2 font-medium",children:"Category"}),e.jsx("th",{className:"p-2 font-medium",children:"Severity"}),e.jsx("th",{className:"p-2 font-medium",children:"Likelihood"}),e.jsx("th",{className:"p-2 font-medium",children:"Impact"}),e.jsx("th",{className:"p-2 font-medium",children:"Owner"}),e.jsx("th",{className:"p-2 font-medium",children:"Status"})]})}),e.jsx("tbody",{children:ce.map((s,c)=>
2{const f=s.severity??null,j=s.likelihood??null,y=s.impact_score??s.impact??(f!=null&&j!=null?f*j:null);return e.jsxs("tr",{className:"border-b border-border/80 last:border-0",children:[e.jsx("td",{className:"p-2 align-top font-medium text-foreground",children:s.title??"-"}),e.jsx("td",{className:"p-2 align-top text-foreground",children:s.category??"-"}),e.jsx("td",{className:"p-2 align-top tabular-nums text-foreground",children:f??"-"}),e.jsx("td",{className:"p-2 align-top tabular-nums text-foreground",children:j??"-"}),e.jsx("td",{className:w("p-2 align-top",Cs(y)),children:y??"-"}),e.jsx("td",{className:"p-2 align-top text-foreground",children:s.owner??"-"}),e.jsx("td",{className:"p-2 align-top text-foreground",children:s.status??"-"})]},c)})})]})})]}):e.jsxs("div",{className:w("mx-auto print:max-w-none",Pe?"max-w-5xl lg:grid lg:grid-cols-[1fr_200px] lg:gap-8":"max-w-3xl"),children:[e.jsxs("article",{className:"report-viewer-content min-w-0",children:[P?null:e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-foreground print:text-black",children:C.title||t.title||(g==null?void 0:g.name)||"Report"}),Ot&&Te?e.jsxs("div",{className:"mt-6 rounded-lg border border-border bg-card p-4 print:break-inside-avoid",children:[e.jsx("p",{className:"mb-3 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Competitive intensity radar"}),e.jsx(Wr,{ratings:Te})]}):null,St&&e.jsxs("div",{className:"mt-6 flex items-start gap-3 rounded-lg border border-oposgold/30 bg-accent px-4 py-3 print:hidden",children:[e.jsx(Fe,{className:"mt-0.5 size-4 shrink-0 text-oposgold"}),e.jsxs("p",{className:"flex-1 text-sm text-foreground/80",children:["This report cites ",J.length," fact",J.length===1?"":"s"," from your campaign."," ",e.jsx("span",{className:"font-medium text-foreground",children:"Click any citation chip to verify the source."})]}),e.jsx("button",{type:"button",onClick:Ct,className:"ml-1 shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:text-foreground","aria-label":"Dismiss",children:e.jsx(Er,{className:"size-3.5"})})]}),e.jsx("div",{className:w("mt-8",P?"max-w-[70ch]":"space-y-8"),children:R.map((s,c)=>{const{bodyWithoutAlignment:f,alignmentNote:j}=ts(s.body??""),y=ue[c];return e.jsxs("section",{id:`report-section-${c}`,className:w("scroll-mt-24",P?"space-y-3 border-t border-border py-8 print:break-inside-avoid print:text-black [&_table]:break-inside-avoid":"space-y-3 rounded-xl p-5 vt-card-3d"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("h2",{className:"font-display text-lg font-semibold text-navy dark:text-foreground print:text-black",children:[P?e.jsxs("span",{className:"mr-2 font-data text-muted-foreground print:text-black",children:[c+1,"."]}):null,s.heading]}),e.jsxs("div",{className:"flex items-center gap-3",children:[y!=null&&y.showBadge?e.jsx(ns,{label:y.label}):null,e.jsx(gs,{sectionId:s.heading,ledgerEntryId:As((t==null?void 0:t.metadata)??void 0,s.heading)}),t&&t.campaign_id&&e.jsx(vs,{campaignId:t.campaign_id,outputId:t.id,outputType:t.output_type,sectionId:s.heading,stage:Ke((t==null?void 0:t.metadata)??void 0)})]})]}),e.jsx(Es,{body:f,assertions:k,campaignId:t==null?void 0:t.campaign_id}),e.jsx(rs,{note:j})]},c)})}),P&&O&&G?e.jsx(ls,{sources:O,limits:G,assertions:k,campaignId:l.id}):null]}),Pe?e.jsx("nav",{className:"hidden lg:block print:hidden","aria-label":"Report sections",children:e.jsxs("div",{className:"sticky top-20 space-y-1 rounded-lg border bg-card p-3",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Sections"}),R.map((s,c)=>e.jsx("button",{type:"button",className:"block w-full rounded px-2 py-1 text-left text-xs transition-colors hover:bg-accent/50",onClick:()=>{var f;(f=document.getElementById(`report-section-${c}`))==null||f.scrollIntoView({behavior:"smooth",block:"start"})},children:s.heading},c)),P?e.jsx("button",{type:"button",className:"block w-full rounded px-2 py-1 text-left text-xs transition-colors hover:bg-accent/50",onClick:()=>{var s;(s=document.getElementById("report-sources"))==null||s.scrollIntoView({behavior:"smooth",block:"start"})},children:"Sources and limits"}):null]})}):null]}),P&&O&&G?null:e.jsx(et,{campaignId:l.id,limits:G,className:"max-w-3xl"})]})]})}export{Ta as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.