@duckcodeailabs/dql-cli 1.13.2 → 1.13.3
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/apps-api.d.ts +25 -3
- package/dist/apps-api.d.ts.map +1 -1
- package/dist/apps-api.js +1037 -175
- package/dist/apps-api.js.map +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-BlUE3qsX.js → AgentLogPage-B3ugEb3H.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-O88iK6UW.js → AiBuildDialog-BK_TDNcM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-D-6G4Sh3.js → AiBuildResult-Cob_Lj05.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-MRSGtQDV.js → AiSidePanel-CzIgxmP9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-CcRVO6zN.js → AnalyticsHome-C2vJ2fxY.js} +1 -1
- package/dist/assets/dql-notebook/assets/AppsView-DEWQ0sHT.js +5588 -0
- package/dist/assets/dql-notebook/assets/BlockStudio-CaDNTKMM.js +55 -0
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-itEIUrYy.js → BusinessArtifactView-zwUOtddi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-CbAqOpNc.js → DbtFirstModelingPage-BlnhTMu3.js} +4 -4
- package/dist/assets/dql-notebook/assets/{GitPage-BxOqRYu2.js → GitPage-Coevr9NJ.js} +3 -3
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-Tfkx76CI.js → GlobalAiRail-BTZS11x5.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-CeaDbepP.js → GovernedContextPage-CjyyM_ne.js} +3 -3
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-D1lAryYv.js → HelpDocsPage-C1UeP85v.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-GB6se6xW.js → HomePage-zGPFIvOY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-zCyN-hdg.js → LineageDAG-DbXnQWu3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-Cg0TgG2Y.js → LineageDetailView-Ch1Db01I.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-DwMcenDf.js → LineageDrawer-DLxqJO6D.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-DUZx3ksU.js → LineagePathBreadcrumb-B2tNdkr_.js} +3 -3
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-DT_ycl6s.js → MiniLineageGraph-0gY-ZwCy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-qdhzeJPF.js → NewBlockModal-DKVkXD20.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BnaDzs1A.js → NewNotebookModal-BUIByvYT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-CouPFzdo.js → NotebookEditor-D2fIUxjE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-DB_KbH9Y.js → ReadinessPage-Ci4LyNiQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-CamQq_N2.js → SetupOnboarding-BF7ai_0t.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SkillsPage--mYkOAK2.js → SkillsPage-BgYrgirJ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-ClEYiYeA.js → TrustBadge-Bob1Laiq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{UnifiedAgentRunPanel-DBfsmXes.js → UnifiedAgentRunPanel-IxDUKSG8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-Cg3UyGwh.js → answer-to-notebook-Dk42N0pU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-DnYPGqlr.js → arrow-left-DKuuTw9l.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-Ct_YGrmU.js → arrow-right-TH8_ufKG.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-DULlwbj6.js → book-open-text-B-dcHHn0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-ByYxoiS9.js → circle-x-BOc2KCZQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-BjYSO53F.js → dagre.esm-CPT_vn5p.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-DprWh9Yf.js → external-link-DtOfpYc6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-CrEEYkXN.js → grip-vertical-B8joDDH9.js} +1 -1
- package/dist/assets/dql-notebook/assets/index-DJRMz64S.js +635 -0
- package/dist/assets/dql-notebook/assets/{link-2-BkW-rkEC.js → link-2-DMZPHawg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-BipBLmIE.js → list-tree-Dw0qlxPK.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-BhXsglrO.js → minimize-2-DUiSrPS3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-BoCSilYB.js → panel-right-open-BrrFrRZQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{play-mdoZawPu.js → play-Ced0HT9g.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-ELiDRUmj.js → rotate-ccw-D_9U9o7X.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-DVNRLfeU.js → semantic-fields-BlDOaonV.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-GeUzpmKz.js → sliders-horizontal-BDt6KRGR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-D63O81Wp.js → star-CxUbF_BW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-BWrCxQVE.js → triangle-alert-COWnsSdh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{upload-CI-ldXhC.js → upload-DSFC2kJX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-Cv7Yq2hK.js → usePersistedAgentThreadId-DYdx896E.js} +1 -1
- package/dist/assets/dql-notebook/assets/{user-round-Do21aFGo.js → user-round-Bfu7fosn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-DT7u7F_x.js → wand-sparkles-DSpG0c0j.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-DHh2mMbn.js → workflow-B1_pj9gq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-7tYr_GKb.js → wrench-CvfM03KZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CcYceFMz.js → x-B4coLiOl.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/local-runtime.d.ts +47 -19
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +1015 -566
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/AppsView-BTkGC-wl.js +0 -5588
- package/dist/assets/dql-notebook/assets/BlockStudio-BrTNaDpb.js +0 -55
- package/dist/assets/dql-notebook/assets/index-9w93YPF9.js +0 -635
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as sn,r as a,j as e,P as et,
|
|
1
|
+
import{c as sn,r as a,j as e,P as et,aL as qn,aM as Lo,aN as oo,a as X,ar as Ft,$ as No,aO as so,L as Oo,u as Wt,t as _o,aP as io,a4 as Xe,aE as Eo,a0 as qo,aQ as ao,aR as To,aS as Fo,aT as Wo,V as Ho,aU as Uo,aV as lo,B as ro,G as Ko,S as Ht,aW as Yo,aX as Vo,aY as Jo,aZ as Tn,l as Qo,a_ as Go}from"./index-DJRMz64S.js";import{S as Zo,C as Xo}from"./SkillsPage-BgYrgirJ.js";import{u as es,i as ts,B as ns,C as os,b as ss,M as is,T as Fn,N as as,H as ft,c as yt,d as ls}from"./dagre.esm-CPT_vn5p.js";import{L as Ot}from"./link-2-DMZPHawg.js";import{M as co,F as an,u as rs}from"./usePersistedAgentThreadId-DYdx896E.js";import{U as ds}from"./UnifiedAgentRunPanel-IxDUKSG8.js";import{U as cs}from"./upload-DSFC2kJX.js";import{X as us}from"./x-B4coLiOl.js";import{P as ps}from"./panel-right-open-BrrFrRZQ.js";import{G as hs}from"./user-round-Bfu7fosn.js";import{S as xs}from"./sliders-horizontal-BDt6KRGR.js";import{C as tt}from"./circle-x-BOc2KCZQ.js";import{R as gs}from"./rotate-ccw-D_9U9o7X.js";import"./react-CRB3T2We.js";import"./triangle-alert-COWnsSdh.js";import"./TrustBadge-Bob1Laiq.js";import"./AiBuildResult-Cob_Lj05.js";import"./wrench-CvfM03KZ.js";import"./list-tree-Dw0qlxPK.js";import"./minimize-2-DUiSrPS3.js";import"./arrow-right-TH8_ufKG.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -13,10 +13,10 @@ import{c as sn,r as a,j as e,P as et,aJ as qn,aK as Lo,aL as oo,a as Z,ap as Ft,
|
|
|
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 bs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],js=sn("panel-right-close",bs);function vs({modeling:t,ghostEntityIds:n,ghostRelationshipIds:s,relationByDbtId:o,detailsByDbtId:i,selectedDomain:r,selectedAreaId:d,selectedId:h,viewMode:y,columnMode:l,search:u,layoutMode:m,density:f,visibleLimit:c,dimUnrelated:x,showEdgeLabels:I,resetLayoutToken:v,focusRequest:w,onVisibleDbtIdsChange:B,onSelectEntity:b,onSelectRelationship:S,onEditRelationship:P,onDraftRelationship:q,onAddRelatedModel:N,onAddModel:j,onCreateDomain:E,onEditEntity:C,onOpenAi:O,theme:M}){const T=`dql-model-layout:${d??r??"all"}`,re=`${T}:sizes`,[be,de]=a.useState(()=>Wn(T)),[k,D]=a.useState(()=>Hn(re));a.useEffect(()=>de(Wn(T)),[T]),a.useEffect(()=>D(Hn(re)),[re]),a.useEffect(()=>{v&&(localStorage.removeItem(T),localStorage.removeItem(re),de({}),D({}))},[v]);const[A,F]=a.useState(null),[U,V]=a.useState(null),K=(R,oe)=>{const me={...k,[R]:Math.round(oe)};D(me),localStorage.setItem(re,JSON.stringify(me))},{nodes:ie,edges:ce}=a.useMemo(()=>ks(t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,K,M,n,s),[t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,M,n,s]),[De,ge,_e]=es(ie);a.useEffect(()=>ge(ie),[ie,ge]);const we=ie.map(R=>R.data.entity.dbtUniqueId),je=we.join("|");if(a.useEffect(()=>B(we),[B,je]),!ie.length)return e.jsxs("div",{style:{display:"flex",flexDirection:"column",placeItems:"center",justifyContent:"center",alignItems:"center",gap:12,height:"100%",color:M.textMuted},children:[e.jsx("strong",{style:{color:M.textPrimary},children:u.trim()?`No models or columns match “${u.trim()}”.`:"Start your Domain Model"}),!u.trim()&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Bind a dbt model, then connect its columns to define governed analytical relationships."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:E,style:Kn(M),children:[e.jsx(et,{size:13})," Create domain"]}),e.jsxs("button",{onClick:j,style:Kn(M,!0),children:[e.jsx(Ot,{size:13})," Bind first model"]})]})]})]});const H=R=>{!R.source||!R.target||q({from:R.source,to:R.target,fromColumn:Un(R.sourceHandle),toColumn:Un(R.targetHandle)})},Ce=U?t.relationships[U.recordKey]:void 0;return e.jsxs("div",{style:{height:"100%",position:"relative"},onClick:()=>{F(null),V(null)},children:[e.jsx("style",{children:Ds}),e.jsxs(ts,{nodes:De,edges:ce,onNodesChange:_e,nodeTypes:{entity:ws},fitView:!0,fitViewOptions:{padding:.16},minZoom:.2,maxZoom:1.8,nodesDraggable:!0,nodesConnectable:!0,onConnect:H,onNodeDragStop:(R,oe)=>{const me={...be,[oe.id]:oe.position};de(me),localStorage.setItem(T,JSON.stringify(me))},onNodeClick:(R,oe)=>b(oe.id),onNodeDoubleClick:(R,oe)=>C(oe.id),onNodeContextMenu:(R,oe)=>{R.preventDefault(),F({x:R.clientX,y:R.clientY,nodeId:oe.id})},onEdgeClick:(R,oe)=>{R.stopPropagation(),S(oe.id),V({x:Math.min(R.clientX,window.innerWidth-340),y:Math.min(R.clientY,window.innerHeight-320),recordKey:oe.id})},colorMode:M.appBg.toLowerCase().includes("0")?"dark":"light",proOptions:{hideAttribution:!0},children:[e.jsx(Is,{focusRequest:w}),e.jsx(ns,{color:"var(--border-strong)",gap:22,size:1}),e.jsx(os,{showInteractive:!1}),e.jsx(ss,{pannable:!0,zoomable:!0,nodeColor:R=>uo(String(R.data.entity.domain)),maskColor:`${M.appBg}bb`})]},`${m}:${f}:${c}:${v}:${u}`),A&&e.jsxs("div",{style:{position:"fixed",left:A.x,top:A.y,zIndex:50,width:178,border:`1px solid ${M.headerBorder}`,borderRadius:7,background:M.cellBg,boxShadow:"0 12px 32px #0004",padding:4},onClick:R=>R.stopPropagation(),children:[e.jsx(At,{label:"Inspect entity",onClick:()=>{b(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Edit Domain Model binding",onClick:()=>{C(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Ask AI about entity",onClick:()=>{O(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Start relationship",onClick:()=>{q({from:A.nodeId,to:""}),F(null)},theme:M})]}),U&&Ce&&e.jsx(Ss,{relationship:Ce,entities:t.entities,x:U.x,y:U.y,theme:M,onClose:()=>V(null),onEdit:P?()=>{P(U.recordKey),V(null)}:void 0,onViewProof:()=>{S(U.recordKey),V(null)}})]})}function Ss({relationship:t,entities:n,x:s,y:o,theme:i,onClose:r,onEdit:d,onViewProof:h}){var f,c;const y=((f=t.validation)==null?void 0:f.status)==="passed",l=t.keys.map(x=>`${x.from} = ${x.to}`).join(" and ")||"No join keys declared",u=x=>{const I=n[x]??Object.values(n).find(v=>v.id===x||v.localId===x);return(I==null?void 0:I.businessName)||(I==null?void 0:I.localId)||x.split("::").pop()||x},m=x=>e.jsx("span",{style:{padding:"3px 8px",borderRadius:6,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(107,93,211,0.2)",fontFamily:i.fontMono,fontSize:11.5,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x});return e.jsxs("div",{onClick:x=>x.stopPropagation(),style:{position:"fixed",left:s,top:o,zIndex:60,width:316,background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:12,boxShadow:"0 12px 34px rgba(26,26,26,0.16)",overflow:"hidden",fontFamily:i.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)"},children:[e.jsx(Ot,{size:14,color:"var(--accent)",style:{flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:i.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.localId}),e.jsx("span",{style:{flexShrink:0,border:`1px solid ${y?"var(--status-success-border)":"var(--status-warning-border)"}`,color:y?"var(--status-success)":"var(--status-warning)",background:y?"var(--status-success-bg)":"var(--status-warning-bg)",borderRadius:999,padding:"2px 8px",fontSize:9.5,fontWeight:700},children:y?"Proven":"Unproven"}),e.jsx("button",{type:"button",onClick:r,title:"Close",style:{flexShrink:0,width:20,height:20,borderRadius:5,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:"×"})]}),e.jsxs("div",{style:{padding:"12px 13px",display:"flex",flexDirection:"column",gap:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,fontSize:11.5},children:[m(u(t.from)),e.jsx("span",{style:{color:i.textMuted,fontSize:10.5,fontWeight:650,whiteSpace:"nowrap"},children:t.cardinality.replace(/_/g," ")}),m(u(t.to))]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Join"}),e.jsx("div",{style:{fontSize:11,fontFamily:i.fontMono,color:i.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:l})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Business context"}),e.jsx("div",{style:{fontSize:12,lineHeight:1.55,color:i.textSecondary},children:t.description||`${t.from} ${t.verb??"relates to"} ${t.to}. Add a business description so agents can pick this route with confidence.`})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:y?"var(--status-success)":"var(--status-warning)"},children:y?`Join proof passed — ${((c=t.validation)==null?void 0:c.joinedRows)??"?"} rows joined, agents may use this route.`:"No warehouse proof yet — automatic agent joins stay blocked."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[d?e.jsx("button",{type:"button",onClick:d,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:"none",background:"var(--accent)",color:"#fff",fontSize:11.5,fontWeight:650,cursor:"pointer",fontFamily:i.font},children:"Edit relationship"}):null,e.jsx("button",{type:"button",onClick:h,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:`1px solid ${i.headerBorder}`,background:i.cellBg,color:i.textSecondary,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:"View join proof"})]})]})]})}function ws({data:t}){var q,N;const{recordKey:n,entity:s,detail:o,relation:i,selected:r,viewMode:d,columnMode:h,density:y,theme:l,onAddRelatedModel:u,onResize:m}=t,[f,c]=a.useState(y==="compact"),x=uo(s.domain),I=oo(s.analyticalRole),v=s.analyticalRole&&s.analyticalRole!=="unknown"?s.analyticalRole:"entity",w=(o==null?void 0:o.columns)??[],B=new Set(s.keys.length?s.keys:((q=o==null?void 0:o.dqlMeta)==null?void 0:q.keys)??[]),b=new Set(w.filter(j=>!B.has(j.name)&&/(^|_)id$/.test(j.name)).map(j=>j.name)),S=f||d==="business"?[]:h==="all"?w.slice(0,16):h==="keys"?w.filter(j=>B.has(j.name)).slice(0,10):w.filter(j=>B.has(j.name)||j.tests.length>0).slice(0,10),P=(N=s.conceptRefs)!=null&&N.length?s.conceptRefs.join(", "):en(s.localId??s.id);return e.jsxs("div",{style:{position:"relative",width:"100%",minWidth:236,borderRadius:10,overflow:"visible",border:`1.5px solid ${r?"var(--accent)":"var(--border-default)"}`,boxShadow:r?"0 1px 6px rgba(107,93,211,0.14)":"0 1px 4px rgba(26,26,26,0.05)",background:l.cellBg,color:l.textPrimary},children:[e.jsx(as,{position:"bottom-right",resizeDirection:"horizontal",minWidth:240,maxWidth:620,onResizeEnd:(j,E)=>m(n,E.width),style:{width:16,height:16,border:0,background:"transparent",color:l.textMuted},children:e.jsx("span",{title:"Drag to resize model",style:{display:"grid",placeItems:"center"},children:e.jsx(co,{size:12})})}),f&&d==="data"&&e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx("button",{className:"nodrag",title:"Add a related model",onClick:j=>{j.stopPropagation(),u({from:n})},style:{position:"absolute",right:-9,top:-9,zIndex:5,width:22,height:22,display:"grid",placeItems:"center",padding:0,borderRadius:999,border:`2px solid ${l.cellBg}`,background:"var(--accent)",color:"#fff",cursor:"pointer",boxShadow:"0 1px 4px rgba(107,93,211,0.3)"},children:e.jsx(et,{size:12})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"9px 12px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:"8.5px 8.5px 0 0"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:I,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:l.textPrimary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d==="business"?s.businessName||en(s.localId??s.id):s.localId??s.id}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:I},children:v}),d==="data"&&e.jsx("button",{className:"nodrag",title:f?"Expand columns":"Collapse columns",onClick:j=>{j.stopPropagation(),c(E=>!E)},style:{border:0,background:"transparent",color:l.textMuted,cursor:"pointer",padding:0,flexShrink:0},children:f?"▾":"▴"})]}),d==="business"?e.jsxs(e.Fragment,{children:[e.jsx("div",{title:s.businessContext,style:{padding:"9px 12px 7px",fontSize:11.5,lineHeight:1.5,color:l.textSecondary,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:s.businessContext||P}),e.jsxs("div",{style:{display:"flex",gap:6,padding:"0 12px 10px",flexWrap:"wrap"},children:[s.owner?e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.owner}):null,e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.grain?`1 row = ${s.grain}`:s.domain})]})]}):null,S.length>0&&e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",maxHeight:242,overflow:"auto"},children:[S.map(j=>e.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:7,padding:"4px 12px",borderBottom:"1px solid var(--border-subtle)",fontSize:11},children:[e.jsx(ft,{className:"dql-modeling-handle",id:`target:${j.name}`,type:"target",position:yt.Left,style:{...bt(x),top:"50%"}}),e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:l.fontMono,color:B.has(j.name)?"var(--pk)":b.has(j.name)?"var(--fk)":"transparent"},children:B.has(j.name)?"PK":b.has(j.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:l.textSecondary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:B.has(j.name)?700:500},children:j.name}),e.jsx("span",{style:{flexShrink:0,fontSize:9.5,color:l.textMuted,fontFamily:l.fontMono},children:j.type??""}),e.jsx(ft,{className:"dql-modeling-handle",id:`source:${j.name}`,type:"source",position:yt.Right,style:{...bt(x),top:"50%"}})]},j.name)),w.length>S.length&&e.jsxs("div",{style:{padding:"6px 12px",color:l.textMuted,fontSize:9},children:["+ ",w.length-S.length," more dbt-owned columns"]})]}),(f||d==="business")&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx(ft,{className:"dql-modeling-handle",id:"entity-source",type:"source",position:yt.Right,style:bt(x)})]})]})}function ks(t,n,s,o,i,r,d,h,y,l,u,m,f,c,x,I,v,w,B,b,S){const P=i?t.areas[i]:void 0,q=new Set(P?[...P.entityIds,...P.referencedEntityIds]:[]),N=Object.entries(t.relationships).flatMap(([k,D])=>{const A=qn(t,D.from),F=qn(t,D.to);return A&&F?[{recordKey:k,relationship:D,from:A,to:F}]:[]}).filter(({recordKey:k,from:D,to:A})=>{var F,U;return P?P.relationshipIds.includes(k):o?((F=t.entities[D])==null?void 0:F.domain)===o||((U=t.entities[A])==null?void 0:U.domain)===o:!0}),j=new Set(N.flatMap(({from:k,to:D})=>[k,D])),E=y.trim().toLowerCase();let C=Lo(t).filter(({recordKey:k,entity:D})=>{if(P&&!q.has(k)&&!j.has(k)||o&&D.domain!==o&&!j.has(k))return!1;if(!E)return!0;const A=s[D.dbtUniqueId];return[k,D.id,D.qualifiedId,D.domain,A==null?void 0:A.relation,...(A==null?void 0:A.columns.map(F=>F.name))??[]].some(F=>String(F??"").toLowerCase().includes(E))});const O=Math.min(200,m>0?m:50);if(C.length>O){const k=new Map;for(const D of N)k.set(D.from,(k.get(D.from)??0)+1),k.set(D.to,(k.get(D.to)??0)+1);C=[...C].sort((D,A)=>D.recordKey===r?-1:A.recordKey===r?1:(k.get(A.recordKey)??0)-(k.get(D.recordKey)??0)||D.recordKey.localeCompare(A.recordKey)).slice(0,O)}const M=[...new Set(C.map(({entity:k})=>k.domain))].sort(),T=[];M.forEach((k,D)=>C.filter(({entity:A})=>A.domain===k).sort((A,F)=>A.recordKey.localeCompare(F.recordKey)).forEach(({recordKey:A,entity:F},U)=>{const V=s[F.dbtUniqueId],K=d==="business"?0:Ms(F,V,h),ie=I[A]??zs(F,V,n[F.dbtUniqueId],u);T.push({id:A,type:"entity",position:{x:D*390,y:U*190},data:{recordKey:A,entity:F,detail:V,relation:n[F.dbtUniqueId],selected:r===A,viewMode:d,columnMode:h,density:u,theme:B,onAddRelatedModel:v,onResize:w},style:{width:ie,height:116+K*29,...b!=null&&b.has(A)?{outline:"2px dashed var(--accent)",outlineOffset:2,opacity:.9,borderRadius:12}:{}}})}));const re=new Set(T.map(k=>k.id)),be=N.filter(({from:k,to:D})=>re.has(k)&&re.has(D)).map(({recordKey:k,relationship:D,from:A,to:F})=>{var H,Ce;const U=((H=D.validation)==null?void 0:H.status)==="passed";D.automaticJoinAllowed||D.staleCertification;const V=D.keys.map(R=>`${R.from} → ${R.to}`).join(", "),K=D.keys[0],ie=t.entities[A],ce=t.entities[F],De=ie?Xt(ie,s[ie.dbtUniqueId],h):new Set,ge=ce?Xt(ce,s[ce.dbtUniqueId],h):new Set,we=((Ce=D.verb)==null?void 0:Ce.trim())||V,je=(S==null?void 0:S.has(k))??!1;return{id:k,source:A,target:F,sourceHandle:d==="data"&&K&&De.has(K.from)?`source:${K.from}`:void 0,targetHandle:d==="data"&&K&&ge.has(K.to)?`target:${K.to}`:void 0,type:"default",label:c?`${we} · ${Cs(D.cardinality)}${je?" · proposed":""}`:void 0,animated:je||D.status==="review"||D.status==="reviewed",markerEnd:{type:is.ArrowClosed,color:je||r===k?"var(--accent)":"var(--border-strong)"},style:{stroke:je||r===k?"var(--accent)":"var(--border-strong)",strokeWidth:r===k?2:1.5,cursor:"pointer",...je?{strokeDasharray:"6 4",opacity:.85}:{}},labelStyle:{fill:r===k?"var(--accent)":B.textSecondary,fontSize:10.5,fontWeight:650,cursor:"pointer"},labelBgStyle:{fill:B.cellBg,fillOpacity:1,stroke:r===k?"var(--accent)":B.headerBorder,strokeWidth:1},labelBgPadding:[9,4],labelBgBorderRadius:999}}),de=new Fn.graphlib.Graph().setDefaultEdgeLabel(()=>({}));if(de.setGraph({rankdir:"LR",ranksep:u==="compact"?90:u==="wide"?190:135,nodesep:u==="compact"?35:u==="wide"?90:60,marginx:35,marginy:35}),T.forEach(k=>{var D,A;return de.setNode(k.id,{width:Number(((D=k.style)==null?void 0:D.width)??Zt(u)),height:Number(((A=k.style)==null?void 0:A.height)??100)})}),be.forEach(k=>de.setEdge(k.source,k.target)),l==="auto"&&Fn.layout(de),T.forEach(k=>{var F,U;const D=x[k.id];if(D){k.position=D;return}if(l==="grid"){const V=T.indexOf(k),K=Math.max(1,Math.ceil(Math.sqrt(T.length)));k.position={x:V%K*360,y:Math.floor(V/K)*260};return}if(l==="star"){const V=T.indexOf(k);if(V===0){k.position={x:0,y:0};return}const K=(V-1)/Math.max(1,T.length-1)*Math.PI*2;k.position={x:Math.cos(K)*460,y:Math.sin(K)*330};return}const A=de.node(k.id);A&&(k.position={x:A.x-Number(((F=k.style)==null?void 0:F.width)??Zt(u))/2,y:A.y-Number(((U=k.style)==null?void 0:U.height)??100)/2})}),f&&r&&t.entities[r]){const k=new Set([r]);for(const D of N)D.from===r&&k.add(D.to),D.to===r&&k.add(D.from);for(const D of T)D.style={...D.style,opacity:k.has(D.id)?1:.18,transition:"opacity 160ms ease"}}return{nodes:T,edges:be}}function Cs(t){return t==="one_to_one"?"1:1":t==="one_to_many"?"1:N":t==="many_to_one"?"N:1":t==="many_to_many"?"N:N":"?"}function Is({focusRequest:t}){const n=ls(),s=a.useRef(-1);return a.useEffect(()=>{if(!t||t.token===s.current)return;s.current=t.token;const o=window.setTimeout(()=>{var h,y,l,u;const i=n.getNode(t.id);if(!i)return;const r=Number(((h=i.measured)==null?void 0:h.width)??i.width??((y=i.style)==null?void 0:y.width)??280),d=Number(((l=i.measured)==null?void 0:l.height)??i.height??((u=i.style)==null?void 0:u.height)??120);n.setCenter(i.position.x+r/2,i.position.y+d/2,{zoom:Math.max(.85,n.getZoom()),duration:500})},60);return()=>window.clearTimeout(o)},[t,n]),null}function At({label:t,onClick:n,theme:s}){return e.jsx("button",{onClick:n,style:{width:"100%",textAlign:"left",border:0,borderRadius:4,padding:"7px 8px",background:"transparent",color:s.textPrimary,fontSize:11,cursor:"pointer"},children:t})}function Ms(t,n,s){return Xt(t,n,s).size}function Xt(t,n,s){var r;const o=(n==null?void 0:n.columns)??[];if(s==="all")return new Set(o.slice(0,16).map(d=>d.name));const i=new Set(t.keys.length?t.keys:((r=n==null?void 0:n.dqlMeta)==null?void 0:r.keys)??[]);return s==="keys"?new Set(o.filter(d=>i.has(d.name)).slice(0,10).map(d=>d.name)):new Set(o.filter(d=>i.has(d.name)||d.tests.length>0).slice(0,10).map(d=>d.name))}function Zt(t){return t==="compact"?250:t==="wide"?340:280}function zs(t,n,s,o){var r;const i=Math.max(en(t.localId??t.id).length,(s==null?void 0:s.length)??0,((r=n==null?void 0:n.description)==null?void 0:r.length)??0,...((n==null?void 0:n.columns)??[]).map(d=>d.name.length));return Math.min(o==="wide"?440:380,Zt(o)+Math.max(0,i-34)*2)}function Wn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s.x=="number"&&typeof s.y=="number"))}catch{return{}}}function Hn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s=="number"&&s>=240&&s<=620))}catch{return{}}}function Un(t){return t!=null&&t.includes(":")?t.slice(t.indexOf(":")+1):void 0}function bt(t){return{background:t,border:"2px solid var(--color-bg-card)",width:9,height:9,cursor:"crosshair"}}const Ds=`
|
|
16
|
+
*/const bs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],js=sn("panel-right-close",bs);function vs({modeling:t,ghostEntityIds:n,ghostRelationshipIds:s,relationByDbtId:o,detailsByDbtId:i,selectedDomain:r,selectedAreaId:d,selectedId:h,viewMode:y,columnMode:l,search:u,layoutMode:m,density:f,visibleLimit:c,dimUnrelated:x,showEdgeLabels:I,resetLayoutToken:v,focusRequest:w,onVisibleDbtIdsChange:B,onSelectEntity:b,onSelectRelationship:S,onEditRelationship:P,onDraftRelationship:q,onAddRelatedModel:N,onAddModel:j,onCreateDomain:E,onEditEntity:C,onOpenAi:O,theme:M}){const T=`dql-model-layout:${d??r??"all"}`,re=`${T}:sizes`,[be,de]=a.useState(()=>Wn(T)),[k,D]=a.useState(()=>Hn(re));a.useEffect(()=>de(Wn(T)),[T]),a.useEffect(()=>D(Hn(re)),[re]),a.useEffect(()=>{v&&(localStorage.removeItem(T),localStorage.removeItem(re),de({}),D({}))},[v]);const[A,F]=a.useState(null),[U,V]=a.useState(null),K=(R,oe)=>{const me={...k,[R]:Math.round(oe)};D(me),localStorage.setItem(re,JSON.stringify(me))},{nodes:ie,edges:ce}=a.useMemo(()=>ks(t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,K,M,n,s),[t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,M,n,s]),[De,ge,_e]=es(ie);a.useEffect(()=>ge(ie),[ie,ge]);const we=ie.map(R=>R.data.entity.dbtUniqueId),je=we.join("|");if(a.useEffect(()=>B(we),[B,je]),!ie.length)return e.jsxs("div",{style:{display:"flex",flexDirection:"column",placeItems:"center",justifyContent:"center",alignItems:"center",gap:12,height:"100%",color:M.textMuted},children:[e.jsx("strong",{style:{color:M.textPrimary},children:u.trim()?`No models or columns match “${u.trim()}”.`:"Start your Domain Model"}),!u.trim()&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Bind a dbt model, then connect its columns to define governed analytical relationships."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:E,style:Kn(M),children:[e.jsx(et,{size:13})," Create domain"]}),e.jsxs("button",{onClick:j,style:Kn(M,!0),children:[e.jsx(Ot,{size:13})," Bind first model"]})]})]})]});const H=R=>{!R.source||!R.target||q({from:R.source,to:R.target,fromColumn:Un(R.sourceHandle),toColumn:Un(R.targetHandle)})},Ce=U?t.relationships[U.recordKey]:void 0;return e.jsxs("div",{style:{height:"100%",position:"relative"},onClick:()=>{F(null),V(null)},children:[e.jsx("style",{children:Ds}),e.jsxs(ts,{nodes:De,edges:ce,onNodesChange:_e,nodeTypes:{entity:ws},fitView:!0,fitViewOptions:{padding:.16},minZoom:.2,maxZoom:1.8,nodesDraggable:!0,nodesConnectable:!0,onConnect:H,onNodeDragStop:(R,oe)=>{const me={...be,[oe.id]:oe.position};de(me),localStorage.setItem(T,JSON.stringify(me))},onNodeClick:(R,oe)=>b(oe.id),onNodeDoubleClick:(R,oe)=>C(oe.id),onNodeContextMenu:(R,oe)=>{R.preventDefault(),F({x:R.clientX,y:R.clientY,nodeId:oe.id})},onEdgeClick:(R,oe)=>{R.stopPropagation(),S(oe.id),V({x:Math.min(R.clientX,window.innerWidth-340),y:Math.min(R.clientY,window.innerHeight-320),recordKey:oe.id})},colorMode:M.appBg.toLowerCase().includes("0")?"dark":"light",proOptions:{hideAttribution:!0},children:[e.jsx(Is,{focusRequest:w}),e.jsx(ns,{color:"var(--border-strong)",gap:22,size:1}),e.jsx(os,{showInteractive:!1}),e.jsx(ss,{pannable:!0,zoomable:!0,nodeColor:R=>uo(String(R.data.entity.domain)),maskColor:`${M.appBg}bb`})]},`${m}:${f}:${c}:${v}:${u}`),A&&e.jsxs("div",{style:{position:"fixed",left:A.x,top:A.y,zIndex:50,width:178,border:`1px solid ${M.headerBorder}`,borderRadius:7,background:M.cellBg,boxShadow:"0 12px 32px #0004",padding:4},onClick:R=>R.stopPropagation(),children:[e.jsx(At,{label:"Inspect entity",onClick:()=>{b(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Edit Domain Model binding",onClick:()=>{C(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Ask AI about entity",onClick:()=>{O(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Start relationship",onClick:()=>{q({from:A.nodeId,to:""}),F(null)},theme:M})]}),U&&Ce&&e.jsx(Ss,{relationship:Ce,entities:t.entities,x:U.x,y:U.y,theme:M,onClose:()=>V(null),onEdit:P?()=>{P(U.recordKey),V(null)}:void 0,onViewProof:()=>{S(U.recordKey),V(null)}})]})}function Ss({relationship:t,entities:n,x:s,y:o,theme:i,onClose:r,onEdit:d,onViewProof:h}){var f,c;const y=((f=t.validation)==null?void 0:f.status)==="passed",l=t.keys.map(x=>`${x.from} = ${x.to}`).join(" and ")||"No join keys declared",u=x=>{const I=n[x]??Object.values(n).find(v=>v.id===x||v.localId===x);return(I==null?void 0:I.businessName)||(I==null?void 0:I.localId)||x.split("::").pop()||x},m=x=>e.jsx("span",{style:{padding:"3px 8px",borderRadius:6,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(107,93,211,0.2)",fontFamily:i.fontMono,fontSize:11.5,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x});return e.jsxs("div",{onClick:x=>x.stopPropagation(),style:{position:"fixed",left:s,top:o,zIndex:60,width:316,background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:12,boxShadow:"0 12px 34px rgba(26,26,26,0.16)",overflow:"hidden",fontFamily:i.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)"},children:[e.jsx(Ot,{size:14,color:"var(--accent)",style:{flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:i.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.localId}),e.jsx("span",{style:{flexShrink:0,border:`1px solid ${y?"var(--status-success-border)":"var(--status-warning-border)"}`,color:y?"var(--status-success)":"var(--status-warning)",background:y?"var(--status-success-bg)":"var(--status-warning-bg)",borderRadius:999,padding:"2px 8px",fontSize:9.5,fontWeight:700},children:y?"Proven":"Unproven"}),e.jsx("button",{type:"button",onClick:r,title:"Close",style:{flexShrink:0,width:20,height:20,borderRadius:5,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:"×"})]}),e.jsxs("div",{style:{padding:"12px 13px",display:"flex",flexDirection:"column",gap:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,fontSize:11.5},children:[m(u(t.from)),e.jsx("span",{style:{color:i.textMuted,fontSize:10.5,fontWeight:650,whiteSpace:"nowrap"},children:t.cardinality.replace(/_/g," ")}),m(u(t.to))]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Join"}),e.jsx("div",{style:{fontSize:11,fontFamily:i.fontMono,color:i.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:l})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Business context"}),e.jsx("div",{style:{fontSize:12,lineHeight:1.55,color:i.textSecondary},children:t.description||`${t.from} ${t.verb??"relates to"} ${t.to}. Add a business description so agents can pick this route with confidence.`})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:y?"var(--status-success)":"var(--status-warning)"},children:y?`Join proof passed — ${((c=t.validation)==null?void 0:c.joinedRows)??"?"} rows joined, agents may use this route.`:"No warehouse proof yet — automatic agent joins stay blocked."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[d?e.jsx("button",{type:"button",onClick:d,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:"none",background:"var(--accent)",color:"#fff",fontSize:11.5,fontWeight:650,cursor:"pointer",fontFamily:i.font},children:"Edit relationship"}):null,e.jsx("button",{type:"button",onClick:h,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:`1px solid ${i.headerBorder}`,background:i.cellBg,color:i.textSecondary,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:"View join proof"})]})]})]})}function ws({data:t}){var q,N;const{recordKey:n,entity:s,detail:o,relation:i,selected:r,viewMode:d,columnMode:h,density:y,theme:l,onAddRelatedModel:u,onResize:m}=t,[f,c]=a.useState(y==="compact"),x=uo(s.domain),I=oo(s.analyticalRole),v=s.analyticalRole&&s.analyticalRole!=="unknown"?s.analyticalRole:"entity",w=(o==null?void 0:o.columns)??[],B=new Set(s.keys.length?s.keys:((q=o==null?void 0:o.dqlMeta)==null?void 0:q.keys)??[]),b=new Set(w.filter(j=>!B.has(j.name)&&/(^|_)id$/.test(j.name)).map(j=>j.name)),S=f||d==="business"?[]:h==="all"?w.slice(0,16):h==="keys"?w.filter(j=>B.has(j.name)).slice(0,10):w.filter(j=>B.has(j.name)||j.tests.length>0).slice(0,10),P=(N=s.conceptRefs)!=null&&N.length?s.conceptRefs.join(", "):en(s.localId??s.id);return e.jsxs("div",{style:{position:"relative",width:"100%",minWidth:236,borderRadius:10,overflow:"visible",border:`1.5px solid ${r?"var(--accent)":"var(--border-default)"}`,boxShadow:r?"0 1px 6px rgba(107,93,211,0.14)":"0 1px 4px rgba(26,26,26,0.05)",background:l.cellBg,color:l.textPrimary},children:[e.jsx(as,{position:"bottom-right",resizeDirection:"horizontal",minWidth:240,maxWidth:620,onResizeEnd:(j,E)=>m(n,E.width),style:{width:16,height:16,border:0,background:"transparent",color:l.textMuted},children:e.jsx("span",{title:"Drag to resize model",style:{display:"grid",placeItems:"center"},children:e.jsx(co,{size:12})})}),f&&d==="data"&&e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx("button",{className:"nodrag",title:"Add a related model",onClick:j=>{j.stopPropagation(),u({from:n})},style:{position:"absolute",right:-9,top:-9,zIndex:5,width:22,height:22,display:"grid",placeItems:"center",padding:0,borderRadius:999,border:`2px solid ${l.cellBg}`,background:"var(--accent)",color:"#fff",cursor:"pointer",boxShadow:"0 1px 4px rgba(107,93,211,0.3)"},children:e.jsx(et,{size:12})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"9px 12px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:"8.5px 8.5px 0 0"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:I,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:l.textPrimary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d==="business"?s.businessName||en(s.localId??s.id):s.localId??s.id}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:I},children:v}),d==="data"&&e.jsx("button",{className:"nodrag",title:f?"Expand columns":"Collapse columns",onClick:j=>{j.stopPropagation(),c(E=>!E)},style:{border:0,background:"transparent",color:l.textMuted,cursor:"pointer",padding:0,flexShrink:0},children:f?"▾":"▴"})]}),d==="business"?e.jsxs(e.Fragment,{children:[e.jsx("div",{title:s.businessContext,style:{padding:"9px 12px 7px",fontSize:11.5,lineHeight:1.5,color:l.textSecondary,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:s.businessContext||P}),e.jsxs("div",{style:{display:"flex",gap:6,padding:"0 12px 10px",flexWrap:"wrap"},children:[s.owner?e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.owner}):null,e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.grain?`1 row = ${s.grain}`:s.domain})]})]}):null,S.length>0&&e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",maxHeight:242,overflow:"auto"},children:[S.map(j=>e.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:7,padding:"4px 12px",borderBottom:"1px solid var(--border-subtle)",fontSize:11},children:[e.jsx(ft,{className:"dql-modeling-handle",id:`target:${j.name}`,type:"target",position:yt.Left,style:{...bt(x),top:"50%"}}),e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:l.fontMono,color:B.has(j.name)?"var(--pk)":b.has(j.name)?"var(--fk)":"transparent"},children:B.has(j.name)?"PK":b.has(j.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:l.textSecondary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:B.has(j.name)?700:500},children:j.name}),e.jsx("span",{style:{flexShrink:0,fontSize:9.5,color:l.textMuted,fontFamily:l.fontMono},children:j.type??""}),e.jsx(ft,{className:"dql-modeling-handle",id:`source:${j.name}`,type:"source",position:yt.Right,style:{...bt(x),top:"50%"}})]},j.name)),w.length>S.length&&e.jsxs("div",{style:{padding:"6px 12px",color:l.textMuted,fontSize:9},children:["+ ",w.length-S.length," more dbt-owned columns"]})]}),(f||d==="business")&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx(ft,{className:"dql-modeling-handle",id:"entity-source",type:"source",position:yt.Right,style:bt(x)})]})]})}function ks(t,n,s,o,i,r,d,h,y,l,u,m,f,c,x,I,v,w,B,b,S){const P=i?t.areas[i]:void 0,q=new Set(P?[...P.entityIds,...P.referencedEntityIds]:[]),N=Object.entries(t.relationships).flatMap(([k,D])=>{const A=qn(t,D.from),F=qn(t,D.to);return A&&F?[{recordKey:k,relationship:D,from:A,to:F}]:[]}).filter(({recordKey:k,from:D,to:A})=>{var F,U;return P?P.relationshipIds.includes(k):o?((F=t.entities[D])==null?void 0:F.domain)===o||((U=t.entities[A])==null?void 0:U.domain)===o:!0}),j=new Set(N.flatMap(({from:k,to:D})=>[k,D])),E=y.trim().toLowerCase();let C=Lo(t).filter(({recordKey:k,entity:D})=>{if(P&&!q.has(k)&&!j.has(k)||o&&D.domain!==o&&!j.has(k))return!1;if(!E)return!0;const A=s[D.dbtUniqueId];return[k,D.id,D.qualifiedId,D.domain,A==null?void 0:A.relation,...(A==null?void 0:A.columns.map(F=>F.name))??[]].some(F=>String(F??"").toLowerCase().includes(E))});const O=Math.min(200,m>0?m:50);if(C.length>O){const k=new Map;for(const D of N)k.set(D.from,(k.get(D.from)??0)+1),k.set(D.to,(k.get(D.to)??0)+1);C=[...C].sort((D,A)=>D.recordKey===r?-1:A.recordKey===r?1:(k.get(A.recordKey)??0)-(k.get(D.recordKey)??0)||D.recordKey.localeCompare(A.recordKey)).slice(0,O)}const M=[...new Set(C.map(({entity:k})=>k.domain))].sort(),T=[];M.forEach((k,D)=>C.filter(({entity:A})=>A.domain===k).sort((A,F)=>A.recordKey.localeCompare(F.recordKey)).forEach(({recordKey:A,entity:F},U)=>{const V=s[F.dbtUniqueId],K=d==="business"?0:Ms(F,V,h),ie=I[A]??zs(F,V,n[F.dbtUniqueId],u);T.push({id:A,type:"entity",position:{x:D*390,y:U*190},data:{recordKey:A,entity:F,detail:V,relation:n[F.dbtUniqueId],selected:r===A,viewMode:d,columnMode:h,density:u,theme:B,onAddRelatedModel:v,onResize:w},style:{width:ie,height:116+K*29,...b!=null&&b.has(A)?{outline:"2px dashed var(--accent)",outlineOffset:2,opacity:.9,borderRadius:12}:{}}})}));const re=new Set(T.map(k=>k.id)),be=N.filter(({from:k,to:D})=>re.has(k)&&re.has(D)).map(({recordKey:k,relationship:D,from:A,to:F})=>{var H,Ce;const U=((H=D.validation)==null?void 0:H.status)==="passed";D.automaticJoinAllowed||D.staleCertification;const V=D.keys.map(R=>`${R.from} → ${R.to}`).join(", "),K=D.keys[0],ie=t.entities[A],ce=t.entities[F],De=ie?Zt(ie,s[ie.dbtUniqueId],h):new Set,ge=ce?Zt(ce,s[ce.dbtUniqueId],h):new Set,we=((Ce=D.verb)==null?void 0:Ce.trim())||V,je=(S==null?void 0:S.has(k))??!1;return{id:k,source:A,target:F,sourceHandle:d==="data"&&K&&De.has(K.from)?`source:${K.from}`:void 0,targetHandle:d==="data"&&K&&ge.has(K.to)?`target:${K.to}`:void 0,type:"default",label:c?`${we} · ${Cs(D.cardinality)}${je?" · proposed":""}`:void 0,animated:je||D.status==="review"||D.status==="reviewed",markerEnd:{type:is.ArrowClosed,color:je||r===k?"var(--accent)":"var(--border-strong)"},style:{stroke:je||r===k?"var(--accent)":"var(--border-strong)",strokeWidth:r===k?2:1.5,cursor:"pointer",...je?{strokeDasharray:"6 4",opacity:.85}:{}},labelStyle:{fill:r===k?"var(--accent)":B.textSecondary,fontSize:10.5,fontWeight:650,cursor:"pointer"},labelBgStyle:{fill:B.cellBg,fillOpacity:1,stroke:r===k?"var(--accent)":B.headerBorder,strokeWidth:1},labelBgPadding:[9,4],labelBgBorderRadius:999}}),de=new Fn.graphlib.Graph().setDefaultEdgeLabel(()=>({}));if(de.setGraph({rankdir:"LR",ranksep:u==="compact"?90:u==="wide"?190:135,nodesep:u==="compact"?35:u==="wide"?90:60,marginx:35,marginy:35}),T.forEach(k=>{var D,A;return de.setNode(k.id,{width:Number(((D=k.style)==null?void 0:D.width)??Xt(u)),height:Number(((A=k.style)==null?void 0:A.height)??100)})}),be.forEach(k=>de.setEdge(k.source,k.target)),l==="auto"&&Fn.layout(de),T.forEach(k=>{var F,U;const D=x[k.id];if(D){k.position=D;return}if(l==="grid"){const V=T.indexOf(k),K=Math.max(1,Math.ceil(Math.sqrt(T.length)));k.position={x:V%K*360,y:Math.floor(V/K)*260};return}if(l==="star"){const V=T.indexOf(k);if(V===0){k.position={x:0,y:0};return}const K=(V-1)/Math.max(1,T.length-1)*Math.PI*2;k.position={x:Math.cos(K)*460,y:Math.sin(K)*330};return}const A=de.node(k.id);A&&(k.position={x:A.x-Number(((F=k.style)==null?void 0:F.width)??Xt(u))/2,y:A.y-Number(((U=k.style)==null?void 0:U.height)??100)/2})}),f&&r&&t.entities[r]){const k=new Set([r]);for(const D of N)D.from===r&&k.add(D.to),D.to===r&&k.add(D.from);for(const D of T)D.style={...D.style,opacity:k.has(D.id)?1:.18,transition:"opacity 160ms ease"}}return{nodes:T,edges:be}}function Cs(t){return t==="one_to_one"?"1:1":t==="one_to_many"?"1:N":t==="many_to_one"?"N:1":t==="many_to_many"?"N:N":"?"}function Is({focusRequest:t}){const n=ls(),s=a.useRef(-1);return a.useEffect(()=>{if(!t||t.token===s.current)return;s.current=t.token;const o=window.setTimeout(()=>{var h,y,l,u;const i=n.getNode(t.id);if(!i)return;const r=Number(((h=i.measured)==null?void 0:h.width)??i.width??((y=i.style)==null?void 0:y.width)??280),d=Number(((l=i.measured)==null?void 0:l.height)??i.height??((u=i.style)==null?void 0:u.height)??120);n.setCenter(i.position.x+r/2,i.position.y+d/2,{zoom:Math.max(.85,n.getZoom()),duration:500})},60);return()=>window.clearTimeout(o)},[t,n]),null}function At({label:t,onClick:n,theme:s}){return e.jsx("button",{onClick:n,style:{width:"100%",textAlign:"left",border:0,borderRadius:4,padding:"7px 8px",background:"transparent",color:s.textPrimary,fontSize:11,cursor:"pointer"},children:t})}function Ms(t,n,s){return Zt(t,n,s).size}function Zt(t,n,s){var r;const o=(n==null?void 0:n.columns)??[];if(s==="all")return new Set(o.slice(0,16).map(d=>d.name));const i=new Set(t.keys.length?t.keys:((r=n==null?void 0:n.dqlMeta)==null?void 0:r.keys)??[]);return s==="keys"?new Set(o.filter(d=>i.has(d.name)).slice(0,10).map(d=>d.name)):new Set(o.filter(d=>i.has(d.name)||d.tests.length>0).slice(0,10).map(d=>d.name))}function Xt(t){return t==="compact"?250:t==="wide"?340:280}function zs(t,n,s,o){var r;const i=Math.max(en(t.localId??t.id).length,(s==null?void 0:s.length)??0,((r=n==null?void 0:n.description)==null?void 0:r.length)??0,...((n==null?void 0:n.columns)??[]).map(d=>d.name.length));return Math.min(o==="wide"?440:380,Xt(o)+Math.max(0,i-34)*2)}function Wn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s.x=="number"&&typeof s.y=="number"))}catch{return{}}}function Hn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s=="number"&&s>=240&&s<=620))}catch{return{}}}function Un(t){return t!=null&&t.includes(":")?t.slice(t.indexOf(":")+1):void 0}function bt(t){return{background:t,border:"2px solid var(--color-bg-card)",width:9,height:9,cursor:"crosshair"}}const Ds=`
|
|
17
17
|
.dql-modeling-handle { opacity: 0; transition: opacity 0.12s ease; }
|
|
18
18
|
.react-flow__node:hover .dql-modeling-handle,
|
|
19
19
|
.dql-modeling-handle.connecting,
|
|
20
20
|
.dql-modeling-handle:hover { opacity: 1; }
|
|
21
|
-
`;function Kn(t,n=!1){return{display:"inline-flex",alignItems:"center",gap:6,border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,padding:"7px 10px",color:n?t.accent:t.textSecondary,background:n?`${t.accent}12`:t.cellBg,cursor:"pointer",fontSize:11,fontWeight:650}}function en(t){return t.replace(/[._-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function uo(t){const n=["#6d5ce7","#2e9b63","#d47822","#377cc8","#bd4f8b","#8a6d3b"];let s=0;for(const o of t)s=(s<<5)-s+o.charCodeAt(0)|0;return n[Math.abs(s)%n.length]}const $s=so;function po(t,n,s){var f;const o=t.modeling.areas[s??""],i=Object.keys(t.modeling.packages??{}),r=n??(i.length===1?i[0]:xo(((f=t.dbtProvenance)==null?void 0:f.projectName)??"").replace(/-/g,"_")||"analytics"),[d,h]=a.useState(r),[y,l]=a.useState((o==null?void 0:o.localId)??(o==null?void 0:o.id)??$s),u=!i.includes(d),m=!Object.values(t.modeling.areas??{}).some(c=>c.domain===d&&(c.localId===y||c.id===y));return{scopeDomain:d,setScopeDomain:h,scopeArea:y,setScopeArea:l,domains:i,domainIsNew:u,areaIsNew:m}}function ho({scope:t,theme:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("label",{style:_t(n),children:["Domain",e.jsx("input",{"aria-label":"Domain",list:"dql-scope-domains",value:t.scopeDomain,onChange:s=>t.setScopeDomain(s.target.value),style:St(n)}),e.jsx("datalist",{id:"dql-scope-domains",children:t.domains.map(s=>e.jsx("option",{value:s},s))}),e.jsx("small",{style:{color:t.domainIsNew?"var(--status-warning)":n.textMuted},children:t.domainIsNew?"Will be created with these models.":"Existing Domain."})]}),e.jsxs("label",{style:_t(n),children:["Subject area",e.jsx("input",{"aria-label":"Subject area",value:t.scopeArea,onChange:s=>t.setScopeArea(s.target.value),style:St(n)}),e.jsxs("small",{style:{color:t.areaIsNew?"var(--status-warning)":n.textMuted},children:[t.areaIsNew?"Will be created with these models.":"Existing subject area."," A subject area is one focused diagram inside the Domain — it organizes source and sharpens retrieval, and never changes what an agent is allowed to use."]})]})]})}function Rs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState(""),[y,l]=a.useState([]),[u,m]=a.useState({}),[f,c]=a.useState([]),[x,I]=a.useState(1),[v,w]=a.useState(!1),[B,b]=a.useState(null),S=po(t,n,s);a.useEffect(()=>{let j=!0;const E=window.setTimeout(()=>{Z.getDbtModelInventory({q:d,limit:100,physicalOnly:!0}).then(C=>{if(!j)return;const O=C.items.filter(M=>!M.binding);l(O),m(M=>({...M,...Object.fromEntries(O.map(T=>[T.uniqueId,T]))}))}).catch(C=>{j&&b(C instanceof Error?C.message:String(C))})},180);return()=>{j=!1,window.clearTimeout(E)}},[d]);const P=f.flatMap(j=>u[j]?[u[j]]:[]),q=a.useMemo(()=>As(t,S.scopeDomain,S.scopeArea,P),[t,S.scopeArea,S.scopeDomain,P]),N=async()=>{var j;w(!0),b(null);try{const E=await Z.createContextProposal({origin:"dbt_discovery",expectedSnapshotId:(j=t.snapshot)==null?void 0:j.id,operations:q});r(E)}catch(E){b(E instanceof Error?E.message:String(E))}finally{w(!1)}};return e.jsxs(go,{title:"Add models",subtitle:`Step ${x} of 3 · ${x===1?"Select dbt models":x===2?"Assign ownership":"Review proposal inputs"}`,theme:o,busy:v,onClose:i,children:[x===1?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:14,style:{position:"absolute",left:10,top:10,color:o.textMuted}}),e.jsx("input",{autoFocus:!0,"aria-label":"Search dbt models",value:d,onChange:j=>h(j.target.value),placeholder:"Search model name, package, or relation",style:{...St(o),width:"100%",paddingLeft:32}})]}),e.jsxs("div",{style:{display:"grid",gap:6,marginTop:12},children:[y.map(j=>e.jsxs("label",{style:Et(o),children:[e.jsx("input",{type:"checkbox",checked:f.includes(j.uniqueId),onChange:E=>c(C=>E.target.checked?[...C,j.uniqueId]:C.filter(O=>O!==j.uniqueId))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11.5},children:j.name}),e.jsx("code",{style:{color:o.textMuted,fontSize:9.5},children:j.uniqueId})]}),e.jsx("small",{style:{color:o.textMuted},children:j.packageName})]},j.uniqueId)),y.length?null:e.jsx(vt,{theme:o,children:"No unbound dbt models match this search."})]})]}):x===2?e.jsxs(e.Fragment,{children:[e.jsx(ho,{scope:S,theme:o}),e.jsx(vt,{theme:o,children:"Every model receives exactly one Domain and subject area. DQL stores the dbt unique ID and business overlay; dbt-owned columns, SQL, tests, descriptions, and lineage remain in dbt."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[q.length," sparse entity-binding patch",q.length===1?"":"es"," will be prepared. No source changes occur until the exact proposal is reviewed and explicitly saved."]}),P.map(j=>e.jsxs("div",{style:Et(o),children:[e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:j.name}),e.jsx("code",{style:{fontSize:9.5,color:o.textMuted},children:j.uniqueId})]}),e.jsxs("span",{style:{fontSize:10,color:o.textMuted},children:[S.scopeDomain," / ",S.scopeArea]})]},j.uniqueId))]}),B?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:B}):null,e.jsx(tn,{theme:o,busy:v,back:x>1?()=>I(x-1):void 0,next:x<3?()=>I(x+1):()=>void N(),nextLabel:x<3?"Continue":"Create review proposal",disabled:f.length===0||!S.scopeDomain.trim()||!S.scopeArea.trim()})]})}function Bs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState("current_project"),[y,l]=a.useState(""),[u,m]=a.useState(""),[f,c]=a.useState("modeling.yml"),[x,I]=a.useState(null),[v,w]=a.useState([]),[B,b]=a.useState(!1),[S,P]=a.useState(null),q=po(t,n,s),N=async()=>{b(!0),P(null);try{const C=await Z.createModelingImport({mode:d,...d==="path"?{path:y}:{},...d==="paste"||d==="upload"?{content:u,filename:f}:{}});I(C),w(C.candidates.filter(O=>O.action==="import").map(O=>O.id))}catch(C){P(C instanceof Error?C.message:String(C))}finally{b(!1)}},j=async()=>{var C;if(x){b(!0),P(null);try{const O=await Z.previewModelingImport(x.id,{selectedCandidateIds:v,domain:q.scopeDomain,areaId:q.scopeArea,expectedSnapshotId:((C=t.snapshot)==null?void 0:C.id)??""});r(O.proposal)}catch(O){P(O instanceof Error?O.message:String(O))}finally{b(!1)}}},E=C=>{if(!C)return;c(C.name);const O=new FileReader;O.onload=()=>m(String(O.result??"")),O.onerror=()=>P("Could not read the selected YAML file."),O.readAsText(C)};return e.jsxs(go,{title:"Import modeling YAML",subtitle:x?"Classify, select, and review":"Choose a safe import source",theme:o,busy:B,onClose:i,children:[x?e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[e.jsx(an,{size:13,style:{verticalAlign:-2,marginRight:5}}),"DQL modeling becomes a reviewed copy; dbt YAML becomes a sparse overlay. Generic YAML is not imported."]}),e.jsx("div",{style:{display:"grid",gap:7},children:x.candidates.map(C=>e.jsxs("label",{style:{...Et(o),opacity:C.action==="import"?1:.72},children:[e.jsx("input",{type:"checkbox",disabled:C.action!=="import",checked:v.includes(C.id),onChange:O=>w(M=>O.target.checked?[...M,C.id]:M.filter(T=>T!==C.id))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:C.name}),e.jsxs("span",{style:{display:"block",marginTop:2,color:o.textMuted,fontSize:9.5},children:[C.dialect.replace(/_/g," ")," · ",C.summary]}),C.warnings.map(O=>e.jsx("small",{style:{display:"block",color:"var(--status-warning)",marginTop:3},children:O},O))]}),e.jsx("span",{style:{fontSize:9.5,color:o.textMuted},children:C.action.replace(/_/g," ")})]},C.id))}),e.jsx(ho,{scope:q,theme:o}),e.jsx(tn,{theme:o,busy:B,back:()=>{I(null),w([])},next:()=>void j(),nextLabel:"Review exact patches",disabled:!v.length||!q.scopeDomain.trim()||!q.scopeArea.trim()})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:6},children:["current_project","path","upload","paste"].map(C=>e.jsx("button",{type:"button",onClick:()=>h(C),style:{...Ut(o),...d===C?{borderColor:o.accent,color:o.accent,background:"var(--accent-dim)"}:{}},children:C==="current_project"?"Project":C[0].toUpperCase()+C.slice(1)},C))}),d==="current_project"?e.jsxs(vt,{theme:o,children:[e.jsx(No,{size:13,style:{verticalAlign:-2,marginRight:5}}),"Search the current project for DQL and dbt YAML. Existing DQL source opens in place and is not copied."]}):null,d==="path"?e.jsxs("label",{style:_t(o),children:["Local file or directory",e.jsx("input",{"aria-label":"Local YAML path",value:y,onChange:C=>l(C.target.value),placeholder:"models or domains/sales",style:St(o)}),e.jsx("small",{children:"Loopback-only and confined to the current approved project root."})]}):null,d==="upload"?e.jsxs("label",{style:{...Et(o),marginTop:12},children:[e.jsx(cs,{size:15}),e.jsx("span",{style:{flex:1},children:"Choose a YAML file"}),e.jsx("input",{type:"file",accept:".yml,.yaml,text/yaml",onChange:C=>{var O;return E((O=C.target.files)==null?void 0:O[0])}})]}):null,d==="paste"?e.jsxs("label",{style:_t(o),children:["Paste DQL or dbt YAML",e.jsx("textarea",{"aria-label":"Paste modeling YAML",value:u,onChange:C=>m(C.target.value),rows:14,style:{...St(o),resize:"vertical",fontFamily:o.fontMono}})]}):null,e.jsx(tn,{theme:o,busy:B,next:()=>void N(),nextLabel:"Discover YAML",disabled:d==="path"&&!y.trim()||(d==="paste"||d==="upload")&&!u.trim()})]}),S?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:S}):null]})}function As(t,n,s,o){if(!n.trim()||!s.trim())return[];const i=new Set(Object.values(t.modeling.entities).filter(r=>r.domain===n).map(r=>r.localId||r.id));return[...o].sort((r,d)=>r.uniqueId.localeCompare(d.uniqueId)).map(r=>{const d=xo(r.name)||"model";let h=d;i.has(h)&&(h=`${d}-${r.identityFingerprint.slice(0,6).toLowerCase()}`);let y=2;for(;i.has(h);)h=`${d}-${y++}`;return i.add(h),{id:`bind:${r.uniqueId}`,kind:"modeling_change",change:{operation:"upsert_entity",value:{id:h,domain:n,areaId:s,dbtModel:r.uniqueId,businessName:Ps(r.name),status:"draft"}},evidence:[`dbt unique id ${r.uniqueId}`,`manifest fingerprint ${r.identityFingerprint}`]}})}function xo(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64)}function Ps(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function go({title:t,subtitle:n,theme:s,busy:o,onClose:i,children:r}){return e.jsx("div",{onClick:()=>!o&&i(),style:{position:"fixed",inset:0,zIndex:120,background:"rgba(8,10,16,.46)",display:"flex",justifyContent:"flex-end"},children:e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-label":t,onClick:d=>d.stopPropagation(),style:{width:"min(600px, 96vw)",height:"100%",background:s.appBg,borderLeft:"1px solid var(--border-default)",boxShadow:"-16px 0 45px rgba(0,0,0,.22)",display:"flex",flexDirection:"column"},children:[e.jsxs("header",{style:{minHeight:58,padding:"0 18px",borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:14},children:t}),e.jsx("small",{style:{color:s.textMuted},children:n})]}),e.jsx("button",{"aria-label":"Close",disabled:o,onClick:i,style:{...Ut(s),width:30,padding:0},children:e.jsx(us,{size:14})})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:18},children:r})]})})}function tn({theme:t,busy:n,back:s,next:o,nextLabel:i,disabled:r=!1}){return e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[s?e.jsx("button",{type:"button",onClick:s,disabled:n,style:Ut(t),children:"Back"}):null,e.jsxs("button",{type:"button",onClick:o,disabled:n||r,style:{...Ls(t),opacity:n||r?.55:1},children:[n?e.jsx(Oo,{size:13}):null,i]})]})}function vt({theme:t,children:n}){return e.jsx("div",{style:{margin:"12px 0",padding:"10px 11px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)",color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:n})}const St=t=>({boxSizing:"border-box",border:"1px solid var(--border-default)",background:t.inputBg,color:t.textPrimary,borderRadius:7,padding:"8px 9px",outline:"none"}),_t=t=>({display:"grid",gap:6,marginTop:12,color:t.textSecondary,fontSize:11}),Et=t=>({display:"flex",gap:9,alignItems:"center",border:"1px solid var(--border-subtle)",borderRadius:8,background:t.cellBg,padding:"9px 10px"}),Ut=t=>({minHeight:31,border:"1px solid var(--border-default)",borderRadius:7,background:t.cellBg,color:t.textPrimary,padding:"0 11px",cursor:"pointer",display:"inline-flex",gap:6,alignItems:"center",justifyContent:"center"}),Ls=t=>({...Ut(t),background:t.accent,borderColor:t.accent,color:"var(--accent-fg)",fontWeight:650});function Ns(t){return t instanceof Error?t:void 0}function Os(t){return t.details&&typeof t.details=="object"&&!Array.isArray(t.details)?t.details:void 0}function Yn(t){const n=Ns(t);if((n==null?void 0:n.code)==="DBT_FIRST_NOT_ENABLED")return{title:"Set up dbt-first modeling",detail:"Domain Studio requires a connected dbt project with manifest v3 and dbt-first modeling enabled. Open Settings → Project & dbt to connect and apply the project.",status:"Modeling mode · Not enabled"};if((n==null?void 0:n.code)==="DBT_MANIFEST_NOT_FOUND"){const o=Os(n),i=typeof(o==null?void 0:o.manifestPath)=="string"&&o.manifestPath.trim()?o.manifestPath:"target/manifest.json";return{title:"dbt manifest is not ready",detail:`The dbt project is connected, but ${i} was not found. Run dbt parse, dbt compile, or dbt build in the configured dbt project, then refresh Domain Studio.`,status:`dbt manifest · Missing (${i})`}}return(n==null?void 0:n.code)==="DBT_MANIFEST_COMPILE_FAILED"?{title:"dbt manifest could not be loaded",detail:`${n.message} Rebuild the dbt manifest, then refresh Domain Studio.`,status:"dbt manifest · Load failed"}:{title:"Domain Studio could not load",detail:t instanceof Error&&t.message?t.message:"The local DQL notebook server did not return Domain Studio data.",status:"Domain Studio · Unavailable"}}function jt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g," ").trim()}function _s(t,n,s=50){const o=jt(n),i=o.split(/\s+/).filter(Boolean);return t.map(r=>{var f;const d=jt(r.label),h=jt(r.value),y=jt(r.description??""),l=jt(((f=r.keywords)==null?void 0:f.join(" "))??""),u=`${d} ${h} ${y} ${l}`;if(i.length&&!i.every(c=>u.includes(c)))return null;let m=0;return o&&((d===o||h===o)&&(m+=1e3),d.startsWith(o)&&(m+=500),h.startsWith(o)&&(m+=350),d.includes(o)&&(m+=200),m+=i.reduce((c,x)=>c+(d.startsWith(x)?80:d.includes(x)?40:10),0)),{option:r,score:m}}).filter(r=>!!r).sort((r,d)=>d.score-r.score||r.option.label.localeCompare(d.option.label)||r.option.value.localeCompare(d.option.value)).slice(0,Math.max(1,s)).map(({option:r})=>r)}function Ri(){var pt,ht;const{state:t,dispatch:n}=Wt(),s=_o[t.themeMode],[o,i]=a.useState(null),[r,d]=a.useState(!0),[h,y]=a.useState(null),l=a.useMemo(()=>Vn(),[]),[u,m]=a.useState(l.section),[f,c]=a.useState(l.domain),[x,I]=a.useState(l.modelAreaId),[v,w]=a.useState(l.selectedId),[B,b]=a.useState(null),[S,P]=a.useState({}),q=a.useRef(new Map),N=a.useRef(new Set),j=a.useMemo(()=>to(),[]),[E,C]=a.useState(j.viewMode??"business"),[O,M]=a.useState(j.columnMode??"relevant"),[T,re]=a.useState(""),[be,de]=a.useState(0),[k,D]=a.useState(null),[A,F]=a.useState(j.layoutMode??"auto"),[U,V]=a.useState(j.density??"normal"),[K,ie]=a.useState(j.visibleLimit??50),[ce,De]=a.useState(j.dimUnrelated??!0),[ge,_e]=a.useState(j.showEdgeLabels??!0),[we,je]=a.useState(!1),[H,Ce]=a.useState(!1),[R,oe]=a.useState(!1),[me,Ee]=a.useState(()=>typeof window<"u"&&window.innerWidth<980),qe=a.useRef(null),wt=a.useRef(null),[ve,te]=a.useState(null),[ue,pe]=a.useState(null),[nt,ke]=a.useState(null),[$e,ot]=a.useState(()=>to().aiDockOpen===!0),[Te,Kt]=a.useState(null),[st,kt]=a.useState(null),[it,at]=a.useState(null),[Se,Fe]=a.useState(null),[Ct,It]=a.useState(!1),[lt,Re]=a.useState(null);a.useEffect(()=>{localStorage.setItem("dql-modeling-preferences",JSON.stringify({modelingView:E,columnMode:O,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,aiDockOpen:$e}))},[E,O,A,U,K,ce,ge,$e]),a.useEffect(()=>{const g=()=>Ee(window.innerWidth<980);return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);const We=a.useCallback(()=>{oe(g=>{const $=!g;return $?window.requestAnimationFrame(()=>{var G;return(G=wt.current)==null?void 0:G.focus()}):window.requestAnimationFrame(()=>{var G;return(G=qe.current)==null?void 0:G.focus()}),$})},[]),rt=a.useCallback(g=>{m(g),Pt(f,g,!1,x,v)},[x,f,v]),Mt=a.useCallback(g=>{c(g),I(null),w(null),Pt(g,u,!1,null,null)},[u]);a.useEffect(()=>{const g=()=>{const $=Vn();c($.domain),I($.modelAreaId),w($.selectedId),m($.section)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[]),a.useEffect(()=>{Pt(f,u,!0,x,v)},[x,f,v,u]);const Be=async()=>{d(!0);try{const g=await Z.getDbtFirstModeling();i(g),y(null);const $=f&&g.modeling.packages[f]?f:null;$!==f&&(c($),Pt($,u,!0))}catch(g){i(null),y(Yn(g))}finally{d(!1)}};a.useEffect(()=>{Be()},[]),a.useEffect(()=>{let g=null;try{g=window.sessionStorage.getItem("dql-context-proposal-handoff"),g&&window.sessionStorage.removeItem("dql-context-proposal-handoff")}catch{}g&&Z.getContextProposal(g).then($=>{ke($),m($.impact.skillChanges>0&&$.impact.modelingChanges===0?"skills":"diagram")}).catch(()=>{})},[]);const He=a.useMemo(()=>Ws((o==null?void 0:o.modeling)??{entities:{},relationships:{}},Te),[o==null?void 0:o.modeling,Te]),Q=o==null?void 0:o.modeling.entities[v??""],he=o==null?void 0:o.modeling.relationships[v??""],dt=a.useMemo(()=>o?Object.values(o.modeling.areas).filter(g=>!f||g.domain===f).sort((g,$)=>g.name.localeCompare($.name)):[],[o,f]),J=o==null?void 0:o.modeling.areas[x??""];a.useEffect(()=>{o&&x&&!dt.some(g=>g.qualifiedId===x)&&I(null)},[o,dt,x]);const Ue=a.useCallback(g=>{const $=q.current.get(g);if($)return $;if(N.current.has(g))return Promise.resolve(void 0);const G=Z.getDbtModelingNode(g).then(Ie=>(N.current.add(g),P(Je=>({...Je,[g]:Ie})),Ie)).catch(()=>{N.current.add(g)}).finally(()=>q.current.delete(g));return q.current.set(g,G),G},[]);a.useEffect(()=>{if(!Q){b(null);return}const g=S[Q.dbtUniqueId];if(g){b(g);return}let $=!1;return Ue(Q.dbtUniqueId).then(G=>{$||b(G??null)}),()=>{$=!0}},[S,Ue,Q==null?void 0:Q.dbtUniqueId]),a.useEffect(()=>{q.current.clear(),N.current.clear(),P({})},[o==null?void 0:o.dbtProvenance.manifestFingerprint]);const Ke=a.useCallback(g=>{for(const $ of g.slice(0,24))Ue($)},[Ue]);if(r&&!o)return e.jsx(Xn,{t:s,title:"Loading Domain Studio…",detail:"Compiling dbt provenance and the sparse DQL analytical overlay."});if(!o){const g=h??Yn(null);return e.jsx(Xn,{t:s,title:g.title,detail:g.detail,status:g.status})}const zt=Object.fromEntries(Object.values(o.dbtProvenance.nodes).map(g=>[g.uniqueId,g.relation])),Ye=Object.entries(o.modeling.entities).flatMap(([g,$])=>{var Je;const G=$.businessName||$.localId||$.id,Ie=[{recordKey:g,type:"model",label:G,sublabel:$.domain,role:$.analyticalRole}];for(const $t of((Je=S[$.dbtUniqueId])==null?void 0:Je.columns)??[])Ie.push({recordKey:g,type:"column",label:$t.name,sublabel:G,role:$.analyticalRole});return Ie}),Dt=g=>{w(g),re(""),D($=>({id:g,token:(($==null?void 0:$.token)??0)+1}))},Ae=J?new Set([...J.entityIds,...J.referencedEntityIds]):void 0,ct=io(o.modeling,f).filter(({recordKey:g})=>!Ae||Ae.has(g)),Pe=Object.values(o.modeling.relationships).filter(g=>{const $=o.modeling.entities[g.from],G=o.modeling.entities[g.to];return J?J.relationshipIds.includes(g.qualifiedId):!f||($==null?void 0:$.domain)===f||(G==null?void 0:G.domain)===f});Object.values(o.dbtProvenance.nodes).filter(g=>!Object.values(o.modeling.entities).some($=>$.dbtUniqueId===g.uniqueId));const ut=R&&u==="diagram",Ve=[...new Set(f?((ht=(pt=o.domainAssets)==null?void 0:pt[f])==null?void 0:ht.skills)??[]:Object.values(o.domainAssets??{}).flatMap(g=>g.skills??[]))].sort();return e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",background:s.appBg,color:s.textPrimary},children:[e.jsx("header",{style:{minHeight:52,padding:"0 14px",borderBottom:`1px solid ${s.headerBorder}`,background:s.headerBg,display:"flex",alignItems:"center"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",width:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx(Ze,{size:16,color:s.accent}),e.jsx("h1",{style:{margin:0,fontSize:12,fontWeight:800,whiteSpace:"nowrap"},children:"Modeling workspace"}),e.jsx("span",{style:{color:s.textMuted,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f?`/${f}`:"/all domains"})]}),e.jsxs("div",{style:{display:"flex",gap:7},children:[f&&e.jsxs(se,{t:s,onClick:()=>{try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},children:[e.jsx(Eo,{size:14})," Ask"]}),e.jsxs(se,{t:s,onClick:()=>pe("yaml"),children:[e.jsx(an,{size:14})," Import YAML"]}),e.jsx(si,{t:s,title:"Recompile",onClick:()=>void Be(),children:e.jsx(qo,{size:15})})]})]})}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"grid",gridTemplateColumns:ut&&!me?"clamp(190px, 15vw, 232px) minmax(460px, 1fr) clamp(270px, 22vw, 380px)":"clamp(190px, 15vw, 232px) minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${s.headerBorder}`,overflow:"auto",background:s.appBg},children:[e.jsx(qs,{data:o,selectedDomain:f,onSelect:Mt,t:s}),e.jsx(Ts,{data:o,domain:f,active:u,onSelect:rt,t:s}),e.jsx("div",{style:{padding:"10px 12px",borderTop:`1px solid ${s.headerBorder}`,display:"flex",flexDirection:"column",gap:5,fontSize:10.5,color:s.textMuted,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(--status-success)",flexShrink:0}}),"dbt synced · ",Object.keys(o.dbtProvenance.nodes).length," model",Object.keys(o.dbtProvenance.nodes).length===1?"":"s"]})})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{minHeight:42,display:"flex",alignItems:"center",gap:7,padding:"0 10px 0 14px",borderBottom:`1px solid ${s.headerBorder}`,background:s.headerBg},children:[mo(u,14,s),e.jsx("strong",{style:{fontSize:11},children:Fs(u)}),e.jsx("span",{style:{width:1,height:15,background:s.headerBorder}}),e.jsx("span",{style:{color:s.textMuted,fontSize:10},children:f??"All domains"}),(u==="diagram"||u==="skills")&&f&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:5},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:s.textMuted,fontSize:10},children:["Area",e.jsxs("select",{"aria-label":"Active subject area",value:x??"",onChange:g=>{I(g.target.value||null),w(null)},style:{...ye(s),minWidth:146,padding:"4px 6px"},children:[e.jsx("option",{value:"",children:"All domain"}),dt.map(g=>e.jsx("option",{value:g.qualifiedId,children:g.name},g.qualifiedId))]})]}),e.jsx("button",{"aria-label":"Add subject area",title:"Add subject area",onClick:()=>te({kind:"area"}),style:{...ze(s),width:27,height:27},children:e.jsx(et,{size:13})})]}),u==="diagram"&&e.jsx("button",{ref:qe,"aria-expanded":R,"aria-controls":"domain-studio-inspector","aria-label":R?"Hide inspector":"Show inspector",title:R?"Hide inspector":"Show inspector",onClick:We,style:{...ze(s),marginLeft:"auto"},children:R?e.jsx(js,{size:14}):e.jsx(ps,{size:14})})]}),e.jsxs("div",{style:{flex:1,minHeight:0},children:[u==="diagram"&&e.jsxs("div",{id:"dql-modeling-diagram",style:{height:"100%",display:"flex",flexDirection:"column",...H?{position:"fixed",inset:0,zIndex:90,background:s.appBg}:{}},children:[e.jsx(Ys,{modelingView:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,showLegend:we,fullscreen:H,aiOpen:$e,onBindModel:()=>pe("models"),onRelationship:()=>te({kind:"relationship"}),onToggleAi:()=>ot(g=>!g),onModelingView:C,onColumnMode:M,onSearch:re,searchItems:Ye,onPickModel:Dt,onLayoutMode:F,onDensity:V,onVisibleLimit:ie,onDimUnrelated:De,onEdgeLabels:_e,onLegend:je,onFullscreen:()=>Ce(g=>!g),onExport:()=>Qs(),onReset:()=>de(g=>g+1),t:s}),J?e.jsxs("div",{style:{padding:"7px 14px",borderBottom:`1px solid ${s.headerBorder}`,background:"var(--accent-dim)",color:s.textSecondary,display:"flex",alignItems:"center",gap:8,fontSize:10.5},children:[e.jsx(Ze,{size:13,color:s.accent}),e.jsx("strong",{style:{color:s.textPrimary},children:J.name}),e.jsx("span",{children:J.description??"Focused business modeling area"}),e.jsxs("span",{style:{marginLeft:"auto",color:s.textMuted},children:[J.entityIds.length," model",J.entityIds.length===1?"":"s"," · ",J.intentExamples.length," example question",J.intentExamples.length===1?"":"s"]})]}):null,we&&e.jsx(Vs,{t:s}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:ct.length===0?e.jsx(Js,{t:s,connectedModels:Object.keys(o.dbtProvenance.nodes).length,onDbt:()=>pe("models"),onYaml:()=>pe("yaml"),onManual:()=>te({kind:"entity"})}):e.jsx(vs,{modeling:He.modeling,ghostEntityIds:He.ghostEntityIds,ghostRelationshipIds:He.ghostRelationshipIds,relationByDbtId:zt,detailsByDbtId:S,selectedDomain:f,selectedAreaId:x,selectedId:v,viewMode:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,resetLayoutToken:be,focusRequest:k??void 0,onVisibleDbtIdsChange:Ke,onSelectEntity:w,onSelectRelationship:w,onEditRelationship:g=>{const $=o.modeling.relationships[g];$&&te({kind:"relationship",relationship:$})},onDraftRelationship:g=>te({kind:"relationship",draft:g}),onAddRelatedModel:g=>te({kind:"entity",relationshipFrom:g}),onAddModel:()=>pe("models"),onCreateDomain:()=>te({kind:"domain"}),onEditEntity:g=>{const $=o.modeling.entities[g];$&&te({kind:"entity",entity:$,dbtUniqueId:$.dbtUniqueId})},onOpenAi:g=>{w(g);try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId,objectId:g}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},theme:s})}),$e&&e.jsx("aside",{"aria-label":"Modeling AI",style:{width:"clamp(320px, 30vw, 460px)",borderLeft:`1px solid ${s.headerBorder}`,background:s.appBg,display:"flex",flexDirection:"column",minHeight:0},children:e.jsx(Xs,{domain:f,areaId:x,selectedId:v,data:o,themeMode:t.themeMode,t:s,correction:st,onClose:()=>ot(!1),onCorrectionStarted:()=>kt(null),onReviewProposal:ke,onPreviewProposal:Kt,onOpenSkills:()=>rt("skills"),onDraftRelationship:()=>te({kind:"relationship",draft:Q&&v?{from:v,to:""}:void 0})})})]})]}),u==="skills"&&e.jsx(Xo,{embedded:!0,domainFilter:f,modelAreaFilter:x,sourcePathFilter:Ve}),u==="blocks"&&e.jsx(Gs,{data:o,domain:f,t:s}),u==="notebooks"&&e.jsx(Jn,{data:o,domain:f,kind:"notebooks",t:s}),u==="apps"&&e.jsx(Jn,{data:o,domain:f,kind:"apps",t:s})]})]}),ut&&e.jsxs("aside",{id:"domain-studio-inspector",ref:wt,role:"complementary","aria-label":"Domain Studio inspector",tabIndex:-1,onKeyDown:g=>{g.key==="Escape"&&We()},style:{borderLeft:`1px solid ${s.headerBorder}`,overflow:"auto",background:s.appBg,minWidth:0,...me?{position:"fixed",inset:"0 0 0 auto",width:"min(90vw, 380px)",zIndex:95,boxShadow:"-12px 0 30px rgba(0,0,0,.18)"}:{}},children:[e.jsx(ii,{t:s,children:"Inspector"}),Q?e.jsx(Zs,{entity:Q,detail:B,relationships:Pe,t:s,onEdit:()=>te({kind:"entity",entity:Q,dbtUniqueId:Q.dbtUniqueId}),onEditDbtSource:()=>at(Q),onSelectRelationship:g=>w(nn(o.modeling.relationships,g)),onDelete:()=>{Re(null),Fe({kind:"entity",id:Q.localId||Q.id,domain:Q.domain,areaId:Q.areaId,label:Q.businessName||Q.localId||Q.id})}}):he?e.jsx(ti,{relationship:he,t:s,onEdit:()=>te({kind:"relationship",relationship:he}),onDelete:()=>{Re(null),Fe({kind:"relationship",id:he.localId||he.id,domain:he.ownerDomain??he.qualifiedId.split("::")[0],areaId:he.areaId,label:he.localId||he.id})}}):e.jsx(ni,{data:o,domainEntities:ct.map(({entity:g})=>g),domainRelationships:Pe,t:s,onSelectRelationship:g=>w(nn(o.modeling.relationships,g))})]})]}),ue==="models"?e.jsx(Rs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,ue==="yaml"?e.jsx(Bs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,nt?e.jsx(Zo,{proposal:nt,theme:s,onClose:()=>ke(null),onCommitted:()=>{ke(null),Be()}}):null,ve&&e.jsx(Us,{editor:ve,data:o,selectedDomain:f,selectedArea:J,t:s,onClose:()=>te(null),onProposal:g=>{te(null),ke(g)},onFixWithAi:(g,$)=>{te(null),g&&w(g),rt("diagram"),ot(!0),kt({text:"Fix the failed relationship validation. Keep it draft, remove stale proof, and explain the corrected cardinality, fanout, or keys using the attached receipt.",nonce:Date.now(),evidence:$})},onApplied:async g=>{te(null),await Be(),ve.kind==="entity"&&ve.relationshipFrom&&g.operation==="upsert_entity"&&te({kind:"relationship",draft:{...ve.relationshipFrom,to:g.value.id}})}}),it&&B&&e.jsx(ei,{entity:it,detail:B,snapshotId:o.snapshotId,t:s,onClose:()=>at(null),onApplied:async()=>{at(null),await Be()}}),Se&&e.jsx(Es,{pending:Se,busy:Ct,error:lt,t:s,onCancel:()=>{Fe(null),Re(null)},onConfirm:async()=>{It(!0),Re(null);try{const g={operation:Se.kind==="entity"?"remove_entity":"remove_relationship",value:{id:Se.id,domain:Se.domain,...Se.areaId?{areaId:Se.areaId}:{}}},$=await Z.createContextProposal({origin:"manual",expectedSnapshotId:o.snapshotId,operations:[{id:`manual:${g.operation}:${Se.id}`,kind:"modeling_change",change:g,evidence:["manual Modeling workspace removal"]}]});if(!$.patches.some(G=>G.changed))throw new Error("Nothing to remove — it is no longer in the domain source.");Fe(null),w(null),ke($)}catch(g){Re(g instanceof Error?g.message:String(g))}finally{It(!1)}}})]})}function Es({pending:t,busy:n,error:s,t:o,onCancel:i,onConfirm:r}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`Delete ${t.kind}`,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.34)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:130},onClick:d=>{d.target===d.currentTarget&&!n&&i()},children:e.jsxs("div",{style:{width:"min(92vw, 420px)",background:o.appBg,border:`1px solid ${o.headerBorder}`,borderRadius:12,padding:18,boxShadow:"0 18px 44px rgba(0,0,0,.22)"},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:700,color:o.textPrimary,marginBottom:6},children:["Delete this ",t.kind,"?"]}),e.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5},children:[e.jsx("strong",{style:{fontFamily:o.fontMono},children:t.label})," will be removed from the"," ",e.jsx("strong",{children:t.domain})," domain source. dbt models and warehouse data are not affected."]}),t.kind==="entity"?e.jsx("div",{style:{fontSize:11.5,color:o.textMuted,marginTop:8,lineHeight:1.5},children:"Relationships that reference it are left in place and will report a missing endpoint until you remove or repoint them."}):null,s?e.jsx("div",{style:{fontSize:11.5,color:o.error,marginTop:10,lineHeight:1.5},children:s}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[e.jsx(se,{t:o,onClick:i,disabled:n,children:"Cancel"}),e.jsx(se,{t:o,danger:!0,onClick:r,disabled:n,children:n?"Deleting…":`Delete ${t.kind}`})]})]})})}function qs({data:t,selectedDomain:n,onSelect:s,t:o}){const{state:i}=Wt(),r=Wo(t.modeling.packages),d=new Map(Ho(i.authoredDomains).map(h=>[h.value,h.label]));return e.jsx("nav",{"aria-label":"Domain packages",children:e.jsx(Uo,{id:"domain-workspace-filter",ariaLabel:"Domain workspace",value:n??"",options:r.map(h=>({value:h.id,label:d.get(h.id)??h.label})),onChange:h=>s(h||null),summary:e.jsxs(e.Fragment,{children:[r.length," authored domain",r.length===1?"":"s"," available"]}),t:o})})}function Ts({data:t,domain:n,active:s,onSelect:o,t:i}){var y;const r=n?[((y=t.domainAssets)==null?void 0:y[n])??{}]:Object.values(t.domainAssets??{}),h={diagram:io(t.modeling,n).length,skills:r.reduce((l,u)=>{var m;return l+(((m=u.skills)==null?void 0:m.length)??0)},0),blocks:new Set(r.flatMap(l=>l.blocks??[])).size};return e.jsx("nav",{"aria-label":n?`${n} workspace`:"All domains workspace",style:{padding:"10px 7px 14px"},children:lo.map((l,u)=>e.jsxs("div",{style:{marginTop:u===0?0:12},children:[l.label?e.jsx("div",{style:{padding:"0 8px 6px",color:i.textMuted,fontSize:9,fontWeight:800,textTransform:"uppercase",letterSpacing:".06em"},children:l.label}):null,l.items.map(m=>e.jsxs("button",{onClick:()=>o(m.id),"aria-current":s===m.id?"page":void 0,style:ri(i,s===m.id,!1),children:[mo(m.id,14,i,s===m.id),e.jsx("span",{style:{flex:1},children:m.label}),h[m.id]!==void 0&&e.jsx("small",{style:{color:s===m.id?i.accent:i.textMuted},children:h[m.id]})]},m.id))]},l.label??`group-${u}`))})}function mo(t,n,s,o=!1){const i=t==="blocks"?ro:t==="diagram"?Ko:t==="skills"?hs:t==="notebooks"||t==="apps"?Gt:Ze;return e.jsx(i,{size:n,color:o?s.accent:s.textMuted})}function Fs(t){var n;return((n=lo.flatMap(s=>s.items).find(s=>s.id===t))==null?void 0:n.label)??t}function Vn(){if(typeof window>"u")return{domain:null,section:"diagram",modelAreaId:null,selectedId:null};let t=null;try{t=window.localStorage.getItem(ao)}catch{t=null}return To(window.location.href,t)}function Pt(t,n,s=!1,o=null,i=null){if(typeof window>"u")return;const r=Fo(window.location.href,{domain:t,section:n,modelAreaId:o,selectedId:i});s?window.history.replaceState(window.history.state,"",r):window.history.pushState(window.history.state,"",r);try{window.localStorage.setItem(ao,JSON.stringify({domain:t,section:n,modelAreaId:o,selectedId:i}))}catch{}}function Ws(t,n){const s=new Set,o=new Set;if(!n)return{modeling:t,ghostEntityIds:s,ghostRelationshipIds:o};const i={...t.entities},r={...t.relationships};for(const d of n.operations){if(d.kind!=="modeling_change")continue;const h=d.change;if(h.operation==="upsert_entity"){const y=`${h.value.domain}::entity::${h.value.id}`;s.add(y),i[y]={...i[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,domain:h.value.domain,dbtUniqueId:h.value.dbtModel,businessName:h.value.businessName,businessContext:h.value.businessContext,grain:h.value.grain,keys:h.value.keys??[],analyticalRole:h.value.analyticalRole,status:"draft",sourcePath:"(proposed)",identityFingerprint:`ghost:${y}`}}else if(h.operation==="upsert_relationship"){const y=`${h.value.domain}::relationship::${h.value.id}`;o.add(y),r[y]={...r[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,from:`${h.value.domain}::entity::${h.value.from}`,to:`${h.value.domain}::entity::${h.value.to}`,keys:h.value.keys,cardinality:h.value.cardinality,fanout:h.value.fanout,status:"draft",crossDomain:!1,ownerDomain:h.value.domain,verb:h.value.verb,description:h.value.description,rationale:h.value.rationale,sourcePath:"(proposed)",fingerprint:`ghost:${y}`,staleCertification:!1,automaticJoinAllowed:!1}}}return{modeling:{...t,entities:i,relationships:r},ghostEntityIds:s,ghostRelationshipIds:o}}function Hs(t){var o;const n=Object.keys(t.modeling.packages??{});return n.length===1?n[0]:(((o=t.dbtProvenance)==null?void 0:o.projectName)??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")||"analytics"}function nn(t,n){const s=Object.entries(t).find(([,o])=>o===n);return s?s[0]:n.qualifiedId??n.id}function Us({editor:t,data:n,selectedDomain:s,selectedArea:o,t:i,onClose:r,onProposal:d,onFixWithAi:h,onApplied:y}){var bn,jn,vn,Sn,wn,kn,Cn,In,Mn,zn,Dn,$n,Rn,Bn,An,Pn,Ln,Nn,On,_n,En;const l=t.kind==="relationship"?t.relationship:void 0,u=t.kind==="entity"?t.entity:void 0,m=t.kind==="area"?t.area:void 0,f=t.kind==="relationship"?t.draft:void 0,[c,x]=a.useState((m==null?void 0:m.domain)??(u==null?void 0:u.domain)??s??Object.keys(n.modeling.packages)[0]??Hs(n)),[I,v]=a.useState((m==null?void 0:m.localId)??((bn=n.modeling.areas[(u==null?void 0:u.areaId)??(l==null?void 0:l.areaId)??""])==null?void 0:bn.localId)??(o==null?void 0:o.localId)??so),[w,B]=a.useState((l==null?void 0:l.localId)??(u==null?void 0:u.localId)??(m==null?void 0:m.localId)??""),[b,S]=a.useState((l==null?void 0:l.owner)??(u==null?void 0:u.owner)??""),[P,q]=a.useState(""),[N,j]=a.useState(t.kind==="entity"?(u==null?void 0:u.dbtUniqueId)??t.dbtUniqueId??"":""),[E,C]=a.useState((u==null?void 0:u.businessName)??""),[O,M]=a.useState((u==null?void 0:u.businessContext)??""),[T,re]=a.useState(((jn=u==null?void 0:u.conceptRefs)==null?void 0:jn.join(", "))??""),[be,de]=a.useState((u==null?void 0:u.analyticalRole)??"unknown"),[k,D]=a.useState((u==null?void 0:u.status)??"draft"),[A,F]=a.useState((u==null?void 0:u.grain)??""),[U,V]=a.useState((u==null?void 0:u.keys.join(", "))??""),[K,ie]=a.useState((m==null?void 0:m.name)??""),[ce,De]=a.useState((m==null?void 0:m.description)??""),[ge,_e]=a.useState((m==null?void 0:m.intentExamples.join(", "))??""),[we,je]=a.useState((m==null?void 0:m.referencedEntityIds.map(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.localId)??p}).join(", "))??""),[H,Ce]=a.useState((l==null?void 0:l.from)??(f==null?void 0:f.from)??""),[R,oe]=a.useState((l==null?void 0:l.to)??(f==null?void 0:f.to)??""),[me,Ee]=a.useState((l==null?void 0:l.keys.map(p=>`${p.from}=${p.to}`).join(", "))??(f!=null&&f.fromColumn&&f.toColumn?`${f.fromColumn}=${f.toColumn}`:"")),[qe,wt]=a.useState((l==null?void 0:l.cardinality)??"unknown"),[ve,te]=a.useState((l==null?void 0:l.fanout)??"unknown"),[ue,pe]=a.useState((l==null?void 0:l.status)??"draft"),[nt,ke]=a.useState((l==null?void 0:l.verb)??""),[$e,ot]=a.useState((l==null?void 0:l.description)??""),[Te,Kt]=a.useState(((vn=l==null?void 0:l.roles)==null?void 0:vn.from)??""),[st,kt]=a.useState(((Sn=l==null?void 0:l.roles)==null?void 0:Sn.to)??""),[it,at]=a.useState(((wn=l==null?void 0:l.optionality)==null?void 0:wn.from)??"unknown"),[Se,Fe]=a.useState(((kn=l==null?void 0:l.optionality)==null?void 0:kn.to)??"unknown"),[Ct,It]=a.useState(((Cn=l==null?void 0:l.joinTypes)==null?void 0:Cn.join(", "))??"left"),[lt,Re]=a.useState(((In=l==null?void 0:l.aggregation)==null?void 0:In.measuresFrom.join(", "))??""),[We,rt]=a.useState(((Mn=l==null?void 0:l.aggregation)==null?void 0:Mn.dimensionsFrom.join(", "))??""),[Mt,Be]=a.useState(((zn=l==null?void 0:l.importRefs)==null?void 0:zn.join(", "))??""),[He,Q]=a.useState((l==null?void 0:l.attributionBlock)??""),[he,dt]=a.useState((l==null?void 0:l.evidenceExpiresAt)??""),[J,Ue]=a.useState(""),[Ke,zt]=a.useState(""),[Ye,Dt]=a.useState(""),[Ae,ct]=a.useState(""),[Pe,ut]=a.useState(""),[Ve,pt]=a.useState(""),[ht,g]=a.useState(""),[$,G]=a.useState(""),[Ie,Je]=a.useState(""),[$t,vo]=a.useState(""),[rn,So]=a.useState(""),[dn,wo]=a.useState(""),[cn,ko]=a.useState("internal"),[un,Co]=a.useState(""),[di,Io]=a.useState(null),[pn,Rt]=a.useState(!1),[hn,xt]=a.useState(null),[gt,mt]=a.useState(l==null?void 0:l.validation),[Le,Yt]=a.useState(null),[Vt,Mo]=a.useState({}),[xn,zo]=a.useState(!!(l&&(l.roles||l.aggregation||(Dn=l.importRefs)!=null&&Dn.length||l.attributionBlock||l.evidenceExpiresAt)));a.useEffect(()=>{t.kind!=="relationship"||l||w||!H||!R||B(`${H}_to_${R}`.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,l,H,R,w]),a.useEffect(()=>{var L;if(t.kind!=="entity"||w||!N)return;const p=(L=n.dbtProvenance.nodes[N])==null?void 0:L.name;p&&B(p.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,w,N,n.dbtProvenance.nodes]),a.useEffect(()=>{if(t.kind!=="entity"||!N){Yt(null);return}let p=!1;return Z.getDbtModelingNode(N).then(L=>{var W,ee;p||(Yt(L),E||C(L.name.replace(/[_-]+/g," ").replace(/\b\w/g,X=>X.toUpperCase())),!A&&((W=L.dqlMeta)!=null&&W.grain)&&F(L.dqlMeta.grain),!U&&((ee=L.dqlMeta)!=null&&ee.keys.length)&&V(L.dqlMeta.keys.join(", ")))}).catch(()=>{p||Yt(null)}),()=>{p=!0}},[N,t.kind]),a.useEffect(()=>{if(t.kind!=="relationship")return;const L=[H,R].map(ee=>{var X;return(X=n.modeling.entities[ee])==null?void 0:X.dbtUniqueId}).filter(ee=>!!ee).filter(ee=>!Vt[ee]);if(!L.length)return;let W=!1;return Z.getDbtModelingNodes(L).then(({details:ee})=>{W||Mo(X=>({...X,...Object.fromEntries(ee.map(xe=>[xe.uniqueId,xe]))}))}).catch(()=>{}),()=>{W=!0}},[t.kind,H,R]);const Jt=()=>{if(t.kind==="domain")return{operation:"upsert_domain",value:{id:w,name:w,owner:b,parent:P||void 0,exports:[]}};if(t.kind==="area")return{operation:"upsert_area",value:{id:w,domain:c,name:K||w,description:ce||void 0,intentExamples:Y(ge),references:Y(we)}};if(t.kind==="entity")return{operation:"upsert_entity",value:{id:w,domain:c,dbtModel:N,areaId:I||void 0,businessName:E||void 0,businessContext:O||void 0,conceptRefs:Y(T),analyticalRole:be,status:k,owner:b||void 0,grain:A||void 0,keys:Y(U)}};if(t.kind==="contract")return{operation:"upsert_contract",value:{id:w,domain:c,entities:Y(J),blocks:Y(Ke),status:"draft",owner:b,requiredEvaluation:!0,purpose:Ye||void 0,metricRefs:Y(Ae),dimensions:Y(Pe),allowedFilters:Y(Ve),requiredFilters:Y(ht),evaluationRefs:Y($)}};if(t.kind==="export")return{operation:"upsert_export",value:{id:w,domain:c,entity:Ie||void 0,metrics:Y(Ae),blocks:Y(Ke),allowedKeys:Y($t),allowedDimensions:Y(Pe),allowedFilters:Y(Ve),purposes:Y(rn),consumerDomains:Y(dn),classification:cn||void 0,status:ue,owner:b||void 0}};if(t.kind==="import")return{operation:"upsert_import",value:{id:w||void 0,domain:c,exportRef:un,purpose:Ye,status:ue,owner:b||void 0}};const p=li(me),W=!l||l.from===H&&l.to===R&&JSON.stringify(l.keys)===JSON.stringify(p)&&l.cardinality===qe&&l.fanout===ve?gt:void 0,ee=ue==="certified"&&(W==null?void 0:W.status)!=="passed"?"reviewed":ue,X=n.modeling.entities[H],xe=n.modeling.entities[R];return{operation:"upsert_relationship",value:{id:w,domain:c,areaId:I||void 0,from:H,to:R,keys:p,cardinality:qe,fanout:ve,status:ee,owner:b||void 0,ownerDomain:c,verb:nt||void 0,description:$e||void 0,roles:Te||st?{from:Te||void 0,to:st||void 0}:void 0,optionality:{from:it,to:Se},joinTypes:Y(Ct),aggregation:lt||We?{measuresFrom:Y(lt),dimensionsFrom:Y(We),requiresPreAggregation:ve!=="safe"}:void 0,attributionBlock:He||void 0,importRefs:Y(Mt),evidenceExpiresAt:he||void 0,crossDomain:(X==null?void 0:X.domain)!==(xe==null?void 0:xe.domain),validation:W,certifiedAgainst:ee==="certified"&&(X!=null&&X.grain)&&(xe!=null&&xe.grain)?{from:{grain:X.grain,keys:X.keys},to:{grain:xe.grain,keys:xe.keys}}:void 0}}},Do=async()=>{try{Rt(!0),xt(null);const p=Jt();if(Io(p),Tn(p,u,m)){const W=await Z.previewModelingChange(p,n.snapshotId);await Z.applyModelingChange(p,W.fingerprint,n.snapshotId),await y(p);return}const L=await Z.createContextProposal({origin:"manual",expectedSnapshotId:n.snapshotId,operations:[{id:`manual:${p.operation}:${w||Date.now().toString(36)}`,kind:"modeling_change",change:p,evidence:["manual Modeling workspace authoring"]}]});d(L)}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},$o=async()=>{try{Rt(!0),xt(null);const p=Jt();if(p.operation!=="upsert_relationship")return;const L=await Z.validateModelingRelationship(p.value,n.snapshotId);mt(L),xt(L.status==="passed"?"Warehouse proof passed. Preview the source change to save it.":L.message??"Validation failed.")}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},gn=Object.entries(n.modeling.entities).map(([p,L])=>{const W=n.dbtProvenance.nodes[L.dbtUniqueId];return{value:p,label:L.businessName||L.localId||L.id,description:`${L.domain} · ${(W==null?void 0:W.relation)??(W==null?void 0:W.name)??L.dbtUniqueId}`,keywords:[L.qualifiedId,L.businessContext??"",L.analyticalRole??""]}}),Ne=Vt[(($n=n.modeling.entities[H])==null?void 0:$n.dbtUniqueId)??""],Oe=Vt[((Rn=n.modeling.entities[R])==null?void 0:Rn.dbtUniqueId)??""],mn=((Ne==null?void 0:Ne.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),fn=((Oe==null?void 0:Oe.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),Bt=mn.map(p=>p.value).filter(p=>fn.some(L=>L.value.toLowerCase()===p.toLowerCase())).slice(0,5),Me=me?me.split(",").map(p=>{const[L="",W=""]=p.split("=").map(ee=>ee.trim());return{from:L,to:W}}):[{from:"",to:""}],yn=(p,L,W)=>{const ee=Me.map((X,xe)=>xe===p?{...X,[L]:W}:X);Ee(ee.map(X=>`${X.from}=${X.to}`).join(", ")),mt(void 0)},Ro=p=>{const L=Me.filter((W,ee)=>ee!==p);Ee(L.map(W=>`${W.from}=${W.to}`).join(", ")),mt(void 0)},Bo=()=>Ee([...Me.filter(p=>p.from||p.to),{from:"",to:""}].map(p=>`${p.from}=${p.to}`).join(", ")),Qt=t.kind==="entity"?!!(c&&w&&N):t.kind==="relationship"?!!(c&&w&&H&&R&&Me.some(p=>p.from&&p.to)&&Me.every(p=>p.from&&p.to)):!0,Ao=(()=>{if(!Qt)return!1;try{return Tn(Jt(),u,m)}catch{return!1}})(),Po=t.kind==="domain"?"Create Domain Package":t.kind==="area"?m?"Edit subject area":"Create subject area":t.kind==="entity"?u?"Edit business entity":"Add dbt model":t.kind==="contract"?"Create analytical contract":t.kind==="export"?"Publish domain export":t.kind==="import"?"Request domain import":l?"Edit relationship":"Create relationship";return e.jsx(yo,{title:Po,t:i,onClose:r,children:e.jsxs("div",{style:{display:"grid",gap:12},children:[t.kind!=="domain"&&e.jsx(z,{label:"Domain",children:e.jsx(ae,{value:c,onChange:x,values:Object.keys(n.modeling.packages),t:i})}),t.kind!=="relationship"&&e.jsx(z,{label:t.kind==="entity"?"Entity id":t.kind==="area"?"Area id":t.kind==="contract"?"Contract id":t.kind==="export"?"Export id":t.kind==="import"?"Import id (optional)":"Domain id",children:e.jsx(_,{value:w,onChange:B,t:i,placeholder:"stable_snake_case_id"})}),t.kind==="domain"&&e.jsx(z,{label:"Parent domain (optional)",children:e.jsx(ae,{value:P,onChange:q,values:Object.keys(n.modeling.packages),t:i})}),t.kind==="area"&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{text:"A subject area is one small, reviewable source file — a focused diagram inside this Domain. It filters the same domain graph; it never creates a competing semantic model and never changes what an agent is allowed to use.",t:i}),e.jsx(z,{label:"Area name",children:e.jsx(_,{value:K,onChange:ie,t:i,placeholder:"Customer lifecycle"})}),e.jsx(z,{label:"Business question or scope",children:e.jsx(_,{value:ce,onChange:De,t:i,placeholder:"How customers progress from first order to repeat purchase."})}),e.jsx(z,{label:"Example questions (comma-separated)",children:e.jsx(_,{value:ge,onChange:_e,t:i,placeholder:"Which customers made a second purchase?"})}),e.jsx(z,{label:"Read-only boundary entities (comma-separated)",children:e.jsx(_,{value:we,onChange:je,t:i,placeholder:"customer"})})]}),t.kind==="entity"&&e.jsxs(e.Fragment,{children:[e.jsx(Zn,{current:N?2:1,labels:["Find dbt model","Add business meaning","Review source change"],t:i}),e.jsx(fe,{text:"Search by model name, relation, or source path. Results stay bounded even when the dbt project has thousands of models.",t:i}),e.jsx(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsx(z,{label:"dbt model",children:e.jsx(oi,{value:N,onChange:j,selectedNode:n.dbtProvenance.nodes[N],domain:c,t:i})}),Le&&e.jsx(eo,{title:Le.name,detail:`${Le.relation??Le.uniqueId} · ${Le.columns.length} columns${(Bn=Le.dqlMeta)!=null&&Bn.grain?` · grain: ${Le.dqlMeta.grain}`:""}`,t:i}),e.jsx(z,{label:"Business name",children:e.jsx(_,{value:E,onChange:C,t:i,placeholder:"Customer order"})}),e.jsx(z,{label:"Business context",children:e.jsx(_,{value:O,onChange:M,t:i,placeholder:"One order used to understand repeat purchasing and revenue."})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business concepts",children:e.jsx(_,{value:T,onChange:re,t:i,placeholder:"customer_lifecycle, revenue"})}),e.jsx(z,{label:"Analytical role",children:e.jsx(ae,{value:be,onChange:p=>de(p),values:["event","dimension","snapshot","bridge","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Grain override (optional)",children:e.jsx(_,{value:A,onChange:F,t:i,placeholder:"Use dbt meta.dql by default"})}),e.jsx(z,{label:"Key overrides (optional)",children:e.jsx(_,{value:U,onChange:V,t:i,placeholder:"customer_id, order_id"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:k==="review"?"reviewed":k,onChange:p=>D(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),t.kind==="relationship"&&e.jsxs(e.Fragment,{children:[e.jsx(Zn,{current:!H||!R?1:Me.some(p=>p.from&&p.to)?3:2,labels:["Choose models","Match join keys","Review policy"],t:i}),e.jsx(fe,{text:"Search business names or dbt relations, then match columns from only those two models. DQL keeps the relationship in draft until warehouse validation passes.",t:i}),e.jsx(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From entity",children:e.jsx(Nt,{ariaLabel:"From entity",value:H,onChange:p=>{Ce(p),mt(void 0)},options:gn,placeholder:"Search source model…",t:i})}),e.jsx(z,{label:"To entity",children:e.jsx(Nt,{ariaLabel:"To entity",value:R,onChange:p=>{oe(p),mt(void 0)},options:gn.filter(p=>p.value!==H),placeholder:"Search target model…",t:i})})]}),H&&R&&e.jsx(eo,{title:`${((An=n.modeling.entities[H])==null?void 0:An.businessName)||((Pn=n.modeling.entities[H])==null?void 0:Pn.localId)} → ${((Ln=n.modeling.entities[R])==null?void 0:Ln.businessName)||((Nn=n.modeling.entities[R])==null?void 0:Nn.localId)}`,detail:`${(Ne==null?void 0:Ne.columns.length)??0} source columns · ${(Oe==null?void 0:Oe.columns.length)??0} target columns`,t:i}),e.jsx(z,{label:"Join keys",children:e.jsxs("div",{style:{display:"grid",gap:8},children:[Bt.length>0&&!Me.some(p=>p.from&&p.to)&&e.jsxs("button",{type:"button",onClick:()=>Ee(`${Bt[0]}=${Bt[0]}`),style:{...Xe(i),justifySelf:"start"},children:[e.jsx(Ht,{size:13})," Use exact match: ",Bt[0]]}),Me.map((p,L)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) 24px minmax(0, 1fr) 30px",gap:7,alignItems:"center"},children:[e.jsx(Nt,{ariaLabel:`Source join column ${L+1}`,value:p.from,onChange:W=>yn(L,"from",W),options:mn,placeholder:H?"Source column…":"Choose source first",disabled:!H||!Ne,t:i}),e.jsx("span",{"aria-hidden":"true",style:{color:i.textMuted,textAlign:"center"},children:"→"}),e.jsx(Nt,{ariaLabel:`Target join column ${L+1}`,value:p.to,onChange:W=>yn(L,"to",W),options:fn,placeholder:R?"Target column…":"Choose target first",disabled:!R||!Oe,t:i}),e.jsx("button",{type:"button","aria-label":"Remove join key",title:"Remove join key",onClick:()=>Ro(L),style:ze(i),children:e.jsx(tt,{size:14})})]},`${L}:${p.from}:${p.to}`)),e.jsxs("button",{type:"button",onClick:Bo,style:{...Xe(i),justifySelf:"start"},children:[e.jsx(et,{size:13})," Add key pair"]})]})}),w&&e.jsxs("div",{style:{color:i.textMuted,fontSize:9.5},children:["Relationship id: ",e.jsx("code",{children:w})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Cardinality",children:e.jsx(ae,{value:qe,onChange:p=>wt(p),values:["unknown","one_to_one","one_to_many","many_to_one","many_to_many"],t:i})}),e.jsx(z,{label:"Fanout policy",children:e.jsx(ae,{value:ve==="unsafe"?"forbidden":ve,onChange:p=>te(p),values:["safe","dedupe_required","attribution_required","forbidden","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business verb (optional)",children:e.jsx(_,{value:nt,onChange:ke,t:i,placeholder:"belongs to"})}),e.jsx(z,{label:"Description (optional)",children:e.jsx(_,{value:$e,onChange:ot,t:i,placeholder:"Why this relationship exists"})})]}),H&&R&&((On=n.modeling.entities[H])==null?void 0:On.domain)!==((_n=n.modeling.entities[R])==null?void 0:_n.domain)&&e.jsx(fe,{text:"This is a cross-domain relationship. Add the approved provider import in Advanced governance before certification.",t:i}),e.jsx("button",{type:"button",onClick:()=>zo(p=>!p),style:{...Xe(i),justifySelf:"start",padding:"6px 0"},children:xn?"Hide advanced governance":"Advanced governance and aggregation"}),xn&&e.jsxs("div",{style:{display:"grid",gap:12,padding:12,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg},children:[e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed join types",children:e.jsx(_,{value:Ct,onChange:It,t:i,placeholder:"left, inner"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From role",children:e.jsx(_,{value:Te,onChange:Kt,t:i})}),e.jsx(z,{label:"To role",children:e.jsx(_,{value:st,onChange:kt,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From optionality",children:e.jsx(ae,{value:it,onChange:p=>at(p),values:["required","optional","unknown"],t:i})}),e.jsx(z,{label:"To optionality",children:e.jsx(ae,{value:Se,onChange:p=>Fe(p),values:["required","optional","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Measures allowed from",children:e.jsx(_,{value:lt,onChange:Re,t:i,placeholder:"order"})}),e.jsx(z,{label:"Dimensions allowed from",children:e.jsx(_,{value:We,onChange:rt,t:i,placeholder:"customer"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Required import refs",children:e.jsx(_,{value:Mt,onChange:Be,t:i,placeholder:"commerce.customer@1"})}),e.jsx(z,{label:"Attribution block",children:e.jsx(_,{value:He,onChange:Q,t:i,placeholder:"growth.revenue_by_channel"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Evidence expires",children:e.jsx(_,{value:he,onChange:dt,t:i,placeholder:"2026-12-31"})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),gt&&e.jsx(fo,{evidence:gt,t:i,onFixWithAi:gt.status==="failed"?()=>h(l?nn(n.modeling.relationships,l):null,gt):void 0})]}),t.kind==="contract"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Covered entities",children:e.jsx(_,{value:J,onChange:Ue,t:i,placeholder:"order, customer"})}),e.jsx(z,{label:"Certified blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i,placeholder:"orders_360"})}),e.jsx(z,{label:"Decision purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue reporting"})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsx(z,{label:"Required filters",children:e.jsx(_,{value:ht,onChange:g,t:i})})]}),e.jsx(z,{label:"Evaluation refs",children:e.jsx(_,{value:$,onChange:G,t:i,placeholder:"revenue_accuracy"})})]}),t.kind==="export"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Exported entity",children:e.jsx(ae,{value:Ie,onChange:Je,values:Object.keys(n.modeling.entities).filter(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.domain)===c}),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed keys",children:e.jsx(_,{value:$t,onChange:vo,t:i})}),e.jsx(z,{label:"Allowed dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i})})]}),e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Approved purposes",children:e.jsx(_,{value:rn,onChange:So,t:i,placeholder:"revenue reporting"})}),e.jsx(z,{label:"Consumer domains",children:e.jsx(_,{value:dn,onChange:wo,t:i,placeholder:"growth"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Classification",children:e.jsx(_,{value:cn,onChange:ko,t:i})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]})]}),t.kind==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Provider export",children:e.jsx(ae,{value:un,onChange:Co,values:Object.values(((En=n.modeling.interfaces)==null?void 0:En.exports)??{}).map(p=>`${p.domain}.${p.localId}@${p.version}`),t:i})}),e.jsx(z,{label:"Exact analytical purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue by acquisition channel"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),t.kind!=="entity"&&t.kind!=="relationship"&&t.kind!=="area"&&e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})}),hn&&e.jsx(fe,{text:hn,t:i}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[t.kind==="relationship"&&e.jsxs(se,{t:i,onClick:()=>void $o(),disabled:pn||!Qt,children:[e.jsx(Qo,{size:14})," Validate in warehouse"]}),e.jsx(se,{primary:!0,t:i,onClick:()=>void Do(),disabled:pn||!Qt,children:Ao?"Save":"Preview source change"})]})]})})}function Ks({search:t,onSearch:n,items:s,onPick:o,t:i}){var f;const[r,d]=a.useState(!1),h=a.useRef(null),y=t.trim().toLowerCase(),l=y?s.filter(c=>c.label.toLowerCase().includes(y)||c.sublabel.toLowerCase().includes(y)).sort((c,x)=>c.type===x.type?c.label.localeCompare(x.label):c.type==="model"?-1:1).slice(0,14):[],u=c=>c==="dimension"?"var(--status-success)":c==="bridge"?"var(--status-warning)":c==="event"||c==="snapshot"?"var(--accent)":"var(--text-tertiary)",m=r&&y?(f=h.current)==null?void 0:f.getBoundingClientRect():void 0;return e.jsxs("label",{ref:h,style:{position:"relative",width:210,flex:"0 0 210px"},children:[e.jsx(Ft,{size:12,style:{position:"absolute",left:7,top:8,color:i.textMuted}}),e.jsx("input",{"aria-label":"Search diagram",value:t,onChange:c=>{n(c.target.value),d(!0)},onFocus:()=>d(!0),placeholder:"Find model or column",style:{...ye(i),padding:"6px 7px 6px 24px"}}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>d(!1),style:{position:"fixed",inset:0,zIndex:60}}),e.jsx("div",{style:{position:"fixed",top:m.bottom+5,left:m.left,zIndex:61,width:300,maxHeight:340,overflow:"auto",background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:9,boxShadow:"0 12px 30px rgba(26,26,26,0.16)",padding:4},children:l.length===0?e.jsx("div",{style:{padding:"10px 10px",fontSize:11.5,color:i.textMuted,fontFamily:i.font},children:"No matching model or column."}):l.map((c,x)=>e.jsxs("button",{type:"button",onMouseDown:I=>{I.preventDefault(),o(c.recordKey),d(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"7px 8px",border:"none",borderRadius:6,background:"transparent",cursor:"pointer",fontFamily:i.font},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:999,background:u(c.role),flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:c.type==="model"?650:500,color:i.textPrimary,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.label}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:i.textMuted},children:c.type==="model"?"model":c.sublabel})]},`${c.type}-${c.recordKey}-${c.label}-${x}`))})]})]})}function Ys({modelingView:t,columnMode:n,search:s,layoutMode:o,density:i,visibleLimit:r,dimUnrelated:d,showEdgeLabels:h,showLegend:y,fullscreen:l,aiOpen:u,onBindModel:m,onRelationship:f,onToggleAi:c,onModelingView:x,onColumnMode:I,onSearch:v,searchItems:w,onPickModel:B,onLayoutMode:b,onDensity:S,onVisibleLimit:P,onDimUnrelated:q,onEdgeLabels:N,onLegend:j,onFullscreen:E,onExport:C,onReset:O,t:M}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:50,padding:"0 10px",borderBottom:`1px solid ${M.headerBorder}`,background:M.headerBg,flexWrap:"nowrap",overflowX:"auto",scrollbarWidth:"thin"},children:[e.jsxs("div",{role:"group","aria-label":"Modeling view",style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${M.headerBorder}`,borderRadius:7,background:M.appBg,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>x("business"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="business"?"var(--accent-dim)":"transparent",color:t==="business"?M.accent:M.textMuted},children:"Business modeling"}),e.jsx("button",{type:"button",onClick:()=>x("data"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="data"?"var(--accent-dim)":"transparent",color:t==="data"?M.accent:M.textMuted},children:"Data modeling"})]}),e.jsx(Ks,{search:s,onSearch:v,items:w,onPick:B,t:M}),e.jsxs("button",{type:"button",onClick:m,style:Ge(M,!0),children:[e.jsx(et,{size:13})," Add models"]}),e.jsxs("button",{type:"button",onClick:f,style:Ge(M),children:[e.jsx(Ot,{size:13})," Connect"]}),e.jsxs("button",{type:"button","aria-pressed":u,onClick:c,style:{...Ge(M),...u?{borderColor:M.accent,color:M.accent,background:"var(--accent-dim)"}:{}},children:[e.jsx(Ht,{size:13})," Build with AI"]}),e.jsxs("details",{style:{position:"relative",flexShrink:0},children:[e.jsxs("summary",{style:{...Ge(M),listStyle:"none"},children:[e.jsx(xs,{size:13})," View"]}),e.jsxs("div",{role:"group","aria-label":"Modeling view options",style:{position:"fixed",zIndex:70,width:250,marginTop:6,right:12,padding:10,display:"grid",gap:9,border:`1px solid ${M.headerBorder}`,borderRadius:9,background:M.cellBg,boxShadow:"0 14px 34px rgba(0,0,0,.18)"},children:[t==="data"&&e.jsxs("label",{style:Lt(M),children:[e.jsxs("span",{children:[e.jsx(fs,{size:13})," Columns"]}),e.jsxs("select",{"aria-label":"Visible columns",value:n,onChange:T=>I(T.target.value),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"keys",children:"Keys only"}),e.jsx("option",{value:"relevant",children:"Relevant"}),e.jsx("option",{value:"all",children:"All columns"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Layout"}),e.jsxs("select",{"aria-label":"Diagram layout",value:o,onChange:T=>{b(T.target.value),O()},style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"grid",children:"Grid"}),e.jsx("option",{value:"star",children:"Star"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Density"}),e.jsxs("select",{"aria-label":"Diagram density",value:i,onChange:T=>S(T.target.value),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"compact",children:"Compact"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"wide",children:"Wide"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Canvas"}),e.jsxs("select",{"aria-label":"Visible model limit",value:r||50,onChange:T=>P(Number(T.target.value)),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:25,children:"25 models"}),e.jsx("option",{value:50,children:"50 models"}),e.jsx("option",{value:100,children:"100 models"}),e.jsx("option",{value:200,children:"200 max"})]})]}),e.jsxs("button",{type:"button",onClick:()=>q(!d),style:Qe(M,d),children:[e.jsx(Yo,{size:14})," Dim unrelated models"]}),e.jsxs("button",{type:"button",onClick:()=>N(!h),style:Qe(M,h),children:[e.jsx(Ot,{size:14})," Relationship labels"]}),e.jsxs("button",{type:"button",onClick:()=>j(!y),style:Qe(M,y),children:[e.jsx(Ze,{size:14})," Relationship legend"]}),e.jsxs("button",{type:"button",onClick:C,style:Qe(M),children:[e.jsx(Vo,{size:14})," Export SVG"]}),e.jsxs("button",{type:"button",onClick:E,style:Qe(M,l),children:[l?e.jsx(tt,{size:14}):e.jsx(co,{size:14})," ",l?"Exit fullscreen":"Fullscreen"]}),e.jsxs("button",{type:"button",onClick:O,style:Qe(M),children:[e.jsx(gs,{size:14})," Reset layout"]})]})]})]})}const Lt=t=>({display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:t.textSecondary,fontSize:10.5}),Qe=(t,n=!1)=>({border:"none",borderRadius:6,padding:"6px 7px",display:"flex",alignItems:"center",gap:7,background:n?"var(--accent-dim)":"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,textAlign:"left",cursor:"pointer"});function Vs({t}){return e.jsxs("div",{style:{display:"flex",gap:14,padding:"7px 12px",borderBottom:`1px solid ${t.headerBorder}`,background:t.headerBg,color:t.textSecondary,fontSize:9.5},children:[[["Safe certified","#2e9b63"],["Validated review","#5b73d6"],["Attribution / draft","#9a6b2f"],["Stale certification","#d47822"]].map(([n,s])=>e.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center"},children:[e.jsx("i",{style:{display:"inline-block",width:18,height:3,background:s,borderRadius:2}}),n]},n)),e.jsx("span",{style:{marginLeft:"auto"},children:"1:1 · 1:N · N:1 · N:N"})]})}function Js({t,connectedModels:n,onDbt:s,onYaml:o,onManual:i}){const r=[{icon:e.jsx(Ze,{size:20}),title:"Use connected dbt",detail:`${n} model${n===1?"":"s"} available. Search, multi-select, confirm where they belong, then review the bindings.`,action:s},{icon:e.jsx(an,{size:20}),title:"Import modeling YAML",detail:"Discover DQL modeling or dbt YAML from this project, a safe local path, an upload, or pasted content. Relationships declared in dbt tests come across as draft edges.",action:o},{icon:e.jsx(et,{size:20}),title:"Start manually",detail:"Create one model binding or relationship with guided review.",action:i}];return e.jsx("div",{style:{height:"100%",display:"grid",placeItems:"center",padding:28},children:e.jsxs("div",{style:{width:"min(840px, 100%)"},children:[e.jsxs("div",{style:{textAlign:"center",marginBottom:18},children:[e.jsx("h2",{style:{margin:0,fontSize:18},children:"Start modeling domain context"}),e.jsx("p",{style:{margin:"7px 0 0",color:t.textMuted,fontSize:11.5},children:"Choose the source you already have. Every path creates the same write-free proposal before a draft can be saved."})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:r.map(d=>e.jsxs("button",{type:"button",onClick:d.action,style:{...Tt(t),minHeight:150,textAlign:"left",cursor:"pointer"},children:[e.jsx("span",{style:{width:38,height:38,borderRadius:9,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--accent-dim)",color:t.accent},children:d.icon}),e.jsx("b",{style:{display:"block",marginTop:12},children:d.title}),e.jsx("span",{style:{display:"block",marginTop:6,color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:d.detail})]},d.title))})]})})}function Qs(){const t=document.querySelector("#dql-modeling-diagram .react-flow__renderer");if(!(t instanceof HTMLElement))return;const n=t.cloneNode(!0),s=t.getBoundingClientRect(),o=new XMLSerializer().serializeToString(n),i=`<svg xmlns="http://www.w3.org/2000/svg" width="${Math.ceil(s.width)}" height="${Math.ceil(s.height)}"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">${o}</div></foreignObject></svg>`,r=URL.createObjectURL(new Blob([i],{type:"image/svg+xml"})),d=document.createElement("a");d.href=r,d.download="dql-domain-model.svg",d.click(),URL.revokeObjectURL(r)}function Gs({data:t,domain:n,t:s}){var m,f;const{state:o,dispatch:i}=Wt(),[r,d]=a.useState(null),[h,y]=a.useState(null),l=[...new Set(n?((f=(m=t.domainAssets)==null?void 0:m[n])==null?void 0:f.blocks)??[]:Object.values(t.domainAssets??{}).flatMap(c=>c.blocks??[]))].sort(),u=async c=>{d(c),y(null);try{if(n)try{window.localStorage.setItem("dql.block-studio.domain",n)}catch{}const x=o.files.find(v=>v.path===c)??{name:c.split("/").at(-1)??c,path:c,type:"block",folder:c.split("/").slice(0,-1).join("/")};o.files.some(v=>v.path===c)||i({type:"FILE_ADDED",file:x});const I=await Z.openBlockStudio(c);i({type:"OPEN_BLOCK_STUDIO",file:x,payload:I})}catch(x){y(x instanceof Error?x.message:String(x))}finally{d(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{title:"Blocks",detail:n?`Reusable blocks owned by ${n}. Select one to open the exact source in Block Studio.`:"All reusable blocks grouped across the current Domain Packages. Select one to open the exact source in Block Studio.",t:s}),h?e.jsx(fe,{text:h,t:s}):null,l.length?e.jsx("div",{style:{display:"grid",gap:10},children:l.map(c=>{var v;const x=(c.split("/").at(-1)??c).replace(/\.dql$/i,""),I=(v=Object.entries(t.domainAssets??{}).find(([,w])=>{var B;return(B=w.blocks)==null?void 0:B.includes(c)}))==null?void 0:v[0];return e.jsxs("button",{type:"button",onClick:()=>void u(c),"aria-label":`Open block ${x}`,style:{...Tt(s),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(ro,{size:14,color:s.accent}),e.jsx("b",{children:x}),n?null:e.jsx(qt,{t:s,children:I??"shared"}),r===c?e.jsx(qt,{t:s,children:"Opening…"}):null]}),e.jsx("code",{style:{display:"block",marginTop:7,color:s.textMuted,fontSize:10},children:c})]},c)})}):e.jsx(on,{title:"No domain blocks yet",detail:"Create a block in Block Studio and assign this domain to make it appear here.",t:s})]})}function Jn({data:t,domain:n,kind:s,t:o}){var w,B;const{state:i,dispatch:r}=Wt(),[d,h]=a.useState([]),[y,l]=a.useState(!0),[u,m]=a.useState(null),[f,c]=a.useState(null);a.useEffect(()=>{let b=!0;return l(!0),(n?Z.getRelatedDomainProducts(n):Z.getAllRelatedDomainProducts()).then(S=>{b&&h(S[s])}).catch(()=>{b&&h([])}).finally(()=>{b&&l(!1)}),()=>{b=!1}},[n,s]);const x=n?((B=(w=t.domainAssets)==null?void 0:w[n])==null?void 0:B[s])??[]:Object.values(t.domainAssets??{}).flatMap(b=>b[s]??[]),I=s==="notebooks"?"Notebooks":"Apps",v=async b=>{const S=String(b.id??b.filePath??b.title??b.name??"product");m(S),c(null);try{if(s==="apps"){const E=String(b.id??Qn(String(b.filePath??"")));if(!E)throw new Error("This App has no stable id to open.");r({type:"OPEN_APP",appId:E,experience:"view",section:"dashboards"});return}const P=String(b.filePath??"");if(!P)throw new Error("This Notebook has no source path to open.");const q=i.files.find(E=>E.path===P)??{name:P.split("/").at(-1)??String(b.title??S),path:P,type:"notebook",folder:P.split("/").slice(0,-1).join("/"),...typeof b.ownerDomain=="string"?{ownerDomain:b.ownerDomain}:{},usesDomains:Array.isArray(b.usesDomains)?b.usesDomains.map(String):[]};i.files.some(E=>E.path===P)||r({type:"FILE_ADDED",file:q});const{content:N}=await Z.readNotebook(P),j=Go(P,N);r({type:"OPEN_FILE",file:q,cells:j.cells,title:j.title,metadata:j.metadata})}catch(P){c(P instanceof Error?P.message:String(P))}finally{m(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{title:n?`Related ${I}`:`All ${I}`,detail:n?`${I} are global shared products related to ${n}. This backlink does not create a second copy inside the Domain Package.`:`All global ${I.toLowerCase()} across Domain Packages. Select a domain above to narrow by owner/uses-domain metadata.`,t:o}),f?e.jsx(fe,{text:f,t:o}):null,y?e.jsx(on,{title:`Loading related ${I.toLowerCase()}…`,detail:"Resolving global product backlinks from the compiled project snapshot.",t:o}):d.length?e.jsx("div",{style:{display:"grid",gap:10},children:d.map(b=>{const S=String(b.id??b.filePath??b.title??"product"),P=Array.isArray(b.usesDomains)?b.usesDomains.map(String):[],q=String(b.name??b.title??S);return e.jsxs("button",{type:"button",onClick:()=>void v(b),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${q}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("b",{children:q}),b.lifecycle?e.jsx(qt,{t:o,children:String(b.lifecycle)}):null,u===S?e.jsx(qt,{t:o,children:"Opening…"}):null]}),e.jsx("p",{style:{color:o.textSecondary,fontSize:11,margin:"7px 0 0"},children:String(b.purpose??"No analytical purpose declared yet.")}),e.jsx("code",{style:{display:"block",marginTop:7,color:o.textMuted,fontSize:10},children:String(b.filePath??"")}),e.jsxs("div",{style:{marginTop:7,color:o.textMuted,fontSize:10},children:["Owner: ",String(b.ownerDomain??"Shared")," · Uses: ",P.join(", ")||"none declared"]})]},S)})}):x.length?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsx(fe,{text:"These paths use the legacy domain-local layout. They remain readable during migration, but new products should be global and declare ownerDomain / usesDomains.",t:o}),x.map(b=>e.jsxs("button",{type:"button",onClick:()=>void v({id:s==="apps"?Qn(b):b,filePath:b}),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${b}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("code",{style:{color:o.textPrimary,fontSize:11},children:b})]}),e.jsx("p",{style:{color:o.textMuted,fontSize:10,margin:"7px 0 0"},children:"Legacy backlink · migrate without duplicating the product."})]},b))]}):e.jsx(on,{title:`No related ${I.toLowerCase()} yet`,detail:`Create the ${s==="notebooks"?"notebook":"app"} from the global ${I} surface, then declare this domain in its product context to make the backlink appear here.`,t:o})]})}function Qn(t){const n=t.replace(/\\/g,"/").split("/").filter(Boolean),s=n.indexOf("apps");return s>=0?n[s+1]??"":""}function Xs({domain:t,areaId:n,selectedId:s,data:o,themeMode:i,t:r,correction:d,onClose:h,onCorrectionStarted:y,onReviewProposal:l,onPreviewProposal:u,onOpenSkills:m,onDraftRelationship:f}){const{threadId:c,onThreadIdChange:x}=rs(Jo(t)),I=s?o.modeling.relationships[s]:void 0,v=s?o.modeling.entities[s]:void 0,w=n?o.modeling.areas[n]:void 0,B=I?{kind:"relationship",id:I.qualifiedId,title:I.id}:v?{kind:"model",id:v.qualifiedId,title:v.businessName||v.id}:w?{kind:"model_area",id:w.qualifiedId,title:w.name}:t?{kind:"domain",id:t,title:t}:{kind:"workspace",title:"New modeling draft"},[b,S]=a.useState(null),P=N=>{const j=N.payload;(j==null?void 0:j.version)===1&&j.trustState==="review_required"&&(S(j),u(j))},q=()=>{S(null),u(null)};return a.useEffect(()=>()=>u(null),[]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderBottom:`1px solid ${r.headerBorder}`},children:[e.jsx(Ht,{size:14,color:r.accent}),e.jsx("strong",{style:{fontSize:12},children:"Build with AI"}),e.jsx("span",{style:{marginLeft:"auto"}}),e.jsx("button",{type:"button",onClick:m,style:Xe(r),children:"Skills"}),e.jsx("button",{type:"button",onClick:f,style:Xe(r),children:"Connect manually"}),e.jsx("button",{type:"button","aria-label":"Close Modeling AI",onClick:h,style:{...ze(r),width:26,height:26},children:e.jsx(tt,{size:14})})]}),e.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${r.headerBorder}`,color:r.textMuted,fontSize:10.5,lineHeight:1.5},children:[t??"new domain",n?` · ${n}`:"",s?` · focused: ${s}`:""," · ",Object.keys(o.modeling.entities).length," models · ",Object.keys(o.modeling.relationships).length," relationships. Proposals are drafts: nothing is written, certified, or joinable until you save and validate it."]}),b?e.jsxs("div",{role:"status",style:{margin:"10px 12px 0",padding:"10px 11px",border:"1px solid var(--accent)",borderRadius:9,background:"var(--accent-dim)",fontSize:11,lineHeight:1.5},children:[e.jsx("strong",{style:{display:"block",fontSize:11.5},children:"Previewing on the canvas"}),e.jsxs("span",{style:{color:r.textSecondary},children:[b.impact.modelingChanges," modeling change",b.impact.modelingChanges===1?"":"s"," shown as dashed outlines. Nothing is saved yet."]}),e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9},children:[e.jsx("button",{type:"button",onClick:()=>{l(b)},style:{...Ge(r,!0),minHeight:27},children:"Review exact changes"}),e.jsx("button",{type:"button",onClick:q,style:{...Ge(r),minHeight:27},children:"Discard"})]})]}):null,e.jsx("div",{style:{flex:1,minHeight:0,margin:"10px 12px 12px",border:`1px solid ${r.headerBorder}`,borderRadius:10,overflow:"hidden"},children:e.jsx(ds,{themeMode:i,title:"Modeling AI",scopeHint:"Modeling proposal · metadata only · explicit draft save",composerPlaceholder:"Describe the model you want…",initialMode:"modeling",selectedObject:B,workspaceContext:{surface:"modeling",domain:t,modelAreaId:n,snapshotId:o.snapshotId,focusedObjectId:s,providerSafety:"no_query_rows",...d?{correction:!0,validationReceipt:d.evidence}:{}},threadId:c,onThreadIdChange:x,autoRun:d?{text:d.text,mode:"modeling",nonce:d.nonce}:void 0,onRunningChange:N=>{N&&d&&y()},onReviewAuthoringProposal:N=>P(N),emptyHint:"Describe the models and relationships you want. Every model and column is checked against the current dbt snapshot before anything is proposed.",examplePrompts:[{label:"Model this area",prompt:"Bind the relevant unbound dbt models for this area, write business context for each, and connect them with draft relationships."},{label:"Describe this model",prompt:"Write the business context and grain for the focused model using only dbt metadata evidence."},{label:"Connect these models",prompt:"Propose draft relationships between the models in this area and explain the evidence for each key pair."}]})})]})}function Zs({entity:t,detail:n,relationships:s=[],t:o,onEdit:i,onEditDbtSource:r,onSelectRelationship:d,onDelete:h}){var f,c,x,I;const y=oo(t.analyticalRole),l=new Set(t.keys.length?t.keys:((f=n==null?void 0:n.dqlMeta)==null?void 0:f.keys)??[]),u={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"0 0 5px"},m=s.filter(v=>v.from===t.id||v.to===t.id||v.from===t.localId||v.to===t.localId);return e.jsxs(ln,{t:o,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,marginBottom:12},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:y,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:13.5,fontWeight:700,color:o.textPrimary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.businessName||t.localId}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:y},children:t.analyticalRole??"entity"})]}),e.jsx("p",{style:{margin:"0 0 12px",color:o.textSecondary,fontSize:12,lineHeight:1.6},children:t.businessContext||`Add the DQL-owned business context for ${t.localId}. dbt descriptions remain physical-source documentation.`}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:u,children:"dbt binding"}),e.jsx("div",{style:{fontSize:11,fontFamily:o.fontMono,color:o.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:(n==null?void 0:n.relation)??t.dbtUniqueId})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs("div",{style:u,children:["Columns · ",(n==null?void 0:n.columns.length)??"…"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n==null?void 0:n.columns.slice(0,16).map(v=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"4px 2px",borderBottom:"1px solid var(--border-subtle)",fontSize:11.5},children:[e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:o.fontMono,color:l.has(v.name)?"var(--pk)":/(^|_)id$/.test(v.name)?"var(--fk)":"transparent"},children:l.has(v.name)?"PK":/(^|_)id$/.test(v.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:o.textSecondary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:o.textMuted,fontFamily:o.fontMono},children:v.type??"—"})]},v.name))})]}),m.length>0&&d?e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:u,children:"Relationships"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map(v=>e.jsxs("button",{type:"button",onClick:()=>d(v),style:{display:"flex",alignItems:"center",gap:7,padding:"6px 8px",borderRadius:7,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",cursor:"pointer",textAlign:"left",fontFamily:o.font,fontSize:11,color:o.textSecondary},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:v.cardinality==="one_to_one"?"1:1":v.cardinality==="one_to_many"?"1:N":v.cardinality==="many_to_one"?"N:1":"N:N"})]},v.qualifiedId??v.localId))})]}):null,e.jsxs("details",{style:{marginBottom:12},children:[e.jsx("summary",{style:{...u,cursor:"pointer"},children:"More metadata"}),e.jsx(le,{label:"concepts",value:((c=t.conceptRefs)==null?void 0:c.join(", "))||"Not mapped",t:o}),e.jsx(le,{label:"owner",value:t.owner??"Not declared",t:o}),e.jsx(le,{label:"grain",value:t.grain??((x=n==null?void 0:n.dqlMeta)==null?void 0:x.grain)??"Not declared",t:o}),e.jsx(le,{label:"keys",value:(t.keys.length?t.keys:((I=n==null?void 0:n.dqlMeta)==null?void 0:I.keys)??[]).join(", ")||"Not declared",t:o}),e.jsx(le,{label:"source",value:(n==null?void 0:n.sourcePath)??t.sourcePath,t:o}),e.jsx(le,{label:"dbt description",value:(n==null?void 0:n.description)??"Not declared",t:o})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(se,{primary:!0,t:o,onClick:i,children:"Edit entity"}),e.jsx(se,{t:o,onClick:r,children:"Preview dbt source patch"}),h?e.jsx(se,{t:o,danger:!0,onClick:h,children:"Delete entity"}):null]})]})}function ei({entity:t,detail:n,snapshotId:s,t:o,onClose:i,onApplied:r}){const d=n.columns.filter(S=>S.tests.length>0).map(S=>`${S.name}: ${S.tests.join(", ")}`).join(`
|
|
22
|
-
`),[h,y]=a.useState(n.description??""),[l,u]=a.useState(d),[m,f]=a.useState(null),[c,x]=a.useState(!1),[I,v]=a.useState(null),w=()=>({uniqueId:t.dbtUniqueId,description:h,columns:l.split(/\r?\n/).flatMap(S=>{const P=S.indexOf(":");if(P<1)return[];const q=S.slice(0,P).trim(),N=Y(S.slice(P+1));return q?[{name:q,tests:N}]:[]})}),B=async()=>{try{x(!0),v(null),f(await Z.previewDbtSourcePatch(w(),s))}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}},b=async()=>{if(m)try{x(!0),v(null),await Z.applyDbtSourcePatch(w(),m.fingerprint,m.snapshotId),await r()}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}};return e.jsxs(yo,{title:`Edit dbt source · ${n.name}`,t:o,onClose:i,children:[e.jsx(fe,{text:"dbt owns descriptions and tests. DQL will preview a guarded patch to the dbt YAML source; no dbt metadata is copied into the Domain Package.",t:o}),m?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{color:o.textSecondary,fontSize:11},children:["Source: ",e.jsx("code",{children:m.patch.path})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(Gn,{title:"Current dbt YAML",source:m.patch.before||"# New dbt schema YAML",t:o}),e.jsx(Gn,{title:"Proposed dbt YAML",source:m.patch.after,t:o})]}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:()=>f(null),children:"Back"}),e.jsx(se,{primary:!0,t:o,disabled:c||!m.patch.changed,onClick:()=>void b(),children:m.patch.changed?"Apply dbt source patch":"No changes"})]})]}):e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(z,{label:"Model description",children:e.jsx("textarea",{"aria-label":"Model description",value:h,onChange:S=>y(S.target.value),rows:5,style:{...ye(o),resize:"vertical"}})}),e.jsx(z,{label:"Column tests (one column per line)",children:e.jsx("textarea",{"aria-label":"Column tests",value:l,onChange:S=>u(S.target.value),rows:6,placeholder:"order_id: unique, not_null",style:{...ye(o),resize:"vertical",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"}})}),e.jsx("p",{style:{margin:0,color:o.textMuted,fontSize:10},children:"Descriptions/tests stay in dbt YAML. Business meaning, relationships, contracts, and policies stay in the DQL Domain Package."}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:i,children:"Cancel"}),e.jsx(se,{primary:!0,t:o,disabled:c,onClick:()=>void B(),children:"Preview source patch"})]})]})]})}function Gn({title:t,source:n,t:s}){return e.jsxs("section",{children:[e.jsx("strong",{style:{fontSize:10},children:t}),e.jsx("pre",{tabIndex:0,style:{maxHeight:360,overflow:"auto",whiteSpace:"pre-wrap",background:s.appBg,border:`1px solid ${s.headerBorder}`,borderRadius:6,padding:10,fontSize:9.5,color:s.textSecondary},children:n})]})}function ti({relationship:t,t:n,onEdit:s,onDelete:o}){var i,r,d;return e.jsxs(ln,{t:n,children:[e.jsx(ai,{title:t.localId,subtitle:`${t.from} → ${t.to}`,t:n}),e.jsx(se,{primary:!0,t:n,onClick:s,children:"Validate / edit"}),e.jsx("h3",{style:no(n),children:"Business meaning"}),e.jsx(le,{label:"verb",value:t.verb??"Not described",t:n}),e.jsx("p",{style:{margin:"0 0 8px",color:n.textSecondary,fontSize:11,lineHeight:1.55},children:t.description||`${t.from} relates to ${t.to}. Add a business description so agents can distinguish this route from similarly shaped joins.`}),e.jsx("h3",{style:no(n),children:"Join route"}),e.jsx(le,{label:"cardinality",value:t.cardinality,t:n}),e.jsx(le,{label:"fanout",value:t.fanout,t:n}),e.jsx(le,{label:"lifecycle",value:t.status,t:n}),e.jsx(le,{label:"join keys",value:t.keys.map(h=>`${h.from} = ${h.to}`).join(", "),t:n}),e.jsx(le,{label:"endpoint roles",value:[(i=t.roles)==null?void 0:i.from,(r=t.roles)==null?void 0:r.to].filter(Boolean).join(" → ")||"Not declared",t:n}),e.jsx(le,{label:"allowed joins",value:((d=t.joinTypes)==null?void 0:d.join(", "))||"left",t:n}),e.jsx(le,{label:"automatic agent join",value:t.automaticJoinAllowed?"Allowed":"Blocked",t:n}),t.validation?e.jsx(fo,{evidence:t.validation,t:n}):e.jsx(fe,{text:"No warehouse proof has been captured. This edge cannot authorize automatic SQL joins.",t:n}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:12},children:[e.jsx(se,{primary:!0,t:n,onClick:s,children:"Edit relationship"}),o?e.jsx(se,{t:n,danger:!0,onClick:o,children:"Delete relationship"}):null]})]})}function ni({data:t,domainEntities:n,domainRelationships:s,t:o,onSelectRelationship:i}){var f;const r=((f=n[0])==null?void 0:f.domain)??"All domains",d=s.filter(c=>{var x;return((x=c.validation)==null?void 0:x.status)==="passed"}).length,h=n.filter(c=>!!c.dbtUniqueId).length,y=n.filter(c=>!c.businessContext),l={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"14px 0 5px"},u=(c,x)=>e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,padding:"10px 12px",background:"var(--bg-1)"},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:o.textPrimary},children:c}),e.jsx("div",{style:{fontSize:10.5,color:o.textMuted},children:x})]}),m=(c,x)=>e.jsxs("span",{style:{display:"flex",alignItems:"flex-start",gap:7,fontSize:11.5,color:o.textSecondary,lineHeight:1.45},children:[e.jsx("span",{style:{color:c?"var(--status-success)":"var(--status-warning)",flexShrink:0,fontWeight:700},children:c?"✓":"△"}),x]},x);return e.jsxs(ln,{t:o,children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted},children:[r," model"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8,marginTop:12},children:[u(n.length,n.length===1?"entity":"entities"),u(s.length,s.length===1?"relationship":"relationships")]}),e.jsx("p",{style:{margin:"12px 0 0",color:o.textSecondary,fontSize:12,lineHeight:1.6},children:"Select an entity to see its columns and dbt binding, or click a relationship label to review its join, cardinality, and business context."}),e.jsx("div",{style:l,children:"Model health"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[s.length>0?m(d===s.length,d===s.length?"All relationships have join proofs":`${d} of ${s.length} relationships have join proofs`):m(!1,"No relationships yet — drag between column handles to create one"),m(h===n.length&&n.length>0,n.length===0?"No entities bound yet — use Bind model":`${h} of ${n.length} entities bound to dbt`),y.length>0?m(!1,`${y[0].localId}${y.length>1?` and ${y.length-1} more`:""} ha${y.length>1?"ve":"s"} no business description`):n.length>0?m(!0,"Every entity has a business description"):null]}),e.jsx("div",{style:l,children:"Relationships"}),s.length?s.map(c=>e.jsxs("button",{onClick:()=>i(c),style:{display:"flex",alignItems:"center",gap:7,width:"100%",textAlign:"left",border:"1px solid var(--border-subtle)",borderRadius:7,background:"var(--bg-1)",color:o.textSecondary,padding:"6px 8px",marginBottom:4,cursor:"pointer",fontSize:11,fontFamily:o.font},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:c.cardinality==="one_to_one"?"1:1":c.cardinality==="one_to_many"?"1:N":c.cardinality==="many_to_one"?"N:1":"N:N"})]},c.qualifiedId)):e.jsx("p",{style:{color:o.textMuted,fontSize:10.5,margin:0},children:"Drag between two column handles to create the first relationship."}),e.jsx("div",{style:l,children:"Ownership boundary"}),e.jsx("p",{style:{color:o.textSecondary,fontSize:11,lineHeight:1.55,margin:0},children:"dbt owns tables, columns, descriptions, tests, and metrics. DQL owns domain membership, analytical identity, safe relationship proof, contracts, certified blocks, and agent policy. Shared apps and notebooks reference this domain without moving inside it."})]})}function fo({evidence:t,t:n,onFixWithAi:s}){return e.jsxs("div",{style:{marginTop:12,padding:10,border:`1px solid ${t.status==="passed"?"#2e9b6355":"#c94b5555"}`,background:t.status==="passed"?"#2e9b630d":"#c94b550d",borderRadius:7,fontSize:11},children:[e.jsx("b",{style:{color:t.status==="passed"?"#2e9b63":"#c94b55"},children:t.status==="passed"?"Warehouse proof passed":"Warehouse proof failed"}),e.jsxs("div",{style:{color:n.textSecondary,marginTop:7,lineHeight:1.55},children:["Rows: ",t.fromRows," → ",t.toRows,e.jsx("br",{}),"Joined: ",t.joinedRows," · unmatched: ",t.unmatchedFrom,e.jsx("br",{}),"Max rows/key: ",t.maxFromPerKey," → ",t.maxToPerKey]}),s?e.jsxs("button",{type:"button",onClick:s,style:{...Xe(n),marginTop:9},children:[e.jsx(Ht,{size:13})," Fix with Modeling AI"]}):null]})}function Xn({t,title:n,detail:s,status:o}){return e.jsx("div",{style:{flex:1,display:"grid",placeItems:"center",background:t.appBg,color:t.textPrimary},children:e.jsxs("div",{style:{maxWidth:560,textAlign:"center"},children:[e.jsx(Ze,{size:34,color:t.accent}),e.jsx("h1",{style:{fontSize:20},children:n}),e.jsx("p",{style:{color:t.textSecondary,lineHeight:1.6},children:s}),o&&e.jsx("code",{style:{fontSize:12},children:o})]})})}function yo({title:t,t:n,onClose:s,children:o}){return e.jsx("div",{style:{position:"fixed",inset:0,zIndex:100,background:"#0008",display:"grid",placeItems:"center",padding:20},onMouseDown:i=>{i.target===i.currentTarget&&s()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&s()},style:{width:"min(720px, 94vw)",maxHeight:"88vh",overflow:"auto",background:n.appBg,border:`1px solid ${n.headerBorder}`,borderRadius:12,boxShadow:"0 24px 80px #0006"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"15px 18px",borderBottom:`1px solid ${n.headerBorder}`},children:[e.jsx("strong",{children:t}),e.jsx("button",{"aria-label":`Close ${t}`,title:"Close",onClick:s,style:ze(n),children:e.jsx(tt,{size:17})})]}),e.jsx("div",{style:{padding:18},children:o})]})})}function Zn({current:t,labels:n,t:s}){return e.jsx("div",{"aria-label":`Step ${t} of ${n.length}`,style:{display:"grid",gridTemplateColumns:`repeat(${n.length}, minmax(0, 1fr))`,gap:6},children:n.map((o,i)=>{const r=i+1,d=r===t,h=r<t;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,color:d?s.textPrimary:s.textMuted,fontSize:10,fontWeight:d?700:550},children:[e.jsx("span",{style:{display:"grid",placeItems:"center",width:20,height:20,flex:"0 0 auto",borderRadius:999,border:`1px solid ${d||h?s.accent:s.headerBorder}`,background:h?s.accent:d?"var(--accent-dim)":s.appBg,color:h?"#fff":d?s.accent:s.textMuted},children:h?"✓":r}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o})]},o)})})}function eo({title:t,detail:n,t:s}){return e.jsxs("div",{style:{display:"grid",gap:3,padding:"9px 11px",border:`1px solid ${s.headerBorder}`,borderRadius:7,background:s.cellBg},children:[e.jsx("strong",{style:{fontSize:11},children:t}),e.jsx("span",{style:{color:s.textMuted,fontSize:9.5,overflowWrap:"anywhere"},children:n})]})}function Nt({ariaLabel:t,value:n,onChange:s,options:o,placeholder:i,disabled:r=!1,t:d}){const[h,y]=a.useState(!1),[l,u]=a.useState(""),m=o.find(c=>c.value===n),f=_s(o,l,50);return e.jsxs("div",{style:{position:"relative",minWidth:0},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:d.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":t,"aria-expanded":h,"aria-controls":h?"modeling-search-results":void 0,disabled:r,value:h?l:(m==null?void 0:m.label)??n,placeholder:i,onFocus:()=>{y(!0),u("")},onBlur:()=>{y(!1),u("")},onChange:c=>{y(!0),u(c.target.value)},onKeyDown:c=>{c.key==="Escape"&&(y(!1),u(""))},style:{...ye(d),paddingLeft:29,paddingRight:n?29:8,opacity:r?.6:1}}),n&&!r&&e.jsx("button",{type:"button","aria-label":"Clear selection",onMouseDown:c=>c.preventDefault(),onClick:()=>{s(""),u(""),y(!0)},style:{...ze(d),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),h&&!r&&e.jsxs("div",{id:"modeling-search-results",role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:230,overflowY:"auto",border:`1px solid ${d.headerBorder}`,borderRadius:7,background:d.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[f.length?f.map(c=>e.jsxs("button",{type:"button",role:"option","aria-selected":c.value===n,onMouseDown:x=>x.preventDefault(),onClick:()=>{s(c.value),y(!1),u("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:c.value===n?"var(--accent-dim)":"transparent",color:d.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:c.label}),c.description&&e.jsx("span",{style:{color:d.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.description})]},c.value)):e.jsx("div",{style:{padding:12,color:d.textMuted,fontSize:10},children:"No matching results."}),o.length>50&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${d.headerBorder}`,color:d.textMuted,fontSize:9},children:["Showing the best 50 of ",o.length.toLocaleString(),". Refine your search for a specific result."]})]})]})}function oi({value:t,onChange:n,selectedNode:s,t:o}){const[i,r]=a.useState(""),[d,h]=a.useState(!1),[y,l]=a.useState(!1),[u,m]=a.useState(0),[f,c]=a.useState([]);return a.useEffect(()=>{let x=!1;const I=window.setTimeout(()=>{l(!0),Z.getDbtModelInventory({q:i,limit:50}).then(v=>{x||(m(v.total),c(v.items.map(w=>{var b;const B=w;return{value:B.uniqueId??"",label:B.name??B.uniqueId??"Unnamed model",description:`${B.relation??B.sourcePath??B.uniqueId}${B.binding?` · already bound to ${B.binding.domain??"a domain"}`:" · unbound"}`,keywords:[B.sourcePath??"",((b=B.binding)==null?void 0:b.businessName)??""]}}).filter(w=>w.value)))}).catch(()=>{x||c([])}).finally(()=>{x||l(!1)})},140);return()=>{x=!0,window.clearTimeout(I)}},[i]),e.jsxs("div",{style:{position:"relative"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:o.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":"Search dbt models","aria-expanded":d,value:d?i:(s==null?void 0:s.name)??t,placeholder:"Search model, relation, or path…",onFocus:()=>{h(!0),r("")},onBlur:()=>{h(!1),r("")},onChange:x=>{r(x.target.value),h(!0)},onKeyDown:x=>{x.key==="Escape"&&h(!1)},style:{...ye(o),paddingLeft:29,paddingRight:t?29:8}}),t&&e.jsx("button",{type:"button","aria-label":"Clear dbt model",onMouseDown:x=>x.preventDefault(),onClick:()=>{n(""),h(!0)},style:{...ze(o),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),d&&e.jsxs("div",{role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:260,overflowY:"auto",border:`1px solid ${o.headerBorder}`,borderRadius:7,background:o.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[y&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"Searching project inventory…"}),!y&&f.map(x=>e.jsxs("button",{type:"button",role:"option","aria-selected":x.value===t,onMouseDown:I=>I.preventDefault(),onClick:()=>{n(x.value),h(!1),r("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:x.value===t?"var(--accent-dim)":"transparent",color:o.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:x.label}),e.jsx("span",{style:{color:o.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.description})]},x.value)),!y&&!f.length&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"No dbt models match this search."}),!y&&u>f.length&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${o.headerBorder}`,color:o.textMuted,fontSize:9},children:["Showing 50 of ",u.toLocaleString(),". Keep typing to narrow the inventory."]})]})]})}function z({label:t,children:n}){return e.jsxs("label",{style:{display:"grid",gap:6,fontSize:11,fontWeight:650},children:[t,n]})}function _({value:t,onChange:n,t:s,placeholder:o}){return e.jsx("input",{value:t,placeholder:o,onChange:i=>n(i.target.value),style:ye(s)})}function ae({value:t,onChange:n,values:s,labels:o,t:i}){return e.jsxs("select",{value:t,onChange:r=>n(r.target.value),style:ye(i),children:[e.jsx("option",{value:"",children:"Select…"}),s.map(r=>e.jsx("option",{value:r,children:(o==null?void 0:o[r])??r},r))]})}function se({children:t,t:n,onClick:s,primary:o,disabled:i,danger:r}){return e.jsx("button",{disabled:i,onClick:s,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,border:`1px solid ${r?n.error:o?n.accent:n.headerBorder}`,background:r?`${n.error}12`:o?n.accent:n.appBg,color:r?n.error:o?"#fff":n.textPrimary,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:650,cursor:i?"wait":"pointer",opacity:i?.65:1},children:t})}function si({children:t,title:n,t:s,onClick:o}){return e.jsx("button",{"aria-label":n,title:n,onClick:o,style:ze(s),children:t})}function qt({children:t,t:n}){return e.jsx("span",{style:{marginLeft:5,border:`1px solid ${n.accent}55`,color:n.accent,background:`${n.accent}10`,borderRadius:999,padding:"3px 7px",fontSize:9,fontWeight:750},children:t})}function ii({children:t,t:n}){return e.jsx("div",{style:{padding:"15px 12px 8px",color:n.textMuted,fontSize:10,fontWeight:750,textTransform:"uppercase",letterSpacing:".07em"},children:t})}function bo({children:t}){return e.jsx("div",{style:{height:"100%",overflow:"auto",padding:20},children:t})}function jo({title:t,detail:n,t:s,action:o}){return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:20,alignItems:"start",marginBottom:18},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("p",{style:{margin:"5px 0 0",color:s.textSecondary,fontSize:11},children:n})]}),o]})}function on({title:t,detail:n,t:s}){return e.jsxs("div",{style:{border:`1px dashed ${s.headerBorder}`,borderRadius:10,padding:30,textAlign:"center"},children:[e.jsx("strong",{children:t}),e.jsx("p",{style:{color:s.textSecondary,fontSize:12},children:n})]})}function ln({children:t}){return e.jsx("div",{style:{padding:"4px 14px 20px"},children:t})}function ai({title:t,subtitle:n,t:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("div",{style:{color:s.textMuted,fontSize:11,marginTop:4},children:n})]})}function le({label:t,value:n,t:s}){return e.jsxs("div",{style:{padding:"9px 0",borderBottom:`1px solid ${s.headerBorder}`},children:[e.jsx("div",{style:{color:s.textMuted,fontSize:9,textTransform:"uppercase",letterSpacing:".05em"},children:t}),e.jsx("div",{style:{fontSize:11,marginTop:4,overflowWrap:"anywhere"},children:n})]})}function fe({text:t,t:n}){return e.jsx("div",{style:{borderLeft:`3px solid ${n.accent}`,background:`${n.accent}0d`,padding:"9px 10px",color:n.textSecondary,fontSize:11,lineHeight:1.5},children:t})}function Y(t){return t.split(",").map(n=>n.trim()).filter(Boolean)}function li(t){return Y(t).map(n=>{const[s,o]=n.split("=").map(i=>i.trim());if(!s||!o)throw new Error(`Invalid join key pair "${n}". Use from_key=to_key.`);return{from:s,to:o}})}function to(){try{return JSON.parse(localStorage.getItem("dql-modeling-preferences")??"{}")}catch{return{}}}const ne={display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},Ge=(t,n=!1)=>({display:"inline-flex",alignItems:"center",gap:5,flex:"0 0 auto",border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,background:n?"var(--accent-dim)":t.appBg,color:n?t.accent:t.textSecondary,padding:"5px 8px",fontSize:10.5,fontWeight:650,cursor:"pointer",whiteSpace:"nowrap"}),ye=t=>({width:"100%",boxSizing:"border-box",border:`1px solid ${t.headerBorder}`,background:t.cellBg,color:t.textPrimary,borderRadius:6,padding:"8px 9px",fontSize:11}),ze=t=>({border:`1px solid ${t.headerBorder}`,background:t.appBg,color:t.textSecondary,borderRadius:6,padding:7,display:"grid",placeItems:"center",cursor:"pointer"}),ri=(t,n,s)=>({width:"100%",minHeight:30,padding:s?"6px 8px 6px 14px":"7px 8px",display:"flex",alignItems:"center",gap:7,border:0,borderRadius:6,background:n?`${t.accent}18`:"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,fontWeight:n?700:500,textAlign:"left",cursor:"pointer"}),Xe=t=>({border:0,background:"transparent",color:t.accent,fontSize:10,fontWeight:650,cursor:"pointer"}),no=t=>({margin:"18px 0 7px",paddingBottom:7,borderBottom:`1px solid ${t.headerBorder}`,fontSize:11,textTransform:"uppercase",letterSpacing:".05em",color:t.textMuted}),Tt=t=>({border:`1px solid ${t.headerBorder}`,background:t.cellBg,borderRadius:9,padding:14});export{Ri as DbtFirstModelingPage};
|
|
21
|
+
`;function Kn(t,n=!1){return{display:"inline-flex",alignItems:"center",gap:6,border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,padding:"7px 10px",color:n?t.accent:t.textSecondary,background:n?`${t.accent}12`:t.cellBg,cursor:"pointer",fontSize:11,fontWeight:650}}function en(t){return t.replace(/[._-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function uo(t){const n=["#6d5ce7","#2e9b63","#d47822","#377cc8","#bd4f8b","#8a6d3b"];let s=0;for(const o of t)s=(s<<5)-s+o.charCodeAt(0)|0;return n[Math.abs(s)%n.length]}const $s=so;function po(t,n,s){var f;const o=t.modeling.areas[s??""],i=Object.keys(t.modeling.packages??{}),r=n??(i.length===1?i[0]:xo(((f=t.dbtProvenance)==null?void 0:f.projectName)??"").replace(/-/g,"_")||"analytics"),[d,h]=a.useState(r),[y,l]=a.useState((o==null?void 0:o.localId)??(o==null?void 0:o.id)??$s),u=!i.includes(d),m=!Object.values(t.modeling.areas??{}).some(c=>c.domain===d&&(c.localId===y||c.id===y));return{scopeDomain:d,setScopeDomain:h,scopeArea:y,setScopeArea:l,domains:i,domainIsNew:u,areaIsNew:m}}function ho({scope:t,theme:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("label",{style:_t(n),children:["Domain",e.jsx("input",{"aria-label":"Domain",list:"dql-scope-domains",value:t.scopeDomain,onChange:s=>t.setScopeDomain(s.target.value),style:St(n)}),e.jsx("datalist",{id:"dql-scope-domains",children:t.domains.map(s=>e.jsx("option",{value:s},s))}),e.jsx("small",{style:{color:t.domainIsNew?"var(--status-warning)":n.textMuted},children:t.domainIsNew?"Will be created with these models.":"Existing Domain."})]}),e.jsxs("label",{style:_t(n),children:["Subject area",e.jsx("input",{"aria-label":"Subject area",value:t.scopeArea,onChange:s=>t.setScopeArea(s.target.value),style:St(n)}),e.jsxs("small",{style:{color:t.areaIsNew?"var(--status-warning)":n.textMuted},children:[t.areaIsNew?"Will be created with these models.":"Existing subject area."," A subject area is one focused diagram inside the Domain — it organizes source and sharpens retrieval, and never changes what an agent is allowed to use."]})]})]})}function Rs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState(""),[y,l]=a.useState([]),[u,m]=a.useState({}),[f,c]=a.useState([]),[x,I]=a.useState(1),[v,w]=a.useState(!1),[B,b]=a.useState(null),S=po(t,n,s);a.useEffect(()=>{let j=!0;const E=window.setTimeout(()=>{X.getDbtModelInventory({q:d,limit:100,physicalOnly:!0}).then(C=>{if(!j)return;const O=C.items.filter(M=>!M.binding);l(O),m(M=>({...M,...Object.fromEntries(O.map(T=>[T.uniqueId,T]))}))}).catch(C=>{j&&b(C instanceof Error?C.message:String(C))})},180);return()=>{j=!1,window.clearTimeout(E)}},[d]);const P=f.flatMap(j=>u[j]?[u[j]]:[]),q=a.useMemo(()=>As(t,S.scopeDomain,S.scopeArea,P),[t,S.scopeArea,S.scopeDomain,P]),N=async()=>{var j;w(!0),b(null);try{const E=await X.createContextProposal({origin:"dbt_discovery",expectedSnapshotId:(j=t.snapshot)==null?void 0:j.id,operations:q});r(E)}catch(E){b(E instanceof Error?E.message:String(E))}finally{w(!1)}};return e.jsxs(go,{title:"Add models",subtitle:`Step ${x} of 3 · ${x===1?"Select dbt models":x===2?"Assign ownership":"Review proposal inputs"}`,theme:o,busy:v,onClose:i,children:[x===1?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:14,style:{position:"absolute",left:10,top:10,color:o.textMuted}}),e.jsx("input",{autoFocus:!0,"aria-label":"Search dbt models",value:d,onChange:j=>h(j.target.value),placeholder:"Search model name, package, or relation",style:{...St(o),width:"100%",paddingLeft:32}})]}),e.jsxs("div",{style:{display:"grid",gap:6,marginTop:12},children:[y.map(j=>e.jsxs("label",{style:Et(o),children:[e.jsx("input",{type:"checkbox",checked:f.includes(j.uniqueId),onChange:E=>c(C=>E.target.checked?[...C,j.uniqueId]:C.filter(O=>O!==j.uniqueId))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11.5},children:j.name}),e.jsx("code",{style:{color:o.textMuted,fontSize:9.5},children:j.uniqueId})]}),e.jsx("small",{style:{color:o.textMuted},children:j.packageName})]},j.uniqueId)),y.length?null:e.jsx(vt,{theme:o,children:"No unbound dbt models match this search."})]})]}):x===2?e.jsxs(e.Fragment,{children:[e.jsx(ho,{scope:S,theme:o}),e.jsx(vt,{theme:o,children:"Every model receives exactly one Domain and subject area. DQL stores the dbt unique ID and business overlay; dbt-owned columns, SQL, tests, descriptions, and lineage remain in dbt."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[q.length," sparse entity-binding patch",q.length===1?"":"es"," will be prepared. No source changes occur until the exact proposal is reviewed and explicitly saved."]}),P.map(j=>e.jsxs("div",{style:Et(o),children:[e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:j.name}),e.jsx("code",{style:{fontSize:9.5,color:o.textMuted},children:j.uniqueId})]}),e.jsxs("span",{style:{fontSize:10,color:o.textMuted},children:[S.scopeDomain," / ",S.scopeArea]})]},j.uniqueId))]}),B?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:B}):null,e.jsx(tn,{theme:o,busy:v,back:x>1?()=>I(x-1):void 0,next:x<3?()=>I(x+1):()=>void N(),nextLabel:x<3?"Continue":"Create review proposal",disabled:f.length===0||!S.scopeDomain.trim()||!S.scopeArea.trim()})]})}function Bs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState("current_project"),[y,l]=a.useState(""),[u,m]=a.useState(""),[f,c]=a.useState("modeling.yml"),[x,I]=a.useState(null),[v,w]=a.useState([]),[B,b]=a.useState(!1),[S,P]=a.useState(null),q=po(t,n,s),N=async()=>{b(!0),P(null);try{const C=await X.createModelingImport({mode:d,...d==="path"?{path:y}:{},...d==="paste"||d==="upload"?{content:u,filename:f}:{}});I(C),w(C.candidates.filter(O=>O.action==="import").map(O=>O.id))}catch(C){P(C instanceof Error?C.message:String(C))}finally{b(!1)}},j=async()=>{var C;if(x){b(!0),P(null);try{const O=await X.previewModelingImport(x.id,{selectedCandidateIds:v,domain:q.scopeDomain,areaId:q.scopeArea,expectedSnapshotId:((C=t.snapshot)==null?void 0:C.id)??""});r(O.proposal)}catch(O){P(O instanceof Error?O.message:String(O))}finally{b(!1)}}},E=C=>{if(!C)return;c(C.name);const O=new FileReader;O.onload=()=>m(String(O.result??"")),O.onerror=()=>P("Could not read the selected YAML file."),O.readAsText(C)};return e.jsxs(go,{title:"Import modeling YAML",subtitle:x?"Classify, select, and review":"Choose a safe import source",theme:o,busy:B,onClose:i,children:[x?e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[e.jsx(an,{size:13,style:{verticalAlign:-2,marginRight:5}}),"DQL modeling becomes a reviewed copy; dbt YAML becomes a sparse overlay. Generic YAML is not imported."]}),e.jsx("div",{style:{display:"grid",gap:7},children:x.candidates.map(C=>e.jsxs("label",{style:{...Et(o),opacity:C.action==="import"?1:.72},children:[e.jsx("input",{type:"checkbox",disabled:C.action!=="import",checked:v.includes(C.id),onChange:O=>w(M=>O.target.checked?[...M,C.id]:M.filter(T=>T!==C.id))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:C.name}),e.jsxs("span",{style:{display:"block",marginTop:2,color:o.textMuted,fontSize:9.5},children:[C.dialect.replace(/_/g," ")," · ",C.summary]}),C.warnings.map(O=>e.jsx("small",{style:{display:"block",color:"var(--status-warning)",marginTop:3},children:O},O))]}),e.jsx("span",{style:{fontSize:9.5,color:o.textMuted},children:C.action.replace(/_/g," ")})]},C.id))}),e.jsx(ho,{scope:q,theme:o}),e.jsx(tn,{theme:o,busy:B,back:()=>{I(null),w([])},next:()=>void j(),nextLabel:"Review exact patches",disabled:!v.length||!q.scopeDomain.trim()||!q.scopeArea.trim()})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:6},children:["current_project","path","upload","paste"].map(C=>e.jsx("button",{type:"button",onClick:()=>h(C),style:{...Ut(o),...d===C?{borderColor:o.accent,color:o.accent,background:"var(--accent-dim)"}:{}},children:C==="current_project"?"Project":C[0].toUpperCase()+C.slice(1)},C))}),d==="current_project"?e.jsxs(vt,{theme:o,children:[e.jsx(No,{size:13,style:{verticalAlign:-2,marginRight:5}}),"Search the current project for DQL and dbt YAML. Existing DQL source opens in place and is not copied."]}):null,d==="path"?e.jsxs("label",{style:_t(o),children:["Local file or directory",e.jsx("input",{"aria-label":"Local YAML path",value:y,onChange:C=>l(C.target.value),placeholder:"models or domains/sales",style:St(o)}),e.jsx("small",{children:"Loopback-only and confined to the current approved project root."})]}):null,d==="upload"?e.jsxs("label",{style:{...Et(o),marginTop:12},children:[e.jsx(cs,{size:15}),e.jsx("span",{style:{flex:1},children:"Choose a YAML file"}),e.jsx("input",{type:"file",accept:".yml,.yaml,text/yaml",onChange:C=>{var O;return E((O=C.target.files)==null?void 0:O[0])}})]}):null,d==="paste"?e.jsxs("label",{style:_t(o),children:["Paste DQL or dbt YAML",e.jsx("textarea",{"aria-label":"Paste modeling YAML",value:u,onChange:C=>m(C.target.value),rows:14,style:{...St(o),resize:"vertical",fontFamily:o.fontMono}})]}):null,e.jsx(tn,{theme:o,busy:B,next:()=>void N(),nextLabel:"Discover YAML",disabled:d==="path"&&!y.trim()||(d==="paste"||d==="upload")&&!u.trim()})]}),S?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:S}):null]})}function As(t,n,s,o){if(!n.trim()||!s.trim())return[];const i=new Set(Object.values(t.modeling.entities).filter(r=>r.domain===n).map(r=>r.localId||r.id));return[...o].sort((r,d)=>r.uniqueId.localeCompare(d.uniqueId)).map(r=>{const d=xo(r.name)||"model";let h=d;i.has(h)&&(h=`${d}-${r.identityFingerprint.slice(0,6).toLowerCase()}`);let y=2;for(;i.has(h);)h=`${d}-${y++}`;return i.add(h),{id:`bind:${r.uniqueId}`,kind:"modeling_change",change:{operation:"upsert_entity",value:{id:h,domain:n,areaId:s,dbtModel:r.uniqueId,businessName:Ps(r.name),status:"draft"}},evidence:[`dbt unique id ${r.uniqueId}`,`manifest fingerprint ${r.identityFingerprint}`]}})}function xo(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64)}function Ps(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function go({title:t,subtitle:n,theme:s,busy:o,onClose:i,children:r}){return e.jsx("div",{onClick:()=>!o&&i(),style:{position:"fixed",inset:0,zIndex:120,background:"rgba(8,10,16,.46)",display:"flex",justifyContent:"flex-end"},children:e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-label":t,onClick:d=>d.stopPropagation(),style:{width:"min(600px, 96vw)",height:"100%",background:s.appBg,borderLeft:"1px solid var(--border-default)",boxShadow:"-16px 0 45px rgba(0,0,0,.22)",display:"flex",flexDirection:"column"},children:[e.jsxs("header",{style:{minHeight:58,padding:"0 18px",borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:14},children:t}),e.jsx("small",{style:{color:s.textMuted},children:n})]}),e.jsx("button",{"aria-label":"Close",disabled:o,onClick:i,style:{...Ut(s),width:30,padding:0},children:e.jsx(us,{size:14})})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:18},children:r})]})})}function tn({theme:t,busy:n,back:s,next:o,nextLabel:i,disabled:r=!1}){return e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[s?e.jsx("button",{type:"button",onClick:s,disabled:n,style:Ut(t),children:"Back"}):null,e.jsxs("button",{type:"button",onClick:o,disabled:n||r,style:{...Ls(t),opacity:n||r?.55:1},children:[n?e.jsx(Oo,{size:13}):null,i]})]})}function vt({theme:t,children:n}){return e.jsx("div",{style:{margin:"12px 0",padding:"10px 11px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)",color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:n})}const St=t=>({boxSizing:"border-box",border:"1px solid var(--border-default)",background:t.inputBg,color:t.textPrimary,borderRadius:7,padding:"8px 9px",outline:"none"}),_t=t=>({display:"grid",gap:6,marginTop:12,color:t.textSecondary,fontSize:11}),Et=t=>({display:"flex",gap:9,alignItems:"center",border:"1px solid var(--border-subtle)",borderRadius:8,background:t.cellBg,padding:"9px 10px"}),Ut=t=>({minHeight:31,border:"1px solid var(--border-default)",borderRadius:7,background:t.cellBg,color:t.textPrimary,padding:"0 11px",cursor:"pointer",display:"inline-flex",gap:6,alignItems:"center",justifyContent:"center"}),Ls=t=>({...Ut(t),background:t.accent,borderColor:t.accent,color:"var(--accent-fg)",fontWeight:650});function Ns(t){return t instanceof Error?t:void 0}function Os(t){return t.details&&typeof t.details=="object"&&!Array.isArray(t.details)?t.details:void 0}function Yn(t){const n=Ns(t);if((n==null?void 0:n.code)==="DBT_FIRST_NOT_ENABLED")return{title:"Set up dbt-first modeling",detail:"Domain Studio requires a connected dbt project with manifest v3 and dbt-first modeling enabled. Open Settings → Project & dbt to connect and apply the project.",status:"Modeling mode · Not enabled"};if((n==null?void 0:n.code)==="DBT_MANIFEST_NOT_FOUND"){const o=Os(n),i=typeof(o==null?void 0:o.manifestPath)=="string"&&o.manifestPath.trim()?o.manifestPath:"target/manifest.json";return{title:"dbt manifest is not ready",detail:`The dbt project is connected, but ${i} was not found. Run dbt parse, dbt compile, or dbt build in the configured dbt project, then refresh Domain Studio.`,status:`dbt manifest · Missing (${i})`}}return(n==null?void 0:n.code)==="DBT_MANIFEST_COMPILE_FAILED"?{title:"dbt manifest could not be loaded",detail:`${n.message} Rebuild the dbt manifest, then refresh Domain Studio.`,status:"dbt manifest · Load failed"}:{title:"Domain Studio could not load",detail:t instanceof Error&&t.message?t.message:"The local DQL notebook server did not return Domain Studio data.",status:"Domain Studio · Unavailable"}}function jt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g," ").trim()}function _s(t,n,s=50){const o=jt(n),i=o.split(/\s+/).filter(Boolean);return t.map(r=>{var f;const d=jt(r.label),h=jt(r.value),y=jt(r.description??""),l=jt(((f=r.keywords)==null?void 0:f.join(" "))??""),u=`${d} ${h} ${y} ${l}`;if(i.length&&!i.every(c=>u.includes(c)))return null;let m=0;return o&&((d===o||h===o)&&(m+=1e3),d.startsWith(o)&&(m+=500),h.startsWith(o)&&(m+=350),d.includes(o)&&(m+=200),m+=i.reduce((c,x)=>c+(d.startsWith(x)?80:d.includes(x)?40:10),0)),{option:r,score:m}}).filter(r=>!!r).sort((r,d)=>d.score-r.score||r.option.label.localeCompare(d.option.label)||r.option.value.localeCompare(d.option.value)).slice(0,Math.max(1,s)).map(({option:r})=>r)}function Ri(){var pt,ht;const{state:t,dispatch:n}=Wt(),s=_o[t.themeMode],[o,i]=a.useState(null),[r,d]=a.useState(!0),[h,y]=a.useState(null),l=a.useMemo(()=>Vn(),[]),[u,m]=a.useState(l.section),[f,c]=a.useState(l.domain),[x,I]=a.useState(l.modelAreaId),[v,w]=a.useState(l.selectedId),[B,b]=a.useState(null),[S,P]=a.useState({}),q=a.useRef(new Map),N=a.useRef(new Set),j=a.useMemo(()=>to(),[]),[E,C]=a.useState(j.viewMode??"business"),[O,M]=a.useState(j.columnMode??"relevant"),[T,re]=a.useState(""),[be,de]=a.useState(0),[k,D]=a.useState(null),[A,F]=a.useState(j.layoutMode??"auto"),[U,V]=a.useState(j.density??"normal"),[K,ie]=a.useState(j.visibleLimit??50),[ce,De]=a.useState(j.dimUnrelated??!0),[ge,_e]=a.useState(j.showEdgeLabels??!0),[we,je]=a.useState(!1),[H,Ce]=a.useState(!1),[R,oe]=a.useState(!1),[me,Ee]=a.useState(()=>typeof window<"u"&&window.innerWidth<980),qe=a.useRef(null),wt=a.useRef(null),[ve,te]=a.useState(null),[ue,pe]=a.useState(null),[nt,ke]=a.useState(null),[$e,ot]=a.useState(()=>to().aiDockOpen===!0),[Te,Kt]=a.useState(null),[st,kt]=a.useState(null),[it,at]=a.useState(null),[Se,Fe]=a.useState(null),[Ct,It]=a.useState(!1),[lt,Re]=a.useState(null);a.useEffect(()=>{localStorage.setItem("dql-modeling-preferences",JSON.stringify({modelingView:E,columnMode:O,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,aiDockOpen:$e}))},[E,O,A,U,K,ce,ge,$e]),a.useEffect(()=>{const g=()=>Ee(window.innerWidth<980);return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);const We=a.useCallback(()=>{oe(g=>{const $=!g;return $?window.requestAnimationFrame(()=>{var G;return(G=wt.current)==null?void 0:G.focus()}):window.requestAnimationFrame(()=>{var G;return(G=qe.current)==null?void 0:G.focus()}),$})},[]),rt=a.useCallback(g=>{m(g),Pt(f,g,!1,x,v)},[x,f,v]),Mt=a.useCallback(g=>{c(g),I(null),w(null),Pt(g,u,!1,null,null)},[u]);a.useEffect(()=>{const g=()=>{const $=Vn();c($.domain),I($.modelAreaId),w($.selectedId),m($.section)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[]),a.useEffect(()=>{Pt(f,u,!0,x,v)},[x,f,v,u]);const Be=async()=>{d(!0);try{const g=await X.getDbtFirstModeling();i(g),y(null);const $=f&&g.modeling.packages[f]?f:null;$!==f&&(c($),Pt($,u,!0))}catch(g){i(null),y(Yn(g))}finally{d(!1)}};a.useEffect(()=>{Be()},[]),a.useEffect(()=>{let g=null;try{g=window.sessionStorage.getItem("dql-context-proposal-handoff"),g&&window.sessionStorage.removeItem("dql-context-proposal-handoff")}catch{}g&&X.getContextProposal(g).then($=>{ke($),m($.impact.skillChanges>0&&$.impact.modelingChanges===0?"skills":"diagram")}).catch(()=>{})},[]);const He=a.useMemo(()=>Ws((o==null?void 0:o.modeling)??{entities:{},relationships:{}},Te),[o==null?void 0:o.modeling,Te]),Q=o==null?void 0:o.modeling.entities[v??""],he=o==null?void 0:o.modeling.relationships[v??""],dt=a.useMemo(()=>o?Object.values(o.modeling.areas).filter(g=>!f||g.domain===f).sort((g,$)=>g.name.localeCompare($.name)):[],[o,f]),J=o==null?void 0:o.modeling.areas[x??""];a.useEffect(()=>{o&&x&&!dt.some(g=>g.qualifiedId===x)&&I(null)},[o,dt,x]);const Ue=a.useCallback(g=>{const $=q.current.get(g);if($)return $;if(N.current.has(g))return Promise.resolve(void 0);const G=X.getDbtModelingNode(g).then(Ie=>(N.current.add(g),P(Je=>({...Je,[g]:Ie})),Ie)).catch(()=>{N.current.add(g)}).finally(()=>q.current.delete(g));return q.current.set(g,G),G},[]);a.useEffect(()=>{if(!Q){b(null);return}const g=S[Q.dbtUniqueId];if(g){b(g);return}let $=!1;return Ue(Q.dbtUniqueId).then(G=>{$||b(G??null)}),()=>{$=!0}},[S,Ue,Q==null?void 0:Q.dbtUniqueId]),a.useEffect(()=>{q.current.clear(),N.current.clear(),P({})},[o==null?void 0:o.dbtProvenance.manifestFingerprint]);const Ke=a.useCallback(g=>{for(const $ of g.slice(0,24))Ue($)},[Ue]);if(r&&!o)return e.jsx(Zn,{t:s,title:"Loading Domain Studio…",detail:"Compiling dbt provenance and the sparse DQL analytical overlay."});if(!o){const g=h??Yn(null);return e.jsx(Zn,{t:s,title:g.title,detail:g.detail,status:g.status})}const zt=Object.fromEntries(Object.values(o.dbtProvenance.nodes).map(g=>[g.uniqueId,g.relation])),Ye=Object.entries(o.modeling.entities).flatMap(([g,$])=>{var Je;const G=$.businessName||$.localId||$.id,Ie=[{recordKey:g,type:"model",label:G,sublabel:$.domain,role:$.analyticalRole}];for(const $t of((Je=S[$.dbtUniqueId])==null?void 0:Je.columns)??[])Ie.push({recordKey:g,type:"column",label:$t.name,sublabel:G,role:$.analyticalRole});return Ie}),Dt=g=>{w(g),re(""),D($=>({id:g,token:(($==null?void 0:$.token)??0)+1}))},Ae=J?new Set([...J.entityIds,...J.referencedEntityIds]):void 0,ct=io(o.modeling,f).filter(({recordKey:g})=>!Ae||Ae.has(g)),Pe=Object.values(o.modeling.relationships).filter(g=>{const $=o.modeling.entities[g.from],G=o.modeling.entities[g.to];return J?J.relationshipIds.includes(g.qualifiedId):!f||($==null?void 0:$.domain)===f||(G==null?void 0:G.domain)===f});Object.values(o.dbtProvenance.nodes).filter(g=>!Object.values(o.modeling.entities).some($=>$.dbtUniqueId===g.uniqueId));const ut=R&&u==="diagram",Ve=[...new Set(f?((ht=(pt=o.domainAssets)==null?void 0:pt[f])==null?void 0:ht.skills)??[]:Object.values(o.domainAssets??{}).flatMap(g=>g.skills??[]))].sort();return e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",background:s.appBg,color:s.textPrimary},children:[e.jsx("header",{style:{minHeight:52,padding:"0 14px",borderBottom:`1px solid ${s.headerBorder}`,background:s.headerBg,display:"flex",alignItems:"center"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",width:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx(Xe,{size:16,color:s.accent}),e.jsx("h1",{style:{margin:0,fontSize:12,fontWeight:800,whiteSpace:"nowrap"},children:"Modeling workspace"}),e.jsx("span",{style:{color:s.textMuted,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f?`/${f}`:"/all domains"})]}),e.jsxs("div",{style:{display:"flex",gap:7},children:[f&&e.jsxs(se,{t:s,onClick:()=>{try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},children:[e.jsx(Eo,{size:14})," Ask"]}),e.jsxs(se,{t:s,onClick:()=>pe("yaml"),children:[e.jsx(an,{size:14})," Import YAML"]}),e.jsx(si,{t:s,title:"Recompile",onClick:()=>void Be(),children:e.jsx(qo,{size:15})})]})]})}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"grid",gridTemplateColumns:ut&&!me?"clamp(190px, 15vw, 232px) minmax(460px, 1fr) clamp(270px, 22vw, 380px)":"clamp(190px, 15vw, 232px) minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${s.headerBorder}`,overflow:"auto",background:s.appBg},children:[e.jsx(qs,{data:o,selectedDomain:f,onSelect:Mt,t:s}),e.jsx(Ts,{data:o,domain:f,active:u,onSelect:rt,t:s}),e.jsx("div",{style:{padding:"10px 12px",borderTop:`1px solid ${s.headerBorder}`,display:"flex",flexDirection:"column",gap:5,fontSize:10.5,color:s.textMuted,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(--status-success)",flexShrink:0}}),"dbt synced · ",Object.keys(o.dbtProvenance.nodes).length," model",Object.keys(o.dbtProvenance.nodes).length===1?"":"s"]})})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{minHeight:42,display:"flex",alignItems:"center",gap:7,padding:"0 10px 0 14px",borderBottom:`1px solid ${s.headerBorder}`,background:s.headerBg},children:[mo(u,14,s),e.jsx("strong",{style:{fontSize:11},children:Fs(u)}),e.jsx("span",{style:{width:1,height:15,background:s.headerBorder}}),e.jsx("span",{style:{color:s.textMuted,fontSize:10},children:f??"All domains"}),(u==="diagram"||u==="skills")&&f&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:5},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:s.textMuted,fontSize:10},children:["Area",e.jsxs("select",{"aria-label":"Active subject area",value:x??"",onChange:g=>{I(g.target.value||null),w(null)},style:{...ye(s),minWidth:146,padding:"4px 6px"},children:[e.jsx("option",{value:"",children:"All domain"}),dt.map(g=>e.jsx("option",{value:g.qualifiedId,children:g.name},g.qualifiedId))]})]}),e.jsx("button",{"aria-label":"Add subject area",title:"Add subject area",onClick:()=>te({kind:"area"}),style:{...ze(s),width:27,height:27},children:e.jsx(et,{size:13})})]}),u==="diagram"&&e.jsx("button",{ref:qe,"aria-expanded":R,"aria-controls":"domain-studio-inspector","aria-label":R?"Hide inspector":"Show inspector",title:R?"Hide inspector":"Show inspector",onClick:We,style:{...ze(s),marginLeft:"auto"},children:R?e.jsx(js,{size:14}):e.jsx(ps,{size:14})})]}),e.jsxs("div",{style:{flex:1,minHeight:0},children:[u==="diagram"&&e.jsxs("div",{id:"dql-modeling-diagram",style:{height:"100%",display:"flex",flexDirection:"column",...H?{position:"fixed",inset:0,zIndex:90,background:s.appBg}:{}},children:[e.jsx(Ys,{modelingView:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,showLegend:we,fullscreen:H,aiOpen:$e,onBindModel:()=>pe("models"),onRelationship:()=>te({kind:"relationship"}),onToggleAi:()=>ot(g=>!g),onModelingView:C,onColumnMode:M,onSearch:re,searchItems:Ye,onPickModel:Dt,onLayoutMode:F,onDensity:V,onVisibleLimit:ie,onDimUnrelated:De,onEdgeLabels:_e,onLegend:je,onFullscreen:()=>Ce(g=>!g),onExport:()=>Qs(),onReset:()=>de(g=>g+1),t:s}),J?e.jsxs("div",{style:{padding:"7px 14px",borderBottom:`1px solid ${s.headerBorder}`,background:"var(--accent-dim)",color:s.textSecondary,display:"flex",alignItems:"center",gap:8,fontSize:10.5},children:[e.jsx(Xe,{size:13,color:s.accent}),e.jsx("strong",{style:{color:s.textPrimary},children:J.name}),e.jsx("span",{children:J.description??"Focused business modeling area"}),e.jsxs("span",{style:{marginLeft:"auto",color:s.textMuted},children:[J.entityIds.length," model",J.entityIds.length===1?"":"s"," · ",J.intentExamples.length," example question",J.intentExamples.length===1?"":"s"]})]}):null,we&&e.jsx(Vs,{t:s}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:ct.length===0?e.jsx(Js,{t:s,connectedModels:Object.keys(o.dbtProvenance.nodes).length,onDbt:()=>pe("models"),onYaml:()=>pe("yaml"),onManual:()=>te({kind:"entity"})}):e.jsx(vs,{modeling:He.modeling,ghostEntityIds:He.ghostEntityIds,ghostRelationshipIds:He.ghostRelationshipIds,relationByDbtId:zt,detailsByDbtId:S,selectedDomain:f,selectedAreaId:x,selectedId:v,viewMode:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,resetLayoutToken:be,focusRequest:k??void 0,onVisibleDbtIdsChange:Ke,onSelectEntity:w,onSelectRelationship:w,onEditRelationship:g=>{const $=o.modeling.relationships[g];$&&te({kind:"relationship",relationship:$})},onDraftRelationship:g=>te({kind:"relationship",draft:g}),onAddRelatedModel:g=>te({kind:"entity",relationshipFrom:g}),onAddModel:()=>pe("models"),onCreateDomain:()=>te({kind:"domain"}),onEditEntity:g=>{const $=o.modeling.entities[g];$&&te({kind:"entity",entity:$,dbtUniqueId:$.dbtUniqueId})},onOpenAi:g=>{w(g);try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId,objectId:g}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},theme:s})}),$e&&e.jsx("aside",{"aria-label":"Modeling AI",style:{width:"clamp(320px, 30vw, 460px)",borderLeft:`1px solid ${s.headerBorder}`,background:s.appBg,display:"flex",flexDirection:"column",minHeight:0},children:e.jsx(Zs,{domain:f,areaId:x,selectedId:v,data:o,themeMode:t.themeMode,t:s,correction:st,onClose:()=>ot(!1),onCorrectionStarted:()=>kt(null),onReviewProposal:ke,onPreviewProposal:Kt,onOpenSkills:()=>rt("skills"),onDraftRelationship:()=>te({kind:"relationship",draft:Q&&v?{from:v,to:""}:void 0})})})]})]}),u==="skills"&&e.jsx(Zo,{embedded:!0,domainFilter:f,modelAreaFilter:x,sourcePathFilter:Ve}),u==="blocks"&&e.jsx(Gs,{data:o,domain:f,t:s}),u==="notebooks"&&e.jsx(Jn,{data:o,domain:f,kind:"notebooks",t:s}),u==="apps"&&e.jsx(Jn,{data:o,domain:f,kind:"apps",t:s})]})]}),ut&&e.jsxs("aside",{id:"domain-studio-inspector",ref:wt,role:"complementary","aria-label":"Domain Studio inspector",tabIndex:-1,onKeyDown:g=>{g.key==="Escape"&&We()},style:{borderLeft:`1px solid ${s.headerBorder}`,overflow:"auto",background:s.appBg,minWidth:0,...me?{position:"fixed",inset:"0 0 0 auto",width:"min(90vw, 380px)",zIndex:95,boxShadow:"-12px 0 30px rgba(0,0,0,.18)"}:{}},children:[e.jsx(ii,{t:s,children:"Inspector"}),Q?e.jsx(Xs,{entity:Q,detail:B,relationships:Pe,t:s,onEdit:()=>te({kind:"entity",entity:Q,dbtUniqueId:Q.dbtUniqueId}),onEditDbtSource:()=>at(Q),onSelectRelationship:g=>w(nn(o.modeling.relationships,g)),onDelete:()=>{Re(null),Fe({kind:"entity",id:Q.localId||Q.id,domain:Q.domain,areaId:Q.areaId,label:Q.businessName||Q.localId||Q.id})}}):he?e.jsx(ti,{relationship:he,t:s,onEdit:()=>te({kind:"relationship",relationship:he}),onDelete:()=>{Re(null),Fe({kind:"relationship",id:he.localId||he.id,domain:he.ownerDomain??he.qualifiedId.split("::")[0],areaId:he.areaId,label:he.localId||he.id})}}):e.jsx(ni,{data:o,domainEntities:ct.map(({entity:g})=>g),domainRelationships:Pe,t:s,onSelectRelationship:g=>w(nn(o.modeling.relationships,g))})]})]}),ue==="models"?e.jsx(Rs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,ue==="yaml"?e.jsx(Bs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,nt?e.jsx(Xo,{proposal:nt,theme:s,onClose:()=>ke(null),onCommitted:()=>{ke(null),Be()}}):null,ve&&e.jsx(Us,{editor:ve,data:o,selectedDomain:f,selectedArea:J,t:s,onClose:()=>te(null),onProposal:g=>{te(null),ke(g)},onFixWithAi:(g,$)=>{te(null),g&&w(g),rt("diagram"),ot(!0),kt({text:"Fix the failed relationship validation. Keep it draft, remove stale proof, and explain the corrected cardinality, fanout, or keys using the attached receipt.",nonce:Date.now(),evidence:$})},onApplied:async g=>{te(null),await Be(),ve.kind==="entity"&&ve.relationshipFrom&&g.operation==="upsert_entity"&&te({kind:"relationship",draft:{...ve.relationshipFrom,to:g.value.id}})}}),it&&B&&e.jsx(ei,{entity:it,detail:B,snapshotId:o.snapshotId,t:s,onClose:()=>at(null),onApplied:async()=>{at(null),await Be()}}),Se&&e.jsx(Es,{pending:Se,busy:Ct,error:lt,t:s,onCancel:()=>{Fe(null),Re(null)},onConfirm:async()=>{It(!0),Re(null);try{const g={operation:Se.kind==="entity"?"remove_entity":"remove_relationship",value:{id:Se.id,domain:Se.domain,...Se.areaId?{areaId:Se.areaId}:{}}},$=await X.createContextProposal({origin:"manual",expectedSnapshotId:o.snapshotId,operations:[{id:`manual:${g.operation}:${Se.id}`,kind:"modeling_change",change:g,evidence:["manual Modeling workspace removal"]}]});if(!$.patches.some(G=>G.changed))throw new Error("Nothing to remove — it is no longer in the domain source.");Fe(null),w(null),ke($)}catch(g){Re(g instanceof Error?g.message:String(g))}finally{It(!1)}}})]})}function Es({pending:t,busy:n,error:s,t:o,onCancel:i,onConfirm:r}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`Delete ${t.kind}`,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.34)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:130},onClick:d=>{d.target===d.currentTarget&&!n&&i()},children:e.jsxs("div",{style:{width:"min(92vw, 420px)",background:o.appBg,border:`1px solid ${o.headerBorder}`,borderRadius:12,padding:18,boxShadow:"0 18px 44px rgba(0,0,0,.22)"},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:700,color:o.textPrimary,marginBottom:6},children:["Delete this ",t.kind,"?"]}),e.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5},children:[e.jsx("strong",{style:{fontFamily:o.fontMono},children:t.label})," will be removed from the"," ",e.jsx("strong",{children:t.domain})," domain source. dbt models and warehouse data are not affected."]}),t.kind==="entity"?e.jsx("div",{style:{fontSize:11.5,color:o.textMuted,marginTop:8,lineHeight:1.5},children:"Relationships that reference it are left in place and will report a missing endpoint until you remove or repoint them."}):null,s?e.jsx("div",{style:{fontSize:11.5,color:o.error,marginTop:10,lineHeight:1.5},children:s}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[e.jsx(se,{t:o,onClick:i,disabled:n,children:"Cancel"}),e.jsx(se,{t:o,danger:!0,onClick:r,disabled:n,children:n?"Deleting…":`Delete ${t.kind}`})]})]})})}function qs({data:t,selectedDomain:n,onSelect:s,t:o}){const{state:i}=Wt(),r=Wo(t.modeling.packages),d=new Map(Ho(i.authoredDomains).map(h=>[h.value,h.label]));return e.jsx("nav",{"aria-label":"Domain packages",children:e.jsx(Uo,{id:"domain-workspace-filter",ariaLabel:"Domain workspace",value:n??"",options:r.map(h=>({value:h.id,label:d.get(h.id)??h.label})),onChange:h=>s(h||null),summary:e.jsxs(e.Fragment,{children:[r.length," authored domain",r.length===1?"":"s"," available"]}),t:o})})}function Ts({data:t,domain:n,active:s,onSelect:o,t:i}){var y;const r=n?[((y=t.domainAssets)==null?void 0:y[n])??{}]:Object.values(t.domainAssets??{}),h={diagram:io(t.modeling,n).length,skills:r.reduce((l,u)=>{var m;return l+(((m=u.skills)==null?void 0:m.length)??0)},0),blocks:new Set(r.flatMap(l=>l.blocks??[])).size};return e.jsx("nav",{"aria-label":n?`${n} workspace`:"All domains workspace",style:{padding:"10px 7px 14px"},children:lo.map((l,u)=>e.jsxs("div",{style:{marginTop:u===0?0:12},children:[l.label?e.jsx("div",{style:{padding:"0 8px 6px",color:i.textMuted,fontSize:9,fontWeight:800,textTransform:"uppercase",letterSpacing:".06em"},children:l.label}):null,l.items.map(m=>e.jsxs("button",{onClick:()=>o(m.id),"aria-current":s===m.id?"page":void 0,style:ri(i,s===m.id,!1),children:[mo(m.id,14,i,s===m.id),e.jsx("span",{style:{flex:1},children:m.label}),h[m.id]!==void 0&&e.jsx("small",{style:{color:s===m.id?i.accent:i.textMuted},children:h[m.id]})]},m.id))]},l.label??`group-${u}`))})}function mo(t,n,s,o=!1){const i=t==="blocks"?ro:t==="diagram"?Ko:t==="skills"?hs:t==="notebooks"||t==="apps"?Gt:Xe;return e.jsx(i,{size:n,color:o?s.accent:s.textMuted})}function Fs(t){var n;return((n=lo.flatMap(s=>s.items).find(s=>s.id===t))==null?void 0:n.label)??t}function Vn(){if(typeof window>"u")return{domain:null,section:"diagram",modelAreaId:null,selectedId:null};let t=null;try{t=window.localStorage.getItem(ao)}catch{t=null}return To(window.location.href,t)}function Pt(t,n,s=!1,o=null,i=null){if(typeof window>"u")return;const r=Fo(window.location.href,{domain:t,section:n,modelAreaId:o,selectedId:i});s?window.history.replaceState(window.history.state,"",r):window.history.pushState(window.history.state,"",r);try{window.localStorage.setItem(ao,JSON.stringify({domain:t,section:n,modelAreaId:o,selectedId:i}))}catch{}}function Ws(t,n){const s=new Set,o=new Set;if(!n)return{modeling:t,ghostEntityIds:s,ghostRelationshipIds:o};const i={...t.entities},r={...t.relationships};for(const d of n.operations){if(d.kind!=="modeling_change")continue;const h=d.change;if(h.operation==="upsert_entity"){const y=`${h.value.domain}::entity::${h.value.id}`;s.add(y),i[y]={...i[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,domain:h.value.domain,dbtUniqueId:h.value.dbtModel,businessName:h.value.businessName,businessContext:h.value.businessContext,grain:h.value.grain,keys:h.value.keys??[],analyticalRole:h.value.analyticalRole,status:"draft",sourcePath:"(proposed)",identityFingerprint:`ghost:${y}`}}else if(h.operation==="upsert_relationship"){const y=`${h.value.domain}::relationship::${h.value.id}`;o.add(y),r[y]={...r[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,from:`${h.value.domain}::entity::${h.value.from}`,to:`${h.value.domain}::entity::${h.value.to}`,keys:h.value.keys,cardinality:h.value.cardinality,fanout:h.value.fanout,status:"draft",crossDomain:!1,ownerDomain:h.value.domain,verb:h.value.verb,description:h.value.description,rationale:h.value.rationale,sourcePath:"(proposed)",fingerprint:`ghost:${y}`,staleCertification:!1,automaticJoinAllowed:!1}}}return{modeling:{...t,entities:i,relationships:r},ghostEntityIds:s,ghostRelationshipIds:o}}function Hs(t){var o;const n=Object.keys(t.modeling.packages??{});return n.length===1?n[0]:(((o=t.dbtProvenance)==null?void 0:o.projectName)??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")||"analytics"}function nn(t,n){const s=Object.entries(t).find(([,o])=>o===n);return s?s[0]:n.qualifiedId??n.id}function Us({editor:t,data:n,selectedDomain:s,selectedArea:o,t:i,onClose:r,onProposal:d,onFixWithAi:h,onApplied:y}){var bn,jn,vn,Sn,wn,kn,Cn,In,Mn,zn,Dn,$n,Rn,Bn,An,Pn,Ln,Nn,On,_n,En;const l=t.kind==="relationship"?t.relationship:void 0,u=t.kind==="entity"?t.entity:void 0,m=t.kind==="area"?t.area:void 0,f=t.kind==="relationship"?t.draft:void 0,[c,x]=a.useState((m==null?void 0:m.domain)??(u==null?void 0:u.domain)??s??Object.keys(n.modeling.packages)[0]??Hs(n)),[I,v]=a.useState((m==null?void 0:m.localId)??((bn=n.modeling.areas[(u==null?void 0:u.areaId)??(l==null?void 0:l.areaId)??""])==null?void 0:bn.localId)??(o==null?void 0:o.localId)??so),[w,B]=a.useState((l==null?void 0:l.localId)??(u==null?void 0:u.localId)??(m==null?void 0:m.localId)??""),[b,S]=a.useState((l==null?void 0:l.owner)??(u==null?void 0:u.owner)??""),[P,q]=a.useState(""),[N,j]=a.useState(t.kind==="entity"?(u==null?void 0:u.dbtUniqueId)??t.dbtUniqueId??"":""),[E,C]=a.useState((u==null?void 0:u.businessName)??""),[O,M]=a.useState((u==null?void 0:u.businessContext)??""),[T,re]=a.useState(((jn=u==null?void 0:u.conceptRefs)==null?void 0:jn.join(", "))??""),[be,de]=a.useState((u==null?void 0:u.analyticalRole)??"unknown"),[k,D]=a.useState((u==null?void 0:u.status)??"draft"),[A,F]=a.useState((u==null?void 0:u.grain)??""),[U,V]=a.useState((u==null?void 0:u.keys.join(", "))??""),[K,ie]=a.useState((m==null?void 0:m.name)??""),[ce,De]=a.useState((m==null?void 0:m.description)??""),[ge,_e]=a.useState((m==null?void 0:m.intentExamples.join(", "))??""),[we,je]=a.useState((m==null?void 0:m.referencedEntityIds.map(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.localId)??p}).join(", "))??""),[H,Ce]=a.useState((l==null?void 0:l.from)??(f==null?void 0:f.from)??""),[R,oe]=a.useState((l==null?void 0:l.to)??(f==null?void 0:f.to)??""),[me,Ee]=a.useState((l==null?void 0:l.keys.map(p=>`${p.from}=${p.to}`).join(", "))??(f!=null&&f.fromColumn&&f.toColumn?`${f.fromColumn}=${f.toColumn}`:"")),[qe,wt]=a.useState((l==null?void 0:l.cardinality)??"unknown"),[ve,te]=a.useState((l==null?void 0:l.fanout)??"unknown"),[ue,pe]=a.useState((l==null?void 0:l.status)??"draft"),[nt,ke]=a.useState((l==null?void 0:l.verb)??""),[$e,ot]=a.useState((l==null?void 0:l.description)??""),[Te,Kt]=a.useState(((vn=l==null?void 0:l.roles)==null?void 0:vn.from)??""),[st,kt]=a.useState(((Sn=l==null?void 0:l.roles)==null?void 0:Sn.to)??""),[it,at]=a.useState(((wn=l==null?void 0:l.optionality)==null?void 0:wn.from)??"unknown"),[Se,Fe]=a.useState(((kn=l==null?void 0:l.optionality)==null?void 0:kn.to)??"unknown"),[Ct,It]=a.useState(((Cn=l==null?void 0:l.joinTypes)==null?void 0:Cn.join(", "))??"left"),[lt,Re]=a.useState(((In=l==null?void 0:l.aggregation)==null?void 0:In.measuresFrom.join(", "))??""),[We,rt]=a.useState(((Mn=l==null?void 0:l.aggregation)==null?void 0:Mn.dimensionsFrom.join(", "))??""),[Mt,Be]=a.useState(((zn=l==null?void 0:l.importRefs)==null?void 0:zn.join(", "))??""),[He,Q]=a.useState((l==null?void 0:l.attributionBlock)??""),[he,dt]=a.useState((l==null?void 0:l.evidenceExpiresAt)??""),[J,Ue]=a.useState(""),[Ke,zt]=a.useState(""),[Ye,Dt]=a.useState(""),[Ae,ct]=a.useState(""),[Pe,ut]=a.useState(""),[Ve,pt]=a.useState(""),[ht,g]=a.useState(""),[$,G]=a.useState(""),[Ie,Je]=a.useState(""),[$t,vo]=a.useState(""),[rn,So]=a.useState(""),[dn,wo]=a.useState(""),[cn,ko]=a.useState("internal"),[un,Co]=a.useState(""),[di,Io]=a.useState(null),[pn,Rt]=a.useState(!1),[hn,xt]=a.useState(null),[gt,mt]=a.useState(l==null?void 0:l.validation),[Le,Yt]=a.useState(null),[Vt,Mo]=a.useState({}),[xn,zo]=a.useState(!!(l&&(l.roles||l.aggregation||(Dn=l.importRefs)!=null&&Dn.length||l.attributionBlock||l.evidenceExpiresAt)));a.useEffect(()=>{t.kind!=="relationship"||l||w||!H||!R||B(`${H}_to_${R}`.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,l,H,R,w]),a.useEffect(()=>{var L;if(t.kind!=="entity"||w||!N)return;const p=(L=n.dbtProvenance.nodes[N])==null?void 0:L.name;p&&B(p.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,w,N,n.dbtProvenance.nodes]),a.useEffect(()=>{if(t.kind!=="entity"||!N){Yt(null);return}let p=!1;return X.getDbtModelingNode(N).then(L=>{var W,ee;p||(Yt(L),E||C(L.name.replace(/[_-]+/g," ").replace(/\b\w/g,Z=>Z.toUpperCase())),!A&&((W=L.dqlMeta)!=null&&W.grain)&&F(L.dqlMeta.grain),!U&&((ee=L.dqlMeta)!=null&&ee.keys.length)&&V(L.dqlMeta.keys.join(", ")))}).catch(()=>{p||Yt(null)}),()=>{p=!0}},[N,t.kind]),a.useEffect(()=>{if(t.kind!=="relationship")return;const L=[H,R].map(ee=>{var Z;return(Z=n.modeling.entities[ee])==null?void 0:Z.dbtUniqueId}).filter(ee=>!!ee).filter(ee=>!Vt[ee]);if(!L.length)return;let W=!1;return X.getDbtModelingNodes(L).then(({details:ee})=>{W||Mo(Z=>({...Z,...Object.fromEntries(ee.map(xe=>[xe.uniqueId,xe]))}))}).catch(()=>{}),()=>{W=!0}},[t.kind,H,R]);const Jt=()=>{if(t.kind==="domain")return{operation:"upsert_domain",value:{id:w,name:w,owner:b,parent:P||void 0,exports:[]}};if(t.kind==="area")return{operation:"upsert_area",value:{id:w,domain:c,name:K||w,description:ce||void 0,intentExamples:Y(ge),references:Y(we)}};if(t.kind==="entity")return{operation:"upsert_entity",value:{id:w,domain:c,dbtModel:N,areaId:I||void 0,businessName:E||void 0,businessContext:O||void 0,conceptRefs:Y(T),analyticalRole:be,status:k,owner:b||void 0,grain:A||void 0,keys:Y(U)}};if(t.kind==="contract")return{operation:"upsert_contract",value:{id:w,domain:c,entities:Y(J),blocks:Y(Ke),status:"draft",owner:b,requiredEvaluation:!0,purpose:Ye||void 0,metricRefs:Y(Ae),dimensions:Y(Pe),allowedFilters:Y(Ve),requiredFilters:Y(ht),evaluationRefs:Y($)}};if(t.kind==="export")return{operation:"upsert_export",value:{id:w,domain:c,entity:Ie||void 0,metrics:Y(Ae),blocks:Y(Ke),allowedKeys:Y($t),allowedDimensions:Y(Pe),allowedFilters:Y(Ve),purposes:Y(rn),consumerDomains:Y(dn),classification:cn||void 0,status:ue,owner:b||void 0}};if(t.kind==="import")return{operation:"upsert_import",value:{id:w||void 0,domain:c,exportRef:un,purpose:Ye,status:ue,owner:b||void 0}};const p=li(me),W=!l||l.from===H&&l.to===R&&JSON.stringify(l.keys)===JSON.stringify(p)&&l.cardinality===qe&&l.fanout===ve?gt:void 0,ee=ue==="certified"&&(W==null?void 0:W.status)!=="passed"?"reviewed":ue,Z=n.modeling.entities[H],xe=n.modeling.entities[R];return{operation:"upsert_relationship",value:{id:w,domain:c,areaId:I||void 0,from:H,to:R,keys:p,cardinality:qe,fanout:ve,status:ee,owner:b||void 0,ownerDomain:c,verb:nt||void 0,description:$e||void 0,roles:Te||st?{from:Te||void 0,to:st||void 0}:void 0,optionality:{from:it,to:Se},joinTypes:Y(Ct),aggregation:lt||We?{measuresFrom:Y(lt),dimensionsFrom:Y(We),requiresPreAggregation:ve!=="safe"}:void 0,attributionBlock:He||void 0,importRefs:Y(Mt),evidenceExpiresAt:he||void 0,crossDomain:(Z==null?void 0:Z.domain)!==(xe==null?void 0:xe.domain),validation:W,certifiedAgainst:ee==="certified"&&(Z!=null&&Z.grain)&&(xe!=null&&xe.grain)?{from:{grain:Z.grain,keys:Z.keys},to:{grain:xe.grain,keys:xe.keys}}:void 0}}},Do=async()=>{try{Rt(!0),xt(null);const p=Jt();if(Io(p),Tn(p,u,m)){const W=await X.previewModelingChange(p,n.snapshotId);await X.applyModelingChange(p,W.fingerprint,n.snapshotId),await y(p);return}const L=await X.createContextProposal({origin:"manual",expectedSnapshotId:n.snapshotId,operations:[{id:`manual:${p.operation}:${w||Date.now().toString(36)}`,kind:"modeling_change",change:p,evidence:["manual Modeling workspace authoring"]}]});d(L)}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},$o=async()=>{try{Rt(!0),xt(null);const p=Jt();if(p.operation!=="upsert_relationship")return;const L=await X.validateModelingRelationship(p.value,n.snapshotId);mt(L),xt(L.status==="passed"?"Warehouse proof passed. Preview the source change to save it.":L.message??"Validation failed.")}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},gn=Object.entries(n.modeling.entities).map(([p,L])=>{const W=n.dbtProvenance.nodes[L.dbtUniqueId];return{value:p,label:L.businessName||L.localId||L.id,description:`${L.domain} · ${(W==null?void 0:W.relation)??(W==null?void 0:W.name)??L.dbtUniqueId}`,keywords:[L.qualifiedId,L.businessContext??"",L.analyticalRole??""]}}),Ne=Vt[(($n=n.modeling.entities[H])==null?void 0:$n.dbtUniqueId)??""],Oe=Vt[((Rn=n.modeling.entities[R])==null?void 0:Rn.dbtUniqueId)??""],mn=((Ne==null?void 0:Ne.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),fn=((Oe==null?void 0:Oe.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),Bt=mn.map(p=>p.value).filter(p=>fn.some(L=>L.value.toLowerCase()===p.toLowerCase())).slice(0,5),Me=me?me.split(",").map(p=>{const[L="",W=""]=p.split("=").map(ee=>ee.trim());return{from:L,to:W}}):[{from:"",to:""}],yn=(p,L,W)=>{const ee=Me.map((Z,xe)=>xe===p?{...Z,[L]:W}:Z);Ee(ee.map(Z=>`${Z.from}=${Z.to}`).join(", ")),mt(void 0)},Ro=p=>{const L=Me.filter((W,ee)=>ee!==p);Ee(L.map(W=>`${W.from}=${W.to}`).join(", ")),mt(void 0)},Bo=()=>Ee([...Me.filter(p=>p.from||p.to),{from:"",to:""}].map(p=>`${p.from}=${p.to}`).join(", ")),Qt=t.kind==="entity"?!!(c&&w&&N):t.kind==="relationship"?!!(c&&w&&H&&R&&Me.some(p=>p.from&&p.to)&&Me.every(p=>p.from&&p.to)):!0,Ao=(()=>{if(!Qt)return!1;try{return Tn(Jt(),u,m)}catch{return!1}})(),Po=t.kind==="domain"?"Create Domain Package":t.kind==="area"?m?"Edit subject area":"Create subject area":t.kind==="entity"?u?"Edit business entity":"Add dbt model":t.kind==="contract"?"Create analytical contract":t.kind==="export"?"Publish domain export":t.kind==="import"?"Request domain import":l?"Edit relationship":"Create relationship";return e.jsx(yo,{title:Po,t:i,onClose:r,children:e.jsxs("div",{style:{display:"grid",gap:12},children:[t.kind!=="domain"&&e.jsx(z,{label:"Domain",children:e.jsx(ae,{value:c,onChange:x,values:Object.keys(n.modeling.packages),t:i})}),t.kind!=="relationship"&&e.jsx(z,{label:t.kind==="entity"?"Entity id":t.kind==="area"?"Area id":t.kind==="contract"?"Contract id":t.kind==="export"?"Export id":t.kind==="import"?"Import id (optional)":"Domain id",children:e.jsx(_,{value:w,onChange:B,t:i,placeholder:"stable_snake_case_id"})}),t.kind==="domain"&&e.jsx(z,{label:"Parent domain (optional)",children:e.jsx(ae,{value:P,onChange:q,values:Object.keys(n.modeling.packages),t:i})}),t.kind==="area"&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{text:"A subject area is one small, reviewable source file — a focused diagram inside this Domain. It filters the same domain graph; it never creates a competing semantic model and never changes what an agent is allowed to use.",t:i}),e.jsx(z,{label:"Area name",children:e.jsx(_,{value:K,onChange:ie,t:i,placeholder:"Customer lifecycle"})}),e.jsx(z,{label:"Business question or scope",children:e.jsx(_,{value:ce,onChange:De,t:i,placeholder:"How customers progress from first order to repeat purchase."})}),e.jsx(z,{label:"Example questions (comma-separated)",children:e.jsx(_,{value:ge,onChange:_e,t:i,placeholder:"Which customers made a second purchase?"})}),e.jsx(z,{label:"Read-only boundary entities (comma-separated)",children:e.jsx(_,{value:we,onChange:je,t:i,placeholder:"customer"})})]}),t.kind==="entity"&&e.jsxs(e.Fragment,{children:[e.jsx(Xn,{current:N?2:1,labels:["Find dbt model","Add business meaning","Review source change"],t:i}),e.jsx(fe,{text:"Search by model name, relation, or source path. Results stay bounded even when the dbt project has thousands of models.",t:i}),e.jsx(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsx(z,{label:"dbt model",children:e.jsx(oi,{value:N,onChange:j,selectedNode:n.dbtProvenance.nodes[N],domain:c,t:i})}),Le&&e.jsx(eo,{title:Le.name,detail:`${Le.relation??Le.uniqueId} · ${Le.columns.length} columns${(Bn=Le.dqlMeta)!=null&&Bn.grain?` · grain: ${Le.dqlMeta.grain}`:""}`,t:i}),e.jsx(z,{label:"Business name",children:e.jsx(_,{value:E,onChange:C,t:i,placeholder:"Customer order"})}),e.jsx(z,{label:"Business context",children:e.jsx(_,{value:O,onChange:M,t:i,placeholder:"One order used to understand repeat purchasing and revenue."})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business concepts",children:e.jsx(_,{value:T,onChange:re,t:i,placeholder:"customer_lifecycle, revenue"})}),e.jsx(z,{label:"Analytical role",children:e.jsx(ae,{value:be,onChange:p=>de(p),values:["event","dimension","snapshot","bridge","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Grain override (optional)",children:e.jsx(_,{value:A,onChange:F,t:i,placeholder:"Use dbt meta.dql by default"})}),e.jsx(z,{label:"Key overrides (optional)",children:e.jsx(_,{value:U,onChange:V,t:i,placeholder:"customer_id, order_id"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:k==="review"?"reviewed":k,onChange:p=>D(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),t.kind==="relationship"&&e.jsxs(e.Fragment,{children:[e.jsx(Xn,{current:!H||!R?1:Me.some(p=>p.from&&p.to)?3:2,labels:["Choose models","Match join keys","Review policy"],t:i}),e.jsx(fe,{text:"Search business names or dbt relations, then match columns from only those two models. DQL keeps the relationship in draft until warehouse validation passes.",t:i}),e.jsx(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From entity",children:e.jsx(Nt,{ariaLabel:"From entity",value:H,onChange:p=>{Ce(p),mt(void 0)},options:gn,placeholder:"Search source model…",t:i})}),e.jsx(z,{label:"To entity",children:e.jsx(Nt,{ariaLabel:"To entity",value:R,onChange:p=>{oe(p),mt(void 0)},options:gn.filter(p=>p.value!==H),placeholder:"Search target model…",t:i})})]}),H&&R&&e.jsx(eo,{title:`${((An=n.modeling.entities[H])==null?void 0:An.businessName)||((Pn=n.modeling.entities[H])==null?void 0:Pn.localId)} → ${((Ln=n.modeling.entities[R])==null?void 0:Ln.businessName)||((Nn=n.modeling.entities[R])==null?void 0:Nn.localId)}`,detail:`${(Ne==null?void 0:Ne.columns.length)??0} source columns · ${(Oe==null?void 0:Oe.columns.length)??0} target columns`,t:i}),e.jsx(z,{label:"Join keys",children:e.jsxs("div",{style:{display:"grid",gap:8},children:[Bt.length>0&&!Me.some(p=>p.from&&p.to)&&e.jsxs("button",{type:"button",onClick:()=>Ee(`${Bt[0]}=${Bt[0]}`),style:{...Ze(i),justifySelf:"start"},children:[e.jsx(Ht,{size:13})," Use exact match: ",Bt[0]]}),Me.map((p,L)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) 24px minmax(0, 1fr) 30px",gap:7,alignItems:"center"},children:[e.jsx(Nt,{ariaLabel:`Source join column ${L+1}`,value:p.from,onChange:W=>yn(L,"from",W),options:mn,placeholder:H?"Source column…":"Choose source first",disabled:!H||!Ne,t:i}),e.jsx("span",{"aria-hidden":"true",style:{color:i.textMuted,textAlign:"center"},children:"→"}),e.jsx(Nt,{ariaLabel:`Target join column ${L+1}`,value:p.to,onChange:W=>yn(L,"to",W),options:fn,placeholder:R?"Target column…":"Choose target first",disabled:!R||!Oe,t:i}),e.jsx("button",{type:"button","aria-label":"Remove join key",title:"Remove join key",onClick:()=>Ro(L),style:ze(i),children:e.jsx(tt,{size:14})})]},`${L}:${p.from}:${p.to}`)),e.jsxs("button",{type:"button",onClick:Bo,style:{...Ze(i),justifySelf:"start"},children:[e.jsx(et,{size:13})," Add key pair"]})]})}),w&&e.jsxs("div",{style:{color:i.textMuted,fontSize:9.5},children:["Relationship id: ",e.jsx("code",{children:w})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Cardinality",children:e.jsx(ae,{value:qe,onChange:p=>wt(p),values:["unknown","one_to_one","one_to_many","many_to_one","many_to_many"],t:i})}),e.jsx(z,{label:"Fanout policy",children:e.jsx(ae,{value:ve==="unsafe"?"forbidden":ve,onChange:p=>te(p),values:["safe","dedupe_required","attribution_required","forbidden","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business verb (optional)",children:e.jsx(_,{value:nt,onChange:ke,t:i,placeholder:"belongs to"})}),e.jsx(z,{label:"Description (optional)",children:e.jsx(_,{value:$e,onChange:ot,t:i,placeholder:"Why this relationship exists"})})]}),H&&R&&((On=n.modeling.entities[H])==null?void 0:On.domain)!==((_n=n.modeling.entities[R])==null?void 0:_n.domain)&&e.jsx(fe,{text:"This is a cross-domain relationship. Add the approved provider import in Advanced governance before certification.",t:i}),e.jsx("button",{type:"button",onClick:()=>zo(p=>!p),style:{...Ze(i),justifySelf:"start",padding:"6px 0"},children:xn?"Hide advanced governance":"Advanced governance and aggregation"}),xn&&e.jsxs("div",{style:{display:"grid",gap:12,padding:12,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg},children:[e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed join types",children:e.jsx(_,{value:Ct,onChange:It,t:i,placeholder:"left, inner"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From role",children:e.jsx(_,{value:Te,onChange:Kt,t:i})}),e.jsx(z,{label:"To role",children:e.jsx(_,{value:st,onChange:kt,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From optionality",children:e.jsx(ae,{value:it,onChange:p=>at(p),values:["required","optional","unknown"],t:i})}),e.jsx(z,{label:"To optionality",children:e.jsx(ae,{value:Se,onChange:p=>Fe(p),values:["required","optional","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Measures allowed from",children:e.jsx(_,{value:lt,onChange:Re,t:i,placeholder:"order"})}),e.jsx(z,{label:"Dimensions allowed from",children:e.jsx(_,{value:We,onChange:rt,t:i,placeholder:"customer"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Required import refs",children:e.jsx(_,{value:Mt,onChange:Be,t:i,placeholder:"commerce.customer@1"})}),e.jsx(z,{label:"Attribution block",children:e.jsx(_,{value:He,onChange:Q,t:i,placeholder:"growth.revenue_by_channel"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Evidence expires",children:e.jsx(_,{value:he,onChange:dt,t:i,placeholder:"2026-12-31"})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),gt&&e.jsx(fo,{evidence:gt,t:i,onFixWithAi:gt.status==="failed"?()=>h(l?nn(n.modeling.relationships,l):null,gt):void 0})]}),t.kind==="contract"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Covered entities",children:e.jsx(_,{value:J,onChange:Ue,t:i,placeholder:"order, customer"})}),e.jsx(z,{label:"Certified blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i,placeholder:"orders_360"})}),e.jsx(z,{label:"Decision purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue reporting"})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsx(z,{label:"Required filters",children:e.jsx(_,{value:ht,onChange:g,t:i})})]}),e.jsx(z,{label:"Evaluation refs",children:e.jsx(_,{value:$,onChange:G,t:i,placeholder:"revenue_accuracy"})})]}),t.kind==="export"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Exported entity",children:e.jsx(ae,{value:Ie,onChange:Je,values:Object.keys(n.modeling.entities).filter(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.domain)===c}),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed keys",children:e.jsx(_,{value:$t,onChange:vo,t:i})}),e.jsx(z,{label:"Allowed dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i})})]}),e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Approved purposes",children:e.jsx(_,{value:rn,onChange:So,t:i,placeholder:"revenue reporting"})}),e.jsx(z,{label:"Consumer domains",children:e.jsx(_,{value:dn,onChange:wo,t:i,placeholder:"growth"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Classification",children:e.jsx(_,{value:cn,onChange:ko,t:i})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]})]}),t.kind==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Provider export",children:e.jsx(ae,{value:un,onChange:Co,values:Object.values(((En=n.modeling.interfaces)==null?void 0:En.exports)??{}).map(p=>`${p.domain}.${p.localId}@${p.version}`),t:i})}),e.jsx(z,{label:"Exact analytical purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue by acquisition channel"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),t.kind!=="entity"&&t.kind!=="relationship"&&t.kind!=="area"&&e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})}),hn&&e.jsx(fe,{text:hn,t:i}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[t.kind==="relationship"&&e.jsxs(se,{t:i,onClick:()=>void $o(),disabled:pn||!Qt,children:[e.jsx(Qo,{size:14})," Validate in warehouse"]}),e.jsx(se,{primary:!0,t:i,onClick:()=>void Do(),disabled:pn||!Qt,children:Ao?"Save":"Preview source change"})]})]})})}function Ks({search:t,onSearch:n,items:s,onPick:o,t:i}){var f;const[r,d]=a.useState(!1),h=a.useRef(null),y=t.trim().toLowerCase(),l=y?s.filter(c=>c.label.toLowerCase().includes(y)||c.sublabel.toLowerCase().includes(y)).sort((c,x)=>c.type===x.type?c.label.localeCompare(x.label):c.type==="model"?-1:1).slice(0,14):[],u=c=>c==="dimension"?"var(--status-success)":c==="bridge"?"var(--status-warning)":c==="event"||c==="snapshot"?"var(--accent)":"var(--text-tertiary)",m=r&&y?(f=h.current)==null?void 0:f.getBoundingClientRect():void 0;return e.jsxs("label",{ref:h,style:{position:"relative",width:210,flex:"0 0 210px"},children:[e.jsx(Ft,{size:12,style:{position:"absolute",left:7,top:8,color:i.textMuted}}),e.jsx("input",{"aria-label":"Search diagram",value:t,onChange:c=>{n(c.target.value),d(!0)},onFocus:()=>d(!0),placeholder:"Find model or column",style:{...ye(i),padding:"6px 7px 6px 24px"}}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>d(!1),style:{position:"fixed",inset:0,zIndex:60}}),e.jsx("div",{style:{position:"fixed",top:m.bottom+5,left:m.left,zIndex:61,width:300,maxHeight:340,overflow:"auto",background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:9,boxShadow:"0 12px 30px rgba(26,26,26,0.16)",padding:4},children:l.length===0?e.jsx("div",{style:{padding:"10px 10px",fontSize:11.5,color:i.textMuted,fontFamily:i.font},children:"No matching model or column."}):l.map((c,x)=>e.jsxs("button",{type:"button",onMouseDown:I=>{I.preventDefault(),o(c.recordKey),d(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"7px 8px",border:"none",borderRadius:6,background:"transparent",cursor:"pointer",fontFamily:i.font},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:999,background:u(c.role),flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:c.type==="model"?650:500,color:i.textPrimary,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.label}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:i.textMuted},children:c.type==="model"?"model":c.sublabel})]},`${c.type}-${c.recordKey}-${c.label}-${x}`))})]})]})}function Ys({modelingView:t,columnMode:n,search:s,layoutMode:o,density:i,visibleLimit:r,dimUnrelated:d,showEdgeLabels:h,showLegend:y,fullscreen:l,aiOpen:u,onBindModel:m,onRelationship:f,onToggleAi:c,onModelingView:x,onColumnMode:I,onSearch:v,searchItems:w,onPickModel:B,onLayoutMode:b,onDensity:S,onVisibleLimit:P,onDimUnrelated:q,onEdgeLabels:N,onLegend:j,onFullscreen:E,onExport:C,onReset:O,t:M}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:50,padding:"0 10px",borderBottom:`1px solid ${M.headerBorder}`,background:M.headerBg,flexWrap:"nowrap",overflowX:"auto",scrollbarWidth:"thin"},children:[e.jsxs("div",{role:"group","aria-label":"Modeling view",style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${M.headerBorder}`,borderRadius:7,background:M.appBg,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>x("business"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="business"?"var(--accent-dim)":"transparent",color:t==="business"?M.accent:M.textMuted},children:"Business modeling"}),e.jsx("button",{type:"button",onClick:()=>x("data"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="data"?"var(--accent-dim)":"transparent",color:t==="data"?M.accent:M.textMuted},children:"Data modeling"})]}),e.jsx(Ks,{search:s,onSearch:v,items:w,onPick:B,t:M}),e.jsxs("button",{type:"button",onClick:m,style:Ge(M,!0),children:[e.jsx(et,{size:13})," Add models"]}),e.jsxs("button",{type:"button",onClick:f,style:Ge(M),children:[e.jsx(Ot,{size:13})," Connect"]}),e.jsxs("button",{type:"button","aria-pressed":u,onClick:c,style:{...Ge(M),...u?{borderColor:M.accent,color:M.accent,background:"var(--accent-dim)"}:{}},children:[e.jsx(Ht,{size:13})," Build with AI"]}),e.jsxs("details",{style:{position:"relative",flexShrink:0},children:[e.jsxs("summary",{style:{...Ge(M),listStyle:"none"},children:[e.jsx(xs,{size:13})," View"]}),e.jsxs("div",{role:"group","aria-label":"Modeling view options",style:{position:"fixed",zIndex:70,width:250,marginTop:6,right:12,padding:10,display:"grid",gap:9,border:`1px solid ${M.headerBorder}`,borderRadius:9,background:M.cellBg,boxShadow:"0 14px 34px rgba(0,0,0,.18)"},children:[t==="data"&&e.jsxs("label",{style:Lt(M),children:[e.jsxs("span",{children:[e.jsx(fs,{size:13})," Columns"]}),e.jsxs("select",{"aria-label":"Visible columns",value:n,onChange:T=>I(T.target.value),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"keys",children:"Keys only"}),e.jsx("option",{value:"relevant",children:"Relevant"}),e.jsx("option",{value:"all",children:"All columns"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Layout"}),e.jsxs("select",{"aria-label":"Diagram layout",value:o,onChange:T=>{b(T.target.value),O()},style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"grid",children:"Grid"}),e.jsx("option",{value:"star",children:"Star"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Density"}),e.jsxs("select",{"aria-label":"Diagram density",value:i,onChange:T=>S(T.target.value),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:"compact",children:"Compact"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"wide",children:"Wide"})]})]}),e.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Canvas"}),e.jsxs("select",{"aria-label":"Visible model limit",value:r||50,onChange:T=>P(Number(T.target.value)),style:{...ye(M),width:108,padding:"5px 6px"},children:[e.jsx("option",{value:25,children:"25 models"}),e.jsx("option",{value:50,children:"50 models"}),e.jsx("option",{value:100,children:"100 models"}),e.jsx("option",{value:200,children:"200 max"})]})]}),e.jsxs("button",{type:"button",onClick:()=>q(!d),style:Qe(M,d),children:[e.jsx(Yo,{size:14})," Dim unrelated models"]}),e.jsxs("button",{type:"button",onClick:()=>N(!h),style:Qe(M,h),children:[e.jsx(Ot,{size:14})," Relationship labels"]}),e.jsxs("button",{type:"button",onClick:()=>j(!y),style:Qe(M,y),children:[e.jsx(Xe,{size:14})," Relationship legend"]}),e.jsxs("button",{type:"button",onClick:C,style:Qe(M),children:[e.jsx(Vo,{size:14})," Export SVG"]}),e.jsxs("button",{type:"button",onClick:E,style:Qe(M,l),children:[l?e.jsx(tt,{size:14}):e.jsx(co,{size:14})," ",l?"Exit fullscreen":"Fullscreen"]}),e.jsxs("button",{type:"button",onClick:O,style:Qe(M),children:[e.jsx(gs,{size:14})," Reset layout"]})]})]})]})}const Lt=t=>({display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:t.textSecondary,fontSize:10.5}),Qe=(t,n=!1)=>({border:"none",borderRadius:6,padding:"6px 7px",display:"flex",alignItems:"center",gap:7,background:n?"var(--accent-dim)":"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,textAlign:"left",cursor:"pointer"});function Vs({t}){return e.jsxs("div",{style:{display:"flex",gap:14,padding:"7px 12px",borderBottom:`1px solid ${t.headerBorder}`,background:t.headerBg,color:t.textSecondary,fontSize:9.5},children:[[["Safe certified","#2e9b63"],["Validated review","#5b73d6"],["Attribution / draft","#9a6b2f"],["Stale certification","#d47822"]].map(([n,s])=>e.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center"},children:[e.jsx("i",{style:{display:"inline-block",width:18,height:3,background:s,borderRadius:2}}),n]},n)),e.jsx("span",{style:{marginLeft:"auto"},children:"1:1 · 1:N · N:1 · N:N"})]})}function Js({t,connectedModels:n,onDbt:s,onYaml:o,onManual:i}){const r=[{icon:e.jsx(Xe,{size:20}),title:"Use connected dbt",detail:`${n} model${n===1?"":"s"} available. Search, multi-select, confirm where they belong, then review the bindings.`,action:s},{icon:e.jsx(an,{size:20}),title:"Import modeling YAML",detail:"Discover DQL modeling or dbt YAML from this project, a safe local path, an upload, or pasted content. Relationships declared in dbt tests come across as draft edges.",action:o},{icon:e.jsx(et,{size:20}),title:"Start manually",detail:"Create one model binding or relationship with guided review.",action:i}];return e.jsx("div",{style:{height:"100%",display:"grid",placeItems:"center",padding:28},children:e.jsxs("div",{style:{width:"min(840px, 100%)"},children:[e.jsxs("div",{style:{textAlign:"center",marginBottom:18},children:[e.jsx("h2",{style:{margin:0,fontSize:18},children:"Start modeling domain context"}),e.jsx("p",{style:{margin:"7px 0 0",color:t.textMuted,fontSize:11.5},children:"Choose the source you already have. Every path creates the same write-free proposal before a draft can be saved."})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:r.map(d=>e.jsxs("button",{type:"button",onClick:d.action,style:{...Tt(t),minHeight:150,textAlign:"left",cursor:"pointer"},children:[e.jsx("span",{style:{width:38,height:38,borderRadius:9,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--accent-dim)",color:t.accent},children:d.icon}),e.jsx("b",{style:{display:"block",marginTop:12},children:d.title}),e.jsx("span",{style:{display:"block",marginTop:6,color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:d.detail})]},d.title))})]})})}function Qs(){const t=document.querySelector("#dql-modeling-diagram .react-flow__renderer");if(!(t instanceof HTMLElement))return;const n=t.cloneNode(!0),s=t.getBoundingClientRect(),o=new XMLSerializer().serializeToString(n),i=`<svg xmlns="http://www.w3.org/2000/svg" width="${Math.ceil(s.width)}" height="${Math.ceil(s.height)}"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">${o}</div></foreignObject></svg>`,r=URL.createObjectURL(new Blob([i],{type:"image/svg+xml"})),d=document.createElement("a");d.href=r,d.download="dql-domain-model.svg",d.click(),URL.revokeObjectURL(r)}function Gs({data:t,domain:n,t:s}){var m,f;const{state:o,dispatch:i}=Wt(),[r,d]=a.useState(null),[h,y]=a.useState(null),l=[...new Set(n?((f=(m=t.domainAssets)==null?void 0:m[n])==null?void 0:f.blocks)??[]:Object.values(t.domainAssets??{}).flatMap(c=>c.blocks??[]))].sort(),u=async c=>{d(c),y(null);try{if(n)try{window.localStorage.setItem("dql.block-studio.domain",n)}catch{}const x=o.files.find(v=>v.path===c)??{name:c.split("/").at(-1)??c,path:c,type:"block",folder:c.split("/").slice(0,-1).join("/")};o.files.some(v=>v.path===c)||i({type:"FILE_ADDED",file:x});const I=await X.openBlockStudio(c);i({type:"OPEN_BLOCK_STUDIO",file:x,payload:I})}catch(x){y(x instanceof Error?x.message:String(x))}finally{d(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{title:"Blocks",detail:n?`Reusable blocks owned by ${n}. Select one to open the exact source in Block Studio.`:"All reusable blocks grouped across the current Domain Packages. Select one to open the exact source in Block Studio.",t:s}),h?e.jsx(fe,{text:h,t:s}):null,l.length?e.jsx("div",{style:{display:"grid",gap:10},children:l.map(c=>{var v;const x=(c.split("/").at(-1)??c).replace(/\.dql$/i,""),I=(v=Object.entries(t.domainAssets??{}).find(([,w])=>{var B;return(B=w.blocks)==null?void 0:B.includes(c)}))==null?void 0:v[0];return e.jsxs("button",{type:"button",onClick:()=>void u(c),"aria-label":`Open block ${x}`,style:{...Tt(s),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(ro,{size:14,color:s.accent}),e.jsx("b",{children:x}),n?null:e.jsx(qt,{t:s,children:I??"shared"}),r===c?e.jsx(qt,{t:s,children:"Opening…"}):null]}),e.jsx("code",{style:{display:"block",marginTop:7,color:s.textMuted,fontSize:10},children:c})]},c)})}):e.jsx(on,{title:"No domain blocks yet",detail:"Create a block in Block Studio and assign this domain to make it appear here.",t:s})]})}function Jn({data:t,domain:n,kind:s,t:o}){var w,B;const{state:i,dispatch:r}=Wt(),[d,h]=a.useState([]),[y,l]=a.useState(!0),[u,m]=a.useState(null),[f,c]=a.useState(null);a.useEffect(()=>{let b=!0;return l(!0),(n?X.getRelatedDomainProducts(n):X.getAllRelatedDomainProducts()).then(S=>{b&&h(S[s])}).catch(()=>{b&&h([])}).finally(()=>{b&&l(!1)}),()=>{b=!1}},[n,s]);const x=n?((B=(w=t.domainAssets)==null?void 0:w[n])==null?void 0:B[s])??[]:Object.values(t.domainAssets??{}).flatMap(b=>b[s]??[]),I=s==="notebooks"?"Notebooks":"Apps",v=async b=>{const S=String(b.id??b.filePath??b.title??b.name??"product");m(S),c(null);try{if(s==="apps"){const E=String(b.id??Qn(String(b.filePath??"")));if(!E)throw new Error("This App has no stable id to open.");r({type:"OPEN_APP",appId:E,experience:"view",section:"dashboards"});return}const P=String(b.filePath??"");if(!P)throw new Error("This Notebook has no source path to open.");const q=i.files.find(E=>E.path===P)??{name:P.split("/").at(-1)??String(b.title??S),path:P,type:"notebook",folder:P.split("/").slice(0,-1).join("/"),...typeof b.ownerDomain=="string"?{ownerDomain:b.ownerDomain}:{},usesDomains:Array.isArray(b.usesDomains)?b.usesDomains.map(String):[]};i.files.some(E=>E.path===P)||r({type:"FILE_ADDED",file:q});const{content:N}=await X.readNotebook(P),j=Go(P,N);r({type:"OPEN_FILE",file:q,cells:j.cells,title:j.title,metadata:j.metadata})}catch(P){c(P instanceof Error?P.message:String(P))}finally{m(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{title:n?`Related ${I}`:`All ${I}`,detail:n?`${I} are global shared products related to ${n}. This backlink does not create a second copy inside the Domain Package.`:`All global ${I.toLowerCase()} across Domain Packages. Select a domain above to narrow by owner/uses-domain metadata.`,t:o}),f?e.jsx(fe,{text:f,t:o}):null,y?e.jsx(on,{title:`Loading related ${I.toLowerCase()}…`,detail:"Resolving global product backlinks from the compiled project snapshot.",t:o}):d.length?e.jsx("div",{style:{display:"grid",gap:10},children:d.map(b=>{const S=String(b.id??b.filePath??b.title??"product"),P=Array.isArray(b.usesDomains)?b.usesDomains.map(String):[],q=String(b.name??b.title??S);return e.jsxs("button",{type:"button",onClick:()=>void v(b),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${q}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("b",{children:q}),b.lifecycle?e.jsx(qt,{t:o,children:String(b.lifecycle)}):null,u===S?e.jsx(qt,{t:o,children:"Opening…"}):null]}),e.jsx("p",{style:{color:o.textSecondary,fontSize:11,margin:"7px 0 0"},children:String(b.purpose??"No analytical purpose declared yet.")}),e.jsx("code",{style:{display:"block",marginTop:7,color:o.textMuted,fontSize:10},children:String(b.filePath??"")}),e.jsxs("div",{style:{marginTop:7,color:o.textMuted,fontSize:10},children:["Owner: ",String(b.ownerDomain??"Shared")," · Uses: ",P.join(", ")||"none declared"]})]},S)})}):x.length?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsx(fe,{text:"These paths use the legacy domain-local layout. They remain readable during migration, but new products should be global and declare ownerDomain / usesDomains.",t:o}),x.map(b=>e.jsxs("button",{type:"button",onClick:()=>void v({id:s==="apps"?Qn(b):b,filePath:b}),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${b}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("code",{style:{color:o.textPrimary,fontSize:11},children:b})]}),e.jsx("p",{style:{color:o.textMuted,fontSize:10,margin:"7px 0 0"},children:"Legacy backlink · migrate without duplicating the product."})]},b))]}):e.jsx(on,{title:`No related ${I.toLowerCase()} yet`,detail:`Create the ${s==="notebooks"?"notebook":"app"} from the global ${I} surface, then declare this domain in its product context to make the backlink appear here.`,t:o})]})}function Qn(t){const n=t.replace(/\\/g,"/").split("/").filter(Boolean),s=n.indexOf("apps");return s>=0?n[s+1]??"":""}function Zs({domain:t,areaId:n,selectedId:s,data:o,themeMode:i,t:r,correction:d,onClose:h,onCorrectionStarted:y,onReviewProposal:l,onPreviewProposal:u,onOpenSkills:m,onDraftRelationship:f}){const{threadId:c,onThreadIdChange:x}=rs(Jo(t)),I=s?o.modeling.relationships[s]:void 0,v=s?o.modeling.entities[s]:void 0,w=n?o.modeling.areas[n]:void 0,B=I?{kind:"relationship",id:I.qualifiedId,title:I.id}:v?{kind:"model",id:v.qualifiedId,title:v.businessName||v.id}:w?{kind:"model_area",id:w.qualifiedId,title:w.name}:t?{kind:"domain",id:t,title:t}:{kind:"workspace",title:"New modeling draft"},[b,S]=a.useState(null),P=N=>{const j=N.payload;(j==null?void 0:j.version)===1&&j.trustState==="review_required"&&(S(j),u(j))},q=()=>{S(null),u(null)};return a.useEffect(()=>()=>u(null),[]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderBottom:`1px solid ${r.headerBorder}`},children:[e.jsx(Ht,{size:14,color:r.accent}),e.jsx("strong",{style:{fontSize:12},children:"Build with AI"}),e.jsx("span",{style:{marginLeft:"auto"}}),e.jsx("button",{type:"button",onClick:m,style:Ze(r),children:"Skills"}),e.jsx("button",{type:"button",onClick:f,style:Ze(r),children:"Connect manually"}),e.jsx("button",{type:"button","aria-label":"Close Modeling AI",onClick:h,style:{...ze(r),width:26,height:26},children:e.jsx(tt,{size:14})})]}),e.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${r.headerBorder}`,color:r.textMuted,fontSize:10.5,lineHeight:1.5},children:[t??"new domain",n?` · ${n}`:"",s?` · focused: ${s}`:""," · ",Object.keys(o.modeling.entities).length," models · ",Object.keys(o.modeling.relationships).length," relationships. Proposals are drafts: nothing is written, certified, or joinable until you save and validate it."]}),b?e.jsxs("div",{role:"status",style:{margin:"10px 12px 0",padding:"10px 11px",border:"1px solid var(--accent)",borderRadius:9,background:"var(--accent-dim)",fontSize:11,lineHeight:1.5},children:[e.jsx("strong",{style:{display:"block",fontSize:11.5},children:"Previewing on the canvas"}),e.jsxs("span",{style:{color:r.textSecondary},children:[b.impact.modelingChanges," modeling change",b.impact.modelingChanges===1?"":"s"," shown as dashed outlines. Nothing is saved yet."]}),e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9},children:[e.jsx("button",{type:"button",onClick:()=>{l(b)},style:{...Ge(r,!0),minHeight:27},children:"Review exact changes"}),e.jsx("button",{type:"button",onClick:q,style:{...Ge(r),minHeight:27},children:"Discard"})]})]}):null,e.jsx("div",{style:{flex:1,minHeight:0,margin:"10px 12px 12px",border:`1px solid ${r.headerBorder}`,borderRadius:10,overflow:"hidden"},children:e.jsx(ds,{themeMode:i,title:"Modeling AI",scopeHint:"Modeling proposal · metadata only · explicit draft save",composerPlaceholder:"Describe the model you want…",initialMode:"modeling",selectedObject:B,workspaceContext:{surface:"modeling",domain:t,modelAreaId:n,snapshotId:o.snapshotId,focusedObjectId:s,providerSafety:"no_query_rows",...d?{correction:!0,validationReceipt:d.evidence}:{}},threadId:c,onThreadIdChange:x,autoRun:d?{text:d.text,mode:"modeling",nonce:d.nonce}:void 0,onRunningChange:N=>{N&&d&&y()},onReviewAuthoringProposal:N=>P(N),emptyHint:"Describe the models and relationships you want. Every model and column is checked against the current dbt snapshot before anything is proposed.",examplePrompts:[{label:"Model this area",prompt:"Bind the relevant unbound dbt models for this area, write business context for each, and connect them with draft relationships."},{label:"Describe this model",prompt:"Write the business context and grain for the focused model using only dbt metadata evidence."},{label:"Connect these models",prompt:"Propose draft relationships between the models in this area and explain the evidence for each key pair."}]})})]})}function Xs({entity:t,detail:n,relationships:s=[],t:o,onEdit:i,onEditDbtSource:r,onSelectRelationship:d,onDelete:h}){var f,c,x,I;const y=oo(t.analyticalRole),l=new Set(t.keys.length?t.keys:((f=n==null?void 0:n.dqlMeta)==null?void 0:f.keys)??[]),u={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"0 0 5px"},m=s.filter(v=>v.from===t.id||v.to===t.id||v.from===t.localId||v.to===t.localId);return e.jsxs(ln,{t:o,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,marginBottom:12},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:y,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:13.5,fontWeight:700,color:o.textPrimary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.businessName||t.localId}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:y},children:t.analyticalRole??"entity"})]}),e.jsx("p",{style:{margin:"0 0 12px",color:o.textSecondary,fontSize:12,lineHeight:1.6},children:t.businessContext||`Add the DQL-owned business context for ${t.localId}. dbt descriptions remain physical-source documentation.`}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:u,children:"dbt binding"}),e.jsx("div",{style:{fontSize:11,fontFamily:o.fontMono,color:o.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:(n==null?void 0:n.relation)??t.dbtUniqueId})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs("div",{style:u,children:["Columns · ",(n==null?void 0:n.columns.length)??"…"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n==null?void 0:n.columns.slice(0,16).map(v=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"4px 2px",borderBottom:"1px solid var(--border-subtle)",fontSize:11.5},children:[e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:o.fontMono,color:l.has(v.name)?"var(--pk)":/(^|_)id$/.test(v.name)?"var(--fk)":"transparent"},children:l.has(v.name)?"PK":/(^|_)id$/.test(v.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:o.textSecondary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:o.textMuted,fontFamily:o.fontMono},children:v.type??"—"})]},v.name))})]}),m.length>0&&d?e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:u,children:"Relationships"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map(v=>e.jsxs("button",{type:"button",onClick:()=>d(v),style:{display:"flex",alignItems:"center",gap:7,padding:"6px 8px",borderRadius:7,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",cursor:"pointer",textAlign:"left",fontFamily:o.font,fontSize:11,color:o.textSecondary},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:v.cardinality==="one_to_one"?"1:1":v.cardinality==="one_to_many"?"1:N":v.cardinality==="many_to_one"?"N:1":"N:N"})]},v.qualifiedId??v.localId))})]}):null,e.jsxs("details",{style:{marginBottom:12},children:[e.jsx("summary",{style:{...u,cursor:"pointer"},children:"More metadata"}),e.jsx(le,{label:"concepts",value:((c=t.conceptRefs)==null?void 0:c.join(", "))||"Not mapped",t:o}),e.jsx(le,{label:"owner",value:t.owner??"Not declared",t:o}),e.jsx(le,{label:"grain",value:t.grain??((x=n==null?void 0:n.dqlMeta)==null?void 0:x.grain)??"Not declared",t:o}),e.jsx(le,{label:"keys",value:(t.keys.length?t.keys:((I=n==null?void 0:n.dqlMeta)==null?void 0:I.keys)??[]).join(", ")||"Not declared",t:o}),e.jsx(le,{label:"source",value:(n==null?void 0:n.sourcePath)??t.sourcePath,t:o}),e.jsx(le,{label:"dbt description",value:(n==null?void 0:n.description)??"Not declared",t:o})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(se,{primary:!0,t:o,onClick:i,children:"Edit entity"}),e.jsx(se,{t:o,onClick:r,children:"Preview dbt source patch"}),h?e.jsx(se,{t:o,danger:!0,onClick:h,children:"Delete entity"}):null]})]})}function ei({entity:t,detail:n,snapshotId:s,t:o,onClose:i,onApplied:r}){const d=n.columns.filter(S=>S.tests.length>0).map(S=>`${S.name}: ${S.tests.join(", ")}`).join(`
|
|
22
|
+
`),[h,y]=a.useState(n.description??""),[l,u]=a.useState(d),[m,f]=a.useState(null),[c,x]=a.useState(!1),[I,v]=a.useState(null),w=()=>({uniqueId:t.dbtUniqueId,description:h,columns:l.split(/\r?\n/).flatMap(S=>{const P=S.indexOf(":");if(P<1)return[];const q=S.slice(0,P).trim(),N=Y(S.slice(P+1));return q?[{name:q,tests:N}]:[]})}),B=async()=>{try{x(!0),v(null),f(await X.previewDbtSourcePatch(w(),s))}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}},b=async()=>{if(m)try{x(!0),v(null),await X.applyDbtSourcePatch(w(),m.fingerprint,m.snapshotId),await r()}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}};return e.jsxs(yo,{title:`Edit dbt source · ${n.name}`,t:o,onClose:i,children:[e.jsx(fe,{text:"dbt owns descriptions and tests. DQL will preview a guarded patch to the dbt YAML source; no dbt metadata is copied into the Domain Package.",t:o}),m?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{color:o.textSecondary,fontSize:11},children:["Source: ",e.jsx("code",{children:m.patch.path})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(Gn,{title:"Current dbt YAML",source:m.patch.before||"# New dbt schema YAML",t:o}),e.jsx(Gn,{title:"Proposed dbt YAML",source:m.patch.after,t:o})]}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:()=>f(null),children:"Back"}),e.jsx(se,{primary:!0,t:o,disabled:c||!m.patch.changed,onClick:()=>void b(),children:m.patch.changed?"Apply dbt source patch":"No changes"})]})]}):e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(z,{label:"Model description",children:e.jsx("textarea",{"aria-label":"Model description",value:h,onChange:S=>y(S.target.value),rows:5,style:{...ye(o),resize:"vertical"}})}),e.jsx(z,{label:"Column tests (one column per line)",children:e.jsx("textarea",{"aria-label":"Column tests",value:l,onChange:S=>u(S.target.value),rows:6,placeholder:"order_id: unique, not_null",style:{...ye(o),resize:"vertical",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"}})}),e.jsx("p",{style:{margin:0,color:o.textMuted,fontSize:10},children:"Descriptions/tests stay in dbt YAML. Business meaning, relationships, contracts, and policies stay in the DQL Domain Package."}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:i,children:"Cancel"}),e.jsx(se,{primary:!0,t:o,disabled:c,onClick:()=>void B(),children:"Preview source patch"})]})]})]})}function Gn({title:t,source:n,t:s}){return e.jsxs("section",{children:[e.jsx("strong",{style:{fontSize:10},children:t}),e.jsx("pre",{tabIndex:0,style:{maxHeight:360,overflow:"auto",whiteSpace:"pre-wrap",background:s.appBg,border:`1px solid ${s.headerBorder}`,borderRadius:6,padding:10,fontSize:9.5,color:s.textSecondary},children:n})]})}function ti({relationship:t,t:n,onEdit:s,onDelete:o}){var i,r,d;return e.jsxs(ln,{t:n,children:[e.jsx(ai,{title:t.localId,subtitle:`${t.from} → ${t.to}`,t:n}),e.jsx(se,{primary:!0,t:n,onClick:s,children:"Validate / edit"}),e.jsx("h3",{style:no(n),children:"Business meaning"}),e.jsx(le,{label:"verb",value:t.verb??"Not described",t:n}),e.jsx("p",{style:{margin:"0 0 8px",color:n.textSecondary,fontSize:11,lineHeight:1.55},children:t.description||`${t.from} relates to ${t.to}. Add a business description so agents can distinguish this route from similarly shaped joins.`}),e.jsx("h3",{style:no(n),children:"Join route"}),e.jsx(le,{label:"cardinality",value:t.cardinality,t:n}),e.jsx(le,{label:"fanout",value:t.fanout,t:n}),e.jsx(le,{label:"lifecycle",value:t.status,t:n}),e.jsx(le,{label:"join keys",value:t.keys.map(h=>`${h.from} = ${h.to}`).join(", "),t:n}),e.jsx(le,{label:"endpoint roles",value:[(i=t.roles)==null?void 0:i.from,(r=t.roles)==null?void 0:r.to].filter(Boolean).join(" → ")||"Not declared",t:n}),e.jsx(le,{label:"allowed joins",value:((d=t.joinTypes)==null?void 0:d.join(", "))||"left",t:n}),e.jsx(le,{label:"automatic agent join",value:t.automaticJoinAllowed?"Allowed":"Blocked",t:n}),t.validation?e.jsx(fo,{evidence:t.validation,t:n}):e.jsx(fe,{text:"No warehouse proof has been captured. This edge cannot authorize automatic SQL joins.",t:n}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:12},children:[e.jsx(se,{primary:!0,t:n,onClick:s,children:"Edit relationship"}),o?e.jsx(se,{t:n,danger:!0,onClick:o,children:"Delete relationship"}):null]})]})}function ni({data:t,domainEntities:n,domainRelationships:s,t:o,onSelectRelationship:i}){var f;const r=((f=n[0])==null?void 0:f.domain)??"All domains",d=s.filter(c=>{var x;return((x=c.validation)==null?void 0:x.status)==="passed"}).length,h=n.filter(c=>!!c.dbtUniqueId).length,y=n.filter(c=>!c.businessContext),l={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"14px 0 5px"},u=(c,x)=>e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,padding:"10px 12px",background:"var(--bg-1)"},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:o.textPrimary},children:c}),e.jsx("div",{style:{fontSize:10.5,color:o.textMuted},children:x})]}),m=(c,x)=>e.jsxs("span",{style:{display:"flex",alignItems:"flex-start",gap:7,fontSize:11.5,color:o.textSecondary,lineHeight:1.45},children:[e.jsx("span",{style:{color:c?"var(--status-success)":"var(--status-warning)",flexShrink:0,fontWeight:700},children:c?"✓":"△"}),x]},x);return e.jsxs(ln,{t:o,children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted},children:[r," model"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8,marginTop:12},children:[u(n.length,n.length===1?"entity":"entities"),u(s.length,s.length===1?"relationship":"relationships")]}),e.jsx("p",{style:{margin:"12px 0 0",color:o.textSecondary,fontSize:12,lineHeight:1.6},children:"Select an entity to see its columns and dbt binding, or click a relationship label to review its join, cardinality, and business context."}),e.jsx("div",{style:l,children:"Model health"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[s.length>0?m(d===s.length,d===s.length?"All relationships have join proofs":`${d} of ${s.length} relationships have join proofs`):m(!1,"No relationships yet — drag between column handles to create one"),m(h===n.length&&n.length>0,n.length===0?"No entities bound yet — use Bind model":`${h} of ${n.length} entities bound to dbt`),y.length>0?m(!1,`${y[0].localId}${y.length>1?` and ${y.length-1} more`:""} ha${y.length>1?"ve":"s"} no business description`):n.length>0?m(!0,"Every entity has a business description"):null]}),e.jsx("div",{style:l,children:"Relationships"}),s.length?s.map(c=>e.jsxs("button",{onClick:()=>i(c),style:{display:"flex",alignItems:"center",gap:7,width:"100%",textAlign:"left",border:"1px solid var(--border-subtle)",borderRadius:7,background:"var(--bg-1)",color:o.textSecondary,padding:"6px 8px",marginBottom:4,cursor:"pointer",fontSize:11,fontFamily:o.font},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:c.cardinality==="one_to_one"?"1:1":c.cardinality==="one_to_many"?"1:N":c.cardinality==="many_to_one"?"N:1":"N:N"})]},c.qualifiedId)):e.jsx("p",{style:{color:o.textMuted,fontSize:10.5,margin:0},children:"Drag between two column handles to create the first relationship."}),e.jsx("div",{style:l,children:"Ownership boundary"}),e.jsx("p",{style:{color:o.textSecondary,fontSize:11,lineHeight:1.55,margin:0},children:"dbt owns tables, columns, descriptions, tests, and metrics. DQL owns domain membership, analytical identity, safe relationship proof, contracts, certified blocks, and agent policy. Shared apps and notebooks reference this domain without moving inside it."})]})}function fo({evidence:t,t:n,onFixWithAi:s}){return e.jsxs("div",{style:{marginTop:12,padding:10,border:`1px solid ${t.status==="passed"?"#2e9b6355":"#c94b5555"}`,background:t.status==="passed"?"#2e9b630d":"#c94b550d",borderRadius:7,fontSize:11},children:[e.jsx("b",{style:{color:t.status==="passed"?"#2e9b63":"#c94b55"},children:t.status==="passed"?"Warehouse proof passed":"Warehouse proof failed"}),e.jsxs("div",{style:{color:n.textSecondary,marginTop:7,lineHeight:1.55},children:["Rows: ",t.fromRows," → ",t.toRows,e.jsx("br",{}),"Joined: ",t.joinedRows," · unmatched: ",t.unmatchedFrom,e.jsx("br",{}),"Max rows/key: ",t.maxFromPerKey," → ",t.maxToPerKey]}),s?e.jsxs("button",{type:"button",onClick:s,style:{...Ze(n),marginTop:9},children:[e.jsx(Ht,{size:13})," Fix with Modeling AI"]}):null]})}function Zn({t,title:n,detail:s,status:o}){return e.jsx("div",{style:{flex:1,display:"grid",placeItems:"center",background:t.appBg,color:t.textPrimary},children:e.jsxs("div",{style:{maxWidth:560,textAlign:"center"},children:[e.jsx(Xe,{size:34,color:t.accent}),e.jsx("h1",{style:{fontSize:20},children:n}),e.jsx("p",{style:{color:t.textSecondary,lineHeight:1.6},children:s}),o&&e.jsx("code",{style:{fontSize:12},children:o})]})})}function yo({title:t,t:n,onClose:s,children:o}){return e.jsx("div",{style:{position:"fixed",inset:0,zIndex:100,background:"#0008",display:"grid",placeItems:"center",padding:20},onMouseDown:i=>{i.target===i.currentTarget&&s()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&s()},style:{width:"min(720px, 94vw)",maxHeight:"88vh",overflow:"auto",background:n.appBg,border:`1px solid ${n.headerBorder}`,borderRadius:12,boxShadow:"0 24px 80px #0006"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"15px 18px",borderBottom:`1px solid ${n.headerBorder}`},children:[e.jsx("strong",{children:t}),e.jsx("button",{"aria-label":`Close ${t}`,title:"Close",onClick:s,style:ze(n),children:e.jsx(tt,{size:17})})]}),e.jsx("div",{style:{padding:18},children:o})]})})}function Xn({current:t,labels:n,t:s}){return e.jsx("div",{"aria-label":`Step ${t} of ${n.length}`,style:{display:"grid",gridTemplateColumns:`repeat(${n.length}, minmax(0, 1fr))`,gap:6},children:n.map((o,i)=>{const r=i+1,d=r===t,h=r<t;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,color:d?s.textPrimary:s.textMuted,fontSize:10,fontWeight:d?700:550},children:[e.jsx("span",{style:{display:"grid",placeItems:"center",width:20,height:20,flex:"0 0 auto",borderRadius:999,border:`1px solid ${d||h?s.accent:s.headerBorder}`,background:h?s.accent:d?"var(--accent-dim)":s.appBg,color:h?"#fff":d?s.accent:s.textMuted},children:h?"✓":r}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o})]},o)})})}function eo({title:t,detail:n,t:s}){return e.jsxs("div",{style:{display:"grid",gap:3,padding:"9px 11px",border:`1px solid ${s.headerBorder}`,borderRadius:7,background:s.cellBg},children:[e.jsx("strong",{style:{fontSize:11},children:t}),e.jsx("span",{style:{color:s.textMuted,fontSize:9.5,overflowWrap:"anywhere"},children:n})]})}function Nt({ariaLabel:t,value:n,onChange:s,options:o,placeholder:i,disabled:r=!1,t:d}){const[h,y]=a.useState(!1),[l,u]=a.useState(""),m=o.find(c=>c.value===n),f=_s(o,l,50);return e.jsxs("div",{style:{position:"relative",minWidth:0},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:d.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":t,"aria-expanded":h,"aria-controls":h?"modeling-search-results":void 0,disabled:r,value:h?l:(m==null?void 0:m.label)??n,placeholder:i,onFocus:()=>{y(!0),u("")},onBlur:()=>{y(!1),u("")},onChange:c=>{y(!0),u(c.target.value)},onKeyDown:c=>{c.key==="Escape"&&(y(!1),u(""))},style:{...ye(d),paddingLeft:29,paddingRight:n?29:8,opacity:r?.6:1}}),n&&!r&&e.jsx("button",{type:"button","aria-label":"Clear selection",onMouseDown:c=>c.preventDefault(),onClick:()=>{s(""),u(""),y(!0)},style:{...ze(d),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),h&&!r&&e.jsxs("div",{id:"modeling-search-results",role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:230,overflowY:"auto",border:`1px solid ${d.headerBorder}`,borderRadius:7,background:d.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[f.length?f.map(c=>e.jsxs("button",{type:"button",role:"option","aria-selected":c.value===n,onMouseDown:x=>x.preventDefault(),onClick:()=>{s(c.value),y(!1),u("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:c.value===n?"var(--accent-dim)":"transparent",color:d.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:c.label}),c.description&&e.jsx("span",{style:{color:d.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.description})]},c.value)):e.jsx("div",{style:{padding:12,color:d.textMuted,fontSize:10},children:"No matching results."}),o.length>50&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${d.headerBorder}`,color:d.textMuted,fontSize:9},children:["Showing the best 50 of ",o.length.toLocaleString(),". Refine your search for a specific result."]})]})]})}function oi({value:t,onChange:n,selectedNode:s,t:o}){const[i,r]=a.useState(""),[d,h]=a.useState(!1),[y,l]=a.useState(!1),[u,m]=a.useState(0),[f,c]=a.useState([]);return a.useEffect(()=>{let x=!1;const I=window.setTimeout(()=>{l(!0),X.getDbtModelInventory({q:i,limit:50}).then(v=>{x||(m(v.total),c(v.items.map(w=>{var b;const B=w;return{value:B.uniqueId??"",label:B.name??B.uniqueId??"Unnamed model",description:`${B.relation??B.sourcePath??B.uniqueId}${B.binding?` · already bound to ${B.binding.domain??"a domain"}`:" · unbound"}`,keywords:[B.sourcePath??"",((b=B.binding)==null?void 0:b.businessName)??""]}}).filter(w=>w.value)))}).catch(()=>{x||c([])}).finally(()=>{x||l(!1)})},140);return()=>{x=!0,window.clearTimeout(I)}},[i]),e.jsxs("div",{style:{position:"relative"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:o.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":"Search dbt models","aria-expanded":d,value:d?i:(s==null?void 0:s.name)??t,placeholder:"Search model, relation, or path…",onFocus:()=>{h(!0),r("")},onBlur:()=>{h(!1),r("")},onChange:x=>{r(x.target.value),h(!0)},onKeyDown:x=>{x.key==="Escape"&&h(!1)},style:{...ye(o),paddingLeft:29,paddingRight:t?29:8}}),t&&e.jsx("button",{type:"button","aria-label":"Clear dbt model",onMouseDown:x=>x.preventDefault(),onClick:()=>{n(""),h(!0)},style:{...ze(o),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),d&&e.jsxs("div",{role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:260,overflowY:"auto",border:`1px solid ${o.headerBorder}`,borderRadius:7,background:o.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[y&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"Searching project inventory…"}),!y&&f.map(x=>e.jsxs("button",{type:"button",role:"option","aria-selected":x.value===t,onMouseDown:I=>I.preventDefault(),onClick:()=>{n(x.value),h(!1),r("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:x.value===t?"var(--accent-dim)":"transparent",color:o.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:x.label}),e.jsx("span",{style:{color:o.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.description})]},x.value)),!y&&!f.length&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"No dbt models match this search."}),!y&&u>f.length&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${o.headerBorder}`,color:o.textMuted,fontSize:9},children:["Showing 50 of ",u.toLocaleString(),". Keep typing to narrow the inventory."]})]})]})}function z({label:t,children:n}){return e.jsxs("label",{style:{display:"grid",gap:6,fontSize:11,fontWeight:650},children:[t,n]})}function _({value:t,onChange:n,t:s,placeholder:o}){return e.jsx("input",{value:t,placeholder:o,onChange:i=>n(i.target.value),style:ye(s)})}function ae({value:t,onChange:n,values:s,labels:o,t:i}){return e.jsxs("select",{value:t,onChange:r=>n(r.target.value),style:ye(i),children:[e.jsx("option",{value:"",children:"Select…"}),s.map(r=>e.jsx("option",{value:r,children:(o==null?void 0:o[r])??r},r))]})}function se({children:t,t:n,onClick:s,primary:o,disabled:i,danger:r}){return e.jsx("button",{disabled:i,onClick:s,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,border:`1px solid ${r?n.error:o?n.accent:n.headerBorder}`,background:r?`${n.error}12`:o?n.accent:n.appBg,color:r?n.error:o?"#fff":n.textPrimary,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:650,cursor:i?"wait":"pointer",opacity:i?.65:1},children:t})}function si({children:t,title:n,t:s,onClick:o}){return e.jsx("button",{"aria-label":n,title:n,onClick:o,style:ze(s),children:t})}function qt({children:t,t:n}){return e.jsx("span",{style:{marginLeft:5,border:`1px solid ${n.accent}55`,color:n.accent,background:`${n.accent}10`,borderRadius:999,padding:"3px 7px",fontSize:9,fontWeight:750},children:t})}function ii({children:t,t:n}){return e.jsx("div",{style:{padding:"15px 12px 8px",color:n.textMuted,fontSize:10,fontWeight:750,textTransform:"uppercase",letterSpacing:".07em"},children:t})}function bo({children:t}){return e.jsx("div",{style:{height:"100%",overflow:"auto",padding:20},children:t})}function jo({title:t,detail:n,t:s,action:o}){return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:20,alignItems:"start",marginBottom:18},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("p",{style:{margin:"5px 0 0",color:s.textSecondary,fontSize:11},children:n})]}),o]})}function on({title:t,detail:n,t:s}){return e.jsxs("div",{style:{border:`1px dashed ${s.headerBorder}`,borderRadius:10,padding:30,textAlign:"center"},children:[e.jsx("strong",{children:t}),e.jsx("p",{style:{color:s.textSecondary,fontSize:12},children:n})]})}function ln({children:t}){return e.jsx("div",{style:{padding:"4px 14px 20px"},children:t})}function ai({title:t,subtitle:n,t:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("div",{style:{color:s.textMuted,fontSize:11,marginTop:4},children:n})]})}function le({label:t,value:n,t:s}){return e.jsxs("div",{style:{padding:"9px 0",borderBottom:`1px solid ${s.headerBorder}`},children:[e.jsx("div",{style:{color:s.textMuted,fontSize:9,textTransform:"uppercase",letterSpacing:".05em"},children:t}),e.jsx("div",{style:{fontSize:11,marginTop:4,overflowWrap:"anywhere"},children:n})]})}function fe({text:t,t:n}){return e.jsx("div",{style:{borderLeft:`3px solid ${n.accent}`,background:`${n.accent}0d`,padding:"9px 10px",color:n.textSecondary,fontSize:11,lineHeight:1.5},children:t})}function Y(t){return t.split(",").map(n=>n.trim()).filter(Boolean)}function li(t){return Y(t).map(n=>{const[s,o]=n.split("=").map(i=>i.trim());if(!s||!o)throw new Error(`Invalid join key pair "${n}". Use from_key=to_key.`);return{from:s,to:o}})}function to(){try{return JSON.parse(localStorage.getItem("dql-modeling-preferences")??"{}")}catch{return{}}}const ne={display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},Ge=(t,n=!1)=>({display:"inline-flex",alignItems:"center",gap:5,flex:"0 0 auto",border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,background:n?"var(--accent-dim)":t.appBg,color:n?t.accent:t.textSecondary,padding:"5px 8px",fontSize:10.5,fontWeight:650,cursor:"pointer",whiteSpace:"nowrap"}),ye=t=>({width:"100%",boxSizing:"border-box",border:`1px solid ${t.headerBorder}`,background:t.cellBg,color:t.textPrimary,borderRadius:6,padding:"8px 9px",fontSize:11}),ze=t=>({border:`1px solid ${t.headerBorder}`,background:t.appBg,color:t.textSecondary,borderRadius:6,padding:7,display:"grid",placeItems:"center",cursor:"pointer"}),ri=(t,n,s)=>({width:"100%",minHeight:30,padding:s?"6px 8px 6px 14px":"7px 8px",display:"flex",alignItems:"center",gap:7,border:0,borderRadius:6,background:n?`${t.accent}18`:"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,fontWeight:n?700:500,textAlign:"left",cursor:"pointer"}),Ze=t=>({border:0,background:"transparent",color:t.accent,fontSize:10,fontWeight:650,cursor:"pointer"}),no=t=>({margin:"18px 0 7px",paddingBottom:7,borderBottom:`1px solid ${t.headerBorder}`,fontSize:11,textTransform:"uppercase",letterSpacing:".05em",color:t.textMuted}),Tt=t=>({border:`1px solid ${t.headerBorder}`,background:t.cellBg,borderRadius:9,padding:14});export{Ri as DbtFirstModelingPage};
|