@objectstack/console 9.9.0 → 9.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{ApiConsolePage-CPV6vWpt.js → ApiConsolePage-B6QExly9.js} +1 -1
- package/dist/assets/{AppDocsIndex-D4Y3i2rM.js → AppDocsIndex-S-ilhz4W.js} +1 -1
- package/dist/assets/{AppManagementPage-CLiHbNPr.js → AppManagementPage-JgLQ-wXj.js} +1 -1
- package/dist/assets/{ConsoleFloatingChatbot-CXwRB3yg.js → ConsoleFloatingChatbot-D13eK4M8.js} +1 -1
- package/dist/assets/{DashboardView-BF0o0wgx.js → DashboardView-P--eXDC-.js} +1 -1
- package/dist/assets/{DashboardWidgetInspector-DIMge0qc.js → DashboardWidgetInspector-VPDtQEP_.js} +1 -1
- package/dist/assets/{FlowRunsPage-CJDL4g0k.js → FlowRunsPage-CCS9xNVc.js} +1 -1
- package/dist/assets/{InterfaceListPage-DZpFSsQf.js → InterfaceListPage-B3jzgT27.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-BWCVUz3e.js → MarketplacePackagePage-DOZgrTZo.js} +1 -1
- package/dist/assets/{MetadataProvider-CEw2X-qL.js → MetadataProvider-Bja7m8Gt.js} +1 -1
- package/dist/assets/{PageView-CP-3dRzz.js → PageView-My4nP5w4.js} +1 -1
- package/dist/assets/{PublicFormsPage-D7D2WWL7.js → PublicFormsPage-CcRFrTQC.js} +1 -1
- package/dist/assets/{RecordDetailView-BdQK61l2.js → RecordDetailView-CMIRy42W.js} +1 -1
- package/dist/assets/{RecordFormPage-lFVOsTl0.js → RecordFormPage-BUfFijzM.js} +1 -1
- package/dist/assets/{ReportDefaultInspector-GD1EQSTh.js → ReportDefaultInspector-C8gR3RMr.js} +1 -1
- package/dist/assets/{ReportView-BHtzV5eK.js → ReportView-DSrtPxzA.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-DXwH4Hvd.js → RuntimeDraftBar-B2fJIAhv.js} +1 -1
- package/dist/assets/{SearchResultsPage-CE_LTSSU.js → SearchResultsPage-C7i-b3gn.js} +1 -1
- package/dist/assets/{SystemHubPage-DjNBraYu.js → SystemHubPage-DWGnZfF0.js} +1 -1
- package/dist/assets/{index-DdQV1cqi.js → index-BgnAjV6_.js} +2 -2
- package/dist/assets/{mergeServerFields-djmY7AgR.js → mergeServerFields-zZ2r6yTA.js} +1 -1
- package/dist/assets/{metadata-admin-BbJpmVQm.js → metadata-admin-BgoJzjrj.js} +1 -1
- package/dist/assets/plugin-form-DXCdD2d-.js +1 -0
- package/dist/assets/{plugin-view-DhNkNfUe.js → plugin-view-D58aYgqA.js} +1 -1
- package/dist/assets/{resolveActionParams-C_x4GXvS.js → resolveActionParams-xmwfLvud.js} +1 -1
- package/dist/assets/{src-Bzm5L_v8.js → src-DXFkWHTV.js} +1 -1
- package/dist/assets/{useActionModal-DDu3wUOI.js → useActionModal-DsVCm46J.js} +1 -1
- package/dist/assets/{useReconcileOnError-Agbi2njU.js → useReconcileOnError-D6sIYKrb.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/dist/assets/plugin-form-gQDKenio.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,a as r,f as i,l as a,m as o,p as s,r as c,t as l,u}from"./vendor-react-DR370ovB.js";import{m as d}from"./infrastructure-CJNwTVno.js";import{B as f,ct as p,w as m}from"./framework-BLEk-ou3.js";import{R as h,_ as g,d as _,p as v}from"./vendor-objectstack-BNd856rx.js";import{$ as y,$n as b,$o as x,$s as S,$t as C,Ai as w,Ar as T,Bn as E,Bo as D,Bs as O,Bt as k,Ca as A,Ci as j,Co as ee,Cr as te,Da as ne,Di as re,Do as ie,Ds as M,Fa as ae,Fi as oe,Fo as se,Fs as ce,Ft as le,Gi as ue,Go as de,Gr as fe,Gs as pe,H as me,Ha as he,Hi as ge,Hn as _e,Ht as ve,Ia as ye,Io as be,Ir as xe,It as Se,Ja as Ce,Ji as we,Js as Te,Jt as Ee,Kn as De,Ks as Oe,L as ke,La as Ae,Ln as je,Lo as Me,Lr as Ne,Ls as Pe,Lt as Fe,Ma as N,Mi as Ie,Mo as Le,Mt as Re,Na as ze,Nr as Be,Oa as Ve,Os as He,Pi as Ue,Po as We,Pr as Ge,Pt as Ke,Qa as qe,Qi as Je,Qo as Ye,Qr as Xe,R as Ze,Rn as Qe,Rr as P,Rt as $e,Sa as et,Si as tt,So as nt,Sr as rt,Ta as it,Ti as at,To as ot,Ts as st,Ua as ct,Ui as F,Uo as lt,Us as ut,Ut as dt,Va as ft,Vi as I,Vn as pt,Vr as mt,Vs as ht,Vt as gt,Wa as _t,Wi as vt,Wo as L,Wr as yt,Ws as bt,Wt as xt,Xa as St,Xi as Ct,Xo as wt,Xr as Tt,Ya as Et,Yo as Dt,Yt as Ot,Zo as kt,_i as At,_r as jt,ac as Mt,at as Nt,ba as Pt,bi as Ft,br as It,bs as Lt,ca as Rt,cc as R,co as zt,ct as Bt,da as Vt,dc as Ht,di as Ut,dt as Wt,ea as Gt,en as Kt,eo as qt,et as Jt,fc as Yt,fi as Xt,fo as Zt,ft as Qt,gi as $t,go as en,gs as tn,ha as nn,hi as rn,ho as an,hr as z,hs as on,ia as sn,ii as cn,io as ln,it as un,ja as dn,jo as fn,ko as pn,kr as mn,li as hn,lo as gn,lt as _n,ma as vn,mi as yn,mo as bn,ms as xn,na as Sn,nc as Cn,ni as wn,nn as B,no as Tn,nt as En,on as V,oo as Dn,os as On,ot as kn,pc as H,pi as An,po as jn,ps as Mn,qo as Nn,qt as Pn,ra as Fn,rs as In,rt as Ln,sa as Rn,sc as zn,si as Bn,so as Vn,ss as Hn,st as Un,ta as Wn,tc as Gn,ti as Kn,tn as qn,to as Jn,ua as Yn,uc as Xn,uo as Zn,us as Qn,ut as $n,va as er,vo as tr,vr as nr,wa as rr,wi as ir,wr as ar,ws as or,xa as sr,xi as cr,xo as lr,xr as ur,ya as dr,yi as fr,yo as pr,yr as mr,ys as hr,z as gr,za as _r,zn as vr,zo as yr,zt as br}from"./ui-components-CrPYFyEM.js";import{r as xr}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-DJb3ZVmJ.js";import{o as Sr,r as Cr}from"./MetadataProvider-CEw2X-qL.js";import{n as wr}from"./RecentItemsProvider-B76qldBH.js";import{C as Tr,S as Er,_ as Dr,a as U,b as Or,c as kr,d as Ar,f as jr,g as W,h as Mr,i as G,l as Nr,m as Pr,n as Fr,o as Ir,p as Lr,r as Rr,s as zr,t as Br,u as Vr,v as Hr,w as Ur,x as Wr,y as K}from"./mergeServerFields-djmY7AgR.js";import{t as Gr}from"./InterfaceListPage-DZpFSsQf.js";import{a as Kr,c as qr,i as Jr,n as Yr,o as Xr,r as Zr,s as Qr,t as $r}from"./ReportDefaultInspector-GD1EQSTh.js";import{i as ei,n as ti,r as ni,t as ri}from"./DashboardWidgetInspector-DIMge0qc.js";var q=l(),J=e(n(),1);function ii(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var ai=new Set(Jt),oi=new Map;function si(e){if(!e)return L;let t=oi.get(e);if(t)return t;let n=ii(e);if(!ai.has(n))return oi.set(e,L),L;let r=e=>J.createElement(y,{name:n,fallback:L,...e});return r.displayName=`LucideIcon(${e})`,oi.set(e,r),r}function ci(e){return Array.isArray(e)?{shape:`array`,entries:e.map((e,t)=>{let{name:n,...r}=e??{};return{name:typeof n==`string`&&n?n:`field_${t+1}`,def:r}})}:e&&typeof e==`object`?{shape:`record`,entries:Object.entries(e).map(([e,t])=>({name:e,def:{...t??{}}}))}:{shape:`record`,entries:[]}}function li(e){if(e.shape===`array`)return e.entries.map(e=>({name:e.name,...e.def}));let t={};for(let n of e.entries)t[n.name]=n.def;return t}function ui(e,t){return e.entries.findIndex(e=>e.name===t)}function di(e,t,n){let r={type:t,label:n??fi(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function fi(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function pi(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/_{2,}/g,`_`);return t?/^[a-z_]/.test(t)?t:`f_${t}`:`field`}function mi(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:``})).filter(e=>e.key):[]}function hi(e,t){let n=/[a-z0-9]/i.test(e)?pi(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function gi(e,t){let n=t.trim()||`New section`,r=hi(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function _i(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function vi(e,t){return e.filter(e=>e.key!==t)}function yi(e,t,n){let r=e.findIndex(e=>e.key===t);if(r<0)return e;let i=r+n;return i<0||i>=e.length?e:xi(e,r,i)}function bi(e,t){return{shape:e.shape,entries:e.entries.map(e=>e.def.group===t?{name:e.name,def:{...e.def,group:void 0}}:e)}}function xi(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function Si(e,t,n){let r=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],i=new Map;for(let e of r)i.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let a=new Set(r.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&a.has(e)?i.get(e).entries.push(t):(i.has(null)||i.set(null,{key:null,label:`Ungrouped`,entries:[]}),i.get(null).entries.push(t))}let o=!!n?.includeEmptyDeclared;return Array.from(i.values()).filter(e=>e.entries.length>0||o&&e.key!==null)}function Ci(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function wi(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)Ci(e[i],t[i])||r.push(i);return r.sort()}function Ti(e,t){let n=ci(e),r=ci(t),i=new Map(n.entries.map(e=>[e.name,e])),a=new Set(r.entries.map(e=>e.name)),o={},s=0,c=0;for(let e of r.entries){let t=i.get(e.name);if(!t){o[e.name]={name:e.name,status:`added`,changedKeys:[]},s+=1;continue}let n=wi(t.def,e.def);n.length?(o[e.name]={name:e.name,status:`changed`,changedKeys:n},c+=1):o[e.name]={name:e.name,status:`unchanged`,changedKeys:[]}}let l=n.entries.filter(e=>!a.has(e.name));return{byName:o,removed:l,counts:{added:s,changed:c,removed:l.length}}}function Ei(e,t){let n=Tr(),[r,i]=J.useState({fields:[],loading:!t&&!!e,error:null});return J.useEffect(()=>{if(t){i({fields:t,loading:!1,error:null});return}if(!e){i({fields:[],loading:!1,error:null});return}let r=!1;return i(e=>({...e,loading:!0,error:null})),n.get(`object`,e).then(e=>{if(!r){if(!e){i({fields:[],loading:!1,error:`Object not found`});return}i({fields:ci(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`&&e.def.label?e.def.label:e.name,type:typeof e.def.type==`string`?e.def.type:`text`,hidden:e.def.hidden===!0})),loading:!1,error:null})}}).catch(e=>{r||i({fields:[],loading:!1,error:e?.message??String(e)})}),()=>{r=!0}},[n,e,t]),r}function Di(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function Oi(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function ki(e){let t=new Set;for(let n of e){let e=Oi(n);e&&t.add(e)}return t}function Ai(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function ji(e,t){return e===t?null:e>t?e-1:e}function Mi(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Ni({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=Ei(i||void 0,a),m=J.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=J.useState(null),[_,v]=J.useState(null),y=J.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),x=J.useCallback(t=>{let i=Dr(n,Ai(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),S=J.useCallback(t=>{let r=K(n,t,null);if(y(r),o!=null){let n=ji(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(r[n],n)})}},[n,y,o,e,l]),C=J.useCallback((t,r)=>{if(t===r)return;let i=Hr(n,t,r);if(y(i),o!=null){let n=Mi(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(i[n],n)})}},[n,y,o,e,l]),w=J.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Di(n[t],t)})},[n,e,l]),T=ki(n);return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,q.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,q.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,q.jsx)(Zr,{index:t,label:Di(e,t),fieldName:Oi(e),fieldType:m.get(Oi(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>w(t),onRemove:()=>S(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&C(h,t),g(null),v(null)}},t))}),u&&(0,q.jsx)(Yr,{fields:d,usedNames:T,loading:f,error:p,onAdd:x})]})}var Pi={io:`input`,unrepresentable:`any`},Fi=new Set([`columns`,`data`,`name`]),Ii,Li=!1;function Ri(){if(Ii||Li)return Ii;try{Ii=h(v,Pi)}catch(e){Li=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return Ii}function zi(){return Ri()?.properties?.list}function Bi(){return Ri()?.properties?.form}var Vi,Hi=!1;function Ui(){if(Vi||Hi)return Vi;try{Vi=h(_,Pi)}catch(e){Hi=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Vi}var Wi;function Gi(){if(Wi)return Wi;if(!(!g||typeof g!=`object`)){try{let e=JSON.parse(JSON.stringify(g));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Fi.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Wi=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Wi}}var Ki=new Set([`form`,`detail`]);function qi(e){return Ki.has(e)}function Ji(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Yi(e,t){return typeof e==`string`&&Ki.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Ki.has(t)?`form`:`list`}function Xi(e){let t=e.config;return Ji(t)?[{storeKey:`config`,familyKey:Yi(e.viewKind,t.type),schema:t}]:[]}function Zi(e){return Xi(e)[0]}function Qi(e,t){return Zi(e)}var $i=new Set([`type`,`object`,`label`,`columns`]),ea={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function ta(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?ea[e]??e:r}var na=[`columns`,`data`,`name`];function ra(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function ia(e,t){return J.useMemo(()=>{let n=zi()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:ta(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:ta(e,t)}),r},[e,t])}function aa({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=qi(n??t),p=typeof d.type==`string`?d.type:`grid`,m=ia(p,l),h=ra(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=Ei(h.value||void 0,c),b=J.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),x=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:S,form:C}=J.useMemo(()=>Br({bundledSchema:f?Bi():zi(),bundledForm:f?void 0:Gi(),serverSchema:x,excludeFields:$i,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:G(`engine.inspector.view.close`,l),hideClose:r,children:[(0,q.jsx)(W,{label:G(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:G(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,q.jsx)(Pr,{label:G(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,q.jsx)(W,{label:G(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:G(`engine.inspector.view.objectPlaceholder`,l),disabled:a,mono:!0}),!f&&(0,q.jsx)(`div`,{className:`border-t pt-3`,children:(0,q.jsx)(Ni,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,q.jsx)(`div`,{className:`border-t pt-3`,children:S?(0,q.jsx)(Fr,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of na)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.view.noSchema`,l)})})]})}function oa({appSlug:e}={}){let t=u(),n=Tr(),{entries:r}=Ur(n),[i,a]=J.useState(!1),[o,s]=J.useState(``),[c,l]=J.useState(null),[d,f]=J.useState(!1),[p,m]=J.useState(0),h=J.useMemo(()=>Rr(),[]);J.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),a(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),J.useEffect(()=>{if(!i||c!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||l(t)}finally{e||f(!1)}})(),()=>{e=!0}},[i,c,d,r,n]);let g=J.useMemo(()=>{let e=o.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||zr(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(c??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[o,r,c]);J.useEffect(()=>{m(0)},[o,i]);function _(n){a(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,q.jsx)(je,{open:i,onOpenChange:a,children:(0,q.jsxs)(Qe,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,q.jsx)(pt,{className:`sr-only`,children:(0,q.jsx)(_e,{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)(tt,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(B,{autoFocus:!0,placeholder:G(`engine.quickfind.placeholder`,h),value:o,onChange:e=>s(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,q.jsx)(ke,{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)(N,{className:`h-3.5 w-3.5 animate-spin`}),G(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:G(`engine.quickfind.noMatches`,h)}),(0,q.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`text-sm font-medium truncate`,children:zr(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,q.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,q.jsx)(dn,{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)(ke,{children:`↑`}),` `,(0,q.jsx)(ke,{children:`↓`}),` navigate`]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(ke,{children:`↵`}),` open`]}),(0,q.jsxs)(`span`,{className:`ml-auto`,children:[(0,q.jsx)(ke,{children:`⌘`}),(0,q.jsx)(ke,{children:`⇧`}),(0,q.jsx)(ke,{children:`M`}),` toggle`]})]})]})})}var sa={data:L,ui:ft,automation:ar,ai:hn,system:Ft,platform:Ft,identity:$t,security:$t},ca=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],la=new Set([`field`,`package`]);function ua(){let e=Tr(),{loading:t,error:n,entries:r}=Ur(e),i=J.useMemo(()=>Rr(),[]),[a,o]=J.useState(``),[l,u]=J.useState(`all`),[d,f]=J.useState(!1),[p,m]=s(),[h,g]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),g(i.map(e=>({id:e.id,name:e.name})))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=J.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);J.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Er(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>la.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[r,v,w]),D=J.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(a){let t=a.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||zr(e.type,i,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=J.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=ca.indexOf(e),r=ca.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,q.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:G(`engine.directory.loading`,i)}):n?(0,q.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[G(`engine.directory.loadFailed`,i),`: `,n]}):(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:G(`engine.directory.title`,i)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:U(`engine.directory.description`,i,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,q.jsx)(tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.directory.search`,i),value:a,onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(z,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,i),` (`,O,`)`]}),x.total>0&&(0,q.jsx)(z,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,q.jsxs)(c,{to:`./_diagnostics`,children:[(0,q.jsx)(P,{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)(ke,{children:`⌘`}),(0,q.jsx)(ke,{children:`⇧`}),(0,q.jsx)(ke,{children:`M`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,q.jsx)(da,{domain:`all`,label:G(`engine.directory.all`,i),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),ca.filter(e=>D[e]).map(e=>(0,q.jsx)(da,{domain:e,label:Ir(e,i),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:G(`engine.directory.noMatches`,i)}),(0,q.jsx)(gr,{children:G(`engine.directory.noMatchesHint`,i)})]}),A.map(([e,t])=>(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,q.jsx)(sa[e]??pe,{className:`h-3.5 w-3.5`}),Ir(e,i),` (`,t.length,`)`]}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,q.jsx)(fa,{entry:e,locale:i,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,q.jsx)(oa,{})]})}function da({domain:e,label:t,active:n,count:r,onClick:i}){return(0,q.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,q.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function fa({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=zr(e.type,t,e.label);return(0,q.jsxs)(c,{to:o?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(o)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(n>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[n>0&&(0,q.jsx)(`span`,{title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,q.jsx)(P,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),s]}),(0,q.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,q.jsx)(b,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:U(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:U(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),a>0&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${a} locked item${a===1?``:`s`} — see ADR-0010`,"aria-label":`${a} locked items`,children:[(0,q.jsx)(dn,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,t)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var pa=`/api/v1/packages`;async function ma(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function ha({scope:e}){let t=J.useMemo(()=>Rr(),[]),n=e??`project`,r=n===`project`?`default`:n===`system`?`secondary`:`outline`,i=n===`project`?`engine.packages.scope.project`:n===`system`?`engine.packages.scope.system`:n===`cloud`?`engine.packages.scope.cloud`:``;return(0,q.jsx)(b,{variant:r,children:i?G(i,t):n})}function ga({pkg:e}){let t=J.useMemo(()=>Rr(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,q.jsx)(b,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var _a=/^[a-z0-9][a-z0-9._-]{1,254}$/i,va=/^\d+\.\d+\.\d+$/;function ya({open:e,onOpenChange:t,onCreated:n}){let r=J.useMemo(()=>Rr(),[]),[i,a]=J.useState(``),[o,s]=J.useState(``),[c,l]=J.useState(`0.1.0`),[u,d]=J.useState(!1),[f,p]=J.useState(null);J.useEffect(()=>{e&&(a(``),s(``),l(`0.1.0`),p(null),d(!1))},[e]);let m=_a.test(i),h=va.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await ma(pa,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:i.trim(),name:o.trim(),version:c.trim(),type:`app`,scope:`project`}})}),n(i.trim()),t(!1)}catch(e){p(e?.message??G(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,q.jsx)(je,{open:e,onOpenChange:t,children:(0,q.jsxs)(Qe,{children:[(0,q.jsxs)(pt,{children:[(0,q.jsx)(_e,{children:G(`engine.packages.create.title`,r)}),(0,q.jsx)(vr,{children:U(`engine.packages.create.description`,r,{example:`com.acme.crm`})})]}),(0,q.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-id`,children:G(`engine.packages.create.id`,r)}),(0,q.jsx)(B,{id:`pkg-id`,placeholder:`com.acme.crm`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!!i&&!m}),!!i&&!m&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.idInvalid`,r)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-name`,children:G(`engine.packages.create.name`,r)}),(0,q.jsx)(B,{id:`pkg-name`,placeholder:`Acme CRM`,value:o,onChange:e=>s(e.target.value)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-version`,children:G(`engine.packages.create.version`,r)}),(0,q.jsx)(B,{id:`pkg-version`,placeholder:`0.1.0`,value:c,onChange:e=>l(e.target.value),"aria-invalid":!!c&&!h}),!!c&&!h&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.versionInvalid`,r)})]}),f&&(0,q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,q.jsx)(P,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{children:f})]})]}),(0,q.jsxs)(E,{children:[(0,q.jsx)(z,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:G(`engine.cancel`,r)}),(0,q.jsx)(z,{onClick:_,disabled:!g,children:G(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function ba({label:e,children:t}){return(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function xa({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=J.useMemo(()=>Rr(),[]),[o,s]=J.useState(null),[l,u]=J.useState(null),[d,f]=J.useState(null);if(J.useEffect(()=>{u(null),s(null)},[e?.manifest.id]),J.useEffect(()=>{let t=e?.manifest.id;if(!n||!t){f(null);return}let r=!1;return ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{r||f(e?.drafts??[])}).catch(()=>{r||f([])}),()=>{r=!0}},[n,e?.manifest.id]),!e)return null;let p=e.manifest.id,m=e.enabled!==!1&&e.status!==`disabled`,h=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function g(e,t,n){s(e),u(null);try{await t(),u({kind:`ok`,text:n}),i()}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.actionFailed`,a)})}finally{s(null)}}return(0,q.jsx)(Ke,{open:n,onOpenChange:r,children:(0,q.jsxs)(le,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,q.jsxs)(Fe,{children:[(0,q.jsxs)($e,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Yn,{className:`h-4 w-4`}),e.manifest.name||p]}),(0,q.jsx)(Se,{className:`font-mono text-xs`,children:p})]}),(0,q.jsxs)(`div`,{className:`mt-4`,children:[(0,q.jsx)(ba,{label:G(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.col.scope`,a),children:(0,q.jsx)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(ba,{label:G(`engine.packages.col.status`,a),children:(0,q.jsx)(ga,{pkg:e})}),e.manifest.description&&(0,q.jsx)(ba,{label:G(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(c,{to:`${t}/metadata/object?package=${encodeURIComponent(p)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,q.jsx)(be,{className:`h-3.5 w-3.5`}),G(`engine.packages.detail.browseMetadata`,a)]}),d&&d.length>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[G(`engine.packages.detail.pendingChanges`,a),(0,q.jsx)(b,{variant:`secondary`,children:d.length})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G(`engine.packages.detail.pendingHint`,a)}),!h&&(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.publishDraftsPartial`,a,{published:e.publishedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.publishDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(Ge,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?G(`engine.packages.detail.publishing`,a):U(`engine.packages.detail.publishApp`,a,{count:d.length})]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.discardDraftsPartial`,a,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.discardDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(xe,{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)(nt,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`))})]})]}),(0,q.jsx)(br,{className:`my-4`}),h?(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.detail.kernelReadOnly`,a)}):(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.packages.detail.actions`,a)}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?U(`engine.packages.detail.publishBlocked`,a,{count:t}):e.validationErrors?.[0]?.message||G(`engine.packages.detail.nothingToPublish`,a))}return e}),G(`engine.packages.detail.published`,a)),disabled:!!o,children:[(0,q.jsx)(Ge,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>ma(`${pa}/${encodeURIComponent(p)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,q.jsx)(xe,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>ma(`${pa}/${encodeURIComponent(p)}/${m?`disable`:`enable`}`,{method:`PATCH`}),G(m?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,a)),disabled:!!o,children:[m?(0,q.jsx)(ge,{className:`mr-1.5 h-3.5 w-3.5`}):(0,q.jsx)(I,{className:`mr-1.5 h-3.5 w-3.5`}),G(m?`engine.packages.detail.disable`:`engine.packages.detail.enable`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`export`,async()=>{let e=await ma(`${pa}/${encodeURIComponent(p)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${p}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},G(`engine.packages.detail.exported`,a)),disabled:!!o,children:[(0,q.jsx)(D,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(U(`engine.packages.detail.deleteConfirm`,a,{name:e?.manifest.name||p}))){s(`delete`),u(null);try{await ma(`${pa}/${encodeURIComponent(p)}`,{method:`DELETE`}),i(),r(!1)}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.deleteFailed`,a)})}finally{s(null)}}},disabled:!!o,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,q.jsx)(mt,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,a)]})]})]}),l&&(0,q.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text})]})})}function Sa(){let e=J.useMemo(()=>Rr(),[]),{pathname:t}=a(),n=J.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[r,i]=J.useState([]),[o,s]=J.useState(!0),[c,l]=J.useState(null),[u,d]=J.useState(``),[f,p]=J.useState(!1),[m,h]=J.useState(!1),[g,_]=J.useState(null),[v,y]=J.useState(!1),b=J.useRef(null),[x,S]=J.useState(!1),[C,w]=J.useState(null),T=J.useCallback(async()=>{s(!0),l(null);try{let e=await ma(pa),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),i(t)}catch(t){l(t?.message??G(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);J.useEffect(()=>{T()},[T]),J.useEffect(()=>{if(!g)return;let e=r.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[r,g]);let E=J.useMemo(()=>{let e=u.trim().toLowerCase();return r.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[r,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(G(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(G(`engine.packages.import.invalidPackage`,e));w({kind:`ok`,text:U(`engine.packages.import.success`,e,{id:(await ma(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})}))?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??G(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=r.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,q.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,q.jsx)(Yn,{className:`h-5 w-5`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:G(`engine.packages.title`,e)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.description`,e)})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,q.jsx)(oe,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),G(`engine.packages.refresh`,e)]}),(0,q.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,q.jsx)(nt,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,q.jsxs)(z,{size:`sm`,onClick:()=>h(!0),children:[(0,q.jsx)(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)(tt,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Qt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,q.jsx)(V,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:U(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,q.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,q.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,q.jsx)(Re,{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)(P,{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)(Ze,{children:[(0,q.jsx)(me,{children:G(`engine.packages.empty`,e)}),(0,q.jsx)(gr,{children:r.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,q.jsxs)(kn,{children:[(0,q.jsx)($n,{children:(0,q.jsxs)(Wt,{children:[(0,q.jsx)(_n,{children:G(`engine.packages.col.name`,e)}),(0,q.jsx)(_n,{children:`ID`}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,q.jsx)(Un,{children:E.map(e=>(0,q.jsxs)(Wt,{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)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(Bt,{children:(0,q.jsx)(ga,{pkg:e})})]},e.manifest.id))})]})}),(0,q.jsx)(ya,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,q.jsx)(xa,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var Ca=new Set([`field`,`package`]),wa={data:L,ui:ft,automation:ar,ai:hn,system:Ft,platform:Ft,identity:$t,security:$t},Ta={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},Ea=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Da=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Oa={object:Xe,dashboard:he,page:ee,report:ce,record:pe,metadata:ft};function ka(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function Aa(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function ja(){let e=Tr(),{loading:t,entries:n}=Ur(e),{recentItems:r}=wr(),i=J.useMemo(()=>Rr(),[]),[a,o]=s(),[l,u]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),u(i.map(e=>({id:e.id,name:e.name})))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=a.get(`package`),f=J.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);J.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(a);e.set(`package`,l[0].id),o(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Er(e,`warning`,f??void 0),b=J.useMemo(()=>n.filter(e=>Ca.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,n,v]),x=J.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=J.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(Ea.indexOf(e)===-1?99:Ea.indexOf(e))-(Ea.indexOf(t)===-1?99:Ea.indexOf(t)))},[b,_]),C=J.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return Da.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:G(`engine.home.loading`,i)}):(0,q.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,q.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,q.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,q.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,q.jsxs)(`div`,{className:`max-w-xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,q.jsx)(hn,{className:`h-4 w-4`}),G(ka(),i)]}),(0,q.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:G(`engine.home.subtitle`,i)}),(0,q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,q.jsx)(z,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,q.jsxs)(c,{to:m,children:[(0,q.jsx)(ft,{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)(tt,{className:`h-3.5 w-3.5`}),G(`engine.directory.quickFind`,i),` ⌘⇧M`]})]})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,q.jsx)(Ma,{value:b.length,label:G(`engine.home.statTypes`,i)}),(0,q.jsx)(Ma,{value:x.length,label:G(`engine.home.statWritable`,i)}),(0,q.jsx)(Ma,{value:l.length,label:G(`engine.home.statPackages`,i)})]})]})]}),(0,q.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,q.jsx)(Na,{icon:ft,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,i),to_link:m}),(0,q.jsx)(Na,{icon:tn,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,i),to_link:m}),(0,q.jsx)(Na,{icon:Yn,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:G(`engine.home.statPackages`,i),to_link:h}),(0,q.jsxs)(c,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,q.jsx)(tn,{className:`h-5 w-5`}):(0,q.jsx)(P,{className:`h-5 w-5`})}),(0,q.jsx)(Mt,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?G(`engine.home.allHealthy`,i):w}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,i)})]})]})]}),C.length>0&&(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon: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)(z,{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:zr(e.type,i,e.label)})]})},e.type))})]}),(0,q.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,q.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,q.jsx)(Pa,{icon:ft,title:G(`engine.home.explore`,i),hint:G(`engine.home.exploreHint`,i)}),(0,q.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,q.jsx)(Fa,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:p},e))})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon:In,title:G(`engine.home.recent`,i)}),(0,q.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:r.length===0?(0,q.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:G(`engine.home.recentEmpty`,i)}):(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:r.slice(0,8).map(e=>{let t=Oa[e.type]??pe;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(c,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,q.jsx)(t,{className:`h-4 w-4`})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Aa(e.visitedAt,i)})]}),(0,q.jsx)(Mt,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,q.jsx)(oa,{})]})}function Ma({value:e,label:t}){return(0,q.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,q.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function Na({icon:e,from:t,to:n,value:r,label:i,to_link:a}){return(0,q.jsxs)(c,{to:a,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${n} text-white shadow-sm`,children:(0,q.jsx)(e,{className:`h-5 w-5`})}),(0,q.jsx)(Mt,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:r}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})}function Pa({icon:e,title:t,hint:n}){return(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,q.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,q.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function Fa({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=wa[e]??pe,o=Ta[e]??Ta.other,s=t.slice(0,6),l=t.length-s.length;return(0,q.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${o.ring}`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${o.from} ${o.to} text-white shadow-sm`,children:(0,q.jsx)(a,{className:`h-[18px] w-[18px]`})}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ir(e,r)}),(0,q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,G(`engine.home.typesLower`,r)]})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[s.map(e=>(0,q.jsxs)(c,{to:`metadata/${encodeURIComponent(e.type)}${i}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:zr(e.type,r,e.label)}),(0,q.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:n[e.type]??0})]},e.type)),l>0&&(0,q.jsxs)(c,{to:`metadata${i}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${o.text} hover:underline`,children:[`+`,l]})]})]})}function Ia({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:o}){let s=e?.type??``,l=J.useMemo(()=>Rr(),[]),u=zr(s,l,e?.label),{pathname:d}=a(),f=J.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,q.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground shrink-0`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(st,{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)(st,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),i]})]}):(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(st,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium`,children:u})]}),(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:u}),(0,q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:s}),e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),i]})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:o})]})}var La={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function Ra(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function za({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=J.useState(null),o=J.useMemo(()=>d(),[]),s=J.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(s.length===0)return null;let c=async e=>{let t=e.label??e.name;if(e.type!==`api`){xr.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i=e.params??{},s={recordId:n,origin:window.location.origin},c=Ra(e.target??``,s,i);if(!c){xr.error(`Action “${t}” has no target.`);return}let l=``.replace(/\/+$/,``),u=/^https?:\/\//i.test(c)?c:`${l}${c}`,d=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:d,headers:{"Content-Type":`application/json`},credentials:`include`};d!==`GET`&&d!==`DELETE`&&(n.body=JSON.stringify(i));let a=await o(u,n),s=null;try{s=await a.json()}catch{}if(!a.ok||s&&s.success===!1){let e=s?.error||s?.message||`HTTP ${a.status} ${a.statusText}`.trim();xr.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;xr.success(c),e.refreshAfter&&r?.()}catch(e){xr.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,q.jsx)(q.Fragment,{children:s.map(e=>{let t=e.icon?si(e.icon):null,n=i===e.name;return(0,q.jsxs)(z,{size:`sm`,variant:La[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,q.jsx)(N,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,q.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)})})}function Ba(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var Va=new Map;function Ha(e){let t=Va.get(e.type);if(!t){Va.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Va.set(e.type,n)}function Ua(e){return Va.get(e)}function Wa(e){let t=[];for(let n of Va.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function Ga(e,t){let n=Va.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Ka(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function qa({type:e}){let t=i(),n=e??t.type??``;if(n===`package`)return(0,q.jsx)(r,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let a=Ua(n);if(a?.ListPage){let e=a.ListPage;return(0,q.jsx)(e,{type:n})}return(0,q.jsx)(Ja,{type:n})}function Ja({type:e}){let t=u(),n=Tr(),{entries:r}=Ur(n),i=r.find(t=>t.type===e),a=Ga(e,i),[o,l]=J.useState([]),[d,f]=J.useState(!0),[p,m]=J.useState(null),[h,g]=J.useState(``),[_,v]=J.useState(`all`),[y,x]=s(),[S,C]=J.useState(0),[w,T]=J.useState(null);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await n.list(`package`);if(e)return;let r=new Set([`system`,`cloud`]),i=(t??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),T(i.map(e=>({id:e.id,name:e.name})))}catch{e||T([])}})(),()=>{e=!0}},[n]);let E=y.get(`package`),D=J.useMemo(()=>w?E&&w.some(e=>e.id===E)?E:w[0]?.id??null:null,[w,E]);J.useEffect(()=>{if(!w||w.length===0||E&&w.some(e=>e.id===E))return;let e=new URLSearchParams(y);e.set(`package`,w[0].id),x(e,{replace:!0})},[w,E]);let O=D?`?package=${encodeURIComponent(D)}`:``;J.useEffect(()=>{let t=!1;return f(!0),m(null),(async()=>{try{let r=await n.list(e);if(t)return;l((r??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Ka(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,S]);let A=a.searchableFields??[`name`,`label`,`description`],j=J.useMemo(()=>o.filter(e=>{if(a.listFilter&&!a.listFilter(e.item)||!D)return!1;let t=e.item?._packageId;return(!t||t===`sys_metadata`?null:t)===D}),[o,D,a]),ee=j.filter(e=>!(!Wr(e.item,h,A)||_!==`all`&&e.source!==_)),te=J.useMemo(()=>{let e={all:j.length,artifact:0,runtime:0};for(let t of j)e[t.source]++;return e},[j]),ne=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[j]),re=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[j]),ie=a.listColumns??Ya(a.primaryKey??`name`),M=Rr(),ae=zr(e,M,i?.label??e),se=e=>{let t=`engine.list.col.${e.key}`,n=G(t,M);return n===t?e.label:n};return(0,q.jsx)(Ia,{entry:i??{type:e,label:e},stats:[{label:G(`engine.list.items`,M),value:j.length},{label:G(`engine.list.filtered`,M),value:ee.length},...ne>0?[{label:G(`engine.list.invalid`,M),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,q.jsx)(P,{className:`w-3.5 h-3.5`}),ne]})}]:[],...re>0?[{label:G(`engine.list.warnings`,M),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,q.jsx)(P,{className:`w-3.5 h-3.5`}),re]})}]:[]],actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(za,{entry:i,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,M),children:(0,q.jsx)(oe,{className:`h-4 w-4`})}),(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsxs)(z,{size:`sm`,variant:a.createFields?`default`:`outline`,onClick:()=>t(`./new${O}`),title:a.createFields?U(`engine.list.createHint`,M,{type:ae}):void 0,children:[(0,q.jsx)(F,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,M)]})]}),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)(tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.list.search`,M),value:h,onChange:e=>g(e.target.value)})]}),(0,q.jsxs)(k,{value:_,onValueChange:v,children:[(0,q.jsx)(dt,{className:`w-[180px]`,children:(0,q.jsx)(xt,{})}),(0,q.jsxs)(gt,{children:[(0,q.jsxs)(ve,{value:`all`,children:[G(`engine.list.allSources`,M),` (`,te.all,`)`]}),(0,q.jsxs)(ve,{value:`artifact`,children:[G(`engine.list.source.artifact`,M),` (`,te.artifact,`)`]}),(0,q.jsxs)(ve,{value:`runtime`,children:[G(`engine.list.source.runtime`,M),` (`,te.runtime,`)`]})]})]})]}),(d||w===null)&&(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[G(`engine.edit.loading`,M),` `,e,`…`]}),p&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:p}),!d&&!p&&w!==null&&w.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!d&&!p&&w!==null&&w.length>0&&ee.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:j.length===0?U(`engine.list.emptyType`,M,{type:ae}):U(`engine.list.emptyQuery`,M,{query:h})}),(0,q.jsx)(gr,{children:a.emptyStateHint??(i?.allowOrgOverride||i?.allowRuntimeCreate?U(`engine.list.createHint`,M,{type:ae}):G(`engine.list.readOnlyHint`,M))}),j.length===0&&(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsxs)(z,{onClick:()=>t(`./new${O}`),children:[(0,q.jsx)(F,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,M)]})})]}),!d&&ee.length>0&&(0,q.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[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:se(e)},e.key)),(0,q.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:G(`engine.list.col.source`,M)})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:ee.map((e,t)=>{let n=a.primaryKey??`name`,r=String(e.item[n]??`(unnamed-${t})`),i=e.item._packageId,o=i&&i!==`sys_metadata`?`?package=${encodeURIComponent(i)}`:O,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(`
|
|
2
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,a as r,f as i,l as a,m as o,p as s,r as c,t as l,u}from"./vendor-react-DR370ovB.js";import{m as d}from"./infrastructure-CJNwTVno.js";import{B as f,ct as p,w as m}from"./framework-BLEk-ou3.js";import{R as h,_ as g,d as _,p as v}from"./vendor-objectstack-BNd856rx.js";import{$ as y,$n as b,$o as x,$s as S,$t as C,Ai as w,Ar as T,Bn as E,Bo as D,Bs as O,Bt as k,Ca as A,Ci as j,Co as ee,Cr as te,Da as ne,Di as re,Do as ie,Ds as M,Fa as ae,Fi as oe,Fo as se,Fs as ce,Ft as le,Gi as ue,Go as de,Gr as fe,Gs as pe,H as me,Ha as he,Hi as ge,Hn as _e,Ht as ve,Ia as ye,Io as be,Ir as xe,It as Se,Ja as Ce,Ji as we,Js as Te,Jt as Ee,Kn as De,Ks as Oe,L as ke,La as Ae,Ln as je,Lo as Me,Lr as Ne,Ls as Pe,Lt as Fe,Ma as N,Mi as Ie,Mo as Le,Mt as Re,Na as ze,Nr as Be,Oa as Ve,Os as He,Pi as Ue,Po as We,Pr as Ge,Pt as Ke,Qa as qe,Qi as Je,Qo as Ye,Qr as Xe,R as Ze,Rn as Qe,Rr as P,Rt as $e,Sa as et,Si as tt,So as nt,Sr as rt,Ta as it,Ti as at,To as ot,Ts as st,Ua as ct,Ui as F,Uo as lt,Us as ut,Ut as dt,Va as ft,Vi as I,Vn as pt,Vr as mt,Vs as ht,Vt as gt,Wa as _t,Wi as vt,Wo as L,Wr as yt,Ws as bt,Wt as xt,Xa as St,Xi as Ct,Xo as wt,Xr as Tt,Ya as Et,Yo as Dt,Yt as Ot,Zo as kt,_i as At,_r as jt,ac as Mt,at as Nt,ba as Pt,bi as Ft,br as It,bs as Lt,ca as Rt,cc as R,co as zt,ct as Bt,da as Vt,dc as Ht,di as Ut,dt as Wt,ea as Gt,en as Kt,eo as qt,et as Jt,fc as Yt,fi as Xt,fo as Zt,ft as Qt,gi as $t,go as en,gs as tn,ha as nn,hi as rn,ho as an,hr as z,hs as on,ia as sn,ii as cn,io as ln,it as un,ja as dn,jo as fn,ko as pn,kr as mn,li as hn,lo as gn,lt as _n,ma as vn,mi as yn,mo as bn,ms as xn,na as Sn,nc as Cn,ni as wn,nn as B,no as Tn,nt as En,on as V,oo as Dn,os as On,ot as kn,pc as H,pi as An,po as jn,ps as Mn,qo as Nn,qt as Pn,ra as Fn,rs as In,rt as Ln,sa as Rn,sc as zn,si as Bn,so as Vn,ss as Hn,st as Un,ta as Wn,tc as Gn,ti as Kn,tn as qn,to as Jn,ua as Yn,uc as Xn,uo as Zn,us as Qn,ut as $n,va as er,vo as tr,vr as nr,wa as rr,wi as ir,wr as ar,ws as or,xa as sr,xi as cr,xo as lr,xr as ur,ya as dr,yi as fr,yo as pr,yr as mr,ys as hr,z as gr,za as _r,zn as vr,zo as yr,zt as br}from"./ui-components-CrPYFyEM.js";import{r as xr}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-DJb3ZVmJ.js";import{o as Sr,r as Cr}from"./MetadataProvider-Bja7m8Gt.js";import{n as wr}from"./RecentItemsProvider-B76qldBH.js";import{C as Tr,S as Er,_ as Dr,a as U,b as Or,c as kr,d as Ar,f as jr,g as W,h as Mr,i as G,l as Nr,m as Pr,n as Fr,o as Ir,p as Lr,r as Rr,s as zr,t as Br,u as Vr,v as Hr,w as Ur,x as Wr,y as K}from"./mergeServerFields-zZ2r6yTA.js";import{t as Gr}from"./InterfaceListPage-B3jzgT27.js";import{a as Kr,c as qr,i as Jr,n as Yr,o as Xr,r as Zr,s as Qr,t as $r}from"./ReportDefaultInspector-C8gR3RMr.js";import{i as ei,n as ti,r as ni,t as ri}from"./DashboardWidgetInspector-VPDtQEP_.js";var q=l(),J=e(n(),1);function ii(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var ai=new Set(Jt),oi=new Map;function si(e){if(!e)return L;let t=oi.get(e);if(t)return t;let n=ii(e);if(!ai.has(n))return oi.set(e,L),L;let r=e=>J.createElement(y,{name:n,fallback:L,...e});return r.displayName=`LucideIcon(${e})`,oi.set(e,r),r}function ci(e){return Array.isArray(e)?{shape:`array`,entries:e.map((e,t)=>{let{name:n,...r}=e??{};return{name:typeof n==`string`&&n?n:`field_${t+1}`,def:r}})}:e&&typeof e==`object`?{shape:`record`,entries:Object.entries(e).map(([e,t])=>({name:e,def:{...t??{}}}))}:{shape:`record`,entries:[]}}function li(e){if(e.shape===`array`)return e.entries.map(e=>({name:e.name,...e.def}));let t={};for(let n of e.entries)t[n.name]=n.def;return t}function ui(e,t){return e.entries.findIndex(e=>e.name===t)}function di(e,t,n){let r={type:t,label:n??fi(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function fi(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function pi(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/_{2,}/g,`_`);return t?/^[a-z_]/.test(t)?t:`f_${t}`:`field`}function mi(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:``})).filter(e=>e.key):[]}function hi(e,t){let n=/[a-z0-9]/i.test(e)?pi(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function gi(e,t){let n=t.trim()||`New section`,r=hi(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function _i(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function vi(e,t){return e.filter(e=>e.key!==t)}function yi(e,t,n){let r=e.findIndex(e=>e.key===t);if(r<0)return e;let i=r+n;return i<0||i>=e.length?e:xi(e,r,i)}function bi(e,t){return{shape:e.shape,entries:e.entries.map(e=>e.def.group===t?{name:e.name,def:{...e.def,group:void 0}}:e)}}function xi(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function Si(e,t,n){let r=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],i=new Map;for(let e of r)i.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let a=new Set(r.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&a.has(e)?i.get(e).entries.push(t):(i.has(null)||i.set(null,{key:null,label:`Ungrouped`,entries:[]}),i.get(null).entries.push(t))}let o=!!n?.includeEmptyDeclared;return Array.from(i.values()).filter(e=>e.entries.length>0||o&&e.key!==null)}function Ci(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function wi(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)Ci(e[i],t[i])||r.push(i);return r.sort()}function Ti(e,t){let n=ci(e),r=ci(t),i=new Map(n.entries.map(e=>[e.name,e])),a=new Set(r.entries.map(e=>e.name)),o={},s=0,c=0;for(let e of r.entries){let t=i.get(e.name);if(!t){o[e.name]={name:e.name,status:`added`,changedKeys:[]},s+=1;continue}let n=wi(t.def,e.def);n.length?(o[e.name]={name:e.name,status:`changed`,changedKeys:n},c+=1):o[e.name]={name:e.name,status:`unchanged`,changedKeys:[]}}let l=n.entries.filter(e=>!a.has(e.name));return{byName:o,removed:l,counts:{added:s,changed:c,removed:l.length}}}function Ei(e,t){let n=Tr(),[r,i]=J.useState({fields:[],loading:!t&&!!e,error:null});return J.useEffect(()=>{if(t){i({fields:t,loading:!1,error:null});return}if(!e){i({fields:[],loading:!1,error:null});return}let r=!1;return i(e=>({...e,loading:!0,error:null})),n.get(`object`,e).then(e=>{if(!r){if(!e){i({fields:[],loading:!1,error:`Object not found`});return}i({fields:ci(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`&&e.def.label?e.def.label:e.name,type:typeof e.def.type==`string`?e.def.type:`text`,hidden:e.def.hidden===!0})),loading:!1,error:null})}}).catch(e=>{r||i({fields:[],loading:!1,error:e?.message??String(e)})}),()=>{r=!0}},[n,e,t]),r}function Di(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function Oi(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function ki(e){let t=new Set;for(let n of e){let e=Oi(n);e&&t.add(e)}return t}function Ai(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function ji(e,t){return e===t?null:e>t?e-1:e}function Mi(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Ni({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=Ei(i||void 0,a),m=J.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=J.useState(null),[_,v]=J.useState(null),y=J.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),x=J.useCallback(t=>{let i=Dr(n,Ai(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),S=J.useCallback(t=>{let r=K(n,t,null);if(y(r),o!=null){let n=ji(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(r[n],n)})}},[n,y,o,e,l]),C=J.useCallback((t,r)=>{if(t===r)return;let i=Hr(n,t,r);if(y(i),o!=null){let n=Mi(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Di(i[n],n)})}},[n,y,o,e,l]),w=J.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Di(n[t],t)})},[n,e,l]),T=ki(n);return(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,q.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,q.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,q.jsx)(Zr,{index:t,label:Di(e,t),fieldName:Oi(e),fieldType:m.get(Oi(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>w(t),onRemove:()=>S(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&C(h,t),g(null),v(null)}},t))}),u&&(0,q.jsx)(Yr,{fields:d,usedNames:T,loading:f,error:p,onAdd:x})]})}var Pi={io:`input`,unrepresentable:`any`},Fi=new Set([`columns`,`data`,`name`]),Ii,Li=!1;function Ri(){if(Ii||Li)return Ii;try{Ii=h(v,Pi)}catch(e){Li=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return Ii}function zi(){return Ri()?.properties?.list}function Bi(){return Ri()?.properties?.form}var Vi,Hi=!1;function Ui(){if(Vi||Hi)return Vi;try{Vi=h(_,Pi)}catch(e){Hi=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Vi}var Wi;function Gi(){if(Wi)return Wi;if(!(!g||typeof g!=`object`)){try{let e=JSON.parse(JSON.stringify(g));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Fi.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Wi=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Wi}}var Ki=new Set([`form`,`detail`]);function qi(e){return Ki.has(e)}function Ji(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Yi(e,t){return typeof e==`string`&&Ki.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Ki.has(t)?`form`:`list`}function Xi(e){let t=e.config;return Ji(t)?[{storeKey:`config`,familyKey:Yi(e.viewKind,t.type),schema:t}]:[]}function Zi(e){return Xi(e)[0]}function Qi(e,t){return Zi(e)}var $i=new Set([`type`,`object`,`label`,`columns`]),ea={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function ta(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?ea[e]??e:r}var na=[`columns`,`data`,`name`];function ra(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function ia(e,t){return J.useMemo(()=>{let n=zi()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:ta(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:ta(e,t)}),r},[e,t])}function aa({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=qi(n??t),p=typeof d.type==`string`?d.type:`grid`,m=ia(p,l),h=ra(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=Ei(h.value||void 0,c),b=J.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),x=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:S,form:C}=J.useMemo(()=>Br({bundledSchema:f?Bi():zi(),bundledForm:f?void 0:Gi(),serverSchema:x,excludeFields:$i,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,q.jsxs)(Mr,{kindLabel:G(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:G(`engine.inspector.view.close`,l),hideClose:r,children:[(0,q.jsx)(W,{label:G(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:G(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,q.jsx)(Pr,{label:G(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,q.jsx)(W,{label:G(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:G(`engine.inspector.view.objectPlaceholder`,l),disabled:a,mono:!0}),!f&&(0,q.jsx)(`div`,{className:`border-t pt-3`,children:(0,q.jsx)(Ni,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,q.jsx)(`div`,{className:`border-t pt-3`,children:S?(0,q.jsx)(Fr,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of na)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.view.noSchema`,l)})})]})}function oa({appSlug:e}={}){let t=u(),n=Tr(),{entries:r}=Ur(n),[i,a]=J.useState(!1),[o,s]=J.useState(``),[c,l]=J.useState(null),[d,f]=J.useState(!1),[p,m]=J.useState(0),h=J.useMemo(()=>Rr(),[]);J.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),a(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),J.useEffect(()=>{if(!i||c!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||l(t)}finally{e||f(!1)}})(),()=>{e=!0}},[i,c,d,r,n]);let g=J.useMemo(()=>{let e=o.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||zr(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(c??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[o,r,c]);J.useEffect(()=>{m(0)},[o,i]);function _(n){a(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,q.jsx)(je,{open:i,onOpenChange:a,children:(0,q.jsxs)(Qe,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,q.jsx)(pt,{className:`sr-only`,children:(0,q.jsx)(_e,{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)(tt,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(B,{autoFocus:!0,placeholder:G(`engine.quickfind.placeholder`,h),value:o,onChange:e=>s(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,q.jsx)(ke,{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)(N,{className:`h-3.5 w-3.5 animate-spin`}),G(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:G(`engine.quickfind.noMatches`,h)}),(0,q.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`text-sm font-medium truncate`,children:zr(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,q.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,q.jsx)(dn,{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)(ke,{children:`↑`}),` `,(0,q.jsx)(ke,{children:`↓`}),` navigate`]}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(ke,{children:`↵`}),` open`]}),(0,q.jsxs)(`span`,{className:`ml-auto`,children:[(0,q.jsx)(ke,{children:`⌘`}),(0,q.jsx)(ke,{children:`⇧`}),(0,q.jsx)(ke,{children:`M`}),` toggle`]})]})]})})}var sa={data:L,ui:ft,automation:ar,ai:hn,system:Ft,platform:Ft,identity:$t,security:$t},ca=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],la=new Set([`field`,`package`]);function ua(){let e=Tr(),{loading:t,error:n,entries:r}=Ur(e),i=J.useMemo(()=>Rr(),[]),[a,o]=J.useState(``),[l,u]=J.useState(`all`),[d,f]=J.useState(!1),[p,m]=s(),[h,g]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),g(i.map(e=>({id:e.id,name:e.name})))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=J.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);J.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Er(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>la.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[r,v,w]),D=J.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(a){let t=a.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||zr(e.type,i,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=J.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=ca.indexOf(e),r=ca.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,q.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:G(`engine.directory.loading`,i)}):n?(0,q.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[G(`engine.directory.loadFailed`,i),`: `,n]}):(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold`,children:G(`engine.directory.title`,i)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:U(`engine.directory.description`,i,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,q.jsx)(tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.directory.search`,i),value:a,onChange:e=>o(e.target.value)})]}),(0,q.jsxs)(z,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,i),` (`,O,`)`]}),x.total>0&&(0,q.jsx)(z,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,q.jsxs)(c,{to:`./_diagnostics`,children:[(0,q.jsx)(P,{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)(ke,{children:`⌘`}),(0,q.jsx)(ke,{children:`⇧`}),(0,q.jsx)(ke,{children:`M`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,q.jsx)(da,{domain:`all`,label:G(`engine.directory.all`,i),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),ca.filter(e=>D[e]).map(e=>(0,q.jsx)(da,{domain:e,label:Ir(e,i),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:G(`engine.directory.noMatches`,i)}),(0,q.jsx)(gr,{children:G(`engine.directory.noMatchesHint`,i)})]}),A.map(([e,t])=>(0,q.jsxs)(`section`,{className:`space-y-2`,children:[(0,q.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,q.jsx)(sa[e]??pe,{className:`h-3.5 w-3.5`}),Ir(e,i),` (`,t.length,`)`]}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,q.jsx)(fa,{entry:e,locale:i,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,q.jsx)(oa,{})]})}function da({domain:e,label:t,active:n,count:r,onClick:i}){return(0,q.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,q.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function fa({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=zr(e.type,t,e.label);return(0,q.jsxs)(c,{to:o?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(o)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(n>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[n>0&&(0,q.jsx)(`span`,{title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,q.jsx)(P,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),s]}),(0,q.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,q.jsx)(b,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:U(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:U(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:U(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),a>0&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${a} locked item${a===1?``:`s`} — see ADR-0010`,"aria-label":`${a} locked items`,children:[(0,q.jsx)(dn,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,t)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var pa=`/api/v1/packages`;async function ma(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function ha({scope:e}){let t=J.useMemo(()=>Rr(),[]),n=e??`project`,r=n===`project`?`default`:n===`system`?`secondary`:`outline`,i=n===`project`?`engine.packages.scope.project`:n===`system`?`engine.packages.scope.system`:n===`cloud`?`engine.packages.scope.cloud`:``;return(0,q.jsx)(b,{variant:r,children:i?G(i,t):n})}function ga({pkg:e}){let t=J.useMemo(()=>Rr(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,q.jsx)(b,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var _a=/^[a-z0-9][a-z0-9._-]{1,254}$/i,va=/^\d+\.\d+\.\d+$/;function ya({open:e,onOpenChange:t,onCreated:n}){let r=J.useMemo(()=>Rr(),[]),[i,a]=J.useState(``),[o,s]=J.useState(``),[c,l]=J.useState(`0.1.0`),[u,d]=J.useState(!1),[f,p]=J.useState(null);J.useEffect(()=>{e&&(a(``),s(``),l(`0.1.0`),p(null),d(!1))},[e]);let m=_a.test(i),h=va.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await ma(pa,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:i.trim(),name:o.trim(),version:c.trim(),type:`app`,scope:`project`}})}),n(i.trim()),t(!1)}catch(e){p(e?.message??G(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,q.jsx)(je,{open:e,onOpenChange:t,children:(0,q.jsxs)(Qe,{children:[(0,q.jsxs)(pt,{children:[(0,q.jsx)(_e,{children:G(`engine.packages.create.title`,r)}),(0,q.jsx)(vr,{children:U(`engine.packages.create.description`,r,{example:`com.acme.crm`})})]}),(0,q.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-id`,children:G(`engine.packages.create.id`,r)}),(0,q.jsx)(B,{id:`pkg-id`,placeholder:`com.acme.crm`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!!i&&!m}),!!i&&!m&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.idInvalid`,r)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-name`,children:G(`engine.packages.create.name`,r)}),(0,q.jsx)(B,{id:`pkg-name`,placeholder:`Acme CRM`,value:o,onChange:e=>s(e.target.value)})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(V,{htmlFor:`pkg-version`,children:G(`engine.packages.create.version`,r)}),(0,q.jsx)(B,{id:`pkg-version`,placeholder:`0.1.0`,value:c,onChange:e=>l(e.target.value),"aria-invalid":!!c&&!h}),!!c&&!h&&(0,q.jsx)(`p`,{className:`text-xs text-destructive`,children:G(`engine.packages.create.versionInvalid`,r)})]}),f&&(0,q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,q.jsx)(P,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,q.jsx)(`span`,{children:f})]})]}),(0,q.jsxs)(E,{children:[(0,q.jsx)(z,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:G(`engine.cancel`,r)}),(0,q.jsx)(z,{onClick:_,disabled:!g,children:G(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function ba({label:e,children:t}){return(0,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function xa({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=J.useMemo(()=>Rr(),[]),[o,s]=J.useState(null),[l,u]=J.useState(null),[d,f]=J.useState(null);if(J.useEffect(()=>{u(null),s(null)},[e?.manifest.id]),J.useEffect(()=>{let t=e?.manifest.id;if(!n||!t){f(null);return}let r=!1;return ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{r||f(e?.drafts??[])}).catch(()=>{r||f([])}),()=>{r=!0}},[n,e?.manifest.id]),!e)return null;let p=e.manifest.id,m=e.enabled!==!1&&e.status!==`disabled`,h=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function g(e,t,n){s(e),u(null);try{await t(),u({kind:`ok`,text:n}),i()}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.actionFailed`,a)})}finally{s(null)}}return(0,q.jsx)(Ke,{open:n,onOpenChange:r,children:(0,q.jsxs)(le,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,q.jsxs)(Fe,{children:[(0,q.jsxs)($e,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Yn,{className:`h-4 w-4`}),e.manifest.name||p]}),(0,q.jsx)(Se,{className:`font-mono text-xs`,children:p})]}),(0,q.jsxs)(`div`,{className:`mt-4`,children:[(0,q.jsx)(ba,{label:G(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,q.jsx)(ba,{label:G(`engine.packages.col.scope`,a),children:(0,q.jsx)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(ba,{label:G(`engine.packages.col.status`,a),children:(0,q.jsx)(ga,{pkg:e})}),e.manifest.description&&(0,q.jsx)(ba,{label:G(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(c,{to:`${t}/metadata/object?package=${encodeURIComponent(p)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,q.jsx)(be,{className:`h-3.5 w-3.5`}),G(`engine.packages.detail.browseMetadata`,a)]}),d&&d.length>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(br,{className:`my-4`}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[G(`engine.packages.detail.pendingChanges`,a),(0,q.jsx)(b,{variant:`secondary`,children:d.length})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G(`engine.packages.detail.pendingHint`,a)}),!h&&(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.publishDraftsPartial`,a,{published:e.publishedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.publishDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(Ge,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?G(`engine.packages.detail.publishing`,a):U(`engine.packages.detail.publishApp`,a,{count:d.length})]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>ma(`${pa}/${encodeURIComponent(p)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{f((await ma(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(p)}`))?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(U(`engine.packages.detail.discardDraftsPartial`,a,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.discardDraftsOk`,a)),disabled:!!o,children:[(0,q.jsx)(xe,{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)(nt,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`))})]})]}),(0,q.jsx)(br,{className:`my-4`}),h?(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.detail.kernelReadOnly`,a)}):(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.packages.detail.actions`,a)}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,q.jsxs)(z,{size:`sm`,onClick:()=>g(`publish`,()=>ma(`${pa}/${encodeURIComponent(p)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?U(`engine.packages.detail.publishBlocked`,a,{count:t}):e.validationErrors?.[0]?.message||G(`engine.packages.detail.nothingToPublish`,a))}return e}),G(`engine.packages.detail.published`,a)),disabled:!!o,children:[(0,q.jsx)(Ge,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>ma(`${pa}/${encodeURIComponent(p)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,q.jsx)(xe,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>ma(`${pa}/${encodeURIComponent(p)}/${m?`disable`:`enable`}`,{method:`PATCH`}),G(m?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,a)),disabled:!!o,children:[m?(0,q.jsx)(ge,{className:`mr-1.5 h-3.5 w-3.5`}):(0,q.jsx)(I,{className:`mr-1.5 h-3.5 w-3.5`}),G(m?`engine.packages.detail.disable`:`engine.packages.detail.enable`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>g(`export`,async()=>{let e=await ma(`${pa}/${encodeURIComponent(p)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${p}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},G(`engine.packages.detail.exported`,a)),disabled:!!o,children:[(0,q.jsx)(D,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,a)]}),(0,q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(U(`engine.packages.detail.deleteConfirm`,a,{name:e?.manifest.name||p}))){s(`delete`),u(null);try{await ma(`${pa}/${encodeURIComponent(p)}`,{method:`DELETE`}),i(),r(!1)}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.deleteFailed`,a)})}finally{s(null)}}},disabled:!!o,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,q.jsx)(mt,{className:`mr-1.5 h-3.5 w-3.5`}),G(o===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,a)]})]})]}),l&&(0,q.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text})]})})}function Sa(){let e=J.useMemo(()=>Rr(),[]),{pathname:t}=a(),n=J.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[r,i]=J.useState([]),[o,s]=J.useState(!0),[c,l]=J.useState(null),[u,d]=J.useState(``),[f,p]=J.useState(!1),[m,h]=J.useState(!1),[g,_]=J.useState(null),[v,y]=J.useState(!1),b=J.useRef(null),[x,S]=J.useState(!1),[C,w]=J.useState(null),T=J.useCallback(async()=>{s(!0),l(null);try{let e=await ma(pa),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),i(t)}catch(t){l(t?.message??G(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);J.useEffect(()=>{T()},[T]),J.useEffect(()=>{if(!g)return;let e=r.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[r,g]);let E=J.useMemo(()=>{let e=u.trim().toLowerCase();return r.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[r,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(G(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(G(`engine.packages.import.invalidPackage`,e));w({kind:`ok`,text:U(`engine.packages.import.success`,e,{id:(await ma(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})}))?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??G(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=r.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,q.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,q.jsx)(Yn,{className:`h-5 w-5`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:G(`engine.packages.title`,e)}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.description`,e)})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,q.jsx)(oe,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),G(`engine.packages.refresh`,e)]}),(0,q.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,q.jsx)(nt,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,q.jsxs)(z,{size:`sm`,onClick:()=>h(!0),children:[(0,q.jsx)(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)(tt,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Qt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,q.jsx)(V,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:U(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,q.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,q.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,q.jsx)(Re,{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)(P,{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)(Ze,{children:[(0,q.jsx)(me,{children:G(`engine.packages.empty`,e)}),(0,q.jsx)(gr,{children:r.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,q.jsxs)(kn,{children:[(0,q.jsx)($n,{children:(0,q.jsxs)(Wt,{children:[(0,q.jsx)(_n,{children:G(`engine.packages.col.name`,e)}),(0,q.jsx)(_n,{children:`ID`}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,q.jsx)(_n,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,q.jsx)(Un,{children:E.map(e=>(0,q.jsxs)(Wt,{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)(ha,{scope:e.manifest.scope})}),(0,q.jsx)(Bt,{children:(0,q.jsx)(ga,{pkg:e})})]},e.manifest.id))})]})}),(0,q.jsx)(ya,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,q.jsx)(xa,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var Ca=new Set([`field`,`package`]),wa={data:L,ui:ft,automation:ar,ai:hn,system:Ft,platform:Ft,identity:$t,security:$t},Ta={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},Ea=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Da=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Oa={object:Xe,dashboard:he,page:ee,report:ce,record:pe,metadata:ft};function ka(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function Aa(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function ja(){let e=Tr(),{loading:t,entries:n}=Ur(e),{recentItems:r}=wr(),i=J.useMemo(()=>Rr(),[]),[a,o]=s(),[l,u]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),u(i.map(e=>({id:e.id,name:e.name})))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=a.get(`package`),f=J.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);J.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(a);e.set(`package`,l[0].id),o(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Er(e,`warning`,f??void 0),b=J.useMemo(()=>n.filter(e=>Ca.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,n,v]),x=J.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=J.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(Ea.indexOf(e)===-1?99:Ea.indexOf(e))-(Ea.indexOf(t)===-1?99:Ea.indexOf(t)))},[b,_]),C=J.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return Da.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:G(`engine.home.loading`,i)}):(0,q.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,q.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,q.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,q.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,q.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,q.jsxs)(`div`,{className:`max-w-xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,q.jsx)(hn,{className:`h-4 w-4`}),G(ka(),i)]}),(0,q.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,q.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:G(`engine.home.subtitle`,i)}),(0,q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,q.jsx)(z,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,q.jsxs)(c,{to:m,children:[(0,q.jsx)(ft,{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)(tt,{className:`h-3.5 w-3.5`}),G(`engine.directory.quickFind`,i),` ⌘⇧M`]})]})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,q.jsx)(Ma,{value:b.length,label:G(`engine.home.statTypes`,i)}),(0,q.jsx)(Ma,{value:x.length,label:G(`engine.home.statWritable`,i)}),(0,q.jsx)(Ma,{value:l.length,label:G(`engine.home.statPackages`,i)})]})]})]}),(0,q.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,q.jsx)(Na,{icon:ft,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,i),to_link:m}),(0,q.jsx)(Na,{icon:tn,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,i),to_link:m}),(0,q.jsx)(Na,{icon:Yn,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:G(`engine.home.statPackages`,i),to_link:h}),(0,q.jsxs)(c,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,q.jsx)(tn,{className:`h-5 w-5`}):(0,q.jsx)(P,{className:`h-5 w-5`})}),(0,q.jsx)(Mt,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?G(`engine.home.allHealthy`,i):w}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,i)})]})]})]}),C.length>0&&(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon: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)(z,{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:zr(e.type,i,e.label)})]})},e.type))})]}),(0,q.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,q.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,q.jsx)(Pa,{icon:ft,title:G(`engine.home.explore`,i),hint:G(`engine.home.exploreHint`,i)}),(0,q.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,q.jsx)(Fa,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:p},e))})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsx)(Pa,{icon:In,title:G(`engine.home.recent`,i)}),(0,q.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:r.length===0?(0,q.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:G(`engine.home.recentEmpty`,i)}):(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:r.slice(0,8).map(e=>{let t=Oa[e.type]??pe;return(0,q.jsx)(`li`,{children:(0,q.jsxs)(c,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,q.jsx)(t,{className:`h-4 w-4`})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Aa(e.visitedAt,i)})]}),(0,q.jsx)(Mt,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,q.jsx)(oa,{})]})}function Ma({value:e,label:t}){return(0,q.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,q.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function Na({icon:e,from:t,to:n,value:r,label:i,to_link:a}){return(0,q.jsxs)(c,{to:a,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${n} text-white shadow-sm`,children:(0,q.jsx)(e,{className:`h-5 w-5`})}),(0,q.jsx)(Mt,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,q.jsxs)(`div`,{className:`mt-3`,children:[(0,q.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:r}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})}function Pa({icon:e,title:t,hint:n}){return(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,q.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,q.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function Fa({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=wa[e]??pe,o=Ta[e]??Ta.other,s=t.slice(0,6),l=t.length-s.length;return(0,q.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${o.ring}`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${o.from} ${o.to} text-white shadow-sm`,children:(0,q.jsx)(a,{className:`h-[18px] w-[18px]`})}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ir(e,r)}),(0,q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,G(`engine.home.typesLower`,r)]})]})]}),(0,q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[s.map(e=>(0,q.jsxs)(c,{to:`metadata/${encodeURIComponent(e.type)}${i}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,q.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:zr(e.type,r,e.label)}),(0,q.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:n[e.type]??0})]},e.type)),l>0&&(0,q.jsxs)(c,{to:`metadata${i}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${o.text} hover:underline`,children:[`+`,l]})]})]})}function Ia({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:o}){let s=e?.type??``,l=J.useMemo(()=>Rr(),[]),u=zr(s,l,e?.label),{pathname:d}=a(),f=J.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,q.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground shrink-0`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(st,{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)(st,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),i]})]}):(0,q.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,q.jsx)(c,{to:f,className:`hover:text-foreground`,children:G(`engine.breadcrumb.allTypes`,l)}),(0,q.jsx)(st,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`text-foreground font-medium`,children:u})]}),(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:u}),(0,q.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:s}),e?.domain&&(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ir(e.domain,l)}),e?.allowOrgOverride?(0,q.jsx)(b,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,q.jsx)(b,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,l)}):(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,l)})]}),n&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,q.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r?.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,q.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),i]})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-auto`,children:o})]})}var La={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function Ra(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function za({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=J.useState(null),o=J.useMemo(()=>d(),[]),s=J.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(s.length===0)return null;let c=async e=>{let t=e.label??e.name;if(e.type!==`api`){xr.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i=e.params??{},s={recordId:n,origin:window.location.origin},c=Ra(e.target??``,s,i);if(!c){xr.error(`Action “${t}” has no target.`);return}let l=``.replace(/\/+$/,``),u=/^https?:\/\//i.test(c)?c:`${l}${c}`,d=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:d,headers:{"Content-Type":`application/json`},credentials:`include`};d!==`GET`&&d!==`DELETE`&&(n.body=JSON.stringify(i));let a=await o(u,n),s=null;try{s=await a.json()}catch{}if(!a.ok||s&&s.success===!1){let e=s?.error||s?.message||`HTTP ${a.status} ${a.statusText}`.trim();xr.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;xr.success(c),e.refreshAfter&&r?.()}catch(e){xr.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,q.jsx)(q.Fragment,{children:s.map(e=>{let t=e.icon?si(e.icon):null,n=i===e.name;return(0,q.jsxs)(z,{size:`sm`,variant:La[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,q.jsx)(N,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,q.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)})})}function Ba(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var Va=new Map;function Ha(e){let t=Va.get(e.type);if(!t){Va.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Va.set(e.type,n)}function Ua(e){return Va.get(e)}function Wa(e){let t=[];for(let n of Va.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function Ga(e,t){let n=Va.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Ka(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function qa({type:e}){let t=i(),n=e??t.type??``;if(n===`package`)return(0,q.jsx)(r,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let a=Ua(n);if(a?.ListPage){let e=a.ListPage;return(0,q.jsx)(e,{type:n})}return(0,q.jsx)(Ja,{type:n})}function Ja({type:e}){let t=u(),n=Tr(),{entries:r}=Ur(n),i=r.find(t=>t.type===e),a=Ga(e,i),[o,l]=J.useState([]),[d,f]=J.useState(!0),[p,m]=J.useState(null),[h,g]=J.useState(``),[_,v]=J.useState(`all`),[y,x]=s(),[S,C]=J.useState(0),[w,T]=J.useState(null);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await n.list(`package`);if(e)return;let r=new Set([`system`,`cloud`]),i=(t??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),T(i.map(e=>({id:e.id,name:e.name})))}catch{e||T([])}})(),()=>{e=!0}},[n]);let E=y.get(`package`),D=J.useMemo(()=>w?E&&w.some(e=>e.id===E)?E:w[0]?.id??null:null,[w,E]);J.useEffect(()=>{if(!w||w.length===0||E&&w.some(e=>e.id===E))return;let e=new URLSearchParams(y);e.set(`package`,w[0].id),x(e,{replace:!0})},[w,E]);let O=D?`?package=${encodeURIComponent(D)}`:``;J.useEffect(()=>{let t=!1;return f(!0),m(null),(async()=>{try{let r=await n.list(e);if(t)return;l((r??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Ka(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,S]);let A=a.searchableFields??[`name`,`label`,`description`],j=J.useMemo(()=>o.filter(e=>{if(a.listFilter&&!a.listFilter(e.item)||!D)return!1;let t=e.item?._packageId;return(!t||t===`sys_metadata`?null:t)===D}),[o,D,a]),ee=j.filter(e=>!(!Wr(e.item,h,A)||_!==`all`&&e.source!==_)),te=J.useMemo(()=>{let e={all:j.length,artifact:0,runtime:0};for(let t of j)e[t.source]++;return e},[j]),ne=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[j]),re=J.useMemo(()=>j.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[j]),ie=a.listColumns??Ya(a.primaryKey??`name`),M=Rr(),ae=zr(e,M,i?.label??e),se=e=>{let t=`engine.list.col.${e.key}`,n=G(t,M);return n===t?e.label:n};return(0,q.jsx)(Ia,{entry:i??{type:e,label:e},stats:[{label:G(`engine.list.items`,M),value:j.length},{label:G(`engine.list.filtered`,M),value:ee.length},...ne>0?[{label:G(`engine.list.invalid`,M),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,q.jsx)(P,{className:`w-3.5 h-3.5`}),ne]})}]:[],...re>0?[{label:G(`engine.list.warnings`,M),value:(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,q.jsx)(P,{className:`w-3.5 h-3.5`}),re]})}]:[]],actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(za,{entry:i,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,M),children:(0,q.jsx)(oe,{className:`h-4 w-4`})}),(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsxs)(z,{size:`sm`,variant:a.createFields?`default`:`outline`,onClick:()=>t(`./new${O}`),title:a.createFields?U(`engine.list.createHint`,M,{type:ae}):void 0,children:[(0,q.jsx)(F,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,M)]})]}),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)(tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(B,{className:`pl-8`,placeholder:G(`engine.list.search`,M),value:h,onChange:e=>g(e.target.value)})]}),(0,q.jsxs)(k,{value:_,onValueChange:v,children:[(0,q.jsx)(dt,{className:`w-[180px]`,children:(0,q.jsx)(xt,{})}),(0,q.jsxs)(gt,{children:[(0,q.jsxs)(ve,{value:`all`,children:[G(`engine.list.allSources`,M),` (`,te.all,`)`]}),(0,q.jsxs)(ve,{value:`artifact`,children:[G(`engine.list.source.artifact`,M),` (`,te.artifact,`)`]}),(0,q.jsxs)(ve,{value:`runtime`,children:[G(`engine.list.source.runtime`,M),` (`,te.runtime,`)`]})]})]})]}),(d||w===null)&&(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[G(`engine.edit.loading`,M),` `,e,`…`]}),p&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:p}),!d&&!p&&w!==null&&w.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:`No project packages installed`}),(0,q.jsx)(gr,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!d&&!p&&w!==null&&w.length>0&&ee.length===0&&(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:j.length===0?U(`engine.list.emptyType`,M,{type:ae}):U(`engine.list.emptyQuery`,M,{query:h})}),(0,q.jsx)(gr,{children:a.emptyStateHint??(i?.allowOrgOverride||i?.allowRuntimeCreate?U(`engine.list.createHint`,M,{type:ae}):G(`engine.list.readOnlyHint`,M))}),j.length===0&&(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,q.jsx)(`div`,{className:`mt-4`,children:(0,q.jsxs)(z,{onClick:()=>t(`./new${O}`),children:[(0,q.jsx)(F,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,M)]})})]}),!d&&ee.length>0&&(0,q.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,q.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[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:se(e)},e.key)),(0,q.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:G(`engine.list.col.source`,M)})]})}),(0,q.jsx)(`tbody`,{className:`divide-y`,children:ee.map((e,t)=>{let n=a.primaryKey??`name`,r=String(e.item[n]??`(unnamed-${t})`),i=e.item._packageId,o=i&&i!==`sys_metadata`?`?package=${encodeURIComponent(i)}`:O,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
3
|
`)+(l.length>3?`\n+${l.length-3} more`:``):d?u.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
4
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):Xa(i);return(0,q.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s&&(0,q.jsx)(`span`,{className:`inline-flex`,"aria-label":G(`engine.list.invalidTitle`,M),title:`${U(`engine.list.invalidCount`,M,{count:l.length})}\n${f}`,children:(0,q.jsx)(P,{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`,M),title:`${U(`engine.list.warnCount`,M,{count:u.length})}\n${f}`,children:(0,q.jsx)(P,{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)(dn,{className:`h-3 w-3`})}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px] `+(e.source===`artifact`?`border-sky-500/50 text-sky-700 dark:text-sky-300`:`border-emerald-500/50 text-emerald-700 dark:text-emerald-300`),title:e.source===`artifact`?`${G(`engine.list.source.artifactDesc`,M)}${e.item._packageId?` (${e.item._packageId})`:``}`:G(`engine.list.source.runtimeDesc`,M),children:G(`engine.list.source.${e.source}`,M)})]})]},r+t)})})]})})]})})}function Ya(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Xa(e){if(e==null||e===``)return(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,q.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Za={unchanged:{badge:`bg-muted text-muted-foreground border border-border`,row:``},modified:{badge:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,row:`bg-amber-50/50 dark:bg-amber-950/20`},added:{badge:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,row:`bg-emerald-50/50 dark:bg-emerald-950/20`},removed:{badge:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`,row:`bg-rose-50/50 dark:bg-rose-950/20`}};function Qa(e,t){let n=$a(e)?e:{},r=$a(t)?t:{},i=new Set([...Object.keys(n),...Object.keys(r)]),a=[];for(let e of i){let t=e in n,i=e in r,o=n[e],s=r[e],c;c=t&&!i?`removed`:!t&&i?`added`:eo(o)===eo(s)?`unchanged`:`modified`,a.push({key:e,status:c,codeValue:o,effectiveValue:s})}let o={modified:0,added:1,removed:2,unchanged:3};return a.sort((e,t)=>o[e.status]===o[t.status]?e.key.localeCompare(t.key):o[e.status]-o[t.status]),a}function $a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function eo(e){try{return JSON.stringify(e,(e,t)=>$a(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function to(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function no(e,t){if(e==null)return 0;let n=0;for(let r of Qa(e,t))r.status!==`unchanged`&&(n+=1);return n}function ro({layered:e,loading:t,locale:n}){if(t)return(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.edit.loading`,n)});if(!e)return(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,q.jsxs)(En,{defaultValue:`diff`,className:`w-full`,children:[(0,q.jsxs)(un,{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)(b,{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)(b,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,q.jsx)(b,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,q.jsxs)(Nt,{value:`effective`,children:[G(`engine.layers.effective`,n),(0,q.jsx)(b,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,q.jsx)(Ln,{value:`diff`,className:`mt-3`,children:(0,q.jsx)(io,{code:e.code,effective:e.effective,locale:n})}),(0,q.jsx)(Ln,{value:`code`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.code,emptyHint:G(`engine.layers.diff.noBaseline`,n)})}),(0,q.jsx)(Ln,{value:`overlay`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.overlay,emptyHint:G(`engine.layers.diff.noChanges`,n)})}),(0,q.jsx)(Ln,{value:`effective`,className:`mt-3`,children:(0,q.jsx)(oo,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function io({code:e,effective:t,locale:n}){let[r,i]=J.useState(!1);if(e==null)return(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let a=J.useMemo(()=>Qa(e,t),[e,t]),o=J.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]),s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:U(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,q.jsx)(Qt,{checked:r,onCheckedChange:i,"aria-label":G(`engine.layers.diff.showUnchanged`,n)}),G(`engine.layers.diff.showUnchanged`,n),(0,q.jsx)(b,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noChanges`,n)}):(0,q.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] bg-muted/50 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.field`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.code`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.effective`,n)}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.status`,n)})]}),(0,q.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Za[e.status];return(0,q.jsxs)(`div`,{className:H(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,q.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,q.jsx)(ao,{value:e.codeValue,muted:e.status===`added`}),(0,q.jsx)(ao,{value:e.effectiveValue,muted:e.status===`removed`}),(0,q.jsx)(`div`,{className:`px-3 py-2`,children:(0,q.jsx)(`span`,{className:H(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:G(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function ao({value:e,muted:t}){let n=to(e);return(0,q.jsx)(`div`,{className:H(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function oo({payload:e,emptyHint:t}){if(e==null)return(0,q.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,q.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var so={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},co={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function lo(e,t){return G(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function uo(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function fo(e,t){let n=0;for(let r of Qa(e,t))r.status!==`unchanged`&&(n+=1);return n}function po({published:e,draft:t,locale:n,className:r}){let i=J.useMemo(()=>Qa(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:G(`designer.draftReview.empty`,n)}):(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${co[t]}`,children:[(0,q.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${so[t]}`,children:lo(t,n)}),(0,q.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,q.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:uo(e.effectiveValue)}):t===`removed`?(0,q.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:uo(e.codeValue)}):(0,q.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:uo(e.codeValue)}),(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,q.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:uo(e.effectiveValue)})]})]},e.key)})})}function mo(e){if(typeof e!=`string`)return``;let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``);return/^\d/.test(t)&&(t=`n_${t}`),t.length>64&&(t=t.slice(0,64).replace(/_+$/g,``)),t}function ho(e){if(typeof e!=`string`)return``;let t=e.trim();return t?!/[A-Za-z]/.test(t)||/(s|ses|xes|zes|ches|shes|ies)$/i.test(t)?t:/[^aeiou]y$/i.test(t)?t.replace(/y$/i,`ies`):/(s|x|z|ch|sh)$/i.test(t)?`${t}es`:`${t}s`:``}function go(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function _o(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function vo(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return mo(n);case`plural-en`:return ho(n);case`titlecase`:return go(n);case`first-token`:return _o(n);default:return n}}function yo(e){let{rules:t,draft:n,onPatch:r,enabled:i=!0}=e,a=(0,J.useRef)(new Set),o=(0,J.useRef)({}),s=(0,J.useCallback)(e=>{a.current.add(e)},[]);return(0,J.useEffect)(()=>{if(!i||!t||t.length===0)return;let e={},s=o.current,c={};for(let r of t){let t=n[r.from];if(c[r.from]=t,Object.is(s[r.from],t)||r.untilUserEdits!==!1&&a.current.has(r.to)||r.to in e)continue;let i=vo(r.transform,t);n[r.to]!==i&&(e[r.to]=i)}o.current={...s,...c},Object.keys(e).length>0&&r(e)},[n,i]),{markTouched:s,touched:a.current}}function bo(e,t){let n=e?Object.keys(e):[],r=[],i=e=>{!r.includes(e)&&n.includes(e)&&r.push(e)};for(let e of n)t?.includes(e)&&i(e);for(let e of[`label`,`pluralLabel`,`name`,`description`])i(e);return r}function xo({type:e,name:t,parentItem:n,onOpen:r}){let i=Tr(),a=u(),o=J.useMemo(()=>Wa(e),[e]),[s,c]=J.useState([]),[l,d]=J.useState(``),[f,p]=J.useState({});if(J.useEffect(()=>{if(o.length===0){c([]);return}let e=!1,r=[...o].sort((e,t)=>(e.anchor.order??999)-(t.anchor.order??999)).map(e=>{if(e.anchor.source===`embedded`){let t=e.anchor.extract&&n?e.anchor.extract(n):[];return{childType:e.type,anchor:e.anchor,loading:!1,error:null,items:t.map(So)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return c(r),Promise.all(r.map(async n=>{if(n.anchor.source===`embedded`)return n;try{let r=await i.list(n.childType);if(e)return n;let a=n.anchor.match??(()=>!1),o=r.filter(e=>a(e,t)).map(e=>So(e));return{...n,loading:!1,items:o}}catch(t){return e?n:{...n,loading:!1,error:t instanceof Error?t.message:String(t)}}})).then(t=>{e||c(t)}),()=>{e=!0}},[i,e,t,o,n]),o.length===0)return(0,q.jsxs)(Ze,{children:[(0,q.jsx)(me,{children:`No related metadata`}),(0,q.jsxs)(gr,{children:[`No metadata types are configured to anchor at `,(0,q.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,q.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let m=s.reduce((e,t)=>e+t.items.length,0),h=s.some(e=>e.loading),g=l.trim().toLowerCase();return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,q.jsx)(tt,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,q.jsx)(B,{placeholder:`Search related…`,value:l,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),s.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,o=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,q.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!o})),children:[(0,q.jsx)(st,{className:H(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>{if(n.anchor.source===`embedded`){if(typeof window<`u`){let e=new URL(window.location.href);e.searchParams.set(`tab`,`form`),e.searchParams.delete(`open`),window.location.assign(e.toString())}return}a(`../../${encodeURIComponent(n.childType)}/_new?anchor=${encodeURIComponent(`${e}:${t}`)}`)},title:n.anchor.source===`embedded`?`Edit in Form tab`:`New ${n.childType}`,children:(0,q.jsx)(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)(N,{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)(be,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function So(e){return{name:Co(e,[`name`,`id`,`key`])??`(unnamed)`,label:Co(e,[`label`,`title`,`displayName`]),description:Co(e,[`description`,`summary`]),raw:e}}function Co(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function wo({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=J.useMemo(()=>Rr(),[]),c=Tr(),{entries:l}=Ur(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?Eo[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=J.useState(a),[g,_]=J.useState(!1),[v,y]=J.useState(null),[b,x]=J.useState([]),[S,C]=J.useState(null);J.useEffect(()=>{h(a),y(null),x([]),C(null)},[a,r,e,t]);let w=u!=null&&!u.allowOrgOverride&&!u.allowRuntimeCreate;async function T(){if(!n){y(G(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=To(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:kr(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?G(`engine.validation.failedOne`,s):U(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,q.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,q.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:G(`engine.embedded.saved`,s)}),w&&(0,q.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:G(`engine.embedded.readOnlyParent`,s)}),(0,q.jsx)(Fr,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,q.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,q.jsxs)(z,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(N,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)(at,{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)(P,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsxs)(z,{onClick:T,disabled:g||!n,children:[g?(0,q.jsx)(N,{className:`h-4 w-4 mr-1 animate-spin`}):(0,q.jsx)(at,{className:`h-4 w-4 mr-1`}),U(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function To(e,t,n,r){let i=t.split(`.`),a=structuredClone(e),o=a;for(let e=0;e<i.length-1;e++)o[i[e]]??(o[i[e]]={}),o=o[i[e]];let s=i[i.length-1],c=o[s];if(Array.isArray(c)){let e=c.findIndex(e=>e&&typeof e==`object`&&e.name===n);e>=0?c[e]=r:c.push(r)}else if(c&&typeof c==`object`){let{name:e,...t}=r;c[n]=t}else{let{name:e,...t}=r;o[s]={[n]:t}}return a}var Eo={index:{schema:{type:`object`,required:[`fields`],properties:{name:{type:`string`,title:`Name`,description:`Synthesised from columns if omitted (e.g. idx_email).`},fields:{type:`array`,title:`Fields`,description:`Columns to index, in order.`,items:{type:`string`}},type:{type:`string`,title:`Algorithm`,enum:[`btree`,`hash`,`gin`,`gist`,`brin`],default:`btree`},unique:{type:`boolean`,title:`Unique`,description:`Enforce uniqueness across the indexed columns.`},where:{type:`string`,title:`Partial-index predicate`,description:`Optional WHERE clause for a partial index.`}}}}};function Do({target:e,onClose:t,parentContext:n}){let r=u(),i=e?.kind===`metadata`,a=e?.kind===`embedded`,o=i?e.type:a?e.groupLabel:``,s=i?e.name:a?e.itemName:``;return(0,q.jsx)(Ke,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,q.jsxs)(le,{side:`right`,className:H(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,q.jsxs)(Fe,{className:`px-4 py-3 border-b space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(b,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,q.jsx)($e,{className:`font-mono text-base truncate`,children:s}),(0,q.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,q.jsx)(be,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,q.jsxs)(Se,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,q.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,q.jsx)(Ss,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,q.jsx)(wo,{parentType:e.parentType,parentName:e.parentName,embeddedPath:e.embeddedPath,itemName:e.itemName,editAs:e.editAs,initialRaw:e.raw},`${e.parentType}/${e.parentName}/${e.embeddedPath}/${e.itemName}`)]})]})})}function Oo({type:e,name:t}){let n=i(),r=e??n.type??``,a=t??n.name??``,o=u(),s=Tr(),{entries:c}=Ur(s),l=c.find(e=>e.type===r),[d,f]=J.useState(0),[p,m]=J.useState(0);return(0,q.jsx)(Ia,{entry:l??{type:r,label:r},itemName:a,subtitle:`Version history`,stats:[{label:`Events`,value:p}],actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,q.jsx)(zn,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+1),children:(0,q.jsx)(oe,{className:`h-4 w-4`})})]}),children:(0,q.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,q.jsx)(ko,{type:r,name:a,refreshKey:d,onCount:m,client:s,onRollback:()=>f(e=>e+1)})})})}function ko({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=J.useState([]),[u,d]=J.useState(!0),[f,p]=J.useState(null),[m,h]=J.useState(null),[g,_]=J.useState(null),[v,y]=J.useState(0);J.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function x(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,q.jsxs)(q.Fragment,{children:[u&&(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(N,{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)(Ze,{children:[(0,q.jsx)(me,{children:`No history yet`}),(0,q.jsx)(gr,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,q.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:c.map((e,t)=>{let n=m===t,r=e.op??e.kind,i=e.ts??e.at,o=!!a&&typeof e.version==`number`&&r!==`delete`&&r!==`tombstone`;return(0,q.jsxs)(`li`,{className:`relative`,children:[(0,q.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>h(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&h(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,q.jsxs)(b,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,q.jsx)(b,{className:`text-[10px] `+(r===`delete`||r===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:r===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:r===`publish`?`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`:r===`revert`?`bg-amber-100 text-amber-900 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(r)}),e.actor&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,q.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:Ao(i)}),o&&(0,q.jsx)(z,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),x(e.version)},children:g===e.version?(0,q.jsx)(N,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(w,{className:`h-3.5 w-3.5`})})]}),n&&(0,q.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:jo(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Ao(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function jo(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Mo(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function No(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:$t},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:rn},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:At}},n=t[e]??t.allowed;return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${n.cls}`,children:[(0,q.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function Po({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=J.useState(!1),[o,s]=J.useState(null),[c,l]=J.useState(null),u=J.useCallback(async()=>{a(!0),s(null);try{l((await n.audit(e,t,{limit:100})).events??[])}catch(e){s(String(e?.message??e)),l([])}finally{a(!1)}},[n,e,t]);return J.useEffect(()=>{u()},[u]),(0,q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,G(`engine.edit.auditCount`,r)]}),(0,q.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:G(`engine.edit.refresh`,r),children:[i?(0,q.jsx)(N,{className:`h-3 w-3 animate-spin`}):(0,q.jsx)(oe,{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)(N,{className:`mr-2 h-3 w-3 animate-spin`}),G(`engine.edit.loading`,r)]}):!c||c.length===0?(0,q.jsxs)(Ze,{className:`py-10`,children:[(0,q.jsx)(me,{children:G(`engine.edit.auditEmptyTitle`,r)}),(0,q.jsx)(gr,{children:G(`engine.edit.auditEmptyDescription`,r)})]}):(0,q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,q.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColTime`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColActor`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOperation`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOutcome`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColLock`,r)}),(0,q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColNote`,r)})]})}),(0,q.jsx)(`tbody`,{children:c.map(e=>(0,q.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,q.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:Mo(e.occurredAt)}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,q.jsx)(b,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:No(e.outcome)}),(0,q.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,q.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,q.jsx)(`td`,{className:`max-w-[28ch] truncate px-2 py-1.5 text-muted-foreground`,title:e.note??e.code,children:e.note??e.code})]},String(e.id)))})]})})]})}var Fo=new Map;function Y(e,t){Fo.set(e,t)}function Io(e){return Fo.get(e)}var Lo=new Map;function Ro(e,t){Lo.set(e,t)}function zo(e){return Lo.get(e)}var Bo=new Map;function Vo(e,t){Bo.set(e,t)}function Ho(e){return Bo.get(e)}function Uo(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Ko(e.charCodeAt(r)))for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Ko(e.charCodeAt(r))){for(r++;r<e.length&&Ko(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
5
5
|
`;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(Go(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(Wo(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Wo(t));return o=15}if(Go(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{n as r}from"./infrastructure-CJNwTVno.js";import{B as i,G as a,H as o,g as s,ht as c}from"./framework-BLEk-ou3.js";import{Ds as l,Es as u,Ft as d,Hn as f,It as p,Jn as m,Jt as h,Ln as g,Lt as _,Ma as v,Mt as y,Nt as b,Os as x,Pt as S,Rt as C,Ts as w,Vn as T,Xn as E,Yn as D,Yt as O,Zn as k,_ as A,_c as j,at as M,gi as N,gs as P,h as F,hr as I,it as L,j as R,ja as z,n as B,nt as ee,pc as V,qn as H,qt as te,rt as ne,s as re,t as U,zn as W}from"./ui-components-CrPYFyEM.js";import{r as ie}from"./vendor-ui-utils-rQOI1gAo.js";var G=e(t(),1),K=n(),q=({label:e,description:t,collapsible:n=!1,collapsed:r=!1,columns:i=1,children:a,className:o,gridClassName:s,showBorder:c})=>{let[u,d]=(0,G.useState)(r),f={1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`},p=()=>{n&&d(!u)},h=c??!!e,g=e||t?(0,K.jsxs)(`div`,{className:V(`flex items-start gap-2`,!h&&`mb-4`,n&&`cursor-pointer select-none`),onClick:p,role:n?`button`:void 0,"aria-expanded":n?!u:void 0,children:[n&&(0,K.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:u?(0,K.jsx)(w,{className:`h-4 w-4`}):(0,K.jsx)(l,{className:`h-4 w-4`})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,K.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),t&&(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}):null,_=u?null:(0,K.jsx)(`div`,{className:V(`grid gap-4`,s||f[i]),children:a});return h?(0,K.jsxs)(H,{className:V(`form-section`,o),children:[g&&(0,K.jsxs)(E,{className:`pb-3`,children:[e&&(0,K.jsx)(k,{className:`text-base`,children:e}),t&&(0,K.jsx)(D,{children:t}),n&&(0,K.jsx)(`button`,{type:`button`,className:`absolute right-4 top-4 text-muted-foreground`,onClick:p,"aria-expanded":!u,"aria-label":u?`Expand section`:`Collapse section`,children:u?(0,K.jsx)(w,{className:`h-4 w-4`}):(0,K.jsx)(l,{className:`h-4 w-4`})})]}),_&&(0,K.jsx)(m,{children:_})]}):(0,K.jsxs)(`div`,{className:V(`form-section`,o),children:[g,_]})};function J(e,t){return typeof t==`string`&&t.trim()?{...e,visible:e=>B(t,e)}:e}function ae(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:F(n.type),required:n.required||!1,disabled:t.readOnly||t.mode===`view`||n.readonly,placeholder:n.placeholder,description:n.help||n.description,validation:U(n),field:n,options:n.options,multiple:n.multiple}:{name:e,label:e,type:`input`}}function oe(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return J(ae(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return J(n,n.visibleOn);let r=n.field,i=ae(r,t);return n.type!=null&&(i.type=F(n.type)),n.widget!=null&&(i.widget=n.widget),n.label!=null&&(i.label=n.label),n.placeholder!=null&&(i.placeholder=n.placeholder),n.helpText!=null&&(i.description=n.helpText),n.required!=null&&(i.required=n.required),n.readonly!=null&&(i.disabled=n.readonly||i.disabled),n.immutable!=null&&(i.immutable=n.immutable),n.hidden!=null&&(i.hidden=n.hidden),n.colSpan!=null&&(i.colSpan=n.colSpan),n.options!=null&&(i.options=n.options),n.multiple!=null&&(i.multiple=n.multiple),n.reference!=null&&(i.reference=n.reference),n.maxLength!=null&&(i.maxLength=n.maxLength),n.minLength!=null&&(i.minLength=n.minLength),n.min!=null&&(i.min=n.min),n.max!=null&&(i.max=n.max),n.precision!=null&&(i.precision=n.precision),n.scale!=null&&(i.scale=n.scale),n.language!=null&&(i.language=n.language),Array.isArray(n.fields)&&(i.fields=n.fields),J(i,n.visibleOn)}function Y(e,t){return(e.fields??[]).map(e=>oe(e,t))}var se=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=j(),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)({}),[l,u]=(0,G.useState)(!0),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);G.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{o(await t.getObjectSchema(e.objectName))}catch(e){f(e)}})()},[e.objectName,t]),G.useEffect(()=>{(a||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[a,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,G.useCallback)(t=>Y(t,{objectSchema:a,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[a,e.readOnly,e.mode,e.objectName,r]),g=(0,G.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),_=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(e,t)=>e.name||e.label||`tab-${t}`;if(d)return(0,K.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,K.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let y={type:`form`,fields:e.sections.flatMap(e=>h(e)),layout:`vertical`,defaultValues:s,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:g,onCancel:_},b=e.tabPosition===`left`||e.tabPosition===`right`;return(0,K.jsx)(`div`,{className:V(`w-full`,n,e.className),children:(0,K.jsxs)(ee,{value:p,onValueChange:m,orientation:b?`vertical`:`horizontal`,className:V(b&&`flex gap-4`),children:[(0,K.jsx)(L,{className:V(b?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,K.jsx)(M,{value:v(e,t),className:b?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},v(e,t)))}),(0,K.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,K.jsx)(ne,{value:v(t,n),className:`mt-0`,children:(0,K.jsx)(q,{description:t.description,columns:t.columns||1,children:(0,K.jsx)(i,{schema:{...y,fields:h(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},v(t,n)))})]})})},ce=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=j(),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)({}),[l,d]=(0,G.useState)(!0),[f,p]=(0,G.useState)(null),[m,h]=(0,G.useState)(0),[g,_]=(0,G.useState)(new Set),[y,b]=(0,G.useState)(!1),S=e.sections.length,C=m===0,T=m===S-1;G.useEffect(()=>{(async()=>{if(!t){d(!1);return}try{o(await t.getObjectSchema(e.objectName))}catch(e){p(e)}})()},[e.objectName,t]),G.useEffect(()=>{(a||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){c(e.initialData||e.initialValues||{}),d(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{d(!1)}})()},[a,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let E=(0,G.useCallback)(t=>Y(t,{objectSchema:a,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[a,e.readOnly,e.mode,e.objectName,r]),D=(0,G.useMemo)(()=>m>=0&&m<S?E(e.sections[m]):[],[m,S,e.sections,E]),O=(0,G.useCallback)(async n=>{let r={...s,...n};if(c(r),_(e=>new Set(e).add(m)),T){b(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(r),r;let n;return e.mode===`create`?n=await t.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(n=await t.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(n),n}catch(t){throw e.onError&&e.onError(t),t}finally{b(!1)}}else k(m+1)},[s,m,T,e,t]),k=(0,G.useCallback)(t=>{t>=0&&t<S&&(h(t),e.onStepChange&&e.onStepChange(t))},[S,e]),A=(0,G.useCallback)(()=>{k(m-1)},[m,k]),M=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),N=(0,G.useCallback)(t=>{(e.allowSkip||g.has(t)||t<=m)&&k(t)},[e.allowSkip,g,m,k]);if(f)return(0,K.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:f.message})]});if(l)return(0,K.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let P=e.sections[m];return(0,K.jsxs)(`div`,{className:V(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,K.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,K.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===m,i=g.has(n),a=e.allowSkip||i||n<=m;return(0,K.jsxs)(`li`,{className:V(`relative flex-1`,n!==S-1&&`pr-8 sm:pr-12`),children:[n!==S-1&&(0,K.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,K.jsx)(`div`,{className:V(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,K.jsxs)(`button`,{type:`button`,className:V(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>N(n),disabled:!a,children:[(0,K.jsx)(`span`,{className:V(`flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors`,i&&`bg-primary text-primary-foreground`,r&&!i&&`border-2 border-primary bg-background text-primary`,!r&&!i&&`border-2 border-muted bg-background text-muted-foreground`),children:i?(0,K.jsx)(x,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,K.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,K.jsx)(`span`,{className:V(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,K.jsx)(`div`,{className:`min-h-[200px]`,children:P&&(0,K.jsx)(q,{label:P.label,description:P.description,columns:P.columns||1,children:D.length>0?(0,K.jsx)(i,{schema:{type:`form`,fields:D,layout:`vertical`,defaultValues:s,showSubmit:!1,showCancel:!1,onSubmit:O}}):(0,K.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,K.jsx)(`div`,{children:e.showCancel!==!1&&(0,K.jsx)(I,{variant:`ghost`,onClick:M,children:e.cancelText||`Cancel`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,m+1,` of `,S]}),!C&&(0,K.jsxs)(I,{variant:`outline`,onClick:A,children:[(0,K.jsx)(u,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),T?(0,K.jsxs)(I,{onClick:()=>O(s),disabled:y||e.mode===`view`,children:[y&&(0,K.jsx)(v,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),y?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,K.jsxs)(I,{onClick:()=>O(s),children:[e.nextText||`Next`,(0,K.jsx)(w,{className:`h-4 w-4 ml-1`})]})]})]})]})},le=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=j(),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)({}),[l,u]=(0,G.useState)(!0),[d,f]=(0,G.useState)(null);(0,G.useEffect)(()=>{(async()=>{if(!t){u(!1);return}try{o(await t.getObjectSchema(e.objectName))}catch(e){f(e),u(!1)}})()},[e.objectName,t]),(0,G.useEffect)(()=>{(a||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){c(e.initialData||e.initialValues||{}),u(!1);return}if(!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[a,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let p=(0,G.useCallback)(t=>Y(t,{objectSchema:a,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[a,e.readOnly,e.mode,e.objectName,r]),m=(0,G.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),g=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),_=(0,G.useMemo)(()=>e.sections.slice(0,1),[e.sections]),v=(0,G.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,G.useMemo)(()=>e.sections.flatMap(e=>p(e)),[e.sections,p]);let y=e.splitDirection||`horizontal`,b=e.splitSize||50;if(d)return(0,K.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,K.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let x={type:`form`,layout:`vertical`,defaultValues:s,onSubmit:m,onCancel:g},S=(t,n)=>(0,K.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,r)=>(0,K.jsx)(q,{label:t.label,description:t.description,columns:t.columns||1,children:(0,K.jsx)(i,{schema:{...x,fields:p(t),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||r))});return(0,K.jsx)(`div`,{className:V(`w-full`,n,e.className),children:(0,K.jsxs)(O,{orientation:y,className:`min-h-[300px] rounded-lg border`,children:[(0,K.jsx)(h,{defaultSize:b,minSize:20,children:S(_,v.length===0)}),v.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(te,{withHandle:e.splitResizable!==!1}),(0,K.jsx)(h,{defaultSize:100-b,minSize:20,children:S(v,!0)})]})]})})},X=e=>e==null?void 0:e.id??e._id??e.recordId,ue=new Set([`id`,`_id`,`recordId`]);function de(e,t){return e?Object.entries(e).every(([e,n])=>e===t||ue.has(e)?!0:n==null||n===``):!0}function fe(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)de(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...t,[e.relationshipField]:{$ref:0}}});return r}function pe(e,t,n,r){let i=[{object:e,action:`update`,id:t,data:n}];for(let e of r){let n=(e.rows||[]).map(n=>({...n,[e.relationshipField]:t})),{toCreate:r,toUpdate:a,toDelete:o}=me(e.original||[],n);for(let t of r){if(de(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:o})}for(let t of a)i.push({object:e.childObject,action:`update`,id:X(t),data:t});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function me(e,t){let n=new Set(t.map(X).filter(Boolean));return{toCreate:t.filter(e=>!X(e)),toUpdate:t.filter(e=>X(e)),toDelete:(e||[]).map(X).filter(e=>!!e&&!n.has(e))}}function he(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}function ge(e){return Array.isArray(e)?e:e&&Array.isArray(e.records)?e.records:e&&Array.isArray(e.data)?e.data:e&&(e.id||e._id)?[e]:[]}async function _e(e,t,n){return n.length===0?[]:typeof e.bulk==`function`?ge(await e.bulk(t,`create`,n)):ge(await Promise.all(n.map(n=>e.create(t,n))))}async function ve(e,t,n,r){let i=[],a=r.rows.filter(e=>X(e)||!de(e,r.relationshipField)).map(e=>({...e,[r.relationshipField]:n}));if(r.original!==void 0){let{toCreate:t,toUpdate:n,toDelete:o}=me(r.original,a),s=await _e(e,r.childObject,t);for(let e of s){let t=X(e);t&&i.push({object:r.childObject,id:t})}await Promise.all(n.map(t=>e.update(r.childObject,X(t),t))),await Promise.all(o.map(t=>e.delete(r.childObject,t)))}else{let t=await _e(e,r.childObject,a);for(let e of t){let t=X(e);t&&i.push({object:r.childObject,id:t})}}if(r.totalField){let i=he(r.rows,r.amountField||`amount`);await e.update(t,n,{[r.totalField]:i})}return{created:i}}var ye=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),be=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),xe=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`file`,`image`,`avatar`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function Se(e){switch(e){case`number`:case`percent`:case`rating`:case`slider`:return`number`;case`currency`:return`currency`;case`date`:case`datetime`:case`time`:return`date`;case`select`:case`picklist`:case`radio`:case`boolean`:case`toggle`:return`select`;case`lookup`:case`master_detail`:return`lookup`;default:return`text`}}function Ce(e){if(e?.type===`boolean`||e?.type===`toggle`)return[{label:`Yes`,value:`true`},{label:`No`,value:`false`}];let t=e?.options;if(Array.isArray(t))return t.map(e=>typeof e==`object`&&e?{label:String(e.label??e.value),value:String(e.value)}:{label:String(e),value:String(e)})}function we(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){let n=i;if(n?.reference===t){if(n?.type===`master_detail`)return e;n?.type===`lookup`&&!r&&(r=e)}}return r}var Te=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],Ee={select:0,currency:1,number:1,lookup:2,date:3,text:4};function De(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>Te.includes(e.field))??e[0];r&&n.add(r.field);for(let t of e)t.required&&n.add(t.field);let i=e.map((e,t)=>({c:e,i:t})).filter(({c:e})=>!n.has(e.field)).sort((e,t)=>(Ee[e.c.type]??5)-(Ee[t.c.type]??5)||e.i-t.i);for(let{c:e}of i){if(n.size>=t)break;n.add(e.field)}return e.map(e=>n.has(e.field)?e:{...e,defaultHidden:!0})}function Oe(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;if(ye.has(e)||r.has(e)||be.has(e)||n?.system||n?.readonly||n?.hidden||xe.has(n?.type))continue;let a={field:e,label:n?.label||e,type:Se(n?.type),required:!!n?.required},o=Ce(n);a.type===`select`&&o&&(a.options=o),a.type===`lookup`&&(a.reference=n?.reference,a.displayField=n?.display_field||n?.reference_field),n?.readonlyWhen&&(a.readonlyWhen=n.readonlyWhen),(n?.requiredWhen??n?.conditionalRequired)&&(a.requiredWhen=n.requiredWhen??n.conditionalRequired);let s=typeof n?.expression==`string`?n.expression:n?.expression?.source;s&&typeof s==`string`&&(a.computed=!0,a.expr=s,a.required=!1,typeof n?.scale==`number`&&(a.scale=n.scale)),i.push(a)}return De(i,t.maxColumns??6)}var ke=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function Ae(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;ye.has(e)||r.has(e)||be.has(e)||n?.system||n?.hidden||ke.has(n?.type)||i.push(e)}return i}var je=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`file`,`image`,`avatar`,`attachment`,`json`,`location`,`address`]);function Me(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=Ae(e,{relationshipField:n.relationshipField});return i.some(e=>je.has(r[e]?.type))||i.length>8?`form`:`grid`}var Ne=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function Pe(e){let t=e.filter(e=>e.type===`number`||e.type===`currency`);if(t.length===0)return;let n=t.find(e=>e.computed);if(n)return n.field;let r=t.find(e=>Ne.includes(e.field));if(r)return r.field;let i=[...t].reverse().find(e=>e.type===`currency`);return i?i.field:t[t.length-1].field}function Fe(e,t,n,r={}){let i=r.relationshipField||we(t,n);if(!i)throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);let a=r.columns?.length?r.columns:Oe(t,{relationshipField:i}),o=r.amountField||Pe(a);return{childObject:e,relationshipField:i,columns:a,formFields:Ae(t,{relationshipField:i}),mode:Me(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>be.has(e))}}function Ie(e){if(!e)return{};let t={};return e.querySelectorAll(`[name]`).forEach(e=>{let n=e.getAttribute(`name`);if(n){if(e.tagName===`INPUT`){let r=e;if(r.type===`checkbox`){t[n]=r.checked;return}if(r.type===`radio`){r.checked&&(t[n]=r.value);return}if(r.type===`number`||r.type===`range`){if(r.value===``){t[n]=null;return}let e=Number(r.value);t[n]=Number.isFinite(e)?e:r.value;return}t[n]=r.value;return}t[n]=e.value}}),t}var Le=({details:e,state:t,setRows:n,formHostRef:r,taxRateField:i,formKey:a,onRowExpand:o,onAddViaForm:s})=>{let[c,l]=(0,G.useState)({}),u=(0,G.useRef)(``);(0,G.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=Ie(e),n;try{n=JSON.stringify(t)}catch{n=String(Math.random())}n!==u.current&&(u.current=n,l(t))};t();let n=()=>t();e.addEventListener(`input`,n),e.addEventListener(`change`,n);let i=[120,360,800].map(e=>setTimeout(t,e));return()=>{e.removeEventListener(`input`,n),e.removeEventListener(`change`,n),i.forEach(clearTimeout)}},[r,a,e.length]);let d=c[i],f=d===void 0?null:Number.isFinite(Number(d))?Number(d):0,p=e.reduce((e,n,r)=>e+he(t[r]?.rows??[],n.amountField||`amount`),0),m=f!==null&&e.some(e=>!!e.amountField),h=f??0,g=h/100*p,_=p+g,v=e=>`¥${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return(0,K.jsxs)(K.Fragment,{children:[e.map((e,r)=>(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,K.jsx)(A,{value:t[r]?.rows??[],onChange:e=>n(r,e),contextRecord:c,...e.inlineMode===`form`||(e.formFields?.length??0)>(e.columns?.length??0)?{onRowExpand:e=>o(r,e)}:{},displayMode:e.inlineMode===`form`?`list`:`grid`,...e.inlineMode===`form`?{onAdd:()=>s(r)}:{},field:{columns:e.columns,total_field:m?void 0:e.amountField||(e.totalField?`amount`:void 0),sort_field:e.sortField,min_rows:e.minRows,max_rows:e.maxRows,add_label:e.inlineMode===`form`?e.addLabel||`Add`:e.addLabel}}):(0,K.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${r}`)),m&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,K.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:v(p)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,h,`%)`]}),(0,K.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:v(g)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,K.jsx)(`dt`,{children:`Total`}),(0,K.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:v(_)})]})]})})]})},Z=({schema:e,dataSource:t,className:n})=>{let r=e.details||[],i=e.mode===`edit`&&!!e.recordId,a=r.some(e=>!e.relationshipField||!e.columns?.length),[o,s]=(0,G.useState)(a?null:r),c=o??r;(0,G.useEffect)(()=>{if(!a){s(r);return}if(!t||typeof t.getObjectSchema!=`function`)return;let n=!1;return(async()=>{let i=await Promise.all(r.map(async n=>{if(n.relationshipField&&n.columns?.length)return n;try{let r=await t.getObjectSchema(n.childObject),i=Fe(n.childObject,r,e.objectName,{relationshipField:n.relationshipField,columns:n.columns,amountField:n.amountField});return{...n,relationshipField:i.relationshipField,columns:i.columns,formFields:n.formFields??i.formFields,inlineMode:n.inlineMode??i.mode,amountField:n.amountField??i.amountField,sortField:n.sortField??i.sortField}}catch{return n}}));n||s(i)})(),()=>{n=!0}},[t,e.objectName,e.details]);let[l,u]=(0,G.useState)(()=>r.map(()=>({rows:[],original:[]}))),d=(0,G.useRef)(l);d.current=l;let[f,p]=(0,G.useState)(0),[h,g]=(0,G.useState)(!1),_=(0,G.useRef)(!1),v=(0,G.useRef)(null),y=(0,G.useCallback)(()=>{_.current=!1,g(!1),v.current&&=(clearTimeout(v.current),null)},[]);(0,G.useEffect)(()=>{let n=!1;if(!(!i||!t))return(async()=>{let r=await Promise.all(c.map(async n=>{if(!n.relationshipField)return{rows:[],original:[]};try{let r=(await t.find(n.childObject,{$filter:{[n.relationshipField]:e.recordId},$top:500}))?.data??[];return{rows:r.map(e=>({...e})),original:r.map(e=>({...e}))}}catch{return{rows:[],original:[]}}}));n||u(r)})(),()=>{n=!0}},[i,t,e.recordId,o]);let b=(0,G.useCallback)((e,t)=>{u(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),x=e.taxRateField||`tax_rate`,[S,C]=(0,G.useState)(null),w=S?l[S.detailIdx]?.rows?.[S.rowIdx]:void 0,T=S?c[S.detailIdx]:void 0,D=(0,G.useCallback)((e,t,n)=>{u(r=>r.map((r,i)=>i===e?{...r,rows:r.rows.map((e,r)=>r===t?{...e,...n}:e)}:r))},[]),O=(0,G.useCallback)(e=>{u(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t);return C({detailIdx:e,rowIdx:n[e].rows.length-1,isNew:!0}),n})},[]),A=(0,G.useCallback)(()=>{C(e=>(e?.isNew&&u(t=>t.map((t,n)=>n===e.detailIdx?{...t,rows:t.rows.filter((t,n)=>n!==e.rowIdx)}:t)),null))},[]),j=(0,G.useCallback)(async t=>{y(),ie.success(i?e.title?`${e.title} saved`:`Saved`:`Created`),i||(u(c.map(()=>({rows:[],original:[]}))),p(e=>e+1)),await e.onSuccess?.(t)},[i,e.onSuccess,e.title,c.length,y]),M=(0,G.useCallback)(t=>{y(),ie.error(t?.message||`Save failed`),e.onError?.(t)},[e,y]),N=(0,G.useCallback)(async n=>{let r=[];for(let a=0;a<c.length;a++){let o=c[a],{rows:s,original:l}=d.current[a];if(!o.relationshipField)continue;let{created:u}=await ve(t,e.objectName,n,{childObject:o.childObject,relationshipField:o.relationshipField,rows:s,original:i?l:void 0,amountField:o.amountField,totalField:o.totalField});r.push(...u)}return r},[c,i,t,e.objectName]),P=(0,G.useCallback)(async n=>{let r=X(n)??e.recordId;if(!r)throw Error(`MasterDetailForm: parent record has no id after save`);if(!t)throw Error(`MasterDetailForm: dataSource is required`);let a=[];try{a=await N(r)}catch(n){throw i||await Promise.allSettled([...a.map(e=>t.delete(e.object,e.id)),t.delete(e.objectName,r)]),n}await j(n)},[t,i,N,e,j]),F=typeof t?.batchTransaction==`function`,L=(0,G.useCallback)(async n=>{let r=t,a={...n};c.forEach((e,t)=>{e.totalField&&(a[e.totalField]=he(d.current[t]?.rows??[],e.amountField||`amount`))});let o=i?pe(e.objectName,e.recordId,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:d.current[t]?.rows??[],original:d.current[t]?.original??[]}))):fe(e.objectName,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:d.current[t]?.rows??[]})));return(await r.batchTransaction(o))?.results?.[0]??{...a,id:e.recordId}},[t,c,e.objectName,e.recordId,i]),R=(0,G.useMemo)(()=>({type:`object-form`,objectName:e.objectName,mode:e.mode??`create`,recordId:e.recordId,initialValues:e.initialValues,initialData:e.initialData,formType:e.formType,sections:e.sections,fields:e.fields,title:e.title,showSubmit:!1,showCancel:!1,...F?{submitHandler:L,onSuccess:j}:{onSuccess:P},onError:M}),[e,P,F,L,j,M]),z=(0,G.useRef)(null),B=e.submitText??(i?`Save`:`Create`),ee=(0,G.useCallback)(()=>{_.current||z.current?.querySelector(`form`)&&(_.current=!0,g(!0),setTimeout(()=>{(z.current?.querySelector(`form`))?.requestSubmit()},0),v.current=setTimeout(()=>y(),1500))},[y]);return(0,G.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),(0,K.jsxs)(`div`,{className:V(`space-y-6`,n,e.className),children:[(0,K.jsx)(`div`,{ref:z,children:(0,K.jsx)($,{schema:R,dataSource:t},f)}),(0,K.jsx)(Le,{details:c,state:l,setRows:b,formHostRef:z,taxRateField:x,formKey:f,onRowExpand:(e,t)=>C({detailIdx:e,rowIdx:t}),onAddViaForm:O}),S&&T&&(0,K.jsxs)(H,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,K.jsxs)(E,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,K.jsxs)(k,{className:`text-sm font-medium`,children:[T.title||`Line item`,` — row `,S.rowIdx+1]}),(0,K.jsx)(I,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:A,children:`Close`})]}),(0,K.jsx)(m,{children:(0,K.jsx)($,{schema:{type:`object-form`,objectName:T.childObject,mode:`edit`,initialData:w??{},...T.formFields?.length?{fields:T.formFields}:{},submitText:`Apply`,submitHandler:async e=>e,onSuccess:e=>{D(S.detailIdx,S.rowIdx,e),C(null)},onCancel:A},dataSource:t},`row-${S.detailIdx}-${S.rowIdx}`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,K.jsx)(I,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:h,"data-testid":`md-form-cancel`,children:`Cancel`}),(0,K.jsx)(I,{type:`button`,onClick:ee,disabled:h||a&&!o,"data-testid":`md-form-submit`,children:h?`Saving…`:B})]})]})},Re=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),ze=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),Be=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function Ve(e){return ze.has(e)}function He(e){return Be.has(e)}function Ue(e){return e<=3?1:2}function We(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&Ve(e.type)?{...e,colSpan:t}:e)}var Ge=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function Ke(e,t){return e.filter(e=>{if(Ge.has(e.name))return!1;let n=t?.fields?.[e.name];return!(n?.hidden===!0||n?.readonly===!0)})}function qe(e,t){return e.filter(e=>{if(e.type&&Re.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!He(n.type):!0})}function Je(e){return e<=1?`default`:e===2?`xl`:`full`}function Q(e,t,n,r){let i=[...e];if(i=Ke(i,t),r===`create`&&(i=qe(i,t)),n!==void 0)return i=We(i,n),{fields:i,columns:n};let a=Ue(i.length);return i=We(i,a),{fields:i,columns:a}}var Ye=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),Xe=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function Ze(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!Ye.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(Xe.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var Qe={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},$e=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=j(),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)([]),[l,u]=(0,G.useState)({}),[f,m]=(0,G.useState)(!0),[h,g]=(0,G.useState)(null),v=e.open!==!1,y=e.drawerSide||`right`,[b,x]=(0,G.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,G.useEffect)(()=>{(async()=>{if(!t){m(!1);return}try{o(await t.getObjectSchema(e.objectName))}catch(e){g(e),m(!1)}})()},[e.objectName,t]),(0,G.useEffect)(()=>{(a||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){u(e.initialData||e.initialValues||{}),m(!1);return}if(!t){u(e.initialData||e.initialValues||{}),m(!1);return}try{u(await t.findOne(e.objectName,e.recordId)||{})}catch(e){g(e)}finally{m(!1)}})()},[a,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let w=(0,G.useCallback)(t=>Y(t,{objectSchema:a,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[a,e.readOnly,e.mode,e.objectName,r]);(0,G.useEffect)(()=>{if(!a&&t)return;if(e.customFields?.length){c(e.customFields),m(!1);return}if(e.sections?.length){m(!1);return}if(!a)return;let n=e.fields||Object.keys(a.fields||{}),i=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let o=a.fields?.[n];o&&i.push({name:n,label:r(e.objectName,n,o.label||n),type:F(o.type),required:o.required||!1,disabled:e.readOnly||e.mode===`view`||o.readonly,placeholder:o.placeholder,description:o.help||o.description,validation:U(o),field:o,options:o.options,multiple:o.multiple})}c(i),m(!1)},[a,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let T=(0,G.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;try{let r,i=Ze(n,a);return e.mode===`create`?r=await t.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t,a]),E=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),D=(0,G.useMemo)(()=>{if(e.drawerWidth)return y===`left`||y===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,y]),O={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:l,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:T,onCancel:E},k=()=>{if(h)return(0,K.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(f)return(0,K.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=b[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>x(e=>({...e,[r]:!i})):void 0});let a=w(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,K.jsx)(i,{schema:{...O,fields:t}})}let t=Q(s,a,e.columns,e.mode),n=Qe[t.columns||1];return(0,K.jsx)(i,{schema:{...O,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},A=e.subforms,M=A?.length&&e.mode!==`view`?(0,K.jsx)(Z,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:e.submitText,details:A,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t}):k();return(0,K.jsx)(S,{open:v,onOpenChange:e.onOpenChange,children:(0,K.jsxs)(d,{side:y,className:V(`overflow-y-auto`,n,e.className),style:D,children:[(e.title||e.description)&&(0,K.jsxs)(_,{children:[e.title&&(0,K.jsx)(C,{children:e.title}),e.description?(0,K.jsx)(p,{children:e.description}):(0,K.jsx)(p,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,K.jsx)(`div`,{className:`@container py-4`,children:M})]})})},et={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},tt={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},nt=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:a}=j(),o=r(),s=(0,G.useCallback)(t=>{if(!o?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}o.checkField(e.objectName,r.name,`read`)&&(!o.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[o,e.objectName,e.mode]),[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)([]),[p,m]=(0,G.useState)({}),[h,_]=(0,G.useState)(!0),[b,x]=(0,G.useState)(null),[S,C]=(0,G.useState)(!1),w=e.open!==!1,E=(0,G.useId)(),D=(0,G.useMemo)(()=>e.sections?.length||e.customFields?.length?null:Q(u,c,e.columns,e.mode),[u,c,e.columns,e.mode,e.sections,e.customFields]),O=et[(0,G.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(D?.columns&&D.columns>1)return Je(D.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return Je(t)}return`default`},[e.modalSize,D,e.sections])]||et.default;(0,G.useEffect)(()=>{(async()=>{if(!t){_(!1);return}try{l(await t.getObjectSchema(e.objectName))}catch(e){x(e),_(!1)}})()},[e.objectName,t]),(0,G.useEffect)(()=>{(c||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){m(e.initialData||e.initialValues||{}),_(!1);return}if(!t){m(e.initialData||e.initialValues||{}),_(!1);return}try{m(await t.findOne(e.objectName,e.recordId)||{})}catch(e){x(e)}finally{_(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let k=(0,G.useCallback)(t=>Y(t,{objectSchema:c,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:a}),[c,e.readOnly,e.mode,e.objectName,a]);(0,G.useEffect)(()=>{if(!c&&t)return;if(e.customFields?.length){d(e.customFields),_(!1);return}if(e.sections?.length){_(!1);return}if(!c)return;let n=e.fields||Object.keys(c.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let i=c.fields?.[n];i&&r.push({name:n,label:a(e.objectName,n,i.label||n),type:F(i.type),required:i.required||!1,disabled:e.readOnly||e.mode===`view`||i.readonly,placeholder:i.placeholder,description:i.help||i.description,validation:U(i),field:i,options:i.options,multiple:i.multiple})}d(r),_(!1)},[c,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let A=(0,G.useCallback)(async n=>{C(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=Ze(n,c);if(o?.isLoaded){let t={};for(let n of Object.keys(i))o.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}return e.mode===`create`?r=await t.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{C(!1)}},[e,t,c,o]),N=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),P=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,z=e.showSubmit!==!1&&e.mode!==`view`,B=e.showCancel!==!1,H=e.submitText||(e.mode===`create`?`Create`:`Update`),te=e.cancelText||`Cancel`,re={type:`form`,layout:P,defaultValues:p,submitLabel:H,cancelLabel:te,showSubmit:z,showCancel:B,onSubmit:A,onCancel:N,showActions:!1,id:E},ie=()=>{if(b)return(0,K.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:b.message})]});if(h)return(0,K.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(y,{className:`h-4 w-24`}),(0,K.jsx)(y,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),r=e=>(0,K.jsx)(i,{schema:{...re,fields:s(k(e))}});return e.contentLayout===`tabbed`&&t.length>1?(0,K.jsxs)(ee,{defaultValue:n(t[0],0),className:`w-full`,children:[(0,K.jsx)(L,{className:`mb-4`,children:t.map((e,t)=>(0,K.jsx)(M,{value:n(e,t),children:e.label||`Section ${t+1}`},n(e,t)))}),t.map((e,t)=>(0,K.jsx)(ne,{value:n(e,t),children:(0,K.jsx)(q,{description:e.description,columns:e.columns||1,gridClassName:tt[e.columns||1],children:r(e)})},n(e,t)))]}):(0,K.jsx)(`div`,{className:`space-y-6`,children:t.map((e,t)=>(0,K.jsx)(q,{label:e.label,description:e.description,columns:e.columns||1,gridClassName:tt[e.columns||1],children:r(e)},n(e,t)))})}let t=D??Q(u,c,e.columns,e.mode),n=tt[t.columns||1];return(0,K.jsx)(i,{schema:{...re,fields:s(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},J=e.subforms;if(J?.length&&e.mode!==`view`)return(0,K.jsx)(g,{open:w,onOpenChange:e.onOpenChange,children:(0,K.jsxs)(R,{className:V(O,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,K.jsxs)(T,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,K.jsx)(f,{children:e.title}),e.description?(0,K.jsx)(W,{children:e.description}):(0,K.jsx)(W,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,K.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,K.jsx)(Z,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:H,details:J,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t})})]})});let ae=!h&&!b&&(z||B);return(0,K.jsx)(g,{open:w,onOpenChange:e.onOpenChange,children:(0,K.jsxs)(R,{className:V(O,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,K.jsxs)(T,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,K.jsx)(f,{children:e.title}),e.description?(0,K.jsx)(W,{children:e.description}):(0,K.jsx)(W,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,K.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:ie()}),ae&&(0,K.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[B&&(0,K.jsx)(I,{type:`button`,variant:`outline`,onClick:N,disabled:S,className:`w-full sm:w-auto`,children:te}),z&&(0,K.jsxs)(I,{type:`submit`,form:E,disabled:S,className:`w-full sm:w-auto`,children:[S&&(0,K.jsx)(v,{className:`mr-2 h-4 w-4 animate-spin`}),H]})]})})]})})};function rt(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:void 0,collapsible:typeof e.collapsible==`boolean`?e.collapsible:void 0,collapsed:typeof e.collapsed==`boolean`?e.collapsed:void 0})).filter(e=>e.key):[]}function it(e,t){let n=rt(t);if(n.length===0)return null;let r=new Set(n.map(e=>e.key)),i=e=>{let t=e.group;return typeof t==`string`&&r.has(t)?t:null};if(!e.some(e=>i(e)!==null))return null;let a=new Map;for(let e of n)a.set(e.key,[]);let o=[];for(let t of e){let e=i(t);e?a.get(e).push(t):o.push(t)}let s=[];for(let e of n){let t=a.get(e.key);t.length!==0&&s.push({name:e.key,label:e.label??e.key,fields:t.map(e=>e.name),...e.collapsible===void 0?{}:{collapsible:e.collapsible},...e.collapsed===void 0?{}:{collapsed:e.collapsed}})}return o.length>0&&s.push({fields:o.map(e=>e.name)}),s}var $=({schema:e,dataSource:t})=>{let n=r(),i=(0,G.useMemo)(()=>{if(!n?.isLoaded)return e;let t=t=>t?.name?n.checkField(e.objectName,t.name,`read`)?!n.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,r=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:r(e.fields),sections:e.sections?.map(e=>({...e,fields:r(e.fields)}))}},[e,n]),{sectionLabel:a}=j(),o=e=>e?.name?a(i.objectName,e.name,e.label||e.name):e?.label;if(i.subforms?.length&&i.mode!==`view`&&i.formType!==`drawer`&&i.formType!==`modal`)return(0,K.jsx)(Z,{schema:{type:`object-master-detail-form`,objectName:i.objectName,mode:i.mode===`edit`?`edit`:`create`,recordId:i.recordId,initialValues:i.initialValues,initialData:i.initialData,formType:i.formType===`tabbed`?`tabbed`:`simple`,sections:i.sections,fields:i.fields,title:i.title,submitText:i.submitText,details:i.subforms,onSuccess:i.onSuccess,onError:i.onError,onCancel:i.onCancel,className:i.className},dataSource:t});if(i.formType===`tabbed`&&i.sections?.length)return(0,K.jsx)(se,{schema:{...i,formType:`tabbed`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:i.defaultTab,tabPosition:i.tabPosition},dataSource:t,className:i.className});if(i.formType===`wizard`&&i.sections?.length)return(0,K.jsx)(ce,{schema:{...i,formType:`wizard`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:i.allowSkip,showStepIndicator:i.showStepIndicator,nextText:i.nextText,prevText:i.prevText,onStepChange:i.onStepChange},dataSource:t,className:i.className});if(i.formType===`split`&&i.sections?.length)return(0,K.jsx)(le,{schema:{...i,formType:`split`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:i.splitDirection,splitSize:i.splitSize,splitResizable:i.splitResizable},dataSource:t,className:i.className});if(i.formType===`drawer`){let{layout:e,...n}=i,r=i.layout===`vertical`||i.layout===`horizontal`?i.layout:void 0;return(0,K.jsx)($e,{schema:{...n,layout:r,formType:`drawer`,sections:i.sections?.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:i.open,onOpenChange:i.onOpenChange,drawerSide:i.drawerSide,drawerWidth:i.drawerWidth},dataSource:t,className:i.className})}if(i.formType===`modal`){let{layout:e,...n}=i,r=i.layout===`vertical`||i.layout===`horizontal`?i.layout:void 0;return(0,K.jsx)(nt,{schema:{...n,layout:r,formType:`modal`,sections:i.sections?.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),open:i.open,onOpenChange:i.onOpenChange,modalSize:i.modalSize,modalCloseButton:i.modalCloseButton},dataSource:t,className:i.className})}return(0,K.jsx)(at,{schema:i,dataSource:t})},at=({schema:e,dataSource:t})=>{let{fieldLabel:n,sectionLabel:a}=j(),o=b(),s=r(),c=(0,G.useCallback)(t=>{if(!s?.isLoaded)return t;let n=[];for(let r of t)s.checkField(e.objectName,r.name,`read`)&&(!s.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[s,e.objectName,e.mode]),[l,u]=(0,G.useState)(null),[d,f]=(0,G.useState)([]),[p,m]=(0,G.useState)(null),[h,g]=(0,G.useState)(!0),[_,v]=(0,G.useState)(null),y=e.customFields&&e.customFields.length>0;(0,G.useEffect)(()=>{y&&(m(e.initialData||e.initialValues||{}),g(!1))},[y,e.initialData,e.initialValues]),(0,G.useEffect)(()=>{y?u({name:e.objectName,fields:{}}):e.objectName&&t?(async()=>{try{if(!t)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let n=await t.getObjectSchema(e.objectName);if(!n)throw Error(`No schema found for object "${e.objectName}"`);u(n)}catch(e){v(e),g(!1)}})():y||g(!1)},[e.objectName,t,y]),(0,G.useEffect)(()=>{l&&!y&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),g(!1);return}if(!y){if(!t){v(Error(`DataSource is required for fetching record data (inline data not provided)`)),g(!1);return}g(!0);try{m(await t.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),v(e)}finally{g(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,l,y]);let x=(0,G.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>B(t,e)}:e},[]);(0,G.useEffect)(()=>{if(y&&e.customFields){f(e.customFields.map(x)),g(!1);return}if(!l)return;let r=[],i=e.fields||Object.keys(l.fields||{});(Array.isArray(i)?i:Object.keys(i)).forEach(t=>{let i=typeof t==`string`?t:t.name;if(!i)return;let a=l.fields?.[i];if(!a&&!y)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let s=e.customFields?.find(e=>e.name===i);if(s)r.push(x(s));else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:F(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||l?.managedBy&&l.managedBy!==`platform`,placeholder:a.placeholder,description:a.help||a.description,validation:U(a),visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen??a.conditionalRequired,group:a.group,field:a};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${re(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visible=e=>B(a.visible_on,e)),r.push(o)}}),f(r),!y&&e.recordId&&e.mode!==`create`&&t||g(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,y,e.recordId,t]);let S=(0,G.useCallback)(async(n,r)=>{if(n&&(n.nativeEvent||n._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=n,n={})),y&&!t)return e.onSuccess&&await e.onSuccess(n),n;if(!t)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=n;if(s?.isLoaded&&n&&typeof n==`object`){i={};for(let t of Object.keys(n))s.checkField(e.objectName,t,`write`)&&(i[t]=n[t])}try{let n;if(e.submitHandler)n=await e.submitHandler(i);else if(e.mode===`create`)n=await t.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)n=await t.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(n),n}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,t,y,s]),C=(0,G.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...G.useMemo(()=>{if(!l?.fields)return{};let e={};return Object.keys(l.fields).forEach(t=>{let n=l.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[l]),...p},T=G.useMemo(()=>e.sections?.length?null:it(d,l?.fieldGroups),[e.sections,d,l]),E=e.sections?.length?e.sections:T,[D,O]=(0,G.useState)({});if(_)return(0,K.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,K.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let k=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(E?.length&&(!e.formType||e.formType===`simple`)){let t=[];return E.forEach((n,r)=>{let i=n.fields.map(e=>typeof e==`string`?e:e.field??e.name),o=c(d.filter(e=>i.includes(e.name)));if(o.length===0)return;let s=n.name||n.label||String(r),l=n.name?a(e.objectName,n.name,n.label||n.name):n.label,u=D[s]??n.collapsed??!1;l&&t.push({name:`__section_${s}`,label:l,type:`section-divider`,colSpan:4,collapsible:n.collapsible,collapsed:u,onToggle:n.collapsible?()=>O(e=>({...e,[s]:!u})):void 0}),l&&u?t.push(...o.map(e=>({...e,hidden:!0}))):t.push(...o)}),(0,K.jsx)(`div`,{className:`w-full`,children:(0,K.jsx)(i,{schema:{type:`form`,fields:t,layout:k,defaultValues:w,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:S,onCancel:C}})})}let A=e.sections?.length,M=c(d),N=A?{fields:M,columns:e.columns}:Q(M,l,e.columns,e.mode),P=e.mobile,I=P?.fullscreenLongText?N.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):N.fields,L=P?.stepper,R=P?.stepperMinFields??8,z=Math.max(1,P?.stepperFieldsPerStep??1);if(!e.formType&&!A&&I.length>=2&&(L===!0||L===`auto`&&o&&I.length>=R)){let n=I,r=[];for(let e=0;e<n.length;e+=z){let t=n.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:t})}return(0,K.jsx)(ce,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let ee={type:`form`,fields:I,layout:k,columns:N.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!P?.stickyActions};return(0,K.jsx)(`div`,{className:P?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":P?`true`:void 0,children:(0,K.jsx)(i,{schema:ee})})},ot={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},st=`_company_website_2`,ct=1500;function lt(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function ut(e){return e&&e.map(e=>{let t=ot[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var dt=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,G.useState)(!1),[o,s]=(0,G.useState)(!1),[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)(!(e.consent?.required??!!e.consent)),[f,p]=(0,G.useState)(null),m=(0,G.useRef)(null),h=(0,G.useRef)(Date.now());(0,G.useEffect)(()=>{i||(h.current=Date.now())},[i]);let g=e.honeypot===!1?null:e.honeypot||st,_=e.minFillTime??ct,y=(0,G.useMemo)(()=>ut(e.customFields),[e.customFields]),b=(0,G.useMemo)(()=>{if(!t||y&&y.length>0||!e.fields||e.fields.length===0)return;let n=async(e,t)=>t;return{...t,create:n,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[t,y,e.fields]),x=(0,G.useMemo)(()=>{let t={};if(n)for(let[e,r]of Object.entries(n))t[e]=r;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[n,e.allowedPrefillFields]),S=(0,G.useCallback)(async n=>{if(e.consent?.required&&!u){p(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(p(null),g&&m.current?.value){a(!0);return}if(_>0&&Date.now()-h.current<_){l(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...n};g&&delete r[g],e.captchaToken&&(r._captcha=e.captchaToken),s(!0),l(null);try{t&&await t.create(e.objectName,r),a(!0);let n=e.thankYouPage?.redirectUrl;if(n)if(lt(n,e.allowedRedirectHosts)){let t=e.thankYouPage?.redirectDelay??3e3;setTimeout(()=>{window.location.href=n},t)}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,n),l(e.texts?.redirectBlocked??null)}catch(e){l(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{s(!1)}},[t,e,u,g,_]),C=(0,G.useCallback)(()=>{a(!1),l(null)},[]),w=(0,G.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(i){let t=e.thankYouPage,n=e.texts??{},i=Math.ceil((t?.redirectDelay??3e3)/1e3),a=(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(i));return(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${r||``}`,style:w,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,K.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,K.jsx)(P,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,K.jsx)(I,{variant:`outline`,size:`sm`,onClick:C,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})})}let T=e.texts??{},E=!!e.consent?.required,D=`${e.formId}-consent`;return(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${r||``}`,style:w,children:(0,K.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,K.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,K.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,K.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:T.requiredHint??`* Required field`})]}),(0,K.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[c&&(0,K.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:c}),(0,K.jsx)($,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:y,initialData:x,onSuccess:S,submitText:o?T.submitting??`Submitting...`:T.submit??`Submit`},dataSource:b}),g&&(0,K.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,K.jsx)(`label`,{htmlFor:`${e.formId}-${g}`,children:`Do not fill this field`}),(0,K.jsx)(`input`,{ref:m,id:`${e.formId}-${g}`,type:`text`,name:g,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:D,checked:u,onChange:e=>{d(e.target.checked),e.target.checked&&p(null)},"aria-required":E||void 0,"aria-invalid":f?`true`:void 0,"aria-describedby":f?`${D}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,K.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??T.consentLabelDefault??`I agree to the privacy policy.`,E&&(0,K.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,K.jsxs)(K.Fragment,{children:[` `,(0,K.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:T.consentLink??`Privacy policy`})]})]})]}),f&&(0,K.jsx)(`p`,{id:`${D}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:f})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,K.jsx)(v,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:T.submitting??`Submitting…`})]})]}),(0,K.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,K.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,K.jsx)(z,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:T.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,K.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,K.jsx)(N,{className:`h-3 w-3`,"aria-hidden":`true`}),T.consentLink??`Privacy policy`]}),(0,K.jsx)(`span`,{children:T.poweredBy??`Powered by ObjectStack`})]})]})]})})};function ft(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}var pt=({formId:e,formTitle:t,metrics:n,className:r})=>{let i=(0,G.useMemo)(()=>{if(!n.abandonedSubmissions)return 100;let e=n.totalSubmissions+n.abandonedSubmissions;return e===0?0:Math.round(n.totalSubmissions/e*100)},[n.totalSubmissions,n.abandonedSubmissions]),a=(0,G.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,K.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,K.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,K.jsx)(H,{children:(0,K.jsxs)(E,{className:`pb-2`,children:[(0,K.jsx)(D,{children:`Total Submissions`}),(0,K.jsx)(k,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,K.jsxs)(H,{children:[(0,K.jsxs)(E,{className:`pb-2`,children:[(0,K.jsx)(D,{children:`Fill Rate`}),(0,K.jsxs)(k,{className:`text-2xl`,children:[i,`%`]})]}),(0,K.jsx)(m,{children:(0,K.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,K.jsx)(H,{children:(0,K.jsxs)(E,{className:`pb-2`,children:[(0,K.jsx)(D,{children:`Avg. Completion Time`}),(0,K.jsx)(k,{className:`text-2xl`,children:n.avgCompletionTime?ft(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,K.jsxs)(H,{children:[(0,K.jsx)(E,{children:(0,K.jsx)(k,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,K.jsx)(m,{children:(0,K.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,K.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/a*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),n.fieldDropOff&&n.fieldDropOff.length>0&&(0,K.jsxs)(H,{children:[(0,K.jsxs)(E,{children:[(0,K.jsx)(k,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,K.jsx)(D,{children:`Percentage of users who completed each field`})]}),(0,K.jsx)(m,{children:(0,K.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,K.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},mt=({schema:e})=>{let t=a()?.dataSource,n;try{n=s()}catch{n=void 0}let r=e.parentObject||n?.objectName,i=e.parentId||e.recordId||n?.recordId,[o,c]=(0,G.useState)([]),[l,u]=(0,G.useState)([]),[d,f]=(0,G.useState)(!0),[p,h]=(0,G.useState)(!1),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(null),b=(0,G.useCallback)(async()=>{if(!t||!i){f(!1);return}f(!0);try{let n=(await t.find(e.childObject,{$filter:{[e.relationshipField]:i},$top:500}))?.data??[];c(n.map(e=>({...e}))),u(n.map(e=>({...e}))),_(!1)}catch(e){y(e?.message||`Failed to load line items`)}finally{f(!1)}},[t,i,e.childObject,e.relationshipField]);(0,G.useEffect)(()=>{b()},[b]);let x=(0,G.useCallback)(e=>{c(e),_(!0)},[]),S=(0,G.useCallback)(async()=>{if(!(!t||!i)){h(!0),y(null);try{await ve(t,r||e.childObject,i,{childObject:e.childObject,relationshipField:e.relationshipField,rows:o,original:l,amountField:e.amountField,totalField:r?e.totalField:void 0}),await b()}catch(e){y(e?.message||`Failed to save line items`)}finally{h(!1)}}},[t,i,o,l,e,r,b]),C=(0,G.useMemo)(()=>({columns:e.columns,total_field:e.totalField?e.amountField||`amount`:void 0,min_rows:e.minRows,max_rows:e.maxRows,allow_add:!e.readonly,allow_delete:!e.readonly}),[e]);return(0,K.jsxs)(H,{className:V(`shadow-none`),children:[(0,K.jsxs)(E,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,K.jsx)(k,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,K.jsx)(I,{type:`button`,size:`sm`,onClick:S,disabled:p||d||!g||!i,children:p?`Saving…`:`Save`})]}),(0,K.jsxs)(m,{children:[v&&(0,K.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:v}),d?(0,K.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):i?(0,K.jsx)(A,{value:o,onChange:x,field:C,readonly:e.readonly}):(0,K.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},ht=({schema:e})=>(0,K.jsx)($,{schema:e,dataSource:(0,G.useContext)(o)?.dataSource??void 0});c.register(`object-form`,ht,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]}]}),c.register(`form`,ht,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),c.register(`embeddable-form`,({schema:e})=>(0,K.jsx)(dt,{config:e}),{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),c.register(`form-analytics`,({schema:e})=>(0,K.jsx)(pt,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),c.register(`object-master-detail-form`,({schema:e})=>(0,K.jsx)(Z,{schema:e,dataSource:(0,G.useContext)(o)?.dataSource??void 0}),{namespace:`plugin-form`,label:`Master-Detail Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Parent Object`,required:!0},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`]},{name:`sections`,type:`array`,label:`Parent Sections`},{name:`details`,type:`array`,label:`Detail Collections`,required:!0}]}),c.register(`line_items`,({schema:e})=>(0,K.jsx)(mt,{schema:e}),{namespace:`record`,skipFallback:!0,label:`Line Items`,category:`record`,inputs:[{name:`childObject`,type:`string`,label:`Child Object`,required:!0},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0},{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`totalField`,type:`string`,label:`Parent Total Field`},{name:`amountField`,type:`string`,label:`Amount Column`}]});export{Me as i,nt as n,$e as r,$ as t};
|