@duckcodeailabs/dql-cli 1.13.5 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.d.ts +17 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +30 -0
- package/dist/args.js.map +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-BzQOKjyV.js → AgentLogPage-BPz-UWFh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-CTxha499.js → AiBuildDialog-BEl53WA_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult--MuD_I6g.js → AiBuildResult-B4yfGTTZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-DcI4PMJ1.js → AiSidePanel-CSZAAvuD.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-Dq54vjNz.js → AnalyticsHome-D5P6Ujwi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AppsView-0SlwWYex.js → AppsView-DQOwU9Cg.js} +4 -4
- package/dist/assets/dql-notebook/assets/{BlockStudio-CxxXZD3M.js → BlockStudio-B4ap0GdY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-DxdAmeUN.js → BusinessArtifactView-BIfNI-0S.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-y81gFg_b.js → DbtFirstModelingPage-D72byb2g.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-GQtcwncb.js → GitPage-lQb1uXH2.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-DM4wkxR_.js → GlobalAiRail-CVECf6Xj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-B8Ft6JES.js → GovernedContextPage-trOyMCY6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-DnD4nMuF.js → HelpDocsPage-D8hLS5lE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-Ehb0ITj-.js → HomePage-eIkfBIep.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-Lvjc2AQX.js → LineageDAG-CSqcbDrE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-DX32pfbp.js → LineageDetailView-DJZZjZu-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-CFq3jPfk.js → LineageDrawer-BcIipIc3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-CVHXuHls.js → LineagePathBreadcrumb-CviIf8PN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-BKaeT5Kt.js → MiniLineageGraph-vH_MY_Ju.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-DI-JDzFH.js → NewBlockModal-DbCQg-pj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-Csw6eF74.js → NewNotebookModal-5Vp6XiuK.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-FEqs3789.js → NotebookEditor-DjqJS44s.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-Bk0S_MEA.js → ReadinessPage-BHGrC5ho.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-DyLaPFGn.js → SetupOnboarding-BfS9Tdx-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SkillsPage-DLHyvhci.js → SkillsPage-BFH21wSj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-CIDLj2A6.js → TrustBadge-zm6g_SxZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel--oxmjlgr.js +88 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-CFEJHLvs.js → answer-to-notebook-DPhxIEzF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-B-Zdcyvm.js → arrow-left-DNEb86Xc.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-Cn8TM7cp.js → arrow-right-DpPWbwaD.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-Bko2NNUs.js → book-open-text-D7s5jo4X.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-AWJAmUBB.js → circle-x-Db3dXKg7.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-Cl_ucrRh.js → dagre.esm-C7pppQ1a.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-DN57tb5f.js → external-link-BxwXitO_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-BOWwFFva.js → grip-vertical-Dt4lkWRi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-Ck-wqvV2.js → index-DKo-bwNw.js} +4 -4
- package/dist/assets/dql-notebook/assets/{link-2-xUhbfBs8.js → link-2-Dfo2P6wi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-BDWcBr67.js → list-tree-DiTmIWAL.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-CEeNoMTS.js → minimize-2-CMTAkPzL.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-DnSeUvOY.js → panel-right-open-DwYr7FW4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{play-EoDj8-fa.js → play-BXhHYQ4x.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-BAMxWT9A.js → rotate-ccw-BNi6F8pl.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-BwLOs1kl.js → semantic-fields-CNOGysAy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-BYkm8SWW.js → sliders-horizontal-Ec5MUMUW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-sVexqNCs.js → star-B9leDkp_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-D2njv4o4.js → triangle-alert-BefTYCzx.js} +1 -1
- package/dist/assets/dql-notebook/assets/{upload-CXTMxIA8.js → upload-SPiOM2tQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-CPDeaAgL.js → usePersistedAgentThreadId-C4foXeiQ.js} +4 -4
- package/dist/assets/dql-notebook/assets/{user-round-zVsI_uud.js → user-round-comGmyw-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-BMIwIzXT.js → wand-sparkles-BffR4dF8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-Dj9y1sNk.js → workflow-ChmPTEzH.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-DPQi6zrs.js → wrench-DovaG_ze.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-XhhbtinL.js → x-nRx91AgW.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/commands/agent-eval-cassette.d.ts +73 -0
- package/dist/commands/agent-eval-cassette.d.ts.map +1 -0
- package/dist/commands/agent-eval-cassette.js +170 -0
- package/dist/commands/agent-eval-cassette.js.map +1 -0
- package/dist/commands/agent-eval-runtime.d.ts +97 -0
- package/dist/commands/agent-eval-runtime.d.ts.map +1 -0
- package/dist/commands/agent-eval-runtime.js +155 -0
- package/dist/commands/agent-eval-runtime.js.map +1 -0
- package/dist/commands/agent.d.ts +115 -1
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +289 -62
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/eval.d.ts +15 -1
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +32 -3
- package/dist/commands/eval.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/analyst-loop-tools.d.ts +19 -0
- package/dist/llm/analyst-loop-tools.d.ts.map +1 -0
- package/dist/llm/analyst-loop-tools.js +56 -0
- package/dist/llm/analyst-loop-tools.js.map +1 -0
- package/dist/llm/providers/dql-agent-provider.d.ts +24 -1
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +343 -10
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/llm/types.d.ts +19 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/local-runtime.d.ts +132 -2
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +1120 -184
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-C0oKTU6G.js +0 -88
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{R as te,j as r,b8 as Ye,c as le,r as R,t as q,u as Ht,a as Ot,b9 as Ze,L as qt,f as Ut,l as Vt,S as Ge,d as Qt,e as Yt}from"./index-
|
|
1
|
+
import{R as te,j as r,b8 as Ye,c as le,r as R,t as q,u as Ht,a as Ot,b9 as Ze,L as qt,f as Ut,l as Vt,S as Ge,d as Qt,e as Yt}from"./index-DKo-bwNw.js";import{T as Zt}from"./TrustBadge-zm6g_SxZ.js";import{R as Gt,G as Xt}from"./AiBuildResult-B4yfGTTZ.js";import{W as Kt}from"./wrench-DovaG_ze.js";const Jt={value:"Value",block:"Certified block",term:"Business term",metric:"Metric",dimension:"Dimension",model:"dbt model",source:"Source table",consumer:"Used by"};function Xe(e){const t=(e??"").toLowerCase();return t==="certified"?"success":t==="deprecated"?"neutral":t.includes("review")||t==="draft"||t==="pending"?"warning":"neutral"}function Ct({walk:e,defaultOpen:t=!1,triggerLabel:n}){const[o,i]=te.useState(t),s=Math.min(e.steps.length,2),[l,c]=te.useState(s),a=()=>c(s),d=e.steps.slice(0,l),u=e.steps.length-l;return r.jsxs("div",{style:{border:"1px solid var(--border-subtle, rgba(127,127,127,0.25))",borderRadius:8,background:"var(--bg-1, transparent)",overflow:"hidden"},children:[r.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>{i(f=>!f),o&&a()},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:0,background:"transparent",color:"var(--text-secondary, inherit)",cursor:"pointer",padding:"8px 11px",font:"inherit",fontSize:12,fontWeight:700},children:[r.jsxs("span",{style:{display:"flex",alignItems:"center",gap:7},children:[r.jsx("span",{"aria-hidden":!0,style:{transform:o?"rotate(90deg)":"none",transition:"transform 120ms",display:"inline-block"},children:"▸"}),n??"Why?"]}),r.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)",fontWeight:600},children:o?"Hide derivation":"Show how this was derived"})]}),o&&r.jsxs("div",{style:{padding:"2px 11px 11px",display:"flex",flexDirection:"column",gap:10},children:[r.jsx("div",{style:{fontSize:12.5,lineHeight:1.5,color:"var(--text-primary, inherit)"},children:e.summary}),(e.trustLabel||e.freshness)&&r.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[e.trustLabel&&r.jsx(Ye,{tone:Xe(e.trustLabel),children:Ke(e.trustLabel)}),e.freshness&&r.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)"},children:["Fresh as of ",en(e.freshness)]})]}),r.jsx("ol",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:7},children:d.map((f,h)=>r.jsxs("li",{style:{display:"flex",gap:9,alignItems:"flex-start",paddingLeft:2},children:[r.jsx("span",{"aria-hidden":!0,style:{marginTop:3,width:7,height:7,borderRadius:999,flexShrink:0,background:"var(--accent, currentColor)",opacity:.7}}),r.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:2},children:[r.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-tertiary, inherit)"},children:Jt[f.kind]}),r.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:"var(--text-primary, inherit)",overflowWrap:"anywhere"},children:f.name}),f.status&&r.jsx(Ye,{tone:Xe(f.status),children:Ke(f.status)})]}),(f.owner||f.detail)&&r.jsxs("div",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:[f.owner&&r.jsxs("span",{children:["Owner: ",f.owner,". "]}),f.detail]})]})]},`${f.kind}-${f.name}-${h}`))}),u>0&&r.jsxs("button",{type:"button",onClick:()=>c(f=>Math.min(e.steps.length,f+1)),style:{alignSelf:"flex-start",border:"1px solid var(--border-default, rgba(127,127,127,0.3))",borderRadius:6,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 9px",fontSize:11,fontWeight:700},children:["Show next step (",u," more)"]}),e.caveats&&e.caveats.length>0&&r.jsxs("div",{style:{borderLeft:"3px solid var(--status-warning, #d29922)",background:"var(--status-warning-bg, rgba(210,153,34,0.08))",borderRadius:6,padding:"8px 10px",display:"flex",flexDirection:"column",gap:4},children:[r.jsx("span",{style:{fontSize:10,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--status-warning, inherit)"},children:"Caveats"}),e.caveats.map((f,h)=>r.jsx("span",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:f},h))]})]})]})}function Ke(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function en(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString()}/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -25,8 +25,8 @@ import{R as te,j as r,b8 as Ye,c as le,r as R,t as q,u as Ht,a as Ot,b9 as Ze,L
|
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
26
|
*/const an=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],ao=le("pencil",an),cn=/date|time|_at$|_on$|timestamp/i;function dn(e){return typeof e=="number"||typeof e=="string"&&e!==""&&!isNaN(Number(e))}function un(e,t){if(cn.test(e))return"date";const n=t.slice(0,40).map(i=>i[e]).filter(i=>i!=null);return n.length===0?"string":n.every(i=>typeof i=="boolean")?"bool":n.every(i=>typeof i=="object")?"json":n.filter(dn).length/n.length>.8?"numeric":"string"}function co(e){return e==="numeric"?"measure":e==="date"?"temporal":"dimension"}const Je=/(?:^|_)(?:revenue|sales|spend|amount|price|cost|profit|margin|income|expense|balance|budget|bookings|arr|mrr|gmv|fee|fees|charge|charges|tax|value)(?:_|$)/i,xn=/(?:^|_)(?:percent|percentage|pct|ratio|share|conversion|churn|retention|utilization)(?:_|$)/i,pn=/(?:^|_)(?:count|orders?|customers?|accounts?|users?|products?|items?|units?|quantity|rank|position|days?|months?|years?|distinct)(?:_|$)/i,Ce=/(?:^|_)(?:average|avg|mean)(?:_|$)/i,fn=/(?:^|_)(?:year|yr)$/i,hn=/(?:^|_)(?:month|monthly|month_num|month_number|month_of_year)$/i,mn=/(?:^|_)(?:date|day|month|quarter|year|time|timestamp|daily|weekly|monthly|quarterly|yearly|hourly)(?:_|$)|_(?:at|on)$/i,mt=/^(\d{4})-(\d{2})$/,oe=/^(\d{4})-(\d{2})-(\d{2})$/,xe=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?$/,yt=/^(\d{1,2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?Z?$/;function _e(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()!==""&&Number.isFinite(Number(e)))return Number(e)}function yn(e){if(e==="currency"||e==="percent"||e==="number")return e;if(e==="duration")return"number"}function gn(e,t=[],n){const o=yn(n);if(o)return o;if(hn.test(e))return"month";if(fn.test(e))return"year";if(mn.test(e))return"date";if(Ce.test(e)&&Je.test(e))return"currency";if(xn.test(e))return"percent";if(Ce.test(e))return"number";if(pn.test(e))return"integer";if(Je.test(e))return"currency";const i=t.filter(s=>s!=null&&s!=="");return i.length===0?"text":i.every(s=>typeof s=="boolean")?"boolean":i.every(s=>_e(s)!==void 0)?"number":i.every(s=>typeof s=="string"&&mt.test(s))?"month":i.every(s=>typeof s=="string"&&(oe.test(s)||xe.test(s)||yt.test(s)))?"date":i.every(s=>typeof s=="object")?"json":"text"}function bn(e,t=!1){return e?{notation:"compact",maximumFractionDigits:1}:t?{maximumFractionDigits:0}:{maximumFractionDigits:2}}function pe(e,t,n=[],o={}){if(t==null)return"";const i=gn(e,n,o.format),s=_e(t);if(i==="year"){const l=typeof t=="string"&&(oe.test(t)||xe.test(t))?Number(t.slice(0,4)):s;if(l!==void 0&&Number.isInteger(l))return new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:0}).format(l)}if(i==="month"){const l=jn(t);if(l)return l}if(i==="date"&&typeof t=="string"){const l=Sn(t);if(l)return l}if(s!==void 0){if(i==="currency")return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",...o.compact?{notation:"compact",maximumFractionDigits:1}:{minimumFractionDigits:2,maximumFractionDigits:2}}).format(s);if(i==="percent"){const l=Math.abs(s)<=1?s:s/100;return new Intl.NumberFormat("en-US",{style:"percent",maximumFractionDigits:2}).format(l)}return new Intl.NumberFormat("en-US",bn(!!o.compact,i==="integer")).format(s)}return i==="boolean"?t?"Yes":"No":i==="json"||typeof t=="object"?JSON.stringify(t):String(t)}function vn(e,t,n){return pe(e,t,[t],{compact:!0,format:n})}function jn(e){const t=_e(e);if(t!==void 0&&Number.isInteger(t)&&t>=1&&t<=12)return new Intl.DateTimeFormat("en-US",{month:"short",timeZone:"UTC"}).format(new Date(Date.UTC(2e3,t-1,1)));if(typeof e!="string")return;const n=mt.exec(e),o=oe.exec(e)??(xe.test(e)?oe.exec(e.slice(0,10)):null),i=n??o;if(!i)return;const s=Number(i[1]),l=Number(i[2]);if(!(l<1||l>12))return new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",timeZone:"UTC"}).format(new Date(Date.UTC(s,l-1,1)))}function Sn(e){const t=yt.exec(e);if(t){const l=Number(t[1]),c=Number(t[2]),a=Number(t[3]??0);return l>23||c>59||a>59?void 0:new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"2-digit",timeZone:"UTC"}).format(new Date(Date.UTC(2e3,0,1,l,c,a)))}const n=oe.exec(e);if(n)return new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",timeZone:"UTC"}).format(new Date(Date.UTC(Number(n[1]),Number(n[2])-1,Number(n[3]))));if(!xe.test(e))return;const o=/(?:Z|[+-]\d{2}:?\d{2})$/.test(e),i=new Date(o?e:`${e}Z`);if(Number.isNaN(i.getTime()))return;const s=i.getUTCHours()===0&&i.getUTCMinutes()===0&&i.getUTCSeconds()===0;return new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",...s?{}:{hour:"numeric",minute:"2-digit"},timeZone:"UTC"}).format(i)}const et=[10,25,50,100,500];function $e(e){return typeof e=="number"?!0:typeof e=="string"?!isNaN(Number(e))&&e.trim()!=="":!1}function wn(e){switch(e){case"numeric":return{icon:"#",color:"#79c0ff"};case"date":return{icon:"D",color:"#e3b341"};case"bool":return{icon:"B",color:"#a371f7"};case"json":return{icon:"{}",color:"#ff7b72"};case"string":default:return{icon:"A",color:"#56d364"}}}function $n(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Mn(e,t){return e==null?1:t==null?-1:$e(e)&&$e(t)?Number(e)-Number(t):String(e).localeCompare(String(t))}function kn(e,t){const n=l=>l.includes(",")||l.includes('"')||l.includes(`
|
|
27
27
|
`)?`"${l.replace(/"/g,'""')}"`:l,o=e.columns.map(n).join(","),i=e.rows.map(l=>e.columns.map(c=>n($n(l[c]))).join(",")),s=[o,...i].join(`
|
|
28
|
-
`);gt(s,"export.csv","text/csv")}function An(e,t){const n=JSON.stringify(e.rows,null,2);gt(n,"export.json","application/json")}function gt(e,t,n){const o=new Blob([e],{type:n}),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Bn({dir:e,color:t}){return e?r.jsx("svg",{width:"8",height:"10",viewBox:"0 0 8 10",fill:t,style:{marginLeft:3,flexShrink:0},children:e==="asc"?r.jsx("path",{d:"M4 0L7 4H1L4 0Z"}):r.jsx("path",{d:"M4 10L1 6H7L4 10Z"})}):r.jsxs("svg",{width:"8",height:"10",viewBox:"0 0 8 10",fill:t,opacity:.3,style:{marginLeft:3,flexShrink:0},children:[r.jsx("path",{d:"M4 0L7 3.5H1L4 0Z"}),r.jsx("path",{d:"M4 10L1 6.5H7L4 10Z"})]})}function ie({result:e,themeMode:t,maxHeight:n=440,initialPageSize:o=50}){const i=q[t],[s,l]=R.useState(null),[c,a]=R.useState(null),[d,u]=R.useState(null),[f,h]=R.useState(""),[p,y]=R.useState(et.includes(o)?o:50),[j,b]=R.useState(0),g=R.useCallback(w=>{c===w?d==="asc"?u("desc"):d==="desc"?(a(null),u(null)):u("asc"):(a(w),u("asc")),b(0)},[c,d]),v=R.useMemo(()=>{if(!f.trim())return e.rows;const w=f.toLowerCase();return e.rows.filter(I=>e.columns.some(W=>{const $=I[W];return $==null?!1:String($).toLowerCase().includes(w)}))},[e.rows,e.columns,f]),m=R.useMemo(()=>{if(!c||!d)return v;const w=[...v];return w.sort((I,W)=>{const $=Mn(I[c],W[c]);return d==="desc"?-$:$}),w},[v,c,d]),A=R.useMemo(()=>{const w=new Map;for(const I of e.columns)w.set(I,un(I,e.rows));return w},[e.columns,e.rows]),T=R.useMemo(()=>new Map(e.columns.map(w=>[w,e.rows.map(I=>I[w])])),[e.columns,e.rows]),[_,x]=R.useState(!1),M=Math.max(1,Math.ceil(m.length/p)),S=Math.min(j,M-1),B=m.slice(S*p,(S+1)*p),z=m.length===0?0:S*p+1,k=Math.min((S+1)*p,m.length);return e.columns.length===0?r.jsx("div",{style:{padding:"12px 16px",color:i.textMuted,fontSize:12,fontFamily:i.font,fontStyle:"italic"},children:"Query executed successfully. No columns to display."}):r.jsxs("div",{children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 8px",borderBottom:`1px solid ${i.tableBorder}`,background:`${i.tableHeaderBg}60`,flexWrap:"wrap"},children:[r.jsxs("div",{style:{position:"relative",flex:"0 1 200px",minWidth:120},children:[r.jsx("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:i.textMuted,style:{position:"absolute",left:6,top:6},children:r.jsx("path",{d:"M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"})}),r.jsx("input",{value:f,onChange:w=>{h(w.target.value),b(0)},placeholder:"Filter rows...",style:{width:"100%",background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:4,color:i.textPrimary,fontSize:11,fontFamily:i.font,padding:"3px 8px 3px 22px",outline:"none"}}),f&&r.jsx("button",{onClick:()=>h(""),style:{position:"absolute",right:4,top:3,background:"none",border:"none",color:i.textMuted,cursor:"pointer",fontSize:12,padding:"0 2px"},children:"×"})]}),r.jsx("span",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:f?`Showing ${z}–${k} of ${m.length} matching (${e.rows.length} total)`:`Showing ${z}–${k} of ${e.rows.length} ${e.rows.length===1?"row":"rows"}`}),r.jsx("div",{style:{flex:1}}),r.jsx(tt,{label:"CSV",onClick:()=>kn(e),t:i}),r.jsx(tt,{label:"JSON",onClick:()=>An(e),t:i}),r.jsx("select",{value:p,onChange:w=>{y(Number(w.target.value)),b(0)},style:{background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:3,color:i.textSecondary,fontSize:10,fontFamily:i.font,padding:"2px 4px",outline:"none"},children:et.map(w=>r.jsxs("option",{value:w,children:[w," / page"]},w))}),M>1&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[r.jsx(ee,{disabled:S===0,onClick:()=>b(0),t:i,children:"«"}),r.jsx(ee,{disabled:S===0,onClick:()=>b(S-1),t:i,children:"‹"}),r.jsxs("span",{style:{fontSize:10,color:i.textSecondary,fontFamily:i.font,padding:"0 4px"},children:[S+1,"/",M]}),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(S+1),t:i,children:"›"}),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(M-1),t:i,children:"»"})]})]}),r.jsx("div",{style:{maxHeight:n,overflow:"auto",position:"relative"},onScroll:w=>x(w.target.scrollTop>0),children:r.jsxs("table",{style:{width:"100%",borderCollapse:"separate",borderSpacing:0,tableLayout:"auto",fontSize:12.5,fontFamily:i.fontMono},children:[r.jsx("thead",{children:r.jsx("tr",{children:e.columns.map(w=>{const I=A.get(w)??"string",W=I==="numeric";return r.jsx("th",{onClick:()=>g(w),style:{background:i.tableHeaderBg,color:i.textSecondary,fontWeight:600,fontSize:11,textAlign:W?"right":"left",padding:"8px 14px",borderBottom:`1px solid ${i.tableBorder}`,minWidth:80,maxWidth:320,whiteSpace:"nowrap",position:"sticky",top:0,zIndex:1,fontFamily:i.font,letterSpacing:"0.03em",overflow:"hidden",textOverflow:"ellipsis",cursor:"pointer",userSelect:"none",boxShadow:_?"0 2px 4px -2px rgba(0,0,0,0.18)":"none",transition:"background 0.1s, box-shadow 0.18s"},children:r.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,justifyContent:W?"flex-end":"flex-start"},children:[(()=>{const $=wn(I);return r.jsx("span",{title:I,style:{fontSize:9,fontFamily:i.fontMono,fontWeight:700,color:$.color,background:`${$.color}15`,border:`1px solid ${$.color}40`,borderRadius:3,padding:"0 4px",minWidth:14,textAlign:"center",lineHeight:"14px",flexShrink:0},children:$.icon})})(),r.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:w}),r.jsx(Bn,{dir:c===w?d:null,color:c===w?i.accent:i.textMuted})]})},w)})})}),r.jsx("tbody",{children:B.map((w,I)=>{const W=s===I,D=I%2===1?i.tableHeaderBg:"transparent";return r.jsx("tr",{onMouseEnter:()=>l(I),onMouseLeave:()=>l(null),style:{transition:"background 0.1s"},children:e.columns.map(P=>{const O=w[P],L=O==null,F=$e(O);return r.jsx("td",{style:{padding:"7px 14px",borderBottom:`1px solid ${i.tableBorder}`,background:W?i.tableRowHover:D,color:L?i.textMuted:i.textPrimary,fontStyle:L?"italic":"normal",fontVariantNumeric:F?"tabular-nums":"normal",textAlign:F?"right":"left",whiteSpace:"nowrap",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",transition:"background 0.1s"},children:L?"—":pe(P,O,T.get(P)??[])},P)})},I)})})]})}),r.jsxs("div",{style:{padding:"5px 10px",color:i.textMuted,fontSize:10,fontFamily:i.font,borderTop:`1px solid ${i.tableBorder}`,background:`${i.tableHeaderBg}60`,display:"flex",alignItems:"center",gap:4},children:[M>1&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[r.jsx(ee,{disabled:S===0,onClick:()=>b(S-1),t:i,children:"‹"}),zn(M,S).map((w,I)=>w==="…"?r.jsx("span",{style:{color:i.textMuted,fontSize:10,padding:"0 2px"},children:"…"},`gap-${I}`):r.jsx("button",{onClick:()=>b(w-1),style:{background:w-1===S?`${i.accent}20`:"transparent",border:"none",color:w-1===S?i.accent:i.textSecondary,fontSize:10,fontFamily:i.font,fontWeight:w-1===S?700:400,padding:"1px 6px",borderRadius:3,cursor:"pointer",minWidth:20},children:w},w)),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(S+1),t:i,children:"›"})]}),r.jsx("div",{style:{flex:1}}),r.jsxs("span",{style:{fontSize:10,color:i.textSecondary,fontFamily:i.font,marginLeft:6,whiteSpace:"nowrap"},children:[m.length.toLocaleString()," ",m.length===1?"row":"rows",f&&e.rows.length!==m.length&&` of ${e.rows.length.toLocaleString()}`]})]})]})}function zn(e,t){if(e<=7)return Array.from({length:e},(i,s)=>s+1);const n=t+1,o=[1];n>3&&o.push("…");for(let i=Math.max(2,n-1);i<=Math.min(e-1,n+1);i++)o.push(i);return n<e-2&&o.push("…"),o.push(e),o}function tt({label:e,onClick:t,t:n}){const[o,i]=R.useState(!1);return r.jsxs("button",{onClick:t,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{background:o?n.btnHover:"transparent",border:`1px solid ${o?n.btnBorder:"transparent"}`,borderRadius:3,cursor:"pointer",color:o?n.textSecondary:n.textMuted,fontSize:10,fontFamily:n.font,fontWeight:600,padding:"2px 6px",transition:"all 0.15s",display:"flex",alignItems:"center",gap:3},children:[r.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 16 16",fill:"currentColor",children:[r.jsx("path",{d:"M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z"}),r.jsx("path",{d:"M7.25 7.689V2a.75.75 0 0 1 1.5 0v5.689l1.97-1.97a.749.749 0 1 1 1.06 1.06l-3.25 3.25a.749.749 0 0 1-1.06 0L4.22 6.779a.749.749 0 1 1 1.06-1.06l1.97 1.97Z"})]}),e]})}function ee({disabled:e,onClick:t,children:n,t:o}){return r.jsx("button",{disabled:e,onClick:t,style:{background:"transparent",border:"none",cursor:e?"default":"pointer",color:e?o.textMuted:o.textSecondary,fontSize:12,fontFamily:o.font,padding:"0 3px",opacity:e?.4:1,transition:"opacity 0.1s"},children:n})}const Me=[{value:"bar",label:"Bar"},{value:"grouped-bar",label:"Grouped Bar"},{value:"stacked-bar",label:"Stacked Bar"},{value:"line",label:"Line"},{value:"area",label:"Area"},{value:"scatter",label:"Scatter"},{value:"pie",label:"Pie"},{value:"donut",label:"Donut"},{value:"heatmap",label:"Heatmap"},{value:"histogram",label:"Histogram"},{value:"funnel",label:"Funnel"},{value:"sankey",label:"Sankey"},{value:"waterfall",label:"Waterfall"},{value:"gauge",label:"Gauge"},{value:"kpi",label:"KPI"}],bt=/date|time|at|day|month|year/i,vt=/^(label|name|category|status|type|group)$/i,jt=/^(value|count|total|revenue|amount|sum|avg|price|quantity|sales)$/i;function G(e){return typeof e=="number"?!0:typeof e=="string"?e.trim()!==""&&!isNaN(Number(e)):!1}function Tn(e){return typeof e=="string"||typeof e=="number"}const _n=new Set(["bar","line","area","pie","donut","scatter","heatmap","funnel","waterfall","histogram","gauge","stacked-bar","grouped-bar","sankey","kpi","table"]);function St(e,t){if(t!=null&&t.chart){const n=t.chart.toLowerCase().replace(/_/g,"-");if(_n.has(n))return n}return Ln(e)}function Ln(e){const{columns:t,rows:n}=e;if(t.length<2||n.length===0)return"table";const o=t[0],i=t[1],s=n.slice(0,5),l=s.every(f=>G(f[i])),c=s.every(f=>Tn(f[o]));if(bt.test(o)&&l&&c)return"line";const a=t.find(f=>vt.test(f)),d=t.find(f=>jt.test(f));return a&&d&&s.every(h=>G(h[d]))?"bar":s.every(f=>G(f[o]))&&l&&t.length>=2?"scatter":t.length===2&&c&&l?"bar":"table"}const ke={default:["#388bfd","#56d364","#e3b341","#f78166","#a371f7","#39c5cf","#ffa657","#ff7b72","#89d185","#d2a8ff","#58a6ff","#3fb950"],warm:["#f85149","#f78166","#ffa657","#e3b341","#d29922","#db6d28","#ff7b72","#ffa198","#ffdfb6","#e6c174","#c4a35a","#b08c3e"],cool:["#388bfd","#58a6ff","#79c0ff","#39c5cf","#56d364","#3fb950","#a371f7","#d2a8ff","#bc8cff","#6cb6ff","#2ea043","#1f6feb"],mono:["#c9d1d9","#b1bac4","#8b949e","#6e7681","#484f58","#30363d","#21262d","#161b22","#a0a8b2","#9e9e9e","#757575","#616161"],pastel:["#b8d8f8","#b4e6c8","#f4e6a0","#f8c4a4","#d2b8f0","#a8e0e0","#f8d8a0","#f4b8b4","#c0e8c0","#e0d0f8","#a8d8f8","#b0e8b0"],corporate:["#2563eb","#16a34a","#7c3aed","#0891b2","#f59e0b","#dc2626","#475569","#0f766e","#9333ea","#0284c7","#65a30d","#ea580c"]};function Y(e){return ke[e??"default"]??ke.default}function H(e,t="value",n){return vn(t,e,n)}function Ae(e,t=8,n=!1){if(/^\d{4}-\d{2}(-\d{2})?/.test(e)){const o=/^\d{4}-\d{2}$/.test(e),i=new Date(o?`${e}-01T00:00:00Z`:e);if(!isNaN(i.getTime()))return i.toLocaleDateString("en-US",o||n?{year:"numeric",month:"short",timeZone:"UTC"}:{year:"numeric",month:"short",day:"numeric",timeZone:"UTC"})}return String(e).length>t?String(e).slice(0,t):String(e)}function Rn(e,t,n=16){return bt.test(t)||/^\d{4}-\d{2}(-\d{2})?(T|$)/.test(e)?Ae(e,n,/month/i.test(t)):e.length>n?`${e.slice(0,Math.max(1,n-1))}…`:e}function ae(e,t){const n=(t!=null&&t.x&&e.columns.includes(t.x)?t.x:void 0)??e.columns.find(i=>vt.test(i))??e.columns[0],o=(t!=null&&t.y&&e.columns.includes(t.y)?t.y:void 0)??e.columns.find(i=>jt.test(i))??e.columns[1];return{labelCol:n,valueCol:o}}const J=20;function Le({result:e,themeMode:t,chartConfig:n,availableHeight:o,availableWidth:i}){const s=q[t],[l,c]=R.useState(null),{labelCol:a,valueCol:d}=ae(e,n),u=(n==null?void 0:n.maxItems)??J,f=Y(n==null?void 0:n.colorPalette),h=e.rows.slice(0,u).map(x=>({label:String(x[a]??""),value:Number(x[d]??0)})),p=e.rows.length>u,y=Math.max(...h.map(x=>x.value),1),j=i&&i>0?Math.max(240,Math.min(720,i)):600,b=Math.min(132,Math.max(82,j*.32)),g=10,v=34,m=o&&o>0?Math.max(96,o-4):h.length*v+g*2,A=Math.max(15,Math.min(v,(m-g*2)/Math.max(1,h.length))),T=Math.max(10,A-4),_=Math.max(80,g*2+h.length*A);return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("svg",{width:"100%",height:_,viewBox:`0 0 ${j} ${_}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:h.map((x,M)=>{const S=g+M*A,B=j-b-Math.min(84,j*.22),z=Math.max(x.value/y*B,2),k=l===M,w=f[0]??s.accent;return r.jsxs("g",{onMouseEnter:()=>c(M),onMouseLeave:()=>c(null),style:{cursor:"default"},children:[r.jsx("text",{x:b-8,y:S+T/2+4,textAnchor:"end",fontSize:11,fontFamily:s.font,fill:s.textSecondary,children:Rn(x.label,a)}),r.jsx("rect",{x:b,y:S,width:z,height:T,rx:3,fill:w,opacity:k?1:.88,style:{transition:"opacity 0.15s"}}),r.jsx("text",{x:b+z+6,y:S+T/2+4,textAnchor:"start",fontSize:11,fontFamily:s.fontMono,fill:s.textMuted,children:H(x.value,d,n==null?void 0:n.format)})]},M)})}),p&&r.jsxs("div",{style:{fontSize:11,color:s.textMuted,fontFamily:s.font,fontStyle:"italic",padding:"4px 12px"},children:["Showing ",J," of ",e.rows.length," rows"]})]})}function In({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=e.rows.slice(0,5),d=e.columns.filter(v=>v!==c&&a.some(m=>G(m[v])));if(d.length===0)return r.jsx(Le,{result:e,themeMode:t,chartConfig:n});const u=e.rows.slice(0,J).map(v=>String(v[c]??"")),f=Math.max(...e.rows.slice(0,J).flatMap(v=>d.map(m=>Math.abs(Number(v[m]??0)))),1),h=24,p=h/d.length,y=120,j=12,b=8,g=u.length*(h+b)+j*2;return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:d.map((v,m)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:l[m%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:v})]},v))}),r.jsx("svg",{width:"100%",height:g,viewBox:`0 0 600 ${g}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:u.map((v,m)=>{const A=j+m*(h+b),T=e.rows[m];return r.jsxs("g",{children:[r.jsx("text",{x:y-8,y:A+h/2+4,textAnchor:"end",fontSize:11,fontFamily:o.font,fill:o.textSecondary,children:v.length>16?v.slice(0,15)+"…":v}),d.map((_,x)=>{const M=Number(T[_]??0),S=600-y-60,B=Math.max(Math.abs(M)/f*S,1),z=A+x*p,k=`${m}-${x}`;return r.jsxs("g",{onMouseEnter:()=>s(k),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:y,y:z,width:B,height:p-1,rx:2,fill:l[x%l.length],opacity:i===k?1:.85,style:{transition:"opacity 0.15s"}}),i===k&&r.jsx("text",{x:y+B+4,y:z+p/2+3,fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(M,_,n==null?void 0:n.format)})]},x)})]},m)})})]})}function Wn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=e.rows.slice(0,5),d=e.columns.filter(v=>v!==c&&a.some(m=>G(m[v])));if(d.length===0)return r.jsx(Le,{result:e,themeMode:t,chartConfig:n});const u=e.rows.slice(0,J),f=u.map(v=>String(v[c]??"")),h=Math.max(...u.map(v=>d.reduce((m,A)=>m+Math.abs(Number(v[A]??0)),0)),1),p=28,y=120,j=12,b=6,g=f.length*(p+b)+j*2;return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:d.map((v,m)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:l[m%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:v})]},v))}),r.jsx("svg",{width:"100%",height:g,viewBox:`0 0 600 ${g}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:f.map((v,m)=>{const A=j+m*(p+b),T=u[m],_=600-y-60;let x=y;return r.jsxs("g",{children:[r.jsx("text",{x:y-8,y:A+p/2+4,textAnchor:"end",fontSize:11,fontFamily:o.font,fill:o.textSecondary,children:v.length>16?v.slice(0,15)+"…":v}),d.map((M,S)=>{const B=Math.abs(Number(T[M]??0)),z=Math.max(B/h*_,0),k=x;x+=z;const w=`${m}-${S}`;return r.jsxs("g",{onMouseEnter:()=>s(w),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:k,y:A,width:z,height:p,rx:S===0?3:0,fill:l[S%l.length],opacity:i===w?1:.85,style:{transition:"opacity 0.15s"}}),i===w&&z>30&&r.jsx("text",{x:k+z/2,y:A+p/2+4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:"#fff",fontWeight:600,children:H(B,M,n==null?void 0:n.format)})]},S)})]},m)})})]})}function nt({result:e,themeMode:t,showArea:n,chartConfig:o,availableHeight:i,availableWidth:s}){const l=q[t],[c,a]=R.useState(null),u=Y(o==null?void 0:o.colorPalette)[0]??l.accent,{labelCol:f,valueCol:h}=ae(e,o),p=e.rows.map(L=>({label:String(L[f]??""),value:Number(L[h]??0)}));if(p.length<2)return null;const y=s&&s>0?Math.max(240,Math.min(720,s)):560,j=i&&i>0?Math.max(150,Math.min(320,i-4)):212,b=y<360,g=b?44:56,v=b?8:16,m=16,A=48,T=y-g-v,_=j-m-A,x=Math.min(...p.map(L=>L.value)),S=Math.max(...p.map(L=>L.value))-x||1,B=T/(p.length-1),z=L=>g+L*B,k=L=>m+_-(L-x)/S*_,w=p.map((L,F)=>({x:z(F),y:k(L.value)})),I=w.reduce((L,F,V)=>{if(V===0)return`M ${F.x},${F.y}`;const Z=w[V-1],X=Z.x+(F.x-Z.x)/2;return`${L} C ${X},${Z.y} ${X},${F.y} ${F.x},${F.y}`},""),W=`${I} L ${w[w.length-1].x},${m+_} L ${g},${m+_} Z`,$=b?4:5,D=Array.from({length:$+1},(L,F)=>{const V=x+S*F/$;return{val:V,y:k(V)}}),P=Math.ceil(p.length/8),O=b?[...new Set(y<300?[0,p.length-1]:[0,Math.floor((p.length-1)/2),p.length-1])]:p.map((L,F)=>F).filter(L=>L%P===0||L===p.length-1);return r.jsx("div",{style:{position:"relative",padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:j,viewBox:`0 0 ${y} ${j}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},onMouseLeave:()=>a(null),children:[D.map((L,F)=>r.jsxs("g",{children:[r.jsx("line",{x1:g,y1:L.y,x2:g+T,y2:L.y,stroke:l.tableBorder,strokeWidth:.5}),r.jsx("text",{x:g-6,y:L.y+4,textAnchor:"end",fontSize:10,fontFamily:l.fontMono,fill:l.textMuted,children:H(L.val,h,o==null?void 0:o.format)})]},F)),r.jsx("path",{d:W,fill:u,opacity:n?.3:.15}),r.jsx("path",{d:I,fill:"none",stroke:u,strokeWidth:2,strokeLinejoin:"round"}),w.map((L,F)=>r.jsx("circle",{cx:L.x,cy:L.y,r:3,fill:u,style:{cursor:"crosshair"},onMouseEnter:()=>a({x:L.x,y:L.y,label:p[F].label,value:p[F].value})},F)),O.map(L=>{const F=p[L];return r.jsx("text",{x:z(L),y:m+_+16,textAnchor:L===0?"start":L===p.length-1?"end":"middle",fontSize:10,fontFamily:l.font,fill:l.textMuted,children:Ae(F.label)},L)}),r.jsx("line",{x1:g,y1:m,x2:g,y2:m+_,stroke:l.tableBorder,strokeWidth:1}),r.jsx("line",{x1:g,y1:m+_,x2:g+T,y2:m+_,stroke:l.tableBorder,strokeWidth:1}),r.jsx("text",{x:g+T/2,y:j-4,textAnchor:"middle",fontSize:10,fontWeight:600,fontFamily:l.font,fill:l.textMuted,letterSpacing:"0.04em",children:f}),b?null:r.jsx("text",{x:12,y:m+_/2,textAnchor:"middle",fontSize:10,fontWeight:600,fontFamily:l.font,fill:l.textMuted,letterSpacing:"0.04em",transform:`rotate(-90, 12, ${m+_/2})`,children:h}),c&&r.jsxs("g",{children:[r.jsx("rect",{x:c.x+8,y:c.y-20,width:90,height:32,rx:4,fill:l.cellBg,stroke:l.cellBorder,strokeWidth:1}),r.jsx("text",{x:c.x+13,y:c.y-8,fontSize:10,fontFamily:l.font,fill:l.textSecondary,children:Ae(c.label,12)}),r.jsx("text",{x:c.x+13,y:c.y+6,fontSize:11,fontFamily:l.fontMono,fill:l.textPrimary,fontWeight:600,children:H(c.value,h,o==null?void 0:o.format)})]})]})})}function Dn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=n!=null&&n.y&&e.columns.includes(n.y)?n.y:e.columns[1],d=n!=null&&n.color&&e.columns.includes(n.color)?n.color:void 0,u=e.rows.slice(0,200).map(k=>({x:Number(k[c]??0),y:Number(k[a]??0),color:d?String(k[d]??""):void 0})),f=560,h=300,p=52,y=16,j=16,b=36,g=f-p-y,v=h-j-b,m=Math.min(...u.map(k=>k.x)),A=Math.max(...u.map(k=>k.x)),T=Math.min(...u.map(k=>k.y)),_=Math.max(...u.map(k=>k.y)),x=A-m||1,M=_-T||1,S=k=>p+(k-m)/x*g,B=k=>j+v-(k-T)/M*v,z=d?[...new Set(u.map(k=>k.color))]:[];return r.jsxs("div",{style:{padding:"8px 0"},children:[d&&z.length>0&&r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:z.slice(0,12).map((k,w)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:l[w%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:k})]},k))}),r.jsxs("svg",{width:"100%",height:h,viewBox:`0 0 ${f} ${h}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:6},(k,w)=>{const I=T+M*w/5,W=B(I);return r.jsxs("g",{children:[r.jsx("line",{x1:p,y1:W,x2:p+g,y2:W,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:p-6,y:W+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(I,a,n==null?void 0:n.format)})]},w)}),Array.from({length:6},(k,w)=>{const I=m+x*w/5,W=S(I);return r.jsx("text",{x:W,y:j+v+16,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(I,c)},w)}),r.jsx("line",{x1:p,y1:j,x2:p,y2:j+v,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:p,y1:j+v,x2:p+g,y2:j+v,stroke:o.tableBorder,strokeWidth:1}),r.jsx("text",{x:p+g/2,y:h-2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,children:c}),r.jsx("text",{x:10,y:j+v/2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,transform:`rotate(-90, 10, ${j+v/2})`,children:a}),u.map((k,w)=>{const I=d?z.indexOf(k.color):0;return r.jsx("circle",{cx:S(k.x),cy:B(k.y),r:i===w?5:3.5,fill:l[I%l.length],opacity:i===w?1:.7,style:{cursor:"crosshair",transition:"r 0.1s, opacity 0.1s"},onMouseEnter:()=>s(w),onMouseLeave:()=>s(null)},w)}),i!==null&&r.jsxs("g",{children:[r.jsx("rect",{x:S(u[i].x)+8,y:B(u[i].y)-24,width:100,height:28,rx:4,fill:o.cellBg,stroke:o.cellBorder,strokeWidth:1}),r.jsxs("text",{x:S(u[i].x)+13,y:B(u[i].y)-8,fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:["(",H(u[i].x,c),", ",H(u[i].y,a,n==null?void 0:n.format),")"]})]})]})]})}const Fn=12;function rt({result:e,themeMode:t,chartConfig:n,isDonut:o}){const i=q[t],[s,l]=R.useState(null),{labelCol:c,valueCol:a}=ae(e,n),d=Y(n==null?void 0:n.colorPalette),u=e.rows.slice(0,Fn).map(m=>({label:String(m[c]??""),value:Math.abs(Number(m[a]??0))})),f=u.reduce((m,A)=>m+A.value,0)||1,h=90,p=90,y=70,j=o?40:0,b=[];let g=-Math.PI/2;u.forEach((m,A)=>{const T=m.value/f*2*Math.PI,_=g,x=g+T,M=h+y*Math.cos(_),S=p+y*Math.sin(_),B=h+y*Math.cos(x),z=p+y*Math.sin(x),k=T>Math.PI?1:0;let w;if(j>0){const I=h+j*Math.cos(_),W=p+j*Math.sin(_),$=h+j*Math.cos(x),D=p+j*Math.sin(x);w=`M ${M} ${S} A ${y} ${y} 0 ${k} 1 ${B} ${z} L ${$} ${D} A ${j} ${j} 0 ${k} 0 ${I} ${W} Z`}else w=`M ${h} ${p} L ${M} ${S} A ${y} ${y} 0 ${k} 1 ${B} ${z} Z`;b.push({path:w,color:d[A%d.length],label:m.label,value:m.value,pct:m.value/f*100}),g=x});const v=s!==null?b[s]:null;return r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"8px 12px",flexWrap:"wrap"},children:[r.jsxs("svg",{width:180,height:180,style:{flexShrink:0},onMouseLeave:()=>l(null),children:[b.map((m,A)=>r.jsx("path",{d:m.path,fill:m.color,opacity:s===null||s===A?1:.55,style:{cursor:"pointer",transition:"opacity 0.15s"},onMouseEnter:()=>l(A)},A)),o&&r.jsxs(r.Fragment,{children:[r.jsx("text",{x:h,y:p-5,textAnchor:"middle",fontSize:11,fontFamily:i.fontMono,fill:i.textSecondary,children:H(v?v.value:f,a,n==null?void 0:n.format)}),r.jsx("text",{x:h,y:p+9,textAnchor:"middle",fontSize:9,fontFamily:i.font,fill:i.textMuted,children:v?`${v.pct.toFixed(1)}%`:"total"})]})]}),r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:180,overflowY:"auto",flex:1},children:b.map((m,A)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,cursor:"default",opacity:s===null||s===A?1:.5},onMouseEnter:()=>l(A),onMouseLeave:()=>l(null),children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:m.color,flexShrink:0}}),r.jsx("span",{style:{fontSize:11,fontFamily:i.font,color:i.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.label}),r.jsxs("span",{style:{fontSize:11,fontFamily:i.fontMono,color:i.textMuted,marginLeft:"auto",flexShrink:0},children:[m.pct.toFixed(1),"%"]})]},A))})]})}function Nn({result:e,themeMode:t}){const n=q[t],[o,i]=R.useState(null),s=e.columns[0],l=e.columns.slice(1),c=e.rows.slice(0,30),a=c.flatMap(b=>l.map(g=>Number(b[g]??0))),d=Math.min(...a),f=Math.max(...a)-d||1,h=Math.min(50,480/l.length),p=24,y=100;function j(b){const g=(b-d)/f,v=Math.round(56+g*192),m=Math.round(139+g*-58),A=Math.round(253+g*-180);return`rgb(${v},${m},${A})`}return r.jsx("div",{style:{padding:"8px 0",overflowX:"auto"},children:r.jsxs("svg",{width:y+l.length*h+20,height:c.length*p+p+16,style:{display:"block",overflow:"visible"},children:[l.map((b,g)=>r.jsx("text",{x:y+g*h+h/2,y:14,textAnchor:"middle",fontSize:9,fontFamily:n.font,fill:n.textMuted,transform:`rotate(-30, ${y+g*h+h/2}, 14)`,children:b.length>8?b.slice(0,7)+"…":b},g)),c.map((b,g)=>{const v=String(b[s]??""),m=p+g*p;return r.jsxs("g",{children:[r.jsx("text",{x:y-6,y:m+p/2+4,textAnchor:"end",fontSize:10,fontFamily:n.font,fill:n.textSecondary,children:v.length>14?v.slice(0,13)+"…":v}),l.map((A,T)=>{const _=Number(b[A]??0),x=(o==null?void 0:o.r)===g&&(o==null?void 0:o.c)===T;return r.jsxs("g",{onMouseEnter:()=>i({r:g,c:T}),onMouseLeave:()=>i(null),children:[r.jsx("rect",{x:y+T*h,y:m,width:h-1,height:p-1,rx:2,fill:j(_),opacity:x?1:.85,stroke:x?n.accent:"none",strokeWidth:x?1.5:0}),x&&r.jsx("text",{x:y+T*h+h/2,y:m+p/2+4,textAnchor:"middle",fontSize:10,fontFamily:n.fontMono,fill:"#fff",fontWeight:600,children:H(_,A)})]},T)})]},g)})]})})}function Pn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),c=Y(n==null?void 0:n.colorPalette)[0]??o.accent,a=(n!=null&&n.x&&e.columns.includes(n.x)?n.x:void 0)??e.columns.find(B=>e.rows.slice(0,5).some(z=>G(z[B])))??e.columns[0],d=e.rows.map(B=>Number(B[a]??0)).filter(B=>!isNaN(B));if(d.length===0)return null;const u=Math.min(20,Math.max(5,Math.ceil(Math.sqrt(d.length)))),f=Math.min(...d),y=(Math.max(...d)-f||1)/u,j=Array.from({length:u},(B,z)=>({low:f+z*y,high:f+(z+1)*y,count:0}));d.forEach(B=>{const z=Math.min(Math.floor((B-f)/y),u-1);j[z].count++});const b=Math.max(...j.map(B=>B.count),1),g=560,v=200,m=52,A=16,T=16,_=36,x=g-m-A,M=v-T-_,S=x/u;return r.jsx("div",{style:{padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:v,viewBox:`0 0 ${g} ${v}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:5},(B,z)=>{const k=b*(z+1)/5,w=T+M-k/b*M;return r.jsxs("g",{children:[r.jsx("line",{x1:m,y1:w,x2:m+x,y2:w,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:m-6,y:w+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:Math.round(k)})]},z)}),j.map((B,z)=>{const k=B.count/b*M,w=m+z*S,I=T+M-k,W=i===z;return r.jsxs("g",{onMouseEnter:()=>s(z),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:w+1,y:I,width:S-2,height:k,rx:1,fill:c,opacity:W?1:.85,style:{transition:"opacity 0.1s"}}),W&&r.jsx("text",{x:w+S/2,y:I-4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:B.count})]},z)}),j.filter((B,z)=>z%Math.ceil(u/6)===0).map((B,z)=>{const k=j.indexOf(B);return r.jsx("text",{x:m+k*S+S/2,y:T+M+16,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(B.low,a,n==null?void 0:n.format)},z)}),r.jsx("line",{x1:m,y1:T,x2:m,y2:T+M,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:m,y1:T+M,x2:m+x,y2:T+M,stroke:o.tableBorder,strokeWidth:1}),r.jsx("text",{x:m+x/2,y:v-2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,children:a})]})})}function En({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),{labelCol:l,valueCol:c}=ae(e,n),a=Y(n==null?void 0:n.colorPalette),d=e.rows.slice(0,10).map(g=>({label:String(g[l]??""),value:Math.abs(Number(g[c]??0))}));if(d.length===0)return null;const u=d[0].value||1,f=400,h=36,p=4,y=16,j=d.length*(h+p)+y*2,b=f/2;return r.jsx("div",{style:{padding:"8px 0",display:"flex",justifyContent:"center"},children:r.jsx("svg",{width:f,height:j,style:{display:"block"},children:d.map((g,v)=>{const m=y+v*(h+p),A=g.value/u,T=Math.max(A*(f-80),40),_=i===v,x=v<d.length-1?d[v+1].value/u:A*.8,M=Math.max(x*(f-80),40),S=b-T/2,B=b+T/2,z=b+M/2,k=b-M/2,w=`M ${S} ${m} L ${B} ${m} L ${z} ${m+h} L ${k} ${m+h} Z`;return r.jsxs("g",{onMouseEnter:()=>s(v),onMouseLeave:()=>s(null),style:{cursor:"default"},children:[r.jsx("path",{d:w,fill:a[v%a.length],opacity:_?1:.85,style:{transition:"opacity 0.15s"}}),r.jsx("text",{x:b,y:m+h/2+1,textAnchor:"middle",fontSize:11,fontFamily:o.font,fill:"#fff",fontWeight:500,children:g.label}),r.jsxs("text",{x:b,y:m+h/2+13,textAnchor:"middle",fontSize:9,fontFamily:o.fontMono,fill:"rgba(255,255,255,0.7)",children:[H(g.value,c,n==null?void 0:n.format)," (",(A*100).toFixed(0),"%)"]})]},v)})})})}function Hn({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=Y(n==null?void 0:n.colorPalette),[s,l]=R.useState(null),c=e.rows.slice(0,20),a=e.columns.filter($=>c.some(D=>G(D[$]))),d=e.columns.filter($=>!a.includes($)),u=n!=null&&n.x&&d.includes(n.x)?n.x:d.find($=>/(?:^|_)(?:source|from|origin|upstream|supplier|producer|category)(?:_|$)/i.test($))??d[0],f=n!=null&&n.color&&d.includes(n.color)&&n.color!==u?n.color:d.find($=>$!==u&&/(?:^|_)(?:target|to|destination|downstream|consumer|customer|product)(?:_|$)/i.test($))??d.find($=>$!==u),h=n!=null&&n.y&&a.includes(n.y)?n.y:a[0];if(!u||!f||!h)return r.jsx(ie,{result:e,themeMode:t});const p=new Map;for(const $ of e.rows){const D=String($[u]??"").trim(),P=String($[f]??"").trim(),O=Math.abs(Number($[h]??0));if(!D||!P||!Number.isFinite(O)||O<=0)continue;const L=`${D}\0${P}`,F=p.get(L);p.set(L,{source:D,target:P,value:((F==null?void 0:F.value)??0)+O})}const y=[...p.values()].sort(($,D)=>D.value-$.value);if(y.length===0)return r.jsx(ie,{result:e,themeMode:t});const j=new Map,b=new Map;y.forEach($=>{j.set($.source,(j.get($.source)??0)+$.value),b.set($.target,(b.get($.target)??0)+$.value)});const g=[...j].sort(($,D)=>D[1]-$[1]).slice(0,12).map(([$])=>$),v=[...b].sort(($,D)=>D[1]-$[1]).slice(0,12).map(([$])=>$),m=new Set(g),A=new Set(v),T=y.filter($=>m.has($.source)&&A.has($.target)).slice(0,40),_=Math.max(...T.map($=>$.value),1),x=640,M=Math.max(250,Math.max(g.length,v.length)*34+40),S=132,B=x-144,z=12,k=28,w=($,D)=>D<=1?M/2:k+$*((M-k*2)/(D-1)),I=new Map(g.map(($,D)=>[$,D])),W=new Map(v.map(($,D)=>[$,D]));return r.jsx("div",{style:{padding:"8px 0",overflowX:"auto"},children:r.jsxs("svg",{role:"img","aria-label":`${u} to ${f} flow by ${h}`,width:"100%",height:M,viewBox:`0 0 ${x} ${M}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",minWidth:520},children:[r.jsx("text",{x:S,y:14,textAnchor:"middle",fontSize:10,fontWeight:700,fontFamily:o.font,fill:o.textMuted,children:u}),r.jsx("text",{x:B,y:14,textAnchor:"middle",fontSize:10,fontWeight:700,fontFamily:o.font,fill:o.textMuted,children:f}),T.map(($,D)=>{const P=w(I.get($.source)??0,g.length),O=w(W.get($.target)??0,v.length),L=`${$.source}\0${$.target}`,F=s===L,V=`M ${S+z},${P} C ${S+150},${P} ${B-150},${O} ${B},${O}`,Z=x/2,X=(P+O)/2;return r.jsxs("g",{onMouseEnter:()=>l(L),onMouseLeave:()=>l(null),children:[r.jsx("path",{d:V,fill:"none",stroke:i[D%i.length],strokeWidth:Math.max(2,$.value/_*18),opacity:s===null||F?.7:.14,strokeLinecap:"round",style:{transition:"opacity 0.15s",cursor:"default"}}),F?r.jsxs("g",{pointerEvents:"none",children:[r.jsx("rect",{x:Z-72,y:X-18,width:144,height:36,rx:5,fill:o.cellBg,stroke:o.cellBorder}),r.jsxs("text",{x:Z,y:X-3,textAnchor:"middle",fontSize:9.5,fontFamily:o.font,fill:o.textSecondary,children:[$.source," → ",$.target]}),r.jsx("text",{x:Z,y:X+11,textAnchor:"middle",fontSize:11,fontWeight:700,fontFamily:o.fontMono,fill:o.textPrimary,children:H($.value,h,n==null?void 0:n.format)})]}):null]},L)}),g.map(($,D)=>{const P=w(D,g.length);return r.jsxs("g",{children:[r.jsx("rect",{x:S,y:P-9,width:z,height:18,rx:3,fill:i[D%i.length]}),r.jsx("text",{x:S-7,y:P+3,textAnchor:"end",fontSize:10.5,fontFamily:o.font,fill:o.textSecondary,children:$.length>18?`${$.slice(0,17)}…`:$})]},`source-${$}`)}),v.map(($,D)=>{const P=w(D,v.length);return r.jsxs("g",{children:[r.jsx("rect",{x:B,y:P-9,width:z,height:18,rx:3,fill:i[(D+g.length)%i.length]}),r.jsx("text",{x:B+z+7,y:P+3,textAnchor:"start",fontSize:10.5,fontFamily:o.font,fill:o.textSecondary,children:$.length>18?`${$.slice(0,17)}…`:$})]},`target-${$}`)})]})})}function On({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),{labelCol:l,valueCol:c}=ae(e,n),a=e.rows.slice(0,15).map(S=>({label:String(S[l]??""),value:Number(S[c]??0)}));if(a.length===0)return null;let d=0;const u=a.map(S=>{const B=d;return d+=S.value,{...S,start:B,end:d}}),f=u.flatMap(S=>[S.start,S.end]),h=Math.min(0,...f),y=Math.max(0,...f)-h||1,j=560,b=240,g=52,v=16,m=16,A=44,T=j-g-v,_=b-m-A,x=T/u.length,M=S=>m+_-(S-h)/y*_;return r.jsx("div",{style:{padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:b,viewBox:`0 0 ${j} ${b}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:6},(S,B)=>{const z=h+y*B/5,k=M(z);return r.jsxs("g",{children:[r.jsx("line",{x1:g,y1:k,x2:g+T,y2:k,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:g-6,y:k+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(z,c,n==null?void 0:n.format)})]},B)}),r.jsx("line",{x1:g,y1:M(0),x2:g+T,y2:M(0),stroke:o.textMuted,strokeWidth:1,strokeDasharray:"3,3"}),u.map((S,B)=>{const z=g+B*x,k=M(Math.max(S.start,S.end)),I=M(Math.min(S.start,S.end))-k,W=S.value>=0,$=i===B;return r.jsxs("g",{onMouseEnter:()=>s(B),onMouseLeave:()=>s(null),children:[B<u.length-1&&r.jsx("line",{x1:z+x-2,y1:M(S.end),x2:z+x+2,y2:M(S.end),stroke:o.textMuted,strokeWidth:1,strokeDasharray:"2,2"}),r.jsx("rect",{x:z+4,y:k,width:x-8,height:Math.max(I,1),rx:2,fill:W?o.success:o.error,opacity:$?1:.8,style:{transition:"opacity 0.1s"}}),$&&r.jsxs("text",{x:z+x/2,y:k-4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:[S.value>=0?"+":"",H(S.value,c,n==null?void 0:n.format)]})]},B)}),u.map((S,B)=>r.jsx("text",{x:g+B*x+x/2,y:b-6,textAnchor:"middle",fontSize:9,fontFamily:o.font,fill:o.textMuted,transform:`rotate(-20, ${g+B*x+x/2}, ${b-6})`,children:S.label.length>8?S.label.slice(0,7)+"…":S.label},B)),r.jsx("line",{x1:g,y1:m,x2:g,y2:m+_,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:g,y1:m+_,x2:g+T,y2:m+_,stroke:o.tableBorder,strokeWidth:1})]})})}function qn({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=e.rows[0];if(!i)return null;const s=(n!=null&&n.y&&e.columns.includes(n.y)?n.y:void 0)??e.columns.find(M=>G(i[M]))??e.columns[0],l=Number(i[s]??0),c=(n==null?void 0:n.title)??s,a=l>100?l*1.2:100,d=Math.min(Math.max(l/a,0),1),u=120,f=110,h=80,p=Math.PI,y=0,j=p-(p-y)*d,b=u+h*Math.cos(p),g=f+h*Math.sin(p),v=u+h*Math.cos(j),m=f+h*Math.sin(j),A=d>.5?1:0,T=u+h*Math.cos(y),_=f+h*Math.sin(y),x=d<.33?o.error:d<.66?o.warning:o.success;return r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"16px 24px"},children:r.jsxs("svg",{width:240,height:140,style:{display:"block",overflow:"visible"},children:[r.jsx("path",{d:`M ${b} ${g} A ${h} ${h} 0 1 1 ${T} ${_}`,fill:"none",stroke:o.tableBorder,strokeWidth:12,strokeLinecap:"round"}),d>0&&r.jsx("path",{d:`M ${b} ${g} A ${h} ${h} 0 ${A} 1 ${v} ${m}`,fill:"none",stroke:x,strokeWidth:12,strokeLinecap:"round"}),r.jsx("text",{x:u,y:f-4,textAnchor:"middle",fontSize:28,fontFamily:o.fontMono,fill:x,fontWeight:700,children:H(l,s,n==null?void 0:n.format)}),r.jsx("text",{x:u,y:f+16,textAnchor:"middle",fontSize:11,fontFamily:o.font,fill:o.textMuted,children:c})]})})}function Un(e,t,n,o){const i=Number(t);return t==null||typeof t!="number"&&isNaN(i)?t==null?"—":String(t):pe(e,t,n,{compact:Math.abs(i)>=1e5,format:o})}function wt({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=Y(n==null?void 0:n.colorPalette),s=e.rows[0];if(!s)return null;const l=n!=null&&n.y&&e.columns.includes(n.y)?n.y:e.columns.find(a=>G(s[a]))??e.columns[0],c=Un(l,s[l],e.rows.map(a=>a[l]),n==null?void 0:n.format);return r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:54,padding:"8px 4px",boxSizing:"border-box",minWidth:0},children:r.jsx("span",{title:String(s[l]),style:{fontSize:"clamp(24px, 3.2vw, 40px)",fontWeight:750,fontFamily:o.fontMono,color:i[0]??o.accent,lineHeight:1.1,maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c})})}function Vn({config:e,columns:t,onChange:n,onClose:o,t:i}){const s={background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:4,color:i.textPrimary,fontSize:11,fontFamily:i.font,padding:"4px 8px",outline:"none",width:"100%",boxSizing:"border-box"};return r.jsxs("div",{style:{position:"absolute",top:4,right:4,zIndex:100,background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:8,padding:12,width:240,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",display:"grid",gap:8},onClick:l=>l.stopPropagation(),children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[r.jsx("span",{style:{fontSize:11,fontWeight:600,color:i.textPrimary,fontFamily:i.font},children:"Chart Settings"}),r.jsx("button",{onClick:o,style:{background:"none",border:"none",color:i.textMuted,cursor:"pointer",fontSize:14},children:"×"})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Title",r.jsx("input",{value:e.title??"",onChange:l=>n({title:l.target.value||void 0}),placeholder:"Chart title",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["X-axis label",r.jsx("input",{value:e.xLabel??"",onChange:l=>n({xLabel:l.target.value||void 0}),placeholder:"Auto",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Y-axis label",r.jsx("input",{value:e.yLabel??"",onChange:l=>n({yLabel:l.target.value||void 0}),placeholder:"Auto",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Legend",r.jsxs("select",{value:e.legendPosition??"top",onChange:l=>n({legendPosition:l.target.value}),style:{...s,marginTop:2},children:[r.jsx("option",{value:"top",children:"Top"}),r.jsx("option",{value:"bottom",children:"Bottom"}),r.jsx("option",{value:"left",children:"Left"}),r.jsx("option",{value:"right",children:"Right"}),r.jsx("option",{value:"none",children:"Hidden"})]})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Color palette",r.jsx("select",{value:e.colorPalette??"default",onChange:l=>n({colorPalette:l.target.value}),style:{...s,marginTop:2},children:Object.keys(ke).map(l=>r.jsx("option",{value:l,children:l.charAt(0).toUpperCase()+l.slice(1)},l))})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Max items",r.jsx("input",{type:"number",value:e.maxItems??J,min:5,max:200,onChange:l=>n({maxItems:parseInt(l.target.value)||J}),style:{...s,marginTop:2}})]})]})}function $t({result:e,themeMode:t,chartConfig:n,availableHeight:o,availableWidth:i,onConfigChange:s}){const l=q[t],c=St(e,n),[a,d]=R.useState(!1);return c==="kpi"?r.jsx(wt,{result:e,themeMode:t,chartConfig:n}):r.jsxs("div",{style:{position:"relative"},children:[(n==null?void 0:n.title)&&r.jsx("div",{style:{padding:"8px 12px 0",fontSize:13,fontWeight:600,color:l.textPrimary,fontFamily:l.font,textAlign:"center"},children:n.title}),s&&r.jsx("button",{onClick:()=>d(!a),title:"Chart settings",style:{position:"absolute",top:4,right:4,zIndex:50,background:a?`${l.accent}18`:"transparent",border:`1px solid ${a?l.accent:"transparent"}`,borderRadius:4,color:a?l.accent:l.textMuted,cursor:"pointer",fontSize:14,padding:"2px 6px",lineHeight:1},children:"⚙"}),a&&s&&r.jsx(Vn,{config:n??{},columns:e.columns,onChange:u=>s(u),onClose:()=>d(!1),t:l}),Qn(c,e,t,n,o,i)]})}function Qn(e,t,n,o,i,s){const l=o!=null&&o.x&&t.columns.includes(o.x)?o.x:void 0,c=o!=null&&o.y&&t.columns.includes(o.y)?o.y:void 0,a=l||c?Yn(t,l,c):t;switch(e){case"line":return r.jsx(nt,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s});case"area":return r.jsx(nt,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s,showArea:!0});case"bar":return r.jsx(Le,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s});case"grouped-bar":return r.jsx(In,{result:a,themeMode:n,chartConfig:o});case"stacked-bar":return r.jsx(Wn,{result:a,themeMode:n,chartConfig:o});case"scatter":return r.jsx(Dn,{result:t,themeMode:n,chartConfig:o});case"pie":return r.jsx(rt,{result:t,themeMode:n,chartConfig:o,isDonut:!1});case"donut":return r.jsx(rt,{result:t,themeMode:n,chartConfig:o,isDonut:!0});case"heatmap":return r.jsx(Nn,{result:t,themeMode:n});case"histogram":return r.jsx(Pn,{result:t,themeMode:n,chartConfig:o});case"funnel":return r.jsx(En,{result:t,themeMode:n,chartConfig:o});case"sankey":return r.jsx(Hn,{result:t,themeMode:n,chartConfig:o});case"waterfall":return r.jsx(On,{result:t,themeMode:n,chartConfig:o});case"gauge":return r.jsx(qn,{result:t,themeMode:n,chartConfig:o});case"kpi":return r.jsx(wt,{result:t,themeMode:n,chartConfig:o});default:return r.jsx(ie,{result:t,themeMode:n})}}function Yn(e,t,n){const o=e.columns,i=[];t&&o.includes(t)&&i.push(t),n&&o.includes(n)&&i.push(n);for(const s of o)i.includes(s)||i.push(s);return i.join(",")===o.join(",")?e:{...e,columns:i,rows:e.rows.map(s=>{const l={};for(const c of i)l[c]=s[c];return l})}}const Be=/date|time|day|month|year|week|quarter|period|_at$|^at$/i,ze=/(?:^|_)(?:id|uuid|key|code)$/i,Te=/(?:name|title|label|display|description|customer|account|product|region|segment|category|channel)$/i,Zn=new Set(["bar","grouped-bar","stacked-bar","line","area","scatter","pie","donut","heatmap","histogram","funnel","sankey","waterfall","gauge","kpi","table"]);function ot(e){return typeof e=="number"?Number.isFinite(e):typeof e=="string"?e.trim()!==""&&Number.isFinite(Number(e)):!1}function Mt(e){const t=e.rows.slice(0,20);return t.length===0?[]:e.columns.filter(n=>t.some(o=>ot(o[n]))&&t.every(o=>{const i=o[n];return i==null||i===""||ot(i)}))}function Gn(e,t){const n=e.columns.filter(o=>!t.includes(o));return n.find(o=>Te.test(o)&&!ze.test(o))??n.find(o=>!ze.test(o))??n[0]??e.columns[0]}function Xn(e){return e.columns.filter(t=>{if(!ze.test(t))return!1;const n=t.replace(/(?:_)?(?:id|uuid|key|code)$/i,"").replace(/_+$/,"");return e.columns.some(o=>o!==t&&(n.length>0&&o.toLowerCase().startsWith(n.toLowerCase())&&Te.test(o)||n.length===0&&Te.test(o)))})}function Kn(e,t){if(t.length===0)return e;const n=new Set(t);return{...e,columns:e.columns.filter(o=>!n.has(o)),rows:e.rows.map(o=>Object.fromEntries(Object.entries(o).filter(([i])=>!n.has(i))))}}function kt(e,t){const n=Mt(e),o=e.rows.length>0,i=e.columns.filter(g=>!n.includes(g));if(!(o&&n.length>=1))return{config:{...t??{},chart:"table",decisionSource:"data",rationale:"The returned rows do not contain a numeric measure to plot."},chartable:!1,reason:"No numeric measure"};const l=Gn(e,n),c=t!=null&&t.x&&e.columns.includes(t.x)?t.x:l,a=t!=null&&t.y&&e.columns.includes(t.y)?t.y:n.find(g=>g!==c)??n[0],d=Cn(e,n,i,c),u=Jn(t==null?void 0:t.chart),f=t==null?void 0:t.decisionSource,h=f==="authored"||f==="user",p=h&&u||u&&er(u,e,n,i,c,a)?u:d.chart,y=!!(u&&u!==p&&!h),j=t!=null&&t.color&&e.columns.includes(t.color)?t.color:p==="sankey"?i.find(g=>g!==c):t==null?void 0:t.color,b=y?`${d.reason}; replaced the agent suggestion because the returned data is not compatible.`:u&&!h?"Agent-selected visualization validated against the returned data.":d.reason;return{config:{...t??{},chart:p,x:c,y:a,...j?{color:j}:{},decisionSource:h?f:u&&!y?"agent":"data",rationale:b},chartable:p!=="table",reason:b}}function Jn(e){if(typeof e!="string")return;const t=e.toLowerCase().replace(/_/g,"-").replace("single-value","kpi");return Zn.has(t)?t:void 0}function Cn(e,t,n,o){return e.rows.length===1&&t.length>=1?{chart:"kpi",reason:"Single returned value"}:Be.test(o)&&t.length>=1?{chart:"line",reason:`Time-like field ${o}`}:n.length>0&&t.length>=2?{chart:"grouped-bar",reason:"One category with multiple numeric measures"}:n.length>0&&t.length===1?{chart:"bar",reason:"Categorical comparison with one numeric measure"}:t.length>=2?{chart:"scatter",reason:"Two continuous numeric measures"}:{chart:"table",reason:"No comparable category or time axis was returned"}}function er(e,t,n,o,i,s){return e==="table"?!0:e==="kpi"||e==="gauge"?n.length>=1&&t.rows.length===1:e==="line"||e==="area"?n.includes(s)&&Be.test(i):e==="scatter"?n.length>=2:e==="sankey"?o.length>=2&&n.length>=1:e==="histogram"?n.length>=1:e==="grouped-bar"||e==="stacked-bar"?o.length>=1&&n.length>=2:e==="pie"||e==="donut"?o.length>=1&&n.length>=1&&t.rows.length>=2&&t.rows.length<=8:e==="heatmap"?t.columns.length>=3&&n.length>=1:e==="funnel"||e==="waterfall"?o.length>=1&&n.length>=1:e==="bar"?o.length>=1&&n.length>=1&&!Be.test(i):!1}function uo({result:e,themeMode:t,t:n,chartConfig:o,embedded:i=!1,tabLabels:s,contentMaxHeight:l,tableMaxHeight:c}){const a=e.rows.length===0,[d,u]=R.useState(),[f,h]=R.useState(!1),p=R.useMemo(()=>({...o??{},...d??{}}),[o,d]),{config:y,chartable:j}=kt(e,p),b=R.useMemo(()=>Mt(e),[e]),g=R.useMemo(()=>Xn(e),[e]),v=R.useMemo(()=>f?e:Kn(e,g),[g,e,f]),[m,A]=R.useState("table"),T=x=>({border:"none",background:"transparent",cursor:"pointer",fontFamily:n.font,fontSize:11,fontWeight:700,padding:"2px 4px",color:x?n.accent:n.textMuted,borderBottom:`2px solid ${x?n.accent:"transparent"}`}),_=Me.some(x=>x.value===y.chart)?y.chart:"bar";return r.jsxs("div",{style:{border:i?"none":`1px solid ${n.headerBorder}`,background:n.cellBg,borderRadius:i?0:8,overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",padding:i?"9px 14px":"5px 9px",borderBottom:`1px solid ${n.headerBorder}`},children:[j&&r.jsx("button",{type:"button",onClick:()=>A("table"),style:T(m==="table"),children:(s==null?void 0:s.table)??"Table"}),j&&r.jsx("button",{type:"button",onClick:()=>A("chart"),style:T(m==="chart"),children:(s==null?void 0:s.chart)??"Chart"}),!j&&!a&&r.jsx("span",{style:{fontSize:11,fontWeight:700,color:n.textMuted},children:(s==null?void 0:s.table)??"Table"}),j&&m==="chart"?r.jsx("select",{value:_,onChange:x=>u(M=>({...M??{},chart:x.target.value,decisionSource:"user",rationale:"Selected manually."})),title:"Chart type",style:{fontFamily:n.font,fontSize:10.5,fontWeight:600,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 4px",cursor:"pointer"},children:Me.map(x=>r.jsx("option",{value:x.value,children:x.label},x.value))}):null,j&&m==="chart"?r.jsxs(r.Fragment,{children:[r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["X",r.jsx("select",{"aria-label":"X-axis field",value:y.x??"",onChange:x=>u(M=>({...M??{},x:x.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.map(x=>r.jsx("option",{value:x,children:x},x))})]}),b.length>0?r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["Y",r.jsx("select",{"aria-label":"Y-axis field",value:y.y??"",onChange:x=>u(M=>({...M??{},y:x.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:b.map(x=>r.jsx("option",{value:x,children:x},x))})]}):null,y.chart==="sankey"?r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["Target",r.jsx("select",{"aria-label":"Sankey target field",value:y.color??"",onChange:x=>u(M=>({...M??{},color:x.target.value,decisionSource:"user",rationale:"Sankey target selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.filter(x=>!b.includes(x)&&x!==y.x).map(x=>r.jsx("option",{value:x,children:x},x))})]}):null]}):null,j&&m==="chart"&&y.rationale?r.jsxs("span",{title:y.rationale,style:{fontSize:10.5,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:230},children:["Smart chart · ",y.chart]}):null,r.jsxs("span",{style:{marginLeft:"auto",fontSize:10.5,color:n.textMuted,alignSelf:"center"},children:[e.rowCount??e.rows.length," rows"]})]}),r.jsx("div",{style:{padding:i?12:8,minHeight:j&&m==="chart"?200:void 0,maxHeight:l??(i?380:320),overflow:"auto"},children:a?r.jsxs("div",{style:{padding:"18px 8px",textAlign:"center",color:n.textMuted,fontSize:12},children:["The query ran successfully and matched 0 rows",e.columns.length>0?` (columns: ${e.columns.join(", ")})`:"","."]}):j&&m==="chart"?r.jsx($t,{result:e,themeMode:t,chartConfig:y,onConfigChange:x=>u(M=>({...M??{},...x,decisionSource:"user",rationale:"Adjusted manually."}))}):r.jsxs(r.Fragment,{children:[g.length>0?r.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:6},children:r.jsx("button",{type:"button",onClick:()=>h(x=>!x),style:{border:"none",background:"transparent",color:n.accent,cursor:"pointer",fontSize:10.5,padding:0},children:f?"Hide technical fields":"Show IDs"})}):null,r.jsx(ie,{result:v,themeMode:t,maxHeight:c})]})})]})}const tr=3;function nr(e){const{business360:t,block:n,value:o,generated:i=!1}=e,s=e.maxPerKind??tr,l=t.focus,c=[];o&&c.push({kind:"value",name:o,detail:l.name?`Reported by ${l.name}.`:void 0});const a=(n==null?void 0:n.owner)??l.owner,d=(n==null?void 0:n.status)??l.status,u=(n==null?void 0:n.reviewCadence)??ge(l.metadata,"reviewCadence");c.push({kind:"block",name:l.name,owner:a,status:d,detail:or({reviewCadence:u,businessOutcome:(n==null?void 0:n.businessOutcome)??ge(l.metadata,"businessOutcome"),decisionUse:n==null?void 0:n.decisionUse})});const f=it([...t.businessDefinition.terms,...t.businessDefinition.definedByTerms]);for(const y of f.slice(0,s))y.id!==l.id&&c.push({kind:"term",name:y.name,owner:y.owner,detail:"Business term this answer is defined in."});for(const y of be(n==null?void 0:n.metricRefs).slice(0,s))c.push({kind:"metric",name:y,detail:"Governed metric used in the calculation."});for(const y of be(n==null?void 0:n.dimensionRefs).slice(0,s))c.push({kind:"dimension",name:y,detail:"Dimension used to slice the value."});for(const y of t.technicalSources.dbtModels.slice(0,s))c.push({kind:"model",name:y.name,detail:"dbt model the certified SQL builds on."});const h=it([...t.technicalSources.dbtSources,...t.technicalSources.sourceTables]);for(const y of h.slice(0,s))c.push({kind:"source",name:y.name,detail:"Raw source table the data originates from."});const p=be((n==null?void 0:n.caveats)??sr(l.metadata,"caveats"));return{value:o,summary:ir({focus:l,blockOwner:a,reviewCadence:u,generated:i,sourceAssets:h}),steps:c,trustLabel:e.trustLabel??(i?"review_required":void 0),freshness:e.freshness??rr(n==null?void 0:n.dataState,n==null?void 0:n.dataStateDetail)??ge(l.metadata,"freshness"),caveats:p.length>0?p:void 0}}function rr(e,t){switch(e){case"failed":return t?`upstream failed — ${t}`:"upstream failed";case"stale":return t?`stale data — ${t}`:"stale data";default:return}}function or(e){const t=[];return e.businessOutcome?t.push(e.businessOutcome):e.decisionUse&&t.push(`Supports: ${e.decisionUse}.`),e.reviewCadence&&t.push(`Reviewed ${e.reviewCadence}.`),t.length>0?t.join(" "):void 0}function ir(e){const t=e.blockOwner?` owned by ${e.blockOwner}`:"",n=e.sourceAssets.length>0?` It traces back to ${e.sourceAssets[0].name}.`:"";if(e.generated)return`This value was generated from ${e.focus.name}${t} and still needs analyst review before it can be certified.${n}`;const o=e.reviewCadence?`, reviewed ${e.reviewCadence}`:"";return`This value comes from the certified ${e.focus.name}${t}${o}.${n}`}function ge(e,t){const n=e==null?void 0:e[t];return typeof n=="string"&&n.trim().length>0?n:void 0}function sr(e,t){const n=e==null?void 0:e[t];return Array.isArray(n)?n.filter(o=>typeof o=="string"&&o.trim().length>0):[]}function be(e){if(!e)return[];const t=new Set,n=[];for(const o of e){const i=typeof o=="string"?o.trim():"";!i||t.has(i.toLowerCase())||(t.add(i.toLowerCase()),n.push(i))}return n}function it(e){const t=new Set,n=[];for(const o of e)t.has(o.id)||(t.add(o.id),n.push(o));return n}function At(e){var o,i;const t=e.dqlArtifact,n=(o=t==null?void 0:t.source)==null?void 0:o.trim();return n?{source:n,kind:t==null?void 0:t.kind,name:t==null?void 0:t.name,sourcePath:t==null?void 0:t.sourcePath,metrics:ve(t==null?void 0:t.metrics),dimensions:ve(t==null?void 0:t.dimensions),filters:((t==null?void 0:t.filters)??[]).map(s=>{var d,u;const l=(d=s.dimension)==null?void 0:d.trim(),c=((u=s.operator)==null?void 0:u.trim())||"equals",a=ve(s.values);return!l||a.length===0?"":`${l} ${c} ${a.join(", ")}`}).filter(Boolean),timeDimension:(i=t==null?void 0:t.timeDimension)!=null&&i.name?[t.timeDimension.name,t.timeDimension.granularity].filter(Boolean).join(" / "):void 0,orderBy:((t==null?void 0:t.orderBy)??[]).map(s=>{var a,d;const l=(a=s.name)==null?void 0:a.trim(),c=(d=s.direction)==null?void 0:d.trim();return l&&c?`${l} ${c}`:""}).filter(Boolean),limit:typeof(t==null?void 0:t.limit)=="number"&&Number.isFinite(t.limit)?t.limit:void 0}:null}function lr(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n.kind!=="tool_result"||n.id!=="governed_answer")continue;const o=n.output;if(o&&typeof o=="object"&&"kind"in o)return o}return null}function ve(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter(Boolean):[]}function ar(e){const t=e.result;if(!t||!Array.isArray(t.rows))return null;const o=(Array.isArray(t.columns)?t.columns:[]).map(s=>typeof s=="string"?s:s&&typeof s=="object"&&typeof s.name=="string"?String(s.name):String(s)),i=t.rows.filter(s=>!!(s&&typeof s=="object"&&!Array.isArray(s))).map(s=>s);return{columns:o,rows:i,rowCount:typeof t.rowCount=="number"?t.rowCount:i.length,executionTime:t.executionTime}}function cr(e,t){const n=e&&typeof e=="object"?e:{},o=typeof n.chart=="string"?n.chart:void 0,i=n.decisionSource==="authored"||n.decisionSource==="agent"||n.decisionSource==="data"||n.decisionSource==="user"?n.decisionSource:void 0,s=o||(typeof t.suggestedViz=="string"?t.suggestedViz:void 0),l=s?s.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":s:void 0;return{...l?{chart:l}:{},...l?{decisionSource:i??(o?"authored":"agent")}:{},...typeof n.rationale=="string"?{rationale:n.rationale}:{},...typeof n.x=="string"?{x:n.x}:{},...typeof n.y=="string"?{y:n.y}:{},...typeof n.color=="string"?{color:n.color}:{},...typeof n.title=="string"?{title:n.title}:{}}}function dr(e,t){return!t||t.columns.length===0?e:kt(t,e).config}function je(e){if(typeof e!="string")return;const t=e.replace(/\s+/g," ").trim();if(t)return t.length>180?`${t.slice(0,177)}...`:t}function Bt(e){const t=ur(e,["Answer","Business summary","Summary"]);if(t)return st(t,340);const n=/^(?:reuse evidence|certified result preview|result preview|result summary|trust status|next action|recommended action|sql used by block|reusable block sql|proposed sql|sql generated|sql draft|evidence|parameters|lineage|technical lineage)\s*:/i,o=/^(?:SELECT|WITH|FROM|WHERE|GROUP BY|ORDER BY|LIMIT)\b/i,i=[];for(const l of e.split(/\r?\n/)){const c=l.trim();if(!(!c||/^#{1,6}\s*/.test(c)||/^```/.test(c)||/^\|/.test(c))&&!/^outcome\s*:/i.test(c)){if(n.test(c)||o.test(c)){if(i.length>0)break;continue}if(i.push(c),i.length>=5)break}}const s=i.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim();return st(s,340)}function ur(e,t){var u,f,h;const n=e.split(/\r?\n/),o=t.map(p=>p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),i=new RegExp(`^\\s*(?:#{1,6}\\s*)?(?:[-*]\\s*)?(?:\\*\\*)?(${o})(?:\\*\\*)?\\s*:\\s*(.*)$`,"i"),s=/^\s*(?:#{1,6}\s*)?(?:[-*]\s*)?(?:\*\*)?[A-Z][A-Za-z /-]{2,42}(?:\*\*)?\s*:/,l=n.findIndex(p=>i.test(p));if(l<0)return;const c=((h=(f=(u=n[l])==null?void 0:u.match(i))==null?void 0:f[2])==null?void 0:h.trim())??"",a=c?[c]:[];for(let p=l+1;p<n.length;p+=1){const y=n[p]??"";if(s.test(y)||/^\s*```/.test(y))break;y.trim()&&a.push(y.trim())}return a.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim()||void 0}function st(e,t){const n=e.replace(/\s+/g," ").trim();if(n.length<=t)return n;const o=n.slice(0,t-1),i=Math.max(o.lastIndexOf(". "),o.lastIndexOf("; "));if(i>100)return o.slice(0,i+1).trim();const s=o.lastIndexOf(" ");return`${o.slice(0,s>80?s:o.length).trim()}...`}function xr({answer:e,themeMode:t,showSql:n=!0,compact:o=!1,sourceQuestion:i,onInvestigate:s,onInsertSql:l,onCreateBlock:c}){var Ie,We,De,Fe,Ne,Pe,Ee,He,Oe,qe,Ue,Ve,Qe;const a=q[t],{dispatch:d}=Ht(),u=ar(e),f=cr((Ie=e.result)==null?void 0:Ie.chartConfig,e),[h,p]=R.useState(),y=dr({...f??{},...h??{}},u),j=!!(u&&St(u,y)!=="table"),b=e.analysisPlan??((We=e.evidence)==null?void 0:We.analysisPlan),g=n?e.sql??((De=e.result)==null?void 0:De.sql)??e.proposedSql??(b==null?void 0:b.sql):void 0,v=At(e),m=e.executionError??(((Ne=(Fe=e.evidence)==null?void 0:Fe.execution)==null?void 0:Ne.status)==="failed"?e.evidence.execution.message:void 0),A=((Pe=e.result)==null?void 0:Pe.blockPath)??((Ee=e.block)==null?void 0:Ee.sourcePath),T=!!(g||m||n&&A),_=!!e.evidence,[x,M]=R.useState("answer"),[S,B]=R.useState(!1),z=It(e),k=Er(z,a),w=(e.answer??e.text??"").replace(/\n\n_Question:_[\s\S]*$/m,"").trim(),I=o?Bt(w):w,W=((He=e.result)==null?void 0:He.blockName)??((Oe=e.block)==null?void 0:Oe.name)??((Ue=(qe=e.citations)==null?void 0:qe.find(N=>N.kind==="block"))==null?void 0:Ue.name),$=Ur(e,W),D=Hr(e,u,W,A),[P,O]=R.useState(null),L=!!(l&&g),F=!!(c&&g),V=je(b==null?void 0:b.question)??je(i)??je(I)??"Investigate this answer",Z=!!(s&&V),X=zt(e,{sql:g,executionError:m,blockName:W,result:u}),Dt=()=>{!l||!g||(l(g,W??(b==null?void 0:b.question)??"AI SQL preview",{question:i??(b==null?void 0:b.question)}),O("Inserted SQL preview cell for review."))},Ft=()=>{!c||!g||c(g,{title:(v==null?void 0:v.name)??W??(b==null?void 0:b.question)??"AI DQL draft",description:I||(b==null?void 0:b.routeReason)||"AI generated DQL draft.",tags:["ai-generated","review-required"]})},Nt=()=>{!s||!V||s({question:V,title:$?`${$}: ${V}`:V,answerSummary:I,blockName:$,sql:g,evidence:e.evidence})},he=[{id:"answer",label:o?"Summary":"Answer",visible:!0},{id:"dql",label:"DQL",visible:!!v},{id:"visual",label:o?"Chart":"Visualization",visible:j},{id:"data",label:"Data",visible:!!u},{id:"sql",label:"SQL / Block",visible:n&&T},{id:"lineage",label:o?"Trace":"Lineage",visible:_},{id:"context",label:o?"Context":"Business Context",visible:_},{id:"review",label:o?"Trust":"Review",visible:_||!!((Ve=e.citations)!=null&&Ve.length)}].filter(N=>N.visible),Re=he.some(N=>N.id===x)?x:"answer",ce=he.filter(N=>N.id!=="answer"),me=ce.some(N=>N.id===x)?x:(Qe=ce[0])==null?void 0:Qe.id,ye=N=>N==="answer"?r.jsx(yr,{summary:I,answer:e,blockName:W,evidence:e.evidence,analysisPlan:b,result:u,sourceTier:e.sourceTier,compact:o,t:a}):N==="dql"&&v?r.jsx(Ir,{artifact:v,t:a}):N==="visual"&&u&&j?r.jsxs("div",{style:{padding:o?"8px 10px":"10px 12px",minHeight:o?180:220,display:"grid",gap:10},children:[r.jsx(Fr,{result:u,chartConfig:y,t:a,onChange:Pt=>p(Et=>({...Et??{},...Pt,decisionSource:"user",rationale:"Adjusted manually."}))}),r.jsx($t,{result:u,themeMode:t,chartConfig:y})]}):N==="data"&&u?r.jsx("div",{style:{maxHeight:o?320:420,overflow:"auto"},children:r.jsx(ie,{result:u,themeMode:t})}):N==="lineage"?r.jsx(_r,{evidence:e.evidence,t:a}):N==="context"?r.jsx(Lr,{evidence:e.evidence,t:a}):N==="sql"&&n&&T?r.jsx(Wr,{sql:g,blockPath:A,executionError:m,t:a}):N==="review"?r.jsx(Rr,{answer:e,t:a}):null;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:o?8:10,whiteSpace:"normal"},children:[r.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[r.jsx(Zt,{state:z}),r.jsx(Gt,{t:a,route:e.route}),C(e.cascade)&&r.jsx("span",{style:{border:`1px solid ${a.cellBorder}`,borderRadius:999,padding:"3px 8px",fontSize:11,fontWeight:700,color:a.textSecondary,background:a.tableHeaderBg},children:C(e.cascade)}),!o&&W&&r.jsxs("span",{style:{fontSize:12,fontFamily:a.fontMono,color:a.textSecondary},children:["block: ",W]}),u&&r.jsxs("span",{style:{fontSize:12,color:a.textMuted},children:[(u.rowCount??u.rows.length).toLocaleString()," rows",u.executionTime!==void 0&&r.jsxs(r.Fragment,{children:[" - ",Math.round(u.executionTime),"ms"]})]}),Z&&r.jsx("button",{type:"button",onClick:Nt,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:`${a.accent}12`,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:800},children:o?"Investigate":"Investigate deeper"}),F&&r.jsx("button",{type:"button",onClick:Ft,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:a.cellBg,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:700},children:o?"DQL draft":v?"Review DQL draft":"Create DQL draft"}),L&&r.jsx("button",{type:"button",onClick:Dt,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:`${a.accent}18`,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:700},children:o?"SQL preview":"Insert SQL preview"})]}),P&&r.jsx("div",{style:{fontSize:11,color:"#3fb950"},children:P}),r.jsx(pr,{outcome:X,t:a,compact:o}),r.jsxs("div",{style:{border:`1px solid ${a.cellBorder}`,borderTop:`2px solid ${k}`,borderRadius:o?10:6,overflow:"hidden",background:a.cellBg},children:[!o&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 10px",borderBottom:`1px solid ${a.cellBorder}`,background:`${a.tableHeaderBg}70`,flexWrap:"wrap"},children:[he.map(N=>r.jsx(ft,{active:Re===N.id,label:N.label,onClick:()=>M(N.id),t:a},N.id)),!n&&A&&r.jsx("span",{style:{marginLeft:"auto",minWidth:0,fontSize:11,fontFamily:a.fontMono,color:a.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:A})]}),ye(o?"answer":Re),o&&ce.length>0&&r.jsxs("div",{style:{borderTop:`1px solid ${a.cellBorder}`,background:`${a.tableHeaderBg}45`},children:[r.jsxs("button",{type:"button",onClick:()=>B(N=>!N),style:{width:"100%",border:0,background:"transparent",color:a.textSecondary,padding:"8px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",fontSize:11,fontWeight:800},children:[r.jsx("span",{children:"Details"}),r.jsx("span",{style:{color:a.textMuted,fontFamily:a.fontMono},children:S?"hide":"show evidence"})]}),S&&r.jsxs("div",{style:{borderTop:`1px solid ${a.cellBorder}`},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 12px",flexWrap:"wrap"},children:ce.map(N=>r.jsx(ft,{active:me===N.id,label:N.label,onClick:()=>M(N.id),t:a},N.id))}),me?ye(me):null]})]}),r.jsx(Dr,{items:D,t:a,accent:k}),r.jsx(Xt,{t:a,skills:e.appliedSkills,onOpenSkills:()=>d({type:"SET_MAIN_VIEW",view:"skills"}),onSuggestCorrection:N=>{try{window.sessionStorage.setItem("dql-skill-ai-correction",JSON.stringify({skillId:N.id,question:i,feedback:"Correct the guidance that shaped this answer."}))}catch{}d({type:"SET_MAIN_VIEW",view:"skills"})}})]})]})}function zt(e,t){var n,o,i,s,l;if(e.kind==="no_answer")return{kind:"cannot_answer",label:"Cannot answer yet",detail:"The assistant did not find enough trusted context to safely answer or generate SQL.",nextAction:"Clarify the business object, metric, grain, or source table.",tone:"error"};if(e.certification==="certified"||e.kind==="certified"){const c=t.blockName??e.sourceCertifiedBlock??((n=e.block)==null?void 0:n.name);return{kind:"reuse_certified_block",label:"Reuse certified block",detail:c?`Existing DQL block ${c} answers this request.`:"A certified DQL artifact answers this request.",nextAction:"Use the certified block instead of creating duplicate SQL.",tone:"success"}}return t.executionError||e.executionError?{kind:"fix_sql",label:"Fix SQL",detail:"The generated or selected SQL needs correction before it can become reusable DQL.",nextAction:"Ask AI to repair, edit manually, then rerun preview.",tone:"error"}:(o=e.draftBlock)!=null&&o.path||e.draftBlockId?{kind:"use_existing_draft",label:"Use existing draft",detail:`A review-required DQL draft is available at ${((i=e.draftBlock)==null?void 0:i.path)??e.draftBlockId}.`,nextAction:"Open the draft, review metadata/tests/lineage, then certify manually.",tone:"accent"}:(l=(s=e.dqlArtifact)==null?void 0:s.source)!=null&&l.trim()?{kind:"create_dql_draft",label:"Review DQL draft",detail:"A review-required DQL artifact is available for analyst review.",nextAction:"Review DQL metadata, query logic, lineage, and result preview before certification.",tone:"warning"}:t.sql?{kind:t.result?"generate_sql_cell":"create_dql_draft",label:t.result?"Review SQL preview":"Create DQL draft",detail:t.result?`Review-required SQL preview returned ${(t.result.rowCount??t.result.rows.length).toLocaleString()} row${(t.result.rowCount??t.result.rows.length)===1?"":"s"}.`:"Review-required SQL is available but still needs preview and DQL metadata review.",nextAction:t.result?"Create a DQL draft after reviewing parameters and lineage; insert SQL only as a notebook preview.":"Run preview, inspect parameters, then create a draft block.",tone:"warning"}:{kind:"needs_review",label:"Needs review",detail:"The assistant returned business context but no executable certified answer or SQL draft.",nextAction:"Review evidence and ask for a specific SQL, reuse, or DQL draft action.",tone:"muted"}}function pr({outcome:e,t,compact:n}){const o=fr(e.tone,t);return r.jsxs("div",{style:{border:`1px solid ${o}45`,borderLeft:`3px solid ${o}`,borderRadius:n?10:7,background:`${o}10`,padding:n?"9px 10px":"10px 12px",display:"grid",gap:n?4:5},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[r.jsx("span",{style:{border:`1px solid ${o}55`,background:`${o}14`,color:o,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:850,lineHeight:1.1,textTransform:"uppercase",letterSpacing:0,flexShrink:0},children:e.label}),r.jsx("span",{style:{fontSize:n?12:12.5,color:t.textPrimary,fontWeight:750,overflow:"hidden",textOverflow:"ellipsis"},children:e.detail})]}),r.jsxs("div",{style:{fontSize:n?11.5:12,color:t.textSecondary,lineHeight:1.45},children:["Next: ",e.nextAction]})]})}function fr(e,t){switch(e){case"success":return t.success;case"accent":return t.accent;case"warning":return t.warning;case"error":return t.error;case"muted":default:return t.textMuted}}function hr({answer:e,blockName:t}){const[n,o]=R.useState(null),[i,s]=R.useState(!1),[l,c]=R.useState(!1),a=te.useCallback(async()=>{var d,u;if(!l){c(!0),s(!0);try{const f=await Ot.fetchBusiness360(t);if(!f){o(null);return}const h=(d=e.evidence)==null?void 0:d.outcome,p=lt(e,"metric"),y=lt(e,"dimension"),j=e.certification!=="certified"&&e.kind!=="certified",b=nr({business360:f,block:{name:t,owner:h==null?void 0:h.owner,status:((u=e.block)==null?void 0:u.status)??e.certification,reviewCadence:h==null?void 0:h.reviewCadence,caveats:h==null?void 0:h.caveats,decisionUse:h==null?void 0:h.decisionUse,metricRefs:p,dimensionRefs:y},value:mr(e),generated:j,trustLabel:e.trustLabel});o(b)}catch{o(null)}finally{s(!1)}}},[e,t,l]);return l?i?r.jsx("div",{style:{fontSize:11.5,color:"var(--text-tertiary, inherit)"},children:"Assembling derivation…"}):n?r.jsx(Ct,{walk:n,defaultOpen:!0}):null:r.jsx("button",{type:"button",onClick:()=>void a(),"aria-expanded":!1,style:{alignSelf:"flex-start",border:0,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 0",fontSize:12,fontWeight:700,textDecoration:"underline",textUnderlineOffset:3},children:"Why? Show how this was derived"})}function lt(e,t){var i,s;const n=(((i=e.evidence)==null?void 0:i.semanticObjects)??[]).filter(l=>l.kind===t).map(l=>l.name).filter(l=>!!l);if(n.length>0)return n;const o=e.analysisPlan??((s=e.evidence)==null?void 0:s.analysisPlan);return(t==="metric"?o==null?void 0:o.measures:o==null?void 0:o.dimensions)??[]}function mr(e){const t=e.result;if(t&&Array.isArray(t.rows)&&t.rows.length===1){const n=t.rows[0];if(n&&typeof n=="object"&&!Array.isArray(n)){const o=Object.values(n);if(o.length===1&&(typeof o[0]=="number"||typeof o[0]=="string"))return String(o[0])}}}function yr({summary:e,answer:t,blockName:n,evidence:o,analysisPlan:i,result:s,sourceTier:l,compact:c,t:a}){var u,f,h,p,y,j,b,g,v;const d=(u=i==null?void 0:i.followUps)==null?void 0:u[0];return r.jsxs("div",{style:{padding:c?14:12,display:"flex",flexDirection:"column",gap:c?10:12},children:[e?r.jsx(Tt,{text:e,t:a,compact:c,summaryOnly:c}):r.jsx("div",{style:{fontSize:12,color:a.textMuted},children:"No summary text was returned."}),t&&n&&r.jsx(hr,{answer:t,blockName:n}),c?r.jsx("div",{style:{fontSize:11.5,color:a.textMuted,display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[l?Pr(l):null,s?`${(s.rowCount??s.rows.length).toLocaleString()} rows`:null,((f=o==null?void 0:o.validation)==null?void 0:f.status)==="failed"?"needs review":null,((h=o==null?void 0:o.execution)==null?void 0:h.status)==="failed"?"data check failed":null].filter(Boolean).map((m,A)=>r.jsxs(te.Fragment,{children:[A>0&&r.jsx("span",{style:{color:a.cellBorder},children:"·"}),r.jsx("span",{children:m})]},`${m}-${A}`))}):r.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[l&&r.jsx(Q,{label:U(l),t:a}),s&&r.jsx(Q,{label:`${(s.rowCount??s.rows.length).toLocaleString()} rows`,t:a}),((p=o==null?void 0:o.validation)==null?void 0:p.status)&&r.jsx(Q,{label:`validation: ${o.validation.status}`,t:a}),((y=o==null?void 0:o.execution)==null?void 0:y.status)&&r.jsx(Q,{label:`execution: ${o.execution.status}`,t:a})]}),s&&!c&&r.jsx(Tr,{result:s,t:a,compact:c}),i&&!c&&r.jsxs("div",{style:{display:"grid",gap:7,padding:c?"9px 10px":10,border:`1px solid ${a.cellBorder}`,borderRadius:8,background:`${a.tableHeaderBg}45`},children:[i.routeReason&&r.jsx("div",{style:{fontSize:c?12.5:12,lineHeight:1.45,color:a.textSecondary},children:i.routeReason}),(i.grain||((j=i.measures)==null?void 0:j.length)||((b=i.dimensions)==null?void 0:b.length))&&r.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[i.grain&&r.jsx(Q,{label:`grain: ${i.grain}`,t:a}),(g=i.measures)==null?void 0:g.slice(0,2).map(m=>r.jsx(Q,{label:m,t:a},`measure-${m}`)),(v=i.dimensions)==null?void 0:v.slice(0,2).map(m=>r.jsx(Q,{label:m,t:a},`dimension-${m}`))]}),i.candidateJoins&&i.candidateJoins.length>0&&r.jsxs("div",{style:{fontSize:12,color:a.textMuted},children:["Join: ",r.jsx("span",{style:{color:a.textSecondary},children:Rt(i.candidateJoins[0])})]}),d&&r.jsxs("div",{style:{fontSize:12,color:a.textMuted},children:["Next: ",r.jsx("span",{style:{color:a.textSecondary},children:d})]})]})]})}function Tt({text:e,t,compact:n=!1,summaryOnly:o=!1}){const i=o?Bt(e):e,s=gr(i,t,n);return r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:n?7:8,color:t.textPrimary,fontFamily:t.font,overflowWrap:"anywhere"},children:s})}function gr(e,t,n){var c;const o=br(e).split(`
|
|
29
|
-
`),i=[];let s=0,l=0;for(;s<o.length;){const d=o[s].trim();if(!d){s+=1;continue}if(d.startsWith("```")){const p=d.replace(/^```/,"").trim(),y=[];for(s+=1;s<o.length&&!o[s].trim().startsWith("```");)y.push(o[s]),s+=1;s<o.length&&(s+=1),i.push(r.jsx("pre",{style:
|
|
28
|
+
`);gt(s,"export.csv","text/csv")}function An(e,t){const n=JSON.stringify(e.rows,null,2);gt(n,"export.json","application/json")}function gt(e,t,n){const o=new Blob([e],{type:n}),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Bn({dir:e,color:t}){return e?r.jsx("svg",{width:"8",height:"10",viewBox:"0 0 8 10",fill:t,style:{marginLeft:3,flexShrink:0},children:e==="asc"?r.jsx("path",{d:"M4 0L7 4H1L4 0Z"}):r.jsx("path",{d:"M4 10L1 6H7L4 10Z"})}):r.jsxs("svg",{width:"8",height:"10",viewBox:"0 0 8 10",fill:t,opacity:.3,style:{marginLeft:3,flexShrink:0},children:[r.jsx("path",{d:"M4 0L7 3.5H1L4 0Z"}),r.jsx("path",{d:"M4 10L1 6.5H7L4 10Z"})]})}function ie({result:e,themeMode:t,maxHeight:n=440,initialPageSize:o=50}){const i=q[t],[s,l]=R.useState(null),[c,a]=R.useState(null),[d,u]=R.useState(null),[f,h]=R.useState(""),[p,y]=R.useState(et.includes(o)?o:50),[j,b]=R.useState(0),g=R.useCallback(w=>{c===w?d==="asc"?u("desc"):d==="desc"?(a(null),u(null)):u("asc"):(a(w),u("asc")),b(0)},[c,d]),v=R.useMemo(()=>{if(!f.trim())return e.rows;const w=f.toLowerCase();return e.rows.filter(I=>e.columns.some(W=>{const $=I[W];return $==null?!1:String($).toLowerCase().includes(w)}))},[e.rows,e.columns,f]),m=R.useMemo(()=>{if(!c||!d)return v;const w=[...v];return w.sort((I,W)=>{const $=Mn(I[c],W[c]);return d==="desc"?-$:$}),w},[v,c,d]),A=R.useMemo(()=>{const w=new Map;for(const I of e.columns)w.set(I,un(I,e.rows));return w},[e.columns,e.rows]),z=R.useMemo(()=>new Map(e.columns.map(w=>[w,e.rows.map(I=>I[w])])),[e.columns,e.rows]),[_,x]=R.useState(!1),M=Math.max(1,Math.ceil(m.length/p)),S=Math.min(j,M-1),B=m.slice(S*p,(S+1)*p),T=m.length===0?0:S*p+1,k=Math.min((S+1)*p,m.length);return e.columns.length===0?r.jsx("div",{style:{padding:"12px 16px",color:i.textMuted,fontSize:12,fontFamily:i.font,fontStyle:"italic"},children:"Query executed successfully. No columns to display."}):r.jsxs("div",{children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 8px",borderBottom:`1px solid ${i.tableBorder}`,background:`${i.tableHeaderBg}60`,flexWrap:"wrap"},children:[r.jsxs("div",{style:{position:"relative",flex:"0 1 200px",minWidth:120},children:[r.jsx("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:i.textMuted,style:{position:"absolute",left:6,top:6},children:r.jsx("path",{d:"M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"})}),r.jsx("input",{value:f,onChange:w=>{h(w.target.value),b(0)},placeholder:"Filter rows...",style:{width:"100%",background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:4,color:i.textPrimary,fontSize:11,fontFamily:i.font,padding:"3px 8px 3px 22px",outline:"none"}}),f&&r.jsx("button",{onClick:()=>h(""),style:{position:"absolute",right:4,top:3,background:"none",border:"none",color:i.textMuted,cursor:"pointer",fontSize:12,padding:"0 2px"},children:"×"})]}),r.jsx("span",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:f?`Showing ${T}–${k} of ${m.length} matching (${e.rows.length} total)`:`Showing ${T}–${k} of ${e.rows.length} ${e.rows.length===1?"row":"rows"}`}),r.jsx("div",{style:{flex:1}}),r.jsx(tt,{label:"CSV",onClick:()=>kn(e),t:i}),r.jsx(tt,{label:"JSON",onClick:()=>An(e),t:i}),r.jsx("select",{value:p,onChange:w=>{y(Number(w.target.value)),b(0)},style:{background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:3,color:i.textSecondary,fontSize:10,fontFamily:i.font,padding:"2px 4px",outline:"none"},children:et.map(w=>r.jsxs("option",{value:w,children:[w," / page"]},w))}),M>1&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[r.jsx(ee,{disabled:S===0,onClick:()=>b(0),t:i,children:"«"}),r.jsx(ee,{disabled:S===0,onClick:()=>b(S-1),t:i,children:"‹"}),r.jsxs("span",{style:{fontSize:10,color:i.textSecondary,fontFamily:i.font,padding:"0 4px"},children:[S+1,"/",M]}),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(S+1),t:i,children:"›"}),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(M-1),t:i,children:"»"})]})]}),r.jsx("div",{style:{maxHeight:n,overflow:"auto",position:"relative"},onScroll:w=>x(w.target.scrollTop>0),children:r.jsxs("table",{style:{width:"100%",borderCollapse:"separate",borderSpacing:0,tableLayout:"auto",fontSize:12.5,fontFamily:i.fontMono},children:[r.jsx("thead",{children:r.jsx("tr",{children:e.columns.map(w=>{const I=A.get(w)??"string",W=I==="numeric";return r.jsx("th",{onClick:()=>g(w),style:{background:i.tableHeaderBg,color:i.textSecondary,fontWeight:600,fontSize:11,textAlign:W?"right":"left",padding:"8px 14px",borderBottom:`1px solid ${i.tableBorder}`,minWidth:80,maxWidth:320,whiteSpace:"nowrap",position:"sticky",top:0,zIndex:1,fontFamily:i.font,letterSpacing:"0.03em",overflow:"hidden",textOverflow:"ellipsis",cursor:"pointer",userSelect:"none",boxShadow:_?"0 2px 4px -2px rgba(0,0,0,0.18)":"none",transition:"background 0.1s, box-shadow 0.18s"},children:r.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,justifyContent:W?"flex-end":"flex-start"},children:[(()=>{const $=wn(I);return r.jsx("span",{title:I,style:{fontSize:9,fontFamily:i.fontMono,fontWeight:700,color:$.color,background:`${$.color}15`,border:`1px solid ${$.color}40`,borderRadius:3,padding:"0 4px",minWidth:14,textAlign:"center",lineHeight:"14px",flexShrink:0},children:$.icon})})(),r.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:w}),r.jsx(Bn,{dir:c===w?d:null,color:c===w?i.accent:i.textMuted})]})},w)})})}),r.jsx("tbody",{children:B.map((w,I)=>{const W=s===I,F=I%2===1?i.tableHeaderBg:"transparent";return r.jsx("tr",{onMouseEnter:()=>l(I),onMouseLeave:()=>l(null),style:{transition:"background 0.1s"},children:e.columns.map(E=>{const O=w[E],L=O==null,D=$e(O);return r.jsx("td",{style:{padding:"7px 14px",borderBottom:`1px solid ${i.tableBorder}`,background:W?i.tableRowHover:F,color:L?i.textMuted:i.textPrimary,fontStyle:L?"italic":"normal",fontVariantNumeric:D?"tabular-nums":"normal",textAlign:D?"right":"left",whiteSpace:"nowrap",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",transition:"background 0.1s"},children:L?"—":pe(E,O,z.get(E)??[])},E)})},I)})})]})}),r.jsxs("div",{style:{padding:"5px 10px",color:i.textMuted,fontSize:10,fontFamily:i.font,borderTop:`1px solid ${i.tableBorder}`,background:`${i.tableHeaderBg}60`,display:"flex",alignItems:"center",gap:4},children:[M>1&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[r.jsx(ee,{disabled:S===0,onClick:()=>b(S-1),t:i,children:"‹"}),Tn(M,S).map((w,I)=>w==="…"?r.jsx("span",{style:{color:i.textMuted,fontSize:10,padding:"0 2px"},children:"…"},`gap-${I}`):r.jsx("button",{onClick:()=>b(w-1),style:{background:w-1===S?`${i.accent}20`:"transparent",border:"none",color:w-1===S?i.accent:i.textSecondary,fontSize:10,fontFamily:i.font,fontWeight:w-1===S?700:400,padding:"1px 6px",borderRadius:3,cursor:"pointer",minWidth:20},children:w},w)),r.jsx(ee,{disabled:S>=M-1,onClick:()=>b(S+1),t:i,children:"›"})]}),r.jsx("div",{style:{flex:1}}),r.jsxs("span",{style:{fontSize:10,color:i.textSecondary,fontFamily:i.font,marginLeft:6,whiteSpace:"nowrap"},children:[m.length.toLocaleString()," ",m.length===1?"row":"rows",f&&e.rows.length!==m.length&&` of ${e.rows.length.toLocaleString()}`]})]})]})}function Tn(e,t){if(e<=7)return Array.from({length:e},(i,s)=>s+1);const n=t+1,o=[1];n>3&&o.push("…");for(let i=Math.max(2,n-1);i<=Math.min(e-1,n+1);i++)o.push(i);return n<e-2&&o.push("…"),o.push(e),o}function tt({label:e,onClick:t,t:n}){const[o,i]=R.useState(!1);return r.jsxs("button",{onClick:t,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{background:o?n.btnHover:"transparent",border:`1px solid ${o?n.btnBorder:"transparent"}`,borderRadius:3,cursor:"pointer",color:o?n.textSecondary:n.textMuted,fontSize:10,fontFamily:n.font,fontWeight:600,padding:"2px 6px",transition:"all 0.15s",display:"flex",alignItems:"center",gap:3},children:[r.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 16 16",fill:"currentColor",children:[r.jsx("path",{d:"M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z"}),r.jsx("path",{d:"M7.25 7.689V2a.75.75 0 0 1 1.5 0v5.689l1.97-1.97a.749.749 0 1 1 1.06 1.06l-3.25 3.25a.749.749 0 0 1-1.06 0L4.22 6.779a.749.749 0 1 1 1.06-1.06l1.97 1.97Z"})]}),e]})}function ee({disabled:e,onClick:t,children:n,t:o}){return r.jsx("button",{disabled:e,onClick:t,style:{background:"transparent",border:"none",cursor:e?"default":"pointer",color:e?o.textMuted:o.textSecondary,fontSize:12,fontFamily:o.font,padding:"0 3px",opacity:e?.4:1,transition:"opacity 0.1s"},children:n})}const Me=[{value:"bar",label:"Bar"},{value:"grouped-bar",label:"Grouped Bar"},{value:"stacked-bar",label:"Stacked Bar"},{value:"line",label:"Line"},{value:"area",label:"Area"},{value:"scatter",label:"Scatter"},{value:"pie",label:"Pie"},{value:"donut",label:"Donut"},{value:"heatmap",label:"Heatmap"},{value:"histogram",label:"Histogram"},{value:"funnel",label:"Funnel"},{value:"sankey",label:"Sankey"},{value:"waterfall",label:"Waterfall"},{value:"gauge",label:"Gauge"},{value:"kpi",label:"KPI"}],bt=/date|time|at|day|month|year/i,vt=/^(label|name|category|status|type|group)$/i,jt=/^(value|count|total|revenue|amount|sum|avg|price|quantity|sales)$/i;function G(e){return typeof e=="number"?!0:typeof e=="string"?e.trim()!==""&&!isNaN(Number(e)):!1}function zn(e){return typeof e=="string"||typeof e=="number"}const _n=new Set(["bar","line","area","pie","donut","scatter","heatmap","funnel","waterfall","histogram","gauge","stacked-bar","grouped-bar","sankey","kpi","table"]);function St(e,t){if(t!=null&&t.chart){const n=t.chart.toLowerCase().replace(/_/g,"-");if(_n.has(n))return n}return Ln(e)}function Ln(e){const{columns:t,rows:n}=e;if(t.length<2||n.length===0)return"table";const o=t[0],i=t[1],s=n.slice(0,5),l=s.every(f=>G(f[i])),c=s.every(f=>zn(f[o]));if(bt.test(o)&&l&&c)return"line";const a=t.find(f=>vt.test(f)),d=t.find(f=>jt.test(f));return a&&d&&s.every(h=>G(h[d]))?"bar":s.every(f=>G(f[o]))&&l&&t.length>=2?"scatter":t.length===2&&c&&l?"bar":"table"}const ke={default:["#388bfd","#56d364","#e3b341","#f78166","#a371f7","#39c5cf","#ffa657","#ff7b72","#89d185","#d2a8ff","#58a6ff","#3fb950"],warm:["#f85149","#f78166","#ffa657","#e3b341","#d29922","#db6d28","#ff7b72","#ffa198","#ffdfb6","#e6c174","#c4a35a","#b08c3e"],cool:["#388bfd","#58a6ff","#79c0ff","#39c5cf","#56d364","#3fb950","#a371f7","#d2a8ff","#bc8cff","#6cb6ff","#2ea043","#1f6feb"],mono:["#c9d1d9","#b1bac4","#8b949e","#6e7681","#484f58","#30363d","#21262d","#161b22","#a0a8b2","#9e9e9e","#757575","#616161"],pastel:["#b8d8f8","#b4e6c8","#f4e6a0","#f8c4a4","#d2b8f0","#a8e0e0","#f8d8a0","#f4b8b4","#c0e8c0","#e0d0f8","#a8d8f8","#b0e8b0"],corporate:["#2563eb","#16a34a","#7c3aed","#0891b2","#f59e0b","#dc2626","#475569","#0f766e","#9333ea","#0284c7","#65a30d","#ea580c"]};function Y(e){return ke[e??"default"]??ke.default}function H(e,t="value",n){return vn(t,e,n)}function Ae(e,t=8,n=!1){if(/^\d{4}-\d{2}(-\d{2})?/.test(e)){const o=/^\d{4}-\d{2}$/.test(e),i=new Date(o?`${e}-01T00:00:00Z`:e);if(!isNaN(i.getTime()))return i.toLocaleDateString("en-US",o||n?{year:"numeric",month:"short",timeZone:"UTC"}:{year:"numeric",month:"short",day:"numeric",timeZone:"UTC"})}return String(e).length>t?String(e).slice(0,t):String(e)}function Rn(e,t,n=16){return bt.test(t)||/^\d{4}-\d{2}(-\d{2})?(T|$)/.test(e)?Ae(e,n,/month/i.test(t)):e.length>n?`${e.slice(0,Math.max(1,n-1))}…`:e}function ae(e,t){const n=(t!=null&&t.x&&e.columns.includes(t.x)?t.x:void 0)??e.columns.find(i=>vt.test(i))??e.columns[0],o=(t!=null&&t.y&&e.columns.includes(t.y)?t.y:void 0)??e.columns.find(i=>jt.test(i))??e.columns[1];return{labelCol:n,valueCol:o}}const J=20;function Le({result:e,themeMode:t,chartConfig:n,availableHeight:o,availableWidth:i}){const s=q[t],[l,c]=R.useState(null),{labelCol:a,valueCol:d}=ae(e,n),u=(n==null?void 0:n.maxItems)??J,f=Y(n==null?void 0:n.colorPalette),h=e.rows.slice(0,u).map(x=>({label:String(x[a]??""),value:Number(x[d]??0)})),p=e.rows.length>u,y=Math.max(...h.map(x=>x.value),1),j=i&&i>0?Math.max(240,Math.min(720,i)):600,b=Math.min(132,Math.max(82,j*.32)),g=10,v=34,m=o&&o>0?Math.max(96,o-4):h.length*v+g*2,A=Math.max(15,Math.min(v,(m-g*2)/Math.max(1,h.length))),z=Math.max(10,A-4),_=Math.max(80,g*2+h.length*A);return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("svg",{width:"100%",height:_,viewBox:`0 0 ${j} ${_}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:h.map((x,M)=>{const S=g+M*A,B=j-b-Math.min(84,j*.22),T=Math.max(x.value/y*B,2),k=l===M,w=f[0]??s.accent;return r.jsxs("g",{onMouseEnter:()=>c(M),onMouseLeave:()=>c(null),style:{cursor:"default"},children:[r.jsx("text",{x:b-8,y:S+z/2+4,textAnchor:"end",fontSize:11,fontFamily:s.font,fill:s.textSecondary,children:Rn(x.label,a)}),r.jsx("rect",{x:b,y:S,width:T,height:z,rx:3,fill:w,opacity:k?1:.88,style:{transition:"opacity 0.15s"}}),r.jsx("text",{x:b+T+6,y:S+z/2+4,textAnchor:"start",fontSize:11,fontFamily:s.fontMono,fill:s.textMuted,children:H(x.value,d,n==null?void 0:n.format)})]},M)})}),p&&r.jsxs("div",{style:{fontSize:11,color:s.textMuted,fontFamily:s.font,fontStyle:"italic",padding:"4px 12px"},children:["Showing ",J," of ",e.rows.length," rows"]})]})}function In({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=e.rows.slice(0,5),d=e.columns.filter(v=>v!==c&&a.some(m=>G(m[v])));if(d.length===0)return r.jsx(Le,{result:e,themeMode:t,chartConfig:n});const u=e.rows.slice(0,J).map(v=>String(v[c]??"")),f=Math.max(...e.rows.slice(0,J).flatMap(v=>d.map(m=>Math.abs(Number(v[m]??0)))),1),h=24,p=h/d.length,y=120,j=12,b=8,g=u.length*(h+b)+j*2;return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:d.map((v,m)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:l[m%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:v})]},v))}),r.jsx("svg",{width:"100%",height:g,viewBox:`0 0 600 ${g}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:u.map((v,m)=>{const A=j+m*(h+b),z=e.rows[m];return r.jsxs("g",{children:[r.jsx("text",{x:y-8,y:A+h/2+4,textAnchor:"end",fontSize:11,fontFamily:o.font,fill:o.textSecondary,children:v.length>16?v.slice(0,15)+"…":v}),d.map((_,x)=>{const M=Number(z[_]??0),S=600-y-60,B=Math.max(Math.abs(M)/f*S,1),T=A+x*p,k=`${m}-${x}`;return r.jsxs("g",{onMouseEnter:()=>s(k),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:y,y:T,width:B,height:p-1,rx:2,fill:l[x%l.length],opacity:i===k?1:.85,style:{transition:"opacity 0.15s"}}),i===k&&r.jsx("text",{x:y+B+4,y:T+p/2+3,fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(M,_,n==null?void 0:n.format)})]},x)})]},m)})})]})}function Wn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=e.rows.slice(0,5),d=e.columns.filter(v=>v!==c&&a.some(m=>G(m[v])));if(d.length===0)return r.jsx(Le,{result:e,themeMode:t,chartConfig:n});const u=e.rows.slice(0,J),f=u.map(v=>String(v[c]??"")),h=Math.max(...u.map(v=>d.reduce((m,A)=>m+Math.abs(Number(v[A]??0)),0)),1),p=28,y=120,j=12,b=6,g=f.length*(p+b)+j*2;return r.jsxs("div",{style:{padding:"8px 0"},children:[r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:d.map((v,m)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:l[m%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:v})]},v))}),r.jsx("svg",{width:"100%",height:g,viewBox:`0 0 600 ${g}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:f.map((v,m)=>{const A=j+m*(p+b),z=u[m],_=600-y-60;let x=y;return r.jsxs("g",{children:[r.jsx("text",{x:y-8,y:A+p/2+4,textAnchor:"end",fontSize:11,fontFamily:o.font,fill:o.textSecondary,children:v.length>16?v.slice(0,15)+"…":v}),d.map((M,S)=>{const B=Math.abs(Number(z[M]??0)),T=Math.max(B/h*_,0),k=x;x+=T;const w=`${m}-${S}`;return r.jsxs("g",{onMouseEnter:()=>s(w),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:k,y:A,width:T,height:p,rx:S===0?3:0,fill:l[S%l.length],opacity:i===w?1:.85,style:{transition:"opacity 0.15s"}}),i===w&&T>30&&r.jsx("text",{x:k+T/2,y:A+p/2+4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:"#fff",fontWeight:600,children:H(B,M,n==null?void 0:n.format)})]},S)})]},m)})})]})}function nt({result:e,themeMode:t,showArea:n,chartConfig:o,availableHeight:i,availableWidth:s}){const l=q[t],[c,a]=R.useState(null),u=Y(o==null?void 0:o.colorPalette)[0]??l.accent,{labelCol:f,valueCol:h}=ae(e,o),p=e.rows.map(L=>({label:String(L[f]??""),value:Number(L[h]??0)}));if(p.length<2)return null;const y=s&&s>0?Math.max(240,Math.min(720,s)):560,j=i&&i>0?Math.max(150,Math.min(320,i-4)):212,b=y<360,g=b?44:56,v=b?8:16,m=16,A=48,z=y-g-v,_=j-m-A,x=Math.min(...p.map(L=>L.value)),S=Math.max(...p.map(L=>L.value))-x||1,B=z/(p.length-1),T=L=>g+L*B,k=L=>m+_-(L-x)/S*_,w=p.map((L,D)=>({x:T(D),y:k(L.value)})),I=w.reduce((L,D,V)=>{if(V===0)return`M ${D.x},${D.y}`;const Z=w[V-1],X=Z.x+(D.x-Z.x)/2;return`${L} C ${X},${Z.y} ${X},${D.y} ${D.x},${D.y}`},""),W=`${I} L ${w[w.length-1].x},${m+_} L ${g},${m+_} Z`,$=b?4:5,F=Array.from({length:$+1},(L,D)=>{const V=x+S*D/$;return{val:V,y:k(V)}}),E=Math.ceil(p.length/8),O=b?[...new Set(y<300?[0,p.length-1]:[0,Math.floor((p.length-1)/2),p.length-1])]:p.map((L,D)=>D).filter(L=>L%E===0||L===p.length-1);return r.jsx("div",{style:{position:"relative",padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:j,viewBox:`0 0 ${y} ${j}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},onMouseLeave:()=>a(null),children:[F.map((L,D)=>r.jsxs("g",{children:[r.jsx("line",{x1:g,y1:L.y,x2:g+z,y2:L.y,stroke:l.tableBorder,strokeWidth:.5}),r.jsx("text",{x:g-6,y:L.y+4,textAnchor:"end",fontSize:10,fontFamily:l.fontMono,fill:l.textMuted,children:H(L.val,h,o==null?void 0:o.format)})]},D)),r.jsx("path",{d:W,fill:u,opacity:n?.3:.15}),r.jsx("path",{d:I,fill:"none",stroke:u,strokeWidth:2,strokeLinejoin:"round"}),w.map((L,D)=>r.jsx("circle",{cx:L.x,cy:L.y,r:3,fill:u,style:{cursor:"crosshair"},onMouseEnter:()=>a({x:L.x,y:L.y,label:p[D].label,value:p[D].value})},D)),O.map(L=>{const D=p[L];return r.jsx("text",{x:T(L),y:m+_+16,textAnchor:L===0?"start":L===p.length-1?"end":"middle",fontSize:10,fontFamily:l.font,fill:l.textMuted,children:Ae(D.label)},L)}),r.jsx("line",{x1:g,y1:m,x2:g,y2:m+_,stroke:l.tableBorder,strokeWidth:1}),r.jsx("line",{x1:g,y1:m+_,x2:g+z,y2:m+_,stroke:l.tableBorder,strokeWidth:1}),r.jsx("text",{x:g+z/2,y:j-4,textAnchor:"middle",fontSize:10,fontWeight:600,fontFamily:l.font,fill:l.textMuted,letterSpacing:"0.04em",children:f}),b?null:r.jsx("text",{x:12,y:m+_/2,textAnchor:"middle",fontSize:10,fontWeight:600,fontFamily:l.font,fill:l.textMuted,letterSpacing:"0.04em",transform:`rotate(-90, 12, ${m+_/2})`,children:h}),c&&r.jsxs("g",{children:[r.jsx("rect",{x:c.x+8,y:c.y-20,width:90,height:32,rx:4,fill:l.cellBg,stroke:l.cellBorder,strokeWidth:1}),r.jsx("text",{x:c.x+13,y:c.y-8,fontSize:10,fontFamily:l.font,fill:l.textSecondary,children:Ae(c.label,12)}),r.jsx("text",{x:c.x+13,y:c.y+6,fontSize:11,fontFamily:l.fontMono,fill:l.textPrimary,fontWeight:600,children:H(c.value,h,o==null?void 0:o.format)})]})]})})}function Fn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),l=Y(n==null?void 0:n.colorPalette),c=n!=null&&n.x&&e.columns.includes(n.x)?n.x:e.columns[0],a=n!=null&&n.y&&e.columns.includes(n.y)?n.y:e.columns[1],d=n!=null&&n.color&&e.columns.includes(n.color)?n.color:void 0,u=e.rows.slice(0,200).map(k=>({x:Number(k[c]??0),y:Number(k[a]??0),color:d?String(k[d]??""):void 0})),f=560,h=300,p=52,y=16,j=16,b=36,g=f-p-y,v=h-j-b,m=Math.min(...u.map(k=>k.x)),A=Math.max(...u.map(k=>k.x)),z=Math.min(...u.map(k=>k.y)),_=Math.max(...u.map(k=>k.y)),x=A-m||1,M=_-z||1,S=k=>p+(k-m)/x*g,B=k=>j+v-(k-z)/M*v,T=d?[...new Set(u.map(k=>k.color))]:[];return r.jsxs("div",{style:{padding:"8px 0"},children:[d&&T.length>0&&r.jsx("div",{style:{display:"flex",gap:12,padding:"0 12px 6px",flexWrap:"wrap"},children:T.slice(0,12).map((k,w)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[r.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:l[w%l.length]}}),r.jsx("span",{style:{fontSize:10,fontFamily:o.font,color:o.textSecondary},children:k})]},k))}),r.jsxs("svg",{width:"100%",height:h,viewBox:`0 0 ${f} ${h}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:6},(k,w)=>{const I=z+M*w/5,W=B(I);return r.jsxs("g",{children:[r.jsx("line",{x1:p,y1:W,x2:p+g,y2:W,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:p-6,y:W+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(I,a,n==null?void 0:n.format)})]},w)}),Array.from({length:6},(k,w)=>{const I=m+x*w/5,W=S(I);return r.jsx("text",{x:W,y:j+v+16,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(I,c)},w)}),r.jsx("line",{x1:p,y1:j,x2:p,y2:j+v,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:p,y1:j+v,x2:p+g,y2:j+v,stroke:o.tableBorder,strokeWidth:1}),r.jsx("text",{x:p+g/2,y:h-2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,children:c}),r.jsx("text",{x:10,y:j+v/2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,transform:`rotate(-90, 10, ${j+v/2})`,children:a}),u.map((k,w)=>{const I=d?T.indexOf(k.color):0;return r.jsx("circle",{cx:S(k.x),cy:B(k.y),r:i===w?5:3.5,fill:l[I%l.length],opacity:i===w?1:.7,style:{cursor:"crosshair",transition:"r 0.1s, opacity 0.1s"},onMouseEnter:()=>s(w),onMouseLeave:()=>s(null)},w)}),i!==null&&r.jsxs("g",{children:[r.jsx("rect",{x:S(u[i].x)+8,y:B(u[i].y)-24,width:100,height:28,rx:4,fill:o.cellBg,stroke:o.cellBorder,strokeWidth:1}),r.jsxs("text",{x:S(u[i].x)+13,y:B(u[i].y)-8,fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:["(",H(u[i].x,c),", ",H(u[i].y,a,n==null?void 0:n.format),")"]})]})]})]})}const Dn=12;function rt({result:e,themeMode:t,chartConfig:n,isDonut:o}){const i=q[t],[s,l]=R.useState(null),{labelCol:c,valueCol:a}=ae(e,n),d=Y(n==null?void 0:n.colorPalette),u=e.rows.slice(0,Dn).map(m=>({label:String(m[c]??""),value:Math.abs(Number(m[a]??0))})),f=u.reduce((m,A)=>m+A.value,0)||1,h=90,p=90,y=70,j=o?40:0,b=[];let g=-Math.PI/2;u.forEach((m,A)=>{const z=m.value/f*2*Math.PI,_=g,x=g+z,M=h+y*Math.cos(_),S=p+y*Math.sin(_),B=h+y*Math.cos(x),T=p+y*Math.sin(x),k=z>Math.PI?1:0;let w;if(j>0){const I=h+j*Math.cos(_),W=p+j*Math.sin(_),$=h+j*Math.cos(x),F=p+j*Math.sin(x);w=`M ${M} ${S} A ${y} ${y} 0 ${k} 1 ${B} ${T} L ${$} ${F} A ${j} ${j} 0 ${k} 0 ${I} ${W} Z`}else w=`M ${h} ${p} L ${M} ${S} A ${y} ${y} 0 ${k} 1 ${B} ${T} Z`;b.push({path:w,color:d[A%d.length],label:m.label,value:m.value,pct:m.value/f*100}),g=x});const v=s!==null?b[s]:null;return r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"8px 12px",flexWrap:"wrap"},children:[r.jsxs("svg",{width:180,height:180,style:{flexShrink:0},onMouseLeave:()=>l(null),children:[b.map((m,A)=>r.jsx("path",{d:m.path,fill:m.color,opacity:s===null||s===A?1:.55,style:{cursor:"pointer",transition:"opacity 0.15s"},onMouseEnter:()=>l(A)},A)),o&&r.jsxs(r.Fragment,{children:[r.jsx("text",{x:h,y:p-5,textAnchor:"middle",fontSize:11,fontFamily:i.fontMono,fill:i.textSecondary,children:H(v?v.value:f,a,n==null?void 0:n.format)}),r.jsx("text",{x:h,y:p+9,textAnchor:"middle",fontSize:9,fontFamily:i.font,fill:i.textMuted,children:v?`${v.pct.toFixed(1)}%`:"total"})]})]}),r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:180,overflowY:"auto",flex:1},children:b.map((m,A)=>r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,cursor:"default",opacity:s===null||s===A?1:.5},onMouseEnter:()=>l(A),onMouseLeave:()=>l(null),children:[r.jsx("div",{style:{width:10,height:10,borderRadius:2,background:m.color,flexShrink:0}}),r.jsx("span",{style:{fontSize:11,fontFamily:i.font,color:i.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.label}),r.jsxs("span",{style:{fontSize:11,fontFamily:i.fontMono,color:i.textMuted,marginLeft:"auto",flexShrink:0},children:[m.pct.toFixed(1),"%"]})]},A))})]})}function Nn({result:e,themeMode:t}){const n=q[t],[o,i]=R.useState(null),s=e.columns[0],l=e.columns.slice(1),c=e.rows.slice(0,30),a=c.flatMap(b=>l.map(g=>Number(b[g]??0))),d=Math.min(...a),f=Math.max(...a)-d||1,h=Math.min(50,480/l.length),p=24,y=100;function j(b){const g=(b-d)/f,v=Math.round(56+g*192),m=Math.round(139+g*-58),A=Math.round(253+g*-180);return`rgb(${v},${m},${A})`}return r.jsx("div",{style:{padding:"8px 0",overflowX:"auto"},children:r.jsxs("svg",{width:y+l.length*h+20,height:c.length*p+p+16,style:{display:"block",overflow:"visible"},children:[l.map((b,g)=>r.jsx("text",{x:y+g*h+h/2,y:14,textAnchor:"middle",fontSize:9,fontFamily:n.font,fill:n.textMuted,transform:`rotate(-30, ${y+g*h+h/2}, 14)`,children:b.length>8?b.slice(0,7)+"…":b},g)),c.map((b,g)=>{const v=String(b[s]??""),m=p+g*p;return r.jsxs("g",{children:[r.jsx("text",{x:y-6,y:m+p/2+4,textAnchor:"end",fontSize:10,fontFamily:n.font,fill:n.textSecondary,children:v.length>14?v.slice(0,13)+"…":v}),l.map((A,z)=>{const _=Number(b[A]??0),x=(o==null?void 0:o.r)===g&&(o==null?void 0:o.c)===z;return r.jsxs("g",{onMouseEnter:()=>i({r:g,c:z}),onMouseLeave:()=>i(null),children:[r.jsx("rect",{x:y+z*h,y:m,width:h-1,height:p-1,rx:2,fill:j(_),opacity:x?1:.85,stroke:x?n.accent:"none",strokeWidth:x?1.5:0}),x&&r.jsx("text",{x:y+z*h+h/2,y:m+p/2+4,textAnchor:"middle",fontSize:10,fontFamily:n.fontMono,fill:"#fff",fontWeight:600,children:H(_,A)})]},z)})]},g)})]})})}function En({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),c=Y(n==null?void 0:n.colorPalette)[0]??o.accent,a=(n!=null&&n.x&&e.columns.includes(n.x)?n.x:void 0)??e.columns.find(B=>e.rows.slice(0,5).some(T=>G(T[B])))??e.columns[0],d=e.rows.map(B=>Number(B[a]??0)).filter(B=>!isNaN(B));if(d.length===0)return null;const u=Math.min(20,Math.max(5,Math.ceil(Math.sqrt(d.length)))),f=Math.min(...d),y=(Math.max(...d)-f||1)/u,j=Array.from({length:u},(B,T)=>({low:f+T*y,high:f+(T+1)*y,count:0}));d.forEach(B=>{const T=Math.min(Math.floor((B-f)/y),u-1);j[T].count++});const b=Math.max(...j.map(B=>B.count),1),g=560,v=200,m=52,A=16,z=16,_=36,x=g-m-A,M=v-z-_,S=x/u;return r.jsx("div",{style:{padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:v,viewBox:`0 0 ${g} ${v}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:5},(B,T)=>{const k=b*(T+1)/5,w=z+M-k/b*M;return r.jsxs("g",{children:[r.jsx("line",{x1:m,y1:w,x2:m+x,y2:w,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:m-6,y:w+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:Math.round(k)})]},T)}),j.map((B,T)=>{const k=B.count/b*M,w=m+T*S,I=z+M-k,W=i===T;return r.jsxs("g",{onMouseEnter:()=>s(T),onMouseLeave:()=>s(null),children:[r.jsx("rect",{x:w+1,y:I,width:S-2,height:k,rx:1,fill:c,opacity:W?1:.85,style:{transition:"opacity 0.1s"}}),W&&r.jsx("text",{x:w+S/2,y:I-4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:B.count})]},T)}),j.filter((B,T)=>T%Math.ceil(u/6)===0).map((B,T)=>{const k=j.indexOf(B);return r.jsx("text",{x:m+k*S+S/2,y:z+M+16,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(B.low,a,n==null?void 0:n.format)},T)}),r.jsx("line",{x1:m,y1:z,x2:m,y2:z+M,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:m,y1:z+M,x2:m+x,y2:z+M,stroke:o.tableBorder,strokeWidth:1}),r.jsx("text",{x:m+x/2,y:v-2,textAnchor:"middle",fontSize:10,fontFamily:o.font,fill:o.textMuted,children:a})]})})}function Pn({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),{labelCol:l,valueCol:c}=ae(e,n),a=Y(n==null?void 0:n.colorPalette),d=e.rows.slice(0,10).map(g=>({label:String(g[l]??""),value:Math.abs(Number(g[c]??0))}));if(d.length===0)return null;const u=d[0].value||1,f=400,h=36,p=4,y=16,j=d.length*(h+p)+y*2,b=f/2;return r.jsx("div",{style:{padding:"8px 0",display:"flex",justifyContent:"center"},children:r.jsx("svg",{width:f,height:j,style:{display:"block"},children:d.map((g,v)=>{const m=y+v*(h+p),A=g.value/u,z=Math.max(A*(f-80),40),_=i===v,x=v<d.length-1?d[v+1].value/u:A*.8,M=Math.max(x*(f-80),40),S=b-z/2,B=b+z/2,T=b+M/2,k=b-M/2,w=`M ${S} ${m} L ${B} ${m} L ${T} ${m+h} L ${k} ${m+h} Z`;return r.jsxs("g",{onMouseEnter:()=>s(v),onMouseLeave:()=>s(null),style:{cursor:"default"},children:[r.jsx("path",{d:w,fill:a[v%a.length],opacity:_?1:.85,style:{transition:"opacity 0.15s"}}),r.jsx("text",{x:b,y:m+h/2+1,textAnchor:"middle",fontSize:11,fontFamily:o.font,fill:"#fff",fontWeight:500,children:g.label}),r.jsxs("text",{x:b,y:m+h/2+13,textAnchor:"middle",fontSize:9,fontFamily:o.fontMono,fill:"rgba(255,255,255,0.7)",children:[H(g.value,c,n==null?void 0:n.format)," (",(A*100).toFixed(0),"%)"]})]},v)})})})}function Hn({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=Y(n==null?void 0:n.colorPalette),[s,l]=R.useState(null),c=e.rows.slice(0,20),a=e.columns.filter($=>c.some(F=>G(F[$]))),d=e.columns.filter($=>!a.includes($)),u=n!=null&&n.x&&d.includes(n.x)?n.x:d.find($=>/(?:^|_)(?:source|from|origin|upstream|supplier|producer|category)(?:_|$)/i.test($))??d[0],f=n!=null&&n.color&&d.includes(n.color)&&n.color!==u?n.color:d.find($=>$!==u&&/(?:^|_)(?:target|to|destination|downstream|consumer|customer|product)(?:_|$)/i.test($))??d.find($=>$!==u),h=n!=null&&n.y&&a.includes(n.y)?n.y:a[0];if(!u||!f||!h)return r.jsx(ie,{result:e,themeMode:t});const p=new Map;for(const $ of e.rows){const F=String($[u]??"").trim(),E=String($[f]??"").trim(),O=Math.abs(Number($[h]??0));if(!F||!E||!Number.isFinite(O)||O<=0)continue;const L=`${F}\0${E}`,D=p.get(L);p.set(L,{source:F,target:E,value:((D==null?void 0:D.value)??0)+O})}const y=[...p.values()].sort(($,F)=>F.value-$.value);if(y.length===0)return r.jsx(ie,{result:e,themeMode:t});const j=new Map,b=new Map;y.forEach($=>{j.set($.source,(j.get($.source)??0)+$.value),b.set($.target,(b.get($.target)??0)+$.value)});const g=[...j].sort(($,F)=>F[1]-$[1]).slice(0,12).map(([$])=>$),v=[...b].sort(($,F)=>F[1]-$[1]).slice(0,12).map(([$])=>$),m=new Set(g),A=new Set(v),z=y.filter($=>m.has($.source)&&A.has($.target)).slice(0,40),_=Math.max(...z.map($=>$.value),1),x=640,M=Math.max(250,Math.max(g.length,v.length)*34+40),S=132,B=x-144,T=12,k=28,w=($,F)=>F<=1?M/2:k+$*((M-k*2)/(F-1)),I=new Map(g.map(($,F)=>[$,F])),W=new Map(v.map(($,F)=>[$,F]));return r.jsx("div",{style:{padding:"8px 0",overflowX:"auto"},children:r.jsxs("svg",{role:"img","aria-label":`${u} to ${f} flow by ${h}`,width:"100%",height:M,viewBox:`0 0 ${x} ${M}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",minWidth:520},children:[r.jsx("text",{x:S,y:14,textAnchor:"middle",fontSize:10,fontWeight:700,fontFamily:o.font,fill:o.textMuted,children:u}),r.jsx("text",{x:B,y:14,textAnchor:"middle",fontSize:10,fontWeight:700,fontFamily:o.font,fill:o.textMuted,children:f}),z.map(($,F)=>{const E=w(I.get($.source)??0,g.length),O=w(W.get($.target)??0,v.length),L=`${$.source}\0${$.target}`,D=s===L,V=`M ${S+T},${E} C ${S+150},${E} ${B-150},${O} ${B},${O}`,Z=x/2,X=(E+O)/2;return r.jsxs("g",{onMouseEnter:()=>l(L),onMouseLeave:()=>l(null),children:[r.jsx("path",{d:V,fill:"none",stroke:i[F%i.length],strokeWidth:Math.max(2,$.value/_*18),opacity:s===null||D?.7:.14,strokeLinecap:"round",style:{transition:"opacity 0.15s",cursor:"default"}}),D?r.jsxs("g",{pointerEvents:"none",children:[r.jsx("rect",{x:Z-72,y:X-18,width:144,height:36,rx:5,fill:o.cellBg,stroke:o.cellBorder}),r.jsxs("text",{x:Z,y:X-3,textAnchor:"middle",fontSize:9.5,fontFamily:o.font,fill:o.textSecondary,children:[$.source," → ",$.target]}),r.jsx("text",{x:Z,y:X+11,textAnchor:"middle",fontSize:11,fontWeight:700,fontFamily:o.fontMono,fill:o.textPrimary,children:H($.value,h,n==null?void 0:n.format)})]}):null]},L)}),g.map(($,F)=>{const E=w(F,g.length);return r.jsxs("g",{children:[r.jsx("rect",{x:S,y:E-9,width:T,height:18,rx:3,fill:i[F%i.length]}),r.jsx("text",{x:S-7,y:E+3,textAnchor:"end",fontSize:10.5,fontFamily:o.font,fill:o.textSecondary,children:$.length>18?`${$.slice(0,17)}…`:$})]},`source-${$}`)}),v.map(($,F)=>{const E=w(F,v.length);return r.jsxs("g",{children:[r.jsx("rect",{x:B,y:E-9,width:T,height:18,rx:3,fill:i[(F+g.length)%i.length]}),r.jsx("text",{x:B+T+7,y:E+3,textAnchor:"start",fontSize:10.5,fontFamily:o.font,fill:o.textSecondary,children:$.length>18?`${$.slice(0,17)}…`:$})]},`target-${$}`)})]})})}function On({result:e,themeMode:t,chartConfig:n}){const o=q[t],[i,s]=R.useState(null),{labelCol:l,valueCol:c}=ae(e,n),a=e.rows.slice(0,15).map(S=>({label:String(S[l]??""),value:Number(S[c]??0)}));if(a.length===0)return null;let d=0;const u=a.map(S=>{const B=d;return d+=S.value,{...S,start:B,end:d}}),f=u.flatMap(S=>[S.start,S.end]),h=Math.min(0,...f),y=Math.max(0,...f)-h||1,j=560,b=240,g=52,v=16,m=16,A=44,z=j-g-v,_=b-m-A,x=z/u.length,M=S=>m+_-(S-h)/y*_;return r.jsx("div",{style:{padding:"8px 0"},children:r.jsxs("svg",{width:"100%",height:b,viewBox:`0 0 ${j} ${b}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},children:[Array.from({length:6},(S,B)=>{const T=h+y*B/5,k=M(T);return r.jsxs("g",{children:[r.jsx("line",{x1:g,y1:k,x2:g+z,y2:k,stroke:o.tableBorder,strokeWidth:.5}),r.jsx("text",{x:g-6,y:k+4,textAnchor:"end",fontSize:10,fontFamily:o.fontMono,fill:o.textMuted,children:H(T,c,n==null?void 0:n.format)})]},B)}),r.jsx("line",{x1:g,y1:M(0),x2:g+z,y2:M(0),stroke:o.textMuted,strokeWidth:1,strokeDasharray:"3,3"}),u.map((S,B)=>{const T=g+B*x,k=M(Math.max(S.start,S.end)),I=M(Math.min(S.start,S.end))-k,W=S.value>=0,$=i===B;return r.jsxs("g",{onMouseEnter:()=>s(B),onMouseLeave:()=>s(null),children:[B<u.length-1&&r.jsx("line",{x1:T+x-2,y1:M(S.end),x2:T+x+2,y2:M(S.end),stroke:o.textMuted,strokeWidth:1,strokeDasharray:"2,2"}),r.jsx("rect",{x:T+4,y:k,width:x-8,height:Math.max(I,1),rx:2,fill:W?o.success:o.error,opacity:$?1:.8,style:{transition:"opacity 0.1s"}}),$&&r.jsxs("text",{x:T+x/2,y:k-4,textAnchor:"middle",fontSize:10,fontFamily:o.fontMono,fill:o.textPrimary,children:[S.value>=0?"+":"",H(S.value,c,n==null?void 0:n.format)]})]},B)}),u.map((S,B)=>r.jsx("text",{x:g+B*x+x/2,y:b-6,textAnchor:"middle",fontSize:9,fontFamily:o.font,fill:o.textMuted,transform:`rotate(-20, ${g+B*x+x/2}, ${b-6})`,children:S.label.length>8?S.label.slice(0,7)+"…":S.label},B)),r.jsx("line",{x1:g,y1:m,x2:g,y2:m+_,stroke:o.tableBorder,strokeWidth:1}),r.jsx("line",{x1:g,y1:m+_,x2:g+z,y2:m+_,stroke:o.tableBorder,strokeWidth:1})]})})}function qn({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=e.rows[0];if(!i)return null;const s=(n!=null&&n.y&&e.columns.includes(n.y)?n.y:void 0)??e.columns.find(M=>G(i[M]))??e.columns[0],l=Number(i[s]??0),c=(n==null?void 0:n.title)??s,a=l>100?l*1.2:100,d=Math.min(Math.max(l/a,0),1),u=120,f=110,h=80,p=Math.PI,y=0,j=p-(p-y)*d,b=u+h*Math.cos(p),g=f+h*Math.sin(p),v=u+h*Math.cos(j),m=f+h*Math.sin(j),A=d>.5?1:0,z=u+h*Math.cos(y),_=f+h*Math.sin(y),x=d<.33?o.error:d<.66?o.warning:o.success;return r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"16px 24px"},children:r.jsxs("svg",{width:240,height:140,style:{display:"block",overflow:"visible"},children:[r.jsx("path",{d:`M ${b} ${g} A ${h} ${h} 0 1 1 ${z} ${_}`,fill:"none",stroke:o.tableBorder,strokeWidth:12,strokeLinecap:"round"}),d>0&&r.jsx("path",{d:`M ${b} ${g} A ${h} ${h} 0 ${A} 1 ${v} ${m}`,fill:"none",stroke:x,strokeWidth:12,strokeLinecap:"round"}),r.jsx("text",{x:u,y:f-4,textAnchor:"middle",fontSize:28,fontFamily:o.fontMono,fill:x,fontWeight:700,children:H(l,s,n==null?void 0:n.format)}),r.jsx("text",{x:u,y:f+16,textAnchor:"middle",fontSize:11,fontFamily:o.font,fill:o.textMuted,children:c})]})})}function Un(e,t,n,o){const i=Number(t);return t==null||typeof t!="number"&&isNaN(i)?t==null?"—":String(t):pe(e,t,n,{compact:Math.abs(i)>=1e5,format:o})}function wt({result:e,themeMode:t,chartConfig:n}){const o=q[t],i=Y(n==null?void 0:n.colorPalette),s=e.rows[0];if(!s)return null;const l=n!=null&&n.y&&e.columns.includes(n.y)?n.y:e.columns.find(a=>G(s[a]))??e.columns[0],c=Un(l,s[l],e.rows.map(a=>a[l]),n==null?void 0:n.format);return r.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:54,padding:"8px 4px",boxSizing:"border-box",minWidth:0},children:r.jsx("span",{title:String(s[l]),style:{fontSize:"clamp(24px, 3.2vw, 40px)",fontWeight:750,fontFamily:o.fontMono,color:i[0]??o.accent,lineHeight:1.1,maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c})})}function Vn({config:e,columns:t,onChange:n,onClose:o,t:i}){const s={background:i.inputBg,border:`1px solid ${i.inputBorder}`,borderRadius:4,color:i.textPrimary,fontSize:11,fontFamily:i.font,padding:"4px 8px",outline:"none",width:"100%",boxSizing:"border-box"};return r.jsxs("div",{style:{position:"absolute",top:4,right:4,zIndex:100,background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:8,padding:12,width:240,boxShadow:"0 4px 16px rgba(0,0,0,0.3)",display:"grid",gap:8},onClick:l=>l.stopPropagation(),children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[r.jsx("span",{style:{fontSize:11,fontWeight:600,color:i.textPrimary,fontFamily:i.font},children:"Chart Settings"}),r.jsx("button",{onClick:o,style:{background:"none",border:"none",color:i.textMuted,cursor:"pointer",fontSize:14},children:"×"})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Title",r.jsx("input",{value:e.title??"",onChange:l=>n({title:l.target.value||void 0}),placeholder:"Chart title",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["X-axis label",r.jsx("input",{value:e.xLabel??"",onChange:l=>n({xLabel:l.target.value||void 0}),placeholder:"Auto",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Y-axis label",r.jsx("input",{value:e.yLabel??"",onChange:l=>n({yLabel:l.target.value||void 0}),placeholder:"Auto",style:{...s,marginTop:2}})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Legend",r.jsxs("select",{value:e.legendPosition??"top",onChange:l=>n({legendPosition:l.target.value}),style:{...s,marginTop:2},children:[r.jsx("option",{value:"top",children:"Top"}),r.jsx("option",{value:"bottom",children:"Bottom"}),r.jsx("option",{value:"left",children:"Left"}),r.jsx("option",{value:"right",children:"Right"}),r.jsx("option",{value:"none",children:"Hidden"})]})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Color palette",r.jsx("select",{value:e.colorPalette??"default",onChange:l=>n({colorPalette:l.target.value}),style:{...s,marginTop:2},children:Object.keys(ke).map(l=>r.jsx("option",{value:l,children:l.charAt(0).toUpperCase()+l.slice(1)},l))})]}),r.jsxs("label",{style:{fontSize:10,color:i.textMuted,fontFamily:i.font},children:["Max items",r.jsx("input",{type:"number",value:e.maxItems??J,min:5,max:200,onChange:l=>n({maxItems:parseInt(l.target.value)||J}),style:{...s,marginTop:2}})]})]})}function $t({result:e,themeMode:t,chartConfig:n,availableHeight:o,availableWidth:i,onConfigChange:s}){const l=q[t],c=St(e,n),[a,d]=R.useState(!1);return c==="kpi"?r.jsx(wt,{result:e,themeMode:t,chartConfig:n}):r.jsxs("div",{style:{position:"relative"},children:[(n==null?void 0:n.title)&&r.jsx("div",{style:{padding:"8px 12px 0",fontSize:13,fontWeight:600,color:l.textPrimary,fontFamily:l.font,textAlign:"center"},children:n.title}),s&&r.jsx("button",{onClick:()=>d(!a),title:"Chart settings",style:{position:"absolute",top:4,right:4,zIndex:50,background:a?`${l.accent}18`:"transparent",border:`1px solid ${a?l.accent:"transparent"}`,borderRadius:4,color:a?l.accent:l.textMuted,cursor:"pointer",fontSize:14,padding:"2px 6px",lineHeight:1},children:"⚙"}),a&&s&&r.jsx(Vn,{config:n??{},columns:e.columns,onChange:u=>s(u),onClose:()=>d(!1),t:l}),Qn(c,e,t,n,o,i)]})}function Qn(e,t,n,o,i,s){const l=o!=null&&o.x&&t.columns.includes(o.x)?o.x:void 0,c=o!=null&&o.y&&t.columns.includes(o.y)?o.y:void 0,a=l||c?Yn(t,l,c):t;switch(e){case"line":return r.jsx(nt,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s});case"area":return r.jsx(nt,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s,showArea:!0});case"bar":return r.jsx(Le,{result:a,themeMode:n,chartConfig:o,availableHeight:i,availableWidth:s});case"grouped-bar":return r.jsx(In,{result:a,themeMode:n,chartConfig:o});case"stacked-bar":return r.jsx(Wn,{result:a,themeMode:n,chartConfig:o});case"scatter":return r.jsx(Fn,{result:t,themeMode:n,chartConfig:o});case"pie":return r.jsx(rt,{result:t,themeMode:n,chartConfig:o,isDonut:!1});case"donut":return r.jsx(rt,{result:t,themeMode:n,chartConfig:o,isDonut:!0});case"heatmap":return r.jsx(Nn,{result:t,themeMode:n});case"histogram":return r.jsx(En,{result:t,themeMode:n,chartConfig:o});case"funnel":return r.jsx(Pn,{result:t,themeMode:n,chartConfig:o});case"sankey":return r.jsx(Hn,{result:t,themeMode:n,chartConfig:o});case"waterfall":return r.jsx(On,{result:t,themeMode:n,chartConfig:o});case"gauge":return r.jsx(qn,{result:t,themeMode:n,chartConfig:o});case"kpi":return r.jsx(wt,{result:t,themeMode:n,chartConfig:o});default:return r.jsx(ie,{result:t,themeMode:n})}}function Yn(e,t,n){const o=e.columns,i=[];t&&o.includes(t)&&i.push(t),n&&o.includes(n)&&i.push(n);for(const s of o)i.includes(s)||i.push(s);return i.join(",")===o.join(",")?e:{...e,columns:i,rows:e.rows.map(s=>{const l={};for(const c of i)l[c]=s[c];return l})}}const Be=/date|time|day|month|year|week|quarter|period|_at$|^at$/i,Te=/(?:^|_)(?:id|uuid|key|code)$/i,ze=/(?:name|title|label|display|description|customer|account|product|region|segment|category|channel)$/i,Zn=new Set(["bar","grouped-bar","stacked-bar","line","area","scatter","pie","donut","heatmap","histogram","funnel","sankey","waterfall","gauge","kpi","table"]);function ot(e){return typeof e=="number"?Number.isFinite(e):typeof e=="string"?e.trim()!==""&&Number.isFinite(Number(e)):!1}function Mt(e){const t=e.rows.slice(0,20);return t.length===0?[]:e.columns.filter(n=>t.some(o=>ot(o[n]))&&t.every(o=>{const i=o[n];return i==null||i===""||ot(i)}))}function Gn(e,t){const n=e.columns.filter(o=>!t.includes(o));return n.find(o=>ze.test(o)&&!Te.test(o))??n.find(o=>!Te.test(o))??n[0]??e.columns[0]}function Xn(e){return e.columns.filter(t=>{if(!Te.test(t))return!1;const n=t.replace(/(?:_)?(?:id|uuid|key|code)$/i,"").replace(/_+$/,"");return e.columns.some(o=>o!==t&&(n.length>0&&o.toLowerCase().startsWith(n.toLowerCase())&&ze.test(o)||n.length===0&&ze.test(o)))})}function Kn(e,t){if(t.length===0)return e;const n=new Set(t);return{...e,columns:e.columns.filter(o=>!n.has(o)),rows:e.rows.map(o=>Object.fromEntries(Object.entries(o).filter(([i])=>!n.has(i))))}}function kt(e,t){const n=Mt(e),o=e.rows.length>0,i=e.columns.filter(g=>!n.includes(g));if(!(o&&n.length>=1))return{config:{...t??{},chart:"table",decisionSource:"data",rationale:"The returned rows do not contain a numeric measure to plot."},chartable:!1,reason:"No numeric measure"};const l=Gn(e,n),c=t!=null&&t.x&&e.columns.includes(t.x)?t.x:l,a=t!=null&&t.y&&e.columns.includes(t.y)?t.y:n.find(g=>g!==c)??n[0],d=Cn(e,n,i,c),u=Jn(t==null?void 0:t.chart),f=t==null?void 0:t.decisionSource,h=f==="authored"||f==="user",p=h&&u||u&&er(u,e,n,i,c,a)?u:d.chart,y=!!(u&&u!==p&&!h),j=t!=null&&t.color&&e.columns.includes(t.color)?t.color:p==="sankey"?i.find(g=>g!==c):t==null?void 0:t.color,b=y?`${d.reason}; replaced the agent suggestion because the returned data is not compatible.`:u&&!h?"Agent-selected visualization validated against the returned data.":d.reason;return{config:{...t??{},chart:p,x:c,y:a,...j?{color:j}:{},decisionSource:h?f:u&&!y?"agent":"data",rationale:b},chartable:p!=="table",reason:b}}function Jn(e){if(typeof e!="string")return;const t=e.toLowerCase().replace(/_/g,"-").replace("single-value","kpi");return Zn.has(t)?t:void 0}function Cn(e,t,n,o){return e.rows.length===1&&t.length>=1?{chart:"kpi",reason:"Single returned value"}:Be.test(o)&&t.length>=1?{chart:"line",reason:`Time-like field ${o}`}:n.length>0&&t.length>=2?{chart:"grouped-bar",reason:"One category with multiple numeric measures"}:n.length>0&&t.length===1?{chart:"bar",reason:"Categorical comparison with one numeric measure"}:t.length>=2?{chart:"scatter",reason:"Two continuous numeric measures"}:{chart:"table",reason:"No comparable category or time axis was returned"}}function er(e,t,n,o,i,s){return e==="table"?!0:e==="kpi"||e==="gauge"?n.length>=1&&t.rows.length===1:e==="line"||e==="area"?n.includes(s)&&Be.test(i):e==="scatter"?n.length>=2:e==="sankey"?o.length>=2&&n.length>=1:e==="histogram"?n.length>=1:e==="grouped-bar"||e==="stacked-bar"?o.length>=1&&n.length>=2:e==="pie"||e==="donut"?o.length>=1&&n.length>=1&&t.rows.length>=2&&t.rows.length<=8:e==="heatmap"?t.columns.length>=3&&n.length>=1:e==="funnel"||e==="waterfall"?o.length>=1&&n.length>=1:e==="bar"?o.length>=1&&n.length>=1&&!Be.test(i):!1}function uo({result:e,themeMode:t,t:n,chartConfig:o,embedded:i=!1,tabLabels:s,contentMaxHeight:l,tableMaxHeight:c}){const a=e.rows.length===0,[d,u]=R.useState(),[f,h]=R.useState(!1),p=R.useMemo(()=>({...o??{},...d??{}}),[o,d]),{config:y,chartable:j}=kt(e,p),b=R.useMemo(()=>Mt(e),[e]),g=R.useMemo(()=>Xn(e),[e]),v=R.useMemo(()=>f?e:Kn(e,g),[g,e,f]),[m,A]=R.useState("table"),z=x=>({border:"none",background:"transparent",cursor:"pointer",fontFamily:n.font,fontSize:11,fontWeight:700,padding:"2px 4px",color:x?n.accent:n.textMuted,borderBottom:`2px solid ${x?n.accent:"transparent"}`}),_=Me.some(x=>x.value===y.chart)?y.chart:"bar";return r.jsxs("div",{style:{border:i?"none":`1px solid ${n.headerBorder}`,background:n.cellBg,borderRadius:i?0:8,overflow:"hidden"},children:[r.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",padding:i?"9px 14px":"5px 9px",borderBottom:`1px solid ${n.headerBorder}`},children:[j&&r.jsx("button",{type:"button",onClick:()=>A("table"),style:z(m==="table"),children:(s==null?void 0:s.table)??"Table"}),j&&r.jsx("button",{type:"button",onClick:()=>A("chart"),style:z(m==="chart"),children:(s==null?void 0:s.chart)??"Chart"}),!j&&!a&&r.jsx("span",{style:{fontSize:11,fontWeight:700,color:n.textMuted},children:(s==null?void 0:s.table)??"Table"}),j&&m==="chart"?r.jsx("select",{value:_,onChange:x=>u(M=>({...M??{},chart:x.target.value,decisionSource:"user",rationale:"Selected manually."})),title:"Chart type",style:{fontFamily:n.font,fontSize:10.5,fontWeight:600,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 4px",cursor:"pointer"},children:Me.map(x=>r.jsx("option",{value:x.value,children:x.label},x.value))}):null,j&&m==="chart"?r.jsxs(r.Fragment,{children:[r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["X",r.jsx("select",{"aria-label":"X-axis field",value:y.x??"",onChange:x=>u(M=>({...M??{},x:x.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.map(x=>r.jsx("option",{value:x,children:x},x))})]}),b.length>0?r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["Y",r.jsx("select",{"aria-label":"Y-axis field",value:y.y??"",onChange:x=>u(M=>({...M??{},y:x.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:b.map(x=>r.jsx("option",{value:x,children:x},x))})]}):null,y.chart==="sankey"?r.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:n.textMuted,fontSize:10.5},children:["Target",r.jsx("select",{"aria-label":"Sankey target field",value:y.color??"",onChange:x=>u(M=>({...M??{},color:x.target.value,decisionSource:"user",rationale:"Sankey target selected manually."})),style:{fontFamily:n.font,fontSize:10.5,color:n.textSecondary,background:n.cellBg,border:`1px solid ${n.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.filter(x=>!b.includes(x)&&x!==y.x).map(x=>r.jsx("option",{value:x,children:x},x))})]}):null]}):null,j&&m==="chart"&&y.rationale?r.jsxs("span",{title:y.rationale,style:{fontSize:10.5,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:230},children:["Smart chart · ",y.chart]}):null,r.jsxs("span",{style:{marginLeft:"auto",fontSize:10.5,color:n.textMuted,alignSelf:"center"},children:[e.rowCount??e.rows.length," rows"]})]}),r.jsx("div",{style:{padding:i?12:8,minHeight:j&&m==="chart"?200:void 0,maxHeight:l??(i?380:320),overflow:"auto"},children:a?r.jsxs("div",{style:{padding:"18px 8px",textAlign:"center",color:n.textMuted,fontSize:12},children:["The query ran successfully and matched 0 rows",e.columns.length>0?` (columns: ${e.columns.join(", ")})`:"","."]}):j&&m==="chart"?r.jsx($t,{result:e,themeMode:t,chartConfig:y,onConfigChange:x=>u(M=>({...M??{},...x,decisionSource:"user",rationale:"Adjusted manually."}))}):r.jsxs(r.Fragment,{children:[g.length>0?r.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:6},children:r.jsx("button",{type:"button",onClick:()=>h(x=>!x),style:{border:"none",background:"transparent",color:n.accent,cursor:"pointer",fontSize:10.5,padding:0},children:f?"Hide technical fields":"Show IDs"})}):null,r.jsx(ie,{result:v,themeMode:t,maxHeight:c})]})})]})}const tr=3;function nr(e){const{business360:t,block:n,value:o,generated:i=!1}=e,s=e.maxPerKind??tr,l=t.focus,c=[];o&&c.push({kind:"value",name:o,detail:l.name?`Reported by ${l.name}.`:void 0});const a=(n==null?void 0:n.owner)??l.owner,d=(n==null?void 0:n.status)??l.status,u=(n==null?void 0:n.reviewCadence)??ge(l.metadata,"reviewCadence");c.push({kind:"block",name:l.name,owner:a,status:d,detail:or({reviewCadence:u,businessOutcome:(n==null?void 0:n.businessOutcome)??ge(l.metadata,"businessOutcome"),decisionUse:n==null?void 0:n.decisionUse})});const f=it([...t.businessDefinition.terms,...t.businessDefinition.definedByTerms]);for(const y of f.slice(0,s))y.id!==l.id&&c.push({kind:"term",name:y.name,owner:y.owner,detail:"Business term this answer is defined in."});for(const y of be(n==null?void 0:n.metricRefs).slice(0,s))c.push({kind:"metric",name:y,detail:"Governed metric used in the calculation."});for(const y of be(n==null?void 0:n.dimensionRefs).slice(0,s))c.push({kind:"dimension",name:y,detail:"Dimension used to slice the value."});for(const y of t.technicalSources.dbtModels.slice(0,s))c.push({kind:"model",name:y.name,detail:"dbt model the certified SQL builds on."});const h=it([...t.technicalSources.dbtSources,...t.technicalSources.sourceTables]);for(const y of h.slice(0,s))c.push({kind:"source",name:y.name,detail:"Raw source table the data originates from."});const p=be((n==null?void 0:n.caveats)??sr(l.metadata,"caveats"));return{value:o,summary:ir({focus:l,blockOwner:a,reviewCadence:u,generated:i,sourceAssets:h}),steps:c,trustLabel:e.trustLabel??(i?"review_required":void 0),freshness:e.freshness??rr(n==null?void 0:n.dataState,n==null?void 0:n.dataStateDetail)??ge(l.metadata,"freshness"),caveats:p.length>0?p:void 0}}function rr(e,t){switch(e){case"failed":return t?`upstream failed — ${t}`:"upstream failed";case"stale":return t?`stale data — ${t}`:"stale data";default:return}}function or(e){const t=[];return e.businessOutcome?t.push(e.businessOutcome):e.decisionUse&&t.push(`Supports: ${e.decisionUse}.`),e.reviewCadence&&t.push(`Reviewed ${e.reviewCadence}.`),t.length>0?t.join(" "):void 0}function ir(e){const t=e.blockOwner?` owned by ${e.blockOwner}`:"",n=e.sourceAssets.length>0?` It traces back to ${e.sourceAssets[0].name}.`:"";if(e.generated)return`This value was generated from ${e.focus.name}${t} and still needs analyst review before it can be certified.${n}`;const o=e.reviewCadence?`, reviewed ${e.reviewCadence}`:"";return`This value comes from the certified ${e.focus.name}${t}${o}.${n}`}function ge(e,t){const n=e==null?void 0:e[t];return typeof n=="string"&&n.trim().length>0?n:void 0}function sr(e,t){const n=e==null?void 0:e[t];return Array.isArray(n)?n.filter(o=>typeof o=="string"&&o.trim().length>0):[]}function be(e){if(!e)return[];const t=new Set,n=[];for(const o of e){const i=typeof o=="string"?o.trim():"";!i||t.has(i.toLowerCase())||(t.add(i.toLowerCase()),n.push(i))}return n}function it(e){const t=new Set,n=[];for(const o of e)t.has(o.id)||(t.add(o.id),n.push(o));return n}function At(e){var o,i;const t=e.dqlArtifact,n=(o=t==null?void 0:t.source)==null?void 0:o.trim();return n?{source:n,kind:t==null?void 0:t.kind,name:t==null?void 0:t.name,sourcePath:t==null?void 0:t.sourcePath,metrics:ve(t==null?void 0:t.metrics),dimensions:ve(t==null?void 0:t.dimensions),filters:((t==null?void 0:t.filters)??[]).map(s=>{var d,u;const l=(d=s.dimension)==null?void 0:d.trim(),c=((u=s.operator)==null?void 0:u.trim())||"equals",a=ve(s.values);return!l||a.length===0?"":`${l} ${c} ${a.join(", ")}`}).filter(Boolean),timeDimension:(i=t==null?void 0:t.timeDimension)!=null&&i.name?[t.timeDimension.name,t.timeDimension.granularity].filter(Boolean).join(" / "):void 0,orderBy:((t==null?void 0:t.orderBy)??[]).map(s=>{var a,d;const l=(a=s.name)==null?void 0:a.trim(),c=(d=s.direction)==null?void 0:d.trim();return l&&c?`${l} ${c}`:""}).filter(Boolean),limit:typeof(t==null?void 0:t.limit)=="number"&&Number.isFinite(t.limit)?t.limit:void 0}:null}function lr(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n.kind!=="tool_result"||n.id!=="governed_answer")continue;const o=n.output;if(o&&typeof o=="object"&&"kind"in o)return o}return null}function ve(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter(Boolean):[]}function ar(e){const t=e.result;if(!t||!Array.isArray(t.rows))return null;const o=(Array.isArray(t.columns)?t.columns:[]).map(l=>typeof l=="string"?l:l&&typeof l=="object"&&typeof l.name=="string"?String(l.name):String(l)),i=o.length>0?o:t.rows.find(l=>l&&typeof l=="object"&&!Array.isArray(l))?Object.keys(t.rows.find(l=>l&&typeof l=="object"&&!Array.isArray(l))):t.rows.find(l=>Array.isArray(l))?t.rows.find(l=>Array.isArray(l)).map((l,c)=>`column_${c+1}`):[],s=t.rows.map(l=>{if(Array.isArray(l))return Object.fromEntries(i.map((c,a)=>[c,l[a]]));if(l&&typeof l=="object"){const c=l;return Object.fromEntries(i.map(a=>[a,c[a]]))}return Object.fromEntries(i.map(c=>[c,void 0]))});return{columns:i,rows:s,rowCount:typeof t.rowCount=="number"?t.rowCount:s.length,...typeof t.resultFingerprint=="string"?{resultFingerprint:t.resultFingerprint}:{},...t.executionReceipt&&typeof t.executionReceipt=="object"?{executionReceipt:t.executionReceipt}:{},...typeof t.trustState=="string"?{trustState:t.trustState}:{},...typeof t.answerTier=="string"?{answerTier:t.answerTier}:{},executionTime:t.executionTime}}function cr(e,t){const n=e&&typeof e=="object"?e:{},o=typeof n.chart=="string"?n.chart:void 0,i=n.decisionSource==="authored"||n.decisionSource==="agent"||n.decisionSource==="data"||n.decisionSource==="user"?n.decisionSource:void 0,s=o||(typeof t.suggestedViz=="string"?t.suggestedViz:void 0),l=s?s.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":s:void 0;return{...l?{chart:l}:{},...l?{decisionSource:i??(o?"authored":"agent")}:{},...typeof n.rationale=="string"?{rationale:n.rationale}:{},...typeof n.x=="string"?{x:n.x}:{},...typeof n.y=="string"?{y:n.y}:{},...typeof n.color=="string"?{color:n.color}:{},...typeof n.title=="string"?{title:n.title}:{}}}function dr(e,t){return!t||t.columns.length===0?e:kt(t,e).config}function je(e){if(typeof e!="string")return;const t=e.replace(/\s+/g," ").trim();if(t)return t.length>180?`${t.slice(0,177)}...`:t}function Bt(e){const t=ur(e,["Answer","Business summary","Summary"]);if(t)return st(t,340);const n=/^(?:reuse evidence|certified result preview|result preview|result summary|trust status|next action|recommended action|sql used by block|reusable block sql|proposed sql|sql generated|sql draft|evidence|parameters|lineage|technical lineage)\s*:/i,o=/^(?:SELECT|WITH|FROM|WHERE|GROUP BY|ORDER BY|LIMIT)\b/i,i=[];for(const l of e.split(/\r?\n/)){const c=l.trim();if(!(!c||/^#{1,6}\s*/.test(c)||/^```/.test(c)||/^\|/.test(c))&&!/^outcome\s*:/i.test(c)){if(n.test(c)||o.test(c)){if(i.length>0)break;continue}if(i.push(c),i.length>=5)break}}const s=i.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim();return st(s,340)}function ur(e,t){var u,f,h;const n=e.split(/\r?\n/),o=t.map(p=>p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),i=new RegExp(`^\\s*(?:#{1,6}\\s*)?(?:[-*]\\s*)?(?:\\*\\*)?(${o})(?:\\*\\*)?\\s*:\\s*(.*)$`,"i"),s=/^\s*(?:#{1,6}\s*)?(?:[-*]\s*)?(?:\*\*)?[A-Z][A-Za-z /-]{2,42}(?:\*\*)?\s*:/,l=n.findIndex(p=>i.test(p));if(l<0)return;const c=((h=(f=(u=n[l])==null?void 0:u.match(i))==null?void 0:f[2])==null?void 0:h.trim())??"",a=c?[c]:[];for(let p=l+1;p<n.length;p+=1){const y=n[p]??"";if(s.test(y)||/^\s*```/.test(y))break;y.trim()&&a.push(y.trim())}return a.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim()||void 0}function st(e,t){const n=e.replace(/\s+/g," ").trim();if(n.length<=t)return n;const o=n.slice(0,t-1),i=Math.max(o.lastIndexOf(". "),o.lastIndexOf("; "));if(i>100)return o.slice(0,i+1).trim();const s=o.lastIndexOf(" ");return`${o.slice(0,s>80?s:o.length).trim()}...`}function xr({answer:e,themeMode:t,showSql:n=!0,compact:o=!1,sourceQuestion:i,onInvestigate:s,onInsertSql:l,onCreateBlock:c}){var Ie,We,Fe,De,Ne,Ee,Pe,He,Oe,qe,Ue,Ve,Qe;const a=q[t],{dispatch:d}=Ht(),u=ar(e),f=cr((Ie=e.result)==null?void 0:Ie.chartConfig,e),[h,p]=R.useState(),y=dr({...f??{},...h??{}},u),j=!!(u&&St(u,y)!=="table"),b=e.analysisPlan??((We=e.evidence)==null?void 0:We.analysisPlan),g=n?e.sql??((Fe=e.result)==null?void 0:Fe.sql)??e.proposedSql??(b==null?void 0:b.sql):void 0,v=At(e),m=e.executionError??(((Ne=(De=e.evidence)==null?void 0:De.execution)==null?void 0:Ne.status)==="failed"?e.evidence.execution.message:void 0),A=((Ee=e.result)==null?void 0:Ee.blockPath)??((Pe=e.block)==null?void 0:Pe.sourcePath),z=!!(g||m||n&&A),_=!!e.evidence,[x,M]=R.useState("answer"),[S,B]=R.useState(!1),T=It(e),k=Pr(T,a),w=(e.answer??e.text??"").replace(/\n\n_Question:_[\s\S]*$/m,"").trim(),I=o?Bt(w):w,W=((He=e.result)==null?void 0:He.blockName)??((Oe=e.block)==null?void 0:Oe.name)??((Ue=(qe=e.citations)==null?void 0:qe.find(N=>N.kind==="block"))==null?void 0:Ue.name),$=Ur(e,W),F=Hr(e,u,W,A),[E,O]=R.useState(null),L=!!(l&&g),D=!!(c&&g),V=je(b==null?void 0:b.question)??je(i)??je(I)??"Investigate this answer",Z=!!(s&&V),X=Tt(e,{sql:g,executionError:m,blockName:W,result:u}),Ft=()=>{!l||!g||(l(g,W??(b==null?void 0:b.question)??"AI SQL preview",{question:i??(b==null?void 0:b.question)}),O("Inserted SQL preview cell for review."))},Dt=()=>{!c||!g||c(g,{title:(v==null?void 0:v.name)??W??(b==null?void 0:b.question)??"AI DQL draft",description:I||(b==null?void 0:b.routeReason)||"AI generated DQL draft.",tags:["ai-generated","review-required"]})},Nt=()=>{!s||!V||s({question:V,title:$?`${$}: ${V}`:V,answerSummary:I,blockName:$,sql:g,evidence:e.evidence})},he=[{id:"answer",label:o?"Summary":"Answer",visible:!0},{id:"dql",label:"DQL",visible:!!v},{id:"visual",label:o?"Chart":"Visualization",visible:j},{id:"data",label:"Data",visible:!!u},{id:"sql",label:"SQL / Block",visible:n&&z},{id:"lineage",label:o?"Trace":"Lineage",visible:_},{id:"context",label:o?"Context":"Business Context",visible:_},{id:"review",label:o?"Trust":"Review",visible:_||!!((Ve=e.citations)!=null&&Ve.length)}].filter(N=>N.visible),Re=he.some(N=>N.id===x)?x:"answer",ce=he.filter(N=>N.id!=="answer"),me=ce.some(N=>N.id===x)?x:(Qe=ce[0])==null?void 0:Qe.id,ye=N=>N==="answer"?r.jsx(yr,{summary:I,answer:e,blockName:W,evidence:e.evidence,analysisPlan:b,result:u,sourceTier:e.sourceTier,compact:o,t:a}):N==="dql"&&v?r.jsx(Ir,{artifact:v,t:a}):N==="visual"&&u&&j?r.jsxs("div",{style:{padding:o?"8px 10px":"10px 12px",minHeight:o?180:220,display:"grid",gap:10},children:[r.jsx(Dr,{result:u,chartConfig:y,t:a,onChange:Et=>p(Pt=>({...Pt??{},...Et,decisionSource:"user",rationale:"Adjusted manually."}))}),r.jsx($t,{result:u,themeMode:t,chartConfig:y})]}):N==="data"&&u?r.jsx("div",{style:{maxHeight:o?320:420,overflow:"auto"},children:r.jsx(ie,{result:u,themeMode:t})}):N==="lineage"?r.jsx(_r,{evidence:e.evidence,t:a}):N==="context"?r.jsx(Lr,{evidence:e.evidence,t:a}):N==="sql"&&n&&z?r.jsx(Wr,{sql:g,blockPath:A,executionError:m,t:a}):N==="review"?r.jsx(Rr,{answer:e,t:a}):null;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:o?8:10,whiteSpace:"normal"},children:[r.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[r.jsx(Zt,{state:T}),r.jsx(Gt,{t:a,route:e.route}),C(e.cascade)&&r.jsx("span",{style:{border:`1px solid ${a.cellBorder}`,borderRadius:999,padding:"3px 8px",fontSize:11,fontWeight:700,color:a.textSecondary,background:a.tableHeaderBg},children:C(e.cascade)}),!o&&W&&r.jsxs("span",{style:{fontSize:12,fontFamily:a.fontMono,color:a.textSecondary},children:["block: ",W]}),u&&r.jsxs("span",{style:{fontSize:12,color:a.textMuted},children:[(u.rowCount??u.rows.length).toLocaleString()," rows",u.executionTime!==void 0&&r.jsxs(r.Fragment,{children:[" - ",Math.round(u.executionTime),"ms"]})]}),Z&&r.jsx("button",{type:"button",onClick:Nt,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:`${a.accent}12`,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:800},children:o?"Investigate":"Investigate deeper"}),D&&r.jsx("button",{type:"button",onClick:Dt,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:a.cellBg,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:700},children:o?"DQL draft":v?"Review DQL draft":"Create DQL draft"}),L&&r.jsx("button",{type:"button",onClick:Ft,style:{border:`1px solid ${a.accent}`,borderRadius:6,background:`${a.accent}18`,color:a.accent,cursor:"pointer",padding:o?"4px 8px":"5px 10px",fontSize:11,fontFamily:a.font,fontWeight:700},children:o?"SQL preview":"Insert SQL preview"})]}),E&&r.jsx("div",{style:{fontSize:11,color:"#3fb950"},children:E}),r.jsx(pr,{outcome:X,t:a,compact:o}),r.jsxs("div",{style:{border:`1px solid ${a.cellBorder}`,borderTop:`2px solid ${k}`,borderRadius:o?10:6,overflow:"hidden",background:a.cellBg},children:[!o&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 10px",borderBottom:`1px solid ${a.cellBorder}`,background:`${a.tableHeaderBg}70`,flexWrap:"wrap"},children:[he.map(N=>r.jsx(ft,{active:Re===N.id,label:N.label,onClick:()=>M(N.id),t:a},N.id)),!n&&A&&r.jsx("span",{style:{marginLeft:"auto",minWidth:0,fontSize:11,fontFamily:a.fontMono,color:a.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:A})]}),ye(o?"answer":Re),o&&ce.length>0&&r.jsxs("div",{style:{borderTop:`1px solid ${a.cellBorder}`,background:`${a.tableHeaderBg}45`},children:[r.jsxs("button",{type:"button",onClick:()=>B(N=>!N),style:{width:"100%",border:0,background:"transparent",color:a.textSecondary,padding:"8px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",fontSize:11,fontWeight:800},children:[r.jsx("span",{children:"Details"}),r.jsx("span",{style:{color:a.textMuted,fontFamily:a.fontMono},children:S?"hide":"show evidence"})]}),S&&r.jsxs("div",{style:{borderTop:`1px solid ${a.cellBorder}`},children:[r.jsx("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 12px",flexWrap:"wrap"},children:ce.map(N=>r.jsx(ft,{active:me===N.id,label:N.label,onClick:()=>M(N.id),t:a},N.id))}),me?ye(me):null]})]}),r.jsx(Fr,{items:F,t:a,accent:k}),r.jsx(Xt,{t:a,skills:e.appliedSkills,onOpenSkills:()=>d({type:"SET_MAIN_VIEW",view:"skills"}),onSuggestCorrection:N=>{try{window.sessionStorage.setItem("dql-skill-ai-correction",JSON.stringify({skillId:N.id,question:i,feedback:"Correct the guidance that shaped this answer."}))}catch{}d({type:"SET_MAIN_VIEW",view:"skills"})}})]})]})}function Tt(e,t){var n,o,i,s,l;if(e.kind==="no_answer")return{kind:"cannot_answer",label:"Cannot answer yet",detail:"The assistant did not find enough trusted context to safely answer or generate SQL.",nextAction:"Clarify the business object, metric, grain, or source table.",tone:"error"};if(e.certification==="certified"||e.kind==="certified"){const c=t.blockName??e.sourceCertifiedBlock??((n=e.block)==null?void 0:n.name);return{kind:"reuse_certified_block",label:"Reuse certified block",detail:c?`Existing DQL block ${c} answers this request.`:"A certified DQL artifact answers this request.",nextAction:"Use the certified block instead of creating duplicate SQL.",tone:"success"}}return t.executionError||e.executionError?{kind:"fix_sql",label:"Fix SQL",detail:"The generated or selected SQL needs correction before it can become reusable DQL.",nextAction:"Ask AI to repair, edit manually, then rerun preview.",tone:"error"}:(o=e.draftBlock)!=null&&o.path||e.draftBlockId?{kind:"use_existing_draft",label:"Use existing draft",detail:`A review-required DQL draft is available at ${((i=e.draftBlock)==null?void 0:i.path)??e.draftBlockId}.`,nextAction:"Open the draft, review metadata/tests/lineage, then certify manually.",tone:"accent"}:(l=(s=e.dqlArtifact)==null?void 0:s.source)!=null&&l.trim()?{kind:"create_dql_draft",label:"Review DQL draft",detail:"A review-required DQL artifact is available for analyst review.",nextAction:"Review DQL metadata, query logic, lineage, and result preview before certification.",tone:"warning"}:t.sql?{kind:t.result?"generate_sql_cell":"create_dql_draft",label:t.result?"Review SQL preview":"Create DQL draft",detail:t.result?`Review-required SQL preview returned ${(t.result.rowCount??t.result.rows.length).toLocaleString()} row${(t.result.rowCount??t.result.rows.length)===1?"":"s"}.`:"Review-required SQL is available but still needs preview and DQL metadata review.",nextAction:t.result?"Create a DQL draft after reviewing parameters and lineage; insert SQL only as a notebook preview.":"Run preview, inspect parameters, then create a draft block.",tone:"warning"}:{kind:"needs_review",label:"Needs review",detail:"The assistant returned business context but no executable certified answer or SQL draft.",nextAction:"Review evidence and ask for a specific SQL, reuse, or DQL draft action.",tone:"muted"}}function pr({outcome:e,t,compact:n}){const o=fr(e.tone,t);return r.jsxs("div",{style:{border:`1px solid ${o}45`,borderLeft:`3px solid ${o}`,borderRadius:n?10:7,background:`${o}10`,padding:n?"9px 10px":"10px 12px",display:"grid",gap:n?4:5},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[r.jsx("span",{style:{border:`1px solid ${o}55`,background:`${o}14`,color:o,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:850,lineHeight:1.1,textTransform:"uppercase",letterSpacing:0,flexShrink:0},children:e.label}),r.jsx("span",{style:{fontSize:n?12:12.5,color:t.textPrimary,fontWeight:750,overflow:"hidden",textOverflow:"ellipsis"},children:e.detail})]}),r.jsxs("div",{style:{fontSize:n?11.5:12,color:t.textSecondary,lineHeight:1.45},children:["Next: ",e.nextAction]})]})}function fr(e,t){switch(e){case"success":return t.success;case"accent":return t.accent;case"warning":return t.warning;case"error":return t.error;case"muted":default:return t.textMuted}}function hr({answer:e,blockName:t}){const[n,o]=R.useState(null),[i,s]=R.useState(!1),[l,c]=R.useState(!1),a=te.useCallback(async()=>{var d,u;if(!l){c(!0),s(!0);try{const f=await Ot.fetchBusiness360(t);if(!f){o(null);return}const h=(d=e.evidence)==null?void 0:d.outcome,p=lt(e,"metric"),y=lt(e,"dimension"),j=e.certification!=="certified"&&e.kind!=="certified",b=nr({business360:f,block:{name:t,owner:h==null?void 0:h.owner,status:((u=e.block)==null?void 0:u.status)??e.certification,reviewCadence:h==null?void 0:h.reviewCadence,caveats:h==null?void 0:h.caveats,decisionUse:h==null?void 0:h.decisionUse,metricRefs:p,dimensionRefs:y},value:mr(e),generated:j,trustLabel:e.trustLabel});o(b)}catch{o(null)}finally{s(!1)}}},[e,t,l]);return l?i?r.jsx("div",{style:{fontSize:11.5,color:"var(--text-tertiary, inherit)"},children:"Assembling derivation…"}):n?r.jsx(Ct,{walk:n,defaultOpen:!0}):null:r.jsx("button",{type:"button",onClick:()=>void a(),"aria-expanded":!1,style:{alignSelf:"flex-start",border:0,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 0",fontSize:12,fontWeight:700,textDecoration:"underline",textUnderlineOffset:3},children:"Why? Show how this was derived"})}function lt(e,t){var i,s;const n=(((i=e.evidence)==null?void 0:i.semanticObjects)??[]).filter(l=>l.kind===t).map(l=>l.name).filter(l=>!!l);if(n.length>0)return n;const o=e.analysisPlan??((s=e.evidence)==null?void 0:s.analysisPlan);return(t==="metric"?o==null?void 0:o.measures:o==null?void 0:o.dimensions)??[]}function mr(e){const t=e.result;if(t&&Array.isArray(t.rows)&&t.rows.length===1){const n=t.rows[0];if(n&&typeof n=="object"&&!Array.isArray(n)){const o=Object.values(n);if(o.length===1&&(typeof o[0]=="number"||typeof o[0]=="string"))return String(o[0])}}}function yr({summary:e,answer:t,blockName:n,evidence:o,analysisPlan:i,result:s,sourceTier:l,compact:c,t:a}){var u,f,h,p,y,j,b,g,v;const d=(u=i==null?void 0:i.followUps)==null?void 0:u[0];return r.jsxs("div",{style:{padding:c?14:12,display:"flex",flexDirection:"column",gap:c?10:12},children:[e?r.jsx(zt,{text:e,t:a,compact:c,summaryOnly:c}):r.jsx("div",{style:{fontSize:12,color:a.textMuted},children:"No summary text was returned."}),t&&n&&r.jsx(hr,{answer:t,blockName:n}),c?r.jsx("div",{style:{fontSize:11.5,color:a.textMuted,display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[l?Er(l):null,s?`${(s.rowCount??s.rows.length).toLocaleString()} rows`:null,((f=o==null?void 0:o.validation)==null?void 0:f.status)==="failed"?"needs review":null,((h=o==null?void 0:o.execution)==null?void 0:h.status)==="failed"?"data check failed":null].filter(Boolean).map((m,A)=>r.jsxs(te.Fragment,{children:[A>0&&r.jsx("span",{style:{color:a.cellBorder},children:"·"}),r.jsx("span",{children:m})]},`${m}-${A}`))}):r.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[l&&r.jsx(Q,{label:U(l),t:a}),s&&r.jsx(Q,{label:`${(s.rowCount??s.rows.length).toLocaleString()} rows`,t:a}),((p=o==null?void 0:o.validation)==null?void 0:p.status)&&r.jsx(Q,{label:`validation: ${o.validation.status}`,t:a}),((y=o==null?void 0:o.execution)==null?void 0:y.status)&&r.jsx(Q,{label:`execution: ${o.execution.status}`,t:a})]}),s&&!c&&r.jsx(zr,{result:s,t:a,compact:c}),i&&!c&&r.jsxs("div",{style:{display:"grid",gap:7,padding:c?"9px 10px":10,border:`1px solid ${a.cellBorder}`,borderRadius:8,background:`${a.tableHeaderBg}45`},children:[i.routeReason&&r.jsx("div",{style:{fontSize:c?12.5:12,lineHeight:1.45,color:a.textSecondary},children:i.routeReason}),(i.grain||((j=i.measures)==null?void 0:j.length)||((b=i.dimensions)==null?void 0:b.length))&&r.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[i.grain&&r.jsx(Q,{label:`grain: ${i.grain}`,t:a}),(g=i.measures)==null?void 0:g.slice(0,2).map(m=>r.jsx(Q,{label:m,t:a},`measure-${m}`)),(v=i.dimensions)==null?void 0:v.slice(0,2).map(m=>r.jsx(Q,{label:m,t:a},`dimension-${m}`))]}),i.candidateJoins&&i.candidateJoins.length>0&&r.jsxs("div",{style:{fontSize:12,color:a.textMuted},children:["Join: ",r.jsx("span",{style:{color:a.textSecondary},children:Rt(i.candidateJoins[0])})]}),d&&r.jsxs("div",{style:{fontSize:12,color:a.textMuted},children:["Next: ",r.jsx("span",{style:{color:a.textSecondary},children:d})]})]})]})}function zt({text:e,t,compact:n=!1,summaryOnly:o=!1}){const i=o?Bt(e):e,s=gr(i,t,n);return r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:n?7:8,color:t.textPrimary,fontFamily:t.font,overflowWrap:"anywhere"},children:s})}function gr(e,t,n){var c;const o=br(e).split(`
|
|
29
|
+
`),i=[];let s=0,l=0;for(;s<o.length;){const d=o[s].trim();if(!d){s+=1;continue}if(d.startsWith("```")){const p=d.replace(/^```/,"").trim(),y=[];for(s+=1;s<o.length&&!o[s].trim().startsWith("```");)y.push(o[s]),s+=1;s<o.length&&(s+=1),i.push(r.jsx("pre",{style:Tr(t,n),"aria-label":p?`${p} code`:"code",children:y.join(`
|
|
30
30
|
`)},`code-${l++}`));continue}const u=d.match(/^(#{1,4})\s+(.+)$/);if(u){const p=u[1].length;i.push(r.jsx("div",{style:Mr(t,n,p),children:K(u[2],t)},`heading-${l++}`)),s+=1;continue}if(/^[-*_]{3,}$/.test(d)){i.push(r.jsx("hr",{style:{width:"100%",border:0,borderTop:`1px solid ${t.cellBorder}`,margin:n?"2px 0":"4px 0"}},`hr-${l++}`)),s+=1;continue}if(vr(o,s)){const p=[];for(;s<o.length&&fe(o[s].trim());)p.push(o[s].trim()),s+=1;i.push(r.jsx(Sr,{lines:p,t,compact:n},`table-${l++}`));continue}if(d.startsWith(">")){const p=[];for(;s<o.length&&o[s].trim().startsWith(">");)p.push(o[s].trim().replace(/^>\s?/,"")),s+=1;i.push(r.jsx("div",{style:ct(t,n),children:K(p.join(" "),t)},`quote-${l++}`));continue}if(/^[-*+]\s+/.test(d)){const p=[];for(;s<o.length&&/^[-*+]\s+/.test(o[s].trim());)p.push(o[s].trim().replace(/^[-*+]\s+/,"")),s+=1;i.push(r.jsx("ul",{style:dt(t,n),children:p.map((y,j)=>r.jsx("li",{style:ut(t,n),children:K(y,t)},`${y}-${j}`))},`ul-${l++}`));continue}if(/^\d+\.\s+/.test(d)){const p=[];for(;s<o.length&&/^\d+\.\s+/.test(o[s].trim());)p.push(o[s].trim().replace(/^\d+\.\s+/,"")),s+=1;i.push(r.jsx("ol",{style:dt(t,n),children:p.map((y,j)=>r.jsx("li",{style:ut(t,n),children:K(y,t)},`${y}-${j}`))},`ol-${l++}`));continue}const f=[];for(;s<o.length;){const p=o[s].trim();if(!p||at(p)&&f.length>0||(f.push(p),s+=1,at(((c=o[s])==null?void 0:c.trim())??"")))break}const h=f.join(" ");i.push(r.jsx("div",{style:i.length===0&&wr(h)?ct(t,n):$r(t,n),children:K(h,t)},`p-${l++}`))}return i}function br(e){return e.replace(/\r\n/g,`
|
|
31
31
|
`).replace(/\|\s+\|(?=[^\n]*\|)/g,`|
|
|
32
|
-
|`)}function at(e){return!!(e.startsWith("```")||/^(#{1,4})\s+/.test(e)||/^[-*_]{3,}$/.test(e)||fe(e)||e.startsWith(">")||/^[-*+]\s+/.test(e)||/^\d+\.\s+/.test(e))}function vr(e,t){var i,s;const n=((i=e[t])==null?void 0:i.trim())??"",o=((s=e[t+1])==null?void 0:s.trim())??"";return fe(n)&&jr(o)}function fe(e){return e.startsWith("|")&&e.endsWith("|")&&re(e).length>=2}function jr(e){if(!fe(e))return!1;const t=re(e);return t.length>=2&&t.every(n=>/^:?-{3,}:?$/.test(n.replace(/\s+/g,"")))}function re(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function Sr({lines:e,t,compact:n}){const o=re(e[0]??""),i=re(e[1]??""),s=e.slice(2).map(re).filter(d=>d.length>0),l=Math.max(o.length,...s.map(d=>d.length),0);if(l===0)return null;const c=Array.from({length:l},(d,u)=>{var h;const f=((h=i[u])==null?void 0:h.replace(/\s+/g,""))??"";return f.startsWith(":")&&f.endsWith(":")?"center":f.endsWith(":")?"right":"left"}),a=Array.from({length:l},(d,u)=>o[u]??"");return r.jsx("div",{style:kr(t),children:r.jsxs("table",{style:Ar(t,n),children:[r.jsx("thead",{children:r.jsx("tr",{children:a.map((d,u)=>r.jsx("th",{style:xt(t,n,!0,c[u]),children:K(d,t)},`h-${u}`))})}),r.jsx("tbody",{children:s.map((d,u)=>r.jsx("tr",{children:Array.from({length:l},(f,h)=>r.jsx("td",{style:xt(t,n,!1,c[h]),children:K(d[h]??"",t)},`c-${u}-${h}`))},`r-${u}`))})]})})}function wr(e){return/\b(certified|uncertified|review[- ]required|draft|trusted|trust)\b/i.test(e)}function K(e,t){const n=[];let o=e,i=0;for(;o.length>0;){const s=o.match(/\*{3}(.+?)\*{3}/),l=o.match(/\*{2}(.+?)\*{2}/),c=o.match(/`([^`]+?)`/),a=o.match(/\[([^\]]+?)\]\((https?:\/\/[^)\s]+|\/[^)\s]+|#[^)\s]+)\)/),d=o.match(/\*([^\s*](?:.*?[^\s*])?)\*/),u=[s?{match:s,type:"boldItalic"}:null,l?{match:l,type:"bold"}:null,c?{match:c,type:"code"}:null,a?{match:a,type:"link"}:null,d?{match:d,type:"italic"}:null].filter(Boolean);if(u.length===0){n.push(r.jsx(te.Fragment,{children:o},`plain-${i++}`));break}const f=u.reduce((p,y)=>(p.match.index??0)<=(y.match.index??0)?p:y),h=f.match.index??0;h>0&&n.push(r.jsx(te.Fragment,{children:o.slice(0,h)},`plain-${i++}`)),f.type==="boldItalic"?n.push(r.jsx("strong",{style:{fontStyle:"italic",color:t.textPrimary},children:f.match[1]},`bi-${i++}`)):f.type==="bold"?n.push(r.jsx("strong",{style:{color:t.textPrimary},children:f.match[1]},`b-${i++}`)):f.type==="italic"?n.push(r.jsx("em",{children:f.match[1]},`i-${i++}`)):f.type==="code"?n.push(r.jsx("code",{style:Br(t),children:f.match[1]},`code-${i++}`)):f.type==="link"&&n.push(r.jsx("a",{href:f.match[2],target:"_blank",rel:"noopener noreferrer",style:{color:t.accent,textDecoration:"underline"},children:f.match[1]},`link-${i++}`)),o=o.slice(h+f.match[0].length)}return r.jsx(r.Fragment,{children:n})}function $r(e,t){return{color:e.textPrimary,fontSize:13,lineHeight:t?1.55:1.6}}function Mr(e,t,n){return{color:e.textPrimary,fontSize:t?13:Math.max(13,15-n),fontWeight:800,lineHeight:1.35,marginTop:n<=2?2:0}}function ct(e,t){return{color:e.textPrimary,fontSize:12.5,lineHeight:1.5,padding:t?"8px 9px":"9px 10px",border:`1px solid ${e.cellBorder}`,borderLeft:`3px solid ${e.accent}`,borderRadius:6,background:`${e.tableHeaderBg}55`}}function dt(e,t){return{margin:0,paddingLeft:t?18:20,color:e.textPrimary,display:"grid",gap:t?4:5}}function ut(e,t){return{color:e.textPrimary,fontSize:13,lineHeight:1.5,paddingLeft:2}}function kr(e){return{width:"100%",maxWidth:"100%",overflowX:"auto",border:`1px solid ${e.cellBorder}`,borderRadius:8,background:e.editorBg}}function Ar(e,t){return{width:"100%",minWidth:t?360:420,borderCollapse:"collapse",color:e.textPrimary,fontSize:t?12:12.5,lineHeight:1.45}}function xt(e,t,n,o){return{padding:t?"6px 8px":"7px 9px",borderBottom:`1px solid ${e.cellBorder}`,color:n?e.textMuted:e.textPrimary,background:n?`${e.tableHeaderBg}75`:void 0,fontFamily:n?e.fontMono:e.font,fontSize:n?t?10.5:11:void 0,fontWeight:n?800:500,textAlign:o,whiteSpace:"nowrap",verticalAlign:"top"}}function Br(e){return{background:e.editorBg,border:`1px solid ${e.cellBorder}`,borderRadius:4,color:e.accent,fontFamily:e.fontMono,fontSize:"0.92em",padding:"1px 4px"}}function zr(e,t){return{margin:0,padding:t?9:10,overflow:"auto",maxHeight:t?220:280,borderRadius:6,background:e.editorBg,color:e.textPrimary,border:`1px solid ${e.cellBorder}`,fontSize:t?11.5:12,fontFamily:e.fontMono,lineHeight:1.5,whiteSpace:"pre"}}function Tr({result:e,t,compact:n}){const o=(e.columns.length>0?e.columns:Object.keys(e.rows[0]??{})).slice(0,n?3:4),i=e.rows.slice(0,n?4:5);return o.length===0||i.length===0?null:r.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:8,overflow:"hidden",background:t.editorBg},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,padding:"7px 9px",borderBottom:`1px solid ${t.cellBorder}`,color:t.textMuted,fontSize:11,fontFamily:t.fontMono,textTransform:"uppercase",letterSpacing:"0.06em"},children:[r.jsx("span",{children:"Preview"}),r.jsxs("span",{children:[i.length," of ",(e.rowCount??e.rows.length).toLocaleString()," rows"]})]}),r.jsx("div",{style:{overflowX:"auto"},children:r.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",tableLayout:"fixed"},children:[r.jsx("thead",{children:r.jsx("tr",{children:o.map(s=>r.jsx("th",{style:{textAlign:"left",padding:"7px 9px",color:t.textMuted,fontSize:11,fontFamily:t.fontMono,borderBottom:`1px solid ${t.cellBorder}`,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:U(s)},s))})}),r.jsx("tbody",{children:i.map((s,l)=>r.jsx("tr",{children:o.map(c=>r.jsx("td",{style:{padding:"7px 9px",color:t.textPrimary,fontSize:n?12:12.5,borderBottom:l<i.length-1?`1px solid ${t.cellBorder}`:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Nr(c,s[c],i.map(a=>a[c]))},`${l}-${c}`))},l))})]})})]})}function _r({evidence:e,t}){const n=(e==null?void 0:e.lineage)??[];return n.length===0?r.jsx(Lt,{t,children:"No lineage evidence was returned for this answer."}):r.jsx("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:10},children:n.map((o,i)=>r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 1fr",gap:8},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center"},children:[r.jsx("div",{style:{width:8,height:8,borderRadius:8,marginTop:5,background:o.role==="question"?t.accent:t.textMuted}}),i<n.length-1&&r.jsx("div",{style:{width:1,flex:1,minHeight:18,background:t.cellBorder}})]}),r.jsxs("div",{style:{minWidth:0},children:[r.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary},children:o.name??o.nodeId}),o.role&&r.jsx(Q,{label:U(o.role),t}),o.kind&&r.jsx(Q,{label:U(o.kind),t})]}),o.description&&r.jsx("div",{style:{fontSize:12,color:t.textSecondary,marginTop:3},children:o.description}),(o.sourcePath||o.provenance)&&r.jsxs("div",{style:{fontSize:11,color:t.textMuted,fontFamily:t.fontMono,marginTop:3,overflow:"hidden",textOverflow:"ellipsis"},children:[o.provenance??o.sourcePath,o.sourcePath&&o.provenance?` - ${o.sourcePath}`:""]})]})]},`${o.nodeId??o.name}-${i}`))})}function Lr({evidence:e,t}){var i;const n=(e==null?void 0:e.businessContext)??[],o=e==null?void 0:e.outcome;return!o&&n.length===0?r.jsx(Lt,{t,children:"No business context was returned for this answer."}):r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:12},children:[o&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Outcome"}),o.name&&r.jsx(E,{label:"Outcome",value:o.name,t}),o.owner&&r.jsx(E,{label:"Owner",value:o.owner,t}),o.decisionUse&&r.jsx(E,{label:"Decision Use",value:o.decisionUse,t}),o.reviewCadence&&r.jsx(E,{label:"Review Cadence",value:o.reviewCadence,t}),(i=o.caveats)==null?void 0:i.map((s,l)=>r.jsx(E,{label:"Caveat",value:s,t},`caveat-${l}`))]}),n.length>0&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Context"}),n.map((s,l)=>r.jsx(E,{label:s.label??"Context",value:s.value??"",source:s.source,t},`${s.label}-${l}`))]}),(e==null?void 0:e.semanticObjects)&&e.semanticObjects.length>0&&r.jsx(pt,{title:"Semantic Objects",assets:e.semanticObjects,t}),(e==null?void 0:e.sourceTables)&&e.sourceTables.length>0&&r.jsx(pt,{title:"Source Tables",assets:e.sourceTables,t})]})}function Rr({answer:e,t}){var s,l;const n=e.evidence,o=e.analysisPlan??(n==null?void 0:n.analysisPlan),i=(n==null?void 0:n.citations)??e.citations??[];return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:12},children:[r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(E,{label:"Certification",value:U(e.certification??e.kind),t}),C(e.cascade)&&r.jsx(E,{label:"Cascade",value:C(e.cascade)??"",t}),e.reviewStatus&&r.jsx(E,{label:"Review Status",value:U(e.reviewStatus),t}),typeof e.confidence=="number"&&r.jsx(E,{label:"Confidence",value:`${Math.round(e.confidence*100)}%`,t}),((s=n==null?void 0:n.validation)==null?void 0:s.message)&&r.jsx(E,{label:`Validation ${n.validation.status??""}`.trim(),value:n.validation.message,t}),((l=n==null?void 0:n.execution)==null?void 0:l.message)&&r.jsx(E,{label:`Execution ${n.execution.status??""}`.trim(),value:n.execution.message,t}),e.executionError&&r.jsx(E,{label:"Execution Error",value:e.executionError,t}),e.kind!=="certified"&&r.jsx(E,{label:"Promotion Path",value:"Create draft block, edit SQL, attach tests, then certify after analyst approval.",t})]}),o&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Analysis Plan"}),o.question&&r.jsx(E,{label:"Question",value:o.question,t}),o.intent&&r.jsx(E,{label:"Intent",value:U(o.intent),t}),o.grain&&r.jsx(E,{label:"Grain",value:o.grain,t}),o.candidateTables&&o.candidateTables.length>0&&r.jsx(E,{label:"Tables",value:o.candidateTables.slice(0,5).map(c=>c.relation).filter(Boolean).join(", "),t}),o.candidateJoins&&o.candidateJoins.length>0&&r.jsx(E,{label:"Join Paths",value:o.candidateJoins.slice(0,3).map(Rt).join("; "),t}),o.assumptions&&o.assumptions.length>0&&r.jsx(E,{label:"Assumptions",value:o.assumptions.join(" "),t}),typeof o.repairAttempts=="number"&&o.repairAttempts>0&&r.jsx(E,{label:"SQL Repair",value:`${o.repairAttempts} retry`,t})]}),i.length>0&&r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[r.jsx(se,{t,children:"Citations"}),i.slice(0,8).map((c,a)=>r.jsxs("div",{style:{fontSize:12,color:t.textSecondary,fontFamily:t.fontMono},children:[c.kind??"source",": ",c.name??"unknown",c.provenance&&r.jsxs("span",{style:{color:t.textMuted},children:[" (",c.provenance,")"]})]},`${c.kind}-${c.name}-${a}`))]})]})}function pt({title:e,assets:t,t:n}){return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[r.jsx(se,{t:n,children:e}),t.map((o,i)=>r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,paddingBottom:4},children:[r.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:o.name??o.nodeId}),o.kind&&r.jsx(Q,{label:U(o.kind),t:n}),o.certification&&r.jsx(Q,{label:U(o.certification),t:n})]}),o.description&&r.jsx("div",{style:{fontSize:12,color:n.textSecondary},children:o.description}),(o.sourcePath||o.owner||o.domain)&&r.jsx("div",{style:{fontSize:11,color:n.textMuted,fontFamily:n.fontMono},children:[o.domain,o.owner,o.sourcePath].filter(Boolean).join(" - ")})]},`${o.nodeId??o.name}-${i}`))]})}function Ir({artifact:e,t}){const n=[e.kind?{label:"Kind",value:U(e.kind)}:null,e.name?{label:"Name",value:e.name}:null,e.sourcePath?{label:"Source Path",value:e.sourcePath}:null,e.metrics.length>0?{label:"Metrics",value:e.metrics.join(", ")}:null,e.dimensions.length>0?{label:"Dimensions",value:e.dimensions.join(", ")}:null,e.timeDimension?{label:"Time",value:e.timeDimension}:null,e.filters.length>0?{label:"Filters",value:e.filters.join("; ")}:null].filter(o=>!!o);return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:10},children:[n.length>0&&r.jsx("div",{style:{display:"grid",gap:6},children:n.map(o=>r.jsx(E,{label:o.label,value:o.value,t},o.label))}),r.jsx("pre",{style:_t(t,340),children:e.source})]})}function Wr({sql:e,blockPath:t,executionError:n,t:o}){return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:8},children:[t&&r.jsxs("div",{style:{fontSize:12,color:o.textSecondary},children:["Source block: ",r.jsx("span",{style:{fontFamily:o.fontMono,color:o.textPrimary},children:t})]}),n&&r.jsx("div",{style:{padding:10,border:"1px solid rgba(248, 81, 73, 0.35)",borderRadius:6,background:"rgba(248, 81, 73, 0.10)",color:"#ff7b72",fontSize:12,lineHeight:1.45,whiteSpace:"pre-wrap"},children:n}),e?r.jsx("pre",{style:_t(o,260),children:e}):r.jsx("div",{style:{fontSize:12,color:o.textMuted},children:"No SQL text was returned for this answer."})]})}function _t(e,t){return{margin:0,padding:10,overflow:"auto",maxHeight:t,borderRadius:4,background:e.editorBg,color:e.textPrimary,border:`1px solid ${e.cellBorder}`,fontSize:12,fontFamily:e.fontMono,whiteSpace:"pre"}}function E({label:e,value:t,source:n,t:o}){return t?r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"130px 1fr",gap:10,fontSize:12,alignItems:"baseline"},children:[r.jsx("span",{style:{color:o.textMuted},children:e}),r.jsxs("span",{style:{color:o.textSecondary},children:[t,n&&r.jsxs("span",{style:{color:o.textMuted},children:[" (",n,")"]})]})]}):null}function se({children:e,t}){return r.jsx("div",{style:{fontSize:11,fontWeight:700,fontFamily:t.fontMono,color:t.textMuted,textTransform:"uppercase",letterSpacing:"0.08em"},children:e})}function Lt({children:e,t}){return r.jsx("div",{style:{padding:12,fontSize:12,color:t.textMuted},children:e})}function Q({label:e,t}){return r.jsx("span",{style:{fontSize:11,fontFamily:t.fontMono,color:t.textSecondary,padding:"2px 6px",borderRadius:4,background:t.editorBg,border:`1px solid ${t.cellBorder}`},children:e})}function Dr({items:e,t,accent:n}){return e.length===0?null:r.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 16px",alignItems:"center",padding:"7px 10px",borderTop:`1px solid ${t.cellBorder}`,boxShadow:`inset 0 2px 0 ${n}`,background:t.editorBg,color:t.textMuted,fontFamily:t.fontMono,fontSize:10.5},children:e.map(o=>r.jsxs("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[r.jsx("span",{style:{color:t.textMuted},children:o.label})," ",r.jsx("strong",{style:{color:t.textSecondary,fontWeight:600},children:o.value})]},`${o.label}-${o.value}`))})}function ft({active:e,label:t,onClick:n,t:o}){return r.jsx("button",{onClick:n,style:{padding:"4px 2px",fontSize:11.5,border:0,borderBottom:`2px solid ${e?o.accent:"transparent"}`,borderRadius:0,background:"transparent",color:e?o.accent:o.textSecondary,fontWeight:e?700:500,cursor:"pointer"},children:t})}function Fr({result:e,chartConfig:t,t:n,onChange:o}){const i=e.columns;if(i.length===0)return null;const s=Me.filter(d=>d.value!=="table"),l=t!=null&&t.x&&i.includes(t.x)?t.x:i[0]??"",c=t!=null&&t.y&&i.includes(t.y)?t.y:i.find(d=>d!==l)??i[0]??"",a=t!=null&&t.color&&i.includes(t.color)?t.color:"";return r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(130px, 1fr))",gap:8,alignItems:"end",border:`1px solid ${n.cellBorder}`,borderRadius:7,background:`${n.tableHeaderBg}55`,padding:10},children:[r.jsx(de,{label:"Chart type",t:n,children:r.jsx("select",{value:(t==null?void 0:t.chart)??"bar",onChange:d=>o({chart:d.target.value}),style:ue(n),children:s.map(d=>r.jsx("option",{value:d.value,children:d.label},d.value))})}),r.jsx(de,{label:"X axis",t:n,children:r.jsx("select",{value:l,onChange:d=>o({x:d.target.value}),style:ue(n),children:i.map(d=>r.jsx("option",{value:d,children:d},d))})}),r.jsx(de,{label:"Y axis",t:n,children:r.jsx("select",{value:c,onChange:d=>o({y:d.target.value}),style:ue(n),children:i.map(d=>r.jsx("option",{value:d,children:d},d))})}),r.jsx(de,{label:"Color",t:n,children:r.jsxs("select",{value:a,onChange:d=>o({color:d.target.value||void 0}),style:ue(n),children:[r.jsx("option",{value:"",children:"None"}),i.map(d=>r.jsx("option",{value:d,children:d},d))]})})]})}function de({label:e,t,children:n}){return r.jsxs("label",{style:{display:"grid",gap:4,minWidth:0},children:[r.jsx("span",{style:{fontSize:10.5,color:t.textMuted,fontWeight:800,textTransform:"uppercase",letterSpacing:0},children:e}),n]})}function ue(e){return{width:"100%",minWidth:0,height:30,border:`1px solid ${e.inputBorder}`,borderRadius:6,background:e.editorBg,color:e.textPrimary,fontFamily:e.font,fontSize:12,padding:"0 8px"}}function U(e){return e.replace(/_/g," ")}function Rt(e){const t=[e.leftRelation,e.leftColumn].filter(Boolean).join("."),n=[e.rightRelation,e.rightColumn].filter(Boolean).join("."),o=[t,n].filter(Boolean).join(" to ");return e.reason?`${o} (${e.reason})`:o}function Nr(e,t,n){return t==null?"-":pe(e,t,n)}function Pr(e){const t=e.toLowerCase();return t.includes("certified")?"trusted business context":t.includes("ai")||t.includes("generated")?"AI draft":t.includes("no_answer")?"needs more context":U(e)}function It(e){var t;switch((t=e.trustLabelInfo)==null?void 0:t.id){case"certified":return"certified";case"reviewed":return"review";case"ai_generated":return"ai_generated";case"conflict":return"review";case"insufficient_context":return e.kind==="no_answer"?"no_answer":"uncertified"}return e.kind==="no_answer"?"no_answer":e.certification==="certified"||e.reviewStatus==="certified"?"certified":e.reviewStatus==="draft_ready"||e.reviewStatus==="analyst_review_required"?"review":e.certification==="ai_generated"?"ai_generated":e.certification==="analyst_review_required"||e.certification==="uncertified"?"uncertified":e.kind==="certified"?"certified":"draft"}function Er(e,t){return e==="certified"?t.success:e==="no_answer"?t.error:e==="deprecated"?t.textMuted:t.warning}function Hr(e,t,n,o){var a,d,u,f,h,p,y,j;const i=[],s=((d=(a=e.evidence)==null?void 0:a.selectedAssets)==null?void 0:d[0])??((f=(u=e.evidence)==null?void 0:u.lineage)==null?void 0:f.find(b=>b.owner||b.domain||b.sourcePath)),l=n??(s==null?void 0:s.name),c=o??(s==null?void 0:s.sourcePath)??(s==null?void 0:s.provenance);if(l&&i.push({label:e.kind==="certified"?"source":"draft source",value:l}),((s==null?void 0:s.owner)??((p=(h=e.evidence)==null?void 0:h.outcome)==null?void 0:p.owner))&&i.push({label:"owner",value:(s==null?void 0:s.owner)??((j=(y=e.evidence)==null?void 0:y.outcome)==null?void 0:j.owner)??""}),c&&i.push({label:"path",value:c}),e.sourceTier&&i.push({label:"tier",value:U(e.sourceTier)}),C(e.cascade)&&i.push({label:"cascade",value:C(e.cascade)??""}),t){const b=t.rowCount??t.rows.length,g=t.executionTime!==void 0?` - ${Math.round(t.executionTime)}ms`:"";i.push({label:"run",value:`${b.toLocaleString()} rows${g}`})}return e.reviewStatus&&e.reviewStatus!=="certified"&&i.push({label:"next",value:U(e.reviewStatus)}),Vr(i).slice(0,5)}function C(e){if(!(e!=null&&e.terminalLane)&&!(e!=null&&e.routeTier))return;const t=Or(e.terminalLane),n=qr(e.routeTier);return[t,n].filter(Boolean).join(" · ")||void 0}function Or(e){switch(e){case"certified":return"Lane 1 certified";case"semantic":return"Lane 2 semantic";case"generated":return"Lane 3 generated";case"refusal":return"Lane 4 refusal";default:return e?U(e):void 0}}function qr(e){switch(e){case"certified_block":return"Certified block";case"semantic_metric":return"Semantic metric";case"generated_sql":return"Generated SQL";case"business_context":return"Business context";case"no_answer":return"No answer";default:return e?U(e):void 0}}function Ur(e,t){var n,o,i,s;return ne(e.sourceCertifiedBlock)??Se((n=e.evidence)==null?void 0:n.selectedAssets)??Se((o=e.evidence)==null?void 0:o.lineage)??Se(e.citations)??ne((i=e.block)==null?void 0:i.name)??ne((s=e.result)==null?void 0:s.blockName)??ne(t)}function Se(e){return e==null?void 0:e.map(t=>t.kind==="block"?ne(t.name):void 0).find(t=>!!t)}function ne(e){return typeof e!="string"?void 0:e.replace(/\s+/g," ").trim()||void 0}function Vr(e){const t=new Set;return e.filter(n=>{const o=n.value.trim();if(!o)return!1;const i=`${n.label}:${o}`;return t.has(i)?!1:(t.add(i),!0)})}const xo=Object.freeze(Object.defineProperty({__proto__:null,AgentAnswerCard:xr,StructuredAnswerText:Tt,extractGovernedAnswer:lr,formatCascadeOutcome:C,resolveAgentOutcome:zt,resolveAnswerTrustState:It,resolveDqlArtifactMeta:At},Symbol.toStringTag,{value:"Module"}));function po(e){return new Set(e.tiles.filter(t=>!t.error&&t.selectedByDefault).map(t=>t.id))}function Qr(e,t){const n=e.intent.target==="personal",o=[];for(const i of e.tiles)i.source!=="ai_generated"||i.error||!t.has(i.id)||(i.sql?n||o.push({id:i.id,title:i.title,reason:"Exploratory AI SQL can only be accepted into a Personal Draft. Switch this build to Personal Draft to keep it."}):o.push({id:i.id,title:i.title,reason:"No query was generated for it, so it has nothing to show. It stays in the review appendix as an open question."}));return o}function fo({proposal:e,t,selected:n,onToggle:o,onCreate:i,busy:s,error:l,compact:c,nameLabel:a="App name",defaultName:d}){const[u,f]=R.useState(d??""),[h,p]=R.useState({}),y=(x,M)=>{p(S=>({...S,[x]:{...S[x],...M}}))},j=e.tiles.filter(x=>!x.error),b=e.tiles.filter(x=>x.error),g=j.filter(x=>n.has(x.id)).length,v=Qr(e,n),m=j.filter(x=>n.has(x.id)&&x.certification==="ai_generated").length,A=j.filter(x=>n.has(x.id)&&x.certification==="reviewed_semantic").length,_=j.filter(x=>n.has(x.id)&&x.certification==="certified").length+A>0||e.intent.target==="personal"&&m>0;return r.jsxs("div",{style:{display:"grid",gap:10},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12.5,fontWeight:800,color:t.textPrimary},children:"Build Brief"}),r.jsxs("span",{style:{fontSize:11,color:t.textMuted},children:[e.coverage.certifiedTiles," certified",e.coverage.semanticTiles>0?` · ${e.coverage.semanticTiles} governed semantic`:"",e.coverage.generatedTiles>0?` · ${e.coverage.generatedTiles} exploratory`:"",e.coverage.gaps>0?` · ${e.coverage.gaps} uncovered`:""]}),r.jsxs("span",{style:{fontSize:10.5,color:t.textMuted},children:[e.intent.target==="personal"?"Personal Draft":"Shared Project target"," · starts private"]})]}),r.jsxs("label",{style:{display:"grid",gap:3},children:[r.jsx("span",{style:{fontSize:10.5,color:t.textMuted,fontWeight:700},children:a}),r.jsx("input",{value:u,onChange:x=>f(x.target.value),placeholder:d,maxLength:120,style:Jr(t)})]}),r.jsxs("div",{style:{display:"grid",gap:6},children:[j.map(x=>r.jsx(Yr,{tile:x,t,checked:n.has(x.id),onToggle:()=>o(x.id),compact:c,edit:h[x.id],onEdit:M=>y(x.id,M)},x.id)),b.map(x=>r.jsxs("div",{style:{...Wt(t),opacity:.75},children:[r.jsx(Ze,{size:13,color:t.warning,style:{flexShrink:0,marginTop:2}}),r.jsxs("div",{style:{minWidth:0,flex:1},children:[r.jsx("div",{style:{fontSize:12,fontWeight:700,color:t.textSecondary},children:x.title}),r.jsx("div",{style:{fontSize:11,color:t.textMuted,marginTop:1},children:x.error})]})]},x.id))]}),e.gaps.length>0?r.jsxs("div",{style:{display:"grid",gap:4},children:[r.jsx("div",{style:{fontSize:11,fontWeight:800,color:t.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Not covered yet"}),e.gaps.map(x=>r.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:t.textMuted},children:[r.jsx(sn,{size:12,style:{flexShrink:0,marginTop:2}}),r.jsx("span",{style:{lineHeight:1.4},children:x.question})]},x.id))]}):null,v.length>0?r.jsxs("div",{role:"status",style:{display:"grid",gap:5,padding:"9px 11px",borderRadius:9,border:`1px solid ${t.headerBorder}`,background:"var(--status-warning-bg, rgba(180,120,0,0.08))"},children:[r.jsx("div",{style:{fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.04em"},children:v.length===1?"1 selected tile will not be built":`${v.length} selected tiles will not be built`}),v.map(x=>r.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:t.textSecondary},children:[r.jsx(Ze,{size:12,style:{flexShrink:0,marginTop:2}}),r.jsxs("span",{style:{lineHeight:1.45},children:[r.jsx("b",{children:x.title})," — ",x.reason]})]},x.id))]}):null,l?r.jsx("div",{style:{fontSize:12,color:t.error},children:l}):null,r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[r.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i({...u.trim()?{appName:u.trim(),pageTitle:u.trim()}:{},tileOverrides:h}),disabled:s||!_,style:Kr(t,_&&!s),children:[s?r.jsx(qt,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):r.jsx(Ut,{size:13}),r.jsx("span",{children:s?"Building draft…":`Build draft (${g} tile${g===1?"":"s"})`})]}),r.jsx("span",{style:{fontSize:11,color:t.textMuted},children:_?A>0?`${A} semantic tile${A===1?"":"s"} will compile against the governed semantic layer and still require result review.`:m>0?`${m} AI-generated tile${m===1?"":"s"} will stay review-required until certified.`:"No App files are written until you confirm this brief.":e.intent.target==="personal"?"Select a certified, semantic, or explicitly accepted exploratory tile.":"Select at least one certified block or governed semantic tile."})]})]})}function Yr({tile:e,t,checked:n,onToggle:o,compact:i,edit:s,onEdit:l}){var h,p;const[c,a]=R.useState(!1),d=e.certification==="certified",u=e.certification==="reviewed_semantic",f=!!(e.sql||e.answer||e.preview&&e.preview.rows.length>0);return r.jsxs("div",{style:Wt(t),children:[r.jsx("input",{type:"checkbox",checked:n,onChange:o,"aria-label":`Include ${e.title}`,style:{marginTop:2,accentColor:t.accent,cursor:"pointer",flexShrink:0}}),r.jsxs("div",{style:{minWidth:0,flex:1},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[r.jsx("input",{value:(s==null?void 0:s.title)??e.title,onChange:y=>l({title:y.target.value}),"aria-label":`Title for ${e.title}`,maxLength:120,style:Cr(t)}),d?r.jsxs("span",{style:we(t.success),children:[r.jsx(Vt,{size:10})," certified"]}):u?r.jsxs("span",{style:we(t.accent),children:[r.jsx(Ge,{size:10})," governed semantic · review required"]}):r.jsxs("span",{style:we(t.warning),children:[((h=e.repair)==null?void 0:h.status)==="repaired"?r.jsx(Kt,{size:10}):r.jsx(Ge,{size:10}),((p=e.repair)==null?void 0:p.status)==="repaired"?"auto-repaired · needs review":"AI-generated · needs review"]}),r.jsx("select",{value:(s==null?void 0:s.viz)??e.viz,onChange:y=>l({viz:y.target.value}),"aria-label":`Visualization for ${e.title}`,style:eo(t),children:[...new Set([...e.allowedVisualizations??[],e.viz,"table"])].map(y=>r.jsx("option",{value:y,children:y.replace(/_/g," ")},y))})]}),e.description&&!i?r.jsx("div",{style:{fontSize:11.5,color:t.textSecondary,marginTop:2,lineHeight:1.4},children:e.description}):null,e.question&&e.question!==e.title?r.jsxs("div",{style:{fontSize:11,color:t.textMuted,marginTop:2},children:["Answers: ",e.question]}):null,i?null:r.jsxs("div",{style:{fontSize:10.5,color:e.preflight.status==="passed"?t.success:e.preflight.status==="blocked"?t.error:t.textMuted,marginTop:2},children:["Preflight: ",e.preflight.status.replace("_"," ")," · ",e.preflight.message]}),e.repair?r.jsxs("div",{style:{fontSize:10.5,color:e.repair.status==="repaired"?t.warning:t.error,marginTop:3,lineHeight:1.4},children:["Repair evidence: ",e.repair.message]}):null,f?r.jsxs("button",{type:"button",onClick:()=>a(y=>!y),style:{border:"none",background:"transparent",color:t.accent,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:700,padding:0,marginTop:4,fontFamily:t.font},children:[c?r.jsx(Qt,{size:11}):r.jsx(Yt,{size:11}),r.jsx(nn,{size:11})," ",c?"Hide details":"Show SQL & preview"]}):null,c&&e.answer?r.jsx("div",{style:{fontSize:11.5,color:t.textSecondary,marginTop:5,lineHeight:1.4},children:e.answer}):null,c&&e.sql?r.jsx("pre",{style:Xr(t),children:e.sql}):null,c&&e.preview&&e.preview.rows.length>0?r.jsx(Zr,{preview:e.preview,t}):null]})]})}function Zr({preview:e,t}){const n=e.columns.slice(0,5),o=e.rows.slice(0,5);return r.jsxs("div",{style:{marginTop:5,overflow:"auto",border:`1px solid ${t.headerBorder}`,borderRadius:6},children:[r.jsxs("table",{style:{borderCollapse:"collapse",fontSize:10.5,fontFamily:t.fontMono,width:"100%"},children:[r.jsx("thead",{children:r.jsx("tr",{children:n.map(i=>r.jsx("th",{style:{textAlign:"left",padding:"3px 8px",color:t.textMuted,borderBottom:`1px solid ${t.headerBorder}`,fontWeight:700,whiteSpace:"nowrap"},children:i},i))})}),r.jsx("tbody",{children:o.map((i,s)=>r.jsx("tr",{children:n.map(l=>r.jsx("td",{style:{padding:"3px 8px",color:t.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:160},children:Gr(i[l])},l))},s))})]}),typeof e.rowCount=="number"&&e.rowCount>o.length?r.jsxs("div",{style:{fontSize:10,color:t.textMuted,padding:"3px 8px"},children:[e.rowCount," rows total"]}):null]})}function Gr(e){return e==null?"":typeof e=="number"?Number.isInteger(e)?String(e):e.toFixed(2):String(e)}function Wt(e){return{display:"flex",gap:9,alignItems:"flex-start",border:`1px solid ${e.cellBorder}`,background:e.cellBg,borderRadius:8,padding:"9px 11px"}}function we(e){return{display:"inline-flex",alignItems:"center",gap:3,border:`1px solid ${e}55`,color:e,background:`${e}12`,borderRadius:999,padding:"1px 7px",fontSize:9.5,fontWeight:800}}function Xr(e){return{margin:"5px 0 0",maxHeight:140,overflow:"auto",border:`1px solid ${e.headerBorder}`,background:e.editorBg,borderRadius:6,padding:8,fontSize:10.5,fontFamily:e.fontMono,color:e.textSecondary,lineHeight:1.45,whiteSpace:"pre-wrap"}}function Kr(e,t){return{display:"inline-flex",alignItems:"center",gap:6,border:"none",borderRadius:8,padding:"8px 14px",fontSize:12.5,fontWeight:800,fontFamily:e.font,cursor:t?"pointer":"default",background:t?e.accent:`${e.accent}55`,color:"#fff"}}function Jr(e){return{border:`1px solid ${e.cellBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:7,padding:"6px 9px",fontSize:12,fontFamily:e.font,outline:"none"}}function Cr(e){return{border:"1px solid transparent",background:"transparent",color:e.textPrimary,borderRadius:5,padding:"1px 4px",fontSize:12.5,fontWeight:750,fontFamily:e.font,minWidth:0,flex:"1 1 180px"}}function eo(e){return{border:`1px solid ${e.cellBorder}`,background:e.cellBg,color:e.textMuted,borderRadius:999,padding:"1px 6px",fontSize:9.5,fontFamily:e.font,cursor:"pointer"}}function ho(e){const t=`dql.agent.threadId.${e}`,[n,o]=R.useState(()=>ht(t));R.useEffect(()=>{o(ht(t))},[t]);const i=R.useCallback(l=>{o(l);try{window.localStorage.setItem(t,l)}catch{}},[t]),s=R.useCallback(()=>{o(void 0);try{window.localStorage.removeItem(t)}catch{}},[t]);return{threadId:n,onThreadIdChange:i,resetThreadId:s}}function ht(e){try{return window.localStorage.getItem(e)??void 0}catch{return}}export{fo as A,Me as C,so as E,sn as F,lo as M,ao as P,uo as R,Tt as S,ie as T,St as a,$t as b,co as c,nn as d,po as e,pe as f,kt as g,xo as h,un as i,Qn as r,ho as u};
|
|
32
|
+
|`)}function at(e){return!!(e.startsWith("```")||/^(#{1,4})\s+/.test(e)||/^[-*_]{3,}$/.test(e)||fe(e)||e.startsWith(">")||/^[-*+]\s+/.test(e)||/^\d+\.\s+/.test(e))}function vr(e,t){var i,s;const n=((i=e[t])==null?void 0:i.trim())??"",o=((s=e[t+1])==null?void 0:s.trim())??"";return fe(n)&&jr(o)}function fe(e){return e.startsWith("|")&&e.endsWith("|")&&re(e).length>=2}function jr(e){if(!fe(e))return!1;const t=re(e);return t.length>=2&&t.every(n=>/^:?-{3,}:?$/.test(n.replace(/\s+/g,"")))}function re(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function Sr({lines:e,t,compact:n}){const o=re(e[0]??""),i=re(e[1]??""),s=e.slice(2).map(re).filter(d=>d.length>0),l=Math.max(o.length,...s.map(d=>d.length),0);if(l===0)return null;const c=Array.from({length:l},(d,u)=>{var h;const f=((h=i[u])==null?void 0:h.replace(/\s+/g,""))??"";return f.startsWith(":")&&f.endsWith(":")?"center":f.endsWith(":")?"right":"left"}),a=Array.from({length:l},(d,u)=>o[u]??"");return r.jsx("div",{style:kr(t),children:r.jsxs("table",{style:Ar(t,n),children:[r.jsx("thead",{children:r.jsx("tr",{children:a.map((d,u)=>r.jsx("th",{style:xt(t,n,!0,c[u]),children:K(d,t)},`h-${u}`))})}),r.jsx("tbody",{children:s.map((d,u)=>r.jsx("tr",{children:Array.from({length:l},(f,h)=>r.jsx("td",{style:xt(t,n,!1,c[h]),children:K(d[h]??"",t)},`c-${u}-${h}`))},`r-${u}`))})]})})}function wr(e){return/\b(certified|uncertified|review[- ]required|draft|trusted|trust)\b/i.test(e)}function K(e,t){const n=[];let o=e,i=0;for(;o.length>0;){const s=o.match(/\*{3}(.+?)\*{3}/),l=o.match(/\*{2}(.+?)\*{2}/),c=o.match(/`([^`]+?)`/),a=o.match(/\[([^\]]+?)\]\((https?:\/\/[^)\s]+|\/[^)\s]+|#[^)\s]+)\)/),d=o.match(/\*([^\s*](?:.*?[^\s*])?)\*/),u=[s?{match:s,type:"boldItalic"}:null,l?{match:l,type:"bold"}:null,c?{match:c,type:"code"}:null,a?{match:a,type:"link"}:null,d?{match:d,type:"italic"}:null].filter(Boolean);if(u.length===0){n.push(r.jsx(te.Fragment,{children:o},`plain-${i++}`));break}const f=u.reduce((p,y)=>(p.match.index??0)<=(y.match.index??0)?p:y),h=f.match.index??0;h>0&&n.push(r.jsx(te.Fragment,{children:o.slice(0,h)},`plain-${i++}`)),f.type==="boldItalic"?n.push(r.jsx("strong",{style:{fontStyle:"italic",color:t.textPrimary},children:f.match[1]},`bi-${i++}`)):f.type==="bold"?n.push(r.jsx("strong",{style:{color:t.textPrimary},children:f.match[1]},`b-${i++}`)):f.type==="italic"?n.push(r.jsx("em",{children:f.match[1]},`i-${i++}`)):f.type==="code"?n.push(r.jsx("code",{style:Br(t),children:f.match[1]},`code-${i++}`)):f.type==="link"&&n.push(r.jsx("a",{href:f.match[2],target:"_blank",rel:"noopener noreferrer",style:{color:t.accent,textDecoration:"underline"},children:f.match[1]},`link-${i++}`)),o=o.slice(h+f.match[0].length)}return r.jsx(r.Fragment,{children:n})}function $r(e,t){return{color:e.textPrimary,fontSize:13,lineHeight:t?1.55:1.6}}function Mr(e,t,n){return{color:e.textPrimary,fontSize:t?13:Math.max(13,15-n),fontWeight:800,lineHeight:1.35,marginTop:n<=2?2:0}}function ct(e,t){return{color:e.textPrimary,fontSize:12.5,lineHeight:1.5,padding:t?"8px 9px":"9px 10px",border:`1px solid ${e.cellBorder}`,borderLeft:`3px solid ${e.accent}`,borderRadius:6,background:`${e.tableHeaderBg}55`}}function dt(e,t){return{margin:0,paddingLeft:t?18:20,color:e.textPrimary,display:"grid",gap:t?4:5}}function ut(e,t){return{color:e.textPrimary,fontSize:13,lineHeight:1.5,paddingLeft:2}}function kr(e){return{width:"100%",maxWidth:"100%",overflowX:"auto",border:`1px solid ${e.cellBorder}`,borderRadius:8,background:e.editorBg}}function Ar(e,t){return{width:"100%",minWidth:t?360:420,borderCollapse:"collapse",color:e.textPrimary,fontSize:t?12:12.5,lineHeight:1.45}}function xt(e,t,n,o){return{padding:t?"6px 8px":"7px 9px",borderBottom:`1px solid ${e.cellBorder}`,color:n?e.textMuted:e.textPrimary,background:n?`${e.tableHeaderBg}75`:void 0,fontFamily:n?e.fontMono:e.font,fontSize:n?t?10.5:11:void 0,fontWeight:n?800:500,textAlign:o,whiteSpace:"nowrap",verticalAlign:"top"}}function Br(e){return{background:e.editorBg,border:`1px solid ${e.cellBorder}`,borderRadius:4,color:e.accent,fontFamily:e.fontMono,fontSize:"0.92em",padding:"1px 4px"}}function Tr(e,t){return{margin:0,padding:t?9:10,overflow:"auto",maxHeight:t?220:280,borderRadius:6,background:e.editorBg,color:e.textPrimary,border:`1px solid ${e.cellBorder}`,fontSize:t?11.5:12,fontFamily:e.fontMono,lineHeight:1.5,whiteSpace:"pre"}}function zr({result:e,t,compact:n}){const o=(e.columns.length>0?e.columns:Object.keys(e.rows[0]??{})).slice(0,n?3:4),i=e.rows.slice(0,n?4:5);return o.length===0||i.length===0?null:r.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:8,overflow:"hidden",background:t.editorBg},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,padding:"7px 9px",borderBottom:`1px solid ${t.cellBorder}`,color:t.textMuted,fontSize:11,fontFamily:t.fontMono,textTransform:"uppercase",letterSpacing:"0.06em"},children:[r.jsx("span",{children:"Preview"}),r.jsxs("span",{children:[i.length," of ",(e.rowCount??e.rows.length).toLocaleString()," rows"]})]}),r.jsx("div",{style:{overflowX:"auto"},children:r.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",tableLayout:"fixed"},children:[r.jsx("thead",{children:r.jsx("tr",{children:o.map(s=>r.jsx("th",{style:{textAlign:"left",padding:"7px 9px",color:t.textMuted,fontSize:11,fontFamily:t.fontMono,borderBottom:`1px solid ${t.cellBorder}`,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:U(s)},s))})}),r.jsx("tbody",{children:i.map((s,l)=>r.jsx("tr",{children:o.map(c=>r.jsx("td",{style:{padding:"7px 9px",color:t.textPrimary,fontSize:n?12:12.5,borderBottom:l<i.length-1?`1px solid ${t.cellBorder}`:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:Nr(c,s[c],i.map(a=>a[c]))},`${l}-${c}`))},l))})]})})]})}function _r({evidence:e,t}){const n=(e==null?void 0:e.lineage)??[];return n.length===0?r.jsx(Lt,{t,children:"No lineage evidence was returned for this answer."}):r.jsx("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:10},children:n.map((o,i)=>r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"20px 1fr",gap:8},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center"},children:[r.jsx("div",{style:{width:8,height:8,borderRadius:8,marginTop:5,background:o.role==="question"?t.accent:t.textMuted}}),i<n.length-1&&r.jsx("div",{style:{width:1,flex:1,minHeight:18,background:t.cellBorder}})]}),r.jsxs("div",{style:{minWidth:0},children:[r.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary},children:o.name??o.nodeId}),o.role&&r.jsx(Q,{label:U(o.role),t}),o.kind&&r.jsx(Q,{label:U(o.kind),t})]}),o.description&&r.jsx("div",{style:{fontSize:12,color:t.textSecondary,marginTop:3},children:o.description}),(o.sourcePath||o.provenance)&&r.jsxs("div",{style:{fontSize:11,color:t.textMuted,fontFamily:t.fontMono,marginTop:3,overflow:"hidden",textOverflow:"ellipsis"},children:[o.provenance??o.sourcePath,o.sourcePath&&o.provenance?` - ${o.sourcePath}`:""]})]})]},`${o.nodeId??o.name}-${i}`))})}function Lr({evidence:e,t}){var i;const n=(e==null?void 0:e.businessContext)??[],o=e==null?void 0:e.outcome;return!o&&n.length===0?r.jsx(Lt,{t,children:"No business context was returned for this answer."}):r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:12},children:[o&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Outcome"}),o.name&&r.jsx(P,{label:"Outcome",value:o.name,t}),o.owner&&r.jsx(P,{label:"Owner",value:o.owner,t}),o.decisionUse&&r.jsx(P,{label:"Decision Use",value:o.decisionUse,t}),o.reviewCadence&&r.jsx(P,{label:"Review Cadence",value:o.reviewCadence,t}),(i=o.caveats)==null?void 0:i.map((s,l)=>r.jsx(P,{label:"Caveat",value:s,t},`caveat-${l}`))]}),n.length>0&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Context"}),n.map((s,l)=>r.jsx(P,{label:s.label??"Context",value:s.value??"",source:s.source,t},`${s.label}-${l}`))]}),(e==null?void 0:e.semanticObjects)&&e.semanticObjects.length>0&&r.jsx(pt,{title:"Semantic Objects",assets:e.semanticObjects,t}),(e==null?void 0:e.sourceTables)&&e.sourceTables.length>0&&r.jsx(pt,{title:"Source Tables",assets:e.sourceTables,t})]})}function Rr({answer:e,t}){var s,l;const n=e.evidence,o=e.analysisPlan??(n==null?void 0:n.analysisPlan),i=(n==null?void 0:n.citations)??e.citations??[];return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:12},children:[r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(P,{label:"Certification",value:U(e.certification??e.kind),t}),C(e.cascade)&&r.jsx(P,{label:"Cascade",value:C(e.cascade)??"",t}),e.reviewStatus&&r.jsx(P,{label:"Review Status",value:U(e.reviewStatus),t}),typeof e.confidence=="number"&&r.jsx(P,{label:"Confidence",value:`${Math.round(e.confidence*100)}%`,t}),((s=n==null?void 0:n.validation)==null?void 0:s.message)&&r.jsx(P,{label:`Validation ${n.validation.status??""}`.trim(),value:n.validation.message,t}),((l=n==null?void 0:n.execution)==null?void 0:l.message)&&r.jsx(P,{label:`Execution ${n.execution.status??""}`.trim(),value:n.execution.message,t}),e.executionError&&r.jsx(P,{label:"Execution Error",value:e.executionError,t}),e.kind!=="certified"&&r.jsx(P,{label:"Promotion Path",value:"Create draft block, edit SQL, attach tests, then certify after analyst approval.",t})]}),o&&r.jsxs("div",{style:{display:"grid",gap:6},children:[r.jsx(se,{t,children:"Analysis Plan"}),o.question&&r.jsx(P,{label:"Question",value:o.question,t}),o.intent&&r.jsx(P,{label:"Intent",value:U(o.intent),t}),o.grain&&r.jsx(P,{label:"Grain",value:o.grain,t}),o.candidateTables&&o.candidateTables.length>0&&r.jsx(P,{label:"Tables",value:o.candidateTables.slice(0,5).map(c=>c.relation).filter(Boolean).join(", "),t}),o.candidateJoins&&o.candidateJoins.length>0&&r.jsx(P,{label:"Join Paths",value:o.candidateJoins.slice(0,3).map(Rt).join("; "),t}),o.assumptions&&o.assumptions.length>0&&r.jsx(P,{label:"Assumptions",value:o.assumptions.join(" "),t}),typeof o.repairAttempts=="number"&&o.repairAttempts>0&&r.jsx(P,{label:"SQL Repair",value:`${o.repairAttempts} retry`,t})]}),i.length>0&&r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[r.jsx(se,{t,children:"Citations"}),i.slice(0,8).map((c,a)=>r.jsxs("div",{style:{fontSize:12,color:t.textSecondary,fontFamily:t.fontMono},children:[c.kind??"source",": ",c.name??"unknown",c.provenance&&r.jsxs("span",{style:{color:t.textMuted},children:[" (",c.provenance,")"]})]},`${c.kind}-${c.name}-${a}`))]})]})}function pt({title:e,assets:t,t:n}){return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[r.jsx(se,{t:n,children:e}),t.map((o,i)=>r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,paddingBottom:4},children:[r.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:o.name??o.nodeId}),o.kind&&r.jsx(Q,{label:U(o.kind),t:n}),o.certification&&r.jsx(Q,{label:U(o.certification),t:n})]}),o.description&&r.jsx("div",{style:{fontSize:12,color:n.textSecondary},children:o.description}),(o.sourcePath||o.owner||o.domain)&&r.jsx("div",{style:{fontSize:11,color:n.textMuted,fontFamily:n.fontMono},children:[o.domain,o.owner,o.sourcePath].filter(Boolean).join(" - ")})]},`${o.nodeId??o.name}-${i}`))]})}function Ir({artifact:e,t}){const n=[e.kind?{label:"Kind",value:U(e.kind)}:null,e.name?{label:"Name",value:e.name}:null,e.sourcePath?{label:"Source Path",value:e.sourcePath}:null,e.metrics.length>0?{label:"Metrics",value:e.metrics.join(", ")}:null,e.dimensions.length>0?{label:"Dimensions",value:e.dimensions.join(", ")}:null,e.timeDimension?{label:"Time",value:e.timeDimension}:null,e.filters.length>0?{label:"Filters",value:e.filters.join("; ")}:null].filter(o=>!!o);return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:10},children:[n.length>0&&r.jsx("div",{style:{display:"grid",gap:6},children:n.map(o=>r.jsx(P,{label:o.label,value:o.value,t},o.label))}),r.jsx("pre",{style:_t(t,340),children:e.source})]})}function Wr({sql:e,blockPath:t,executionError:n,t:o}){return r.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:8},children:[t&&r.jsxs("div",{style:{fontSize:12,color:o.textSecondary},children:["Source block: ",r.jsx("span",{style:{fontFamily:o.fontMono,color:o.textPrimary},children:t})]}),n&&r.jsx("div",{style:{padding:10,border:"1px solid rgba(248, 81, 73, 0.35)",borderRadius:6,background:"rgba(248, 81, 73, 0.10)",color:"#ff7b72",fontSize:12,lineHeight:1.45,whiteSpace:"pre-wrap"},children:n}),e?r.jsx("pre",{style:_t(o,260),children:e}):r.jsx("div",{style:{fontSize:12,color:o.textMuted},children:"No SQL text was returned for this answer."})]})}function _t(e,t){return{margin:0,padding:10,overflow:"auto",maxHeight:t,borderRadius:4,background:e.editorBg,color:e.textPrimary,border:`1px solid ${e.cellBorder}`,fontSize:12,fontFamily:e.fontMono,whiteSpace:"pre"}}function P({label:e,value:t,source:n,t:o}){return t?r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"130px 1fr",gap:10,fontSize:12,alignItems:"baseline"},children:[r.jsx("span",{style:{color:o.textMuted},children:e}),r.jsxs("span",{style:{color:o.textSecondary},children:[t,n&&r.jsxs("span",{style:{color:o.textMuted},children:[" (",n,")"]})]})]}):null}function se({children:e,t}){return r.jsx("div",{style:{fontSize:11,fontWeight:700,fontFamily:t.fontMono,color:t.textMuted,textTransform:"uppercase",letterSpacing:"0.08em"},children:e})}function Lt({children:e,t}){return r.jsx("div",{style:{padding:12,fontSize:12,color:t.textMuted},children:e})}function Q({label:e,t}){return r.jsx("span",{style:{fontSize:11,fontFamily:t.fontMono,color:t.textSecondary,padding:"2px 6px",borderRadius:4,background:t.editorBg,border:`1px solid ${t.cellBorder}`},children:e})}function Fr({items:e,t,accent:n}){return e.length===0?null:r.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 16px",alignItems:"center",padding:"7px 10px",borderTop:`1px solid ${t.cellBorder}`,boxShadow:`inset 0 2px 0 ${n}`,background:t.editorBg,color:t.textMuted,fontFamily:t.fontMono,fontSize:10.5},children:e.map(o=>r.jsxs("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[r.jsx("span",{style:{color:t.textMuted},children:o.label})," ",r.jsx("strong",{style:{color:t.textSecondary,fontWeight:600},children:o.value})]},`${o.label}-${o.value}`))})}function ft({active:e,label:t,onClick:n,t:o}){return r.jsx("button",{onClick:n,style:{padding:"4px 2px",fontSize:11.5,border:0,borderBottom:`2px solid ${e?o.accent:"transparent"}`,borderRadius:0,background:"transparent",color:e?o.accent:o.textSecondary,fontWeight:e?700:500,cursor:"pointer"},children:t})}function Dr({result:e,chartConfig:t,t:n,onChange:o}){const i=e.columns;if(i.length===0)return null;const s=Me.filter(d=>d.value!=="table"),l=t!=null&&t.x&&i.includes(t.x)?t.x:i[0]??"",c=t!=null&&t.y&&i.includes(t.y)?t.y:i.find(d=>d!==l)??i[0]??"",a=t!=null&&t.color&&i.includes(t.color)?t.color:"";return r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(130px, 1fr))",gap:8,alignItems:"end",border:`1px solid ${n.cellBorder}`,borderRadius:7,background:`${n.tableHeaderBg}55`,padding:10},children:[r.jsx(de,{label:"Chart type",t:n,children:r.jsx("select",{value:(t==null?void 0:t.chart)??"bar",onChange:d=>o({chart:d.target.value}),style:ue(n),children:s.map(d=>r.jsx("option",{value:d.value,children:d.label},d.value))})}),r.jsx(de,{label:"X axis",t:n,children:r.jsx("select",{value:l,onChange:d=>o({x:d.target.value}),style:ue(n),children:i.map(d=>r.jsx("option",{value:d,children:d},d))})}),r.jsx(de,{label:"Y axis",t:n,children:r.jsx("select",{value:c,onChange:d=>o({y:d.target.value}),style:ue(n),children:i.map(d=>r.jsx("option",{value:d,children:d},d))})}),r.jsx(de,{label:"Color",t:n,children:r.jsxs("select",{value:a,onChange:d=>o({color:d.target.value||void 0}),style:ue(n),children:[r.jsx("option",{value:"",children:"None"}),i.map(d=>r.jsx("option",{value:d,children:d},d))]})})]})}function de({label:e,t,children:n}){return r.jsxs("label",{style:{display:"grid",gap:4,minWidth:0},children:[r.jsx("span",{style:{fontSize:10.5,color:t.textMuted,fontWeight:800,textTransform:"uppercase",letterSpacing:0},children:e}),n]})}function ue(e){return{width:"100%",minWidth:0,height:30,border:`1px solid ${e.inputBorder}`,borderRadius:6,background:e.editorBg,color:e.textPrimary,fontFamily:e.font,fontSize:12,padding:"0 8px"}}function U(e){return e.replace(/_/g," ")}function Rt(e){const t=[e.leftRelation,e.leftColumn].filter(Boolean).join("."),n=[e.rightRelation,e.rightColumn].filter(Boolean).join("."),o=[t,n].filter(Boolean).join(" to ");return e.reason?`${o} (${e.reason})`:o}function Nr(e,t,n){return t==null?"-":pe(e,t,n)}function Er(e){const t=e.toLowerCase();return t.includes("certified")?"trusted business context":t.includes("ai")||t.includes("generated")?"AI draft":t.includes("no_answer")?"needs more context":U(e)}function It(e){var t;switch((t=e.trustLabelInfo)==null?void 0:t.id){case"certified":return"certified";case"reviewed":return"review";case"ai_generated":return"ai_generated";case"conflict":return"review";case"insufficient_context":return e.kind==="no_answer"?"no_answer":"uncertified"}return e.kind==="no_answer"?"no_answer":e.certification==="certified"||e.reviewStatus==="certified"?"certified":e.reviewStatus==="draft_ready"||e.reviewStatus==="analyst_review_required"?"review":e.certification==="ai_generated"?"ai_generated":e.certification==="analyst_review_required"||e.certification==="uncertified"?"uncertified":e.kind==="certified"?"certified":"draft"}function Pr(e,t){return e==="certified"?t.success:e==="no_answer"?t.error:e==="deprecated"?t.textMuted:t.warning}function Hr(e,t,n,o){var a,d,u,f,h,p,y,j;const i=[],s=((d=(a=e.evidence)==null?void 0:a.selectedAssets)==null?void 0:d[0])??((f=(u=e.evidence)==null?void 0:u.lineage)==null?void 0:f.find(b=>b.owner||b.domain||b.sourcePath)),l=n??(s==null?void 0:s.name),c=o??(s==null?void 0:s.sourcePath)??(s==null?void 0:s.provenance);if(l&&i.push({label:e.kind==="certified"?"source":"draft source",value:l}),((s==null?void 0:s.owner)??((p=(h=e.evidence)==null?void 0:h.outcome)==null?void 0:p.owner))&&i.push({label:"owner",value:(s==null?void 0:s.owner)??((j=(y=e.evidence)==null?void 0:y.outcome)==null?void 0:j.owner)??""}),c&&i.push({label:"path",value:c}),e.sourceTier&&i.push({label:"tier",value:U(e.sourceTier)}),C(e.cascade)&&i.push({label:"cascade",value:C(e.cascade)??""}),t){const b=t.rowCount??t.rows.length,g=t.executionTime!==void 0?` - ${Math.round(t.executionTime)}ms`:"";i.push({label:"run",value:`${b.toLocaleString()} rows${g}`})}return e.reviewStatus&&e.reviewStatus!=="certified"&&i.push({label:"next",value:U(e.reviewStatus)}),Vr(i).slice(0,5)}function C(e){if(!(e!=null&&e.terminalLane)&&!(e!=null&&e.routeTier))return;const t=Or(e.terminalLane),n=qr(e.routeTier);return[t,n].filter(Boolean).join(" · ")||void 0}function Or(e){switch(e){case"certified":return"Lane 1 certified";case"semantic":return"Lane 2 semantic";case"generated":return"Lane 3 generated";case"refusal":return"Lane 4 refusal";default:return e?U(e):void 0}}function qr(e){switch(e){case"certified_block":return"Certified block";case"semantic_metric":return"Semantic metric";case"generated_sql":return"Generated SQL";case"business_context":return"Business context";case"no_answer":return"No answer";default:return e?U(e):void 0}}function Ur(e,t){var n,o,i,s;return ne(e.sourceCertifiedBlock)??Se((n=e.evidence)==null?void 0:n.selectedAssets)??Se((o=e.evidence)==null?void 0:o.lineage)??Se(e.citations)??ne((i=e.block)==null?void 0:i.name)??ne((s=e.result)==null?void 0:s.blockName)??ne(t)}function Se(e){return e==null?void 0:e.map(t=>t.kind==="block"?ne(t.name):void 0).find(t=>!!t)}function ne(e){return typeof e!="string"?void 0:e.replace(/\s+/g," ").trim()||void 0}function Vr(e){const t=new Set;return e.filter(n=>{const o=n.value.trim();if(!o)return!1;const i=`${n.label}:${o}`;return t.has(i)?!1:(t.add(i),!0)})}const xo=Object.freeze(Object.defineProperty({__proto__:null,AgentAnswerCard:xr,StructuredAnswerText:zt,extractGovernedAnswer:lr,formatCascadeOutcome:C,resolveAgentOutcome:Tt,resolveAnswerTrustState:It,resolveDqlArtifactMeta:At},Symbol.toStringTag,{value:"Module"}));function po(e){return new Set(e.tiles.filter(t=>!t.error&&t.selectedByDefault).map(t=>t.id))}function Qr(e,t){const n=e.intent.target==="personal",o=[];for(const i of e.tiles)i.source!=="ai_generated"||i.error||!t.has(i.id)||(i.sql?n||o.push({id:i.id,title:i.title,reason:"Exploratory AI SQL can only be accepted into a Personal Draft. Switch this build to Personal Draft to keep it."}):o.push({id:i.id,title:i.title,reason:"No query was generated for it, so it has nothing to show. It stays in the review appendix as an open question."}));return o}function fo({proposal:e,t,selected:n,onToggle:o,onCreate:i,busy:s,error:l,compact:c,nameLabel:a="App name",defaultName:d}){const[u,f]=R.useState(d??""),[h,p]=R.useState({}),y=(x,M)=>{p(S=>({...S,[x]:{...S[x],...M}}))},j=e.tiles.filter(x=>!x.error),b=e.tiles.filter(x=>x.error),g=j.filter(x=>n.has(x.id)).length,v=Qr(e,n),m=j.filter(x=>n.has(x.id)&&x.certification==="ai_generated").length,A=j.filter(x=>n.has(x.id)&&x.certification==="reviewed_semantic").length,_=j.filter(x=>n.has(x.id)&&x.certification==="certified").length+A>0||e.intent.target==="personal"&&m>0;return r.jsxs("div",{style:{display:"grid",gap:10},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[r.jsx("span",{style:{fontSize:12.5,fontWeight:800,color:t.textPrimary},children:"Build Brief"}),r.jsxs("span",{style:{fontSize:11,color:t.textMuted},children:[e.coverage.certifiedTiles," certified",e.coverage.semanticTiles>0?` · ${e.coverage.semanticTiles} governed semantic`:"",e.coverage.generatedTiles>0?` · ${e.coverage.generatedTiles} exploratory`:"",e.coverage.gaps>0?` · ${e.coverage.gaps} uncovered`:""]}),r.jsxs("span",{style:{fontSize:10.5,color:t.textMuted},children:[e.intent.target==="personal"?"Personal Draft":"Shared Project target"," · starts private"]})]}),r.jsxs("label",{style:{display:"grid",gap:3},children:[r.jsx("span",{style:{fontSize:10.5,color:t.textMuted,fontWeight:700},children:a}),r.jsx("input",{value:u,onChange:x=>f(x.target.value),placeholder:d,maxLength:120,style:Jr(t)})]}),r.jsxs("div",{style:{display:"grid",gap:6},children:[j.map(x=>r.jsx(Yr,{tile:x,t,checked:n.has(x.id),onToggle:()=>o(x.id),compact:c,edit:h[x.id],onEdit:M=>y(x.id,M)},x.id)),b.map(x=>r.jsxs("div",{style:{...Wt(t),opacity:.75},children:[r.jsx(Ze,{size:13,color:t.warning,style:{flexShrink:0,marginTop:2}}),r.jsxs("div",{style:{minWidth:0,flex:1},children:[r.jsx("div",{style:{fontSize:12,fontWeight:700,color:t.textSecondary},children:x.title}),r.jsx("div",{style:{fontSize:11,color:t.textMuted,marginTop:1},children:x.error})]})]},x.id))]}),e.gaps.length>0?r.jsxs("div",{style:{display:"grid",gap:4},children:[r.jsx("div",{style:{fontSize:11,fontWeight:800,color:t.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Not covered yet"}),e.gaps.map(x=>r.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:t.textMuted},children:[r.jsx(sn,{size:12,style:{flexShrink:0,marginTop:2}}),r.jsx("span",{style:{lineHeight:1.4},children:x.question})]},x.id))]}):null,v.length>0?r.jsxs("div",{role:"status",style:{display:"grid",gap:5,padding:"9px 11px",borderRadius:9,border:`1px solid ${t.headerBorder}`,background:"var(--status-warning-bg, rgba(180,120,0,0.08))"},children:[r.jsx("div",{style:{fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.04em"},children:v.length===1?"1 selected tile will not be built":`${v.length} selected tiles will not be built`}),v.map(x=>r.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:t.textSecondary},children:[r.jsx(Ze,{size:12,style:{flexShrink:0,marginTop:2}}),r.jsxs("span",{style:{lineHeight:1.45},children:[r.jsx("b",{children:x.title})," — ",x.reason]})]},x.id))]}):null,l?r.jsx("div",{style:{fontSize:12,color:t.error},children:l}):null,r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[r.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i({...u.trim()?{appName:u.trim(),pageTitle:u.trim()}:{},tileOverrides:h}),disabled:s||!_,style:Kr(t,_&&!s),children:[s?r.jsx(qt,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):r.jsx(Ut,{size:13}),r.jsx("span",{children:s?"Building draft…":`Build draft (${g} tile${g===1?"":"s"})`})]}),r.jsx("span",{style:{fontSize:11,color:t.textMuted},children:_?A>0?`${A} semantic tile${A===1?"":"s"} will compile against the governed semantic layer and still require result review.`:m>0?`${m} AI-generated tile${m===1?"":"s"} will stay review-required until certified.`:"No App files are written until you confirm this brief.":e.intent.target==="personal"?"Select a certified, semantic, or explicitly accepted exploratory tile.":"Select at least one certified block or governed semantic tile."})]})]})}function Yr({tile:e,t,checked:n,onToggle:o,compact:i,edit:s,onEdit:l}){var h,p;const[c,a]=R.useState(!1),d=e.certification==="certified",u=e.certification==="reviewed_semantic",f=!!(e.sql||e.answer||e.preview&&e.preview.rows.length>0);return r.jsxs("div",{style:Wt(t),children:[r.jsx("input",{type:"checkbox",checked:n,onChange:o,"aria-label":`Include ${e.title}`,style:{marginTop:2,accentColor:t.accent,cursor:"pointer",flexShrink:0}}),r.jsxs("div",{style:{minWidth:0,flex:1},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[r.jsx("input",{value:(s==null?void 0:s.title)??e.title,onChange:y=>l({title:y.target.value}),"aria-label":`Title for ${e.title}`,maxLength:120,style:Cr(t)}),d?r.jsxs("span",{style:we(t.success),children:[r.jsx(Vt,{size:10})," certified"]}):u?r.jsxs("span",{style:we(t.accent),children:[r.jsx(Ge,{size:10})," governed semantic · review required"]}):r.jsxs("span",{style:we(t.warning),children:[((h=e.repair)==null?void 0:h.status)==="repaired"?r.jsx(Kt,{size:10}):r.jsx(Ge,{size:10}),((p=e.repair)==null?void 0:p.status)==="repaired"?"auto-repaired · needs review":"AI-generated · needs review"]}),r.jsx("select",{value:(s==null?void 0:s.viz)??e.viz,onChange:y=>l({viz:y.target.value}),"aria-label":`Visualization for ${e.title}`,style:eo(t),children:[...new Set([...e.allowedVisualizations??[],e.viz,"table"])].map(y=>r.jsx("option",{value:y,children:y.replace(/_/g," ")},y))})]}),e.description&&!i?r.jsx("div",{style:{fontSize:11.5,color:t.textSecondary,marginTop:2,lineHeight:1.4},children:e.description}):null,e.question&&e.question!==e.title?r.jsxs("div",{style:{fontSize:11,color:t.textMuted,marginTop:2},children:["Answers: ",e.question]}):null,i?null:r.jsxs("div",{style:{fontSize:10.5,color:e.preflight.status==="passed"?t.success:e.preflight.status==="blocked"?t.error:t.textMuted,marginTop:2},children:["Preflight: ",e.preflight.status.replace("_"," ")," · ",e.preflight.message]}),e.repair?r.jsxs("div",{style:{fontSize:10.5,color:e.repair.status==="repaired"?t.warning:t.error,marginTop:3,lineHeight:1.4},children:["Repair evidence: ",e.repair.message]}):null,f?r.jsxs("button",{type:"button",onClick:()=>a(y=>!y),style:{border:"none",background:"transparent",color:t.accent,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:700,padding:0,marginTop:4,fontFamily:t.font},children:[c?r.jsx(Qt,{size:11}):r.jsx(Yt,{size:11}),r.jsx(nn,{size:11})," ",c?"Hide details":"Show SQL & preview"]}):null,c&&e.answer?r.jsx("div",{style:{fontSize:11.5,color:t.textSecondary,marginTop:5,lineHeight:1.4},children:e.answer}):null,c&&e.sql?r.jsx("pre",{style:Xr(t),children:e.sql}):null,c&&e.preview&&e.preview.rows.length>0?r.jsx(Zr,{preview:e.preview,t}):null]})]})}function Zr({preview:e,t}){const n=e.columns.slice(0,5),o=e.rows.slice(0,5);return r.jsxs("div",{style:{marginTop:5,overflow:"auto",border:`1px solid ${t.headerBorder}`,borderRadius:6},children:[r.jsxs("table",{style:{borderCollapse:"collapse",fontSize:10.5,fontFamily:t.fontMono,width:"100%"},children:[r.jsx("thead",{children:r.jsx("tr",{children:n.map(i=>r.jsx("th",{style:{textAlign:"left",padding:"3px 8px",color:t.textMuted,borderBottom:`1px solid ${t.headerBorder}`,fontWeight:700,whiteSpace:"nowrap"},children:i},i))})}),r.jsx("tbody",{children:o.map((i,s)=>r.jsx("tr",{children:n.map(l=>r.jsx("td",{style:{padding:"3px 8px",color:t.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:160},children:Gr(i[l])},l))},s))})]}),typeof e.rowCount=="number"&&e.rowCount>o.length?r.jsxs("div",{style:{fontSize:10,color:t.textMuted,padding:"3px 8px"},children:[e.rowCount," rows total"]}):null]})}function Gr(e){return e==null?"":typeof e=="number"?Number.isInteger(e)?String(e):e.toFixed(2):String(e)}function Wt(e){return{display:"flex",gap:9,alignItems:"flex-start",border:`1px solid ${e.cellBorder}`,background:e.cellBg,borderRadius:8,padding:"9px 11px"}}function we(e){return{display:"inline-flex",alignItems:"center",gap:3,border:`1px solid ${e}55`,color:e,background:`${e}12`,borderRadius:999,padding:"1px 7px",fontSize:9.5,fontWeight:800}}function Xr(e){return{margin:"5px 0 0",maxHeight:140,overflow:"auto",border:`1px solid ${e.headerBorder}`,background:e.editorBg,borderRadius:6,padding:8,fontSize:10.5,fontFamily:e.fontMono,color:e.textSecondary,lineHeight:1.45,whiteSpace:"pre-wrap"}}function Kr(e,t){return{display:"inline-flex",alignItems:"center",gap:6,border:"none",borderRadius:8,padding:"8px 14px",fontSize:12.5,fontWeight:800,fontFamily:e.font,cursor:t?"pointer":"default",background:t?e.accent:`${e.accent}55`,color:"#fff"}}function Jr(e){return{border:`1px solid ${e.cellBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:7,padding:"6px 9px",fontSize:12,fontFamily:e.font,outline:"none"}}function Cr(e){return{border:"1px solid transparent",background:"transparent",color:e.textPrimary,borderRadius:5,padding:"1px 4px",fontSize:12.5,fontWeight:750,fontFamily:e.font,minWidth:0,flex:"1 1 180px"}}function eo(e){return{border:`1px solid ${e.cellBorder}`,background:e.cellBg,color:e.textMuted,borderRadius:999,padding:"1px 6px",fontSize:9.5,fontFamily:e.font,cursor:"pointer"}}function ho(e){const t=`dql.agent.threadId.${e}`,[n,o]=R.useState(()=>ht(t));R.useEffect(()=>{o(ht(t))},[t]);const i=R.useCallback(l=>{o(l);try{window.localStorage.setItem(t,l)}catch{}},[t]),s=R.useCallback(()=>{o(void 0);try{window.localStorage.removeItem(t)}catch{}},[t]);return{threadId:n,onThreadIdChange:i,resetThreadId:s}}function ht(e){try{return window.localStorage.getItem(e)??void 0}catch{return}}export{fo as A,Me as C,so as E,sn as F,lo as M,ao as P,uo as R,zt as S,ie as T,St as a,$t as b,co as c,nn as d,po as e,pe as f,kt as g,xo as h,un as i,Qn as r,ho as u};
|