@objectstack/console 9.5.1 → 9.6.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/{AdapterProvider-BrKPQ1rE.js → AdapterProvider-o2n9dY2j.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-BcncanbT.js → AiPendingActionsPage-DGAL-HJ9.js} +1 -1
- package/dist/assets/{ApiConsolePage-C6tVqeCx.js → ApiConsolePage-DNuInlzy.js} +1 -1
- package/dist/assets/{AppDocsIndex-D--pdm0E.js → AppDocsIndex-DtACBq8P.js} +1 -1
- package/dist/assets/{AppManagementPage-B66TgUPL.js → AppManagementPage-BSgP2T9T.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-C8mv1Yo5.js → ApprovalsInboxPage-jrTqrLxX.js} +1 -1
- package/dist/assets/{AuditLogPage-CS-Jundr.js → AuditLogPage-B_gxba-u.js} +1 -1
- package/dist/assets/{ComponentNavView-Br-wa130.js → ComponentNavView-BSV-rPCq.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-B1xDv7X-.js +1 -0
- package/dist/assets/DashboardView-BNUhTJ8Y.js +1 -0
- package/dist/assets/{DashboardWidgetInspector-Cr6cJ0BC.js → DashboardWidgetInspector-CNmycNmj.js} +1 -1
- package/dist/assets/{DeveloperHubPage-B3I-35Xy.js → DeveloperHubPage-YvUkG7Lt.js} +1 -1
- package/dist/assets/{ExpressionProvider-CqfGEBur.js → ExpressionProvider-Cuv0RaiR.js} +1 -1
- package/dist/assets/{FlowRunsPage-CATcsy8B.js → FlowRunsPage-DdjGSDw1.js} +1 -1
- package/dist/assets/{IntegrationsPage-Cq1qq5jk.js → IntegrationsPage-C8k36Ie_.js} +1 -1
- package/dist/assets/{InterfaceListPage-OHu23CRA.js → InterfaceListPage-DTHEyaKG.js} +1 -1
- package/dist/assets/{ManagedByBadge-BodEaDXN.js → ManagedByBadge-B60ZX6y9.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-B5oYOVdC.js → MarketplaceInstalledPage-DJN3P4aw.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-DnmqDFCq.js → MarketplacePackagePage-BUrsYfA7.js} +1 -1
- package/dist/assets/{MarketplacePage-C5lziiq9.js → MarketplacePage-q23E8dYU.js} +1 -1
- package/dist/assets/{MetadataInspector-BMHaVCoM.js → MetadataInspector-zJtxyFau.js} +1 -1
- package/dist/assets/{MetadataProvider-Cvue7gQ0.js → MetadataProvider-BagIop6q.js} +1 -1
- package/dist/assets/PageView-M09zUJqv.js +1 -0
- package/dist/assets/{ProfilePage-BBeI_CPu.js → ProfilePage-0yyBZHjT.js} +1 -1
- package/dist/assets/PublicFormsPage-BPEDFiNo.js +1 -0
- package/dist/assets/{RecentItemsProvider-gLV-GFpQ.js → RecentItemsProvider-B76qldBH.js} +1 -1
- package/dist/assets/RecordDetailView-cj45YVH-.js +1 -0
- package/dist/assets/RecordFormPage-DqFdHPz8.js +1 -0
- package/dist/assets/{ReportDefaultInspector-CmSJUILm.js → ReportDefaultInspector-D5dIioUJ.js} +1 -1
- package/dist/assets/{ReportView-_NBbKT5l.js → ReportView-Cx-qFxJZ.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-DroTFTnx.js → RuntimeDraftBar-Be6SQ4g6.js} +1 -1
- package/dist/assets/{SearchResultsPage-D9HdE2xf.js → SearchResultsPage-DkQMPMlE.js} +1 -1
- package/dist/assets/{SettingsHub-Ca4TQg_Q.js → SettingsHub-el09ZPJP.js} +1 -1
- package/dist/assets/{SettingsView-6GSnMLNA.js → SettingsView-BiYeb1nb.js} +1 -1
- package/dist/assets/{SystemHubPage-maebng1S.js → SystemHubPage-QSk3FL5a.js} +1 -1
- package/dist/assets/{data-adapter-SqbPGFBI.js → data-adapter-BtpuYbBh.js} +1 -1
- package/dist/assets/{framework-CVigpa4L.js → framework-ZJouI0cJ.js} +6 -6
- package/dist/assets/{highlighted-body-OFNGDK62-B0SlzSfX.js → highlighted-body-OFNGDK62-DfdyR_41.js} +1 -1
- package/dist/assets/index-B99f8h8i.js +4 -0
- package/dist/assets/index-BXu9hpEZ.css +2 -0
- package/dist/assets/infrastructure-CJNwTVno.js +3 -0
- package/dist/assets/{marketplaceApi-Cw1CUgrg.js → marketplaceApi-DCvJ2C6u.js} +1 -1
- package/dist/assets/{mergeServerFields-DKhjl-pc.js → mergeServerFields-DPrTk8u4.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-BF-AoOMn.js +1 -0
- package/dist/assets/metadata-admin-DT8BohcC.js +19 -0
- package/dist/assets/{plugin-calendar-BWXBFRkE.js → plugin-calendar-CwYuZf8c.js} +1 -1
- package/dist/assets/plugin-charts-DhlEvpuy.js +7 -0
- package/dist/assets/{plugin-chatbot-CBg5Zd15.js → plugin-chatbot-CJsfoGAD.js} +45 -45
- package/dist/assets/plugin-dashboard-CGRjBe2V.js +5 -0
- package/dist/assets/plugin-form-C5yl9byI.js +1 -0
- package/dist/assets/plugin-gantt-C5hIQDHF.js +23 -0
- package/dist/assets/{plugin-grid-BsA9XQ8Q.js → plugin-grid-2QHjCxCx.js} +4 -4
- package/dist/assets/{plugin-kanban-DTWtfUzv.js → plugin-kanban-LtqKit9T.js} +1 -1
- package/dist/assets/{plugin-map-B-PDDoET.js → plugin-map-Cz9tJHoZ.js} +1 -1
- package/dist/assets/{plugin-markdown--e1MOP0x.js → plugin-markdown-_H-xFg2t.js} +1 -1
- package/dist/assets/{plugin-report-BTvuqkOa.js → plugin-report-DA6bVPuW.js} +2 -2
- package/dist/assets/{plugin-timeline-Dmqt8jd_.js → plugin-timeline-DjngAdR-.js} +1 -1
- package/dist/assets/plugin-view-BUsWmCh-.js +1 -0
- package/dist/assets/plugins-views-yfd0iHKg.js +4 -0
- package/dist/assets/resolveActionParams-ergReBd1.js +9 -0
- package/dist/assets/{skeletons-D42JPA2I.js → skeletons-BRDBm95C.js} +1 -1
- package/dist/assets/{src-B-bY4wJT.js → src-B5JRlZgC.js} +1 -1
- package/dist/assets/{types-HYNWZWMw.js → types-fX7qb4I3.js} +1 -1
- package/dist/assets/ui-components-Bs-DxYrW.js +42 -0
- package/dist/assets/{ui-layout-DM7b0Gu1.js → ui-layout-CswtJjnW.js} +1 -1
- package/dist/assets/{useActionModal-DcFjU7Dq.js → useActionModal-d8GNl1HP.js} +1 -1
- package/dist/assets/{vendor-markdown-DIJxJfmj.js → vendor-markdown-CyAGIM8D.js} +2 -2
- package/dist/assets/vendor-objectstack-BNd856rx.js +96 -0
- package/dist/assets/{vendor-sentry-Cv_7Tgs6.js → vendor-sentry-BIOhD5Kg.js} +14 -14
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ConsoleFloatingChatbot-CIsrrZv4.js +0 -1
- package/dist/assets/DashboardView-HNhMjAZZ.js +0 -1
- package/dist/assets/PageView-H7j3JwJI.js +0 -1
- package/dist/assets/PublicFormsPage-Bhp5KfIY.js +0 -1
- package/dist/assets/RecordDetailView-CGxfnls1.js +0 -1
- package/dist/assets/RecordFormPage-B8sjq5K3.js +0 -1
- package/dist/assets/index-TlmJdKxQ.js +0 -4
- package/dist/assets/index-mrmp6qU6.css +0 -2
- package/dist/assets/infrastructure-ckitl7Ev.js +0 -3
- package/dist/assets/mermaid-GHXKKRXX-DOu_26de.js +0 -1
- package/dist/assets/metadata-admin-2GXysZST.js +0 -19
- package/dist/assets/plugin-charts-Ck5EMx6H.js +0 -7
- package/dist/assets/plugin-dashboard-DJturdHm.js +0 -5
- package/dist/assets/plugin-form-CM6RvRf2.js +0 -1
- package/dist/assets/plugin-gantt-DO7NQ-4h.js +0 -23
- package/dist/assets/plugin-view-CmAdMV7R.js +0 -1
- package/dist/assets/plugins-views-BP1sk9hy.js +0 -4
- package/dist/assets/resolveActionParams-CWIOgcoF.js +0 -9
- package/dist/assets/ui-components-BK0FqwOC.js +0 -42
- package/dist/assets/vendor-objectstack-RB3xvhcR.js +0 -102
|
@@ -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-ZJouI0cJ.js";import{R as h,_ as g,d as _,p as v}from"./vendor-objectstack-BNd856rx.js";import{$ as y,$a as b,$i as x,$n as S,$t as C,Aa as w,Ao as T,Ar as E,Ba as D,Bi as O,Bn as k,Bs as A,Bt as ee,Ca as j,Ci as te,Cr as ne,Cs as M,Da as re,Di as ie,Ea as N,Eo as ae,Fa as oe,Fo as P,Ft as se,Gr as ce,H as le,Ha as ue,Hi as F,Hn as de,Ho as fe,Hs as pe,Ht as me,Ia as he,Io as ge,Ir as _e,It as ve,Ja as ye,Jo as be,Jt as xe,Kn as Se,Ko as Ce,L as we,Ln as Te,Lr as Ee,Ls as De,Lt as Oe,Ma as ke,Mt as Ae,Ni as je,No as Me,Nr as Ne,Ns as Pe,Oo as Fe,Pa as Ie,Pi as Le,Po as Re,Pr as ze,Pt as Be,Qo as Ve,Qr as He,Qs as Ue,R as We,Ra as Ge,Rn as Ke,Ro as qe,Rr as I,Rt as Je,Sa as Ye,Si as Xe,So as Ze,Sr as Qe,Ti as $e,Ua as et,Ui as tt,Uo as nt,Ut as rt,Va as it,Vi as at,Vn as ot,Vr as st,Vs as ct,Vt as lt,Wi as ut,Wo as dt,Wr as ft,Ws as pt,Wt as mt,Xo as ht,Xr as gt,Ya as _t,Yi as vt,Yo as yt,Ys as bt,Yt as xt,Za as St,Zi as Ct,Zo as wt,Zs as Tt,_a as Et,_i as Dt,_o as Ot,_r as kt,_s as At,ao as jt,as as Mt,at as Nt,ba as Pt,bi as Ft,bo as It,br as Lt,bs as Rt,cc as L,co as zt,ct as Bt,di as Vt,do as Ht,dt as Ut,ea as Wt,en as Gt,eo as Kt,et as qt,fi as Jt,fo as Yt,fs as Xt,ft as Zt,gi as Qt,hi as $t,ho as en,hr as R,hs as tn,ic as nn,ii as rn,it as an,ja as z,ji as on,jo as sn,js as cn,ki as ln,kr as un,la as dn,lc as B,li as fn,lo as pn,ls as mn,lt as hn,ma as gn,mi as _n,ms as vn,na as yn,ni as bn,nn as V,ns as xn,nt as Sn,oa as Cn,oc as wn,on as H,oo as Tn,os as En,ot as Dn,pa as On,pi as kn,po as An,ps as jn,qa as Mn,qi as Nn,qt as Pn,ra as Fn,rc as In,ro as Ln,rt as Rn,sa as zn,sc as Bn,si as Vn,so as Hn,st as Un,ta as Wn,tc as Gn,ti as Kn,tn as qn,to as Jn,ua as Yn,ut as Xn,va as Zn,vo as Qn,vr as $n,vs as er,wa as tr,wi as nr,wo as rr,wr as ir,ws as ar,xa as or,xi as sr,xo as cr,xr as lr,xs as ur,ya as dr,yi as fr,yr as pr,z as mr,zn as hr,zo as gr,zs as _r,zt as vr}from"./ui-components-Bs-DxYrW.js";import{r as yr}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-o2n9dY2j.js";import{o as br,r as xr}from"./MetadataProvider-BagIop6q.js";import{n as Sr}from"./RecentItemsProvider-B76qldBH.js";import{C as Cr,S as wr,_ as Tr,a as U,b as Er,c as Dr,d as Or,f as kr,g as W,h as Ar,i as G,l as jr,m as Mr,n as Nr,o as Pr,p as Fr,r as Ir,s as Lr,t as Rr,u as zr,v as Br,w as Vr,x as Hr,y as K}from"./mergeServerFields-DPrTk8u4.js";import{t as Ur}from"./InterfaceListPage-DTHEyaKG.js";import{a as Wr,c as Gr,i as Kr,n as qr,o as Jr,r as Yr,s as Xr,t as Zr}from"./ReportDefaultInspector-D5dIioUJ.js";import{i as Qr,n as $r,r as ei,t as ti}from"./DashboardWidgetInspector-CNmycNmj.js";var q=l(),J=e(n(),1);function ni(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 ri=new Set(qt),ii=new Map;function ai(e){if(!e)return nt;let t=ii.get(e);if(t)return t;let n=ni(e);if(!ri.has(n))return ii.set(e,nt),nt;let r=e=>J.createElement(y,{name:n,fallback:nt,...e});return r.displayName=`LucideIcon(${e})`,ii.set(e,r),r}function oi(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 si(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 ci(e,t){return e.entries.findIndex(e=>e.name===t)}function li(e,t,n){let r={type:t,label:n??ui(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function ui(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function di(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 fi(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 pi(e,t){let n=/[a-z0-9]/i.test(e)?di(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function mi(e,t){let n=t.trim()||`New section`,r=pi(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function hi(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function gi(e,t){return e.filter(e=>e.key!==t)}function _i(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:yi(e,r,i)}function vi(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 yi(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function bi(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 xi(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function Si(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)xi(e[i],t[i])||r.push(i);return r.sort()}function Ci(e,t){let n=oi(e),r=oi(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=Si(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 wi(e,t){let n=Cr(),[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:oi(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 Ti(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 Ei(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 Di(e){let t=new Set;for(let n of e){let e=Ei(n);e&&t.add(e)}return t}function Oi(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function ki(e,t){return e===t?null:e>t?e-1:e}function Ai(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function ji({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}=wi(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]),b=J.useCallback(t=>{let i=Tr(n,Oi(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),x=J.useCallback(t=>{let r=K(n,t,null);if(y(r),o!=null){let n=ki(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Ti(r[n],n)})}},[n,y,o,e,l]),C=J.useCallback((t,r)=>{if(t===r)return;let i=Br(n,t,r);if(y(i),o!=null){let n=Ai(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Ti(i[n],n)})}},[n,y,o,e,l]),w=J.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Ti(n[t],t)})},[n,e,l]),T=Di(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)(H,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,q.jsx)(S,{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)(Yr,{index:t,label:Ti(e,t),fieldName:Ei(e),fieldType:m.get(Ei(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>w(t),onRemove:()=>x(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)(qr,{fields:d,usedNames:T,loading:f,error:p,onAdd:b})]})}var Mi={io:`input`,unrepresentable:`any`},Ni=new Set([`columns`,`data`,`name`]),Pi,Fi=!1;function Ii(){if(Pi||Fi)return Pi;try{Pi=h(v,Mi)}catch(e){Fi=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return Pi}function Li(){return Ii()?.properties?.list}function Ri(){return Ii()?.properties?.form}var zi,Bi=!1;function Vi(){if(zi||Bi)return zi;try{zi=h(_,Mi)}catch(e){Bi=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return zi}var Hi;function Ui(){if(Hi)return Hi;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!Ni.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Hi=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Hi}}var Wi=new Set([`form`,`detail`]);function Gi(e){return Wi.has(e)}function Ki(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function qi(e,t){return typeof e==`string`&&Wi.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Wi.has(t)?`form`:`list`}function Ji(e){let t=e.config;return Ki(t)?[{storeKey:`config`,familyKey:qi(e.viewKind,t.type),schema:t}]:[]}function Yi(e){return Ji(e)[0]}function Xi(e,t){return Yi(e)}var Zi=new Set([`type`,`object`,`label`,`columns`]),Qi={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function $i(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?Qi[e]??e:r}var ea=[`columns`,`data`,`name`];function ta(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 na(e,t){return J.useMemo(()=>{let n=Li()?.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:$i(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:$i(e,t)}),r},[e,t])}function ra({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=Gi(n??t),p=typeof d.type==`string`?d.type:`grid`,m=na(p,l),h=ta(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}=wi(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(()=>Rr({bundledSchema:f?Ri():Li(),bundledForm:f?void 0:Ui(),serverSchema:x,excludeFields:Zi,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,q.jsxs)(Ar,{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)(Mr,{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)(ji,{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)(Nr,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of ea)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 ia({appSlug:e}={}){let t=u(),n=Cr(),{entries:r}=Vr(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(()=>Ir(),[]);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)||Lr(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)(Te,{open:i,onOpenChange:a,children:(0,q.jsxs)(Ke,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,q.jsx)(ot,{className:`sr-only`,children:(0,q.jsx)(de,{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)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(V,{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)(we,{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)(z,{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)(S,{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:Lr(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)(w,{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)(we,{children:`↑`}),` `,(0,q.jsx)(we,{children:`↓`}),` navigate`]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(we,{children:`↵`}),` open`]}),(0,q.jsxs)(`span`,{className:`ml-auto`,children:[(0,q.jsx)(we,{children:`⌘`}),(0,q.jsx)(we,{children:`⇧`}),(0,q.jsx)(we,{children:`M`}),` toggle`]})]})]})})}var aa={data:nt,ui:D,automation:ir,ai:fn,system:Ft,platform:Ft,identity:Qt,security:Qt},oa=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],sa=new Set([`field`,`package`]);function ca(){let e=Cr(),{loading:t,error:n,entries:r}=Vr(e),i=J.useMemo(()=>Ir(),[]),[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}=wr(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>sa.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)||Lr(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=oa.indexOf(e),r=oa.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)(Xe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(V,{className:`pl-8`,placeholder:G(`engine.directory.search`,i),value:a,onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(R,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,i),` (`,O,`)`]}),x.total>0&&(0,q.jsx)(R,{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)(we,{children:`⌘`}),(0,q.jsx)(we,{children:`⇧`}),(0,q.jsx)(we,{children:`M`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,q.jsx)(la,{domain:`all`,label:G(`engine.directory.all`,i),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),oa.filter(e=>D[e]).map(e=>(0,q.jsx)(la,{domain:e,label:Pr(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)(We,{children:[(0,q.jsx)(le,{children:`No project packages installed`}),(0,q.jsx)(mr,{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)(We,{children:[(0,q.jsx)(le,{children:G(`engine.directory.noMatches`,i)}),(0,q.jsx)(mr,{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)(aa[e]??ct,{className:`h-3.5 w-3.5`}),Pr(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)(ua,{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)(ia,{})]})}function la({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 ua({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=Lr(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)(S,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:U(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,q.jsx)(S,{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)(S,{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)(S,{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)(w,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,q.jsx)(S,{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)(S,{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)(S,{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 da=`/api/v1/packages`;async function fa(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 pa({scope:e}){let t=J.useMemo(()=>Ir(),[]),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)(S,{variant:r,children:i?G(i,t):n})}function ma({pkg:e}){let t=J.useMemo(()=>Ir(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,q.jsx)(S,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var ha=/^[a-z0-9][a-z0-9._-]{1,254}$/i,ga=/^\d+\.\d+\.\d+$/;function _a({open:e,onOpenChange:t,onCreated:n}){let r=J.useMemo(()=>Ir(),[]),[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=ha.test(i),h=ga.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await fa(da,{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)(Te,{open:e,onOpenChange:t,children:(0,q.jsxs)(Ke,{children:[(0,q.jsxs)(ot,{children:[(0,q.jsx)(de,{children:G(`engine.packages.create.title`,r)}),(0,q.jsx)(hr,{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)(H,{htmlFor:`pkg-id`,children:G(`engine.packages.create.id`,r)}),(0,q.jsx)(V,{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)(H,{htmlFor:`pkg-name`,children:G(`engine.packages.create.name`,r)}),(0,q.jsx)(V,{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)(H,{htmlFor:`pkg-version`,children:G(`engine.packages.create.version`,r)}),(0,q.jsx)(V,{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)(k,{children:[(0,q.jsx)(R,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:G(`engine.cancel`,r)}),(0,q.jsx)(R,{onClick:_,disabled:!g,children:G(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function va({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 ya({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=J.useMemo(()=>Ir(),[]),[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 fa(`/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)(Be,{open:n,onOpenChange:r,children:(0,q.jsxs)(se,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,q.jsxs)(Oe,{children:[(0,q.jsxs)(Je,{className:`flex items-center gap-2`,children:[(0,q.jsx)(dn,{className:`h-4 w-4`}),e.manifest.name||p]}),(0,q.jsx)(ve,{className:`font-mono text-xs`,children:p})]}),(0,q.jsxs)(`div`,{className:`mt-4`,children:[(0,q.jsx)(va,{label:G(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,q.jsx)(va,{label:G(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,q.jsx)(va,{label:G(`engine.packages.col.scope`,a),children:(0,q.jsx)(pa,{scope:e.manifest.scope})}),(0,q.jsx)(va,{label:G(`engine.packages.col.status`,a),children:(0,q.jsx)(ma,{pkg:e})}),e.manifest.description&&(0,q.jsx)(va,{label:G(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,q.jsx)(vr,{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)(P,{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)(vr,{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)(S,{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)(R,{size:`sm`,onClick:()=>g(`publish-drafts`,()=>fa(`${da}/${encodeURIComponent(p)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await fa(`/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)(ze,{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)(R,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>fa(`${da}/${encodeURIComponent(p)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await fa(`/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)(_e,{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)(cr,{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)(vr,{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)(R,{size:`sm`,onClick:()=>g(`publish`,()=>fa(`${da}/${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)(ze,{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)(R,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>fa(`${da}/${encodeURIComponent(p)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,q.jsx)(_e,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,a)]}),(0,q.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>fa(`${da}/${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)(at,{className:`mr-1.5 h-3.5 w-3.5`}):(0,q.jsx)(O,{className:`mr-1.5 h-3.5 w-3.5`}),G(m?`engine.packages.detail.disable`:`engine.packages.detail.enable`,a)]}),(0,q.jsxs)(R,{size:`sm`,variant:`outline`,onClick:()=>g(`export`,async()=>{let e=await fa(`${da}/${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)(gr,{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)(R,{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 fa(`${da}/${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)(st,{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 ba(){let e=J.useMemo(()=>Ir(),[]),{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 fa(da),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 fa(`/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)(dn,{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)(R,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,q.jsx)(Le,{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)(R,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,q.jsx)(cr,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,q.jsxs)(R,{size:`sm`,onClick:()=>h(!0),children:[(0,q.jsx)(F,{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)(Xe,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,q.jsx)(V,{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)(Zt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,q.jsx)(H,{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)(Ae,{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)(We,{children:[(0,q.jsx)(le,{children:G(`engine.packages.empty`,e)}),(0,q.jsx)(mr,{children:r.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,q.jsxs)(Dn,{children:[(0,q.jsx)(Xn,{children:(0,q.jsxs)(Ut,{children:[(0,q.jsx)(hn,{children:G(`engine.packages.col.name`,e)}),(0,q.jsx)(hn,{children:`ID`}),(0,q.jsx)(hn,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,q.jsx)(hn,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,q.jsx)(hn,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,q.jsx)(Un,{children:E.map(e=>(0,q.jsxs)(Ut,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,q.jsx)(Bt,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,q.jsx)(Bt,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,q.jsx)(Bt,{children:e.manifest.version||`—`}),(0,q.jsx)(Bt,{children:(0,q.jsx)(pa,{scope:e.manifest.scope})}),(0,q.jsx)(Bt,{children:(0,q.jsx)(ma,{pkg:e})})]},e.manifest.id))})]})}),(0,q.jsx)(_a,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,q.jsx)(ya,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var xa=new Set([`field`,`package`]),Sa={data:nt,ui:D,automation:ir,ai:fn,system:Ft,platform:Ft,identity:Qt,security:Qt},Ca={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`}},wa=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Ta=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Ea={object:He,dashboard:it,page:Ze,report:cn,record:ct,metadata:D};function Da(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function Oa(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 ka(){let e=Cr(),{loading:t,entries:n}=Vr(e),{recentItems:r}=Sr(),i=J.useMemo(()=>Ir(),[]),[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}=wr(e,`warning`,f??void 0),b=J.useMemo(()=>n.filter(e=>xa.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])=>(wa.indexOf(e)===-1?99:wa.indexOf(e))-(wa.indexOf(t)===-1?99:wa.indexOf(t)))},[b,_]),C=J.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return Ta.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)(fn,{className:`h-4 w-4`}),G(Da(),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)(R,{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)(D,{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)(Xe,{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)(Aa,{value:b.length,label:G(`engine.home.statTypes`,i)}),(0,q.jsx)(Aa,{value:x.length,label:G(`engine.home.statWritable`,i)}),(0,q.jsx)(Aa,{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)(ja,{icon:D,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,i),to_link:m}),(0,q.jsx)(ja,{icon:tn,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,i),to_link:m}),(0,q.jsx)(ja,{icon:dn,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)(tn,{className:`h-5 w-5`}):(0,q.jsx)(I,{className:`h-5 w-5`})}),(0,q.jsx)(Gn,{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)(Ma,{icon:F,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)(R,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-dashed hover:border-solid hover:border-primary hover:bg-primary/5`,children:(0,q.jsxs)(c,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,q.jsx)(F,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),U(`engine.home.newItem`,i,{label:Lr(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)(Ma,{icon:D,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)(Na,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:p},e))})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Ma,{icon:xn,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=Ea[e.type]??ct;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:Oa(e.visitedAt,i)})]}),(0,q.jsx)(Gn,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,q.jsx)(ia,{})]})}function Aa({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 ja({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)(Gn,{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 Ma({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 Na({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=Sa[e]??ct,o=Ca[e]??Ca.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:Pr(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:Lr(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 Pa({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:o}){let s=e?.type??``,l=J.useMemo(()=>Ir(),[]),u=Lr(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)(ur,{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)(ur,{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)(S,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Pr(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(S,{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)(S,{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)(S,{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)(ur,{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)(S,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Pr(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(S,{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)(S,{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)(S,{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 Fa={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function Ia(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 La({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`){yr.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=Ia(e.target??``,s,i);if(!c){yr.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();yr.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;yr.success(c),e.refreshAfter&&r?.()}catch(e){yr.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,q.jsx)(q.Fragment,{children:s.map(e=>{let t=e.icon?ai(e.icon):null,n=i===e.name;return(0,q.jsxs)(R,{size:`sm`,variant:Fa[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,q.jsx)(z,{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 Ra(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 za=new Map;function Ba(e){let t=za.get(e.type);if(!t){za.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);za.set(e.type,n)}function Va(e){return za.get(e)}function Ha(e){let t=[];for(let n of za.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 Ua(e,t){let n=za.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 Wa(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 Ga({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=Va(n);if(a?.ListPage){let e=a.ListPage;return(0,q.jsx)(e,{type:n})}return(0,q.jsx)(Ka,{type:n})}function Ka({type:e}){let t=u(),n=Cr(),{entries:r}=Vr(n),i=r.find(t=>t.type===e),a=Ua(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,b]=s(),[x,C]=J.useState(0),[T,E]=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)),E(i.map(e=>({id:e.id,name:e.name})))}catch{e||E([])}})(),()=>{e=!0}},[n]);let D=y.get(`package`),O=J.useMemo(()=>T?D&&T.some(e=>e.id===D)?D:T[0]?.id??null:null,[T,D]);J.useEffect(()=>{if(!T||T.length===0||D&&T.some(e=>e.id===D))return;let e=new URLSearchParams(y);e.set(`package`,T[0].id),b(e,{replace:!0})},[T,D]);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:Wa(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,x]);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]),te=j.filter(e=>!(!Hr(e.item,h,A)||_!==`all`&&e.source!==_)),ne=J.useMemo(()=>{let e={all:j.length,artifact:0,runtime:0};for(let t of j)e[t.source]++;return e},[j]),M=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]),ie=a.listColumns??qa(a.primaryKey??`name`),N=Ir(),ae=Lr(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)(Pa,{entry:i??{type:e,label:e},stats:[{label:G(`engine.list.items`,N),value:j.length},{label:G(`engine.list.filtered`,N),value:te.length},...M>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`}),M]})}]:[],...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)(La,{entry:i,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,N),children:(0,q.jsx)(Le,{className:`h-4 w-4`})}),(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsxs)(R,{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)(F,{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)(Xe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(V,{className:`pl-8`,placeholder:G(`engine.list.search`,N),value:h,onChange:e=>g(e.target.value)})]}),(0,q.jsxs)(ee,{value:_,onValueChange:v,children:[(0,q.jsx)(rt,{className:`w-[180px]`,children:(0,q.jsx)(mt,{})}),(0,q.jsxs)(lt,{children:[(0,q.jsxs)(me,{value:`all`,children:[G(`engine.list.allSources`,N),` (`,ne.all,`)`]}),(0,q.jsxs)(me,{value:`artifact`,children:[G(`engine.list.source.artifact`,N),` (`,ne.artifact,`)`]}),(0,q.jsxs)(me,{value:`runtime`,children:[G(`engine.list.source.runtime`,N),` (`,ne.runtime,`)`]})]})]})]}),(d||T===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&&T!==null&&T.length===0&&(0,q.jsxs)(We,{children:[(0,q.jsx)(le,{children:`No project packages installed`}),(0,q.jsx)(mr,{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&&T!==null&&T.length>0&&te.length===0&&(0,q.jsxs)(We,{children:[(0,q.jsx)(le,{children:j.length===0?U(`engine.list.emptyType`,N,{type:ae}):U(`engine.list.emptyQuery`,N,{query:h})}),(0,q.jsx)(mr,{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)(R,{onClick:()=>t(`./new${k}`),children:[(0,q.jsx)(F,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,N)]})})]}),!d&&te.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:[ie.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:te.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:[ie.map((t,n)=>{let i=e.item[t.key],a=t.render?t.render(i,e.item):Ja(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)(w,{className:`h-3 w-3`})}),(0,q.jsx)(S,{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 qa(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Ja(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 Ya={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 Xa(e,t){let n=Za(e)?e:{},r=Za(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`:Qa(o)===Qa(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 Za(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qa(e){try{return JSON.stringify(e,(e,t)=>Za(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function $a(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 eo(e,t){if(e==null)return 0;let n=0;for(let r of Xa(e,t))r.status!==`unchanged`&&(n+=1);return n}function to({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)(Sn,{defaultValue:`diff`,className:`w-full`,children:[(0,q.jsxs)(an,{className:`grid grid-cols-4 w-fit`,children:[(0,q.jsx)(Nt,{value:`diff`,children:G(`engine.layers.diff`,n)}),(0,q.jsxs)(Nt,{value:`code`,children:[G(`engine.layers.code`,n),(0,q.jsx)(S,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,q.jsxs)(Nt,{value:`overlay`,children:[G(`engine.layers.overlay`,n),r?(0,q.jsx)(S,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,q.jsx)(S,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,q.jsxs)(Nt,{value:`effective`,children:[G(`engine.layers.effective`,n),(0,q.jsx)(S,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,q.jsx)(Rn,{value:`diff`,className:`mt-3`,children:(0,q.jsx)(no,{code:e.code,effective:e.effective,locale:n})}),(0,q.jsx)(Rn,{value:`code`,className:`mt-3`,children:(0,q.jsx)(io,{payload:e.code,emptyHint:G(`engine.layers.diff.noBaseline`,n)})}),(0,q.jsx)(Rn,{value:`overlay`,className:`mt-3`,children:(0,q.jsx)(io,{payload:e.overlay,emptyHint:G(`engine.layers.diff.noChanges`,n)})}),(0,q.jsx)(Rn,{value:`effective`,className:`mt-3`,children:(0,q.jsx)(io,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function no({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(()=>Xa(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)(Zt,{checked:r,onCheckedChange:i,"aria-label":G(`engine.layers.diff.showUnchanged`,n)}),G(`engine.layers.diff.showUnchanged`,n),(0,q.jsx)(S,{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=Ya[e.status];return(0,q.jsxs)(`div`,{className:B(`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)(ro,{value:e.codeValue,muted:e.status===`added`}),(0,q.jsx)(ro,{value:e.effectiveValue,muted:e.status===`removed`}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:(0,q.jsx)(`span`,{className:B(`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 ro({value:e,muted:t}){let n=$a(e);return(0,q.jsx)(`div`,{className:B(`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 io({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 ao={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`},oo={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 so(e,t){return G(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function co(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 lo(e,t){let n=0;for(let r of Xa(e,t))r.status!==`unchanged`&&(n+=1);return n}function uo({published:e,draft:t,locale:n,className:r}){let i=J.useMemo(()=>Xa(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 ${oo[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 ${ao[t]}`,children:so(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:co(e.effectiveValue)}):t===`removed`?(0,q.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:co(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:co(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:co(e.effectiveValue)})]})]},e.key)})})}function fo(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 po(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 mo(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function ho(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function go(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return fo(n);case`plural-en`:return po(n);case`titlecase`:return mo(n);case`first-token`:return ho(n);default:return n}}function _o(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=go(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 vo(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 yo({type:e,name:t,parentItem:n,onOpen:r}){let i=Cr(),a=u(),o=J.useMemo(()=>Ha(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(bo)}}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=>bo(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)(We,{children:[(0,q.jsx)(le,{children:`No related metadata`}),(0,q.jsxs)(mr,{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)(Xe,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,q.jsx)(V,{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)(ur,{className:B(`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)(S,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,q.jsx)(R,{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)(F,{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)(z,{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)(P,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function bo(e){return{name:xo(e,[`name`,`id`,`key`])??`(unnamed)`,label:xo(e,[`label`,`title`,`displayName`]),description:xo(e,[`description`,`summary`]),raw:e}}function xo(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function So({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=J.useMemo(()=>Ir(),[]),c=Cr(),{entries:l}=Vr(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?wo[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=Co(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:Dr(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)(Nr,{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)(R,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(z,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)($e,{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)(R,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(z,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)($e,{className:`h-4 w-4 mr-1`}),U(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function Co(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 wo={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 To({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)(Be,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(se,{side:`right`,className:B(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,q.jsxs)(Oe,{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)(S,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,q.jsx)(Je,{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)(R,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,q.jsx)(P,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,q.jsxs)(ve,{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)(bs,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,q.jsx)(So,{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 Eo({type:e,name:t}){let n=i(),r=e??n.type??``,a=t??n.name??``,o=u(),s=Cr(),{entries:c}=Vr(s),l=c.find(e=>e.type===r),[d,f]=J.useState(0),[p,m]=J.useState(0);return(0,q.jsx)(Pa,{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)(R,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,q.jsx)(In,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+1),children:(0,q.jsx)(Le,{className:`h-4 w-4`})})]}),children:(0,q.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,q.jsx)(Do,{type:r,name:a,refreshKey:d,onCount:m,client:s,onRollback:()=>f(e=>e+1)})})})}function Do({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 b(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)(z,{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)(We,{children:[(0,q.jsx)(le,{children:`No history yet`}),(0,q.jsx)(mr,{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)(S,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,q.jsxs)(S,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,q.jsx)(S,{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:Oo(i)}),o&&(0,q.jsx)(R,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),b(e.version)},children:g===e.version?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ln,{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:ko(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Oo(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function ko(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Ao(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function jo(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:Qt},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:$t},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:Dt}},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 Mo({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)(R,{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)(z,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(Le,{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)(z,{className:`mr-2 h-3 w-3 animate-spin`}),G(`engine.edit.loading`,r)]}):!c||c.length===0?(0,q.jsxs)(We,{className:`py-10`,children:[(0,q.jsx)(le,{children:G(`engine.edit.auditEmptyTitle`,r)}),(0,q.jsx)(mr,{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:Ao(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)(S,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:jo(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 No=new Map;function Y(e,t){No.set(e,t)}function Po(e){return No.get(e)}var Fo=new Map;function Io(e,t){Fo.set(e,t)}function Lo(e){return Fo.get(e)}var Ro=new Map;function zo(e,t){Ro.set(e,t)}function Bo(e){return Ro.get(e)}function Vo(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&&Wo(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Wo(e.charCodeAt(r)))for(r++;r<e.length&&Wo(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&&Wo(e.charCodeAt(r))){for(r++;r<e.length&&Wo(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(Uo(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(Ho(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Ho(t));return o=15}if(Uo(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&&!Uo(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++,Uo(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||!Wo(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(Ho(e)||Uo(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 Ho(e){return e===32||e===9}function Uo(e){return e===10||e===13}function Wo(e){return e>=48&&e<=57}var Go;(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`})(Go||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var Ko=200;Array(Ko).fill(0).map((e,t)=>`
|
|
7
|
+
`+` `.repeat(t)),Array(Ko).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Ko).fill(0).map((e,t)=>`\r
|
|
8
|
+
`+` `.repeat(t)),Array(Ko).fill(0).map((e,t)=>`
|
|
9
|
+
`+` `.repeat(t)),Array(Ko).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Ko).fill(0).map((e,t)=>`\r
|
|
10
|
+
`+` `.repeat(t));var qo;(function(e){e.DEFAULT={allowTrailingComma:!1}})(qo||={});function Jo(e,t=[],n=qo.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}Xo(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:Zo(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 Yo(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 Xo(e,t,n=qo.DEFAULT){let r=Vo(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 Zo(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 Qo;(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`})(Qo||={});var $o;(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`})($o||={});var es=Jo,ts=Yo,ns;(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`})(ns||={});var rs=J.lazy(async()=>({default:(await o(()=>import(`./dist-DYcwLEm6.js`),[],import.meta.url)).default}));function is(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function as(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function os({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let a=J.useMemo(()=>Ir(),[]),[o,s]=J.useState(()=>is(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=es(o)}catch{i=void 0}let a=r.map(e=>{let r=as(e.path),a=1,o=1,s=1,c=2,l=i?ts(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=is(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)(Ae,{className:`w-full h-full`}),children:(0,q.jsx)(rs,{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 ss={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},cs=new Set([`approval`,`connector_action`]),ls=/^nodes\.(\d+)\.type$/;function us(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 ds=new Map;async function fs(e){if(ds.has(e))return ds.get(e)??null;let t=ss[e];if(!t)return ds.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return ds.set(e,r),r}catch{return ds.set(e,null),null}}function ps(e){return e in ss}async function ms(e,t,n){let r=await fs(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=ls.exec(n);if(!r)return!0;let i=us(t,Number(r[1]));return!(i&&cs.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 hs=xt,gs=new Set([`object`]),_s={object:[`fields`,`fieldGroups`]};function vs(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 ys(e){return e.loadFailed?!1:e.hasDiag||e.hasClientValidator}function bs({type:e,name:t,createMode:n=!1,embedded:r=!1}){let a=i(),o=e??a.type??``,s=t??a.name??``,c=Va(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)(xs,{type:o,name:s,createMode:n,embedded:r})}function xs({type:e,name:t,createMode:n,embedded:r}){let i=u(),[a,o]=s(),c=a.get(`package`)??void 0,l=Cr(),{entries:d}=Vr(l),f=d.find(t=>t.type===e),p=Ua(e,f),m=(n&&p.createSchema?p.createSchema:f?.schema)??p.defaultSchema,h=J.useMemo(()=>Ir(),[]),[g,_]=J.useState(null),v=p.identityField??`name`,[y,x]=J.useState(()=>n?{...p.createDefaults??{},[v]:``}:{}),[C,E]=J.useState(null),[O,ee]=J.useState(!n),[j,te]=J.useState(!1),[ne,M]=J.useState(null),[re,ie]=J.useState(!1),[N,ae]=J.useState([]),P=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&&ae(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[ce,le]=J.useState(null),[ue,F]=J.useState(null),fe=J.useCallback(e=>{P(t=>({...t,...e}))},[P]),{markTouched:pe}=_o({rules:p.createDerive,draft:y,onPatch:fe,enabled:!!n}),me=J.useMemo(()=>{if(n)return p.createFields&&p.createFields.length>0?p.createFields:vo(m?.properties??void 0,m?.required??void 0)},[n,p.createFields,m]),he=J.useMemo(()=>{let t=_s[e]??[];if(!n||!me)return t.length===0?p.hiddenFields:Array.from(new Set([...p.hiddenFields??[],...t]));let r=m?.properties??{},i=new Set(me),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,me,m,p.hiddenFields,e]),ge=J.useMemo(()=>n&&me?me:p.fieldOrder,[n,me,p.fieldOrder]),ye=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])||pe(e)}P(e)},[n,y,P,pe]);J.useEffect(()=>{if(!ps(e))return;let t=!1,n=window.setTimeout(()=>{ms(e,y,f?.schema).then(e=>{t||ae(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,y,f?.schema]);let[be,Se]=J.useState(!1),[Ce,we]=J.useState(!1),[Ee,De]=J.useState(0),[ke,Ae]=J.useState(!!n),[je,Ne]=J.useState(null);J.useEffect(()=>{Ne(null)},[e,t]),J.useEffect(()=>{ke||Ne(null)},[ke]);let Pe=J.useRef(null),[Fe,Ie]=J.useState(null),[Le,Re]=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`,Le?`1`:`0`)}catch{}},[Le]);let ze=J.useRef(null),[Ve,He]=J.useState([]),[Ue,We]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await l.list(`object`);if(e)return;He(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||He([])}finally{e||We(!1)}})(),()=>{e=!0}},[l]);let Ge=y?.interfaceConfig?.source||y?.object||y?.objectName,[qe,Ye]=J.useState([]),[Xe,Ze]=J.useState(!1);J.useEffect(()=>{let e=!1;if(!Ge){Ye([]);return}return Ze(!0),(async()=>{try{let t=await l.get(`object`,Ge);if(e)return;let n=t?.fields;Ye((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||Ye([])}finally{e||Ze(!1)}})(),()=>{e=!0}},[l,Ge]);let[et,tt]=J.useState([]),[nt,rt]=J.useState(!1);J.useEffect(()=>{let e=!1;if(!Ge){tt([]);return}return rt(!0),(async()=>{try{let t=await l.list(`view`);if(e)return;let n=(t||[]).filter(e=>(e?.objectName??e?.object??e?.object_name)===Ge),r=new Set;tt(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||tt([])}finally{e||rt(!1)}})(),()=>{e=!0}},[l,Ge]);let it=J.useMemo(()=>({objectNames:Ve,objectsLoading:Ue,objectFields:qe,objectFieldsLoading:Xe,objectViews:et,objectViewsLoading:nt}),[Ve,Ue,qe,Xe,et,nt]);J.useEffect(()=>{if(n){ee(!1);return}let r=!1;return ee(!0),M(null),ie(!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)?ae(o.errors.map(e=>({path:e.path||``,message:e.message}))):ae([]);let s=vs(a),u=i.effective??i.code??{},d=s?{...u,...s}:u,f=p.toDraft?p.toDraft(d):d;x(f),Pe.current=f,Se(!!s),ee(!1)}catch(n){r||(ie(!0),M(U(`engine.edit.loadFailed`,h,{type:e,name:t??``,message:n?.message??String(n)})),ee(!1))}})(),()=>{r=!0}},[l,e,t,c,n,Ee,h]);let[at,ct]=J.useState(!1);async function lt(){if(!(C!=null||at)){ct(!0);try{E(await l.references(e,t))}catch(e){E([]),console.error(`references() failed`,e)}finally{ct(!1)}}}let[ut,dt]=J.useState(null),ft=J.useMemo(()=>!n&&!r&&Ha(e).length>0,[e,n,r]),pt=J.useRef(null),[mt,ht]=J.useState(null),gt=a.get(`review`),_t=J.useRef(!1);J.useEffect(()=>{if(!(gt!==`1`||n)){if(!_t.current){_t.current=!0,De(e=>e+1);return}if(!O){be&&ht(`review`);let e=new URLSearchParams(a);e.delete(`review`),o(e,{replace:!0}),_t.current=!1}}},[gt,n,O,be]);let[yt,bt]=J.useState(`properties`);J.useEffect(()=>{if(mt===`references`&<(),typeof window<`u`&&!r){let e=new URL(window.location.href);mt?e.searchParams.set(`tab`,mt):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[mt,r]);let xt=`metadata-edit:inspector-collapsed`,St=`metadata-edit:inspector-size`,[Ct,wt]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(xt)===`1`),Tt=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(St));Number.isFinite(e)&&e>=22&&e<=80&&(Tt.current=e)},[]);let Et=J.useRef(null),Dt=J.useCallback(()=>{wt(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(xt,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=Et.current;if(e)if(Ct)e.resize?.(`0%`);else{let t=Tt.current||38;e.resize?.(`${t}%`)}},[Ct]);let[Ot,kt]=J.useState(!1),[At,jt]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!At)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[At]),J.useEffect(()=>{if(typeof window>`u`||!At)return;function e(e){e.key===`Escape`&&(e.preventDefault(),jt(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[At]);let Mt=J.useRef(null);J.useEffect(()=>{Mt.current=null},[e,t]),J.useEffect(()=>{if(n||r||O)return;let i=`${e}/${t??``}`;Mt.current!==i&&Po(e)&&(g?.code==null?f?.allowOrgOverride||f?.allowRuntimeCreate:f?.allowOrgOverride)&&(Mt.current=i,Ae(!0))},[e,t,n,r,O,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(),Dt())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Dt]),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`)&&ht(t),pt.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&dt({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);ut?.kind===`metadata`?e.searchParams.set(`open`,`${ut.type}:${ut.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[ut,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 Pt(r){te(!0),M(null),ae([]);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){M(G(`engine.validation.nameRequired`,h)),te(!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=vs(m);Se(!!g);let b=f.effective??s,S=g?{...b,...g}:b,C=p.toDraft?p.toDraft(S):S;x(C),Pe.current=C,Ie(new Date),ze.current=JSON.stringify(C),le(null),F(null);let w=!n&&!!Po(e);!n&&!w&&Ae(!1),n&&i(`../${encodeURIComponent(o)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];le(Array.isArray(t)?t:[]),F(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:Dr(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:Dr(e[2].trim(),h)}]:[{path:``,message:Dr(r,h)}]}ae(n),n.length===1&&!n[0].path?M(n[0].message):n.length===1?M(`${Nt(n[0].path)}: ${n[0].message}`):M(U(`engine.validation.failed`,h,{count:n.length}))}else M(e?.message??String(e))}finally{te(!1)}}async function Ft(){let r=!n&&g?.code!=null;if(confirm(U(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,h,{type:e,name:t??``}))){te(!0),M(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),Pe.current=r,Po(e)?Mt.current=null:Ae(!1)}else i(`../`,{relative:`path`})}catch(e){M(e?.message??String(e))}finally{te(!1)}}}async function It(){we(!0),M(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=vs(r);Se(!!i);let a=n.effective??y,o=i?{...a,...i}:a;x(o),Pe.current=o}catch(e){M(e?.message??String(e))}finally{we(!1)}}async function Rt(){if(confirm(U(`engine.edit.discardDraftConfirm`,h,{type:e,name:t??``}))){te(!0),M(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),Pe.current=r,Se(!1)}catch(e){M(e?.message??String(e))}finally{te(!1)}}}let L=J.useMemo(()=>{if(n)return Object.keys(y).length>0;let e=Pe.current;if(!e)return!1;try{return JSON.stringify(y)!==JSON.stringify(e)}catch{return!1}},[y,n]),zt=!n&&g?.code!=null,Bt=g?.editable!==!1,Ht=g?.deletable!==!1,Ut=g?.resettable!==!1,Wt=g?.lockReason,Gt=g?.lock&&g.lock!==`none`,Kt=(n?!!(f?.allowOrgOverride||f?.allowRuntimeCreate):zt?!!f?.allowOrgOverride:!!(f?.allowOrgOverride||f?.allowRuntimeCreate))&&(n||Bt),qt=!Kt&&!n,Jt=J.useRef(Pt);if(J.useEffect(()=>{Jt.current=Pt}),J.useEffect(()=>{if(!Le||n||qt||!ke||!L||j)return;let e;try{e=JSON.stringify(y)}catch{return}if(e===ze.current)return;let t=window.setTimeout(()=>{ze.current=e,Jt.current(!1)},1500);return()=>window.clearTimeout(t)},[y,L,ke,j,n,qt,Le]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!Kt||qt||!ke&&!n)return;e.preventDefault(),!j&&(n||L)&&Jt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Kt,qt,ke,n,j,L]),J.useEffect(()=>{if(!L)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[L]),J.useEffect(()=>{if(!L)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)},[L,h]),br(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=oi(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])),O)return(0,q.jsx)(Pa,{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)(z,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let Yt=qt&&zt&&!!f?.allowRuntimeCreate,Xt=gs.has(e),Zt=!r&&(!n||Xt)?Po(e):void 0,$t=Lo(e),en=Bo(e);function tn(){Pe.current&&x(Pe.current),ae([]),M(null),Ae(!1)}let nn=qt||!ke&&!n,rn=(0,q.jsxs)(q.Fragment,{children:[!n&&(0,q.jsx)(La,{entry:f,location:`record_header`,recordId:t,onAfter:()=>De(e=>e+1)}),(!n||ft)&&(0,q.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`layers`),title:G(`engine.edit.layers`,h),className:`h-7 w-7 p-0 relative`,children:[(0,q.jsx)(D,{className:`h-3.5 w-3.5`}),g?.overlay&&(()=>{let e=eo(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&&be&&(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`review`),title:G(`designer.draftReview.title`,h),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,q.jsx)(Hn,{className:`h-3.5 w-3.5`}),(()=>{let e=lo(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)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`references`),title:G(`engine.edit.references`,h),className:`h-7 w-7 p-0 relative`,children:[(0,q.jsx)(oe,{className:`h-3.5 w-3.5`}),C&&C.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:C.length})]}),ft&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`related`),title:G(`engine.edit.related`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)(A,{className:`h-3.5 w-3.5`})}),!n&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`history`),title:G(`engine.edit.history`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)(b,{className:`h-3.5 w-3.5`})}),!n&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>ht(`audit`),title:G(`engine.edit.auditTab`,h),className:`h-7 w-7 p-0`,children:(0,q.jsx)(Qt,{className:`h-3.5 w-3.5`})})]}),!n&&Kt&&g?.overlay&&(zt?Ut:Ht)&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:Ft,disabled:j,title:G(zt?`engine.edit.reset`:`engine.edit.delete`,h),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:zt?(0,q.jsx)(ln,{className:`h-3.5 w-3.5`}):(0,q.jsx)(st,{className:`h-3.5 w-3.5`})}),Kt&&!n&&!ke&&!Zt&&(0,q.jsxs)(R,{size:`sm`,onClick:()=>Ae(!0),className:`h-7`,children:[(0,q.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]}),Kt&&(ke||n)&&(0,q.jsx)(Cs,{saving:j,isDirty:L,autoSaveEnabled:Le,lastSavedAt:Fe,createMode:!!n,locale:h}),Kt&&(ke||n)&&!n&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>Re(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:G(Le?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,h),children:Le?(0,q.jsx)(Lt,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,q.jsx)(lr,{className:`h-3.5 w-3.5`})}),Kt&&!n&&ke&&!Zt&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:tn,disabled:j,className:`h-7 w-7 p-0`,title:G(`engine.cancel`,h),children:(0,q.jsx)(Qe,{className:`h-3.5 w-3.5`})}),Kt&&(ke||n)&&(0,q.jsxs)(R,{size:`sm`,onClick:()=>Pt(!1),disabled:j||!n&&!L,className:`h-7 w-7 p-0 relative`,title:j?G(`engine.edit.saving`,h):!n&&!L?G(`engine.edit.noChanges`,h):`${G(`engine.edit.save`,h)} (⌘S)`,children:[j?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)($e,{className:`h-3.5 w-3.5`}),L&&!j&&(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`})]}),Kt&&!n&&be&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:Rt,disabled:j||Ce,className:`h-7 w-7 p-0 text-muted-foreground`,title:G(`engine.edit.discardDraft`,h),children:(0,q.jsx)(_e,{className:`h-3.5 w-3.5`})}),Kt&&!n&&be&&(0,q.jsx)(R,{size:`sm`,onClick:It,disabled:j||Ce||L,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:G(L?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),children:Ce?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(sr,{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)(Pa,{entry:f??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?G(`engine.edit.createNew`,h):void 0,actions:Zt?null:rn,children:[(0,q.jsxs)(`div`,{className:Zt?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(ne||qt||be||Gt)&&(0,q.jsxs)(`div`,{className:Zt?`px-6 pt-4 space-y-3`:`space-y-3`,children:[ne&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:ne}),Gt&&(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)(w,{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)]}),Wt&&(0,q.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Wt}),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}`:``]})})]}),Yt&&(0,q.jsx)(R,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]}),be&&!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)(sr,{className:`h-3.5 w-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`flex-1`,children:G(`engine.edit.draftPending`,h)}),Kt&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(R,{size:`sm`,variant:`ghost`,onClick:Rt,disabled:j||Ce,className:`h-7`,children:G(`engine.edit.discardDraft`,h)}),(0,q.jsx)(R,{size:`sm`,onClick:It,disabled:j||Ce||L,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:Ce?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):G(`engine.edit.publish`,h)})]})]}),qt&&!Gt&&(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:Yt?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))}),Yt&&(0,q.jsx)(R,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]})]}),(0,q.jsx)(`div`,{className:Zt?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,q.jsxs)(`div`,{className:Zt?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!Zt&&nn&&!qt&&Kt&&!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)(R,{size:`sm`,variant:`outline`,onClick:()=>Ae(!0),children:[(0,q.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]})]}),(()=>{let t=g?._diagnostics,n=ps(e)?N.map(e=>({path:e.path,message:Dr(e.message,h)})):(t?.errors??[]).map(e=>({...e,message:Dr(e.message,h)})),r=ps(e)?n.length===0:t?.valid!==!1;if(!ys({loadFailed:re,hasDiag:!!t,hasClientValidator:ps(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)]})})(),Zt?(0,q.jsx)(`div`,{className:At?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,q.jsxs)(hs,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,q.jsx)(xe,{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:Kt&&(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":!Ot,onClick:()=>kt(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ot?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:G(`engine.edit.designMode`,h),children:[(0,q.jsx)(gn,{className:`h-3.5 w-3.5`}),G(`engine.edit.designMode`,h)]}),(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Ot,onClick:()=>kt(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ot?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.previewMode`,h),children:[(0,q.jsx)(Me,{className:`h-3.5 w-3.5`}),G(`engine.edit.previewMode`,h)]})]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[rn,(0,q.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),Zt&&(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:Dt,className:`h-7 w-7 p-0`,title:G(Ct?`engine.edit.showInspector`:`engine.edit.hideInspector`,h)+` (⌘\\)`,children:Ct?(0,q.jsx)(Wn,{className:`h-3.5 w-3.5`}):(0,q.jsx)(yn,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>jt(e=>!e),className:`h-7 w-7 p-0`,title:G(At?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,h),children:At?(0,q.jsx)(dr,{className:`h-3.5 w-3.5`}):(0,q.jsx)(tr,{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)(Zt,{type:e,name:t,draft:y,baseline:n?void 0:g?.effective??void 0,editing:ke&&!Ot,selection:Ot?null:je,onSelectionChange:Ne,locale:h,onPatch:e=>P(t=>({...t,...e}))})})]})}),(0,q.jsx)(Pn,{withHandle:!0,className:Ct?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,q.jsx)(xe,{panelRef:Et,defaultSize:Tt.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Tt.current=t,typeof window<`u`&&window.localStorage.setItem(St,String(Math.round(t)))),wt(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(xt,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":yt===`properties`,onClick:()=>bt(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(yt===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.properties`,h),children:[(0,q.jsx)(Vt,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.properties`,h)]}),(0,q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":yt===`source`,onClick:()=>bt(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(yt===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.source`,h),children:[(0,q.jsx)(T,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.source`,h)]})]}),L&&(0,q.jsxs)(S,{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:yt===`source`?(0,q.jsx)(os,{value:y,onChange:P,readOnly:nn,issues:N.map(e=>({path:e.path??``,message:e.message}))}):je&&$t?(0,q.jsx)($t,{type:e,name:t,draft:y,selection:je,onPatch:e=>P(t=>({...t,...e})),onClearSelection:()=>Ne(null),onSelectionChange:Ne,readOnly:nn,locale:h}):!je&&en?(0,q.jsx)(en,{type:e,name:t,draft:y,onPatch:e=>P(t=>({...t,...e})),onSelectionChange:Ne,readOnly:nn,locale:h,serverSchema:f?.schema}):(0,q.jsx)(Nr,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:ye,issues:N,hiddenFields:he,fieldOrder:ge,readOnly:nn,createMode:n,widgetContext:it})})]})})]})}):(0,q.jsx)(Nr,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:ye,issues:N,hiddenFields:he,fieldOrder:ge,readOnly:nn,createMode:n,widgetContext:it})]})})]}),(0,q.jsx)(Be,{open:mt===`layers`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Je,{className:`text-base`,children:G(`engine.edit.layers`,h)}),(0,q.jsxs)(ve,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(to,{layered:g,locale:h})})]})}),(0,q.jsx)(Be,{open:mt===`review`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Je,{className:`text-base`,children:G(`designer.draftReview.title`,h)}),(0,q.jsxs)(ve,{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)(uo,{published:g?.effective??null,draft:y,locale:h})})]})}),(0,q.jsx)(Be,{open:mt===`references`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsxs)(Je,{className:`text-base`,children:[G(`engine.edit.references`,h),C&&(0,q.jsx)(S,{variant:`outline`,className:`ml-2 text-[10px]`,children:C.length})]}),(0,q.jsxs)(ve,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(Ss,{refs:C,loading:at})})]})}),ft&&(0,q.jsx)(Be,{open:mt===`related`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Je,{className:`text-base`,children:G(`engine.edit.related`,h)}),(0,q.jsxs)(ve,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(yo,{type:e,name:t,parentItem:y,onOpen:e=>dt(e)})})]})}),!n&&(0,q.jsx)(Be,{open:mt===`history`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Je,{className:`text-base`,children:G(`engine.edit.history`,h)}),(0,q.jsxs)(ve,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,q.jsx)(Do,{type:e,name:t,client:l,onRollback:()=>De(e=>e+1),rollbackLabel:G(`engine.edit.rollback`,h),rollbackConfirm:e=>G(`engine.edit.rollbackConfirm`,h).replace(`{version}`,String(e))})})]})}),!n&&(0,q.jsx)(Be,{open:mt===`audit`,onOpenChange:e=>!e&&ht(null),children:(0,q.jsxs)(se,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,q.jsxs)(Oe,{className:`px-4 py-3 border-b`,children:[(0,q.jsx)(Je,{className:`text-base`,children:G(`engine.edit.auditTab`,h)}),(0,q.jsxs)(ve,{className:`text-xs`,children:[e,` / `,t]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,q.jsx)(Mo,{type:e,name:t,client:l,locale:h})})]})}),(0,q.jsx)(To,{target:ut,onClose:()=>dt(null),parentContext:{type:e,name:t}}),(0,q.jsx)(Te,{open:ce!=null,onOpenChange:e=>{e||(le(null),F(null))},children:(0,q.jsxs)(Ke,{children:[(0,q.jsxs)(ot,{children:[(0,q.jsxs)(de,{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)(hr,{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:ce?.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)(k,{children:[(0,q.jsx)(R,{variant:`ghost`,onClick:()=>le(null),children:`Cancel`}),(0,q.jsx)(R,{variant:`destructive`,onClick:()=>Pt(!0),disabled:j,children:j?`Forcing…`:`Force save`})]})]})})]})}function Ss({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)(z,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,q.jsxs)(We,{children:[(0,q.jsx)(le,{children:`No references found`}),(0,q.jsx)(mr,{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)(S,{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 Cs({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)(z,{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 ws({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)(We,{children:[(0,q.jsx)(le,{children:`Missing metadata type`}),(0,q.jsxs)(mr,{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=Ts(t.pathname),o=i.split(`/`).filter(Boolean);return o.length===0?(0,q.jsx)(Ga,{type:r}):o[0]===`new`&&o.length===1?(0,q.jsx)(bs,{type:r,name:``,createMode:!0},`${r}:__new__`):o.length===2&&o[1]===`history`?(0,q.jsx)(Eo,{type:r,name:decodeURIComponent(o[0])}):o.length===1?(0,q.jsx)(bs,{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)(We,{children:[(0,q.jsx)(le,{children:`Unknown sub-path`}),(0,q.jsxs)(mr,{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 Ts(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function Es(){let e=Cr(),t=J.useMemo(()=>Ir(),[]),[n,r]=J.useState(`error`),{loading:i,error:a,summary:o,reload:s}=wr(e,n),{entries:l}=Vr(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=Lr(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)(In,{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)(S,{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)(R,{variant:`ghost`,size:`sm`,onClick:s,children:[(0,q.jsx)(Le,{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)(We,{children:[(0,q.jsx)(le,{children:G(`engine.diagnostics.cleanTitle`,t)}),(0,q.jsx)(mr,{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)(S,{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)(S,{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)(S,{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 Ds(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 Os({type:e,name:t}){let n=u(),r=Cr(),{entries:i}=Vr(r),a=i.find(t=>t.type===e),o=!!Ua(e,a).allowOrgOverride,s=J.useMemo(()=>Ir(),[]),c=J.useCallback(e=>G(e,s),[s]),l=J.useMemo(()=>Ds(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),[C,w]=J.useState(!1),[T,E]=J.useState(null),[D,O]=J.useState(null),[A,ee]=J.useState(``),[j,te]=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 ne(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 M(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),ne(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 ie(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 N(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 ae(t,n){let i=n??d;w(!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{w(!1)}}let oe=J.useMemo(()=>{let e=A.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,A,j,d.objects]),P=[{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)(Pa,{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)(z,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,q.jsxs)(Pa,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:P,actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,q.jsx)(b,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,q.jsxs)(R,{size:`sm`,onClick:()=>ae(!1),disabled:C,children:[C?(0,q.jsx)(z,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)($e,{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:[T&&(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:T})]}),(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)(H,{htmlFor:`perm-name`,className:`text-xs`,children:c(`perm.field.name`)}),(0,q.jsx)(V,{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)(H,{htmlFor:`perm-label`,className:`text-xs`,children:c(`perm.field.label`)}),(0,q.jsx)(V,{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)(Zt,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,q.jsx)(H,{htmlFor:`perm-is-profile`,className:`text-xs`,children:c(`perm.field.isProfile`)})]}),!o&&(0,q.jsx)(S,{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)(V,{placeholder:c(`perm.filter.placeholder`),value:A,onChange:e=>ee(e.target.value),className:`h-8 w-72`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Zt,{id:`only-enabled`,checked:j,onCheckedChange:e=>te(!!e)}),(0,q.jsx)(H,{htmlFor:`only-enabled`,className:`text-xs`,children:c(`perm.filter.onlyGranted`)})]}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[oe.length,` / `,p.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,q.jsx)(ks,{objects:oe,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:l,t:c,onToggleExpand:M,onObjectPerm:re,onFieldPerm:N,onBulkSet:ie})})]}),(0,q.jsx)(Te,{open:!!D,onOpenChange:e=>!e&&O(null),children:(0,q.jsxs)(Ke,{children:[(0,q.jsxs)(ot,{children:[(0,q.jsxs)(de,{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)(hr,{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)(S,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,q.jsxs)(k,{children:[(0,q.jsx)(R,{variant:`ghost`,onClick:()=>O(null),children:c(`engine.cancel`)}),(0,q.jsxs)(R,{variant:`destructive`,onClick:()=>D&&ae(!0,D.pending),disabled:C,children:[C&&(0,q.jsx)(z,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function ks({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)(M,{className:`h-3.5 w-3.5`}):(0,q.jsx)(ur,{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)(Se,{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)(R,{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)(R,{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)(R,{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)(R,{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)(As,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function As({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)(Se,{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)(Se,{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)(z,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function js(){Ba({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Ms(e.fields),groupLabel:`Fields`,order:5}]}),Ba({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}]}),Ba({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Ms(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Ba({type:`hook`,anchors:[{anchorType:`object`,match:Ra(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Ba({type:`page`,anchors:[{anchorType:`object`,match:Ra(`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-yfd0iHKg.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{}}}}),Ba({type:`view`,anchors:[{anchorType:`object`,match:Ra([`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}}}}}),Ba({type:`flow`,anchors:[{anchorType:`object`,match:Ra([`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:[]}}),Ba({type:`trigger`,anchors:[{anchorType:`object`,match:Ra([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ba({type:`validation`,anchors:[{anchorType:`object`,match:Ra(`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`}}),Ba({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:{}}}),Ba({type:`action`,anchors:[{anchorType:`object`,match:Ra([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ba({type:`dashboard`,anchors:[{anchorType:`object`,match:Ra([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Ba({type:`report`,anchors:[{anchorType:`object`,match:Ra([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Ba({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 Ms(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Ns={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`}},Ps={role:{type:`object`,title:`Role`,required:[`name`],properties:{...Ns,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:{...Ns,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:{...Ns.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Ns.label,description:Ns.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:{...Ns,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:{...Ns,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Ns,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Ns,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Ns,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:{...Ns,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Ns,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...Ns,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 Fs(){for(let[e,t]of Object.entries(Ps))Ba({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)(At,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,q.jsx)(`div`,{className:`flex-1`,children:t})]})}function Is({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)(ye,{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 Ls({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:B(`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)(F,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:a??`Add`})]})]})]})}var Rs={"page:header":{label:`Header`,category:`layout`,Icon:x},"page:footer":{label:`Footer`,category:`layout`,Icon:Cn},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Fn},"page:tabs":{label:`Tabs`,category:`layout`,Icon:Yt},"page:accordion":{label:`Accordion`,category:`layout`,Icon:er},"page:card":{label:`Card`,category:`layout`,Icon:rn},"page:section":{label:`Section`,category:`layout`,Icon:D},"record:details":{label:`Record details`,category:`record`,Icon:Ze},"record:highlights":{label:`Highlights`,category:`record`,Icon:gt},"record:related_list":{label:`Related list`,category:`record`,Icon:Ie},"record:activity":{label:`Activity timeline`,category:`record`,Icon:L},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:or},"record:path":{label:`Stage path`,category:`record`,Icon:yt},"record:alert":{label:`Alert banner`,category:`record`,Icon:I},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:Lt},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:pt},"record:history":{label:`History`,category:`record`,Icon:b},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:j},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:yt},"global:search":{label:`Global search`,category:`navigation`,Icon:Xe},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:pe},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:fn},"element:text":{label:`Text`,category:`element`,Icon:Ee},"element:number":{label:`Number`,category:`element`,Icon:Kt},"element:image":{label:`Image`,category:`element`,Icon:_t},"element:divider":{label:`Divider`,category:`element`,Icon:Zn},"element:button":{label:`Button`,category:`element`,Icon:On},"element:definition-list":{label:`Definition list`,category:`element`,Icon:ke},"element:repeater":{label:`Repeater`,category:`element`,Icon:ie}},zs={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Bs=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Rs))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)})(),Vs=ct,Hs={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 Us(e){return Hs[Rs[e]?.category??`misc`]}var Ws={"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 Gs(e){return!!e&&Array.isArray(Ws[e])&&Ws[e].length>0}function Ks(){let e=Cr(),[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 qs(e){let{fields:t}=wi(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 Js({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=Ks();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)(Mr,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function Ys({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=qs(t);return!t||a.length===0?(0,q.jsx)(W,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,q.jsx)(Mr,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function Xs({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=qs(t),o=Array.isArray(n)?n:[];return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(H,{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)(ee,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,q.jsx)(rt,{className:`h-8`,children:(0,q.jsx)(mt,{placeholder:`—`})}),(0,q.jsx)(lt,{children:a.map(e=>(0,q.jsx)(me,{value:e.value,children:e.label},e.value))})]})}):(0,q.jsx)(V,{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)(R,{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)(Qe,{className:`h-4 w-4`})})]},t)),!i&&(0,q.jsxs)(R,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,q.jsx)(F,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}var Zs=Symbol(`remove`);function Qs(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 $s(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function ec(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function tc(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===Zs?t.splice(r,1):t[r]=n:t[r]=tc(t[r],i,n),t}let a={...e||{}};return i.length===0?n===Zs?delete a[r]:a[r]=n:a[r]=tc(a[r],i,n),a}function nc(e,t){return ec(e,$s(t))}function rc(e,t,n){let r=$s(t),i=tc(e,r,n===null?Zs:n),a=r[0];return{[a]:i[a]}}function ic(e,t){let n=$s(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=ec(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function ac(e,t,n){let r=$s(t),i=tc(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function oc({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:Qs(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?Qs(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?nc(h||{},f):h:c?nc(t,c):null,y=s?f?ic(h||{},f):{siblings:m,index:u}:c?ic(t,c):null;if(!s&&!c||!v)return(0,q.jsx)(Ar,{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)(zr,{message:e.id})});let b=e=>s?_(f?{...h,...rc(h||{},f,{...v,...e})}:{...v,...e}):n(rc(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)(Or,{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)(jr,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`select`:return(0,q.jsx)(Mr,{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)(H,{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)(V,{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)(R,{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)(Qe,{className:`h-4 w-4`})})]},i)),!o&&(0,q.jsxs)(R,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,q.jsx)(F,{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)(H,{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)(R,{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)(st,{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)(R,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,q.jsx)(F,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,q.jsx)(Js,{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)(Ys,{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)(Xs,{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,...rc(h||{},f,null)}:null):n(rc(t,c,null)),r()},O=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,q.jsxs)(Ar,{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)(Fr,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=Br(y.siblings,y.index,e);_({...h,...ac(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(Br(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}n(ac(t,c,Br(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)(kr,{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}),Gs(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)}),Ws[v.type].map(e=>E(e,w,T))]})]})}function sc(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 cc=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function lc(e){let t=e||{};return cc.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function uc(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 dc(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:lc(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 fc(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function pc(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 mc=`text/x-objectui-pageblock`;function hc({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>dc(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:uc(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=fc(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:pc(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:fc(o,e,l,i[e]?.name),label:pc(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=Qs(i);if(!s)return;let c=$s(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=ec(p,c)||[];f[l]=tc(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=Qs(`${n}.${i}`);if(!o)return;let s=$s(o),c=ec(e,s)||[],l=tc(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)(R,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,q.jsx)(F,{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)(gc,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:fc(o,t,n,e.name),label:pc(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>fc(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)(R,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function gc({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:B(`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(mc)||(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(mc);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=fc(n,t,d,e.name);return(0,q.jsxs)(J.Fragment,{children:[(0,q.jsx)(_c,{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)(vc,{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)(yc,{onPick:e=>s(t,e)})})]})]})}function _c({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Rs[c]?.Icon??Vs,u=Us(c),d=pc(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(mc,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(mc))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(mc);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,b]=J.useState(!1),[x,C]=J.useState(d);J.useEffect(()=>{C(d)},[d]);let w=e=>{i||(e.preventDefault(),e.stopPropagation(),C(d),b(!0))},T=()=>{if(i){b(!1);return}let e=x.trim();e&&e!==d&&s(e),b(!1)},E=()=>{C(d),b(!1)};return(0,q.jsxs)(`div`,{className:B(`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:B(`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)(Ln,{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:B(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,q.jsx)(`input`,{autoFocus:!0,value:x,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:B(`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)(S,{variant:`outline`,className:B(`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 vc({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=sc(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=Rs[s]?.Icon??Vs;return(0,q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,pc(r))},className:B(`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:pc(r)}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:s})]},a)}),!r&&(0,q.jsx)(yc,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function yc({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?Bs.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Rs[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Bs,[a]);return(0,q.jsxs)(C,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,q.jsx)(qn,{asChild:!0,children:(0,q.jsxs)(R,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,q.jsxs)(Gt,{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:zs[t.category]}),t.types.map(t=>{let r=Rs[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:B(`h-3.5 w-3.5 shrink-0`,Us(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 bc({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)(Ur,{page:e})})}):!o||Object.keys(o).length<=1?(0,q.jsxs)(X,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,q.jsx)(hc,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,q.jsx)(Ls,{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)(hc,{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)(Ls,{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 xc(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 Sc=new Set([`simple`,`tabbed`,`wizard`,`split`]);function Cc(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 wc(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:Sc.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(Cc):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function Tc({name:e,draft:t,editing:n}){let r=J.useMemo(()=>Yi(t)?.schema,[t]),i=J.useMemo(()=>xc(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=wc(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 Ec=J.lazy(()=>o(()=>import(`./plugin-dashboard-CGRjBe2V.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Dc({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=Er(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Qr[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:Tr(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)(ei,{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)(Oc,{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)(z,{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)(Ec,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function Oc({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=Qr[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)(ar,{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)(vt,{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)(Qe,{className:`h-3.5 w-3.5`})})]})}var kc=J.lazy(()=>o(()=>import(`./plugin-report-DA6bVPuW.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Ac({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)(z,{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)(kc,{schema:e,dataSource:t})})})})})}return(0,q.jsx)(X,{children:(0,q.jsx)(Is,{icon:(0,q.jsx)(nt,{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 jc=`text/x-objectui-nav`;function Mc(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 Nc(e){switch(e){case`object`:return nt;case`page`:return Ze;case`dashboard`:return it;case`report`:return cn;case`link`:return he;case`group`:return An;default:return yt}}var Pc={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 Fc(e){return Pc[e]??Pc.item}function Ic(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Lc(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Rc({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=Tr(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=Br(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Ic(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)(S,{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)(F,{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(jc)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(jc)&&(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)(zc,{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 zc({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)(Bc,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Ic(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)(zc,{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 Bc({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=Mc(e),p=Nc(f),m=Fc(f),h=Lc(e),[g,_]=J.useState(!1),[v,y]=J.useState(Ic(e,t)),[b,x]=J.useState(!1),[C,w]=J.useState(null);return J.useEffect(()=>{g||y(Ic(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(jc,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(jc)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(jc)&&(e.preventDefault(),e.stopPropagation(),w(null),d())},onClick:o,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!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)(Ln,{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:B(`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!==Ic(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Ic(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:Ic(e,t)}),(0,q.jsx)(S,{variant:`outline`,className:B(`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&&b&&!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)(st,{className:`h-3 w-3`})})]})]})}function Vc(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)?Vc(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Hc(e){switch(e){case`object`:return nt;case`page`:return Ze;case`dashboard`:return it;case`report`:return cn;default:return yt}}function Uc({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:Vc(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)(P,{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)(Rc,{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)(Wc,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Wc({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Hc(e.kind),s=Gc(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)(P,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,q.jsx)(Wc,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function Gc(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 Kc(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,q.jsx)(qc,{...e,icon:t===`password`?(0,q.jsx)(w,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(bt,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(jt,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(Nn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(Kt,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(Pe,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.pickDate`,n)});case`time`:return(0,q.jsx)(qc,{...e,icon:(0,q.jsx)(xn,{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)(Jc,{...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)(Zt,{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)(Yc,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,q.jsx)(Yc,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,q.jsx)(Xc,{...e});case`image`:case`avatar`:return(0,q.jsx)(Zc,{icon:(0,q.jsx)(_t,{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)(Zc,{icon:(0,q.jsx)(Ct,{className:`h-4 w-4`}),label:U(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,q.jsx)(Zc,{icon:(0,q.jsx)(Ct,{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)(zn,{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)(bn,{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)(qc,{...e,icon:(0,q.jsx)(N,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.latLng`,n)});case`address`:return(0,q.jsx)(Jc,{...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)(V,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,q.jsx)(S,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function qc({placeholder:e,icon:t}){return(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(V,{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 Jc({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 Yc({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)(M,{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)(S,{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 Xc({referenceTo:e,placeholder:t,locale:n}){let r=e?Xr.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)(oe,{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)(S,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,q.jsx)(Xe,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function Zc({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 Qc=e=>(e??``).toLowerCase().startsWith(`zh`),$c=(e,t)=>e?Qc(t)?e.labelZh:e.label:void 0,el=(e,t)=>(Qc(t)?Wr:Kr)[e];function tl({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,c=J.useMemo(()=>oi(t.fields),[t]),l=J.useMemo(()=>n?Ci(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(()=>fi(t.fieldGroups),[t]),_=g.length>0,v=J.useMemo(()=>bi(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),ee=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 j=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=ee.indexOf(A.current),t=ee.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];k(new Set(ee.slice(n,r+1)));return}}O.size&&k(new Set),A.current=n,D(e)},[s,ee,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:si({shape:c.shape,entries:e})}),T&&O.has(T)&&a?.(null),k(new Set)},[r,O,c,T,a]),M=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:si({shape:c.shape,entries:t})})},[r,O,c]),re=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=li(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:si({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=mi(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:hi(g,e,t)})},[r,g]),ae=J.useCallback(e=>{if(!r)return;let t=vi(c,e);r({fieldGroups:gi(g,e),fields:si(t)})},[r,g,c]),oe=J.useCallback((e,t)=>{r&&r({fieldGroups:_i(g,e,t)})},[r,g]),P=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:si({shape:c.shape,entries:i})})},[r,c]),se=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:si({shape:c.shape,entries:n})})},[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]=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:si({shape:c.shape,entries:n})})},[r,c]),le=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:si({shape:c.shape,entries:n})})},[r,c]),ue=J.useCallback(e=>{e.target===e.currentTarget&&T&&a?.(null)},[a,T]),F=c.entries.length===0,de=_||v.length>1;return(0,q.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:ue,"data-object-name":e,children:[!s&&O.size>0&&(0,q.jsx)(rl,{count:O.size,groups:g,onMoveToGroup:M,onDelete:ne,onClear:te,locale:o}),(0,q.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:ue,children:[!F&&(0,q.jsx)(nl,{fieldCount:c.entries.length,requiredCount:E,sectionCount:g.length,allCollapsed:C,onToggleAll:de?()=>w(!C):void 0,reviewAvailable:u>0,reviewing:p,diffCounts:l?.counts,onToggleReview:()=>f(e=>!e),locale:o}),F?(0,q.jsx)(cl,{onAdd:s?void 0:re,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)(il,{groupKey:e.key,label:e.key===null?G(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:de,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=>re(t,e.key),onDropField:s?void 0:ce,children:[e.entries.map(e=>(0,q.jsx)(sl,{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=>j(e,t),onReorder:s?void 0:P,onRenameLabel:s?void 0:le,onMoveOffset:s?void 0:t=>se(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)(ol,{entry:e,locale:o},e.name))]}),!F&&!s&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,q.jsx)(ll,{onPick:e=>re(e),locale:o}),(0,q.jsxs)(R,{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)(R,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>xr(),children:[(0,q.jsx)(fn,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAi`,o)]})]})]})]})}function nl({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:B(`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)(Hn,{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)(er,{className:`h-3 w-3`}):(0,q.jsx)(Rt,{className:`h-3 w-3`}),G(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function rl({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)(C,{open:o,onOpenChange:s,children:[(0,q.jsx)(qn,{asChild:!0,children:(0,q.jsxs)(R,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,q.jsx)(Ot,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkMoveTo`,a),(0,q.jsx)(M,{className:`h-3 w-3`})]})}),(0,q.jsxs)(Gt,{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)(R,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,q.jsx)(st,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkDelete`,a)]}),(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,q.jsx)(Qe,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkClear`,a)]})]})]})}function il({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:B(`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)(al,{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 al({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?ur:M;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:B(`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)(ll,{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)(Tt,{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)(nn,{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)(st,{className:`h-3 w-3`})})]})]})}function ol({entry:e,locale:t}){let n=e.def,r=Xr[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)(S,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:G(`designer.canvas.diffRemoved`,t)})]})})}function sl({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=Xr[f],m=p?.Icon,h=Jr[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,b=typeof d.reference==`string`?d.reference:void 0,x=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 ee=e=>{l&&(e.preventDefault(),e.stopPropagation(),A(g),O(!0))},j=()=>{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:B(`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:B(`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)(Ln,{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:B(`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(),j()):e.key===`Escape`&&(e.preventDefault(),te())},onBlur:j,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:B(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:ee,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)(S,{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)(S,{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)(S,{variant:`outline`,className:B(`text-[10px] font-medium`,h.badge),children:$c(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)(Kc,{type:f,label:g,placeholder:C,options:y,referenceTo:b,formula:x,locale:o})]}),w===`after`&&(0,q.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function cl({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)(ll,{onPick:e,locale:t}),(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>xr(),children:[(0,q.jsx)(fn,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAiGenerate`,t)]})]})]})}function ll({onPick:e,compact:t,locale:n}){let[r,i]=J.useState(!1),[a,o]=J.useState(``),s=a.trim().toLowerCase(),c=J.useMemo(()=>s?Gr.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Xr[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):Gr,[s,a]);return(0,q.jsxs)(C,{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)(F,{className:`h-3 w-3`})}):(0,q.jsxs)(R,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,q.jsx)(F,{className:`h-3.5 w-3.5`}),G(`designer.canvas.addField`,n)]})}),(0,q.jsxs)(Gt,{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:el(t.category,n)}),(0,q.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=Xr[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:B(`h-3.5 w-3.5 shrink-0`,Jr[r.category].icon)}),(0,q.jsx)(`span`,{className:`truncate`,children:$c(r,n)})]},t)})})]},t.category))})]})]})}function ul({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)(tl,{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 dl(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 fl(e,t){return t[e]??``}function pl(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>fl(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>fl(n,t))}function ml({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 dl(t))e.add(n);for(let t of dl(i))e.add(t);for(let t of dl(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=J.useState({}),l=pl(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?pl(i,s):pl(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)(re,{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 hl(e){return typeof e==`number`&&Number.isFinite(e)}function gl(e){return hl(e.ui?.x)&&hl(e.ui?.y)}function _l(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)gl(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function vl(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 yl(e){return{x:e.x+240/2,y:e.y+66}}function bl(e){return{x:e.x+240/2,y:e.y}}function xl(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 Sl(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Cl(e,t){return e.id||`${e.source}->${e.target}#${t}`}function wl(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Tl(e){switch(e){case`start`:return ut;case`end`:return mn;case`decision`:case`branch`:case`gateway`:return fe;case`wait`:case`timer`:case`delay`:return ce;case`boundary_event`:case`signal`:return Lt;case`subflow`:case`flow`:return ir;case`create_record`:return ae;case`update_record`:return Fe;case`delete_record`:return It;case`get_record`:return rr;case`http_request`:case`webhook`:return jt;case`script`:case`script_task`:return wt;case`screen`:case`user_task`:return Et;case`approval`:return Ne;case`connector_action`:case`service_task`:return tt;case`assignment`:return un;case`loop`:case`for_each`:return on;case`map`:return Ie;case`parallel_gateway`:case`join_gateway`:case`parallel`:return Tn;case`try_catch`:return Dt;default:return vn}}var El={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 Dl(e){switch(e){case`start`:return El.start;case`end`:return El.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return El.decision;case`wait`:case`timer`:case`delay`:return El.wait;case`boundary_event`:case`signal`:case`try_catch`:return El.signal;case`subflow`:case`flow`:return El.subflow;case`approval`:return El.approval;case`loop`:case`for_each`:case`map`:return El.loop;case`screen`:case`user_task`:return El.screen;case`assignment`:return El.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return El.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return El.integration;default:return El.task}}function Ol({type:e,className:t}){return J.createElement(Tl(e),{className:t,"aria-hidden":!0})}var kl=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Al(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 jl=[{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 Ml(e){let t=jl.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Nl(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 Pl({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=Dl(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:B(`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:B(`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)(Ol,{type:e,className:B(`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:B(`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:B(`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)(F,{className:`h-3.5 w-3.5`})})]})}function Fl({items:e=jl,onPick:t,onClose:n}){let r=J.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??Al(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return kl.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=Dl(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:B(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,q.jsx)(Ol,{type:e.type,className:B(`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:B(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 Il(){return`${``.replace(/\/$/,``)}/api/v1`}function Ll(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??Al(e.type)})}return[...n.values()]}function Rl(){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(`${Il()}/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 zl(){let e=Rl();return(0,J.useMemo)(()=>e.length?Ll(jl,e):jl,[e])}function Bl(){let e=Rl();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 Vl=.4,Hl=1.6,Ul=4;function Wl({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=zl(),[x,S]=J.useState(null),C=J.useRef(null),w=J.useRef(null),T=J.useMemo(()=>_l(e,t),[e,t]),E=J.useMemo(()=>vl(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]),ee=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]),j=J.useCallback((n,r)=>{if(!f)return;let i=Er(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Ml(n),o=r?.at,s={id:i,type:n,label:a,...Nl(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:Tr(e,s)};r?.from&&(c.edges=Tr(t,{id:Er(`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=Er(`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:Ml(r),...Nl(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:Er(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=K(t,i,d);f({nodes:Tr(e,l),edges:Tr(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]),M=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]),re=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)<Ul||(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&&ee(t.nodeId,Math.round(x.x),Math.round(x.y)),S(null))},[x,ee]),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},[]),P=e=>Math.min(Hl,Math.max(Vl,e)),se=J.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=P(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]),ce=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)(F,{className:`h-3.5 w-3.5`}),G(`engine.inspector.add.node`,o)]}),v&&(0,q.jsx)(Fl,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>j(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=>P(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,q.jsx)($n,{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=>P(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(pr,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:se,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,q.jsx)(tr,{className:`h-3.5 w-3.5`})})]})]}),(0,q.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:ce,onPointerDown:N,onPointerMove:e=>{ae(e),re(e)},onPointerUp:e=>{oe(e),ie(e)},className:B(`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=yl(x?.id===e.source?A(e.source):i),c=bl(x?.id===e.target?A(e.target):o),l=Sl(s,c),u=wl(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=Cl(e,t),m=O.has(p),h=a===p,g=xl(s,c),_=r&&!!d;return(0,q.jsxs)(`g`,{children:[(0,q.jsx)(`path`,{d:g,strokeLinecap:`round`,className:B(`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:B(_&&`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:B(`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)(F,{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)(Pl,{id:e.id,type:e.type,label:e.label||e.id,summary:Gl(e),position:A(e.id),selected:i===e.id,editable:n,runState:t,dimmed:k&&!t,onPointerDown:M(e.id),onSelect:()=>r&&u(e),onAppend:()=>j(`create_record`,{from:e.id})},e.id)})]})})]})}function Gl(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 Kl=e=>typeof e==`string`?e:void 0;function ql(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 Jl(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=>Kl(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 Yl=500,Xl=new Set([`start`,`assignment`]),Zl=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),Ql=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),$l=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,eu=e=>typeof e==`string`?e:void 0,tu=e=>typeof e==`string`&&e?e:void 0,nu=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=Jl([...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>=Yl)return e.status=`error`,e.error=`Step limit (${Yl}) 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(Ql.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(Zl.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:Xl.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=eu(e.condition);if(!t){n.push({edgeId:$l(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=ql(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:$l(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:$l(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=tu(e.config?.collection),n=tu(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=tu(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=tu(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=$l(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 ru(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 iu=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function au(e){let t=[];for(let n of e){if(!iu.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 ou={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 su({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(()=>au(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:ru(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=ru(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]=ru(n));return e},[h]),b=J.useCallback(()=>{let n=new nu(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(),_()},C=()=>{x().step(),_()},w=()=>{let e=x();e.resume(),e.runToEnd(),_()},T=()=>{i.current=null,o(null),c(null),r?.(null)},E=a?.status??`idle`,D=(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)(R,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:D,children:[(0,q.jsx)(ut,{className:`h-3.5 w-3.5`}),` Run`]}),(0,q.jsxs)(R,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:D||E===`done`||E===`error`,children:[(0,q.jsx)(Kn,{className:`h-3.5 w-3.5`}),` Step`]}),E===`paused`&&(0,q.jsxs)(R,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,q.jsx)(ur,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,q.jsxs)(R,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:T,children:[(0,q.jsx)(ln,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,q.jsx)(`span`,{className:B(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,ou[E===`idle`||E===`running`?`ok`:E]??`bg-muted`),children:E})]}),(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)(At,{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)(H,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,q.jsx)(V,{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)(F,{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)(V,{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)(V,{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)(st,{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)(H,{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)(V,{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:B(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,ou[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:B(`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:B(`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&&!D&&(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 cu(e,t){try{let n=await fetch(`${Il()}/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 lu={completed:{icon:tn,cls:`text-emerald-600 dark:text-emerald-400`,label:`Completed`},failed:{icon:At,cls:`text-rose-600 dark:text-rose-400`,label:`Failed`},paused:{icon:jn,cls:`text-amber-600 dark:text-amber-400`,label:`Paused`},running:{icon:z,cls:`text-sky-600 dark:text-sky-400`,label:`Running`},cancelled:{icon:Jt,cls:`text-muted-foreground`,label:`Cancelled`}};function uu(e){return lu[e]??{icon:xn,cls:`text-muted-foreground`,label:e}}function du(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function fu(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function pu({step:e}){return(0,q.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,children:[(0,q.jsx)(`span`,{className:B(`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}),fu(e.durationMs)&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:fu(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 mu({run:e}){let[t,n]=J.useState(!1),r=uu(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)(M,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,q.jsx)(ur,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,q.jsx)(i,{className:B(`h-3.5 w-3.5 shrink-0`,r.cls,e.status===`running`&&`animate-spin`)}),(0,q.jsx)(`span`,{className:B(`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:du(e.startedAt)}),fu(e.durationMs)&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:fu(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)(pu,{step:e},`${e.nodeId}#${t}`))})]})]})}function hu({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 cu(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)(xn,{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)(Le,{className:B(`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)(mu,{run:e},e.id))})]})}function gu({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),[x,S]=J.useState(null),C=J.useCallback(()=>{if(!d)return;let e={id:Er(`node`,s.map(e=>e.id).filter(Boolean)),type:`start`,label:`Start`};i({nodes:Tr(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),w=typeof o.name==`string`&&o.name?o.name:``,T=String(o.type??`autolaunched`),E=String(o.status??(o.active?`active`:`draft`)),D=String(o.runAs??`user`),O=o.version==null?void 0:String(o.version),k=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:C,children:[(0,q.jsx)(F,{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)(_u,{icon:Lt,label:`Trigger`,value:T}),(0,q.jsx)(_u,{icon:vn,label:`Status`,value:E,tone:E===`active`?`green`:E===`draft`?`gray`:`amber`}),(0,q.jsx)(_u,{icon:fr,label:`Run as`,value:D}),O&&(0,q.jsx)(_u,{label:`v`,value:O}),k&&(0,q.jsx)(_u,{icon:zt,label:`On error`,value:k}),(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)(Wt,{className:`h-3 w-3`}),` Variables`]}),w&&(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)(b,{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)(De,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(Wl,{nodes:s,edges:c,editable:d,designMode:u,selectedId:f,selectedEdgeId:p,locale:a,activeNodeId:x?.activeNodeId??null,visitedNodeIds:x?.visitedNodeIds,traversedEdgeIds:x?.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)(su,{nodes:s,edges:c,variables:l,onRunStateChange:S})}):v&&w?(0,q.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,q.jsx)(hu,{flowName:w})}):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)(un,{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 _u({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 vu({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)(P,{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)(pe,{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)(Du,{icon:c?Me:Re,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,q.jsx)(Du,{icon:w,label:l}),u.provider&&(0,q.jsx)(Du,{icon:fn,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,q.jsx)(Du,{icon:pn,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,q.jsx)(Du,{label:`max ${u.maxTokens}t`})]})]})]}),(0,q.jsx)(bu,{title:`Instructions`,icon:te,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)(xu,{children:`No system prompt set yet.`})}),(0,q.jsx)(bu,{title:`Capabilities`,icon:ne,children:(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(Cu,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:fn,tone:`violet`,mono:!0}),(0,q.jsx)(Cu,{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:ne,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,q.jsx)(bu,{title:`Knowledge (RAG)`,icon:nt,children:(0,q.jsx)(yu,{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)(wu,{icon:_r,title:`Planning`,children:(0,q.jsx)(Tu,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,q.jsx)(wu,{icon:L,title:`Memory`,children:(0,q.jsx)(Tu,{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)(wu,{icon:_n,title:`Guardrails`,children:(0,q.jsx)(Tu,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,q.jsx)(wu,{icon:w,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 yu({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)(nt,{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 bu({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 xu({children:e}){return(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var Su={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 Cu({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?Su[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:B(`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:B(`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 wu({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 Tu({data:e,keys:t}){let n=t.map(t=>[t,Eu(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 Eu(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function Du({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 Ou(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function ku(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${ku(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Au(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 ju({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=Ou(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]=Au(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Au(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)(P,{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)(ne,{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)(Fu,{icon:gt,label:o}),s&&(0,q.jsx)(Fu,{icon:nt,label:s,mono:!0}),(0,q.jsx)(Fu,{icon:O,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,q.jsx)(Fu,{icon:I,label:`Requires confirmation`,tone:`amber`}),u&&(0,q.jsx)(Fu,{label:`built-in`})]})]})]}),a&&(0,q.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,q.jsx)(Nu,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,q.jsx)(Pu,{children:`This tool takes no input parameters.`}):(0,q.jsx)(Mu,{props:p,required:m})}),Object.keys(p).length>0&&(0,q.jsx)(Nu,{title:`Example LLM Call`,icon:sn,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
|
+
}`})}),Ou(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,q.jsx)(Nu,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:ct,children:(0,q.jsx)(Mu,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Mu({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)(tn,{className:`h-3 w-3 text-emerald-600`}):(0,q.jsx)(ur,{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:ku(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 Nu({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 Pu({children:e}){return(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Fu({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 Iu=[{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 Lu(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 Ru({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(()=>Lu(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)(bn,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,q.jsx)(Qt,{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)(Hu,{icon:D,label:`${d.length} objects`}),(0,q.jsx)(Hu,{icon:gt,label:`${c.length} system perms`}),(0,q.jsx)(Hu,{icon:Me,label:`${Object.keys(l).length} tabs`}),(0,q.jsx)(Hu,{icon:w,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,q.jsxs)(Vu,{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`}),Iu.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}),Iu.map(e=>(0,q.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,q.jsx)(zu,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,q.jsx)(Bu,{})]}),p.size>0&&(0,q.jsx)(Vu,{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)(Vu,{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)(Vu,{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 zu({granted:e,danger:t}){return e?(0,q.jsx)(tn,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,q.jsx)(En,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Bu(){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)(tn,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(tn,{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)(En,{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 Vu({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 Hu({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 Uu(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 Wu(e){switch(e){case`url`:return oe;case`modal`:return Ge;case`flow`:return ir;case`api`:return jt;case`form`:return vt;default:return Ve}}function Gu(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 Ku(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 qu({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Uu(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=Uu(n.confirmText),g=Uu(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,x=n.visible,S=n.disabled,C=Wu(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)(Ju,{label:i,icon:a,variant:c,iconOnly:T,disabled:!!S&&typeof S==`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)(td,{icon:C,label:`type: ${o}`}),b&&(0,q.jsx)(td,{icon:rn,label:`object: ${b}`,mono:!0}),c&&(0,q.jsx)(td,{label:`variant: ${c}`}),l&&(0,q.jsx)(td,{icon:ge,label:l}),d&&(0,q.jsx)(td,{icon:et,label:d,mono:!0}),f&&(0,q.jsx)(td,{icon:nr,label:`bulk`,tone:`green`}),p&&(0,q.jsx)(td,{icon:Le,label:`refresh after`}),m===!1&&(0,q.jsx)(td,{icon:pe,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,q.jsx)(td,{icon:fn,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 x==`string`||x&&typeof x==`object`)&&(0,q.jsx)($u,{label:`Visible when`,value:x,icon:Me}),S!=null&&typeof S!=`boolean`&&(0,q.jsx)($u,{label:`Disabled when`,value:S,icon:w})]}),(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)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,q.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:Ku(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)(ed,{title:`Input Dialog`,count:_.length,children:(0,q.jsx)(Xu,{title:i,params:_,variant:c})}),v&&(0,q.jsx)(ed,{title:`Result Dialog`,icon:Me,children:(0,q.jsx)(Qu,{dialog:v})}),y?.source&&(0,q.jsx)(ed,{title:`Script Body (${y.language??`expression`})`,icon:Ve,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 Ju({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 ${Gu(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,q.jsx)(Yu,{name:t}),!r&&(0,q.jsx)(`span`,{children:e})]})}function Yu({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 Xu({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:[Uu(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})]}),Zu(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 ${Gu(n||`primary`)}`,children:`OK`})]})]})}function Zu(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:Uu(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 Qu({dialog:e}){let t=Uu(e.title)||`Result`,n=Uu(e.description),r=Uu(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:Uu(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 $u({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 ed({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 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`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var nd={"@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 rd(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 id(e){let t=(nd[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=rd(n,0,59),c=rd(r,0,23),l=rd(i,1,31),u=rd(a,1,12),d=rd(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function ad(e,t,n){let r=id(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 od(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 sd(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function cd(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function ld(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?ud(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`?ud(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function ud(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 dd({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}=ld(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?od(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=ad(o,e,5);else if(_)t=sd(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>fd(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)(Bn,{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)(hd,{icon:O,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,q.jsx)(hd,{icon:qe,label:l,mono:!0}),p!=null&&(0,q.jsx)(hd,{icon:ln,label:`retries: ${p}${m?` (${ud(m)} backoff)`:``}`}),h!=null&&(0,q.jsx)(hd,{icon:ft,label:`timeout: ${ud(h)}`}),g!=null&&(0,q.jsx)(hd,{label:`concurrency: ${g}`})]})]})]})}),(0,q.jsx)(md,{title:`Schedule`,icon:Pe,children:(0,q.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,q.jsx)(pd,{label:`Cron`,children:(0,q.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,q.jsxs)(pd,{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)(pd,{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)(md,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:xn,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)(xn,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-mono`,children:cd(e)}),(0,q.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,q.jsx)(md,{title:`Handler`,icon:Ve,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)(Xt,{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 fd(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 pd({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 md({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 hd({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 gd=[{key:`objects`,label:`Objects`,icon:Ie,flat:!1},{key:`apps`,label:`Apps`,icon:wn,flat:!1},{key:`messages`,label:`Messages`,icon:Ye,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Dt,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Mt,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:it,flat:!1},{key:`settings`,label:`Settings`,icon:fr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:Ze,flat:!1}];function _d({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=gd.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/gd.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)(ue,{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)(qe,{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)(pn,{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,`/`,gd.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)(vd,{cat:e},e.key))})]})})})}function vd({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:yd(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 yd(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function bd({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)(E,{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)(St,{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)(Ce,{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)(Qt,{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 xd({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)(fn,{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)(Cd,{icon:O,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,q.jsx)(Cd,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,q.jsx)(Cd,{icon:Qt,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,q.jsx)(Sd,{title:`Instructions`,icon:pt,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)(Sd,{title:`Tools (${s.length})`,icon:ne,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)(Ue,{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)(Sd,{title:`Trigger Phrases (${c.length})`,icon:Pt,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)(Sd,{title:`Trigger Conditions (${l.length})`,icon:Ht,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)(Sd,{title:`Required Permissions`,icon:Qt,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 Sd({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 Cd({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 wd=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Td=d();function Ed(){return``.replace(/\/+$/,``)}function Dd(e){return`${Ed()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function Od(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 wd}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 kd(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await Od(await Td(`${Dd(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Ad(e,t,n={}){return(await Od(await Td(`${Dd(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function jd(e){return(await Od(await Td(`${Dd(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Md(e){return Od(await Td(`${Dd(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Nd(e){await Od(await Td(`${Ed()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Pd({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 Ad(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof wd?`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 Nd(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)(Te,{open:n,onOpenChange:r,children:(0,q.jsxs)(Ke,{className:`max-w-2xl`,children:[(0,q.jsxs)(ot,{children:[(0,q.jsxs)(de,{className:`flex items-center gap-2`,children:[(0,q.jsx)(nt,{className:`h-4 w-4`}),`Import as Object`]}),(0,q.jsxs)(hr,{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)(z,{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)(tn,{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)(T,{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)(k,{children:a===`done`?(0,q.jsx)(R,{onClick:()=>r(!1),children:`Close`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(R,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,q.jsx)(R,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Fd({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 kd(e)),n(`loaded`)}catch(e){e instanceof wd?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)(Id,{}):(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)(Xe,{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)(R,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(Le,{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)(z,{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)(He,{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)(ht,{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)(R,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,q.jsx)(gr,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,q.jsx)(Pd,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Id(){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 Ld={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 Rd({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 Md(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof wd?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)(R,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(Xt,{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)(tn,{className:`h-4 w-4`}):(0,q.jsx)(Dt,{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)(zd,{result:e},e.object))})]})}function zd({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)(Qt,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,q.jsx)(Dt,{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)(Bd,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Bd({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:Ld[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 Vd({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 jd(e))}catch(e){c(e instanceof wd?`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)(dt,{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)(xn,{className:`h-3 w-3`}),`snapshot `,Hd(r.snapshotAt)]}),(0,q.jsxs)(R,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(Le,{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)(Sn,{defaultValue:`tables`,className:`p-3`,children:[(0,q.jsxs)(an,{children:[(0,q.jsx)(Nt,{value:`tables`,children:`Tables`}),(0,q.jsx)(Nt,{value:`validation`,children:`Validation`})]}),(0,q.jsx)(Rn,{value:`tables`,className:`mt-3`,children:(0,q.jsx)(Fd,{datasource:e})}),(0,q.jsx)(Rn,{value:`validation`,className:`mt-3`,children:(0,q.jsx)(Rd,{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 Hd(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Ud=/pass|secret|key|token|credential|auth/i;function Wd(e){return Ud.test(e)}function Gd(e){return e==null||e===``?`∅`:`••••••`}function Kd(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 qd({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)(nt,{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)(Jn,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,q.jsx)(Xd,{icon:O,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,q.jsx)(Xd,{icon:bn,label:`default`,tone:`amber`}),m.length>0&&(0,q.jsx)(Xd,{icon:be,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,q.jsx)(Vd,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,q.jsx)(Yd,{title:`Connection`,icon:w,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=Wd(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:Gd(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`})]}):Kd(t)})]},e)})})})})}),(0,q.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,q.jsx)(Jd,{title:`Pool`,icon:L,value:u}),(0,q.jsx)(Jd,{title:`SSL`,icon:Qt,value:typeof d==`boolean`?{enabled:d}:d}),(0,q.jsx)(Jd,{title:`Retry Policy`,icon:ln,value:f}),(0,q.jsx)(Jd,{title:`Health Check`,icon:L,value:p})]}),h.length>0&&(0,q.jsx)(Yd,{title:`Capabilities`,icon:Qt,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 Jd({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:Wd(e)?Gd(t):Kd(t)})]},e))}):(0,q.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function Yd({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 Xd({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 Zd(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Qd(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:Yn};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:Mn}}}function $d({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=Qd(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)(Dt,{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)(rf,{icon:O,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,q.jsx)(rf,{label:`object: ${s}`,mono:!0}),f!=null&&(0,q.jsx)(rf,{label:`priority ${f}`}),d.length>0&&(0,q.jsx)(rf,{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)(ef,{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 ef({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,q.jsx)(nf,{title:`Condition`,icon:Ve,children:(0,q.jsx)(tf,{value:Zd(t.condition)??Zd(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=Zd(t.scope)??Zd(t.where);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(nf,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Qn,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)(nf,{title:`Scope`,icon:kn,children:(0,q.jsx)(tf,{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)(nf,{title:`Transitions${r?` on ${r}`:``}`,icon:ir,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)(Gn,{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)(nf,{title:`Format`,icon:je,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=Zd(t.condition);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(nf,{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)(nf,{title:`Cross-field condition`,icon:Ve,children:(0,q.jsx)(tf,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,q.jsx)(nf,{title:`Async endpoint`,icon:qe,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)(nf,{title:`Custom handler`,icon:Ve,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)(nf,{title:`Rule`,icon:Dt,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 tf({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 nf({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 rf({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 af=J.lazy(()=>o(()=>import(`./plugin-charts-DhlEvpuy.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function of(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 sf({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)(Is,{icon:(0,q.jsx)(cn,{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)(Is,{icon:(0,q.jsx)(cn,{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)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(cn,{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)(Is,{icon:(0,q.jsx)(cn,{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)(z,{className:`h-4 w-4 animate-spin`})}),children:(0,q.jsx)(`div`,{className:`rounded-md border p-2`,children:(0,q.jsx)(af,{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:of(e[t])},t))},t))})]})})]})})}function cf(){Y(`page`,bc),Y(`view`,Tc),Y(`dashboard`,Dc),Y(`report`,Ac),Y(`app`,Uc),Y(`action`,qu),Y(`object`,ul),Y(`datasource`,qd),Y(`validation`,$d),Y(`dataset`,sf),Y(`email_template`,ml),Y(`translation`,_d),Y(`flow`,gu),Y(`job`,dd),Y(`agent`,vu),Y(`tool`,ju),Y(`skill`,xd),Y(`permission`,Ru),Y(`profile`,Ru),Y(`role`,bd)}function $(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function lf(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var uf=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),df={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:uf,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:[lf(`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`}),lf(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),lf(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),lf(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),lf(`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:[lf(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),lf(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),lf(`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:[lf(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),lf(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),lf(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),lf(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),lf(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),lf(`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`})]},ff={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 pf(e){return e?df[ff[e]??e]??[]:[]}function mf(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 hf(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function gf(e,t,n){if(!e.showWhen)return!0;let r=mf(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=mf(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 _f=[`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`],vf=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function yf(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`&&vf.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&vf.has(t.kind))return{kind:t.kind,...n}}function bf(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 xf(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Sf(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 Cf(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:bf(e)}))}function wf(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 Tf(e){if(Array.isArray(e.enum))return`select`;let t=Sf(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function Ef(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!xf(r))continue;let t=Sf(r),i,a,o=yf(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=Cf(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||bf(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function Df(e,t){return{label:e.title||bf(t),...e.description?{help:e.description}:{},...wf(e)?{defaultValue:wf(e)}:{}}}function Of(e){if(!xf(e)||Sf(e)!==`object`||!xf(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!xf(r))continue;let e=Sf(r);if(e===`array`){let e=xf(r.items)?r.items:void 0,i=e?Sf(e):void 0;e&&i===`object`&&xf(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:Ef(e),...Df(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...Df(r,n)});continue}if(e===`object`&&xf(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>xf(e)),i=e.some(([e,t])=>e===`enabled`&&Sf(t)===`boolean`);for(let[a,o]of e){let e=o,s=yf(e),c=s?`reference`:Tf(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||bf(n),...r.description?{help:r.description}:{},...wf(e)?{defaultValue:wf(e)}:{}}:Df(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:Cf(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=yf(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...Df(r,n)});continue}let a=Tf(r);a&&t.push({id:n,path:[`config`,n],kind:a,...Df(r,n),...a===`select`&&Array.isArray(r.enum)?{options:Cf(r.enum)}:{}})}return t}function kf(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Af(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function jf(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 Mf(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=Er(`kv`,n);return n.push(r),{id:r,key:e,raw:Af(t)}})}function Nf(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=jf(n.raw))}return t}function Pf(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function Ff({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=kf(t)?t:{},[d,f]=J.useState(()=>Mf(u,[])),p=J.useRef(Pf(u));J.useEffect(()=>{let e=Pf(u);e!==p.current&&(f(Mf(u,[])),p.current=e)},[u]);let m=e=>{let t=Nf(e);p.current=Pf(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:Er(`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)(H,{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)(V,{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)(V,{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)(R,{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)(Qe,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,q.jsxs)(R,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,q.jsx)(F,{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 If(e,t){let n=[...t];return e.map(e=>{let t=Er(`sl`,n);return n.push(t),{id:t,value:e}})}function Lf(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Rf({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(()=>If(c,[])),d=J.useRef(JSON.stringify(c));J.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(If(c,[])),d.current=e)},[c]);let f=e=>{let t=Lf(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:Er(`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)(H,{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)(V,{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)(R,{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)(Qe,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,q.jsxs)(R,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,q.jsx)(F,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var zf={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function Bf(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 Vf(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 Hf(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Vf((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Vf(n.node,r)}function Uf(e){let t=Cr(),[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 Wf({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?Hf(e.kind,e.objectSource,l):void 0,{fields:f}=wi(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?zf[u]:void 0,{options:m}=Uf(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)(V,{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 Gf({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Bf(e.ref,e=>Vf(a,e));return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(H,{className:`text-xs text-muted-foreground`,children:e.label}),(0,q.jsx)(Wf,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function Kf(e,t){let n=[];return e.map(e=>{let r=Er(`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 qf(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 Jf({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(()=>Kf(l,t)),f=J.useRef(JSON.stringify(l));J.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(Kf(l,t)),f.current=e)},[l,t]);let p=e=>{let n=qf(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:Er(`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)(H,{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)(R,{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)(Qe,{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)(H,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,q.jsx)(Se,{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)(Wf,{resolved:Bf(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)(V,{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)(R,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,q.jsx)(F,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var Yf=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function Xf(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 Zf(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.`};Xf(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=Yf.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=Yf.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\`).`}:Xf(n,`(`,`)`)?Xf(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function Qf({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){let o=(()=>{switch(e.kind){case`reference`:return(0,q.jsx)(Gf,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,q.jsx)(Ff,{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)(Rf,{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)(Jf,{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)(Or,{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)(jr,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,q.jsx)(Mr,{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)(H,{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`?Zf(`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 $f(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function ep(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=ep(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function tp({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=Bl(),u=J.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:Of(e))??pf(c?.type)},[l,c?.type]),d=$f(c),f=u.filter(e=>gf(e,c,u)),p=J.useMemo(()=>{let e=new Set;for(let t of u){let n=hf(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)(Ar,{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)(zr,{message:e.id})});let C=e=>{n({nodes:K(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:K(o,s,ep(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=_f.includes(c.type)?[..._f]:[..._f,c.type??``].filter(Boolean);return(0,q.jsxs)(Ar,{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)(kr,{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)(Mr,{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)(Qf,{field:e,value:mf(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)(F,{className:`h-3 w-3`}),G(`engine.inspector.flowNode.advanced`,i)]})]})}function np({label:e,value:t}){return(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(H,{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 rp({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)=>Cl(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,q.jsx)(Ar,{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)(zr,{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)(Ar,{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)(kr,{label:G(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:K(o,s,null)}),r()},disabled:a}),children:[(0,q.jsx)(np,{label:G(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,q.jsx)(np,{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:wl(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:Zf(`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)(jr,{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 ip(e){return e.selection.kind===`edge`?(0,q.jsx)(rp,{...e}):(0,q.jsx)(tp,{...e})}var ap=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function op(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 sp(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 cp(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 lp(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 up({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=op(e.id),{node:c,parent:l,index:u}=s?sp(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,q.jsx)(Ar,{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)(zr,{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(cp(t,s,{...c,...e}))};return(0,q.jsxs)(Ar,{kindLabel:G(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:G(`engine.inspector.appNav.close`,a),headerActions:(0,q.jsx)(Fr,{index:u,total:l.length,onMove:e=>{n(lp(t,s,Br(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)(kr,{label:G(`engine.inspector.appNav.remove`,a),onClick:()=>{n(cp(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)(Mr,{label:G(`engine.inspector.appNav.kindField`,a),value:c.kind,options:ap.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var dp=[`field`,`label`,`accessorKey`,`header`];function fp(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function pp(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function mp(e){return e.field??e.accessorKey??``}function hp(e){return e.label??e.header??mp(e)}function gp(e){return Object.keys(e).some(e=>!dp.includes(e))}function _p(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function vp({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=fp(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(pp),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=J.useMemo(()=>Vi(),[]),m=_p(c),{fields:h}=wi(m||void 0),g=d?mp(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)(Ar,{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)(zr,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=mp(e);return n&&!gp(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)(Ar,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:hp(d)||e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),headerActions:(0,q.jsx)(Fr,{index:s.index,total:u.length,onMove:e=>{v(Br(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:hp(d)||`columns[${e}]`})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,q.jsx)(kr,{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)(ji,{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)(Mr,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:mp(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,q.jsx)(W,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:mp(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,q.jsx)(W,{label:G(`engine.inspector.viewColumn.header`,a),value:hp(d)===mp(d)?``:hp(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,q.jsx)(`div`,{className:`border-t pt-3`,children:(0,q.jsx)(Nr,{schema:p,value:d,hiddenFields:dp,readOnly:o,onChange:e=>{v(K(u,s.index,e))}})}):null]})]})}function yp(e){let{selection:t}=e;if(t.kind===`column`)return(0,q.jsx)(vp,{...e});let n=Xi(e.draft,t.id||void 0)??Yi(e.draft);return(0,q.jsx)(ra,{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 bp(e){let t=Yi(e.draft);return(0,q.jsx)(ra,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var xp=e=>(e??``).toLowerCase().startsWith(`zh`);function Sp(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 Cp(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function wp(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Tp(e){return e===`formula`||e===`summary`}function Ep(e){return e===`number`||e===`currency`||e===`percent`}function Dp(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Op(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 kp(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?Wr:Kr;return Gr.flatMap(e=>e.types.map(r=>{let i=Xr[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function Ap({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(()=>kp(o),[o]),l=J.useMemo(()=>oi(t.fields),[t]),u=String(e.id),d=ci(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=Ip();if(!f)return(0,q.jsx)(Ar,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,q.jsx)(zr,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=Xr[g],v=e=>{n({fields:si(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=di(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:Br(l.entries,d,e)})},w=Sp(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)(R,{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)(be,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(Fr,{index:d,total:l.entries.length,onMove:C,disabled:a})]}),D=(0,q.jsx)(kr,{label:U(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:x,disabled:a}),O=xp(o)?_?.labelZh:_?.label;return(0,q.jsxs)(Ar,{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)(jp,{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)(Mr,{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)(jr,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,q.jsx)(jr,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,q.jsx)(Np,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),Op(g)&&(0,q.jsx)(Mp,{kind:Op(g),value:h.defaultValue,options:w,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,q.jsx)(Np,{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`)})]}),(Cp(g)||wp(g)||Tp(g)||Ep(g)||Dp(g))&&(0,q.jsxs)(jp,{title:U(`designer.field.section.options`,o,{type:O??g}),children:[Cp(g)&&(0,q.jsx)(Fp,{options:w,onChange:T,disabled:a,locale:o}),wp(g)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Pp,{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`)})]}),Tp(g)&&(0,q.jsx)(Np,{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`}),Ep(g)&&(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(Or,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,q.jsx)(Or,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,q.jsx)(Or,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,q.jsx)(Or,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),Dp(g)&&(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(Or,{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)(Or,{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)(jp,{title:s(`designer.field.section.advanced`),children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsx)(jr,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,q.jsx)(jr,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,q.jsx)(jr,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,q.jsx)(jr,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,q.jsx)(jr,{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)(Mr,{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 jp({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 Mp({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)(Mr,{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)(Or,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,q.jsx)(Mr,{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 Np({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)(H,{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 Pp({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)(H,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(V,{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 Fp({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(Br(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)(H,{className:`text-xs text-muted-foreground`,children:G(`designer.field.picklistValues`,r)}),(0,q.jsx)(S,{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)(V,{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)(V,{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)(R,{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)(Tt,{className:`h-3 w-3`})}),(0,q.jsx)(R,{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)(nn,{className:`h-3 w-3`})}),(0,q.jsx)(R,{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)(Qe,{className:`h-3 w-3`})})]},s))}),!n&&(0,q.jsxs)(R,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,q.jsx)(F,{className:`h-3 w-3`}),G(`designer.field.addValue`,r)]})]})}function Ip(){let e=Cr(),[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 Lp({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=di(e)),n(t)},u=e=>{c.current=!0,n({name:di(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,q.jsx)(Ar,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,q.jsxs)(Rp,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,q.jsx)(zp,{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)(zp,{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)(H,{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 Rp({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 zp({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 Bp=[{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`}],Vp=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}];function Hp({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)(H,{className:`text-xs text-muted-foreground`,children:e}),(0,q.jsx)(S,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,q.jsxs)(R,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,q.jsx)(F,{className:`h-3 w-3`}),` `,r]})]})}function Up({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)(Ar,{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)(Hp,{title:`Included relationships`,count:o.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:Tr(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)(V,{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)(R,{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)(Qe,{className:`h-3.5 w-3.5`})})]},r))]}),(0,q.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,q.jsx)(Hp,{title:`Dimensions`,count:s.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:Tr(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)(kr,{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)(Mr,{label:`Type`,value:e.type,options:Vp,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)(Hp,{title:`Measures`,count:c.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:Tr(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)(kr,{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)(Mr,{label:`Aggregate`,value:e.aggregate,options:Bp,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)(jr,{label:`Certified`,value:!!e.certified,onCommit:e=>u(r,{certified:e}),disabled:n})]},r))]})]})}function Wp(){Io(`dashboard`,ti),zo(`dashboard`,$r),Io(`flow`,ip),Io(`app`,up),Io(`view`,yp),zo(`view`,bp),Io(`page`,oc),zo(`report`,Zr),Io(`object`,Ap),zo(`object`,Lp),zo(`dataset`,Up)}var Gp=t({MetadataDiagnosticsPage:()=>Es,MetadataDirectoryPage:()=>ca,MetadataResourceEditPage:()=>bs,MetadataResourceHistoryPage:()=>Eo,MetadataResourceListPage:()=>Ga,StudioHomePage:()=>ka});js(),Fs(),cf(),Wp();export{ba as a,Gi as c,Ba as i,ai as l,Os as n,ca as o,ws as r,ra as s,Gp as t};
|