{
  "name": "matrix-widget",
  "type": "registry:ui",
  "description": "Canadian AI Matrix generative UI: Sales, Kanban, templates, LaTeX, PDF handoff, data rooms, Sequence Flow and analysis",
  "files": [
    {
      "path": "components/generative/matrix-widget.tsx",
      "content": "\"use client\"\nimport * as React from \"react\"\n\nexport type WidgetRow = { id?: string; title?: string; name?: string; business?: string; stage?: string; status?: string; tier?: string; nextStep?: string; description?: string; [key: string]: unknown }\nexport type WidgetAction = { kind: \"inspect\" | \"preview\" | \"prepare\" | \"open\"; id?: string; value?: string }\nexport type SequenceEvent = { from: string; to: string; label: string; detail?: string }\nexport type WidgetData = { kind: \"sales\" | \"kanban\" | \"templates\" | \"latex\" | \"pdf\" | \"documents\" | \"sequence\" | \"analysis\" | \"solutions\" | \"travel\" | \"tools\"; title: string; rows?: WidgetRow[]; text?: string; events?: SequenceEvent[]; complete?: boolean; url?: string }\nconst colors = { bg: \"var(--cai-color-surface-background,#161717)\", panel: \"var(--cai-color-surface-container-low,#1d201f)\", fg: \"var(--cai-color-text-body,#e5e9e6)\", muted: \"var(--cai-color-text-secondary,#a4aba8)\", line: \"var(--cai-color-border-neutral-medium,#3a3f3d)\", accent: \"#75b89a\" }\nconst cell: React.CSSProperties = { padding: 12, border: \"1px solid \"+colors.line, background: colors.panel, minWidth: 0, overflowWrap: \"anywhere\" }\nconst label = (r: WidgetRow) => String(r.title ?? r.business ?? r.name ?? \"Untitled\")\nexport function MatrixButton({children,onClick,disabled}: {children: React.ReactNode; onClick:()=>void; disabled?:boolean}) { return <button type=\"button\" disabled={disabled} onClick={onClick} style={{...cell,color:colors.fg,cursor:disabled?\"default\":\"pointer\",font:\"inherit\",borderRadius:0}}>{children}</button> }\nexport function MatrixShell({title,children}: {title:string;children:React.ReactNode}) { return <section aria-label={title} style={{background:colors.bg,color:colors.fg,border:\"1px solid \"+colors.line,padding:16,fontFamily:\"system-ui,sans-serif\",maxWidth:\"100%\"}}><header style={{display:\"flex\",alignItems:\"center\",gap:8,borderBottom:\"1px solid \"+colors.line,paddingBottom:12,marginBottom:12}}><svg aria-hidden=\"true\" width=\"20\" height=\"20\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1080 1080\"><path fill=\"currentColor\" d=\"M1080,477.72v104.55c-19.84,255.58-221.7,461.02-474.67,491.57-21.43,2.58-43.24,6.16-65.33,6.16-54.13,0-106.38-10.24-155.64-25.12-4.06-11.11-3.07-24.13,4.96-35.2l202.02-279.04s0-.02,0-.03c6.37-8.82,9.79-19.38,9.79-30.25v-56.18c0-44.75-53.1-68.29-86.26-38.22l-113.72,103.09s0,.01-.03.03c-20.39,18.44-51.67,17.67-71.11-1.78l-88.8-88.8c-19.63-19.64-20.21-51.29-1.29-71.63l252.97-271.94.02-.02c30.69-33,7.27-86.73-37.8-86.73h-29.65c-13.7,0-26.81,5.44-36.49,15.11h-.02S88.09,514.19,88.09,514.19c-.03.03-.08.08-.11.11L0,602.28v-104.55C19.37,248.14,212.34,46.37,456.96,8.6c5.88-.9,11.77-1.71,17.71-2.44,21.43-2.58,43.24-6.16,65.33-6.16,54.13,0,106.38,10.24,155.64,25.12,4.06,11.11,3.07,24.13-4.96,35.2l-202.02,279.04s0,.02,0,.03c-6.37,8.82-9.79,19.4-9.79,30.25v56.18c0,44.75,53.1,68.29,86.26,38.22l113.72-103.09s0-.01.03-.03c20.39-18.44,51.67-17.67,71.11,1.78l88.8,88.8c19.63,19.64,20.21,51.29,1.29,71.63l-252.97,271.94-.02.02c-30.69,33-7.27,86.73,37.8,86.73h29.65c13.7,0,26.81-5.44,36.49-15.11h.02s300.87-300.9,300.87-300.9c.03-.03.08-.08.11-.11l87.98-87.98Z\" /></svg><strong>{title}</strong><small style={{marginLeft:\"auto\",color:colors.muted}}>Canadian AI</small></header>{children}<footer style={{color:colors.muted,fontSize:11,marginTop:12}}>Built by Canadian AI in Montréal, Canada</footer></section> }\nexport function MatrixRows({rows,onAction}: {rows:WidgetRow[];onAction?:(a:WidgetAction)=>void}) { const [q,setQ]=React.useState(\"\");return <><input aria-label=\"Filter records\" placeholder=\"Filter records\" value={q} onChange={e=>setQ(e.target.value)} style={{...cell,color:colors.fg,width:\"100%\"}}/><div style={{display:\"grid\",gap:6,marginTop:8}}>{rows.filter(r=>[label(r),r.stage,r.tier,r.status].join(\" \").toLowerCase().includes(q.toLowerCase())).map((r,i)=><div key={r.id??i} style={cell}><strong>{label(r)}</strong><div style={{color:colors.muted,fontSize:12}}>{[r.tier,r.stage,r.status].filter(Boolean).join(\" · \")}</div>{r.description&&<p>{r.description}</p>}{r.id&&onAction&&<MatrixButton onClick={()=>onAction({kind:\"inspect\",id:r.id})}>Inspect</MatrixButton>}</div>)}</div></> }\nexport function MatrixKanban({rows,onAction}: {rows:WidgetRow[];onAction?:(a:WidgetAction)=>void}) { const stages=[...new Set(rows.map(r=>r.stage??r.status??\"Unassigned\"))];return <div style={{display:\"grid\",gridAutoFlow:\"column\",gridAutoColumns:\"minmax(170px,1fr)\",gap:8,overflowX:\"auto\"}}>{stages.map(stage=><section key={stage} style={cell}><strong>{stage} · {rows.filter(r=>(r.stage??r.status??\"Unassigned\")===stage).length}</strong>{rows.filter(r=>(r.stage??r.status??\"Unassigned\")===stage).map((r,i)=><div key={r.id??i} style={{...cell,marginTop:8,background:colors.bg}}>{label(r)}{r.tier&&<small style={{display:\"block\",color:colors.accent}}>{r.tier}</small>}{r.id&&onAction&&<MatrixButton onClick={()=>onAction({kind:\"inspect\",id:r.id})}>Inspect</MatrixButton>}</div>)}</section>)}</div> }\nexport function MatrixSales({rows,complete,onAction}: {rows:WidgetRow[];complete?:boolean;onAction?:(a:WidgetAction)=>void}) { const [mode,setMode]=React.useState(\"board\");return <><div style={{display:\"flex\",gap:8,flexWrap:\"wrap\",marginBottom:12}}>{[[\"Loaded\",rows.length],[\"A+\",rows.filter(r=>r.tier===\"A+\").length],[\"Open\",rows.filter(r=>r.status===\"open\").length]].map(([k,v])=><div key={k} style={cell}><small>{k}</small><div style={{fontSize:24}}>{v}</div></div>)}</div>{!complete&&<p>Counts describe loaded records only.</p>}<MatrixButton onClick={()=>setMode(mode===\"board\"?\"list\":\"board\")}>{mode===\"board\"?\"List view\":\"Board view\"}</MatrixButton>{mode===\"board\"?<MatrixKanban rows={rows} onAction={onAction}/>:<MatrixRows rows={rows} onAction={onAction}/>}</> }\nexport function MatrixSequence({events}: {events:SequenceEvent[]}) { const [step,setStep]=React.useState(0);const actors=[...new Set(events.flatMap(e=>[e.from,e.to]))];return <><div style={{display:\"flex\",gap:8,alignItems:\"center\"}}><MatrixButton disabled={step<=0} onClick={()=>setStep(Math.max(0,step-1))}>Previous</MatrixButton><span>{Math.min(step+1,events.length)} / {events.length}</span><MatrixButton disabled={step>=events.length-1} onClick={()=>setStep(Math.min(events.length-1,step+1))}>Next</MatrixButton></div><div style={{overflowX:\"auto\"}}><svg role=\"img\" aria-label=\"Sequence flow\" width={Math.max(300,actors.length*145)} height={80+events.length*52}>{actors.map((a,i)=><g key={a}><rect x={i*145+10} y={12} width={125} height={30} fill={colors.panel} stroke={colors.line}/><text x={i*145+72} y={31} textAnchor=\"middle\" fontSize={12} fill={colors.fg}>{a.slice(0,20)}</text><path d={\"M\"+(i*145+72)+\" 42V\"+(65+events.length*52)} stroke={colors.line} strokeDasharray=\"4 5\"/></g>)}{events.map((e,i)=>{const x=actors.indexOf(e.from)*145+72,y=actors.indexOf(e.to)*145+72,h=75+i*52;return <g key={i} opacity={i<=step?1:.22}><line x1={x} x2={y===x?y+28:y} y1={h} y2={h} stroke={colors.accent} strokeWidth={2}/><path d={y>=x?\"M\"+(y===x?y+28:y)+\" \"+h+\"l-7 -4v8z\":\"M\"+y+\" \"+h+\"l7 -4v8z\"} fill={colors.accent}/><text x={(x+y)/2} y={h-7} fontSize={11} textAnchor=\"middle\" fill={colors.fg}>{e.label.slice(0,44)}</text></g>})}</svg></div>{events[step]&&<p>{events[step].detail??events[step].label}</p>}</> }\nexport function MatrixTemplates({rows,onAction}: {rows:WidgetRow[];onAction?:(a:WidgetAction)=>void}) { const [selected,setSelected]=React.useState<WidgetRow>();return <><div style={{display:\"grid\",gridTemplateColumns:\"repeat(auto-fit,minmax(150px,1fr))\",gap:8}}>{rows.map((r,i)=><div key={r.id??i} style={cell}><strong>{label(r)}</strong><p>{r.description}</p><MatrixButton onClick={()=>{setSelected(r);onAction?.({kind:\"preview\",id:r.id})}}>Preview</MatrixButton></div>)}</div>{selected&&<div style={{...cell,marginTop:12}}><strong>{label(selected)}</strong><p>Preview is supplied by the authorized host.</p><MatrixButton disabled={!onAction} onClick={()=>onAction?.({kind:\"prepare\",id:selected.id})}>Prepare site</MatrixButton></div>}</> }\nexport function MatrixDocument({kind,text,url,onAction}: {kind:\"latex\"|\"pdf\"|\"analysis\";text?:string;url?:string;onAction?:(a:WidgetAction)=>void}) { return <>{text&&<pre style={{...cell,whiteSpace:\"pre-wrap\",fontFamily:kind===\"latex\"?\"monospace\":\"inherit\",maxHeight:440,overflow:\"auto\"}}>{text}</pre>}{kind===\"pdf\"&&<p>Open the authorized PDF in the host document viewer.</p>}{url&&onAction&&<MatrixButton onClick={()=>onAction({kind:\"open\",value:url})}>Open document</MatrixButton>}</> }\nexport function MatrixWidget({data,onAction}: {data:WidgetData;onAction?:(a:WidgetAction)=>void}) { const rows=data.rows??[];return <MatrixShell title={data.title}>{data.kind===\"sales\"?<MatrixSales rows={rows} complete={data.complete} onAction={onAction}/>:data.kind===\"kanban\"?<MatrixKanban rows={rows} onAction={onAction}/>:data.kind===\"sequence\"?<MatrixSequence events={data.events??[]}/>:data.kind===\"templates\"?<MatrixTemplates rows={rows} onAction={onAction}/>:[\"latex\",\"pdf\",\"analysis\"].includes(data.kind)?<MatrixDocument kind={data.kind as \"latex\"|\"pdf\"|\"analysis\"} text={data.text} url={data.url} onAction={onAction}/>:<MatrixRows rows={rows} onAction={onAction}/>}</MatrixShell> }\n",
      "type": "registry:ui"
    }
  ]
}