@duckcodeailabs/dql-cli 1.12.3 → 1.12.5
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/assets/dql-notebook/assets/AgentAnswerCard-BJAnjaLA.js +5 -0
- package/dist/assets/dql-notebook/assets/{AgentLogPage-CsSC2tOR.js → AgentLogPage-J72WR6hk.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-CjJ-9bQW.js → AiBuildDialog-CHJZfDmp.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-BvTcW9oE.js → AiBuildResult-Da7_Cn12.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-CxFrOfCE.js → AiSidePanel-BY6W_5aC.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-BtXEdJNR.js → AnalyticsHome-u-buXgdv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AppsView-HjQkbbE6.js → AppsView-3k7ftDpd.js} +3 -3
- package/dist/assets/dql-notebook/assets/{BlockStudio-oQHTJsXC.js → BlockStudio-CLX4EUyO.js} +14 -14
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-Dpsftjs7.js → BusinessArtifactView-3THMNeyO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-c6ZteaI6.js → DbtFirstModelingPage-BwBPwtdA.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-Cj6mc-Yv.js → GitPage-CvEki0pe.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-8G_rEyhK.js → GlobalAiRail-NXdk9kNy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-BTtzt0Za.js → GovernedContextPage-DILbw-Vr.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-e2CesE73.js → HelpDocsPage-DgCu4bvY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-U3ryMLEF.js → HomePage-CK3fXTQo.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-CEmgJzm3.js → LineageDAG-DW_NO3P2.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-CeV5QMXS.js → LineageDetailView-VT7DLJOB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-B1oAn-N_.js → LineageDrawer-DSTm8aXw.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-fP6RTXut.js → LineagePathBreadcrumb-DRlAYasJ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CBYSTmRC.js → MiniLineageGraph-CR_nhwhZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-ksEwimjl.js → NewBlockModal-CJvjYiBF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-CUx0WmXb.js → NewNotebookModal-BEpPH93n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-BdxJL3LX.js → NotebookEditor-C7GDFwhF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-DZ9wDW76.js → ReadinessPage-rZiOp2xr.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-Bt0AAe0h.js → SetupOnboarding-BWjhTjPB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-DNVJK_mP.js → TrustBadge-RvZ9s6OQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{UnifiedAgentRunPanel-BNqE169i.js → UnifiedAgentRunPanel-CGPcpY1B.js} +18 -18
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-B_gE6rsY.js → answer-to-notebook-Di227Cd4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-DnKGhzOR.js → arrow-left-BZHDcWHR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-CQ73DG7_.js → arrow-right-DlM1pC3_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-CyBV5Nhw.js → book-open-text-DBcXFQAu.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-UOPtBzCj.js → bot-BAywbvPm.js} +1 -1
- package/dist/assets/dql-notebook/assets/{chevron-up-CDHDU3N3.js → chevron-up-B_GfKE_F.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-DC5nkL_u.js → circle-x-BcxtZ-ym.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-C7ujXipB.js → dagre.esm-Bqs0lsEz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-BiJ_dtTM.js → external-link-B24Dk9_t.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-eXvkUerq.js → grip-vertical-D9g31N3j.js} +1 -1
- package/dist/assets/dql-notebook/assets/index-DU7j3Sqk.js +644 -0
- package/dist/assets/dql-notebook/assets/{link-2-DkHVJTuH.js → link-2-B36oR5Bj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-8lYW2Itb.js → list-tree-B9ZzGc4U.js} +1 -1
- package/dist/assets/dql-notebook/assets/{maximize-2-DjSovOdP.js → maximize-2-BrvQLPoj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-DGlmQLES.js → minimize-2-BrpFmsxS.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-DPc4gShM.js → panel-right-open-B1g1qhh5.js} +1 -1
- package/dist/assets/dql-notebook/assets/{pencil-nwaGtOdL.js → pencil-DwywbTqQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-ByjLhAu7.js → rotate-ccw-Db_KVs3J.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-eEhwnQhG.js → semantic-fields-BIVuvP2l.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-zws0cKhp.js → triangle-alert-Cne6C2aG.js} +1 -1
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-D6mtrJ-_.js +18 -0
- package/dist/assets/dql-notebook/assets/{user-round-CM8xNakq.js → user-round-DkzxN1xD.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-CIKc8r-4.js → wand-sparkles-CJUvFtur.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-6C0ZLbTi.js → workflow-BOvVTg7R.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-CeU7hF12.js → wrench-YeSpzZRt.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-DLWEzvri.js → x-C6tsHUR7.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/block-invocation.js +4 -0
- package/dist/block-invocation.js.map +1 -1
- package/dist/llm/answer-loop-tools.d.ts +8 -2
- package/dist/llm/answer-loop-tools.d.ts.map +1 -1
- package/dist/llm/answer-loop-tools.js +29 -2
- package/dist/llm/answer-loop-tools.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +27 -1
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +79 -15
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/llm/types.d.ts +8 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/local-runtime.d.ts +46 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +647 -66
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/dist/sql-result-filter.d.ts +39 -0
- package/dist/sql-result-filter.d.ts.map +1 -0
- package/dist/sql-result-filter.js +256 -0
- package/dist/sql-result-filter.js.map +1 -0
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-BEIwKGm4.js +0 -5
- package/dist/assets/dql-notebook/assets/index-BMVfPaXr.js +0 -644
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-hxi1RZDm.js +0 -18
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import{g as Zt,r as c,j as e,u as wt,t as Ct,a as
|
|
1
|
+
import{g as Zt,r as c,j as e,u as wt,t as Ct,a as O,a1 as ot,a2 as eo,d as Gt,D as Vt,T as $t,P as to,S as Yt,e as jt,h as no,a3 as io,a4 as oo,a5 as ae,a6 as yt,a7 as bt,a8 as si,a9 as ri,c as so,aa as ro,B as Rt,y as li,L as rt,ab as ai,ac as di,ad as lo,ae as Gn,af as Re,x as ao,ag as ci,J as ui,ah as co,ai as uo,q as po,z as Nt,v as fo,w as ho,A as Vn}from"./index-DU7j3Sqk.js";import{S as mo,a as go,b as Yn}from"./LineagePathBreadcrumb-DRlAYasJ.js";import{u as xo,a as yo,T as pi,b as bo,d as vo,C as fi}from"./usePersistedAgentThreadId-D6mtrJ-_.js";import{M as So}from"./MiniLineageGraph-CR_nhwhZ.js";import{b as hi,U as jo,E as ko,B as wo}from"./UnifiedAgentRunPanel-CGPcpY1B.js";import{a as Co,A as Bo}from"./AiSidePanel-BY6W_5aC.js";import{T as Et}from"./triangle-alert-Cne6C2aG.js";import{P as To}from"./panel-right-open-B1g1qhh5.js";import{X as Mo}from"./x-C6tsHUR7.js";import{B as Io}from"./bot-BAywbvPm.js";import{P as Do}from"./pencil-DwywbTqQ.js";import"./react-CRB3T2We.js";import"./codemirror-1_I9gm6Z.js";import"./dagre.esm-Bqs0lsEz.js";import"./AgentAnswerCard-BJAnjaLA.js";import"./TrustBadge-RvZ9s6OQ.js";import"./AiBuildResult-Da7_Cn12.js";import"./user-round-DkzxN1xD.js";import"./rotate-ccw-Db_KVs3J.js";import"./list-tree-B9ZzGc4U.js";import"./wrench-YeSpzZRt.js";import"./arrow-right-DlM1pC3_.js";import"./chevron-up-B_GfKE_F.js";import"./minimize-2-BrpFmsxS.js";import"./maximize-2-BrvQLPoj.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const zo=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Po=Zt("chevron-left",zo);/**
|
|
7
7
|
* @license lucide-react v0.563.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Ro=[["path",{d:"M4 11V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-1",key:"1q9hii"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M2 15h10",key:"jfw4w8"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]],mi=Zt("file-input",Ro);/**
|
|
12
12
|
* @license lucide-react v0.563.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Do=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],pi=Zt("play",Do);function vt({value:t,onChange:n,multiline:i,placeholder:o,style:l,ariaLabel:a,rows:p}){const[y,x]=c.useState(t),k=c.useRef(!1);c.useEffect(()=>{k.current||x(t)},[t]);const r={value:y,placeholder:o,style:l,"aria-label":a,onFocus:()=>{k.current=!0},onBlur:()=>{k.current=!1,x(t)},onChange:f=>{x(f.target.value),n(f.target.value)}};return i?e.jsx("textarea",{...r,rows:p}):e.jsx("input",{type:"text",...r})}function zo(t,n){const i=(t==null?void 0:t.trim())??"",o=n.map(a=>a.trim()).filter(Boolean),l=[...new Set(o)].sort((a,p)=>a.localeCompare(p));return i?[i,...l.filter(a=>a!==i)]:l}const Po={native:"Native (DQL)","metricflow-cli":"Local MetricFlow","dbt-cloud":"dbt Cloud"};function Ro(t){switch(t){case"no_join_path":return"No join path from this metric’s model to this dimension.";case"not_shared_across_metrics":return"Not reachable from every selected metric.";case"metric_unresolved":return"The selected metric could not be resolved.";default:return"Not compatible with the selected metrics."}}const Kn=["day","week","month","quarter","year"];function Lo(t,n,i){var a,p;if(!t)return Kn;const o=(a=n.get(t))==null?void 0:a.granularities;if(o&&o.length>0)return o;const l=(p=i.find(y=>(y.reference??y.name)===t||y.name===t))==null?void 0:p.granularities;return l&&l.length>0?l:Kn}function nr(){var xn,yn,bn,vn,Sn,jn,kn,wn,Cn,Bn,Tn,In,Mn,Dn,zn,Pn,Rn,Ln,$n,En,An,_n,Wn,Fn,On;const{state:t,dispatch:n}=wt(),i=Ct[t.themeMode],[o,l]=c.useState(()=>vs()),a=t.activeBlockPath?`block-studio.block.${encodeURIComponent(t.activeBlockPath)}`:`block-studio.draft.${o}`,p=fo(a),[y,x]=c.useState("blocks"),[k,r]=c.useState("results"),[f,g]=c.useState(()=>Ss()),[M,P]=c.useState([]),[_,se]=c.useState({}),[$,j]=c.useState(""),[v,ie]=c.useState(new Set),V=c.useMemo(()=>{const s=t.schemaTables.map(b=>[b.name,b.columns.map(W=>W.name)]),u=Ts(M).map(b=>[b.path,b.columns]),S=new Map;for(const[b,W]of[...u,...s])b&&S.set(b,W);return S.size>0?Object.fromEntries(S):void 0},[t.schemaTables,M]),[J,E]=c.useState(!1),[Z,H]=c.useState(null),[I,U]=c.useState(null),[O,Y]=c.useState(0),[de,ee]=c.useState({}),[N,re]=c.useState(!1),D=c.useRef(null),[X,le]=c.useState(null),[we,ke]=c.useState(!1),[ce,Te]=c.useState(null),[he,Pe]=c.useState(!1),[Re,ue]=c.useState(null),[We,d]=c.useState(0),[R,K]=c.useState(!1),[ge,be]=c.useState(!1),Le=c.useRef(!1),te=c.useRef(!1),[pe,Ce]=c.useState(null),[Ze,$e]=c.useState([]),[qe,Ne]=c.useState(!1),[et,He]=c.useState(!1),[Qe,Ue]=c.useState(null),[Ie,Ke]=c.useState(null),[tt,Ge]=c.useState(null),[Ve,nt]=c.useState(340),[m,T]=c.useState(320),[w,C]=c.useState(!1),[q,oe]=c.useState(!1),[h,B]=c.useState(()=>typeof window<"u"?window.innerWidth<900:!1),[z,A]=c.useState(()=>t.blockStudioImportOpen?"import":"start"),[xe,G]=c.useState("visual"),[Be,it]=c.useState(()=>js("dql.block-studio.ai.open",!1)),[Bt,yi]=c.useState(()=>ks("dql.block-studio.ai.width",420,360,520)),[tn,nn]=c.useState(!1),[bi,vi]=c.useState(!1),[Si,ji]=c.useState(0),[Me,Tt]=c.useState(null),[ki,on]=c.useState([]),[wi,sn]=c.useState(!1),[at,At]=c.useState(null),[rn,_t]=c.useState(null),[ln,Ci]=c.useState("ask"),[Bi,Ti]=c.useState(""),[Ii,Mi]=c.useState(void 0),[Di,zi]=c.useState(!1),[an,Ms]=c.useState(null),dn=c.useRef(t.activeBlockPath);c.useEffect(()=>{let s=!0;return n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:!0}),n({type:"SET_SEMANTIC_LOADING",loading:!0}),Ce(null),F.getBlockStudioCatalog({includeSemantic:!1}).then(u=>{s&&(n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:u}),P(u.databaseTree))}).catch(()=>{s&&Ce("Failed to load schema. Check your connection and try refreshing.")}).finally(()=>{s&&n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:!1})}),F.getBlockStudioDbtStatus().then(u=>{s&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:u})}).catch(()=>{s&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:null})}),F.getSemanticLayer().then(u=>{s&&n({type:"SET_SEMANTIC_LAYER",layer:u})}).finally(()=>{s&&n({type:"SET_SEMANTIC_LOADING",loading:!1})}),()=>{s=!1}},[n]);const It=c.useCallback(async()=>{sn(!0);try{const s=await F.listBlockStudioImports();on(s.sessions??[])}catch{on([])}finally{sn(!1)}},[]);c.useEffect(()=>{It()},[It]),c.useEffect(()=>{const s=dn.current,u=t.activeBlockPath;u&&u!==s&&n({type:"CLOSE_BLOCK_IMPORT"}),dn.current=u},[t.activeBlockPath,n]),c.useEffect(()=>{const s=window.setTimeout(()=>{t.blockStudioDraft.trim()&&F.validateBlockStudio(t.blockStudioDraft,t.activeBlockPath).then(u=>n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:u})).catch(()=>{})},250);return()=>window.clearTimeout(s)},[t.blockStudioDraft,t.activeBlockPath,n]),c.useMemo(()=>Cs(M,$),[M,$]);const Mt=c.useMemo(()=>Bs(M),[M]),cn={metrics:t.semanticLayer.metrics.length,measures:t.semanticLayer.measures.length,dimensions:t.semanticLayer.dimensions.length,timeDimensions:t.semanticLayer.timeDimensions.length,entities:t.semanticLayer.entities.length,hierarchies:t.semanticLayer.hierarchies.length,semanticModels:t.semanticLayer.semanticModels.length,savedQueries:t.semanticLayer.savedQueries.length},un=Is(cn);c.useEffect(()=>{const s=()=>B(window.innerWidth<900);return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.open",Be?"1":"0")}catch{}},[Be]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.width",String(Bt))}catch{}},[Bt]),c.useEffect(()=>{if(f)try{window.localStorage.setItem("dql.block-studio.domain",f)}catch{}},[f]),c.useEffect(()=>{var u,S;const s=(S=(u=t.blockStudioMetadata)==null?void 0:u.domain)==null?void 0:S.trim();s&&s!=="uncategorized"&&g(s)},[t.activeBlockPath,(xn=t.blockStudioMetadata)==null?void 0:xn.domain]),c.useEffect(()=>{t.blockStudioImportOpen&&(A("import"),n({type:"CLOSE_BLOCK_IMPORT"}))},[n,t.blockStudioImportOpen]),c.useEffect(()=>{var s;A(ws(t)?"manual":"start"),G(((s=ot(t.blockStudioDraft))==null?void 0:s.blockType)==="semantic"?"visual":"source")},[t.activeBlockPath]);const Ye=c.useMemo(()=>{var u;const s=ot(t.blockStudioDraft);return t.blockStudioMetadata?{...s,name:(s==null?void 0:s.name)||t.blockStudioMetadata.name,domain:(s==null?void 0:s.domain)||t.blockStudioMetadata.domain,description:(s==null?void 0:s.description)||t.blockStudioMetadata.description,owner:(s==null?void 0:s.owner)||t.blockStudioMetadata.owner,tags:(u=s==null?void 0:s.tags)!=null&&u.length?s.tags:t.blockStudioMetadata.tags,blockType:(s==null?void 0:s.blockType)||"custom",status:(s==null?void 0:s.status)||t.blockStudioMetadata.reviewStatus||"draft"}:s},[t.blockStudioDraft,t.blockStudioMetadata]),me=(Ye==null?void 0:Ye.name)??((yn=t.blockStudioMetadata)==null?void 0:yn.name)??null,Fe=((Ye==null?void 0:Ye.blockType)??"custom")==="semantic",Ee=!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath);c.useEffect(()=>{var s;if(t.activeBlockPath){if(D.current==="builder"){D.current=null,G(((s=ot(t.blockStudioDraft))==null?void 0:s.blockType)==="semantic"?"visual":"source");return}t.activeBlockPath&&G("detail")}},[t.activeBlockPath]);const Wt=c.useCallback(async s=>{const u=`block:${s}`;n({type:"SET_LINEAGE_FOCUS",nodeId:u}),He(!0);try{const[S,b,W]=await Promise.all([F.fetchLineageNode(u),F.queryLineage({focus:u,upstreamDepth:3,downstreamDepth:2}),F.fetchLineagePaths(u,{maxDepth:6,maxPaths:6})]);Ue(S),Ke(b.graph??null),Ge(W)}catch{Ue(null),Ke(null),Ge(null)}finally{He(!1)}},[n]);c.useEffect(()=>{me&&Wt(me)},[me,Wt]);const De=s=>{H(null),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:s});const u=ot(s),S=t.blockStudioMetadata;if(!u||!S)return;const b={...S,name:u.name||S.name,domain:u.domain||S.domain,description:u.description,owner:u.owner,tags:u.tags,reviewStatus:u.status||S.reviewStatus};(b.name!==S.name||b.domain!==S.domain||b.description!==S.description||b.owner!==S.owner||b.reviewStatus!==S.reviewStatus||b.tags.join("\0")!==S.tags.join("\0"))&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:b})},Pi=s=>{if(s==="semantic"===Fe)return;const u=t.blockStudioMetadata,S=(u==null?void 0:u.name)||(s==="semantic"?"new_semantic_block":"new_sql_block");let b=s==="semantic"?Kt(S):Pt(S);b=yt(b,S),s==="custom"&&(b=oi(b,"")),u&&(b=ae(b,"domain",u.domain||"uncategorized"),b=ae(b,"description",u.description??""),b=ae(b,"owner",u.owner??""),b=bt(b,u.tags??[])),De(b),G("visual")},Ri=(s,u)=>{const S=t.blockStudioMetadata;let b=Fe?t.blockStudioDraft:Kt((S==null?void 0:S.name)||"new_semantic_block");!Fe&&S&&(b=ae(b,"domain",S.domain||"uncategorized"),b=ae(b,"description",S.description??""),b=ae(b,"owner",S.owner??""),b=bt(b,S.tags??[])),b=ti(b,s),b=ni(b,"dimensions",u),De(b),At(null),_t(null),A("manual"),G("visual")},Dt=()=>{n({type:"START_NEW_BLOCK_WORKSPACE"}),l(Jt()),Tt(null),A("start"),G("visual")},pn=()=>{if(t.blockStudioDirty){be(!0);return}Dt()},fn=()=>{pn()},hn=s=>{const u=s==="semantic"?"new_semantic_block":"new_sql_block",S=f||"uncategorized",b=s==="semantic"?Kt(u):Pt(u),W=ae(b,"domain",S);n({type:"SET_BLOCK_STUDIO_DRAFT",draft:W}),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:u,path:null,domain:S,folderPath:"",description:"",owner:"",tags:[],reviewStatus:"draft",sourceKind:"manual"}}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:null}),A("manual"),G("visual")},zt=async()=>{E(!0),H(null),U(Date.now()),Y(0),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null});try{const s=await F.runBlockStudio(t.blockStudioDraft,t.activeBlockPath,de);n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:s}),r("results")}catch(s){const u=s instanceof Error?s.message:String(s);H(u),r(/required parameter|provide required parameter/i.test(u)?"parameters":"results")}finally{E(!1),U(null)}},Li=async(s=t.blockStudioDraft)=>{var b,W;if(!t.blockStudioMetadata)throw new Error("Block metadata is required before saving.");const u=await F.saveBlockStudio({path:t.activeBlockPath,source:s,metadata:{name:t.blockStudioMetadata.name,domain:t.blockStudioMetadata.domain,folderPath:t.blockStudioMetadata.folderPath,description:t.blockStudioMetadata.description,owner:t.blockStudioMetadata.owner,tags:t.blockStudioMetadata.tags,sourceKind:t.blockStudioMetadata.sourceKind,sourcePath:t.blockStudioMetadata.sourcePath,importId:t.blockStudioMetadata.importId,candidateId:t.blockStudioMetadata.candidateId,lineage:t.blockStudioMetadata.lineage}});return d(Q=>Q+1),n({type:"OPEN_BLOCK_STUDIO",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"},payload:u}),t.files.some(Q=>Q.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),((b=u.lineageRefresh)==null?void 0:b.status)==="ready"?await Wt(u.metadata.name):((W=u.lineageRefresh)==null?void 0:W.status)==="failed"&&(le(`Block saved, but lineage refresh failed: ${u.lineageRefresh.message??"compile failed"}`),setTimeout(()=>le(null),7e3)),u},Ft=async()=>{var s;if(!((s=t.blockStudioMetadata)!=null&&s.name.trim())||!t.blockStudioMetadata.owner.trim())return K(!0),!1;re(!0),le(null);try{const u=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ae(t.blockStudioDraft,"status","draft"):t.blockStudioDraft;return await Li(u),r("save"),!0}catch(u){const S=(u==null?void 0:u.message)??"Save failed";return le(S.includes("409")||S.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":S),setTimeout(()=>le(null),5e3),!1}finally{re(!1)}},Ot=(s,u)=>{ue(null),Te({path:s,name:u}),ke(!0)},$i=async()=>{var u;const s=ce==null?void 0:ce.path;if(s){Pe(!0),ue(null);try{const S=await F.deleteBlockStudio(s);n({type:"FILE_REMOVED",path:S.path}),t.activeBlockPath===S.path&&(n({type:"START_NEW_BLOCK_WORKSPACE"}),l(Jt()),Tt(null),A("start"),G("visual")),ke(!1),Te(null),d(b=>b+1),((u=S.lineageRefresh)==null?void 0:u.status)==="failed"&&Ce(`Block deleted, but lineage refresh failed: ${S.lineageRefresh.message??"compile failed"}`)}catch(S){ue(S instanceof Error?S.message:String(S))}finally{Pe(!1)}}};c.useEffect(()=>{var s;!Le.current||!((s=t.blockStudioMetadata)!=null&&s.name.trim())||!t.blockStudioMetadata.owner.trim()||(Le.current=!1,Ft().then(u=>{u&&te.current&&(te.current=!1,Dt())}))},[(bn=t.blockStudioMetadata)==null?void 0:bn.name,(vn=t.blockStudioMetadata)==null?void 0:vn.owner,t.blockStudioDraft]);const Ei=s=>{var b;const u=s.savedPath??((b=s.draftSave)==null?void 0:b.path)??"",S={path:u,source:s.dqlSource,metadata:{name:s.name,path:u||null,domain:s.domain,description:s.description,owner:s.owner,tags:s.tags,reviewStatus:s.reviewStatus,sourceKind:s.sourceKind,sourcePath:s.sourcePath,importId:Me==null?void 0:Me.id,candidateId:s.id,lineage:s.lineage.sourceTables},companionPath:null,validation:s.validation??{valid:!0,diagnostics:[],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:null}};n({type:"OPEN_BLOCK_STUDIO",file:{name:`${s.name}.dql`,path:u,type:"block",folder:"blocks",isNew:!u},payload:S}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:s.preview}),r("results"),A("manual"),G("visual")},Ai=(s,u)=>{t.files.some(b=>b.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),Tt(b=>b&&{...b,candidates:b.candidates.map(W=>W.id===s.id?s:W)}),It()},_i=(s,u)=>{var Q,Ae,ct,ut,pt,ft,ht;const S=t.blockStudioDraft.trim()?t.blockStudioDraft:Pt(((Q=u==null?void 0:u.title)==null?void 0:Q.trim())||"AI Generated Block"),b=(Ae=u==null?void 0:u.blockSource)!=null&&Ae.trim()?u.blockSource.trim():Zn(S,s);De(b);const W=ot(b);W&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:W.name||(u==null?void 0:u.title)||"AI Generated Block",path:t.activeBlockPath,domain:W.domain||(u==null?void 0:u.domain)||"analytics",description:W.description||(u==null?void 0:u.description)||`AI generated block for ${(u==null?void 0:u.question)??"analysis"}`,owner:W.owner||(u==null?void 0:u.owner)||"",tags:W.tags.length>0?W.tags:(u==null?void 0:u.tags)??["ai-generated","review-required"],reviewStatus:W.status||"draft",sourceKind:((ct=t.blockStudioMetadata)==null?void 0:ct.sourceKind)??"ai-generated",sourcePath:(ut=t.blockStudioMetadata)==null?void 0:ut.sourcePath,importId:(pt=t.blockStudioMetadata)==null?void 0:pt.importId,candidateId:(ft=t.blockStudioMetadata)==null?void 0:ft.candidateId,lineage:(ht=t.blockStudioMetadata)==null?void 0:ht.lineage}}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:{valid:!0,diagnostics:[{severity:"info",code:"ai_sql_draft_inserted",message:W?"AI generated a draft block with metadata, SQL, visualization, and tests. Run preview, review joins and grain, then save.":"AI generated SQL inserted. Run preview, review joins and grain, then save or certify."}],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:s.trim()}}),r("results")},Wi=async s=>{var ct,ut,pt,ft,ht,qn,Nn;const u=(ut=(ct=s.dqlArtifact)==null?void 0:ct.source)==null?void 0:ut.trim(),S=(s.sql??"").trim();if(!u&&!S)return;let b;if((pt=s.question)!=null&&pt.trim())try{const ve=await F.composeSemanticBlock(s.question.trim());ve.ok&&ve.source.trim()&&(b=ve.source.trim())}catch{}const W=b||u||Zn(Pt(((ft=s.title)==null?void 0:ft.trim())||"AI Generated Block"),S),Q=ot(W),Ae=(Q==null?void 0:Q.name)||((ht=s.dqlArtifact)==null?void 0:ht.name)||s.title||"AI Generated Block";re(!0),le(null);try{const ve=await F.saveAgentBlockDraft({source:W,name:Ae,domain:(Q==null?void 0:Q.domain)||((qn=t.blockStudioMetadata)==null?void 0:qn.domain)||"uncategorized",description:(Q==null?void 0:Q.description)||`AI-generated draft for ${s.title??Ae}`,tags:(Nn=Q==null?void 0:Q.tags)!=null&&Nn.length?Q.tags:["ai-generated","review-required"],runId:s.sourceRunId});D.current="builder",n({type:"OPEN_BLOCK_STUDIO",file:{name:`${ve.metadata.name}.dql`,path:ve.path,type:"block",folder:"blocks",isNew:!1},payload:ve}),t.files.some(qt=>qt.path===ve.path)||n({type:"FILE_ADDED",file:{name:`${ve.metadata.name}.dql`,path:ve.path,type:"block",folder:"blocks"}}),d(qt=>qt+1),A("manual"),G("visual"),r("save")}catch(ve){le(ve instanceof Error?ve.message:String(ve))}finally{re(!1)}},dt=s=>{const u=(s==null?void 0:s.kind)??"ask";r("results"),Ci(u),Ti((s==null?void 0:s.initialInput)??""),Mi(s!=null&&s.autoRun?{text:s.autoRun,mode:"block",nonce:Date.now()}:void 0),it(!0)};c.useCallback(async()=>{try{const s=await F.getBlockStudioCatalog({includeSemantic:!1});s!=null&&s.databaseTree&&P(s.databaseTree),n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:s})}catch{}},[n]),c.useEffect(()=>{if(!J||!I)return;const s=()=>Y(Date.now()-I);s();const u=window.setInterval(s,1e3);return()=>window.clearInterval(u)},[J,I]);const mn=((Sn=t.blockStudioValidation)==null?void 0:Sn.chartConfig)??((jn=t.blockStudioPreview)==null?void 0:jn.chartConfig)??{chart:"table"},Fi=t.blockStudioPreview?ho(t.blockStudioPreview.result,t.blockStudioPreview.chartConfig):"table",Oi=s=>{s.preventDefault();const u=s.clientX,S=Ve,b=Q=>{const Ae=Math.min(560,Math.max(300,S+Q.clientX-u));nt(Ae)},W=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",W)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",W)},qi=s=>{s.preventDefault();const u=s.clientY,S=m,b=Q=>{const Ae=Math.min(500,Math.max(180,S-(Q.clientY-u)));T(Ae)},W=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",W)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",W)},Ni=s=>{s.preventDefault();const u=s.clientX,S=Bt,b=Q=>{yi(Math.min(520,Math.max(360,S-(Q.clientX-u))))},W=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",W)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",W)},Xe=Ee&&!q,Hi=h?"minmax(0, 1fr)":`${w?0:Ve}px ${w?0:6}px minmax(0, 1fr) ${Be?6:0}px ${Be?tn?`min(${So}px, 52vw)`:`${Bt}px`:0}`,Qi=h?w?Xe?`minmax(0, 1fr) 6px ${m}px`:"minmax(0, 1fr) 0 0":Xe?`minmax(220px, 34vh) minmax(320px, 1fr) 6px ${m}px`:"minmax(220px, 34vh) minmax(0, 1fr) 0 0":Xe?`minmax(0, 1fr) 6px ${m}px`:"minmax(0, 1fr) 0 0",Ui=h?"1":"3",gn=h?w?"1":"2":"1",Ki=h?"1":"3",Gi=h?w?"2":"3":"2",Vi=h?"1":"3",Yi=h?w?"3":"4":"3";return e.jsxs("div",{style:{flex:1,position:"relative",display:"grid",gridTemplateColumns:Hi,gridTemplateRows:Qi,overflow:"hidden",background:i.appBg},children:[e.jsx("div",{style:{gridColumn:"1",gridRow:h?"1":"1 / 4",borderRight:w?"none":`1px solid ${i.headerBorder}`,borderBottom:h&&!w?`1px solid ${i.headerBorder}`:"none",display:w?"none":"flex",flexDirection:"column",overflow:"hidden",background:i.sidebarBg,minWidth:0},children:e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e.jsx(Xi,{tabs:["blocks","semantic","database"],defaultTab:y,blockDomain:f,onBlockDomainChange:g,onInsertText:s=>{if(Fe){_t("That snippet is SQL. Use a SQL Block for raw SELECT work, or keep this Semantic Block on metrics and dimensions.");return}De(bs(t.blockStudioDraft,s))},onSemanticCompose:Ri,onNewBlock:fn,onDeleteBlock:s=>Ot(s.path,s.name),blockLibraryRefreshKey:We,onCollapse:()=>C(!0),footer:t.semanticLayer.loading?`Loading ${(((kn=t.blockStudioDbtStatus)==null?void 0:kn.counts.metrics)??0).toLocaleString()} semantic metrics…`:`${t.semanticLayer.provider?`${t.semanticLayer.provider} synced`:"dbt synced"} · ${Mt.tables} table${Mt.tables===1?"":"s"} · ${t.semanticLayer.metrics.length.toLocaleString()} metric${t.semanticLayer.metrics.length===1?"":"s"}`,footerStatus:t.semanticLayer.loading?"loading":"ready"})})}),e.jsx("div",{onMouseDown:w?void 0:Oi,style:{gridColumn:"2",gridRow:"1 / 4",display:w||h?"none":"block",cursor:"col-resize",background:i.headerBorder}}),e.jsxs("div",{style:{display:h&&Be?"none":"flex",flexDirection:"column",minWidth:0,overflow:"hidden",gridColumn:Ui,gridRow:gn},children:[e.jsx("style",{children:`
|
|
16
|
+
*/const Lo=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],gi=Zt("play",Lo);function vt({value:t,onChange:n,multiline:i,placeholder:s,style:l,ariaLabel:a,rows:p}){const[y,x]=c.useState(t),k=c.useRef(!1);c.useEffect(()=>{k.current||x(t)},[t]);const r={value:y,placeholder:s,style:l,"aria-label":a,onFocus:()=>{k.current=!0},onBlur:()=>{k.current=!1,x(t)},onChange:f=>{x(f.target.value),n(f.target.value)}};return i?e.jsx("textarea",{...r,rows:p}):e.jsx("input",{type:"text",...r})}function $o(t,n){const i=(t==null?void 0:t.trim())??"",s=n.map(a=>a.trim()).filter(Boolean),l=[...new Set(s)].sort((a,p)=>a.localeCompare(p));return i?[i,...l.filter(a=>a!==i)]:l}const Eo={native:"Native (DQL)","metricflow-cli":"Local MetricFlow","dbt-cloud":"dbt Cloud"};function Ao(t){switch(t){case"no_join_path":return"No join path from this metric’s model to this dimension.";case"not_shared_across_metrics":return"Not reachable from every selected metric.";case"metric_unresolved":return"The selected metric could not be resolved.";default:return"Not compatible with the selected metrics."}}const Xn=["day","week","month","quarter","year"];function _o(t,n,i){var a,p;if(!t)return Xn;const s=(a=n.get(t))==null?void 0:a.granularities;if(s&&s.length>0)return s;const l=(p=i.find(y=>(y.reference??y.name)===t||y.name===t))==null?void 0:p.granularities;return l&&l.length>0?l:Xn}function sr(){var vn,Sn,jn,kn,wn,Cn,Bn,Tn,Mn,In,Dn,zn,Pn,Rn,Ln,$n,En,An,_n,Wn,On,Fn,qn,Nn,Hn,Qn;const{state:t,dispatch:n}=wt(),i=Ct[t.themeMode],[s,l]=c.useState(()=>ws()),a=t.activeBlockPath?`block-studio.block.${encodeURIComponent(t.activeBlockPath)}`:`block-studio.draft.${s}`,p=xo(a),[y,x]=c.useState("blocks"),[k,r]=c.useState("results"),[f,g]=c.useState(()=>Cs()),[I,P]=c.useState([]),[W,le]=c.useState({}),[E,j]=c.useState(""),[S,ie]=c.useState(new Set),V=c.useMemo(()=>{const o=t.schemaTables.map(b=>[b.name,b.columns.map(R=>R.name)]),u=zs(I).map(b=>[b.path,b.columns]),v=new Map;for(const[b,R]of[...u,...o])b&&v.set(b,R);return v.size>0?Object.fromEntries(v):void 0},[t.schemaTables,I]),[J,A]=c.useState(!1),[Z,Q]=c.useState(null),[M,K]=c.useState(null),[F,Y]=c.useState(0),[de,ee]=c.useState({}),[N,oe]=c.useState(!1),D=c.useRef(null),[X,se]=c.useState(null),[Ce,ke]=c.useState(!1),[ce,Ie]=c.useState(null),[he,Le]=c.useState(!1),[$e,ue]=c.useState(null),[We,d]=c.useState(0),[L,U]=c.useState(!1),[ge,be]=c.useState(!1),Be=c.useRef(null),te=c.useRef(!1),[pe,Te]=c.useState(null),[Ze,Ee]=c.useState([]),[Ne,He]=c.useState(!1),[et,Qe]=c.useState(!1),[Ue,Ke]=c.useState(null),[De,Ge]=c.useState(null),[tt,Ve]=c.useState(null),[Ye,nt]=c.useState(340),[m,T]=c.useState(320),[w,C]=c.useState(!1),[q,re]=c.useState(!1),[h,B]=c.useState(()=>typeof window<"u"?window.innerWidth<900:!1),[z,_]=c.useState(()=>t.blockStudioImportOpen?"import":"start"),[xe,G]=c.useState("visual"),[Me,it]=c.useState(()=>Bs("dql.block-studio.ai.open",!1)),[Bt,ji]=c.useState(()=>Ts("dql.block-studio.ai.width",420,360,520)),[tn,nn]=c.useState(!1),[ki,wi]=c.useState(!1),[Ci,Bi]=c.useState(0),[ze,Tt]=c.useState(null),[Ti,on]=c.useState([]),[Mi,sn]=c.useState(!1),[at,At]=c.useState(null),[rn,_t]=c.useState(null),[ln,Ii]=c.useState("ask"),[Di,zi]=c.useState(""),[Pi,Ri]=c.useState(void 0),[Li,$i]=c.useState(!1),[an,dn]=c.useState(null),cn=c.useRef(t.activeBlockPath);c.useEffect(()=>{let o=!0;return n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:!0}),n({type:"SET_SEMANTIC_LOADING",loading:!0}),Te(null),O.getBlockStudioCatalog({includeSemantic:!1}).then(u=>{o&&(n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:u}),P(u.databaseTree))}).catch(()=>{o&&Te("Failed to load schema. Check your connection and try refreshing.")}).finally(()=>{o&&n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:!1})}),O.getBlockStudioDbtStatus().then(u=>{o&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:u})}).catch(()=>{o&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:null})}),O.getSemanticLayer().then(u=>{o&&n({type:"SET_SEMANTIC_LAYER",layer:u})}).finally(()=>{o&&n({type:"SET_SEMANTIC_LOADING",loading:!1})}),()=>{o=!1}},[n]);const Mt=c.useCallback(async()=>{sn(!0);try{const o=await O.listBlockStudioImports();on(o.sessions??[])}catch{on([])}finally{sn(!1)}},[]);c.useEffect(()=>{Mt()},[Mt]),c.useEffect(()=>{const o=cn.current,u=t.activeBlockPath;u&&u!==o&&n({type:"CLOSE_BLOCK_IMPORT"}),cn.current=u},[t.activeBlockPath,n]),c.useEffect(()=>{const o=window.setTimeout(()=>{t.blockStudioDraft.trim()&&O.validateBlockStudio(t.blockStudioDraft,t.activeBlockPath).then(u=>n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:u})).catch(()=>{})},250);return()=>window.clearTimeout(o)},[t.blockStudioDraft,t.activeBlockPath,n]),c.useMemo(()=>Is(I,E),[I,E]);const It=c.useMemo(()=>Ds(I),[I]),un={metrics:t.semanticLayer.metrics.length,measures:t.semanticLayer.measures.length,dimensions:t.semanticLayer.dimensions.length,timeDimensions:t.semanticLayer.timeDimensions.length,entities:t.semanticLayer.entities.length,hierarchies:t.semanticLayer.hierarchies.length,semanticModels:t.semanticLayer.semanticModels.length,savedQueries:t.semanticLayer.savedQueries.length},pn=Ps(un);c.useEffect(()=>{const o=()=>B(window.innerWidth<900);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.open",Me?"1":"0")}catch{}},[Me]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.width",String(Bt))}catch{}},[Bt]),c.useEffect(()=>{if(f)try{window.localStorage.setItem("dql.block-studio.domain",f)}catch{}},[f]),c.useEffect(()=>{var u,v;const o=(v=(u=t.blockStudioMetadata)==null?void 0:u.domain)==null?void 0:v.trim();o&&o!=="uncategorized"&&g(o)},[t.activeBlockPath,(vn=t.blockStudioMetadata)==null?void 0:vn.domain]),c.useEffect(()=>{t.blockStudioImportOpen&&(_("import"),n({type:"CLOSE_BLOCK_IMPORT"}))},[n,t.blockStudioImportOpen]),c.useEffect(()=>{var o;_(Ms(t)?"manual":"start"),G(((o=ot(t.blockStudioDraft))==null?void 0:o.blockType)==="semantic"?"visual":"source")},[t.activeBlockPath]);const Xe=c.useMemo(()=>{var u;const o=ot(t.blockStudioDraft);return t.blockStudioMetadata?{...o,name:(o==null?void 0:o.name)||t.blockStudioMetadata.name,domain:(o==null?void 0:o.domain)||t.blockStudioMetadata.domain,description:(o==null?void 0:o.description)||t.blockStudioMetadata.description,owner:(o==null?void 0:o.owner)||t.blockStudioMetadata.owner,tags:(u=o==null?void 0:o.tags)!=null&&u.length?o.tags:t.blockStudioMetadata.tags,blockType:(o==null?void 0:o.blockType)||"custom",status:(o==null?void 0:o.status)||t.blockStudioMetadata.reviewStatus||"draft"}:o},[t.blockStudioDraft,t.blockStudioMetadata]),me=(Xe==null?void 0:Xe.name)??((Sn=t.blockStudioMetadata)==null?void 0:Sn.name)??null,Oe=((Xe==null?void 0:Xe.blockType)??"custom")==="semantic",Ae=!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath);c.useEffect(()=>{var o;if(t.activeBlockPath){if(D.current==="builder"){D.current=null,G(((o=ot(t.blockStudioDraft))==null?void 0:o.blockType)==="semantic"?"visual":"source");return}t.activeBlockPath&&G("detail")}},[t.activeBlockPath]);const Wt=c.useCallback(async o=>{const u=`block:${o}`;n({type:"SET_LINEAGE_FOCUS",nodeId:u}),Qe(!0);try{const[v,b,R]=await Promise.all([O.fetchLineageNode(u),O.queryLineage({focus:u,upstreamDepth:3,downstreamDepth:2}),O.fetchLineagePaths(u,{maxDepth:6,maxPaths:6})]);Ke(v),Ge(b.graph??null),Ve(R)}catch{Ke(null),Ge(null),Ve(null)}finally{Qe(!1)}},[n]);c.useEffect(()=>{me&&Wt(me)},[me,Wt]);const Pe=o=>{Q(null),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:o});const u=ot(o),v=t.blockStudioMetadata;if(!u||!v)return;const b={...v,name:u.name||v.name,domain:u.domain||v.domain,description:u.description,owner:u.owner,tags:u.tags,reviewStatus:u.status||v.reviewStatus};(b.name!==v.name||b.domain!==v.domain||b.description!==v.description||b.owner!==v.owner||b.reviewStatus!==v.reviewStatus||b.tags.join("\0")!==v.tags.join("\0"))&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:b})},Ei=o=>{if(o==="semantic"===Oe)return;const u=t.blockStudioMetadata,v=(u==null?void 0:u.name)||(o==="semantic"?"new_semantic_block":"new_sql_block");let b=o==="semantic"?Kt(v):Pt(v);b=yt(b,v),o==="custom"&&(b=ai(b,"")),u&&(b=ae(b,"domain",u.domain||"uncategorized"),b=ae(b,"description",u.description??""),b=ae(b,"owner",u.owner??""),b=bt(b,u.tags??[])),Pe(b),G("visual")},Ai=(o,u)=>{const v=t.blockStudioMetadata;let b=Oe?t.blockStudioDraft:Kt((v==null?void 0:v.name)||"new_semantic_block");!Oe&&v&&(b=ae(b,"domain",v.domain||"uncategorized"),b=ae(b,"description",v.description??""),b=ae(b,"owner",v.owner??""),b=bt(b,v.tags??[])),b=si(b,o),b=ri(b,"dimensions",u),Pe(b),At(null),_t(null),_("manual"),G("visual")},Dt=()=>{n({type:"START_NEW_BLOCK_WORKSPACE"}),l(Jt()),Tt(null),_("start"),G("visual")},fn=()=>{if(t.blockStudioDirty){be(!0);return}Dt()},hn=()=>{fn()},mn=o=>{const u=o==="semantic"?"new_semantic_block":"new_sql_block",v=f||"uncategorized",b=o==="semantic"?Kt(u):Pt(u),R=ae(b,"domain",v);n({type:"SET_BLOCK_STUDIO_DRAFT",draft:R}),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:u,path:null,domain:v,folderPath:"",description:"",owner:"",tags:[],reviewStatus:"draft",sourceKind:"manual"}}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:null}),_("manual"),G("visual")},zt=async()=>{A(!0),Q(null),K(Date.now()),Y(0),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null});try{const o=await O.runBlockStudio(t.blockStudioDraft,t.activeBlockPath,de);n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:o}),r("results")}catch(o){const u=o instanceof Error?o.message:String(o);Q(u),r(/required parameter|provide required parameter/i.test(u)?"parameters":"results")}finally{A(!1),K(null)}},gn=async(o=t.blockStudioDraft)=>{var b,R;if(!t.blockStudioMetadata)throw new Error("Block metadata is required before saving.");const u=await O.saveBlockStudio({path:t.activeBlockPath,source:o,metadata:{name:t.blockStudioMetadata.name,domain:t.blockStudioMetadata.domain,folderPath:t.blockStudioMetadata.folderPath,description:t.blockStudioMetadata.description,owner:t.blockStudioMetadata.owner,tags:t.blockStudioMetadata.tags,sourceKind:t.blockStudioMetadata.sourceKind,sourcePath:t.blockStudioMetadata.sourcePath,importId:t.blockStudioMetadata.importId,candidateId:t.blockStudioMetadata.candidateId,lineage:t.blockStudioMetadata.lineage}});return d(H=>H+1),n({type:"OPEN_BLOCK_STUDIO",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"},payload:u}),t.files.some(H=>H.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),((b=u.lineageRefresh)==null?void 0:b.status)==="ready"?await Wt(u.metadata.name):((R=u.lineageRefresh)==null?void 0:R.status)==="failed"&&(se(`Block saved, but lineage refresh failed: ${u.lineageRefresh.message??"compile failed"}`),setTimeout(()=>se(null),7e3)),u},Ot=async()=>{var o;if(!((o=t.blockStudioMetadata)!=null&&o.name.trim())||!t.blockStudioMetadata.owner.trim())return Be.current="save",U(!0),!1;oe(!0),se(null);try{const u=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ae(t.blockStudioDraft,"status","draft"):t.blockStudioDraft;return await gn(u),r("save"),!0}catch(u){const v=(u==null?void 0:u.message)??"Save failed";return se(v.includes("409")||v.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":v),setTimeout(()=>se(null),5e3),!1}finally{oe(!1)}},Ft=(o,u)=>{ue(null),Ie({path:o,name:u}),ke(!0)},_i=async()=>{var u;const o=ce==null?void 0:ce.path;if(o){Le(!0),ue(null);try{const v=await O.deleteBlockStudio(o);n({type:"FILE_REMOVED",path:v.path}),t.activeBlockPath===v.path&&(n({type:"START_NEW_BLOCK_WORKSPACE"}),l(Jt()),Tt(null),_("start"),G("visual")),ke(!1),Ie(null),d(b=>b+1),((u=v.lineageRefresh)==null?void 0:u.status)==="failed"&&Te(`Block deleted, but lineage refresh failed: ${v.lineageRefresh.message??"compile failed"}`)}catch(v){ue(v instanceof Error?v.message:String(v))}finally{Le(!1)}}},xn=async()=>{var u;if(!((u=t.blockStudioMetadata)!=null&&u.name.trim())||!t.blockStudioMetadata.owner.trim())return Be.current="certify",U(!0),!1;let o=!1;oe(!0),se(null);try{dn(null);const v=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ae(t.blockStudioDraft,"status","draft"):t.blockStudioDraft,b=await gn(v);o=!0;const R=await O.certifyBlockStudio({source:b.source,path:b.path});if(dn(R),R.ok&&R.status){const H=R.path||b.path,we={path:H,source:R.source??ae(b.source,"status",R.status),metadata:R.metadata??{...b.metadata,path:H,reviewStatus:R.status},companionPath:R.companionPath??b.companionPath??null,validation:R.validation??b.validation};n({type:"OPEN_BLOCK_STUDIO",file:{name:`${we.metadata.name}.dql`,path:H,type:"block",folder:"blocks",isNew:!1},payload:we})}return r("save"),!0}catch(v){const b=(v==null?void 0:v.message)??"Save failed";return se(b.includes("409")||b.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":b),setTimeout(()=>se(null),5e3),o}finally{oe(!1)}};c.useEffect(()=>{var v;const o=Be.current;if(!o||!((v=t.blockStudioMetadata)!=null&&v.name.trim())||!t.blockStudioMetadata.owner.trim())return;Be.current=null,(o==="certify"?xn():Ot()).then(b=>{b&&te.current&&(te.current=!1,Dt())})},[(jn=t.blockStudioMetadata)==null?void 0:jn.name,(kn=t.blockStudioMetadata)==null?void 0:kn.owner,t.blockStudioDraft]);const Wi=o=>{var b;const u=o.savedPath??((b=o.draftSave)==null?void 0:b.path)??"",v={path:u,source:o.dqlSource,metadata:{name:o.name,path:u||null,domain:o.domain,description:o.description,owner:o.owner,tags:o.tags,reviewStatus:o.reviewStatus,sourceKind:o.sourceKind,sourcePath:o.sourcePath,importId:ze==null?void 0:ze.id,candidateId:o.id,lineage:o.lineage.sourceTables},companionPath:null,validation:o.validation??{valid:!0,diagnostics:[],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:null}};n({type:"OPEN_BLOCK_STUDIO",file:{name:`${o.name}.dql`,path:u,type:"block",folder:"blocks",isNew:!u},payload:v}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:o.preview}),r("results"),_("manual"),G("visual")},Oi=(o,u)=>{t.files.some(b=>b.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),Tt(b=>b&&{...b,candidates:b.candidates.map(R=>R.id===o.id?o:R)}),Mt()},Fi=(o,u)=>{var H,we,ct,ut,pt,ft,ht;const v=t.blockStudioDraft.trim()?t.blockStudioDraft:Pt(((H=u==null?void 0:u.title)==null?void 0:H.trim())||"AI Generated Block"),b=(we=u==null?void 0:u.blockSource)!=null&&we.trim()?u.blockSource.trim():ii(v,o);Pe(b);const R=ot(b);R&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:R.name||(u==null?void 0:u.title)||"AI Generated Block",path:t.activeBlockPath,domain:R.domain||(u==null?void 0:u.domain)||"analytics",description:R.description||(u==null?void 0:u.description)||`AI generated block for ${(u==null?void 0:u.question)??"analysis"}`,owner:R.owner||(u==null?void 0:u.owner)||"",tags:R.tags.length>0?R.tags:(u==null?void 0:u.tags)??["ai-generated","review-required"],reviewStatus:R.status||"draft",sourceKind:((ct=t.blockStudioMetadata)==null?void 0:ct.sourceKind)??"ai-generated",sourcePath:(ut=t.blockStudioMetadata)==null?void 0:ut.sourcePath,importId:(pt=t.blockStudioMetadata)==null?void 0:pt.importId,candidateId:(ft=t.blockStudioMetadata)==null?void 0:ft.candidateId,lineage:(ht=t.blockStudioMetadata)==null?void 0:ht.lineage}}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:{valid:!0,diagnostics:[{severity:"info",code:"ai_sql_draft_inserted",message:R?"AI generated a draft block with metadata, SQL, visualization, and tests. Run preview, review joins and grain, then save.":"AI generated SQL inserted. Run preview, review joins and grain, then save or certify."}],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:o.trim()}}),r("results")},qi=async o=>{var ct,ut,pt,ft,ht,Un,Kn;const u=(ut=(ct=o.dqlArtifact)==null?void 0:ct.source)==null?void 0:ut.trim(),v=(o.sql??"").trim();if(!u&&!v)return;let b;if((pt=o.question)!=null&&pt.trim())try{const ve=await O.composeSemanticBlock(o.question.trim());ve.ok&&ve.source.trim()&&(b=ve.source.trim())}catch{}const R=b||u||ii(Pt(((ft=o.title)==null?void 0:ft.trim())||"AI Generated Block"),v),H=ot(R),we=(H==null?void 0:H.name)||((ht=o.dqlArtifact)==null?void 0:ht.name)||o.title||"AI Generated Block";oe(!0),se(null);try{const ve=await O.saveAgentBlockDraft({source:R,name:we,domain:(H==null?void 0:H.domain)||((Un=t.blockStudioMetadata)==null?void 0:Un.domain)||"uncategorized",description:(H==null?void 0:H.description)||`AI-generated draft for ${o.title??we}`,tags:(Kn=H==null?void 0:H.tags)!=null&&Kn.length?H.tags:["ai-generated","review-required"],runId:o.sourceRunId});D.current="builder",n({type:"OPEN_BLOCK_STUDIO",file:{name:`${ve.metadata.name}.dql`,path:ve.path,type:"block",folder:"blocks",isNew:!1},payload:ve}),t.files.some(qt=>qt.path===ve.path)||n({type:"FILE_ADDED",file:{name:`${ve.metadata.name}.dql`,path:ve.path,type:"block",folder:"blocks"}}),d(qt=>qt+1),_("manual"),G("visual"),r("save")}catch(ve){se(ve instanceof Error?ve.message:String(ve))}finally{oe(!1)}},dt=o=>{const u=(o==null?void 0:o.kind)??"ask";r("results"),Ii(u),zi((o==null?void 0:o.initialInput)??""),Ri(o!=null&&o.autoRun?{text:o.autoRun,mode:"block",nonce:Date.now()}:void 0),it(!0)};c.useCallback(async()=>{try{const o=await O.getBlockStudioCatalog({includeSemantic:!1});o!=null&&o.databaseTree&&P(o.databaseTree),n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:o})}catch{}},[n]),c.useEffect(()=>{if(!J||!M)return;const o=()=>Y(Date.now()-M);o();const u=window.setInterval(o,1e3);return()=>window.clearInterval(u)},[J,M]);const yn=((wn=t.blockStudioValidation)==null?void 0:wn.chartConfig)??((Cn=t.blockStudioPreview)==null?void 0:Cn.chartConfig)??{chart:"table"},Ni=t.blockStudioPreview?yo(t.blockStudioPreview.result,t.blockStudioPreview.chartConfig):"table",Hi=o=>{o.preventDefault();const u=o.clientX,v=Ye,b=H=>{const we=Math.min(560,Math.max(300,v+H.clientX-u));nt(we)},R=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",R)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",R)},Qi=o=>{o.preventDefault();const u=o.clientY,v=m,b=H=>{const we=Math.min(500,Math.max(180,v-(H.clientY-u)));T(we)},R=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",R)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",R)},Ui=o=>{o.preventDefault();const u=o.clientX,v=Bt,b=H=>{ji(Math.min(520,Math.max(360,v-(H.clientX-u))))},R=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",R)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",R)},Je=Ae&&!q,Ki=h?"minmax(0, 1fr)":`${w?0:Ye}px ${w?0:6}px minmax(0, 1fr) ${Me?6:0}px ${Me?tn?`min(${Co}px, 52vw)`:`${Bt}px`:0}`,Gi=h?w?Je?`minmax(0, 1fr) 6px ${m}px`:"minmax(0, 1fr) 0 0":Je?`minmax(220px, 34vh) minmax(320px, 1fr) 6px ${m}px`:"minmax(220px, 34vh) minmax(0, 1fr) 0 0":Je?`minmax(0, 1fr) 6px ${m}px`:"minmax(0, 1fr) 0 0",Vi=h?"1":"3",bn=h?w?"1":"2":"1",Yi=h?"1":"3",Xi=h?w?"2":"3":"2",Ji=h?"1":"3",Zi=h?w?"3":"4":"3";return e.jsxs("div",{style:{flex:1,position:"relative",display:"grid",gridTemplateColumns:Ki,gridTemplateRows:Gi,overflow:"hidden",background:i.appBg},children:[e.jsx("div",{style:{gridColumn:"1",gridRow:h?"1":"1 / 4",borderRight:w?"none":`1px solid ${i.headerBorder}`,borderBottom:h&&!w?`1px solid ${i.headerBorder}`:"none",display:w?"none":"flex",flexDirection:"column",overflow:"hidden",background:i.sidebarBg,minWidth:0},children:e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e.jsx(eo,{tabs:["blocks","semantic","database"],defaultTab:y,blockDomain:f,onBlockDomainChange:g,onInsertText:o=>{if(Oe){_t("That snippet is SQL. Use a SQL Block for raw SELECT work, or keep this Semantic Block on metrics and dimensions.");return}Pe(ks(t.blockStudioDraft,o))},onSemanticCompose:Ai,onNewBlock:hn,onDeleteBlock:o=>Ft(o.path,o.name),blockLibraryRefreshKey:We,onCollapse:()=>C(!0),footer:t.semanticLayer.loading?`Loading ${(((Bn=t.blockStudioDbtStatus)==null?void 0:Bn.counts.metrics)??0).toLocaleString()} semantic metrics…`:`${t.semanticLayer.provider?`${t.semanticLayer.provider} synced`:"dbt synced"} · ${It.tables} table${It.tables===1?"":"s"} · ${t.semanticLayer.metrics.length.toLocaleString()} metric${t.semanticLayer.metrics.length===1?"":"s"}`,footerStatus:t.semanticLayer.loading?"loading":"ready"})})}),e.jsx("div",{onMouseDown:w?void 0:Hi,style:{gridColumn:"2",gridRow:"1 / 4",display:w||h?"none":"block",cursor:"col-resize",background:i.headerBorder}}),e.jsxs("div",{style:{display:h&&Me?"none":"flex",flexDirection:"column",minWidth:0,overflow:"hidden",gridColumn:Vi,gridRow:bn},children:[e.jsx("style",{children:`
|
|
17
17
|
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
18
18
|
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
19
|
-
`}),e.jsxs("div",{style:{height:46,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,background:i.cellBg,overflowX:"auto"},children:[w&&e.jsx("button",{onClick:()=>C(!1),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:14,fontFamily:i.font,padding:0,lineHeight:1},title:"Open explorer",children:"›"}),e.jsxs("button",{type:"button",onClick:pn,title:"Back to Block Studio",className:"dql-hover",style:{display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",padding:"2px 4px",margin:"0 -4px",borderRadius:6,color:i.textMuted,fontSize:12,fontFamily:i.font,whiteSpace:"nowrap",cursor:"pointer"},children:[e.jsx(Io,{size:12,strokeWidth:2})," Blocks"]}),e.jsx(Gt,{size:11,color:i.textMuted,style:{flexShrink:0}}),e.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:i.textPrimary,fontFamily:i.fontMono,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},children:me||((wn=t.blockStudioMetadata)==null?void 0:wn.name)||(Ee?"new_block":Fe?"semantic":"sql")}),((Cn=t.blockStudioMetadata)==null?void 0:Cn.reviewStatus)&&e.jsx(ci,{status:t.blockStudioMetadata.reviewStatus,t:i}),Ee&&z==="manual"&&xe!=="detail"&&e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${i.headerBorder}`,borderRadius:7,background:i.appBg,marginLeft:6,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>G("visual"),style:Gn(i,xe==="visual"),children:"Visual Builder"}),e.jsx("button",{type:"button",onClick:()=>G("source"),style:Gn(i,xe==="source"),children:"DQL Source"})]}),Ee&&e.jsx(Je,{label:`Context${ei(t.blockStudioDraft)?` (${ei(t.blockStudioDraft)})`:""}`,Icon:Vt,onClick:()=>zi(s=>!s)}),e.jsx("div",{style:{flex:1}}),t.activeBlockPath&&e.jsx(Je,{label:"Delete",Icon:$t,variant:"danger",title:"Delete this saved block",onClick:()=>{var s;return Ot(t.activeBlockPath,((s=t.blockStudioMetadata)==null?void 0:s.name)||me||t.activeBlockPath)}}),e.jsx(Je,{label:"New block",Icon:Ji,onClick:fn}),Ee&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{label:"Ask AI",Icon:Yt,onClick:()=>dt({kind:"ask"})}),t.activeBlockPath&&e.jsx(Je,{label:"Modify with AI",Icon:Yt,onClick:()=>dt({kind:"edit",initialInput:`Modify this block${me?` (${me})`:""}: `})}),e.jsx(Je,{label:"Run",Icon:pi,onClick:()=>void zt(),busy:J}),e.jsx(Je,{label:N?"Saving":"Save draft",Icon:jt,variant:"primary",busy:N,onClick:()=>void Ft()})]}),X&&e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",fontFamily:i.font,padding:"4px 8px",background:"var(--status-error-bg)",borderRadius:6},children:X})]}),Ee&&Di&&e.jsx(qo,{source:t.blockStudioDraft,databaseStats:Mt,semanticCount:un,onChange:De,onOpenExplorer:()=>{C(!1),x("database")},onOpenAi:()=>dt({kind:"edit",initialInput:"Review and improve this block context. Keep only grounded business references, sources, constraints, and caveats: "}),t:i}),e.jsx("div",{style:{flex:1,overflow:"hidden"},children:z==="import"?e.jsx(ns,{session:Me,sessions:ki,sessionsLoading:wi,onClose:()=>A(Ee?"manual":"start"),onSessionChange:Tt,onRefreshSessions:It,onSelectCandidate:Ei,onSavedCandidate:Ai,defaultDomain:((Bn=t.blockStudioMetadata)==null?void 0:Bn.domain)??f,defaultOwner:((Tn=t.blockStudioMetadata)==null?void 0:Tn.owner)??"",themeMode:t.themeMode,t:i,inline:!0}):Ee?xe==="detail"?e.jsx(Qo,{metadata:t.blockStudioMetadata,source:t.blockStudioDraft,parameters:((In=t.blockStudioValidation)==null?void 0:In.parameters)??[],preview:t.blockStudioPreview,lineageDetail:Qe,isSemanticBlock:Fe,running:J,onOpenBuilder:()=>G("visual"),onOpenSource:()=>G("source"),onDelete:()=>{var s;return t.activeBlockPath&&Ot(t.activeBlockPath,((s=t.blockStudioMetadata)==null?void 0:s.name)||me||t.activeBlockPath)},onRun:()=>void zt(),onOpenHistory:()=>{r("history"),oe(!1),!qe&&t.activeBlockPath&&F.getBlockHistory(t.activeBlockPath).then(s=>{$e(s.entries),Ne(!0)})},t:i}):xe==="visual"?e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsx(Ko,{mode:Fe?"semantic":"custom",onModeChange:Pi,t:i}),e.jsx("div",{style:{flex:1,minHeight:0},children:Fe?e.jsx(Uo,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,semanticLayer:t.semanticLayer,dbtStatus:t.blockStudioDbtStatus,domainOptions:t.semanticLayer.domains,chartConfig:mn,onChange:De,onMetadataChange:s=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...s}}),onOpenAi:()=>dt({kind:"edit",initialInput:"Help resolve the selected semantic metrics and dimensions for this block: "}),onSetupRuntime:()=>{n({type:"SET_SETTINGS_TAB",tab:"project"}),n({type:"SET_MAIN_VIEW",view:"settings"})},t:i},`sem-${t.activeBlockPath??o}`):e.jsx(Go,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,domainOptions:t.semanticLayer.domains,chartConfig:mn,onChange:De,onMetadataChange:s=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...s}}),onConvertToDql:()=>G("source"),t:i},`sql-${t.activeBlockPath??o}`)})]}):e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(at||rn)&&e.jsx(Vo,{semanticChoice:at,databaseWarning:rn,onDismiss:()=>{At(null),_t(null)},onInsertAdvanced:()=>{if(!at)return;const s=Zi(at.kind==="metric"?"metric":"dimension",at.name);De(eo(t.blockStudioDraft,s)),At(null)},onCreateSemantic:()=>n({type:"OPEN_NEW_BLOCK_MODAL",blockType:"semantic"}),t:i}),e.jsxs("div",{style:{height:34,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 14px",borderBottom:"1px solid var(--border-subtle)",background:i.appBg},children:[e.jsx("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.activeBlockPath??gi(t.blockStudioMetadata)}),e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)",flexShrink:0},title:"Unsaved changes"}),e.jsx("div",{style:{flex:1}}),(((Mn=t.blockStudioValidation)==null?void 0:Mn.diagnostics.filter(s=>s.severity==="error").length)??0)===0?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-success)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(jt,{size:12})," Valid"]}):e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-warning)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(Et,{size:12})," ",t.blockStudioValidation.diagnostics.filter(s=>s.severity==="error").length," problem",t.blockStudioValidation.diagnostics.filter(s=>s.severity==="error").length===1?"":"s"]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[e.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",background:i.cellBg,borderRight:"1px solid var(--border-subtle)"},children:e.jsx(uo,{value:t.blockStudioDraft,onChange:De,onRun:()=>void zt(),themeMode:t.themeMode,autoFocus:!0,wrap:!1,fillHeight:!0,schema:V,dqlMode:!0,errorMessage:(zn=(Dn=t.blockStudioValidation)==null?void 0:Dn.diagnostics.find(s=>s.severity==="error"))==null?void 0:zn.message})}),!h&&e.jsx(Eo,{source:t.blockStudioDraft,diagnostics:((Pn=t.blockStudioValidation)==null?void 0:Pn.diagnostics)??[],parameterCount:((Ln=(Rn=t.blockStudioValidation)==null?void 0:Rn.parameters)==null?void 0:Ln.length)??0,t:i})]})]}):e.jsx(Fo,{dbtStatus:t.blockStudioDbtStatus,semanticStats:cn,semanticObjectCount:un,databaseStats:Mt,onCreateSql:()=>hn("custom"),onCreateSemantic:()=>hn("semantic"),onImport:()=>A("import"),onBuildDql:()=>dt({kind:"build",initialInput:"Draft a reusable DQL block that "}),t:i})})]}),e.jsx("div",{onMouseDown:Xe?qi:void 0,style:{gridColumn:Ki,gridRow:Gi,display:Xe?"block":"none",cursor:"row-resize",background:i.headerBorder}}),e.jsxs("div",{style:{gridColumn:Vi,gridRow:Yi,borderTop:Xe?`1px solid ${i.headerBorder}`:"none",display:Xe?"flex":"none",flexDirection:"column",overflow:"hidden",background:i.cellBg},children:[e.jsxs("div",{style:{display:"flex",gap:14,alignItems:"center",padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,flexWrap:"wrap"},children:[e.jsx(mt,{active:k==="results",onClick:()=>r("results"),label:"Results",t:i}),e.jsx(mt,{active:k==="parameters",onClick:()=>r("parameters"),label:`Run inputs${(((En=($n=t.blockStudioValidation)==null?void 0:$n.parameters)==null?void 0:En.length)??0)>0?` · ${t.blockStudioValidation.parameters.length}`:""}`,t:i}),e.jsx(mt,{active:k==="lineage",onClick:()=>r("lineage"),label:"Lineage",t:i}),e.jsx(mt,{active:k==="history",onClick:()=>{r("history"),!qe&&t.activeBlockPath&&F.getBlockHistory(t.activeBlockPath).then(s=>{$e(s.entries),Ne(!0)})},label:"History",t:i}),e.jsx(mt,{active:k==="save",onClick:()=>r("save"),label:"Metadata",t:i}),e.jsx("div",{style:{flex:1}}),t.blockStudioPreview?e.jsxs("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.font,whiteSpace:"nowrap"},children:[t.blockStudioPreview.result.executionTime?`Ran in ${(t.blockStudioPreview.result.executionTime/1e3).toFixed(1)}s · `:"",t.blockStudioPreview.result.rowCount??t.blockStudioPreview.result.rows.length," rows"]}):null,e.jsx("button",{onClick:()=>oe(!0),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:11,fontFamily:i.font,padding:"4px 6px"},title:"Hide pane",children:"▾ Hide"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[k==="results"&&(J?e.jsx(cs,{elapsedMs:O}):t.blockStudioPreview?e.jsxs("div",{style:{display:"grid",gap:12,padding:12},children:[(_n=(An=t.blockStudioPreview.invocation)==null?void 0:An.resolvedParameters)!=null&&_n.length?e.jsx(ds,{values:t.blockStudioPreview.invocation.resolvedParameters,t:i}):null,e.jsx("div",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono},children:t.blockStudioPreview.sql}),Fi==="table"?e.jsx(ai,{result:t.blockStudioPreview.result,themeMode:t.themeMode}):e.jsx(mo,{result:t.blockStudioPreview.result,chartConfig:t.blockStudioPreview.chartConfig,themeMode:t.themeMode})]}):Z?e.jsx(us,{message:Z}):e.jsx(lt,{message:"Run the block to preview results."})),k==="lineage"&&e.jsx(rs,{blockName:me,loading:et,detail:Qe,graph:Ie,paths:tt,onSelectNode:s=>{n({type:"SET_LINEAGE_FOCUS",nodeId:s}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:s})},onOpenInspector:()=>{if(me){const s=`block:${me}`;n({type:"SET_LINEAGE_FOCUS",nodeId:s}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:s})}},t:i}),k==="parameters"&&e.jsx(as,{parameters:((Wn=t.blockStudioValidation)==null?void 0:Wn.parameters)??[],values:de,onChange:(s,u)=>ee(S=>({...S,[s]:u})),onReset:s=>ee(u=>{const S={...u};return delete S[s],S}),onRun:()=>void zt(),running:J,t:i}),k==="history"&&e.jsx(ys,{entries:Ze,t:i}),k==="save"&&e.jsxs("div",{style:{display:"grid",gap:12},children:[t.activeBlockPath&&t.blockStudioMetadata&&e.jsx("div",{style:{padding:"12px 12px 0"},children:e.jsx(hs,{currentStatus:t.blockStudioMetadata.reviewStatus??"draft",blockPath:t.activeBlockPath,onStatusChanged:s=>{t.blockStudioMetadata&&(n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,reviewStatus:s}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:ae(t.blockStudioDraft,"status",s)}))},t:i})}),an&&e.jsx(ms,{result:an,t:i}),e.jsx(ls,{metadata:t.blockStudioMetadata,draftMetadata:Ye,onChange:s=>{if(!t.blockStudioMetadata)return;n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...s}});let u=t.blockStudioDraft;typeof s.name=="string"&&(u=yt(u,s.name)),typeof s.domain=="string"&&(u=ae(u,"domain",s.domain)),typeof s.owner=="string"&&(u=ae(u,"owner",s.owner)),typeof s.description=="string"&&(u=ae(u,"description",s.description)),s.tags&&(u=bt(u,s.tags)),De(u)},t:i})]})]})]}),Ee&&q&&e.jsx("div",{style:{position:"absolute",right:16,bottom:16},children:e.jsx("button",{onClick:()=>oe(!1),style:{background:i.btnBg,border:`1px solid ${i.btnBorder}`,borderRadius:6,color:i.textSecondary,cursor:"pointer",fontSize:12,fontFamily:i.font,padding:"8px 12px"},children:"Open Results"})}),!h&&Be&&e.jsx("div",{onMouseDown:Ni,style:{gridColumn:"4",gridRow:"1 / 4",cursor:"col-resize",background:i.headerBorder}}),Be&&e.jsx(jo,{t:i,title:"Block AI",subtitle:me?`Current block: ${me}`:"Unsaved governed block draft",expanded:tn,onToggleExpanded:()=>nn(s=>!s),onClose:()=>{it(!1),nn(!1)},onNewChat:()=>{p.resetThreadId(),ji(s=>s+1)},running:bi,compact:h,ariaLabel:"Block Studio AI",style:{gridColumn:h?"1":"5",gridRow:h?gn:"1 / 4"},children:e.jsx(yo,{themeMode:t.themeMode,title:"Block AI",scopeHint:me?`Current block: ${me}`:"Block Studio project context",workspaceContext:{surface:"block-studio",task:ln==="edit"?"edit_block":"author_block",draftSessionId:o,blockStudioDraft:t.blockStudioDraft,activeBlockPath:t.activeBlockPath,domain:(Fn=t.blockStudioMetadata)==null?void 0:Fn.domain,importId:Me==null?void 0:Me.id,importCandidateId:(On=Me==null?void 0:Me.candidates[0])==null?void 0:On.id,...ln==="edit"?{mode:"edit",blockPath:t.activeBlockPath}:{}},initialMode:"block",initialInput:Bi,autoRun:Ii,threadId:p.threadId,onThreadIdChange:p.onThreadIdChange,onRunningChange:vi,onInsertSql:(s,u)=>_i(s,{question:u??me??"analysis",title:u}),onInsertDql:s=>{Wi(s)},answerFirstCards:!0,insertDqlActionLabel:"Add to Block Studio",emptyHint:"Describe the governed block you need. DQL checks certified blocks and semantic metrics before creating a review-required draft.",examplePrompts:[{label:"Build from business question",prompt:"Build a reusable governed DQL block for this business question: "},{label:"Find reusable blocks",prompt:"Which certified DQL blocks already answer this analysis, and what should be reused instead of duplicated?"},{label:"Review this block",prompt:"Review this block for grain, compatible metrics and dimensions, parameters, tests, and certification gaps."}]},`${a}:${Si}`)}),!Be&&!h&&e.jsx("button",{type:"button",onClick:()=>it(!0),title:"Open Block AI",style:{position:"absolute",right:12,top:58,width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${i.btnBorder}`,background:i.btnBg,color:i.accent,cursor:"pointer",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.12)"},children:e.jsx(ko,{size:16,strokeWidth:2})}),R&&t.blockStudioMetadata&&e.jsx(Ao,{metadata:t.blockStudioMetadata,onCancel:()=>K(!1),onConfirm:s=>{let u=yt(t.blockStudioDraft,s.name);u=ae(u,"owner",s.owner),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...s}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:u}),Le.current=!0,K(!1)},t:i}),ge&&e.jsx(_o,{saving:N,onCancel:()=>be(!1),onDiscard:()=>{be(!1),Dt()},onSave:async()=>{te.current=!0,be(!1),await Ft()&&(te.current=!1,Dt())},t:i}),we&&ce&&e.jsx(Wo,{blockName:ce.name,blockPath:ce.path,deleting:he,error:Re,onCancel:()=>{he||(ke(!1),Te(null),ue(null))},onConfirm:()=>void $i(),t:i})]})}function $o({active:t,onClick:n,label:i,busy:o,Icon:l,variant:a="secondary",title:p}){const{state:y}=wt(),x=Ct[y.themeMode],k=a==="primary",r=a==="danger";return e.jsxs("button",{onClick:n,title:p??i,style:{background:k?x.accent:r?`${x.error}0d`:t?`${x.accent}18`:x.btnBg,border:`1px solid ${k?x.accent:r?`${x.error}55`:t?x.accent:x.btnBorder}`,borderRadius:6,height:28,color:k?"#ffffff":r?x.error:t?x.accent:x.textSecondary,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:k?800:600,fontFamily:x.font,padding:"0 10px",whiteSpace:"nowrap",opacity:o?.7:1},children:[o?e.jsx(rt,{size:13,strokeWidth:2,"aria-hidden":"true"}):l?e.jsx(l,{size:13,strokeWidth:2,"aria-hidden":"true"}):null,o?`${i}...`:i]})}function Je(t){return e.jsx($o,{active:!1,...t})}function Eo({source:t,diagnostics:n,parameterCount:i,t:o}){const l=t.split(`
|
|
20
|
-
`),a={block:"var(--text-tertiary)",parameters:"var(--accent)",query:"var(--status-success)",tests:"var(--status-warning)",visualization:"var(--cat-audit)"},p=[];l.forEach((r,f)=>{const g=r.match(/^\s*(block|parameters|query|tests|visualization)\b/);if(g&&!p.some(M=>M.label.toLowerCase().startsWith(g[1]))){const M=g[1],P=M==="block"?"Metadata":M==="parameters"?`Parameters${i?` · ${i}`:""}`:M.charAt(0).toUpperCase()+M.slice(1);p.push({label:P,line:f+1,color:a[M]??"var(--text-tertiary)"})}});const y=(t.match(/^\s*assert\b/gm)??[]).length,x=new Set((t.match(/\b(?:from|join)\s+([a-z_][\w.]*)/gi)??[]).map(r=>r.replace(/^(from|join)\s+/i,""))).size,k=n.filter(r=>r.severity==="error");return e.jsxs("div",{style:{width:208,flexShrink:0,background:o.appBg,display:"flex",flexDirection:"column",overflow:"auto"},children:[e.jsx("div",{style:{padding:"12px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,fontFamily:o.font},children:"Outline"}),e.jsx("div",{style:{padding:"0 8px",display:"flex",flexDirection:"column",gap:1},children:p.length===0?e.jsx("span",{style:{fontSize:11,color:o.textMuted,padding:"2px 8px",fontFamily:o.font},children:"No sections yet."}):p.map(r=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:6},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2,background:r.color,flexShrink:0}}),e.jsx("span",{style:{flex:1,fontSize:11.5,fontWeight:550,color:o.textSecondary,fontFamily:o.font},children:r.label}),e.jsxs("span",{style:{fontSize:10,color:o.textMuted,fontFamily:o.fontMono},children:[":",r.line]})]},r.label))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,fontFamily:o.font},children:"Problems"}),k.length===0?e.jsxs("div",{style:{padding:"0 14px",fontSize:11.5,color:"var(--status-success)",display:"flex",alignItems:"center",gap:6,fontFamily:o.font},children:[e.jsx(jt,{size:12})," No problems"]}):e.jsx("div",{style:{padding:"0 14px",display:"flex",flexDirection:"column",gap:5},children:k.slice(0,4).map((r,f)=>e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",lineHeight:1.4,fontFamily:o.font},children:r.message},f))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,fontFamily:o.font},children:"Context"}),e.jsxs("div",{style:{padding:"0 14px 16px",display:"flex",flexDirection:"column",gap:5,fontSize:11,color:o.textSecondary,fontFamily:o.font},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--accent)"}}),i," parameter",i===1?"":"s"," bound"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-success)"}}),x," model",x===1?"":"s"," referenced"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)"}}),y," test",y===1?"":"s"," declared"]})]})]})}function mt({active:t,onClick:n,label:i,t:o}){return e.jsx("button",{type:"button",onClick:n,style:{padding:"9px 1px",fontSize:11.5,fontWeight:650,cursor:"pointer",border:"none",background:"none",fontFamily:o.font,whiteSpace:"nowrap",color:t?o.textPrimary:o.textMuted,boxShadow:t?`inset 0 -2px 0 0 ${o.accent}`:"none"},children:i})}function Gn(t,n){return to(t,{variant:n?"accent":"ghost",size:"xs",active:n})}function St(t,n){return{display:"inline-flex",alignItems:"center",gap:5,background:n?"var(--accent-dim)":t.btnBg,border:`1px solid ${n?`${t.accent}55`:t.btnBorder}`,borderRadius:999,color:n?t.accent:t.textSecondary,cursor:"pointer",fontSize:11.5,fontFamily:t.fontMono,lineHeight:1.2,padding:"4px 9px"}}function Ao({metadata:t,onCancel:n,onConfirm:i,t:o}){const[l,a]=c.useState(t.name),[p,y]=c.useState(t.owner),x=!!(l.trim()&&p.trim());return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Save block",style:{position:"absolute",inset:0,zIndex:70,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,.32)",padding:18},children:e.jsxs("div",{style:{width:420,maxWidth:"100%",display:"grid",gap:14,padding:18,borderRadius:10,border:`1px solid ${o.headerBorder}`,background:o.cellBg,boxShadow:"0 24px 70px rgba(0,0,0,.35)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:850,color:o.textPrimary},children:"Save governed block"}),e.jsx("div",{style:{marginTop:4,fontSize:11,lineHeight:1.45,color:o.textMuted},children:"Name and owner are required. DQL will run the local governance checks and certify the block when they pass; otherwise it remains a draft with blockers."})]}),e.jsx(L,{label:"Block name",t:o,children:e.jsx("input",{autoFocus:!0,value:l,onChange:k=>a(k.target.value),style:Se(o)})}),e.jsx(L,{label:"Owner",t:o,children:e.jsx("input",{value:p,onChange:k=>y(k.target.value),placeholder:"analytics@company.com or team name",style:Se(o)})}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:n,style:ne(o),children:"Cancel"}),e.jsx("button",{type:"button",disabled:!x,onClick:()=>x&&i({name:l.trim(),owner:p.trim()}),style:{...je(o),opacity:x?1:.55},children:"Save block"})]})]})})}function _o({saving:t,onSave:n,onDiscard:i,onCancel:o,t:l}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Unsaved block",style:{position:"fixed",inset:0,zIndex:90,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(430px, 100%)",border:`1px solid ${l.cellBorder}`,borderRadius:12,background:l.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.24)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,color:l.textPrimary,fontFamily:l.font},children:"Save this block before starting another?"}),e.jsx("div",{style:{marginTop:5,fontSize:12,lineHeight:1.5,color:l.textMuted,fontFamily:l.font},children:"Your current workspace has unsaved changes."})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:o,disabled:t,style:ne(l),children:"Cancel"}),e.jsx("button",{type:"button",onClick:i,disabled:t,style:{...ne(l),color:l.error},children:"Discard"}),e.jsx("button",{type:"button",onClick:()=>void n(),disabled:t,style:je(l),children:t?"Saving…":"Save block"})]})]})})}function Wo({blockName:t,blockPath:n,deleting:i,error:o,onCancel:l,onConfirm:a,t:p}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Delete block",style:{position:"fixed",inset:0,zIndex:95,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(460px, 100%)",border:`1px solid ${p.error}55`,borderRadius:12,background:p.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.26)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx("span",{style:{width:30,height:30,display:"grid",placeItems:"center",borderRadius:8,background:`${p.error}12`},children:e.jsx($t,{size:16,color:p.error})}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:15,fontWeight:800,color:p.textPrimary,fontFamily:p.font},children:["Delete “",t,"”?"]}),e.jsx("div",{style:{marginTop:3,fontSize:11,color:p.textMuted,fontFamily:p.fontMono},children:n})]})]}),e.jsxs("div",{style:{fontSize:12,lineHeight:1.5,color:p.textSecondary,fontFamily:p.font},children:["This removes the saved ",e.jsx("code",{children:".dql"})," block and its generated semantic companion. Unsaved editor changes are discarded. Git can recover committed versions."]}),o&&e.jsx("div",{role:"alert",style:{padding:"8px 10px",borderRadius:7,border:`1px solid ${p.error}45`,background:`${p.error}0d`,color:p.error,fontSize:11,lineHeight:1.4},children:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:l,disabled:i,style:ne(p),children:"Cancel"}),e.jsx("button",{type:"button",onClick:a,disabled:i,style:{...je(p),background:p.error,borderColor:p.error,opacity:i?.65:1},children:i?e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:13,className:"dql-spin"})," Deleting…"]}):e.jsxs(e.Fragment,{children:[e.jsx($t,{size:13})," Delete block"]})})]})]})})}function Fo({dbtStatus:t,semanticStats:n,semanticObjectCount:i,databaseStats:o,onCreateSql:l,onCreateSemantic:a,onImport:p,onBuildDql:y,t:x}){var P;const k=[{title:"Blank SQL block",detail:"Start with an empty custom query.",action:l,label:"Create",Icon:go},{title:"Semantic block",detail:"Build directly from governed metrics.",action:a,label:"Build",Icon:Rt}],r=!!(t!=null&&t.artifacts.manifest.exists),f=(t==null?void 0:t.counts.metrics)??n.metrics,g=t?`${t.counts.models} dbt models · ${f} MetricFlow metrics`:"Waiting for dbt artifacts",M=(t==null?void 0:t.projectName)||((P=t==null?void 0:t.projectPath)==null?void 0:P.split("/").filter(Boolean).pop())||"dbt project";return e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:22,display:"grid",gap:14,alignContent:"start",background:x.appBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:800,color:x.textPrimary,fontFamily:x.font},children:"Create DQL blocks"}),e.jsx("div",{style:{fontSize:12,color:x.textMuted,lineHeight:1.45,marginTop:5,maxWidth:560,fontFamily:x.font},children:"Start from SQL you already have, or describe the business asset you want DQL to build from project context."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"7px 10px",border:`1px solid ${r?"#2ea04340":x.headerBorder}`,borderRadius:8,background:r?"#2ea0430d":x.cellBg},children:[e.jsx(jt,{size:15,strokeWidth:2,color:r?"#2ea043":x.textMuted,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:11,color:r?"#2ea043":x.textMuted,fontWeight:700,fontFamily:x.font},children:r?"dbt ready":"dbt pending"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))",gap:10},children:[e.jsx(Ht,{title:"Ask AI",detail:"Describe the business asset you need. DQL uses this domain's blocks, models, and semantic metrics to draft it.",label:"Describe block",Icon:Co,onClick:y,t:x}),e.jsx(Ht,{title:"Import SQL",detail:"Paste scripts, upload files, or point at a folder. DQL analyzes candidates without writing block files until you save.",label:"Start import",Icon:ui,onClick:p,t:x}),e.jsx(Ht,{title:"Build manually",detail:"Use the visual semantic builder for multiple metrics, compatible dimensions, time grain, filters, and chart intent.",label:"Open builder",Icon:Rt,onClick:a,t:x})]}),e.jsxs("details",{style:gt(x),children:[e.jsx("summary",{style:xt(x),children:"Manual options"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:10},children:k.map(_=>e.jsx(Oo,{title:_.title,detail:_.detail,label:_.label,Icon:_.Icon,onClick:_.action,t:x},_.title))})]}),e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:8},children:[e.jsx(Qt,{Icon:Vt,label:`${M} dbt`,value:g,tone:r?"success":"neutral",t:x}),e.jsx(Qt,{Icon:Vt,label:"Database",value:`${o.tables} tables`,tone:o.tables>0?"success":"neutral",t:x}),e.jsx(Qt,{Icon:Rt,label:"DQL semantic layer",value:`${i} objects`,tone:i>0?"success":"neutral",t:x})]})]})}function Ht({title:t,detail:n,label:i,Icon:o,onClick:l,t:a}){return e.jsxs("button",{onClick:l,style:{border:`1px solid ${a.accent}`,borderRadius:8,background:a.cellBg,color:a.textPrimary,cursor:"pointer",display:"grid",gridTemplateColumns:"42px minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:16,minHeight:104,textAlign:"left",fontFamily:a.font,boxShadow:`inset 0 0 0 1px ${a.accent}22`},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}18`,color:a.accent},children:e.jsx(o,{size:20,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:850,color:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:12,color:a.textMuted,lineHeight:1.4},children:n})]}),e.jsx("span",{style:{color:"#ffffff",background:a.accent,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:800,whiteSpace:"nowrap"},children:i})]})}function Oo({title:t,detail:n,label:i,Icon:o,onClick:l,t:a}){return e.jsxs("button",{onClick:l,style:{textAlign:"left",background:a.cellBg,border:`1px solid ${a.headerBorder}`,borderRadius:8,padding:12,cursor:"pointer",color:a.textPrimary,display:"grid",gridTemplateColumns:"30px minmax(0, 1fr)",gap:10,minHeight:94,fontFamily:a.font,alignItems:"start"},children:[e.jsx("span",{style:{width:30,height:30,borderRadius:7,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}14`,color:a.accent},children:e.jsx(o,{size:16,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:13,fontWeight:800,color:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:11,color:a.textMuted,lineHeight:1.35},children:n}),e.jsx("span",{style:{color:a.accent,fontSize:11,fontWeight:800},children:i})]})]})}function Qt({Icon:t,label:n,value:i,tone:o,t:l}){const a=o==="success"?"#2ea043":l.textMuted;return e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:8,background:l.cellBg,padding:"9px 10px",display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx("span",{style:{color:a,display:"inline-flex",flexShrink:0},children:e.jsx(t,{size:15,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:10,color:l.textMuted,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),e.jsx("span",{style:{fontSize:12,color:l.textPrimary,fontWeight:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]})]})}function qo({source:t,databaseStats:n,semanticCount:i,onChange:o,onOpenExplorer:l,onOpenAi:a,t:p}){const y=r=>{var f;return((f=t.match(new RegExp(`\\b${r}\\s*=\\s*"([^"]*)"`,"i")))==null?void 0:f[1])??""},x=r=>{var f;return(((f=t.match(new RegExp(`\\b${r}\\s*=\\s*\\[([\\s\\S]*?)\\]`,"i")))==null?void 0:f[1].match(/"([^"]*)"/g))??[]).map(g=>g.slice(1,-1))},k=[{key:"primaryTerms",label:"Business terms",hint:"net revenue, active customer"},{key:"sourceSystems",label:"Source systems",hint:"billing, product events"},{key:"synonyms",label:"Question aliases",hint:"sales, bookings"}];return e.jsxs("div",{style:{padding:"10px 14px",borderBottom:`1px solid ${p.headerBorder}`,background:p.appBg,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:12,fontWeight:750,color:p.textPrimary},children:"Block context"}),e.jsx("span",{style:{fontSize:11,color:p.textMuted},children:"Only grounded context is kept with the block and used for retrieval."}),e.jsx("div",{style:{flex:1}}),e.jsxs("button",{type:"button",onClick:l,style:ne(p),children:[n.tables," database tables"]}),e.jsx("button",{type:"button",onClick:a,style:ne(p),children:"Review with AI"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:10},children:[e.jsx(L,{label:"Business outcome",t:p,children:e.jsx(vt,{value:y("businessOutcome"),onChange:r=>o(ae(t,"businessOutcome",r)),placeholder:"Decision or outcome this block supports",style:Se(p)})}),e.jsx(L,{label:"Agent guidance",t:p,children:e.jsx(vt,{value:y("llmContext"),onChange:r=>o(ae(t,"llmContext",r)),placeholder:"When to use this block",style:Se(p)})}),k.map(r=>e.jsx(No,{label:r.label,hint:r.hint,values:x(r.key),onChange:f=>o(no(t,r.key,f)),t:p},r.key)),e.jsx(L,{label:"Rules and caveats",t:p,children:e.jsx(vt,{value:y("caveats"),onChange:r=>o(ae(t,"caveats",r)),placeholder:"Known limitation or interpretation rule",style:Se(p)})})]}),e.jsxs("div",{style:{fontSize:10,color:p.textMuted},children:["Available authoring context: ",i," semantic objects, ",n.schemas," schemas, ",n.columns," columns. SQL completion uses the same loaded catalog."]})]})}function No({label:t,hint:n,values:i,onChange:o,t:l}){const[a,p]=c.useState(""),y=()=>{const x=a.split(",").map(k=>k.trim()).filter(Boolean);x.length>0&&o([...i,...x]),p("")};return e.jsx(L,{label:t,t:l,children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:5,padding:6,minHeight:36,border:`1px solid ${l.cellBorder}`,borderRadius:6,background:l.cellBg},children:[i.map(x=>e.jsxs("button",{type:"button",onClick:()=>o(i.filter(k=>k!==x)),title:"Remove",style:{...St(l,!0),border:"none",cursor:"pointer"},children:[x," ×"]},x)),e.jsx("input",{value:a,onChange:x=>p(x.target.value),onKeyDown:x=>{(x.key==="Enter"||x.key===",")&&(x.preventDefault(),y())},onBlur:y,placeholder:i.length?"Add another…":n,style:{minWidth:120,flex:1,border:"none",outline:"none",background:"transparent",color:l.textPrimary,fontSize:11,fontFamily:l.font}})]})})}function fi({source:t,kind:n,onChange:i,t:o}){const l=c.useMemo(()=>lo(t),[t]),[a,p]=c.useState(""),[y,x]=c.useState(""),[k,r]=c.useState(!0),[f,g]=c.useState("dynamic"),[M,P]=c.useState("auto"),_=Nt(y,a),se=M==="auto"?_:M,$=Se(o),j=()=>{a.trim()&&(i(Qn(t,{name:a,type:se,required:k&&!y.trim(),defaultText:y,policy:f})),p(""),x(""),r(!0),g("dynamic"),P("auto"))};return e.jsx(fe,{title:"Runtime parameters",t:o,children:e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{fontSize:11,color:o.textMuted,lineHeight:1.45},children:["Add a values-only input once, then reuse this block for a different period, region, customer set, or limit.",n==="custom"?e.jsxs(e.Fragment,{children:[" Use ",e.jsx("code",{children:"${parameter_name}"})," in SQL where the value belongs; DQL always binds it safely."]}):" Choose a semantic field above as a filter to create its governed parameter binding."]}),l.length>0&&e.jsx("div",{style:{display:"grid",gap:7},children:l.map(v=>{var J;const ie=ao(v),V=E=>i(Qn(t,{name:v.name,type:E.type??v.type,required:E.required??v.required,defaultText:E.defaultText??ie,policy:E.policy??v.policy}));return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 1fr) 122px minmax(150px, 1fr) 118px auto",gap:7,alignItems:"center",padding:8,border:`1px solid ${o.cellBorder}`,borderRadius:7,background:o.cellBg},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:o.textPrimary},children:v.name}),e.jsxs("div",{style:{fontSize:10,color:o.textMuted},children:[((J=v.binding)==null?void 0:J.kind)??"declared value"," · ",v.required?"required":"has default"]})]}),e.jsx("select",{"aria-label":`${v.name} type`,value:v.type,onChange:E=>V({type:E.target.value}),style:$,children:Vn.map(E=>e.jsx("option",{value:E,children:E},E))}),v.type==="boolean"?e.jsxs("select",{"aria-label":`${v.name} default`,value:ie,onChange:E=>V({defaultText:E.target.value,required:!1}),style:$,children:[e.jsx("option",{value:"",children:"Required / no default"}),e.jsx("option",{value:"true",children:"True"}),e.jsx("option",{value:"false",children:"False"})]}):e.jsx("input",{"aria-label":`${v.name} default`,value:ie,onChange:E=>{const Z=E.target.value,H=v.type===Nt(ie,v.name);V({defaultText:Z,required:Z.trim()?!1:v.required,...H?{type:Nt(Z,v.name)}:{}})},placeholder:v.type.endsWith("[]")?"West, East":v.required?"Required value":"Default value",style:$}),e.jsx("select",{"aria-label":`${v.name} policy`,value:v.policy,onChange:E=>V({policy:E.target.value}),style:$,children:Ho.map(E=>e.jsx("option",{value:E,children:E},E))}),e.jsx("button",{type:"button",onClick:()=>i(co(t,v.name)),title:`Remove ${v.name}`,style:{border:"none",background:"transparent",color:o.error,cursor:"pointer",fontSize:16,padding:"3px 5px"},children:"×"})]},v.name)})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(140px, 1fr) minmax(150px, 1.3fr) 150px 130px auto",gap:7,alignItems:"center",padding:9,border:`1px dashed ${o.btnBorder}`,borderRadius:7,background:o.appBg},children:[e.jsx("input",{"aria-label":"New parameter name",value:a,onChange:v=>p(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"region_set",style:$}),e.jsx("input",{"aria-label":"New parameter default",value:y,onChange:v=>{x(v.target.value),v.target.value.trim()&&r(!1)},onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"Central, East or 2026-01-01",style:$}),e.jsxs("select",{"aria-label":"New parameter type",value:M,onChange:v=>P(v.target.value),style:$,children:[e.jsxs("option",{value:"auto",children:["Auto · ",_]}),Vn.map(v=>e.jsx("option",{value:v,children:v},v))]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:o.textSecondary,fontSize:11,whiteSpace:"nowrap"},children:[e.jsx("input",{type:"checkbox",checked:k&&!y.trim(),onChange:v=>r(v.target.checked)})," Required"]}),e.jsx("button",{type:"button",onClick:j,disabled:!a.trim(),style:{...je(o),opacity:a.trim()?1:.5},children:"Add"})]}),e.jsxs("div",{style:{fontSize:10,color:o.textMuted},children:["Type is inferred from a value you enter: ",e.jsx("code",{children:"10"})," → number, ",e.jsx("code",{children:"2026-01-01"})," → date, ",e.jsx("code",{children:"West, East"})," → string[]. You can override it at any time."]})]})})}const Vn=["string","number","boolean","date","string[]","number[]","date[]"],Ho=["dynamic","static","business","derived","optional","ambiguous_review_required"];function Qo({metadata:t,source:n,parameters:i,preview:o,lineageDetail:l,isSemanticBlock:a,running:p,onOpenBuilder:y,onOpenSource:x,onDelete:k,onRun:r,onOpenHistory:f,t:g}){var Y,de,ee,N,re;const M=((t==null?void 0:t.reviewStatus)??"").toLowerCase()==="certified",P=(t==null?void 0:t.name)||"block",_=a?ii(n):null,se=((de=(Y=n.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:Y[1])==null?void 0:de.trim())??"",$=_?Array.from(new Set([..._.dimensions,..._.timeDimension?[_.timeDimension]:[],..._.metrics])):xi(se),j=(n.match(/^\s*assert\b.*$/gm)??[]).map(D=>D.trim()),v=((ee=l==null?void 0:l.incoming)==null?void 0:ee.length)??0,ie=((N=l==null?void 0:l.outgoing)==null?void 0:N.length)??0,[V,J]=c.useState(!1),E=((l==null?void 0:l.incoming)??[]).map(D=>{var X;return(X=D.node)==null?void 0:X.name}).filter(Boolean).slice(0,3),Z=((l==null?void 0:l.outgoing)??[]).map(D=>{var X;return(X=D.node)==null?void 0:X.name}).filter(Boolean).slice(0,3),H={fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted,marginBottom:8,fontFamily:g.font},I=(D,X=!1)=>e.jsx("span",{style:{padding:"3px 9px",borderRadius:999,border:`1px solid ${X?`${g.accent}59`:g.headerBorder}`,background:X?"var(--accent-dim)":"var(--bg-1)",color:X?g.accent:g.textSecondary,fontFamily:g.fontMono,fontWeight:X?600:400,fontSize:11.5},children:D},D),U=e.jsx("span",{style:{color:g.textMuted,fontSize:11},children:"→"}),O=[["Last run",o!=null&&o.result.executionTime?`${(o.result.executionTime/1e3).toFixed(1)}s`:"Not run yet"],["Rows",o?String(o.result.rowCount??o.result.rows.length):"—"],["Used in",ie>0?`${ie} downstream`:"—"],["Tests",j.length>0?`${j.length} declared`:"None yet"]];return e.jsx("div",{style:{height:"100%",overflow:"auto",background:g.appBg},children:e.jsxs("div",{style:{width:"min(860px, 100% - 48px)",margin:"0 auto",padding:"26px 0 40px",display:"flex",flexDirection:"column",gap:20,animation:"dql-agent-fadein 0.25s ease-out",fontFamily:g.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:14},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:10,background:M?"var(--status-success-bg)":"var(--accent-dim)",color:M?"var(--status-success)":g.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:e.jsx(Rt,{size:20,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:17,fontWeight:700,color:g.textPrimary,fontFamily:g.fontMono,letterSpacing:"-0.01em"},children:P}),t!=null&&t.reviewStatus?e.jsx(ci,{status:t.reviewStatus,t:g}):null]}),e.jsx("div",{style:{fontSize:12,color:g.textMuted,marginTop:4},children:[t==null?void 0:t.domain,t!=null&&t.folderPath?`folder: ${t.folderPath}`:null,t==null?void 0:t.owner,...(re=t==null?void 0:t.tags)!=null&&re.length?[t.tags.join(", ")]:[]].filter(Boolean).join(" · ")||"Unsaved draft"})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:y,style:{display:"inline-flex",alignItems:"center",gap:7,height:32,padding:"0 14px",borderRadius:8,border:"none",background:g.accent,color:"#fff",fontSize:12.5,fontWeight:650,cursor:"pointer",fontFamily:g.font,boxShadow:"0 1px 4px rgba(107,93,211,0.25)"},children:[e.jsx(Bo,{size:13,strokeWidth:1.75})," Open in builder"]}),e.jsxs("button",{type:"button",onClick:r,disabled:p,style:{display:"inline-flex",alignItems:"center",gap:6,height:32,padding:"0 13px",borderRadius:8,border:`1px solid ${g.headerBorder}`,background:g.cellBg,color:g.textSecondary,fontSize:12.5,fontWeight:600,cursor:"pointer",fontFamily:g.font,opacity:p?.7:1},children:[p?e.jsx(rt,{size:12,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(pi,{size:11,fill:"currentColor"})," Run"]}),e.jsx("button",{type:"button","aria-label":`Delete ${P}`,title:"Delete block",onClick:k,style:{width:32,height:32,borderRadius:8,border:`1px solid ${g.error}55`,background:`${g.error}0d`,color:g.error,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx($t,{size:14})}),e.jsx("button",{type:"button",title:"History and metadata",onClick:f,style:{width:32,height:32,borderRadius:8,border:`1px solid ${g.headerBorder}`,background:g.cellBg,color:g.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(bo,{size:15})})]})]}),t!=null&&t.description?e.jsx("div",{style:{fontSize:13.5,lineHeight:1.6,color:g.textSecondary,maxWidth:640},children:t.description}):null,e.jsx("div",{style:{display:"flex",border:"1px solid var(--border-subtle)",borderRadius:10,background:g.cellBg,overflow:"hidden"},children:O.map(([D,X],le)=>e.jsxs("div",{style:{flex:1,padding:"12px 16px",borderRight:le<O.length-1?"1px solid var(--border-subtle)":"none"},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted},children:D}),e.jsx("div",{style:{fontSize:14,fontWeight:650,color:g.textPrimary,marginTop:3},children:X})]},D))}),e.jsxs("div",{children:[e.jsx("div",{style:H,children:"Outputs"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:$.length>0?$.map(D=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 10px",borderRadius:999,background:"var(--accent-dim)",color:g.accent,border:`1px solid ${g.accent}33`,fontFamily:g.fontMono},children:D},D)):e.jsx("span",{style:{fontSize:11.5,color:g.textMuted},children:"Open the builder to define outputs."})})]}),e.jsxs("div",{children:[e.jsx("div",{style:H,children:"Parameters"}),e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,overflow:"hidden",background:g.cellBg},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"7px 12px",background:"var(--bg-1)",borderBottom:"1px solid var(--border-subtle)",fontSize:10.5,fontWeight:700,color:g.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"}),e.jsx("span",{children:"Default"}),e.jsx("span",{children:"Policy"})]}),i.length===0?e.jsx("div",{style:{padding:"9px 12px",fontSize:12,color:g.textMuted},children:"No parameters — this block always runs the same way."}):i.map((D,X)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"8px 12px",borderBottom:X<i.length-1?"1px solid var(--border-subtle)":"none",fontSize:12,alignItems:"center"},children:[e.jsx("span",{style:{fontFamily:g.fontMono,fontWeight:600,color:g.textPrimary},children:D.name}),e.jsx("span",{style:{color:g.textSecondary},children:D.type}),e.jsx("span",{style:{fontFamily:g.fontMono,color:D.default!==void 0&&D.default!==null&&D.default!==""?"var(--status-warning)":g.textMuted},children:D.default!==void 0&&D.default!==null&&D.default!==""?JSON.stringify(D.default):D.required?"required":"—"}),e.jsx("span",{style:{color:g.textMuted},children:D.policy})]},D.name))]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{style:{...H,marginBottom:0},children:"DQL source"}),e.jsxs("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"none",color:g.accent,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:g.font,padding:0},children:["Open in DQL Source ",e.jsx(Gt,{size:11,strokeWidth:2})]})]}),e.jsx("pre",{style:{margin:0,border:"1px solid var(--border-subtle)",background:g.cellBg,borderRadius:9,padding:"13px 15px",fontSize:11.5,lineHeight:1.65,fontFamily:g.fontMono,whiteSpace:"pre",overflowX:"auto",color:g.textPrimary,maxHeight:320,overflowY:"auto"},children:n.trim()||"Open the builder to author this block."})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},children:[e.jsxs("div",{children:[e.jsx("div",{style:H,children:"Tests"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:j.length>0?j.map(D=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[e.jsx(jt,{size:13,color:"var(--status-success)",strokeWidth:2,style:{flexShrink:0}}),e.jsx("span",{style:{fontFamily:g.fontMono,color:g.textSecondary},children:D})]},D)):e.jsx("span",{style:{fontSize:11.5,color:g.textMuted},children:"No tests yet — add assertions in the builder before certification."})})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>J(D=>!D),style:{display:"flex",alignItems:"center",gap:6,border:"none",background:"none",cursor:"pointer",padding:0,fontFamily:g.font,marginBottom:8},children:[e.jsx(Gt,{size:11,color:g.textMuted,strokeWidth:2,style:{transform:V?"rotate(90deg)":"none",transition:"transform 0.12s"}}),e.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted},children:"Lineage"}),V?null:e.jsxs("span",{style:{fontSize:10.5,color:g.textMuted},children:[v," upstream · ",ie," downstream"]})]}),V?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:11.5,animation:"dql-agent-fadein 0.18s ease-out"},children:[E.length>0?E.map(D=>I(D)):I("no upstream"),U,I(P,!0),U,Z.length>0?Z.map(D=>I(D)):I("no downstream yet")]}):null]})]})]})})}function Uo({source:t,metadata:n,semanticLayer:i,dbtStatus:o,domainOptions:l,chartConfig:a,onChange:p,onMetadataChange:y,onOpenAi:x,onSetupRuntime:k,t:r}){const f=ii(t),g={...f,filters:f.requestedFilters},[M,P]=c.useState([]),[_,se]=c.useState(!1),[$,j]=c.useState(null),[v,ie]=c.useState(null),[V,J]=c.useState(0);c.useEffect(()=>{let d=!1;if(g.metrics.length===0){P([]),j(null),ie(null),se(!1);return}return P([]),j(null),se(!0),ie(null),F.getCompatibility(g.metrics).then(R=>{d||(j(R),P(R.dimensions))}).catch(R=>{d||(P([]),ie(R instanceof Error?R.message:String(R)))}).finally(()=>{d||se(!1)}),()=>{d=!0}},[i.dimensions,g.metrics.join("|"),V]);const E=new Set(M.flatMap(d=>[d.reference??d.name,d.name])),Z=new Map(M.flatMap(d=>[[d.reference??d.name,d.qualifiedName??void 0],[d.name,d.qualifiedName??void 0]])),H=new Map((($==null?void 0:$.incompatible)??[]).map(d=>[d.name,Ro(d.reason)])),I=new Map(M.flatMap(d=>[[d.reference??d.name,d],[d.name,d]])),U=Array.from(new Map([...i.dimensions,...i.timeDimensions].map(d=>{const R=d.reference??d.name;return[R,{...d,name:R}]})).values()),O=new Map(U.flatMap(d=>[[d.name,d],[d.reference??d.name,d]])),Y=M.map(d=>{const R=d.reference??d.name;return{...O.get(R)??O.get(d.name),...d,name:R}}),de=Y.filter(d=>d.isTimeDimension||d.type==="time"),ee=en(r),[N,re]=c.useState(""),[D,X]=c.useState(""),le=c.useMemo(()=>new Map(i.metrics.map(d=>[d.name,d])),[i.metrics]),we=c.useMemo(()=>new Map([...U,...Y].flatMap(d=>[[d.name,d],[d.reference??d.name,d]])),[U,Y]),ke=c.useMemo(()=>Yn(i.metrics,N),[i.metrics,N]),ce=c.useMemo(()=>Yn(Y,D),[Y,D]),Te=si(t,"tests"),he=Array.from(new Set([...g.dimensions,...g.timeDimension?[g.timeDimension]:[],...g.metrics])),Pe=(d,R)=>{y({[d]:R}),p(d==="name"?yt(t,R):ae(t,d,R))},Re=d=>{const R=g.metrics.includes(d)?g.metrics.filter(K=>K!==d):[...g.metrics,d];p(ti(t,R))},ue=d=>p(ni(t,"dimensions",d)),We=d=>{const R=g.dimensions.includes(d)?g.dimensions.filter(K=>K!==d):[...g.dimensions,d];ue(R)};return c.useEffect(()=>{if(!$||g.metrics.length===0)return;const d=io(t,Array.from(E));d!==t&&p(d)},[$,t]),e.jsx("div",{style:{height:"100%",overflow:"auto",background:r.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"24px 0 40px",display:"flex",flexDirection:"column",animation:"dql-agent-fadein 0.25s ease-out"},children:[e.jsx(hi,{metadata:n,domains:l,onTextChange:Pe,onFolderChange:d=>y({folderPath:d}),onTagsChange:d=>{y({tags:d}),p(bt(t,d))},t:r}),e.jsxs(fe,{title:"Metric and grain",hint:"Pick governed semantic objects — they compile to the DQL script.",t:r,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsxs("span",{style:{fontSize:11,fontWeight:750,color:r.textSecondary},children:["Governed metrics · ",g.metrics.length," selected"]}),_&&e.jsx("span",{style:{fontSize:10,color:r.textMuted},children:"Checking compatibility…"})]}),e.jsx(Xn,{kind:"metric",total:i.metrics.length,search:N,onSearchChange:re,matches:ke,pool:i.metrics,selected:g.metrics,resolveLabel:d=>{var R;return((R=le.get(d))==null?void 0:R.label)||d},onToggle:Re,compatible:d=>{var R,K,ge,be;return((K=(R=le.get(d))==null?void 0:R.execution)==null?void 0:K.status)!=="requires_setup"&&((be=(ge=le.get(d))==null?void 0:ge.execution)==null?void 0:be.status)!=="unsupported"},t:r}),i.metrics.some(d=>d.execution&&d.execution.status!=="ready")&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",fontSize:10.5,color:r.textMuted,lineHeight:1.4},children:[e.jsx("span",{style:{flex:1},children:"Complex metrics are imported but need a full semantic runtime to execute."}),e.jsx("button",{type:"button",onClick:k,style:{border:"none",background:"transparent",color:r.accent,fontSize:10.5,fontWeight:700,cursor:"pointer",whiteSpace:"nowrap"},children:"Set up runtime →"})]}),(($==null?void 0:$.engine)||($==null?void 0:$.degraded))&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,color:r.textMuted,marginTop:2},children:[e.jsxs("span",{style:{padding:"1px 7px",borderRadius:999,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:700},children:["Runs via ",Po[$.engine]??$.engine]}),$.degraded&&e.jsx("span",{style:{color:"var(--status-warning)"},children:$.degraded})]}),v&&e.jsxs("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"var(--status-warning)",lineHeight:1.4,marginTop:4},children:[e.jsx(Et,{size:14,style:{flexShrink:0}}),e.jsxs("span",{style:{flex:1},children:["Could not verify governed dimensions: ",v,". Dimension selection is paused so an unapproved join cannot be saved."]}),e.jsx("button",{type:"button",onClick:()=>J(d=>d+1),style:ne(r),children:"Retry"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 150px",gap:8},children:[e.jsx(L,{label:"Time dimension",t:r,children:e.jsxs("select",{disabled:g.metrics.length===0||_||!!v,value:g.timeDimension,onChange:d=>p(Hn(t,"time_dimension",d.target.value)),style:{...ee,opacity:g.metrics.length===0||_||v?.6:1},children:[e.jsx("option",{value:"",children:"None"}),de.map(d=>e.jsxs("option",{value:d.reference??d.name,children:[d.label||d.name," · ",d.name]},d.reference??d.name))]})}),e.jsx(L,{label:"Grain",t:r,children:e.jsxs("select",{value:g.granularity,onChange:d=>p(Hn(t,"granularity",d.target.value)),style:ee,children:[e.jsx("option",{value:"",children:"None"}),Lo(g.timeDimension,I,i.timeDimensions).map(d=>e.jsx("option",{value:d,children:d},d))]})})]}),i.metrics.length===0&&(i.loading?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:r.textMuted,lineHeight:1.45},children:[e.jsx(rt,{size:14,className:"dql-spin"}),"Loading ",((o==null?void 0:o.counts.metrics)??0).toLocaleString()," semantic metrics from parsed dbt artifacts… Large catalogs continue loading in the background."]}):((o==null?void 0:o.counts.metrics)??0)>0||o!=null&&o.artifacts.semanticManifest.exists?e.jsxs("div",{role:"alert",style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:["dbt artifacts contain ",((o==null?void 0:o.counts.metrics)??0).toLocaleString()," metrics, but Block Studio could not load them. Refresh the semantic layer; another dbt parse is not required."]}):e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:"No semantic metrics were discovered. Run dbt parse or import a semantic layer, then refresh Block Studio."})),g.metrics.length>1&&$&&M.length===0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#d29922",fontSize:11,lineHeight:1.4},children:[e.jsx(Et,{size:14})," These metrics do not expose a common dimension or join path.",e.jsx("button",{type:"button",onClick:x,style:ne(r),children:"Resolve with AI"})]})]}),e.jsxs(fe,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:r,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx(L,{label:"Type",t:r,children:e.jsxs("select",{value:a.chart??"table",onChange:d=>p(ze(t,{...a,chart:d.target.value})),style:ee,children:[e.jsx("option",{value:"table",children:"Table"}),di.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]})}),e.jsx(L,{label:"X axis",t:r,children:e.jsxs("select",{value:a.x??"",onChange:d=>p(ze(t,{...a,x:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"Auto"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})}),e.jsx(L,{label:"Y axis",t:r,children:e.jsxs("select",{value:a.y??"",onChange:d=>p(ze(t,{...a,y:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"Auto"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})}),e.jsx(L,{label:"Series / color",t:r,children:e.jsxs("select",{value:a.color??"",onChange:d=>p(ze(t,{...a,color:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"None"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})})]}),e.jsx(L,{label:"Title",t:r,children:e.jsx("input",{value:a.title??"",onChange:d=>p(ze(t,{...a,title:d.target.value})),placeholder:"Chart title",style:ee})})]}),e.jsx(fe,{title:"Dimensions",hint:"Governed group-bys checked against the metric's join path.",t:r,children:g.metrics.length===0?e.jsx("div",{style:{fontSize:12,color:r.textMuted},children:"Choose one or more governed metrics first. Only their connected, approved dimensions will appear."}):_?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:r.textMuted},children:[e.jsx(rt,{size:14,className:"dql-spin"}),"Checking common governed dimensions…"]}):v?e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)"},children:"Dimension selection is unavailable until compatibility succeeds."}):Y.length===0?e.jsx("div",{style:{fontSize:12,color:r.textMuted},children:"No dimensions are loaded yet."}):e.jsx(Xn,{kind:"dimension",total:Y.length,search:D,onSearchChange:X,matches:ce,pool:Y,selected:g.dimensions,resolveLabel:d=>{var R;return((R=we.get(d))==null?void 0:R.label)||d},resolveMachineName:d=>{var R;return Z.get(d)??((R=we.get(d))==null?void 0:R.name)??d},reasonFor:d=>H.get(d),onToggle:We,compatible:d=>E.has(d),disabled:g.metrics.length===0||_||!!v,emptyHint:_?"Checking common governed dimensions…":v?"Retry compatibility before selecting dimensions.":"Choose a metric first; dimensions are checked against its governed join path.",t:r})}),e.jsxs(fe,{title:"Filters and parameters",hint:"Values-only inputs so this block is reusable across periods and regions.",t:r,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:7},children:Array.from(new Set([...g.dimensions,...g.timeDimension?[g.timeDimension]:[]])).map(d=>{var K;const R=g.filters.includes(d);return e.jsx("button",{type:"button",onClick:()=>p(oo(t,R?g.filters.filter(ge=>ge!==d):[...g.filters,d])),style:St(r,R),children:((K=we.get(d))==null?void 0:K.label)||d},d)})}),e.jsx("div",{style:{fontSize:10,color:r.textMuted,marginTop:8},children:g.dimensions.length===0&&!g.timeDimension?"Search and add a compatible dimension first, then choose whether it should also be a dynamic filter.":"Selected fields become governed runtime filters. Values stay dynamic rather than being hard-coded into SQL."}),g.filters.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:8},children:g.filters.map(d=>e.jsxs("span",{style:St(r,!0),children:[_e(d)," · dynamic"]},d))})]}),e.jsx(fi,{source:t,kind:"semantic",onChange:p,t:r}),e.jsx(fe,{title:`Output fields${he.length?` · ${he.length}`:""}`,hint:"What consumers see when this block answers a question.",t:r,children:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:he.length>0?he.map(d=>e.jsx("span",{style:St(r,!0),children:_e(d)},d)):e.jsx("span",{style:{fontSize:11,color:r.textMuted},children:"Select metrics and dimensions to define outputs."})})}),e.jsx(fe,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:r,children:e.jsx(vt,{multiline:!0,value:Te,onChange:d=>p(ri(t,"tests",d)),placeholder:`assert row_count >= 1
|
|
21
|
-
assert total_revenue >= 0`,style:{...ee,minHeight:64,resize:"vertical",fontFamily:r.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:r.textSecondary,fontFamily:r.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:r.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:r.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function
|
|
19
|
+
`}),e.jsxs("div",{style:{height:46,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,background:i.cellBg,overflowX:"auto"},children:[w&&e.jsx("button",{onClick:()=>C(!1),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:14,fontFamily:i.font,padding:0,lineHeight:1},title:"Open explorer",children:"›"}),e.jsxs("button",{type:"button",onClick:fn,title:"Back to Block Studio",className:"dql-hover",style:{display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",padding:"2px 4px",margin:"0 -4px",borderRadius:6,color:i.textMuted,fontSize:12,fontFamily:i.font,whiteSpace:"nowrap",cursor:"pointer"},children:[e.jsx(Po,{size:12,strokeWidth:2})," Blocks"]}),e.jsx(Gt,{size:11,color:i.textMuted,style:{flexShrink:0}}),e.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:i.textPrimary,fontFamily:i.fontMono,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},children:me||((Tn=t.blockStudioMetadata)==null?void 0:Tn.name)||(Ae?"new_block":Oe?"semantic":"sql")}),((Mn=t.blockStudioMetadata)==null?void 0:Mn.reviewStatus)&&e.jsx(hi,{status:t.blockStudioMetadata.reviewStatus,t:i}),Ae&&z==="manual"&&xe!=="detail"&&e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${i.headerBorder}`,borderRadius:7,background:i.appBg,marginLeft:6,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>G("visual"),style:Jn(i,xe==="visual"),children:"Visual Builder"}),e.jsx("button",{type:"button",onClick:()=>G("source"),style:Jn(i,xe==="source"),children:"DQL Source"})]}),Ae&&e.jsx(Fe,{label:`Context${oi(t.blockStudioDraft)?` (${oi(t.blockStudioDraft)})`:""}`,Icon:Vt,onClick:()=>$i(o=>!o)}),e.jsx("div",{style:{flex:1}}),t.activeBlockPath&&e.jsx(Fe,{label:"Delete",Icon:$t,variant:"danger",title:"Delete this saved block",onClick:()=>{var o;return Ft(t.activeBlockPath,((o=t.blockStudioMetadata)==null?void 0:o.name)||me||t.activeBlockPath)}}),e.jsx(Fe,{label:"New block",Icon:to,onClick:hn}),Ae&&e.jsxs(e.Fragment,{children:[e.jsx(Fe,{label:"Ask AI",Icon:Yt,onClick:()=>dt({kind:"ask"})}),t.activeBlockPath&&e.jsx(Fe,{label:"Modify with AI",Icon:Yt,onClick:()=>dt({kind:"edit",initialInput:`Modify this block${me?` (${me})`:""}: `})}),e.jsx(Fe,{label:"Run",Icon:gi,onClick:()=>void zt(),busy:J}),e.jsx(Fe,{label:N?"Saving":"Save draft",Icon:jt,variant:"secondary",busy:N,onClick:()=>void Ot(),title:"Save changes as a review-required draft"}),e.jsx(Fe,{label:((In=t.blockStudioMetadata)==null?void 0:In.reviewStatus)==="certified"?"Re-certify":"Certify",Icon:no,variant:"primary",busy:N,onClick:()=>void xn(),title:"Run validation, query, tests, chart, and lineage gates before certification"})]}),X&&e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",fontFamily:i.font,padding:"4px 8px",background:"var(--status-error-bg)",borderRadius:6},children:X})]}),Ae&&Li&&e.jsx(Uo,{source:t.blockStudioDraft,databaseStats:It,semanticCount:pn,onChange:Pe,onOpenExplorer:()=>{C(!1),x("database")},onOpenAi:()=>dt({kind:"edit",initialInput:"Review and improve this block context. Keep only grounded business references, sources, constraints, and caveats: "}),t:i}),e.jsx("div",{style:{flex:1,overflow:"hidden"},children:z==="import"?e.jsx(rs,{session:ze,sessions:Ti,sessionsLoading:Mi,onClose:()=>_(Ae?"manual":"start"),onSessionChange:Tt,onRefreshSessions:Mt,onSelectCandidate:Wi,onSavedCandidate:Oi,defaultDomain:((Dn=t.blockStudioMetadata)==null?void 0:Dn.domain)??f,defaultOwner:((zn=t.blockStudioMetadata)==null?void 0:zn.owner)??"",themeMode:t.themeMode,t:i,inline:!0}):Ae?xe==="detail"?e.jsx(Vo,{metadata:t.blockStudioMetadata,source:t.blockStudioDraft,parameters:((Pn=t.blockStudioValidation)==null?void 0:Pn.parameters)??[],preview:t.blockStudioPreview,lineageDetail:Ue,isSemanticBlock:Oe,running:J,onOpenBuilder:()=>G("visual"),onOpenSource:()=>G("source"),onDelete:()=>{var o;return t.activeBlockPath&&Ft(t.activeBlockPath,((o=t.blockStudioMetadata)==null?void 0:o.name)||me||t.activeBlockPath)},onRun:()=>void zt(),onOpenHistory:()=>{r("history"),re(!1),!Ne&&t.activeBlockPath&&O.getBlockHistory(t.activeBlockPath).then(o=>{Ee(o.entries),He(!0)})},t:i}):xe==="visual"?e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsx(Xo,{mode:Oe?"semantic":"custom",onModeChange:Ei,t:i}),e.jsx("div",{style:{flex:1,minHeight:0},children:Oe?e.jsx(Yo,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,semanticLayer:t.semanticLayer,dbtStatus:t.blockStudioDbtStatus,domainOptions:t.semanticLayer.domains,chartConfig:yn,onChange:Pe,onMetadataChange:o=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),onOpenAi:()=>dt({kind:"edit",initialInput:"Help resolve the selected semantic metrics and dimensions for this block: "}),onSetupRuntime:()=>{n({type:"SET_SETTINGS_TAB",tab:"project"}),n({type:"SET_MAIN_VIEW",view:"settings"})},t:i},`sem-${t.activeBlockPath??s}`):e.jsx(Jo,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,domainOptions:t.semanticLayer.domains,chartConfig:yn,onChange:Pe,onMetadataChange:o=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),onConvertToDql:()=>G("source"),t:i},`sql-${t.activeBlockPath??s}`)})]}):e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(at||rn)&&e.jsx(Zo,{semanticChoice:at,databaseWarning:rn,onDismiss:()=>{At(null),_t(null)},onInsertAdvanced:()=>{if(!at)return;const o=io(at.kind==="metric"?"metric":"dimension",at.name);Pe(oo(t.blockStudioDraft,o)),At(null)},onCreateSemantic:()=>n({type:"OPEN_NEW_BLOCK_MODAL",blockType:"semantic"}),t:i}),e.jsxs("div",{style:{height:34,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 14px",borderBottom:"1px solid var(--border-subtle)",background:i.appBg},children:[e.jsx("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.activeBlockPath??vi(t.blockStudioMetadata)}),e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)",flexShrink:0},title:"Unsaved changes"}),e.jsx("div",{style:{flex:1}}),(((Rn=t.blockStudioValidation)==null?void 0:Rn.diagnostics.filter(o=>o.severity==="error").length)??0)===0?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-success)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(jt,{size:12})," Valid"]}):e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-warning)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(Et,{size:12})," ",t.blockStudioValidation.diagnostics.filter(o=>o.severity==="error").length," problem",t.blockStudioValidation.diagnostics.filter(o=>o.severity==="error").length===1?"":"s"]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[e.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",background:i.cellBg,borderRight:"1px solid var(--border-subtle)"},children:e.jsx(mo,{value:t.blockStudioDraft,onChange:Pe,onRun:()=>void zt(),themeMode:t.themeMode,autoFocus:!0,wrap:!1,fillHeight:!0,schema:V,dqlMode:!0,errorMessage:($n=(Ln=t.blockStudioValidation)==null?void 0:Ln.diagnostics.find(o=>o.severity==="error"))==null?void 0:$n.message})}),!h&&e.jsx(Oo,{source:t.blockStudioDraft,diagnostics:((En=t.blockStudioValidation)==null?void 0:En.diagnostics)??[],parameterCount:((_n=(An=t.blockStudioValidation)==null?void 0:An.parameters)==null?void 0:_n.length)??0,t:i})]})]}):e.jsx(Ho,{dbtStatus:t.blockStudioDbtStatus,semanticStats:un,semanticObjectCount:pn,databaseStats:It,onCreateSql:()=>mn("custom"),onCreateSemantic:()=>mn("semantic"),onImport:()=>_("import"),onBuildDql:()=>dt({kind:"build",initialInput:"Draft a reusable DQL block that "}),t:i})})]}),e.jsx("div",{onMouseDown:Je?Qi:void 0,style:{gridColumn:Yi,gridRow:Xi,display:Je?"block":"none",cursor:"row-resize",background:i.headerBorder}}),e.jsxs("div",{style:{gridColumn:Ji,gridRow:Zi,borderTop:Je?`1px solid ${i.headerBorder}`:"none",display:Je?"flex":"none",flexDirection:"column",overflow:"hidden",background:i.cellBg},children:[e.jsxs("div",{style:{display:"flex",gap:14,alignItems:"center",padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,flexWrap:"wrap"},children:[e.jsx(mt,{active:k==="results",onClick:()=>r("results"),label:"Results",t:i}),e.jsx(mt,{active:k==="parameters",onClick:()=>r("parameters"),label:`Run inputs${(((On=(Wn=t.blockStudioValidation)==null?void 0:Wn.parameters)==null?void 0:On.length)??0)>0?` · ${t.blockStudioValidation.parameters.length}`:""}`,t:i}),e.jsx(mt,{active:k==="lineage",onClick:()=>r("lineage"),label:"Lineage",t:i}),e.jsx(mt,{active:k==="history",onClick:()=>{r("history"),!Ne&&t.activeBlockPath&&O.getBlockHistory(t.activeBlockPath).then(o=>{Ee(o.entries),He(!0)})},label:"History",t:i}),e.jsx(mt,{active:k==="save",onClick:()=>r("save"),label:"Metadata",t:i}),e.jsx("div",{style:{flex:1}}),t.blockStudioPreview?e.jsxs("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.font,whiteSpace:"nowrap"},children:[t.blockStudioPreview.result.executionTime?`Ran in ${(t.blockStudioPreview.result.executionTime/1e3).toFixed(1)}s · `:"",t.blockStudioPreview.result.rowCount??t.blockStudioPreview.result.rows.length," rows"]}):null,e.jsx("button",{onClick:()=>re(!0),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:11,fontFamily:i.font,padding:"4px 6px"},title:"Hide pane",children:"▾ Hide"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[k==="results"&&(J?e.jsx(hs,{elapsedMs:F}):t.blockStudioPreview?e.jsxs("div",{style:{display:"grid",gap:12,padding:12},children:[(qn=(Fn=t.blockStudioPreview.invocation)==null?void 0:Fn.resolvedParameters)!=null&&qn.length?e.jsx(fs,{values:t.blockStudioPreview.invocation.resolvedParameters,t:i}):null,e.jsx("div",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono},children:t.blockStudioPreview.sql}),Ni==="table"?e.jsx(pi,{result:t.blockStudioPreview.result,themeMode:t.themeMode}):e.jsx(bo,{result:t.blockStudioPreview.result,chartConfig:t.blockStudioPreview.chartConfig,themeMode:t.themeMode})]}):Z?e.jsx(ms,{message:Z}):e.jsx(lt,{message:"Run the block to preview results."})),k==="lineage"&&e.jsx(cs,{blockName:me,loading:et,detail:Ue,graph:De,paths:tt,onSelectNode:o=>{n({type:"SET_LINEAGE_FOCUS",nodeId:o}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:o})},onOpenInspector:()=>{if(me){const o=`block:${me}`;n({type:"SET_LINEAGE_FOCUS",nodeId:o}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:o})}},t:i}),k==="parameters"&&e.jsx(ps,{parameters:((Nn=t.blockStudioValidation)==null?void 0:Nn.parameters)??[],values:de,onChange:(o,u)=>ee(v=>({...v,[o]:u})),onReset:o=>ee(u=>{const v={...u};return delete v[o],v}),onRun:()=>void zt(),running:J,t:i}),k==="history"&&e.jsx(js,{entries:Ze,t:i}),k==="save"&&e.jsxs("div",{style:{display:"grid",gap:12},children:[t.activeBlockPath&&t.blockStudioMetadata&&e.jsx("div",{style:{padding:"12px 12px 0"},children:e.jsx(ys,{currentStatus:t.blockStudioMetadata.reviewStatus??"draft",blockPath:t.activeBlockPath,onStatusChanged:o=>{t.blockStudioMetadata&&(n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,reviewStatus:o}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:ae(t.blockStudioDraft,"status",o)}))},t:i})}),an&&e.jsx(bs,{result:an,t:i}),e.jsx(us,{metadata:t.blockStudioMetadata,draftMetadata:Xe,onChange:o=>{if(!t.blockStudioMetadata)return;n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}});let u=t.blockStudioDraft;typeof o.name=="string"&&(u=yt(u,o.name)),typeof o.domain=="string"&&(u=ae(u,"domain",o.domain)),typeof o.owner=="string"&&(u=ae(u,"owner",o.owner)),typeof o.description=="string"&&(u=ae(u,"description",o.description)),o.tags&&(u=bt(u,o.tags)),Pe(u)},t:i})]})]})]}),Ae&&q&&e.jsx("div",{style:{position:"absolute",right:16,bottom:16},children:e.jsx("button",{onClick:()=>re(!1),style:{background:i.btnBg,border:`1px solid ${i.btnBorder}`,borderRadius:6,color:i.textSecondary,cursor:"pointer",fontSize:12,fontFamily:i.font,padding:"8px 12px"},children:"Open Results"})}),!h&&Me&&e.jsx("div",{onMouseDown:Ui,style:{gridColumn:"4",gridRow:"1 / 4",cursor:"col-resize",background:i.headerBorder}}),Me&&e.jsx(Bo,{t:i,title:"Block AI",subtitle:me?`Current block: ${me}`:"Unsaved governed block draft",expanded:tn,onToggleExpanded:()=>nn(o=>!o),onClose:()=>{it(!1),nn(!1)},onNewChat:()=>{p.resetThreadId(),Bi(o=>o+1)},running:ki,compact:h,ariaLabel:"Block Studio AI",style:{gridColumn:h?"1":"5",gridRow:h?bn:"1 / 4"},children:e.jsx(jo,{themeMode:t.themeMode,title:"Block AI",scopeHint:me?`Current block: ${me}`:"Block Studio project context",workspaceContext:{surface:"block-studio",task:ln==="edit"?"edit_block":"author_block",draftSessionId:s,blockStudioDraft:t.blockStudioDraft,activeBlockPath:t.activeBlockPath,domain:(Hn=t.blockStudioMetadata)==null?void 0:Hn.domain,importId:ze==null?void 0:ze.id,importCandidateId:(Qn=ze==null?void 0:ze.candidates[0])==null?void 0:Qn.id,...ln==="edit"?{mode:"edit",blockPath:t.activeBlockPath}:{}},initialMode:"block",initialInput:Di,autoRun:Pi,threadId:p.threadId,onThreadIdChange:p.onThreadIdChange,onRunningChange:wi,onInsertSql:(o,u)=>Fi(o,{question:u??me??"analysis",title:u}),onInsertDql:o=>{qi(o)},answerFirstCards:!0,insertDqlActionLabel:"Add to Block Studio",emptyHint:"Describe the governed block you need. DQL checks certified blocks and semantic metrics before creating a review-required draft.",examplePrompts:[{label:"Build from business question",prompt:"Build a reusable governed DQL block for this business question: "},{label:"Find reusable blocks",prompt:"Which certified DQL blocks already answer this analysis, and what should be reused instead of duplicated?"},{label:"Review this block",prompt:"Review this block for grain, compatible metrics and dimensions, parameters, tests, and certification gaps."}]},`${a}:${Ci}`)}),!Me&&!h&&e.jsx("button",{type:"button",onClick:()=>it(!0),title:"Open Block AI",style:{position:"absolute",right:12,top:58,width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${i.btnBorder}`,background:i.btnBg,color:i.accent,cursor:"pointer",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.12)"},children:e.jsx(To,{size:16,strokeWidth:2})}),L&&t.blockStudioMetadata&&e.jsx(Fo,{metadata:t.blockStudioMetadata,onCancel:()=>{Be.current=null,U(!1)},onConfirm:o=>{let u=yt(t.blockStudioDraft,o.name);u=ae(u,"owner",o.owner),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:u}),U(!1)},t:i}),ge&&e.jsx(qo,{saving:N,onCancel:()=>be(!1),onDiscard:()=>{be(!1),Dt()},onSave:async()=>{te.current=!0,be(!1),await Ot()&&(te.current=!1,Dt())},t:i}),Ce&&ce&&e.jsx(No,{blockName:ce.name,blockPath:ce.path,deleting:he,error:$e,onCancel:()=>{he||(ke(!1),Ie(null),ue(null))},onConfirm:()=>void _i(),t:i})]})}function Wo({active:t,onClick:n,label:i,busy:s,Icon:l,variant:a="secondary",title:p}){const{state:y}=wt(),x=Ct[y.themeMode],k=a==="primary",r=a==="danger";return e.jsxs("button",{onClick:n,title:p??i,style:{background:k?x.accent:r?`${x.error}0d`:t?`${x.accent}18`:x.btnBg,border:`1px solid ${k?x.accent:r?`${x.error}55`:t?x.accent:x.btnBorder}`,borderRadius:6,height:28,color:k?"#ffffff":r?x.error:t?x.accent:x.textSecondary,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:k?800:600,fontFamily:x.font,padding:"0 10px",whiteSpace:"nowrap",opacity:s?.7:1},children:[s?e.jsx(rt,{size:13,strokeWidth:2,"aria-hidden":"true"}):l?e.jsx(l,{size:13,strokeWidth:2,"aria-hidden":"true"}):null,s?`${i}...`:i]})}function Fe(t){return e.jsx(Wo,{active:!1,...t})}function Oo({source:t,diagnostics:n,parameterCount:i,t:s}){const l=t.split(`
|
|
20
|
+
`),a={block:"var(--text-tertiary)",parameters:"var(--accent)",query:"var(--status-success)",tests:"var(--status-warning)",visualization:"var(--cat-audit)"},p=[];l.forEach((r,f)=>{const g=r.match(/^\s*(block|parameters|query|tests|visualization)\b/);if(g&&!p.some(I=>I.label.toLowerCase().startsWith(g[1]))){const I=g[1],P=I==="block"?"Metadata":I==="parameters"?`Parameters${i?` · ${i}`:""}`:I.charAt(0).toUpperCase()+I.slice(1);p.push({label:P,line:f+1,color:a[I]??"var(--text-tertiary)"})}});const y=(t.match(/^\s*assert\b/gm)??[]).length,x=new Set((t.match(/\b(?:from|join)\s+([a-z_][\w.]*)/gi)??[]).map(r=>r.replace(/^(from|join)\s+/i,""))).size,k=n.filter(r=>r.severity==="error");return e.jsxs("div",{style:{width:208,flexShrink:0,background:s.appBg,display:"flex",flexDirection:"column",overflow:"auto"},children:[e.jsx("div",{style:{padding:"12px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Outline"}),e.jsx("div",{style:{padding:"0 8px",display:"flex",flexDirection:"column",gap:1},children:p.length===0?e.jsx("span",{style:{fontSize:11,color:s.textMuted,padding:"2px 8px",fontFamily:s.font},children:"No sections yet."}):p.map(r=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:6},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2,background:r.color,flexShrink:0}}),e.jsx("span",{style:{flex:1,fontSize:11.5,fontWeight:550,color:s.textSecondary,fontFamily:s.font},children:r.label}),e.jsxs("span",{style:{fontSize:10,color:s.textMuted,fontFamily:s.fontMono},children:[":",r.line]})]},r.label))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Problems"}),k.length===0?e.jsxs("div",{style:{padding:"0 14px",fontSize:11.5,color:"var(--status-success)",display:"flex",alignItems:"center",gap:6,fontFamily:s.font},children:[e.jsx(jt,{size:12})," No problems"]}):e.jsx("div",{style:{padding:"0 14px",display:"flex",flexDirection:"column",gap:5},children:k.slice(0,4).map((r,f)=>e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",lineHeight:1.4,fontFamily:s.font},children:r.message},f))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Context"}),e.jsxs("div",{style:{padding:"0 14px 16px",display:"flex",flexDirection:"column",gap:5,fontSize:11,color:s.textSecondary,fontFamily:s.font},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--accent)"}}),i," parameter",i===1?"":"s"," bound"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-success)"}}),x," model",x===1?"":"s"," referenced"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)"}}),y," test",y===1?"":"s"," declared"]})]})]})}function mt({active:t,onClick:n,label:i,t:s}){return e.jsx("button",{type:"button",onClick:n,style:{padding:"9px 1px",fontSize:11.5,fontWeight:650,cursor:"pointer",border:"none",background:"none",fontFamily:s.font,whiteSpace:"nowrap",color:t?s.textPrimary:s.textMuted,boxShadow:t?`inset 0 -2px 0 0 ${s.accent}`:"none"},children:i})}function Jn(t,n){return so(t,{variant:n?"accent":"ghost",size:"xs",active:n})}function St(t,n){return{display:"inline-flex",alignItems:"center",gap:5,background:n?"var(--accent-dim)":t.btnBg,border:`1px solid ${n?`${t.accent}55`:t.btnBorder}`,borderRadius:999,color:n?t.accent:t.textSecondary,cursor:"pointer",fontSize:11.5,fontFamily:t.fontMono,lineHeight:1.2,padding:"4px 9px"}}function Fo({metadata:t,onCancel:n,onConfirm:i,t:s}){const[l,a]=c.useState(t.name),[p,y]=c.useState(t.owner),x=!!(l.trim()&&p.trim());return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Save block",style:{position:"absolute",inset:0,zIndex:70,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,.32)",padding:18},children:e.jsxs("div",{style:{width:420,maxWidth:"100%",display:"grid",gap:14,padding:18,borderRadius:10,border:`1px solid ${s.headerBorder}`,background:s.cellBg,boxShadow:"0 24px 70px rgba(0,0,0,.35)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:850,color:s.textPrimary},children:"Save governed block"}),e.jsx("div",{style:{marginTop:4,fontSize:11,lineHeight:1.45,color:s.textMuted},children:"Name and owner are required. DQL will run the local governance checks and certify the block when they pass; otherwise it remains a draft with blockers."})]}),e.jsx($,{label:"Block name",t:s,children:e.jsx("input",{autoFocus:!0,value:l,onChange:k=>a(k.target.value),style:Se(s)})}),e.jsx($,{label:"Owner",t:s,children:e.jsx("input",{value:p,onChange:k=>y(k.target.value),placeholder:"analytics@company.com or team name",style:Se(s)})}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:n,style:ne(s),children:"Cancel"}),e.jsx("button",{type:"button",disabled:!x,onClick:()=>x&&i({name:l.trim(),owner:p.trim()}),style:{...je(s),opacity:x?1:.55},children:"Save block"})]})]})})}function qo({saving:t,onSave:n,onDiscard:i,onCancel:s,t:l}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Unsaved block",style:{position:"fixed",inset:0,zIndex:90,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(430px, 100%)",border:`1px solid ${l.cellBorder}`,borderRadius:12,background:l.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.24)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,color:l.textPrimary,fontFamily:l.font},children:"Save this block before starting another?"}),e.jsx("div",{style:{marginTop:5,fontSize:12,lineHeight:1.5,color:l.textMuted,fontFamily:l.font},children:"Your current workspace has unsaved changes."})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:s,disabled:t,style:ne(l),children:"Cancel"}),e.jsx("button",{type:"button",onClick:i,disabled:t,style:{...ne(l),color:l.error},children:"Discard"}),e.jsx("button",{type:"button",onClick:()=>void n(),disabled:t,style:je(l),children:t?"Saving…":"Save block"})]})]})})}function No({blockName:t,blockPath:n,deleting:i,error:s,onCancel:l,onConfirm:a,t:p}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Delete block",style:{position:"fixed",inset:0,zIndex:95,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(460px, 100%)",border:`1px solid ${p.error}55`,borderRadius:12,background:p.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.26)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx("span",{style:{width:30,height:30,display:"grid",placeItems:"center",borderRadius:8,background:`${p.error}12`},children:e.jsx($t,{size:16,color:p.error})}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:15,fontWeight:800,color:p.textPrimary,fontFamily:p.font},children:["Delete “",t,"”?"]}),e.jsx("div",{style:{marginTop:3,fontSize:11,color:p.textMuted,fontFamily:p.fontMono},children:n})]})]}),e.jsxs("div",{style:{fontSize:12,lineHeight:1.5,color:p.textSecondary,fontFamily:p.font},children:["This removes the saved ",e.jsx("code",{children:".dql"})," block and its generated semantic companion. Unsaved editor changes are discarded. Git can recover committed versions."]}),s&&e.jsx("div",{role:"alert",style:{padding:"8px 10px",borderRadius:7,border:`1px solid ${p.error}45`,background:`${p.error}0d`,color:p.error,fontSize:11,lineHeight:1.4},children:s}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:l,disabled:i,style:ne(p),children:"Cancel"}),e.jsx("button",{type:"button",onClick:a,disabled:i,style:{...je(p),background:p.error,borderColor:p.error,opacity:i?.65:1},children:i?e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:13,className:"dql-spin"})," Deleting…"]}):e.jsxs(e.Fragment,{children:[e.jsx($t,{size:13})," Delete block"]})})]})]})})}function Ho({dbtStatus:t,semanticStats:n,semanticObjectCount:i,databaseStats:s,onCreateSql:l,onCreateSemantic:a,onImport:p,onBuildDql:y,t:x}){var P;const k=[{title:"Blank SQL block",detail:"Start with an empty custom query.",action:l,label:"Create",Icon:vo},{title:"Semantic block",detail:"Build directly from governed metrics.",action:a,label:"Build",Icon:Rt}],r=!!(t!=null&&t.artifacts.manifest.exists),f=(t==null?void 0:t.counts.metrics)??n.metrics,g=t?`${t.counts.models} dbt models · ${f} MetricFlow metrics`:"Waiting for dbt artifacts",I=(t==null?void 0:t.projectName)||((P=t==null?void 0:t.projectPath)==null?void 0:P.split("/").filter(Boolean).pop())||"dbt project";return e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:22,display:"grid",gap:14,alignContent:"start",background:x.appBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:800,color:x.textPrimary,fontFamily:x.font},children:"Create DQL blocks"}),e.jsx("div",{style:{fontSize:12,color:x.textMuted,lineHeight:1.45,marginTop:5,maxWidth:560,fontFamily:x.font},children:"Start from SQL you already have, or describe the business asset you want DQL to build from project context."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"7px 10px",border:`1px solid ${r?"#2ea04340":x.headerBorder}`,borderRadius:8,background:r?"#2ea0430d":x.cellBg},children:[e.jsx(jt,{size:15,strokeWidth:2,color:r?"#2ea043":x.textMuted,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:11,color:r?"#2ea043":x.textMuted,fontWeight:700,fontFamily:x.font},children:r?"dbt ready":"dbt pending"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))",gap:10},children:[e.jsx(Ht,{title:"Ask AI",detail:"Describe the business asset you need. DQL uses this domain's blocks, models, and semantic metrics to draft it.",label:"Describe block",Icon:Io,onClick:y,t:x}),e.jsx(Ht,{title:"Import SQL",detail:"Paste scripts, upload files, or point at a folder. DQL analyzes candidates without writing block files until you save.",label:"Start import",Icon:mi,onClick:p,t:x}),e.jsx(Ht,{title:"Build manually",detail:"Use the visual semantic builder for multiple metrics, compatible dimensions, time grain, filters, and chart intent.",label:"Open builder",Icon:Rt,onClick:a,t:x})]}),e.jsxs("details",{style:gt(x),children:[e.jsx("summary",{style:xt(x),children:"Manual options"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:10},children:k.map(W=>e.jsx(Qo,{title:W.title,detail:W.detail,label:W.label,Icon:W.Icon,onClick:W.action,t:x},W.title))})]}),e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:8},children:[e.jsx(Qt,{Icon:Vt,label:`${I} dbt`,value:g,tone:r?"success":"neutral",t:x}),e.jsx(Qt,{Icon:Vt,label:"Database",value:`${s.tables} tables`,tone:s.tables>0?"success":"neutral",t:x}),e.jsx(Qt,{Icon:Rt,label:"DQL semantic layer",value:`${i} objects`,tone:i>0?"success":"neutral",t:x})]})]})}function Ht({title:t,detail:n,label:i,Icon:s,onClick:l,t:a}){return e.jsxs("button",{onClick:l,style:{border:`1px solid ${a.accent}`,borderRadius:8,background:a.cellBg,color:a.textPrimary,cursor:"pointer",display:"grid",gridTemplateColumns:"42px minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:16,minHeight:104,textAlign:"left",fontFamily:a.font,boxShadow:`inset 0 0 0 1px ${a.accent}22`},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}18`,color:a.accent},children:e.jsx(s,{size:20,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:850,color:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:12,color:a.textMuted,lineHeight:1.4},children:n})]}),e.jsx("span",{style:{color:"#ffffff",background:a.accent,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:800,whiteSpace:"nowrap"},children:i})]})}function Qo({title:t,detail:n,label:i,Icon:s,onClick:l,t:a}){return e.jsxs("button",{onClick:l,style:{textAlign:"left",background:a.cellBg,border:`1px solid ${a.headerBorder}`,borderRadius:8,padding:12,cursor:"pointer",color:a.textPrimary,display:"grid",gridTemplateColumns:"30px minmax(0, 1fr)",gap:10,minHeight:94,fontFamily:a.font,alignItems:"start"},children:[e.jsx("span",{style:{width:30,height:30,borderRadius:7,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}14`,color:a.accent},children:e.jsx(s,{size:16,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:13,fontWeight:800,color:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:11,color:a.textMuted,lineHeight:1.35},children:n}),e.jsx("span",{style:{color:a.accent,fontSize:11,fontWeight:800},children:i})]})]})}function Qt({Icon:t,label:n,value:i,tone:s,t:l}){const a=s==="success"?"#2ea043":l.textMuted;return e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:8,background:l.cellBg,padding:"9px 10px",display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx("span",{style:{color:a,display:"inline-flex",flexShrink:0},children:e.jsx(t,{size:15,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:10,color:l.textMuted,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),e.jsx("span",{style:{fontSize:12,color:l.textPrimary,fontWeight:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]})]})}function Uo({source:t,databaseStats:n,semanticCount:i,onChange:s,onOpenExplorer:l,onOpenAi:a,t:p}){const y=r=>{var f;return((f=t.match(new RegExp(`\\b${r}\\s*=\\s*"([^"]*)"`,"i")))==null?void 0:f[1])??""},x=r=>{var f;return(((f=t.match(new RegExp(`\\b${r}\\s*=\\s*\\[([\\s\\S]*?)\\]`,"i")))==null?void 0:f[1].match(/"([^"]*)"/g))??[]).map(g=>g.slice(1,-1))},k=[{key:"primaryTerms",label:"Business terms",hint:"net revenue, active customer"},{key:"sourceSystems",label:"Source systems",hint:"billing, product events"},{key:"synonyms",label:"Question aliases",hint:"sales, bookings"}];return e.jsxs("div",{style:{padding:"10px 14px",borderBottom:`1px solid ${p.headerBorder}`,background:p.appBg,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:12,fontWeight:750,color:p.textPrimary},children:"Block context"}),e.jsx("span",{style:{fontSize:11,color:p.textMuted},children:"Only grounded context is kept with the block and used for retrieval."}),e.jsx("div",{style:{flex:1}}),e.jsxs("button",{type:"button",onClick:l,style:ne(p),children:[n.tables," database tables"]}),e.jsx("button",{type:"button",onClick:a,style:ne(p),children:"Review with AI"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:10},children:[e.jsx($,{label:"Business outcome",t:p,children:e.jsx(vt,{value:y("businessOutcome"),onChange:r=>s(ae(t,"businessOutcome",r)),placeholder:"Decision or outcome this block supports",style:Se(p)})}),e.jsx($,{label:"Agent guidance",t:p,children:e.jsx(vt,{value:y("llmContext"),onChange:r=>s(ae(t,"llmContext",r)),placeholder:"When to use this block",style:Se(p)})}),k.map(r=>e.jsx(Ko,{label:r.label,hint:r.hint,values:x(r.key),onChange:f=>s(ro(t,r.key,f)),t:p},r.key)),e.jsx($,{label:"Rules and caveats",t:p,children:e.jsx(vt,{value:y("caveats"),onChange:r=>s(ae(t,"caveats",r)),placeholder:"Known limitation or interpretation rule",style:Se(p)})})]}),e.jsxs("div",{style:{fontSize:10,color:p.textMuted},children:["Available authoring context: ",i," semantic objects, ",n.schemas," schemas, ",n.columns," columns. SQL completion uses the same loaded catalog."]})]})}function Ko({label:t,hint:n,values:i,onChange:s,t:l}){const[a,p]=c.useState(""),y=()=>{const x=a.split(",").map(k=>k.trim()).filter(Boolean);x.length>0&&s([...i,...x]),p("")};return e.jsx($,{label:t,t:l,children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:5,padding:6,minHeight:36,border:`1px solid ${l.cellBorder}`,borderRadius:6,background:l.cellBg},children:[i.map(x=>e.jsxs("button",{type:"button",onClick:()=>s(i.filter(k=>k!==x)),title:"Remove",style:{...St(l,!0),border:"none",cursor:"pointer"},children:[x," ×"]},x)),e.jsx("input",{value:a,onChange:x=>p(x.target.value),onKeyDown:x=>{(x.key==="Enter"||x.key===",")&&(x.preventDefault(),y())},onBlur:y,placeholder:i.length?"Add another…":n,style:{minWidth:120,flex:1,border:"none",outline:"none",background:"transparent",color:l.textPrimary,fontSize:11,fontFamily:l.font}})]})})}function xi({source:t,kind:n,onChange:i,t:s}){const l=c.useMemo(()=>po(t),[t]),[a,p]=c.useState(""),[y,x]=c.useState(""),[k,r]=c.useState(!0),[f,g]=c.useState("dynamic"),[I,P]=c.useState("auto"),W=Nt(y,a),le=I==="auto"?W:I,E=Se(s),j=()=>{a.trim()&&(i(Vn(t,{name:a,type:le,required:k&&!y.trim(),defaultText:y,policy:f})),p(""),x(""),r(!0),g("dynamic"),P("auto"))};return e.jsx(fe,{title:"Runtime parameters",t:s,children:e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{fontSize:11,color:s.textMuted,lineHeight:1.45},children:["Add a values-only input once, then reuse this block for a different period, region, customer set, or limit.",n==="custom"?e.jsxs(e.Fragment,{children:[" Use ",e.jsx("code",{children:"${parameter_name}"})," in SQL where the value belongs; DQL always binds it safely."]}):" Choose a semantic field above as a filter to create its governed parameter binding."]}),l.length>0&&e.jsx("div",{style:{display:"grid",gap:7},children:l.map(S=>{var J;const ie=fo(S),V=A=>i(Vn(t,{name:S.name,type:A.type??S.type,required:A.required??S.required,defaultText:A.defaultText??ie,policy:A.policy??S.policy}));return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 1fr) 122px minmax(150px, 1fr) 118px auto",gap:7,alignItems:"center",padding:8,border:`1px solid ${s.cellBorder}`,borderRadius:7,background:s.cellBg},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:s.textPrimary},children:S.name}),e.jsxs("div",{style:{fontSize:10,color:s.textMuted},children:[((J=S.binding)==null?void 0:J.kind)??"declared value"," · ",S.required?"required":"has default"]})]}),e.jsx("select",{"aria-label":`${S.name} type`,value:S.type,onChange:A=>V({type:A.target.value}),style:E,children:Zn.map(A=>e.jsx("option",{value:A,children:A},A))}),S.type==="boolean"?e.jsxs("select",{"aria-label":`${S.name} default`,value:ie,onChange:A=>V({defaultText:A.target.value,required:!1}),style:E,children:[e.jsx("option",{value:"",children:"Required / no default"}),e.jsx("option",{value:"true",children:"True"}),e.jsx("option",{value:"false",children:"False"})]}):e.jsx("input",{"aria-label":`${S.name} default`,value:ie,onChange:A=>{const Z=A.target.value,Q=S.type===Nt(ie,S.name);V({defaultText:Z,required:Z.trim()?!1:S.required,...Q?{type:Nt(Z,S.name)}:{}})},placeholder:S.type.endsWith("[]")?"West, East":S.required?"Required value":"Default value",style:E}),e.jsx("select",{"aria-label":`${S.name} policy`,value:S.policy,onChange:A=>V({policy:A.target.value}),style:E,children:Go.map(A=>e.jsx("option",{value:A,children:A},A))}),e.jsx("button",{type:"button",onClick:()=>i(ho(t,S.name)),title:`Remove ${S.name}`,style:{border:"none",background:"transparent",color:s.error,cursor:"pointer",fontSize:16,padding:"3px 5px"},children:"×"})]},S.name)})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(140px, 1fr) minmax(150px, 1.3fr) 150px 130px auto",gap:7,alignItems:"center",padding:9,border:`1px dashed ${s.btnBorder}`,borderRadius:7,background:s.appBg},children:[e.jsx("input",{"aria-label":"New parameter name",value:a,onChange:S=>p(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),j())},placeholder:"region_set",style:E}),e.jsx("input",{"aria-label":"New parameter default",value:y,onChange:S=>{x(S.target.value),S.target.value.trim()&&r(!1)},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),j())},placeholder:"Central, East or 2026-01-01",style:E}),e.jsxs("select",{"aria-label":"New parameter type",value:I,onChange:S=>P(S.target.value),style:E,children:[e.jsxs("option",{value:"auto",children:["Auto · ",W]}),Zn.map(S=>e.jsx("option",{value:S,children:S},S))]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:s.textSecondary,fontSize:11,whiteSpace:"nowrap"},children:[e.jsx("input",{type:"checkbox",checked:k&&!y.trim(),onChange:S=>r(S.target.checked)})," Required"]}),e.jsx("button",{type:"button",onClick:j,disabled:!a.trim(),style:{...je(s),opacity:a.trim()?1:.5},children:"Add"})]}),e.jsxs("div",{style:{fontSize:10,color:s.textMuted},children:["Type is inferred from a value you enter: ",e.jsx("code",{children:"10"})," → number, ",e.jsx("code",{children:"2026-01-01"})," → date, ",e.jsx("code",{children:"West, East"})," → string[]. You can override it at any time."]})]})})}const Zn=["string","number","boolean","date","string[]","number[]","date[]"],Go=["dynamic","static","business","derived","optional","ambiguous_review_required"];function Vo({metadata:t,source:n,parameters:i,preview:s,lineageDetail:l,isSemanticBlock:a,running:p,onOpenBuilder:y,onOpenSource:x,onDelete:k,onRun:r,onOpenHistory:f,t:g}){var Y,de,ee,N,oe;const I=((t==null?void 0:t.reviewStatus)??"").toLowerCase()==="certified",P=(t==null?void 0:t.name)||"block",W=a?li(n):null,le=((de=(Y=n.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:Y[1])==null?void 0:de.trim())??"",E=W?Array.from(new Set([...W.dimensions,...W.timeDimension?[W.timeDimension]:[],...W.metrics])):Si(le),j=(n.match(/^\s*assert\b.*$/gm)??[]).map(D=>D.trim()),S=((ee=l==null?void 0:l.incoming)==null?void 0:ee.length)??0,ie=((N=l==null?void 0:l.outgoing)==null?void 0:N.length)??0,[V,J]=c.useState(!1),A=((l==null?void 0:l.incoming)??[]).map(D=>{var X;return(X=D.node)==null?void 0:X.name}).filter(Boolean).slice(0,3),Z=((l==null?void 0:l.outgoing)??[]).map(D=>{var X;return(X=D.node)==null?void 0:X.name}).filter(Boolean).slice(0,3),Q={fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted,marginBottom:8,fontFamily:g.font},M=(D,X=!1)=>e.jsx("span",{style:{padding:"3px 9px",borderRadius:999,border:`1px solid ${X?`${g.accent}59`:g.headerBorder}`,background:X?"var(--accent-dim)":"var(--bg-1)",color:X?g.accent:g.textSecondary,fontFamily:g.fontMono,fontWeight:X?600:400,fontSize:11.5},children:D},D),K=e.jsx("span",{style:{color:g.textMuted,fontSize:11},children:"→"}),F=[["Last run",s!=null&&s.result.executionTime?`${(s.result.executionTime/1e3).toFixed(1)}s`:"Not run yet"],["Rows",s?String(s.result.rowCount??s.result.rows.length):"—"],["Used in",ie>0?`${ie} downstream`:"—"],["Tests",j.length>0?`${j.length} declared`:"None yet"]];return e.jsx("div",{style:{height:"100%",overflow:"auto",background:g.appBg},children:e.jsxs("div",{style:{width:"min(860px, 100% - 48px)",margin:"0 auto",padding:"26px 0 40px",display:"flex",flexDirection:"column",gap:20,animation:"dql-agent-fadein 0.25s ease-out",fontFamily:g.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:14},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:10,background:I?"var(--status-success-bg)":"var(--accent-dim)",color:I?"var(--status-success)":g.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:e.jsx(Rt,{size:20,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:17,fontWeight:700,color:g.textPrimary,fontFamily:g.fontMono,letterSpacing:"-0.01em"},children:P}),t!=null&&t.reviewStatus?e.jsx(hi,{status:t.reviewStatus,t:g}):null]}),e.jsx("div",{style:{fontSize:12,color:g.textMuted,marginTop:4},children:[t==null?void 0:t.domain,t!=null&&t.folderPath?`folder: ${t.folderPath}`:null,t==null?void 0:t.owner,...(oe=t==null?void 0:t.tags)!=null&&oe.length?[t.tags.join(", ")]:[]].filter(Boolean).join(" · ")||"Unsaved draft"})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:y,style:{display:"inline-flex",alignItems:"center",gap:7,height:32,padding:"0 14px",borderRadius:8,border:"none",background:g.accent,color:"#fff",fontSize:12.5,fontWeight:650,cursor:"pointer",fontFamily:g.font,boxShadow:"0 1px 4px rgba(107,93,211,0.25)"},children:[e.jsx(Do,{size:13,strokeWidth:1.75})," Open in builder"]}),e.jsxs("button",{type:"button",onClick:r,disabled:p,style:{display:"inline-flex",alignItems:"center",gap:6,height:32,padding:"0 13px",borderRadius:8,border:`1px solid ${g.headerBorder}`,background:g.cellBg,color:g.textSecondary,fontSize:12.5,fontWeight:600,cursor:"pointer",fontFamily:g.font,opacity:p?.7:1},children:[p?e.jsx(rt,{size:12,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(gi,{size:11,fill:"currentColor"})," Run"]}),e.jsx("button",{type:"button","aria-label":`Delete ${P}`,title:"Delete block",onClick:k,style:{width:32,height:32,borderRadius:8,border:`1px solid ${g.error}55`,background:`${g.error}0d`,color:g.error,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx($t,{size:14})}),e.jsx("button",{type:"button",title:"History and metadata",onClick:f,style:{width:32,height:32,borderRadius:8,border:`1px solid ${g.headerBorder}`,background:g.cellBg,color:g.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(ko,{size:15})})]})]}),t!=null&&t.description?e.jsx("div",{style:{fontSize:13.5,lineHeight:1.6,color:g.textSecondary,maxWidth:640},children:t.description}):null,e.jsx("div",{style:{display:"flex",border:"1px solid var(--border-subtle)",borderRadius:10,background:g.cellBg,overflow:"hidden"},children:F.map(([D,X],se)=>e.jsxs("div",{style:{flex:1,padding:"12px 16px",borderRight:se<F.length-1?"1px solid var(--border-subtle)":"none"},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted},children:D}),e.jsx("div",{style:{fontSize:14,fontWeight:650,color:g.textPrimary,marginTop:3},children:X})]},D))}),e.jsxs("div",{children:[e.jsx("div",{style:Q,children:"Outputs"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:E.length>0?E.map(D=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 10px",borderRadius:999,background:"var(--accent-dim)",color:g.accent,border:`1px solid ${g.accent}33`,fontFamily:g.fontMono},children:D},D)):e.jsx("span",{style:{fontSize:11.5,color:g.textMuted},children:"Open the builder to define outputs."})})]}),e.jsxs("div",{children:[e.jsx("div",{style:Q,children:"Parameters"}),e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,overflow:"hidden",background:g.cellBg},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"7px 12px",background:"var(--bg-1)",borderBottom:"1px solid var(--border-subtle)",fontSize:10.5,fontWeight:700,color:g.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"}),e.jsx("span",{children:"Default"}),e.jsx("span",{children:"Policy"})]}),i.length===0?e.jsx("div",{style:{padding:"9px 12px",fontSize:12,color:g.textMuted},children:"No parameters — this block always runs the same way."}):i.map((D,X)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"8px 12px",borderBottom:X<i.length-1?"1px solid var(--border-subtle)":"none",fontSize:12,alignItems:"center"},children:[e.jsx("span",{style:{fontFamily:g.fontMono,fontWeight:600,color:g.textPrimary},children:D.name}),e.jsx("span",{style:{color:g.textSecondary},children:D.type}),e.jsx("span",{style:{fontFamily:g.fontMono,color:D.default!==void 0&&D.default!==null&&D.default!==""?"var(--status-warning)":g.textMuted},children:D.default!==void 0&&D.default!==null&&D.default!==""?JSON.stringify(D.default):D.required?"required":"—"}),e.jsx("span",{style:{color:g.textMuted},children:D.policy})]},D.name))]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{style:{...Q,marginBottom:0},children:"DQL source"}),e.jsxs("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"none",color:g.accent,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:g.font,padding:0},children:["Open in DQL Source ",e.jsx(Gt,{size:11,strokeWidth:2})]})]}),e.jsx("pre",{style:{margin:0,border:"1px solid var(--border-subtle)",background:g.cellBg,borderRadius:9,padding:"13px 15px",fontSize:11.5,lineHeight:1.65,fontFamily:g.fontMono,whiteSpace:"pre",overflowX:"auto",color:g.textPrimary,maxHeight:320,overflowY:"auto"},children:n.trim()||"Open the builder to author this block."})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},children:[e.jsxs("div",{children:[e.jsx("div",{style:Q,children:"Tests"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:j.length>0?j.map(D=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[e.jsx(jt,{size:13,color:"var(--status-success)",strokeWidth:2,style:{flexShrink:0}}),e.jsx("span",{style:{fontFamily:g.fontMono,color:g.textSecondary},children:D})]},D)):e.jsx("span",{style:{fontSize:11.5,color:g.textMuted},children:"No tests yet — add assertions in the builder before certification."})})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>J(D=>!D),style:{display:"flex",alignItems:"center",gap:6,border:"none",background:"none",cursor:"pointer",padding:0,fontFamily:g.font,marginBottom:8},children:[e.jsx(Gt,{size:11,color:g.textMuted,strokeWidth:2,style:{transform:V?"rotate(90deg)":"none",transition:"transform 0.12s"}}),e.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:g.textMuted},children:"Lineage"}),V?null:e.jsxs("span",{style:{fontSize:10.5,color:g.textMuted},children:[S," upstream · ",ie," downstream"]})]}),V?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:11.5,animation:"dql-agent-fadein 0.18s ease-out"},children:[A.length>0?A.map(D=>M(D)):M("no upstream"),K,M(P,!0),K,Z.length>0?Z.map(D=>M(D)):M("no downstream yet")]}):null]})]})]})})}function Yo({source:t,metadata:n,semanticLayer:i,dbtStatus:s,domainOptions:l,chartConfig:a,onChange:p,onMetadataChange:y,onOpenAi:x,onSetupRuntime:k,t:r}){const f=li(t),g={...f,filters:f.requestedFilters},[I,P]=c.useState([]),[W,le]=c.useState(!1),[E,j]=c.useState(null),[S,ie]=c.useState(null),[V,J]=c.useState(0);c.useEffect(()=>{let d=!1;if(g.metrics.length===0){P([]),j(null),ie(null),le(!1);return}return P([]),j(null),le(!0),ie(null),O.getCompatibility(g.metrics).then(L=>{d||(j(L),P(L.dimensions))}).catch(L=>{d||(P([]),ie(L instanceof Error?L.message:String(L)))}).finally(()=>{d||le(!1)}),()=>{d=!0}},[i.dimensions,g.metrics.join("|"),V]);const A=new Set(I.flatMap(d=>[d.reference??d.name,d.name])),Z=new Map(I.flatMap(d=>[[d.reference??d.name,d.qualifiedName??void 0],[d.name,d.qualifiedName??void 0]])),Q=new Map(((E==null?void 0:E.incompatible)??[]).map(d=>[d.name,Ao(d.reason)])),M=new Map(I.flatMap(d=>[[d.reference??d.name,d],[d.name,d]])),K=Array.from(new Map([...i.dimensions,...i.timeDimensions].map(d=>{const L=d.reference??d.name;return[L,{...d,name:L}]})).values()),F=new Map(K.flatMap(d=>[[d.name,d],[d.reference??d.name,d]])),Y=I.map(d=>{const L=d.reference??d.name;return{...F.get(L)??F.get(d.name),...d,name:L}}),de=Y.filter(d=>d.isTimeDimension||d.type==="time"),ee=en(r),[N,oe]=c.useState(""),[D,X]=c.useState(""),se=c.useMemo(()=>new Map(i.metrics.map(d=>[d.name,d])),[i.metrics]),Ce=c.useMemo(()=>new Map([...K,...Y].flatMap(d=>[[d.name,d],[d.reference??d.name,d]])),[K,Y]),ke=c.useMemo(()=>ei(i.metrics,N),[i.metrics,N]),ce=c.useMemo(()=>ei(Y,D),[Y,D]),Ie=di(t,"tests"),he=Array.from(new Set([...g.dimensions,...g.timeDimension?[g.timeDimension]:[],...g.metrics])),Le=(d,L)=>{y({[d]:L}),p(d==="name"?yt(t,L):ae(t,d,L))},$e=d=>{const L=g.metrics.includes(d)?g.metrics.filter(U=>U!==d):[...g.metrics,d];p(si(t,L))},ue=d=>p(ri(t,"dimensions",d)),We=d=>{const L=g.dimensions.includes(d)?g.dimensions.filter(U=>U!==d):[...g.dimensions,d];ue(L)};return c.useEffect(()=>{if(!E||g.metrics.length===0)return;const d=lo(t,Array.from(A));d!==t&&p(d)},[E,t]),e.jsx("div",{style:{height:"100%",overflow:"auto",background:r.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"24px 0 40px",display:"flex",flexDirection:"column",animation:"dql-agent-fadein 0.25s ease-out"},children:[e.jsx(yi,{metadata:n,domains:l,onTextChange:Le,onFolderChange:d=>y({folderPath:d}),onTagsChange:d=>{y({tags:d}),p(bt(t,d))},t:r}),e.jsxs(fe,{title:"Metric and grain",hint:"Pick governed semantic objects — they compile to the DQL script.",t:r,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsxs("span",{style:{fontSize:11,fontWeight:750,color:r.textSecondary},children:["Governed metrics · ",g.metrics.length," selected"]}),W&&e.jsx("span",{style:{fontSize:10,color:r.textMuted},children:"Checking compatibility…"})]}),e.jsx(ti,{kind:"metric",total:i.metrics.length,search:N,onSearchChange:oe,matches:ke,pool:i.metrics,selected:g.metrics,resolveLabel:d=>{var L;return((L=se.get(d))==null?void 0:L.label)||d},onToggle:$e,compatible:d=>{var L,U,ge,be;return((U=(L=se.get(d))==null?void 0:L.execution)==null?void 0:U.status)!=="requires_setup"&&((be=(ge=se.get(d))==null?void 0:ge.execution)==null?void 0:be.status)!=="unsupported"},t:r}),i.metrics.some(d=>d.execution&&d.execution.status!=="ready")&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",fontSize:10.5,color:r.textMuted,lineHeight:1.4},children:[e.jsx("span",{style:{flex:1},children:"Complex metrics are imported but need a full semantic runtime to execute."}),e.jsx("button",{type:"button",onClick:k,style:{border:"none",background:"transparent",color:r.accent,fontSize:10.5,fontWeight:700,cursor:"pointer",whiteSpace:"nowrap"},children:"Set up runtime →"})]}),((E==null?void 0:E.engine)||(E==null?void 0:E.degraded))&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,color:r.textMuted,marginTop:2},children:[e.jsxs("span",{style:{padding:"1px 7px",borderRadius:999,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:700},children:["Runs via ",Eo[E.engine]??E.engine]}),E.degraded&&e.jsx("span",{style:{color:"var(--status-warning)"},children:E.degraded})]}),S&&e.jsxs("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"var(--status-warning)",lineHeight:1.4,marginTop:4},children:[e.jsx(Et,{size:14,style:{flexShrink:0}}),e.jsxs("span",{style:{flex:1},children:["Could not verify governed dimensions: ",S,". Dimension selection is paused so an unapproved join cannot be saved."]}),e.jsx("button",{type:"button",onClick:()=>J(d=>d+1),style:ne(r),children:"Retry"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 150px",gap:8},children:[e.jsx($,{label:"Time dimension",t:r,children:e.jsxs("select",{disabled:g.metrics.length===0||W||!!S,value:g.timeDimension,onChange:d=>p(Gn(t,"time_dimension",d.target.value)),style:{...ee,opacity:g.metrics.length===0||W||S?.6:1},children:[e.jsx("option",{value:"",children:"None"}),de.map(d=>e.jsxs("option",{value:d.reference??d.name,children:[d.label||d.name," · ",d.name]},d.reference??d.name))]})}),e.jsx($,{label:"Grain",t:r,children:e.jsxs("select",{value:g.granularity,onChange:d=>p(Gn(t,"granularity",d.target.value)),style:ee,children:[e.jsx("option",{value:"",children:"None"}),_o(g.timeDimension,M,i.timeDimensions).map(d=>e.jsx("option",{value:d,children:d},d))]})})]}),i.metrics.length===0&&(i.loading?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:r.textMuted,lineHeight:1.45},children:[e.jsx(rt,{size:14,className:"dql-spin"}),"Loading ",((s==null?void 0:s.counts.metrics)??0).toLocaleString()," semantic metrics from parsed dbt artifacts… Large catalogs continue loading in the background."]}):((s==null?void 0:s.counts.metrics)??0)>0||s!=null&&s.artifacts.semanticManifest.exists?e.jsxs("div",{role:"alert",style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:["dbt artifacts contain ",((s==null?void 0:s.counts.metrics)??0).toLocaleString()," metrics, but Block Studio could not load them. Refresh the semantic layer; another dbt parse is not required."]}):e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:"No semantic metrics were discovered. Run dbt parse or import a semantic layer, then refresh Block Studio."})),g.metrics.length>1&&E&&I.length===0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#d29922",fontSize:11,lineHeight:1.4},children:[e.jsx(Et,{size:14})," These metrics do not expose a common dimension or join path.",e.jsx("button",{type:"button",onClick:x,style:ne(r),children:"Resolve with AI"})]})]}),e.jsxs(fe,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:r,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx($,{label:"Type",t:r,children:e.jsxs("select",{value:a.chart??"table",onChange:d=>p(Re(t,{...a,chart:d.target.value})),style:ee,children:[e.jsx("option",{value:"table",children:"Table"}),fi.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]})}),e.jsx($,{label:"X axis",t:r,children:e.jsxs("select",{value:a.x??"",onChange:d=>p(Re(t,{...a,x:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"Auto"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})}),e.jsx($,{label:"Y axis",t:r,children:e.jsxs("select",{value:a.y??"",onChange:d=>p(Re(t,{...a,y:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"Auto"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})}),e.jsx($,{label:"Series / color",t:r,children:e.jsxs("select",{value:a.color??"",onChange:d=>p(Re(t,{...a,color:d.target.value})),style:ee,children:[e.jsx("option",{value:"",children:"None"}),he.map(d=>e.jsx("option",{value:d,children:_e(d)},d))]})})]}),e.jsx($,{label:"Title",t:r,children:e.jsx("input",{value:a.title??"",onChange:d=>p(Re(t,{...a,title:d.target.value})),placeholder:"Chart title",style:ee})})]}),e.jsx(fe,{title:"Dimensions",hint:"Governed group-bys checked against the metric's join path.",t:r,children:g.metrics.length===0?e.jsx("div",{style:{fontSize:12,color:r.textMuted},children:"Choose one or more governed metrics first. Only their connected, approved dimensions will appear."}):W?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:r.textMuted},children:[e.jsx(rt,{size:14,className:"dql-spin"}),"Checking common governed dimensions…"]}):S?e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)"},children:"Dimension selection is unavailable until compatibility succeeds."}):Y.length===0?e.jsx("div",{style:{fontSize:12,color:r.textMuted},children:"No dimensions are loaded yet."}):e.jsx(ti,{kind:"dimension",total:Y.length,search:D,onSearchChange:X,matches:ce,pool:Y,selected:g.dimensions,resolveLabel:d=>{var L;return((L=Ce.get(d))==null?void 0:L.label)||d},resolveMachineName:d=>{var L;return Z.get(d)??((L=Ce.get(d))==null?void 0:L.name)??d},reasonFor:d=>Q.get(d),onToggle:We,compatible:d=>A.has(d),disabled:g.metrics.length===0||W||!!S,emptyHint:W?"Checking common governed dimensions…":S?"Retry compatibility before selecting dimensions.":"Choose a metric first; dimensions are checked against its governed join path.",t:r})}),e.jsxs(fe,{title:"Filters and parameters",hint:"Values-only inputs so this block is reusable across periods and regions.",t:r,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:7},children:Array.from(new Set([...g.dimensions,...g.timeDimension?[g.timeDimension]:[]])).map(d=>{var U;const L=g.filters.includes(d);return e.jsx("button",{type:"button",onClick:()=>p(ao(t,L?g.filters.filter(ge=>ge!==d):[...g.filters,d])),style:St(r,L),children:((U=Ce.get(d))==null?void 0:U.label)||d},d)})}),e.jsx("div",{style:{fontSize:10,color:r.textMuted,marginTop:8},children:g.dimensions.length===0&&!g.timeDimension?"Search and add a compatible dimension first, then choose whether it should also be a dynamic filter.":"Selected fields become governed runtime filters. Values stay dynamic rather than being hard-coded into SQL."}),g.filters.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:8},children:g.filters.map(d=>e.jsxs("span",{style:St(r,!0),children:[_e(d)," · dynamic"]},d))})]}),e.jsx(xi,{source:t,kind:"semantic",onChange:p,t:r}),e.jsx(fe,{title:`Output fields${he.length?` · ${he.length}`:""}`,hint:"What consumers see when this block answers a question.",t:r,children:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:he.length>0?he.map(d=>e.jsx("span",{style:St(r,!0),children:_e(d)},d)):e.jsx("span",{style:{fontSize:11,color:r.textMuted},children:"Select metrics and dimensions to define outputs."})})}),e.jsx(fe,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:r,children:e.jsx(vt,{multiline:!0,value:Ie,onChange:d=>p(ci(t,"tests",d)),placeholder:`assert row_count >= 1
|
|
21
|
+
assert total_revenue >= 0`,style:{...ee,minHeight:64,resize:"vertical",fontFamily:r.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:r.textSecondary,fontFamily:r.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:r.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:r.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function yi({metadata:t,domains:n,onTextChange:i,onFolderChange:s,onTagsChange:l,t:a}){const p=$o(t==null?void 0:t.domain,n),y=en(a);return e.jsx(fe,{title:"Details",hint:"Name, ownership, and where this block lives.",t:a,children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx($,{label:"Block name",t:a,children:e.jsx("input",{value:(t==null?void 0:t.name)??"",onChange:x=>i("name",x.target.value),style:{...y,fontFamily:a.fontMono}})}),e.jsx($,{label:"Domain",t:a,children:e.jsxs("select",{"aria-label":"Block domain",value:(t==null?void 0:t.domain)??"",onChange:x=>i("domain",x.target.value),style:y,children:[e.jsx("option",{value:"",children:"Select domain…"}),p.map(x=>e.jsx("option",{value:x,children:x},x))]})}),e.jsx($,{label:"Owner",t:a,children:e.jsx("input",{value:(t==null?void 0:t.owner)??"",onChange:x=>i("owner",x.target.value),placeholder:"Required to save",style:y})}),e.jsx($,{label:"Tags",t:a,children:e.jsx(ui,{values:(t==null?void 0:t.tags)??[],onChange:l,placeholder:"finance, emea",style:y})}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx($,{label:"Folder (optional)",t:a,children:e.jsx("input",{"aria-label":"Block folder",value:(t==null?void 0:t.folderPath)??"",onChange:x=>s(x.target.value),placeholder:"executive/monthly",style:{...y,fontFamily:a.fontMono}})}),e.jsx("div",{style:{marginTop:5,fontSize:10,color:a.textMuted,fontFamily:a.fontMono},children:vi(t)})]}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx($,{label:"Description",t:a,children:e.jsx("input",{value:(t==null?void 0:t.description)??"",onChange:x=>i("description",x.target.value),placeholder:"What business question does this answer?",style:y})})})]})})}function ei(t,n){const i=n.trim().toLowerCase();return i.length<2?[]:t.filter(s=>[s.name,s.label,s.description,s.domain].filter(Boolean).some(l=>l.toLowerCase().includes(i))).slice(0,30)}function ti({kind:t,total:n,search:i,onSearchChange:s,matches:l,pool:a=[],selected:p,resolveLabel:y,resolveMachineName:x,reasonFor:k,onToggle:r,compatible:f=()=>!0,disabled:g=!1,emptyHint:I,t:P}){const[W,le]=c.useState(!1),E=c.useRef(null),j=c.useRef(null),S=t==="metric"?"measures":"dimensions",ie=t==="metric"?"Σ":"ab",V=t==="metric"?"var(--accent)":"var(--status-success)",J=t==="metric"?"var(--accent-dim)":"var(--status-success-bg)",A=i.trim().length>=2,Z=A?l:a.filter(M=>!p.includes(M.name)).slice(0,8),Q=()=>{le(!1),s("")};return c.useEffect(()=>{if(!W)return;requestAnimationFrame(()=>{var F;return(F=E.current)==null?void 0:F.focus()});const M=F=>{j.current&&!j.current.contains(F.target)&&Q()},K=F=>{F.key==="Escape"&&Q()};return document.addEventListener("mousedown",M),document.addEventListener("keydown",K),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",K)}},[W]),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:9},children:[p.map(M=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 9px",borderRadius:999,background:J,color:V,border:`1px solid ${t==="metric"?"rgba(107,93,211,0.2)":"rgba(46,139,87,0.25)"}`,fontFamily:P.fontMono},children:[t==="metric"?`Σ ${y(M)}`:y(M),e.jsx("button",{type:"button",onClick:()=>r(M),title:`Remove ${y(M)}`,style:{border:"none",background:"none",color:V,cursor:"pointer",padding:0,fontSize:12,lineHeight:1,fontFamily:"inherit"},children:"×"})]},M)),e.jsxs("span",{ref:j,style:{position:"relative"},children:[e.jsxs("button",{type:"button",disabled:g,onClick:()=>le(M=>!M),title:g?I:`Add ${t}`,style:{border:"1.5px dashed var(--border-strong)",background:"transparent",borderRadius:999,padding:"4px 10px",fontSize:11,fontFamily:P.font,color:g?P.textMuted:P.textSecondary,cursor:g?"not-allowed":"pointer",opacity:g?.6:1},children:["+ Add ",t]}),W&&!g?e.jsxs("div",{style:{position:"absolute",right:0,top:30,zIndex:40,width:300,background:P.cellBg,border:`1px solid ${P.headerBorder}`,borderRadius:10,boxShadow:"0 10px 30px rgba(26,26,26,0.14)",overflow:"hidden",animation:"dql-agent-fadein 0.12s ease-out"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"8px 10px",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx(uo,{size:12,color:P.textMuted,style:{flexShrink:0}}),e.jsx("input",{ref:E,value:i,onChange:M=>s(M.target.value),placeholder:`Search ${n.toLocaleString()} ${S}…`,style:{flex:1,border:"none",background:"none",outline:"none",fontSize:12,fontFamily:P.font,color:P.textPrimary,minWidth:0}}),e.jsx("button",{type:"button",onClick:Q,style:{border:"none",background:"none",color:P.textMuted,cursor:"pointer",padding:0,fontSize:13,lineHeight:1},children:"×"})]}),e.jsx("div",{style:{maxHeight:208,overflow:"auto"},children:Z.length===0?e.jsx("div",{style:{padding:10,fontSize:11,color:P.textMuted},children:A?`No ${S} match “${i}”.`:`No more ${S} to add.`}):Z.map(M=>{const K=p.includes(M.name),F=f(M.name),Y=(x==null?void 0:x(M.name))??M.name,de=Y!==(M.label||M.name),ee=F?void 0:(k==null?void 0:k(M.name))??"Not compatible with every selected metric";return e.jsxs("button",{type:"button",disabled:!F,onClick:()=>{r(M.name),K||Q()},title:ee??M.description??Y,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",background:K?J:"none",cursor:F?"pointer":"not-allowed",textAlign:"left",fontFamily:P.font,borderBottom:"1px solid var(--border-subtle)",opacity:F?1:.5},children:[e.jsx("span",{style:{flexShrink:0,width:16,height:16,borderRadius:4,background:J,color:V,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:t==="metric"?10:9,fontWeight:700,fontFamily:P.fontMono},children:ie}),e.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1,overflow:"hidden"},children:[e.jsx("span",{style:{fontSize:12,fontFamily:P.font,color:P.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M.label||M.name}),de?e.jsx("span",{style:{fontSize:10,fontFamily:P.fontMono,color:P.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Y}):null]}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:P.textMuted},children:M.domain||M.type||""})]},M.name)})}),e.jsx("div",{style:{padding:"6px 10px",background:"var(--bg-1)",fontSize:10,color:P.textMuted},children:A?`${Z.length} match${Z.length===1?"":"es"} · certified shown first`:`Showing top ${Z.length} of ${n.toLocaleString()} · type to search all`})]}):null]})]})}function Xo({mode:t,onModeChange:n,t:i}){const s=[{key:"semantic",label:"Semantic picker"},{key:"custom",label:"Raw SQL"}];return e.jsx("div",{style:{flexShrink:0,borderBottom:`1px solid ${i.headerBorder}`,background:i.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"10px 0",display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{fontSize:10.5,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted},children:"Query"}),e.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg},children:s.map(l=>{const a=l.key===t;return e.jsx("button",{type:"button",onClick:()=>n(l.key),style:{border:"none",borderRadius:6,padding:"5px 12px",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:i.font,background:a?"var(--accent-dim)":"transparent",color:a?i.accent:i.textMuted},children:l.label},l.key)})}),e.jsx("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.font},children:t==="semantic"?"Pick governed metrics & dimensions — they compile to DQL.":"Write SQL and convert it into a governed DQL script."})]})})}function Jo({source:t,metadata:n,domainOptions:i,chartConfig:s,onChange:l,onMetadataChange:a,onConvertToDql:p,t:y}){var le,E;const x=en(y),k=((E=(le=t.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:le[1])==null?void 0:E.trim())??"",[r,f]=c.useState(k),g=Si(r),I=di(t,"tests"),P=j=>{f(j),l(ai(t,j))},W=(j,S)=>{a({[j]:S}),l(j==="name"?yt(t,S):ae(t,j,S))};return e.jsx("div",{style:{height:"100%",overflow:"auto",background:y.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"24px 0 40px",display:"flex",flexDirection:"column",animation:"dql-agent-fadein 0.25s ease-out"},children:[e.jsx(yi,{metadata:n,domains:i,onTextChange:W,onFolderChange:j=>a({folderPath:j}),onTagsChange:j=>{a({tags:j}),l(bt(t,j))},t:y}),e.jsxs(fe,{title:"Query",hint:"Write raw SQL — it compiles into a governed DQL script.",t:y,children:[e.jsx("textarea",{rows:7,value:r,onChange:j=>P(j.target.value),spellCheck:!1,style:{border:"1px solid var(--border-default)",background:"var(--bg-1)",borderRadius:8,padding:"10px 12px",fontSize:11.5,lineHeight:1.6,fontFamily:y.fontMono,color:y.textPrimary,outline:"none",resize:"vertical"},placeholder:`SELECT
|
|
22
22
|
category,
|
|
23
23
|
SUM(revenue) AS revenue
|
|
24
24
|
FROM {{ ref('orders') }}
|
|
25
|
-
GROUP BY 1`}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",onClick:p,disabled:!r.trim(),style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 12px",borderRadius:8,border:`1px solid ${y.accent}`,background:"var(--accent-dim)",color:y.accent,fontSize:11.5,fontWeight:650,cursor:r.trim()?"pointer":"not-allowed",fontFamily:y.font,opacity:r.trim()?1:.6},children:"Convert to DQL script"}),e.jsxs("span",{style:{fontSize:10.5,color:y.textMuted,fontFamily:y.font},children:["Detects ",e.jsx("span",{style:{fontFamily:y.fontMono},children:"${params}"})," and grounds tables against dbt. Open the DQL Source editor for the full script."]})]})]}),e.jsxs(fe,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:y,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx(
|
|
26
|
-
assert revenue >= 0`,style:{...x,minHeight:64,resize:"vertical",fontFamily:y.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:y.textSecondary,fontFamily:y.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:y.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:y.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function Vo({semanticChoice:t,databaseWarning:n,onDismiss:i,onInsertAdvanced:o,onCreateSemantic:l,t:a}){const p=t?`${t.kind==="metric"?"Metric":"Dimension"} "${t.name}" belongs in a Semantic Block. SQL Blocks can still use advanced @metric/@dim refs when you choose that explicitly.`:n??"";return e.jsxs("div",{style:{padding:"10px 12px",borderBottom:`1px solid ${a.headerBorder}`,background:`${a.accent}10`,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:a.textSecondary,lineHeight:1.4,flex:1,minWidth:260},children:p}),t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:l,style:ne(a),children:"Create Semantic Block"}),e.jsx("button",{onClick:o,style:je(a),children:"Insert advanced ref"})]}),e.jsx("button",{onClick:i,style:ne(a),children:"Dismiss"})]})}function Xt(t){var i,o,l,a,p;const n=((o=(i=t.preview)==null?void 0:i.result)==null?void 0:o.rowCount)??((p=(a=(l=t.preview)==null?void 0:l.result)==null?void 0:a.rows)==null?void 0:p.length);return typeof n=="number"?n:void 0}function kt(t){return t?t.startsWith("blocks/_drafts/")||/^domains\/[^/]+\/blocks\/_drafts\//.test(t):!1}function Oe(t){var n,i,o,l,a;return t.reviewStatus==="saved"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"saved",rows:Xt(t),message:"Block saved."}:((n=t.validation)==null?void 0:n.valid)===!1?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:((i=t.validation.diagnostics.find(p=>p.severity==="error"))==null?void 0:i.message)??"DQL validation needs attention."}:t.preview?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",rows:Xt(t),savedPath:t.savedPath,message:kt(t.savedPath)?"Preview ran successfully. Draft is saved for review.":"Preview ran successfully. Nothing is written until you save."}:((o=t.draftSave)==null?void 0:o.status)==="saved"||kt(t.savedPath)?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",savedPath:((l=t.draftSave)==null?void 0:l.path)??t.savedPath,message:"Draft saved. Run preview, then certify when ready."}:((a=t.draftSave)==null?void 0:a.status)==="error"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:t.draftSave.error??"Draft preparation failed."}:{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"queued",message:"Ready to process."}}function Yo(t){return t==="retrieving"?"Checking certified blocks and semantic metrics.":t==="reviewing"?"Reviewing governed evidence and building the candidate.":t==="ready"?"Analysis ready. Preparing preview.":t==="needs_attention"?"Analysis needs attention.":"Queued for governed retrieval."}async function Xo(t,n){for(let i=0;i<240;i+=1){const o=await F.getDqlGenerationSession(t);if(n(o),o.candidates.every(l=>l.analysisStatus==="ready"||l.analysisStatus==="needs_attention"))return o;await new Promise(l=>window.setTimeout(l,500))}throw new Error("Import analysis is still running. You can leave this workspace and resume the session later.")}async function Jo(t,n,i){let o=0;const l=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;o<t.length;){const a=o;o+=1,await i(t[a])}});await Promise.all(l)}function Lt(t){return!!(t.generationMode||t.draftSave||kt(t.savedPath))}function Zo(t){return t==="creating"?"Reading SQL":t==="running"?"Running previews":t==="saving"?"Saving blocks":t==="complete"?"Import complete":"Ready"}function es(t){return t==="needs_attention"?"needs attention":t.replace("_"," ")}function ts(t){return t==="saved"||t==="ready"?"ok":t==="needs_attention"?"warn":"info"}function ns({session:t,sessions:n,sessionsLoading:i,onClose:o,onSessionChange:l,onRefreshSessions:a,onSelectCandidate:p,onSavedCandidate:y,defaultDomain:x,defaultOwner:k,themeMode:r,t:f,inline:g=!1}){const[M,P]=c.useState("paste"),[_,se]=c.useState(""),[$,j]=c.useState(""),[v,ie]=c.useState([]),[V,J]=c.useState(x),[E,Z]=c.useState(k),[H,I]=c.useState(null),[U,O]=c.useState(!1),[Y,de]=c.useState(!1),[ee,N]=c.useState(null),[re,D]=c.useState(null),[X,le]=c.useState(!1),[we,ke]=c.useState(!0),[ce,Te]=c.useState(""),[he,Pe]=c.useState(!1),[Re,ue]=c.useState({}),[We,d]=c.useState("idle"),[R,K]=c.useState({}),ge=c.useMemo(()=>t?t.candidates.find(m=>m.id===H)??t.candidates[0]??null:null,[t,H]);c.useEffect(()=>{if(!(t!=null&&t.candidates.length)){I(null);return}(!H||!t.candidates.some(m=>m.id===H))&&I(t.candidates[0].id)},[t,H]),c.useEffect(()=>{ue({})},[t==null?void 0:t.id]),c.useEffect(()=>{ke(!(t!=null&&t.candidates.length))},[t==null?void 0:t.id,t==null?void 0:t.candidates.length]),c.useEffect(()=>{if(!t){K({}),d("idle");return}K(Object.fromEntries(t.candidates.map(m=>[m.id,Oe(m)]))),d(m=>m==="idle"?"complete":m)},[t==null?void 0:t.id]);const be=c.useMemo(()=>{const m=ce.trim().toLowerCase(),T=(t==null?void 0:t.candidates)??[];return m?T.filter(w=>[w.name,w.domain,w.sourcePath,w.description,...w.lineage.sourceTables].some(C=>C.toLowerCase().includes(m))):T},[ce,t]),Le=he||ce.trim()?be:be.slice(0,10),pe=((t==null?void 0:t.candidates.map(m=>R[m.id]??Oe(m)))??[]).reduce((m,T)=>(T.status==="saved"?m.saved+=1:T.status==="ready"?m.ready+=1:T.status==="needs_attention"?m.attention+=1:m.processing+=1,m),{saved:0,ready:0,attention:0,processing:0}),Ce=t?pe.saved>0?3:2:1,Ze=(t==null?void 0:t.candidates.filter(m=>{var T;return((T=m.validation)==null?void 0:T.valid)!==!1}).length)??0,$e=!!(M==="paste"?$.trim():M==="upload"?v.length>0:_.trim()),qe=()=>M==="paste"?{inputMode:"paste",sourceKind:"raw-sql",domain:V,owner:E,sources:[{path:"pasted.sql",content:$}],async:!0,persistence:"session-only"}:M==="upload"?{inputMode:"upload",sourceKind:"raw-sql",domain:V,owner:E,sources:v,async:!0,persistence:"session-only"}:{path:_,inputMode:"path",sourceKind:"raw-sql",domain:V,owner:E,async:!0,persistence:"session-only"},Ne=async()=>{var m,T,w;O(!0),de(!0),N(null),ue({}),K({}),d("creating");try{const C=await F.createDqlGenerationSession(qe());let q=C,oe=Object.fromEntries(C.candidates.map(z=>[z.id,{...Oe(z),status:"queued",message:"Queued for governed retrieval."}]));const h=(z,A)=>{oe={...oe,[z]:A(oe[z])},K(oe)},B=z=>{q={...q,candidates:q.candidates.map(A=>A.id===z.id?z:A)},l(q)};l(q),I(((m=q.candidates[0])==null?void 0:m.id)??null),K(oe),await a(),d("running"),q=await Xo(C.id,z=>{q=z,l(z);for(const A of z.candidates)h(A.id,xe=>({...xe,name:A.name,sourcePath:A.sourcePath,status:A.analysisStatus==="needs_attention"?"needs_attention":A.analysisStatus==="ready"?"queued":"running",message:Yo(A.analysisStatus)}))}),await Jo(q.candidates,2,async z=>{if(z.analysisStatus!=="needs_attention"){h(z.id,A=>({...A,status:"running",message:"Running preview."}));try{const A=await F.previewDqlGenerationCandidate(q.id,z.id);B(A),h(z.id,xe=>{var G;return{...xe,name:A.name,sourcePath:A.sourcePath,status:"ready",rows:Xt(A),savedPath:((G=A.draftSave)==null?void 0:G.path)??A.savedPath,message:A.recommendedAction==="reuse_existing"?"A governed block already answers this SQL. Reuse it instead of saving a duplicate.":"Preview ran successfully. Nothing is written until you save."}})}catch(A){const xe=(A==null?void 0:A.message)??"Preview failed.";ue(G=>({...G,[z.id]:xe})),h(z.id,G=>({...G,status:"needs_attention",message:xe}))}}}),l(q),I(((T=q.candidates.find(z=>z.reviewStatus!=="rejected"))==null?void 0:T.id)??((w=q.candidates[0])==null?void 0:w.id)??null),await a(),d("complete")}catch(C){N((C==null?void 0:C.message)??"Import failed."),d("idle")}finally{O(!1),de(!1)}},et=async m=>{var T,w;O(!0),N(null);try{const C=await F.getDqlGenerationSession(m).catch(()=>F.getBlockStudioImport(m));l(C),I(((T=C.candidates.find(q=>q.reviewStatus!=="saved"&&q.reviewStatus!=="rejected"))==null?void 0:T.id)??((w=C.candidates[0])==null?void 0:w.id)??null),ue({}),d("complete")}catch(C){N((C==null?void 0:C.message)??"Failed to resume import session.")}finally{O(!1)}},He=async m=>{D({kind:"one",id:m})},Qe=async()=>{n.length!==0&&D({kind:"all"})},Ue=async()=>{if(!re)return;const m=re;O(!0),N(null);try{m.kind==="one"?await F.deleteBlockStudioImport(m.id):await F.clearBlockStudioImports(),(m.kind==="all"||(t==null?void 0:t.id)===m.id)&&(l(null),I(null)),D(null),await a()}catch(T){N((T==null?void 0:T.message)??"Failed to update import history.")}finally{O(!1)}},Ie=m=>{t&&(l({...t,candidates:t.candidates.map(T=>T.id===m.id?m:T)}),K(T=>({...T,[m.id]:Oe(m)})))},Ke=async m=>{if(t){O(!0),N(null),ue(T=>{if(!T[m.id])return T;const w={...T};return delete w[m.id],w});try{const T=Lt(m)?await F.previewDqlGenerationCandidate(t.id,m.id):await F.runBlockStudioImportCandidate(t.id,m.id);Ie(T),I(T.id),ue(w=>{if(!w[m.id])return w;const C={...w};return delete C[m.id],C})}catch(T){const w=(T==null?void 0:T.message)??"Candidate run failed.";N(w),I(m.id),ue(C=>({...C,[m.id]:w}))}finally{O(!1)}}},tt=async m=>{if(!t)return;const T=m.owner.trim()||E.trim();if(!T){N("Owner is required before a block can be saved or certified.");return}O(!0),N(null);try{if(Lt(m)){const w=await F.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:[m.id],owner:T});l(w.session);const C=w.results[0];if(!C||C.status==="error")throw new Error((C==null?void 0:C.error)??(C==null?void 0:C.blockers.join(" "))??"Candidate save failed.");C.candidate&&Ie(C.candidate),C.candidate&&C.block&&y(C.candidate,C.block),C.status==="draft"&&C.blockers.length>0&&N(`Saved as draft: ${C.blockers.join(" ")}`)}else{const w=await F.saveBlockStudioImportCandidate(t.id,m.id);Ie(w.candidate),y(w.candidate,w.block)}await a()}catch(w){const C=(w==null?void 0:w.message)??"Candidate save failed.";N(C.includes("409")||C.includes("already exists")?"A block with this name already exists. Rename this candidate, then save again.":C)}finally{O(!1)}},Ge=async()=>{if(!t)return;const m=E.trim()||t.defaults.owner.trim();if(!m){N("Owner is required before blocks can be saved or certified.");return}de(!0),N(null);try{const T=t.candidates.filter(B=>B.reviewStatus!=="rejected"&&B.analysisStatus!=="needs_attention").map(B=>B.id),w=await F.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:T,owner:m});l(w.session);const C=new Map(w.results.filter(B=>B.status==="error").map(B=>[B.candidateId,B.error??B.blockers.join(" ")])),q=new Map(w.results.filter(B=>B.path).map(B=>[B.candidateId,B.path]));K(Object.fromEntries(w.session.candidates.map(B=>{const z=C.get(B.id),A=q.get(B.id)??B.savedPath;return z?[B.id,{...Oe(B),status:"needs_attention",message:z.includes("409")||z.includes("already exists")?"A block with this name already exists. Rename it in advanced details, then save again.":z}]:A||B.reviewStatus==="saved"?[B.id,{...Oe(B),status:"saved",savedPath:A,message:"Block saved."}]:[B.id,Oe(B)]}))),await a();const oe=w.results.filter(B=>B.status==="error").length,h=w.results.filter(B=>B.status==="draft").length;(oe>0||h>0)&&N(`${w.results.length-oe} saved. ${h} stayed draft; ${oe} need attention.`)}catch(T){N((T==null?void 0:T.message)??"Save all failed.")}finally{de(!1)}},Ve=async m=>{if(!t)return;const T=await F.updateBlockStudioImportCandidate(t.id,m.id,{reviewStatus:"rejected"});Ie(T),a()},nt=async m=>{const w=Array.from(m??[]).filter(q=>q.name.toLowerCase().endsWith(".sql")),C=await Promise.all(w.map(async q=>({path:q.name,content:await q.text()})));ie(C),C.length>0&&se("")};return e.jsxs("div",{style:{position:"relative",height:"100%",display:"grid",gridTemplateRows:"80px minmax(0, 1fr)",minHeight:0,background:f.appBg,borderRadius:g?0:8},children:[e.jsxs("header",{style:{borderBottom:`1px solid ${f.headerBorder}`,background:f.cellBg,padding:"14px 14px 12px",display:"flex",alignItems:"center",gap:14,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:260},children:[e.jsx("span",{style:{width:34,height:34,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",color:f.accent,background:`${f.accent}16`,flexShrink:0},children:e.jsx(Yt,{size:17,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Import SQL to DQL"}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"SQL source to AI-grounded drafts to review and certify"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(130px, 1fr))",gap:6,width:"min(560px, 44vw)",minWidth:390},children:[e.jsx(Ut,{index:1,active:Ce===1,complete:!!t,title:"Source",detail:M==="paste"?"Paste SQL":M==="upload"?"Upload files":"Local path",t:f}),e.jsx(Ut,{index:2,active:Ce===2,complete:pe.ready>0||pe.saved>0,title:"Draft",detail:t?`${t.candidates.length} blocks · ${Ze} ready`:"Generate DQL",t:f}),e.jsx(Ut,{index:3,active:Ce===3,complete:pe.saved>0,title:"Review",detail:pe.saved>0?`${pe.saved} certified`:"Preview and certify",t:f})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:o,title:"Close import","aria-label":"Close import",style:{...ne(f),width:32,height:32,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(wo,{size:15,strokeWidth:2,"aria-hidden":"true"})})]}),e.jsxs("div",{style:{minHeight:0,display:"grid",gridTemplateColumns:"300px minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${f.headerBorder}`,display:"grid",gridTemplateRows:"auto minmax(0, 1fr) auto",minHeight:0,background:f.cellBg},children:[e.jsxs("section",{style:{borderBottom:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:10},children:[e.jsxs("button",{onClick:()=>ke(m=>!m),style:{background:"transparent",border:"none",color:f.textPrimary,cursor:"pointer",display:"flex",alignItems:"center",gap:8,padding:0,fontFamily:f.font,textAlign:"left"},children:[e.jsx(ui,{size:14,strokeWidth:2,color:f.accent,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:12,fontWeight:800,flex:1},children:"Source"}),t&&e.jsx("span",{style:{fontSize:10,color:f.textMuted},children:we?"Hide":"Edit"})]}),we?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:4},children:["paste","upload","path"].map(m=>e.jsx("button",{onClick:()=>P(m),style:{...ne(f),padding:"6px 4px",color:M===m?f.accent:f.textSecondary,borderColor:M===m?f.accent:f.btnBorder,background:M===m?`${f.accent}14`:f.btnBg},children:m==="paste"?"Paste SQL":m==="upload"?"Upload files":"Local path"},m))}),M==="path"&&e.jsx(L,{label:"Path",t:f,children:e.jsx("input",{value:_,onChange:m=>{se(m.target.value),m.target.value.trim()&&ie([])},placeholder:"./queries or ./legacy.sql",style:Se(f)})}),M==="upload"&&e.jsxs(L,{label:"Upload SQL files",t:f,children:[e.jsx("input",{type:"file",multiple:!0,accept:".sql,text/sql,text/plain",onChange:m=>void nt(m.target.files),style:Se(f)}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font},children:v.length>0?`${v.length} SQL file(s) ready`:"Choose one or more SQL files."})]}),M==="paste"&&e.jsx(L,{label:"Paste SQL",t:f,children:e.jsx("textarea",{value:$,onChange:m=>j(m.target.value),placeholder:`select ...; go
|
|
27
|
-
select ...`,style:{...Se(f),minHeight:t?86:150,resize:"vertical",fontFamily:f.fontMono}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(L,{label:"Domain",t:f,children:e.jsx("input",{value:V,onChange:m=>J(m.target.value),placeholder:"auto",style:Se(f)})}),e.jsx(L,{label:"Owner",t:f,children:e.jsx("input",{value:E,onChange:m=>Z(m.target.value),placeholder:"analytics",style:Se(f)})})]}),e.jsx("button",{onClick:()=>void Ne(),disabled:U||!$e,style:{...je(f),padding:"8px 12px",opacity:U||!$e?.65:1,cursor:U||!$e?"not-allowed":"pointer"},children:U?Zo(We):"Generate DQL drafts"}),e.jsx("div",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,lineHeight:1.45},children:"Uses dbt, MetricFlow, warehouse catalog, and existing DQL context when available."})]}):e.jsxs("button",{onClick:()=>ke(!0),style:{...ne(f),display:"grid",gap:4,textAlign:"left",width:"100%",justifyItems:"start"},children:[e.jsx("span",{style:{fontSize:11,color:f.textSecondary},children:M==="paste"?"Pasted SQL":M==="upload"?"Uploaded files":"Local path"}),e.jsx("span",{style:{maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:f.textMuted,fontFamily:f.fontMono},children:(t==null?void 0:t.inputPath)??(M==="paste"?"pasted.sql":M==="upload"?`${v.length} file(s)`:_||"./queries")})]})]}),e.jsx("section",{style:{minHeight:0,overflow:"auto",padding:12,display:"grid",alignContent:"start",gap:10},children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Drafts"}),e.jsx(ye,{label:`${t.candidates.length}`,tone:"info",t:f}),pe.ready>0&&e.jsx(ye,{label:`${pe.ready} ready`,tone:"ok",t:f}),pe.attention>0&&e.jsx(ye,{label:`${pe.attention} attention`,tone:"warn",t:f})]}),t.candidates.length>6&&e.jsx("input",{value:ce,onChange:m=>Te(m.target.value),placeholder:"Search drafts, tables, files...",style:Se(f)})]}),Le.map(m=>{var h,B,z,A,xe,G,Be,it;const T=m.id===(ge==null?void 0:ge.id),w=m.warnings??m.lineage.warnings,C=Re[m.id],q=((B=(h=m.preview)==null?void 0:h.result)==null?void 0:B.rowCount)??((xe=(A=(z=m.preview)==null?void 0:z.result)==null?void 0:A.rows)==null?void 0:xe.length),oe=R[m.id]??Oe(m);return e.jsxs("button",{onClick:()=>{I(m.id)},style:{border:`1px solid ${T?f.accent:C?"#f8514955":f.headerBorder}`,borderRadius:8,background:T?`${f.accent}10`:f.appBg,color:f.textPrimary,padding:10,display:"grid",gap:6,textAlign:"left",cursor:"pointer",minWidth:0},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{minWidth:0,flex:1,fontSize:12,fontWeight:800,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.name}),e.jsx(ye,{label:es(oe.status),tone:ts(oe.status),t:f})]}),e.jsxs("span",{style:{fontSize:10,color:f.textMuted,fontFamily:f.fontMono,overflowWrap:"anywhere"},children:[m.lineage.statementIndex,"/",m.lineage.totalStatements," · ",m.sourcePath]}),e.jsxs("span",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[e.jsx(ye,{label:((G=m.draftSave)==null?void 0:G.status)==="saved"||kt(m.savedPath)?"draft saved":m.reviewStatus,tone:m.reviewStatus==="rejected"?"warn":"info",t:f}),e.jsx(ye,{label:((Be=m.validation)==null?void 0:Be.valid)===!1?"fix":"valid",tone:((it=m.validation)==null?void 0:it.valid)===!1?"warn":"ok",t:f}),typeof q=="number"&&e.jsx(ye,{label:`${q} rows`,tone:"ok",t:f}),w.length>0&&e.jsx(ye,{label:`${w.length} warning`,tone:"warn",t:f})]}),(C||oe.message)&&e.jsx("span",{style:{fontSize:11,color:C?"#f85149":f.textMuted,lineHeight:1.35,overflowWrap:"anywhere"},children:C??oe.message})]},m.id)}),!he&&!ce.trim()&&be.length>10&&e.jsxs("button",{onClick:()=>Pe(!0),style:ne(f),children:["Show all ",be.length," drafts"]}),!t.candidates.some(Lt)&&pe.ready>0&&e.jsx("button",{onClick:()=>void Ge(),disabled:Y,style:je(f),children:Y?"Saving...":"Save valid blocks"})]}):e.jsx("div",{style:{fontSize:12,color:f.textMuted,lineHeight:1.5},children:"Paste SQL, upload files, or choose a local path. Analysis stays in this session until you save a block."})}),e.jsxs("details",{open:X,onToggle:m=>le(m.currentTarget.open),style:{borderTop:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:8},children:[e.jsxs("summary",{style:{cursor:"pointer",color:f.textSecondary,fontSize:11,fontWeight:800,fontFamily:f.font},children:["Import history",n.length>0?` (${n.length})`:""]}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:8},children:[e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>void a(),style:ne(f),children:"Refresh"}),n.length>0&&e.jsx("button",{onClick:()=>void Qe(),style:ne(f),children:"Clear"})]}),i?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"Loading..."}):n.length===0?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"No saved import sessions."}):e.jsx("div",{style:{display:"grid",gap:6,maxHeight:140,overflow:"auto"},children:n.slice(0,6).map(m=>e.jsxs("div",{style:{border:`1px solid ${(t==null?void 0:t.id)===m.id?f.accent:f.btnBorder}`,borderRadius:8,background:(t==null?void 0:t.id)===m.id?`${f.accent}10`:f.btnBg,display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",overflow:"hidden"},children:[e.jsxs("button",{onClick:()=>void et(m.id),style:{background:"transparent",border:"none",color:f.textSecondary,cursor:"pointer",fontFamily:f.font,padding:"8px 9px",textAlign:"left",display:"grid",gap:3,minWidth:0},children:[e.jsxs("span",{style:{fontSize:11},children:[m.candidateCount," drafts · ",m.savedCount," certified"]}),e.jsx("span",{style:{fontSize:10,color:f.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.inputPath})]}),e.jsx("button",{onClick:()=>void He(m.id),title:"Delete local import session",style:{background:"transparent",border:"none",borderLeft:`1px solid ${f.headerBorder}`,color:f.textMuted,cursor:"pointer",fontFamily:f.font,padding:"0 8px",fontSize:11,fontWeight:700},children:"Delete"})]},m.id))})]})]})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,overflow:"auto",padding:20,background:f.appBg},children:[ee&&e.jsx("div",{role:"alert",style:{padding:"10px 12px",color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,marginBottom:12,fontSize:12},children:ee}),!t||!ge?e.jsx(ss,{t:f}):e.jsx(os,{session:t,candidate:ge,loading:U,onCandidateUpdated:Ie,onRun:Ke,onSave:tt,onReject:Ve,onReviewInEditor:p,runError:Re[ge.id]??null,themeMode:r,t:f})]})]}),re&&e.jsx(is,{t:f,busy:U,title:re.kind==="all"?"Clear import history?":"Delete import preview?",message:re.kind==="all"?`This removes ${n.length} local import preview${n.length===1?"":"s"} from .dql/imports. Saved blocks stay in the project.`:"This removes the selected local import preview from .dql/imports. Saved blocks stay in the project.",confirmLabel:re.kind==="all"?"Clear history":"Delete preview",onCancel:()=>D(null),onConfirm:()=>void Ue()})]})}function is({title:t,message:n,confirmLabel:i,busy:o,onCancel:l,onConfirm:a,t:p}){return e.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(0, 0, 0, 0.22)",display:"flex",alignItems:"center",justifyContent:"center",padding:20,zIndex:20},children:e.jsxs("div",{style:{width:"min(420px, 92vw)",background:p.cellBg,color:p.textPrimary,border:`1px solid ${p.headerBorder}`,borderRadius:8,boxShadow:"0 18px 48px rgba(0, 0, 0, 0.30)",padding:16,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,fontFamily:p.font},children:t}),e.jsx("div",{style:{fontSize:12,color:p.textMuted,lineHeight:1.5,fontFamily:p.font},children:n}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{onClick:l,disabled:o,style:ne(p),children:"Cancel"}),e.jsx("button",{onClick:a,disabled:o,style:{...je(p),opacity:o?.65:1},children:o?"Working...":i})]})]})})}function os({session:t,candidate:n,loading:i,onCandidateUpdated:o,onRun:l,onSave:a,onReject:p,onReviewInEditor:y,runError:x,themeMode:k,t:r}){var qe,Ne,et,He,Qe,Ue,Ie,Ke,tt,Ge,Ve,nt,m,T,w,C,q,oe;const[f,g]=c.useState(n.name),[M,P]=c.useState(n.domain),[_,se]=c.useState(n.owner),[$,j]=c.useState(n.description),[v,ie]=c.useState(n.tags.join(", ")),[V,J]=c.useState((n.terms??[]).join(", ")),[E,Z]=c.useState(n.pattern??""),[H,I]=c.useState(n.grain??""),[U,O]=c.useState((n.entities??[]).join(", ")),[Y,de]=c.useState((n.outputs??[]).join(", ")),[ee,N]=c.useState((n.dimensions??[]).join(", ")),[re,D]=c.useState((n.allowedFilters??[]).join(", ")),[X,le]=c.useState((n.sourceSystems??[]).join(", ")),[we,ke]=c.useState((n.replacementFor??[]).join(", ")),[ce,Te]=c.useState(n.reviewCadence??"monthly"),[he,Pe]=c.useState(n.sql),[Re,ue]=c.useState(null),[We,d]=c.useState(null),[R,K]=c.useState(!1);c.useEffect(()=>{g(n.name),P(n.domain),se(n.owner),j(n.description),ie(n.tags.join(", ")),J((n.terms??[]).join(", ")),Z(n.pattern??""),I(n.grain??""),O((n.entities??[]).join(", ")),de((n.outputs??[]).join(", ")),N((n.dimensions??[]).join(", ")),D((n.allowedFilters??[]).join(", ")),le((n.sourceSystems??[]).join(", ")),ke((n.replacementFor??[]).join(", ")),Te(n.reviewCadence??"monthly"),Pe(n.sql),d(null),K(!1)},[n.id,n.name,n.domain,n.owner,n.description,n.tags,n.terms,n.pattern,n.grain,n.entities,n.outputs,n.dimensions,n.allowedFilters,n.sourceSystems,n.replacementFor,n.reviewCadence,n.sql]);const ge=async()=>{d(null);try{const h={name:f,domain:M,owner:_,description:$,tags:v.split(",").map(z=>z.trim()).filter(Boolean),terms:V.split(",").map(z=>z.trim()).filter(Boolean),pattern:E,grain:H,entities:U.split(",").map(z=>z.trim()).filter(Boolean),outputs:Y.split(",").map(z=>z.trim()).filter(Boolean),dimensions:ee.split(",").map(z=>z.trim()).filter(Boolean),allowedFilters:re.split(",").map(z=>z.trim()).filter(Boolean),sourceSystems:X.split(",").map(z=>z.trim()).filter(Boolean),replacementFor:we.split(",").map(z=>z.trim()).filter(Boolean),reviewCadence:ce,sql:he,llmContext:n.llmContext},B=Lt(n)?await F.updateDqlGenerationCandidate(t.id,n.id,h):await F.updateBlockStudioImportCandidate(t.id,n.id,h);o(B)}catch(h){d((h==null?void 0:h.message)??"Could not update candidate.")}},be=async h=>{ue(h),d(null);try{const B=await F.assistBlockStudioImportCandidate(t.id,n.id,h);o(B)}catch(B){d((B==null?void 0:B.message)??"AI assist failed.")}finally{ue(null)}},Le=n.warnings??n.lineage.warnings,te=Se(r),pe=((Ne=(qe=n.preview)==null?void 0:qe.result)==null?void 0:Ne.rowCount)??((Qe=(He=(et=n.preview)==null?void 0:et.result)==null?void 0:He.rows)==null?void 0:Qe.length),Ce=((Ue=n.draftSave)==null?void 0:Ue.path)??(kt(n.savedPath)?n.savedPath:void 0),Ze=n.recommendedAction==="reuse_existing"||((Ie=n.draftSave)==null?void 0:Ie.status)==="skipped",$e=n.lineage.sourceTables.length+(((Ke=n.evidence)==null?void 0:Ke.length)??0)+n.lineage.parameters.length+Le.length;return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{style:{fontSize:18,fontWeight:800,color:r.textPrimary},children:n.name}),e.jsxs("div",{style:{fontSize:11,color:r.textMuted,fontFamily:r.fontMono,marginTop:3},children:[n.sourcePath," · statement ",n.lineage.statementIndex,"/",n.lineage.totalStatements]})]}),e.jsx("button",{onClick:()=>void l(n),disabled:i,style:ne(r),children:i?"Running...":"Preview"}),e.jsx("button",{onClick:()=>K(h=>!h),style:R?je(r):ne(r),children:R?"Hide context":`Show context${$e>0?` (${$e})`:""}`}),e.jsx("button",{onClick:()=>y(n),style:je(r),children:"Edit full DQL"}),e.jsx("button",{onClick:()=>void a(n),disabled:i||n.reviewStatus==="saved"||Ze,style:je(r),children:Ze?"Reuse existing":n.reviewStatus==="saved"?"Certified":"Save block"})]}),We&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",borderRadius:8,padding:10},children:We}),x&&e.jsxs("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,padding:10,lineHeight:1.45,overflowWrap:"anywhere"},children:["Preview failed: ",x]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(ye,{label:((tt=n.draftSave)==null?void 0:tt.status)==="skipped"?"reuse recommended":((Ge=n.draftSave)==null?void 0:Ge.status)==="saved"||Ce?"draft saved":n.reviewStatus,tone:n.reviewStatus==="rejected"?"warn":((Ve=n.draftSave)==null?void 0:Ve.status)==="skipped"?"ok":"info",t:r}),e.jsx(ye,{label:`${Math.round(n.confidence*100)}% confidence`,tone:"info",t:r}),e.jsx(ye,{label:((nt=n.validation)==null?void 0:nt.valid)===!1?"needs fixes":"valid",tone:((m=n.validation)==null?void 0:m.valid)===!1?"warn":"ok",t:r}),typeof pe=="number"&&e.jsx(ye,{label:`${pe} rows`,tone:"ok",t:r})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:R?"minmax(0, 1fr) minmax(320px, 380px)":"minmax(0, 1fr)",gap:12,alignItems:"start"},children:[e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs(fe,{title:"Review details",t:r,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(L,{label:"Name",t:r,children:e.jsx("input",{value:f,onChange:h=>g(h.target.value),style:te})}),e.jsx(L,{label:"Domain",t:r,children:e.jsx("input",{value:M,onChange:h=>P(h.target.value),style:te})}),e.jsx(L,{label:"Owner",t:r,children:e.jsx("input",{value:_,onChange:h=>se(h.target.value),style:te})}),e.jsx(L,{label:"Tags",t:r,children:e.jsx("textarea",{value:v,onChange:h=>ie(h.target.value),style:{...te,minHeight:58,resize:"vertical"}})})]}),e.jsx(L,{label:"Business description",t:r,children:e.jsx("textarea",{value:$,onChange:h=>j(h.target.value),style:{...te,minHeight:70,resize:"vertical"}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:8},children:[e.jsx(L,{label:"Pattern",t:r,children:e.jsx("select",{value:E,onChange:h=>Z(h.target.value),style:te,children:["custom","metric_wrapper","entity_profile","entity_rollup","ranking","trend","bridge","drilldown","replacement"].map(h=>e.jsx("option",{value:h,children:h},h))})}),e.jsx(L,{label:"Grain",t:r,children:e.jsx("input",{value:H,onChange:h=>I(h.target.value),style:te})}),e.jsx(L,{label:"Review cadence",t:r,children:e.jsx("select",{value:ce,onChange:h=>Te(h.target.value),style:te,children:["weekly","monthly","quarterly","semiannual","annual"].map(h=>e.jsx("option",{value:h,children:h},h))})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(L,{label:"Entities",t:r,children:e.jsx("input",{value:U,onChange:h=>O(h.target.value),style:te})}),e.jsx(L,{label:"Outputs",t:r,children:e.jsx("input",{value:Y,onChange:h=>de(h.target.value),style:te})}),e.jsx(L,{label:"Dimensions",t:r,children:e.jsx("input",{value:ee,onChange:h=>N(h.target.value),style:te})}),e.jsx(L,{label:"Allowed filters",t:r,children:e.jsx("input",{value:re,onChange:h=>D(h.target.value),style:te})}),e.jsx(L,{label:"Source systems",t:r,children:e.jsx("input",{value:X,onChange:h=>le(h.target.value),style:te})}),e.jsx(L,{label:"Terms",t:r,children:e.jsx("input",{value:V,onChange:h=>J(h.target.value),style:te})})]}),e.jsx(L,{label:"Replaces",t:r,children:e.jsx("input",{value:we,onChange:h=>ke(h.target.value),style:te})}),e.jsx("button",{onClick:()=>void ge(),style:{...je(r),justifySelf:"start"},children:"Apply edits"})]}),n.preview&&e.jsxs(fe,{title:"Preview Results",t:r,children:[e.jsxs("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.45},children:["Query ran successfully",typeof pe=="number"?` and returned ${pe} rows`:"","."]}),e.jsx("div",{style:{maxHeight:320,overflow:"auto",border:`1px solid ${r.headerBorder}`,borderRadius:8},children:e.jsx(ai,{result:n.preview.result,themeMode:k})})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Original SQL"}),e.jsx("textarea",{value:he,onChange:h=>Pe(h.target.value),style:{...te,minHeight:210,fontFamily:r.fontMono,resize:"vertical",marginTop:10}})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Draft DQL block"}),e.jsx("pre",{style:{margin:"10px 0 0",whiteSpace:"pre-wrap",fontSize:11,lineHeight:1.45,color:r.textSecondary,fontFamily:r.fontMono},children:n.dqlSource})]})]}),R&&e.jsxs("div",{style:{display:"grid",gap:12},children:[(((T=n.similarityMatches)==null?void 0:T.length)||((w=n.draftSave)==null?void 0:w.status)==="skipped")&&e.jsx(fe,{title:"Reuse recommendation",t:r,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsx(st,{label:"Action",value:n.recommendedAction??"create_new",t:r}),((C=n.draftSave)==null?void 0:C.reason)&&e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.4},children:n.draftSave.reason}),(n.similarityMatches??[]).slice(0,3).map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:r.textSecondary,overflowWrap:"anywhere"},children:h.name}),e.jsxs("div",{style:{fontSize:10,color:r.textMuted,marginTop:3},children:[h.kind," · ",Math.round(h.score*100),"% · ",h.recommendedAction]}),e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.reason})]},`${h.objectKey??h.name}-${B}`))]})}),(((q=n.parameterDecisions)==null?void 0:q.length)||((oe=n.filterBindings)==null?void 0:oe.length))&&e.jsx(fe,{title:"Parameter contract",t:r,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[(n.parameterDecisions??[]).slice(0,8).map(h=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:11,fontWeight:800,color:r.textSecondary},children:h.name}),e.jsx("span",{style:{fontSize:10,color:r.textMuted},children:h.policy})]}),e.jsxs("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:[h.sourceExpression," = ",String(h.value)]}),e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.reason})]},h.name)),(n.filterBindings??[]).length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:(n.filterBindings??[]).map(h=>e.jsx(ye,{label:`${h.filter} -> ${h.binding}`,tone:"info",t:r},h.filter))})]})}),e.jsxs(fe,{title:"Grounding",t:r,children:[e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Source tables"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.sourceTables.length?n.lineage.sourceTables.map(h=>e.jsx(ye,{label:h,tone:"info",t:r},h)):e.jsx("span",{style:{fontSize:12,color:r.textMuted},children:"None detected"})})]}),(n.evidence??[]).length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Context used"}),(n.evidence??[]).slice(0,5).map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:r.textSecondary,overflowWrap:"anywhere"},children:h.name}),e.jsxs("div",{style:{fontSize:10,color:r.textMuted,marginTop:3},children:[h.kind,h.reason?` · ${h.reason}`:""]}),h.description&&e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.description})]},`${h.objectKey??h.name}-${B}`))]}),e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Parameters"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.parameters.length?n.lineage.parameters.map(h=>e.jsx(ye,{label:h,tone:"warn",t:r},h)):e.jsx("span",{style:{fontSize:12,color:r.textMuted},children:"None detected"})})]}),Le.length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Warnings"}),Le.map((h,B)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:h},B))]})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Generation audit"}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:10},children:[e.jsx(st,{label:"Method",value:n.generationMode==="ai"?`AI-assisted local generation (${n.generationProvider??"configured provider"})`:"Deterministic local generation",t:r}),Ce&&e.jsx(st,{label:"Draft path",value:Ce,t:r}),e.jsx(st,{label:"Default test",value:"assert row_count > 0",t:r}),e.jsx(st,{label:"Split strategy",value:n.splitStrategy??"semicolon-go",t:r}),n.llmContext&&e.jsx(st,{label:"Agent use",value:n.llmContext,t:r}),(n.conversionNotes??[]).map((h,B)=>e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.4},children:h},B))]})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"AI refine tools"}),e.jsxs("div",{style:{display:"grid",gap:10,marginTop:10},children:[e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.45},children:"Use these only when the generated draft needs a targeted improvement before certification."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[["explain","Explain"],["fix-validation","Fix validation"],["infer-chart","Infer chart"],["propose-tests","Propose tests"]].map(([h,B])=>e.jsx("button",{onClick:()=>void be(h),disabled:!!Re,style:ne(r),children:Re===h?"Working...":B},h))}),(n.aiAssistance??[]).length>0&&e.jsx("div",{style:{display:"grid",gap:8},children:(n.aiAssistance??[]).slice().reverse().map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:8,padding:9,background:r.appBg},children:[e.jsxs("div",{style:{fontSize:10,color:r.textMuted,fontWeight:800,textTransform:"uppercase"},children:[h.action," · ",h.status]}),e.jsx("div",{style:{fontSize:12,color:r.textSecondary,lineHeight:1.45,marginTop:5},children:h.summary})]},`${h.createdAt}-${B}`))})]})]}),e.jsx("button",{onClick:()=>void p(n),disabled:n.reviewStatus==="rejected",style:{...ne(r),justifySelf:"start"},children:n.reviewStatus==="rejected"?"Rejected":"Reject draft"})]})]})]})}function Ut({index:t,active:n,complete:i,title:o,detail:l,t:a}){const p=i?"#2ea043":n?a.accent:a.textMuted;return e.jsxs("div",{style:{border:`1px solid ${n?a.accent:a.headerBorder}`,borderRadius:8,padding:"9px 10px",display:"grid",gridTemplateColumns:"24px minmax(0, 1fr)",gap:8,alignItems:"center",background:n?`${a.accent}10`:a.cellBg},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${p}18`,color:p,fontSize:11,fontWeight:800,fontFamily:a.font},children:i?"✓":t}),e.jsxs("span",{style:{minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:12,fontWeight:700,color:a.textPrimary,fontFamily:a.font},children:o}),e.jsx("span",{style:{display:"block",fontSize:10,color:a.textMuted,fontFamily:a.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l})]})]})}function ss({t}){const n=[["1","Add SQL","Paste SQL, upload files, or point to an enterprise SQL folder."],["2","Generate drafts","DQL analyzes statements, project metadata, tables, and business context."],["3","Review and certify","Preview results, edit metadata, then certify the governed block."]];return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(lt,{message:"Add SQL to analyze DQL candidates without creating block files."}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:n.map(([i,o,l])=>e.jsxs("div",{style:{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.appBg,padding:12,display:"grid",gap:6},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${t.accent}18`,color:t.accent,fontSize:11,fontWeight:800,fontFamily:t.font},children:i}),e.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary,fontFamily:t.font},children:o}),e.jsx("span",{style:{fontSize:11,color:t.textMuted,fontFamily:t.font,lineHeight:1.4},children:l})]},o))})]})}function L({label:t,children:n,t:i}){return e.jsxs("label",{style:{display:"grid",gap:5},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,color:i.textMuted,letterSpacing:"0.05em",textTransform:"uppercase",fontFamily:i.font},children:t}),n]})}function fe({title:t,hint:n,children:i,t:o}){return e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"176px minmax(0, 1fr)",gap:24,padding:"18px 0",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:o.textPrimary,fontFamily:o.font},children:t}),n?e.jsx("div",{style:{fontSize:11,color:o.textMuted,lineHeight:1.45,marginTop:3,fontFamily:o.font},children:n}):null]}),e.jsx("div",{style:{minWidth:0,display:"grid",gap:10,alignContent:"start"},children:i})]})}function st({label:t,value:n,t:i}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"110px minmax(0, 1fr)",gap:8,fontSize:12,fontFamily:i.font},children:[e.jsx("span",{style:{color:i.textMuted},children:t}),e.jsx("span",{title:n,style:{color:i.textSecondary,overflowWrap:"anywhere"},children:n})]})}function ye({label:t,tone:n,t:i}){const o=n==="ok"?"#2ea043":n==="warn"?"#d29922":i.accent;return e.jsx("span",{style:{fontSize:10,fontWeight:700,color:o,background:`${o}18`,borderRadius:999,padding:"3px 7px",fontFamily:i.font,textTransform:"uppercase"},children:t})}function gt(t){return{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.cellBg,padding:12,color:t.textPrimary,fontFamily:t.font}}function xt(t){return{cursor:"pointer",color:t.textSecondary,fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.05em",fontFamily:t.font}}function Se(t){return{background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:6,color:t.textPrimary,fontSize:12,fontFamily:t.font,padding:"8px 10px",outline:"none",minWidth:0}}function en(t){return{...Se(t),boxSizing:"border-box",fontSize:11.5,minHeight:32,padding:"6px 8px"}}function ne(t){return{background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,color:t.textSecondary,cursor:"pointer",fontSize:11,fontFamily:t.font,padding:"6px 10px"}}function je(t){return{...ne(t),background:`${t.accent}18`,border:`1px solid ${t.accent}`,color:t.accent,fontWeight:700}}function rs({blockName:t,loading:n,detail:i,graph:o,paths:l,onSelectNode:a,onOpenInspector:p,t:y}){if(!t)return e.jsx(lt,{message:"Lineage will appear once the block has a name."});if(n)return e.jsx(lt,{message:"Loading block lineage…"});if(!(i!=null&&i.node))return e.jsxs("div",{style:{padding:12,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:12,color:y.textMuted,fontFamily:y.font},children:"No lineage node was found for this block yet. Save the block to compile and refresh its focused lineage automatically."}),e.jsx("div",{children:e.jsx("button",{onClick:p,style:{background:y.btnBg,border:`1px solid ${y.btnBorder}`,borderRadius:6,color:y.textPrimary,cursor:"pointer",fontSize:11,fontFamily:y.font,padding:"6px 10px"},children:"Open Focused Lineage"})})]});const x=`block:${t}`;return e.jsxs("div",{style:{padding:12,display:"grid",gap:12,overflowY:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:y.textPrimary,fontFamily:y.font},children:i.node.name}),e.jsx("div",{style:{fontSize:11,color:y.textMuted,fontFamily:y.font},children:i.node.domain?`Domain: ${i.node.domain}`:"Block lineage focus"})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:p,style:{background:y.btnBg,border:`1px solid ${y.btnBorder}`,borderRadius:6,color:y.textPrimary,cursor:"pointer",fontSize:11,fontFamily:y.font,padding:"6px 10px"},children:"Open Focused Lineage"})]}),(l==null?void 0:l.layerSummary)&&e.jsx(po,{layerSummary:l.layerSummary,t:y}),o&&o.nodes.length>0&&e.jsx(xo,{nodes:o.nodes,edges:o.edges,focalNodeId:x,height:360,onNodeClick:a,layoutMode:"flow"}),l&&(l.upstreamPaths.length>0||l.downstreamPaths.length>0)&&e.jsxs("div",{style:{display:"grid",gap:10},children:[l.upstreamPaths.length>0&&e.jsx(Un,{title:"Source to Block",paths:l.upstreamPaths,onNodeClick:a,focalNodeId:x,t:y}),l.downstreamPaths.length>0&&e.jsx(Un,{title:"Block to Consumption",paths:l.downstreamPaths,onNodeClick:a,focalNodeId:x,t:y})]})]})}function ls({metadata:t,draftMetadata:n,onChange:i,t:o}){const l={width:"100%",background:o.inputBg,border:`1px solid ${o.inputBorder}`,borderRadius:6,color:o.textPrimary,fontSize:12,fontFamily:o.font,padding:"8px 10px",outline:"none"},a={name:(n==null?void 0:n.name)||(t==null?void 0:t.name)||"",domain:(n==null?void 0:n.domain)||(t==null?void 0:t.domain)||"uncategorized",folderPath:(t==null?void 0:t.folderPath)||"",description:(n==null?void 0:n.description)||(t==null?void 0:t.description)||"",owner:(n==null?void 0:n.owner)||(t==null?void 0:t.owner)||"",tags:(n==null?void 0:n.tags)||(t==null?void 0:t.tags)||[]};return e.jsxs("div",{style:{display:"grid",gap:10,padding:12},children:[e.jsx("input",{value:a.name,onChange:p=>i({name:p.target.value}),placeholder:"Block name",style:l}),e.jsx("input",{value:a.domain,onChange:p=>i({domain:p.target.value}),placeholder:"Domain",style:l}),e.jsx("input",{value:a.folderPath,onChange:p=>i({folderPath:p.target.value}),placeholder:"Folder (optional), e.g. executive/monthly",style:{...l,fontFamily:o.fontMono}}),e.jsx("input",{value:a.owner,onChange:p=>i({owner:p.target.value}),placeholder:"Owner",style:l}),e.jsx("input",{value:a.description,onChange:p=>i({description:p.target.value}),placeholder:"Description",style:l}),e.jsx(li,{values:a.tags,onChange:p=>i({tags:p}),placeholder:"Tags",style:l})]})}function as({parameters:t,values:n,onChange:i,onReset:o,onRun:l,running:a,t:p}){return t.length===0?e.jsx(lt,{message:"This block has no runtime parameters. Add typed params in DQL Source when scope should be configurable."}):e.jsxs("div",{style:{padding:14,display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontSize:13,fontWeight:800,color:p.textPrimary},children:"Test parameter values"}),e.jsx("div",{style:{fontSize:11,color:p.textMuted,marginTop:3},children:"These values affect only the preview. Save defaults in the block definition."})]}),e.jsx("button",{type:"button",onClick:l,disabled:a,style:je(p),children:a?"Running…":"Run preview"})]}),e.jsx(vo,{parameters:t,values:n,onChange:i,onReset:o,t:p,includeNonRuntime:!0,card:!0})]})}function ds({values:t,t:n}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t.map(i=>e.jsxs("span",{style:{fontSize:10,color:n.textSecondary,background:n.appBg,border:`1px solid ${n.cellBorder}`,borderRadius:999,padding:"4px 7px"},children:[i.name," = ",Array.isArray(i.value)?i.value.join(", "):String(i.value)," ",e.jsxs("span",{style:{color:n.textMuted},children:["(",i.source,")"]})]},i.name))})}function lt({message:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:16,fontSize:12,color:i.textMuted},children:t})}function cs({elapsedMs:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg,padding:12,color:i.textPrimary,fontFamily:i.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700},children:[e.jsx(rt,{size:16,strokeWidth:2,color:i.accent,"aria-hidden":"true"}),e.jsx("span",{children:"Running preview"}),e.jsx("span",{style:{marginLeft:"auto",color:i.textMuted,fontSize:11,fontWeight:500},children:ps(t)})]}),e.jsx("div",{style:{color:i.textMuted,fontSize:12,lineHeight:1.45},children:"Executing the block query against the active connection."})]})})}function us({message:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:"1px solid rgba(248, 81, 73, 0.35)",borderRadius:8,background:"rgba(248, 81, 73, 0.08)",color:i.textPrimary,fontFamily:i.font,padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700,color:"#f85149"},children:[e.jsx(Et,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"Preview failed"})]}),e.jsx("div",{style:{color:i.textPrimary,fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t})]})})}function ps(t){const n=Math.max(0,Math.floor(t/1e3));if(n<60)return`${n}s`;const i=Math.floor(n/60),o=n%60;return`${i}m ${o}s`}const Jn={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149"},fs={draft:[],review:["draft"],certified:["deprecated"],deprecated:["draft"]};function hs({currentStatus:t,blockPath:n,onStatusChanged:i,t:o}){const[l,a]=c.useState(!1),p=fs[t]??[],y=async x=>{if(n){a(!0);try{const k=await F.updateBlockStatus(n,x);k.ok&&k.status&&i(k.status)}finally{a(!1)}}};return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",background:o.pillBg,borderRadius:8},children:[e.jsx("span",{style:{fontSize:11,color:o.textMuted,fontFamily:o.font},children:"Status:"}),e.jsx("span",{style:{fontSize:11,fontWeight:600,color:Jn[t]??o.textMuted,background:`${Jn[t]??o.textMuted}18`,padding:"2px 8px",borderRadius:4,textTransform:"uppercase",letterSpacing:"0.04em",fontFamily:o.font},children:t}),e.jsx("span",{style:{flex:1}}),p.map(x=>e.jsx("button",{onClick:()=>void y(x),disabled:l,style:{background:x==="certified"?"#3fb950":x==="deprecated"?"#f85149":o.btnBg,border:`1px solid ${x==="certified"?"#3fb950":x==="deprecated"?"#f85149":o.btnBorder}`,borderRadius:4,color:x==="certified"||x==="deprecated"?"#fff":o.textSecondary,cursor:l?"not-allowed":"pointer",fontSize:10,fontWeight:600,fontFamily:o.font,padding:"3px 10px",textTransform:"capitalize",opacity:l?.5:1},children:l?"...":x==="certified"?"Certify":x==="deprecated"?"Deprecate":`Move to ${x}`},x))]})}function ms({result:t,t:n}){var p,y,x;const i=t.checklist,o=i?[["Metadata",i.metadata],["Validation",i.validation],["Run",i.run],["Tests",i.tests],["Chart",i.chart],["Lineage",i.lineage]]:[],l=Array.from(new Set(((p=t.blockers)!=null&&p.length?t.blockers:(i==null?void 0:i.blockers)??[]).map(gs))),a=xs(l);return e.jsxs("div",{style:{margin:"12px 12px 0",border:`1px solid ${t.ok?"#3fb95055":"#d2992255"}`,borderRadius:8,background:t.ok?"#3fb9500d":"#d299220d",padding:12,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:t.ok?"#3fb950":"#d29922",fontFamily:n.font},children:t.ok?"Block certified":"Unable to certify"}),(i==null?void 0:i.checkedAt)&&e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.fontMono},children:i.checkedAt})]}),e.jsx("div",{style:{fontSize:12,color:n.textMuted,lineHeight:1.45},children:t.ok?"Latest edits were saved, the block ran successfully, tests passed, and status was updated to certified.":a?`Latest edits were saved, but certification cannot finish because ${a}. Fix it, then click Certify again.`:"Latest edits were saved, but certification cannot finish yet. Fix the blockers below, then click Certify again."}),o.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:o.map(([k,r])=>e.jsxs("span",{style:{fontSize:11,fontWeight:700,color:r?"#3fb950":"#d29922",background:r?"#3fb95018":"#d2992218",borderRadius:999,padding:"4px 8px"},children:[r?"✓":"!"," ",k]},k))}),t.error&&e.jsx("div",{style:{fontSize:12,color:"#f85149"},children:t.error}),l.length>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Missing before certification"}),l.map((k,r)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:k},r))]}),(((x=(y=t.certification)==null?void 0:y.warnings)==null?void 0:x.length)??0)>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:n.textMuted,textTransform:"uppercase",fontWeight:800},children:"Warnings"}),t.certification.warnings.map(k=>e.jsxs("div",{style:{fontSize:12,color:n.textMuted},children:[k.rule,": ",k.message]},`${k.rule}-${k.message}`))]})]})}function gs(t){const n=t.trim(),i=n.toLowerCase();return i==="missing owner"||i==="block has owner: missing owner"?"Owner is required.":i==="missing domain"||i==="block has domain: missing domain"?"Domain is required.":i==="missing description"||i==="block has description: missing description"?"Description is required.":i==="block has not run successfully"?"The query must run successfully.":i==="tests must pass before certification"||i.startsWith("all tests pass:")?"Tests must pass.":i==="at least one test assertion is required before certification"||i.startsWith("block has tests:")?"Add at least one test assertion.":i==="visualization config is missing"?"Choose a visualization.":n}function xs(t){const n=t.filter(i=>i.endsWith(" is required.")).map(i=>i.replace(" is required.","").toLowerCase());return n.length===0?t[0]?t[0].replace(/\.$/,"").toLowerCase():"":n.length===1?`${n[0]} is missing`:n.length===2?`${n[0]} and ${n[1]} are missing`:n.length>2?`${n.slice(0,-1).join(", ")}, and ${n[n.length-1]} are missing`:t.includes("Add at least one test assertion.")?"a test assertion is missing":t.includes("Choose a visualization.")?"a visualization is missing":t.includes("Tests must pass.")?"tests must pass":t.includes("The query must run successfully.")?"the query has not run successfully":t[0]?t[0].replace(/\.$/,"").toLowerCase():""}function ys({entries:t,t:n}){return t.length===0?e.jsx(lt,{message:"No version history available. Commit changes to build history."}):e.jsxs("div",{style:{padding:12,display:"grid",gap:8},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:n.textPrimary,fontFamily:n.font},children:"Version History"}),t.map(i=>e.jsxs("div",{style:{padding:"8px 12px",border:`1px solid ${n.cellBorder}`,borderRadius:8,background:n.inputBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:10,fontFamily:n.fontMono,color:n.accent,background:`${n.accent}12`,padding:"1px 6px",borderRadius:4},children:i.hash.slice(0,7)}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font},children:new Date(i.date).toLocaleDateString()}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font,marginLeft:"auto"},children:i.author})]}),e.jsx("div",{style:{fontSize:12,color:n.textPrimary,fontFamily:n.font},children:i.message})]},i.hash))]})}function bs(t,n){const i=t.match(/query\s*=\s*"""([\s\S]*?)"""/i);return i?t.replace(i[0],`query = """${i[1].trimEnd()}
|
|
25
|
+
GROUP BY 1`}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",onClick:p,disabled:!r.trim(),style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 12px",borderRadius:8,border:`1px solid ${y.accent}`,background:"var(--accent-dim)",color:y.accent,fontSize:11.5,fontWeight:650,cursor:r.trim()?"pointer":"not-allowed",fontFamily:y.font,opacity:r.trim()?1:.6},children:"Convert to DQL script"}),e.jsxs("span",{style:{fontSize:10.5,color:y.textMuted,fontFamily:y.font},children:["Detects ",e.jsx("span",{style:{fontFamily:y.fontMono},children:"${params}"})," and grounds tables against dbt. Open the DQL Source editor for the full script."]})]})]}),e.jsxs(fe,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:y,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx($,{label:"Type",t:y,children:e.jsxs("select",{value:s.chart??"table",onChange:j=>l(Re(t,{...s,chart:j.target.value})),style:x,children:[e.jsx("option",{value:"table",children:"Table"}),fi.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))]})}),e.jsx($,{label:"X axis",t:y,children:e.jsxs("select",{value:s.x??"",onChange:j=>l(Re(t,{...s,x:j.target.value})),style:x,children:[e.jsx("option",{value:"",children:"Auto"}),g.map(j=>e.jsx("option",{value:j,children:_e(j)},j))]})}),e.jsx($,{label:"Y axis",t:y,children:e.jsxs("select",{value:s.y??"",onChange:j=>l(Re(t,{...s,y:j.target.value})),style:x,children:[e.jsx("option",{value:"",children:"Auto"}),g.map(j=>e.jsx("option",{value:j,children:_e(j)},j))]})}),e.jsx($,{label:"Series / color",t:y,children:e.jsxs("select",{value:s.color??"",onChange:j=>l(Re(t,{...s,color:j.target.value})),style:x,children:[e.jsx("option",{value:"",children:"None"}),g.map(j=>e.jsx("option",{value:j,children:_e(j)},j))]})})]}),e.jsx($,{label:"Title",t:y,children:e.jsx("input",{value:s.title??"",onChange:j=>l(Re(t,{...s,title:j.target.value})),style:x})})]}),e.jsx(fe,{title:"Business outputs",hint:"What consumers see when this block answers a question.",t:y,children:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:7},children:g.length>0?g.map(j=>e.jsx("span",{style:St(y,!0),children:_e(j)},j)):e.jsx("span",{style:{fontSize:11,color:y.textMuted},children:"Add aliases in DQL Source to expose business-friendly output names."})})}),e.jsx(xi,{source:t,kind:"custom",onChange:l,t:y}),e.jsx(fe,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:y,children:e.jsx(vt,{multiline:!0,value:I,onChange:j=>l(ci(t,"tests",j)),placeholder:`assert row_count >= 1
|
|
26
|
+
assert revenue >= 0`,style:{...x,minHeight:64,resize:"vertical",fontFamily:y.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:y.textSecondary,fontFamily:y.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:y.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:y.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function Zo({semanticChoice:t,databaseWarning:n,onDismiss:i,onInsertAdvanced:s,onCreateSemantic:l,t:a}){const p=t?`${t.kind==="metric"?"Metric":"Dimension"} "${t.name}" belongs in a Semantic Block. SQL Blocks can still use advanced @metric/@dim refs when you choose that explicitly.`:n??"";return e.jsxs("div",{style:{padding:"10px 12px",borderBottom:`1px solid ${a.headerBorder}`,background:`${a.accent}10`,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:a.textSecondary,lineHeight:1.4,flex:1,minWidth:260},children:p}),t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:l,style:ne(a),children:"Create Semantic Block"}),e.jsx("button",{onClick:s,style:je(a),children:"Insert advanced ref"})]}),e.jsx("button",{onClick:i,style:ne(a),children:"Dismiss"})]})}function Xt(t){var i,s,l,a,p;const n=((s=(i=t.preview)==null?void 0:i.result)==null?void 0:s.rowCount)??((p=(a=(l=t.preview)==null?void 0:l.result)==null?void 0:a.rows)==null?void 0:p.length);return typeof n=="number"?n:void 0}function kt(t){return t?t.startsWith("blocks/_drafts/")||/^domains\/[^/]+\/blocks\/_drafts\//.test(t):!1}function qe(t){var n,i,s,l,a;return t.reviewStatus==="saved"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"saved",rows:Xt(t),message:"Block saved."}:((n=t.validation)==null?void 0:n.valid)===!1?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:((i=t.validation.diagnostics.find(p=>p.severity==="error"))==null?void 0:i.message)??"DQL validation needs attention."}:t.preview?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",rows:Xt(t),savedPath:t.savedPath,message:kt(t.savedPath)?"Preview ran successfully. Draft is saved for review.":"Preview ran successfully. Nothing is written until you save."}:((s=t.draftSave)==null?void 0:s.status)==="saved"||kt(t.savedPath)?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",savedPath:((l=t.draftSave)==null?void 0:l.path)??t.savedPath,message:"Draft saved. Run preview, then certify when ready."}:((a=t.draftSave)==null?void 0:a.status)==="error"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:t.draftSave.error??"Draft preparation failed."}:{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"queued",message:"Ready to process."}}function es(t){return t==="retrieving"?"Checking certified blocks and semantic metrics.":t==="reviewing"?"Reviewing governed evidence and building the candidate.":t==="ready"?"Analysis ready. Preparing preview.":t==="needs_attention"?"Analysis needs attention.":"Queued for governed retrieval."}async function ts(t,n){for(let i=0;i<240;i+=1){const s=await O.getDqlGenerationSession(t);if(n(s),s.candidates.every(l=>l.analysisStatus==="ready"||l.analysisStatus==="needs_attention"))return s;await new Promise(l=>window.setTimeout(l,500))}throw new Error("Import analysis is still running. You can leave this workspace and resume the session later.")}async function ns(t,n,i){let s=0;const l=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;s<t.length;){const a=s;s+=1,await i(t[a])}});await Promise.all(l)}function Lt(t){return!!(t.generationMode||t.draftSave||kt(t.savedPath))}function is(t){return t==="creating"?"Reading SQL":t==="running"?"Running previews":t==="saving"?"Saving blocks":t==="complete"?"Import complete":"Ready"}function os(t){return t==="needs_attention"?"needs attention":t.replace("_"," ")}function ss(t){return t==="saved"||t==="ready"?"ok":t==="needs_attention"?"warn":"info"}function rs({session:t,sessions:n,sessionsLoading:i,onClose:s,onSessionChange:l,onRefreshSessions:a,onSelectCandidate:p,onSavedCandidate:y,defaultDomain:x,defaultOwner:k,themeMode:r,t:f,inline:g=!1}){const[I,P]=c.useState("paste"),[W,le]=c.useState(""),[E,j]=c.useState(""),[S,ie]=c.useState([]),[V,J]=c.useState(x),[A,Z]=c.useState(k),[Q,M]=c.useState(null),[K,F]=c.useState(!1),[Y,de]=c.useState(!1),[ee,N]=c.useState(null),[oe,D]=c.useState(null),[X,se]=c.useState(!1),[Ce,ke]=c.useState(!0),[ce,Ie]=c.useState(""),[he,Le]=c.useState(!1),[$e,ue]=c.useState({}),[We,d]=c.useState("idle"),[L,U]=c.useState({}),ge=c.useMemo(()=>t?t.candidates.find(m=>m.id===Q)??t.candidates[0]??null:null,[t,Q]);c.useEffect(()=>{if(!(t!=null&&t.candidates.length)){M(null);return}(!Q||!t.candidates.some(m=>m.id===Q))&&M(t.candidates[0].id)},[t,Q]),c.useEffect(()=>{ue({})},[t==null?void 0:t.id]),c.useEffect(()=>{ke(!(t!=null&&t.candidates.length))},[t==null?void 0:t.id,t==null?void 0:t.candidates.length]),c.useEffect(()=>{if(!t){U({}),d("idle");return}U(Object.fromEntries(t.candidates.map(m=>[m.id,qe(m)]))),d(m=>m==="idle"?"complete":m)},[t==null?void 0:t.id]);const be=c.useMemo(()=>{const m=ce.trim().toLowerCase(),T=(t==null?void 0:t.candidates)??[];return m?T.filter(w=>[w.name,w.domain,w.sourcePath,w.description,...w.lineage.sourceTables].some(C=>C.toLowerCase().includes(m))):T},[ce,t]),Be=he||ce.trim()?be:be.slice(0,10),pe=((t==null?void 0:t.candidates.map(m=>L[m.id]??qe(m)))??[]).reduce((m,T)=>(T.status==="saved"?m.saved+=1:T.status==="ready"?m.ready+=1:T.status==="needs_attention"?m.attention+=1:m.processing+=1,m),{saved:0,ready:0,attention:0,processing:0}),Te=t?pe.saved>0?3:2:1,Ze=(t==null?void 0:t.candidates.filter(m=>{var T;return((T=m.validation)==null?void 0:T.valid)!==!1}).length)??0,Ee=!!(I==="paste"?E.trim():I==="upload"?S.length>0:W.trim()),Ne=()=>I==="paste"?{inputMode:"paste",sourceKind:"raw-sql",domain:V,owner:A,sources:[{path:"pasted.sql",content:E}],async:!0,persistence:"session-only"}:I==="upload"?{inputMode:"upload",sourceKind:"raw-sql",domain:V,owner:A,sources:S,async:!0,persistence:"session-only"}:{path:W,inputMode:"path",sourceKind:"raw-sql",domain:V,owner:A,async:!0,persistence:"session-only"},He=async()=>{var m,T,w;F(!0),de(!0),N(null),ue({}),U({}),d("creating");try{const C=await O.createDqlGenerationSession(Ne());let q=C,re=Object.fromEntries(C.candidates.map(z=>[z.id,{...qe(z),status:"queued",message:"Queued for governed retrieval."}]));const h=(z,_)=>{re={...re,[z]:_(re[z])},U(re)},B=z=>{q={...q,candidates:q.candidates.map(_=>_.id===z.id?z:_)},l(q)};l(q),M(((m=q.candidates[0])==null?void 0:m.id)??null),U(re),await a(),d("running"),q=await ts(C.id,z=>{q=z,l(z);for(const _ of z.candidates)h(_.id,xe=>({...xe,name:_.name,sourcePath:_.sourcePath,status:_.analysisStatus==="needs_attention"?"needs_attention":_.analysisStatus==="ready"?"queued":"running",message:es(_.analysisStatus)}))}),await ns(q.candidates,2,async z=>{if(z.analysisStatus!=="needs_attention"){h(z.id,_=>({..._,status:"running",message:"Running preview."}));try{const _=await O.previewDqlGenerationCandidate(q.id,z.id);B(_),h(z.id,xe=>{var G;return{...xe,name:_.name,sourcePath:_.sourcePath,status:"ready",rows:Xt(_),savedPath:((G=_.draftSave)==null?void 0:G.path)??_.savedPath,message:_.recommendedAction==="reuse_existing"?"A governed block already answers this SQL. Reuse it instead of saving a duplicate.":"Preview ran successfully. Nothing is written until you save."}})}catch(_){const xe=(_==null?void 0:_.message)??"Preview failed.";ue(G=>({...G,[z.id]:xe})),h(z.id,G=>({...G,status:"needs_attention",message:xe}))}}}),l(q),M(((T=q.candidates.find(z=>z.reviewStatus!=="rejected"))==null?void 0:T.id)??((w=q.candidates[0])==null?void 0:w.id)??null),await a(),d("complete")}catch(C){N((C==null?void 0:C.message)??"Import failed."),d("idle")}finally{F(!1),de(!1)}},et=async m=>{var T,w;F(!0),N(null);try{const C=await O.getDqlGenerationSession(m).catch(()=>O.getBlockStudioImport(m));l(C),M(((T=C.candidates.find(q=>q.reviewStatus!=="saved"&&q.reviewStatus!=="rejected"))==null?void 0:T.id)??((w=C.candidates[0])==null?void 0:w.id)??null),ue({}),d("complete")}catch(C){N((C==null?void 0:C.message)??"Failed to resume import session.")}finally{F(!1)}},Qe=async m=>{D({kind:"one",id:m})},Ue=async()=>{n.length!==0&&D({kind:"all"})},Ke=async()=>{if(!oe)return;const m=oe;F(!0),N(null);try{m.kind==="one"?await O.deleteBlockStudioImport(m.id):await O.clearBlockStudioImports(),(m.kind==="all"||(t==null?void 0:t.id)===m.id)&&(l(null),M(null)),D(null),await a()}catch(T){N((T==null?void 0:T.message)??"Failed to update import history.")}finally{F(!1)}},De=m=>{t&&(l({...t,candidates:t.candidates.map(T=>T.id===m.id?m:T)}),U(T=>({...T,[m.id]:qe(m)})))},Ge=async m=>{if(t){F(!0),N(null),ue(T=>{if(!T[m.id])return T;const w={...T};return delete w[m.id],w});try{const T=Lt(m)?await O.previewDqlGenerationCandidate(t.id,m.id):await O.runBlockStudioImportCandidate(t.id,m.id);De(T),M(T.id),ue(w=>{if(!w[m.id])return w;const C={...w};return delete C[m.id],C})}catch(T){const w=(T==null?void 0:T.message)??"Candidate run failed.";N(w),M(m.id),ue(C=>({...C,[m.id]:w}))}finally{F(!1)}}},tt=async m=>{if(!t)return;const T=m.owner.trim()||A.trim();if(!T){N("Owner is required before a block can be saved or certified.");return}F(!0),N(null);try{if(Lt(m)){const w=await O.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:[m.id],owner:T});l(w.session);const C=w.results[0];if(!C||C.status==="error")throw new Error((C==null?void 0:C.error)??(C==null?void 0:C.blockers.join(" "))??"Candidate save failed.");C.candidate&&De(C.candidate),C.candidate&&C.block&&y(C.candidate,C.block),C.status==="draft"&&C.blockers.length>0&&N(`Saved as draft: ${C.blockers.join(" ")}`)}else{const w=await O.saveBlockStudioImportCandidate(t.id,m.id);De(w.candidate),y(w.candidate,w.block)}await a()}catch(w){const C=(w==null?void 0:w.message)??"Candidate save failed.";N(C.includes("409")||C.includes("already exists")?"A block with this name already exists. Rename this candidate, then save again.":C)}finally{F(!1)}},Ve=async()=>{if(!t)return;const m=A.trim()||t.defaults.owner.trim();if(!m){N("Owner is required before blocks can be saved or certified.");return}de(!0),N(null);try{const T=t.candidates.filter(B=>B.reviewStatus!=="rejected"&&B.analysisStatus!=="needs_attention").map(B=>B.id),w=await O.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:T,owner:m});l(w.session);const C=new Map(w.results.filter(B=>B.status==="error").map(B=>[B.candidateId,B.error??B.blockers.join(" ")])),q=new Map(w.results.filter(B=>B.path).map(B=>[B.candidateId,B.path]));U(Object.fromEntries(w.session.candidates.map(B=>{const z=C.get(B.id),_=q.get(B.id)??B.savedPath;return z?[B.id,{...qe(B),status:"needs_attention",message:z.includes("409")||z.includes("already exists")?"A block with this name already exists. Rename it in advanced details, then save again.":z}]:_||B.reviewStatus==="saved"?[B.id,{...qe(B),status:"saved",savedPath:_,message:"Block saved."}]:[B.id,qe(B)]}))),await a();const re=w.results.filter(B=>B.status==="error").length,h=w.results.filter(B=>B.status==="draft").length;(re>0||h>0)&&N(`${w.results.length-re} saved. ${h} stayed draft; ${re} need attention.`)}catch(T){N((T==null?void 0:T.message)??"Save all failed.")}finally{de(!1)}},Ye=async m=>{if(!t)return;const T=await O.updateBlockStudioImportCandidate(t.id,m.id,{reviewStatus:"rejected"});De(T),a()},nt=async m=>{const w=Array.from(m??[]).filter(q=>q.name.toLowerCase().endsWith(".sql")),C=await Promise.all(w.map(async q=>({path:q.name,content:await q.text()})));ie(C),C.length>0&&le("")};return e.jsxs("div",{style:{position:"relative",height:"100%",display:"grid",gridTemplateRows:"80px minmax(0, 1fr)",minHeight:0,background:f.appBg,borderRadius:g?0:8},children:[e.jsxs("header",{style:{borderBottom:`1px solid ${f.headerBorder}`,background:f.cellBg,padding:"14px 14px 12px",display:"flex",alignItems:"center",gap:14,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:260},children:[e.jsx("span",{style:{width:34,height:34,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",color:f.accent,background:`${f.accent}16`,flexShrink:0},children:e.jsx(Yt,{size:17,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Import SQL to DQL"}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"SQL source to AI-grounded drafts to review and certify"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(130px, 1fr))",gap:6,width:"min(560px, 44vw)",minWidth:390},children:[e.jsx(Ut,{index:1,active:Te===1,complete:!!t,title:"Source",detail:I==="paste"?"Paste SQL":I==="upload"?"Upload files":"Local path",t:f}),e.jsx(Ut,{index:2,active:Te===2,complete:pe.ready>0||pe.saved>0,title:"Draft",detail:t?`${t.candidates.length} blocks · ${Ze} ready`:"Generate DQL",t:f}),e.jsx(Ut,{index:3,active:Te===3,complete:pe.saved>0,title:"Review",detail:pe.saved>0?`${pe.saved} certified`:"Preview and certify",t:f})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:s,title:"Close import","aria-label":"Close import",style:{...ne(f),width:32,height:32,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(Mo,{size:15,strokeWidth:2,"aria-hidden":"true"})})]}),e.jsxs("div",{style:{minHeight:0,display:"grid",gridTemplateColumns:"300px minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${f.headerBorder}`,display:"grid",gridTemplateRows:"auto minmax(0, 1fr) auto",minHeight:0,background:f.cellBg},children:[e.jsxs("section",{style:{borderBottom:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:10},children:[e.jsxs("button",{onClick:()=>ke(m=>!m),style:{background:"transparent",border:"none",color:f.textPrimary,cursor:"pointer",display:"flex",alignItems:"center",gap:8,padding:0,fontFamily:f.font,textAlign:"left"},children:[e.jsx(mi,{size:14,strokeWidth:2,color:f.accent,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:12,fontWeight:800,flex:1},children:"Source"}),t&&e.jsx("span",{style:{fontSize:10,color:f.textMuted},children:Ce?"Hide":"Edit"})]}),Ce?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:4},children:["paste","upload","path"].map(m=>e.jsx("button",{onClick:()=>P(m),style:{...ne(f),padding:"6px 4px",color:I===m?f.accent:f.textSecondary,borderColor:I===m?f.accent:f.btnBorder,background:I===m?`${f.accent}14`:f.btnBg},children:m==="paste"?"Paste SQL":m==="upload"?"Upload files":"Local path"},m))}),I==="path"&&e.jsx($,{label:"Path",t:f,children:e.jsx("input",{value:W,onChange:m=>{le(m.target.value),m.target.value.trim()&&ie([])},placeholder:"./queries or ./legacy.sql",style:Se(f)})}),I==="upload"&&e.jsxs($,{label:"Upload SQL files",t:f,children:[e.jsx("input",{type:"file",multiple:!0,accept:".sql,text/sql,text/plain",onChange:m=>void nt(m.target.files),style:Se(f)}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font},children:S.length>0?`${S.length} SQL file(s) ready`:"Choose one or more SQL files."})]}),I==="paste"&&e.jsx($,{label:"Paste SQL",t:f,children:e.jsx("textarea",{value:E,onChange:m=>j(m.target.value),placeholder:`select ...; go
|
|
27
|
+
select ...`,style:{...Se(f),minHeight:t?86:150,resize:"vertical",fontFamily:f.fontMono}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Domain",t:f,children:e.jsx("input",{value:V,onChange:m=>J(m.target.value),placeholder:"auto",style:Se(f)})}),e.jsx($,{label:"Owner",t:f,children:e.jsx("input",{value:A,onChange:m=>Z(m.target.value),placeholder:"analytics",style:Se(f)})})]}),e.jsx("button",{onClick:()=>void He(),disabled:K||!Ee,style:{...je(f),padding:"8px 12px",opacity:K||!Ee?.65:1,cursor:K||!Ee?"not-allowed":"pointer"},children:K?is(We):"Generate DQL drafts"}),e.jsx("div",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,lineHeight:1.45},children:"Uses dbt, MetricFlow, warehouse catalog, and existing DQL context when available."})]}):e.jsxs("button",{onClick:()=>ke(!0),style:{...ne(f),display:"grid",gap:4,textAlign:"left",width:"100%",justifyItems:"start"},children:[e.jsx("span",{style:{fontSize:11,color:f.textSecondary},children:I==="paste"?"Pasted SQL":I==="upload"?"Uploaded files":"Local path"}),e.jsx("span",{style:{maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:f.textMuted,fontFamily:f.fontMono},children:(t==null?void 0:t.inputPath)??(I==="paste"?"pasted.sql":I==="upload"?`${S.length} file(s)`:W||"./queries")})]})]}),e.jsx("section",{style:{minHeight:0,overflow:"auto",padding:12,display:"grid",alignContent:"start",gap:10},children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Drafts"}),e.jsx(ye,{label:`${t.candidates.length}`,tone:"info",t:f}),pe.ready>0&&e.jsx(ye,{label:`${pe.ready} ready`,tone:"ok",t:f}),pe.attention>0&&e.jsx(ye,{label:`${pe.attention} attention`,tone:"warn",t:f})]}),t.candidates.length>6&&e.jsx("input",{value:ce,onChange:m=>Ie(m.target.value),placeholder:"Search drafts, tables, files...",style:Se(f)})]}),Be.map(m=>{var h,B,z,_,xe,G,Me,it;const T=m.id===(ge==null?void 0:ge.id),w=m.warnings??m.lineage.warnings,C=$e[m.id],q=((B=(h=m.preview)==null?void 0:h.result)==null?void 0:B.rowCount)??((xe=(_=(z=m.preview)==null?void 0:z.result)==null?void 0:_.rows)==null?void 0:xe.length),re=L[m.id]??qe(m);return e.jsxs("button",{onClick:()=>{M(m.id)},style:{border:`1px solid ${T?f.accent:C?"#f8514955":f.headerBorder}`,borderRadius:8,background:T?`${f.accent}10`:f.appBg,color:f.textPrimary,padding:10,display:"grid",gap:6,textAlign:"left",cursor:"pointer",minWidth:0},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{minWidth:0,flex:1,fontSize:12,fontWeight:800,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.name}),e.jsx(ye,{label:os(re.status),tone:ss(re.status),t:f})]}),e.jsxs("span",{style:{fontSize:10,color:f.textMuted,fontFamily:f.fontMono,overflowWrap:"anywhere"},children:[m.lineage.statementIndex,"/",m.lineage.totalStatements," · ",m.sourcePath]}),e.jsxs("span",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[e.jsx(ye,{label:((G=m.draftSave)==null?void 0:G.status)==="saved"||kt(m.savedPath)?"draft saved":m.reviewStatus,tone:m.reviewStatus==="rejected"?"warn":"info",t:f}),e.jsx(ye,{label:((Me=m.validation)==null?void 0:Me.valid)===!1?"fix":"valid",tone:((it=m.validation)==null?void 0:it.valid)===!1?"warn":"ok",t:f}),typeof q=="number"&&e.jsx(ye,{label:`${q} rows`,tone:"ok",t:f}),w.length>0&&e.jsx(ye,{label:`${w.length} warning`,tone:"warn",t:f})]}),(C||re.message)&&e.jsx("span",{style:{fontSize:11,color:C?"#f85149":f.textMuted,lineHeight:1.35,overflowWrap:"anywhere"},children:C??re.message})]},m.id)}),!he&&!ce.trim()&&be.length>10&&e.jsxs("button",{onClick:()=>Le(!0),style:ne(f),children:["Show all ",be.length," drafts"]}),!t.candidates.some(Lt)&&pe.ready>0&&e.jsx("button",{onClick:()=>void Ve(),disabled:Y,style:je(f),children:Y?"Saving...":"Save valid blocks"})]}):e.jsx("div",{style:{fontSize:12,color:f.textMuted,lineHeight:1.5},children:"Paste SQL, upload files, or choose a local path. Analysis stays in this session until you save a block."})}),e.jsxs("details",{open:X,onToggle:m=>se(m.currentTarget.open),style:{borderTop:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:8},children:[e.jsxs("summary",{style:{cursor:"pointer",color:f.textSecondary,fontSize:11,fontWeight:800,fontFamily:f.font},children:["Import history",n.length>0?` (${n.length})`:""]}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:8},children:[e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>void a(),style:ne(f),children:"Refresh"}),n.length>0&&e.jsx("button",{onClick:()=>void Ue(),style:ne(f),children:"Clear"})]}),i?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"Loading..."}):n.length===0?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"No saved import sessions."}):e.jsx("div",{style:{display:"grid",gap:6,maxHeight:140,overflow:"auto"},children:n.slice(0,6).map(m=>e.jsxs("div",{style:{border:`1px solid ${(t==null?void 0:t.id)===m.id?f.accent:f.btnBorder}`,borderRadius:8,background:(t==null?void 0:t.id)===m.id?`${f.accent}10`:f.btnBg,display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",overflow:"hidden"},children:[e.jsxs("button",{onClick:()=>void et(m.id),style:{background:"transparent",border:"none",color:f.textSecondary,cursor:"pointer",fontFamily:f.font,padding:"8px 9px",textAlign:"left",display:"grid",gap:3,minWidth:0},children:[e.jsxs("span",{style:{fontSize:11},children:[m.candidateCount," drafts · ",m.savedCount," certified"]}),e.jsx("span",{style:{fontSize:10,color:f.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.inputPath})]}),e.jsx("button",{onClick:()=>void Qe(m.id),title:"Delete local import session",style:{background:"transparent",border:"none",borderLeft:`1px solid ${f.headerBorder}`,color:f.textMuted,cursor:"pointer",fontFamily:f.font,padding:"0 8px",fontSize:11,fontWeight:700},children:"Delete"})]},m.id))})]})]})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,overflow:"auto",padding:20,background:f.appBg},children:[ee&&e.jsx("div",{role:"alert",style:{padding:"10px 12px",color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,marginBottom:12,fontSize:12},children:ee}),!t||!ge?e.jsx(ds,{t:f}):e.jsx(as,{session:t,candidate:ge,loading:K,onCandidateUpdated:De,onRun:Ge,onSave:tt,onReject:Ye,onReviewInEditor:p,runError:$e[ge.id]??null,themeMode:r,t:f})]})]}),oe&&e.jsx(ls,{t:f,busy:K,title:oe.kind==="all"?"Clear import history?":"Delete import preview?",message:oe.kind==="all"?`This removes ${n.length} local import preview${n.length===1?"":"s"} from .dql/imports. Saved blocks stay in the project.`:"This removes the selected local import preview from .dql/imports. Saved blocks stay in the project.",confirmLabel:oe.kind==="all"?"Clear history":"Delete preview",onCancel:()=>D(null),onConfirm:()=>void Ke()})]})}function ls({title:t,message:n,confirmLabel:i,busy:s,onCancel:l,onConfirm:a,t:p}){return e.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(0, 0, 0, 0.22)",display:"flex",alignItems:"center",justifyContent:"center",padding:20,zIndex:20},children:e.jsxs("div",{style:{width:"min(420px, 92vw)",background:p.cellBg,color:p.textPrimary,border:`1px solid ${p.headerBorder}`,borderRadius:8,boxShadow:"0 18px 48px rgba(0, 0, 0, 0.30)",padding:16,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,fontFamily:p.font},children:t}),e.jsx("div",{style:{fontSize:12,color:p.textMuted,lineHeight:1.5,fontFamily:p.font},children:n}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{onClick:l,disabled:s,style:ne(p),children:"Cancel"}),e.jsx("button",{onClick:a,disabled:s,style:{...je(p),opacity:s?.65:1},children:s?"Working...":i})]})]})})}function as({session:t,candidate:n,loading:i,onCandidateUpdated:s,onRun:l,onSave:a,onReject:p,onReviewInEditor:y,runError:x,themeMode:k,t:r}){var Ne,He,et,Qe,Ue,Ke,De,Ge,tt,Ve,Ye,nt,m,T,w,C,q,re;const[f,g]=c.useState(n.name),[I,P]=c.useState(n.domain),[W,le]=c.useState(n.owner),[E,j]=c.useState(n.description),[S,ie]=c.useState(n.tags.join(", ")),[V,J]=c.useState((n.terms??[]).join(", ")),[A,Z]=c.useState(n.pattern??""),[Q,M]=c.useState(n.grain??""),[K,F]=c.useState((n.entities??[]).join(", ")),[Y,de]=c.useState((n.outputs??[]).join(", ")),[ee,N]=c.useState((n.dimensions??[]).join(", ")),[oe,D]=c.useState((n.allowedFilters??[]).join(", ")),[X,se]=c.useState((n.sourceSystems??[]).join(", ")),[Ce,ke]=c.useState((n.replacementFor??[]).join(", ")),[ce,Ie]=c.useState(n.reviewCadence??"monthly"),[he,Le]=c.useState(n.sql),[$e,ue]=c.useState(null),[We,d]=c.useState(null),[L,U]=c.useState(!1);c.useEffect(()=>{g(n.name),P(n.domain),le(n.owner),j(n.description),ie(n.tags.join(", ")),J((n.terms??[]).join(", ")),Z(n.pattern??""),M(n.grain??""),F((n.entities??[]).join(", ")),de((n.outputs??[]).join(", ")),N((n.dimensions??[]).join(", ")),D((n.allowedFilters??[]).join(", ")),se((n.sourceSystems??[]).join(", ")),ke((n.replacementFor??[]).join(", ")),Ie(n.reviewCadence??"monthly"),Le(n.sql),d(null),U(!1)},[n.id,n.name,n.domain,n.owner,n.description,n.tags,n.terms,n.pattern,n.grain,n.entities,n.outputs,n.dimensions,n.allowedFilters,n.sourceSystems,n.replacementFor,n.reviewCadence,n.sql]);const ge=async()=>{d(null);try{const h={name:f,domain:I,owner:W,description:E,tags:S.split(",").map(z=>z.trim()).filter(Boolean),terms:V.split(",").map(z=>z.trim()).filter(Boolean),pattern:A,grain:Q,entities:K.split(",").map(z=>z.trim()).filter(Boolean),outputs:Y.split(",").map(z=>z.trim()).filter(Boolean),dimensions:ee.split(",").map(z=>z.trim()).filter(Boolean),allowedFilters:oe.split(",").map(z=>z.trim()).filter(Boolean),sourceSystems:X.split(",").map(z=>z.trim()).filter(Boolean),replacementFor:Ce.split(",").map(z=>z.trim()).filter(Boolean),reviewCadence:ce,sql:he,llmContext:n.llmContext},B=Lt(n)?await O.updateDqlGenerationCandidate(t.id,n.id,h):await O.updateBlockStudioImportCandidate(t.id,n.id,h);s(B)}catch(h){d((h==null?void 0:h.message)??"Could not update candidate.")}},be=async h=>{ue(h),d(null);try{const B=await O.assistBlockStudioImportCandidate(t.id,n.id,h);s(B)}catch(B){d((B==null?void 0:B.message)??"AI assist failed.")}finally{ue(null)}},Be=n.warnings??n.lineage.warnings,te=Se(r),pe=((He=(Ne=n.preview)==null?void 0:Ne.result)==null?void 0:He.rowCount)??((Ue=(Qe=(et=n.preview)==null?void 0:et.result)==null?void 0:Qe.rows)==null?void 0:Ue.length),Te=((Ke=n.draftSave)==null?void 0:Ke.path)??(kt(n.savedPath)?n.savedPath:void 0),Ze=n.recommendedAction==="reuse_existing"||((De=n.draftSave)==null?void 0:De.status)==="skipped",Ee=n.lineage.sourceTables.length+(((Ge=n.evidence)==null?void 0:Ge.length)??0)+n.lineage.parameters.length+Be.length;return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{style:{fontSize:18,fontWeight:800,color:r.textPrimary},children:n.name}),e.jsxs("div",{style:{fontSize:11,color:r.textMuted,fontFamily:r.fontMono,marginTop:3},children:[n.sourcePath," · statement ",n.lineage.statementIndex,"/",n.lineage.totalStatements]})]}),e.jsx("button",{onClick:()=>void l(n),disabled:i,style:ne(r),children:i?"Running...":"Preview"}),e.jsx("button",{onClick:()=>U(h=>!h),style:L?je(r):ne(r),children:L?"Hide context":`Show context${Ee>0?` (${Ee})`:""}`}),e.jsx("button",{onClick:()=>y(n),style:je(r),children:"Edit full DQL"}),e.jsx("button",{onClick:()=>void a(n),disabled:i||n.reviewStatus==="saved"||Ze,style:je(r),children:Ze?"Reuse existing":n.reviewStatus==="saved"?"Certified":"Save block"})]}),We&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",borderRadius:8,padding:10},children:We}),x&&e.jsxs("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,padding:10,lineHeight:1.45,overflowWrap:"anywhere"},children:["Preview failed: ",x]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(ye,{label:((tt=n.draftSave)==null?void 0:tt.status)==="skipped"?"reuse recommended":((Ve=n.draftSave)==null?void 0:Ve.status)==="saved"||Te?"draft saved":n.reviewStatus,tone:n.reviewStatus==="rejected"?"warn":((Ye=n.draftSave)==null?void 0:Ye.status)==="skipped"?"ok":"info",t:r}),e.jsx(ye,{label:`${Math.round(n.confidence*100)}% confidence`,tone:"info",t:r}),e.jsx(ye,{label:((nt=n.validation)==null?void 0:nt.valid)===!1?"needs fixes":"valid",tone:((m=n.validation)==null?void 0:m.valid)===!1?"warn":"ok",t:r}),typeof pe=="number"&&e.jsx(ye,{label:`${pe} rows`,tone:"ok",t:r})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:L?"minmax(0, 1fr) minmax(320px, 380px)":"minmax(0, 1fr)",gap:12,alignItems:"start"},children:[e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs(fe,{title:"Review details",t:r,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Name",t:r,children:e.jsx("input",{value:f,onChange:h=>g(h.target.value),style:te})}),e.jsx($,{label:"Domain",t:r,children:e.jsx("input",{value:I,onChange:h=>P(h.target.value),style:te})}),e.jsx($,{label:"Owner",t:r,children:e.jsx("input",{value:W,onChange:h=>le(h.target.value),style:te})}),e.jsx($,{label:"Tags",t:r,children:e.jsx("textarea",{value:S,onChange:h=>ie(h.target.value),style:{...te,minHeight:58,resize:"vertical"}})})]}),e.jsx($,{label:"Business description",t:r,children:e.jsx("textarea",{value:E,onChange:h=>j(h.target.value),style:{...te,minHeight:70,resize:"vertical"}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:8},children:[e.jsx($,{label:"Pattern",t:r,children:e.jsx("select",{value:A,onChange:h=>Z(h.target.value),style:te,children:["custom","metric_wrapper","entity_profile","entity_rollup","ranking","trend","bridge","drilldown","replacement"].map(h=>e.jsx("option",{value:h,children:h},h))})}),e.jsx($,{label:"Grain",t:r,children:e.jsx("input",{value:Q,onChange:h=>M(h.target.value),style:te})}),e.jsx($,{label:"Review cadence",t:r,children:e.jsx("select",{value:ce,onChange:h=>Ie(h.target.value),style:te,children:["weekly","monthly","quarterly","semiannual","annual"].map(h=>e.jsx("option",{value:h,children:h},h))})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Entities",t:r,children:e.jsx("input",{value:K,onChange:h=>F(h.target.value),style:te})}),e.jsx($,{label:"Outputs",t:r,children:e.jsx("input",{value:Y,onChange:h=>de(h.target.value),style:te})}),e.jsx($,{label:"Dimensions",t:r,children:e.jsx("input",{value:ee,onChange:h=>N(h.target.value),style:te})}),e.jsx($,{label:"Allowed filters",t:r,children:e.jsx("input",{value:oe,onChange:h=>D(h.target.value),style:te})}),e.jsx($,{label:"Source systems",t:r,children:e.jsx("input",{value:X,onChange:h=>se(h.target.value),style:te})}),e.jsx($,{label:"Terms",t:r,children:e.jsx("input",{value:V,onChange:h=>J(h.target.value),style:te})})]}),e.jsx($,{label:"Replaces",t:r,children:e.jsx("input",{value:Ce,onChange:h=>ke(h.target.value),style:te})}),e.jsx("button",{onClick:()=>void ge(),style:{...je(r),justifySelf:"start"},children:"Apply edits"})]}),n.preview&&e.jsxs(fe,{title:"Preview Results",t:r,children:[e.jsxs("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.45},children:["Query ran successfully",typeof pe=="number"?` and returned ${pe} rows`:"","."]}),e.jsx("div",{style:{maxHeight:320,overflow:"auto",border:`1px solid ${r.headerBorder}`,borderRadius:8},children:e.jsx(pi,{result:n.preview.result,themeMode:k})})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Original SQL"}),e.jsx("textarea",{value:he,onChange:h=>Le(h.target.value),style:{...te,minHeight:210,fontFamily:r.fontMono,resize:"vertical",marginTop:10}})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Draft DQL block"}),e.jsx("pre",{style:{margin:"10px 0 0",whiteSpace:"pre-wrap",fontSize:11,lineHeight:1.45,color:r.textSecondary,fontFamily:r.fontMono},children:n.dqlSource})]})]}),L&&e.jsxs("div",{style:{display:"grid",gap:12},children:[(((T=n.similarityMatches)==null?void 0:T.length)||((w=n.draftSave)==null?void 0:w.status)==="skipped")&&e.jsx(fe,{title:"Reuse recommendation",t:r,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsx(st,{label:"Action",value:n.recommendedAction??"create_new",t:r}),((C=n.draftSave)==null?void 0:C.reason)&&e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.4},children:n.draftSave.reason}),(n.similarityMatches??[]).slice(0,3).map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:r.textSecondary,overflowWrap:"anywhere"},children:h.name}),e.jsxs("div",{style:{fontSize:10,color:r.textMuted,marginTop:3},children:[h.kind," · ",Math.round(h.score*100),"% · ",h.recommendedAction]}),e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.reason})]},`${h.objectKey??h.name}-${B}`))]})}),(((q=n.parameterDecisions)==null?void 0:q.length)||((re=n.filterBindings)==null?void 0:re.length))&&e.jsx(fe,{title:"Parameter contract",t:r,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[(n.parameterDecisions??[]).slice(0,8).map(h=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:11,fontWeight:800,color:r.textSecondary},children:h.name}),e.jsx("span",{style:{fontSize:10,color:r.textMuted},children:h.policy})]}),e.jsxs("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:[h.sourceExpression," = ",String(h.value)]}),e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.reason})]},h.name)),(n.filterBindings??[]).length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:(n.filterBindings??[]).map(h=>e.jsx(ye,{label:`${h.filter} -> ${h.binding}`,tone:"info",t:r},h.filter))})]})}),e.jsxs(fe,{title:"Grounding",t:r,children:[e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Source tables"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.sourceTables.length?n.lineage.sourceTables.map(h=>e.jsx(ye,{label:h,tone:"info",t:r},h)):e.jsx("span",{style:{fontSize:12,color:r.textMuted},children:"None detected"})})]}),(n.evidence??[]).length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Context used"}),(n.evidence??[]).slice(0,5).map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:7,padding:8,background:r.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:r.textSecondary,overflowWrap:"anywhere"},children:h.name}),e.jsxs("div",{style:{fontSize:10,color:r.textMuted,marginTop:3},children:[h.kind,h.reason?` · ${h.reason}`:""]}),h.description&&e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.35,marginTop:5},children:h.description})]},`${h.objectKey??h.name}-${B}`))]}),e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:r.textMuted,textTransform:"uppercase",fontWeight:800},children:"Parameters"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.parameters.length?n.lineage.parameters.map(h=>e.jsx(ye,{label:h,tone:"warn",t:r},h)):e.jsx("span",{style:{fontSize:12,color:r.textMuted},children:"None detected"})})]}),Be.length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Warnings"}),Be.map((h,B)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:h},B))]})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"Generation audit"}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:10},children:[e.jsx(st,{label:"Method",value:n.generationMode==="ai"?`AI-assisted local generation (${n.generationProvider??"configured provider"})`:"Deterministic local generation",t:r}),Te&&e.jsx(st,{label:"Draft path",value:Te,t:r}),e.jsx(st,{label:"Default test",value:"assert row_count > 0",t:r}),e.jsx(st,{label:"Split strategy",value:n.splitStrategy??"semicolon-go",t:r}),n.llmContext&&e.jsx(st,{label:"Agent use",value:n.llmContext,t:r}),(n.conversionNotes??[]).map((h,B)=>e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.4},children:h},B))]})]}),e.jsxs("details",{style:gt(r),children:[e.jsx("summary",{style:xt(r),children:"AI refine tools"}),e.jsxs("div",{style:{display:"grid",gap:10,marginTop:10},children:[e.jsx("div",{style:{fontSize:12,color:r.textMuted,lineHeight:1.45},children:"Use these only when the generated draft needs a targeted improvement before certification."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[["explain","Explain"],["fix-validation","Fix validation"],["infer-chart","Infer chart"],["propose-tests","Propose tests"]].map(([h,B])=>e.jsx("button",{onClick:()=>void be(h),disabled:!!$e,style:ne(r),children:$e===h?"Working...":B},h))}),(n.aiAssistance??[]).length>0&&e.jsx("div",{style:{display:"grid",gap:8},children:(n.aiAssistance??[]).slice().reverse().map((h,B)=>e.jsxs("div",{style:{border:`1px solid ${r.headerBorder}`,borderRadius:8,padding:9,background:r.appBg},children:[e.jsxs("div",{style:{fontSize:10,color:r.textMuted,fontWeight:800,textTransform:"uppercase"},children:[h.action," · ",h.status]}),e.jsx("div",{style:{fontSize:12,color:r.textSecondary,lineHeight:1.45,marginTop:5},children:h.summary})]},`${h.createdAt}-${B}`))})]})]}),e.jsx("button",{onClick:()=>void p(n),disabled:n.reviewStatus==="rejected",style:{...ne(r),justifySelf:"start"},children:n.reviewStatus==="rejected"?"Rejected":"Reject draft"})]})]})]})}function Ut({index:t,active:n,complete:i,title:s,detail:l,t:a}){const p=i?"#2ea043":n?a.accent:a.textMuted;return e.jsxs("div",{style:{border:`1px solid ${n?a.accent:a.headerBorder}`,borderRadius:8,padding:"9px 10px",display:"grid",gridTemplateColumns:"24px minmax(0, 1fr)",gap:8,alignItems:"center",background:n?`${a.accent}10`:a.cellBg},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${p}18`,color:p,fontSize:11,fontWeight:800,fontFamily:a.font},children:i?"✓":t}),e.jsxs("span",{style:{minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:12,fontWeight:700,color:a.textPrimary,fontFamily:a.font},children:s}),e.jsx("span",{style:{display:"block",fontSize:10,color:a.textMuted,fontFamily:a.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l})]})]})}function ds({t}){const n=[["1","Add SQL","Paste SQL, upload files, or point to an enterprise SQL folder."],["2","Generate drafts","DQL analyzes statements, project metadata, tables, and business context."],["3","Review and certify","Preview results, edit metadata, then certify the governed block."]];return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(lt,{message:"Add SQL to analyze DQL candidates without creating block files."}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:n.map(([i,s,l])=>e.jsxs("div",{style:{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.appBg,padding:12,display:"grid",gap:6},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${t.accent}18`,color:t.accent,fontSize:11,fontWeight:800,fontFamily:t.font},children:i}),e.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary,fontFamily:t.font},children:s}),e.jsx("span",{style:{fontSize:11,color:t.textMuted,fontFamily:t.font,lineHeight:1.4},children:l})]},s))})]})}function $({label:t,children:n,t:i}){return e.jsxs("label",{style:{display:"grid",gap:5},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,color:i.textMuted,letterSpacing:"0.05em",textTransform:"uppercase",fontFamily:i.font},children:t}),n]})}function fe({title:t,hint:n,children:i,t:s}){return e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"176px minmax(0, 1fr)",gap:24,padding:"18px 0",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:s.textPrimary,fontFamily:s.font},children:t}),n?e.jsx("div",{style:{fontSize:11,color:s.textMuted,lineHeight:1.45,marginTop:3,fontFamily:s.font},children:n}):null]}),e.jsx("div",{style:{minWidth:0,display:"grid",gap:10,alignContent:"start"},children:i})]})}function st({label:t,value:n,t:i}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"110px minmax(0, 1fr)",gap:8,fontSize:12,fontFamily:i.font},children:[e.jsx("span",{style:{color:i.textMuted},children:t}),e.jsx("span",{title:n,style:{color:i.textSecondary,overflowWrap:"anywhere"},children:n})]})}function ye({label:t,tone:n,t:i}){const s=n==="ok"?"#2ea043":n==="warn"?"#d29922":i.accent;return e.jsx("span",{style:{fontSize:10,fontWeight:700,color:s,background:`${s}18`,borderRadius:999,padding:"3px 7px",fontFamily:i.font,textTransform:"uppercase"},children:t})}function gt(t){return{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.cellBg,padding:12,color:t.textPrimary,fontFamily:t.font}}function xt(t){return{cursor:"pointer",color:t.textSecondary,fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.05em",fontFamily:t.font}}function Se(t){return{background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:6,color:t.textPrimary,fontSize:12,fontFamily:t.font,padding:"8px 10px",outline:"none",minWidth:0}}function en(t){return{...Se(t),boxSizing:"border-box",fontSize:11.5,minHeight:32,padding:"6px 8px"}}function ne(t){return{background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,color:t.textSecondary,cursor:"pointer",fontSize:11,fontFamily:t.font,padding:"6px 10px"}}function je(t){return{...ne(t),background:`${t.accent}18`,border:`1px solid ${t.accent}`,color:t.accent,fontWeight:700}}function cs({blockName:t,loading:n,detail:i,graph:s,paths:l,onSelectNode:a,onOpenInspector:p,t:y}){if(!t)return e.jsx(lt,{message:"Lineage will appear once the block has a name."});if(n)return e.jsx(lt,{message:"Loading block lineage…"});if(!(i!=null&&i.node))return e.jsxs("div",{style:{padding:12,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:12,color:y.textMuted,fontFamily:y.font},children:"No lineage node was found for this block yet. Save the block to compile and refresh its focused lineage automatically."}),e.jsx("div",{children:e.jsx("button",{onClick:p,style:{background:y.btnBg,border:`1px solid ${y.btnBorder}`,borderRadius:6,color:y.textPrimary,cursor:"pointer",fontSize:11,fontFamily:y.font,padding:"6px 10px"},children:"Open Focused Lineage"})})]});const x=`block:${t}`;return e.jsxs("div",{style:{padding:12,display:"grid",gap:12,overflowY:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:y.textPrimary,fontFamily:y.font},children:i.node.name}),e.jsx("div",{style:{fontSize:11,color:y.textMuted,fontFamily:y.font},children:i.node.domain?`Domain: ${i.node.domain}`:"Block lineage focus"})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:p,style:{background:y.btnBg,border:`1px solid ${y.btnBorder}`,borderRadius:6,color:y.textPrimary,cursor:"pointer",fontSize:11,fontFamily:y.font,padding:"6px 10px"},children:"Open Focused Lineage"})]}),(l==null?void 0:l.layerSummary)&&e.jsx(go,{layerSummary:l.layerSummary,t:y}),s&&s.nodes.length>0&&e.jsx(So,{nodes:s.nodes,edges:s.edges,focalNodeId:x,height:360,onNodeClick:a,layoutMode:"flow"}),l&&(l.upstreamPaths.length>0||l.downstreamPaths.length>0)&&e.jsxs("div",{style:{display:"grid",gap:10},children:[l.upstreamPaths.length>0&&e.jsx(Yn,{title:"Source to Block",paths:l.upstreamPaths,onNodeClick:a,focalNodeId:x,t:y}),l.downstreamPaths.length>0&&e.jsx(Yn,{title:"Block to Consumption",paths:l.downstreamPaths,onNodeClick:a,focalNodeId:x,t:y})]})]})}function us({metadata:t,draftMetadata:n,onChange:i,t:s}){const l={width:"100%",background:s.inputBg,border:`1px solid ${s.inputBorder}`,borderRadius:6,color:s.textPrimary,fontSize:12,fontFamily:s.font,padding:"8px 10px",outline:"none"},a={name:(n==null?void 0:n.name)||(t==null?void 0:t.name)||"",domain:(n==null?void 0:n.domain)||(t==null?void 0:t.domain)||"uncategorized",folderPath:(t==null?void 0:t.folderPath)||"",description:(n==null?void 0:n.description)||(t==null?void 0:t.description)||"",owner:(n==null?void 0:n.owner)||(t==null?void 0:t.owner)||"",tags:(n==null?void 0:n.tags)||(t==null?void 0:t.tags)||[]};return e.jsxs("div",{style:{display:"grid",gap:10,padding:12},children:[e.jsx("input",{value:a.name,onChange:p=>i({name:p.target.value}),placeholder:"Block name",style:l}),e.jsx("input",{value:a.domain,onChange:p=>i({domain:p.target.value}),placeholder:"Domain",style:l}),e.jsx("input",{value:a.folderPath,onChange:p=>i({folderPath:p.target.value}),placeholder:"Folder (optional), e.g. executive/monthly",style:{...l,fontFamily:s.fontMono}}),e.jsx("input",{value:a.owner,onChange:p=>i({owner:p.target.value}),placeholder:"Owner",style:l}),e.jsx("input",{value:a.description,onChange:p=>i({description:p.target.value}),placeholder:"Description",style:l}),e.jsx(ui,{values:a.tags,onChange:p=>i({tags:p}),placeholder:"Tags",style:l})]})}function ps({parameters:t,values:n,onChange:i,onReset:s,onRun:l,running:a,t:p}){return t.length===0?e.jsx(lt,{message:"This block has no runtime parameters. Add typed params in DQL Source when scope should be configurable."}):e.jsxs("div",{style:{padding:14,display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontSize:13,fontWeight:800,color:p.textPrimary},children:"Test parameter values"}),e.jsx("div",{style:{fontSize:11,color:p.textMuted,marginTop:3},children:"These values affect only the preview. Save defaults in the block definition."})]}),e.jsx("button",{type:"button",onClick:l,disabled:a,style:je(p),children:a?"Running…":"Run preview"})]}),e.jsx(wo,{parameters:t,values:n,onChange:i,onReset:s,t:p,includeNonRuntime:!0,card:!0})]})}function fs({values:t,t:n}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t.map(i=>e.jsxs("span",{style:{fontSize:10,color:n.textSecondary,background:n.appBg,border:`1px solid ${n.cellBorder}`,borderRadius:999,padding:"4px 7px"},children:[i.name," = ",Array.isArray(i.value)?i.value.join(", "):String(i.value)," ",e.jsxs("span",{style:{color:n.textMuted},children:["(",i.source,")"]})]},i.name))})}function lt({message:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:16,fontSize:12,color:i.textMuted},children:t})}function hs({elapsedMs:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg,padding:12,color:i.textPrimary,fontFamily:i.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700},children:[e.jsx(rt,{size:16,strokeWidth:2,color:i.accent,"aria-hidden":"true"}),e.jsx("span",{children:"Running preview"}),e.jsx("span",{style:{marginLeft:"auto",color:i.textMuted,fontSize:11,fontWeight:500},children:gs(t)})]}),e.jsx("div",{style:{color:i.textMuted,fontSize:12,lineHeight:1.45},children:"Executing the block query against the active connection."})]})})}function ms({message:t}){const{state:n}=wt(),i=Ct[n.themeMode];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:"1px solid rgba(248, 81, 73, 0.35)",borderRadius:8,background:"rgba(248, 81, 73, 0.08)",color:i.textPrimary,fontFamily:i.font,padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700,color:"#f85149"},children:[e.jsx(Et,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"Preview failed"})]}),e.jsx("div",{style:{color:i.textPrimary,fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t})]})})}function gs(t){const n=Math.max(0,Math.floor(t/1e3));if(n<60)return`${n}s`;const i=Math.floor(n/60),s=n%60;return`${i}m ${s}s`}const ni={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149"},xs={draft:[],review:["draft"],certified:["deprecated"],deprecated:["draft"]};function ys({currentStatus:t,blockPath:n,onStatusChanged:i,t:s}){const[l,a]=c.useState(!1),p=xs[t]??[],y=async x=>{if(n){a(!0);try{const k=await O.updateBlockStatus(n,x);k.ok&&k.status&&i(k.status)}finally{a(!1)}}};return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",background:s.pillBg,borderRadius:8},children:[e.jsx("span",{style:{fontSize:11,color:s.textMuted,fontFamily:s.font},children:"Status:"}),e.jsx("span",{style:{fontSize:11,fontWeight:600,color:ni[t]??s.textMuted,background:`${ni[t]??s.textMuted}18`,padding:"2px 8px",borderRadius:4,textTransform:"uppercase",letterSpacing:"0.04em",fontFamily:s.font},children:t}),e.jsx("span",{style:{flex:1}}),p.map(x=>e.jsx("button",{onClick:()=>void y(x),disabled:l,style:{background:x==="certified"?"#3fb950":x==="deprecated"?"#f85149":s.btnBg,border:`1px solid ${x==="certified"?"#3fb950":x==="deprecated"?"#f85149":s.btnBorder}`,borderRadius:4,color:x==="certified"||x==="deprecated"?"#fff":s.textSecondary,cursor:l?"not-allowed":"pointer",fontSize:10,fontWeight:600,fontFamily:s.font,padding:"3px 10px",textTransform:"capitalize",opacity:l?.5:1},children:l?"...":x==="certified"?"Certify":x==="deprecated"?"Deprecate":`Move to ${x}`},x))]})}function bs({result:t,t:n}){var p,y,x;const i=t.checklist,s=i?[["Metadata",i.metadata],["Validation",i.validation],["Run",i.run],["Tests",i.tests],["Chart",i.chart],["Lineage",i.lineage]]:[],l=Array.from(new Set(((p=t.blockers)!=null&&p.length?t.blockers:(i==null?void 0:i.blockers)??[]).map(vs))),a=Ss(l);return e.jsxs("div",{style:{margin:"12px 12px 0",border:`1px solid ${t.ok?"#3fb95055":"#d2992255"}`,borderRadius:8,background:t.ok?"#3fb9500d":"#d299220d",padding:12,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:t.ok?"#3fb950":"#d29922",fontFamily:n.font},children:t.ok?"Block certified":"Unable to certify"}),(i==null?void 0:i.checkedAt)&&e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.fontMono},children:i.checkedAt})]}),e.jsx("div",{style:{fontSize:12,color:n.textMuted,lineHeight:1.45},children:t.ok?"Latest edits were saved, the block ran successfully, tests passed, and status was updated to certified.":a?`Latest edits were saved, but certification cannot finish because ${a}. Fix it, then click Certify again.`:"Latest edits were saved, but certification cannot finish yet. Fix the blockers below, then click Certify again."}),s.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:s.map(([k,r])=>e.jsxs("span",{style:{fontSize:11,fontWeight:700,color:r?"#3fb950":"#d29922",background:r?"#3fb95018":"#d2992218",borderRadius:999,padding:"4px 8px"},children:[r?"✓":"!"," ",k]},k))}),t.error&&e.jsx("div",{style:{fontSize:12,color:"#f85149"},children:t.error}),l.length>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Missing before certification"}),l.map((k,r)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:k},r))]}),(((x=(y=t.certification)==null?void 0:y.warnings)==null?void 0:x.length)??0)>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:n.textMuted,textTransform:"uppercase",fontWeight:800},children:"Warnings"}),t.certification.warnings.map(k=>e.jsxs("div",{style:{fontSize:12,color:n.textMuted},children:[k.rule,": ",k.message]},`${k.rule}-${k.message}`))]})]})}function vs(t){const n=t.trim(),i=n.toLowerCase();return i==="missing owner"||i==="block has owner: missing owner"?"Owner is required.":i==="missing domain"||i==="block has domain: missing domain"?"Domain is required.":i==="missing description"||i==="block has description: missing description"?"Description is required.":i==="block has not run successfully"?"The query must run successfully.":i==="tests must pass before certification"||i.startsWith("all tests pass:")?"Tests must pass.":i==="at least one test assertion is required before certification"||i.startsWith("block has tests:")?"Add at least one test assertion.":i==="visualization config is missing"?"Choose a visualization.":n}function Ss(t){const n=t.filter(i=>i.endsWith(" is required.")).map(i=>i.replace(" is required.","").toLowerCase());return n.length===0?t[0]?t[0].replace(/\.$/,"").toLowerCase():"":n.length===1?`${n[0]} is missing`:n.length===2?`${n[0]} and ${n[1]} are missing`:n.length>2?`${n.slice(0,-1).join(", ")}, and ${n[n.length-1]} are missing`:t.includes("Add at least one test assertion.")?"a test assertion is missing":t.includes("Choose a visualization.")?"a visualization is missing":t.includes("Tests must pass.")?"tests must pass":t.includes("The query must run successfully.")?"the query has not run successfully":t[0]?t[0].replace(/\.$/,"").toLowerCase():""}function js({entries:t,t:n}){return t.length===0?e.jsx(lt,{message:"No version history available. Commit changes to build history."}):e.jsxs("div",{style:{padding:12,display:"grid",gap:8},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:n.textPrimary,fontFamily:n.font},children:"Version History"}),t.map(i=>e.jsxs("div",{style:{padding:"8px 12px",border:`1px solid ${n.cellBorder}`,borderRadius:8,background:n.inputBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:10,fontFamily:n.fontMono,color:n.accent,background:`${n.accent}12`,padding:"1px 6px",borderRadius:4},children:i.hash.slice(0,7)}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font},children:new Date(i.date).toLocaleDateString()}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font,marginLeft:"auto"},children:i.author})]}),e.jsx("div",{style:{fontSize:12,color:n.textPrimary,fontFamily:n.font},children:i.message})]},i.hash))]})}function ks(t,n){const i=t.match(/query\s*=\s*"""([\s\S]*?)"""/i);return i?t.replace(i[0],`query = """${i[1].trimEnd()}
|
|
28
28
|
${n}
|
|
29
29
|
"""`):/^\s*block\s+"/i.test(t.trim())?t.replace(/\n\}\s*$/,`
|
|
30
30
|
|
|
@@ -34,14 +34,14 @@ ${n}
|
|
|
34
34
|
}
|
|
35
35
|
`):`${t.trimEnd()}
|
|
36
36
|
${n}
|
|
37
|
-
`}function
|
|
37
|
+
`}function ii(t,n){const i=n.trim().replace(/;\s*$/,"");if(!i)return t;const s=t.trim();if(!s)return i;const l=t.match(/query\s*=\s*"""[\s\S]*?"""/i);if(l)return t.replace(l[0],`query = """
|
|
38
38
|
${i}
|
|
39
|
-
"""`);if(/^\s*block\s+"/i.test(
|
|
39
|
+
"""`);if(/^\s*block\s+"/i.test(s)){const a=`
|
|
40
40
|
query = """
|
|
41
41
|
${i}
|
|
42
42
|
"""
|
|
43
43
|
`;return/\}\s*$/.test(t)?t.replace(/\}\s*$/,`${a}}
|
|
44
|
-
`):`${t.trimEnd()}${a}`}return i}function Kt(t){return
|
|
44
|
+
`):`${t.trimEnd()}${a}`}return i}function Kt(t){return co({name:t,status:"draft",metrics:[],dimensions:[],visualization:{chart:"table"}})}function Pt(t){return`block "${t}" {
|
|
45
45
|
domain = "uncategorized"
|
|
46
46
|
type = "custom"
|
|
47
47
|
description = ""
|
|
@@ -57,4 +57,4 @@ SELECT 1 AS value
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
`}const
|
|
60
|
+
`}const bi="dql.block-studio.draft-session";function Jt(){const t=`draft-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;try{window.localStorage.setItem(bi,t)}catch{}return t}function ws(){var t;try{const n=(t=window.localStorage.getItem(bi))==null?void 0:t.trim();if(n)return n}catch{}return Jt()}function Cs(){var t;if(typeof window>"u")return"";try{return((t=window.localStorage.getItem("dql.block-studio.domain"))==null?void 0:t.trim())??""}catch{return""}}function Bs(t,n){try{const i=window.localStorage.getItem(t);return i==null?n:i==="1"}catch{return n}}function Ts(t,n,i,s){try{const l=Number(window.localStorage.getItem(t));return Number.isFinite(l)?Math.min(s,Math.max(i,l)):n}catch{return n}}function Ms(t){return!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath)}function vi(t){var l,a;const n=((l=t==null?void 0:t.domain)==null?void 0:l.trim())||"uncategorized",i=(a=t==null?void 0:t.folderPath)==null?void 0:a.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""),s=((t==null?void 0:t.name)||"new_block").toLowerCase().replace(/[^a-z0-9_]+/g,"-").replace(/^[-_]+|[-_]+$/g,"")||"new-block";return`blocks/${n}/${i?`${i}/`:""}${s}.dql`}function Si(t){var i;const n=((i=t.match(/\bselect\b([\s\S]*?)\bfrom\b/i))==null?void 0:i[1])??"";return n?Array.from(new Set(n.split(",").map(s=>{var p,y;const l=(p=s.match(/\bas\s+([a-zA-Z_][\w$]*)\s*$/i))==null?void 0:p[1];return l||(((y=s.trim().match(/(?:^|\.)([a-zA-Z_][\w$]*)$/))==null?void 0:y[1])??"")}).filter(Boolean))).slice(0,24):[]}function _e(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Is(t,n){const i=n.trim().toLowerCase();if(!i)return t;const s=l=>{const a=[l.label,l.path,l.type].filter(y=>!!y).some(y=>y.toLowerCase().includes(i)),p=(l.children??[]).map(y=>s(y)).filter(y=>!!y);return a||p.length>0?{...l,children:p}:null};return t.map(l=>s(l)).filter(l=>!!l)}function Ds(t){let n=0,i=0,s=0;const l=a=>{a.kind==="schema"&&(n+=1),a.kind==="table"&&(i+=1),a.kind==="column"&&(s+=1);for(const p of a.children??[])l(p)};for(const a of t)l(a);return{schemas:n,tables:i,columns:s}}function zs(t){const n=[],i=s=>{s.kind==="table"&&s.path&&n.push({path:s.path,columns:(s.children??[]).filter(l=>l.kind==="column").map(l=>l.label)});for(const l of s.children??[])i(l)};for(const s of t)i(s);return n}function oi(t){return["businessOutcome","llmContext","primaryTerms","sourceSystems","synonyms","caveats"].filter(i=>new RegExp(`\\b${i}\\s*=`,"i").test(t)).length}function Ps(t){return t.metrics+t.measures+t.dimensions+t.timeDimensions+t.entities+t.hierarchies+t.semanticModels+t.savedQueries}export{sr as BlockStudio};
|