@objectstack/console 9.9.1 → 9.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AiPendingActionsPage-BI-QQNee.js → AiPendingActionsPage-BDYUc-T8.js} +1 -1
- package/dist/assets/{ApiConsolePage-B6QExly9.js → ApiConsolePage-BJB9Xho6.js} +1 -1
- package/dist/assets/{AppDocsIndex-S-ilhz4W.js → AppDocsIndex-Cj0DpA3d.js} +1 -1
- package/dist/assets/{AppManagementPage-JgLQ-wXj.js → AppManagementPage-BzjUDLx3.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-CAyznoRP.js → ApprovalsInboxPage-Dym3zM3t.js} +1 -1
- package/dist/assets/{AuditLogPage-BeEqEy4g.js → AuditLogPage-BJh3wy1L.js} +1 -1
- package/dist/assets/{ComponentNavView-DmALsugj.js → ComponentNavView-BFSklq8D.js} +1 -1
- package/dist/assets/{ConsoleFloatingChatbot-D13eK4M8.js → ConsoleFloatingChatbot-_UeVODsx.js} +1 -1
- package/dist/assets/{DashboardView-P--eXDC-.js → DashboardView-kL9_gMzd.js} +1 -1
- package/dist/assets/{DashboardWidgetInspector-VPDtQEP_.js → DashboardWidgetInspector-BN8Yy27Q.js} +1 -1
- package/dist/assets/{DeveloperHubPage-DbQwi1EV.js → DeveloperHubPage-CB5nkyun.js} +1 -1
- package/dist/assets/{FlowRunsPage-CCS9xNVc.js → FlowRunsPage-65yB_BWO.js} +1 -1
- package/dist/assets/{IntegrationsPage-DU_wvj4-.js → IntegrationsPage-8M_88h2y.js} +2 -2
- package/dist/assets/{InterfaceListPage-B3jzgT27.js → InterfaceListPage-CBomrdcf.js} +1 -1
- package/dist/assets/{ManagedByBadge-Difq_L_A.js → ManagedByBadge-Bmg77Q4v.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-CXUE33gy.js → MarketplaceAccessDenied-CX0RbkOJ.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-CBfcARvX.js → MarketplaceInstalledPage-BYXiUCpz.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-DOZgrTZo.js → MarketplacePackagePage-C8yVjW5r.js} +2 -2
- package/dist/assets/{MarketplacePage-BT-WkhAG.js → MarketplacePage-pVW-NfrG.js} +1 -1
- package/dist/assets/{MetadataInspector-BRICMLXW.js → MetadataInspector-CACgSTc7.js} +1 -1
- package/dist/assets/{MetadataProvider-Bja7m8Gt.js → MetadataProvider-Dh20h6BN.js} +1 -1
- package/dist/assets/{PageView-My4nP5w4.js → PageView-D388xYQA.js} +1 -1
- package/dist/assets/{ProfilePage-BAtKSxuK.js → ProfilePage-SXmEEOn3.js} +1 -1
- package/dist/assets/{PublicFormsPage-CcRFrTQC.js → PublicFormsPage-aXes2XrW.js} +1 -1
- package/dist/assets/{RecordDetailView-CMIRy42W.js → RecordDetailView-DIiHv2mR.js} +1 -1
- package/dist/assets/{RecordFormPage-BUfFijzM.js → RecordFormPage-C052nJig.js} +1 -1
- package/dist/assets/ReportDefaultInspector-CjR-PcBn.js +1 -0
- package/dist/assets/{ReportView-DSrtPxzA.js → ReportView-M_mx8mgW.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-B2fJIAhv.js → RuntimeDraftBar-DTf-DIfT.js} +1 -1
- package/dist/assets/{SearchResultsPage-C7i-b3gn.js → SearchResultsPage-DGuFKZit.js} +1 -1
- package/dist/assets/{SettingsHub-BLEC_8Ao.js → SettingsHub-eYWWi8O5.js} +1 -1
- package/dist/assets/{SettingsView-BEjR60F6.js → SettingsView-Cq3IKOhI.js} +1 -1
- package/dist/assets/{SystemHubPage-DWGnZfF0.js → SystemHubPage-6FccxnKY.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-DiT7C6XW.js → highlighted-body-OFNGDK62-CKMBhexn.js} +1 -1
- package/dist/assets/index-A8r_lURn.js +4 -0
- package/dist/assets/index-BGyrRTzt.css +2 -0
- package/dist/assets/{mergeServerFields-zZ2r6yTA.js → mergeServerFields-CMIOI8QD.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-C3g3SOag.js +1 -0
- package/dist/assets/metadata-admin-ORqaeHUJ.js +19 -0
- package/dist/assets/plugin-calendar-Czocnijo.js +1 -0
- package/dist/assets/{plugin-charts-AMObsZz3.js → plugin-charts-dCyWH9k8.js} +1 -1
- package/dist/assets/{plugin-chatbot-Ch8YIyYL.js → plugin-chatbot-BpAQS7-q.js} +6 -6
- package/dist/assets/plugin-dashboard-CjtE0zwv.js +5 -0
- package/dist/assets/{plugin-form-DXCdD2d-.js → plugin-form-Dzz6GAZM.js} +1 -1
- package/dist/assets/plugin-gantt-BedjcmIc.js +23 -0
- package/dist/assets/plugin-grid-BqmF7p-H.js +6 -0
- package/dist/assets/{plugin-kanban-DOsTOpJz.js → plugin-kanban-Dq0xJjXt.js} +1 -1
- package/dist/assets/{plugin-map-Bid9UXOR.js → plugin-map-DG62gl97.js} +1 -1
- package/dist/assets/{plugin-markdown-BUQOG31j.js → plugin-markdown-BL0QvMCD.js} +1 -1
- package/dist/assets/{plugin-report-FxG9jOvy.js → plugin-report-DckNGNq6.js} +1 -1
- package/dist/assets/{plugin-timeline-DDrFKEb8.js → plugin-timeline-dBrX3lS3.js} +1 -1
- package/dist/assets/plugin-view-DCPYomdU.js +1 -0
- package/dist/assets/plugins-views-B-EGcBP2.js +4 -0
- package/dist/assets/{resolveActionParams-xmwfLvud.js → resolveActionParams-B_7wSkli.js} +1 -1
- package/dist/assets/{skeletons-B_SNEnMn.js → skeletons-BK7w4pLE.js} +1 -1
- package/dist/assets/src-9qM7N8MR.js +2 -0
- package/dist/assets/{src-DbxuLwqh.js → src-Czx03pos.js} +1 -1
- package/dist/assets/{types-CosU35As.js → types-C2_UYDEK.js} +1 -1
- package/dist/assets/{ui-components-CrPYFyEM.js → ui-components-NS_7__gn.js} +7 -7
- package/dist/assets/{ui-layout-DAWxaQvy.js → ui-layout-BdKOzi1L.js} +1 -1
- package/dist/assets/{useActionModal-DsVCm46J.js → useActionModal-BE61500N.js} +1 -1
- package/dist/assets/{useReconcileOnError-D6sIYKrb.js → useReconcileOnError-Cvd01WQv.js} +1 -1
- package/dist/assets/{utils-bipVuqQL.js → utils-29quoGQV.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +1 -1
- package/dist/assets/ReportDefaultInspector-C8gR3RMr.js +0 -1
- package/dist/assets/index-BgnAjV6_.js +0 -4
- package/dist/assets/index-CJe1zUD0.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-CK-9EMhD.js +0 -1
- package/dist/assets/metadata-admin-BgoJzjrj.js +0 -19
- package/dist/assets/plugin-calendar-DQC9zdKq.js +0 -1
- package/dist/assets/plugin-dashboard-C7fxXXeO.js +0 -5
- package/dist/assets/plugin-gantt-BHmpu6VX.js +0 -23
- package/dist/assets/plugin-grid-boi_rkH3.js +0 -6
- package/dist/assets/plugin-view-D58aYgqA.js +0 -1
- package/dist/assets/plugins-views-DUKPQNs8.js +0 -4
- package/dist/assets/src-DXFkWHTV.js +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,a as r,f as i,l as a,m as o,p as s,r as c,t as l,u}from"./vendor-react-DR370ovB.js";import{m as d}from"./infrastructure-CJNwTVno.js";import{B as f,ct as p,w as m}from"./framework-BLEk-ou3.js";import{R as h,_ as g,d as _,p as v}from"./vendor-objectstack-BNd856rx.js";import{$ as y,$n as b,$o as x,$t as S,Ai as C,Ar as w,Bn as T,Bo as E,Bt as D,Ca as O,Ci as k,Co as A,Cr as j,Da as ee,Di as te,Do as ne,Ds as re,Fa as M,Fi as ie,Fo as N,Ft as ae,Gi as oe,Go as se,Gr as ce,Gs as le,H as ue,Ha as de,Hi as fe,Hn as pe,Hs as me,Ht as he,Ia as ge,Io as _e,Ir as ve,Is as ye,It as be,Ja as xe,Ji as Se,Jt as Ce,Kn as we,Ks as Te,L as P,La as Ee,Ln as De,Lo as Oe,Lr as ke,Lt as Ae,Ma as F,Mi as je,Mo as Me,Mt as Ne,Na as Pe,Nr as Fe,Oa as Ie,Os as Le,Pi as Re,Po as ze,Pr as Be,Pt as Ve,Qa as He,Qi as Ue,Qo as We,Qr as Ge,R as Ke,Rn as qe,Rr as I,Rs as Je,Rt as Ye,Sa as Xe,Si as Ze,So as Qe,Sr as $e,Ta as et,Ti as tt,To as nt,Ts as rt,Ua as it,Ui as L,Uo as at,Ut as ot,Va as st,Vi as ct,Vn as lt,Vr as ut,Vs as dt,Vt as ft,Wa as pt,Wi as mt,Wo as ht,Wr as gt,Ws as _t,Wt as vt,Xa as yt,Xi as bt,Xo as xt,Xr as St,Ya as Ct,Yo as wt,Ys as Tt,Yt as Et,Zo as Dt,_i as Ot,_r as kt,ac as At,at as jt,ba as Mt,bi as Nt,br as Pt,bs as Ft,ca as It,cc as Lt,co as Rt,ct as zt,da as Bt,dc as Vt,di as Ht,dt as Ut,ea as Wt,ec as Gt,en as Kt,eo as qt,et as Jt,fc as Yt,fi as Xt,fo as Zt,ft as Qt,gi as $t,go as en,gs as R,ha as tn,hi as nn,ho as rn,hr as z,hs as an,ia as on,ii as sn,io as cn,it as ln,ja as un,jo as dn,ko as fn,kr as pn,li as mn,lo as hn,lt as gn,ma as _n,mi as vn,mo as yn,ms as bn,na as xn,nc as Sn,ni as Cn,nn as B,no as wn,nt as Tn,on as V,oo as En,os as Dn,ot as On,pc as H,pi as kn,po as An,ps as jn,qo as Mn,qs as Nn,qt as Pn,ra as Fn,rc as In,rs as Ln,rt as Rn,sa as zn,sc as Bn,si as Vn,so as Hn,ss as Un,st as Wn,ta as Gn,ti as Kn,tn as qn,to as Jn,ua as Yn,uc as Xn,uo as Zn,us as Qn,ut as $n,va as er,vo as tr,vr as nr,wa as rr,wi as ir,wr as ar,ws as or,xa as sr,xi as cr,xo as lr,xr as ur,ya as dr,yi as fr,yo as pr,yr as mr,ys as hr,z as gr,za as _r,zn as vr,zo as yr,zt as br}from"./ui-components-NS_7__gn.js";import{r as xr}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-DJb3ZVmJ.js";import{o as Sr,r as Cr}from"./MetadataProvider-Dh20h6BN.js";import{n as wr}from"./RecentItemsProvider-B76qldBH.js";import{C as Tr,S as Er,_ as Dr,a as U,b as Or,c as kr,d as Ar,f as jr,g as W,h as Mr,i as G,l as Nr,m as Pr,n as Fr,o as Ir,p as Lr,r as Rr,s as zr,t as Br,u as Vr,v as Hr,w as Ur,x as Wr,y as K}from"./mergeServerFields-CMIOI8QD.js";import{t as Gr}from"./InterfaceListPage-CBomrdcf.js";import{a as Kr,c as qr,i as Jr,n as Yr,o as Xr,r as Zr,s as Qr,t as $r}from"./ReportDefaultInspector-CjR-PcBn.js";import{i as ei,n as ti,r as ni,t as ri}from"./DashboardWidgetInspector-BN8Yy27Q.js";var q=l(),J=e(n(),1);function ii(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var ai=new Set(Jt),oi=new Map;function si(e){if(!e)return ht;let t=oi.get(e);if(t)return t;let n=ii(e);if(!ai.has(n))return oi.set(e,ht),ht;let r=e=>J.createElement(y,{name:n,fallback:ht,...e});return r.displayName=`LucideIcon(${e})`,oi.set(e,r),r}function ci(e){return Array.isArray(e)?{shape:`array`,entries:e.map((e,t)=>{let{name:n,...r}=e??{};return{name:typeof n==`string`&&n?n:`field_${t+1}`,def:r}})}:e&&typeof e==`object`?{shape:`record`,entries:Object.entries(e).map(([e,t])=>({name:e,def:{...t??{}}}))}:{shape:`record`,entries:[]}}function li(e){if(e.shape===`array`)return e.entries.map(e=>({name:e.name,...e.def}));let t={};for(let n of e.entries)t[n.name]=n.def;return t}function ui(e,t){return e.entries.findIndex(e=>e.name===t)}function di(e,t,n){let r={type:t,label:n??fi(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function fi(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function pi(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/_{2,}/g,`_`);return t?/^[a-z_]/.test(t)?t:`f_${t}`:`field`}function mi(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:``})).filter(e=>e.key):[]}function hi(e,t){let n=/[a-z0-9]/i.test(e)?pi(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function gi(e,t){let n=t.trim()||`New section`,r=hi(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function _i(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function vi(e,t){return e.filter(e=>e.key!==t)}function yi(e,t,n){let r=e.findIndex(e=>e.key===t);if(r<0)return e;let i=r+n;return i<0||i>=e.length?e:xi(e,r,i)}function bi(e,t){return{shape:e.shape,entries:e.entries.map(e=>e.def.group===t?{name:e.name,def:{...e.def,group:void 0}}:e)}}function xi(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function Si(e,t,n){let r=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],i=new Map;for(let e of r)i.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let a=new Set(r.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&a.has(e)?i.get(e).entries.push(t):(i.has(null)||i.set(null,{key:null,label:`Ungrouped`,entries:[]}),i.get(null).entries.push(t))}let o=!!n?.includeEmptyDeclared;return Array.from(i.values()).filter(e=>e.entries.length>0||o&&e.key!==null)}function Ci(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function wi(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)Ci(e[i],t[i])||r.push(i);return r.sort()}function Ti(e,t){let n=ci(e),r=ci(t),i=new Map(n.entries.map(e=>[e.name,e])),a=new Set(r.entries.map(e=>e.name)),o={},s=0,c=0;for(let e of r.entries){let t=i.get(e.name);if(!t){o[e.name]={name:e.name,status:`added`,changedKeys:[]},s+=1;continue}let n=wi(t.def,e.def);n.length?(o[e.name]={name:e.name,status:`changed`,changedKeys:n},c+=1):o[e.name]={name:e.name,status:`unchanged`,changedKeys:[]}}let l=n.entries.filter(e=>!a.has(e.name));return{byName:o,removed:l,counts:{added:s,changed:c,removed:l.length}}}function Ei(e,t){let n=Tr(),[r,i]=J.useState({fields:[],loading:!t&&!!e,error:null});return J.useEffect(()=>{if(t){i({fields:t,loading:!1,error:null});return}if(!e){i({fields:[],loading:!1,error:null});return}let r=!1;return i(e=>({...e,loading:!0,error:null})),n.get(`object`,e).then(e=>{if(!r){if(!e){i({fields:[],loading:!1,error:`Object not found`});return}i({fields:ci(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`&&e.def.label?e.def.label:e.name,type:typeof e.def.type==`string`?e.def.type:`text`,hidden:e.def.hidden===!0})),loading:!1,error:null})}}).catch(e=>{r||i({fields:[],loading:!1,error:e?.message??String(e)})}),()=>{r=!0}},[n,e,t]),r}function Di(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function Oi(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function ki(e){let t=new Set;for(let n of e){let e=Oi(n);e&&t.add(e)}return t}function Ai(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function ji(e,t){return e===t?null:e>t?e-1:e}function Mi(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Ni({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=Ei(i||void 0,a),m=J.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=J.useState(null),[_,v]=J.useState(null),y=J.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),x=J.useCallback(t=>{let i=Dr(n,Ai(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),S=J.useCallback(t=>{let r=K(n,t,null);if(y(r),o!=null){let n=ji(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(r[n],n)})}},[n,y,o,e,l]),C=J.useCallback((t,r)=>{if(t===r)return;let i=Hr(n,t,r);if(y(i),o!=null){let n=Mi(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(i[n],n)})}},[n,y,o,e,l]),w=J.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Di(n[t],t)})},[n,e,l]),T=ki(n);return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,q.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,q.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,q.jsx)(Zr,{index:t,label:Di(e,t),fieldName:Oi(e),fieldType:m.get(Oi(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>w(t),onRemove:()=>S(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&C(h,t),g(null),v(null)}},t))}),u&&(0,q.jsx)(Yr,{fields:d,usedNames:T,loading:f,error:p,onAdd:x})]})}var Pi={io:`input`,unrepresentable:`any`},Fi=new Set([`columns`,`data`,`name`]),Ii,Li=!1;function Ri(){if(Ii||Li)return Ii;try{Ii=h(v,Pi)}catch(e){Li=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return Ii}function zi(){return Ri()?.properties?.list}function Bi(){return Ri()?.properties?.form}var Vi,Hi=!1;function Ui(){if(Vi||Hi)return Vi;try{Vi=h(_,Pi)}catch(e){Hi=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Vi}var Wi;function Gi(){if(Wi)return Wi;if(!(!g||typeof g!=`object`)){try{let e=JSON.parse(JSON.stringify(g));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Fi.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Wi=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Wi}}var Ki=new Set([`form`,`detail`]);function qi(e){return Ki.has(e)}function Ji(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Yi(e,t){return typeof e==`string`&&Ki.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Ki.has(t)?`form`:`list`}function Xi(e){let t=e.config;return Ji(t)?[{storeKey:`config`,familyKey:Yi(e.viewKind,t.type),schema:t}]:[]}function Zi(e){return Xi(e)[0]}function Qi(e,t){return Zi(e)}var $i=new Set([`type`,`object`,`label`,`columns`]),ea={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function ta(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?ea[e]??e:r}var na=[`columns`,`data`,`name`];function ra(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function ia(e,t){return J.useMemo(()=>{let n=zi()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:ta(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:ta(e,t)}),r},[e,t])}function aa({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=qi(n??t),p=typeof d.type==`string`?d.type:`grid`,m=ia(p,l),h=ra(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=Ei(h.value||void 0,c),b=J.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),x=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:S,form:C}=J.useMemo(()=>Br({bundledSchema:f?Bi():zi(),bundledForm:f?void 0:Gi(),serverSchema:x,excludeFields:$i,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:G(`engine.inspector.view.close`,l),hideClose:r,children:[(0,q.jsx)(W,{label:G(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:G(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,q.jsx)(Pr,{label:G(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,q.jsx)(W,{label:G(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:G(`engine.inspector.view.objectPlaceholder`,l),disabled:a,mono:!0}),!f&&(0,q.jsx)(`div`,{className:`border-t pt-3`,children:(0,q.jsx)(Ni,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,q.jsx)(`div`,{className:`border-t pt-3`,children:S?(0,q.jsx)(Fr,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of na)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.view.noSchema`,l)})})]})}function oa({appSlug:e}={}){let t=u(),n=Tr(),{entries:r}=Ur(n),[i,a]=J.useState(!1),[o,s]=J.useState(``),[c,l]=J.useState(null),[d,f]=J.useState(!1),[p,m]=J.useState(0),h=J.useMemo(()=>Rr(),[]);J.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),a(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),J.useEffect(()=>{if(!i||c!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||l(t)}finally{e||f(!1)}})(),()=>{e=!0}},[i,c,d,r,n]);let g=J.useMemo(()=>{let e=o.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||zr(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(c??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[o,r,c]);J.useEffect(()=>{m(0)},[o,i]);function _(n){a(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,q.jsx)(De,{open:i,onOpenChange:a,children:(0,q.jsxs)(qe,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,q.jsx)(lt,{className:`sr-only`,children:(0,q.jsx)(pe,{children:G(`engine.quickfind.title`,h)})}),(0,q.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,q.jsx)(Ze,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(B,{autoFocus:!0,placeholder:G(`engine.quickfind.placeholder`,h),value:o,onChange:e=>s(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,q.jsx)(P,{children:`esc`})]}),(0,q.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,q.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}),G(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:G(`engine.quickfind.noMatches`,h)}),(0,q.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`text-sm font-medium truncate`,children:zr(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,q.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,q.jsx)(un,{className:`h-3 w-3`})}),e.name,e.label&&(0,q.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})})]})},e.kind===`type`?`t:${e.entry.type}`:`i:${e.type}:${e.name}`))})]}),(0,q.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(P,{children:`↑`}),` `,(0,q.jsx)(P,{children:`↓`}),` navigate`]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(P,{children:`↵`}),` open`]}),(0,q.jsxs)(`span`,{className:`ml-auto`,children:[(0,q.jsx)(P,{children:`⌘`}),(0,q.jsx)(P,{children:`⇧`}),(0,q.jsx)(P,{children:`M`}),` toggle`]})]})]})})}var sa={data:ht,ui:st,automation:ar,ai:mn,system:Nt,platform:Nt,identity:$t,security:$t},ca=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],la=new Set([`field`,`package`]);function ua(){let e=Tr(),{loading:t,error:n,entries:r}=Ur(e),i=J.useMemo(()=>Rr(),[]),[a,o]=J.useState(``),[l,u]=J.useState(`all`),[d,f]=J.useState(!1),[p,m]=s(),[h,g]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),g(i.map(e=>({id:e.id,name:e.name})))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=J.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);J.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Er(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>la.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[r,v,w]),D=J.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(a){let t=a.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||zr(e.type,i,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=J.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=ca.indexOf(e),r=ca.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,q.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:G(`engine.directory.loading`,i)}):n?(0,q.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[G(`engine.directory.loadFailed`,i),`: `,n]}):(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:G(`engine.directory.title`,i)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:U(`engine.directory.description`,i,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,q.jsx)(Ze,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.directory.search`,i),value:a,onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(z,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,i),` (`,O,`)`]}),x.total>0&&(0,q.jsx)(z,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,q.jsxs)(c,{to:`./_diagnostics`,children:[(0,q.jsx)(I,{className:`h-3.5 w-3.5 mr-1`}),U(`engine.directory.diagnosticsLink`,i,{count:x.total})]})}),(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[G(`engine.directory.quickFind`,i),` `,(0,q.jsx)(P,{children:`⌘`}),(0,q.jsx)(P,{children:`⇧`}),(0,q.jsx)(P,{children:`M`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,q.jsx)(da,{domain:`all`,label:G(`engine.directory.all`,i),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),ca.filter(e=>D[e]).map(e=>(0,q.jsx)(da,{domain:e,label:Ir(e,i),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:G(`engine.directory.noMatches`,i)}),(0,q.jsx)(gr,{children:G(`engine.directory.noMatchesHint`,i)})]}),A.map(([e,t])=>(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,q.jsx)(sa[e]??Te,{className:`h-3.5 w-3.5`}),Ir(e,i),` (`,t.length,`)`]}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,q.jsx)(fa,{entry:e,locale:i,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,q.jsx)(oa,{})]})}function da({domain:e,label:t,active:n,count:r,onClick:i}){return(0,q.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,q.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function fa({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=zr(e.type,t,e.label);return(0,q.jsxs)(c,{to:o?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(o)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(n>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[n>0&&(0,q.jsx)(`span`,{title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,q.jsx)(I,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),s]}),(0,q.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,q.jsx)(b,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:U(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:U(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),a>0&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${a} locked item${a===1?``:`s`} — see ADR-0010`,"aria-label":`${a} locked items`,children:[(0,q.jsx)(un,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,t)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var pa=`/api/v1/packages`;async function ma(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function ha({scope:e}){let t=J.useMemo(()=>Rr(),[]),n=e??`project`,r=n===`project`?`default`:n===`system`?`secondary`:`outline`,i=n===`project`?`engine.packages.scope.project`:n===`system`?`engine.packages.scope.system`:n===`cloud`?`engine.packages.scope.cloud`:``;return(0,q.jsx)(b,{variant:r,children:i?G(i,t):n})}function ga({pkg:e}){let t=J.useMemo(()=>Rr(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,q.jsx)(b,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var _a=/^[a-z0-9][a-z0-9._-]{1,254}$/i,va=/^\d+\.\d+\.\d+$/;function ya({open:e,onOpenChange:t,onCreated:n}){let r=J.useMemo(()=>Rr(),[]),[i,a]=J.useState(``),[o,s]=J.useState(``),[c,l]=J.useState(`0.1.0`),[u,d]=J.useState(!1),[f,p]=J.useState(null);J.useEffect(()=>{e&&(a(``),s(``),l(`0.1.0`),p(null),d(!1))},[e]);let m=_a.test(i),h=va.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await ma(pa,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:i.trim(),name:o.trim(),version:c.trim(),type:`app`,scope:`project`}})}),n(i.trim()),t(!1)}catch(e){p(e?.message??G(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,q.jsx)(De,{open:e,onOpenChange:t,children:(0,q.jsxs)(qe,{children:[(0,q.jsxs)(lt,{children:[(0,q.jsx)(pe,{children:G(`engine.packages.create.title`,r)}),(0,q.jsx)(vr,{children:U(`engine.packages.create.description`,r,{example:`com.acme.crm`})})]}),(0,q.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-id`,children:G(`engine.packages.create.id`,r)}),(0,q.jsx)(B,{id:`pkg-id`,placeholder:`com.acme.crm`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!!i&&!m}),!!i&&!m&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.idInvalid`,r)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-name`,children:G(`engine.packages.create.name`,r)}),(0,q.jsx)(B,{id:`pkg-name`,placeholder:`Acme CRM`,value:o,onChange:e=>s(e.target.value)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-version`,children:G(`engine.packages.create.version`,r)}),(0,q.jsx)(B,{id:`pkg-version`,placeholder:`0.1.0`,value:c,onChange:e=>l(e.target.value),"aria-invalid":!!c&&!h}),!!c&&!h&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.versionInvalid`,r)})]}),f&&(0,q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,q.jsx)(I,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{children:f})]})]}),(0,q.jsxs)(T,{children:[(0,q.jsx)(z,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:G(`engine.cancel`,r)}),(0,q.jsx)(z,{onClick:_,disabled:!g,children:G(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function ba({label:e,children:t}){return(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function xa({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=J.useMemo(()=>Rr(),[]),[o,s]=J.useState(null),[l,u]=J.useState(null),[d,f]=J.useState(null);if(J.useEffect(()=>{u(null),s(null)},[e?.manifest.id]),J.useEffect(()=>{let t=e?.manifest.id;if(!n||!t){f(null);return}let r=!1;return ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{r||f(e?.drafts??[])}).catch(()=>{r||f([])}),()=>{r=!0}},[n,e?.manifest.id]),!e)return null;let p=e.manifest.id,m=e.enabled!==!1&&e.status!==`disabled`,h=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function g(e,t,n){s(e),u(null);try{await t(),u({kind:`ok`,text:n}),i()}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.actionFailed`,a)})}finally{s(null)}}return(0,q.jsx)(Ve,{open:n,onOpenChange:r,children:(0,q.jsxs)(ae,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,q.jsxs)(Ae,{children:[(0,q.jsxs)(Ye,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Yn,{className:`h-4 w-4`}),e.manifest.name||p]}),(0,q.jsx)(be,{className:`font-mono text-xs`,children:p})]}),(0,q.jsxs)(`div`,{className:`mt-4`,children:[(0,q.jsx)(ba,{label:G(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.col.scope`,a),children:(0,q.jsx)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(ba,{label:G(`engine.packages.col.status`,a),children:(0,q.jsx)(ga,{pkg:e})}),e.manifest.description&&(0,q.jsx)(ba,{label:G(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(c,{to:`${t}/metadata/object?package=${encodeURIComponent(p)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,q.jsx)(_e,{className:`h-3.5 w-3.5`}),G(`engine.packages.detail.browseMetadata`,a)]}),d&&d.length>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[G(`engine.packages.detail.pendingChanges`,a),(0,q.jsx)(b,{variant:`secondary`,children:d.length})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G(`engine.packages.detail.pendingHint`,a)}),!h&&(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.publishDraftsPartial`,a,{published:e.publishedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.publishDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(Be,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?G(`engine.packages.detail.publishing`,a):U(`engine.packages.detail.publishApp`,a,{count:d.length})]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.discardDraftsPartial`,a,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.discardDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(ve,{className:`mr-1.5 h-3.5 w-3.5`}),o===`discard-drafts`?G(`engine.packages.detail.discarding`,a):U(`engine.packages.detail.discardChanges`,a,{count:d.length})]})]}),(0,q.jsx)(`ul`,{className:`space-y-1`,children:d.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(c,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,q.jsx)(Qe,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`))})]})]}),(0,q.jsx)(br,{className:`my-4`}),h?(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.detail.kernelReadOnly`,a)}):(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.packages.detail.actions`,a)}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?U(`engine.packages.detail.publishBlocked`,a,{count:t}):e.validationErrors?.[0]?.message||G(`engine.packages.detail.nothingToPublish`,a))}return e}),G(`engine.packages.detail.published`,a)),disabled:!!o,children:[(0,q.jsx)(Be,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>ma(`${pa}/${encodeURIComponent(p)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,q.jsx)(ve,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>ma(`${pa}/${encodeURIComponent(p)}/${m?`disable`:`enable`}`,{method:`PATCH`}),G(m?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,a)),disabled:!!o,children:[m?(0,q.jsx)(fe,{className:`mr-1.5 h-3.5 w-3.5`}):(0,q.jsx)(ct,{className:`mr-1.5 h-3.5 w-3.5`}),G(m?`engine.packages.detail.disable`:`engine.packages.detail.enable`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`export`,async()=>{let e=await ma(`${pa}/${encodeURIComponent(p)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${p}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},G(`engine.packages.detail.exported`,a)),disabled:!!o,children:[(0,q.jsx)(E,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(U(`engine.packages.detail.deleteConfirm`,a,{name:e?.manifest.name||p}))){s(`delete`),u(null);try{await ma(`${pa}/${encodeURIComponent(p)}`,{method:`DELETE`}),i(),r(!1)}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.deleteFailed`,a)})}finally{s(null)}}},disabled:!!o,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,q.jsx)(ut,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,a)]})]})]}),l&&(0,q.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text})]})})}function Sa(){let e=J.useMemo(()=>Rr(),[]),{pathname:t}=a(),n=J.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[r,i]=J.useState([]),[o,s]=J.useState(!0),[c,l]=J.useState(null),[u,d]=J.useState(``),[f,p]=J.useState(!1),[m,h]=J.useState(!1),[g,_]=J.useState(null),[v,y]=J.useState(!1),b=J.useRef(null),[x,S]=J.useState(!1),[C,w]=J.useState(null),T=J.useCallback(async()=>{s(!0),l(null);try{let e=await ma(pa),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),i(t)}catch(t){l(t?.message??G(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);J.useEffect(()=>{T()},[T]),J.useEffect(()=>{if(!g)return;let e=r.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[r,g]);let E=J.useMemo(()=>{let e=u.trim().toLowerCase();return r.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[r,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(G(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(G(`engine.packages.import.invalidPackage`,e));w({kind:`ok`,text:U(`engine.packages.import.success`,e,{id:(await ma(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})}))?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??G(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=r.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,q.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,q.jsx)(Yn,{className:`h-5 w-5`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:G(`engine.packages.title`,e)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.description`,e)})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,q.jsx)(ie,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),G(`engine.packages.refresh`,e)]}),(0,q.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,q.jsx)(Qe,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,q.jsxs)(z,{size:`sm`,onClick:()=>h(!0),children:[(0,q.jsx)(L,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.new`,e)]})]})]}),C&&(0,q.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${C.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:C.text}),(0,q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,q.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,q.jsx)(Ze,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Qt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,q.jsx)(V,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:U(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,q.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,q.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,q.jsx)(Ne,{className:`h-10 w-full`},e))}):c?(0,q.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,q.jsx)(I,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{children:c})]}):E.length===0?(0,q.jsx)(`div`,{className:`p-8`,children:(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:G(`engine.packages.empty`,e)}),(0,q.jsx)(gr,{children:r.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,q.jsxs)(On,{children:[(0,q.jsx)($n,{children:(0,q.jsxs)(Ut,{children:[(0,q.jsx)(gn,{children:G(`engine.packages.col.name`,e)}),(0,q.jsx)(gn,{children:`ID`}),(0,q.jsx)(gn,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,q.jsx)(gn,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,q.jsx)(gn,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,q.jsx)(Wn,{children:E.map(e=>(0,q.jsxs)(Ut,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,q.jsx)(zt,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,q.jsx)(zt,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,q.jsx)(zt,{children:e.manifest.version||`—`}),(0,q.jsx)(zt,{children:(0,q.jsx)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(zt,{children:(0,q.jsx)(ga,{pkg:e})})]},e.manifest.id))})]})}),(0,q.jsx)(ya,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,q.jsx)(xa,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var Ca=new Set([`field`,`package`]),wa={data:ht,ui:st,automation:ar,ai:mn,system:Nt,platform:Nt,identity:$t,security:$t},Ta={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},Ea=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Da=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Oa={object:Ge,dashboard:de,page:A,report:ye,record:Te,metadata:st};function ka(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function Aa(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function ja(){let e=Tr(),{loading:t,entries:n}=Ur(e),{recentItems:r}=wr(),i=J.useMemo(()=>Rr(),[]),[a,o]=s(),[l,u]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),u(i.map(e=>({id:e.id,name:e.name})))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=a.get(`package`),f=J.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);J.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(a);e.set(`package`,l[0].id),o(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Er(e,`warning`,f??void 0),b=J.useMemo(()=>n.filter(e=>Ca.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,n,v]),x=J.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=J.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(Ea.indexOf(e)===-1?99:Ea.indexOf(e))-(Ea.indexOf(t)===-1?99:Ea.indexOf(t)))},[b,_]),C=J.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return Da.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:G(`engine.home.loading`,i)}):(0,q.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,q.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,q.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,q.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,q.jsxs)(`div`,{className:`max-w-xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,q.jsx)(mn,{className:`h-4 w-4`}),G(ka(),i)]}),(0,q.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:G(`engine.home.subtitle`,i)}),(0,q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,q.jsx)(z,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,q.jsxs)(c,{to:m,children:[(0,q.jsx)(st,{className:`mr-1.5 h-4 w-4`}),G(`engine.home.browseAll`,i)]})}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white/90 backdrop-blur-sm`,children:[(0,q.jsx)(Ze,{className:`h-3.5 w-3.5`}),G(`engine.directory.quickFind`,i),` ⌘⇧M`]})]})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,q.jsx)(Ma,{value:b.length,label:G(`engine.home.statTypes`,i)}),(0,q.jsx)(Ma,{value:x.length,label:G(`engine.home.statWritable`,i)}),(0,q.jsx)(Ma,{value:l.length,label:G(`engine.home.statPackages`,i)})]})]})]}),(0,q.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,q.jsx)(Na,{icon:st,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,i),to_link:m}),(0,q.jsx)(Na,{icon:R,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,i),to_link:m}),(0,q.jsx)(Na,{icon:Yn,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:G(`engine.home.statPackages`,i),to_link:h}),(0,q.jsxs)(c,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,q.jsx)(R,{className:`h-5 w-5`}):(0,q.jsx)(I,{className:`h-5 w-5`})}),(0,q.jsx)(At,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?G(`engine.home.allHealthy`,i):w}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,i)})]})]})]}),C.length>0&&(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon:L,title:G(`engine.home.quickActions`,i),hint:G(`engine.home.quickActionsHint`,i)}),(0,q.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,q.jsx)(z,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-transparent bg-muted hover:bg-primary/10 hover:text-primary`,children:(0,q.jsxs)(c,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),U(`engine.home.newItem`,i,{label:zr(e.type,i,e.label)})]})},e.type))})]}),(0,q.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,q.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,q.jsx)(Pa,{icon:st,title:G(`engine.home.explore`,i),hint:G(`engine.home.exploreHint`,i)}),(0,q.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,q.jsx)(Fa,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:p},e))})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon:Ln,title:G(`engine.home.recent`,i)}),(0,q.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:r.length===0?(0,q.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:G(`engine.home.recentEmpty`,i)}):(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:r.slice(0,8).map(e=>{let t=Oa[e.type]??Te;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(c,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,q.jsx)(t,{className:`h-4 w-4`})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Aa(e.visitedAt,i)})]}),(0,q.jsx)(At,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,q.jsx)(oa,{})]})}function Ma({value:e,label:t}){return(0,q.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,q.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function Na({icon:e,from:t,to:n,value:r,label:i,to_link:a}){return(0,q.jsxs)(c,{to:a,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${n} text-white shadow-sm`,children:(0,q.jsx)(e,{className:`h-5 w-5`})}),(0,q.jsx)(At,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:r}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})}function Pa({icon:e,title:t,hint:n}){return(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,q.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,q.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function Fa({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=wa[e]??Te,o=Ta[e]??Ta.other,s=t.slice(0,6),l=t.length-s.length;return(0,q.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${o.ring}`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${o.from} ${o.to} text-white shadow-sm`,children:(0,q.jsx)(a,{className:`h-[18px] w-[18px]`})}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ir(e,r)}),(0,q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,G(`engine.home.typesLower`,r)]})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[s.map(e=>(0,q.jsxs)(c,{to:`metadata/${encodeURIComponent(e.type)}${i}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:zr(e.type,r,e.label)}),(0,q.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:n[e.type]??0})]},e.type)),l>0&&(0,q.jsxs)(c,{to:`metadata${i}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${o.text} hover:underline`,children:[`+`,l]})]})]})}function Ia({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:o}){let s=e?.type??``,l=J.useMemo(()=>Rr(),[]),u=zr(s,l,e?.label),{pathname:d}=a(),f=J.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,q.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground shrink-0`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(rt,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(c,{to:`${f}/${encodeURIComponent(s)}`,className:`hover:text-foreground shrink-0`,children:u}),(0,q.jsx)(rt,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),i]})]}):(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(rt,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium`,children:u})]}),(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:u}),(0,q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:s}),e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),i]})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:o})]})}var La={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function Ra(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function za({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=J.useState(null),o=J.useMemo(()=>d(),[]),s=J.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(s.length===0)return null;let c=async e=>{let t=e.label??e.name;if(e.type!==`api`){xr.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i=e.params??{},s={recordId:n,origin:window.location.origin},c=Ra(e.target??``,s,i);if(!c){xr.error(`Action “${t}” has no target.`);return}let l=``.replace(/\/+$/,``),u=/^https?:\/\//i.test(c)?c:`${l}${c}`,d=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:d,headers:{"Content-Type":`application/json`},credentials:`include`};d!==`GET`&&d!==`DELETE`&&(n.body=JSON.stringify(i));let a=await o(u,n),s=null;try{s=await a.json()}catch{}if(!a.ok||s&&s.success===!1){let e=s?.error||s?.message||`HTTP ${a.status} ${a.statusText}`.trim();xr.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;xr.success(c),e.refreshAfter&&r?.()}catch(e){xr.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,q.jsx)(q.Fragment,{children:s.map(e=>{let t=e.icon?si(e.icon):null,n=i===e.name;return(0,q.jsxs)(z,{size:`sm`,variant:La[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,q.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,q.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)})})}function Ba(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var Va=new Map;function Ha(e){let t=Va.get(e.type);if(!t){Va.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Va.set(e.type,n)}function Ua(e){return Va.get(e)}function Wa(e){let t=[];for(let n of Va.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function Ga(e,t){let n=Va.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Ka(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function qa({type:e}){let t=i(),n=e??t.type??``;if(n===`package`)return(0,q.jsx)(r,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let a=Ua(n);if(a?.ListPage){let e=a.ListPage;return(0,q.jsx)(e,{type:n})}return(0,q.jsx)(Ja,{type:n})}function Ja({type:e}){let t=u(),n=Tr(),{entries:r}=Ur(n),i=r.find(t=>t.type===e),a=Ga(e,i),[o,l]=J.useState([]),[d,f]=J.useState(!0),[p,m]=J.useState(null),[h,g]=J.useState(``),[_,v]=J.useState(`all`),[y,x]=s(),[S,C]=J.useState(0),[w,T]=J.useState(null);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await n.list(`package`);if(e)return;let r=new Set([`system`,`cloud`]),i=(t??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),T(i.map(e=>({id:e.id,name:e.name})))}catch{e||T([])}})(),()=>{e=!0}},[n]);let E=y.get(`package`),O=J.useMemo(()=>w?E&&w.some(e=>e.id===E)?E:w[0]?.id??null:null,[w,E]);J.useEffect(()=>{if(!w||w.length===0||E&&w.some(e=>e.id===E))return;let e=new URLSearchParams(y);e.set(`package`,w[0].id),x(e,{replace:!0})},[w,E]);let k=O?`?package=${encodeURIComponent(O)}`:``;J.useEffect(()=>{let t=!1;return f(!0),m(null),(async()=>{try{let r=await n.list(e);if(t)return;l((r??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Ka(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,S]);let A=a.searchableFields??[`name`,`label`,`description`],j=J.useMemo(()=>o.filter(e=>{if(a.listFilter&&!a.listFilter(e.item)||!O)return!1;let t=e.item?._packageId;return(!t||t===`sys_metadata`?null:t)===O}),[o,O,a]),ee=j.filter(e=>!(!Wr(e.item,h,A)||_!==`all`&&e.source!==_)),te=J.useMemo(()=>{let e={all:j.length,artifact:0,runtime:0};for(let t of j)e[t.source]++;return e},[j]),ne=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[j]),re=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[j]),M=a.listColumns??Ya(a.primaryKey??`name`),N=Rr(),ae=zr(e,N,i?.label??e),oe=e=>{let t=`engine.list.col.${e.key}`,n=G(t,N);return n===t?e.label:n};return(0,q.jsx)(Ia,{entry:i??{type:e,label:e},stats:[{label:G(`engine.list.items`,N),value:j.length},{label:G(`engine.list.filtered`,N),value:ee.length},...ne>0?[{label:G(`engine.list.invalid`,N),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,q.jsx)(I,{className:`w-3.5 h-3.5`}),ne]})}]:[],...re>0?[{label:G(`engine.list.warnings`,N),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,q.jsx)(I,{className:`w-3.5 h-3.5`}),re]})}]:[]],actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(za,{entry:i,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,N),children:(0,q.jsx)(ie,{className:`h-4 w-4`})}),(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsxs)(z,{size:`sm`,variant:a.createFields?`default`:`outline`,onClick:()=>t(`./new${k}`),title:a.createFields?U(`engine.list.createHint`,N,{type:ae}):void 0,children:[(0,q.jsx)(L,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,N)]})]}),children:(0,q.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,q.jsx)(Ze,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.list.search`,N),value:h,onChange:e=>g(e.target.value)})]}),(0,q.jsxs)(D,{value:_,onValueChange:v,children:[(0,q.jsx)(ot,{className:`w-[180px]`,children:(0,q.jsx)(vt,{})}),(0,q.jsxs)(ft,{children:[(0,q.jsxs)(he,{value:`all`,children:[G(`engine.list.allSources`,N),` (`,te.all,`)`]}),(0,q.jsxs)(he,{value:`artifact`,children:[G(`engine.list.source.artifact`,N),` (`,te.artifact,`)`]}),(0,q.jsxs)(he,{value:`runtime`,children:[G(`engine.list.source.runtime`,N),` (`,te.runtime,`)`]})]})]})]}),(d||w===null)&&(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[G(`engine.edit.loading`,N),` `,e,`…`]}),p&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:p}),!d&&!p&&w!==null&&w.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!d&&!p&&w!==null&&w.length>0&&ee.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:j.length===0?U(`engine.list.emptyType`,N,{type:ae}):U(`engine.list.emptyQuery`,N,{query:h})}),(0,q.jsx)(gr,{children:a.emptyStateHint??(i?.allowOrgOverride||i?.allowRuntimeCreate?U(`engine.list.createHint`,N,{type:ae}):G(`engine.list.readOnlyHint`,N))}),j.length===0&&(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsxs)(z,{onClick:()=>t(`./new${k}`),children:[(0,q.jsx)(L,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,N)]})})]}),!d&&ee.length>0&&(0,q.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[M.map(e=>(0,q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:oe(e)},e.key)),(0,q.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:G(`engine.list.col.source`,N)})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:ee.map((e,t)=>{let n=a.primaryKey??`name`,r=String(e.item[n]??`(unnamed-${t})`),i=e.item._packageId,o=i&&i!==`sys_metadata`?`?package=${encodeURIComponent(i)}`:k,s=e.diagnostics?.valid===!1,l=e.diagnostics?.errors??[],u=e.diagnostics?.warnings??[],d=!s&&u.length>0,f=s?l.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
3
|
+
`)+(l.length>3?`\n+${l.length-3} more`:``):d?u.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
4
|
+
`)+(u.length>3?`\n+${u.length-3} more`:``):``;return(0,q.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(s?`bg-destructive/[0.04]`:d?`bg-amber-500/[0.05]`:``),children:[M.map((t,n)=>{let i=e.item[t.key],a=t.render?t.render(i,e.item):Xa(i);return(0,q.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s&&(0,q.jsx)(`span`,{className:`inline-flex`,"aria-label":G(`engine.list.invalidTitle`,N),title:`${U(`engine.list.invalidCount`,N,{count:l.length})}\n${f}`,children:(0,q.jsx)(I,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),d&&(0,q.jsx)(`span`,{className:`inline-flex`,"aria-label":G(`engine.list.warnTitle`,N),title:`${U(`engine.list.warnCount`,N,{count:u.length})}\n${f}`,children:(0,q.jsx)(I,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,q.jsx)(c,{to:`./${encodeURIComponent(r)}${o}`,className:`text-primary hover:underline font-mono`,children:a})]}):a},t.key)}),(0,q.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,q.jsx)(`span`,{className:`inline-flex items-center mr-1 text-amber-600 dark:text-amber-400`,title:e.item._lockReason??`_lock=${String(e.item._lock)}`,children:(0,q.jsx)(un,{className:`h-3 w-3`})}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] `+(e.source===`artifact`?`border-sky-500/50 text-sky-700 dark:text-sky-300`:`border-emerald-500/50 text-emerald-700 dark:text-emerald-300`),title:e.source===`artifact`?`${G(`engine.list.source.artifactDesc`,N)}${e.item._packageId?` (${e.item._packageId})`:``}`:G(`engine.list.source.runtimeDesc`,N),children:G(`engine.list.source.${e.source}`,N)})]})]},r+t)})})]})})]})})}function Ya(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Xa(e){if(e==null||e===``)return(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,q.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Za={unchanged:{badge:`bg-muted text-muted-foreground border border-border`,row:``},modified:{badge:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,row:`bg-amber-50/50 dark:bg-amber-950/20`},added:{badge:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,row:`bg-emerald-50/50 dark:bg-emerald-950/20`},removed:{badge:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`,row:`bg-rose-50/50 dark:bg-rose-950/20`}};function Qa(e,t){let n=$a(e)?e:{},r=$a(t)?t:{},i=new Set([...Object.keys(n),...Object.keys(r)]),a=[];for(let e of i){let t=e in n,i=e in r,o=n[e],s=r[e],c;c=t&&!i?`removed`:!t&&i?`added`:eo(o)===eo(s)?`unchanged`:`modified`,a.push({key:e,status:c,codeValue:o,effectiveValue:s})}let o={modified:0,added:1,removed:2,unchanged:3};return a.sort((e,t)=>o[e.status]===o[t.status]?e.key.localeCompare(t.key):o[e.status]-o[t.status]),a}function $a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function eo(e){try{return JSON.stringify(e,(e,t)=>$a(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function to(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function no(e,t){if(e==null)return 0;let n=0;for(let r of Qa(e,t))r.status!==`unchanged`&&(n+=1);return n}function ro({layered:e,loading:t,locale:n}){if(t)return(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.edit.loading`,n)});if(!e)return(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,q.jsxs)(Tn,{defaultValue:`diff`,className:`w-full`,children:[(0,q.jsxs)(ln,{className:`grid grid-cols-4 w-fit`,children:[(0,q.jsx)(jt,{value:`diff`,children:G(`engine.layers.diff`,n)}),(0,q.jsxs)(jt,{value:`code`,children:[G(`engine.layers.code`,n),(0,q.jsx)(b,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,q.jsxs)(jt,{value:`overlay`,children:[G(`engine.layers.overlay`,n),r?(0,q.jsx)(b,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,q.jsx)(b,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,q.jsxs)(jt,{value:`effective`,children:[G(`engine.layers.effective`,n),(0,q.jsx)(b,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,q.jsx)(Rn,{value:`diff`,className:`mt-3`,children:(0,q.jsx)(io,{code:e.code,effective:e.effective,locale:n})}),(0,q.jsx)(Rn,{value:`code`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.code,emptyHint:G(`engine.layers.diff.noBaseline`,n)})}),(0,q.jsx)(Rn,{value:`overlay`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.overlay,emptyHint:G(`engine.layers.diff.noChanges`,n)})}),(0,q.jsx)(Rn,{value:`effective`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function io({code:e,effective:t,locale:n}){let[r,i]=J.useState(!1);if(e==null)return(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let a=J.useMemo(()=>Qa(e,t),[e,t]),o=J.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]),s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:U(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,q.jsx)(Qt,{checked:r,onCheckedChange:i,"aria-label":G(`engine.layers.diff.showUnchanged`,n)}),G(`engine.layers.diff.showUnchanged`,n),(0,q.jsx)(b,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noChanges`,n)}):(0,q.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] bg-muted/50 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.field`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.code`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.effective`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.status`,n)})]}),(0,q.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Za[e.status];return(0,q.jsxs)(`div`,{className:H(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,q.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,q.jsx)(ao,{value:e.codeValue,muted:e.status===`added`}),(0,q.jsx)(ao,{value:e.effectiveValue,muted:e.status===`removed`}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:(0,q.jsx)(`span`,{className:H(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:G(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function ao({value:e,muted:t}){let n=to(e);return(0,q.jsx)(`div`,{className:H(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function oo({payload:e,emptyHint:t}){if(e==null)return(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,q.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var so={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},co={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function lo(e,t){return G(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function uo(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function fo(e,t){let n=0;for(let r of Qa(e,t))r.status!==`unchanged`&&(n+=1);return n}function po({published:e,draft:t,locale:n,className:r}){let i=J.useMemo(()=>Qa(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:G(`designer.draftReview.empty`,n)}):(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${co[t]}`,children:[(0,q.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${so[t]}`,children:lo(t,n)}),(0,q.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,q.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:uo(e.effectiveValue)}):t===`removed`?(0,q.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:uo(e.codeValue)}):(0,q.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:uo(e.codeValue)}),(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,q.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:uo(e.effectiveValue)})]})]},e.key)})})}function mo(e){if(typeof e!=`string`)return``;let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``);return/^\d/.test(t)&&(t=`n_${t}`),t.length>64&&(t=t.slice(0,64).replace(/_+$/g,``)),t}function ho(e){if(typeof e!=`string`)return``;let t=e.trim();return t?!/[A-Za-z]/.test(t)||/(s|ses|xes|zes|ches|shes|ies)$/i.test(t)?t:/[^aeiou]y$/i.test(t)?t.replace(/y$/i,`ies`):/(s|x|z|ch|sh)$/i.test(t)?`${t}es`:`${t}s`:``}function go(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function _o(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function vo(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return mo(n);case`plural-en`:return ho(n);case`titlecase`:return go(n);case`first-token`:return _o(n);default:return n}}function yo(e){let{rules:t,draft:n,onPatch:r,enabled:i=!0}=e,a=(0,J.useRef)(new Set),o=(0,J.useRef)({}),s=(0,J.useCallback)(e=>{a.current.add(e)},[]);return(0,J.useEffect)(()=>{if(!i||!t||t.length===0)return;let e={},s=o.current,c={};for(let r of t){let t=n[r.from];if(c[r.from]=t,Object.is(s[r.from],t)||r.untilUserEdits!==!1&&a.current.has(r.to)||r.to in e)continue;let i=vo(r.transform,t);n[r.to]!==i&&(e[r.to]=i)}o.current={...s,...c},Object.keys(e).length>0&&r(e)},[n,i]),{markTouched:s,touched:a.current}}function bo(e,t){let n=e?Object.keys(e):[],r=[],i=e=>{!r.includes(e)&&n.includes(e)&&r.push(e)};for(let e of n)t?.includes(e)&&i(e);for(let e of[`label`,`pluralLabel`,`name`,`description`])i(e);return r}function xo({type:e,name:t,parentItem:n,onOpen:r}){let i=Tr(),a=u(),o=J.useMemo(()=>Wa(e),[e]),[s,c]=J.useState([]),[l,d]=J.useState(``),[f,p]=J.useState({});if(J.useEffect(()=>{if(o.length===0){c([]);return}let e=!1,r=[...o].sort((e,t)=>(e.anchor.order??999)-(t.anchor.order??999)).map(e=>{if(e.anchor.source===`embedded`){let t=e.anchor.extract&&n?e.anchor.extract(n):[];return{childType:e.type,anchor:e.anchor,loading:!1,error:null,items:t.map(So)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return c(r),Promise.all(r.map(async n=>{if(n.anchor.source===`embedded`)return n;try{let r=await i.list(n.childType);if(e)return n;let a=n.anchor.match??(()=>!1),o=r.filter(e=>a(e,t)).map(e=>So(e));return{...n,loading:!1,items:o}}catch(t){return e?n:{...n,loading:!1,error:t instanceof Error?t.message:String(t)}}})).then(t=>{e||c(t)}),()=>{e=!0}},[i,e,t,o,n]),o.length===0)return(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`No related metadata`}),(0,q.jsxs)(gr,{children:[`No metadata types are configured to anchor at `,(0,q.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,q.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let m=s.reduce((e,t)=>e+t.items.length,0),h=s.some(e=>e.loading),g=l.trim().toLowerCase();return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,q.jsx)(Ze,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,q.jsx)(B,{placeholder:`Search related…`,value:l,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),s.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,o=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,q.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!o})),children:[(0,q.jsx)(rt,{className:H(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>{if(n.anchor.source===`embedded`){if(typeof window<`u`){let e=new URL(window.location.href);e.searchParams.set(`tab`,`form`),e.searchParams.delete(`open`),window.location.assign(e.toString())}return}a(`../../${encodeURIComponent(n.childType)}/_new?anchor=${encodeURIComponent(`${e}:${t}`)}`)},title:n.anchor.source===`embedded`?`Edit in Form tab`:`New ${n.childType}`,children:(0,q.jsx)(L,{className:`h-3.5 w-3.5`})})]}),!o&&(0,q.jsxs)(`div`,{children:[n.loading&&(0,q.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,q.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:g?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,q.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,q.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,q.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,q.jsx)(`th`,{className:`w-8`})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,q.jsxs)(`tr`,{role:`button`,tabIndex:0,onClick:()=>r(n.anchor.source===`embedded`?{kind:`embedded`,parentType:e,parentName:t,groupLabel:n.anchor.groupLabel??n.childType,itemName:i.name,raw:i.raw,editAs:n.anchor.editAs,embeddedPath:n.anchor.embeddedPath}:{kind:`metadata`,type:n.childType,name:i.name}),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&e.currentTarget.click()},className:`hover:bg-accent/50 cursor-pointer`,children:[(0,q.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,q.jsx)(`td`,{className:`px-3 py-1.5 text-xs text-muted-foreground truncate max-w-0`,children:i.label&&i.label!==i.name?i.label:``}),(0,q.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,q.jsx)(_e,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function So(e){return{name:Co(e,[`name`,`id`,`key`])??`(unnamed)`,label:Co(e,[`label`,`title`,`displayName`]),description:Co(e,[`description`,`summary`]),raw:e}}function Co(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function wo({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=J.useMemo(()=>Rr(),[]),c=Tr(),{entries:l}=Ur(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?Eo[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=J.useState(a),[g,_]=J.useState(!1),[v,y]=J.useState(null),[b,x]=J.useState([]),[S,C]=J.useState(null);J.useEffect(()=>{h(a),y(null),x([]),C(null)},[a,r,e,t]);let w=u!=null&&!u.allowOrgOverride&&!u.allowRuntimeCreate;async function T(){if(!n){y(G(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=To(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:kr(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?G(`engine.validation.failedOne`,s):U(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,q.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:G(`engine.embedded.saved`,s)}),w&&(0,q.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:G(`engine.embedded.readOnlyParent`,s)}),(0,q.jsx)(Fr,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,q.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,q.jsxs)(z,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)(tt,{className:`h-4 w-4 mr-1`}),U(`engine.embedded.saveIntoParent`,s,{parentType:e})]})}),!n&&(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:G(`engine.embedded.readOnly`,s)}),(0,q.jsx)(`div`,{children:G(`engine.embedded.noPathHint`,s)})]})]}):(0,q.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:U(`engine.embedded.noSchema`,s,{type:i??`this item`,target:`${e}/${t}.${n}.${r}`})}),(0,q.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(m,null,2),onChange:e=>{try{h(JSON.parse(e.target.value)),y(null)}catch(e){y(`${G(`engine.form.invalidJson`,s)}: ${e.message}`)}}}),v&&(0,q.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,q.jsx)(I,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsxs)(z,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)(tt,{className:`h-4 w-4 mr-1`}),U(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function To(e,t,n,r){let i=t.split(`.`),a=structuredClone(e),o=a;for(let e=0;e<i.length-1;e++)o[i[e]]??(o[i[e]]={}),o=o[i[e]];let s=i[i.length-1],c=o[s];if(Array.isArray(c)){let e=c.findIndex(e=>e&&typeof e==`object`&&e.name===n);e>=0?c[e]=r:c.push(r)}else if(c&&typeof c==`object`){let{name:e,...t}=r;c[n]=t}else{let{name:e,...t}=r;o[s]={[n]:t}}return a}var Eo={index:{schema:{type:`object`,required:[`fields`],properties:{name:{type:`string`,title:`Name`,description:`Synthesised from columns if omitted (e.g. idx_email).`},fields:{type:`array`,title:`Fields`,description:`Columns to index, in order.`,items:{type:`string`}},type:{type:`string`,title:`Algorithm`,enum:[`btree`,`hash`,`gin`,`gist`,`brin`],default:`btree`},unique:{type:`boolean`,title:`Unique`,description:`Enforce uniqueness across the indexed columns.`},where:{type:`string`,title:`Partial-index predicate`,description:`Optional WHERE clause for a partial index.`}}}}};function Do({target:e,onClose:t,parentContext:n}){let r=u(),i=e?.kind===`metadata`,a=e?.kind===`embedded`,o=i?e.type:a?e.groupLabel:``,s=i?e.name:a?e.itemName:``;return(0,q.jsx)(Ve,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(ae,{side:`right`,className:H(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(b,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,q.jsx)(Ye,{className:`font-mono text-base truncate`,children:s}),(0,q.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,q.jsx)(_e,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,q.jsxs)(be,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,q.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,q.jsx)(Ss,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,q.jsx)(wo,{parentType:e.parentType,parentName:e.parentName,embeddedPath:e.embeddedPath,itemName:e.itemName,editAs:e.editAs,initialRaw:e.raw},`${e.parentType}/${e.parentName}/${e.embeddedPath}/${e.itemName}`)]})]})})}function Oo({type:e,name:t}){let n=i(),r=e??n.type??``,a=t??n.name??``,o=u(),s=Tr(),{entries:c}=Ur(s),l=c.find(e=>e.type===r),[d,f]=J.useState(0),[p,m]=J.useState(0);return(0,q.jsx)(Ia,{entry:l??{type:r,label:r},itemName:a,subtitle:`Version history`,stats:[{label:`Events`,value:p}],actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,q.jsx)(Bn,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+1),children:(0,q.jsx)(ie,{className:`h-4 w-4`})})]}),children:(0,q.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,q.jsx)(ko,{type:r,name:a,refreshKey:d,onCount:m,client:s,onRollback:()=>f(e=>e+1)})})})}function ko({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=J.useState([]),[u,d]=J.useState(!0),[f,p]=J.useState(null),[m,h]=J.useState(null),[g,_]=J.useState(null),[v,y]=J.useState(0);J.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function x(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,q.jsxs)(q.Fragment,{children:[u&&(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:f}),!u&&!f&&c.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`No history yet`}),(0,q.jsx)(gr,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,q.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:c.map((e,t)=>{let n=m===t,r=e.op??e.kind,i=e.ts??e.at,o=!!a&&typeof e.version==`number`&&r!==`delete`&&r!==`tombstone`;return(0,q.jsxs)(`li`,{className:`relative`,children:[(0,q.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>h(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&h(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,q.jsx)(b,{className:`text-[10px] `+(r===`delete`||r===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:r===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:r===`publish`?`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`:r===`revert`?`bg-amber-100 text-amber-900 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(r)}),e.actor&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,q.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:Ao(i)}),o&&(0,q.jsx)(z,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),x(e.version)},children:g===e.version?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(C,{className:`h-3.5 w-3.5`})})]}),n&&(0,q.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:jo(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Ao(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function jo(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Mo(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function No(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:$t},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:nn},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:Ot}},n=t[e]??t.allowed;return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${n.cls}`,children:[(0,q.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function Po({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=J.useState(!1),[o,s]=J.useState(null),[c,l]=J.useState(null),u=J.useCallback(async()=>{a(!0),s(null);try{l((await n.audit(e,t,{limit:100})).events??[])}catch(e){s(String(e?.message??e)),l([])}finally{a(!1)}},[n,e,t]);return J.useEffect(()=>{u()},[u]),(0,q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,G(`engine.edit.auditCount`,r)]}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:G(`engine.edit.refresh`,r),children:[i?(0,q.jsx)(F,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(ie,{className:`h-3 w-3`}),G(`engine.edit.refresh`,r)]})]}),o&&(0,q.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,q.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,q.jsx)(F,{className:`mr-2 h-3 w-3 animate-spin`}),G(`engine.edit.loading`,r)]}):!c||c.length===0?(0,q.jsxs)(Ke,{className:`py-10`,children:[(0,q.jsx)(ue,{children:G(`engine.edit.auditEmptyTitle`,r)}),(0,q.jsx)(gr,{children:G(`engine.edit.auditEmptyDescription`,r)})]}):(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColTime`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColActor`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOperation`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOutcome`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColLock`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColNote`,r)})]})}),(0,q.jsx)(`tbody`,{children:c.map(e=>(0,q.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,q.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:Mo(e.occurredAt)}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:No(e.outcome)}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,q.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,q.jsx)(`td`,{className:`max-w-[28ch] truncate px-2 py-1.5 text-muted-foreground`,title:e.note??e.code,children:e.note??e.code})]},String(e.id)))})]})})]})}var Fo=new Map;function Y(e,t){Fo.set(e,t)}function Io(e){return Fo.get(e)}var Lo=new Map;function Ro(e,t){Lo.set(e,t)}function zo(e){return Lo.get(e)}var Bo=new Map;function Vo(e,t){Bo.set(e,t)}function Ho(e){return Bo.get(e)}function Uo(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Ko(e.charCodeAt(r)))for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Ko(e.charCodeAt(r))){for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
5
|
+
`;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(Go(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(Wo(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Wo(t));return o=15}if(Go(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
6
|
+
`),s++,l=r,o=14;switch(t){case 123:return r++,o=1;case 125:return r++,o=2;case 91:return r++,o=3;case 93:return r++,o=4;case 58:return r++,o=6;case 44:return r++,o=5;case 34:return r++,i=h(),o=10;case 47:let c=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Go(e.charCodeAt(r));)r++;return i=e.substring(c,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;let t=n-1,a=!1;for(;r<t;){let t=e.charCodeAt(r);if(t===42&&e.charCodeAt(r+1)===47){r+=2,a=!0;break}r++,Go(t)&&(t===13&&e.charCodeAt(r)===10&&r++,s++,l=r)}return a||(r++,d=1),i=e.substring(c,r),o=13}return i+=String.fromCharCode(t),r++,o=16;case 45:if(i+=String.fromCharCode(t),r++,r===n||!Ko(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=m(),o=11;default:for(;r<n&&_(t);)r++,t=e.charCodeAt(r);if(a!==r){switch(i=e.substring(a,r),i){case`true`:return o=8;case`false`:return o=9;case`null`:return o=7}return o=16}return i+=String.fromCharCode(t),r++,o=16}}function _(e){if(Wo(e)||Go(e))return!1;switch(e){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function v(){let e;do e=g();while(e>=12&&e<=15);return e}return{setPosition:p,getPosition:()=>r,scan:t?v:g,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>a,getTokenLength:()=>r-a,getTokenStartLine:()=>c,getTokenStartCharacter:()=>a-u,getTokenError:()=>d}}function Wo(e){return e===32||e===9}function Go(e){return e===10||e===13}function Ko(e){return e>=48&&e<=57}var qo;(function(e){e[e.lineFeed=10]=`lineFeed`,e[e.carriageReturn=13]=`carriageReturn`,e[e.space=32]=`space`,e[e._0=48]=`_0`,e[e._1=49]=`_1`,e[e._2=50]=`_2`,e[e._3=51]=`_3`,e[e._4=52]=`_4`,e[e._5=53]=`_5`,e[e._6=54]=`_6`,e[e._7=55]=`_7`,e[e._8=56]=`_8`,e[e._9=57]=`_9`,e[e.a=97]=`a`,e[e.b=98]=`b`,e[e.c=99]=`c`,e[e.d=100]=`d`,e[e.e=101]=`e`,e[e.f=102]=`f`,e[e.g=103]=`g`,e[e.h=104]=`h`,e[e.i=105]=`i`,e[e.j=106]=`j`,e[e.k=107]=`k`,e[e.l=108]=`l`,e[e.m=109]=`m`,e[e.n=110]=`n`,e[e.o=111]=`o`,e[e.p=112]=`p`,e[e.q=113]=`q`,e[e.r=114]=`r`,e[e.s=115]=`s`,e[e.t=116]=`t`,e[e.u=117]=`u`,e[e.v=118]=`v`,e[e.w=119]=`w`,e[e.x=120]=`x`,e[e.y=121]=`y`,e[e.z=122]=`z`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.asterisk=42]=`asterisk`,e[e.backslash=92]=`backslash`,e[e.closeBrace=125]=`closeBrace`,e[e.closeBracket=93]=`closeBracket`,e[e.colon=58]=`colon`,e[e.comma=44]=`comma`,e[e.dot=46]=`dot`,e[e.doubleQuote=34]=`doubleQuote`,e[e.minus=45]=`minus`,e[e.openBrace=123]=`openBrace`,e[e.openBracket=91]=`openBracket`,e[e.plus=43]=`plus`,e[e.slash=47]=`slash`,e[e.formFeed=12]=`formFeed`,e[e.tab=9]=`tab`})(qo||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var Jo=200;Array(Jo).fill(0).map((e,t)=>`
|
|
7
|
+
`+` `.repeat(t)),Array(Jo).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Jo).fill(0).map((e,t)=>`\r
|
|
8
|
+
`+` `.repeat(t)),Array(Jo).fill(0).map((e,t)=>`
|
|
9
|
+
`+` `.repeat(t)),Array(Jo).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Jo).fill(0).map((e,t)=>`\r
|
|
10
|
+
`+` `.repeat(t));var Yo;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Yo||={});function Xo(e,t=[],n=Yo.DEFAULT){let r={type:`array`,offset:-1,length:-1,children:[],parent:void 0};function i(e){r.type===`property`&&(r.length=e-r.offset,r=r.parent)}function a(e){return r.children.push(e),e}Qo(e,{onObjectBegin:e=>{r=a({type:`object`,offset:e,length:-1,parent:r,children:[]})},onObjectProperty:(e,t,n)=>{r=a({type:`property`,offset:t,length:-1,parent:r,children:[]}),r.children.push({type:`string`,value:e,offset:t,length:n,parent:r})},onObjectEnd:(e,t)=>{i(e+t),r.length=e+t-r.offset,r=r.parent,i(e+t)},onArrayBegin:(e,t)=>{r=a({type:`array`,offset:e,length:-1,parent:r,children:[]})},onArrayEnd:(e,t)=>{r.length=e+t-r.offset,r=r.parent,i(e+t)},onLiteralValue:(e,t,n)=>{a({type:$o(e),offset:t,length:n,parent:r,value:e}),i(t+n)},onSeparator:(e,t,n)=>{r.type===`property`&&(e===`:`?r.colonOffset=t:e===`,`&&i(t))},onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n);let o=r.children[0];return o&&delete o.parent,o}function Zo(e,t){if(!e)return;let n=e;for(let e of t)if(typeof e==`string`){if(n.type!==`object`||!Array.isArray(n.children))return;let t=!1;for(let r of n.children)if(Array.isArray(r.children)&&r.children[0].value===e&&r.children.length===2){n=r.children[1],t=!0;break}if(!t)return}else{let t=e;if(n.type!==`array`||t<0||!Array.isArray(n.children)||t>=n.children.length)return;n=n.children[t]}return n}function Qo(e,t,n=Yo.DEFAULT){let r=Uo(e,!1),i=[],a=0;function o(e){return e?()=>a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function s(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function c(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function l(e){return e?()=>{a>0?a++:e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(a=1)}:()=>!0}function u(e){return e?()=>{a>0&&a--,a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}let d=l(t.onObjectBegin),f=c(t.onObjectProperty),p=u(t.onObjectEnd),m=l(t.onArrayBegin),h=u(t.onArrayEnd),g=c(t.onLiteralValue),_=s(t.onSeparator),v=o(t.onComment),y=s(t.onError),b=n&&n.disallowComments,x=n&&n.allowTrailingComma;function S(){for(;;){let e=r.scan();switch(r.getTokenError()){case 4:C(14);break;case 5:C(15);break;case 3:C(13);break;case 1:b||C(11);break;case 2:C(12);break;case 6:C(16);break}switch(e){case 12:case 13:b?C(10):v();break;case 16:C(1);break;case 15:case 14:break;default:return e}}}function C(e,t=[],n=[]){if(y(e),t.length+n.length>0){let e=r.getToken();for(;e!==17;){if(t.indexOf(e)!==-1){S();break}else if(n.indexOf(e)!==-1)break;e=S()}}}function w(e){let t=r.getTokenValue();return e?g(t):(f(t),i.push(t)),S(),!0}function T(){switch(r.getToken()){case 11:let e=r.getTokenValue(),t=Number(e);isNaN(t)&&(C(2),t=0),g(t);break;case 7:g(null);break;case 8:g(!0);break;case 9:g(!1);break;default:return!1}return S(),!0}function E(){return r.getToken()===10?(w(!1),r.getToken()===6?(_(`:`),S(),k()||C(4,[],[2,5])):C(5,[],[2,5]),i.pop(),!0):(C(3,[],[2,5]),!1)}function D(){d(),S();let e=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(e||C(4,[],[]),_(`,`),S(),r.getToken()===2&&x)break}else e&&C(6,[],[]);E()||C(4,[],[2,5]),e=!0}return p(),r.getToken()===2?S():C(7,[2],[]),!0}function O(){m(),S();let e=!0,t=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(t||C(4,[],[]),_(`,`),S(),r.getToken()===4&&x)break}else t&&C(6,[],[]);e?(i.push(0),e=!1):i[i.length-1]++,k()||C(4,[],[4,5]),t=!0}return h(),e||i.pop(),r.getToken()===4?S():C(8,[4],[]),!0}function k(){switch(r.getToken()){case 3:return O();case 1:return D();case 10:return w(!0);default:return T()}}return S(),r.getToken()===17?n.allowEmptyContent?!0:(C(4,[],[]),!1):k()?(r.getToken()!==17&&C(9,[],[]),!0):(C(4,[],[]),!1)}function $o(e){switch(typeof e){case`boolean`:return`boolean`;case`number`:return`number`;case`string`:return`string`;case`object`:return e?Array.isArray(e)?`array`:`object`:`null`;default:return`null`}}var es;(function(e){e[e.None=0]=`None`,e[e.UnexpectedEndOfComment=1]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=2]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=3]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=4]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=5]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=6]=`InvalidCharacter`})(es||={});var ts;(function(e){e[e.OpenBraceToken=1]=`OpenBraceToken`,e[e.CloseBraceToken=2]=`CloseBraceToken`,e[e.OpenBracketToken=3]=`OpenBracketToken`,e[e.CloseBracketToken=4]=`CloseBracketToken`,e[e.CommaToken=5]=`CommaToken`,e[e.ColonToken=6]=`ColonToken`,e[e.NullKeyword=7]=`NullKeyword`,e[e.TrueKeyword=8]=`TrueKeyword`,e[e.FalseKeyword=9]=`FalseKeyword`,e[e.StringLiteral=10]=`StringLiteral`,e[e.NumericLiteral=11]=`NumericLiteral`,e[e.LineCommentTrivia=12]=`LineCommentTrivia`,e[e.BlockCommentTrivia=13]=`BlockCommentTrivia`,e[e.LineBreakTrivia=14]=`LineBreakTrivia`,e[e.Trivia=15]=`Trivia`,e[e.Unknown=16]=`Unknown`,e[e.EOF=17]=`EOF`})(ts||={});var ns=Xo,rs=Zo,is;(function(e){e[e.InvalidSymbol=1]=`InvalidSymbol`,e[e.InvalidNumberFormat=2]=`InvalidNumberFormat`,e[e.PropertyNameExpected=3]=`PropertyNameExpected`,e[e.ValueExpected=4]=`ValueExpected`,e[e.ColonExpected=5]=`ColonExpected`,e[e.CommaExpected=6]=`CommaExpected`,e[e.CloseBraceExpected=7]=`CloseBraceExpected`,e[e.CloseBracketExpected=8]=`CloseBracketExpected`,e[e.EndOfFileExpected=9]=`EndOfFileExpected`,e[e.InvalidCommentToken=10]=`InvalidCommentToken`,e[e.UnexpectedEndOfComment=11]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=12]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=13]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=14]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=15]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=16]=`InvalidCharacter`})(is||={});var as=J.lazy(async()=>({default:(await o(()=>import(`./dist-DYcwLEm6.js`),[],import.meta.url)).default}));function os(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function ss(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function cs({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let a=J.useMemo(()=>Rr(),[]),[o,s]=J.useState(()=>os(e)),[c,l]=J.useState(null),u=J.useRef(o),d=J.useRef(null),f=J.useRef(null),[p,m]=J.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);J.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>m(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let h=J.useCallback(()=>{let e=d.current,t=f.current;if(!e||!t)return;let n=e.getModel();if(!n)return;if(!r||r.length===0){t.editor.setModelMarkers(n,`objectui-diagnostics`,[]);return}let i;try{i=ns(o)}catch{i=void 0}let a=r.map(e=>{let r=ss(e.path),a=1,o=1,s=1,c=2,l=i?rs(i,r):void 0;if(l){let e=n.getPositionAt(l.offset),t=n.getPositionAt(l.offset+l.length);a=e.lineNumber,o=e.column,s=t.lineNumber,c=t.column}return{severity:e.severity===`warning`?t.MarkerSeverity.Warning:t.MarkerSeverity.Error,message:e.path?`${e.path}: ${e.message}`:e.message,startLineNumber:a,startColumn:o,endLineNumber:s,endColumn:c,source:`metadata`}});t.editor.setModelMarkers(n,`objectui-diagnostics`,a)},[r,o]);return J.useEffect(()=>{h()},[h]),J.useEffect(()=>{let t=os(e);t!==u.current&&(s(t),u.current=t,l(null))},[e]),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`div`,{className:`border rounded overflow-hidden bg-background`,style:{height:typeof i==`number`?`${i}px`:i},children:(0,q.jsx)(J.Suspense,{fallback:(0,q.jsx)(Ne,{className:`w-full h-full`}),children:(0,q.jsx)(as,{value:o,language:`json`,theme:p,onChange:e=>{let n=e??``;s(n);try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)?(l(null),u.current=n,t(e)):l(G(`engine.form.rootJsonObject`,a))}catch(e){l(e?.message??G(`engine.form.invalidJson`,a))}},onMount:(e,t)=>{d.current=e,f.current=t,setTimeout(h,0)},options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,renderLineHighlight:`line`,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),c&&(0,q.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,q.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,q.jsx)(`span`,{children:c})]})]})}var ls={object:async()=>(await o(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.c);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await o(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.c);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await o(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.c);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await o(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.c);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await o(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await o(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await o(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await o(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await o(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await o(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await o(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.g);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await o(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.i);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await o(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.i);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await o(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.o);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await o(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.o);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await o(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.o);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await o(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await o(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await o(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await o(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await o(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await o(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await o(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-BNd856rx.js`).then(e=>e.a);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},us=new Set([`approval`,`connector_action`]),ds=/^nodes\.(\d+)\.type$/;function fs(e,t){let n=e?.nodes;if(!Array.isArray(n))return;let r=n[t];return typeof r?.type==`string`?r.type:void 0}var ps=new Map;async function ms(e){if(ps.has(e))return ps.get(e)??null;let t=ls[e];if(!t)return ps.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return ps.set(e,r),r}catch{return ps.set(e,null),null}}function hs(e){return e in ls}async function gs(e,t,n){let r=await ms(e);if(!r)return{ok:!0,issues:[]};let i=r.safeParse(t);if(i.success)return{ok:!0,issues:[]};let a=i.error?.issues??[],o=Array.isArray(n?.required)?new Set(n.required.map(e=>String(e))):void 0;if(o&&t&&typeof t==`object`&&!Array.isArray(t)){let e=t;a=a.filter(t=>{let n=t.path??[];if(n.length!==1)return!0;let r=String(n[0]);return!((e[r]===void 0||e[r]===null)&&!o.has(r))})}return e===`flow`&&(a=a.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=ds.exec(n);if(!r)return!0;let i=fs(t,Number(r[1]));return!(i&&us.has(i))})),a.length===0?{ok:!0,issues:[]}:{ok:!1,issues:a.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message}))}}var _s=Et,vs=new Set([`object`]),ys={object:[`fields`,`fieldGroups`]};function bs(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function xs(e){return e.loadFailed?!1:e.hasDiag||e.hasClientValidator}function Ss({type:e,name:t,createMode:n=!1,embedded:r=!1}){let a=i(),o=e??a.type??``,s=t??a.name??``,c=Ua(o);if(c?.EditPage&&!n){let e=c.EditPage;return(0,q.jsx)(e,{type:o,name:s})}if(c?.CreatePage&&n){let e=c.CreatePage;return(0,q.jsx)(e,{type:o})}return(0,q.jsx)(Cs,{type:o,name:s,createMode:n,embedded:r})}function Cs({type:e,name:t,createMode:n,embedded:r}){let i=u(),[a,o]=s(),c=a.get(`package`)??void 0,l=Tr(),{entries:d}=Ur(l),f=d.find(t=>t.type===e),p=Ga(e,f),m=(n&&p.createSchema?p.createSchema:f?.schema)??p.defaultSchema,h=J.useMemo(()=>Rr(),[]),[g,_]=J.useState(null),v=p.identityField??`name`,[y,x]=J.useState(()=>n?{...p.createDefaults??{},[v]:``}:{}),[S,w]=J.useState(null),[E,D]=J.useState(!n),[O,k]=J.useState(!1),[A,j]=J.useState(null),[ee,te]=J.useState(!1),[ne,re]=J.useState([]),M=J.useCallback(e=>{x(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&re(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[ie,N]=J.useState(null),[oe,se]=J.useState(null),ce=J.useCallback(e=>{M(t=>({...t,...e}))},[M]),{markTouched:ue}=yo({rules:p.createDerive,draft:y,onPatch:ce,enabled:!!n}),de=J.useMemo(()=>{if(n)return p.createFields&&p.createFields.length>0?p.createFields:bo(m?.properties??void 0,m?.required??void 0)},[n,p.createFields,m]),fe=J.useMemo(()=>{let t=ys[e]??[];if(!n||!de)return t.length===0?p.hiddenFields:Array.from(new Set([...p.hiddenFields??[],...t]));let r=m?.properties??{},i=new Set(de),a=Object.keys(r).filter(e=>!i.has(e));if(p.hiddenFields)for(let e of p.hiddenFields)a.includes(e)||a.push(e);for(let e of t)a.includes(e)||a.push(e);return a},[n,de,m,p.hiddenFields,e]),me=J.useMemo(()=>n&&de?de:p.fieldOrder,[n,de,p.fieldOrder]),he=J.useCallback(e=>{if(n){let t=y,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||ue(e)}M(e)},[n,y,M,ue]);J.useEffect(()=>{if(!hs(e))return;let t=!1,n=window.setTimeout(()=>{gs(e,y,f?.schema).then(e=>{t||re(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,y,f?.schema]);let[_e,ye]=J.useState(!1),[xe,Se]=J.useState(!1),[we,Te]=J.useState(0),[P,Ee]=J.useState(!!n),[Oe,ke]=J.useState(null);J.useEffect(()=>{ke(null)},[e,t]),J.useEffect(()=>{P||ke(null)},[P]);let je=J.useRef(null),[Me,Ne]=J.useState(null),[Pe,Fe]=J.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null?!0:e===`1`}catch{return!0}});J.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,Pe?`1`:`0`)}catch{}},[Pe]);let Ie=J.useRef(null),[Le,Re]=J.useState([]),[Be,He]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await l.list(`object`);if(e)return;Re(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||Re([])}finally{e||He(!1)}})(),()=>{e=!0}},[l]);let Ue=y?.interfaceConfig?.source||y?.object||y?.objectName,[We,Ge]=J.useState([]),[Ke,Je]=J.useState(!1);J.useEffect(()=>{let e=!1;if(!Ue){Ge([]);return}return Je(!0),(async()=>{try{let t=await l.get(`object`,Ue);if(e)return;let n=t?.fields;Ge((Array.isArray(n)?n.map(e=>({name:e?.name,label:e?.label,type:e?.type})):n&&typeof n==`object`?Object.entries(n).map(([e,t])=>({name:e,label:t?.label,type:t?.type})):[]).filter(e=>!!e.name))}catch{e||Ge([])}finally{e||Je(!1)}})(),()=>{e=!0}},[l,Ue]);let[Xe,Ze]=J.useState([]),[Qe,nt]=J.useState(!1);J.useEffect(()=>{let e=!1;if(!Ue){Ze([]);return}return nt(!0),(async()=>{try{let t=await l.list(`view`);if(e)return;let n=(t||[]).filter(e=>(e?.objectName??e?.object??e?.object_name)===Ue),r=new Set;Ze(n.map(e=>({name:e?.name,label:e?.label||void 0})).filter(e=>!!e.name&&!r.has(e.name)&&r.add(e.name)))}catch{e||Ze([])}finally{e||nt(!1)}})(),()=>{e=!0}},[l,Ue]);let rt=J.useMemo(()=>({objectNames:Le,objectsLoading:Be,objectFields:We,objectFieldsLoading:Ke,objectViews:Xe,objectViewsLoading:Qe}),[Le,Be,We,Ke,Xe,Qe]);J.useEffect(()=>{if(n){D(!1);return}let r=!1;return D(!0),j(null),te(!1),(async()=>{try{let n=c?{packageId:c}:{},[i,a]=await Promise.all([l.layered(e,t,n),l.getDraft(e,t,n).catch(()=>null)]);if(r)return;_(i);let o=i?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?re(o.errors.map(e=>({path:e.path||``,message:e.message}))):re([]);let s=bs(a),u=i.effective??i.code??{},d=s?{...u,...s}:u,f=p.toDraft?p.toDraft(d):d;x(f),je.current=f,ye(!!s),D(!1)}catch(n){r||(te(!0),j(U(`engine.edit.loadFailed`,h,{type:e,name:t??``,message:n?.message??String(n)})),D(!1))}})(),()=>{r=!0}},[l,e,t,c,n,we,h]);let[it,L]=J.useState(!1);async function at(){if(!(S!=null||it)){L(!0);try{w(await l.references(e,t))}catch(e){w([]),console.error(`references() failed`,e)}finally{L(!1)}}}let[ot,ct]=J.useState(null),dt=J.useMemo(()=>!n&&!r&&Wa(e).length>0,[e,n,r]),ft=J.useRef(null),[pt,mt]=J.useState(null),ht=a.get(`review`),gt=J.useRef(!1);J.useEffect(()=>{if(!(ht!==`1`||n)){if(!gt.current){gt.current=!0,Te(e=>e+1);return}if(!E){_e&&mt(`review`);let e=new URLSearchParams(a);e.delete(`review`),o(e,{replace:!0}),gt.current=!1}}},[ht,n,E,_e]);let[_t,vt]=J.useState(`properties`);J.useEffect(()=>{if(pt===`references`&&at(),typeof window<`u`&&!r){let e=new URL(window.location.href);pt?e.searchParams.set(`tab`,pt):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[pt,r]);let yt=`metadata-edit:inspector-collapsed`,xt=`metadata-edit:inspector-size`,[St,Ct]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(yt)===`1`),wt=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(xt));Number.isFinite(e)&&e>=22&&e<=80&&(wt.current=e)},[]);let Tt=J.useRef(null),Et=J.useCallback(()=>{Ct(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(yt,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=Tt.current;if(e)if(St)e.resize?.(`0%`);else{let t=wt.current||38;e.resize?.(`${t}%`)}},[St]);let[Dt,Ot]=J.useState(!1),[kt,At]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!kt)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[kt]),J.useEffect(()=>{if(typeof window>`u`||!kt)return;function e(e){e.key===`Escape`&&(e.preventDefault(),At(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[kt]);let jt=J.useRef(null);J.useEffect(()=>{jt.current=null},[e,t]),J.useEffect(()=>{if(n||r||E)return;let i=`${e}/${t??``}`;jt.current!==i&&Io(e)&&(g?.code==null?f?.allowOrgOverride||f?.allowRuntimeCreate:f?.allowOrgOverride)&&(jt.current=i,Ee(!0))},[e,t,n,r,E,f,g]),J.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),Et())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Et]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&mt(t),ft.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&ct({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);ot?.kind===`metadata`?e.searchParams.set(`open`,`${ot.type}:${ot.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[ot,r]);function Nt(e){let t=e.split(`.`)[0];if(!t)return e;let r=n&&p.createSchema?void 0:f?.form,i=Array.isArray(r?.sections)?r.sections:[];for(let e of i){let n=Array.isArray(e?.fields)?e.fields:[];for(let e of n)if(typeof e==`string`){if(e===t)return e}else if(e?.field===t)return String(e.label??t)}let a=m?.properties??{};return String(a[t]?.title??t)}async function Ft(r){k(!0),j(null),re([]);try{let a=n?p.createBuildBody?p.createBuildBody(y):{...p.createDefaults??{},...y}:p.fromDraft?p.fromDraft(y):y;if(n&&p.createSeed)try{let e=await p.createSeed(y,{client:l});e&&typeof e==`object`&&(a={...a,...e})}catch{}let o=String(a[v]??y[v]??t),s=n?{...a,[v]:o}:a;if(!o){j(G(`engine.validation.nameRequired`,h)),k(!1);return}let u=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await l.save(e,o,s,{force:r,mode:`draft`,...u?{packageId:u}:{}});let d=c?{packageId:c}:{},[f,m]=await Promise.all([l.layered(e,o,d),l.getDraft(e,o,d).catch(()=>null)]);_(f);let g=bs(m);ye(!!g);let b=f.effective??s,S=g?{...b,...g}:b,C=p.toDraft?p.toDraft(S):S;x(C),je.current=C,Ne(new Date),Ie.current=JSON.stringify(C),N(null),se(null);let w=!n&&!!Io(e);!n&&!w&&Ee(!1),n&&i(`../${encodeURIComponent(o)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];N(Array.isArray(t)?t:[]),se(y)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:kr(String(e.message??`Invalid`),h)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:kr(e[2].trim(),h)}]:[{path:``,message:kr(r,h)}]}re(n),n.length===1&&!n[0].path?j(n[0].message):n.length===1?j(`${Nt(n[0].path)}: ${n[0].message}`):j(U(`engine.validation.failed`,h,{count:n.length}))}else j(e?.message??String(e))}finally{k(!1)}}async function It(){let r=!n&&g?.code!=null;if(confirm(U(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,h,{type:e,name:t??``}))){k(!0),j(null);try{if(await l.reset(e,t),r){let n=await l.layered(e,t);_(n);let r=n.effective??n.code??{};x(r),je.current=r,Io(e)?jt.current=null:Ee(!1)}else i(`../`,{relative:`path`})}catch(e){j(e?.message??String(e))}finally{k(!1)}}}async function Lt(){Se(!0),j(null);try{await l.publish(e,t);let[n,r]=await Promise.all([l.layered(e,t),l.getDraft(e,t).catch(()=>null)]);_(n);let i=bs(r);ye(!!i);let a=n.effective??y,o=i?{...a,...i}:a;x(o),je.current=o}catch(e){j(e?.message??String(e))}finally{Se(!1)}}async function zt(){if(confirm(U(`engine.edit.discardDraftConfirm`,h,{type:e,name:t??``}))){k(!0),j(null);try{await l.reset(e,t,{state:`draft`});let n=await l.layered(e,t);_(n);let r=n.effective??n.code??{};x(r),je.current=r,ye(!1)}catch(e){j(e?.message??String(e))}finally{k(!1)}}}let Bt=J.useMemo(()=>{if(n)return Object.keys(y).length>0;let e=je.current;if(!e)return!1;try{return JSON.stringify(y)!==JSON.stringify(e)}catch{return!1}},[y,n]),Vt=!n&&g?.code!=null,Ut=g?.editable!==!1,Wt=g?.deletable!==!1,Gt=g?.resettable!==!1,Kt=g?.lockReason,Jt=g?.lock&&g.lock!==`none`,Yt=(n?!!(f?.allowOrgOverride||f?.allowRuntimeCreate):Vt?!!f?.allowOrgOverride:!!(f?.allowOrgOverride||f?.allowRuntimeCreate))&&(n||Ut),Xt=!Yt&&!n,Zt=J.useRef(Ft);if(J.useEffect(()=>{Zt.current=Ft}),J.useEffect(()=>{if(!Pe||n||Xt||!P||!Bt||O)return;let e;try{e=JSON.stringify(y)}catch{return}if(e===Ie.current)return;let t=window.setTimeout(()=>{Ie.current=e,Zt.current(!1)},1500);return()=>window.clearTimeout(t)},[y,Bt,P,O,n,Xt,Pe]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!Yt||Xt||!P&&!n)return;e.preventDefault(),!O&&(n||Bt)&&Zt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Yt,Xt,P,n,O,Bt]),J.useEffect(()=>{if(!Bt)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Bt]),J.useEffect(()=>{if(!Bt)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(G(`engine.edit.unsavedLeaveConfirm`,h))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[Bt,h]),Sr(J.useMemo(()=>{if(r)return null;let n=String(y.name??t??``);if(!n)return null;let i={type:e,name:n,label:typeof y.label==`string`?y.label:void 0};return e===`object`&&(i.fields=ci(y.fields).entries.slice(0,60).map(e=>({name:e.name,type:typeof e.def.type==`string`?e.def.type:void 0,label:typeof e.def.label==`string`?e.def.label:void 0,required:!!e.def.required||void 0}))),i},[r,e,t,y])),E)return(0,q.jsx)(Ia,{entry:f,itemName:t,children:(0,q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let Qt=Xt&&Vt&&!!f?.allowRuntimeCreate,en=vs.has(e),R=!r&&(!n||en)?Io(e):void 0,nn=zo(e),rn=Ho(e);function an(){je.current&&x(je.current),re([]),j(null),Ee(!1)}let on=Xt||!P&&!n,sn=(0,q.jsxs)(q.Fragment,{children:[!n&&(0,q.jsx)(za,{entry:f,location:`record_header`,recordId:t,onAfter:()=>Te(e=>e+1)}),(!n||dt)&&(0,q.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`layers`),title:G(`engine.edit.layers`,h),className:`h-7 w-7 p-0 relative`,children:[(0,q.jsx)(st,{className:`h-3.5 w-3.5`}),g?.overlay&&(()=>{let e=no(g.code,g.effective);return e>0?(0,q.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:G(`engine.layers.diff`,h),children:e}):null})()]}),!n&&_e&&(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`review`),title:G(`designer.draftReview.title`,h),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,q.jsx)(Rt,{className:`h-3.5 w-3.5`}),(()=>{let e=fo(g?.effective??null,y);return e>0?(0,q.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-amber-500 text-amber-50 text-[9px] leading-[14px] text-center font-medium`,title:U(`designer.draftReview.badge`,h,{n:e}),children:e}):null})()]}),!n&&(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`references`),title:G(`engine.edit.references`,h),className:`h-7 w-7 p-0 relative`,children:[(0,q.jsx)(ge,{className:`h-3.5 w-3.5`}),S&&S.length>0&&(0,q.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:S.length})]}),dt&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`related`),title:G(`engine.edit.related`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)(le,{className:`h-3.5 w-3.5`})}),!n&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`history`),title:G(`engine.edit.history`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)(qt,{className:`h-3.5 w-3.5`})}),!n&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>mt(`audit`),title:G(`engine.edit.auditTab`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)($t,{className:`h-3.5 w-3.5`})})]}),!n&&Yt&&g?.overlay&&(Vt?Gt:Wt)&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:It,disabled:O,title:G(Vt?`engine.edit.reset`:`engine.edit.delete`,h),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Vt?(0,q.jsx)(C,{className:`h-3.5 w-3.5`}):(0,q.jsx)(ut,{className:`h-3.5 w-3.5`})}),Yt&&!n&&!P&&!R&&(0,q.jsxs)(z,{size:`sm`,onClick:()=>Ee(!0),className:`h-7`,children:[(0,q.jsx)(bt,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]}),Yt&&(P||n)&&(0,q.jsx)(Ts,{saving:O,isDirty:Bt,autoSaveEnabled:Pe,lastSavedAt:Me,createMode:!!n,locale:h}),Yt&&(P||n)&&!n&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>Fe(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:G(Pe?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,h),children:Pe?(0,q.jsx)(Pt,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,q.jsx)(ur,{className:`h-3.5 w-3.5`})}),Yt&&!n&&P&&!R&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:an,disabled:O,className:`h-7 w-7 p-0`,title:G(`engine.cancel`,h),children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})}),Yt&&(P||n)&&(0,q.jsxs)(z,{size:`sm`,onClick:()=>Ft(!1),disabled:O||!n&&!Bt,className:`h-7 w-7 p-0 relative`,title:O?G(`engine.edit.saving`,h):!n&&!Bt?G(`engine.edit.noChanges`,h):`${G(`engine.edit.save`,h)} (⌘S)`,children:[O?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(tt,{className:`h-3.5 w-3.5`}),Bt&&!O&&(0,q.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),Yt&&!n&&_e&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:zt,disabled:O||xe,className:`h-7 w-7 p-0 text-muted-foreground`,title:G(`engine.edit.discardDraft`,h),children:(0,q.jsx)(ve,{className:`h-3.5 w-3.5`})}),Yt&&!n&&_e&&(0,q.jsx)(z,{size:`sm`,onClick:Lt,disabled:O||xe||Bt,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:G(Bt?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),children:xe?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(cr,{className:`h-3.5 w-3.5 mr-1`}),(0,q.jsx)(`span`,{className:`text-xs`,children:G(`engine.edit.publish`,h)})]})})]});return(0,q.jsxs)(Ia,{entry:f??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?G(`engine.edit.createNew`,h):void 0,actions:R?null:sn,children:[(0,q.jsxs)(`div`,{className:R?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(A||Xt||_e||Jt)&&(0,q.jsxs)(`div`,{className:R?`px-6 pt-4 space-y-3`:`space-y-3`,children:[A&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:A}),Jt&&(0,q.jsxs)(`div`,{className:`text-xs text-amber-900 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-2.5`,children:[(0,q.jsx)(un,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`font-medium`,children:[g?.lock===`full`&&G(`engine.edit.lockFull`,h),g?.lock===`no-overlay`&&G(`engine.edit.lockNoOverlay`,h),g?.lock===`no-delete`&&G(`engine.edit.lockNoDelete`,h)]}),Kt&&(0,q.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Kt}),g?.lockDocsUrl&&(0,q.jsxs)(`a`,{href:g.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[h===`zh-CN`?`查看文档`:`View docs`,` →`]}),g?.packageId&&(0,q.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,q.jsxs)(`code`,{className:`font-mono`,children:[g.packageId,g.packageVersion?`@${g.packageVersion}`:``]})})]}),Qt&&(0,q.jsx)(z,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]}),_e&&!n&&(0,q.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,q.jsx)(cr,{className:`h-3.5 w-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`flex-1`,children:G(`engine.edit.draftPending`,h)}),Yt&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(z,{size:`sm`,variant:`ghost`,onClick:zt,disabled:O||xe,className:`h-7`,children:G(`engine.edit.discardDraft`,h)}),(0,q.jsx)(z,{size:`sm`,onClick:Lt,disabled:O||xe||Bt,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:xe?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):G(`engine.edit.publish`,h)})]})]}),Xt&&!Jt&&(0,q.jsxs)(`div`,{className:`text-xs text-amber-800 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-3`,children:[(0,q.jsx)(`div`,{className:`flex-1`,children:Qt?G(`engine.edit.artifactLockedBanner`,h).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,q.jsx)(`code`,{className:`font-mono`,children:e},n):(0,q.jsx)(J.Fragment,{children:t},n)):G(`engine.edit.readOnlyTypeBanner`,h).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,q.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,q.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,q.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,q.jsx)(J.Fragment,{children:t},n))}),Qt&&(0,q.jsx)(z,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]})]}),(0,q.jsx)(`div`,{className:R?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,q.jsxs)(`div`,{className:R?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!R&&on&&!Xt&&Yt&&!n&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,q.jsx)(`span`,{children:G(`engine.edit.readOnlyBanner`,h).split(/\{edit\}/).map((e,t,n)=>(0,q.jsxs)(J.Fragment,{children:[e,t<n.length-1&&(0,q.jsx)(`strong`,{children:G(`engine.edit.edit`,h)})]},t))}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>Ee(!0),children:[(0,q.jsx)(bt,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]})]}),(()=>{let t=g?._diagnostics,n=hs(e)?ne.map(e=>({path:e.path,message:kr(e.message,h)})):(t?.errors??[]).map(e=>({...e,message:kr(e.message,h)})),r=hs(e)?n.length===0:t?.valid!==!1;if(!xs({loadFailed:ee,hasDiag:!!t,hasClientValidator:hs(e)}))return null;let i=n,a=t?.warnings??[],o=!r&&i.length>0,s=a.length>0;if(!o&&!s)return null;let c=(e,t)=>{let n=t.slice(0,3),r=Math.max(0,t.length-n.length),i=e===`error`?`border-destructive/40 bg-destructive/[0.06] text-destructive`:`border-amber-500/40 bg-amber-500/[0.08] text-amber-800 dark:text-amber-200`,a=e===`error`?`engine.edit.diagnostics.title`:`engine.edit.diagnostics.warnTitle`;return(0,q.jsxs)(`div`,{className:`flex items-start gap-2 text-xs border rounded p-2.5 ${i}`,children:[(0,q.jsx)(I,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:U(a,h,{count:t.length})}),(0,q.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,q.jsxs)(`li`,{className:`truncate`,children:[(0,q.jsx)(`span`,{className:`opacity-70`,children:e.path?Nt(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,q.jsx)(`li`,{className:`opacity-70`,children:U(`engine.edit.diagnostics.more`,h,{count:r})})]})]})]},e)};return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),R?(0,q.jsx)(`div`,{className:kt?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,q.jsxs)(_s,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,q.jsx)(Ce,{defaultSize:62,minSize:30,children:(0,q.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b bg-background/95 backdrop-blur px-3 py-2 sticky top-0 z-10`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-1`,children:Yt&&(0,q.jsxs)(`div`,{role:`tablist`,"aria-label":G(`engine.edit.designer`,h),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Dt,onClick:()=>Ot(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Dt?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:G(`engine.edit.designMode`,h),children:[(0,q.jsx)(tn,{className:`h-3.5 w-3.5`}),G(`engine.edit.designMode`,h)]}),(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Dt,onClick:()=>Ot(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Dt?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.previewMode`,h),children:[(0,q.jsx)(ze,{className:`h-3.5 w-3.5`}),G(`engine.edit.previewMode`,h)]})]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[sn,(0,q.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),R&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:Et,className:`h-7 w-7 p-0`,title:G(St?`engine.edit.showInspector`:`engine.edit.hideInspector`,h)+` (⌘\\)`,children:St?(0,q.jsx)(xn,{className:`h-3.5 w-3.5`}):(0,q.jsx)(Fn,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>At(e=>!e),className:`h-7 w-7 p-0`,title:G(kt?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,h),children:kt?(0,q.jsx)(Mt,{className:`h-3.5 w-3.5`}):(0,q.jsx)(et,{className:`h-3.5 w-3.5`})})]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4 bg-[radial-gradient(circle_at_1px_1px,theme(colors.border)_1px,transparent_0)] [background-size:16px_16px] bg-muted/30`,children:(0,q.jsx)(R,{type:e,name:t,draft:y,baseline:n?void 0:g?.effective??void 0,editing:P&&!Dt,selection:Dt?null:Oe,onSelectionChange:ke,locale:h,onPatch:e=>M(t=>({...t,...e}))})})]})}),(0,q.jsx)(Pn,{withHandle:!0,className:St?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,q.jsx)(Ce,{panelRef:Tt,defaultSize:wt.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(wt.current=t,typeof window<`u`&&window.localStorage.setItem(xt,String(Math.round(t)))),Ct(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(yt,n?`1`:`0`),n))},children:(0,q.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,q.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":_t===`properties`,onClick:()=>vt(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(_t===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.properties`,h),children:[(0,q.jsx)(Ht,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.properties`,h)]}),(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":_t===`source`,onClick:()=>vt(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(_t===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.source`,h),children:[(0,q.jsx)(dn,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.source`,h)]})]}),Bt&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,q.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),G(`engine.edit.unsaved`,h)]})]}),(0,q.jsx)(`div`,{className:`p-4`,children:_t===`source`?(0,q.jsx)(cs,{value:y,onChange:M,readOnly:on,issues:ne.map(e=>({path:e.path??``,message:e.message}))}):Oe&&nn?(0,q.jsx)(nn,{type:e,name:t,draft:y,selection:Oe,onPatch:e=>M(t=>({...t,...e})),onClearSelection:()=>ke(null),onSelectionChange:ke,readOnly:on,locale:h}):!Oe&&rn?(0,q.jsx)(rn,{type:e,name:t,draft:y,onPatch:e=>M(t=>({...t,...e})),onSelectionChange:ke,readOnly:on,locale:h,serverSchema:f?.schema}):(0,q.jsx)(Fr,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:he,issues:ne,hiddenFields:fe,fieldOrder:me,readOnly:on,createMode:n,widgetContext:rt})})]})})]})}):(0,q.jsx)(Fr,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:he,issues:ne,hiddenFields:fe,fieldOrder:me,readOnly:on,createMode:n,widgetContext:rt})]})})]}),(0,q.jsx)(Ve,{open:pt===`layers`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Ye,{className:`text-base`,children:G(`engine.edit.layers`,h)}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(ro,{layered:g,locale:h})})]})}),(0,q.jsx)(Ve,{open:pt===`review`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Ye,{className:`text-base`,children:G(`designer.draftReview.title`,h)}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t,` · `,G(`designer.canvas.reviewVsPublished`,h)]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(po,{published:g?.effective??null,draft:y,locale:h})})]})}),(0,q.jsx)(Ve,{open:pt===`references`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsxs)(Ye,{className:`text-base`,children:[G(`engine.edit.references`,h),S&&(0,q.jsx)(b,{variant:`outline`,className:`ml-2 text-[10px]`,children:S.length})]}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(ws,{refs:S,loading:it})})]})}),dt&&(0,q.jsx)(Ve,{open:pt===`related`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Ye,{className:`text-base`,children:G(`engine.edit.related`,h)}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(xo,{type:e,name:t,parentItem:y,onOpen:e=>ct(e)})})]})}),!n&&(0,q.jsx)(Ve,{open:pt===`history`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Ye,{className:`text-base`,children:G(`engine.edit.history`,h)}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(ko,{type:e,name:t,client:l,onRollback:()=>Te(e=>e+1),rollbackLabel:G(`engine.edit.rollback`,h),rollbackConfirm:e=>G(`engine.edit.rollbackConfirm`,h).replace(`{version}`,String(e))})})]})}),!n&&(0,q.jsx)(Ve,{open:pt===`audit`,onOpenChange:e=>!e&&mt(null),children:(0,q.jsxs)(ae,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Ae,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Ye,{className:`text-base`,children:G(`engine.edit.auditTab`,h)}),(0,q.jsxs)(be,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,q.jsx)(Po,{type:e,name:t,client:l,locale:h})})]})}),(0,q.jsx)(Do,{target:ot,onClose:()=>ct(null),parentContext:{type:e,name:t}}),(0,q.jsx)(De,{open:ie!=null,onOpenChange:e=>{e||(N(null),se(null))},children:(0,q.jsxs)(qe,{children:[(0,q.jsxs)(lt,{children:[(0,q.jsxs)(pe,{className:`flex items-center gap-2`,children:[(0,q.jsx)(I,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,q.jsx)(vr,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,q.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:ie?.map((e,t)=>(0,q.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,q.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,q.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,q.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,q.jsxs)(T,{children:[(0,q.jsx)(z,{variant:`ghost`,onClick:()=>N(null),children:`Cancel`}),(0,q.jsx)(z,{variant:`destructive`,onClick:()=>Ft(!0),disabled:O,children:O?`Forcing…`:`Force save`})]})]})})]})}function ws({refs:e,loading:t}){return t||e==null?(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`No references found`}),(0,q.jsx)(gr,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,q.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,q.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,q.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,q.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,q.jsx)(`td`,{className:`px-3 py-2`,children:(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,q.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,q.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function Ts({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=J.useReducer(e=>e+1,0);return J.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,q.jsx)(F,{className:`h-3 w-3 animate-spin`}),G(`engine.edit.saving`,a)]}):t?i?null:(0,q.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),G(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:U(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function Es({type:e}){let t=a(),[n]=s(),r=e??n.get(`type`)??``;if(!r)return(0,q.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`Missing metadata type`}),(0,q.jsxs)(gr,{children:[`This page expects a `,(0,q.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,q.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,q.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let i=Ds(t.pathname),o=i.split(`/`).filter(Boolean);return o.length===0?(0,q.jsx)(qa,{type:r}):o[0]===`new`&&o.length===1?(0,q.jsx)(Ss,{type:r,name:``,createMode:!0},`${r}:__new__`):o.length===2&&o[1]===`history`?(0,q.jsx)(Oo,{type:r,name:decodeURIComponent(o[0])}):o.length===1?(0,q.jsx)(Ss,{type:r,name:decodeURIComponent(o[0])},`${r}:${o[0]}`):(0,q.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:`Unknown sub-path`}),(0,q.jsxs)(gr,{children:[`The path `,(0,q.jsx)(`code`,{className:`font-mono`,children:i}),` isn't recognized. Valid forms are `,(0,q.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,q.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,q.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,q.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function Ds(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function Os(){let e=Tr(),t=J.useMemo(()=>Rr(),[]),[n,r]=J.useState(`error`),{loading:i,error:a,summary:o,reload:s}=Er(e,n),{entries:l}=Ur(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=zr(n.type,t,n.label);return e},[l,t]),d=J.useMemo(()=>{let e={};for(let t of o.entries)(e[t.type]??=[]).push(t);return Object.entries(e).sort(([,e],[,t])=>t.length-e.length)},[o]);return(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,q.jsxs)(c,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,q.jsx)(Bn,{className:`h-3 w-3`}),G(`engine.diagnostics.back`,t)]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,q.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,q.jsx)(I,{className:`h-5 w-5 text-destructive`}),G(`engine.diagnostics.title`,t)]}),(0,q.jsx)(b,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:U(`engine.diagnostics.summary`,t,{count:o.total,items:o.scannedItems,types:o.scannedTypes})}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5 text-xs`,children:[`error`,`warning`].map(e=>(0,q.jsx)(`button`,{role:`tab`,type:`button`,"aria-selected":n===e,onClick:()=>r(e),className:`px-2.5 py-1 rounded transition-colors `+(n===e?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),children:G(`engine.diagnostics.severity.${e}`,t)},e))}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:s,children:[(0,q.jsx)(ie,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.diagnostics.refresh`,t)]})]}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:G(`engine.diagnostics.description`,t)})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[i&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:G(`engine.diagnostics.loading`,t)}),!i&&a&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:U(`engine.diagnostics.loadFailed`,t,{error:a})}),!i&&!a&&d.length===0&&(0,q.jsxs)(Ke,{children:[(0,q.jsx)(ue,{children:G(`engine.diagnostics.cleanTitle`,t)}),(0,q.jsx)(gr,{children:U(`engine.diagnostics.cleanHint`,t,{items:o.scannedItems,types:o.scannedTypes})})]}),d.map(([e,r])=>(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(c,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:u[e]??e}),(0,q.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:r.length})]}),(0,q.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:G(`engine.diagnostics.col.name`,t)}),(0,q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:G(`engine.diagnostics.col.issues`,t)})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:r.map(r=>{let i=r.diagnostics.errors??[],a=r.diagnostics.warnings??[],o=(n===`warning`&&i.length===0?a:i).slice(0,3),s=Math.max(0,(i.length||a.length)-o.length);return(0,q.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,q.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,q.jsx)(c,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(r.name)}`,className:`text-primary hover:underline font-mono`,children:r.name}),i.length>0&&(0,q.jsx)(b,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:U(`engine.diagnostics.errorN`,t,{count:i.length})}),a.length>0&&(0,q.jsx)(b,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:U(`engine.diagnostics.warnN`,t,{count:a.length})})]}),(0,q.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,q.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[o.map((e,t)=>(0,q.jsxs)(`li`,{className:`truncate`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),s>0&&(0,q.jsx)(`li`,{className:`text-muted-foreground`,children:U(`engine.diagnostics.more`,t,{count:s})})]})})]},r.name)})})]})})]},e))]})]})}function ks(e){return[{key:`allowCreate`,short:`C`,tip:G(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:G(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:G(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:G(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:G(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:G(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:G(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:G(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:G(`perm.action.modifyAll`,e)}]}function As({type:e,name:t}){let n=u(),r=Tr(),{entries:i}=Ur(r),a=i.find(t=>t.type===e),o=!!Ga(e,a).allowOrgOverride,s=J.useMemo(()=>Rr(),[]),c=J.useCallback(e=>G(e,s),[s]),l=J.useMemo(()=>ks(s),[s]),[d,f]=J.useState({name:t,objects:{},fields:{}}),[p,m]=J.useState([]),[h,g]=J.useState({}),[_,v]=J.useState(new Set),[y,x]=J.useState(!0),[S,C]=J.useState(!1),[w,E]=J.useState(null),[D,O]=J.useState(null),[k,A]=J.useState(``),[j,ee]=J.useState(!1);J.useEffect(()=>{let n=!1;return x(!0),(async()=>{try{let[i,a]=await Promise.all([r.layered(e,t).catch(()=>null),r.list(`object`).catch(()=>[])]);if(n)return;let o=i?.effective??i?.code??{name:t,objects:{}};f({...o,name:String(o?.name??t),objects:o?.objects??{},fields:o?.fields??{}}),m((a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name)))}catch(e){E(e?.message??String(e))}finally{n||x(!1)}})(),()=>{n=!0}},[r,e,t]);async function te(e){if(!h[e])try{let t=(await r.list(`field`)??[]).map(e=>e?.item??e).filter(t=>String(t?.object??``)===e).map(e=>({name:String(e?.name??``),label:e?.label})).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));g(n=>({...n,[e]:t}))}catch{g(t=>({...t,[e]:[]}))}}function ne(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),te(e)),n})}function re(e,t,n){f(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function M(e,t){f(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(l.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function ie(e,t,n,r){let i=`${e}.${t}`;f(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function N(t,n){let i=n??d;C(!0),E(null);try{await r.save(e,i.name,i,{force:t}),f((await r.layered(e,i.name)).effective??i),O(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];O({issues:Array.isArray(t)?t:[],pending:i})}else E(e?.message??String(e))}finally{C(!1)}}let ae=J.useMemo(()=>{let e=k.trim().toLowerCase();return p.filter(t=>{if(j){let e=d.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[p,k,j,d.objects]),oe=[{label:c(`perm.stat.objectsGranted`),value:Object.values(d.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:c(`perm.stat.fieldOverrides`),value:Object.keys(d.fields??{}).length}];return y?(0,q.jsx)(Ia,{entry:a,itemName:t,children:(0,q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,q.jsxs)(Ia,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:oe,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,q.jsx)(qt,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,q.jsxs)(z,{size:`sm`,onClick:()=>N(!1),disabled:S,children:[S?(0,q.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)(tt,{className:`h-4 w-4 mr-1`}),c(`engine.edit.save`)]})]}),children:[(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[w&&(0,q.jsxs)(`div`,{className:`m-4 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive flex items-start gap-2`,children:[(0,q.jsx)(I,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,q.jsx)(`span`,{children:w})]}),(0,q.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{htmlFor:`perm-name`,className:`text-xs`,children:c(`perm.field.name`)}),(0,q.jsx)(B,{id:`perm-name`,value:d.name,disabled:!o,onChange:e=>f(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{htmlFor:`perm-label`,className:`text-xs`,children:c(`perm.field.label`)}),(0,q.jsx)(B,{id:`perm-label`,value:d.label??``,disabled:!o,onChange:e=>f(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,q.jsx)(Qt,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,q.jsx)(V,{htmlFor:`perm-is-profile`,className:`text-xs`,children:c(`perm.field.isProfile`)})]}),!o&&(0,q.jsx)(b,{variant:`secondary`,className:`ml-auto`,children:c(`perm.readOnly`)})]}),(0,q.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,q.jsx)(B,{placeholder:c(`perm.filter.placeholder`),value:k,onChange:e=>A(e.target.value),className:`h-8 w-72`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Qt,{id:`only-enabled`,checked:j,onCheckedChange:e=>ee(!!e)}),(0,q.jsx)(V,{htmlFor:`only-enabled`,className:`text-xs`,children:c(`perm.filter.onlyGranted`)})]}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[ae.length,` / `,p.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,q.jsx)(js,{objects:ae,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:l,t:c,onToggleExpand:ne,onObjectPerm:re,onFieldPerm:ie,onBulkSet:M})})]}),(0,q.jsx)(De,{open:!!D,onOpenChange:e=>!e&&O(null),children:(0,q.jsxs)(qe,{children:[(0,q.jsxs)(lt,{children:[(0,q.jsxs)(pe,{className:`flex items-center gap-2`,children:[(0,q.jsx)(I,{className:`h-4 w-4 text-amber-500`}),` `,c(`engine.edit.destructive`)]}),(0,q.jsx)(vr,{children:c(`engine.edit.destructiveHint`)})]}),(0,q.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:D?.issues.map((e,t)=>(0,q.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,q.jsx)(b,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,q.jsxs)(T,{children:[(0,q.jsx)(z,{variant:`ghost`,onClick:()=>O(null),children:c(`engine.cancel`)}),(0,q.jsxs)(z,{variant:`destructive`,onClick:()=>D&&N(!0,D.pending),disabled:S,children:[S&&(0,q.jsx)(F,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function js({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,q.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,q.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,q.jsxs)(`tbody`,{children:[e.length===0&&(0,q.jsx)(`tr`,{children:(0,q.jsx)(`td`,{colSpan:a.length+2,className:`px-4 py-8 text-center text-muted-foreground`,children:o(`perm.filter.empty`)})}),e.map(e=>{let d=t.objects[e.name]??{},f=n.has(e.name);return(0,q.jsxs)(J.Fragment,{children:[(0,q.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,q.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,q.jsx)(re,{className:`h-3.5 w-3.5`}):(0,q.jsx)(rt,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,q.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,q.jsx)(we,{checked:!!d[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,q.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`read`),children:o(`perm.bulk.read`)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`crud`),children:o(`perm.bulk.crud`)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`all`),children:o(`perm.bulk.all`)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),f&&(0,q.jsx)(`tr`,{className:`bg-muted/10`,children:(0,q.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,q.jsx)(Ms,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function Ms({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,q.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,q.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,q.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,q.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,q.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,q.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,q.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,q.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,q.jsx)(we,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,q.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,q.jsx)(we,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function Ns(){Ha({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Ps(e.fields),groupLabel:`Fields`,order:5}]}),Ha({type:`__object_index`,label:`Index`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`index`,embeddedPath:`indexes`,extract:e=>{let t=e.indexes;return Array.isArray(t)?t.map((e,t)=>{let n=Array.isArray(e.fields)?e.fields.join(`,`):``;return{name:n?`idx_${n}`:`index_${t}`,...e}}):[]},groupLabel:`Indexes`,order:10}]}),Ha({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Ps(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Ha({type:`hook`,anchors:[{anchorType:`object`,match:Ba(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Ha({type:`page`,anchors:[{anchorType:`object`,match:Ba(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`object`,`type`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`type`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable page title.`},name:{type:`string`,title:`Name`,description:`Page key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},type:{type:`string`,title:`Page type`,enum:[`record`,`app`,`home`,`dashboard`,`utility`],default:`record`,description:"A `record` page renders for an object’s records; pick the object below."},object:{type:`string`,title:`Object`,description:`For a record page — the object whose records this page renders.`},kind:{type:`string`,title:`Kind`,enum:[`full`,`slotted`],default:`full`,description:`full = the whole page; slotted = override only named slots of the default.`}}},createDefaults:{type:`record`,kind:`full`,regions:[]},createSeed:async(e,{client:t})=>{if(e?.type!==`record`||!e?.object)return{};try{let n=await t.get(`object`,String(e.object));if(!n||typeof n!=`object`)return{};let{buildDefaultPageSchema:r}=await o(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-B-EGcBP2.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),i=r(n),a={};return Array.isArray(i?.regions)&&i.regions.length&&(a.regions=i.regions),i?.template&&(a.template=i.template),a}catch{return{}}}}),Ha({type:`view`,anchors:[{anchorType:`object`,match:Ba([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`kind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`View key (snake_case). Qualified to <object>.<key> on save.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,description:`The object this view displays.`},kind:{type:`string`,title:`View kind`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``);return{name:n.includes(`.`)||!t?n:`${t}.${n}`,object:t,viewKind:`list`,label:e.label,config:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}}}}}),Ha({type:`flow`,anchors:[{anchorType:`object`,match:Ba([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{nodes:[],edges:[]}}),Ha({type:`trigger`,anchors:[{anchorType:`object`,match:Ba([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ha({type:`validation`,anchors:[{anchorType:`object`,match:Ba(`object`),groupLabel:`Validations`,order:25}],createFields:[`label`,`name`,`message`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`message`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable rule name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},message:{type:`string`,title:`Error message`,description:`Shown to the user when the rule blocks save.`}}},createDefaults:{type:`script`,active:!0,events:[`insert`,`update`],priority:10,severity:`error`,condition:`false`}}),Ha({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}],createFields:[`label`,`name`,`isProfile`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),Ha({type:`action`,anchors:[{anchorType:`object`,match:Ba([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ha({type:`dashboard`,anchors:[{anchorType:`object`,match:Ba([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Ha({type:`report`,anchors:[{anchorType:`object`,match:Ba([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Ha({type:`object`,iconName:`database`,domain:`data`,createFields:[`label`,`pluralLabel`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0},{from:`label`,to:`pluralLabel`,transform:`plural-en`,untilUserEdits:!0}],createDefaults:{fields:{}},searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function Ps(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Fs={name:{type:`string`,title:`Name`,description:`Machine name. snake_case, used as the URL path and DB key.`,pattern:`^[a-z_][a-z0-9_]*$`},label:{type:`string`,title:`Label`,description:`Human-readable display name.`},description:{type:`string`,title:`Description`,format:`multiline`}},Is={role:{type:`object`,title:`Role`,required:[`name`],properties:{...Fs,level:{type:`string`,title:`Level`,description:`Coarse seniority tier (used by UI / sort order).`,enum:[`member`,`lead`,`manager`,`director`,`executive`,`admin`]},parentRole:{type:`string`,title:`Parent Role`,description:`Optional parent role name for hierarchy.`}}},profile:{type:`object`,title:`Profile`,required:[`name`],properties:{...Fs,isProfile:{type:`boolean`,title:`Is profile`,description:`Profiles are mutually exclusive (one per user).`},objects:{type:`object`,title:`Object Permissions`,description:`Edit this via the Permission Matrix tab for a row-by-row UI.`}}},permission:{type:`object`,title:`Permission`,required:[`id`,`resource`,`actions`,`description`],properties:{id:{type:`string`,title:`ID`,description:`Stable identifier (e.g. crm.account.read).`},resource:{type:`string`,title:`Resource`,description:`What this permission applies to.`,enum:[`data.object`,`data.record`,`data.field`,`ui.view`,`ui.dashboard`,`ui.report`,`system.config`,`system.plugin`,`system.api`,`system.service`,`storage.file`,`storage.database`,`network.http`,`network.websocket`,`process.spawn`,`process.env`]},actions:{type:`array`,title:`Actions`,description:`Permitted operations on the resource.`,items:{type:`string`,enum:[`create`,`read`,`update`,`delete`,`execute`,`admin`,`manage`,`configure`,`import`,`export`,`share`]}},description:{type:`string`,title:`Description`,description:`Why this permission exists (shown in admin UIs).`},scope:{type:`string`,title:`Scope`,enum:[`tenant`,`user`,`plugin`,`global`,`resource`],default:`tenant`},required:{type:`boolean`,title:`Required`,description:`Must be present for the holder to function.`},justification:{type:`string`,title:`Justification`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...Fs.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Fs.label,description:Fs.description,locale:{type:`string`,title:`Locale`,description:`BCP-47 tag, e.g. en, zh-Hans, ja-JP.`},strings:{type:`object`,title:`Strings`,description:`Key → translated string map.`}}},tool:{type:`object`,title:`AI Tool`,required:[`name`],properties:{...Fs,kind:{type:`string`,title:`Kind`,enum:[`function`,`http`,`mcp`]},inputSchema:{type:`object`,title:`Input Schema (JSON Schema)`},outputSchema:{type:`object`,title:`Output Schema (JSON Schema)`}}},skill:{type:`object`,title:`AI Skill`,required:[`name`],properties:{...Fs,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Fs,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Fs,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Fs,type:{type:`string`,title:`View Type`,enum:[`grid`,`kanban`,`calendar`,`gantt`,`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]}}},dashboard:{type:`object`,title:`Dashboard`,required:[`name`],properties:{...Fs,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Fs,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...Fs,slug:{type:`string`,title:`Slug`,description:`Portal URL segment; defaults to the name without its package prefix.`},icon:{type:`string`,title:`Icon`},order:{type:`number`,title:`Order`,description:`Orders books within the portal.`},audience:{title:`Audience`,description:`Access audience. 'org' (default) inherits the package grant; 'public' is anonymously readable; { profile } gates by role.`,oneOf:[{type:`string`,enum:[`org`,`public`]},{type:`object`,title:`Role-gated`,properties:{profile:{type:`string`,title:`Profile`}},required:[`profile`]}]},groups:{type:`array`,title:`Groups (spine)`,description:`Ordered sections. Membership is derived from each group's include rule — edit the structure visually in the Preview tab.`,items:{type:`object`,required:[`key`,`label`],properties:{key:{type:`string`,title:`Key`,pattern:`^[a-z][a-z0-9_]*$`},label:{type:`string`,title:`Label`},order:{type:`number`,title:`Order`},include:{title:`Include rule`,description:`Glob over doc names (e.g. crm_guide_*) or { tag }.`},package:{type:`string`,title:`Package scope`},pages:{type:`array`,title:`Explicit pages (override)`,items:{}}}}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...Fs,category:{type:`string`,title:`Category`,enum:[`auth`,`notification`,`workflow`,`marketing`,`custom`],default:`custom`},locale:{type:`string`,title:`Locale`,default:`en-US`,description:`BCP-47 tag (en-US, zh-CN, …)`},subject:{type:`string`,title:`Subject`,description:`Supports {{var.path}} interpolation`},bodyHtml:{type:`string`,title:`HTML Body`,format:`multiline`},bodyText:{type:`string`,title:`Plain-Text Body`,format:`multiline`},variables:{type:`array`,title:`Variables`,items:{type:`object`}},fromOverride:{type:`object`,title:`From Override`},replyTo:{type:`string`,title:`Reply-To`},active:{type:`boolean`,title:`Active`,default:!0},isSystem:{type:`boolean`,title:`System Template`,default:!1}}}};function Ls(){for(let[e,t]of Object.entries(Is))Ha({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function X({toolbar:e,children:t}){return(0,q.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,q.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,q.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function Z({tone:e=`info`,children:t}){return(0,q.jsxs)(`div`,{className:`m-4 rounded border p-3 text-sm flex items-start gap-2 ${e===`warn`?`text-amber-800 bg-amber-50 border-amber-200`:e===`error`?`text-destructive bg-destructive/5 border-destructive/30`:`text-muted-foreground border-muted`}`,children:[e!==`info`&&(0,q.jsx)(hr,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,q.jsx)(`div`,{className:`flex-1`,children:t})]})}function Rs({icon:e,title:t,description:n,action:r,tone:i=`info`}){let a=i===`warn`?`text-amber-700 bg-amber-50/40 border-amber-200/60`:`text-muted-foreground border-dashed border-muted-foreground/25 bg-muted/10`,o=e??(0,q.jsx)(Ct,{className:`h-8 w-8 opacity-50`});return(0,q.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,q.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border ${a} px-6 py-10 flex flex-col items-center gap-3 text-center`,children:[(0,q.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,q.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,q.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,q.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Q=class extends J.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,q.jsxs)(Z,{tone:`error`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,q.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,q.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function zs({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,q.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:H(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,q.jsx)(L,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:a??`Add`})]})]})]})}var Bs={"page:header":{label:`Header`,category:`layout`,Icon:Wt},"page:footer":{label:`Footer`,category:`layout`,Icon:zn},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:on},"page:tabs":{label:`Tabs`,category:`layout`,Icon:An},"page:accordion":{label:`Accordion`,category:`layout`,Icon:Ft},"page:card":{label:`Card`,category:`layout`,Icon:sn},"page:section":{label:`Section`,category:`layout`,Icon:st},"record:details":{label:`Record details`,category:`record`,Icon:A},"record:highlights":{label:`Highlights`,category:`record`,Icon:St},"record:related_list":{label:`Related list`,category:`record`,Icon:M},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Yt},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Xe},"record:path":{label:`Stage path`,category:`record`,Icon:xt},"record:alert":{label:`Alert banner`,category:`record`,Icon:I},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:Pt},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Tt},"record:history":{label:`History`,category:`record`,Icon:qt},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:rr},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:xt},"global:search":{label:`Global search`,category:`navigation`,Icon:Ze},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:Nn},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:mn},"element:text":{label:`Text`,category:`element`,Icon:ke},"element:number":{label:`Number`,category:`element`,Icon:Jn},"element:image":{label:`Image`,category:`element`,Icon:yt},"element:divider":{label:`Divider`,category:`element`,Icon:dr},"element:button":{label:`Button`,category:`element`,Icon:_n},"element:definition-list":{label:`Definition list`,category:`element`,Icon:Pe},"element:repeater":{label:`Repeater`,category:`element`,Icon:te}},Vs={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Hs=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Bs))e[n.category].push(t);return[`layout`,`record`,`element`,`navigation`,`ai`,`misc`].map(t=>({category:t,types:e[t]})).filter(e=>e.types.length>0)})(),Us=Te,Ws={layout:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},record:{icon:`text-blue-500 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},navigation:{icon:`text-indigo-500 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},element:{icon:`text-teal-500 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},ai:{icon:`text-violet-500 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},misc:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function Gs(e){return Ws[Bs[e]?.category??`misc`]}var Ks={"element:text":[{name:`content`,label:`Content`,kind:`text`,placeholder:`Text…`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`heading`,label:`Heading`},{value:`subheading`,label:`Subheading`},{value:`body`,label:`Body`},{value:`caption`,label:`Caption`}]},{name:`align`,label:`Align`,kind:`select`,options:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}],"element:image":[{name:`src`,label:`Source URL`,kind:`text`,placeholder:`https://…`},{name:`alt`,label:`Alt text`,kind:`text`},{name:`fit`,label:`Fit`,kind:`select`,options:[{value:`cover`,label:`Cover`},{value:`contain`,label:`Contain`},{value:`fill`,label:`Fill`}]}],"element:definition-list":[{name:`items`,label:`Items`,kind:`array`,addLabel:`Add item`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`value`,label:`Value`,kind:`text`}]},{name:`columns`,label:`Columns (1 or 2)`,kind:`number`,placeholder:`1`},{name:`inline`,label:`Inline (label · value)`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`},{name:`emptyText`,label:`Empty text`,kind:`text`},{name:`divided`,label:`Dividers between rows`,kind:`boolean`}],"element:number":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`field`,label:`Field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`Aggregate`,kind:`select`,options:[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"element:button":[{name:`label`,label:`Label`,kind:`text`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}]},{name:`size`,label:`Size`,kind:`select`,options:[{value:`small`,label:`Small`},{value:`medium`,label:`Medium`},{value:`large`,label:`Large`}]},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`}],"page:header":[{name:`title`,label:`Title`,kind:`text`},{name:`subtitle`,label:`Subtitle`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`breadcrumb`,label:`Show breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`Title`,kind:`text`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`Tabs`,kind:`array`,addLabel:`Add tab`,itemFields:[{name:`key`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"page:accordion":[{name:`title`,label:`Title`,kind:`text`},{name:`items`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`value`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`relationshipField`,label:`Relationship field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`}],"record:highlights":[{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`columns`,label:`Columns`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`Severity`,kind:`select`,options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`error`,label:`Error`},{value:`success`,label:`Success`}]},{name:`title`,label:`Title`,kind:`text`},{name:`body`,label:`Body`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`dismissible`,label:`Dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`Status field`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`Stages`,kind:`array`,addLabel:`Add stage`,itemFields:[{name:`value`,label:`Value`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`Action names`,kind:`string-list`,placeholder:`action name`},{name:`location`,label:`Location`,kind:`select`,options:[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record more menu`},{value:`record_section`,label:`Record section`},{value:`record_related`,label:`Record related`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List item`},{value:`global_nav`,label:`Global nav`}]}],"ai:chat_window":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}],"ai:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function qs(e){return!!e&&Array.isArray(Ks[e])&&Ks[e].length>0}function Js(){let e=Tr(),[t,n]=J.useState([]),[r,i]=J.useState(!0);return J.useEffect(()=>{let t=!1;return i(!0),e.list(`object`).then(e=>{t||(n((e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value))),i(!1))}).catch(()=>{t||(n([]),i(!1))}),()=>{t=!0}},[e]),{options:t,loading:r}}function Ys(e){let{fields:t}=Ei(e);return J.useMemo(()=>t.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[t])}function Xs({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=Js();return i.length===0?(0,q.jsx)(W,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,q.jsx)(Pr,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function Zs({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=Ys(t);return!t||a.length===0?(0,q.jsx)(W,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,q.jsx)(Pr,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function Qs({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=Ys(t),o=Array.isArray(n)?n:[];return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,q.jsx)(`div`,{className:`flex-1`,children:(0,q.jsxs)(D,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,q.jsx)(ot,{className:`h-8`,children:(0,q.jsx)(vt,{placeholder:`—`})}),(0,q.jsx)(ft,{children:a.map(e=>(0,q.jsx)(he,{value:e.value,children:e.label},e.value))})]})}):(0,q.jsx)(B,{className:`h-8 text-sm`,value:String(e??``),placeholder:`field name`,disabled:i,onChange:e=>{let n=[...o];n[t]=e.target.value,r(n)}}),(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":`Remove`,onClick:()=>r(o.filter((e,n)=>n!==t)),children:(0,q.jsx)($e,{className:`h-4 w-4`})})]},t)),!i&&(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}var $s=Symbol(`remove`);function ec(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)(?:\[(\d+)\])?$/.exec(e);if(!t)return null;n.push({key:t[1],index:t[2]==null?-1:Number(t[2])})}return n.length>0?n:null}function tc(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function nc(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function rc(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return i.length===0?n===$s?t.splice(r,1):t[r]=n:t[r]=rc(t[r],i,n),t}let a={...e||{}};return i.length===0?n===$s?delete a[r]:a[r]=n:a[r]=rc(a[r],i,n),a}function ic(e,t){return nc(e,tc(t))}function ac(e,t,n){let r=tc(t),i=rc(e,r,n===null?$s:n),a=r[0];return{[a]:i[a]}}function oc(e,t){let n=tc(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=nc(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function sc(e,t,n){let r=tc(t),i=rc(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function cc({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),c=s?null:ec(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?ec(d):null,p=t.slots&&typeof t.slots==`object`?t.slots:{},m=s?Array.isArray(p[l])?p[l]:p[l]==null?[]:[p[l]]:[],h=s?m[u]??null:null,g=e=>n({slots:{...p,[l]:e}}),_=e=>g(e===null?m.filter((e,t)=>t!==u):m.map((t,n)=>n===u?e:t)),v=s?f?ic(h||{},f):h:c?ic(t,c):null,y=s?f?oc(h||{},f):{siblings:m,index:u}:c?oc(t,c):null;if(!s&&!c||!v)return(0,q.jsx)(Mr,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),children:(0,q.jsx)(Vr,{message:e.id})});let b=e=>s?_(f?{...h,...ac(h||{},f,{...v,...e})}:{...v,...e}):n(ac(t,c,{...v,...e})),x=v.properties||{},S=typeof t?.object==`string`?t.object:void 0,C=e=>e.objectFrom===`page`?S:e.objectProp!=null&&x[e.objectProp]!=null?String(x[e.objectProp]):void 0,w=e=>x[e]??v[e],T=(e,t)=>b({properties:{...x,[e]:t}}),E=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,q.jsx)(Ar,{label:e.label,value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`boolean`:return(0,q.jsx)(Nr,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`select`:return(0,q.jsx)(Pr,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),options:e.options,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(B,{className:`h-8 text-sm`,value:String(t??``),placeholder:e.placeholder,disabled:o,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:o,"aria-label":`Remove`,onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,q.jsx)($e,{className:`h-4 w-4`})})]},i)),!o&&(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]},i)}case`array`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,q.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:o,"aria-label":`Remove item`,onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,q.jsx)(ut,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>E(t,e=>s[e],(t,i)=>{let o=[...r];o[a]={...s,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!o&&(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,q.jsx)(Xs,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-picker`:return(0,q.jsx)(Zs,{label:e.label,objectName:C(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-list`:return(0,q.jsx)(Qs,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,q.jsx)(W,{label:e.label,value:t(e.name)==null?``:String(t(e.name)),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i)}},D=()=>{s?_(f?{...h,...ac(h||{},f,null)}:null):n(ac(t,c,null)),r()},O=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,q.jsx)(Lr,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=Hr(y.siblings,y.index,e);_({...h,...sc(h||{},f,t)});let n=O([...f.slice(0,-1),{key:f[f.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${l}:${u}.${n}`,label:String(v.id||v.type||e)})}else g(Hr(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}n(sc(t,c,Hr(y.siblings,y.index,e)));let r=O([...c.slice(0,-1),{key:c[c.length-1].key,index:e}]);i?.({kind:`block`,id:r,label:String(v.id||v.type||r)})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,q.jsx)(jr,{label:G(`engine.inspector.pageBlock.remove`,a),onClick:D,disabled:o}),children:[(0,q.jsx)(W,{label:G(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e}),disabled:o,mono:!0}),qs(v.type)&&(0,q.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.pageBlock.properties`,a)}),Ks[v.type].map(e=>E(e,w,T))]})]})}function lc(e){let t=e?.properties||{};switch(e?.type){case`page:tabs`:case`page:accordion`:return(Array.isArray(t.items)?t.items:[]).map((e,t)=>({label:e?.label||e?.key||`Item ${t+1}`,pathSuffix:`properties.items[${t}].children`,children:Array.isArray(e?.children)?e.children:[]}));case`page:card`:return[{label:`Body`,pathSuffix:`properties.body`,children:Array.isArray(t.body)?t.body:[]}];case`page:section`:return[{label:`Content`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];default:return[]}}var uc=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function dc(e){let t=e||{};return uc.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function fc(e){let t={};for(let n of e){let e=Array.isArray(n.components)?n.components:[];e.length===0||!n.name||(t[n.name]=e)}return t}function pc(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:dc(t),shape:`slots`};let n=e.regions;if(Array.isArray(n))return{regions:n,shape:`regions`};let r=e.children;return Array.isArray(r)?{regions:[{name:`children`,components:r}],shape:`children`}:{regions:[],shape:`regions`}}function mc(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function hc(e){return typeof e.label==`string`&&e.label||typeof e.title==`string`&&e.title||typeof e.id==`string`&&e.id||String(e.type??`block`)}var gc=`text/x-objectui-pageblock`;function _c({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>pc(e),[e]),s=n?.kind===`block`?String(n.id):null,c=J.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:fc(e)}):t?.({regions:e})},[t,o]),l=J.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),s=i[e.region]?.components;if(!s)return;let[l]=s.splice(e.comp,1);if(!l)return;let u=i[n.region]?.components;if(!u)return;let d=u.length;if(`appendEnd`in n)d=u.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,d=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,d=t}u.splice(d,0,l),c(i);let f=mc(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:hc(l)})},[t,r,a,c,o]),u=J.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]}));i[e]||(i[e]={name:`region_${e+1}`,components:[]});let s={type:n};i[e].components.push(s),c(i);let l=i[e].components.length-1;r?.({kind:`block`,id:mc(o,e,l,i[e]?.name),label:hc(s)})},[t,r,a,c,o]),d=J.useCallback((e,n,r)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e]?.components?.[n];o&&(i[e].components[n]={...o,label:r||void 0},c(i))},[t,a,c]),f=J.useCallback(()=>{t&&c([...a,{name:`region_${a.length+1}`,components:[]}])},[t,a,c]),p=J.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=ec(i);if(!s)return;let c=tc(s);if(o){let s=o[1],l=Number(o[2]),u=e.slots||{},d=u[s],f=Array.isArray(d)?[...d]:d==null?[]:[d],p=f[l];if(!p)return;let m=nc(p,c)||[];f[l]=rc(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=ec(`${n}.${i}`);if(!o)return;let s=tc(o),c=nc(e,s)||[],l=rc(e,s,[...c,{type:a}]);t({[s[0]]:l[s[0]]}),r?.({kind:`block`,id:`${n}.${i}[${c.length}]`,label:a})}},[t,e,r]),m=J.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,q.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,q.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,q.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`A Page is composed of regions (header / main / sidebar / …). Add a region to start dropping blocks into it.`}),!i&&(0,q.jsx)(`div`,{className:`pt-2`,children:(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,q.jsx)(L,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,q.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,q.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,q.jsx)(vc,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:mc(o,t,n,e.name),label:hc(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>mc(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,q.jsx)(`div`,{className:`pt-1`,children:(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,q.jsx)(L,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function vc({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c,onSelectId:l,onAddNested:u}){let d=Array.isArray(e.components)?e.components:[],[f,p]=J.useState(!1);return(0,q.jsxs)(`section`,{className:H(`rounded-md transition-colors`,f&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(i)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(gc)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(!0))},onDragLeave:e=>{e.currentTarget===e.target&&p(!1)},onDrop:e=>{if(i||(p(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(gc);if(n)try{let e=JSON.parse(n);if(typeof e.region!=`number`||typeof e.comp!=`number`)return;o(e,{region:t,appendEnd:!0})}catch{}},children:[(0,q.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,q.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,q.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,q.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,q.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,q.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:n===`slots`?`Inherited from the default page — add a block to override this slot.`:`Empty region — drop a block here or use the add button below.`}):d.map((s,d)=>{let f=mc(n,t,d,e.name);return(0,q.jsxs)(J.Fragment,{children:[(0,q.jsx)(yc,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,q.jsx)(bc,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,q.jsx)(`div`,{className:`pt-1`,children:(0,q.jsx)(xc,{onPick:e=>s(t,e)})})]})]})}function yc({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Bs[c]?.Icon??Us,u=Gs(c),d=hc(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(gc,JSON.stringify({region:t,comp:n})),e.dataTransfer.effectAllowed=`move`},g=e=>{if(!f)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(gc))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();m(e.clientY-n.top<n.height/2?`before`:`after`)},_=()=>m(null),v=e=>{if(i)return;e.preventDefault(),e.stopPropagation();let r=p??`before`;m(null);let a=e.dataTransfer.getData(gc);if(a)try{let e=JSON.parse(a);if(e.region===t&&e.comp===n)return;o(e,r===`before`?{region:t,before:n}:{region:t,after:n})}catch{}},[y,x]=J.useState(!1),[S,C]=J.useState(d);J.useEffect(()=>{C(d)},[d]);let w=e=>{i||(e.preventDefault(),e.stopPropagation(),C(d),x(!0))},T=()=>{if(i){x(!1);return}let e=S.trim();e&&e!==d&&s(e),x(!1)},E=()=>{C(d),x(!1)};return(0,q.jsxs)(`div`,{className:H(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,q.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,q.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:H(`group w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,q.jsx)(cn,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,q.jsx)(l,{className:H(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,q.jsx)(`input`,{autoFocus:!0,value:S,onChange:e=>C(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),T()):e.key===`Escape`&&(e.preventDefault(),E())},onBlur:T,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,q.jsx)(`span`,{className:H(`text-sm font-medium truncate`,!i&&`cursor-text`),onDoubleClick:w,title:i?void 0:`Double-click to rename`,children:d}),e.id&&e.id!==d&&(0,q.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,q.jsx)(b,{variant:`outline`,className:H(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]})}),p===`after`&&(0,q.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function bc({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=lc(e);return o.length===0?null:(0,q.jsx)(`div`,{className:`ml-5 mt-1.5 space-y-2.5 border-l border-dashed border-border pl-3`,children:o.map((e,o)=>(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,q.jsx)(`div`,{className:`rounded border border-dashed bg-background/40 py-2 px-3 text-[11px] text-muted-foreground`,children:`Empty — add a block.`}):e.children.map((r,a)=>{let o=`${t}.${e.pathSuffix}[${a}]`,s=String(r?.type??``),c=Bs[s]?.Icon??Us;return(0,q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,hc(r))},className:H(`flex w-full items-center gap-2 rounded border px-2.5 py-1.5 text-left text-xs transition-colors`,o===n?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-border bg-background hover:bg-muted/40`),children:[(0,q.jsx)(c,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`flex-1 truncate`,children:hc(r)}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:s})]},a)}),!r&&(0,q.jsx)(xc,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function xc({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?Hs.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Bs[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Hs,[a]);return(0,q.jsxs)(S,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,q.jsx)(qn,{asChild:!0,children:(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,q.jsx)(L,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,q.jsxs)(Kt,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,q.jsx)(`div`,{className:`p-2 border-b`,children:(0,q.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search block type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:Vs[t.category]}),t.types.map(t=>{let r=Bs[t],a=r.Icon;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent text-left`,children:[(0,q.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,Gs(t).icon)}),(0,q.jsx)(`span`,{className:`truncate`,children:r.label}),(0,q.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function Sc({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=J.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=!!e?.interfaceConfig?.source,d=J.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),p=J.useMemo(()=>{if(d===`regions`){let t=e.regions,n=[];return t.forEach((e,t)=>{(Array.isArray(e.components)?e.components:[]).forEach((r,i)=>{n.push({id:`regions[${t}].components[${i}]`,label:r.id||r.type||`${e.name??`region ${t+1}`} · ${i+1}`})})}),n}return(Array.isArray(e.children)?e.children:[]).map((e,t)=>({id:`children[${t}]`,label:e.id||e.type||`block ${t+1}`}))},[e,d]),m=J.useCallback(()=>{if(!c)return;let t={type:`container`};if(d===`regions`){let n=Array.isArray(e.regions)?[...e.regions]:[],a=n.length-1;a<0&&(n.push({name:`main`,components:[]}),a=0);let o={...n[a]},s=Array.isArray(o.components)?[...o.components]:[];s.push(t),o.components=s,n[a]=o,i({regions:n}),r?.({kind:`block`,id:`regions[${a}].components[${s.length-1}]`,label:t.type});return}let n=[...Array.isArray(e.children)?e.children:[],t];i({children:n}),r?.({kind:`block`,id:`children[${n.length-1}]`,label:t.type})},[c,e,i,r,d]);return u?(0,q.jsx)(X,{hint:`page · interface`,children:(0,q.jsx)(Q,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,q.jsx)(Gr,{page:e})})}):!o||Object.keys(o).length<=1?(0,q.jsxs)(X,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,q.jsx)(_c,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,q.jsx)(zs,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:p,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?m:void 0,addLabel:G(`engine.inspector.add.block`,a)}):null,!s&&(0,q.jsx)(Z,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,q.jsx)(X,{hint:`page · design`,children:(0,q.jsx)(_c,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,q.jsx)(X,{hint:`page${s?` · design`:``}`,children:(0,q.jsxs)(Q,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,q.jsx)(zs,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:p,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?m:void 0,addLabel:G(`engine.inspector.add.block`,a)}),(0,q.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,q.jsx)(f,{schema:o})})]})})}function Cc(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object];for(let e of n)if(typeof e==`string`&&e)return e}var wc=new Set([`simple`,`tabbed`,`wizard`,`split`]);function Tc(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.name;return n?{...t,name:n,readOnly:t.readOnly??t.readonly}:t}return String(e)}function Ec(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:wc.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(Tc):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function Dc({name:e,draft:t,editing:n}){let r=J.useMemo(()=>Zi(t)?.schema,[t]),i=J.useMemo(()=>Cc(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=J.useMemo(()=>{if(!r)return{listViews:{},defaultViewId:void 0,defaultViewType:`grid`};let n=String(e)||`default`;return{listViews:{[n]:{...r,label:r.label??t.label??e}},defaultViewId:n,defaultViewType:r.type??`grid`}},[r,t,e]);if(!r&&t.type){let e={...t};return(0,q.jsx)(X,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,q.jsx)(Q,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,q.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,q.jsx)(f,{schema:e})})})})}if(!i)return(0,q.jsx)(X,{hint:`view${a?` · design`:``}`,children:(0,q.jsxs)(Z,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,q.jsx)(`code`,{children:`Object`}),` in the right panel to fetch live data and field options.`]})});if(t.viewKind===`form`&&r){let e=String(r.type??`simple`),t=Ec(i,r);return(0,q.jsx)(X,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,q.jsx)(Q,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,q.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,q.jsx)(f,{schema:t})})})})}let l=J.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);return(0,q.jsx)(X,{hint:`view · ${c}${a?` · design`:``}`,children:(0,q.jsx)(Q,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,q.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,q.jsx)(f,{schema:l})})})})}var Oc=J.lazy(()=>o(()=>import(`./plugin-dashboard-CjtE0zwv.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function kc({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=m(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=J.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=J.useCallback(e=>{n&&n({widgets:e})},[n]),p=J.useCallback(e=>{if(!l)return;let t=Or(`widget`,s.map(e=>e?.id).filter(Boolean)),r=ei[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:Dr(s,{id:t,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),h=J.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),g=u?s.find(e=>e?.id===u)??null:null,_=l?(0,q.jsx)(ni,{onAdd:p,label:G(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,q.jsx)(X,{hint:`dashboard${c?` · design`:``}`,toolbar:_,children:(0,q.jsx)(Z,{children:`Add at least one widget to see a preview.`})}):(0,q.jsx)(X,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:_,children:(0,q.jsxs)(Q,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&g?(0,q.jsx)(Ac,{widget:g,onRename:e=>h(g.id,e),onClose:()=>i?.(null)}):null,(0,q.jsx)(J.Suspense,{fallback:(0,q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,q.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,q.jsx)(`div`,{className:`min-w-[768px]`,children:(0,q.jsx)(Oc,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function Ac({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=J.useState(!1),[o,s]=J.useState(r),c=J.useRef(null);J.useEffect(()=>{s(r),a(!1)},[e.id,r]),J.useEffect(()=>{i&&c.current?.select()},[i]);let l=()=>{let e=o.trim();e&&e!==r&&t(e),a(!1)},u=()=>{s(r),a(!1)},d=ei[e.type]?.icon??null;return(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-primary/5 px-3 py-1.5 text-xs`,children:[d?(0,q.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,q.jsx)(`span`,{className:`rounded bg-primary px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-foreground`,children:`Selected`}),i?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`input`,{ref:c,value:o,onChange:e=>s(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),u())},className:`flex-1 min-w-0 rounded border bg-background px-2 py-0.5 text-xs outline-none focus:ring-1 focus:ring-primary`}),(0,q.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,q.jsx)(Le,{className:`h-3.5 w-3.5`})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`flex-1 min-w-0 truncate text-left font-medium hover:underline`,title:`Click to rename`,children:r||(0,q.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,q.jsx)(bt,{className:`h-3.5 w-3.5`})})]}),(0,q.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})})]})}var jc=J.lazy(()=>o(()=>import(`./plugin-report-DckNGNq6.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Mc({draft:e}){let t=m();if(typeof e.dataset==`string`&&e.dataset){let n=Array.isArray(e.rows)?e.rows.filter(Boolean):[];return(0,q.jsx)(X,{hint:`report · dataset "${e.dataset}"${n.length?` · by `+n.join(`, `):``}`,children:(0,q.jsx)(Q,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,q.jsx)(J.Suspense,{fallback:(0,q.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,q.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,q.jsx)(jc,{schema:e,dataSource:t})})})})})}return(0,q.jsx)(X,{children:(0,q.jsx)(Rs,{icon:(0,q.jsx)(ht,{className:`h-8 w-8`}),title:`Bind a dataset to preview this report`,description:`Since the 9.0 single-form cutover a report renders its dataset's measures (values) grouped by dimensions (rows). Choose a Dataset in the right panel to start designing.`})})}var Nc=`text/x-objectui-nav`;function Pc(e){if(e.kind)return String(e.kind);if(e.object||e.objectName)return`object`;if(e.page||e.pageName)return`page`;if(e.dashboard)return`dashboard`;if(e.report)return`report`;if(Array.isArray(e.children)&&e.children.length)return`group`;let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&/^https?:/i.test(t)?`link`:`item`}function Fc(e){switch(e){case`object`:return ht;case`page`:return A;case`dashboard`:return de;case`report`:return ye;case`link`:return Ee;case`group`:return yn;default:return xt}}var Ic={object:{icon:`text-blue-500`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},page:{icon:`text-violet-500`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},dashboard:{icon:`text-teal-500`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},report:{icon:`text-amber-500`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},link:{icon:`text-indigo-500`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},group:{icon:`text-slate-500`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},item:{icon:`text-zinc-500`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function Lc(e){return Ic[e]??Ic.item}function Rc(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function zc(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Bc({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=J.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),o=r&&r.kind===`nav`?r.id:null,[s,c]=J.useState(null),l=J.useCallback(e=>{n&&n({[t]:e})},[n,t]),u=J.useCallback(()=>{if(!n)return;let e=Dr(a,{label:`New item`,path:``});l(e),i?.({kind:`nav`,id:`${t}[${e.length-1}]`,label:`New item`})},[n,a,l,t,i]),d=J.useCallback(e=>{n&&(l(K(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=J.useCallback((e,r)=>{n&&(l(K(a,e,{...a[e]??{},label:r})),o===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r}))},[n,a,l,t,o,i]),p=J.useCallback((e,r)=>{if(!n)return;let o=r;if(e<r&&(o=r-1),o===e)return;let s=Hr(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Rc(s[o]??{},o)})},[n,a,l,t,i]);return(0,q.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,q.jsx)(`span`,{className:`font-mono uppercase tracking-wide text-muted-foreground`,children:t}),(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px]`,children:[a.length,` `,a.length===1?`item`:`items`]})]}),n&&(0,q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:u,children:[(0,q.jsx)(L,{className:`h-3 w-3`}),` Add nav item`]})]}),(0,q.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Nc)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Nc)&&(e.preventDefault(),s!=null&&(p(s,a.length),c(null)))},children:a.length===0?(0,q.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:n?`Empty — click "Add nav item" to start`:`No top-level nav items yet`}):a.map((e,r)=>(0,q.jsx)(Vc,{item:e,index:r,depth:0,path:`${t}[${r}]`,selectedId:o,canEdit:!!n,onClick:(e,t)=>i?.({kind:`nav`,id:e,label:t}),onRename:e=>f(r,e),onRemove:()=>d(r),onDragStart:()=>c(r),onDragEnd:()=>c(null),onDropBefore:()=>{s!=null&&(p(s,r),c(null))}},r))})]})}function Vc({item:e,index:t,depth:n,path:r,selectedId:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Hc,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Rc(e,t)),onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}),Array.isArray(e.children)&&e.children.map((e,t)=>{let s=`${r}.children[${t}]`;return(0,q.jsx)(Vc,{item:e,index:t,depth:n+1,path:s,selectedId:i,canEdit:a,onClick:o,onRename:()=>void 0,onRemove:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onDropBefore:()=>void 0},t)})]})}function Hc({item:e,index:t,depth:n,path:r,isSelected:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){let f=Pc(e),p=Fc(f),m=Lc(f),h=zc(e),[g,_]=J.useState(!1),[v,y]=J.useState(Rc(e,t)),[x,S]=J.useState(!1),[C,w]=J.useState(null);return J.useEffect(()=>{g||y(Rc(e,t))},[e,t,g]),(0,q.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[C===`before`&&(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,q.jsxs)(`button`,{type:`button`,draggable:a&&!g,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(Nc,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Nc)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Nc)&&(e.preventDefault(),e.stopPropagation(),w(null),d())},onClick:o,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),"aria-pressed":i,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${i?`border-primary ring-1 ring-primary`:`border-border`} ${a&&!g?`cursor-grab active:cursor-grabbing`:``}`,children:[a?(0,q.jsx)(cn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,q.jsx)(`span`,{className:`w-3.5`}),(0,q.jsx)(p,{className:H(`h-3.5 w-3.5 shrink-0`,m.icon)}),g?(0,q.jsx)(`input`,{autoFocus:!0,value:v,onChange:e=>y(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{_(!1);let n=v.trim();n&&n!==Rc(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Rc(e,t)),_(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,q.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),_(!0))},children:Rc(e,t)}),(0,q.jsx)(b,{variant:`outline`,className:H(`text-[10px] font-medium`,m.badge),children:f}),h&&(0,q.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:h}),a&&x&&!g&&(0,q.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":`Remove nav item`,children:(0,q.jsx)(ut,{className:`h-3 w-3`})})]})]})}function Uc(e){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let t=String(e.label??e.title??e.name??e.path??``).trim();if(!t&&!e.children)return null;let n=e.path??e.href??e.route??e.url??void 0,r;e.object||e.objectName?r=`object`:e.page||e.pageName?r=`page`:e.dashboard?r=`dashboard`:e.report?r=`report`:typeof n==`string`&&/^https?:/i.test(n)?r=`link`:Array.isArray(e.children)&&e.children.length&&(r=`group`);let i=Array.isArray(e.children)?Uc(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Wc(e){switch(e){case`object`:return ht;case`page`:return A;case`dashboard`:return de;case`report`:return ye;default:return xt}}function Gc({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,c=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:l,navItems:u}=J.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:Uc(n)};return{rootKey:null,navItems:[]}},[t]),d=l??`nav`,f=!!(n&&i),p=f&&!!a,m=r&&r.kind===`nav`?r.id:null,h=f?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,g=o?`/apps/${encodeURIComponent(o)}/`:null;return(0,q.jsx)(X,{hint:`app`,toolbar:g&&(0,q.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,q.jsx)(_e,{className:`h-3 w-3`})]}),children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,q.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,q.jsx)(Bc,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,q.jsxs)(Z,{children:[`No top-level nav items. Add `,(0,q.jsx)(`code`,{children:`nav`}),` / `,(0,q.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,q.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,q.jsx)(Kc,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Kc({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Wc(e.kind),s=qc(t,e.path);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40 ${i?`cursor-pointer`:``} ${a===r?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+n*16}px`},onClick:i?t=>{t.stopPropagation(),i(r,e)}:void 0,children:[(0,q.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,q.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,q.jsx)(_e,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,q.jsx)(Kc,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function qc(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function Jc(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,q.jsx)(Yc,{...e,icon:t===`password`?(0,q.jsx)(un,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(Gt,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(En,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(Se,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(Jn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(Je,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.pickDate`,n)});case`time`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(Ln,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,q.jsx)(Xc,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,q.jsx)(Qt,{disabled:!0}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??G(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,q.jsx)(Zc,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,q.jsx)(Zc,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,q.jsx)(Qc,{...e});case`image`:case`avatar`:return(0,q.jsx)($c,{icon:(0,q.jsx)(yt,{className:`h-4 w-4`}),label:G(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,q.jsx)($c,{icon:(0,q.jsx)(Ue,{className:`h-4 w-4`}),label:U(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,q.jsx)($c,{icon:(0,q.jsx)(Ue,{className:`h-4 w-4`}),label:G(`designer.stub.qrcode`,n)});case`color`:return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,q.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,q.jsx)(It,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,q.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,q.jsx)(Cn,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,q.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,q.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,q.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,q.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,q.jsx)(Yc,{...e,icon:(0,q.jsx)(ee,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.latLng`,n)});case`address`:return(0,q.jsx)(Xc,{...e,placeholder:e.placeholder??`Street
|
|
11
|
+
City, State ZIP
|
|
12
|
+
Country`});case`formula`:case`summary`:return(0,q.jsx)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:e.formula?`ƒ ${e.formula}`:`ƒ ${G(`designer.stub.computed`,n)}`});case`composite`:return(0,q.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:G(`designer.stub.composite`,n)});case`repeater`:return(0,q.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:G(`designer.stub.repeater`,n)});case`vector`:return(0,q.jsxs)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:[`[0.124, 0.337, …] `,e.placeholder?`(${e.placeholder})`:``]});default:return(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(B,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function Yc({placeholder:e,icon:t}){return(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(B,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,q.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function Xc({placeholder:e,mono:t}){return(0,q.jsx)(`textarea`,{disabled:!0,placeholder:e??``,className:`w-full min-h-[60px] text-sm rounded-md border bg-background px-2 py-1.5 disabled:opacity-100 `+(t?`font-mono text-xs`:``)})}function Zc({options:e,placeholder:t,single:n,locale:r}){let i=e??[],a=i.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,q.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:`truncate`,children:a[0]?.label||a[0]?.value||t||G(`designer.stub.select`,r)}),(0,q.jsx)(re,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,q.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[a.length===0?(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||G(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,q.jsx)(b,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function Qc({referenceTo:e,placeholder:t,locale:n}){let r=e?Qr.lookup:null;return(0,q.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,q.jsx)(ge,{className:`h-3.5 w-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?U(`designer.stub.searchRef`,n,{ref:e}):G(`designer.stub.chooseRelated`,n))}),e&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,q.jsx)(Ze,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function $c({icon:e,label:t}){return(0,q.jsxs)(`div`,{className:`h-16 w-full border-2 border-dashed rounded flex flex-col items-center justify-center gap-1 text-muted-foreground bg-muted/20`,children:[e,(0,q.jsx)(`span`,{className:`text-[11px]`,children:t})]})}var el=e=>(e??``).toLowerCase().startsWith(`zh`),tl=(e,t)=>e?el(t)?e.labelZh:e.label:void 0,nl=(e,t)=>(el(t)?Kr:Jr)[e];function rl({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,c=J.useMemo(()=>ci(t.fields),[t]),l=J.useMemo(()=>n?Ti(n.fields,t.fields):null,[n,t]),u=l?l.counts.added+l.counts.changed+l.counts.removed:0,[d,f]=J.useState(!1);J.useEffect(()=>{d&&u===0&&f(!1)},[d,u]);let p=d&&u>0,m=e=>p?l?.byName[e]?.status:void 0,h=e=>p?l?.byName[e]?.changedKeys??[]:[],g=J.useMemo(()=>mi(t.fieldGroups),[t]),_=g.length>0,v=J.useMemo(()=>Si(c,g,{includeEmptyDeclared:!s}),[c,g,s]),[y,b]=J.useState({}),x=e=>e??`__ungrouped__`,S=J.useCallback(e=>{let t=e??`__ungrouped__`;b(e=>({...e,[t]:!e[t]}))},[]),C=v.length>0&&v.every(e=>y[x(e.key)]),w=J.useCallback(e=>{b(()=>{let t={};for(let n of v)t[x(n.key)]=e;return t})},[v]),T=i?.kind===`field`?String(i.id):null,E=c.entries.filter(e=>!!e.def.required).length,D=J.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[O,k]=J.useState(()=>new Set),A=J.useRef(null),j=J.useMemo(()=>v.flatMap(e=>e.entries.map(e=>e.name)),[v]);J.useEffect(()=>{k(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>c.entries.some(t=>t.name===e)));return t.size===e.size?e:t})},[c]);let ee=J.useCallback((e,t)=>{let n=e.name;if(!s&&t&&(t.metaKey||t.ctrlKey)){k(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),A.current=n;return}if(!s&&t&&t.shiftKey&&A.current&&A.current!==n){let e=j.indexOf(A.current),t=j.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];k(new Set(j.slice(n,r+1)));return}}O.size&&k(new Set),A.current=n,D(e)},[s,j,O,D]),te=J.useCallback(()=>k(new Set),[]),ne=J.useCallback(()=>{if(!r||O.size===0)return;let e=c.entries.filter(e=>!O.has(e.name));r({fields:li({shape:c.shape,entries:e})}),T&&O.has(T)&&a?.(null),k(new Set)},[r,O,c,T,a]),re=J.useCallback(e=>{if(!r||O.size===0)return;let t=c.entries.map(t=>O.has(t.name)?{name:t.name,def:{...t.def,group:e??void 0}}:t);r({fields:li({shape:c.shape,entries:t})})},[r,O,c]),M=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(e=>e.name),i=e===`select`?`status`:e,o=1,s=i;for(;n.includes(s);)o+=1,s=`${i}_${o}`;let l=di(s,e);t&&(l.def={...l.def,group:t});let u=c.entries.length;if(t){for(let e=c.entries.length-1;e>=0;--e)if(c.entries[e].def.group===t){u=e+1;break}}let d=c.entries.slice();d.splice(u,0,l),r({fields:li({shape:c.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(l.def.label??s)})},[r,a,c]),ie=J.useCallback(()=>{if(!r)return;let e=gi(g,U(`designer.canvas.sectionN`,o,{n:g.length+1})),t=e[e.length-1];r({fieldGroups:e}),b(e=>({...e,[t.key]:!1}))},[r,g,o]),N=J.useCallback((e,t)=>{r&&r({fieldGroups:_i(g,e,t)})},[r,g]),ae=J.useCallback(e=>{if(!r)return;let t=bi(c,e);r({fieldGroups:vi(g,e),fields:li(t)})},[r,g,c]),oe=J.useCallback((e,t)=>{r&&r({fieldGroups:yi(g,e,t)})},[r,g]),se=J.useCallback((e,t,n)=>{if(!r||e===t)return;let i=c.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[o]=i.splice(a,1),s=i.findIndex(e=>e.name===t),l=s>=0?i[s]:void 0;if(l){let e=typeof l.def.group==`string`?l.def.group:void 0;e!==(typeof o.def.group==`string`?o.def.group:void 0)&&(o.def={...o.def,group:e})}s<0?i.push(o):i.splice(n===`before`?s:s+1,0,o),r({fields:li({shape:c.shape,entries:i})})},[r,c]),ce=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let a=typeof n[i].def.group==`string`?n[i].def.group:null,o=i+t;for(;o>=0&&o<n.length&&(typeof n[o].def.group==`string`?n[o].def.group:null)!==a;)o+=t;if(o<0||o>=n.length)return;let s=n[i];n[i]=n[o],n[o]=s,r({fields:li({shape:c.shape,entries:n})})},[r,c]),le=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let[a]=n.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){n.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let o=n.length;for(let e=n.length-1;e>=0;--e)if((typeof n[e].def.group==`string`?n[e].def.group:null)===t){o=e+1;break}n.splice(o,0,a),r({fields:li({shape:c.shape,entries:n})})},[r,c]),ue=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);r({fields:li({shape:c.shape,entries:n})})},[r,c]),de=J.useCallback(e=>{e.target===e.currentTarget&&T&&a?.(null)},[a,T]),fe=c.entries.length===0,pe=_||v.length>1;return(0,q.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:de,"data-object-name":e,children:[!s&&O.size>0&&(0,q.jsx)(al,{count:O.size,groups:g,onMoveToGroup:re,onDelete:ne,onClear:te,locale:o}),(0,q.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:de,children:[!fe&&(0,q.jsx)(il,{fieldCount:c.entries.length,requiredCount:E,sectionCount:g.length,allCollapsed:C,onToggleAll:pe?()=>w(!C):void 0,reviewAvailable:u>0,reviewing:p,diffCounts:l?.counts,onToggleReview:()=>f(e=>!e),locale:o}),fe?(0,q.jsx)(ul,{onAdd:s?void 0:M,locale:o}):(0,q.jsx)(`div`,{className:`space-y-5`,children:v.map(e=>{let t=e.key?g.findIndex(t=>t.key===e.key):-1;return(0,q.jsxs)(ol,{groupKey:e.key,label:e.key===null?G(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:pe,collapsed:!!y[x(e.key)],onToggleCollapse:()=>S(e.key),readOnly:s,locale:o,canMoveUp:t>0,canMoveDown:t>=0&&t<g.length-1,onRename:e.key?t=>N(e.key,t):void 0,onRemove:e.key?()=>ae(e.key):void 0,onMove:e.key?t=>oe(e.key,t):void 0,onAddField:s?void 0:t=>M(t,e.key),onDropField:s?void 0:le,children:[e.entries.map(e=>(0,q.jsx)(ll,{entry:e,selected:e.name===T,multiSelected:O.has(e.name),diffStatus:m(e.name),changedKeys:h(e.name),readOnly:s,locale:o,onClick:t=>ee(e,t),onReorder:s?void 0:se,onRenameLabel:s?void 0:ue,onMoveOffset:s?void 0:t=>ce(e.name,t)},e.name)),e.entries.length===0&&(0,q.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:G(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),p&&l&&l.removed.length>0&&(0,q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,q.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:G(`designer.canvas.diffRemoved`,o)}),l.removed.map(e=>(0,q.jsx)(cl,{entry:e,locale:o},e.name))]}),!fe&&!s&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,q.jsx)(dl,{onPick:e=>M(e),locale:o}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:ie,children:[(0,q.jsx)(en,{className:`h-3.5 w-3.5`}),G(`designer.canvas.addSection`,o)]}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>Cr(),children:[(0,q.jsx)(mn,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAi`,o)]})]})]})]})}function il({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,G(`designer.canvas.diffAdded`,l),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,G(`designer.canvas.diffChanged`,l),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,G(`designer.canvas.diffRemoved`,l),(0,q.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:G(`designer.canvas.reviewVsPublished`,l)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,G(`designer.canvas.fields`,l),(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,G(`designer.canvas.required`,l),n>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,q.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,G(`designer.canvas.sections`,l)]})]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,q.jsxs)(`button`,{type:`button`,onClick:c,className:H(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 transition-colors`,o?`bg-primary/10 text-primary hover:bg-primary/15`:`hover:bg-accent hover:text-foreground`),children:[(0,q.jsx)(Rt,{className:`h-3 w-3`}),G(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,q.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:[r?(0,q.jsx)(Ft,{className:`h-3 w-3`}):(0,q.jsx)(or,{className:`h-3 w-3`}),G(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function al({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=J.useState(!1);return(0,q.jsxs)(`div`,{className:`sticky top-0 z-20 flex items-center gap-2 border-b border-primary/20 bg-primary/10 backdrop-blur px-6 py-2 text-sm`,children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:U(`designer.canvas.bulkSelected`,a,{n:e})}),(0,q.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:G(`designer.canvas.bulkHint`,a)}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,q.jsxs)(S,{open:o,onOpenChange:s,children:[(0,q.jsx)(qn,{asChild:!0,children:(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,q.jsx)(tr,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkMoveTo`,a),(0,q.jsx)(re,{className:`h-3 w-3`})]})}),(0,q.jsxs)(Kt,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>{n(null),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent`,children:G(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>{n(e.key),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent truncate`,children:e.label||e.key},e.key))]})]}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,q.jsx)(ut,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkDelete`,a)]}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,q.jsx)($e,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkClear`,a)]})]})]})}function ol({groupKey:e,label:t,count:n,showHeader:r,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,onRename:u,onRemove:d,onMove:f,onAddField:p,onDropField:m,children:h}){let[g,_]=J.useState(!1);return(0,q.jsxs)(`section`,{className:H(`space-y-2.5 rounded-md transition-colors`,g&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!m)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(!0))},onDragLeave:e=>{e.currentTarget===e.target&&_(!1)},onDrop:t=>{if(!m)return;if(t.defaultPrevented){_(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);_(!1),n&&m(n,e)},children:[r&&(0,q.jsx)(sl,{label:t,count:n,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,dropActive:g,onRename:u,onRemove:d,onMove:f,onAddField:p}),!i&&(0,q.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function sl({label:e,count:t,collapsed:n,onToggleCollapse:r,readOnly:i,locale:a,canMoveUp:o,canMoveDown:s,dropActive:c,onRename:l,onRemove:u,onMove:d,onAddField:f}){let[p,m]=J.useState(!1),[h,g]=J.useState(e);J.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?rt:re;return(0,q.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-accent hover:text-foreground transition-colors shrink-0`,"aria-label":G(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,q.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,q.jsx)(`input`,{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`?(t.preventDefault(),_()):t.key===`Escape`&&(t.preventDefault(),g(e),m(!1))},onBlur:_,className:`text-[11px] font-medium uppercase tracking-wider px-1 py-0.5 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1 max-w-[220px]`}):(0,q.jsx)(`span`,{className:H(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?G(`designer.canvas.renameHint`,a):void 0,children:e}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,q.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:G(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 opacity-0 group-hover/sec:opacity-100 focus-within:opacity-100 transition-opacity`,children:[f&&(0,q.jsx)(dl,{onPick:f,compact:!0,locale:a}),d&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>d(-1),disabled:!o,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":G(`designer.canvas.moveSectionUp`,a),children:(0,q.jsx)(Sn,{className:`h-3 w-3`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>d(1),disabled:!s,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":G(`designer.canvas.moveSectionDown`,a),children:(0,q.jsx)(Lt,{className:`h-3 w-3`})})]}),u&&(0,q.jsx)(`button`,{type:`button`,onClick:u,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":G(`designer.canvas.removeSection`,a),title:G(`designer.canvas.removeSectionHint`,a),children:(0,q.jsx)(ut,{className:`h-3 w-3`})})]})]})}function cl({entry:e,locale:t}){let n=e.def,r=Qr[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,q.jsx)(`div`,{className:`rounded-md border border-dashed border-destructive/30 bg-destructive/[0.03] px-3.5 py-2.5 opacity-80`,children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[r&&(0,q.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,q.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,q.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,q.jsx)(b,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:G(`designer.canvas.diffRemoved`,t)})]})})}function ll({entry:e,selected:t,multiSelected:n,diffStatus:r,changedKeys:i,readOnly:a,locale:o,onClick:s,onReorder:c,onRenameLabel:l,onMoveOffset:u}){let d=e.def,f=typeof d.type==`string`?d.type:`text`,p=Qr[f],m=p?.Icon,h=Xr[p?.category??`advanced`],g=typeof d.label==`string`?d.label:e.name,_=!!d.required,v=typeof d.description==`string`?d.description:null,y=Array.isArray(d.options)?d.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,x=typeof d.reference==`string`?d.reference:void 0,S=typeof d.formula==`string`?d.formula:void 0,C=typeof d.placeholder==`string`?d.placeholder:void 0,[w,T]=J.useState(null),E=!!c,[D,O]=J.useState(!1),[k,A]=J.useState(g);J.useEffect(()=>{A(g)},[g]);let j=e=>{l&&(e.preventDefault(),e.stopPropagation(),A(g),O(!0))},ee=()=>{if(!l){O(!1);return}let t=k.trim();t&&t!==g&&l(e.name,t),O(!1)},te=()=>{A(g),O(!1)};return(0,q.jsxs)(`div`,{className:H(`relative`,w===`before`&&`pt-1.5`),onDragOver:e=>{if(!E)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();T(e.clientY-n.top<n.height/2?`before`:`after`)},onDragLeave:()=>T(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);T(null),n&&n!==e.name&&c(n,e.name,w??`before`)},children:[w===`before`&&(0,q.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,q.jsxs)(`div`,{role:`button`,tabIndex:a?-1:0,onClick:s,onKeyDown:e=>{if(e.target===e.currentTarget){if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u&&(e.preventDefault(),u(e.key===`ArrowUp`?-1:1));return}(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s?.())}},draggable:E,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:H(`group block w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,t?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,n&&`border-primary/60 ring-2 ring-primary/40 bg-primary/[0.04]`,r===`added`&&`border-l-[3px] border-l-emerald-500`,r===`changed`&&`border-l-[3px] border-l-amber-500`,a&&`cursor-default`,E&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[n&&(0,q.jsx)(Vn,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),E&&!n&&(0,q.jsx)(cn,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,q.jsx)(m,{className:H(`h-3.5 w-3.5 shrink-0`,h.icon)}),D?(0,q.jsx)(`input`,{autoFocus:!0,value:k,onChange:e=>A(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),ee()):e.key===`Escape`&&(e.preventDefault(),te())},onBlur:ee,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,q.jsx)(`span`,{className:H(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:j,title:l?G(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(0,q.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,q.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,q.jsx)(b,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:G(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,q.jsx)(b,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?U(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:G(`designer.canvas.diffChanged`,o)}),(0,q.jsx)(b,{variant:`outline`,className:H(`text-[10px] font-medium`,h.badge),children:tl(p,o)??f})]})]}),v&&(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,q.jsx)(Jc,{type:f,label:g,placeholder:C,options:y,referenceTo:x,formula:S,locale:o})]}),w===`after`&&(0,q.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function ul({onAdd:e,locale:t}){return(0,q.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:G(`designer.canvas.noFields`,t)}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(`designer.canvas.noFieldsHint`,t)}),e&&(0,q.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,q.jsx)(dl,{onPick:e,locale:t}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>Cr(),children:[(0,q.jsx)(mn,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAiGenerate`,t)]})]})]})}function dl({onPick:e,compact:t,locale:n}){let[r,i]=J.useState(!1),[a,o]=J.useState(``),s=a.trim().toLowerCase(),c=J.useMemo(()=>s?qr.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Qr[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):qr,[s,a]);return(0,q.jsxs)(S,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,q.jsx)(qn,{asChild:!0,children:t?(0,q.jsx)(`button`,{type:`button`,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":G(`designer.canvas.addFieldToSection`,n),title:G(`designer.canvas.addFieldToSection`,n),children:(0,q.jsx)(L,{className:`h-3 w-3`})}):(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,q.jsx)(L,{className:`h-3.5 w-3.5`}),G(`designer.canvas.addField`,n)]})}),(0,q.jsxs)(Kt,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,q.jsx)(`div`,{className:`p-2 border-b`,children:(0,q.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:G(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:G(`designer.canvas.noMatchingTypes`,n)}):c.map(t=>(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:nl(t.category,n)}),(0,q.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=Qr[t],a=r.Icon;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),i(!1),o(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,q.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,Xr[r.category].icon)}),(0,q.jsx)(`span`,{className:`truncate`,children:tl(r,n)})]},t)})})]},t.category))})]})]})}function fl({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,q.jsx)(X,{hint:`object · designer`,children:(0,q.jsx)(Q,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,q.jsx)(rl,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,q.jsx)(X,{hint:`object`,children:(0,q.jsx)(Z,{children:G(`designer.canvas.nameToStart`,o)})})}function pl(e){let t=new Set;for(let n of e.matchAll(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g))t.add(n[1]);for(let n of e.matchAll(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g))t.add(n[1]);return Array.from(t).sort()}function ml(e,t){return t[e]??``}function hl(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>ml(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>ml(n,t))}function gl({draft:e}){let t=String(e.subject??``),n=String(e.from??e.fromAddress??``),r=String(e.to??``),i=String(e.bodyHtml??e.html??e.body??``),a=String(e.bodyText??e.text??``),o=J.useMemo(()=>{let e=new Set;for(let n of pl(t))e.add(n);for(let t of pl(i))e.add(t);for(let t of pl(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=J.useState({}),l=hl(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
13
|
+
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
14
|
+
a{color:#2563eb;}
|
|
15
|
+
</style></head><body>${(i?hl(i,s):hl(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,q.jsx)(X,{hint:`email_template`,children:(0,q.jsx)(Z,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,q.jsx)(X,{hint:`email_template`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,q.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,q.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,q.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,q.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,q.jsx)(`iframe`,{title:`Email preview`,srcDoc:u,sandbox:`allow-same-origin`,className:`w-full min-h-[400px] max-h-[60vh] border rounded bg-white`})]}),(0,q.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,q.jsx)(Ie,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,q.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,q.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,q.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,q.jsxs)(`label`,{className:`block`,children:[(0,q.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,q.jsx)(`input`,{type:`text`,value:s[e]??``,onChange:t=>c(n=>({...n,[e]:t.target.value})),placeholder:`sample for ${e}`,className:`w-full text-xs px-2 py-1 border rounded bg-background`})]},e))})]})]})})})}function _l(e){return typeof e==`number`&&Number.isFinite(e)}function vl(e){return _l(e.ui?.x)&&_l(e.ui?.y)}function yl(e,t){let n=new Map;if(e.length===0)return n;let r=new Map(e.map(e=>[e.id,e])),i=new Map(e.map((e,t)=>[e.id,t])),a=new Map,o=new Map;for(let t of e)o.set(t.id,0);for(let e of t)!r.has(e.source)||!r.has(e.target)||e.source===e.target||(a.has(e.source)||a.set(e.source,[]),a.get(e.source).push(e.target),o.set(e.target,(o.get(e.target)??0)+1));let s=[];for(let t of e)t.type===`start`&&s.push(t.id);for(let t of e)(o.get(t.id)??0)===0&&!s.includes(t.id)&&s.push(t.id);s.length===0&&s.push(e[0].id);let c=new Map,l=[];for(let e of s)c.set(e,0),l.push(e);let u=e.length*Math.max(1,t.length)+e.length+1,d=0;for(;l.length&&d<u;){d+=1;let e=l.shift(),t=c.get(e)??0;for(let n of a.get(e)??[]){let e=t+1;(c.get(n)??-1)<e&&(c.set(n,e),l.push(n))}}let f=0;for(let e of c.values())f=Math.max(f,e);for(let t of e)c.has(t.id)||(f+=1,c.set(t.id,f));let p=new Map;for(let t of e){let e=c.get(t.id)??0;p.has(e)||p.set(e,[]),p.get(e).push(t.id)}for(let e of p.values())e.sort((e,t)=>(i.get(e)??0)-(i.get(t)??0));let m=[...p.keys()].sort((e,t)=>e-t);for(let e of m){let t=p.get(e),r=-(t.length*240+(t.length-1)*44)/2;t.forEach((t,i)=>{n.set(t,{x:r+i*284,y:e*122})})}let h=1/0,g=1/0;for(let e of n.values())h=Math.min(h,e.x),g=Math.min(g,e.y);if(Number.isFinite(h)&&Number.isFinite(g)){let e=28-h,t=28-g;for(let[r,i]of n)n.set(r,{x:i.x+e,y:i.y+t})}for(let t of e)vl(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function bl(e){let t=0,n=0;for(let r of e.values())t=Math.max(t,r.x+240),n=Math.max(n,r.y+66);return{width:t+28,height:n+28}}function xl(e){return{x:e.x+240/2,y:e.y+66}}function Sl(e){return{x:e.x+240/2,y:e.y}}function Cl(e,t){let n=Math.max(Math.abs(t.y-e.y)*.5,24),r={x:e.x,y:e.y+n},i={x:t.x,y:t.y-n};return`M ${e.x},${e.y} C ${r.x},${r.y} ${i.x},${i.y} ${t.x},${t.y}`}function wl(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Tl(e,t){return e.id||`${e.source}->${e.target}#${t}`}function El(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Dl(e){switch(e){case`start`:return oe;case`end`:return Qn;case`decision`:case`branch`:case`gateway`:return at;case`wait`:case`timer`:case`delay`:return ce;case`boundary_event`:case`signal`:return Pt;case`subflow`:case`flow`:return ar;case`create_record`:return ne;case`update_record`:return fn;case`delete_record`:return lr;case`get_record`:return nt;case`http_request`:case`webhook`:return En;case`script`:case`script_task`:return We;case`screen`:case`user_task`:return er;case`approval`:return Fe;case`connector_action`:case`service_task`:return mt;case`assignment`:return pn;case`loop`:case`for_each`:return je;case`map`:return M;case`parallel_gateway`:case`join_gateway`:case`parallel`:return Hn;case`try_catch`:return Ot;default:return an}}var Ol={start:{icon:`text-emerald-600 dark:text-emerald-400`,accent:`border-l-emerald-500`,label:`text-emerald-600 dark:text-emerald-400`,chip:`bg-emerald-500/10 ring-1 ring-inset ring-emerald-500/20 dark:bg-emerald-400/10`},end:{icon:`text-rose-600 dark:text-rose-400`,accent:`border-l-rose-500`,label:`text-rose-600 dark:text-rose-400`,chip:`bg-rose-500/10 ring-1 ring-inset ring-rose-500/20 dark:bg-rose-400/10`},decision:{icon:`text-amber-600 dark:text-amber-400`,accent:`border-l-amber-500`,label:`text-amber-600 dark:text-amber-400`,chip:`bg-amber-500/10 ring-1 ring-inset ring-amber-500/20 dark:bg-amber-400/10`},wait:{icon:`text-blue-600 dark:text-blue-400`,accent:`border-l-blue-500`,label:`text-blue-600 dark:text-blue-400`,chip:`bg-blue-500/10 ring-1 ring-inset ring-blue-500/20 dark:bg-blue-400/10`},signal:{icon:`text-violet-600 dark:text-violet-400`,accent:`border-l-violet-500`,label:`text-violet-600 dark:text-violet-400`,chip:`bg-violet-500/10 ring-1 ring-inset ring-violet-500/20 dark:bg-violet-400/10`},subflow:{icon:`text-indigo-600 dark:text-indigo-400`,accent:`border-l-indigo-500`,label:`text-indigo-600 dark:text-indigo-400`,chip:`bg-indigo-500/10 ring-1 ring-inset ring-indigo-500/20 dark:bg-indigo-400/10`},task:{icon:`text-slate-500 dark:text-slate-400`,accent:`border-l-slate-400`,label:`text-slate-500 dark:text-slate-400`,chip:`bg-slate-500/10 ring-1 ring-inset ring-slate-500/20 dark:bg-slate-400/10`},record:{icon:`text-cyan-600 dark:text-cyan-400`,accent:`border-l-cyan-500`,label:`text-cyan-600 dark:text-cyan-400`,chip:`bg-cyan-500/10 ring-1 ring-inset ring-cyan-500/20 dark:bg-cyan-400/10`},integration:{icon:`text-fuchsia-600 dark:text-fuchsia-400`,accent:`border-l-fuchsia-500`,label:`text-fuchsia-600 dark:text-fuchsia-400`,chip:`bg-fuchsia-500/10 ring-1 ring-inset ring-fuchsia-500/20 dark:bg-fuchsia-400/10`},approval:{icon:`text-teal-600 dark:text-teal-400`,accent:`border-l-teal-500`,label:`text-teal-600 dark:text-teal-400`,chip:`bg-teal-500/10 ring-1 ring-inset ring-teal-500/20 dark:bg-teal-400/10`},loop:{icon:`text-sky-600 dark:text-sky-400`,accent:`border-l-sky-500`,label:`text-sky-600 dark:text-sky-400`,chip:`bg-sky-500/10 ring-1 ring-inset ring-sky-500/20 dark:bg-sky-400/10`},screen:{icon:`text-pink-600 dark:text-pink-400`,accent:`border-l-pink-500`,label:`text-pink-600 dark:text-pink-400`,chip:`bg-pink-500/10 ring-1 ring-inset ring-pink-500/20 dark:bg-pink-400/10`},assignment:{icon:`text-purple-600 dark:text-purple-400`,accent:`border-l-purple-500`,label:`text-purple-600 dark:text-purple-400`,chip:`bg-purple-500/10 ring-1 ring-inset ring-purple-500/20 dark:bg-purple-400/10`}};function kl(e){switch(e){case`start`:return Ol.start;case`end`:return Ol.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return Ol.decision;case`wait`:case`timer`:case`delay`:return Ol.wait;case`boundary_event`:case`signal`:case`try_catch`:return Ol.signal;case`subflow`:case`flow`:return Ol.subflow;case`approval`:return Ol.approval;case`loop`:case`for_each`:case`map`:return Ol.loop;case`screen`:case`user_task`:return Ol.screen;case`assignment`:return Ol.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return Ol.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return Ol.integration;default:return Ol.task}}function Al({type:e,className:t}){return J.createElement(Dl(e),{className:t,"aria-hidden":!0})}var jl=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Ml(e){switch(e){case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return`Data`;case`decision`:case`branch`:case`gateway`:case`loop`:case`for_each`:case`map`:case`assignment`:case`parallel_gateway`:case`join_gateway`:case`parallel`:case`try_catch`:return`Logic`;case`approval`:case`screen`:case`user_task`:return`Human`;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return`Integration`;default:return`Flow`}}var Nl=[{type:`create_record`,label:`Create record`,hint:`Insert a new record`,category:`Data`},{type:`update_record`,label:`Update record`,hint:`Modify an existing record`,category:`Data`},{type:`get_record`,label:`Get record`,hint:`Query records`,category:`Data`},{type:`delete_record`,label:`Delete record`,hint:`Remove matching records`,category:`Data`},{type:`decision`,label:`Decision`,hint:`Branch on a condition`,category:`Logic`},{type:`loop`,label:`Loop`,hint:`Iterate over a collection`,category:`Logic`},{type:`assignment`,label:`Set variables`,hint:`Assign flow variables`,category:`Logic`},{type:`parallel`,label:`Parallel`,hint:`Run branches concurrently, join at end`,category:`Logic`},{type:`try_catch`,label:`Try / Catch`,hint:`Protect steps with error handling and retry`,category:`Logic`},{type:`approval`,label:`Approval`,hint:`Pause for a human decision`,category:`Human`},{type:`screen`,label:`Screen`,hint:`Collect input from a user`,category:`Human`},{type:`http_request`,label:`HTTP request`,hint:`Call an external API`,category:`Integration`},{type:`connector_action`,label:`Connector`,hint:`Run an integration action`,category:`Integration`},{type:`script`,label:`Script`,hint:`Run custom code`,category:`Integration`},{type:`subflow`,label:`Subflow`,hint:`Invoke another flow`,category:`Flow`},{type:`wait`,label:`Wait`,hint:`Pause for an event or timer`,category:`Flow`},{type:`end`,label:`End`,hint:`Terminate the flow`,category:`Flow`}];function Pl(e){let t=Nl.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Fl(e){switch(e){case`start`:return{};case`wait`:return{waitEventConfig:{eventType:`timer`,onTimeout:`fail`}};case`connector_action`:return{connectorConfig:{connectorId:``,actionId:``,input:{}}};case`boundary_event`:return{boundaryConfig:{attachedToNodeId:``,eventType:`error`,interrupting:!0}};case`approval`:return{config:{approvers:[{type:`manager`}],behavior:`first_response`,lockRecord:!0}};case`http_request`:return{config:{method:`GET`}};case`script`:return{};default:return{}}}function Il({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=kl(e);return(0,q.jsxs)(`div`,{className:`absolute transition-opacity duration-200`,style:{left:r.x,top:r.y,width:240,height:66,opacity:s?.35:1},children:[(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":i,onPointerDown:c,onClick:e=>{e.stopPropagation(),l?.()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),l?.())},className:H(`group flex h-full w-full items-center gap-3 rounded-xl border bg-card px-2.5 py-2 text-left shadow-sm outline-none`,`transition-[transform,box-shadow,border-color] duration-150 ease-out will-change-transform`,`hover:-translate-y-0.5 hover:shadow-lg hover:shadow-foreground/[0.06] focus-visible:ring-2 focus-visible:ring-primary/40`,a?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o===`active`?`border-sky-500 shadow-md shadow-sky-500/20 ring-2 ring-sky-400/60`:o===`visited`?`border-emerald-500/70 ring-1 ring-emerald-400/40`:i?`border-primary shadow-md ring-2 ring-primary/30`:`border-border/80`),children:[(0,q.jsx)(`div`,{className:H(`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-transform duration-150 group-hover:scale-105`,d.chip,o===`active`&&`animate-pulse`),children:(0,q.jsx)(Al,{type:e,className:H(`h-[18px] w-[18px]`,d.icon)})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{title:t,className:`truncate text-[13px] font-semibold leading-tight text-foreground`,children:t}),(0,q.jsxs)(`div`,{className:`mt-1 flex items-baseline gap-1.5 leading-tight`,children:[(0,q.jsx)(`span`,{className:H(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.08em]`,d.label),children:e}),n&&(0,q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,title:n,children:n})]})]})]}),a&&e!==`end`&&(0,q.jsx)(`button`,{type:`button`,title:`Add connected node`,"aria-label":`Add connected node`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),u?.()},className:H(`absolute left-1/2 -bottom-3 z-10 inline-flex h-6 w-6 -translate-x-1/2 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm transition-colors`,`opacity-0 hover:border-primary hover:text-primary group-hover:opacity-100 focus-visible:opacity-100`),children:(0,q.jsx)(L,{className:`h-3.5 w-3.5`})})]})}function Ll({items:e=Nl,onPick:t,onClose:n}){let r=J.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??Ml(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return jl.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=kl(e.type);return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>t(e.type),className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:H(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,q.jsx)(Al,{type:e.type,className:H(`h-[15px] w-[15px]`,n.icon)})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`truncate text-[13px] font-medium`,children:e.label}),e.hint&&(0,q.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.hint})]})]},e.type)};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-20`,onClick:n,"aria-hidden":!0}),(0,q.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-1.5 max-h-[66vh] w-60 overflow-y-auto rounded-xl border bg-popover/95 p-1.5 shadow-xl shadow-foreground/[0.08] ring-1 ring-black/[0.03] backdrop-blur-md`,children:r.map(([e,t],n)=>(0,q.jsxs)(`div`,{className:H(n>0&&`mt-1 border-t border-border/60 pt-1`),children:[(0,q.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground`,children:e}),t.map(i)]},e))})]})}function Rl(){return`${``.replace(/\/$/,``)}/api/v1`}function zl(e,t){let n=new Map;for(let t of e)n.set(t.type,t);for(let e of t){if(!e?.type||e.deprecated||Array.isArray(e.paradigms)&&e.paradigms.length>0&&!e.paradigms.includes(`flow`))continue;let t=n.get(e.type);n.set(e.type,{type:e.type,label:e.name||t?.label||e.type,hint:e.description||t?.hint,category:t?.category??Ml(e.type)})}return[...n.values()]}function Bl(){let[e,t]=(0,J.useState)([]),n=(0,J.useRef)(!0);return(0,J.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${Rl()}/automation/actions`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!r.ok)return;let i=(await r.json())?.data?.actions;if(!Array.isArray(i)||i.length===0)return;n.current&&t(i)}catch{}})(),()=>{n.current=!1,e.abort()}},[]),e}function Vl(){let e=Bl();return(0,J.useMemo)(()=>e.length?zl(Nl,e):Nl,[e])}function Hl(){let e=Bl();return(0,J.useMemo)(()=>{let t={};for(let n of e)n?.type&&n.configSchema!==void 0&&n.configSchema!==null&&(t[n.type]=n.configSchema);return t},[e])}var Ul=.4,Wl=1.6,Gl=4;function Kl({nodes:e,edges:t,editable:n,designMode:r,selectedId:i,selectedEdgeId:a,locale:o,activeNodeId:s,visitedNodeIds:c,traversedEdgeIds:l,onSelect:u,onSelectEdge:d,onPatch:f}){let p=J.useRef(null),[m,h]=J.useState(1),[g,_]=J.useState({x:0,y:0}),[v,y]=J.useState(!1),b=Vl(),[x,S]=J.useState(null),C=J.useRef(null),w=J.useRef(null),T=J.useMemo(()=>yl(e,t),[e,t]),E=J.useMemo(()=>bl(T),[T]),D=J.useMemo(()=>new Set(c??[]),[c]),O=J.useMemo(()=>new Set(l??[]),[l]),k=(c?.length??0)>0||!!s,A=J.useCallback(e=>x&&x.id===e?{x:x.x,y:x.y}:T.get(e)??{x:0,y:0},[x,T]),j=J.useCallback((t,n,r)=>{if(!f)return;let i=e.findIndex(e=>e.id===t);if(i<0)return;let a=e[i];f({nodes:K(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),ee=J.useCallback((n,r)=>{if(!f)return;let i=Or(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Pl(n),o=r?.at,s={id:i,type:n,label:a,...Fl(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:Dr(e,s)};r?.from&&(c.edges=Dr(t,{id:Or(`edge`,t.map(e=>e.id).filter(Boolean)),source:r.from,target:i})),f(c),u(s),y(!1)},[t,e,f,u,A]),te=J.useCallback((n,r=`create_record`)=>{if(!f)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=Or(`node`,e.map(e=>e.id).filter(Boolean)),o=A(n.source),s=A(n.target),c={x:(o.x+s.x)/2,y:(o.y+s.y)/2},l={id:a,type:r,label:Pl(r),...Fl(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:Or(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=K(t,i,d);f({nodes:Dr(e,l),edges:Dr(m,p)}),u(l)},[t,e,f,u,A]),ne=J.useCallback(n=>{f&&(f({nodes:e.filter(e=>e.id!==n),edges:t.filter(e=>e.source!==n&&e.target!==n)}),u(null))},[t,e,f,u]),re=J.useCallback(e=>t=>{if(!n||t.button!==0)return;t.stopPropagation();let r=A(e);C.current={nodeId:e,startX:t.clientX,startY:t.clientY,originX:r.x,originY:r.y,moved:!1},t.currentTarget.setPointerCapture?.(t.pointerId)},[n,A]),M=J.useCallback(e=>{let t=C.current;if(!t)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;!t.moved&&Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<Gl||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),ie=J.useCallback(e=>{let t=C.current;C.current=null,t&&(e.currentTarget.releasePointerCapture?.(e.pointerId),t.moved&&x&&j(t.nodeId,Math.round(x.x),Math.round(x.y)),S(null))},[x,j]),N=J.useCallback(e=>{e.button===0&&(u(null),w.current={startX:e.clientX,startY:e.clientY,originX:g.x,originY:g.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[u,g.x,g.y]),ae=J.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),oe=J.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),se=e=>Math.min(Wl,Math.max(Ul,e)),ce=J.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=se(Math.min(t,n,1));h(r),_({x:(e.clientWidth-E.width*r)/2,y:Math.max(16,(e.clientHeight-E.height*r)/2)})},[E.height,E.width]),le=J.useCallback(e=>{if(!(!n||!i)&&(e.key===`Delete`||e.key===`Backspace`)){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;e.preventDefault(),ne(i)}},[ne,n,i]);return(0,q.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`absolute right-2 top-2 z-30 flex items-center gap-1.5`,children:[n&&(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`inline-flex items-center gap-1.5 rounded-lg border bg-background/90 px-2.5 py-1.5 text-xs font-medium shadow-sm backdrop-blur-sm transition-colors hover:border-primary/50 hover:bg-accent hover:text-foreground`,children:[(0,q.jsx)(L,{className:`h-3.5 w-3.5`}),G(`engine.inspector.add.node`,o)]}),v&&(0,q.jsx)(Ll,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>ee(e,{from:i??void 0})})]}),(0,q.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-background/90 shadow-sm backdrop-blur-sm`,children:[(0,q.jsx)(`button`,{type:`button`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>h(e=>se(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(nr,{className:`h-3.5 w-3.5`})}),(0,q.jsxs)(`span`,{className:`w-10 text-center text-[11px] tabular-nums text-muted-foreground`,children:[Math.round(m*100),`%`]}),(0,q.jsx)(`button`,{type:`button`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>h(e=>se(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(mr,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:ce,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(et,{className:`h-3.5 w-3.5`})})]})]}),(0,q.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:le,onPointerDown:N,onPointerMove:e=>{ae(e),M(e)},onPointerUp:e=>{oe(e),ie(e)},className:H(`h-full w-full cursor-grab outline-none active:cursor-grabbing`,`bg-muted/15 dark:bg-background/30`,`shadow-[inset_0_0_90px_rgba(0,0,0,0.05)]`),style:{backgroundImage:`radial-gradient(circle at 1px 1px, hsl(var(--border)) 1px, transparent 0)`,backgroundSize:`${18*m}px ${18*m}px`,backgroundPosition:`${g.x}px ${g.y}px`},children:(0,q.jsxs)(`div`,{className:`relative origin-top-left`,style:{width:E.width,height:E.height,transform:`translate(${g.x}px, ${g.y}px) scale(${m})`},children:[(0,q.jsxs)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:E.width,height:E.height,children:[(0,q.jsx)(`defs`,{children:(0,q.jsx)(`marker`,{id:`flow-arrow`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,q.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground/55`})})}),t.map((e,t)=>{let i=T.get(e.source),o=T.get(e.target);if(!i||!o)return null;let s=xl(x?.id===e.source?A(e.source):i),c=Sl(x?.id===e.target?A(e.target):o),l=wl(s,c),u=El(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=Tl(e,t),m=O.has(p),h=a===p,g=Cl(s,c),_=r&&!!d;return(0,q.jsxs)(`g`,{children:[(0,q.jsx)(`path`,{d:g,strokeLinecap:`round`,className:H(`fill-none transition-[stroke] duration-150`,m?`stroke-sky-500`:h?`stroke-primary`:k?`stroke-muted-foreground/20`:`stroke-muted-foreground/40`),strokeWidth:m||h?2.5:1.75,markerEnd:`url(#flow-arrow)`}),_&&(0,q.jsx)(`path`,{d:g,className:`pointer-events-auto cursor-pointer fill-none stroke-transparent`,strokeWidth:14,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),d(e,p)},children:(0,q.jsx)(`title`,{children:`${e.source} → ${e.target}`})}),f&&(0,q.jsx)(`foreignObject`,{x:l.x-60,y:l.y-11,width:120,height:22,className:H(_&&`pointer-events-auto`),children:(0,q.jsx)(`div`,{className:`flex justify-center`,children:(0,q.jsx)(`span`,{onPointerDown:_?e=>e.stopPropagation():void 0,onClick:_?t=>{t.stopPropagation(),d(e,p)}:void 0,className:H(`max-w-full truncate rounded-full border bg-background/95 px-2 py-0.5 text-[10px] font-medium shadow-sm backdrop-blur-sm transition-colors`,_&&`cursor-pointer hover:border-primary/60`,h?`border-primary text-primary`:`border-border text-muted-foreground`),children:f})})}),n&&(0,q.jsx)(`foreignObject`,{x:f?l.x+66:l.x-11,y:l.y-11,width:22,height:22,className:`pointer-events-auto`,children:(0,q.jsx)(`button`,{type:`button`,title:`Insert node here`,"aria-label":`Insert node here`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),te(e)},className:`inline-flex h-[22px] w-[22px] items-center justify-center rounded-full border bg-background/90 text-muted-foreground opacity-50 shadow-sm backdrop-blur-sm transition-all hover:scale-110 hover:border-primary hover:bg-background hover:text-primary hover:opacity-100 focus-visible:opacity-100`,children:(0,q.jsx)(L,{className:`h-3 w-3`})})})]},e.id||`${e.source}-${e.target}-${t}`)})]}),e.map(e=>{let t=s===e.id?`active`:D.has(e.id)?`visited`:void 0;return(0,q.jsx)(Il,{id:e.id,type:e.type,label:e.label||e.id,summary:ql(e),position:A(e.id),selected:i===e.id,editable:n,runState:t,dimmed:k&&!t,onPointerDown:re(e.id),onSelect:()=>r&&u(e),onAppend:()=>ee(`create_record`,{from:e.id})},e.id)})]})})]})}function ql(e){let t=e.config,n=e=>typeof e==`string`&&e?e:void 0,r=(t,r)=>{let i=e[t];return i&&typeof i==`object`?n(i[r]):void 0},i=e=>t?n(t[e]):void 0;if(e.type===`start`)return i(`condition`)||i(`criteria`)||i(`objectName`)||i(`cron`)||i(`schedule`)||i(`triggerType`);if(e.type===`decision`){let e=t?.conditions;if(Array.isArray(e)&&e.length){let t=e.map(e=>e&&typeof e==`object`?n(e.label):void 0).filter(Boolean);return t.length?t.join(` / `):`${e.length} branches`}return i(`condition`)}if(e.type===`script`)return i(`actionType`)||i(`template`)||(t&&t.script?`code`:void 0);if(e.type===`approval`){let e=t?.approvers,n=Array.isArray(e)?e.length:0,r=i(`behavior`);return n>0?`${n} approver${n===1?``:`s`}${r===`unanimous`?` · all`:``}`:r||void 0}return i(`objectName`)||r(`connectorConfig`,`actionId`)||r(`waitEventConfig`,`timerDuration`)||r(`waitEventConfig`,`eventType`)||r(`boundaryConfig`,`eventType`)||i(`condition`)||i(`flowName`)||i(`url`)||i(`collection`)||i(`action`)||i(`flow`)||i(`event`)||i(`duration`)||void 0}var Jl=e=>typeof e==`string`?e:void 0;function Yl(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new p({...t,data:t});return{result:(/\$\{/.test(n)?e.evaluate(n,{throwOnError:!0}):e.evaluateExpression(n))===!0}}catch(e){return{result:!1,error:e.message||`Evaluation failed.`}}}function Xl(e,t){let n=[],r=[],i=e.map(e=>e.id),a=new Set;for(let e of i){if(!e){n.push({level:`error`,message:`A node is missing an id.`});continue}a.has(e)&&n.push({level:`error`,nodeId:e,message:`Duplicate node id "${e}".`}),a.add(e)}for(let e of t)a.has(e.source)||n.push({level:`error`,message:`Edge source "${e.source}" does not exist.`}),a.has(e.target)||n.push({level:`error`,message:`Edge target "${e.target}" does not exist.`});let o=new Set(t.map(e=>e.target)),s=e.filter(e=>e.type===`start`),c=e.filter(e=>!o.has(e.id)),l;s.length===1?(l=s[0].id,o.has(l)&&r.push({level:`warning`,nodeId:l,message:`Start node has an incoming edge.`})):s.length>1?n.push({level:`error`,message:`Flow has ${s.length} start nodes; expected one.`}):c.length===1?(l=c[0].id,r.push({level:`warning`,nodeId:l,message:`No "start" node; using the only root node as the entry.`})):c.length===0?n.push({level:`error`,message:`No entry node (every node has an incoming edge — the graph is fully cyclic).`}):n.push({level:`error`,message:`Cannot determine a single entry node (${c.length} candidates). Add a "start" node.`});for(let i of e){if(i.type!==`decision`)continue;let e=t.filter(e=>e.source===i.id),a=e.filter(e=>e.isDefault);a.length>1&&n.push({level:`error`,nodeId:i.id,message:`Decision "${i.id}" has ${a.length} default branches.`}),e.length===0?r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no outgoing branches.`}):a.length===0&&e.every(e=>Jl(e.condition))&&r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no default branch; it may dead-end when no condition matches.`})}if(l){let n=new Set([l]),i=[l];for(;i.length;){let e=i.shift();for(let r of t)r.source===e&&a.has(r.target)&&!n.has(r.target)&&(n.add(r.target),i.push(r.target))}for(let t of e)n.has(t.id)||r.push({level:`warning`,nodeId:t.id,message:`Node "${t.id}" is unreachable from the entry.`})}return{errors:n,warnings:r,startNodeId:l}}var Zl=500,Ql=new Set([`start`,`assignment`]),$l=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),eu=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),tu=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,nu=e=>typeof e==`string`?e:void 0,ru=e=>typeof e==`string`&&e?e:void 0,iu=class{nodes=new Map;edges=[];mocks={};seq=0;state={status:`idle`,variables:{},steps:[],frontier:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[]};constructor(e,t){for(let t of e)this.nodes.set(t.id,t);this.edges=t}reset(e={},t={}){let n=Xl([...this.nodes.values()],this.edges);return this.mocks=t,this.seq=0,this.state={status:n.errors.length?`error`:`idle`,variables:{...e},steps:[],frontier:n.startNodeId?[n.startNodeId]:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[],error:n.errors.length?n.errors[0].message:void 0},n}get done(){return this.state.status===`done`||this.state.status===`error`}step(){let e=this.state;if(e.status===`error`||e.status===`done`||e.status===`paused`)return null;if(this.seq>=Zl)return e.status=`error`,e.error=`Step limit (${Zl}) exceeded — the flow may contain an infinite loop.`,null;let t=e.frontier.shift();if(!t)return e.status=`done`,e.activeNodeId=null,null;let n=this.nodes.get(t);if(!n)return this.record(t,`unknown`,t,`error`,{error:`Node "${t}" not found.`});e.status=`running`,e.activeNodeId=t,e.visitedNodeIds.includes(t)||e.visitedNodeIds.push(t);let r=this.execute(n);return e.status===`running`&&e.frontier.length===0&&(e.status=`done`,e.activeNodeId=null),r}runToEnd(){let e=0;for(;this.state.status!==`done`&&this.state.status!==`error`&&this.state.status!==`paused`&&!(++e>505);)this.step();return this.state}resume(e){let t=this.state;if(t.status!==`paused`||!t.activeNodeId)return;let n=this.nodes.get(t.activeNodeId);e&&n?.type===`screen`&&Object.assign(t.variables,e),t.pausedReason=void 0,t.status=`running`,n&&this.enqueueSuccessors(n),t.frontier.length===0&&(t.status=`done`,t.activeNodeId=null)}execute(e){let t=e.type;if(t===`end`)return this.record(e.id,t,e.label,`ok`,{note:`Flow end reached.`});if(t===`decision`)return this.executeDecision(e);if(eu.has(t))return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`skipped`,{note:`"${t}" is not modelled by the simulator; passing through without its real semantics.`});if(t===`parallel_gateway`)return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:`Parallel split — branches fan out (no join synchronization is simulated).`});if(t===`wait`)return this.state.status=`paused`,this.state.pausedReason=`wait`,this.record(e.id,t,e.label,`paused`,{note:`Wait reached — continue manually.`});if(t===`screen`)return this.state.status=`paused`,this.state.pausedReason=`screen`,this.record(e.id,t,e.label,`paused`,{note:`Screen reached — provide inputs, then continue.`});if(t===`loop`){let t=this.executeLoop(e);return this.enqueueSuccessors(e),t}if($l.has(t)||t===`script`){let n=this.applyMock(e);return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`mocked`,{wrote:n,note:this.mockNote(e)})}return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:Ql.has(t)?void 0:`Type "${t}" treated as pass-through.`})}executeDecision(e){let t=this.edges.map((e,t)=>({e,i:t})).filter(t=>t.e.source===e.id),n=[],r,i;for(let{e,i:a}of t){if(e.isDefault)continue;let t=nu(e.condition);if(!t){n.push({edgeId:tu(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=Yl(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:tu(e,a),target:e.target,condition:t,result:o.result,error:o.error,selected:s})}if(!r){let e=t.find(e=>e.e.isDefault);e&&(r=e,n.push({edgeId:tu(e.e,e.i),target:e.e.target,isDefault:!0,result:!0,selected:!0}))}let a=n.filter(e=>e.result&&!e.isDefault).length>1;return r&&this.traverse(r.e,r.i),this.record(e.id,`decision`,e.label,r?`ok`:`error`,{edges:n,error:r?void 0:i??`No branch matched and there is no default branch.`,note:a?`Multiple conditions matched; the first declared branch was taken.`:void 0})}executeLoop(e){let t=ru(e.config?.collection),n=ru(e.config?.iteratorVariable),r=`Loop simulated as a single pass (body re-execution is not modelled).`;if(t){let e=this.resolveRef(t);Array.isArray(e)?(r=`Collection "${t}" has ${e.length} item(s); simulated as a single pass.`,n&&e.length&&(this.state.variables[n]=e[0])):e!==void 0&&(r=`Collection "${t}" is not an array; loop may not run at runtime.`)}return this.record(e.id,`loop`,e.label,`ok`,{note:r})}resolveRef(e){let t=e.match(/^\{(.+)\}$/),n=(t?t[1]:e).trim();return this.state.variables[n]}applyMock(e){let t=e.config??{},n=this.mocks[e.id],r={},i=ru(t.outputVariable);i&&(r[i]=n===void 0?{}:n,this.state.variables[i]=r[i]);let a=Array.isArray(t.outputVariables)?t.outputVariables:[];if(a.length){let e=n&&typeof n==`object`?n:{};for(let t of a)typeof t==`string`&&(r[t]=t in e?e[t]:void 0,this.state.variables[t]=r[t])}return Object.keys(r).length?r:void 0}mockNote(e){if(e.type===`script`){let t=ru(e.config?.actionType);if(t&&t!==`code`){let n=Array.isArray(e.config?.recipients)?e.config.recipients.length:0;return`Mocked ${t} notification${n?` to ${n} recipient(s)`:``}.`}return`Mocked code script (no real code executed).`}return`Mocked ${e.type.replace(/_/g,` `)} (no backend call).`}enqueueSuccessors(e){this.edges.forEach((t,n)=>{t.source===e.id&&this.traverse(t,n)})}traverse(e,t){let n=tu(e,t);this.state.traversedEdgeIds.includes(n)||this.state.traversedEdgeIds.push(n),this.nodes.has(e.target)&&this.state.frontier.push(e.target)}record(e,t,n,r,i={}){let a={seq:this.seq++,nodeId:e,type:t,label:n||e,status:r,...i};return this.state.steps.push(a),r===`error`&&this.state.status!==`paused`&&(this.state.status=`error`,this.state.error=i.error),a}};function au(e){let t=e.trim();if(t!==``){if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}}var ou=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function su(e){let t=[];for(let n of e){if(!ou.has(n.type))continue;let e=n.config??{},r=[];if(typeof e.outputVariable==`string`&&e.outputVariable&&r.push(e.outputVariable),Array.isArray(e.outputVariables))for(let t of e.outputVariables)typeof t==`string`&&r.push(t);t.push({id:n.id,label:n.label||n.id,type:n.type,outputs:r})}return t}var cu={ok:`bg-emerald-100 text-emerald-700`,mocked:`bg-violet-100 text-violet-700`,paused:`bg-amber-100 text-amber-700`,skipped:`bg-zinc-100 text-zinc-600`,error:`bg-rose-100 text-rose-700`};function lu({nodes:e,edges:t,variables:n,onRunStateChange:r}){let i=J.useRef(null),[a,o]=J.useState(null),[s,c]=J.useState(null),l=J.useMemo(()=>n.filter(e=>e.isInput),[n]),u=J.useMemo(()=>su(e),[e]),[d,f]=J.useState({}),[p,m]=J.useState([]),[h,g]=J.useState({}),_=J.useCallback(()=>{let e=i.current;if(!e)return;let t=e.state;o({...t,steps:[...t.steps],variables:{...t.variables},frontier:[...t.frontier],visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]}),r?.({activeNodeId:t.activeNodeId,visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]})},[r]),v=J.useCallback(()=>{let e={};for(let t of l){let n=d[t.name],r=n==null?void 0:au(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=au(t.v))}return e},[l,d,p]),y=J.useCallback(()=>{let e={};for(let[t,n]of Object.entries(h))n!=null&&n.trim()!==``&&(e[t]=au(n));return e},[h]),b=J.useCallback(()=>{let n=new iu(e,t);i.current=n,c(n.reset(v(),y())),_()},[e,t,v,y,_]),x=J.useCallback(()=>(i.current||b(),i.current),[b]),S=()=>{let e=i.current;e&&e.state.status===`paused`?e.resume():(b(),e=i.current),e.runToEnd(),_()},w=()=>{x().step(),_()},T=()=>{let e=x();e.resume(),e.runToEnd(),_()},E=()=>{i.current=null,o(null),c(null),r?.(null)},D=a?.status??`idle`,O=(s?.errors.length??0)>0;return(0,q.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,q.jsxs)(z,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:O,children:[(0,q.jsx)(oe,{className:`h-3.5 w-3.5`}),` Run`]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,disabled:O||D===`done`||D===`error`,children:[(0,q.jsx)(Kn,{className:`h-3.5 w-3.5`}),` Step`]}),D===`paused`&&(0,q.jsxs)(z,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:T,children:[(0,q.jsx)(rt,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,q.jsxs)(z,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:E,children:[(0,q.jsx)(C,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,q.jsx)(`span`,{className:H(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,cu[D===`idle`||D===`running`?`ok`:D]??`bg-muted`),children:D})]}),(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-auto p-3`,children:[s&&(s.errors.length>0||s.warnings.length>0)&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[s.errors.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-rose-200 bg-rose-50 px-2 py-1 text-rose-700`,children:[(0,q.jsx)(hr,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{children:e.message})]},`e${t}`)),s.warnings.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-amber-200 bg-amber-50 px-2 py-1 text-amber-700`,children:[(0,q.jsx)(I,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{children:e.message})]},`w${t}`))]}),l.length>0&&(0,q.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Inputs`}),l.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(V,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,q.jsx)(B,{value:d[e.name]??(e.defaultValue==null?``:String(e.defaultValue)),onChange:t=>f(n=>({...n,[e.name]:t.target.value})),placeholder:e.type??`value`,className:`h-7 flex-1 text-xs`})]},e.name))]}),(0,q.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:`Set variables`}),(0,q.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[10px] hover:bg-muted/50`,onClick:()=>m(e=>[...e,{k:``,v:``}]),children:[(0,q.jsx)(L,{className:`h-3 w-3`}),` Add`]})]}),p.length===0?(0,q.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Override or inject any variable (wins over inputs and mocks at start).`}):p.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(B,{value:e.k,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,k:e.target.value}:n)),placeholder:`name`,className:`h-7 w-24 shrink-0 font-mono text-[11px]`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,q.jsx)(B,{value:e.v,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,v:e.target.value}:n)),placeholder:`value`,className:`h-7 flex-1 text-xs`}),(0,q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-1 text-muted-foreground hover:bg-muted/50 hover:text-rose-600`,onClick:()=>m(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove variable`,children:(0,q.jsx)(ut,{className:`h-3 w-3`})})]},t))]}),u.length>0&&(0,q.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Mock outputs`}),u.map(e=>(0,q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,q.jsxs)(V,{className:`flex items-baseline gap-1.5 text-[11px]`,title:e.id,children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type.replace(/_/g,` `)}),e.outputs.length>0&&(0,q.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-violet-600`,children:[`→ `,e.outputs.join(`, `)]})]}),(0,q.jsx)(B,{value:h[e.id]??``,onChange:t=>g(n=>({...n,[e.id]:t.target.value})),placeholder:e.type===`script`&&e.outputs.length?`{ "${e.outputs[0]}": … }`:`mocked result (JSON)`,className:`h-7 w-full font-mono text-[11px]`})]},e.id))]}),a&&(0,q.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Variables`}),Object.keys(a.variables).length===0?(0,q.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No variables set.`}):(0,q.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(a.variables).map(([e,t])=>(0,q.jsxs)(`li`,{className:`flex items-baseline gap-1.5 rounded border bg-background px-1.5 py-1`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[11px]`,children:e}),(0,q.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:[`= `,typeof t==`object`?JSON.stringify(t):String(t)]})]},e))})]}),a&&a.steps.length>0&&(0,q.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Timeline`}),(0,q.jsx)(`ol`,{className:`space-y-1`,children:a.steps.map(e=>(0,q.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.seq+1}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),(0,q.jsx)(`span`,{className:H(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,cu[e.status]),children:e.status})]}),e.note&&(0,q.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e.note}),e.error&&(0,q.jsx)(`div`,{className:`mt-0.5 text-[10px] text-rose-600`,children:e.error}),e.wrote&&(0,q.jsxs)(`div`,{className:`mt-0.5 truncate font-mono text-[10px] text-violet-600`,children:[`→ `,Object.keys(e.wrote).join(`, `)]}),e.edges&&e.edges.length>0&&(0,q.jsx)(`ul`,{className:`mt-0.5 space-y-0.5`,children:e.edges.map(e=>(0,q.jsxs)(`li`,{className:`space-y-0.5`,children:[(0,q.jsxs)(`div`,{className:H(`flex items-center gap-1 font-mono text-[10px]`,e.selected?`text-sky-700`:`text-muted-foreground`),children:[(0,q.jsx)(`span`,{children:e.selected?`▶`:`·`}),(0,q.jsx)(`span`,{className:`truncate`,children:e.isDefault?`else`:e.condition}),(0,q.jsx)(`span`,{className:H(`ml-auto`,e.error&&`text-rose-600`),children:e.error?`error`:e.result?`true`:`false`})]}),e.error&&(0,q.jsx)(`div`,{className:`pl-3 text-[10px] text-rose-600`,children:e.error})]},e.edgeId))})]},e.seq))})]}),!a&&!O&&(0,q.jsx)(`p`,{className:`italic text-muted-foreground`,children:`Press Run to simulate, or Step to walk node by node. Side effects are mocked — no backend is called.`})]})]})}async function uu(e,t){try{let n=await fetch(`${Rl()}/automation/${encodeURIComponent(e)}/runs?limit=25`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:t});if(!n.ok)return null;let r=await n.json(),i=r?.data?.runs??r?.runs;return Array.isArray(i)?i:null}catch{return null}}var du={completed:{icon:R,cls:`text-emerald-600 dark:text-emerald-400`,label:`Completed`},failed:{icon:hr,cls:`text-rose-600 dark:text-rose-400`,label:`Failed`},paused:{icon:bn,cls:`text-amber-600 dark:text-amber-400`,label:`Paused`},running:{icon:F,cls:`text-sky-600 dark:text-sky-400`,label:`Running`},cancelled:{icon:Xt,cls:`text-muted-foreground`,label:`Cancelled`}};function fu(e){return du[e]??{icon:Ln,cls:`text-muted-foreground`,label:e}}function pu(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function mu(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function hu({step:e}){return(0,q.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,children:[(0,q.jsx)(`span`,{className:H(`shrink-0 text-[9px] font-semibold uppercase`,e.status===`success`?`text-emerald-600 dark:text-emerald-400`:e.status===`failure`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`),children:e.status}),(0,q.jsx)(`span`,{className:`truncate font-mono text-[10px]`,title:e.nodeId,children:e.nodeId}),e.nodeType&&(0,q.jsx)(`span`,{className:`shrink-0 text-[9px] uppercase text-muted-foreground`,children:e.nodeType}),mu(e.durationMs)&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:mu(e.durationMs)}),e.error?.message&&(0,q.jsx)(`span`,{className:`min-w-0 truncate text-[9px] text-rose-600`,title:e.error.message,children:e.error.message})]})}function gu({run:e}){let[t,n]=J.useState(!1),r=fu(e.status),i=r.icon,a=Array.isArray(e.steps)?e.steps:[];return(0,q.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-1.5 p-1.5 text-left`,"aria-expanded":t,children:[t?(0,q.jsx)(re,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,q.jsx)(rt,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,q.jsx)(i,{className:H(`h-3.5 w-3.5 shrink-0`,r.cls,e.status===`running`&&`animate-spin`)}),(0,q.jsx)(`span`,{className:H(`shrink-0 text-[10px] font-semibold`,r.cls),children:r.label}),(0,q.jsx)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground`,title:e.id,children:pu(e.startedAt)}),mu(e.durationMs)&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:mu(e.durationMs)})]}),t&&(0,q.jsxs)(`div`,{className:`border-t px-2 py-1.5`,children:[(0,q.jsxs)(`div`,{className:`pb-1 font-mono text-[9px] text-muted-foreground`,title:e.id,children:[`run `,e.id,e.trigger?.type&&` · trigger ${e.trigger.type}`]}),e.error?.message&&(0,q.jsx)(`div`,{className:`pb-1 text-[10px] text-rose-600`,children:e.error.message}),a.length===0?(0,q.jsx)(`div`,{className:`text-[10px] italic text-muted-foreground`,children:`No step log recorded.`}):(0,q.jsx)(`ul`,{className:`divide-y divide-border/50`,children:a.map((e,t)=>(0,q.jsx)(hu,{step:e},`${e.nodeId}#${t}`))})]})]})}function _u({flowName:e}){let[t,n]=J.useState([]),[r,i]=J.useState(`loading`),[a,o]=J.useState(0);return J.useEffect(()=>{let t=new AbortController,r=!0;return i(`loading`),(async()=>{let a=await uu(e,t.signal);r&&(a===null?i(`unavailable`):(n(a),i(`ready`)))})(),()=>{r=!1,t.abort()}},[e,a]),(0,q.jsxs)(`div`,{className:`flex h-full flex-col p-3 text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 font-medium text-muted-foreground`,children:[(0,q.jsx)(Ln,{className:`h-3 w-3`}),` Runs`,(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(e=>e+1),title:`Refresh run history`,"aria-label":`Refresh run history`,className:`ml-auto rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:(0,q.jsx)(ie,{className:H(`h-3 w-3`,r===`loading`&&`animate-spin`)})})]}),r===`unavailable`?(0,q.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Run history unavailable — the automation engine is offline or this flow hasn’t been published.`}):r===`ready`&&t.length===0?(0,q.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No runs yet.`}):(0,q.jsx)(`ul`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto`,children:t.map(e=>(0,q.jsx)(gu,{run:e},e.id))})]})}function vu({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=e,s=Array.isArray(o.nodes)?o.nodes:[],c=Array.isArray(o.edges)?o.edges:[],l=Array.isArray(o.variables)?o.variables:[],u=!!(t&&r),d=u&&!!i,f=n&&n.kind===`node`?n.id:null,p=n&&n.kind===`edge`?n.id:null,[m,h]=J.useState(!1),[g,_]=J.useState(!0),[v,y]=J.useState(!1),[b,x]=J.useState(null),S=J.useCallback(()=>{if(!d)return;let e={id:Or(`node`,s.map(e=>e.id).filter(Boolean)),type:`start`,label:`Start`};i({nodes:Dr(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),C=typeof o.name==`string`&&o.name?o.name:``,w=String(o.type??`autolaunched`),T=String(o.status??(o.active?`active`:`draft`)),E=String(o.runAs??`user`),D=o.version==null?void 0:String(o.version),O=o.errorHandling?.strategy;return s.length===0?(0,q.jsx)(X,{hint:`flow${u?` · design`:``}`,children:d?(0,q.jsx)(`div`,{className:`p-3`,children:(0,q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-2 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:S,children:[(0,q.jsx)(L,{className:`h-3 w-3`}),G(`engine.inspector.add.node`,a)]})}):(0,q.jsx)(Z,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,q.jsx)(X,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,q.jsx)(Q,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,q.jsxs)(`div`,{className:`grid gap-0 h-full min-h-[440px] `+(m||g||v?`lg:grid-cols-[1fr_240px]`:`grid-cols-1`),children:[(0,q.jsxs)(`div`,{className:`flex flex-col min-w-0 min-h-0`,children:[(0,q.jsxs)(`div`,{className:`rounded-none border-b bg-muted/30 px-3 py-2 text-xs flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,q.jsx)(yu,{icon:Pt,label:`Trigger`,value:w}),(0,q.jsx)(yu,{icon:an,label:`Status`,value:T,tone:T===`active`?`green`:T===`draft`?`gray`:`amber`}),(0,q.jsx)(yu,{icon:fr,label:`Run as`,value:E}),D&&(0,q.jsx)(yu,{label:`v`,value:D}),O&&(0,q.jsx)(yu,{icon:hn,label:`On error`,value:O}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!m&&!v&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(g?`border-violet-500 bg-violet-50 text-violet-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:g?`Hide variables panel`:`Show variables panel`,children:[(0,q.jsx)(Gn,{className:`h-3 w-3`}),` Variables`]}),C&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{y(e=>!e),h(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(v?`border-emerald-500 bg-emerald-50 text-emerald-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:`Run history from the automation engine`,children:[(0,q.jsx)(qt,{className:`h-3 w-3`}),` Runs`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{h(e=>!e),y(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(m?`border-sky-500 bg-sky-50 text-sky-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),children:[(0,q.jsx)(me,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(Kl,{nodes:s,edges:c,editable:d,designMode:u,selectedId:f,selectedEdgeId:p,locale:a,activeNodeId:b?.activeNodeId??null,visitedNodeIds:b?.visitedNodeIds,traversedEdgeIds:b?.traversedEdgeIds,onSelect:e=>e?r?.({kind:`node`,id:e.id,label:e.label||e.id}):r?.(null),onSelectEdge:(e,t)=>e?r?.({kind:`edge`,id:t,label:`${e.source} → ${e.target}`}):r?.(null),onPatch:i})})]}),m?(0,q.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,q.jsx)(lu,{nodes:s,edges:c,variables:l,onRunStateChange:x})}):v&&C?(0,q.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,q.jsx)(_u,{flowName:C})}):g?(0,q.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,q.jsx)(pn,{className:`h-3 w-3`}),` Variables`]}),l.length===0?(0,q.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,q.jsx)(`ul`,{className:`space-y-1.5`,children:l.map((e,t)=>(0,q.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,q.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,q.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,q.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]}):null]})})})}function yu({icon:e,label:t,value:n,tone:r=`gray`}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,q.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function bu({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.role??``),o=n.avatar||void 0,s=String(n.instructions??``),c=n.active!==!1,l=String(n.visibility??`organization`),u=n.model??{},d=Array.isArray(n.skills)?n.skills:[],f=Array.isArray(n.tools)?n.tools:[],p=n.knowledge,m=n.planning,h=n.memory,g=n.guardrails,_=Array.isArray(n.permissions)?n.permissions:[];if(!r&&!s&&d.length===0&&f.length===0)return(0,q.jsx)(X,{hint:`agent`,children:(0,q.jsx)(Z,{children:`Fill in label, role, and instructions in the Form tab to see the agent preview.`})});let v=r?`/console/ai/agents/${encodeURIComponent(r)}/chat`:null;return(0,q.jsx)(X,{hint:`agent`,toolbar:v&&(0,q.jsxs)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open the saved version of this agent in a new chat`,children:[`Try in chat `,(0,q.jsx)(_e,{className:`h-3 w-3`})]}),children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,q.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,q.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,q.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,q.jsx)(Nn,{className:`h-5 w-5 text-muted-foreground`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(ku,{icon:c?ze:N,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,q.jsx)(ku,{icon:un,label:l}),u.provider&&(0,q.jsx)(ku,{icon:mn,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,q.jsx)(ku,{icon:Zn,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,q.jsx)(ku,{label:`max ${u.maxTokens}t`})]})]})]}),(0,q.jsx)(Su,{title:`Instructions`,icon:k,children:s?(0,q.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs whitespace-pre-wrap font-mono max-h-[40vh] overflow-auto`,children:s}):(0,q.jsx)(Cu,{children:`No system prompt set yet.`})}),(0,q.jsx)(Su,{title:`Capabilities`,icon:j,children:(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(Tu,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:mn,tone:`violet`,mono:!0}),(0,q.jsx)(Tu,{label:`Tools`,emptyHint:`No direct tools (skills can provide them)`,items:f.map((e,t)=>({key:`${e.type??``}:${e.name??t}`,label:e.name??String(e),hint:e.type})),icon:j,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,q.jsx)(Su,{title:`Knowledge (RAG)`,icon:ht,children:(0,q.jsx)(xu,{knowledge:p})})]}),(0,q.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,q.jsx)(Eu,{icon:_t,title:`Planning`,children:(0,q.jsx)(Du,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,q.jsx)(Eu,{icon:Yt,title:`Memory`,children:(0,q.jsx)(Du,{data:{"short.maxMessages":h.shortTerm?.maxMessages,"long.enabled":h.longTerm?.enabled,"long.store":h.longTerm?.store},keys:[`short.maxMessages`,`long.enabled`,`long.store`]})}),g&&Object.keys(g).length>0&&(0,q.jsx)(Eu,{icon:vn,title:`Guardrails`,children:(0,q.jsx)(Du,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,q.jsx)(Eu,{icon:un,title:`Permissions`,children:(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,q.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,q.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function xu({knowledge:e}){let t=Array.isArray(e.sources)?e.sources:[],n=Array.isArray(e.indexes)?e.indexes:[],r=[...t,...n];if(r.length===0){let t=Object.keys(e);return(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,q.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:r.map((e,t)=>{let n=e??{},r=n.id??n.name??`source ${t+1}`,i=n.type??n.kind??``;return(0,q.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,q.jsx)(ht,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,q.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Su({title:e,icon:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,q.jsx)(t,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e})]}),n]})}function Cu({children:e}){return(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var wu={violet:{chip:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`,icon:`text-violet-500 dark:text-violet-400`},blue:{chip:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`,icon:`text-blue-500 dark:text-blue-400`}};function Tu({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?wu[i]:null;return(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,q.jsxs)(`span`,{className:H(`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px]`,o?o.chip:`bg-background`,a&&`font-mono`),children:[r&&(0,q.jsx)(r,{className:H(`h-3 w-3 shrink-0`,o?.icon)}),e.label,e.hint&&(0,q.jsx)(`span`,{className:`text-[9px] uppercase opacity-70`,children:e.hint})]},e.key))})]})}function Eu({icon:e,title:t,children:n}){return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,q.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function Du({data:e,keys:t}){let n=t.map(t=>[t,Ou(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,q.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,q.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,q.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,q.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,q.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function Ou(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function ku({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Au(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function ju(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${ju(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Mu(e){if(e.default!==void 0)return e.default;if(Array.isArray(e.enum)&&e.enum.length)return e.enum[0];switch(Array.isArray(e.type)?e.type[0]:e.type){case`string`:return e.format?`<${e.format}>`:`<string>`;case`number`:case`integer`:return 0;case`boolean`:return!1;case`array`:return[];case`object`:return{};default:return null}}function Nu({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.description??``),o=n.category||void 0,s=n.objectName||void 0,c=!!n.requiresConfirmation,l=n.active!==!1,u=!!n.builtIn,d=n.parameters??{},f=n.outputSchema??void 0,p=Au(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=J.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=Mu(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Mu(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,q.jsx)(X,{hint:`tool`,children:(0,q.jsx)(Z,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,q.jsx)(X,{hint:`tool`,toolbar:r&&(0,q.jsxs)(`a`,{href:`/developer/api-console?path=/api/v1/ai/tools/${encodeURIComponent(r)}/invoke`,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open API Console to test invocation`,children:[`Open in API Console `,(0,q.jsx)(_e,{className:`h-3 w-3`})]}),children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(j,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,q.jsx)(Lu,{icon:St,label:o}),s&&(0,q.jsx)(Lu,{icon:ht,label:s,mono:!0}),(0,q.jsx)(Lu,{icon:ct,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,q.jsx)(Lu,{icon:I,label:`Requires confirmation`,tone:`amber`}),u&&(0,q.jsx)(Lu,{label:`built-in`})]})]})]}),a&&(0,q.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,q.jsx)(Fu,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,q.jsx)(Iu,{children:`This tool takes no input parameters.`}):(0,q.jsx)(Pu,{props:p,required:m})}),Object.keys(p).length>0&&(0,q.jsx)(Fu,{title:`Example LLM Call`,icon:Me,children:(0,q.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
|
|
16
|
+
"tool": "${r}",
|
|
17
|
+
"arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
|
|
18
|
+
`)}
|
|
19
|
+
}`})}),Au(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,q.jsx)(Fu,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Te,children:(0,q.jsx)(Pu,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Pu({props:e,required:t}){return(0,q.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:Object.keys(e).map(n=>{let r=e[n],i=t.has(n);return(0,q.jsxs)(`tr`,{className:`align-top`,children:[(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,q.jsx)(R,{className:`h-3 w-3 text-emerald-600`}):(0,q.jsx)(rt,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,q.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:ju(r)}),(0,q.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,q.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,q.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function Fu({title:e,count:t,icon:n,children:r}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,q.jsx)(n,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e}),t!=null&&(0,q.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Iu({children:e}){return(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Lu({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Ru=[{key:`allowCreate`,short:`C`,long:`Create`},{key:`allowRead`,short:`R`,long:`Read`},{key:`allowEdit`,short:`U`,long:`Edit`},{key:`allowDelete`,short:`D`,long:`Delete`},{key:`allowTransfer`,short:`T`,long:`Transfer`},{key:`allowRestore`,short:`Re`,long:`Restore`},{key:`allowPurge`,short:`P`,long:`Purge`,danger:!0},{key:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}];function zu(e){let t=[];for(let[n,r]of Object.entries(e))r.allowEdit&&!r.allowRead&&t.push({object:n,message:`Edit granted without Read (record updates will fail).`}),r.allowDelete&&!r.allowRead&&t.push({object:n,message:`Delete granted without Read.`}),r.modifyAllRecords&&!r.viewAllRecords&&t.push({object:n,message:`Modify All without View All — modifications may target invisible records.`}),r.allowPurge&&!r.allowDelete&&t.push({object:n,message:`Purge (hard delete) granted without Delete.`});return t}function Bu({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isProfile,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=J.useMemo(()=>Object.keys(o).sort(),[o]),f=J.useMemo(()=>zu(o),[o]),p=J.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,q.jsx)(X,{hint:`permission`,children:(0,q.jsx)(Z,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,q.jsx)(X,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,q.jsx)(Cn,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,q.jsx)($t,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(Wu,{icon:st,label:`${d.length} objects`}),(0,q.jsx)(Wu,{icon:St,label:`${c.length} system perms`}),(0,q.jsx)(Wu,{icon:ze,label:`${Object.keys(l).length} tabs`}),(0,q.jsx)(Wu,{icon:un,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,q.jsxs)(Uu,{title:`Object Permissions`,count:d.length,children:[(0,q.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),Ru.map(e=>(0,q.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),Ru.map(e=>(0,q.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,q.jsx)(Vu,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,q.jsx)(Hu,{})]}),p.size>0&&(0,q.jsx)(Uu,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,q.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,q.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,q.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,q.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,q.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded border bg-muted/30 px-1.5 py-0.5`,title:`readable=${t.readable!==!1}, editable=${!!t.editable}`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,q.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,q.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,q.jsx)(Uu,{title:`System Permissions`,count:c.length,children:(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),Object.keys(l).length>0&&(0,q.jsx)(Uu,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e}),(0,q.jsx)(`span`,{className:t===`hidden`?`text-[9px] uppercase text-red-700`:t===`visible`||t===`default_on`?`text-[9px] uppercase text-emerald-700`:`text-[9px] uppercase text-muted-foreground`,children:t})]},e))})}),f.length>0&&(0,q.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,q.jsx)(I,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,q.jsxs)(`li`,{className:`text-amber-900`,children:[(0,q.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function Vu({granted:e,danger:t}){return e?(0,q.jsx)(R,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,q.jsx)(Un,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Hu(){return(0,q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(R,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(R,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(Un,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,q.jsx)(`span`,{className:`ml-auto font-mono`,children:`C R U D = CRUD · T Re P = Transfer/Restore/Purge · V* M* = View/Modify All`})]})}function Uu({title:e,count:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,q.jsx)(`span`,{children:e}),t!=null&&(0,q.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Wu({icon:e,label:t}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{children:t})]})}function Gu(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function Ku(e){switch(e){case`url`:return ge;case`modal`:return _r;case`flow`:return ar;case`api`:return En;case`form`:return bt;default:return x}}function qu(e){switch(e){case`primary`:case`default`:case void 0:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:case`destructive`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function Ju(e,t,n){if(!t&&!n)return`No handler bound yet.`;switch(e){case`url`:return`Navigate to ${t}`;case`flow`:return`Run flow ${t}`;case`modal`:return`Open modal ${t}`;case`api`:return`Call API endpoint ${t}`;case`form`:return`Open form view ${t} (/console/forms/${t??`?`})`;case`script`:return n?`Run inline script body (L1 expression or L2 sandboxed JS).`:`Run named script ${t}`;default:return`Invoke ${t}`}}function Yu({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Gu(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target??n.execute,c=n.variant||void 0,l=String(n.component??``),u=Array.isArray(n.locations)?n.locations:[],d=n.shortcut||void 0,f=!!n.bulkEnabled,p=!!n.refreshAfter,m=n.aiExposed,h=Gu(n.confirmText),g=Gu(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,S=n.visible,C=n.disabled,w=Ku(o),T=l===`action:icon`;return!r&&!i?(0,q.jsx)(X,{hint:`action`,children:(0,q.jsx)(Z,{children:`Set name and label to see the action preview.`})}):(0,q.jsx)(X,{hint:`action`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,q.jsx)(Xu,{label:i,icon:a,variant:c,iconOnly:T,disabled:!!C&&typeof C==`boolean`})}),(0,q.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(rd,{icon:w,label:`type: ${o}`}),b&&(0,q.jsx)(rd,{icon:sn,label:`object: ${b}`,mono:!0}),c&&(0,q.jsx)(rd,{label:`variant: ${c}`}),l&&(0,q.jsx)(rd,{icon:Oe,label:l}),d&&(0,q.jsx)(rd,{icon:pt,label:d,mono:!0}),f&&(0,q.jsx)(rd,{icon:ir,label:`bulk`,tone:`green`}),p&&(0,q.jsx)(rd,{icon:ie,label:`refresh after`}),m===!1&&(0,q.jsx)(rd,{icon:Nn,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,q.jsx)(rd,{icon:mn,label:`AI: exposed`})]}),u.length>0&&(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,q.jsx)(`span`,{className:`inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e},e))]}),!!(typeof S==`string`||S&&typeof S==`object`)&&(0,q.jsx)(td,{label:`Visible when`,value:S,icon:ze}),C!=null&&typeof C!=`boolean`&&(0,q.jsx)(td,{label:`Disabled when`,value:C,icon:un})]}),(0,q.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,q.jsx)(w,{className:`h-3.5 w-3.5`}),` On click`]}),(0,q.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:Ju(o,s,!!y?.source)}),h&&(0,q.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,q.jsx)(I,{className:`h-3 w-3 mt-0.5`}),(0,q.jsxs)(`span`,{children:[`First asks: `,(0,q.jsx)(`em`,{children:h})]})]}),g&&(0,q.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,q.jsx)(`em`,{children:g})]})]}),_.length>0&&(0,q.jsx)(nd,{title:`Input Dialog`,count:_.length,children:(0,q.jsx)(Qu,{title:i,params:_,variant:c})}),v&&(0,q.jsx)(nd,{title:`Result Dialog`,icon:ze,children:(0,q.jsx)(ed,{dialog:v})}),y?.source&&(0,q.jsx)(nd,{title:`Script Body (${y.language??`expression`})`,icon:x,children:(0,q.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap max-h-[200px] overflow-auto`,children:y.source})})]})})})}function Xu({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${qu(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,q.jsx)(Zu,{name:t}),!r&&(0,q.jsx)(`span`,{children:e})]})}function Zu({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=kt[t===`Home`?`House`:t];return n?(0,q.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,q.jsx)(`span`,{className:`inline-flex h-4 min-w-4 items-center justify-center rounded bg-white/30 px-1 text-[9px] uppercase font-mono`,children:e.slice(0,3)})}function Qu({title:e,params:t,variant:n}){return(0,q.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,q.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,q.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,q.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[Gu(e.label)||n,e.required&&(0,q.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,q.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,q.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),$u(e),e.helpText&&(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,q.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${qu(n||`primary`)}`,children:`OK`})]})]})}function $u(e){let t=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,n=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),r=e.defaultValue;return Array.isArray(e.options)&&e.options.length>0?(0,q.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,q.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,q.jsx)(`option`,{value:e.value,children:Gu(e.label)},t))]}):e.type===`boolean`?(0,q.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,q.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,q.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,q.jsx)(`input`,{type:e.type===`number`||e.type===`integer`?`number`:e.type===`date`?`date`:`text`,className:t,placeholder:n,value:r==null?``:String(r),readOnly:!0})}function ed({dialog:e}){let t=Gu(e.title)||`Result`,n=Gu(e.description),r=Gu(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,q.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,q.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,q.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,q.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,q.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,q.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,q.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:Gu(t.label)||t.path}),(0,q.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,q.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,q.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,q.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded bg-primary text-primary-foreground pointer-events-none`,children:r})})]})}function td({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,q.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,q.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function nd({title:e,count:t,icon:n,children:r}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,q.jsx)(n,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e}),t!=null&&(0,q.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function rd({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var id={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function ad(e,t,n){let r={values:new Set,any:!1};if(e===`*`){for(let e=t;e<=n;e++)r.values.add(e);return r.any=!0,r}for(let i of e.split(`,`)){let e,a=i;if(i.includes(`/`)){let[t,n]=i.split(`/`);a=t,e=n}let o=e?Math.max(1,parseInt(e,10)||1):1,s=t,c=n;if(a!==`*`)if(a.includes(`-`)){let[e,t]=a.split(`-`).map(e=>parseInt(e,10));if(Number.isNaN(e)||Number.isNaN(t))return null;s=e,c=t}else{let e=parseInt(a,10);if(Number.isNaN(e))return null;s=e,c=e}for(let e=s;e<=c;e+=o)e>=t&&e<=n&&r.values.add(e)}return r}function od(e){let t=(id[e.trim()]??e.trim()).split(/\s+/);if(t.length!==5&&t.length!==6)return null;let[n,r,i,a,o]=t.length===6?t.slice(1):t,s=ad(n,0,59),c=ad(r,0,23),l=ad(i,1,31),u=ad(a,1,12),d=ad(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function sd(e,t,n){let r=od(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+366*24*60*60*1e3;for(;i.length<n&&a.getTime()<=o;)r.minute.values.has(a.getMinutes())&&r.hour.values.has(a.getHours())&&r.month.values.has(a.getMonth()+1)&&(r.dom.any||r.dow.any?r.dom.values.has(a.getDate())&&r.dow.values.has(a.getDay()):r.dom.values.has(a.getDate())||r.dow.values.has(a.getDay()))&&i.push(new Date(a.getTime())),a.setMinutes(a.getMinutes()+1);return i}function cd(e){let t=/^(\d+)\s*(ms|s|m|h|d)$/.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;case`d`:return n*864e5;default:return null}}function ld(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function ud(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function dd(e){if(e.schedule&&typeof e.schedule==`object`){let t=e.schedule,n=String(t.type??``),r=t.timezone??e.timezone??e.tz;if(n===`cron`){let e=t.expression;return{cron:typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0,timezone:r}}if(n===`interval`){let e=Number(t.intervalMs);return{every:Number.isFinite(e)&&e>0?fd(e):void 0,timezone:r}}if(n===`once`)return{at:typeof t.at==`string`?t.at:void 0,timezone:r}}let t=typeof e.cron==`string`?e.cron:typeof e.schedule==`string`?e.schedule:void 0,n=e.every??e.interval;return{cron:t,every:typeof n==`string`?n:typeof n==`number`?fd(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function fd(e){return e%864e5==0?`${e/864e5}d`:e%36e5==0?`${e/36e5}h`:e%6e4==0?`${e/6e4}m`:e%1e3==0?`${e/1e3}s`:`${e}ms`}function pd({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,{cron:o,every:s,at:c,timezone:l}=dd(n),u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.retryPolicy,p=f?.maxRetries??n.maxRetries??n.retries,m=f?.backoffMs,h=n.timeout??n.timeoutMs,g=n.concurrency,_=s?cd(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=sd(o,e,5);else if(_)t=ld(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>md(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,q.jsx)(X,{hint:`job`,children:(0,q.jsx)(Z,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,q.jsx)(X,{hint:`job`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(Vt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(_d,{icon:ct,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,q.jsx)(_d,{icon:yr,label:l,mono:!0}),p!=null&&(0,q.jsx)(_d,{icon:C,label:`retries: ${p}${m?` (${fd(m)} backoff)`:``}`}),h!=null&&(0,q.jsx)(_d,{icon:gt,label:`timeout: ${fd(h)}`}),g!=null&&(0,q.jsx)(_d,{label:`concurrency: ${g}`})]})]})]})}),(0,q.jsx)(gd,{title:`Schedule`,icon:Je,children:(0,q.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,q.jsx)(hd,{label:`Cron`,children:(0,q.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,q.jsxs)(hd,{label:`Every`,children:[(0,q.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,q.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,q.jsx)(hd,{label:`At`,children:(0,q.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,q.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,q.jsx)(gd,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:Ln,children:v.length===0?(0,q.jsx)(`div`,{className:`text-xs text-amber-700`,children:b?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,q.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,q.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,q.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,q.jsx)(Ln,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-mono`,children:ud(e)}),(0,q.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,q.jsx)(gd,{title:`Handler`,icon:x,children:u?(0,q.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,q.jsx)(jn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,q.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function md(e){if(e<=0)return`now`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<48?`${r}h`:`${Math.round(r/24)}d`}function hd({label:e,children:t}){return(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,q.jsx)(`span`,{className:`break-all`,children:t})]})}function gd({title:e,icon:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,q.jsx)(t,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e})]}),n]})}function _d({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var vd=[{key:`objects`,label:`Objects`,icon:M,flat:!1},{key:`apps`,label:`Apps`,icon:Xn,flat:!1},{key:`messages`,label:`Messages`,icon:O,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Ot,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Dn,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:de,flat:!1},{key:`settings`,label:`Settings`,icon:fr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:A,flat:!1}];function yd({name:e,draft:t}){let n=t,r=n.locale??n.language??`?`,i=n.label??n.name??e??``,a=n.description,o=n.data??n,s=vd.map(e=>{let t=o?.[e.key];if(!t||typeof t!=`object`)return{...e,count:0,sample:[]};let n=Object.entries(t);return{...e,count:n.length,sample:n.slice(0,5)}}),c=s.reduce((e,t)=>e+t.count,0),l=s.filter(e=>e.count>0).length,u=Math.round(l/vd.length*100);return c===0?(0,q.jsx)(X,{hint:`translation · ${r}`,children:(0,q.jsx)(Z,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,q.jsx)(X,{hint:`translation · ${r} · ${c} keys`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(it,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[10px] font-mono text-emerald-800`,children:[(0,q.jsx)(yr,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,q.jsx)(Zn,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,q.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,q.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,q.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,vd.length,` (`,u,`%)`]}),(0,q.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,q.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,q.jsx)(bd,{cat:e},e.key))})]})})})}function bd({cat:e}){let t=e.icon;return(0,q.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,q.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,q.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,q.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,q.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,q.jsx)(`span`,{className:`truncate text-foreground/80`,children:xd(n,e.flat)})]},t)),e.count>e.sample.length&&(0,q.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function xd(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Sd({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.parent;return r?(0,q.jsx)(X,{hint:`role`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(w,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,q.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(He,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,q.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,q.jsx)(Mn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,q.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,q.jsx)($t,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,q.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,q.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,q.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,q.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,q.jsx)(X,{hint:`role`,children:(0,q.jsx)(Z,{children:`Give the role a name to see the preview.`})})}function Cd({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.instructions??``,s=Array.isArray(n.tools)?n.tools:[],c=Array.isArray(n.triggerPhrases)?n.triggerPhrases:[],l=Array.isArray(n.triggerConditions)?n.triggerConditions:[],u=Array.isArray(n.permissions)?n.permissions:[],d=n.active!==!1,f=n.model??void 0;return r?(0,q.jsx)(X,{hint:`skill`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(mn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(Td,{icon:ct,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,q.jsx)(Td,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,q.jsx)(Td,{icon:$t,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,q.jsx)(wd,{title:`Instructions`,icon:Tt,children:o?(0,q.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words max-h-64 overflow-auto`,children:o}):(0,q.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,q.jsxs)(wd,{title:`Tools (${s.length})`,icon:j,children:[s.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-mono border ${t?`border-amber-300 bg-amber-50 text-amber-900`:`border-border bg-muted/40`}`,children:[t&&(0,q.jsx)(In,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-amber-700`,children:`Wildcards expand to many tools at runtime — review the matching set in the agent before activating.`})]}),c.length>0&&(0,q.jsx)(wd,{title:`Trigger Phrases (${c.length})`,icon:sr,children:(0,q.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,q.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,q.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,q.jsx)(wd,{title:`Trigger Conditions (${l.length})`,icon:Zt,children:(0,q.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,q.jsx)(`table`,{className:`w-full text-xs`,children:(0,q.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})}),u.length>0&&(0,q.jsx)(wd,{title:`Required Permissions`,icon:$t,children:(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})}):(0,q.jsx)(X,{hint:`skill`,children:(0,q.jsx)(Z,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function wd({title:e,icon:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,q.jsx)(t,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e})]}),n]})}function Td({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Ed=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Dd=d();function Od(){return``.replace(/\/+$/,``)}function kd(e){return`${Od()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function Ad(e){if(e.status===503){let t;try{t=await e.json()}catch{t=void 0}if((t&&typeof t==`object`&&`error`in t?String(t.error):``)===`external_service_unavailable`)throw new Ed}if(!e.ok){let t=`${e.status} ${e.statusText}`;try{let n=await e.json();n&&typeof n==`object`&&`error`in n&&(t=String(n.error))}catch{}throw Error(t)}return await e.json()}async function jd(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await Ad(await Dd(`${kd(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Md(e,t,n={}){return(await Ad(await Dd(`${kd(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Nd(e){return(await Ad(await Dd(`${kd(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Pd(e){return Ad(await Dd(`${kd(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Fd(e){await Ad(await Dd(`${Od()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Id({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=J.useState(`loading`),[s,c]=J.useState(null),[l,u]=J.useState(null);J.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await Md(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof Ed?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=J.useCallback(async()=>{if(s){o(`importing`),u(null);try{await Fd(s),o(`done`),i?.(s.name)}catch(e){u(e instanceof Error?e.message:String(e)),o(`ready`)}}},[s,i]),f=t?[t.schema,t.name].filter(Boolean).join(`.`):``;return(0,q.jsx)(De,{open:n,onOpenChange:r,children:(0,q.jsxs)(qe,{className:`max-w-2xl`,children:[(0,q.jsxs)(lt,{children:[(0,q.jsxs)(pe,{className:`flex items-center gap-2`,children:[(0,q.jsx)(ht,{className:`h-4 w-4`}),`Import as Object`]}),(0,q.jsxs)(vr,{children:[`Map remote table `,(0,q.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,q.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,q.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,q.jsx)(R,{className:`h-8 w-8 text-emerald-500`}),(0,q.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Review its binding and run validation to confirm it matches the remote table.`})]}),(a===`ready`||a===`importing`)&&s&&(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,q.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,q.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,q.jsx)(I,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,q.jsx)(`ul`,{className:`mt-1.5 space-y-1 text-[11px] text-amber-900/90 dark:text-amber-200/80`,children:s.review.map(e=>(0,q.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,q.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,q.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,q.jsx)(dn,{className:`h-3 w-3`}),` Generated source`]}),(0,q.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/30 p-2.5 text-[11px] leading-relaxed font-mono`,children:s.source})]})]}),(0,q.jsx)(T,{children:a===`done`?(0,q.jsx)(z,{onClick:()=>r(!1),children:`Close`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(z,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,q.jsx)(z,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Ld({datasource:e}){let[t,n]=J.useState(`idle`),[r,i]=J.useState([]),[a,o]=J.useState(null),[s,c]=J.useState(``),[l,u]=J.useState(null),[d,f]=J.useState(!1),p=J.useCallback(async()=>{n(`loading`),o(null);try{i(await jd(e)),n(`loaded`)}catch(e){e instanceof Ed?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);J.useEffect(()=>{p()},[p]);let m=J.useMemo(()=>{let e=s.trim().toLowerCase();return e?r.filter(t=>[t.schema,t.name].filter(Boolean).join(`.`).toLowerCase().includes(e)):r},[r,s]),h=e=>{u(e),f(!0)};return t===`unavailable`?(0,q.jsx)(Rd,{}):(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1`,children:[(0,q.jsx)(Ze,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Filter tables…`,className:`w-full rounded border bg-background pl-7 pr-2 py-1.5 text-xs outline-none focus:ring-1 focus:ring-ring`})]}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,q.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:a}),t===`loading`&&r.length===0&&(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,q.jsx)(`div`,{className:`py-10 text-center text-sm text-muted-foreground`,children:r.length===0?`No remote tables found (check the datasource’s allowedSchemas).`:`No tables match the filter.`}),m.length>0&&(0,q.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,q.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,q.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,q.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,q.jsx)(Ge,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,q.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,q.jsx)(Dt,{className:`h-3 w-3`}),e.columnCount]})}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums text-muted-foreground`,children:typeof e.rowCountEstimate==`number`?e.rowCountEstimate.toLocaleString():`—`}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,q.jsx)(E,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,q.jsx)(Id,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Rd(){return(0,q.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:[`Federation is not enabled on this server. The`,(0,q.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var zd={missing_table:`Missing table`,missing_column:`Missing column`,type_mismatch:`Type mismatch`,nullability_mismatch:`Nullability mismatch`,unmapped_column:`Unmapped column`,pk_mismatch:`Primary-key mismatch`};function Bd({datasource:e}){let[t,n]=J.useState(`idle`),[r,i]=J.useState([]),[a,o]=J.useState(null),[s,c]=J.useState(null),l=J.useCallback(async()=>{n(`running`),c(null);try{let t=await Pd(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof Ed?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,q.jsx)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:`Federation is not enabled on this server, so validation is unavailable.`}):(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,q.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(jn,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,q.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:s}),t===`done`&&a!==null&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 rounded border p-2.5 text-sm ${a?`border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 text-emerald-800 dark:text-emerald-300`:`border-destructive/40 bg-destructive/5 text-destructive`}`,children:[a?(0,q.jsx)(R,{className:`h-4 w-4`}):(0,q.jsx)(Ot,{className:`h-4 w-4`}),a?`All ${r.length} object${r.length===1?``:`s`} match the remote schema.`:`${r.filter(e=>!e.ok).length} of ${r.length} object${r.length===1?``:`s`} diverge from the remote schema.`]}),t===`done`&&r.length===0&&(0,q.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No federated objects are bound to this datasource yet. Import a table from the Tables tab to get started.`}),r.length>0&&(0,q.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,q.jsx)(Vd,{result:e},e.object))})]})}function Vd({result:e}){return(0,q.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,q.jsx)($t,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,q.jsx)(Ot,{className:`h-3.5 w-3.5 text-destructive`}),(0,q.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,q.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[e.diffs.length,` diff`,e.diffs.length===1?``:`s`]})]}),e.diffs.length>0&&(0,q.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,q.jsx)(Hd,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Hd({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,q.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-2.5 py-1.5 text-[11px]`,children:[(0,q.jsx)(`span`,{className:`rounded px-1 py-0.5 font-medium uppercase tracking-wide text-[9px] ${e.severity===`error`?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:zd[e.kind]??e.kind}),t&&(0,q.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,q.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,q.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,q.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function Ud({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=J.useState(null),[a,o]=J.useState(!1),[s,c]=J.useState(null),l=J.useCallback(async()=>{if(e){o(!0),c(null);try{i(await Nd(e))}catch(e){c(e instanceof Ed?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,q.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,q.jsx)(se,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,q.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:t??`external`}),(0,q.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`:`bg-muted text-muted-foreground`}`,children:n?`writes allowed`:`read-only`}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,q.jsx)(Ln,{className:`h-3 w-3`}),`snapshot `,Wd(r.snapshotAt)]}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,q.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,q.jsxs)(Tn,{defaultValue:`tables`,className:`p-3`,children:[(0,q.jsxs)(ln,{children:[(0,q.jsx)(jt,{value:`tables`,children:`Tables`}),(0,q.jsx)(jt,{value:`validation`,children:`Validation`})]}),(0,q.jsx)(Rn,{value:`tables`,className:`mt-3`,children:(0,q.jsx)(Ld,{datasource:e})}),(0,q.jsx)(Rn,{value:`validation`,className:`mt-3`,children:(0,q.jsx)(Bd,{datasource:e})})]})]}):(0,q.jsx)(`div`,{className:`rounded border bg-muted/20 p-3 text-xs text-muted-foreground`,children:`Save the datasource first to browse its remote tables and validate federated objects.`})}function Wd(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Gd=/pass|secret|key|token|credential|auth/i;function Kd(e){return Gd.test(e)}function qd(e){return e==null||e===``?`∅`:`••••••`}function Jd(e){return e==null?`∅`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`[${e.length}]`:typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e)}function Yd({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=n.schemaMode??`managed`,_=g!==`managed`,v=!!(n.external??void 0)?.allowWrites,y=Object.entries(l);return!r&&y.length===0?(0,q.jsx)(X,{hint:`datasource`,children:(0,q.jsx)(Z,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,q.jsx)(X,{hint:`datasource · ${o}`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(ht,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,q.jsx)(wn,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,q.jsx)(Qd,{icon:ct,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,q.jsx)(Qd,{icon:Cn,label:`default`,tone:`amber`}),m.length>0&&(0,q.jsx)(Qd,{icon:wt,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,q.jsx)(Ud,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,q.jsx)(Zd,{title:`Connection`,icon:un,children:y.length===0?(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,q.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,q.jsx)(`table`,{className:`w-full text-xs`,children:(0,q.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=Kd(e);return(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,q.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{children:qd(t)}),(0,q.jsx)(`span`,{className:`rounded bg-amber-50 border border-amber-200 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-800`,children:`redacted`})]}):Jd(t)})]},e)})})})})}),(0,q.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,q.jsx)(Xd,{title:`Pool`,icon:Yt,value:u}),(0,q.jsx)(Xd,{title:`SSL`,icon:$t,value:typeof d==`boolean`?{enabled:d}:d}),(0,q.jsx)(Xd,{title:`Retry Policy`,icon:C,value:f}),(0,q.jsx)(Xd,{title:`Health Check`,icon:Yt,value:p})]}),h.length>0&&(0,q.jsx)(Zd,{title:`Capabilities`,icon:$t,children:(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})})}function Xd({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,q.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,q.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,q.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,q.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,q.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,q.jsx)(`dd`,{className:`font-mono truncate`,children:Kd(e)?qd(t):Jd(t)})]},e))}):(0,q.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function Zd({title:e,icon:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,q.jsx)(t,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e})]}),n]})}function Qd({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function $d(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function ef(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/40`,text:`text-red-700 dark:text-red-300`,icon:Bt};case`warning`:return{ring:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`,text:`text-amber-800 dark:text-amber-300`,icon:I};default:return{ring:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`,text:`text-blue-800 dark:text-blue-300`,icon:xe}}}function tf({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.type??`script`,s=n.object,c=n.message??``,l=n.severity??`error`,u=n.active!==!1,d=Array.isArray(n.events)?n.events:[],f=n.priority,p=Array.isArray(n.tags)?n.tags:[],m=ef(l);return r?(0,q.jsx)(X,{hint:`validation · ${o}`,children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(Ot,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,q.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,q.jsx)(of,{icon:ct,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,q.jsx)(of,{label:`object: ${s}`,mono:!0}),f!=null&&(0,q.jsx)(of,{label:`priority ${f}`}),d.length>0&&(0,q.jsx)(of,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,q.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,q.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,q.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,q.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,q.jsx)(nf,{type:o,d:n}),p.length>0&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,q.jsx)(`span`,{className:`inline-flex items-center rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})]})]})})}):(0,q.jsx)(X,{hint:`validation`,children:(0,q.jsx)(Z,{children:`Give the validation a name to see the preview.`})})}function nf({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,q.jsx)(af,{title:`Condition`,icon:x,children:(0,q.jsx)(rf,{value:$d(t.condition)??$d(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=$d(t.scope)??$d(t.where);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(af,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:pr,children:(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,q.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,q.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,q.jsx)(af,{title:`Scope`,icon:kn,children:(0,q.jsx)(rf,{value:n})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field;return(0,q.jsx)(af,{title:`Transitions${r?` on ${r}`:``}`,icon:ar,children:n.length===0?(0,q.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,q.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,q.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e}),(0,q.jsx)(At,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:Array.isArray(t)&&t.length>0?t.join(` | `):`∅ (dead-end)`})]},e))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,q.jsx)(af,{title:`Format`,icon:Re,children:(0,q.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,q.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,q.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,q.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=$d(t.condition);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(af,{title:`Fields involved`,icon:kn,children:(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,q.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e)),e.length===0&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,q.jsx)(af,{title:`Cross-field condition`,icon:x,children:(0,q.jsx)(rf,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,q.jsx)(af,{title:`Async endpoint`,icon:yr,children:(0,q.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,q.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,q.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,q.jsx)(af,{title:`Custom handler`,icon:x,children:(0,q.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,q.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,q.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,q.jsx)(af,{title:`Rule`,icon:Ot,children:(0,q.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs text-muted-foreground italic`,children:[`Unknown rule type "`,e,`". Showing common fields only.`]})})}}function rf({value:e}){return e?(0,q.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,q.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function af({title:e,icon:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,q.jsx)(t,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e})]}),n]})}function of({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,q.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var sf=J.lazy(()=>o(()=>import(`./plugin-charts-dCyWH9k8.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function cf(e){return e==null?`—`:typeof e==`number`?Number.isInteger(e)?String(e):e.toLocaleString(void 0,{maximumFractionDigits:2}):typeof e==`boolean`?e?`true`:`false`:String(e)}function lf({draft:e}){let t=m(),n=e.object,r=J.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),i=J.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=!!n&&r.length>0,[o,s]=J.useState({status:`idle`,rows:[]}),c=J.useCallback(async()=>{if(a){s({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:i,measures:r});s({status:`ok`,rows:Array.isArray(n?.rows)?n.rows:[]})}catch(e){s({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,i,r,a]),l=`${n??``}|${i.join(`,`)}|${r.join(`,`)}`;if(J.useEffect(()=>{a&&c()},[l]),!n)return(0,q.jsx)(X,{children:(0,q.jsx)(Rs,{icon:(0,q.jsx)(ye,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(r.length===0)return(0,q.jsx)(X,{children:(0,q.jsx)(Rs,{icon:(0,q.jsx)(ye,{className:`h-8 w-8`}),title:`Add a measure`,description:`A dataset needs at least one measure (e.g. revenue = sum(amount)) to preview.`})});let u=[...i,...r];return(0,q.jsx)(X,{hint:`dataset · ${n}${i.length?` · by `+i.join(`, `):``}`,children:(0,q.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>void c(),disabled:o.status===`loading`,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[o.status===`loading`?(0,q.jsx)(F,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ye,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[r.length,` measure`,r.length===1?``:`s`,` · `,i.length,` dimension`,i.length===1?``:`s`]})]}),o.status===`error`&&(0,q.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,q.jsx)(I,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,q.jsx)(`span`,{className:`break-words`,children:o.error})]}),o.status===`ok`&&o.rows.length===0&&(0,q.jsx)(Rs,{icon:(0,q.jsx)(ye,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),o.rows.length>0&&i.length>=1&&(0,q.jsx)(Q,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,q.jsx)(J.Suspense,{fallback:(0,q.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,q.jsx)(F,{className:`h-4 w-4 animate-spin`})}),children:(0,q.jsx)(`div`,{className:`rounded-md border p-2`,children:(0,q.jsx)(sf,{schema:{data:o.rows,xAxisKey:i[0],series:r.map(e=>({dataKey:e,label:e,chartType:`bar`}))}})})})}),o.rows.length>0&&(0,q.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40`,children:(0,q.jsx)(`tr`,{children:u.map(e=>(0,q.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:e},e))})}),(0,q.jsx)(`tbody`,{children:o.rows.map((e,t)=>(0,q.jsx)(`tr`,{className:`border-t`,children:u.map(t=>(0,q.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:cf(e[t])},t))},t))})]})})]})})}function uf(e){return Array.isArray(e)?e.map((e,t)=>{if(!e||typeof e!=`object`)return null;let n=String(e.key??``).trim(),r=String(e.label??n??``).trim();return!n&&!r?null:{g:{key:n||`(no key)`,label:r||n||`(unnamed)`,order:typeof e.order==`number`?e.order:void 0,include:df(e.include),package:typeof e.package==`string`?e.package:void 0,pages:ff(e.pages)},i:t}}).filter(e=>e!==null).sort((e,t)=>(e.g.order??0)-(t.g.order??0)||e.i-t.i).map(e=>e.g):[]}function df(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function ff(e){if(Array.isArray(e))return e.map(e=>typeof e==`string`?{literal:e}:e&&typeof e==`object`?{doc:typeof e.doc==`string`?e.doc:void 0,href:typeof e.href==`string`?e.href:void 0,label:typeof e.label==`string`?e.label:void 0,badge:typeof e.badge==`string`?e.badge:void 0,icon:typeof e.icon==`string`?e.icon:void 0}:null).filter(e=>e!==null)}function pf(e){return e===`public`?{icon:(0,q.jsx)(En,{className:`h-3 w-3`}),label:`Public`,tone:`text-emerald-700 bg-emerald-50 border-emerald-200`}:e&&typeof e==`object`&&typeof e.profile==`string`?{icon:(0,q.jsx)(un,{className:`h-3 w-3`}),label:`Profile: ${e.profile}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,q.jsx)(dt,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function mf({name:e,draft:t}){let n=t,r=String(n.name??e??``).trim(),i=String(n.label??r),a=typeof n.description==`string`?n.description:``,o=typeof n.slug==`string`?n.slug:``,s=J.useMemo(()=>uf(n.groups),[n.groups]),c=pf(n.audience);return r?(0,q.jsx)(X,{hint:`book · spine`,toolbar:(0,q.jsxs)(`a`,{href:`/meta/book/${encodeURIComponent(r)}/tree`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open the live-resolved navigation tree (actual docs per group)`,children:[`Resolved tree `,(0,q.jsx)(_e,{className:`h-3 w-3`})]}),children:(0,q.jsx)(Q,{children:(0,q.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Tt,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:i}),(0,q.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium ${c.tone}`,children:[c.icon,c.label]})]}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:r}),o&&(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Slug: `,(0,q.jsx)(`code`,{className:`font-mono`,children:o})]}),a&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1.5`,children:a})]}),s.length===0?(0,q.jsx)(Rs,{icon:(0,q.jsx)(rn,{className:`h-8 w-8 opacity-50`}),title:`No groups yet`,tone:`warn`,description:(0,q.jsxs)(q.Fragment,{children:[`A book needs at least one group in its `,(0,q.jsx)(`code`,{children:`groups`}),` spine. Each group derives its members from an `,(0,q.jsx)(`code`,{children:`include`}),` rule (a glob like`,` `,(0,q.jsx)(`code`,{children:`crm_guide_*`}),` or a `,(0,q.jsx)(`code`,{children:`{ tag }`}),`).`]})}):(0,q.jsx)(`div`,{className:`space-y-2`,children:s.map((e,t)=>(0,q.jsx)(hf,{group:e},`${e.key}-${t}`))})]})})}):(0,q.jsx)(X,{hint:`book`,children:(0,q.jsx)(Rs,{icon:(0,q.jsx)(Tt,{className:`h-8 w-8 opacity-50`}),title:`Name your book`,description:`Enter a name in the Form tab to start authoring the documentation spine.`})})}function hf({group:e}){return(0,q.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/20 px-3 py-2`,children:[(0,q.jsx)(rn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.key}),typeof e.order==`number`&&(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Order within the book`,children:[`#`,e.order]}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[e.package&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Membership rule is scoped to this package`,children:[(0,q.jsx)(Yn,{className:`h-3 w-3`}),e.package]}),(0,q.jsx)(gf,{include:e.include,hasOverride:!!e.pages?.length})]})]}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:e.pages?.length?(0,q.jsx)(`ol`,{className:`space-y-1`,children:e.pages.map((e,t)=>(0,q.jsx)(_f,{node:e},t))}):e.include==null?(0,q.jsxs)(`div`,{className:`text-[11px] text-amber-700 italic`,children:[`No `,(0,q.jsx)(`code`,{children:`include`}),` rule and no explicit `,(0,q.jsx)(`code`,{children:`pages`}),` — this group matches nothing unless docs set `,(0,q.jsxs)(`code`,{children:[`group: "`,e.key,`"`]}),`.`]}):(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Members derived from the rule above — resolved against the live doc set.`})})]})}function gf({include:e,hasOverride:t}){return e==null?t?(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Curated order via explicit pages`,children:`curated`}):null:typeof e==`string`?(0,q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,title:`Glob over doc names`,children:e}):(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[10px] text-foreground`,title:`Match by doc tag`,children:[(0,q.jsx)(St,{className:`h-3 w-3`}),e.tag]})}function _f({node:e}){if(e.literal===`---`)return(0,q.jsxs)(`li`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-wider text-muted-foreground/60`,children:[(0,q.jsx)(dr,{className:`h-3 w-3`}),`separator`]});if(e.literal===`...`)return(0,q.jsxs)(`li`,{className:`flex items-center gap-2 text-[11px] italic text-muted-foreground`,children:[(0,q.jsx)(Oe,{className:`h-3.5 w-3.5`}),`…rest (remaining matched docs, by order)`]});let t=!!e.href,n=e.literal??e.doc,r=e.label??n??e.href??`(empty)`;return(0,q.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,q.jsx)(_e,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,q.jsx)(A,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:r}),!t&&n&&e.label&&(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n}),e.badge&&(0,q.jsx)(`span`,{className:`rounded-full border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-foreground`,children:e.badge}),t&&(0,q.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground truncate max-w-[40%]`,title:e.href,children:e.href})]})}function vf(){Y(`page`,Sc),Y(`view`,Dc),Y(`dashboard`,kc),Y(`report`,Mc),Y(`app`,Gc),Y(`action`,Yu),Y(`object`,fl),Y(`datasource`,Yd),Y(`validation`,tf),Y(`dataset`,lf),Y(`email_template`,gl),Y(`translation`,yd),Y(`book`,mf),Y(`flow`,vu),Y(`job`,pd),Y(`agent`,bu),Y(`tool`,Nu),Y(`skill`,Cd),Y(`permission`,Bu),Y(`profile`,Bu),Y(`role`,Sd)}function $(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function yf(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var bf=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),xf={start:[$(`triggerType`,`Trigger`,`select`,{help:`When this flow starts. Record triggers fire on data changes; schedule triggers fire on a cron.`,options:[{value:`record-after-create`,label:`Record created`},{value:`record-after-update`,label:`Record updated`},{value:`record-before-update`,label:`Record before update`},{value:`record-after-delete`,label:`Record deleted`},{value:`record-change`,label:`Record changed (any)`},{value:`schedule`,label:`Schedule (cron)`},{value:`manual`,label:`Manual / autolaunched`},{value:`webhook`,label:`Webhook / API`},{value:`event`,label:`Platform event`}]}),$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`crm_lead`,help:`Target object for record / scheduled-scan triggers.`}),$(`condition`,`Entry condition`,`expression`,{placeholder:`status == "qualifying" && previous.status != "qualifying"`,help:`CEL predicate — the flow runs only when this is true. Leave empty to run on every event.`}),$(`cron`,`Cron schedule`,`text`,{placeholder:`0 7 * * *`,help:`Cron expression for scheduled triggers.`,showWhen:{field:`triggerType`,equals:[`schedule`]}}),$(`criteria`,`Entry condition (legacy)`,`expression`,{placeholder:`status == "active"`,help:`Legacy key — prefer "Entry condition" (condition).`,showWhen:{field:`__legacy__`,equals:[]}}),$(`schedule`,`Cron schedule (legacy)`,`text`,{placeholder:`0 9 * * *`,help:`Legacy key — prefer "Cron schedule" (cron).`,showWhen:{field:`__legacy__`,equals:[]}})],end:[$(`outcome`,`Outcome`,`text`,{placeholder:`success · failure`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})],decision:[$(`conditions`,`Branches`,`objectList`,{help:`Each branch has a label and a CEL expression (spec decision shape). A branch whose expression is "true" is the default/else path.`,columns:[{key:`label`,label:`Label`,kind:`text`,placeholder:`Has deals`},{key:`expression`,label:`Expression`,kind:`expression`,placeholder:`expiring_deals.length > 0`}]}),$(`condition`,`Condition (single)`,`expression`,{placeholder:`amount > 10000`,help:`Legacy single-branch condition (CEL). Prefer Branches above; per-edge conditions also live on the outgoing edges.`,showWhen:{field:`__legacy__`,equals:[]}})],assignment:[$(`assignments`,`Assignments`,`keyValue`,{help:`Set variables: each key is a variable, each value an expression or literal.`})],loop:[$(`collection`,`Collection`,`expression`,{placeholder:`{leadList}`,help:`Expression resolving to the items to iterate.`}),$(`iteratorVariable`,`Item variable`,`text`,{placeholder:`currentItem`})],map:[$(`collection`,`Collection`,`expression`,{placeholder:`{items}`,help:`Expression resolving to the array to process, one item at a time.`}),$(`flowName`,`Per-item flow`,`reference`,{ref:{kind:`flow`},placeholder:`one_task_signoff`,help:`Subflow run for each item — it may pause (e.g. an approval).`}),$(`iteratorVariable`,`Item variable`,`text`,{placeholder:`item`}),$(`itemObject`,`Item object`,`reference`,{ref:{kind:`object`},placeholder:`showcase_task`,help:`When items are records, the object they belong to (exposes each item as the child’s record).`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`results`,help:`Each item’s subflow output, collected in order.`})],create_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`fields`,`Field values`,`keyValue`,{help:`Field values to write on the new record.`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`newRecord`})],update_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to update (e.g. id → {recordId}).`}),$(`fields`,`Field values`,`keyValue`,{help:`Field values to write.`})],delete_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to delete.`})],get_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs to match (e.g. status → active). Operator values like {"$ne": null} are preserved.`}),$(`limit`,`Limit`,`number`,{placeholder:`100`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`records`})],http_request:[$(`method`,`Method`,`select`,{options:bf,defaultValue:`GET`}),$(`url`,`URL`,`text`,{placeholder:`https://api.example.com/v1/contracts`}),$(`headers`,`Headers`,`keyValue`,{help:`Request headers (e.g. Authorization, Content-Type).`}),$(`body`,`Body`,`textarea`,{placeholder:`{ "key": "value" }`,help:`Request payload (JSON or expression).`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`response`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],script:[$(`actionType`,`Action type`,`select`,{options:[{value:`code`,label:`Code`},{value:`email`,label:`Email`},{value:`sms`,label:`SMS`},{value:`notification`,label:`Notification`}],defaultValue:`code`,help:`How this step runs. Leave as Code for a raw script.`}),$(`template`,`Template`,`reference`,{ref:{kindFrom:`actionType`,map:{email:`email-template`}},placeholder:`case_escalated`,help:`Message template id.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`recipients`,`Recipients`,`stringList`,{help:`One recipient per row (user id, field ref, or address).`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`variables`,`Template variables`,`keyValue`,{help:`Values injected into the template.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`script`,`Code`,`textarea`,{placeholder:`return { ok: true };`,help:`Script body (JS/TS).`,showWhen:{field:`actionType`,equals:[`code`]}}),$(`outputVariables`,`Output variables`,`stringList`,{help:`Names of variables this script writes back.`,showWhen:{field:`actionType`,equals:[`code`]}}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],screen:[$(`fields`,`Fields`,`objectList`,{help:`Fields presented on this screen.`,columns:[{key:`name`,label:`Name`,kind:`text`,placeholder:`discount`},{key:`label`,label:`Label`,kind:`text`,placeholder:`Discount %`},{key:`type`,label:`Type`,kind:`text`,placeholder:`number`},{key:`required`,label:`Required`,kind:`boolean`},{key:`visibleWhen`,label:`Visible when`,kind:`expression`,placeholder:`stage == "review"`}]})],approval:[$(`approvers`,`Approvers`,`objectList`,{help:`Who may act on this step. Wire the node’s out-edges with labels "approve" and "reject".`,columns:[{key:`type`,label:`Type`,kind:`select`,options:[{value:`user`,label:`User`},{value:`role`,label:`Role`},{value:`team`,label:`Team`},{value:`department`,label:`Department`},{value:`manager`,label:`Manager`},{value:`field`,label:`Field`},{value:`queue`,label:`Queue`}]},{key:`value`,label:`Value`,kind:`reference`,placeholder:`user id / role / field — per type`,ref:{kindFrom:`type`,objectSource:`$trigger`,map:{user:`user`,role:`role`,team:`team`,department:`department`,field:`object-field`,queue:`queue`}}}]}),$(`behavior`,`Behavior`,`select`,{options:[{value:`first_response`,label:`First response wins`},{value:`unanimous`,label:`Unanimous (all approve)`}],defaultValue:`first_response`,help:`How multiple approvers combine.`}),$(`lockRecord`,`Lock record`,`boolean`,{help:`Lock the triggering record from edits while this node is pending.`}),$(`approvalStatusField`,`Status field`,`reference`,{ref:{kind:`object-field`,objectSource:`$trigger`},placeholder:`approval_status`,help:`Business-object field to mirror request status onto (pending/approved/rejected). Should be readonly.`}),{id:`escalation.enabled`,path:[`config`,`escalation`,`enabled`],label:`SLA escalation`,kind:`boolean`,defaultValue:`false`,help:`Escalate when a decision is not recorded within the timeout.`},{id:`escalation.timeoutHours`,path:[`config`,`escalation`,`timeoutHours`],label:`Timeout (hours)`,kind:`number`,placeholder:`24`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.action`,path:[`config`,`escalation`,`action`],label:`On timeout`,kind:`select`,defaultValue:`notify`,options:[{value:`notify`,label:`Notify`},{value:`reassign`,label:`Reassign`},{value:`auto_approve`,label:`Auto-approve`},{value:`auto_reject`,label:`Auto-reject`}],showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.escalateTo`,path:[`config`,`escalation`,`escalateTo`],label:`Escalate to`,kind:`reference`,ref:{kind:`role`},placeholder:`user id / role / manager level`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.notifySubmitter`,path:[`config`,`escalation`,`notifySubmitter`],label:`Notify submitter`,kind:`boolean`,showWhen:{field:`escalation.enabled`,equals:[`true`]}}],wait:[yf(`waitEventConfig`,`eventType`,`Wait for`,`select`,{options:[{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`webhook`,label:`Webhook`},{value:`manual`,label:`Manual`},{value:`condition`,label:`Condition`}],defaultValue:`timer`}),yf(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),yf(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),yf(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),yf(`waitEventConfig`,`onTimeout`,`On timeout`,`select`,{options:[{value:`fail`,label:`Fail`},{value:`continue`,label:`Continue`}],defaultValue:`fail`})],subflow:[$(`flowName`,`Flow`,`reference`,{ref:{kind:`flow`},placeholder:`escalation_flow`}),$(`input`,`Input mapping`,`keyValue`,{help:`Values passed to the subflow’s input variables.`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`subResult`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`60000`}],connector_action:[yf(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),yf(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),yf(`connectorConfig`,`input`,`Input`,`keyValue`,{help:`Mapped inputs for the connector action.`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],parallel:[],try_catch:[$(`errorVariable`,`Error variable`,`text`,{placeholder:`$error`,help:`Variable the caught error is bound to inside the catch region.`})],parallel_gateway:[],join_gateway:[],boundary_event:[yf(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),yf(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),yf(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),yf(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),yf(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),yf(`boundaryConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.cancelled`,showWhen:{field:`boundaryConfig.eventType`,equals:[`signal`]}})],legacy_action:[$(`action`,`Action`,`text`,{placeholder:`sendEmail · createTask · update · query`}),$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`recordId`,`Record`,`expression`,{placeholder:`record.id`}),$(`params`,`Parameters`,`keyValue`,{help:`Action inputs. Values auto-typed: 3 → number, true → boolean.`}),$(`fields`,`Field values`,`keyValue`),$(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})]},Sf={action:`legacy_action`,branch:`decision`,gateway:`decision`,condition:`decision`,timer:`wait`,delay:`wait`,flow:`subflow`,invoke:`subflow`,task:`legacy_action`,user_task:`screen`,service_task:`connector_action`,script_task:`script`,notification:`connector_action`,signal:`boundary_event`,webhook:`connector_action`,for_each:`loop`};function Cf(e){return e?xf[Sf[e]??e]??[]:[]}function wf(e,t){let n=e;for(let e of t.path)if(n&&typeof n==`object`&&!Array.isArray(n))n=n[e];else return;return n}function Tf(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function Ef(e,t,n){if(!e.showWhen)return!0;let r=wf(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=wf(t,i),o=a==null||a===``?i.defaultValue:a,s=typeof o==`boolean`?String(o):o;return typeof s==`string`&&e.showWhen.equals.includes(s)}var Df=[`start`,`create_record`,`update_record`,`delete_record`,`get_record`,`decision`,`assignment`,`loop`,`http_request`,`script`,`screen`,`approval`,`wait`,`subflow`,`map`,`connector_action`,`parallel`,`try_catch`,`end`],Of=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function kf(e){let t=e.xRef;if(!t||typeof t!=`object`)return;let n=typeof t.objectSource==`string`&&t.objectSource?{objectSource:t.objectSource}:{};if(typeof t.kindFrom==`string`&&t.kindFrom&&t.map&&typeof t.map==`object`){let e={};for(let[n,r]of Object.entries(t.map))typeof r==`string`&&Of.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&Of.has(t.kind))return{kind:t.kind,...n}}function Af(e){let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim();return t?t.split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):e}function jf(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Mf(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`);if(typeof e.type==`string`)return e.type;if(Array.isArray(e.enum))return`string`;if(e.properties)return`object`;if(e.items)return`array`}function Nf(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:Af(e)}))}function Pf(e){if(!(e.default===void 0||e.default===null)){if(typeof e.default==`boolean`||typeof e.default==`number`)return String(e.default);if(typeof e.default==`string`)return e.default}}function Ff(e){if(Array.isArray(e.enum))return`select`;let t=Mf(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function If(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!jf(r))continue;let t=Mf(r),i,a,o=kf(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=Nf(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||Af(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function Lf(e,t){return{label:e.title||Af(t),...e.description?{help:e.description}:{},...Pf(e)?{defaultValue:Pf(e)}:{}}}function Rf(e){if(!jf(e)||Mf(e)!==`object`||!jf(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!jf(r))continue;let e=Mf(r);if(e===`array`){let e=jf(r.items)?r.items:void 0,i=e?Mf(e):void 0;e&&i===`object`&&jf(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:If(e),...Lf(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...Lf(r,n)});continue}if(e===`object`&&jf(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>jf(e)),i=e.some(([e,t])=>e===`enabled`&&Mf(t)===`boolean`);for(let[a,o]of e){let e=o,s=kf(e),c=s?`reference`:Ff(e);if(!c)continue;let l=`${n}.${a}`,u=i&&a===`enabled`,d={id:l,path:[`config`,n,a],kind:c,...u?{label:r.title||Af(n),...r.description?{help:r.description}:{},...Pf(e)?{defaultValue:Pf(e)}:{}}:Lf(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:Nf(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=kf(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...Lf(r,n)});continue}let a=Ff(r);a&&t.push({id:n,path:[`config`,n],kind:a,...Lf(r,n),...a===`select`&&Array.isArray(r.enum)?{options:Nf(r.enum)}:{}})}return t}function zf(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Bf(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Vf(e){let t=e.trim();if(t===``)return``;if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function Hf(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=Or(`kv`,n);return n.push(r),{id:r,key:e,raw:Bf(t)}})}function Uf(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=Vf(n.raw))}return t}function Wf(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function Gf({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=zf(t)?t:{},[d,f]=J.useState(()=>Hf(u,[])),p=J.useRef(Wf(u));J.useEffect(()=>{let e=Wf(u);e!==p.current&&(f(Hf(u,[])),p.current=e)},[u]);let m=e=>{let t=Uf(e);p.current=Wf(t),n(Object.keys(t).length?t:void 0)},h=(e,t)=>{f(n=>n.map(n=>n.id===e?{...n,...t}:n))},g=()=>{f(e=>[...e,{id:Or(`kv`,e.map(e=>e.id)),key:``,raw:``}])},_=e=>{f(t=>{let n=t.filter(t=>t.id!==e);return m(n),n})};return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[d.length===0&&(0,q.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),d.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(B,{value:e.key,onChange:t=>h(e.id,{key:t.target.value}),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:r,className:`h-8 flex-1 font-mono text-xs`}),(0,q.jsx)(B,{value:e.raw,onChange:t=>h(e.id,{raw:t.target.value}),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:s,disabled:r,className:`h-8 flex-1 text-xs`}),(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>_(e.id),disabled:r,"aria-label":c,title:c,children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function Kf(e,t){let n=[...t];return e.map(e=>{let t=Or(`sl`,n);return n.push(t),{id:t,value:e}})}function qf(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Jf({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=J.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=J.useState(()=>Kf(c,[])),d=J.useRef(JSON.stringify(c));J.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Kf(c,[])),d.current=e)},[c]);let f=e=>{let t=qf(e);d.current=JSON.stringify(t),n(t.length?t:void 0)},p=(e,t)=>{u(n=>n.map(n=>n.id===e?{...n,value:t}:n))},m=()=>{u(e=>[...e,{id:Or(`sl`,e.map(e=>e.id)),value:``}])},h=e=>{u(t=>{let n=t.filter(t=>t.id!==e);return f(n),n})};return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,q.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(B,{value:e.value,onChange:t=>p(e.id,t.target.value),onBlur:()=>f(l),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:a,disabled:r,className:`h-8 flex-1 text-xs`}),(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(e.id),disabled:r,"aria-label":o,title:o,children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var Yf={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function Xf(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource};if(e.kindFrom&&e.map){let n=t(e.kindFrom),r=typeof n==`string`?e.map[n]:void 0;if(r)return{kind:r,objectSource:e.objectSource}}}}function Zf(e,t){let n=e?.config;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[t];return typeof r==`string`&&r?r:void 0}function Qf(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Zf((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Zf(n.node,r)}function $f(e){let t=Tr(),[n,r]=J.useState({options:[],loading:!!e});return J.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{n||r({options:(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)})),loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}function ep({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=J.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?Qf(e.kind,e.objectSource,l):void 0,{fields:f}=Ei(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?Yf[u]:void 0,{options:m}=$f(p),h=J.useMemo(()=>{if(u===`object-field`)return f.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(u===`node`){let e=Array.isArray(l.draft.nodes)?l.draft.nodes:[],t=typeof l.node?.id==`string`?l.node.id:void 0;return e.filter(e=>typeof e?.id==`string`&&e.id&&e.id!==t).map(e=>{let t=String(e.id);return{value:t,label:typeof e.label==`string`&&e.label?`${e.label} (${t})`:t}})}return p?m:[]},[u,p,f,m,l.draft,l.node]),g=u===`object-field`&&!d;return(0,q.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,q.jsx)(B,{list:h.length?c:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:a,disabled:i,className:`h-8 text-sm`}),h.length>0&&(0,q.jsx)(`datalist`,{id:c,children:h.map(e=>(0,q.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,q.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&g&&(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`})]})}function tp({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Xf(e.ref,e=>Zf(a,e));return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,q.jsx)(ep,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function np(e,t){let n=[];return e.map(e=>{let r=Or(`ol`,n);n.push(r);let i={};for(let n of t){let t=e[n.key];n.kind===`boolean`?i[n.key]=t===!0:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function rp(e,t){let n=[];for(let r of e){let e={},i=!1;for(let n of t){let t=r.values[n.key];n.kind===`boolean`?t===!0&&(e[n.key]=!0,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function ip({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,context:c}){let l=J.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[u,d]=J.useState(()=>np(l,t)),f=J.useRef(JSON.stringify(l));J.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(np(l,t)),f.current=e)},[l,t]);let p=e=>{let n=rp(e,t);f.current=JSON.stringify(n),r(n.length?n:void 0)},m=(e,t,n)=>{d(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},h=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:``;d(t=>[...t,{id:Or(`ol`,t.map(e=>e.id)),values:e}])},g=e=>{d(t=>{let n=t.filter(t=>t.id!==e);return p(n),n})};return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[u.length===0&&(0,q.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),u.map(e=>(0,q.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,q.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>g(e.id),disabled:i,"aria-label":o,title:o,children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})})}),(0,q.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(V,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,q.jsx)(we,{checked:e.values[t.key]===!0,onCheckedChange:n=>{d(r=>{let i=r.map(r=>r.id===e.id?{...r,values:{...r.values,[t.key]:n===!0}}:r);return p(i),i})},disabled:i}):t.kind===`reference`?(0,q.jsx)(`div`,{className:`flex-1`,children:(0,q.jsx)(ep,{resolved:Xf(t.ref,t=>e.values[t]),value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>m(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>p(u),placeholder:t.placeholder,disabled:i,context:c,showHint:!1})}):(0,q.jsx)(B,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>m(e.id,t.key,n.target.value),onBlur:()=>p(u),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:t.placeholder,disabled:i,className:`h-8 flex-1 text-xs${t.kind===`expression`?` font-mono`:``}`})]},t.key))})]},e.id))]}),(0,q.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,q.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var ap=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function op(e,t,n){let r=0;for(let i of e)if(i===t)r++;else if(i===n&&(r--,r<0))return!1;return r===0}function sp(e,t){let n=``,r;if(typeof t==`string`)n=t;else if(t&&typeof t==`object`){let e=t;r=e.dialect,n=e.source??``}if(!n.trim())return null;if(e===`template`){if(r&&r!==`template`)return{message:`Expected a text template but got a \`${r}\` expression.`};op(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=ap.exec(n);return e?{message:`Single-brace \`{${e[1]}}\` is not a valid template hole — use double braces: \`{{ ${e[1]} }}\`.`}:null}if(r&&r!==`cel`)return{message:`Expected a CEL expression but got a \`${r}\` dialect.`};let i=ap.exec(n);return i?{message:`It looks like a \`{${i[1]}}\` template brace was used inside a condition — \`{…}\` parses as a CEL map literal and fails. Write the bare reference instead, e.g. \`${i[1]}\`. Conditions are bare CEL (e.g. \`record.rating >= 4\`).`}:op(n,`(`,`)`)?op(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function cp({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){let o=(()=>{switch(e.kind){case`reference`:return(0,q.jsx)(tp,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,q.jsx)(Gf,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.kv.add`,i),keyLabel:G(`engine.inspector.flowNode.kv.key`,i),valueLabel:G(`engine.inspector.flowNode.kv.value`,i),removeLabel:G(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:G(`engine.inspector.flowNode.kv.empty`,i)});case`stringList`:return(0,q.jsx)(Jf,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,q.jsx)(ip,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i),context:a});case`number`:return(0,q.jsx)(Ar,{label:e.label,value:typeof t==`number`?t:t!=null&&t!==``?Number(t):void 0,placeholder:e.placeholder,onCommit:e=>n(e),disabled:r});case`boolean`:return(0,q.jsx)(Nr,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,q.jsx)(Pr,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,q.jsx)(`textarea`,{value:t==null?``:String(t),onChange:e=>n(e.target.value),placeholder:e.placeholder,disabled:r,rows:4,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`})]});default:return(0,q.jsx)(W,{label:e.label,value:t==null?``:String(t),placeholder:e.placeholder,onCommit:e=>n(e),disabled:r,mono:e.kind===`expression`})}})(),s=e.kind===`expression`?sp(`predicate`,t):null;return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[o,s&&(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:s.message}),e.help&&!s&&(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}function lp(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function up(e,t,n){let[r,...i]=t,a={...e};if(i.length===0)n==null||n===``?delete a[r]:a[r]=n;else{let e=a[r],t=up(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function dp({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.nodes)?t.nodes:[],s=o.findIndex(t=>t?.id===e.id),c=s>=0?o[s]:null,l=Hl(),u=J.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:Rf(e))??Cf(c?.type)},[l,c?.type]),d=lp(c),f=u.filter(e=>Ef(e,c,u)),p=J.useMemo(()=>{let e=new Set;for(let t of u){let n=Tf(t);n&&e.add(n)}return e},[u]),m=J.useMemo(()=>{let e=Object.fromEntries(Object.entries(d).filter(([e])=>!p.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[c,p]),[h,g]=J.useState(m),[_,v]=J.useState(null),[y,b]=J.useState(m.trim()!==``),[x,S]=J.useState(!1);if(J.useEffect(()=>{g(m),v(null),b(m.trim()!==``),S(!1)},[m]),!c)return(0,q.jsx)(Mr,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),children:(0,q.jsx)(Vr,{message:e.id})});let C=e=>{n({nodes:K(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:K(o,s,up(c,e,t))})},E=()=>{try{let e=h.trim()===``?{}:JSON.parse(h);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(d).filter(([e])=>p.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!p.has(e))),i={...t,...r};v(null);let a={...c};Object.keys(i).length===0?delete a.config:a.config=i,n({nodes:K(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:K(o,s,null)}),r()},O=Df.includes(c.type)?[...Df]:[...Df,c.type??``].filter(Boolean);return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),footer:(0,q.jsx)(jr,{label:G(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,q.jsx)(W,{label:G(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,q.jsx)(Pr,{label:G(`engine.inspector.flowNode.type`,i),value:c.type,options:O.map(e=>({value:e,label:e})),onCommit:e=>C({type:e}),disabled:a}),(0,q.jsx)(W,{label:G(`engine.inspector.flowNode.description`,i),value:c.description??``,onCommit:e=>C({description:e||void 0}),disabled:a}),u.length===0?(0,q.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:G(`engine.inspector.flowNode.noConfig`,i)}):f.length>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,q.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowNode.configuration`,i)}),(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),f.map(e=>(0,q.jsx)(cp,{field:e,value:wf(c,e),onCommit:t=>T(e.path,t),disabled:a,locale:i,context:{draft:t,node:c}},e.id)),w||x?(0,q.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:y,onToggle:e=>b(e.target.open),children:[(0,q.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:G(`engine.inspector.flowNode.advanced`,i)}),(0,q.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowNode.advancedHint`,i)}),(0,q.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),onBlur:E,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),_&&(0,q.jsx)(`div`,{className:`text-xs text-destructive`,children:_})]})]}):!a&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{S(!0),b(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,q.jsx)(L,{className:`h-3 w-3`}),G(`engine.inspector.flowNode.advanced`,i)]})]})}function fp({label:e,value:t}){return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(`div`,{className:`flex h-8 items-center rounded border bg-muted/30 px-2 font-mono text-sm text-muted-foreground`,children:t})]})}function pp({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.edges)?t.edges:[],s=o.findIndex((t,n)=>Tl(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,q.jsx)(Mr,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),children:(0,q.jsx)(Vr,{message:G(`engine.inspector.flowEdge.missing`,i)})});let l=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}n({edges:K(o,s,t)})},u=c.isDefault===!0;return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),footer:(0,q.jsx)(jr,{label:G(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:K(o,s,null)}),r()},disabled:a}),children:[(0,q.jsx)(fp,{label:G(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,q.jsx)(fp,{label:G(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,q.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowEdge.routing`,i)}),(0,q.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,q.jsx)(W,{label:G(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>l({label:e}),placeholder:G(`engine.inspector.flowEdge.labelHint`,i),disabled:a||u}),(0,q.jsx)(W,{label:G(`engine.inspector.flowEdge.condition`,i),value:El(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:G(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(()=>{let e=u?null:sp(`predicate`,c.condition);return e?(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message}):null})(),(0,q.jsx)(Nr,{label:G(`engine.inspector.flowEdge.isDefault`,i),value:u,onCommit:e=>l(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,q.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowEdge.hint`,i)})]})}function mp(e){return e.selection.kind===`edge`?(0,q.jsx)(pp,{...e}):(0,q.jsx)(dp,{...e})}var hp=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function gp(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function _p(e,t){let n=e[t[0].key];if(!Array.isArray(n))return{parent:[],node:null,index:-1};let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r)return{parent:n,node:null,index:t[e].index};if(n=r[t[e].key],!Array.isArray(n))return{parent:[],node:null,index:-1};r=n[t[e].index]??null}return{parent:n,node:r,index:t[t.length-1].index}}function vp(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:K(i,t[0].index,n)};let a=i,o=[];for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}};o.push({arr:a,index:t[e].index,node:n});let r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let s=K(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function yp(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function bp({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=gp(e.id),{node:c,parent:l,index:u}=s?_p(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,q.jsx)(Mr,{kindLabel:G(`engine.inspector.appNav.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.appNav.close`,a),children:(0,q.jsx)(Vr,{message:e.id})});let d=c.label??c.title??c.name??c.path??e.id,f=c.path??c.href??c.route??``,p=e=>{n(vp(t,s,{...c,...e}))};return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:G(`engine.inspector.appNav.close`,a),headerActions:(0,q.jsx)(Lr,{index:u,total:l.length,onMove:e=>{n(yp(t,s,Hr(l,u,e)));let r=s.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),a=s[s.length-1].key,o=r?`${r}.${a}[${e}]`:`${a}[${e}]`;i?.({kind:`nav`,id:o,label:String(d)})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,q.jsx)(jr,{label:G(`engine.inspector.appNav.remove`,a),onClick:()=>{n(vp(t,s,null)),r()},disabled:o}),children:[(0,q.jsx)(W,{label:G(`engine.inspector.appNav.label`,a),value:String(c.label??c.title??c.name??``),onCommit:e=>p({label:e}),disabled:o}),(0,q.jsx)(W,{label:G(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,q.jsx)(Pr,{label:G(`engine.inspector.appNav.kindField`,a),value:c.kind,options:hp.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var xp=[`field`,`label`,`accessorKey`,`header`];function Sp(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function Cp(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function wp(e){return e.field??e.accessorKey??``}function Tp(e){return e.label??e.header??wp(e)}function Ep(e){return Object.keys(e).some(e=>!xp.includes(e))}function Dp(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function Op({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Sp(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(Cp),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=J.useMemo(()=>Ui(),[]),m=Dp(c),{fields:h}=Ei(m||void 0),g=d?wp(d):``,_=J.useMemo(()=>{let e=h.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} · ${e.name}`:e.name}));return g&&!e.some(e=>e.value===g)&&e.unshift({value:g,label:`${g} (not in object)`}),e},[h,g]);if(!s||!d)return(0,q.jsx)(Mr,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),children:(0,q.jsx)(Vr,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=wp(e);return n&&!Ep(e)&&!e.label&&!e.header&&r?r:e});n({[s.variant]:{...c,columns:t}})},y=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),v(K(u,s.index,{...d,...r}))};return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:Tp(d)||e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),headerActions:(0,q.jsx)(Lr,{index:s.index,total:u.length,onMove:e=>{v(Hr(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:Tp(d)||`columns[${e}]`})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,q.jsx)(jr,{label:G(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(K(u,s.index,null)),r()},disabled:o}),children:[c&&(0,q.jsx)(`div`,{className:`pb-1`,children:(0,q.jsx)(Ni,{variantKey:s.variant,schema:c,columns:l,allStrings:l.length>0&&l.every(e=>typeof e==`string`),objectName:m||void 0,selectedIndex:s.index,readOnly:o,onPatch:n,onSelectionChange:i})}),(0,q.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,q.jsx)(Pr,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:wp(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,q.jsx)(W,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:wp(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.viewColumn.header`,a),value:Tp(d)===wp(d)?``:Tp(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,q.jsx)(`div`,{className:`border-t pt-3`,children:(0,q.jsx)(Fr,{schema:p,value:d,hiddenFields:xp,readOnly:o,onChange:e=>{v(K(u,s.index,e))}})}):null]})]})}function kp(e){let{selection:t}=e;if(t.kind===`column`)return(0,q.jsx)(Op,{...e});let n=Qi(e.draft,t.id||void 0)??Zi(e.draft);return(0,q.jsx)(aa,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function Ap(e){let t=Zi(e.draft);return(0,q.jsx)(aa,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var jp=e=>(e??``).toLowerCase().startsWith(`zh`);function Mp(e){let t=e.options;return Array.isArray(t)?t.map(e=>({value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0})):[]}function Np(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Pp(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Fp(e){return e===`formula`||e===`summary`}function Ip(e){return e===`number`||e===`currency`||e===`percent`}function Lp(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Rp(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}function zp(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?Kr:Jr;return qr.flatMap(e=>e.types.map(r=>{let i=Qr[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function Bp({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=J.useCallback(e=>G(e,o),[o]),c=J.useMemo(()=>zp(o),[o]),l=J.useMemo(()=>ci(t.fields),[t]),u=String(e.id),d=ui(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=Kp();if(!f)return(0,q.jsx)(Mr,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,q.jsx)(Vr,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=Qr[g],v=e=>{n({fields:li(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=pi(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},v({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(h.label??t)})},x=()=>{let e=l.entries.filter((e,t)=>t!==d);v({shape:l.shape,entries:e}),r()},S=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof h.label==`string`&&h.label?h.label:``,o={name:n,def:{...h,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),v({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},C=e=>{v({shape:l.shape,entries:Hr(l.entries,d,e)})},w=Mp(h),T=e=>{y({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},E=(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:S,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,q.jsx)(wt,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(Lr,{index:d,total:l.entries.length,onMove:C,disabled:a})]}),D=(0,q.jsx)(jr,{label:U(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:x,disabled:a}),O=jp(o)?_?.labelZh:_?.label;return(0,q.jsxs)(Mr,{kindLabel:s(`designer.field.kind`),title:typeof h.label==`string`&&h.label?h.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:E,footer:D,children:[(0,q.jsxs)(Vp,{title:s(`designer.field.section.basic`),children:[(0,q.jsx)(W,{label:s(`designer.field.apiName`),value:f.name,onCommit:b,disabled:a,mono:!0}),(0,q.jsx)(W,{label:s(`designer.field.label`),value:typeof h.label==`string`?h.label:``,onCommit:e=>y({label:e}),disabled:a}),(0,q.jsx)(Pr,{label:s(`designer.field.type`),value:g,options:c,onCommit:e=>y({type:e}),disabled:a}),(0,q.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,q.jsx)(Nr,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,q.jsx)(Nr,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,q.jsx)(Up,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),Rp(g)&&(0,q.jsx)(Hp,{kind:Rp(g),value:h.defaultValue,options:w,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,q.jsx)(Up,{label:s(`designer.field.helpText`),value:typeof h.inlineHelpText==`string`?h.inlineHelpText:``,onCommit:e=>y({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(Np(g)||Pp(g)||Fp(g)||Ip(g)||Lp(g))&&(0,q.jsxs)(Vp,{title:U(`designer.field.section.options`,o,{type:O??g}),children:[Np(g)&&(0,q.jsx)(Gp,{options:w,onChange:T,disabled:a,locale:o}),Pp(g)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Wp,{label:s(`designer.field.relatedObject`),value:typeof h.reference==`string`?h.reference:``,options:m,onCommit:e=>y({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,q.jsx)(W,{label:s(`designer.field.relationshipName`),value:typeof h.relationshipName==`string`?h.relationshipName:``,onCommit:e=>y({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)})]}),Fp(g)&&(0,q.jsx)(Up,{label:s(`designer.field.formula`),value:typeof h.formula==`string`?h.formula:``,onCommit:e=>y({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),Ip(g)&&(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(Ar,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,q.jsx)(Ar,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,q.jsx)(Ar,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,q.jsx)(Ar,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),Lp(g)&&(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(Ar,{label:s(`designer.field.minLength`),value:typeof h.minLength==`number`?h.minLength:void 0,onCommit:e=>y({minLength:e}),disabled:a,placeholder:`0`}),(0,q.jsx)(Ar,{label:s(`designer.field.maxLength`),value:typeof h.maxLength==`number`?h.maxLength:void 0,onCommit:e=>y({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,q.jsxs)(Vp,{title:s(`designer.field.section.advanced`),children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(Nr,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,q.jsx)(Nr,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,q.jsx)(Nr,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,q.jsx)(Nr,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,q.jsx)(Nr,{label:s(`designer.field.trackHistory`),value:!!h.trackHistory,onCommit:e=>y({trackHistory:e||void 0}),disabled:a})]}),(0,q.jsx)(W,{label:s(`designer.field.placeholder`),value:typeof h.placeholder==`string`?h.placeholder:``,onCommit:e=>y({placeholder:e||void 0}),disabled:a}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(W,{label:s(`designer.field.conditionalRequired`),value:typeof h.conditionalRequired==`string`?h.conditionalRequired:``,onCommit:e=>y({conditionalRequired:e||void 0}),disabled:a,mono:!0,placeholder:`record.status == 'closed'`}),(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRequiredHint`)})]}),p.length>0&&(0,q.jsx)(Pr,{label:s(`designer.field.group`),value:typeof h.group==`string`?h.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>y({group:e||void 0}),disabled:a})]})]})}function Vp({title:e,children:t}){return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,q.jsx)(`div`,{className:`space-y-2`,children:t})]})}function Hp({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=G(`designer.field.defaultValue`,a),s=G(`designer.field.defaultNone`,a);return e===`bool`?(0,q.jsx)(Pr,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:G(`designer.field.true`,a)},{value:`false`,label:G(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,q.jsx)(Ar,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,q.jsx)(Pr,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,q.jsx)(W,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function Up({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(`textarea`,{value:t,disabled:r,rows:i,placeholder:o,onChange:e=>n(e.target.value),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary `+(a?`font-mono text-xs `:``)})]})}function Wp({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=J.useId();return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(B,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,q.jsx)(`datalist`,{id:o,children:n.map(e=>(0,q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Gp({options:e,onChange:t,disabled:n,locale:r}){let i=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},a=n=>t(e.filter((e,t)=>t!==n)),o=(n,r)=>t(Hr(e,n,r));return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:G(`designer.field.picklistValues`,r)}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:e.length})]}),e.length===0?(0,q.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:G(`designer.field.noValues`,r)}):(0,q.jsx)(`div`,{className:`space-y-1`,children:e.map((t,s)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(B,{value:t.value,onChange:e=>i(s,{value:e.target.value}),placeholder:G(`designer.field.optValue`,r),disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,q.jsx)(B,{value:t.label??``,onChange:e=>i(s,{label:e.target.value}),placeholder:G(`designer.field.optLabel`,r),disabled:n,className:`h-7 text-xs flex-1`}),(0,q.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>i(s,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:G(`designer.field.optColor`,r)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o(s,s-1),disabled:n||s===0,"aria-label":G(`designer.field.moveUp`,r),children:(0,q.jsx)(Sn,{className:`h-3 w-3`})}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o(s,s+1),disabled:n||s===e.length-1,"aria-label":G(`designer.field.moveDown`,r),children:(0,q.jsx)(Lt,{className:`h-3 w-3`})}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>a(s),disabled:n,"aria-label":G(`designer.field.removeValue`,r),children:(0,q.jsx)($e,{className:`h-3 w-3`})})]},s))}),!n&&(0,q.jsxs)(z,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,q.jsx)(L,{className:`h-3 w-3`}),G(`designer.field.addValue`,r)]})]})}function Kp(){let e=Tr(),[t,n]=J.useState([]);return J.useEffect(()=>{let t=!1;return e.list(`object`).then(e=>{t||n(e.filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{t=!0}},[e]),t}function qp({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=J.useCallback(e=>G(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=J.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=pi(e)),n(t)},u=e=>{c.current=!0,n({name:pi(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,q.jsx)(Mr,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,q.jsxs)(Jp,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,q.jsx)(Yp,{hint:a(`designer.object.nameHint`),children:(0,q.jsx)(W,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,placeholder:a(`designer.object.namePlaceholder`)})}),(0,q.jsx)(W,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,q.jsx)(W,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,q.jsx)(Yp,{hint:a(`designer.object.iconHint`),children:(0,q.jsx)(W,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,q.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]})})}function Jp({title:e,hint:t,children:n}){return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,q.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,q.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,q.jsx)(`div`,{className:`space-y-2`,children:n})]})}function Yp({hint:e,children:t}){return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var Xp=[{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`},{value:`count_distinct`,label:`count distinct`}],Zp=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}];function Qp({title:e,count:t,onAdd:n,addLabel:r}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,q.jsxs)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,q.jsx)(L,{className:`h-3 w-3`}),` `,r]})]})}function $p({draft:e,onPatch:t,readOnly:n}){let r=typeof e.label==`string`?e.label:``,i=typeof e.description==`string`?e.description:``,a=typeof e.object==`string`?e.object:``,o=Array.isArray(e.include)?e.include:[],s=Array.isArray(e.dimensions)?e.dimensions:[],c=Array.isArray(e.measures)?e.measures:[],l=(e,n)=>t({dimensions:s.map((t,r)=>r===e?{...t,...n}:t)}),u=(e,n)=>t({measures:c.map((t,r)=>r===e?{...t,...n}:t)});return(0,q.jsxs)(Mr,{kindLabel:`Dataset`,title:String(r||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[(0,q.jsx)(W,{label:`Label`,value:r,onCommit:e=>t({label:e}),disabled:n}),(0,q.jsx)(W,{label:`Description`,value:i,onCommit:e=>t({description:e}),disabled:n}),(0,q.jsx)(W,{label:`Base object`,value:a,onCommit:e=>t({object:e}),placeholder:`e.g. opportunity`,disabled:n,mono:!0}),(0,q.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,q.jsx)(Qp,{title:`Included relationships`,count:o.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:Dr(o,``)})}),o.length===0?(0,q.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:[`No joins. Add a relationship name (e.g. `,(0,q.jsx)(`code`,{children:`account`}),`) to use `,(0,q.jsx)(`code`,{children:`account.field`}),` dimensions/measures.`]}):o.map((e,r)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(B,{value:e,onChange:e=>t({include:o.map((t,n)=>n===r?e.target.value:t)}),placeholder:`relationship name (lookup field)`,disabled:n,className:`h-8 text-sm font-mono`}),!n&&(0,q.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:K(o,r,null)}),"aria-label":`Remove relationship`,children:(0,q.jsx)($e,{className:`h-3.5 w-3.5`})})]},r))]}),(0,q.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,q.jsx)(Qp,{title:`Dimensions`,count:s.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:Dr(s,{name:``,field:``,type:`string`})})}),s.map((e,r)=>(0,q.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,q.jsx)(jr,{label:`Remove`,onClick:()=>t({dimensions:K(s,r,null)})})]}),(0,q.jsx)(W,{label:`Name`,value:e.name??``,onCommit:e=>l(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,q.jsx)(W,{label:`Field`,value:e.field??``,onCommit:e=>l(r,{field:e}),placeholder:`field or relationship.field`,disabled:n,mono:!0}),(0,q.jsx)(Pr,{label:`Type`,value:e.type,options:Zp,onCommit:e=>l(r,{type:e}),disabled:n})]},r))]}),(0,q.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,q.jsx)(Qp,{title:`Measures`,count:c.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:Dr(c,{name:``,aggregate:`sum`,field:``,certified:!1})})}),c.map((e,r)=>(0,q.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,q.jsx)(jr,{label:`Remove`,onClick:()=>t({measures:K(c,r,null)})})]}),(0,q.jsx)(W,{label:`Name`,value:e.name??``,onCommit:e=>u(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,q.jsx)(Pr,{label:`Aggregate`,value:e.aggregate,options:Xp,onCommit:e=>u(r,{aggregate:e}),disabled:n}),(0,q.jsx)(W,{label:`Field`,value:e.field??``,onCommit:e=>u(r,{field:e}),placeholder:`field (optional for count)`,disabled:n,mono:!0}),(0,q.jsx)(Nr,{label:`Certified`,value:!!e.certified,onCommit:e=>u(r,{certified:e}),disabled:n})]},r))]})]})}function em(){Ro(`dashboard`,ri),Vo(`dashboard`,ti),Ro(`flow`,mp),Ro(`app`,bp),Ro(`view`,kp),Vo(`view`,Ap),Ro(`page`,cc),Vo(`report`,$r),Ro(`object`,Bp),Vo(`object`,qp),Vo(`dataset`,$p)}var tm=t({MetadataDiagnosticsPage:()=>Os,MetadataDirectoryPage:()=>ua,MetadataResourceEditPage:()=>Ss,MetadataResourceHistoryPage:()=>Oo,MetadataResourceListPage:()=>qa,StudioHomePage:()=>ja});Ns(),Ls(),vf(),em();export{Sa as a,qi as c,Ha as i,si as l,As as n,ua as o,Es as r,aa as s,tm as t};
|