@objectstack/console 7.1.0 → 7.2.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/{AiPendingActionsPage-DfPQB-bV.js → AiPendingActionsPage-DYX4ANzZ.js} +1 -1
- package/dist/assets/ApiConsolePage-C70S6MYv.js +1 -0
- package/dist/assets/{AppManagementPage-DuIaI8a2.js → AppManagementPage-BnwBNW_m.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-CQQmK4Pz.js +1 -0
- package/dist/assets/{AuditLogPage-CDXmY4Lg.js → AuditLogPage-C1CgKWC8.js} +1 -1
- package/dist/assets/ComponentNavView-g_X1YUdk.js +1 -0
- package/dist/assets/{ConsoleFloatingChatbot-c1A9X4w7.js → ConsoleFloatingChatbot-DJW7zeKU.js} +1 -1
- package/dist/assets/{DeveloperHubPage-E4ydudW4.js → DeveloperHubPage-CcV4mWRr.js} +1 -1
- package/dist/assets/FlowRunsPage-Rtd6u1e_.js +1 -0
- package/dist/assets/MonacoImpl-DcAVOHcx.js +1 -0
- package/dist/assets/{ProfilePage-4wnWye8l.js → ProfilePage-DPGkAZWG.js} +1 -1
- package/dist/assets/PublicFormsPage-BNIOSFr1.js +1 -0
- package/dist/assets/RecentItemsProvider-Dt0K6V1V.js +1 -0
- package/dist/assets/{SettingsHub-B4d9Pn8t.js → SettingsHub-4RDkAyKq.js} +1 -1
- package/dist/assets/{SettingsView-cRQBVn6H.js → SettingsView-_5h2mExc.js} +1 -1
- package/dist/assets/{SystemHubPage-DIKmhwy1.js → SystemHubPage-DRRxgNWV.js} +1 -1
- package/dist/assets/data-adapter-Bi1Re1fK.js +1 -0
- package/dist/assets/dist-Dal4BOHf.js +11 -0
- package/dist/assets/{framework-ClI3DbWX.js → framework-DVkqUSPj.js} +4 -4
- package/dist/assets/{highlighted-body-OFNGDK62-Dynkkk0t.js → highlighted-body-OFNGDK62-Dp9QBuY-.js} +1 -1
- package/dist/assets/index-DWtLSzKK.js +33 -0
- package/dist/assets/index-JLLCOoA3.css +2 -0
- package/dist/assets/infrastructure-IQKE4Vv8.js +3 -0
- package/dist/assets/mermaid-GHXKKRXX-PDO-QkSF.js +1 -0
- package/dist/assets/plugin-calendar-D1wyyvEx.js +1 -0
- package/dist/assets/{plugin-charts-Mt2y8Sdm.js → plugin-charts-DrCI3cJo.js} +2 -2
- package/dist/assets/{plugin-chatbot-DXGXTdLU.js → plugin-chatbot-CiVctLlf.js} +8 -8
- package/dist/assets/plugin-dashboard-BRn9AjyQ.js +3 -0
- package/dist/assets/{plugin-form-BBc-xwrZ.js → plugin-form-KOOMD5ZY.js} +1 -1
- package/dist/assets/plugin-gantt-D3OFukY1.js +1 -0
- package/dist/assets/plugin-grid-DGQxmfxn.js +6 -0
- package/dist/assets/plugin-kanban-C-qMP4VL.js +1 -0
- package/dist/assets/plugin-map-DRf0LmJy.js +1 -0
- package/dist/assets/plugin-markdown-BVFW0U6V.js +7 -0
- package/dist/assets/plugin-report-CJSBthhg.js +59 -0
- package/dist/assets/plugin-timeline-RAn1F_nX.js +1 -0
- package/dist/assets/plugin-view-DspcF1Mc.js +1 -0
- package/dist/assets/plugins-views-DUx-xpiH.js +4 -0
- package/dist/assets/src-DL8N52oz.js +2 -0
- package/dist/assets/{types-BsFD2pPK.js → types-CbmNTewl.js} +1 -1
- package/dist/assets/ui-components-CIdYg6m3.js +41 -0
- package/dist/assets/ui-layout-DGPxy1gI.js +1 -0
- package/dist/assets/{vendor-charts-vh1WJI0j.js → vendor-charts-Ba_-W-di.js} +3 -3
- package/dist/assets/{vendor-dndkit-0jp7h5ty.js → vendor-dndkit-CucFgdMa.js} +1 -1
- package/dist/assets/{vendor-i18n-CnFu8bdi.js → vendor-i18n-DPyFo2xM.js} +1 -1
- package/dist/assets/{vendor-icons-core-D5MicM14.js → vendor-icons-core-Cx2WYOuR.js} +1 -1
- package/dist/assets/{vendor-markdown-CvMSBmgq.js → vendor-markdown-B0mCB2Nu.js} +2 -2
- package/dist/assets/vendor-objectstack-B3zP6Fz_.js +65 -0
- package/dist/assets/{vendor-radix-BNWIlSsV.js → vendor-radix-thTS_QfF.js} +1 -1
- package/dist/assets/vendor-react-CyVA1SE-.js +13 -0
- package/dist/assets/{vendor-sentry-D5yZpZ5X.js → vendor-sentry-DjMgMAaz.js} +1 -1
- package/dist/assets/{vendor-ui-utils-D3GsyZyi.js → vendor-ui-utils-BbOuugky.js} +1 -1
- package/dist/favicon.svg +11 -0
- package/dist/index.html +7 -7
- package/dist/logo.svg +15 -0
- package/dist/manifest.json +2 -2
- package/package.json +1 -1
- package/dist/assets/ApiConsolePage-CVt86JW9.js +0 -1
- package/dist/assets/ApprovalsInboxPage-BRv2RqN4.js +0 -1
- package/dist/assets/ComponentNavView-B2VAx_8W.js +0 -1
- package/dist/assets/FlowRunsPage-CF-nkx9E.js +0 -1
- package/dist/assets/MonacoImpl-CKoKq1tG.js +0 -11
- package/dist/assets/PublicFormsPage-B1cdfwoQ.js +0 -1
- package/dist/assets/data-adapter-Be-s1kWX.js +0 -1
- package/dist/assets/index-D7iz-IIn.js +0 -24
- package/dist/assets/index-Db8Nmh4R.css +0 -2
- package/dist/assets/infrastructure-ezj3FgNE.js +0 -3
- package/dist/assets/mermaid-GHXKKRXX-DJsGdxYj.js +0 -1
- package/dist/assets/plugin-calendar-wl24Whh9.js +0 -1
- package/dist/assets/plugin-dashboard-DqF5vvlQ.js +0 -3
- package/dist/assets/plugin-gantt-scBgVq2Q.js +0 -1
- package/dist/assets/plugin-grid-u5JmW5Ui.js +0 -6
- package/dist/assets/plugin-kanban-0qj1Kr3T.js +0 -1
- package/dist/assets/plugin-map-CjA33cHV.js +0 -1
- package/dist/assets/plugin-markdown-BPsaoDf-.js +0 -7
- package/dist/assets/plugin-report-C35V4A8F.js +0 -59
- package/dist/assets/plugin-timeline-Bmy8v-AN.js +0 -1
- package/dist/assets/plugin-view-tV_8MnpT.js +0 -1
- package/dist/assets/plugins-views-DM6-O61C.js +0 -4
- package/dist/assets/src-BJJhwsID.js +0 -2
- package/dist/assets/ui-components-DYQ4Pai7.js +0 -41
- package/dist/assets/ui-layout-Dmw4Ab7P.js +0 -1
- package/dist/assets/vendor-objectstack-CwZ3saTl.js +0 -65
- package/dist/assets/vendor-react-CIpZOxG3.js +0 -13
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{a as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _,u as v}from"./vendor-react-CIpZOxG3.js";import{a as y,c as b,d as x,i as S,l as C,n as w,o as T,r as E,s as D,u as O}from"./infrastructure-ezj3FgNE.js";import{A as k,B as A,D as j,L as M,M as ee,N as te,O as ne,P as N,R as P,S as F,T as re,X as I,Y as L,_ as ie,at as ae,b as oe,c as se,d as ce,n as le,nt as ue,r as R,rt as de,tt as fe,u as pe,ut as z,v as me,x as he,y as B}from"./framework-ClI3DbWX.js";import{n as V,r as H,t as ge}from"./data-adapter-Be-s1kWX.js";import{$ as _e,$a as ve,$i as U,$n as ye,$o as be,$r as xe,$t as Se,Aa as Ce,Ai as we,An as Te,Ar as Ee,At as W,Bn as De,Bt as Oe,Ca as ke,Co as Ae,Cr as je,Da as Me,Di as Ne,Do as Pe,Dt as Fe,Ea as Ie,Ei as Le,Eo as Re,Er as ze,Et as Be,F as Ve,Fa as He,Fi as Ue,Fn as We,Fo as Ge,Ft as Ke,Ga as qe,Gi as Je,Gn as Ye,Gr as Xe,Gt as Ze,Ha as Qe,Hi as $e,Ho as et,Hr as tt,Ht as nt,I as rt,Ia as it,Ii as at,In as ot,Ir as st,It as ct,Ji as lt,Jn as ut,Jo as dt,Jr as ft,Ka as pt,Ki as mt,Kn as ht,Ko as gt,Kr as _t,Kt as vt,La as yt,Li as bt,Ln as xt,Lo as St,Lr as Ct,M as wt,Ma as Tt,Mn as Et,Mo as Dt,Mr as Ot,Mt as kt,N as At,Na as jt,Ni as Mt,Nn as Nt,No as Pt,Nr as Ft,Nt as It,Oa as Lt,On as Rt,Oo as zt,Or as Bt,Ot as Vt,P as Ht,Pa as Ut,Pi as Wt,Pn as Gt,Po as Kt,Pr as qt,Pt as Jt,Q as Yt,Qa as Xt,Qi as Zt,Qn as G,Qo as Qt,Qr as $t,Qt as en,Ra as tn,Ri as nn,Rn as rn,Rr as an,Rt as on,So as sn,Sr as cn,St as ln,T as un,Ta as dn,Ti as fn,To as pn,Tr as mn,Tt as hn,Ui as gn,Uo as _n,Ur as vn,Ut as yn,V as bn,Va as xn,Vi as Sn,Vo as Cn,Vr as wn,Vt as Tn,Wa as En,Wi as Dn,Wo as On,Wr as kn,X as An,Xa as jn,Xi as Mn,Xn as Nn,Xo as Pn,Xr as Fn,Ya as In,Yi as Ln,Yn as Rn,Yo as zn,Z as Bn,Za as Vn,Zi as Hn,Zo as Un,Zr as Wn,Zt as Gn,_i as Kn,_r as qn,_t as Jn,ai as Yn,an as Xn,ao as Zn,ar as Qn,ba as $n,bi as er,bo as tr,br as nr,bt as rr,ca as ir,ci as ar,cn as or,co as sr,cr,da as lr,di as ur,do as dr,dr as fr,dt as pr,ea as mr,en as K,er as hr,es as gr,et as _r,fa as vr,fi as yr,fo as br,fr as xr,ft as Sr,g as Cr,ga as wr,go as Tr,gt as Er,h as Dr,ha as Or,ho as kr,ht as Ar,ia as jr,ii as Mr,in as Nr,io as Pr,ja as Fr,ji as Ir,jn as Lr,jr as Rr,kn as zr,kr as Br,kt as Vr,la as Hr,li as Ur,ln as Wr,lo as Gr,lr as Kr,lt as qr,ma as Jr,mn as Yr,mo as Xr,mr as q,mt as Zr,na as Qr,ni as $r,no as ei,ns as ti,nt as ni,oa as ri,oi as ii,on as ai,oo as oi,or as si,pa as ci,pi as li,pt as ui,qa as di,qi as fi,qn as pi,qr as mi,qt as hi,ra as gi,ri as _i,ro as vi,sa as yi,si as bi,sn as xi,so as Si,sr as Ci,ta as wi,ti as Ti,to as Ei,tr as Di,tt as Oi,ua as ki,ui as Ai,un as ji,uo as Mi,ur as Ni,v as Pi,va as Fi,vi as Ii,vo as Li,vr as Ri,w as zi,wa as Bi,wi as Vi,wo as Hi,wr as Ui,wt as Wi,x as Gi,xa as Ki,xi as qi,xo as Ji,xr as Yi,xt as Xi,yi as Zi,yo as Qi,yr as $i,yt as ea,z as ta,za as na,zi as ra,zn as ia,zo as aa,zt as oa}from"./ui-components-DYQ4Pai7.js";import{a as sa,i as ca,o as J,r as la}from"./vendor-ui-utils-D3GsyZyi.js";import{n as ua,r as da,t as fa}from"./ui-layout-Dmw4Ab7P.js";import{a as pa,n as ma,o as ha,s as ga,t as _a}from"./plugins-views-DM6-O61C.js";import{i as va,r as ya}from"./plugin-grid-u5JmW5Ui.js";import{n as ba,r as xa,t as Sa}from"./plugin-form-BBc-xwrZ.js";import{a as Ca,c as wa,d as Ta,f as Ea,i as Da,l as Oa,m as ka,n as Aa,o as ja,p as Ma,r as Na,s as Pa,t as Fa,u as Ia}from"./plugin-view-tV_8MnpT.js";import{i as La,n as Ra,r as za}from"./plugin-dashboard-DqF5vvlQ.js";import{i as Ba,l as Va,t as Ha,u as Ua}from"./plugin-chatbot-DXGXTdLU.js";var Y=e(s(),1),Wa=e(d(),1),X=h();function Ga({children:e,adapter:t}){let[n,r]=(0,Y.useState)(t??null);return(0,Y.useEffect)(()=>{if(t){r(t);return}let e=!1;async function n(){try{let t=new ge({baseUrl:``,fetch:x(),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});await t.connect(),e||r(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return n(),()=>{e=!0}},[t]),(0,X.jsx)(B.Provider,{value:n,children:e})}var Ka=300*1e3,qa=[`app`,`view`],Ja={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},Ya=`objectui:metadata:`;function Xa(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var Za=Xa();function Qa(...e){Za&&console.debug(`[MetadataProvider]`,...e)}function $a(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function eo(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function to(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function no(e,t){if(!e.length||!t.length)return e;let n={};for(let e of t){let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t)continue;let r=n[t]||={listViews:{},formViews:{}};if(e.list){r.primary=e.list;let t=e.list.name||`list`;r.listViews[t]=e.list}if(e.form&&(r.form=e.form),e.listViews&&typeof e.listViews==`object`)for(let[t,n]of Object.entries(e.listViews))r.listViews[t]=n;if(e.formViews&&typeof e.formViews==`object`)for(let[t,n]of Object.entries(e.formViews))r.formViews[t]=n}return e.map(e=>{let t=n[e.name];if(!t)return e;let r=e.listViews||e.list_views||{},i=e.formViews||e.form_views||{},a={...e,listViews:{...t.listViews,...r}};return(Object.keys(t.formViews).length||Object.keys(i).length)&&(a.formViews={...t.formViews,...i}),t.primary&&!e.list&&(a.list=t.primary),t.form&&!e.form&&(a.form=t.form),a})}function ro(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function io(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(Ya+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function ao(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(Ya+e,JSON.stringify(t))}catch{}}function oo({children:e,adapter:t,ttlMs:n=Ka}){let r=(0,Y.useRef)(new Map),i=(0,Y.useRef)(new Map),a=(0,Y.useRef)(t);a.current=t;let[o,s]=(0,Y.useState)(0),c=(0,Y.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>s(e=>e+1)):Promise.resolve().then(()=>s(e=>e+1))},[]),l=(0,Y.useCallback)(e=>{let t=r.current.get(e);return t||(t=ro(),r.current.set(e,t)),t},[]),u=(0,Y.useCallback)(e=>{let t=l(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return Qa(`cache hit (fresh) type=${e} items=${t.items.length}`),Promise.resolve(t.items);let r=Date.now();t.status=`loading`,t.error=null;let i=a.current.getClient().meta.getItems(e).then(n=>{let i=$a(n);t.items=i,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of i)to(e)&&t.byName.set(e.name,e);return e===`app`&&ao(e,i),Qa(`fetched type=${e} items=${i.length} in ${Date.now()-r}ms`),c(),i}).catch(n=>{let r=n instanceof Error?n:Error(String(n));return t.status=`error`,t.error=r,t.promise=null,Qa(`fetch failed type=${e}`,r),c(),[]});return t.promise=i,i},[c,l,n]),d=(0,Y.useCallback)((e,t)=>{let n=l(e);if(n.byName.has(t))return Qa(`item cache hit type=${e} name=${t}`),Promise.resolve(n.byName.get(t)??null);let r=i.current.get(e);r||(r=new Map,i.current.set(e,r));let o=r.get(t);if(o)return o;let s=Date.now(),c=a.current.getClient().meta.getItem(e,t).then(i=>{let a=eo(i);return a&&n.byName.set(t,a),Qa(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Qa(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,c),c},[l]),f=(0,Y.useCallback)(async e=>{if(e){let t=l(e);t.fetchedAt=0,t.byName.clear(),await u(e);return}let t=Array.from(r.current.keys()).filter(e=>r.current.get(e).status!==`idle`);await Promise.all(t.map(e=>{let t=r.current.get(e);return t.fetchedAt=0,t.byName.clear(),u(e)}))},[u,l]),p=(0,Y.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),Qa(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Qa(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,Y.useState)(!0),[g,_]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1,t=io(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)to(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of qa)try{await u(t),e||_(null)}catch(t){e||_(t instanceof Error?t:Error(String(t)))}e||h(!1)})(),()=>{e=!0}},[t,u,l,c]);let v=(0,Y.useMemo)(()=>{let e=e=>{let t=l(e);return t.status===`idle`&&u(e),t.items};return{apps:l(`app`).items,get objects(){let t=e(Ja.objects),n=e(`view`);return n.length?no(t,n):t},get dashboards(){return e(Ja.dashboards)},get reports(){return e(Ja.reports)},get pages(){return e(Ja.pages)},loading:m,error:g??l(`app`).error,refresh:f,invalidate:p,ensureType:u,getItem:d,getItemsByType:t=>e(t)}},[o,m,g,u,d,l,f,p]);return(0,X.jsx)(oe.Provider,{value:v,children:e})}var so=(0,Y.createContext)(null);function co({children:e,user:t={},app:n={},data:r={},features:i={}}){let a=(0,Y.useMemo)(()=>({user:t,app:n,data:r,features:i,evaluator:new de({user:t,app:n,data:r,features:i})}),[t,n,r,i]),o=(0,Y.useMemo)(()=>({user:t,app:n,data:r,features:i}),[t,n,r,i]);return(0,X.jsx)(so.Provider,{value:a,children:(0,X.jsx)(N,{scope:o,children:e})})}function lo(){let e=(0,Y.useContext)(so);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new de(e)}}return e}function uo(e,t){if(e==null||e===!0||e===`true`)return!0;if(e===!1||e===`false`)return!1;if(typeof e==`string`&&e.includes("${"))try{return t.evaluateCondition(e)}catch{return!0}return!0}function fo({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:o,onToast:s}){let c=v(),{appName:l}=a(),{t:u}=R(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=te({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:o,onToast:s});return(0,Y.useEffect)(()=>{h.registerHandler(`create`,async()=>(r?.(null),{success:!0})),h.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(J.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0}):(J.error(u(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1,error:`${o} failed`})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:u(`objectActions.noRecordId`)};try{return await n.delete(e,o),i?.(),J.success(u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return J.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),h.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),h.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[h,e,n,r,i,c,d,u,t]),{execute:f,create:(0,Y.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,Y.useCallback)(async e=>f({type:`delete`,confirmText:u(`objectActions.deleteConfirm`),params:{recordId:e}}),[f,u]),navigateToView:(0,Y.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,Y.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:p,error:m}}var po=(0,Y.createContext)({favorites:null,recent:null}),mo=(0,Y.createContext)(null);function ho({children:e}){let[t,n]=(0,Y.useState)({favorites:null,recent:null}),r=(0,Y.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,X.jsx)(mo.Provider,{value:r.current,children:(0,X.jsx)(po.Provider,{value:t,children:e})})}function go(e){return(0,Y.useContext)(po)[e]}function _o(){let e=(0,Y.useContext)(mo);return(0,Y.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function vo(e,t){return t?`${e}:u:${t}`:e}function yo(e,t){let n=(0,Y.useRef)(t);n.current=t,(0,Y.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function bo(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var xo=`objectui-recent-items`,So=8;function Co(e){try{let t=localStorage.getItem(vo(xo,e));return t?JSON.parse(t):[]}catch{return[]}}function wo(e,t){try{localStorage.setItem(vo(xo,t),JSON.stringify(e))}catch{}}var To=(0,Y.createContext)(null);function Eo({children:e}){let{user:t}=C(),n=t?.id??null,r=go(`recent`),[i,a]=(0,Y.useState)(()=>Co(n));(0,Y.useEffect)(()=>{a(Co(n))},[n]),yo(vo(xo,n),e=>{a(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,So):[])});let o=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{if(!r)return;let e=++o.current,t=!1;return(async()=>{try{let i=await r.load();if(t||e!==o.current)return;let s=(Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`).slice(0,So);a(s),wo(s,n)}catch{}})(),()=>{t=!0}},[r,n]);let s=(0,Y.useMemo)(()=>bo(async e=>{r&&await r.save(e)},500),[r]);(0,Y.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,Y.useCallback)(e=>{wo(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,Y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,So);return c(r),r})},[c]),u=(0,Y.useCallback)(()=>{a([]),c([])},[c]),d=(0,Y.useMemo)(()=>({recentItems:i,addRecentItem:l,clearRecentItems:u}),[i,l,u]);return(0,X.jsx)(To.Provider,{value:d,children:e})}function Do(){return(0,Y.useContext)(To)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}var Oo=(0,Y.createContext)(void 0);function ko({children:e}){let[t,n]=(0,Y.useState)(`home`),[r,i]=(0,Y.useState)(),[a,o]=(0,Y.useState)(),s=(0,Y.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,X.jsx)(Oo.Provider,{value:s,children:e})}function Ao(){return(0,Y.useContext)(Oo)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function jo(e){let{setRecordTitle:t}=Ao();(0,Y.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Mo=`objectui-favorites`,No=`objectui-nav-pins`,Po=20,Fo=20;function Io(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Fo&&(r=!0)):(t++,t>Po&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Fo&&(i.push(t),o++):a<Po&&(i.push(t),a++);return i}function Lo(e){try{let t=localStorage.getItem(vo(Mo,e));return t?JSON.parse(t):[]}catch{return[]}}function Ro(e,t){try{localStorage.setItem(vo(Mo,t),JSON.stringify(e))}catch{}}function zo(e){let t;try{t=localStorage.getItem(No)}catch{return{migrated:e,didMigrate:!1}}if(!t)return{migrated:e,didMigrate:!1};let n=[];try{let e=JSON.parse(t);Array.isArray(e)&&(n=e.filter(e=>typeof e==`string`))}catch{}try{localStorage.removeItem(No)}catch{}if(n.length===0)return{migrated:e,didMigrate:!1};let r=new Set(e.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),i=new Date().toISOString(),a=[];for(let e of n)r.has(e)||a.push({id:`nav:${e}`,label:e,href:``,type:`nav`,navId:e,pinned:!0,favoritedAt:i});return a.length===0?{migrated:e,didMigrate:!0}:{migrated:[...e,...a],didMigrate:!0}}var Bo=(0,Y.createContext)(null);function Vo({children:e}){let{user:t}=C(),n=t?.id??null,r=go(`favorites`),[i,a]=(0,Y.useState)(()=>Lo(n));(0,Y.useEffect)(()=>{a(Lo(n))},[n]),yo(vo(Mo,n),e=>{a(Array.isArray(e)?Io(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{if(!r)return;let e=++o.current,t=!1;return(async()=>{try{let i=await r.load();if(t||e!==o.current)return;let c=Io((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Lo(n),u=new Set(c.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),d=l.filter(e=>e.type===`nav`&&e.navId&&!u.has(e.navId)),f=c,p=!1;d.length>0&&(f=Io([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=zo(f);h&&(f=Io(m),p=!0),a(f),Ro(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,Y.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=zo(e);if(!r)return e;let i=Io(t);return Ro(i,n),i})},[r,n]);let s=(0,Y.useMemo)(()=>bo(async e=>{r&&await r.save(e)},500),[r]);(0,Y.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,Y.useCallback)(e=>{Ro(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,Y.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=Io([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),u=(0,Y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),d=(0,Y.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):Io([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),f=(0,Y.useCallback)(()=>{a([]),c([])},[c]),p=(0,Y.useCallback)((e,t)=>{!e||!t||a(n=>{let r=!1,i=n.map(n=>n.id===e&&n.label!==t?(r=!0,{...n,label:t}):n);return r?(c(i),i):n})},[c]),m=(0,Y.useCallback)((e,t)=>{a(n=>{let r=!1,i=n.map(n=>n.id!==e||!!n.pinned===t?n:(r=!0,{...n,pinned:t}));return r?(c(i),i):n})},[c]),h=(0,Y.useMemo)(()=>{let e=new Set;for(let t of i)t.pinned&&t.type===`nav`&&t.navId&&e.add(t.navId);return{favorites:i,addFavorite:l,removeFavorite:u,toggleFavorite:d,isFavorite:e=>i.some(t=>t.id===e),clearFavorites:f,refreshLabel:p,setPinned:m,isPinned:e=>i.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[i,l,u,d,f,p,m]);return(0,X.jsx)(Bo.Provider,{value:h,children:e})}function Ho(){return(0,Y.useContext)(Bo)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Uo=(0,Y.createContext)({theme:`system`,setTheme:()=>null});function Wo({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Y.useState)(()=>localStorage.getItem(n)||t);(0,Y.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t);return}e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e)}};return(0,X.jsx)(Uo.Provider,{...r,value:o,children:e})}var Go=()=>{let e=(0,Y.useContext)(Uo);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Ko(){return(0,X.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function qo({children:e}){return(0,X.jsx)(Wo,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,X.jsx)(ko,{children:(0,X.jsx)(ho,{children:(0,X.jsx)(Vo,{children:(0,X.jsx)(Eo,{children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(Ko,{}),children:e})})})})})})}function Jo({children:e}){return(0,X.jsx)(Ga,{children:(0,X.jsx)(Yo,{children:e})})}function Yo({children:e}){let t=he();return t?(0,X.jsx)(A,{dataSource:t,children:(0,X.jsxs)(oo,{adapter:t,children:[(0,X.jsx)(Xo,{}),e]})}):(0,X.jsx)(Ko,{})}function Xo(){let{user:e}=C(),t=he(),n=_o();return(0,Y.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=H({dataSource:t,userId:e.id,key:`ui.favorites`}),i=H({dataSource:t,userId:e.id,key:`ui.recent`});return n(`favorites`,r),n(`recent`,i),()=>{n(`favorites`,null),n(`recent`,null)}},[e?.id,t,n]),null}function Zo({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=C();return r?(0,X.jsx)(Ko,{}):((n??[]).length>0||t)&&!t?(0,X.jsx)(p,{to:`/organizations`,replace:!0}):(0,X.jsx)(X.Fragment,{children:e})}function Qo(){let e=u(),t=e.pathname.replace(/^\/system/,``);return(0,X.jsx)(p,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var $o=(0,Y.lazy)(()=>m(()=>import(`./ConsoleFloatingChatbot-c1A9X4w7.js`),__vite__mapDeps([0]),import.meta.url)),es=()=>{m(()=>import(`./ConsoleFloatingChatbot-c1A9X4w7.js`),__vite__mapDeps([0]),import.meta.url)};function ts(e){let[t,n]=(0,Y.useState)(!1);return t?(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)($o,{...e,defaultOpen:!0})}):(0,X.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:es,onFocus:es,className:`fixed bottom-6 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2`,children:(0,X.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,X.jsx)(`path`,{d:`M12 3v3`}),(0,X.jsx)(`path`,{d:`M12 18v3`}),(0,X.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,X.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,X.jsx)(`path`,{d:`M3 12h3`}),(0,X.jsx)(`path`,{d:`M18 12h3`}),(0,X.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,X.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function ns(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 rs=new Set(Bn),is=new Map;function as(e){if(!e)return Xt;let t=is.get(e);if(t)return t;let n=ns(e);if(!rs.has(n))return is.set(e,Xt),Xt;let r=e=>Y.createElement(An,{name:n,fallback:Xt,...e});return r.displayName=`LucideIcon(${e})`,is.set(e,r),r}var os=20;function ss(e,t=``){let{href:n,external:r}=ua(e,t);return r?n:!n||n===`#`?``:n}function cs(e){return`nav:${e}`}function ls(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Ho(),a=(0,Y.useCallback)((e,i,a,o)=>{let s=cs(e);i?(a&&t({id:s,label:a.label,href:ss(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,Y.useCallback)(e=>i.has(e),[i]),s=(0,Y.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<os;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,Y.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,Y.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}function us(e){let t=`objectui-nav-order-${e}`,[n,r]=Y.useState(()=>{try{let e=localStorage.getItem(t);if(!e)return{};let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))return{};let r={};for(let[e,t]of Object.entries(n))Array.isArray(t)&&t.every(e=>typeof e==`string`)&&(r[e]=t);return r}catch{return{}}}),i=Y.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Y.useCallback(e=>{let t=n.__root__;if(!t)return e;let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}return r.forEach(e=>i.push(e)),i},[n]),handleReorder:Y.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function ds({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=hn(),i=u(),{t:a}=R(),{objectLabel:o,dashboardLabel:s,navGroupLabel:c,viewLabel:l}=ti(),{context:d,currentAppName:f}=Ao(),{user:p}=C();Y.useEffect(()=>{let e=0,n=t=>{e=t.touches[0].clientX},r=n=>{let r=n.changedTouches[0].clientX-e;e<30&&r>50&&t&&document.querySelector(`[data-sidebar="trigger"]`)?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0}))};return document.addEventListener(`touchstart`,n,{passive:!0}),document.addEventListener(`touchend`,r,{passive:!0}),()=>{document.removeEventListener(`touchstart`,n),document.removeEventListener(`touchend`,r)}},[t]);let{recentItems:m}=Do(),{favorites:h,removeFavorite:g}=Ho(),{apps:_,objects:v}=F(),y=_||[],b=y.filter(e=>e.active!==!1&&e.hidden!==!0),x=y.find(t=>t.name===(e||f)&&t.active!==!1)||b[0],{applyOrder:S,handleReorder:T}=us(x?.name||`home`),{togglePin:E,applyPins:D}=ls(),O=x?.areas||[],[k,A]=Y.useState(()=>O.length>0?O[0].id:null);Y.useEffect(()=>{O.length>0?A(e=>O.some(t=>t.id===e)?e:O[0].id):A(null)},[x?.name,O.length]);let j=O.find(e=>e.id===k)?.navigation||x?.navigation||[],M=Y.useMemo(()=>[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[a]),ee=d===`home`?M:j,te=Y.useMemo(()=>D(S(ee)),[ee,S,D]),[ne,N]=Y.useState(!1),{evaluator:P}=lo(),re=Y.useCallback(e=>uo(e,P),[P]),{can:I}=w(),L=Y.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return I(n,r)}),[I]),ie=Y.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),ae=Y.useCallback((e,t)=>e===`object`?ie.size===0?!0:ie.has(t):!0,[ie]),oe=d===`app`&&x?`/apps/${x.name}`:``;return(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(pr,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,X.jsx)(Jn,{className:`border-b p-1.5`,children:(0,X.jsx)(ea,{children:(0,X.jsx)(ln,{children:(0,X.jsx)(Xi,{asChild:!0,className:`h-9 text-sm font-medium`,children:(0,X.jsxs)(r,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,X.jsx)(dn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,X.jsx)(Sr,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&x?(0,X.jsxs)(X.Fragment,{children:[O.length>1&&(0,X.jsxs)(Zr,{children:[(0,X.jsxs)(Er,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Jr,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,X.jsx)(Ar,{children:(0,X.jsx)(ea,{children:O.map(e=>{let t=as(e.icon);return(0,X.jsx)(ln,{children:(0,X.jsxs)(Xi,{isActive:e.id===k,tooltip:e.label,onClick:()=>A(e.id),children:[(0,X.jsx)(t,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,X.jsx)(fa,{items:te,basePath:oe,evaluateVisibility:re,checkPermission:L,checkCapability:ae,enablePinning:!t,onPinToggle:E,enableReorder:!t,onReorder:T,resolveObjectLabel:(e,t)=>o({name:e,label:t}),resolveDashboardLabel:(e,t)=>s({name:e,label:t}),resolveGroupLabel:x?(e,t)=>c(x.name,e,t):void 0,resolveItemLabel:x?(e,t)=>c(x.name,e,t):void 0,resolveViewLabel:(e,t,n)=>l(e,t,n),t:a,templateContext:{currentUserId:p?.id??null}}),m.length>0&&(0,X.jsxs)(Zr,{children:[(0,X.jsxs)(Er,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>N(e=>!e),children:[(0,X.jsx)(tr,{className:`h-3 w-3 transition-transform duration-150 ${ne?`rotate-90`:``}`}),(0,X.jsx)(oi,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),ne&&(0,X.jsx)(Ar,{children:(0,X.jsx)(ea,{children:m.slice(0,5).map(e=>(0,X.jsx)(ln,{children:(0,X.jsx)(Xi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),h.some(e=>e.type!==`nav`)&&(0,X.jsxs)(Zr,{children:[(0,X.jsxs)(Er,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(_t,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,X.jsx)(Ar,{children:(0,X.jsx)(ea,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,X.jsxs)(ln,{children:[(0,X.jsx)(Xi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,X.jsx)(rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,X.jsx)(mi,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Zr,{children:(0,X.jsx)(Ar,{children:(0,X.jsx)(ea,{children:M.map(e=>{let t=as(e.icon),n=i.pathname===e.url;return(0,X.jsx)(ln,{children:(0,X.jsx)(Xi,{asChild:!0,tooltip:e.label,isActive:n,children:(0,X.jsxs)(r,{to:e.url||`/home`,children:[(0,X.jsx)(t,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,X.jsxs)(Zr,{children:[(0,X.jsxs)(Er,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(_t,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,X.jsx)(Ar,{children:(0,X.jsx)(ea,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,X.jsxs)(ln,{children:[(0,X.jsx)(Xi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,X.jsx)(rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,X.jsx)(mi,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,X.jsx)(ui,{className:`border-t p-1`,children:(0,X.jsx)(Wi,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function fs(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,Y.useState)(`disconnected`),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),g=(0,Y.useRef)(0),_=(0,Y.useRef)(null),v=(0,Y.useRef)(new Map),y=(0,Y.useRef)([]),b=(0,Y.useRef)(!0),x=(0,Y.useRef)(!1),S=(0,Y.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,Y.useCallback)(e=>{for(;y.current.length>0;){let t=y.current.shift(),r={type:t.type,channel:n,data:t.data,timestamp:new Date().toISOString()};e.send(JSON.stringify(r))}},[n]),w=(0,Y.useCallback)(()=>{if(typeof WebSocket>`u`){m(Error(`WebSocket is not available in this environment`)),c(`error`);return}if(!t){m(Error(`WebSocket URL is required`)),c(`error`);return}try{let e=new URL(t);if(e.protocol!==`ws:`&&e.protocol!==`wss:`){m(Error(`WebSocket URL must use ws: or wss: protocol`)),c(`error`);return}}catch{m(Error(`Invalid WebSocket URL`)),c(`error`);return}h.current&&=(x.current=!0,h.current.close(),null),x.current=!1,c(`connecting`),m(null);let e=o?`${t}?token=${encodeURIComponent(o)}&channel=${encodeURIComponent(n)}`:`${t}?channel=${encodeURIComponent(n)}`,s;try{s=new WebSocket(e)}catch(e){if(!b.current)return;m(e instanceof Error?e:Error(`Failed to create WebSocket connection`)),c(`error`);return}h.current=s,s.onopen=()=>{b.current&&(c(`connected`),m(null),g.current=0,C(s))},s.onmessage=e=>{if(b.current)try{let t=JSON.parse(String(e.data));if(t.channel!==n)return;u(t),f(e=>[...e,t]);let r=v.current.get(t.type);r&&r.forEach(e=>e(t.data))}catch{}},s.onerror=()=>{b.current&&(m(Error(`WebSocket connection error`)),c(`error`))},s.onclose=()=>{if(b.current){if(h.current=null,x.current){c(`disconnected`);return}if(r&&g.current<a){c(`reconnecting`);let e=Math.min(i*2**g.current,3e4);g.current+=1,_.current=setTimeout(()=>{b.current&&w()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,C]),T=(0,Y.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,Y.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,Y.useCallback)((e,t)=>{let r=h.current;if(r&&r.readyState===WebSocket.OPEN){let i={type:e,channel:n,data:t,timestamp:new Date().toISOString()};r.send(JSON.stringify(i))}else y.current.push({type:e,data:t})},[n]),O=(0,Y.useCallback)((e,t)=>(v.current.has(e)||v.current.set(e,new Set),v.current.get(e).add(t),()=>{let n=v.current.get(e);n&&(n.delete(t),n.size===0&&v.current.delete(e))}),[]);return(0,Y.useEffect)(()=>(b.current=!0,t&&w(),()=>{b.current=!1,S(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:D,subscribe:O,disconnect:T,reconnect:E,error:p}}var ps=0;function ms(){return ps+=1,`conflict-${Date.now()}-${ps}`}var hs=0;function gs(){return hs+=1,`ver-${Date.now()}-${hs}`}function _s(e,t,n){let[r,i]=(0,Y.useState)([]),[a,o]=(0,Y.useState)([]);return{versions:r,currentVersion:(0,Y.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,Y.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:gs(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,Y.useCallback)((n,r,a)=>{o(o=>{let s=o.find(e=>e.id===n);if(!s)return o;let c;switch(r){case`local`:c=s.localValue;break;case`remote`:c=s.remoteValue;break;case`merge`:c=a??s.localValue;break}return i(n=>{let i=n.length===0?1:n[n.length-1].version+1,a={id:gs(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:{[s.field]:{before:s.baseValue,after:c}},message:`Resolved conflict on "${s.field}" using ${r} strategy`};return[...n,a]}),o.filter(e=>e.id!==n)})},[e,t]),resolveAllConflicts:(0,Y.useCallback)(n=>{o(r=>{if(r.length===0)return r;let a={};for(let e of r)a[e.field]={before:e.baseValue,after:n===`local`?e.localValue:e.remoteValue};return i(r=>{let i=r.length===0?1:r[r.length-1].version+1,o={id:gs(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:a,message:`Resolved all conflicts using ${n} strategy`};return[...r,o]}),[]})},[e,t]),revertToVersion:(0,Y.useCallback)(n=>{let a=r.findIndex(e=>e.id===n);if(a===-1)return null;let o={};for(let e=0;e<=a;e++){let t=r[e];for(let[e,n]of Object.entries(t.changes))o[e]=n.after}let s={},c={};for(let e of r)for(let[t,n]of Object.entries(e.changes))c[t]=n.after;for(let[e,t]of Object.entries(o))c[e]!==t&&(s[e]={before:c[e],after:t});return Object.keys(s).length>0&&i(n=>{let i=n.length===0?1:n[n.length-1].version+1,o={id:gs(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:s,message:`Reverted to version ${r[a].version}`};return[...n,o]}),o},[r,e,t]),compareVersions:(0,Y.useCallback)((e,t)=>{let n=r.findIndex(t=>t.id===e),i=r.findIndex(e=>e.id===t);if(n===-1||i===-1)return null;let[a,o]=n<i?[n,i]:[i,n],s=e=>{let t={};for(let n=0;n<=e;n++)for(let[e,i]of Object.entries(r[n].changes))t[e]=i.after;return t},c=s(a),l=s(o),u=new Set([...Object.keys(c),...Object.keys(l)]),d={};for(let e of u){let t=c[e],n=l[e];t!==n&&(d[e]={before:t,after:n})}return d},[r]),addConflict:(0,Y.useCallback)(e=>{let t={...e,id:ms()};o(e=>[...e,t])},[]),clearHistory:(0,Y.useCallback)(()=>{i([]),o([])},[])}}var vs={sm:24,md:32,lg:40},ys={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function bs(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function xs({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=vs[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,Y.useMemo)(()=>e.slice(0,t),[e,t]),u=Math.max(0,e.length-t),d={display:`inline-flex`,alignItems:`center`,flexDirection:`row-reverse`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`},f={width:`${a}px`,height:`${a}px`,borderRadius:`50%`,border:`2px solid #fff`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`${s}px`,fontWeight:600,color:`#fff`,position:`relative`,flexShrink:0,overflow:`hidden`,boxSizing:`border-box`},p={...f,backgroundColor:`#e2e8f0`,color:`#475569`,marginLeft:`-${o}px`},m={position:`absolute`,bottom:`-1px`,right:`-1px`,width:`${c}px`,height:`${c}px`,borderRadius:`50%`,border:`2px solid #fff`,boxSizing:`border-box`},h=(0,Y.useMemo)(()=>[...l].reverse(),[l]);return Y.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&Y.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>Y.createElement(`div`,{key:e.userId,style:{...f,backgroundColor:e.color,marginLeft:t>0||u>0?`-${o}px`:`0`},title:`${e.userName} (${e.status})`},e.avatar?Y.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):bs(e.userName),r&&Y.createElement(`span`,{style:{...m,backgroundColor:ys[e.status]}}))))}var Ss=Y.createContext({});function Cs(){let e=Y.useContext(Ss),[t,n]=Y.useState([]);return Y.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function ws(e,t){let n=Y.useContext(Ss),[r,i]=Y.useState([]);return Y.useEffect(()=>{if(!n.subscribeRecord||!e||!t){i([]);return}return n.subscribeRecord({objectName:e,recordId:t},e=>{i(Array.isArray(e)?e:[])})},[n,e,t]),r}function Ts(){let{theme:e,setTheme:t}=Go(),{t:n}=R();return(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,X.jsx)(kn,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,X.jsx)(Je,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,X.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,X.jsxs)(ai,{align:`end`,children:[(0,X.jsxs)(or,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,X.jsx)(kn,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,X.jsxs)(or,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,X.jsx)(Je,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,X.jsxs)(or,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,X.jsx)(mt,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var Es=[{code:`en`,label:`English`},{code:`zh`,label:`中文`},{code:`ja`,label:`日本語`},{code:`ko`,label:`한국어`},{code:`de`,label:`Deutsch`},{code:`fr`,label:`Français`},{code:`es`,label:`Español`},{code:`pt`,label:`Português`},{code:`ru`,label:`Русский`},{code:`ar`,label:`العربية`}];function Ds(){let{t:e,language:t,changeLanguage:n}=R();return(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,X.jsx)(Tt,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,X.jsx)(ai,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Es.map(e=>(0,X.jsxs)(or,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var Os={connected:{label:`Connected`,color:`text-green-500`,icon:Tr},connecting:{label:`Connecting...`,color:`text-yellow-500`,icon:jr},reconnecting:{label:`Reconnecting...`,color:`text-yellow-500`,icon:jr},disconnected:{label:`Disconnected`,color:`text-muted-foreground`,icon:Ui},error:{label:`Connection Error`,color:`text-destructive`,icon:Ui}};function ks({state:e,className:t}){let n=Os[e],r=n.icon,[i,a]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(e===`connected`){a(!0);let e=setTimeout(()=>a(!1),2e3);return()=>clearTimeout(e)}a(!1)},[e]),e===`connected`&&!i?null:(0,X.jsxs)(`div`,{className:gr(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:n.label,children:[(0,X.jsx)(r,{className:gr(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function As(e){if(!e)return``;let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=(Date.now()-t)/1e3;return n<60?`${Math.max(1,Math.floor(n))}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`}function js({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:o}){let{t:s}=R(),c=v(),l=a(),{currentAppName:u}=Ao(),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(`notifications`),[h,g]=(0,Y.useState)(`unread`),_=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,Y.useRef)(null),[x,S]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let e=b.current;if(e!==null&&_>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=_},[_]),(0,Y.useEffect)(()=>{x||(b.current=_)},[x,_]);let C=()=>{f(!1);let e=u??l.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{f(!1),c(`/apps/setup/sys_notification?view=mine`)},T=()=>{f(!1),c(`/apps/setup/sys_activity`)},E=e=>{if(o(e.id),e.source_object&&e.source_id){f(!1);let t=u??l.appName;c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`)}};return(0,X.jsxs)(Gn,{open:d,onOpenChange:f,children:[(0,X.jsx)(Se,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${x?`motion-safe:animate-bounce`:``}`,"aria-label":y,title:s(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,X.jsx)(aa,{className:`h-4 w-4`}),_>0&&(0,X.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:_>9?`9+`:_},_)]})}),(0,X.jsxs)(en,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:s(`sidebar.inbox`,{defaultValue:`Inbox`})}),p===`notifications`&&t>0&&(0,X.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:s(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,X.jsxs)(_e,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,X.jsxs)(Oi,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,X.jsxs)(ni,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(aa,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,X.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:t>9?`9+`:t},`notif-${t}`)]}),(0,X.jsxs)(ni,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(Wn,{className:`h-3.5 w-3.5`}),s(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,X.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-amber-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:n>9?`9+`:n},`appr-${n}`)]}),(0,X.jsxs)(ni,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(be,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,X.jsxs)(_r,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,X.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=h===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,X.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:h===`unread`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})}):(0,X.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,X.jsx)(`li`,{className:`motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:(0,X.jsx)(`button`,{type:`button`,onClick:()=>E(e),className:`w-full text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.is_read?``:`bg-accent/40`}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`span`,{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary transition-opacity duration-200 ${e.is_read?`opacity-0`:`opacity-100`}`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:As(e.created_at)})]})]})})},e.id))})})(),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,X.jsx)(_r,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,X.jsx)(`div`,{className:`px-3 py-6 text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:n>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Wn,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,X.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:s(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,X.jsx)(q,{size:`sm`,className:`mt-3`,onClick:C,children:s(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,X.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,X.jsxs)(_r,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,X.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:s(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,X.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,X.jsxs)(`li`,{className:`px-3 py-2.5 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:[(0,X.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[As(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function Ms(e){let{objectDef:t,baseUrl:n,record:r}=e;if(!t?.name||t.editMode!==`page`)return{kind:`modal`};let i=r?.id??r?._id;if(r&&i!=null&&i!==``){let e=encodeURIComponent(String(i));return{kind:`page`,url:`${n}/${t.name}/record/${e}/edit`}}return{kind:`page`,url:`${n}/${t.name}/new`}}function Ns(e){let{action:t,context:n={},defaultBaseUrl:r}=e,i=t.params?.objectName??t.objectName??n.objectName,a=n.baseUrl??r;return i?{success:!0,url:`${a}/${i}/new`}:{success:!1,error:`navigate_create: objectName is required`}}function Ps(e){let{action:t,context:n={},defaultBaseUrl:r}=e,i=t.params?.objectName??t.objectName??n.objectName,a=t.params?.recordId??t.recordId,o=n.baseUrl??r;return!i||a==null||a===``?{success:!1,error:`navigate_edit: objectName and recordId are required`}:{success:!0,url:`${o}/${i}/record/${encodeURIComponent(String(a))}/edit`}}function Fs(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}function Is(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var Ls=`\0`,Rs=`[-\\u2013\\u2014|/·,:]`;function zs(e,t){let n=typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0;if(!n||!t)return t?.id||t?._id||`Record`;let r=!1,i=n.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=String(n).trim().split(`.`),a=t;for(let e of i){if(a==null)break;a=a[e]}if(a&&typeof a==`object`){let e=a,t=e.name??e.full_name??e.display_name??e.label??e.title??e.subject??null;(t==null||typeof t==`string`&&!t.trim())&&(t=[e.salutation,e.first_name,e.last_name].filter(e=>typeof e==`string`&&e.trim()).map(e=>e.trim()).join(` `)||(typeof e.email==`string`&&e.email.trim()?e.email.trim():null)),a=t}return a==null||a===``?Ls:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Rs}\\s*${Ls}`,`g`),o=RegExp(`${Ls}\\s*${Rs}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(Ls,`g`),``).replace(/\s+/g,` `).trim(),i}function Bs(e,t){if(e?.titleFormat){let n=zs(e.titleFormat,t);if(n)return n}return t?.name||t?.full_name||t?.fullName||t?.title||t?.label||t?.subject||t?.id||t?._id||`Untitled`}function Vs({activeAppName:e,onAppChange:t}){let{apps:n}=F(),{t:r}=R(),{appLabel:i}=ti(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=o.find(t=>t.name===e)||a.find(t=>t.name===e&&t.active!==!1)||o[0];return s?(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(`button`,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 hover:bg-accent hover:text-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring max-w-[40vw] sm:max-w-none`,children:[(0,X.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:Fs(s.label,r)})}),(0,X.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,X.jsxs)(ai,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,X.jsx)(Wr,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,X.jsx)(ji,{}),o.map(e=>{let n=as(e.icon),a=i({name:e.name,label:Fs(e.label,r)}),o=s.name===e.name;return(0,X.jsxs)(or,{onClick:()=>t(e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,X.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,X.jsx)(n,{className:`size-3`})}),(0,X.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,X.jsx)(Ae,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Hs=(0,Y.createContext)(null);function Us({children:e}){let[t,n]=(0,Y.useState)(null),r=(0,Y.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,X.jsx)(Hs.Provider,{value:r,children:e})}function Ws(){return(0,Y.useContext)(Hs)?.value??null}function Gs(e){let t=(0,Y.useContext)(Hs),n=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Ks(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,Y.useRef)(r);o.current=r;let s=(0,Y.useCallback)(e=>o.current(e),[]);Gs((0,Y.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function qs(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Js(){return(0,X.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Ys=[];function Xs({variant:e,appName:t,objects:n,connectionState:i,presenceUsers:o,activities:s,activeAppName:c,onAppChange:l}){let d=e??(t?`app`:`home`),f=d===`app`,p=u(),m=a(),h=v(),{isOnline:g}=ne(),{user:_,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:S,isOrganizationsLoading:w}=C(),E=he(),{t:D}=R(),{objectLabel:O,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:M,appLabel:ee}=ti(),{apps:te,dashboards:N,pages:P,reports:re}=F(),{currentAppName:I,recordTitle:L}=Ao(),ie=Ws(),[ae,oe]=(0,Y.useState)(null),[se,ce]=(0,Y.useState)([]),le=(0,Y.useRef)(!1),ue=(0,Y.useRef)(!1),[de,fe]=(0,Y.useState)(0),pe=(0,Y.useRef)(!1),z=(0,Y.useCallback)(async()=>{if(!E||!f)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!le.current)try{let t=await E.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(le.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&oe(e)}}catch{}},[E,f]);(0,Y.useEffect)(()=>{z()},[z]),(0,Y.useEffect)(()=>{if(!E||!f||!_?.id||ue.current)return;let e=!1,t=null,n=1e4,r=n,i=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`,a=async()=>{try{let t=await E.find(`sys_notification`,{$filter:{recipient_id:_.id},$orderby:{created_at:`desc`},$top:20});if(e)return;Array.isArray(t?.data)&&ce(t.data),r=n}catch(e){if(i(e)){ue.current=!0;return}r=Math.min(r*2,12e4)}},o=()=>{if(e||ue.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await a(),o()},n)},s=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,a().finally(o))};return a().finally(o),typeof document<`u`&&document.addEventListener(`visibilitychange`,s),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,s)}},[E,f,_?.id]),(0,Y.useEffect)(()=>{if(!f||!_?.id||pe.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];_.id&&t.push(_.id),_.email&&t.push(_.email);for(let e of _.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{try{let r=new Set;if(t.length===0)return;for(let n of t){let t=new URLSearchParams({status:`pending`,approverId:n}),i=await fetch(`${e}?${t}`,{credentials:`include`});if(i.status===404){pe.current=!0;return}if(!i.ok)return;let a=await i.json().catch(()=>null);for(let e of a?.data||[])r.add(e.id)}n||fe(r.size)}catch{}},a=()=>{n||pe.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[f,_?.id]);let me=se.reduce((e,t)=>e+ +!t.is_read,0),B=(0,Y.useCallback)(async e=>{if(ce(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),E)try{await E.update(`sys_notification`,e,{is_read:!0,read_at:new Date().toISOString()})}catch{}},[E]),V=(0,Y.useCallback)(async()=>{let e=se.filter(e=>!e.is_read);if(!e.length||(ce(e=>e.map(e=>({...e,is_read:!0}))),!E))return;let t=new Date().toISOString(),n=e.map(e=>e.id),r=E;if(typeof r.bulkUpdate==`function`)try{await r.bulkUpdate(`sys_notification`,n,{is_read:!0,read_at:t});return}catch{}await Promise.all(e.map(e=>E.update(`sys_notification`,e.id,{is_read:!0,read_at:t}).catch(()=>{})))},[E,se]),H=Cs(),ge=o??(H.length>0?H:Ys),_e=s??ae??[],ve=w||(x??[]).length>0||!!S,U=p.pathname.split(`/`).filter(Boolean),be=m.appName||U[1],xe=U[2],Se=`/apps/${be}`,Ce=n??[],we=c||I||be,Te=(te||[]).find(e=>e.name===we),Ee=new Set,W=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ee.add(t.objectName),t.children&&W(t.children)};W(Te?.navigation||[]);for(let e of Te?.areas||[])W(e.navigation||[]);let De=(Ee.size>0?Ce.filter(e=>Ee.has(e.name)):Ce.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:O(e),href:`${Se}/${e.name}`})),Oe=[];if(f){if(xe===`dashboard`){if(Oe.push({label:D(`console.breadcrumb.dashboards`),href:Se}),U[3]){let e=U[3],t=(N||[]).find(t=>t.name===e)?.label||qs(e);Oe.push({label:k({name:e,label:t})})}}else if(xe===`page`){if(Oe.push({label:D(`console.breadcrumb.pages`),href:Se}),U[3]){let e=U[3],t=(P||[]).find(t=>t.name===e)?.label||qs(e);Oe.push({label:A({name:e,label:t})})}}else if(xe===`report`){if(Oe.push({label:D(`console.breadcrumb.reports`),href:Se}),U[3]){let e=U[3],t=(re||[]).find(t=>t.name===e)?.label||qs(e);Oe.push({label:j({name:e,label:t})})}}else if(xe===`system`)Oe.push({label:D(`console.breadcrumb.system`)}),U[3]&&Oe.push({label:qs(U[3])});else if(xe){let e=Ce.find(e=>e.name===xe);if(e){if(Oe.push({label:O(e),href:`${Se}/${xe}`,siblings:De}),U[3]===`record`&&U[4]){let e=U[4].length>12?`${U[4].slice(0,8)}…`:U[4],t=L?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Oe.push({label:n||`#${e}`})}else if(U[3]===`view`&&U[4]){let t=U[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||qs(t),i=M(e.name,t,r);Oe.push({label:i})}}}}let ke=Oe[Oe.length-1]?.label||t||``;return(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,X.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,X.jsx)(r,{to:`/home`,className:gr(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,f&&`hidden sm:flex`),title:`ObjectStack`,children:(0,X.jsx)(Pt,{className:`h-4 w-4`})}),d===`home`&&(0,X.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:`ObjectStack`}),d===`orgs`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Js,{}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:D(`organizations.title`,{defaultValue:`Organizations`})})]}),f&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Wi,{className:`md:hidden shrink-0 ml-1`,"aria-label":D(`common.toggleSidebar`)||`Toggle sidebar`}),c&&l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(Js,{})}),(0,X.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(Vs,{activeAppName:c,onAppChange:l})})]}):t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(Js,{})}),(0,X.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Oe.map((e,t)=>{let n=t===Oe.length-1;return(0,X.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,X.jsx)(Js,{}),e.siblings&&e.siblings.length>1?(0,X.jsxs)(Xn,{children:[(0,X.jsxs)(Yr,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hover:bg-accent hover:text-foreground ${n?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,X.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,X.jsxs)(ai,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,X.jsx)(Wr,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,X.jsx)(ji,{}),e.siblings.map(e=>(0,X.jsx)(or,{asChild:!0,children:(0,X.jsx)(r,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,X.jsx)(r,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,X.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),ie&&ie.views.length>0?ie.views.length>1?(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`sm:hidden flex items-center gap-0.5 min-w-0 ml-1 rounded-md px-1.5 py-1 text-sm font-medium hover:bg-accent active:bg-accent/80 transition-colors`,"aria-label":`Switch view`,children:[(0,X.jsx)(`span`,{className:`truncate max-w-[180px]`,children:ie.triggerLabel??ie.views.find(e=>e.id===ie.activeViewId)?.label??ke}),(0,X.jsx)(sn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,X.jsx)(ai,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:ie.views.map(e=>{let t=e.id===ie.activeViewId;return(0,X.jsxs)(or,{onSelect:()=>{t||ie.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,X.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,X.jsx)(gi,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,X.jsx)(Ae,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,X.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:ie.triggerLabel??ie.views[0].label}):(0,X.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:ke})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!g&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 text-xs font-medium`,children:[(0,X.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),`Offline`]}),f&&i&&(0,X.jsx)(ks,{state:i}),f&&ge.length>0&&(0,X.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:`Users currently online`,children:(0,X.jsx)(xs,{users:ge,size:`sm`,maxVisible:3,showStatus:!0})}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,X.jsxs)(`button`,{onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),className:`hidden lg:flex relative items-center gap-2 w-48 xl:w-64 h-8 px-3 text-sm rounded-md border bg-muted/50 text-muted-foreground hover:bg-muted transition-colors`,children:[(0,X.jsx)(Ai,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:D(`console.search`,{defaultValue:`Search…`})}),(0,X.jsxs)(`kbd`,{className:`pointer-events-none inline-flex h-5 items-center gap-0.5 rounded border bg-background px-1.5 text-[10px] font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),"aria-label":D(`console.search`,{defaultValue:`Search…`}),children:(0,X.jsx)(Ai,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,X.jsx)(js,{notifications:se,unreadCount:me,pendingApprovalsCount:de,activities:_e,onMarkAllRead:V,onMarkRead:B}),(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":D(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,X.jsx)(r,{to:`/ai`,children:(0,X.jsx)(Ge,{className:`h-4 w-4`})})}),(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,asChild:!0,"aria-label":D(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,X.jsx)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:(0,X.jsx)(br,{className:`h-4 w-4`})})})]}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,X.jsxs)(ye,{className:`h-7 w-7 rounded-full`,children:[(0,X.jsx)(Di,{src:_?.image,alt:_?.name??`User`}),(0,X.jsx)(hr,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:T(_)})]})})}),(0,X.jsxs)(ai,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,X.jsx)(Wr,{className:`p-0 font-normal`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,X.jsxs)(ye,{className:`h-8 w-8 rounded-lg`,children:[(0,X.jsx)(Di,{src:_?.image,alt:_?.name??`User`}),(0,X.jsx)(hr,{className:`rounded-lg bg-primary text-primary-foreground`,children:T(_)})]}),(0,X.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,X.jsx)(`span`,{className:`truncate font-semibold`,children:_?.name??`User`}),(0,X.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:_?.email??``})]})]})}),(0,X.jsx)(ji,{}),(0,X.jsxs)(xi,{children:[ve&&(0,X.jsxs)(or,{onClick:()=>h(`/organizations`),className:`cursor-pointer`,children:[(0,X.jsx)(Pt,{className:`mr-2 h-4 w-4`}),D(`organizations.mine`,{defaultValue:`My Organizations`})]}),(te||[]).filter(e=>e.active!==!1&&e.hidden===!0).map(e=>{let t=as(e.icon),n=ee({name:e.name,label:Fs(e.label,D)});return(0,X.jsxs)(or,{onClick:()=>h(`/apps/${e.name}`),className:`cursor-pointer`,children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,X.jsx)(ji,{}),(0,X.jsx)(Wr,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:D(`user.preferences`,{defaultValue:`Preferences`})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.theme`,{defaultValue:`Theme`})}),(0,X.jsx)(Ts,{})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.language`,{defaultValue:`Language`})}),(0,X.jsx)(Ds,{})]}),b&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ji,{}),(0,X.jsxs)(or,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,X.jsx)(Qr,{className:`mr-2 h-4 w-4`}),D(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Zs=768,Qs=1024;function $s(){let{setOpen:e,isMobile:t}=hn();(0,Y.useEffect)(()=>{function t(){let t=window.innerWidth;t>=Zs&&t<Qs&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}var ec={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function tc(e){ec={...ec,...e,features:{...ec.features,...e.features??{}},branding:{...ec.branding,...e.branding??{}}}}async function nc(e=``){let t=(e||``).replace(/\/+$/,``);try{let e=await fetch(`${t}/api/v1/runtime/config`,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let n=await e.json();if(!n||typeof n!=`object`)return;tc({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):ec.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??ec.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??ec.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:ec.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():ec.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():ec.branding.productShortName}:ec.branding})}catch{}}function rc(){return ec}function ic(){return ec.branding?.productName||`ObjectOS`}function ac(){return ec.branding?.productShortName||ic()}function oc(){return ec.cloudUrl??``}function sc({children:e}){return $s(),(0,X.jsx)(X.Fragment,{children:e})}function cc({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Fs(n?.label)||t,{isAiEnabled:c}=k(),l=c||!1,{setContext:u,setCurrentAppName:d}=Ao();return(0,Y.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,X.jsx)(Us,{children:(0,X.jsxs)(da,{sidebar:(0,X.jsx)(ds,{activeAppName:t,onAppChange:r}),navbar:(0,X.jsx)(Xs,{variant:`app`,appName:s,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,logo:n.branding.logo,title:n.label?`${Fs(n.label)} — ${ic()}`:void 0}:void 0,children:[(0,X.jsx)(sc,{children:e}),l&&(0,X.jsx)(ts,{appLabel:s,objects:i,userId:o})]})})}function lc({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,X.jsxs)(`div`,{style:{"--page-header-accent":i||`hsl(var(--primary))`},className:gr(`relative shrink-0 border-b bg-background z-10`,a&&`sticky top-0 bg-background/85 backdrop-blur supports-[backdrop-filter]:bg-background/75`,o),"data-testid":s??`page-header`,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 top-0 h-[2px] opacity-80`,style:{background:`linear-gradient(90deg, transparent, var(--page-header-accent), transparent)`}}),(0,X.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,X.jsx)(`div`,{className:gr(`shrink-0 inline-flex items-center justify-center rounded-lg`,`h-9 w-9 sm:h-10 sm:w-10`,`[&_svg]:h-[18px] [&_svg]:w-[18px] sm:[&_svg]:h-5 sm:[&_svg]:w-5`),style:{color:`var(--page-header-accent)`,background:`linear-gradient(135deg, color-mix(in srgb, var(--page-header-accent) 18%, transparent), color-mix(in srgb, var(--page-header-accent) 6%, transparent))`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, var(--page-header-accent) 22%, transparent)`},children:n}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,X.jsx)(`p`,{className:`text-xs sm:text-sm text-muted-foreground truncate hidden sm:block max-w-xl mt-0.5`,children:t})]})]}),r&&(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function uc({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(``),u=v(),{appName:d}=a(),{setTheme:f}=Go(),{evaluator:p}=lo(),{t:m}=R();(0,Y.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),s(e=>!e))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,Y.useEffect)(()=>{o||l(``)},[o]);let h=`/apps/${d||t?.name}`,{user:g}=C(),_=(0,Y.useMemo)(()=>({currentUserId:g?.id??null}),[g?.id]),y=(0,Y.useCallback)(e=>{s(!1),e()},[]),b=dc(t?.navigation||[]).filter(e=>uo(e.visible??e.visibleOn,p)),{results:x,isSearching:S}=ie({query:c,objects:n,dataSource:i,objectNames:(0,Y.useMemo)(()=>b.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,b.map(e=>e.objectName||``).join(`|`)]),enabled:o&&!!i,getDisplayName:Bs}),{recentItems:w}=Do(),T=(0,Y.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=o&&c.trim().length===0&&T.length>0;return(0,X.jsxs)(Rt,{open:o,onOpenChange:s,children:[(0,X.jsx)(Lr,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(zr,{children:S?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`}),m(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):m(`console.commandPalette.noResults`)}),E&&(0,X.jsx)(Te,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,X.jsxs)(Et,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,X.jsx)(Ai,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),x.length>0&&(0,X.jsx)(Te,{heading:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[m(`console.commandPalette.records`,{defaultValue:`Records`}),S&&(0,X.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:x.map(e=>{let t=as(e.icon);return(0,X.jsxs)(Et,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>y(()=>u(`${h}/${e.objectName}/record/${e.recordId}`)),children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.display}),(0,X.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:e.objectLabel})]},`${e.objectName}:${e.recordId}`)})}),b.filter(e=>e.type===`object`).length>0&&(0,X.jsx)(Te,{heading:m(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=as(e.icon);return(0,X.jsxs)(Et,{value:`object ${Fs(e.label,m)} ${e.objectName}`,onSelect:()=>y(()=>u(ua(e,h,_).href)),children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Fs(e.label,m)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,X.jsx)(Te,{heading:m(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,X.jsxs)(Et,{value:`dashboard ${Fs(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(ua(e,h,_).href)),children:[(0,X.jsx)(ci,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Fs(e.label,m)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,X.jsx)(Te,{heading:m(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,X.jsxs)(Et,{value:`page ${Fs(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(ua(e,h,_).href)),children:[(0,X.jsx)(na,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Fs(e.label,m)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,X.jsx)(Te,{heading:m(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,X.jsxs)(Et,{value:`report ${Fs(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(ua(e,h,_).href)),children:[(0,X.jsx)(Pe,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Fs(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Gt,{}),(0,X.jsx)(Te,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=as(e.icon);return(0,X.jsxs)(Et,{value:`app ${Fs(e.label,m)} ${e.name}`,onSelect:()=>y(()=>r(e.name)),children:[(0,X.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Fs(e.label,m)}),e.name===t?.name&&(0,X.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:m(`console.commandPalette.current`)})]},e.name)})})]}),(0,X.jsx)(Gt,{}),(0,X.jsxs)(Te,{heading:m(`console.commandPalette.preferences`),children:[(0,X.jsxs)(Et,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,X.jsx)(kn,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,X.jsxs)(Et,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,X.jsx)(Je,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,X.jsxs)(Et,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,X.jsx)(mt,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,X.jsx)(Gt,{}),(0,X.jsxs)(Te,{heading:m(`console.commandPalette.actions`),children:[(0,X.jsxs)(Et,{value:`create new app application`,onSelect:()=>y(()=>u(`${h}/create-app`)),children:[(0,X.jsx)(fn,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.createApp`)})]}),(0,X.jsxs)(Et,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,X.jsx)(Ai,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})]})]})]})}function dc(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...dc(n.children)):t.push(n);return t}function fc(){let{t:e}=R(),[t,n]=(0,Y.useState)(!1),r=(0,Y.useMemo)(()=>[{title:e(`console.shortcuts.groups.general`),shortcuts:[{keys:[`⌘`,`K`],description:e(`console.shortcuts.openCommandPalette`)},{keys:[`?`],description:e(`console.shortcuts.showShortcuts`)},{keys:[`Esc`],description:e(`console.shortcuts.closeDialog`)}]},{title:e(`console.shortcuts.groups.navigation`),shortcuts:[{keys:[`B`],description:e(`console.shortcuts.toggleSidebar`)},{keys:[`⌘`,`/`],description:e(`console.shortcuts.focusSearch`)}]},{title:e(`console.shortcuts.groups.dataViews`),shortcuts:[{keys:[`N`],description:e(`console.shortcuts.createRecord`)},{keys:[`R`],description:e(`console.shortcuts.refreshData`)},{keys:[`⌘`,`E`],description:e(`console.shortcuts.editRecord`)}]},{title:e(`console.shortcuts.groups.preferences`),shortcuts:[{keys:[`⌘`,`D`],description:e(`console.shortcuts.toggleDarkMode`)}]}],[e]);return(0,Y.useEffect)(()=>{function e(e){let t=e.target;t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable||e.key===`?`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),n(e=>!e))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,X.jsx)(We,{open:t,onOpenChange:n,children:(0,X.jsxs)(ot,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:e(`console.shortcuts.title`)}),(0,X.jsx)(xt,{children:e(`console.shortcuts.description`)})]}),(0,X.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,X.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function pc(){return null}var mc={initializing:`Initializing…`,steps:{connecting:`Connecting to server`,loadingConfig:`Loading configuration`,preparingWorkspace:`Preparing workspace`},error:{connectionFailed:`Cannot connect to server`,checkServer:`Please check your network connection or that the backend is running.`},actions:{retry:`Retry`,retrying:`Retrying…`}};function hc({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Y.useState)(0),o=(0,Y.useMemo)(()=>[mc.steps.connecting,mc.steps.loadingConfig,mc.steps.preparingWorkspace],[]);return(0,Y.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,o.length-1))},1200);return()=>clearInterval(n)},[e,t,o.length]),(0,X.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,X.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,X.jsx)(Xt,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,X.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:ic()}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:mc.initializing})]}),t?(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-5 rounded-lg border border-destructive/30 bg-destructive/5 w-full`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,X.jsx)(Li,{className:`h-5 w-5 shrink-0`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold`,children:mc.error.connectionFailed})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:mc.error.checkServer})]}),n&&(0,X.jsx)(q,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),mc.actions.retrying]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Zi,{className:`h-4 w-4`}),mc.actions.retry]})})]}):e?(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,X.jsx)(wt,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:o.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2.5 text-sm transition-opacity duration-300`,style:{opacity:t<=i?1:.3},children:[t<i?(0,X.jsx)(Tr,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,X.jsx)(jr,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,X.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}function gc(e){let{theme:t=`system`}=Go();return(0,X.jsx)(sa,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,X.jsx)(Tr,{className:`h-4 w-4`}),info:(0,X.jsx)($n,{className:`h-4 w-4`}),warning:(0,X.jsx)(Ot,{className:`h-4 w-4`}),error:(0,X.jsx)($e,{className:`h-4 w-4`}),loading:(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`})},toastOptions:{duration:4e3,classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})}var _c=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function vc({children:e,className:t}){let n=u(),r=Y.useRef(null),i=Y.useRef(n.pathname);return Y.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(..._c),e.offsetWidth,e.classList.add(..._c))},[n.pathname]),(0,X.jsx)(`div`,{ref:r,className:[..._c,t??``].filter(Boolean).join(` `),children:e})}var yc=null,bc=null;function xc(){return bc||(bc=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_SENTRY_DSN;if(!t)return!1;try{let n=await m(()=>import(`./vendor-sentry-D5yZpZ5X.js`).then(e=>e.t),[],import.meta.url),r=Number(e.VITE_SENTRY_TRACES_SAMPLE_RATE??`0.1`);return n.init({dsn:t,environment:e.VITE_SENTRY_ENVIRONMENT||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:Number.isFinite(r)?r:.1,sendDefaultPii:e.VITE_SENTRY_SEND_DEFAULT_PII!==`false`,replaysSessionSampleRate:0,replaysOnErrorSampleRate:e.VITE_SENTRY_REPLAY===`true`?.1:0,integrations:[n.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=Cc(e.data.url)),e}}),yc=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),bc)}function Sc(e,t){if(yc)try{yc.captureException(e,t?{extra:t}:void 0)}catch{}}function Cc(e){try{let t=new URL(e,`http://localhost`);for(let e of[`token`,`access_token`,`id_token`,`apiKey`,`api_key`,`password`])t.searchParams.has(e)&&t.searchParams.set(e,`[redacted]`);return t.pathname+(t.searchParams.toString()?`?`+t.searchParams.toString():``)}catch{return e}}function wc({error:e,onReset:t}){let{t:n}=R();return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,X.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,X.jsx)(Ot,{className:`h-6 w-6 text-destructive`})}),(0,X.jsx)(ta,{children:n(`console.errors.somethingWentWrong`)}),(0,X.jsx)(rt,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,X.jsx)(Kn,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,X.jsx)(dn,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Tc=class extends Y.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary] Caught error:`,e,t),Sc(e,{componentStack:t.componentStack}),this.props.onError?.(e,t)}resetErrorBoundary=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?typeof this.props.fallback==`function`?this.props.fallback({error:this.state.error,reset:this.resetErrorBoundary}):this.props.fallback:(0,X.jsx)(wc,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function Ec({sections:e,open:t}){if(!t)return null;let{t:n}=R(),[r,i]=(0,Y.useState)([`0`]),[a,o]=(0,Y.useState)(null),s=async(e,t)=>{try{await navigator.clipboard.writeText(JSON.stringify(e,null,2)),o(t),setTimeout(()=>o(null),2e3)}catch(e){console.error(`Failed to copy:`,e)}},c=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])};return(0,X.jsxs)(`div`,{className:`w-80 border-l bg-background p-0 overflow-hidden flex flex-col shrink-0 z-20 transition-all`,children:[(0,X.jsxs)(`div`,{className:`px-4 py-3 border-b bg-muted/5 flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:n(`layout.metadata.panelTitle`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60`,children:n(`layout.metadata.jsonBadge`)})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:e.map((e,t)=>{let i=String(t),o=r.includes(i),l=a===t;return(0,X.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 hover:bg-muted/5 transition-colors`,children:[(0,X.jsxs)(`button`,{onClick:()=>c(i),className:`flex-1 flex items-center justify-between text-left`,children:[(0,X.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:e.title}),o?(0,X.jsx)(sn,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,X.jsx)(tr,{className:`h-3 w-3 text-muted-foreground ml-2`})]}),(0,X.jsx)(`button`,{onClick:()=>s(e.data,t),className:`p-1 hover:bg-muted rounded transition-colors ml-2`,title:n(`layout.metadata.copyJson`),children:l?(0,X.jsx)(Ae,{className:`h-3 w-3 text-green-600`}):(0,X.jsx)(Ei,{className:`h-3 w-3 text-muted-foreground`})})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(`div`,{className:`relative rounded-md border border-border/50 bg-muted/5 overflow-hidden`,children:(0,X.jsx)(`pre`,{className:`text-[11px] leading-relaxed p-3 overflow-auto max-h-96 font-mono text-foreground/90`,children:JSON.stringify(e.data,null,2)})})})]},t)})})]})}function Dc(){let[e,t]=(0,Y.useState)((0,Y.useMemo)(()=>{try{return typeof window<`u`?L(window.location.search).enabled:!1}catch{return!1}},[]));return{showDebug:e,toggleDebug:()=>t(e=>!e)}}function Oc({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s}){let{t:c}=R(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{e||d(!1)},[e]);let f=(0,Y.useMemo)(()=>({id:`view_${Date.now()}`,label:c(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[],showSearch:!0,showFilters:!0,showSort:!0}),[]),p=(0,Y.useMemo)(()=>({...r}),[n===`create`?`create`:r.id]),{draft:m,isDirty:h,updateField:g,discard:_,undo:v,redo:y,canUndo:b,canRedo:x}=zi(n===`create`?f:p,{mode:n,onUpdate:a});(0,Y.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,Y.useMemo)(()=>ja(i),[i.fields]),C=(0,Y.useMemo)(()=>Ia(m.filter),[m.filter]),w=(0,Y.useMemo)(()=>Ta(m.sort),[m.sort]),T=(0,Y.useMemo)(()=>Fa({t:c,fieldOptions:S,objectDef:i,updateField:g,filterGroupValue:C,sortItemsValue:w,essentialOnly:!u}),[c,S,i,g,C,w,u]),E=m.type||`grid`,D=(0,Y.useMemo)(()=>({...T,breadcrumb:[c(`console.objectView.page`),Ca[E]||E]}),[T,c,E]),O=(0,Y.useCallback)(()=>{n===`create`?s?.(m):o?.(m),_()},[m,o,s,n,_]),k=(0,Y.useCallback)(()=>{if(n===`create`){t();return}_()},[_,n,t]),A=c(n===`create`?`console.objectView.createView`:`console.objectView.configureView`),j=(0,X.jsx)(q,{size:`sm`,variant:u?`secondary`:`ghost`,onClick:()=>d(e=>!e),className:`h-7 w-7 p-0`,"data-testid":`view-config-advanced-toggle`,"aria-pressed":u,title:u?c(`console.objectView.showFewerSettings`,{defaultValue:`Show fewer settings`}):c(`console.objectView.showAdvancedSettings`,{defaultValue:`Show advanced settings`}),children:(0,X.jsx)(ar,{className:`h-3.5 w-3.5`})});return(0,X.jsx)(bn,{open:e,onClose:t,schema:D,draft:m,isDirty:h,onFieldChange:g,onSave:O,onDiscard:k,onUndo:v,onRedo:y,canUndo:b,canRedo:x,undoLabel:c(`designer.undo`),redoLabel:c(`designer.redo`),objectDef:i,saveLabel:c(`console.objectView.save`),discardLabel:c(`console.objectView.discard`),panelRef:l,role:`complementary`,ariaLabel:A,tabIndex:-1,testId:`view-config-panel`,closeTitle:c(`console.objectView.closePanel`),footerTestId:`view-config-footer`,saveTestId:`view-config-save`,discardTestId:`view-config-discard`,headerExtra:j,className:`transition-all overflow-hidden`})}function kc(e){return[{type:`grid`,icon:vr,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Fn,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:zt,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:ke,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:oi,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:$t,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:U,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Pe,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function Ac(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var jc={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:Na}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:Da},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],timeline:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.timelineDateFieldHelp`,filter:e=>e.type===`date`,preferred:Da},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],gantt:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.ganttStartDateFieldHelp`,filter:e=>e.type===`date`,preferred:Da},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Aa},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],gallery:[{key:`coverField`,i18nKey:`console.objectView.imageField`,helpI18nKey:`console.objectView.imageFieldHelp`,filter:e=>wa(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&Pa(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&Pa(e,`longitude`)}],chart:[{key:`chartType`,i18nKey:`console.objectView.chartType`,helpI18nKey:`console.objectView.chartTypeHelp`,kind:`enum`,enumOptions:[{value:`bar`,i18nKey:`console.objectView.chartTypeBar`},{value:`line`,i18nKey:`console.objectView.chartTypeLine`},{value:`pie`,i18nKey:`console.objectView.chartTypePie`},{value:`area`,i18nKey:`console.objectView.chartTypeArea`},{value:`scatter`,i18nKey:`console.objectView.chartTypeScatter`}],defaultValue:`bar`},{key:`xAxisField`,i18nKey:`console.objectView.xAxisField`,helpI18nKey:`console.objectView.xAxisFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`||e.type===`date`||e.type===`text`,preferred:Na},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function Mc({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=R(),s=(0,Y.useMemo)(()=>kc(o),[o]),c=(0,Y.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,Y.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,Y.useMemo)(()=>a?ja(a):[],[a]),[d,f]=(0,Y.useState)(c[0]?.type??`grid`),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)({});(0,Y.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,Y.useEffect)(()=>{h||m(Ac(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=jc[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,Y.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(jc[t.type]??[]).find(e=>!b(e));e[t.type]=n??null}),e},[c,u,a]),S=e=>_[`${d}.${e}`]??``,C=(e,t)=>v(n=>({...n,[`${d}.${e}`]:t})),w=p.trim(),T=w.length>0&&l.has(w),E=y.every(e=>S(e.key).length>0),D=w.length>0&&!T&&E;(0,Y.useEffect)(()=>{y.length!==0&&y.forEach(e=>{if(S(e.key).length>0)return;if(e.kind===`enum`){e.defaultValue&&C(e.key,e.defaultValue);return}let t=e.filter?u.filter(e.filter):u;if(t.length===0)return;if(t.length===1){C(e.key,t[0].value);return}let n=Oa(t,e.preferred??[]);n&&C(e.key,n)})},[d,u]);let O=()=>{if(!D)return;let e={};y.forEach(t=>{let n=S(t.key);n&&(e[t.key]=t.key===`yAxisFields`?[n]:n)});let r={type:d,label:w};Object.keys(e).length>0&&(r[d]=e),n(r),t(!1)};return(0,X.jsx)(We,{open:e,onOpenChange:t,children:(0,X.jsxs)(ot,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:o(`console.objectView.createView`)}),(0,X.jsx)(xt,{children:o(`console.objectView.createViewDesc`)})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-4 gap-2 py-2`,"data-testid":`create-view-type-grid`,children:c.map(({type:e,label:t,description:n,icon:r})=>{let i=e===d,a=x[e],s=!!a,c=s?o(`console.objectView.viewTypeUnavailable`,{field:o(a.i18nKey)}):void 0;return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`create-view-type-${e}`,"aria-pressed":i,"aria-disabled":s,disabled:s,title:c,onClick:()=>{s||f(e)},className:gr(`group flex flex-col items-start gap-1 rounded-lg border bg-background p-3 text-left transition-colors`,!s&&`hover:border-primary/60 hover:bg-accent/40`,i&&!s?`border-primary ring-2 ring-primary/30 bg-accent/40`:`border-border`,s&&`opacity-50 cursor-not-allowed`),children:[(0,X.jsx)(r,{className:gr(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,X.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,X.jsx)(`div`,{className:`text-[10px] leading-tight text-muted-foreground line-clamp-2`,children:s?o(`console.objectView.viewTypeUnavailableShort`):n})]},e)})}),y.length>0&&(0,X.jsx)(`div`,{className:`space-y-3 rounded-md border border-dashed bg-muted/30 p-3`,"data-testid":`create-view-required-fields`,children:y.map(e=>{let t=S(e.key),n=e.kind===`enum`,r=n?[]:e.filter?u.filter(e.filter):u,i=!n&&u.length>0&&r.length===0;return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,X.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,X.jsxs)(`select`,{id:`create-view-required-${e.key}`,"data-testid":`create-view-required-${e.key}`,value:t,onChange:t=>C(e.key,t.target.value),disabled:i,className:gr(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,X.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,X.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,X.jsx)(Li,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,X.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,X.jsx)(K,{id:`create-view-name-input`,"data-testid":`create-view-name-input`,autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(!0)},onKeyDown:e=>{e.key===`Enter`&&D&&O()},placeholder:o(`console.objectView.newView`),className:`h-9`}),T&&(0,X.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,X.jsxs)(rn,{className:`mt-2`,children:[(0,X.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,X.jsx)(q,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var Nc={config:{icon:ar,short:`Admin config`,title:`Administrator configuration`,body:()=>`These rows define how the platform behaves at runtime. Author them here; the runtime data they produce lives in a separate table.`,tone:`border-sky-300/60 bg-sky-50 text-sky-900 hover:bg-sky-100 dark:border-sky-500/40 dark:bg-sky-950/40 dark:text-sky-100`},system:{icon:gi,short:`System-managed`,title:`Managed by the platform`,body:()=>`Rows here are created automatically when actions run on the source record. The list below is a read-only monitoring surface — row-level actions (Approve, Recall, Resend, …) live on each row.`,tone:`border-slate-300/60 bg-slate-50 text-slate-900 hover:bg-slate-100 dark:border-slate-500/40 dark:bg-slate-950/40 dark:text-slate-100`},"append-only":{icon:Pn,short:`Read-only · Audit log`,title:`Read-only historical record`,body:()=>`Immutable audit log. Rows cannot be created, edited, or deleted from the UI — they're written by the platform when events occur. Use Export to download for compliance review.`,tone:`border-zinc-300/60 bg-zinc-50 text-zinc-900 hover:bg-zinc-100 dark:border-zinc-500/40 dark:bg-zinc-950/40 dark:text-zinc-100`},"better-auth":{icon:Yn,short:`Identity`,title:`Managed by the identity provider`,body:e=>`This object's schema is owned by ${e}. Direct edits bypass password hashing, session validation, two-factor checks, and audit hooks. Use the dedicated identity workflows instead (Invite User, Reset Password, Revoke Session, Rotate Key, …).`,tone:`border-amber-300/60 bg-amber-50 text-amber-900 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-amber-950/40 dark:text-amber-100`}};function Pc({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=Nc[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,X.jsx)(Vt,{delayDuration:200,children:(0,X.jsxs)(Be,{children:[(0,X.jsx)(Vr,{asChild:!0,children:(0,X.jsxs)(G,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:gr(`gap-1 font-normal text-[11px] leading-none py-0.5 px-1.5 cursor-help`,r.tone,n),children:[(0,X.jsx)(i,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:r.short})]})}),(0,X.jsxs)(Fe,{side:`bottom`,align:`start`,className:`max-w-xs text-xs leading-relaxed`,children:[(0,X.jsx)(`p`,{className:`font-semibold mb-1`,children:r.title}),(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:r.body(a)})]})]})})}function Fc({cards:e=6}){return(0,X.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(W,{className:`h-7 w-56`}),(0,X.jsx)(W,{className:`h-4 w-80`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:Array.from({length:4}).map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,X.jsx)(W,{className:`h-4 w-20`}),(0,X.jsx)(W,{className:`h-8 w-24`}),(0,X.jsx)(W,{className:`h-3 w-16`})]},`stat-${t}`))}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:e}).map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(W,{className:`h-5 w-32`}),(0,X.jsx)(W,{className:`h-5 w-5 rounded-full`})]}),(0,X.jsx)(W,{className:`h-40 w-full`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(W,{className:`h-3 w-16`}),(0,X.jsx)(W,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Ic({fields:e=8,columns:t=2}){return(0,X.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(W,{className:`h-8 w-8 rounded`}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(W,{className:`h-6 w-48`}),(0,X.jsx)(W,{className:`h-4 w-32`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(W,{className:`h-9 w-20`}),(0,X.jsx)(W,{className:`h-9 w-20`})]})]}),(0,X.jsx)(W,{className:`h-5 w-24`}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 ${t===2?`md:grid-cols-2`:``} gap-4`,children:Array.from({length:e}).map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(W,{className:`h-4 w-24`}),(0,X.jsx)(W,{className:`h-9 w-full`})]},`field-${t}`))}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,X.jsx)(W,{className:`h-5 w-32`}),(0,X.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:3}).map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-3 py-2`,children:[(0,X.jsx)(W,{className:`h-8 w-8 rounded-full`}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,X.jsx)(W,{className:`h-4 w-40`}),(0,X.jsx)(W,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var Lc={platform:{create:!0,import:!0,edit:!0,delete:!0,exportCsv:!0},config:{create:!0,import:!1,edit:!0,delete:!0,exportCsv:!0},system:{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"append-only":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"better-auth":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0}};function Rc(e){let t=Lc[e?.managedBy??`platform`]??Lc.platform,n=e?.userActions??{};return{create:n.create??t.create,import:n.import??t.import,edit:n.edit??t.edit,delete:n.delete??t.delete,exportCsv:n.exportCsv??t.exportCsv}}var zc=new Set([`record:discussion`,`record:chatter`]);function Bc(e){let t=new WeakSet,n=e=>{if(!e||typeof e!=`object`||t.has(e))return!1;if(t.add(e),Array.isArray(e))return e.some(n);let r=e?.type;return typeof r==`string`&&zc.has(r)?!0:[e.children,e.items,e.body,e.components,e.properties?.children,e.properties?.items,e.regions].some(n)};return n(e)}function Vc({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,X.jsx)(Qn,{open:e.open,onOpenChange:e=>{e||r()},children:(0,X.jsxs)(cr,{children:[(0,X.jsxs)(fr,{children:[(0,X.jsx)(xr,{children:e.options?.title||`Confirm Action`}),(0,X.jsx)(Kr,{children:e.message})]}),(0,X.jsxs)(Ni,{children:[(0,X.jsx)(Ci,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,X.jsx)(si,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function Hc({state:e,onOpenChange:t}){let{t:n}=R(),[r,i]=(0,Y.useState)({}),[a,o]=(0,Y.useState)({});(0,Y.useEffect)(()=>{if(e.open){let t={};for(let n of e.params)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);i(t),o({})}},[e.open,e.params]);let s=e=>e==null?!0:typeof e==`string`?e.trim()===``:Array.isArray(e)?e.length===0:!1,c=()=>{let n={};for(let t of e.params)t.required&&s(r[t.name])&&(n[t.name]=!0);if(Object.keys(n).length>0){o(n);return}e.resolve?.(r),t(!1)},l=()=>{e.resolve?.(null),t(!1)},u=(e,t)=>{i(n=>({...n,[e]:t})),o(t=>({...t,[e]:!1}))};return(0,X.jsx)(We,{open:e.open,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(ot,{children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:n(`actionDialog.title`)}),(0,X.jsx)(xt,{children:n(`actionDialog.description`)})]}),(0,X.jsx)(`div`,{className:`grid gap-4 py-4`,children:e.params.map(e=>{if(e.type===`boolean`||e.type===`checkbox`){let t=r[e.name]===!0;return(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Ye,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,X.jsxs)(Nr,{htmlFor:e.name,className:`font-normal cursor-pointer`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),a[e.name]&&(0,X.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground ml-6`,children:e.helpText})]},e.name)}let t=e.type===`lookup`||e.type===`reference`;return(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsxs)(Nr,{htmlFor:e.name,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,X.jsxs)(on,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,X.jsx)(Tn,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,X.jsx)(nt,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,X.jsx)(oa,{children:e.options.map(e=>(0,X.jsx)(Oe,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,X.jsx)(Pi,{value:r[e.name]??null,onChange:t=>u(e.name,t),field:{name:e.name,type:`lookup`,reference_to:e.referenceTo,display_field:e.displayField,id_field:e.idField,description_field:e.descriptionField,multiple:e.multiple,title_format:e.titleFormat,lookup_columns:e.lookupColumns,lookup_filters:e.lookupFilters,lookup_page_size:e.lookupPageSize,depends_on:e.dependsOn,placeholder:e.placeholder}}):e.type===`textarea`?(0,X.jsx)(Yt,{id:e.name,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):e.type===`number`?(0,X.jsx)(K,{id:e.name,type:`number`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value===``?void 0:t.target.valueAsNumber),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):(0,X.jsx)(K,{id:e.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(e.type)?e.type:`text`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder||(t?n(`actionDialog.lookupPlaceholder`,{label:e.label}):void 0),className:a[e.name]?`border-destructive`:``}),a[e.name]&&(0,X.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,X.jsx)(q,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var Uc=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Wc=n((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),Gc=n((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),Kc=n(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),qc=n(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),Jc=n((e=>{var t=Wc().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),Yc=n((e=>{var t=Wc().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Xc=n((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),Zc=n((e=>{var t=Gc(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),Qc=n((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),$c=n((e=>{var t=Qc();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),el=n(((e,t)=>{var n=$c();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),tl=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),nl=n((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
|
|
3
|
-
]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),rl=n((e=>{var t=tl(),n=nl();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),il=n((e=>{var t=Wc(),n=Zc(),r=Gc(),i=rl(),a=tl(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),al=n((e=>{var t=Wc(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),ol=n(((e,t)=>{var n=rl();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),sl=n(((e,t)=>{var n=rl(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),cl=n(((e,t)=>{var n=rl();function r(e){this.mode=n.BYTE,typeof e==`string`?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),ll=n(((e,t)=>{var n=rl(),r=Wc();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
|
|
4
|
-
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),ul=n(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),dl=n((e=>{var t=rl(),n=ol(),r=sl(),i=cl(),a=ll(),o=nl(),s=Wc(),c=ul();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
|
|
5
|
-
Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),fl=n((e=>{var t=Wc(),n=Gc(),r=Kc(),i=qc(),a=Jc(),o=Yc(),s=Xc(),c=Zc(),l=el(),u=il(),d=al(),f=rl(),p=dl();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
|
|
6
|
-
The chosen QR Code version cannot contain this amount of data.
|
|
7
|
-
Minimum version required to store current data is: `+c+`.
|
|
8
|
-
`);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),pl=n((e=>{function t(e){if(typeof e==`number`&&(e=e.toString()),typeof e!=`string`)throw Error(`Color should be defined as hex string`);let t=e.slice().replace(`#`,``).split(``);if(t.length<3||t.length===5||t.length>8)throw Error(`Invalid hex color: `+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),t.length===6&&t.push(`F`,`F`);let n=parseInt(t.join(``),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:`#`+t.slice(0,6).join(``)}}e.getOptions=function(e){e||={},e.color||={};let n=e.margin===void 0||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||`#000000ff`),light:t(e.color.light||`#ffffffff`)},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale},e.getImageWidth=function(t,n){let r=e.getScale(t,n);return Math.floor((t+n.margin*2)*r)},e.qrToImageData=function(t,n,r){let i=n.modules.size,a=n.modules.data,o=e.getScale(i,r),s=Math.floor((i+r.margin*2)*o),c=r.margin*o,l=[r.color.light,r.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=(e*s+n)*4,d=r.color.light;if(e>=c&&n>=c&&e<s-c&&n<s-c){let t=Math.floor((e-c)/o),r=Math.floor((n-c)/o);d=l[+!!a[t*i+r]]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}})),ml=n((e=>{var t=pl();function n(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||={},t.height=n,t.width=n,t.style.height=n+`px`,t.style.width=n+`px`}function r(){try{return document.createElement(`canvas`)}catch{throw Error(`You need to specify a canvas element`)}}e.render=function(e,i,a){let o=a,s=i;o===void 0&&(!i||!i.getContext)&&(o=i,i=void 0),i||(s=r()),o=t.getOptions(o);let c=t.getImageWidth(e.modules.size,o),l=s.getContext(`2d`),u=l.createImageData(c,c);return t.qrToImageData(u.data,e,o),n(l,s,c),l.putImageData(u,0,0),s},e.renderToDataURL=function(t,n,r){let i=r;i===void 0&&(!n||!n.getContext)&&(i=n,n=void 0),i||={};let a=e.render(t,n,i),o=i.type||`image/png`,s=i.rendererOpts||{};return a.toDataURL(o,s.quality)}})),hl=n((e=>{var t=pl();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
|
|
9
|
-
`;return typeof a==`function`&&a(null,p),p}})),gl=n((e=>{var t=Uc(),n=fl(),r=ml(),i=hl();function a(e,r,i,a,o){let s=[].slice.call(arguments,1),c=s.length,l=typeof s[c-1]==`function`;if(!l&&!t())throw Error(`Callback required as last argument`);if(l){if(c<2)throw Error(`Too few arguments provided`);c===2?(o=i,i=r,r=a=void 0):c===3&&(r.getContext&&o===void 0?(o=a,a=void 0):(o=a,a=i,i=r,r=void 0))}else{if(c<1)throw Error(`Too few arguments provided`);return c===1?(i=r,r=a=void 0):c===2&&!r.getContext&&(a=i,i=r,r=void 0),new Promise(function(t,o){try{t(e(n.create(i,a),r,a))}catch(e){o(e)}})}try{let t=n.create(i,a);o(null,e(t,r,a))}catch(e){o(e)}}e.create=n.create,e.toCanvas=a.bind(null,r.render),e.toDataURL=a.bind(null,r.renderToDataURL),e.toString=a.bind(null,function(e,t,n){return i.render(e,n)})}))();function _l(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function vl({state:e,onAcknowledge:t}){let{t:n}=R(),{spec:r,data:i}=e,a=(0,Y.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,X.jsx)(We,{open:e.open,onOpenChange:e=>{},children:(0,X.jsxs)(ot,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,X.jsx)(xt,{children:r.description}):null]}),(0,X.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,X.jsx)(yl,{field:e,value:e.path===``?i:_l(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,X.jsx)(rn,{children:(0,X.jsx)(q,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function yl({field:e,value:t,defaultFormat:n}){let r=e.format??n??`json`,i=e.label,a=r===`qrcode`&&typeof t!=`string`||r===`code-list`&&!Array.isArray(t)||(r===`secret`||r===`text`)&&typeof t!=`string`?`json`:r;return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,X.jsx)(Sl,{value:t}):null,a===`code-list`?(0,X.jsx)(Cl,{value:t}):null,a===`secret`?(0,X.jsx)(wl,{value:t}):null,a===`text`?(0,X.jsx)(Tl,{value:t}):null,a===`json`?(0,X.jsx)(El,{value:t}):null]})}function bl(e){let[t,n]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>n(!1),1500);return()=>clearTimeout(e)},[t]),{copy:async()=>{if(e!=null)try{await navigator.clipboard.writeText(e),n(!0)}catch{}},copied:t}}function xl({value:e,label:t}){let{copy:n,copied:r}=bl(e);return(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,X.jsx)(Ae,{className:`w-4 h-4`}):(0,X.jsx)(Ei,{className:`w-4 h-4`}),t?(0,X.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function Sl({value:e}){let[t,n]=(0,Y.useState)(null);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,X.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,X.jsx)(`canvas`,{ref:t=>{!t||!e||(0,gl.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,X.jsx)(xl,{value:e})]})]})}function Cl({value:e}){let t=e.join(`
|
|
10
|
-
`);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,X.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,X.jsx)(xl,{value:e})]},`${t}-${e}`))})}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(xl,{value:t,label:`Copy all`})})]})}function wl({value:e}){let[t,n]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:t?e:e.replace(/./g,`•`)}),(0,X.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,X.jsx)(qe,{className:`w-4 h-4`}):(0,X.jsx)(En,{className:`w-4 h-4`})}),(0,X.jsx)(xl,{value:e})]})}function Tl({value:e}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,X.jsx)(xl,{value:e})]})}function El({value:e}){let t=(0,Y.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(xl,{value:t})})]})}function Dl(e,t,n,r){if(!(!Array.isArray(e)||e.length===0))return e.map(e=>{let i=typeof e==`string`?{label:e,value:e}:e;return{label:r?r(t,n,i.value,i.label):i.label,value:i.value}})}function Ol(e,t){let n=e.field??e.name,r=e.defaultFromRow&&t.row&&n!=null&&Object.prototype.hasOwnProperty.call(t.row,n)?t.row[n]:void 0;if(!e.field)return{name:e.name??``,label:e.label??e.name??``,type:e.type??`text`,required:e.required??!1,options:e.options,placeholder:e.placeholder,helpText:e.helpText,defaultValue:r??e.defaultValue};let i=e.objectOverride??t.objectName,a=t.objects.find(e=>e?.name===i)?.fields?.[e.field];if(!a)return{name:e.name??e.field,label:e.label??t.fieldLabel(i,e.field,e.field),type:e.type??`text`,required:e.required??!1,options:e.options,placeholder:e.placeholder,helpText:e.helpText,defaultValue:r??e.defaultValue};let o=e.type??a.type??`text`,s=e.options??Dl(a.options,i,e.field,t.fieldOptionLabel),c=e.label??t.fieldLabel(i,e.field,a.label??e.field),l=o===`lookup`||o===`reference`?{referenceTo:a.reference_to??a.reference,displayField:a.display_field??a.reference_field,idField:a.id_field,descriptionField:a.description_field,multiple:a.multiple,titleFormat:a.title_format,lookupColumns:a.lookup_columns,lookupFilters:a.lookup_filters,lookupPageSize:a.lookup_page_size,dependsOn:a.depends_on}:{};return{name:e.name??e.field,label:c,type:o,required:e.required??a.required??!1,options:s,placeholder:e.placeholder??a.placeholder,helpText:e.helpText??a.help??a.description,defaultValue:r??e.defaultValue??a.defaultValue,...l}}function kl(e,t){return Array.isArray(e)?e.map(e=>Ol(e,t)):[]}function Al(){return`${``.replace(/\/$/,``)}/api/v1`}async function jl(e,t){let n=await fetch(`${Al()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=Error(r?.error||`HTTP ${n.status}`);throw e.code=r?.code??`HTTP_${n.status}`,e.status=n.status,e}return r}function Ml(e,t,n){let[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(!0),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)([]),d=(0,Y.useRef)(!1),f=(0,Y.useCallback)(async()=>{if(!(!e||!t)&&!d.current){i(!0);try{let[n,r]=await Promise.all([jl(`/approvals/processes?object=${encodeURIComponent(e)}&activeOnly=true`),jl(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`)]);c(n?.data??[]),u(r?.data??[]),o(!0)}catch(e){e?.status===404&&(d.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,Y.useEffect)(()=>{if(!e||!t){c([]),u([]);return}f()},[e,t,f]);let p=(0,Y.useMemo)(()=>l.find(e=>e.status===`pending`)??null,[l]);return{loading:r,available:a,processes:s,pendingRequest:p,latestRequest:(0,Y.useMemo)(()=>l.length===0?null:[...l].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[l]),canSubmit:a&&s.length>0&&!p,canRecall:!!p&&!!n&&p.submitter_id===n,submit:(0,Y.useCallback)(async n=>{if(!e||!t)throw Error(`Missing object or record`);let r=n?.processName??(s.length===1?s[0].name:void 0),i=await jl(`/approvals/requests`,{method:`POST`,body:JSON.stringify({object:e,recordId:t,...r?{processName:r}:{},...n?.comment?{comment:n.comment}:{}})});return await f(),i},[e,t,s,f]),recall:(0,Y.useCallback)(async e=>{if(!p)throw Error(`No pending request`);let t=await jl(`/approvals/requests/${encodeURIComponent(p.id)}/recall`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...e?.comment?{comment:e.comment}:{}})});return await f(),t.request},[p,n,f]),refresh:f}}var Nl=t({RecordDetailView:()=>Bl}),Pl={id:`current-user`,name:`Demo User`},Fl=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Il=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),Ll=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],Rl=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function zl(e,t){if(Rl.has(t?.type))return!0;let n=e.toLowerCase();return Ll.some(e=>n===e||n.endsWith(`_${e}`))}function Bl({dataSource:e,objects:t,onEdit:n,objectNameOverride:i,recordIdOverride:o,embedded:s}){let c=a(),l=c.appName,d=i??c.objectName,f=o??c.recordId,{showDebug:p}=Dc(),{user:m}=C(),h=v(),g=u().state?.from,{t:_}=R(),{objectLabel:y,viewLabel:b,sectionLabel:S,actionLabel:w,actionConfirm:T,actionSuccess:E,fieldLabel:D,fieldOptionLabel:O}=ti(),{isFavorite:k,toggleFavorite:A,refreshLabel:j}=Ho(),{addRecentItem:ee}=Do(),[te,ne]=(0,Y.useState)(!0),[N,P]=(0,Y.useState)([]),[F,I]=(0,Y.useState)([]),[L,ie]=(0,Y.useState)(0),[oe,le]=(0,Y.useState)({}),[ue,de]=(0,Y.useState)(null),[fe,z]=(0,Y.useState)(!1),[he,B]=(0,Y.useState)(),V=t.find(e=>e.name===d);jo(s?void 0:he);let H=f,ge=ws(d,H),_e=(0,Y.useMemo)(()=>!d||!H?null:{id:`record:${d}:${H}`,label:he||H||``,href:`/apps/${l}/${d}/record/${H}`,type:`record`},[l,d,H,he]),ve=_e?k(_e.id):!1,U=(0,Y.useCallback)(()=>{_e&&A(_e)},[_e,A]),{page:ye,slots:be}=me(d),xe=(0,Y.useMemo)(()=>{if(typeof window<`u`)try{let e=new URLSearchParams(window.location.search).get(`renderViaSchema`);if(e===`0`||e===`false`)return!1;if(e===`1`||e===`true`)return!0}catch{}return V?.detail?.renderViaSchema!==!1},[V]),Se=(0,Y.useMemo)(()=>ye||!V||!xe&&!be?null:_a(V,be?{slots:be}:void 0),[xe,ye,be,V]),Ce=ye||Se,[we,Te]=(0,Y.useState)(null),[Ee,W]=(0,Y.useState)(`idle`);(0,Y.useEffect)(()=>{let t=!1;if(!Ce||!H||!d||!e?.findOne){Te(null),W(`idle`);return}let n=ae(V?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{W(`loading`),(r?e.findOne(d,H,r):e.findOne(d,H)).then(e=>{t||(e&&typeof e==`object`?(Te(e),W(`loaded`)):(Te(null),W(`missing`)))}).catch(()=>{t||(Te(null),W(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==d||String(t.recordId)!==String(H)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[Ce,d,H,e,V]),(0,Y.useEffect)(()=>{if(!we||typeof we!=`object`||!V)return;let e=Bs(V,we);e&&e!==`Untitled`&&e!==he&&B(e)},[we,V,he]),(0,Y.useEffect)(()=>{if(!d||!H||!l||!he)return;let e=`record:${d}:${H}`;ee({id:e,label:he,href:`/apps/${l}/${d}/record/${H}`,type:`record`}),j(e,he)},[l,d,H,he,ee,j]);let[De,Oe]=(0,Y.useState)({open:!1,message:``}),[ke,Ae]=(0,Y.useState)({open:!1,params:[]}),[je,Me]=(0,Y.useState)({open:!1}),Ne=(0,Y.useCallback)((e,t)=>new Promise(n=>{Me({open:!0,spec:e,data:t,resolve:n})}),[]),Pe=(0,Y.useCallback)((e,t)=>new Promise(n=>{Oe({open:!0,message:e,options:t,resolve:n})}),[]),Fe=(0,Y.useCallback)(e=>new Promise(n=>{Ae({open:!0,params:kl(e,{objectName:d||V?.name||``,objects:t||[],fieldLabel:D,fieldOptionLabel:O}),resolve:n})}),[d,V,t,D,O]),Ie=(0,Y.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),Le=(0,Y.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):h(e)},[h]),Re=(0,Y.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(d,H,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(d,H,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(d,H,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(d,H,r);break}let i=t.refreshAfter===!0;return i&&ie(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,d,H]),ze=(0,Y.useMemo)(()=>x(),[]),Be=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=await ze(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:H,objectName:d,params:e.params??{}})}),r=await n.json().catch(()=>null);if(!n.ok||r&&r.success===!1)return{success:!1,error:r?.error||`Flow "${t}" failed (HTTP ${n.status})`};let i=e.refreshAfter!==!1;return i&&ie(e=>e+1),{success:!0,data:r?.data,reload:i}}catch(e){return{success:!1,error:e.message}}},[ze,H,d]),He=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{},r=null;if(e.opensInNewTab)try{r=window.open(`about:blank`,`_blank`,`noopener,noreferrer`)}catch{r=null}try{let i=e.objectName||d||`global`,a=await ze(`/api/v1/actions/${encodeURIComponent(i)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:H,params:n})}),o=await a.json().catch(()=>null);if(!a.ok||o&&o.success===!1){let e=o?.error||`Action "${t}" failed (HTTP ${a.status})`;if(r)try{r.close()}catch{}return{success:!1,error:e}}let s=e.refreshAfter!==!1;s&&ie(e=>e+1);let c=o?.data;if(c&&typeof c==`object`&&typeof c.redirectUrl==`string`){let e=c.redirectUrl;if(r)try{r.location.href=e}catch{try{r.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`,`noopener,noreferrer`)}catch{t=null}t||(window.location.href=e)}}else if(r)try{r.close()}catch{}return{success:!0,data:c,reload:s}}catch(e){if(r)try{r.close()}catch{}return{success:!1,error:e.message}}},[ze,H,d]),Ue=Ml(d,H,m?.id),We=(0,Y.useRef)(Ue);We.current=Ue;let Ge=(0,Y.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`submit_approval`)await We.current.submit({processName:n.processName,comment:n.comment});else if(t===`recall_approval`)await We.current.recall({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return ie(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Ke=(0,Y.useMemo)(()=>{if(!V||!t)return[];let e=new Set([`created_by`,`updated_by`,`owner_id`]),n=[],r=new Set;for(let i of t)if(i.name!==V.name){for(let[t,a]of Object.entries(i.fields||{}))if(!e.has(t)&&a&&(a.type===`lookup`||a.type===`master_detail`)&&(a.reference_to||a.reference)===V.name){if(r.has(i.name))continue;r.add(i.name),n.push({childObject:i.name,childLabel:i.label||i.name,referenceField:t})}}return n},[V,t]);(0,Y.useEffect)(()=>{if(!e||!H||Ke.length===0)return;let t=!1;return Promise.all(Ke.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:H}}).then(e=>({childObject:t,items:Array.isArray(e)?e:e?.data||[]})).catch(e=>(console.warn(`[RecordDetailView] Failed to fetch related ${t}:`,e),{childObject:t,items:[]})))).then(e=>{if(t)return;let n={};for(let{childObject:t,items:r}of e)n[t]=r;le(n)}),()=>{t=!0}},[e,H,Ke]);let qe=(0,Y.useMemo)(()=>!V||V.name===`sys_audit_log`||V.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[V,t]);(0,Y.useEffect)(()=>{if(!e||!H||!V||!qe){de(null);return}let t=!1;return z(!0),e.find(`sys_audit_log`,{$filter:{record_id:H,object_name:V.name},$orderby:{created_at:`desc`},$top:50,$select:[`id`,`created_at`,`action`,`user_id`,`old_value`,`new_value`]}).then(async n=>{if(t)return;let r=Array.isArray(n)?n:n?.data||[],i=Array.from(new Set(r.map(e=>e?.user_id).filter(e=>typeof e==`string`&&e.length>0))),a=new Map;if(i.length>0)try{let t=await e.find(`sys_user`,{$filter:{id:{$in:i}},$top:i.length,$select:[`id`,`name`,`email`,`image`]}),n=Array.isArray(t)?t:t?.data||[];a=new Map(n.map(e=>[e.id,{name:e.name||e.email||null,image:e.image||null}]))}catch(e){console.warn(`[RecordDetailView] Failed to resolve audit user names:`,e)}let o={};for(let[e,t]of Object.entries(V.fields||{}))t?.label&&(o[e]=t.label);let s=e=>{if(!e)return null;if(typeof e==`object`)return e;if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return null};de(r.map(e=>{let t=e?.user_id?a.get(e.user_id):void 0,n=s(e?.old_value)||{},r=s(e?.new_value)||{},i=new Set([...Object.keys(n),...Object.keys(r)]),c=Array.from(i).filter(e=>JSON.stringify(n[e])!==JSON.stringify(r[e])).map(e=>({field:e,label:o[e]||e,from:n[e],to:r[e]}));return{...e,user_name:t?.name??null,user_avatar:t?.image??null,changes:c.length>0?c:void 0}}))}).catch(e=>{t||(console.warn(`[RecordDetailView] Failed to fetch sys_audit_log:`,e),de([]))}).finally(()=>{t||z(!1)}),()=>{t=!0}},[e,H,V,qe]),(0,Y.useEffect)(()=>{if(!e)return;let t=!1,n=m?[{id:String(m.id),label:m.name||m.email||String(m.id),avatarUrl:m.image||void 0}]:[];return(async()=>{try{let r=await e.find(`sys_user`,{$top:50,$select:[`id`,`name`,`email`,`image`]});if(t)return;let i=(Array.isArray(r)?r:r?.data||[]).map(e=>({id:String(e.id),label:e.name||e.email||String(e.id),avatarUrl:e.image||void 0})).filter(e=>e.label),a=new Set(n.map(e=>e.id)),o=[...n,...i.filter(e=>!a.has(e.id))];I(o.length>0?o:n)}catch{if(t)return;I(n)}})(),()=>{t=!0}},[e,m?.id,m?.name,m?.email]);let Je=(0,Y.useMemo)(()=>m?{id:m.id,name:m.name,avatar:m.image}:Pl,[m?.id,m?.name,m?.image]);(0,Y.useEffect)(()=>{if(!e||!d||!H)return;let t=`${d}:${H}`,n=e=>{if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&(t=e);if(t)return Object.entries(t).map(([e,t])=>({emoji:e,count:Array.isArray(t)?t.length:0,reacted:Array.isArray(t)&&t.includes(Je.id)}))};e.find(`sys_comment`,{$filter:{thread_id:t},$orderby:{created_at:`asc`}}).then(e=>{if(!e?.data?.length)return;let t=e.data.map(e=>({id:e.id,type:`comment`,actor:e.author_name??`Unknown`,actorAvatarUrl:e.author_avatar_url??void 0,body:e.body??``,createdAt:e.created_at,updatedAt:e.updated_at,parentId:e.parent_id??void 0,reactions:n(e.reactions)}));P(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{});let r={created:`field_change`,updated:`field_change`,deleted:`field_change`,assigned:`field_change`,shared:`field_change`,system:`system`,completed:`task`,commented:void 0,mentioned:void 0,login:void 0,logout:void 0};e.find(`sys_activity`,{$filter:{object_name:d,record_id:H},$orderby:{timestamp:`asc`},$top:200}).then(e=>{if(!e?.data?.length)return;let t=[];for(let n of e.data){let e=r[n.type];if(!e)continue;let i=n.timestamp;(!i||i===`NOW()`||Number.isNaN(Date.parse(i)))&&(i=n.created_at),t.push({id:n.id,type:e,actor:n.actor_name??`System`,actorAvatarUrl:n.actor_avatar_url??void 0,body:n.summary??``,createdAt:i})}t.length&&P(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{})},[e,d,H,Je]);let Ye=(0,Y.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Je.name,actorAvatarUrl:`avatar`in Je?Je.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(P(e=>[...e,n]),e){let r=`${d}:${H}`,i=ma(t,F);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Je.id,author_name:Je.name,author_avatar_url:`avatar`in Je?Je.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Je,e,d,H,F]),Xe=(0,Y.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Je.name,actorAvatarUrl:`avatar`in Je?Je.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(P(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${d}:${H}`,a=ma(n,F);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Je.id,author_name:Je.name,author_avatar_url:`avatar`in Je?Je.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Je,e,d,H,F]),Ze=(0,Y.useCallback)((t,n)=>{P(r=>r.map(r=>{if(r.id!==t)return r;let i=[...r.reactions??[]],a=i.findIndex(e=>e.emoji===n);if(a>=0){let e=i[a];e.reacted?e.count<=1?i.splice(a,1):i[a]={...e,count:e.count-1,reacted:!1}:i[a]={...e,count:e.count+1,reacted:!0}}else i.push({emoji:n,count:1,reacted:!0});let o={...r,reactions:i};if(e){let n=Je.id,r={};for(let e of i){let t=[];for(e.reacted&&t.push(n);t.length<e.count;)t.push(`__other__`);r[e.emoji]=t}e.update(`sys_comment`,String(t),{reactions:JSON.stringify(r)}).catch(()=>{})}return o}))},[Je.id,e]);(0,Y.useEffect)(()=>{ne(!0),queueMicrotask(()=>ne(!1))},[d,f]);let Qe=(0,Y.useMemo)(()=>{if(!V)return{type:`detail-view`};let n=V.primaryField||Object.keys(V.fields||{}).find(e=>e===`name`||e===`title`),r=V.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?S(V.name,e.name,e.title||e.name):e.title,collapsible:e.collapsible,defaultCollapsed:e.defaultCollapsed,fields:(e.fields||[]).filter(e=>{let t=typeof e==`string`?e:e.name;return!V.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=V.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${V.name} definition`),{name:t,label:t};let r=n.reference_to||n.reference;return{name:t,label:n.label||t,type:n.type||`text`,...n.options&&{options:n.options},...r&&{reference_to:r},...n.reference_field&&{reference_field:n.reference_field},...n.currency&&{currency:n.currency}}})})):(()=>{let e=Object.keys(V.fields||{}).filter(e=>!Fl.has(e)&&!Il.has(e)&&!V.fields[e]?.hidden),t=e=>{let t=V.fields[e],n=t.reference_to||t.reference;return{name:e,label:t.label||e,type:t.type||`text`,...t.options&&{options:t.options},...n&&{reference_to:n},...t.reference_field&&{reference_field:t.reference_field},...t.currency&&{currency:t.currency}}},n=e.filter(e=>!zl(e,V.fields[e])),r=e.filter(e=>zl(e,V.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:e.map(t)}]:[{showBorder:!1,fields:n.map(t)},{name:`details`,title:S(V.name,`details`,_(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(V.actions||[]).filter(t=>t.locations?.includes(`record_header`)?t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0:!1).map(e=>({...e,label:w(V.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:T(V.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(V.name,e.name,e.successMessage)}}));return Ue.available&&Ue.processes.length>0&&(Ue.canSubmit&&t.push({name:`submit_approval`,type:`approval`,target:`submit_approval`,label:_(`approvals.submitForApproval`,{defaultValue:`Submit for Approval`}),icon:`send`,variant:`default`,locations:[`record_header`],refreshAfter:!0,successMessage:_(`approvals.submitSuccess`,{defaultValue:`Approval request submitted`}),...Ue.processes.length===1?{params:{processName:Ue.processes[0].name}}:{collectParams:[{name:`processName`,label:_(`approvals.process`,{defaultValue:`Process`}),type:`select`,required:!0,options:Ue.processes.map(e=>({value:e.name,label:e.label||e.name}))},{name:`comment`,label:_(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0}]}}),Ue.canRecall&&t.push({name:`recall_approval`,type:`approval`,target:`recall_approval`,label:_(`approvals.recall`,{defaultValue:`Recall`}),icon:`undo`,variant:`outline`,locations:[`record_header`],refreshAfter:!0,confirmText:_(`approvals.recallConfirm`,{defaultValue:`Recall this pending approval request?`}),successMessage:_(`approvals.recallSuccess`,{defaultValue:`Approval recalled`})})),t})(),o=V.views?.detail?.highlightFields??[],c=V.views?.detail?.sectionGroups??V.views?.form?.sectionGroups,u=l?`/apps/${l}`:``,d=Ke.map(({childObject:n,childLabel:r,referenceField:i})=>{let a=t.find(e=>e.name===n),o=H||``,s=a?y({name:a.name,label:a.label||r}):r,c=()=>{let e=new URLSearchParams({[i]:o}).toString();return`${u}/${n}/new${e?`?${e}`:``}`},l=()=>{let e=new URLSearchParams({[`filter[${i}]`]:o}).toString();return`${u}/${n}${e?`?${e}`:``}`},d=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},f=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}`:null},p=u?()=>h(c()):void 0,m=u?()=>h(l()):void 0,g=u?e=>{let t=f(e);t&&h(t)}:void 0,v=u?e=>{let t=d(e);t&&h(t)}:void 0,b=e&&o?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),J.success(_(`detail.deleteSuccess`,{defaultValue:`Deleted`})),le(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){J.error(e?.message||_(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:s,type:`table`,api:n,data:oe[n]||[],referenceField:i,icon:a?.icon,displayField:a?.displayNameField||(Array.isArray(a?.compactLayout)?a.compactLayout[0]:void 0),onNew:p,onViewAll:m,onRowClick:g,onRowEdit:v,onRowDelete:b}}),f=Rc(V);return{type:`detail-view`,objectName:V.name,resourceId:H,showBack:!s,onBack:`history`,showEdit:f.edit,title:V.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...qe&&{history:{entries:ue??[],loading:fe&&ue===null}},...d.length>0&&{related:d},...o.length>0&&{highlightFields:o},...c&&c.length>0&&{sectionGroups:c},...a.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:a}]}}},[V?.name,H,oe,L,l,h,e,_,y,t,qe,ue,fe,Ue.available,Ue.processes,Ue.canSubmit,Ue.canRecall,Ue.pendingRequest,Ue.latestRequest,s]);if(te)return(0,X.jsx)(Ic,{});if(!V)return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Xt,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:_(`empty.objectNotFound`)}),(0,X.jsx)(rt,{children:_(`empty.objectNotFoundDescription`,{name:d})})]})});if(Ce&&Ee===`missing`)return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Xt,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:_(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,X.jsx)(rt,{children:_(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(Ce){let t=Ce?.disableDiscussion===!0,i=Bc(Ce),a=!t&&!i,o=(()=>{let e=Qe.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),c=(()=>{let t=Rc(V),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:_(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:H,objectName:d}}))}}),r.push({name:`sys_edit`,label:_(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:H})})),r.push({name:`sys_share`,label:_(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:async()=>{try{if(navigator.share){await navigator.share({title:document.title,url:window.location.href});return}}catch{return}try{await navigator.clipboard.writeText(window.location.href),J.success(_(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){J.error(_(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:_(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=_(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(d,H),J.success(_(`detail.deleted`,{defaultValue:`Record deleted`})),h(`${l?`/apps/${l}`:``}/${d}`,{replace:!0})}catch(e){J.error(e?.message||`Delete failed`)}}}),r})(),u=o.length>0?o:void 0,f=Array.isArray(Qe.related)?Qe.related.filter(e=>e?.api&&e?.referenceField).map(e=>({title:e.title,objectName:e.api,relationshipField:e.referenceField,...Array.isArray(e.columns)?{columns:e.columns}:{},...typeof e.pageSize==`number`?{limit:e.pageSize}:{},...e.icon?{icon:e.icon}:{}})):void 0,m=Qe.history?{entries:Qe.history.entries??[],loading:!!Qe.history.loading,emptyText:Qe.history.emptyText}:void 0,v=ye?Ce:_a(V,{sections:Qe.sections,highlightFields:Array.isArray(Qe.highlightFields)?Qe.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:u,related:f,history:m,hideReferenceRail:V?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:V?.detail?.hideRelatedTab===!0||void 0,...be?{slots:be}:{}});return(0,X.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,X.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[ge.length>0&&(0,X.jsx)(xs,{users:ge,size:`sm`,maxVisible:3,showStatus:!0}),(0,X.jsx)(Pc,{managedBy:V?.managedBy})]}),(0,X.jsx)(ce,{objectName:d,recordId:H,data:we,objectSchema:V,dataSource:e,embedded:s,headerSystemActions:c,isFavorite:ve,onToggleFavorite:_e?U:void 0,children:(0,X.jsx)(pe,{children:(0,X.jsx)(se,{items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze,mentionSuggestions:F,children:(0,X.jsx)(re,{context:{record:we||{},objectName:d,user:Je},onConfirm:Pe,onToast:Ie,onNavigate:Le,onParamCollection:Fe,onResultDialog:Ne,handlers:{api:Re,flow:Be,script:He,modal:He,approval:Ge},children:(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[g?.pathname&&g?.label&&(0,X.jsxs)(r,{to:g.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,X.jsx)(Ji,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:g.label})]}),(0,X.jsx)(M,{schema:v}),a&&(0,X.jsx)(`div`,{className:`mt-6`,children:(0,X.jsx)(pa,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze,mentionSuggestions:F})})]}),(0,X.jsx)(Ec,{open:p,sections:[{title:`Page Schema`,data:v}]})]})})})})}),(0,X.jsx)(Vc,{state:De,onOpenChange:e=>{e||Oe(e=>({...e,open:!1}))}}),(0,X.jsx)(Hc,{state:ke,onOpenChange:e=>{e||Ae(e=>({...e,open:!1}))}}),(0,X.jsx)(vl,{state:je,onAcknowledge:()=>{je.resolve?.(),Me({open:!1})}})]})}return(0,X.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,X.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[ge.length>0&&(0,X.jsx)(xs,{users:ge,size:`sm`,maxVisible:3,showStatus:!0}),(0,X.jsx)(Pc,{managedBy:V?.managedBy})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,X.jsx)(re,{context:{record:{},objectName:d,user:Je},onConfirm:Pe,onToast:Ie,onNavigate:Le,onParamCollection:Fe,onResultDialog:Ne,handlers:{api:Re,flow:Be,script:He,modal:He,approval:Ge},children:(0,X.jsx)(ha,{schema:Qe,dataSource:e,objectLabel:y({name:V.name,label:V.label}),isFavorite:ve,onToggleFavorite:_e?U:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=Bs(V,e);t&&t!==he&&t!==`Untitled`&&B(t)},onEdit:()=>{n({id:H})},discussionSlot:(0,X.jsx)(pa,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze})},L)})}),(0,X.jsx)(Ec,{open:p,sections:[{title:`View Schema`,data:Qe}]})]}),(0,X.jsx)(Vc,{state:De,onOpenChange:e=>{e||Oe(e=>({...e,open:!1}))}}),(0,X.jsx)(Hc,{state:ke,onOpenChange:e=>{e||Ae(e=>({...e,open:!1}))}}),(0,X.jsx)(vl,{state:je,onAcknowledge:()=>{je.resolve?.(),Me({open:!1})}})]})}function Vl(e){switch(e){case`system`:return{icon:`Lock`,title:`Nothing here yet`,message:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`};case`append-only`:return{icon:`Archive`,title:`No events recorded`,message:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`};case`better-auth`:return{icon:`ShieldAlert`,title:`No identity records`,message:`Identity rows are managed by the authentication provider. Use the dedicated identity workflows (Invite User, Reset Password, …) to create new entries.`};default:return}}var Hl=(0,Y.lazy)(()=>m(()=>import(`./plugin-charts-Mt2y8Sdm.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),Ul=(0,Y.lazy)(()=>m(()=>import(`./plugin-grid-u5JmW5Ui.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Wl={grid:tt,kanban:Fn,calendar:zt,gallery:vr,timeline:be,gantt:Hi,map:mr,chart:Pe},Gl={id:`current-user`,name:`Demo User`};function Kl(e,t){if(!Array.isArray(e))return e;let n=e=>{if(typeof e==`string`)return e===`{current_user_id}`?t??e:e;if(Array.isArray(e))return e.map(n);if(e&&typeof e==`object`){let t={};for(let r of Object.keys(e))t[r]=n(e[r]);return t}return e};return e.map(n)}function ql(e,t,n={}){let r=[`kanban`,`calendar`,`timeline`,`gantt`,`gallery`,`map`,`chart`,`grid`],i={};for(let t of r)e[t]&&typeof e[t]==`object`&&Object.assign(i,e[t]);for(let t of[`bulkActions`,`bulkActionDefs`,`rowActions`,`pagination`,`navigation`,`emptyState`,`exportOptions`,`rowHeight`,`isPinned`,`isDefault`,`visibility`,`sortOrder`,`showSort`])e[t]!==void 0&&(i[t]=e[t]);let a=Array.isArray(e.columns)&&e.columns.length>0?e.columns:n.defaultColumns??[],o=e.type||`grid`,s=e.label||e.name||`Untitled View`;return{name:`${s.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,60)||`view`}_${Date.now().toString(36)}`,label:s,object_name:t,view_type:o,columns_json:JSON.stringify(a),filters_json:e.filter?JSON.stringify(e.filter):null,sort_json:e.sort?JSON.stringify(e.sort):null,config_json:Object.keys(i).length>0?JSON.stringify(i):null,page_size:e.pageSize??25,show_search:e.showSearch!==!1,show_filters:e.showFilters!==!1,managed_by:`user`}}function Jl(e){let t=e=>{if(e!=null){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return}}},n=t(e.columns_json)??e.columns,r=t(e.filters_json)??e.filter,i=t(e.sort_json)??e.sort,a=t(e.config_json)??{};return{...e,...a,type:e.view_type??e.type??`grid`,objectName:e.object_name??e.objectName,columns:n,filter:r,sort:i,showSearch:e.show_search??e.showSearch,showFilters:e.show_filters??e.showFilters,pageSize:e.page_size??e.pageSize}}function Yl({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=v(),{appName:s,objectName:c,viewId:l}=a(),[d,f]=o(),p=u(),{showDebug:m}=Dc(),{t:h}=R(),{objectLabel:g,objectDescription:_,viewLabel:y,viewEmptyState:b,actionLabel:S,actionConfirm:T,actionSuccess:E,fieldLabel:D,fieldOptionLabel:O}=ti(),{isFavorite:k,toggleFavorite:A}=Ho(),[j,te]=(0,Y.useState)(!1),[ne,N]=(0,Y.useState)(`edit`),[P,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(!1),[ie,ae]=(0,Y.useState)(null),oe=(0,Y.useRef)({}),se=(0,Y.useRef)({}),ce=(0,Y.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!c||!t)return;let i=se.current[t]||{};se.current[t]={...i,...r};let a=oe.current[t];a&&clearTimeout(a),oe.current[t]=setTimeout(()=>{let r=se.current[t]||{};delete se.current[t],delete oe.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),le=(0,Y.useCallback)(t=>{if(ae(t),H(e=>e+1),e?.updateViewConfig){let n=c,r=t.id;n&&r?e.updateViewConfig(n,r,t).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing objectName or viewId.`)}else console.warn(`[ViewConfigPanel] dataSource.updateViewConfig is not available. View config saved locally only.`)},[e,c]),ue=(0,Y.useCallback)(async n=>{try{let r;if(e?.create){let i=t?.find?.(e=>e.name===c),a=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),o=[];Array.isArray(i?.compactLayout)&&i.compactLayout.length>0?o=i.compactLayout.filter(e=>i.fields?.[e]):i?.fields&&(o=Object.entries(i.fields).filter(([e,t])=>t&&!t.hidden&&!a.has(e)).map(([e])=>e).slice(0,5));let s=Array.isArray(n.columns)&&n.columns.length>0?n.columns:o,l={...n,columns:s};if(n.type===`kanban`)l.kanban={...l.kanban||{},columns:s};else if(n.type===`gallery`){let e=l.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(l.gallery={...e,visibleFields:s})}if(typeof e?.createView==`function`)r=(await e.createView(c,l))?.name||n?.name;else if(e?.create){let t=ql(l,c,{defaultColumns:o}),n=await e.create(`sys_view`,t);r=n?.id??n?._id}}te(!1),N(`edit`),H(e=>e+1),r&&(l?i(`../${r}`,{relative:`path`}):i(`view/${r}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,c,t,i,l]),[de,fe]=(0,Y.useState)(void 0),{user:pe,activeOrganization:z}=C(),me=pe?.role===`admin`,{can:he}=w(),B=t.find(e=>e.name===c);if(!B)return(0,X.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(tt,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:h(`console.objectView.objectNotFound`)}),(0,X.jsxs)(rt,{children:[h(`console.objectView.objectNotFoundDescription`,{objectName:c}),` `,h(`console.objectView.objectNotFoundHint`)]})]})});let[V,H]=(0,Y.useState)(0),ge=(0,Y.useMemo)(()=>Rc(B),[B]);(0,Y.useEffect)(()=>{r===void 0||r===0||H(e=>e+1)},[r]);let[_e,ve]=(0,Y.useState)(!1),[U,ye]=(0,Y.useState)([]);(0,Y.useEffect)(()=>{let t=!1;if(!c){ye([]);return}if(typeof e?.listViews==`function`)return e.listViews(c).then(e=>{t||ye((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||c})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||ye([])}),()=>{t=!0};if(!e?.find){ye([]);return}return e.find(`sys_view`,{$filter:[`object_name`,`=`,c],$orderby:[{field:`created_at`,order:`asc`}],$top:200}).then(e=>{t||ye((Array.isArray(e)?e:Array.isArray(e?.data)?e.data:Array.isArray(e?.records)?e.records:Array.isArray(e?.value)?e.value:[]).filter(e=>e&&(e.object_name===c||e.objectName===c)).map(Jl))}).catch(e=>{console.error(`[ObjectView] Failed to load sys_view records:`,e),t||ye([])}),()=>{t=!0}},[e,c,V]);let[be,xe]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let t=!1;if(!e||!c){xe({});return}let n=B.listViews||B.list_views||{},r=Object.keys(n),i=B.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){xe({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(c);if(t&&typeof t==`object`){let e={};for(let n of r)t[n]&&(e[n]=t[n]);return e}}catch{}if(typeof e.getView!=`function`)return{};let t=await Promise.all(r.map(async t=>{try{return[t,await e.getView(c,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||xe(e)}),()=>{t=!0}},[e,c,B.listViews,B.list_views,B.list,V]);let Se=(0,Y.useMemo)(()=>{let e=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),t=()=>Array.isArray(B.compactLayout)&&B.compactLayout.length>0?B.compactLayout.filter(e=>B.fields?.[e]):B.fields?Object.entries(B.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=B.listViews||B.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=be[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=B.list;if(i&&typeof i==`object`){let e=i.name||`list`,t=r.findIndex(t=>t.id===e);if(t>=0){let[e]=r.splice(t,1);r.unshift({...e,isDefault:!0})}else{let t=be[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:h(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of U){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},i={};for(let[e,t]of Object.entries(n))t!==void 0&&(i[e]=t);if(a.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...i}}else r.push(i)}let o=new Set([`grid`,`list`,`table`]);for(let e of r)o.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let s=new Map(r.map((e,t)=>[e.id,t])),c=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${B.name}`):null;e&&(c=JSON.parse(e))}catch{}let l=new Map(c.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=l.get(e.id),r=l.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=U.find(t=>(t.id||t._id)===e.id),a=U.find(e=>(e.id||e._id)===t.id),o=i&&typeof i.sortOrder==`number`,c=a&&typeof a.sortOrder==`number`;return o&&c?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:o?-1:c?1:(s.get(e.id)??0)-(s.get(t.id)??0)}),r},[B,U,be,h]),Ce=(0,Y.useMemo)(()=>Se.find(e=>e.isDefault)?.id,[Se]),we=l||d.get(`view`)||Ce||Se[0]?.id,Te=Se.find(e=>e.id===we)||Se[0],Ee=ie&&ie.id===Te?.id?{...Te,...ie}:Te,W=(0,Y.useCallback)((e,t)=>{ae(n=>({...n||{},id:Te?.id,[e]:t}))},[Te?.id]),De=e=>{let t=Se.find(t=>t.id===e);t&&(t.id!==we&&te(!1),l?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Oe=(0,Y.useMemo)(()=>(Se||[]).map(e=>{let t=Wl[e.type];return{id:e.id,label:y(B.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,X.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Se,B.name,y]);Ks({views:Oe,activeViewId:we??``,onChange:De,enabled:Oe.length>0&&!!we});let ke=(0,Y.useCallback)(()=>{F(!0)},[]),Ae=(0,Y.useCallback)((e,t)=>{if(e===`settings`){let e=Se.find(e=>e.type===t);e&&De(e.id),N(`edit`),te(!0)}},[Se,De]),je=(0,Y.useCallback)(e=>U.some(t=>(t.id||t._id)===e),[U]),Me=(0,Y.useCallback)(async(t,n)=>{if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`?await e.updateView(c,t,{label:n}):e?.update&&await e.update(`sys_view`,t,{label:n}),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),J.error(h(`objectViewActions.renameFailed`))}},[e,c,je,h]),[Ne,Pe]=(0,Y.useState)({open:!1,message:``}),[Fe,Ie]=(0,Y.useState)({open:!1,params:[]}),[Le,Re]=(0,Y.useState)({open:!1}),ze=(0,Y.useCallback)((e,t)=>new Promise(n=>{Re({open:!0,spec:e,data:t,resolve:n})}),[]),Be=(0,Y.useCallback)((e,t)=>new Promise(n=>{Pe({open:!0,message:e,options:t,resolve:n})}),[]),He=(0,Y.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;Ie({open:!0,params:kl(e,{objectName:c||B?.name||``,objects:t||[],fieldLabel:D,fieldOptionLabel:O,row:i}),resolve:r})}),[c,B,t,D,O]),Ue=(0,Y.useCallback)(async t=>{if(!e)return;if(!je(t)){J.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Se.find(e=>e.id===t)?.label||t;if(await Be(h(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:h(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:h(`console.objectView.delete`)||`Delete`,cancelText:h(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`?await e.deleteView(c,t):e?.delete&&await e.delete(`sys_view`,t),t===we){let e=Se.find(e=>e.id!==t);e&&i(l?`../${e.id}`:`view/${e.id}`,l?{relative:`path`}:void 0)}H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),J.error(h(`objectViewActions.deleteFailed`))}},[e,je,we,Se,l,i,h,Be]),We=(0,Y.useCallback)(async t=>{if(!e)return;let n=Se.find(e=>e.id===t);if(n)try{let r=`${String(n.name||t).toLowerCase().replace(/[^a-z0-9_]+/g,`_`).replace(/^_+|_+$/g,``)||`view`}_copy_${Date.now().toString(36)}`,{id:a,...o}=n,s={...o,name:r,label:`${n.label||t} (Copy)`,isDefault:!1,isPinned:!1,data:n.data||{provider:`object`,object:c},object:n.object||c},u;if(typeof e?.createView==`function`)u=(await e.createView(c,s))?.name||r;else if(e?.create){let t=ql(s,c),n=await e.create(`sys_view`,t);u=n?.id??n?._id}H(e=>e+1),u&&(l?i(`../${u}`,{relative:`path`}):i(`view/${u}`))}catch(e){console.error(`[ViewTabBar] Failed to duplicate view:`,e),J.error(`Failed to duplicate view`)}},[e,Se,c,i,l]),Ge=(0,Y.useCallback)(async(t,n)=>{if(e){if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`?await e.updateView(c,t,{isPinned:n}):e?.update&&await e.update(`sys_view`,t,{isPinned:n}),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,c,je,h]),Ke=(0,Y.useCallback)(async t=>{if(e){if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to mark a default.`);return}try{let n=typeof e?.updateView==`function`,r=U.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(t=>{let r=t.id||t._id;return n?e.updateView(c,r,{isDefault:!1}):e.update(`sys_view`,r,{isDefault:!1})});r.push(n?e.updateView(c,t,{isDefault:!0}):e.update(`sys_view`,t,{isDefault:!0})),await Promise.all(r),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),J.error(`Failed to set default view`)}}},[e,c,U,je,h]),qe=(0,Y.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${c}`,JSON.stringify(t))}catch{}if(e){let n=typeof e?.updateView==`function`,r=new Set(U.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((t,r)=>n?e.updateView(c,t,{sortOrder:r}):e.update?.(`sys_view`,t,{sortOrder:r})).filter(Boolean);try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}H(e=>e+1)},[e,U,c]),Je=(0,Y.useCallback)(e=>{if(!je(e)){J.error(h(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==we&&De(e),N(`edit`),te(!0)},[we,De,je,h]),Ye=(0,Y.useCallback)(()=>{F(!0)},[]),Xe=pe?{id:pe.id,name:pe.name,avatar:pe.image}:Gl,Ze=(0,Y.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),Qe=fo({objectName:B.name,objectLabel:B.label,dataSource:e,onEdit:n,onRefresh:()=>H(e=>e+1),onConfirm:Be,onToast:Ze}),$e=(0,Y.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):i(e)},[i]),et=(0,Y.useMemo)(()=>x(),[]),nt=(0,Y.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{},i=typeof n==`string`?n:``;if(i.startsWith(`/`)||/^https?:\/\//i.test(i)){let e={...r},n=e._rowRecord;delete e._rowRecord;let a=i;n&&/\{[a-z_][a-z0-9_]*\}/i.test(a)&&(a=a.replace(/\{([a-z_][a-z0-9_]*)\}/gi,(e,t)=>{let r=n[t];return r==null?``:encodeURIComponent(String(r))}));let o=a.startsWith(`http`)?a:`${a}`,s=t.bodyShape&&typeof t.bodyShape==`object`&&t.bodyShape.wrap?t.bodyShape.wrap:void 0,c=s?{[s]:e}:{...e};if(n&&t.recordIdParam){let e=n[t.recordIdField||`id`];e!=null&&(c[t.recordIdParam]=e)}/\/api\/v1\/auth\//.test(a)&&!c.organizationId&&z?.id&&(c.organizationId=z.id),t.bodyExtra&&typeof t.bodyExtra==`object`&&Object.assign(c,t.bodyExtra);let l=(t.method||`POST`).toUpperCase(),u={method:l,headers:{"Content-Type":`application/json`},credentials:`include`};l!==`GET`&&l!==`DELETE`&&(u.body=JSON.stringify(c));let d=await et(o,u);if(!d.ok){let e=`HTTP ${d.status}`;try{let t=await d.json();e=t?.error||t?.message||e}catch{}return{success:!1,error:e}}let f=await d.json().catch(()=>({}));return t.refreshAfter!==!1&&H(e=>e+1),{success:!0,data:f,reload:t.refreshAfter!==!1}}typeof e.execute==`function`?await e.execute(B.name,n,r):r.recordId&&Object.keys(r).length>1&&typeof e.update==`function`&&await e.update(B.name,r.recordId,r);let a=t.refreshAfter!==!1;return a&&H(e=>e+1),{success:!0,reload:a}}catch(e){return{success:!1,error:e.message}}},[e,B.name,et,z]),it=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=e.params||{},r=await et(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,objectName:B.name,params:n})}),i=await r.json().catch(()=>null);if(!r.ok||i&&i.success===!1)return{success:!1,error:i?.error||`Flow "${t}" failed (HTTP ${r.status})`};let a=e.refreshAfter!==!1;return a&&H(e=>e+1),{success:!0,data:i?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[et,B.name]),at=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{};try{let r=e.objectName||B.name||`global`,i=await et(`/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,params:n})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1)return{success:!1,error:a?.error||`Action "${t}" failed (HTTP ${i.status})`};let o=e.refreshAfter!==!1;return o&&H(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[et,B.name]),{lastMessage:ot}=fs({channel:`object:${B.name}`}),{hasConflicts:st,resolveAllConflicts:ct}=_s(B.name?`user-${B.name}`:`current-user`);(0,Y.useEffect)(()=>{ot&&(st&&ct(`remote`),H(e=>e+1))},[ot,st,ct]),(0,Y.useEffect)(()=>{e?.find&&B.name&&e.find(B.name,{limit:0}).then(e=>{typeof e?.total==`number`?fe(e.total):Array.isArray(e?.data)?fe(e.data.length):Array.isArray(e)&&fe(e.length)}).catch(()=>{})},[e,B.name,V]);let lt=(0,Y.useMemo)(()=>Ee?.navigation??B.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Ee?.navigation,B.navigation]),ut=d.get(`recordId`),dt=(0,Y.useMemo)(()=>{let e=[];return d.forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[d.toString()]),ft=(0,Y.useCallback)((e,t)=>{if(t===`new_window`){let t=window.location.pathname.replace(/\/view\/.*$/,``);window.open(`${t}/record/${encodeURIComponent(String(e))}`,`_blank`);return}let n={from:{pathname:p.pathname+(p.search||``),label:y(B.name,Ee?.name??``,Ee?.label??``)||g(B)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,l,p.pathname,p.search,B,Ee?.name,Ee?.label,y,g]),pt=ee({navigation:lt,objectName:B.name,onNavigate:ft}),mt=()=>{pt.close();let e=new URLSearchParams(d);e.delete(`recordId`),f(e)},ht=(0,Y.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){pt.handleClick(e,t);return}if(pt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),f(e);return}}pt.handleClick(e,t)},[pt,d,f]),gt=(0,Y.useCallback)(()=>{let e=pt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(mt(),ft(t))},[pt.selectedRecord,ft]);(0,Y.useEffect)(()=>{ut&&!pt.isOpen?pt.open({id:ut}):!ut&&pt.isOpen&&pt.close()},[ut]);let vt=(0,Y.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=V+(i||0),o=`${c}-${Ee.id}-${a}`,s=Ee;if(s.type===`chart`){let e=s.chart||{};return(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,X.jsx)(Hl,{dataSource:t,schema:{type:`object-chart`,objectName:B.name,chartType:e.chartType,xAxisField:e.xAxisField,yAxisFields:e.yAxisFields,aggregation:e.aggregation,series:e.series,config:e.config,filter:e.filter}})},o)}return(0,X.jsx)(ga,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=Kl(s.filter??e.filter,Xe.id);return dt.length?[...Array.isArray(t)?t:[],...dt]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{ce(s.id,s,{densityMode:e})},onSortChange:e=>{ce(s.id,s,{sort:e})},onFilterChange:e=>{ce(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{ce(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{ce(s.id,s,{columnState:e})},inlineEdit:s.inlineEdit??s.editRecordsInline??e.inlineEdit,appearance:s.showDescription==null?e.appearance:{showDescription:s.showDescription},showSearch:s.showSearch??e.showSearch,showSort:s.showSort??e.showSort,showFilters:s.showFilters??e.showFilters,showHideFields:s.showHideFields??e.showHideFields,showGroup:s.showGroup??e.showGroup,showColor:s.showColor??e.showColor,showDensity:s.showDensity??e.showDensity,allowExport:s.allowExport??e.allowExport,exportOptions:s.allowExport===!1?void 0:s.exportOptions??e.exportOptions,striped:s.striped??e.striped,bordered:s.bordered??e.bordered,color:s.color??e.color,wrapHeaders:s.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:s.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:s.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:s.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:s.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:s.fieldTextColor??e.fieldTextColor,prefixField:s.prefixField??e.prefixField,showDescription:s.showDescription??e.showDescription,navigation:s.navigation??e.navigation,selection:s.selection??e.selection,pagination:s.pagination??e.pagination,searchableFields:s.searchableFields??e.searchableFields,filterableFields:s.filterableFields??e.filterableFields,resizable:s.resizable??e.resizable,rowActions:s.rowActions??e.rowActions,rowActionDefs:Array.isArray(B?.actions)?B.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)):[],bulkActions:s.bulkActions??e.bulkActions,bulkActionDefs:s.bulkActionDefs??e.bulkActionDefs,sharing:s.sharing??e.sharing,addRecord:s.addRecord??e.addRecord,conditionalFormatting:s.conditionalFormatting??e.conditionalFormatting,quickFilters:s.quickFilters??e.quickFilters,userFilters:s.userFilters??e.userFilters,showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,virtualScroll:s.virtualScroll??e.virtualScroll,emptyState:b(B.name,s.name||s.id||``,s.emptyState??e.emptyState??Vl(B?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=Kl([...Array.isArray(s.filter)?s.filter:[],...dt],Xe.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...s.sort?.length?{sort:s.sort}:{},options:{kanban:{groupBy:s.kanban?.groupByField||s.kanban?.groupField||`status`,groupField:s.kanban?.groupByField||s.kanban?.groupField||`status`,titleField:s.kanban?.titleField||B.titleField||`name`,cardFields:s.kanban?.columns},calendar:{startDateField:s.calendar?.startDateField||`due_date`,endDateField:s.calendar?.endDateField,titleField:s.calendar?.titleField||`name`,colorField:s.calendar?.colorField,allDayField:s.calendar?.allDayField,defaultView:s.calendar?.defaultView},timeline:{dateField:s.timeline?.dateField||`due_date`,titleField:s.timeline?.titleField||B.titleField||`name`,descriptionField:s.timeline?.descriptionField},map:{locationField:s.map?.locationField,titleField:s.map?.titleField||B.titleField||`name`,latitudeField:s.map?.latitudeField,longitudeField:s.map?.longitudeField,zoom:s.map?.zoom,center:s.map?.center},gallery:{...s.gallery||{},imageField:s.gallery?.imageField||s.gallery?.coverField||`image`,coverField:s.gallery?.coverField||s.gallery?.imageField,titleField:s.gallery?.titleField||B.titleField||`name`,subtitleField:s.gallery?.subtitleField},gantt:{startDateField:s.gantt?.startDateField||`start_date`,endDateField:s.gantt?.endDateField||`end_date`,titleField:s.gantt?.titleField||`name`,progressField:s.gantt?.progressField,dependenciesField:s.gantt?.dependenciesField,colorField:s.gantt?.colorField},chart:{chartType:s.chart?.chartType,xAxisField:s.chart?.xAxisField,yAxisFields:s.chart?.yAxisFields,aggregation:s.chart?.aggregation,series:s.chart?.series,config:s.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&Qe.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Qe.execute({type:`delete`,confirmText:h(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{ht(e,t)},onSortChange:e=>{ce(s.id,s,{sort:e})},onFilterChange:e=>{ce(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{ce(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{ce(s.id,s,{columnState:e})},dataSource:t},o)},[Ee,B,c,V,pt,Qe,ce,dt]),yt=(0,Y.useMemo)(()=>Se.map(e=>e.id===we&&ie&&ie.id===e.id?{...e,...ie}:e),[Se,we,ie]),bt=(0,Y.useMemo)(()=>({type:`object-view`,objectName:B.name,layout:`page`,showSearch:Ee?.showSearch!==!1,showFilters:Ee?.showFilters!==!1,showSort:Ee?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:me,viewActions:me?[{type:`settings`},{type:`share`},{type:`duplicate`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:p.pathname+(p.search||``),label:y(B.name,Ee?.name??``,Ee?.label??``)||g(B)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[B,n,Ee?.showSearch,Ee?.showFilters,Ee?.showSort,Ee?.name,Ee?.label,i,l,me,p.pathname,p.search,y,g]);return(0,X.jsxs)(re,{context:{objectName:B.name,user:Xe,apiBase:``,activeOrganization:z?{id:z.id,slug:z.slug,name:z.name}:null},onConfirm:Be,onToast:Ze,onNavigate:$e,onParamCollection:He,onResultDialog:ze,handlers:{api:nt,flow:it,script:at,modal:at},children:[(0,X.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(lc,{title:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:g(B)}),(0,X.jsx)(Pc,{managedBy:B?.managedBy})]}),description:B.description?_(B):void 0,icon:(0,X.jsx)(as(B?.icon),{className:`h-4 w-4`}),actions:(0,X.jsxs)(X.Fragment,{children:[c&&(0,X.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>A({id:`object:${c}`,label:g(B),href:`/apps/${s}/${c}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":k(`object:${c}`),"aria-label":k(`object:${c}`)?h(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):h(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${c}`,children:k(`object:${c}`)?(0,X.jsx)(_t,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,X.jsx)(mi,{className:`h-4 w-4`})}),ge.create&&he(B.name,`create`)&&(0,X.jsxs)(q,{size:`sm`,onClick:Qe.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,X.jsx)(fn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),ge.import&&he(B.name,`create`)&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>ve(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:h(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,X.jsx)(Br,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),B.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,X.jsx)(M,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(B.actions||[]).map(e=>({...e,label:S(B.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:T(B.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(B.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),ge.create&&he(B.name,`create`)&&(0,X.jsx)(`button`,{type:`button`,onClick:Qe.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":h(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,X.jsx)(fn,{className:`h-5 w-5`})}),_e&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Ul,{open:_e,onOpenChange:ve,objectName:B.name,objectLabel:g(B),fields:Object.entries(B.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{H(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?J.warning(h(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&J.success(h(`console.objectView.importedToast`,{count:t}))}})}),Se.length>=1&&(()=>{let e=Se.map(e=>{let t=U.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(B.name,e.name||e.id,e.label||e.name||e.id),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?h(`console.objectView.systemViewReadonly`)||`System view defined in code — duplicate to customize.`:void 0}});return(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,X.jsx)(Ma,{views:e,activeViewId:we,onViewChange:De,viewTypeIcons:Wl,config:{reorderable:!1,showAddButton:me,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:me?Ye:void 0,onRenameView:me?Me:void 0,onDeleteView:me?Ue:void 0,onDuplicateView:me?We:void 0,onPinView:me?Ge:void 0,onSetDefaultView:me?Ke:void 0,onConfigView:me?Je:void 0,onManageViews:me?()=>L(!0):void 0}),me&&(0,X.jsx)(Ea,{open:I,onOpenChange:L,views:e,activeViewId:we,viewTypeIcons:Wl,onRename:Me,onDelete:Ue,onDuplicate:We,onSetDefault:Ke,onSetPinned:Ge,onReorder:qe,onAddView:Ye,onConfigView:Je})]})})})(),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[pt.mode===`split`&&pt.isOpen?(0,X.jsx)(At,{...pt,setIsOpen:e=>{e||mt()},title:g(B),onExpand:gt,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${B.name}`,mainContent:(0,X.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,X.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,X.jsx)(ka,{schema:bt,dataSource:e,views:yt,activeViewId:we,onViewChange:De,onEdit:e=>n?.(e),onRowClick:(e,t)=>{ht(e,t)},renderListView:vt,onCreateView:ke,onViewAction:Ae})})}),typeof de==`number`&&(0,X.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:h(`console.objectView.recordCount`,{count:de})})]}),children:r=>{let i=r.id||r._id;return(0,X.jsx)(Bl,{dataSource:e,objects:t,onEdit:n,objectNameOverride:B.name,recordIdOverride:i,embedded:!0})}}):(0,X.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,X.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,X.jsx)(ka,{schema:bt,dataSource:e,views:yt,activeViewId:we,onViewChange:De,onEdit:e=>n?.(e),onRowClick:(e,t)=>{ht(e,t)},renderListView:vt,onCreateView:ke,onViewAction:Ae})})})}),(0,X.jsx)(Ec,{open:m&&me,sections:[{title:`View Configuration`,data:Ee},{title:`Object Definition`,data:B}]}),(0,X.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${j&&me?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,X.jsx)(Oc,{open:j&&me,onClose:()=>{te(!1),N(`edit`)},mode:ne,activeView:Ee,objectDef:B,recordCount:de,onSave:le,onViewUpdate:W,onCreate:ue})}),(0,X.jsx)(Mc,{open:P&&me,onOpenChange:F,existingLabels:Se.map(e=>e.label).filter(Boolean),objectDef:B,onCreate:e=>ue(e)})]}),pt.mode!==`split`&&(0,X.jsx)(At,{...pt,setIsOpen:e=>{e||mt()},title:g(B),onExpand:gt,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${B.name}`,children:r=>{let i=r.id||r._id;return(0,X.jsx)(Bl,{dataSource:e,objects:t,onEdit:n,objectNameOverride:B.name,recordIdOverride:i,embedded:!0})}})]}),(0,X.jsx)(Vc,{state:Ne,onOpenChange:e=>{e||Pe({open:!1,message:``})}}),(0,X.jsx)(Hc,{state:Fe,onOpenChange:e=>{e||Ie({open:!1,params:[]})}}),(0,X.jsx)(vl,{state:Le,onAcknowledge:()=>{Le.resolve?.(),Re({open:!1})}})]})}var Xl=t({RecordFormPage:()=>Zl});function Zl({mode:e}){let{appName:t,objectName:n,recordId:i}=a(),s=v(),[c]=o(),l=he(),{objects:u,loading:d}=F(),{t:f}=R(),{objectLabel:p}=ti(),{user:m,getAuthConfig:h}=C(),[g,_]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let e=!1;return h().then(t=>{e||_(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[h]);let y=(0,Y.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of c.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,c.toString()]),b=(0,Y.useMemo)(()=>u.find(e=>e.name===n),[u,n]),x=`/apps/${t}`,S=`${x}/${n}`,w=e===`edit`&&i?`${x}/${n}/record/${encodeURIComponent(i)}`:S,T=(0,Y.useCallback)(()=>{typeof window<`u`&&window.history.length>1?s(-1):s(w,{replace:!0})},[s,w]),E=b?p(b):n??``,D=e===`create`?f(`form.createTitle`,{object:E,defaultValue:`New ${E}`}):f(`form.editTitle`,{object:E,defaultValue:`Edit ${E}`}),O=(0,Y.useCallback)(()=>{J.success(e===`create`?f(`form.createSuccess`,{object:E,defaultValue:`${E} created successfully`}):f(`form.updateSuccess`,{object:E,defaultValue:`${E} updated successfully`})),T()},[e,f,E,T]),k=(0,Y.useCallback)(()=>{T()},[T]),A=(0,Y.useMemo)(()=>m?{name:m.name,email:m.email,role:m.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[m]),j=(0,Y.useMemo)(()=>new de({user:A,app:{name:t},data:{}}),[A,t]),M=(0,Y.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:uo(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>uo(e.visible,j)).map(([e])=>e):[],[b,j]);return d?(0,X.jsx)(Ic,{}):b?(0,X.jsx)(co,{user:A,app:{name:t},data:{},features:g,children:(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,X.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":f(`common.back`,{defaultValue:`Back`}),children:(0,X.jsx)(dt,{className:`h-4 w-4`})}),(0,X.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(r,{to:S,className:`hover:text-foreground transition-colors`,children:E}),(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:D}),(0,X.jsx)(Pc,{managedBy:b?.managedBy,className:`ml-1`})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,X.jsx)(Sa,{schema:{type:`object-form`,formType:`simple`,objectName:b.name,mode:e,recordId:e===`edit`?i:void 0,...y&&{initialValues:y},title:D,description:e===`create`?f(`form.createDescription`,{object:E,defaultValue:`Create a new ${E}.`}):f(`form.editDescription`,{object:E,defaultValue:`Edit this ${E}.`}),layout:`vertical`,fields:M,onSuccess:O,onCancel:k,showSubmit:!0,showCancel:!0,submitText:f(`form.saveRecord`,{defaultValue:`Save`}),cancelText:f(`common.cancel`,{defaultValue:`Cancel`})},dataSource:l??void 0},`${e}:${n}:${i??`new`}`)})})]})}):(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Xt,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:f(`empty.objectNotFound`)}),(0,X.jsx)(rt,{children:f(`empty.objectNotFoundDescription`,{name:n})}),(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsxs)(q,{variant:`outline`,onClick:()=>s(x),children:[(0,X.jsx)(dt,{className:`mr-2 h-4 w-4`}),f(`empty.back`)]})})]})})}var Ql=t({DashboardView:()=>cu}),$l=[{type:`metric`,label:`KPI Metric`,Icon:Ft},{type:`bar`,label:`Bar Chart`,Icon:Pe},{type:`line`,label:`Line Chart`,Icon:Re},{type:`pie`,label:`Pie Chart`,Icon:pn},{type:`table`,label:`Table`,Icon:vn},{type:`pivot`,label:`Pivot`,Icon:vr}],eu=0;function tu(){return eu+=1,`widget_${Date.now()}_${eu}`}function nu(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:tu()})}}function ru(e){let t=$l.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var iu=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function au(e){let t=e.options??{},n=t.drillDown??{};return{...t,title:e.title??``,description:e.description??``,type:e.type??`metric`,object:e.object??``,categoryField:e.categoryField??t.categoryField??``,valueField:e.valueField??t.valueField??``,aggregate:e.aggregate??t.aggregate??`count`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1,colorVariant:e.colorVariant??t.colorVariant??`default`,actionUrl:e.actionUrl??t.actionUrl??``,searchable:e.searchable??t.searchable??!1,pagination:e.pagination??t.pagination??!1,drillDownEnabled:n.enabled??!1,drillDownTarget:n.target??`drawer`}}function ou(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))iu.has(t)||n!==void 0&&(r[t]=n);let i=e.drillDownEnabled,a=e.drillDownTarget;return(i!==void 0||a!==void 0)&&(r.drillDown={...n.drillDown||{},...i===void 0?{}:{enabled:!!i},...a===void 0?{}:{target:a}}),{title:e.title,description:e.description,type:e.type,object:e.object,categoryField:e.categoryField,valueField:e.valueField,aggregate:e.aggregate,layout:{...t.layout||{},w:e.layoutW,h:e.layoutH},colorVariant:e.colorVariant,actionUrl:e.actionUrl,...e.searchable===void 0?{}:{searchable:!!e.searchable},...e.pagination===void 0?{}:{pagination:!!e.pagination},...Object.keys(r).length>0?{options:r}:{}}}function su(e){let t=e??{};return{columns:t.columns??3,gap:t.gap??4,rowHeight:String(t.rowHeight??`120`),refreshInterval:String(t.refreshInterval??`0`),title:t.title??``,description:t.description??``,showDescription:t.showDescription??!0,theme:t.theme??`auto`}}function cu({dataSource:e}){let{dashboardName:t}=a(),{showDebug:n}=Dc(),r=he(),{t:i}=R(),{dashboardLabel:o,dashboardDescription:s}=ti(),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(0),[g,_]=(0,Y.useState)(null),v=(0,Y.useCallback)(e=>{_(t=>(t&&t.resolve(e),null))},[]),y=(0,Y.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;_({schema:n,resolve:t})}),[]),b=(0,Y.useMemo)(()=>({export_dashboard_pdf:async()=>{J.info(i(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return J.error(i(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(J.info(i(`dashboardActions.forecastSoon`)),{success:!0})}),[i]);(0,Y.useEffect)(()=>{l(!0),E(null),d(!1),p(null),queueMicrotask(()=>l(!1))},[t]);let{dashboards:x,objects:S,refresh:C}=F(),w=x?.find(e=>e.name===t),[T,E]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{u||E(null)},[w]);let D=(0,Y.useCallback)(async e=>{try{r&&r.updateDashboard?await r.updateDashboard(t,e):r&&await r.update(`sys_dashboard`,t,e),C().catch(()=>{})}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`[DashboardView] Auto-save failed:`,e),J.error(`Failed to save dashboard: ${t}`)}},[r,t,C]),O=(0,Y.useCallback)(()=>{E(nu(w)),d(!0),h(e=>e+1)},[w]),k=(0,Y.useCallback)(()=>{d(!1),p(null)},[]),A=(0,Y.useCallback)(e=>{if(!T)return;let t=tu(),n={id:t,title:ru(e),type:e,layout:{x:0,y:T.widgets?.length??0,w:T.columns??2,h:1}},r={...T,widgets:[...T.widgets||[],n]};E(r),D(r),p(t),h(e=>e+1)},[T,D]),j=(0,Y.useCallback)(e=>{if(!T)return;let t={...T,widgets:T.widgets.filter(t=>t.id!==e)};E(t),D(t),f===e&&p(null)},[T,f,D]),M=(0,Y.useCallback)(e=>{let t=T||w;if(!t)return;let n={...t,widgets:e};E(n),D(n)},[T,w,D]),ee=(0,Y.useMemo)(()=>su(T||w),[m]),te=(0,Y.useCallback)(e=>{if(!T)return;let t=(e,t)=>{let n=Number(e);return Number.isFinite(n)?n:t},n={...T,columns:t(e.columns,T.columns),gap:t(e.gap,T.gap),rowHeight:t(e.rowHeight,T.rowHeight),refreshInterval:t(e.refreshInterval,0)??0,title:e.title,description:e.description,showDescription:e.showDescription,theme:e.theme};E(n),D(n),h(e=>e+1)},[T,D]),ne=(0,Y.useCallback)((e,t)=>{T&&E(n=>{if(!n)return n;if(new Set([`columns`,`gap`,`rowHeight`,`refreshInterval`]).has(e)){let r=Number(t);return{...n,[e]:Number.isFinite(r)?r:n[e]}}return{...n,[e]:t}})},[T]),N=T?.widgets?.find(e=>e.id===f),P=(0,Y.useMemo)(()=>N?au(N):{},[f,m]),re=(0,Y.useCallback)(e=>{if(!T||!f||!N)return;let t=ou(e,N),n={...T,widgets:T.widgets.map(e=>e.id===f?{...e,...t}:e)};E(n),D(n),h(e=>e+1)},[T,f,N,D]),I=(0,Y.useCallback)((e,t)=>{f&&E(n=>{if(!n)return n;let r=n.widgets?.find(e=>e.id===f);if(!r)return n;let i=au(r);i[e]=t;let a=ou(i,r);return{...n,widgets:n.widgets.map(e=>e.id===f?{...e,...a}:e)}})},[f]),L=(0,Y.useMemo)(()=>{if(S?.length)return S.map(e=>({value:e.name,label:e.label||e.name}))},[S]),ie=(0,Y.useMemo)(()=>{let e=N?.object;if(!e||!S?.length)return;let t=S.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.filter(e=>e.name).map(e=>({value:e.name,label:e.label||e.name})):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e}))},[N?.object,S]),ae=(0,Y.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),oe=T||w,se=(0,Y.useMemo)(()=>{if(!oe||ae.size===0)return oe;let e=oe.widgets;if(!Array.isArray(e)||e.length===0)return oe;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?ae.has(t):!0});return t.length===e.length?oe:{...oe,widgets:t}},[oe,ae]);return c?(0,X.jsx)(Fc,{}):w?(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=Fs((se||w).title,i),t=Fs(w.label,i),n=o({name:w.name,label:t});return(0,X.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||w.name})})(),(()=>{let e=(se||w).description??w.description,t=s({name:w.name,description:Fs(e,i)});return t?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,X.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[u&&(0,X.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:$l.map(({type:e,label:t,Icon:n})=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>A(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),(0,X.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,X.jsxs)(`button`,{type:`button`,onClick:O,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,X.jsx)(Ir,{className:`h-3.5 w-3.5`}),i(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,X.jsx)(La,{schema:se,dataSource:e,designMode:u,selectedWidgetId:f,onWidgetClick:p,onWidgetsReorder:M,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),N?(0,X.jsx)(Ra,{open:u,onClose:k,config:P,onSave:re,onFieldChange:I,availableObjects:L,availableFields:ie,headerExtra:(0,X.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>j(f),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"data-testid":`widget-delete-button`,title:`Delete widget`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})},f):(0,X.jsx)(za,{open:u,onClose:k,config:ee,onSave:te,onFieldChange:ne}),(0,X.jsx)(Ec,{open:n,sections:[{title:`Dashboard Configuration`,data:se}]})]}),g&&g.schema?.objectName?(0,X.jsx)(ba,{schema:{type:`object-form`,formType:`modal`,objectName:g.schema.objectName,mode:g.schema.mode||`create`,recordId:g.schema.recordId,title:g.schema.title,description:g.schema.description,fields:g.schema.fields,open:!0,onOpenChange:e=>{e||v({success:!1})},onSuccess:e=>{v({success:!0,reload:!0,data:e})},onCancel:()=>{v({success:!1})},showSubmit:!0,showCancel:!0},dataSource:r}):g?(0,X.jsx)(We,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,X.jsxs)(ot,{children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,X.jsx)(xt,{children:g.schema.description})]}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:()=>v({success:!1}),children:i(`actionDialog.cancel`)}),(0,X.jsx)(q,{onClick:()=>v({success:!0}),children:i(`actionDialog.ok`)})]})]})}):null]}):(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(ci,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:i(`empty.dashboardNotFound`)}),(0,X.jsx)(rt,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var lu=t({PageView:()=>uu});function uu(){let{t:e}=R(),{pageName:t}=a(),[n]=o(),{showDebug:r}=Dc(),{pages:i}=F(),s=i?.find(e=>e.name===t);if(!s)return(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(na,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:e(`empty.pageNotFound`)}),(0,X.jsx)(rt,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let c=Object.fromEntries(n.entries());return(0,X.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:(0,X.jsx)(M,{schema:{...s,type:s.type||`page`,context:{...s.context,params:c}}})}),(0,X.jsx)(Ec,{open:r,sections:[{title:`Page Configuration`,data:s}]})]})}var du=t({ReportView:()=>gu}),fu=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),pu=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),mu=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),hu=[{value:`month`,label:`Month`,type:`text`},{value:`revenue`,label:`Revenue`,type:`number`},{value:`count`,label:`Count`,type:`number`},{value:`region`,label:`Region`,type:`text`},{value:`product`,label:`Product`,type:`text`},{value:`source`,label:`Lead Source`,type:`text`},{value:`stage`,label:`Stage`,type:`text`},{value:`amount`,label:`Amount`,type:`number`}];function gu({dataSource:e}){let{t}=R(),{reportName:n}=a(),{showDebug:r}=Dc(),i=he(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(0),{reports:u,objects:d,loading:f,refresh:p}=F(),m=u?.find(e=>e.name===n),[h,g]=(0,Y.useState)(m),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),C=(0,Y.useCallback)(e=>{if(!e||!d?.length)return;let t=d.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.map(e=>typeof e==`string`?{value:e,label:e,type:`text`}:{value:e.name,label:e.label||e.name,type:e.type||`text`}):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))},[d]),w=(0,Y.useMemo)(()=>{let e=_||h;return C(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??hu},[_,h,C]),T=(0,Y.useCallback)(async e=>{try{i&&(await i.update(`sys_report`,n,e),p().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,n,p]),E=(0,Y.useCallback)(()=>{v(h),s(!0),l(e=>e+1)},[h]),D=(0,Y.useCallback)(()=>{s(!1)},[]),O=(0,Y.useMemo)(()=>_||h,[c]),k=(0,Y.useCallback)(e=>{v(e),T(e),l(e=>e+1)},[T]),A=(0,Y.useCallback)((e,t)=>{v(n=>({...n,[e]:t}))},[]);(0,Y.useEffect)(()=>{g(m)},[m]),(0,Y.useEffect)(()=>{o||v(null)},[m]);let j=_||h,M=(0,Y.useMemo)(()=>JSON.stringify(j?.filters),[j?.filters]),ee=(0,Y.useMemo)(()=>JSON.stringify(j?.dataSource),[j?.dataSource]),te=(0,Y.useMemo)(()=>JSON.stringify(j?.data),[j?.data]);if((0,Y.useEffect)(()=>{if(!j||!e){b([]);return}if(j.data&&Array.isArray(j.data)){b(j.data);return}if(j.dataSource){(async()=>{S(!0);try{let t=j.dataSource.object||j.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),b([]);return}b((await e.find(t,{$filter:j.dataSource.filter,$orderby:j.dataSource.sort,$top:j.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),b([])}finally{S(!1)}})();return}if(j.objectName){(async()=>{S(!0);try{b((await e.find(j.objectName,{$filter:j.filters,$orderby:j.sort,$top:j.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),b([])}finally{S(!1)}})();return}b([])},[j?.objectName,j?.limit,M,ee,te,e]),f)return(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsx)(jr,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!m||!h)return!f&&!m?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Pe,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(ta,{children:t(`empty.reportNotFound`)}),(0,X.jsx)(rt,{children:t(`empty.reportNotFoundDescription`,{name:n})})]})}):(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsx)(jr,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let ne=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?d?.find(e=>e.name===n):null,i=Array.isArray(r?.fields)?r.fields:r?.fields?Object.entries(r.fields).map(([e,t])=>({name:e,...t})):[],a={};for(let e of i)e&&e.name&&(a[e.name]=e);let o=e=>{let t=e.name||e.field,n=t?a[t]:void 0;if(!n)return e;let r={...e};if(r.type===void 0&&n.type!==void 0&&(r.type=n.type),r.options===void 0&&Array.isArray(n.options)&&(r.options=n.options),r.referenceTo===void 0){let e=n.referenceTo||n.reference?.to||n.target;e&&(r.referenceTo=e)}return r.label===void 0&&n.label&&(r.label=n.label),r};if(!t.fields&&Array.isArray(t.columns)?t.fields=t.columns.map(e=>{let t=o(e);return{name:t.field||t.name,label:t.label,type:t.type,options:t.options,referenceTo:t.referenceTo,format:t.format,renderAs:t.renderAs,colorMap:t.colorMap,...t.aggregate?{aggregation:t.aggregate,showInSummary:!0}:{}}}):Array.isArray(t.fields)&&(t.fields=t.fields.map(o)),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.type||t.reportType||`tabular`,i=[];(r===`summary`||n)&&i.push({type:`summary`,title:`Key Metrics`}),i.push({type:`table`,title:`Details`,columns:t.fields.map(e=>({name:e.name,label:e.label,type:e.type,options:e.options,referenceTo:e.referenceTo,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))});let a=t.chart||t.chartConfig,o=a?.type||a?.chartType;if(o){let e=a.xAxis||a.xAxisField,t=a.yAxis||a.yAxisFields?.[0];i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:o,xAxisField:e,yAxisFields:t?[t]:a.yAxisFields}})}if(Array.isArray(e.sections)){let t=e.sections.filter(e=>e.type===`chart`&&!o);i.push(...t)}t.sections=i}else t.sections||=[];return t},N=_||h,P=!!(N&&N.objectName&&(N.type===`matrix`||N.type===`joined`||N.type===`summary`||N.type===`tabular`||N.type===void 0||Array.isArray(N.groupingsAcross)&&N.groupingsAcross.length>0||Array.isArray(N.columns))),re={type:`report-viewer`,report:ne(N),data:y,showToolbar:!0,allowExport:!0,loading:x};return(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:N.title||N.label||`Report Viewer`}),N.description&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:N.description})]}),(0,X.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:E,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`report-edit-button`,children:[(0,X.jsx)(Ir,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,X.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:P?(0,X.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,X.jsx)(pu,{schema:N,dataSource:e})}):(0,X.jsx)(fu,{schema:re})})})}),(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(mu,{open:o,onClose:D,config:O,onSave:k,onFieldChange:A,availableFields:w,getFieldsForObject:C})}),(0,X.jsx)(Ec,{open:r,sections:[{title:`Report Configuration`,data:N}]})]})]})}var _u=t({SearchResultsPage:()=>xu});function vu(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...vu(n.children)):t.push(n);return t}var yu={object:Xt,dashboard:ci,page:na,report:Pe},bu={object:`bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200`,dashboard:`bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200`,page:`bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200`,report:`bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200`};function xu(){let{t:e}=R(),{appName:t}=a(),[n,i]=o(),[s,c]=(0,Y.useState)(n.get(`q`)||``),{apps:l}=F(),u=l||[],d=u.find(e=>e.name===t)||u[0],f=`/apps/${t}`,{user:p}=C(),m=(0,Y.useMemo)(()=>{if(!d)return[];let e=vu(d.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=ua(e,f,t);return{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:n,type:e.type,description:e.description}}).filter(e=>e.href!==`#`)},[d,f,p?.id]),h=(0,Y.useMemo)(()=>{if(!s.trim())return m;let e=s.toLowerCase();return m.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[m,s]),g=e=>{c(e),i(e?{q:e}:{})},_=(0,Y.useMemo)(()=>{let e={};for(let t of h)(e[t.type]||=[]).push(t);return e},[h]);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(r,{to:f,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,X.jsx)(dt,{className:`h-4 w-4`}),e(`search.back`)]}),(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`search.title`)})]}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:e(`search.placeholder`)}),(0,X.jsx)(Ai,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsx)(K,{id:`search-results-input`,value:s,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s.trim()?e(h.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:h.length,query:s}):e(`search.itemsAvailable`,{count:m.length})}),h.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,X.jsx)(Ai,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,X.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:e(`search.noResults`)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:e(`search.noResultsHint`)})]}):(0,X.jsx)(`div`,{className:`space-y-6`,children:Object.entries(_).map(([t,n])=>{let i=yu[t]||Xt,a=`search.type${t.charAt(0).toUpperCase()}${t.slice(1)}s`;return`${t.charAt(0).toUpperCase()}${t.slice(1)}`,(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,X.jsx)(i,{className:`h-4 w-4`}),e(a),(0,X.jsx)(G,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,X.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=yu[t.type]||Xt,i=`search.badge${t.type.charAt(0).toUpperCase()}${t.type.slice(1)}`;return(0,X.jsx)(r,{to:t.href,className:`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:(0,X.jsx)(ht,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,X.jsxs)(pi,{className:`flex items-center gap-3 p-3`,children:[(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${bu[t.type]||``}`,children:(0,X.jsx)(n,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium truncate`,children:t.label}),t.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:t.description})]}),(0,X.jsx)(G,{variant:`outline`,className:`text-xs shrink-0`,children:e(i)})]})})},t.id)})})]},t)})})]})}function Su(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function Cu(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var wu=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=Su(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(Cu)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function Tu(){let e=he();return(0,Y.useMemo)(()=>e?new wu(e):null,[e])}var Eu=0;function Du(e=`nav`){return`${e}_${Date.now()}_${++Eu}`}function Ou(e,t){return[...e,t]}function ku(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:ku(e.children,t,n)}:e)}function Au(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:Au(i.children,t,n,r)}:i})}function ju(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Mu(){let e=he(),{apps:t,refresh:n}=F(),{t:r}=R(),i=(0,Y.useRef)(e);i.current=e;let a=(0,Y.useRef)(n);a.current=n;let o=(0,Y.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,Y.useCallback)(e=>t.find(t=>t.name===e),[t]),c=(0,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Ou(a,{id:Du(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Ou(a,{id:Du(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,Y.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=ku(i,`page`,t);if(ju(a,i))return;let c={...n,navigation:a};try{await o(e,c),J.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,Y.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=ku(i,`dashboard`,t);if(ju(a,i))return;let c={...n,navigation:a};try{await o(e,c),J.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Au(a,`page`,t,n);if(ju(c,a))return;let l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Au(a,`dashboard`,t,n);if(ju(c,a))return;let l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Y.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Y.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await p(t,e,n)}},[t,p])}}function Nu(){let{pages:e,dashboards:t,apps:n}=F(),r=he(),i=(0,Y.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=Mu(),l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),d=(0,Y.useRef)(0),f=(0,Y.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Y.useEffect)(()=>{if(f.current)return;let r=new Set((e??[]).map(e=>e.name).filter(Boolean)),i=new Set((t??[]).map(e=>e.name).filter(Boolean)),m=l.current,h=u.current;if(m===null||h===null){l.current=r,u.current=i;return}let g=[...r].filter(e=>!m.has(e)),_=[...m].filter(e=>!r.has(e)),v=[...i].filter(e=>!h.has(e)),y=[...h].filter(e=>!i.has(e));if(g.length===0&&_.length===0&&v.length===0&&y.length===0){l.current=r,u.current=i;return}let b=++d.current;f.current=!0;let x=!1;return(async()=>{try{for(let e of n){if(x||d.current!==b)break;let t=p(e);if(t){for(let e of g){if(x)break;await a(t,e)}for(let e of _){if(x)break;await s(t,e)}for(let e of v){if(x)break;await o(t,e)}for(let e of y){if(x)break;await c(t,e)}}}}finally{d.current===b&&(l.current=r,u.current=i,f.current=!1)}})(),()=>{x=!0}},[e,t,n,a,o,s,c]),null}var Pu=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Fu(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Iu({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=Do(),o=(0,Y.useRef)(n);o.current=n,(0,Y.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s&&!Pu.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:Fu(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Fu(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Fu(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Lu=`objectstack:ai-chat-conversation-id`;function Ru(e,t){return t?`${Lu}:${e}:${t}`:`${Lu}:${e}`}function zu(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Bu(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function Vu(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``):``}function Hu(e){if(!e)return[];let t=[];return e.forEach((e,n)=>{let r=e.role;if(r!==`user`&&r!==`assistant`&&r!==`system`)return;let i=Vu(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function Uu(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function Wu(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function Gu(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Ku(e){let{userId:t,scope:n,apiBase:r,activeId:i}=e,[a,o]=(0,Y.useState)(void 0),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(!!t),d=(0,Y.useRef)(!0),f=(0,Y.useRef)(void 0);return(0,Y.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]),(0,Y.useEffect)(()=>{if(!t){o(void 0),c([]),u(!1),f.current=void 0;return}if(!i&&f.current===t&&a)return;let e=!1,s=Ru(t,n);return u(!0),(async()=>{try{if(i){let n=await Uu(r,i);if(e)return;if(n){Bu(s,n.id),o(n.id),c(Hu(n.messages)),f.current=t;return}Bu(s,void 0)}else{let n=zu(s);if(n){let i=await Uu(r,n);if(e)return;if(i){o(i.id),c(Hu(i.messages)),f.current=t;return}Bu(s,void 0)}}let n=await Wu(r);if(e)return;Bu(s,n.id),o(n.id),c(Hu(n.messages)),f.current=t}catch{e||(o(void 0),c([]))}finally{e||u(!1)}})(),()=>{e=!0}},[t,n,r,i]),{conversationId:a,initialMessages:s,isLoading:l,reset:(0,Y.useCallback)(async()=>{if(!t)return;let e=Ru(t,n);u(!0);try{a&&await Gu(r,a),Bu(e,void 0);let t=await Wu(r);if(Bu(e,t.id),!d.current)return;o(t.id),c([])}catch{d.current&&(o(void 0),c([]))}finally{d.current&&u(!1)}},[a,t,n,r])}}function qu(e){if(!e||e.length===0)return;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.role===`user`){let e=Ju(n.content);if(e)return e}}let t=e[e.length-1];return Ju(t?.content)}function Ju(e){if(typeof e==`string`)return e.slice(0,140);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function Yu(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:qu(e.messages)}}function Xu(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,Y.useState)([]),[s,c]=(0,Y.useState)(!!t),[l,u]=(0,Y.useState)(void 0),[d,f]=(0,Y.useState)(0),p=(0,Y.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,Y.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,Y.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,Y.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;o(a.map(Yu).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``)))}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}var Zu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Nl).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Qu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Ql).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),$u=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>lu).then(e=>({default:e.PageView})),void 0,import.meta.url)),ed=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>du).then(e=>({default:e.ReportView})),void 0,import.meta.url)),td=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>_u).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),nd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Xl).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),rd=(0,Y.lazy)(()=>m(()=>import(`./ComponentNavView-B2VAx_8W.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),id=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>nv).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),ad=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>nv).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),od=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>nv).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),sd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>nv).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),cd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Ub).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),ld=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Ub).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),ud=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Ub).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),dd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Xd).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),fd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>nf).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),pd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>af).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function md({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,Y.useState)(`disconnected`),{user:o,getAuthConfig:s}=C(),c=he(),[l,d]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let e=!1;return s().then(t=>{e||d(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[s]);let f=v(),m=u(),{appName:h}=a(),{apps:_,objects:y,loading:b,ensureType:x}=F(),{t:S}=R(),{objectLabel:w}=ti(),[T,E]=(0,Y.useState)(!x);(0,Y.useEffect)(()=>{if(!x){E(!0);return}let e=!1;return Promise.all([x(`object`),x(`dashboard`),x(`report`),x(`page`)]).finally(()=>{e||E(!0)}),()=>{e=!0}},[x]);let D=_.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),O=_.find(e=>e.name===h)||D.find(e=>e.isDefault===!0)||D[0],[k,A]=(0,Y.useState)(!1),[M,ee]=(0,Y.useState)(null),[ne,N]=(0,Y.useState)(0),{execute:P,runner:re}=te();j({dataSource:c??void 0,onUndo:e=>{J.info(`Undo: ${e.description}`,{duration:4e3}),N(e=>e+1)},onRedo:e=>{J.info(`Redo: ${e.description}`,{duration:3e3}),N(e=>e+1)}}),(0,Y.useEffect)(()=>{re.registerHandler(`crud_success`,async e=>(A(!1),N(e=>e+1),J.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),re.registerHandler(`dialog_cancel`,async()=>(A(!1),{success:!0})),re.registerHandler(`navigate_create`,async e=>{let t=Ns({action:e,context:re.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(f(t.url),{success:!0}):t}),re.registerHandler(`navigate_edit`,async e=>{let t=Ps({action:e,context:re.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(f(t.url),{success:!0}):t})},[re,f,h]),(0,Y.useEffect)(()=>{if(!c)return;let e=c.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(c.getConnectionState()),e},[c]);let I=m.pathname.split(`/`).filter(Boolean)[2];(I===`view`||I===`record`||I===`page`||I===`dashboard`||I===`design`)&&(I=``);let L=y.find(e=>e.name===I),ie=(0,Y.useCallback)(()=>{let e=L?w(L):S(`common.record`,{defaultValue:`Record`});P({type:`crud_success`,params:{message:M?S(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):S(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[P,M,L,w,S]),ae=(0,Y.useCallback)(()=>{P({type:`dialog_cancel`})},[P]);Iu({pathname:m.pathname,appName:O?.name,objects:y});let oe=e=>{let t=Ms({objectDef:L,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){f(t.url);return}ee(e),A(!0)},se=e=>{f(`/apps/${e}`)},ce=(0,Y.useMemo)(()=>new de({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:O||{},data:M||{}}),[o,O,M]);if(!c||b||!T)return(0,X.jsx)(hc,{});let le=m.pathname.endsWith(`/create-app`),ue=m.pathname.includes(`/system`);return!O&&!le&&!ue?(0,X.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:S(`empty.noAppsConfigured`)}),(0,X.jsx)(rt,{children:S(`empty.noAppsConfiguredDescription`)}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,X.jsx)(q,{onClick:()=>f(`/create-app`),"data-testid":`create-first-app-btn`,children:S(`empty.createFirstApp`)}),(0,X.jsx)(q,{variant:`outline`,onClick:()=>f(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:S(`empty.systemSettings`)})]})]})}):!O&&(le||ue)?(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`create-app`,element:(0,X.jsx)(cd,{})}),(0,X.jsx)(g,{path:`system/marketplace`,element:(0,X.jsx)(dd,{})}),(0,X.jsx)(g,{path:`system/marketplace/installed`,element:(0,X.jsx)(pd,{})}),(0,X.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,X.jsx)(fd,{})}),t]})}):(0,X.jsxs)(co,{user:o?{name:o.name,email:o.email,role:o.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:O,data:{},features:l,children:[(0,X.jsx)(Nu,{}),(0,X.jsxs)(cc,{activeAppName:O.name,activeApp:O,onAppChange:se,objects:y,connectionState:n,userId:o?.id,children:[(0,X.jsx)(uc,{apps:_,activeApp:O,objects:y,onAppChange:se,dataSource:c}),(0,X.jsx)(fc,{}),(0,X.jsx)(pc,{}),(0,X.jsx)(Tc,{children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(vc,{className:`h-full`,children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`/`,element:(0,X.jsx)(p,{to:vd(O,{currentUserId:o?.id??null}),replace:!0})}),(0,X.jsxs)(g,{path:`metadata`,children:[(0,X.jsx)(g,{index:!0,element:(0,X.jsx)(id,{})}),(0,X.jsx)(g,{path:`:type`,element:(0,X.jsx)(ad,{})}),(0,X.jsx)(g,{path:`:type/new`,element:(0,X.jsx)(od,{createMode:!0})}),(0,X.jsx)(g,{path:`:type/:name`,element:(0,X.jsx)(od,{})}),(0,X.jsx)(g,{path:`:type/:name/history`,element:(0,X.jsx)(sd,{})})]}),(0,X.jsx)(g,{path:`:objectName`,element:(0,X.jsx)(Yl,{dataSource:c,objects:y,onEdit:oe,externalRefreshKey:ne})}),(0,X.jsx)(g,{path:`:objectName/new`,element:(0,X.jsx)(nd,{mode:`create`})}),(0,X.jsx)(g,{path:`:objectName/view/:viewId`,element:(0,X.jsx)(Yl,{dataSource:c,objects:y,onEdit:oe,externalRefreshKey:ne})}),(0,X.jsx)(g,{path:`:objectName/record/:recordId`,element:(0,X.jsx)(Zu,{dataSource:c,objects:y,onEdit:oe},ne)}),(0,X.jsx)(g,{path:`:objectName/record/:recordId/edit`,element:(0,X.jsx)(nd,{mode:`edit`})}),(0,X.jsx)(g,{path:`dashboard/:dashboardName`,element:(0,X.jsx)(Qu,{dataSource:c})}),(0,X.jsx)(g,{path:`report/:reportName`,element:(0,X.jsx)(ed,{dataSource:c})}),(0,X.jsx)(g,{path:`page/:pageName`,element:(0,X.jsx)($u,{})}),(0,X.jsx)(g,{path:`component/:ns/:name/*`,element:(0,X.jsx)(rd,{})}),(0,X.jsx)(g,{path:`component/metadata/directory`,element:(0,X.jsx)(xd,{mode:`directory`})}),(0,X.jsx)(g,{path:`component/metadata/resource/*`,element:(0,X.jsx)(xd,{mode:`resource`})}),(0,X.jsx)(g,{path:`design/dashboard/:dashboardName`,element:(0,X.jsx)(ud,{})}),(0,X.jsx)(g,{path:`search`,element:(0,X.jsx)(td,{})}),(0,X.jsx)(g,{path:`create-app`,element:(0,X.jsx)(cd,{})}),(0,X.jsx)(g,{path:`edit-app/:editAppName`,element:(0,X.jsx)(ld,{})}),(0,X.jsx)(g,{path:`system/marketplace`,element:(0,X.jsx)(dd,{})}),(0,X.jsx)(g,{path:`system/marketplace/installed`,element:(0,X.jsx)(pd,{})}),(0,X.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,X.jsx)(fd,{})}),e,(0,X.jsx)(g,{path:`:objectName/:maybeRecordId`,element:(0,X.jsx)(Sd,{})}),(0,X.jsx)(g,{path:`*`,element:(0,X.jsx)(Cd,{})})]})})})}),L&&(0,X.jsx)(ba,{schema:{type:`object-form`,formType:`modal`,objectName:L.name,mode:M?`edit`:`create`,recordId:M?.id,title:S(M?`form.editTitle`:`form.createTitle`,{object:w(L)}),description:S(M?`form.editDescription`:`form.createDescription`,{object:w(L)}),open:k,onOpenChange:A,layout:`vertical`,fields:L.fields?Array.isArray(L.fields)?L.fields.filter(e=>typeof e==`string`?!0:uo(e.visible,ce)).map(e=>typeof e==`string`?e:e.name):Object.entries(L.fields).filter(([e,t])=>uo(t.visible,ce)).map(([e])=>e):[],onSuccess:ie,onCancel:ae,showSubmit:!0,showCancel:!0,submitText:M?S(`form.update`,{defaultValue:S(`common.save`,{defaultValue:`Save`})}):S(`form.create`,{defaultValue:S(`common.create`,{defaultValue:`Create`})}),cancelText:S(`common.cancel`)},dataSource:c},M?.id||`new`)]})]})}function hd(e,t){if(!e||e.length===0)return``;for(let n of e){if(n.type===`object`||n.type===`page`||n.type===`dashboard`||n.type===`report`){let e=gd(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=hd(n.children,t);if(e!==``)return e}}return``}function gd(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=ua(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function _d(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=_d(n.children,t);if(e)return e}}}function vd(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=gd(_d(r,n),t);if(e)return e}return hd(r,t)}var yd=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function bd(e){return!e||yd.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function xd({mode:e}){let t=u(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,X.jsx)(p,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,i=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,X.jsx)(p,{to:r?`${n}/metadata/${encodeURIComponent(r)}${i}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function Sd(){let{objectName:e,maybeRecordId:t}=a(),n=u();return e&&bd(t)?(0,X.jsx)(p,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,X.jsx)(Cd,{})}function Cd(){let e=v(),{t}=R();return(0,X.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,X.jsx)(rt,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(q,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function wd({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,Y.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,X.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,X.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,X.jsx)(`span`,{className:i,children:s})})}function Td(){let e=v(),{appName:t}=a(),{t:n}=R(),r=t?`/apps/${t}`:`/`;return(0,X.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,X.jsx)(ht,{children:(0,X.jsxs)(pi,{className:`flex flex-col items-center gap-4 py-12 text-center`,children:[(0,X.jsx)(`div`,{className:`rounded-full bg-muted p-3`,children:(0,X.jsx)(gi,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold`,children:n(`marketplace.accessDenied.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:n(`marketplace.accessDenied.description`)})]}),(0,X.jsx)(q,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var Ed=`en`;function Dd(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function Od(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function kd(e,t,n){if(!e)return;let r=Dd(t),i=Od([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),Ed]);for(let t of i){let r=e[t];if(!r)continue;let i=r[n];if(typeof i==`string`&&i.length>0)return i}}function Ad(e,t){let n=e[{displayName:`display_name`,description:`description`,readme:`readme`,tagline:`tagline`,screenshotCaptions:`screenshotCaptions`}[t]]??e[t];return typeof n==`string`&&n.length>0?n:void 0}function jd(e,t){let n=t||Ed;return{displayName:kd(e.translations??void 0,n,`displayName`)??Ad(e,`displayName`)??e.manifest_id,description:kd(e.translations??void 0,n,`description`)??Ad(e,`description`),readme:kd(e.translations??void 0,n,`readme`)??Ad(e,`readme`),tagline:kd(e.translations??void 0,n,`tagline`)??Ad(e,`tagline`)}}var Md=``.replace(/\/$/,``),Nd=`${Md}/api/v1/marketplace`;async function Pd(e,t){let n=await fetch(`${Nd}${e}`,{credentials:`omit`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.error?.code??r?.code??`HTTP_${n.status}`,t=r?.error?.message??r?.error??n.statusText,i=Error(typeof t==`string`?t:`${e}`);throw i.code=e,i.status=n.status,i}return r?.data??r}async function Fd(e={}){let t=new URLSearchParams;e.q&&t.set(`q`,e.q),e.category&&t.set(`category`,e.category),e.limit!=null&&t.set(`limit`,String(e.limit)),e.offset!=null&&t.set(`offset`,String(e.offset));let n=t.toString();return Pd(`/packages${n?`?${n}`:``}`)}async function Id(e){return Pd(`/packages/${encodeURIComponent(e)}`)}async function Ld(e){let t=oc()||Md,n=await fetch(`${t}/api/v1/actions/sys_package/install_package`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({recordId:e.packageId,params:{environment_id:e.environmentId,seed_sample_data:!!e.seedSampleData}})}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??r?.error?.code??`HTTP_${n.status}`,t=r?.error??r?.message??n.statusText,i=Error(typeof t==`string`?t:`${e}`);throw i.code=e,i.status=n.status,i}return r?.data??r}async function Rd(){let e=oc()||Md,t=await fetch(`${e}/api/v1/data/sys_environment?limit=200`,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok){let e=Error(`HTTP_${t.status}`);throw e.status=t.status,e}let n=await t.json().catch(()=>({})),r=n?.records??n?.data??n?.items??n??[];return Array.isArray(r)?r:[]}async function zd(){let e=oc()||Md,t=null;try{let n=await fetch(`${e}/api/v1/auth/get-session`,{credentials:`include`,headers:{Accept:`application/json`}});n.ok&&(t=(await n.json().catch(()=>({})))?.user?.id??null)}catch{}if(!t)return new Set;let n=`${e}/api/v1/data/sys_member?limit=200`,r=null;try{let e=await fetch(n,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return new Set;r=await e.json().catch(()=>({}))}catch{return new Set}let i=r?.records??r?.data??r?.items??r??[];if(!Array.isArray(i))return new Set;let a=new Set;for(let e of i){if(String(e?.user_id??e?.userId??``)!==t)continue;let n=String(e?.role??``).toLowerCase(),r=e?.organization_id??e?.organizationId;r&&(n===`owner`||n===`admin`)&&a.add(String(r))}return a}function Bd(e){return`${oc()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function Vd(e,t){if(!e||!t)return null;let n=oc()||Md,r=JSON.stringify([`and`,[`package_id`,`=`,e],[`environment_id`,`=`,t]]),i=`${n}/api/v1/data/sys_package_installation?top=1&filter=${encodeURIComponent(r)}`;try{let e=await fetch(i,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return null;let t=await e.json().catch(()=>({})),n=t?.records??t?.data??t?.items??[];if(!Array.isArray(n)||n.length===0)return null;let r=n[0],a=r?.enabled;return a===!1||a===0||a===`0`?null:{installationId:String(r?.id??``),version:String(r?.version??r?.installed_version??`installed`),withSampleData:r?.with_sample_data===!0||r?.with_sample_data===1||r?.with_sample_data===`1`||r?.with_sample_data===`true`}}catch{return null}}async function Hd(e){if(!e)return{ok:!1,error:`installation id required`};let t=oc()||Md;try{let n=await fetch(`${t}/api/v1/cloud/installations/${encodeURIComponent(e)}/reseed-sample-data`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:`{}`}),r=await n.json().catch(()=>({}));return!n.ok||r?.success===!1?{ok:!1,error:r?.error||`HTTP ${n.status}`}:{ok:!0}}catch(e){return{ok:!1,error:e?.message||`Network error`}}}async function Ud(e){if(!e)return{ok:!1,error:`installation id required`};let t=oc()||Md;try{let n=await fetch(`${t}/api/v1/cloud/installations/${encodeURIComponent(e)}/purge-sample-data`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:`{}`}),r=await n.json().catch(()=>({}));return!n.ok||r?.success===!1?{ok:!1,error:r?.error||`HTTP ${n.status}`}:{ok:!0,deleted:Number(r?.data?.deleted??0)}}catch(e){return{ok:!1,error:e?.message||`Network error`}}}async function Wd(e){let t=await fetch(`${Nd}/install-local`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({packageId:e.packageId,...e.versionId?{versionId:e.versionId}:{}})}),n=null;try{n=await t.json()}catch{}if(!t.ok){let e=n?.error?.code??`HTTP_${t.status}`,r=n?.error?.message??t.statusText,i=Error(typeof r==`string`?r:`${e}`);throw i.code=e,i.status=t.status,i}return n?.data??n}async function Gd(){try{let e=await fetch(`${Nd}/install-local`,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return[];let t=await e.json().catch(()=>({})),n=t?.data?.items??t?.items??[];return Array.isArray(n)?n:[]}catch{return[]}}async function Kd(e){let t=await fetch(`${Nd}/install-local/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok){let e=(await t.json().catch(()=>({})))?.error?.message??t.statusText;throw Error(typeof e==`string`?e:`HTTP_${t.status}`)}}async function qd(e,t){let n=await fetch(`${Nd}/install-local/${encodeURIComponent(e)}/${t===`reseed`?`reseed-sample-data`:`purge-sample-data`}`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`}}),r=await n.json().catch(()=>({}));if(!n.ok){let e=r?.error?.message??n.statusText,t=Error(typeof e==`string`?e:`HTTP_${n.status}`);throw t.code=r?.error?.code??`HTTP_${n.status}`,t}return r?.data??r}function Jd(e){return qd(e,`reseed`)}function Yd(e){return qd(e,`purge`)}var Xd=t({MarketplacePage:()=>Qd});function Zd(){let{language:e,t}=R();return n=>{if(!n)return``;let r=new Date(n);if(Number.isNaN(r.getTime()))return``;let i=Math.floor((Date.now()-r.getTime())/864e5);if(i<1)return t(`marketplace.relativeTime.today`);try{let t=new Intl.RelativeTimeFormat(e||`en`,{numeric:`auto`});return i<30?t.format(-i,`day`):i<365?t.format(-Math.floor(i/30),`month`):t.format(-Math.floor(i/365),`year`)}catch{return i<30?t(`marketplace.relativeTime.daysAgo`,{count:i}):i<365?t(`marketplace.relativeTime.monthsAgo`,{count:Math.floor(i/30)}):t(`marketplace.relativeTime.yearsAgo`,{count:Math.floor(i/365)})}}}function Qd(){let e=v(),{appName:t}=a(),n=b(),{t:r,language:i}=R(),o=Zd(),s=t?`/apps/${t}`:``,[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(!0),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(``),[y,x]=(0,Y.useState)([]),S=(0,Y.useMemo)(()=>{let e=new Map;for(let t of y)e.set(t.manifestId,t);return e},[y]),C=async()=>{d(!0),p(null);try{let[e,t]=await Promise.all([Fd({limit:100}),Gd()]);l(e.items??[]),x(t)}catch(e){p(e?.message??String(e)),l([])}finally{d(!1)}};(0,Y.useEffect)(()=>{C()},[]);let w=(0,Y.useMemo)(()=>{let e=new Set;for(let t of c)t.category&&e.add(t.category);return Array.from(e).sort()},[c]),T=e=>{let t=`marketplace.category.${e}`,n=r(t,{defaultValue:e});return n===t?e:n},E=(0,Y.useMemo)(()=>{let e=m.trim().toLowerCase();return c.filter(t=>{if(g&&t.category!==g)return!1;if(!e)return!0;let n=jd(t,i);return`${n.displayName} ${t.manifest_id} ${n.description??``}`.toLowerCase().includes(e)})},[c,m,g,i]);return n?(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xe,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,X.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.title`)})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:r(`marketplace.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>e(`${s}/system/marketplace/installed`),children:[(0,X.jsx)(bi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),y.length>0?r(`marketplace.installedCount`,{count:y.length}):r(`marketplace.installed`)]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void C(),disabled:u,children:[(0,X.jsx)(er,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(Ai,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsx)(K,{value:m,onChange:e=>h(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,X.jsx)(q,{size:`sm`,variant:g===``?`default`:`outline`,onClick:()=>_(``),children:r(`marketplace.all`)}),w.map(e=>(0,X.jsx)(q,{size:`sm`,variant:g===e?`default`:`outline`,onClick:()=>_(e),children:T(e)},e))]})]}),f&&(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-destructive`,children:r(`marketplace.load.failed`)}),(0,X.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:f}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2`,dangerouslySetInnerHTML:{__html:r(`marketplace.load.failedHint`)}})]})]}),u&&c.length===0?(0,X.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,X.jsxs)(ht,{children:[(0,X.jsxs)(Rn,{className:`pb-2`,children:[(0,X.jsx)(W,{className:`h-10 w-10 rounded-lg mb-2`}),(0,X.jsx)(W,{className:`h-5 w-3/4`}),(0,X.jsx)(W,{className:`h-4 w-1/2 mt-1`})]}),(0,X.jsx)(pi,{children:(0,X.jsx)(W,{className:`h-12 w-full`})})]},t))}):E.length===0?(0,X.jsx)(`div`,{className:`text-center py-12 text-sm text-muted-foreground`,children:c.length===0?r(`marketplace.noApprovedYet`):r(`marketplace.noMatchFilters`)}):(0,X.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:E.map(t=>{let n=S.get(t.manifest_id),a=jd(t,i);return(0,X.jsxs)(ht,{className:`cursor-pointer transition-colors hover:bg-accent/50 flex flex-col`,onClick:()=>e(`${s}/system/marketplace/${t.id}`),role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(`${s}/system/marketplace/${t.id}`))},"data-testid":`marketplace-card-${t.manifest_id}`,children:[(0,X.jsxs)(Rn,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,X.jsx)(wd,{iconUrl:t.icon_url,displayName:a.displayName,manifestId:t.manifest_id}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(Nn,{className:`text-base truncate`,children:a.displayName}),(0,X.jsx)(ut,{className:`text-xs truncate`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,X.jsx)(G,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,X.jsxs)(pi,{className:`flex-1 flex flex-col gap-2`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:a.description||r(`marketplace.noDescription`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-auto pt-2 flex-wrap`,children:[n&&(0,X.jsxs)(G,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,X.jsx)(Tr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,X.jsxs)(G,{variant:`outline`,className:`text-xs`,children:[(0,X.jsx)(Sn,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,X.jsx)(G,{variant:`outline`,className:`text-xs`,children:T(t.category)}),t.latest_version?.published_at&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:o(t.latest_version.published_at)})]})]})]},t.id)})})]}):(0,X.jsx)(Td,{})}function $d(e){let t=e.replace(/\r\n/g,`
|
|
11
|
-
`).split(`
|
|
12
|
-
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(e.startsWith("```")){let i=e.slice(3).trim();r++;let a=[];for(;r<t.length&&!t[r].startsWith("```");)a.push(t[r]),r++;r++,n.push({type:`code`,text:a.join(`
|
|
13
|
-
`),lang:i});continue}let i=/^(#{1,3})\s+(.*)$/.exec(e);if(i){let e=i[1].length;n.push({type:`h${e}`,text:i[2].trim()}),r++;continue}if(/^[-*]\s+/.test(e)){let e=[];for(;r<t.length&&/^[-*]\s+/.test(t[r]);)e.push(t[r].replace(/^[-*]\s+/,``)),r++;n.push({type:`ul`,items:e});continue}if(/^\d+\.\s+/.test(e)){let e=[];for(;r<t.length&&/^\d+\.\s+/.test(t[r]);)e.push(t[r].replace(/^\d+\.\s+/,``)),r++;n.push({type:`ol`,items:e});continue}if(!e.trim()){r++;continue}let a=[];for(;r<t.length&&t[r].trim()&&!/^#{1,3}\s+/.test(t[r])&&!/^[-*]\s+/.test(t[r])&&!/^\d+\.\s+/.test(t[r])&&!t[r].startsWith("```");)a.push(t[r]),r++;n.push({type:`p`,text:a.join(` `)})}return n}function ef(e){let t=[],n=e,r=0,i=[{re:/`([^`]+)`/,render:e=>(0,X.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[0.85em]`,children:e[1]},`k${r++}`)},{re:/\*\*([^*]+)\*\*/,render:e=>(0,X.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e[1]},`k${r++}`)},{re:/\*([^*]+)\*/,render:e=>(0,X.jsx)(`em`,{children:e[1]},`k${r++}`)},{re:/\[([^\]]+)\]\(([^)]+)\)/,render:e=>(0,X.jsx)(`a`,{href:e[2],target:`_blank`,rel:`noopener noreferrer`,className:`text-violet-600 underline-offset-2 hover:underline dark:text-violet-400`,children:e[1]},`k${r++}`)}];for(;n;){let e=-1,r=null,a=null;for(let t of i){let i=t.re.exec(n);i&&(e===-1||i.index<e)&&(e=i.index,r=i,a=t)}if(!r||!a){t.push(n);break}e>0&&t.push(n.slice(0,e)),t.push(a.render(r)),n=n.slice(e+r[0].length)}return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>(0,X.jsx)(Y.Fragment,{children:e},t))})}function tf({source:e,className:t}){let n=$d(e);return(0,X.jsx)(`div`,{className:`flex flex-col gap-4 text-sm leading-relaxed text-foreground/90 ${t??``}`,children:n.map((e,t)=>{switch(e.type){case`h1`:return(0,X.jsx)(`h2`,{className:`mt-2 text-xl font-bold tracking-tight`,children:ef(e.text??``)},t);case`h2`:return(0,X.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:ef(e.text??``)},t);case`h3`:return(0,X.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:ef(e.text??``)},t);case`p`:return(0,X.jsx)(`p`,{children:ef(e.text??``)},t);case`ul`:return(0,X.jsx)(`ul`,{className:`ml-1 flex list-none flex-col gap-1.5`,children:(e.items??[]).map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1.5 inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-violet-500/70`}),(0,X.jsx)(`span`,{children:ef(e)})]},t))},t);case`ol`:return(0,X.jsx)(`ol`,{className:`ml-5 flex list-decimal flex-col gap-1.5 marker:text-muted-foreground`,children:(e.items??[]).map((e,t)=>(0,X.jsx)(`li`,{className:`pl-1`,children:ef(e)},t))},t);case`code`:return(0,X.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border bg-muted/40 p-3 text-xs leading-relaxed`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:e.text})},t)}return null})})}var nf=t({MarketplacePackagePage:()=>rf});function rf(){let e=v(),{packageId:t,appName:n}=a(),r=b(),{t:i,language:o}=R(),s=n?`/apps/${n}`:``,{refresh:c}=F(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!0),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(!1),[_,y]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(null),[ee,te]=(0,Y.useState)(null),[ne,N]=(0,Y.useState)(null),[P,re]=(0,Y.useState)(null),[I,L]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)([]),[oe,se]=(0,Y.useState)(!1),[ce,le]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!rc().features.installLocal)return;let e=!1;return(async()=>{let t=await Gd();e||ae(t)})(),()=>{e=!0}},[t,ce]),(0,Y.useEffect)(()=>{if(!t)return;let e=rc().defaultEnvironmentId;if(!e)return;let n=!1;return(async()=>{let r=await Vd(t,e);n||!r||(N(r),te(r.version))})(),()=>{n=!0}},[t]),(0,Y.useEffect)(()=>{let e=!1;return(async()=>{if(t){f(!0),m(null);try{let n=await Id(t);e||u(n)}catch(t){e||m(t?.message??String(t))}finally{e||f(!1)}}})(),()=>{e=!0}},[t]);let ue=async()=>{g(!0),M(null),w(null);let e=rc().defaultEnvironmentId;if(e){S(!1),E(e),y([]);return}S(!0);try{let[e,t]=await Promise.all([Rd(),zd()]),n=e.filter(e=>{let n=e.organization_id;return n?t.has(String(n)):!1});y(n),e.length>0&&n.length===0?w(i(`marketplace.install.noPermission`)):n.length===1&&E(n[0].id)}catch(e){let t=e?.status;w(t===401||t===403?i(`marketplace.install.signInFirst`):e?.message??String(e))}finally{S(!1)}},de=async()=>{if(!(!t||!T)){A(!0),M(null);try{te(((await Ld({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=rc().defaultEnvironmentId||T;if(e){let n=await Vd(t,e);n&&N(n)}}catch{}let e=rc().defaultEnvironmentId;if(!e||e===T)try{if(typeof sessionStorage<`u`)for(let e of Object.keys(sessionStorage))e.startsWith(`objectui:metadata:`)&&sessionStorage.removeItem(e);await c()}catch{}M({ok:!0,message:i(`marketplace.install.success`)})}catch(e){M({ok:!1,message:e?.message??String(e)})}finally{A(!1)}}},fe=async()=>{if(t){se(!0),le(null);try{let e=await Wd({packageId:t});try{await c(`app`)}catch{}le({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?jd(l.package,o).displayName:e.manifestId})})}catch(e){let t=e?.code,n=e?.message??String(e);t===`manifest_conflict`?n=i(`marketplace.install.localManifestConflict`,{message:n}):t===`unauthorized`?n=i(`marketplace.install.localUnauthorized`):t===`marketplace_unavailable`&&(n=i(`marketplace.install.localMarketplaceUnavailable`)),le({ok:!1,message:n})}finally{se(!1)}}},pe=async()=>{if(_e&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:_e.manifestId,version:_e.version}))){se(!0),le(null);try{await Kd(_e.manifestId);try{await c(`app`)}catch{}le({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:_e.manifestId})})}catch(e){le({ok:!1,message:e?.message??String(e)})}finally{se(!1)}}},z=async()=>{if(ne){re(`reseed`),L(null);try{let e=await Hd(ne.installationId);e.ok?(N({...ne,withSampleData:!0}),L({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):L({ok:!1,text:e.error||`Re-seed failed`})}finally{re(null)}}},me=async()=>{if(ne&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){re(`purge`),L(null);try{let e=await Ud(ne.installationId);if(e.ok){N({...ne,withSampleData:!1});let t=e.deleted??0;L({ok:!0,text:t>0?i(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:i(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}else L({ok:!1,text:e.error||`Purge failed`})}finally{re(null)}}},he=async()=>{if(_e){re(`reseed`),L(null);try{let e=await Jd(_e.manifestId);ae(e=>e.map(e=>e.manifestId===_e.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;L({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){L({ok:!1,text:e?.message||`Re-seed failed`})}finally{re(null)}}},B=async()=>{if(_e&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){re(`purge`),L(null);try{let e=await Yd(_e.manifestId);ae(e=>e.map(e=>e.manifestId===_e.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;L({ok:!0,text:t>0?i(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:i(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}catch(e){L({ok:!1,text:e?.message||`Purge failed`})}finally{re(null)}}};if(d)return(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsx)(W,{className:`h-8 w-32`}),(0,X.jsx)(W,{className:`h-16 w-full`}),(0,X.jsx)(W,{className:`h-64 w-full`})]});if(p||!l)return(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,X.jsx)(dt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-destructive`,children:i(`marketplace.load.packageFailed`)}),(0,X.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:p??i(`marketplace.load.notFound`)})]})]})]});let V=l.package,H=jd(V,o),ge=V.latest_version?.version??l.versions[0]?.version??null,_e=ie.find(e=>e.manifestId===V.manifest_id)??null,ve=rc().features.installLocal,U=!ge||oe||k||!ve&&!!ee,ye=ve?{label:i(oe?`marketplace.action.working`:_e?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:fe}:{label:k?i(`marketplace.action.installing`):ee?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:ue},be=V.category?i(`marketplace.category.${V.category}`,{defaultValue:V.category}):null;return r?(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,X.jsx)(dt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-5 flex-wrap sm:flex-nowrap rounded-2xl border bg-gradient-to-br from-primary/5 via-background to-background p-6 sm:p-8`,children:[(0,X.jsx)(wd,{iconUrl:V.icon_url,displayName:H.displayName,manifestId:V.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:H.displayName||V.manifest_id}),V.homepage_url&&(0,X.jsxs)(`a`,{href:V.homepage_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,title:i(`marketplace.detail.homepage`),children:[(0,X.jsx)(pt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:i(`marketplace.detail.homepage`)})]})]}),(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`code`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:V.manifest_id}),ge&&(0,X.jsx)(G,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:ge})}),V.publisher&&V.publisher!==`private`&&(0,X.jsx)(G,{variant:V.publisher===`objectstack`?`default`:`secondary`,children:V.publisher}),be&&(0,X.jsx)(G,{variant:`outline`,children:be}),V.license&&(0,X.jsx)(G,{variant:`outline`,className:`font-normal`,children:V.license}),_e&&(0,X.jsxs)(G,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,X.jsx)(Tr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:_e.version})]}),!_e&&ee&&(0,X.jsxs)(G,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,X.jsx)(Tr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:ee})]})]}),H.description&&(0,X.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:H.description})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,X.jsxs)(q,{onClick:ye.onClick,disabled:U,size:`lg`,className:`min-w-[8rem]`,children:[(0,X.jsx)(jn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),ye.label]}),_e&&(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsx)(q,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`),children:(0,X.jsx)(di,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,X.jsxs)(ai,{align:`end`,className:`w-56`,children:[(0,X.jsxs)(or,{onSelect:he,disabled:P!==null,children:[P===`reseed`?(0,X.jsx)(jr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(Xt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),_e.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,X.jsxs)(or,{onSelect:B,disabled:P!==null||!_e.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,X.jsx)(jr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(qt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,X.jsxs)(or,{onSelect:pe,disabled:oe,className:`text-destructive focus:text-destructive`,children:[(0,X.jsx)(qt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!_e&&ne&&(0,X.jsxs)(Xn,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsx)(q,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`)||`More options`,children:(0,X.jsx)(di,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,X.jsxs)(ai,{align:`end`,className:`w-56`,children:[(0,X.jsxs)(or,{onSelect:z,disabled:P!==null,children:[P===`reseed`?(0,X.jsx)(jr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(Xt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),ne.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,X.jsxs)(or,{onSelect:me,disabled:P!==null||!ne.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,X.jsx)(jr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(qt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),I&&(0,X.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${I.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[I.ok?(0,X.jsx)(Tr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:I.text}),(0,X.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>L(null),children:i(`marketplace.action.dismiss`)})]}),ce&&(0,X.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${ce.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[ce.ok?(0,X.jsx)(Tr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:ce.message}),(0,X.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>le(null),children:i(`marketplace.action.dismiss`)})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,children:[(0,X.jsx)(`div`,{className:`lg:col-span-2 space-y-4`,children:(0,X.jsxs)(ht,{children:[(0,X.jsx)(Rn,{children:(0,X.jsx)(Nn,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,X.jsx)(pi,{children:H.readme?(0,X.jsx)(tf,{source:H.readme}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noReadme`)})})]})}),(0,X.jsx)(`div`,{className:`space-y-4`,children:(0,X.jsxs)(ht,{children:[(0,X.jsx)(Rn,{children:(0,X.jsx)(Nn,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,X.jsx)(pi,{children:l.versions.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noApprovedVersions`)}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:l.versions.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Sn,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsxs)(`code`,{className:`font-mono`,children:[`v`,e.version]}),e.is_prerelease&&(0,X.jsx)(G,{variant:`outline`,className:`text-xs`,children:i(`marketplace.detail.prerelease`)})]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.published_at?new Date(e.published_at).toLocaleDateString():`—`})]},e.id))})})]})})]}),(0,X.jsx)(We,{open:h,onOpenChange:e=>{g(e),e||M(null)},children:(0,X.jsxs)(ot,{children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:i(`marketplace.install.dialogTitle`,{name:H.displayName||V.manifest_id})}),(0,X.jsx)(xt,{children:rc().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),x?(0,X.jsx)(W,{className:`h-10 w-full`}):C?(0,X.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 text-sm space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 text-amber-600`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:C})]}),(0,X.jsx)(`a`,{href:Bd(V.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,X.jsxs)(q,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,X.jsx)(pt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):rc().defaultEnvironmentId?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ye,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,X.jsx)(Nr,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]}):_.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.install.noEnvs`)}):(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(Nr,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,X.jsxs)(on,{value:T,onValueChange:E,children:[(0,X.jsx)(Tn,{id:`env-select`,children:(0,X.jsx)(nt,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,X.jsx)(oa,{children:_.map(e=>(0,X.jsxs)(Oe,{value:e.id,children:[e.display_name||e.hostname||e.id,e.plan&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.plan]})]},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ye,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,X.jsx)(Nr,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),j&&(0,X.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${j.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:j.message}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:()=>g(!1),children:i(`marketplace.action.close`)}),!C&&(0,X.jsx)(q,{onClick:de,disabled:!T||k||j?.ok===!0,children:i(k?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,X.jsx)(Td,{})}var af=t({MarketplaceInstalledPage:()=>of});function of(){let e=v(),{appName:t}=a(),n=b(),{t:r,language:i}=R(),o=t?`/apps/${t}`:``,[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),h=async()=>{u(!0);try{c(await Gd())}finally{u(!1)}};(0,Y.useEffect)(()=>{h()},[]);let g=async e=>{if(confirm(r(`marketplace.uninstall.confirm`,{manifestId:e.manifestId,version:e.version}))){f(e.manifestId),m(null);try{await Kd(e.manifestId),m({ok:!0,message:r(`marketplace.uninstall.successInList`,{manifestId:e.manifestId})}),await h()}catch(e){m({ok:!1,message:e?.message??String(e)})}finally{f(null)}}};return n?(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-5xl`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,className:`self-start`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,X.jsx)(dt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.back`)]}),(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xe,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,X.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.installedTitle`)})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedSubtitle`)}})]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void h(),disabled:l,children:[(0,X.jsx)(er,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]}),p&&(0,X.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${p.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{children:p.message})]})}),l&&s.length===0?(0,X.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:3}).map((e,t)=>(0,X.jsx)(W,{className:`h-20 w-full`},t))}):s.length===0?(0,X.jsxs)(`div`,{className:`text-center py-12 text-sm text-muted-foreground border rounded-md`,children:[(0,X.jsx)(`p`,{children:r(`marketplace.installedEmpty`)}),(0,X.jsx)(q,{variant:`link`,className:`mt-2`,onClick:()=>e(`${o}/system/marketplace`),children:r(`marketplace.browseLink`)})]}):(0,X.jsx)(`div`,{className:`grid gap-3`,children:s.map(t=>(0,X.jsxs)(ht,{children:[(0,X.jsxs)(Rn,{className:`flex flex-row items-start justify-between gap-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(Nn,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,X.jsx)(G,{variant:`outline`,children:r(`marketplace.versionBadge`,{version:t.version})})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap gap-x-3 gap-y-1`,children:[(0,X.jsx)(`span`,{children:r(`marketplace.installedAt`,{when:new Date(t.installedAt).toLocaleString(i||void 0)})}),t.installedBy&&(0,X.jsx)(`span`,{children:r(`marketplace.installedBy`,{user:t.installedBy})}),(0,X.jsxs)(`span`,{children:[r(`marketplace.installedPackageId`),` `,(0,X.jsx)(`code`,{className:`font-mono`,children:t.packageId})]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/${t.packageId}`),children:[(0,X.jsx)(pt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.action.details`)]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void g(t),disabled:d===t.manifestId,children:[(0,X.jsx)(qt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),d===t.manifestId?r(`marketplace.action.uninstalling`):r(`marketplace.action.uninstall`)]})]})]}),(0,X.jsx)(pi,{className:`pt-0 text-xs text-muted-foreground`,dangerouslySetInnerHTML:{__html:r(`marketplace.cachedAs`,{path:`.objectstack/installed-packages/${t.manifestId.replace(/[^a-zA-Z0-9._-]/g,`_`)}.json`})}})]},t.manifestId))}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground border-t pt-4`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedAdditiveNote`)}})]}):(0,X.jsx)(Td,{})}function sf({children:e,userId:t}){let{setContext:n}=Ao(),{isAiEnabled:r}=k(),i=r||!1;return(0,Y.useEffect)(()=>{n(`home`)},[n]),(0,X.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,X.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,X.jsx)(Xs,{variant:`home`})}),(0,X.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,X.jsx)(ts,{appLabel:`Workspace`,objects:[],userId:t})]})}var cf=[{from:`from-blue-500/15`,to:`to-indigo-500/10`,text:`text-blue-600 dark:text-blue-400`,ring:`group-hover:border-blue-500/40`,solid:`bg-blue-500`},{from:`from-emerald-500/15`,to:`to-teal-500/10`,text:`text-emerald-600 dark:text-emerald-400`,ring:`group-hover:border-emerald-500/40`,solid:`bg-emerald-500`},{from:`from-fuchsia-500/15`,to:`to-pink-500/10`,text:`text-fuchsia-600 dark:text-fuchsia-400`,ring:`group-hover:border-fuchsia-500/40`,solid:`bg-fuchsia-500`},{from:`from-amber-500/15`,to:`to-orange-500/10`,text:`text-amber-600 dark:text-amber-400`,ring:`group-hover:border-amber-500/40`,solid:`bg-amber-500`},{from:`from-sky-500/15`,to:`to-cyan-500/10`,text:`text-sky-600 dark:text-sky-400`,ring:`group-hover:border-sky-500/40`,solid:`bg-sky-500`},{from:`from-violet-500/15`,to:`to-purple-500/10`,text:`text-violet-600 dark:text-violet-400`,ring:`group-hover:border-violet-500/40`,solid:`bg-violet-500`},{from:`from-rose-500/15`,to:`to-red-500/10`,text:`text-rose-600 dark:text-rose-400`,ring:`group-hover:border-rose-500/40`,solid:`bg-rose-500`}];function lf(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function uf({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=R(),{appLabel:a,appDescription:o}=ti(),{toggleFavorite:s}=Ho(),c=as(e.icon),l=a({name:e.name,label:Fs(e.label,i)}),u=o({name:e.name,description:Fs(e.description,i)}),d=e.branding?.primaryColor,f=cf[(lf(e.name)+r)%cf.length];return(0,X.jsxs)(ht,{role:`button`,tabIndex:0,"aria-label":l,className:gr(`group relative cursor-pointer overflow-hidden border border-border/70 bg-card/80 backdrop-blur-sm`,`transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-lg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`motion-reduce:transition-none motion-reduce:hover:transform-none`,!d&&f.ring),onClick:t,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())},"data-testid":`app-card-${e.name}`,style:d?{borderColor:void 0}:void 0,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:gr(`absolute inset-x-0 top-0 h-1`,d?``:f.solid),style:d?{backgroundColor:d}:void 0}),!d&&(0,X.jsx)(`div`,{"aria-hidden":!0,className:gr(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,f.from,f.to)}),(0,X.jsxs)(pi,{className:`relative p-5`,children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`absolute top-2 right-2 h-8 w-8 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,onClick:t=>{t.stopPropagation(),s({id:`app:${e.name}`,label:l,href:`/apps/${e.name}`,type:`object`})},"aria-label":n?i(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`})+` — ${l}`:i(`common.addToFavorites`,{defaultValue:`Add to favorites`})+` — ${l}`,"aria-pressed":n,"data-testid":`favorite-btn-${e.name}`,children:n?(0,X.jsx)(_t,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,X.jsx)(mi,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:gr(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,d?``:gr(`bg-gradient-to-br`,f.from,f.to,`ring-border/40`)),style:d?{backgroundColor:`${d}1f`,boxShadow:`inset 0 0 0 1px ${d}33`}:void 0,children:(0,X.jsx)(c,{className:gr(`h-7 w-7`,d?``:f.text),style:d?{color:d}:void 0})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`h3`,{className:`font-semibold text-base sm:text-lg leading-tight truncate`,children:l}),e.isDefault&&(0,X.jsx)(G,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,X.jsx)(`p`,{className:gr(`text-sm text-muted-foreground mt-1.5 line-clamp-2 min-h-[2.5rem]`,!u&&`italic`),children:u||i(`home.appCard.noDescription`,{defaultValue:`No description`})})]}),(0,X.jsx)(`div`,{className:`mt-4 flex items-center justify-between text-xs font-medium`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground transition-colors group-hover:text-foreground`,children:[i(`home.open`,{defaultValue:`Open`}),(0,X.jsx)(On,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var df={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400 ring-blue-500/20`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-violet-500/20`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 ring-emerald-500/20`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400 ring-amber-500/20`},ff={object:Xt,record:na,dashboard:ci,page:tn};function pf({items:e}){let t=v(),{t:n}=R();return e.length===0?null:(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,X.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg bg-sky-500/10 ring-1 ring-sky-500/20 text-sky-600 dark:text-sky-400`,children:(0,X.jsx)(oi,{className:`h-4 w-4`})}),(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>{let r=ff[e.type]||Xt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Is(e.type)}),a=df[e.type]||df.object;return(0,X.jsx)(ht,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`recent-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,X.jsx)(pi,{className:`p-3.5`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:gr(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,a),children:(0,X.jsx)(r,{className:`h-5 w-5`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,X.jsx)(On,{className:`h-4 w-4 text-muted-foreground opacity-0 -translate-x-1 transition-[opacity,transform] duration-200 group-hover:opacity-100 group-hover:translate-x-0`})]})})},e.id)})})]})}var mf={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400 ring-blue-500/20`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-violet-500/20`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 ring-emerald-500/20`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400 ring-amber-500/20`},hf={object:Xt,record:na,dashboard:ci,page:tn};function gf({items:e}){let t=v(),{t:n}=R();return e.length===0?null:(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,X.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg bg-amber-500/10 ring-1 ring-amber-500/20 text-amber-600 dark:text-amber-400`,children:(0,X.jsx)(_t,{className:`h-4 w-4 fill-current`})}),(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>{let r=hf[e.type]||Xt,i=mf[e.type]||mf.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Is(e.type)});return(0,X.jsx)(ht,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`starred-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,X.jsx)(pi,{className:`p-3.5`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:gr(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,i),children:(0,X.jsx)(r,{className:`h-5 w-5`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]}),(0,X.jsx)(On,{className:`h-4 w-4 text-muted-foreground opacity-0 -translate-x-1 transition-[opacity,transform] duration-200 group-hover:opacity-100 group-hover:translate-x-0`})]})})},e.id)})})]})}function _f(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function vf({t:e}){return(0,X.jsxs)(`section`,{"data-testid":`home-getting-started`,className:`relative overflow-hidden rounded-2xl border border-border/60 bg-card/70 backdrop-blur-sm p-6 sm:p-8`,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-fuchsia-500/5`}),(0,X.jsxs)(`div`,{className:`relative flex flex-col sm:flex-row sm:items-center gap-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.jsx)(`span`,{className:`inline-flex h-10 w-10 items-center justify-center rounded-lg bg-amber-500/10 ring-1 ring-amber-500/20 text-amber-600 dark:text-amber-400`,children:(0,X.jsx)(_t,{className:`h-5 w-5`})}),(0,X.jsx)(`span`,{className:`inline-flex h-10 w-10 items-center justify-center rounded-lg bg-emerald-500/10 ring-1 ring-emerald-500/20 text-emerald-600 dark:text-emerald-400`,children:(0,X.jsx)(oi,{className:`h-5 w-5`})})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:e(`home.gettingStarted.title`,{defaultValue:`Make this home yours`})}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-xl`,children:e(`home.gettingStarted.description`,{defaultValue:`Star an app to pin it here for one-click access. Anything you open will show up under Recently Accessed automatically.`})})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:e(`home.gettingStarted.cta`,{defaultValue:`Browse all applications`})}),(0,X.jsx)(zn,{className:`h-3.5 w-3.5`})]})]})]})}function yf(){let e=v(),{t}=R(),{apps:n,loading:r}=F(),{recentItems:i}=Do(),{favorites:a}=Ho(),{user:o}=C(),s=b(),c=n.filter(e=>e.active!==!1&&e.hidden!==!0),l=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),u=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,8),d=(0,Y.useMemo)(()=>t(_f(new Date().getHours()),{defaultValue:`Welcome`}),[t]),f=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,X.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):c.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,X.jsx)(rt,{children:t(`home.welcomeDescription`,{defaultValue:`Get started by creating your first application or configure your system settings.`})}),(0,X.jsxs)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:[(0,X.jsxs)(q,{onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,X.jsx)(fn,{className:`mr-2 h-4 w-4`}),t(`home.createFirstApp`,{defaultValue:`Create Your First App`})]}),s&&(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-empty-btn`,children:[(0,X.jsx)(Xe,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]}),(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,X.jsx)(bi,{className:`mr-2 h-4 w-4`}),t(`home.systemSettings`,{defaultValue:`System Settings`})]})]})]})}):(0,X.jsxs)(`div`,{className:`relative isolate min-h-full bg-gradient-to-b from-background via-background to-muted/40`,children:[(0,X.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 top-0 -z-10 h-[28rem] overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`absolute -top-32 -left-24 h-[28rem] w-[28rem] rounded-full bg-primary/30 blur-3xl opacity-70 dark:opacity-40`}),(0,X.jsx)(`div`,{className:`absolute -top-20 right-[-6rem] h-[26rem] w-[36rem] rounded-full bg-sky-400/30 blur-3xl opacity-70 dark:opacity-35`}),(0,X.jsx)(`div`,{className:`absolute top-32 left-1/3 h-[18rem] w-[24rem] rounded-full bg-fuchsia-400/25 blur-3xl opacity-60 dark:opacity-25`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-b from-transparent via-background/40 to-background`})]}),(0,X.jsx)(`section`,{className:`px-4 sm:px-6 lg:px-8 pt-10 pb-6`,children:(0,X.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-3`,children:[(0,X.jsx)(xe,{className:`h-3.5 w-3.5 text-primary`}),(0,X.jsx)(`span`,{className:`uppercase tracking-wider`,children:t(`home.title`,{defaultValue:`Home`})})]}),(0,X.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-pretty`,children:[(0,X.jsxs)(`span`,{className:`bg-gradient-to-r from-foreground via-foreground to-foreground/70 bg-clip-text text-transparent`,children:[d,f?`, ${f}`:``]}),(0,X.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,X.jsx)(`p`,{className:`text-base sm:text-lg text-muted-foreground mt-2 max-w-2xl`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})})]})}),(0,X.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pb-16`,children:(0,X.jsxs)(`div`,{className:`max-w-7xl mx-auto space-y-10`,children:[u.length===0&&l.length===0&&(0,X.jsx)(vf,{t}),u.length>0&&(0,X.jsx)(gf,{items:u}),l.length>0&&(0,X.jsx)(pf,{items:l}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-end justify-between mb-5`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[c.length,` · `,t(`home.stats.apps`,{defaultValue:`Applications`})]})]}),s&&(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,X.jsx)(Xe,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:c.map((t,n)=>(0,X.jsx)(uf,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function bf({children:e}){let{setContext:t}=Ao();return(0,Y.useEffect)(()=>{t(`home`)},[t]),(0,X.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,X.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,X.jsx)(Xs,{variant:`orgs`})}),(0,X.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function xf(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function Sf({open:e,onOpenChange:t,onCreated:n}){let{t:r}=R(),{createOrganization:i,getAuthConfig:a}=C(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,Y.useEffect)(()=>{u||l(xf(o))},[o,u]),(0,Y.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,X.jsx)(We,{open:e,onOpenChange:t,children:(0,X.jsx)(ot,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,X.jsxs)(`form`,{onSubmit:(0,Y.useCallback)(async e=>{if(e.preventDefault(),!(!o.trim()||!c.trim())){if(g){h(r(`workspace.multiOrgDisabled`,{defaultValue:`Creating new organizations is disabled on this instance.`}));return}p(!0),h(null);try{let e=await i({name:o.trim(),slug:c.trim()});n?.(e)}catch(e){h(e instanceof Error?e.message:`Failed to create workspace`)}finally{p(!1)}}},[o,c,i,n]),children:[(0,X.jsxs)(ia,{children:[(0,X.jsx)(De,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,X.jsx)(xt,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(Nr,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,X.jsx)(K,{id:`workspace-name`,placeholder:r(`workspace.namePlaceholder`,{defaultValue:`e.g., Acme Inc`}),value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`workspace-name-input`})]}),(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(Nr,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,X.jsx)(K,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,X.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,X.jsxs)(q,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,X.jsx)(jr,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function Cf(e){if(e!==void 0)return new URL(`home`,e).toString();let t=document.querySelector(`base`)?.getAttribute(`href`),n=t?new URL(t,window.location.origin):new URL(`/`,window.location.origin);return new URL(`home`,n).toString()}function wf(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Tf(){let{t:e}=R(),t=v(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a,getAuthConfig:o}=C(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{let e=!1;return o().then(t=>{e||t?.features?.multiOrgEnabled===!1&&m(!1)}).catch(()=>{}),()=>{e=!0}},[o]);let h=n??[],g=(0,Y.useMemo)(()=>{let e=s.trim().toLowerCase();return e?h.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):h},[h,s]),_=async e=>{f(e.id);try{e.id!==r?.id&&await a(e.id),window.location.href=Cf()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),f(null)}},y=e=>{u(!1),_(e)},b=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{b.current||i||h.length===1&&(b.current=!0,_(h[0]))},[i,h.length]);let x=!i&&h.length===1;return i||x?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,X.jsx)(jr,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,X.jsxs)(`div`,{className:`mb-8`,children:[(0,X.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select an organization to continue, or create a new one.`})})]}),(0,X.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,X.jsx)(Ai,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(K,{value:s,onChange:e=>c(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),p&&(0,X.jsxs)(q,{onClick:()=>u(!0),"data-testid":`organizations-new`,children:[(0,X.jsx)(fn,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,X.jsx)(rt,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),p&&(0,X.jsxs)(q,{className:`mt-6`,onClick:()=>u(!0),children:[(0,X.jsx)(fn,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):g.length===0?(0,X.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No organizations match your search.`})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:g.map(n=>{let i=n.id===r?.id,a=d===n.id;return(0,X.jsxs)(`button`,{onClick:()=>_(n),disabled:a,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,X.jsxs)(ye,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,X.jsx)(Di,{src:n.logo,alt:n.name}),(0,X.jsx)(hr,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:wf(n.name)})]}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,X.jsx)(`span`,{className:`text-xs text-primary underline-offset-4 hover:underline shrink-0`,onClick:e=>{e.stopPropagation(),t(`/organizations/${n.slug}/members`)},children:e(`organizations.manage`,{defaultValue:`Manage`})}),a&&(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,X.jsx)(Sf,{open:l,onOpenChange:u,onCreated:y})]})}function Ef(e){if(!e)return``;let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=Date.now()-t.getTime(),r=60*1e3,i=60*r,a=24*i;return n<r?`just now`:n<i?`${Math.floor(n/r)}m ago`:n<a?`${Math.floor(n/i)}h ago`:n<7*a?`${Math.floor(n/a)}d ago`:t.toLocaleDateString()}function Df({userId:e,apiBase:t,className:n,refreshKey:r}){let i=v(),{conversationId:o}=a(),{conversations:s,isLoading:c,error:l,remove:u,rename:d}=Xu({userId:e,apiBase:t,refreshKey:r}),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(void 0),g=(0,Y.useMemo)(()=>{let e=f.trim().toLowerCase();return e?s.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):s},[s,f]),_=(0,Y.useCallback)(()=>i(`/ai`),[i]),y=(0,Y.useCallback)(async(e,t)=>{e.stopPropagation(),await u(t),t===o&&i(`/ai`,{replace:!0})},[u,o,i]),b=(0,Y.useCallback)(async(e,t)=>{h(void 0);try{await d(e,t)}catch{}},[d]);return(0,X.jsxs)(`aside`,{className:gr(`flex h-full min-h-0 flex-col bg-muted/30`,n),"data-testid":`ai-conversations-sidebar`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`Chats`}),(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:_,"data-testid":`ai-new-chat`,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5`}),`New`]})]}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Ai,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(K,{value:f,onChange:e=>p(e.target.value),placeholder:`Search chats...`,className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,X.jsx)(yn,{className:`flex-1 min-h-0`,children:c&&s.length===0?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`Loading…`}):l?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:l.message}):s.length===0?(0,X.jsxs)(Ve,{className:`px-3 py-8`,children:[(0,X.jsx)(Mn,{className:`h-8 w-8 text-muted-foreground`}),(0,X.jsx)(ta,{children:`No chats yet`}),(0,X.jsx)(rt,{children:`Start a new conversation to see it here.`})]}):g.length===0?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`No matching chats.`}):(0,X.jsx)(`ul`,{className:`flex flex-col py-1`,children:g.map(e=>(0,X.jsx)(Of,{conversation:e,active:e.id===o,renaming:e.id===m,onSelect:()=>i(`/ai/${e.id}`),onDelete:t=>y(t,e.id),onStartRename:()=>h(e.id),onCancelRename:()=>h(void 0),onSubmitRename:t=>b(e.id,t)},e.id))})})]})}function Of({conversation:e,active:t,renaming:n,onSelect:r,onDelete:i,onStartRename:a,onCancelRename:o,onSubmitRename:s}){let c=e.title?.trim()||e.preview?.trim()||`New conversation`,[l,u]=(0,Y.useState)(c),d=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{n&&(u(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>d.current?.select(),0))},[n,e.title,e.preview]),n?(0,X.jsx)(`li`,{children:(0,X.jsxs)(`div`,{className:gr(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,t?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,X.jsx)(K,{ref:d,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s(l)):e.key===`Escape`&&(e.preventDefault(),o())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":`Rename conversation`}),(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>s(l),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":`Save rename`,children:(0,X.jsx)(Ae,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:o,"aria-label":`Cancel rename`,children:(0,X.jsx)(Yi,{className:`h-3.5 w-3.5`})})]})}):(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:r,className:gr(`group flex w-full flex-col gap-0.5 border-l-2 border-transparent px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50`,t&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`line-clamp-1 flex-1 font-medium`,children:c}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),a()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),a())},className:`hover:text-primary`,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":`Rename conversation`,children:(0,X.jsx)(Ir,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),i(e)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),i(e))},className:`hover:text-destructive`,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":`Delete conversation`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]}),e.preview&&e.preview!==c?(0,X.jsx)(`span`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:e.preview}):null,(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Ef(e.updatedAt??e.createdAt)})]})})}var kf=`/api/v1/ai`;function Af(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${kf}`}function jf({apiBase:e,defaultAgent:t}={}){let{user:n}=C(),r=n?.id,{conversationId:i}=a(),o=v(),{setContext:s}=Ao();(0,Y.useEffect)(()=>{s(`home`)},[s]);let c=(0,Y.useMemo)(()=>Af(e),[e]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:u,isLoading:d,error:f}=Va({apiBase:c}),[p,m]=(0,Y.useState)(void 0);(0,Y.useEffect)(()=>{if(!p&&u.length>0){let e=t??l;m(((e?u.find(t=>t.name===e):void 0)??u[0]).name)}},[u,p,t,l]);let h=p?`${c}/agents/${encodeURIComponent(p)}/chat`:void 0,{conversationId:g,initialMessages:_,isLoading:y}=Ku({userId:r,scope:p,apiBase:c,activeId:i}),[b,x]=(0,Y.useState)(0),[S,w]=(0,Y.useState)(!1),T=(0,Y.useMemo)(()=>c.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[c]);(0,Y.useEffect)(()=>{!i&&g&&o(`/ai/${g}`,{replace:!0})},[i,g,o]);let E=(0,Y.useRef)(new Set);(0,Y.useEffect)(()=>{g&&_.length>0&&E.current.add(g)},[g,_.length]);let D=(0,Y.useCallback)(e=>{if(x(e=>e+1),!e||!g||E.current.has(g))return;E.current.add(g);let t=()=>x(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[g]);return(0,X.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,X.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:[(0,X.jsx)(Xs,{variant:`home`}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,X.jsxs)(q,{variant:`outline`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>w(!0),disabled:!g,"data-testid":`ai-chat-share-button`,title:g?`Share this conversation`:`Start chatting to enable sharing`,children:[(0,X.jsx)(ii,{className:`h-3.5 w-3.5`}),`Share`]})})]}),g&&(0,X.jsx)(Gi,{open:S,onOpenChange:w,objectName:`ai_conversations`,recordId:g,recordLabel:`this conversation`,apiBase:T}),(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0 w-full`,children:[(0,X.jsx)(Df,{userId:r,apiBase:c,refreshKey:b,className:`hidden w-72 shrink-0 border-r md:flex`}),(0,X.jsx)(`main`,{className:`flex flex-1 min-w-0 flex-col`,children:(0,X.jsx)(Mf,{agents:u,agentsLoading:d,agentsError:f,activeAgent:p,onAgentChange:m,chatApi:h,apiBase:c,conversationId:g,initialMessages:_,hydrating:y,onSent:D},`${h??`local`}:${g??`pending`}`)})]})]})}function Mf({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,onAgentChange:i,chatApi:a,apiBase:o,conversationId:s,initialMessages:c,hydrating:l,onSent:u}){let d=(0,Y.useMemo)(()=>e.find(e=>e.name===r)?.label??r??`Assistant`,[e,r]),f=(0,Y.useMemo)(()=>c.map(e=>({id:e.id,role:e.role,content:e.parts.map(e=>e.text).join(``)})),[c]),p=(0,Y.useMemo)(()=>{if(!(f.length>0))return Ff(r,d)},[f.length,r,d]),{messages:m,isLoading:h,error:g,sendMessage:_,stop:v,reload:y,clear:b}=Ua({api:a,conversationId:s,body:{context:{activeApp:`AI`,agentName:r}},initialMessages:f,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600}),x=Ha({messages:m,apiBase:o,continueConversation:e=>{_(e)}}),S=(0,Y.useCallback)((e,t)=>{_(e,t),u(e)},[_,u]);return(0,X.jsx)(Ba,{className:`flex-1 min-h-0 rounded-none border-0`,maxHeight:`100%`,headerSlot:e.length>0?(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Agent:`}),(0,X.jsxs)(on,{value:r,onValueChange:i,disabled:t,children:[(0,X.jsx)(Tn,{className:`h-7 w-[220px] text-xs`,"data-testid":`ai-chat-agent-picker`,children:(0,X.jsx)(nt,{placeholder:`Choose agent...`})}),(0,X.jsx)(oa,{align:`start`,children:e.map(e=>(0,X.jsxs)(Oe,{value:e.name,className:`text-xs`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,X.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}),l?(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Loading history…`}):null,n?(0,X.jsx)(`span`,{className:`text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:`⚠ Offline demo mode — agent list unavailable`}):null]}):null,messages:m,placeholder:r?`Ask ${d}… (try “${p?.[0]??`How can you help?`}”)`:t?`Loading agents…`:`Ask anything…`,suggestions:p,onSendMessage:S,onClear:b,onStop:h?v:void 0,onReload:y,isLoading:h,error:g,enableMarkdown:!0,onToolApprove:x.decide,toolDecisions:x.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,"data-testid":`ai-chat-panel`})}var Nf={data_chat:[`系统里有多少个用户?列出他们的邮箱。`,`帮我列出最近创建的 5 条记录。`,`统计每个对象的记录数。`],metadata_assistant:[`系统里注册了哪些对象类型?`,`sys_user 对象有哪些字段?`,`描述一下用户相关的对象关系。`]},Pf=[`What can you help me with?`,`List the available data objects.`,`Summarize my recent activity.`];function Ff(e,t){if(e&&Nf[e])return Nf[e];let n=(e??t).toLowerCase();return n.includes(`data`)?Nf.data_chat:n.includes(`metadata`)?Nf.metadata_assistant:Pf}var If=new Map;function Lf(e){If.set(e.ref,e)}function Rf(e){return If.get(e)}function zf(e){return(0,Y.useMemo)(()=>{let t=new V({baseUrl:``});return e?t.withEnvironment(e):t},[e])}function Bf(e){let[t,n]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)([]);return(0,Y.useEffect)(()=>{let t=!1;return n(!0),i(null),(async()=>{try{let r=await e.listTypes(),i;if(Array.isArray(r))i=r.map(e=>typeof e==`string`?{type:e}:e);else{let e=r?.entries;i=Array.isArray(e)&&e.length>0?e:(r?.types??[]).map(e=>({type:e}))}t||(o(i),n(!1))}catch(e){t||(i(e?.message??String(e)),n(!1))}})(),()=>{t=!0}},[e]),{loading:t,error:r,entries:a}}function Vf(e,t,n=[`name`,`label`,`description`]){if(!t)return!0;let r=t.toLowerCase();for(let t of n){let n=e[t];if(typeof n==`string`&&n.toLowerCase().includes(r))return!0}return!1}var Hf={object:`Object`,field:`Field`,trigger:`Trigger`,validation:`Validation Rule`,hook:`Hook`,view:`View`,page:`Page`,dashboard:`Dashboard`,app:`Application`,action:`Action`,report:`Report`,flow:`Flow`,workflow:`Workflow`,approval:`Approval Process`,datasource:`Datasource`,translation:`Translation`,router:`Router`,function:`Function`,service:`Service`,email_template:`Email Template`,permission:`Permission Set`,profile:`Profile`,role:`Role`,agent:`AI Agent`,tool:`AI Tool`,skill:`AI Skill`,package:`Package`,data:`Dataset`,job:`Background Job`},Uf={object:`对象`,field:`字段`,trigger:`触发器`,validation:`校验规则`,hook:`钩子`,view:`视图`,page:`页面`,dashboard:`仪表板`,app:`应用`,action:`操作`,report:`报表`,flow:`流程`,workflow:`工作流`,approval:`审批流程`,datasource:`数据源`,translation:`翻译`,router:`路由`,function:`函数`,service:`服务`,email_template:`邮件模板`,permission:`权限集`,profile:`配置文件`,role:`角色`,agent:`AI 智能体`,tool:`AI 工具`,skill:`AI 技能`,package:`包`,data:`数据集`,job:`后台任务`},Wf={data:`Data`,ui:`UI`,automation:`Automation`,ai:`AI`,system:`System`,platform:`Platform`,identity:`Identity`,security:`Security`,other:`Other`},Gf={data:`数据`,ui:`界面`,automation:`自动化`,ai:`AI`,system:`系统`,platform:`平台`,identity:`身份`,security:`安全`,other:`其他`},Kf={"engine.directory.title":`All Metadata Types`,"engine.directory.description":`The platform protocol exposes {count} metadata types ({writable} writable at runtime). Click any tile to browse, override, or create instances.`,"engine.directory.search":`Search metadata types…`,"engine.directory.writableOnly":`Writable only`,"engine.directory.quickFind":`Quick Find`,"engine.directory.noMatches":`No matches`,"engine.directory.noMatchesHint":`Adjust your search or filters to see more metadata types.`,"engine.directory.loading":`Loading metadata types…`,"engine.directory.loadFailed":`Failed to load metadata types`,"engine.directory.all":`All`,"engine.list.create":`New`,"engine.list.refresh":`Refresh`,"engine.list.search":`Search name, label, description…`,"engine.list.empty":`No items yet.`,"engine.list.items":`Items`,"engine.list.filtered":`Filtered`,"engine.list.invalid":`Invalid`,"engine.list.invalidTitle":`Invalid metadata`,"engine.list.invalidCount":`{count} validation error(s):`,"engine.list.allSources":`All sources`,"engine.list.source.artifact":`Artifact`,"engine.list.source.runtime":`Runtime`,"engine.list.source.artifactDesc":`Shipped by code package`,"engine.list.source.runtimeDesc":`Authored at runtime`,"engine.list.col.name":`Name`,"engine.list.col.label":`Label`,"engine.list.col.source":`Source`,"engine.list.col.object":`Object`,"engine.list.col.type":`Type`,"engine.list.col.description":`Description`,"engine.list.emptyType":`No {type} items registered`,"engine.list.emptyQuery":`No matches for "{query}"`,"engine.list.createHint":`Click "New" above to create the first {type}.`,"engine.list.readOnlyHint":`This type is read-only — instances are defined by code artifacts in packages.`,"engine.edit.save":`Save`,"engine.edit.publish":`Publish`,"engine.edit.publishBlockedDirty":`Save first, then publish.`,"engine.edit.discardDraft":`Discard draft`,"engine.edit.discardDraftConfirm":`Discard the pending draft for {type}/{name}?`,"engine.edit.draftPending":`Pending changes — save lives in a draft. Click Publish to release.`,"engine.edit.rollback":`Rollback to this version`,"engine.edit.rollbackConfirm":`Restore version {version}? This writes the historical body back as the current published overlay.`,"engine.edit.reset":`Reset overlay`,"engine.edit.resetConfirm":`Reset overlay for {type}/{name}?`,"engine.edit.delete":`Delete`,"engine.edit.deleteConfirm":`Delete {type}/{name}? This cannot be undone.`,"engine.edit.history":`History`,"engine.edit.layers":`Layers`,"engine.layers.code":`Code`,"engine.layers.overlay":`Overlay`,"engine.layers.effective":`Effective`,"engine.layers.diff":`Diff`,"engine.layers.diff.field":`Field`,"engine.layers.diff.code":`Code (artifact)`,"engine.layers.diff.effective":`Effective`,"engine.layers.diff.status":`Status`,"engine.layers.diff.unchanged":`unchanged`,"engine.layers.diff.modified":`modified`,"engine.layers.diff.added":`added`,"engine.layers.diff.removed":`removed`,"engine.layers.diff.showUnchanged":`Show unchanged`,"engine.layers.diff.noChanges":`Overlay matches the code value — no field-level differences.`,"engine.layers.diff.noBaseline":`No code-level artifact to compare against. All fields are runtime-authored.`,"engine.layers.diff.summary":`{modified} modified · {added} added · {removed} removed`,"engine.edit.overlaidCount":`{count} overlaid`,"engine.edit.noOverlay":`no overlay`,"engine.edit.references":`References`,"engine.edit.form":`Form`,"engine.edit.edit":`Edit`,"engine.edit.editOverlay":`Edit overlay`,"engine.edit.createNew":`Create new`,"engine.edit.detail":`Detail`,"engine.edit.preview":`Preview`,"engine.edit.designer":`Designer`,"engine.edit.related":`Related`,"engine.edit.hideInspector":`Hide inspector`,"engine.edit.showInspector":`Show inspector`,"engine.edit.noChanges":`No changes to save`,"engine.edit.inspector":`Inspector`,"engine.edit.inspector.properties":`Properties`,"engine.edit.inspector.source":`Source`,"engine.edit.fullscreen":`Fullscreen`,"engine.edit.exitFullscreen":`Exit fullscreen`,"engine.edit.designMode":`Design`,"engine.edit.previewMode":`Preview`,"engine.inspector.widget.kind":`Widget`,"engine.inspector.widget.close":`Close widget`,"engine.inspector.widget.title":`Title`,"engine.inspector.widget.type":`Type`,"engine.inspector.widget.object":`Data Source (Object)`,"engine.inspector.widget.valueField":`Value Field`,"engine.inspector.widget.categoryField":`Category Field`,"engine.inspector.widget.aggregate":`Aggregate`,"engine.inspector.widget.color":`Color Variant`,"engine.inspector.widget.width":`Width`,"engine.inspector.widget.height":`Height`,"engine.inspector.widget.remove":`Remove widget`,"engine.inspector.flowNode.kind":`Node`,"engine.inspector.flowNode.close":`Close node`,"engine.inspector.flowNode.id":`ID`,"engine.inspector.flowNode.label":`Label`,"engine.inspector.flowNode.type":`Node Type`,"engine.inspector.flowNode.config":`Config (JSON)`,"engine.inspector.flowNode.remove":`Remove node`,"engine.inspector.approvalStep.kind":`Step`,"engine.inspector.approvalStep.close":`Close step`,"engine.inspector.approvalStep.name":`Name (machine)`,"engine.inspector.approvalStep.label":`Label`,"engine.inspector.approvalStep.description":`Description`,"engine.inspector.approvalStep.behavior":`Behavior`,"engine.inspector.approvalStep.entryCriteria":`Entry criteria (CEL)`,"engine.inspector.approvalStep.rejectionBehavior":`Rejection behavior`,"engine.inspector.approvalStep.remove":`Remove step`,"engine.inspector.workflowAction.kind":`Action`,"engine.inspector.workflowAction.close":`Close action`,"engine.inspector.workflowAction.type":`Action Type`,"engine.inspector.workflowAction.name":`Name`,"engine.inspector.workflowAction.config":`Config (JSON)`,"engine.inspector.workflowAction.remove":`Remove action`,"engine.inspector.appNav.kind":`Nav Item`,"engine.inspector.appNav.close":`Close nav item`,"engine.inspector.appNav.label":`Label`,"engine.inspector.appNav.path":`Path / Route`,"engine.inspector.appNav.icon":`Icon`,"engine.inspector.appNav.kindField":`Kind`,"engine.inspector.appNav.remove":`Remove nav item`,"engine.inspector.viewColumn.kind":`Column`,"engine.inspector.viewColumn.close":`Close column`,"engine.inspector.viewColumn.header":`Header`,"engine.inspector.viewColumn.accessorKey":`Field key`,"engine.inspector.viewColumn.width":`Width`,"engine.inspector.viewColumn.align":`Align`,"engine.inspector.viewColumn.sortable":`Sortable`,"engine.inspector.viewColumn.filterable":`Filterable`,"engine.inspector.viewColumn.remove":`Remove column`,"engine.inspector.viewColumn.outlineLabel":`Columns`,"engine.inspector.pageBlock.kind":`Block`,"engine.inspector.pageBlock.close":`Close block`,"engine.inspector.pageBlock.type":`Type`,"engine.inspector.pageBlock.id":`ID`,"engine.inspector.pageBlock.className":`Class names`,"engine.inspector.pageBlock.hidden":`Hidden (CEL)`,"engine.inspector.pageBlock.remove":`Remove block`,"engine.inspector.pageBlock.outlineLabel":`Blocks`,"engine.inspector.reportColumn.kind":`Column`,"engine.inspector.reportColumn.close":`Close column`,"engine.inspector.reportColumn.field":`Field`,"engine.inspector.reportColumn.label":`Label`,"engine.inspector.reportColumn.aggregate":`Aggregate`,"engine.inspector.reportColumn.remove":`Remove column`,"engine.inspector.reportColumn.outlineLabel":`Columns`,"engine.inspector.add.widget":`Add widget`,"engine.inspector.add.column":`Add column`,"engine.inspector.add.block":`Add block`,"engine.inspector.add.node":`Add node`,"engine.inspector.add.step":`Add step`,"engine.inspector.add.action":`Add action`,"engine.inspector.add.nav":`Add nav item`,"engine.inspector.reorder.up":`Move up`,"engine.inspector.reorder.down":`Move down`,"engine.edit.overlay":`overlay`,"engine.edit.readOnlyBanner":`Viewing in read-only mode. Click {edit} to make changes.`,"engine.edit.readOnlyTypeBanner":`This metadata type is read-only for safety: it ships executable code or sensitive configuration and cannot be overlaid at runtime. Edit the source in your package and redeploy. To override this lock (use with caution), set {flag} to include {type}, or flip {override} in the registry.`,"engine.edit.artifactLockedBanner":`This item is shipped by a code package and cannot be modified at runtime. You can still create your own {type} from scratch and freely edit or delete it.`,"engine.badge.createOnly":`create-only`,"engine.repeater.empty":`No items. Click + to add.`,"engine.badge.writable":`writable`,"engine.badge.readOnly":`read-only`,"engine.edit.readOnly":`Read-only (runtime overrides disabled).`,"engine.edit.loading":`Loading`,"engine.edit.bespokeDesigner":`Designer`,"engine.edit.readOnlyHint":`Read-only — this metadata type does not allow runtime overrides. Edit the source in the package and redeploy.`,"engine.edit.unsaved":`Unsaved`,"engine.edit.unsavedHint":`You have unsaved changes.`,"engine.edit.diagnostics.title":`This metadata does not match the spec — {count} validation error(s).`,"engine.edit.diagnostics.more":`+{count} more…`,"engine.edit.unsavedLeaveConfirm":`You have unsaved changes. Leave this page anyway?`,"engine.edit.saving":`Saving…`,"engine.edit.savedAt":`Saved {time}`,"engine.edit.autoSaveOn":`Auto-save is on — click to disable`,"engine.edit.autoSaveOff":`Auto-save is off — click to enable`,"engine.edit.autoSavingShortly":`Auto-saving…`,"engine.edit.destructive":`Destructive change`,"engine.edit.destructiveHint":`The change would break existing references. Review the issues and confirm to force-save.`,"engine.edit.forceSave":`Force save`,"engine.cancel":`Cancel`,"engine.quickfind.placeholder":`Find metadata types or items… (try 'view', 'account')`,"engine.quickfind.empty":`Type to search across all metadata types.`,"engine.quickfind.title":`Quick Find`,"engine.quickfind.indexing":`Indexing items across`,"engine.quickfind.noMatches":`No matches.`,"engine.breadcrumb.allTypes":`All Metadata Types`,"perm.action.create":`Create`,"perm.action.read":`Read`,"perm.action.edit":`Edit`,"perm.action.delete":`Delete`,"perm.action.transfer":`Transfer ownership`,"perm.action.restore":`Restore from trash`,"perm.action.purge":`Hard delete (purge)`,"perm.action.viewAll":`View All Records (bypass sharing)`,"perm.action.modifyAll":`Modify All Records (bypass sharing)`,"perm.col.object":`Object`,"perm.col.bulk":`Bulk`,"perm.bulk.read":`R`,"perm.bulk.crud":`CRUD`,"perm.bulk.all":`All`,"perm.bulk.none":`None`,"perm.filter.placeholder":`Filter objects…`,"perm.filter.onlyGranted":`Only granted`,"perm.filter.empty":`No objects match the filter.`,"perm.field.name":`Name`,"perm.field.label":`Label`,"perm.field.isProfile":`Is profile`,"perm.field.loading":`Loading fields…`,"perm.field.empty":`No fields registered for this object.`,"perm.field.col.name":`Field`,"perm.field.read":`Read`,"perm.field.edit":`Edit`,"perm.stat.objects":`Objects granted`,"perm.stat.fields":`Fields granted`,"perm.stat.objectsGranted":`Objects granted`,"perm.stat.fieldOverrides":`Field overrides`,"perm.stat.objectsSuffix":`objects`,"perm.subtitle.profile":`Profile`,"perm.subtitle.set":`Permission set`,"perm.loading":`Loading permission set {name}…`,"perm.readOnly":`Read-only (OS_METADATA_WRITABLE not enabled)`,"designer.unsavedChanges":`Unsaved changes`,"designer.editingOverlay":`Editing overlay`,"designer.codeBaseline":`Code baseline`},qf={"engine.directory.title":`元数据`,"engine.directory.description":`平台协议共暴露 {count} 个元数据类型(其中 {writable} 个支持运行时覆盖)。点击任意卡片即可浏览、覆盖或创建实例。`,"engine.directory.search":`搜索元数据类型…`,"engine.directory.writableOnly":`仅显示可写`,"engine.directory.quickFind":`快速查找`,"engine.directory.noMatches":`没有匹配项`,"engine.directory.noMatchesHint":`调整搜索或筛选条件以查看更多元数据类型。`,"engine.directory.loading":`正在加载元数据类型…`,"engine.directory.loadFailed":`加载元数据类型失败`,"engine.directory.all":`全部`,"engine.list.create":`新建`,"engine.list.refresh":`刷新`,"engine.list.search":`搜索名称、标签或描述…`,"engine.list.empty":`暂无数据。`,"engine.list.items":`条目`,"engine.list.filtered":`已筛选`,"engine.list.invalid":`无效`,"engine.list.invalidTitle":`元数据无效`,"engine.list.invalidCount":`{count} 个校验错误:`,"engine.list.allSources":`全部来源`,"engine.list.source.artifact":`代码包`,"engine.list.source.runtime":`运行时`,"engine.list.source.artifactDesc":`由代码包提供`,"engine.list.source.runtimeDesc":`运行时创建`,"engine.list.col.name":`名称`,"engine.list.col.label":`标签`,"engine.list.col.source":`来源`,"engine.list.col.object":`对象`,"engine.list.col.type":`类型`,"engine.list.col.description":`描述`,"engine.list.emptyType":`暂无 {type} 条目`,"engine.list.emptyQuery":`没有匹配 "{query}" 的结果`,"engine.list.createHint":`点击上方"新建"创建第一个 {type}。`,"engine.list.readOnlyHint":`此类型为只读 — 实例由包内的代码工件定义。`,"engine.edit.save":`保存`,"engine.edit.publish":`发布`,"engine.edit.publishBlockedDirty":`请先保存再发布。`,"engine.edit.discardDraft":`丢弃草稿`,"engine.edit.discardDraftConfirm":`丢弃 {type}/{name} 的待发布草稿?`,"engine.edit.draftPending":`存在未发布的草稿 — 保存仅写入草稿,点击"发布"使其生效。`,"engine.edit.rollback":`回滚到此版本`,"engine.edit.rollbackConfirm":`恢复版本 {version}?该历史内容将被写回作为当前已发布的覆盖层。`,"engine.edit.reset":`重置覆盖`,"engine.edit.resetConfirm":`重置 {type}/{name} 的覆盖层?`,"engine.edit.delete":`删除`,"engine.edit.deleteConfirm":`删除 {type}/{name}?此操作不可撤销。`,"engine.edit.history":`历史`,"engine.edit.layers":`层次`,"engine.layers.code":`代码`,"engine.layers.overlay":`覆盖`,"engine.layers.effective":`生效`,"engine.layers.diff":`差异`,"engine.layers.diff.field":`字段`,"engine.layers.diff.code":`代码(工件)`,"engine.layers.diff.effective":`生效值`,"engine.layers.diff.status":`状态`,"engine.layers.diff.unchanged":`未变更`,"engine.layers.diff.modified":`已修改`,"engine.layers.diff.added":`新增`,"engine.layers.diff.removed":`删除`,"engine.layers.diff.showUnchanged":`显示未变更字段`,"engine.layers.diff.noChanges":`覆盖层与代码值一致——没有字段级差异。`,"engine.layers.diff.noBaseline":`没有代码级工件可比对——所有字段均为运行时创建。`,"engine.layers.diff.summary":`{modified} 修改 · {added} 新增 · {removed} 删除`,"engine.edit.overlaidCount":`{count} 处覆盖`,"engine.edit.noOverlay":`无覆盖`,"engine.edit.references":`引用关系`,"engine.edit.form":`表单`,"engine.edit.edit":`编辑`,"engine.edit.editOverlay":`编辑覆盖层`,"engine.edit.createNew":`新建`,"engine.edit.detail":`详情`,"engine.edit.preview":`预览`,"engine.edit.designer":`可视化编辑器`,"engine.edit.related":`关联`,"engine.edit.hideInspector":`隐藏属性面板`,"engine.edit.showInspector":`显示属性面板`,"engine.edit.noChanges":`没有需要保存的更改`,"engine.edit.inspector":`属性`,"engine.edit.inspector.properties":`属性`,"engine.edit.inspector.source":`源码`,"engine.edit.fullscreen":`全屏`,"engine.edit.exitFullscreen":`退出全屏`,"engine.edit.designMode":`设计`,"engine.edit.previewMode":`预览`,"engine.inspector.widget.kind":`组件`,"engine.inspector.widget.close":`关闭组件`,"engine.inspector.widget.title":`标题`,"engine.inspector.widget.type":`类型`,"engine.inspector.widget.object":`数据源(对象)`,"engine.inspector.widget.valueField":`取值字段`,"engine.inspector.widget.categoryField":`分组字段`,"engine.inspector.widget.aggregate":`聚合方式`,"engine.inspector.widget.color":`颜色`,"engine.inspector.widget.width":`宽度`,"engine.inspector.widget.height":`高度`,"engine.inspector.widget.remove":`删除组件`,"engine.inspector.flowNode.kind":`节点`,"engine.inspector.flowNode.close":`关闭节点`,"engine.inspector.flowNode.id":`ID`,"engine.inspector.flowNode.label":`标签`,"engine.inspector.flowNode.type":`节点类型`,"engine.inspector.flowNode.config":`配置(JSON)`,"engine.inspector.flowNode.remove":`删除节点`,"engine.inspector.approvalStep.kind":`审批步骤`,"engine.inspector.approvalStep.close":`关闭步骤`,"engine.inspector.approvalStep.name":`机器名`,"engine.inspector.approvalStep.label":`标签`,"engine.inspector.approvalStep.description":`描述`,"engine.inspector.approvalStep.behavior":`审批策略`,"engine.inspector.approvalStep.entryCriteria":`进入条件(CEL)`,"engine.inspector.approvalStep.rejectionBehavior":`拒绝行为`,"engine.inspector.approvalStep.remove":`删除步骤`,"engine.inspector.workflowAction.kind":`动作`,"engine.inspector.workflowAction.close":`关闭动作`,"engine.inspector.workflowAction.type":`动作类型`,"engine.inspector.workflowAction.name":`名称`,"engine.inspector.workflowAction.config":`配置(JSON)`,"engine.inspector.workflowAction.remove":`删除动作`,"engine.inspector.appNav.kind":`导航项`,"engine.inspector.appNav.close":`关闭导航项`,"engine.inspector.appNav.label":`名称`,"engine.inspector.appNav.path":`路径 / 路由`,"engine.inspector.appNav.icon":`图标`,"engine.inspector.appNav.kindField":`类型`,"engine.inspector.appNav.remove":`删除导航项`,"engine.inspector.viewColumn.kind":`列`,"engine.inspector.viewColumn.close":`关闭列`,"engine.inspector.viewColumn.header":`表头`,"engine.inspector.viewColumn.accessorKey":`字段键`,"engine.inspector.viewColumn.width":`宽度`,"engine.inspector.viewColumn.align":`对齐`,"engine.inspector.viewColumn.sortable":`可排序`,"engine.inspector.viewColumn.filterable":`可过滤`,"engine.inspector.viewColumn.remove":`删除列`,"engine.inspector.viewColumn.outlineLabel":`列`,"engine.inspector.pageBlock.kind":`区块`,"engine.inspector.pageBlock.close":`关闭区块`,"engine.inspector.pageBlock.type":`类型`,"engine.inspector.pageBlock.id":`ID`,"engine.inspector.pageBlock.className":`类名`,"engine.inspector.pageBlock.hidden":`隐藏条件(CEL)`,"engine.inspector.pageBlock.remove":`删除区块`,"engine.inspector.pageBlock.outlineLabel":`区块`,"engine.inspector.reportColumn.kind":`列`,"engine.inspector.reportColumn.close":`关闭列`,"engine.inspector.reportColumn.field":`字段`,"engine.inspector.reportColumn.label":`标签`,"engine.inspector.reportColumn.aggregate":`聚合方式`,"engine.inspector.reportColumn.remove":`删除列`,"engine.inspector.reportColumn.outlineLabel":`列`,"engine.inspector.add.widget":`添加组件`,"engine.inspector.add.column":`添加列`,"engine.inspector.add.block":`添加区块`,"engine.inspector.add.node":`添加节点`,"engine.inspector.add.step":`添加步骤`,"engine.inspector.add.action":`添加动作`,"engine.inspector.add.nav":`添加导航项`,"engine.inspector.reorder.up":`上移`,"engine.inspector.reorder.down":`下移`,"engine.edit.overlay":`覆盖`,"engine.edit.readOnlyBanner":`当前为只读模式。点击 {edit} 进行修改。`,"engine.edit.readOnlyTypeBanner":`出于安全考虑,此元数据类型为只读:它包含可执行代码或敏感配置,不允许在运行时通过覆盖层修改。请编辑包内源代码后重新部署。如需临时解除限制(请谨慎使用),可将 {flag} 设置为包含 {type},或在注册表中开启 {override}。`,"engine.edit.artifactLockedBanner":`此条目由代码包提供,无法在运行时修改。但您可以新建自己的 {type},并自由地编辑或删除。`,"engine.badge.createOnly":`仅可新建`,"engine.repeater.empty":`暂无条目。点击 + 添加。`,"engine.badge.writable":`可写`,"engine.badge.readOnly":`只读`,"engine.edit.readOnly":`只读(运行时覆盖未启用)。`,"engine.edit.loading":`加载中`,"engine.edit.bespokeDesigner":`可视化编辑器`,"engine.edit.readOnlyHint":`只读 — 该元数据类型不支持运行时覆盖。请修改包内源代码并重新部署。`,"engine.edit.unsaved":`未保存`,"engine.edit.diagnostics.title":`元数据不符合规范 — 共 {count} 个校验错误。`,"engine.edit.diagnostics.more":`还有 {count} 个…`,"engine.edit.unsavedHint":`当前存在未保存的修改。`,"engine.edit.unsavedLeaveConfirm":`当前存在未保存的修改,确定离开此页面吗?`,"engine.edit.saving":`保存中…`,"engine.edit.savedAt":`已保存 {time}`,"engine.edit.autoSaveOn":`自动保存已开启,点击关闭`,"engine.edit.autoSaveOff":`自动保存已关闭,点击开启`,"engine.edit.autoSavingShortly":`即将自动保存…`,"engine.edit.destructive":`破坏性变更`,"engine.edit.destructiveHint":`该修改会破坏现有引用关系。请检查问题清单后确认强制保存。`,"engine.edit.forceSave":`强制保存`,"engine.cancel":`取消`,"engine.quickfind.placeholder":`搜索元数据类型或条目…(如:view、account)`,"engine.quickfind.empty":`输入关键字以搜索所有元数据类型。`,"engine.quickfind.title":`快速查找`,"engine.quickfind.indexing":`正在索引所有类型,共`,"engine.quickfind.noMatches":`没有匹配项。`,"engine.breadcrumb.allTypes":`元数据`,"perm.action.create":`创建`,"perm.action.read":`读取`,"perm.action.edit":`编辑`,"perm.action.delete":`删除`,"perm.action.transfer":`转移所有者`,"perm.action.restore":`从回收站恢复`,"perm.action.purge":`彻底删除`,"perm.action.viewAll":`查看所有记录(绕过共享规则)`,"perm.action.modifyAll":`修改所有记录(绕过共享规则)`,"perm.col.object":`对象`,"perm.col.bulk":`批量`,"perm.bulk.read":`读`,"perm.bulk.crud":`增改删`,"perm.bulk.all":`全选`,"perm.bulk.none":`清空`,"perm.filter.placeholder":`筛选对象…`,"perm.filter.onlyGranted":`只看已授权`,"perm.filter.empty":`没有匹配的对象。`,"perm.field.name":`名称`,"perm.field.label":`标签`,"perm.field.isProfile":`作为 Profile`,"perm.field.loading":`加载字段中…`,"perm.field.empty":`该对象未注册字段。`,"perm.field.col.name":`字段`,"perm.field.read":`读`,"perm.field.edit":`改`,"perm.stat.objects":`已授权对象`,"perm.stat.fields":`已授权字段`,"perm.stat.objectsGranted":`已授权对象`,"perm.stat.fieldOverrides":`字段覆盖`,"perm.stat.objectsSuffix":`个对象`,"perm.subtitle.profile":`Profile`,"perm.subtitle.set":`权限集`,"perm.loading":`加载权限集 {name}…`,"perm.readOnly":`只读(OS_METADATA_WRITABLE 未启用)`,"designer.unsavedChanges":`未保存的修改`,"designer.editingOverlay":`编辑覆盖层`,"designer.codeBaseline":`代码基线`};function Jf(e){return(e??``).toLowerCase().startsWith(`zh`)?{types:Uf,domains:Gf,strings:qf}:{types:Hf,domains:Wf,strings:Kf}}function Yf(e,t,n){return Jf(t).types[e]||(n??e)}function Xf(e,t){return Jf(t).domains[e]??e}function Z(e,t){return Jf(t).strings[e]??e}function Zf(e,t,n){return Z(e,t).replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):`{${t}}`)}function Qf(){return typeof navigator<`u`&&/^zh/i.test(navigator.language)?`zh-CN`:`en-US`}function $f({appSlug:e}={}){let t=v(),n=zf(),{entries:r}=Bf(n),[i,a]=Y.useState(!1),[o,s]=Y.useState(``),[c,l]=Y.useState(null),[u,d]=Y.useState(!1),[f,p]=Y.useState(0),m=Y.useMemo(()=>Qf(),[]);Y.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)},[]),Y.useEffect(()=>{if(!i||c!=null||u||r.length===0)return;d(!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})}}catch{}})),e||l(t)}finally{e||d(!1)}})(),()=>{e=!0}},[i,c,u,r,n]);let h=Y.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)||(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]);Y.useEffect(()=>{p(0)},[o,i]);function g(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 _(e){e.key===`ArrowDown`?(e.preventDefault(),p(e=>Math.min(e+1,h.length-1))):e.key===`ArrowUp`?(e.preventDefault(),p(e=>Math.max(e-1,0))):e.key===`Enter`&&h[f]&&(e.preventDefault(),g(h[f]))}return(0,X.jsx)(We,{open:i,onOpenChange:a,children:(0,X.jsxs)(ot,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,X.jsx)(ia,{className:`sr-only`,children:(0,X.jsx)(De,{children:Z(`engine.quickfind.title`,m)})}),(0,X.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,X.jsx)(Ai,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(K,{autoFocus:!0,placeholder:Z(`engine.quickfind.placeholder`,m),value:o,onChange:e=>s(e.target.value),onKeyDown:_,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,X.jsx)(Ht,{children:`esc`})]}),(0,X.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[u&&(0,X.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}),Z(`engine.quickfind.indexing`,m),` `,r.length,`…`]}),!u&&h.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:Z(`engine.quickfind.noMatches`,m)}),(0,X.jsx)(`ul`,{role:`listbox`,children:h.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>g(e),onMouseEnter:()=>p(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===f?`bg-accent`:``),children:[(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e.entry.label??e.entry.type}),e.entry.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-sm font-mono truncate`,children:[e.name,e.label&&(0,X.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,X.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,X.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(Ht,{children:`↑`}),` `,(0,X.jsx)(Ht,{children:`↓`}),` navigate`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(Ht,{children:`↵`}),` open`]}),(0,X.jsxs)(`span`,{className:`ml-auto`,children:[(0,X.jsx)(Ht,{children:`⌘`}),(0,X.jsx)(Ht,{children:`⇧`}),(0,X.jsx)(Ht,{children:`M`}),` toggle`]})]})]})})}var ep={data:Xt,ui:Jr,automation:je,ai:xe,system:bi,platform:bi,identity:Mr,security:Mr},tp=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],np=new Set([`field`]);function rp(){let{loading:e,error:t,entries:n}=Bf(zf()),r=Y.useMemo(()=>Qf(),[]),[i,a]=Y.useState(``),[o,s]=Y.useState(`all`),[c,l]=Y.useState(!1),u=Y.useMemo(()=>{let e=n.filter(e=>!np.has(e.type)),t={all:e.length};for(let n of e){let e=n.domain??`other`;t[e]=(t[e]??0)+1}return t},[n]),d=n.filter(e=>!np.has(e.type)&&(e.allowOrgOverride||e.allowRuntimeCreate)).length,f=n.filter(e=>{if(np.has(e.type)||c&&!(e.allowOrgOverride||e.allowRuntimeCreate)||o!==`all`&&(e.domain??`other`)!==o)return!1;if(i){let t=i.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),p=Y.useMemo(()=>{let e={};for(let t of f)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=tp.indexOf(e),r=tp.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[f]);return e?(0,X.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:Z(`engine.directory.loading`,r)}):t?(0,X.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[Z(`engine.directory.loadFailed`,r),`: `,t]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:Z(`engine.directory.title`,r)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:Zf(`engine.directory.description`,r,{count:`<strong class="text-foreground">${n.filter(e=>!np.has(e.type)).length}</strong>`,writable:d})}}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,X.jsx)(Ai,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(K,{className:`pl-8`,placeholder:Z(`engine.directory.search`,r),value:i,onChange:e=>a(e.target.value)})]}),(0,X.jsxs)(q,{variant:c?`default`:`outline`,size:`sm`,onClick:()=>l(e=>!e),children:[Z(`engine.directory.writableOnly`,r),` (`,d,`)`]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[Z(`engine.directory.quickFind`,r),` `,(0,X.jsx)(Ht,{children:`⌘`}),(0,X.jsx)(Ht,{children:`⇧`}),(0,X.jsx)(Ht,{children:`M`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,X.jsx)(ip,{domain:`all`,label:Z(`engine.directory.all`,r),active:o===`all`,count:u.all??0,onClick:()=>s(`all`)}),tp.filter(e=>u[e]).map(e=>(0,X.jsx)(ip,{domain:e,label:Xf(e,r),active:o===e,count:u[e]??0,onClick:()=>s(e)},e))]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[f.length===0&&(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:Z(`engine.directory.noMatches`,r)}),(0,X.jsx)(rt,{children:Z(`engine.directory.noMatchesHint`,r)})]}),p.map(([e,t])=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,X.jsx)(ep[e]??Kt,{className:`h-3.5 w-3.5`}),Xf(e,r),` (`,t.length,`)`]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>(0,X.jsx)(ap,{entry:e,locale:r},e.type))})]},e))]}),(0,X.jsx)($f,{})]})}function ip({domain:e,label:t,active:n,count:r,onClick:i}){return(0,X.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,X.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function ap({entry:e,locale:t}){let n=Yf(e.type,t,e.label);return(0,X.jsxs)(r,{to:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:border-primary hover:bg-accent transition-colors`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:n}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),e.allowOrgOverride?(0,X.jsx)(G,{className:`text-[10px] shrink-0 `+(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:Z(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,X.jsx)(G,{className:`text-[10px] shrink-0 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:Z(`engine.badge.createOnly`,t)}):(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] shrink-0 text-muted-foreground`,children:Z(`engine.badge.readOnly`,t)})]}),e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}function op({entry:e,itemName:t,subtitle:n,stats:i,actions:a,children:o}){let s=e?.type??``,c=Y.useMemo(()=>Qf(),[]),l=Yf(s,c,e?.label),{pathname:d}=u(),f=Y.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,X.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,X.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,X.jsx)(r,{to:f,className:`hover:text-foreground shrink-0`,children:Z(`engine.breadcrumb.allTypes`,c)}),(0,X.jsx)(tr,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(r,{to:`${f}/${encodeURIComponent(s)}`,className:`hover:text-foreground shrink-0`,children:l}),(0,X.jsx)(tr,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Xf(e.domain,c)}),e?.allowOrgOverride?(0,X.jsx)(G,{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:Z(`engine.badge.writable`,c)}):e?.allowRuntimeCreate?(0,X.jsx)(G,{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:Z(`engine.badge.createOnly`,c)}):(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:Z(`engine.badge.readOnly`,c)})]}),n&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[i?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,X.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),a]})]}):(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,X.jsx)(r,{to:f,className:`hover:text-foreground`,children:Z(`engine.breadcrumb.allTypes`,c)}),(0,X.jsx)(tr,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:l})]}),(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:l}),(0,X.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:s}),e?.domain&&(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Xf(e.domain,c)}),e?.allowOrgOverride?(0,X.jsx)(G,{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:Z(`engine.badge.writable`,c)}):e?.allowRuntimeCreate?(0,X.jsx)(G,{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:Z(`engine.badge.createOnly`,c)}):(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:Z(`engine.badge.readOnly`,c)})]}),n&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,X.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),a]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:o})]})}function sp(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 cp=new Map;function lp(e){let t=cp.get(e.type);if(!t){cp.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);cp.set(e.type,n)}function up(e){return cp.get(e)}function dp(e){let t=[];for(let n of cp.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 fp(e,t){let n=cp.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 pp(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 mp({type:e}){let t=a(),n=e??t.type??``,r=up(n);if(r?.ListPage){let e=r.ListPage;return(0,X.jsx)(e,{type:n})}return(0,X.jsx)(hp,{type:n})}function hp({type:e}){let t=v(),n=zf(),{entries:i}=Bf(n),a=i.find(t=>t.type===e),o=fp(e,a),[s,c]=Y.useState([]),[l,u]=Y.useState(!0),[d,f]=Y.useState(null),[p,m]=Y.useState(``),[h,g]=Y.useState(`all`),[_,y]=Y.useState(0);Y.useEffect(()=>{let t=!1;return u(!0),f(null),(async()=>{try{let r=await n.list(e);if(t)return;c((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:pp(t,e?.source),diagnostics:n}})),u(!1)}catch(e){t||(f(e?.message??String(e)),u(!1))}})(),()=>{t=!0}},[n,e,_]);let b=o.searchableFields??[`name`,`label`,`description`],x=s.filter(e=>!(!Vf(e.item,p,b)||h!==`all`&&e.source!==h)),S=Y.useMemo(()=>{let e={all:s.length,artifact:0,runtime:0};for(let t of s)e[t.source]++;return e},[s]),C=Y.useMemo(()=>s.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[s]),w=o.listColumns??gp(o.primaryKey??`name`),T=Qf(),E=Yf(e,T,a?.label??e),D=e=>{let t=`engine.list.col.${e.key}`,n=Z(t,T);return n===t?e.label:n};return(0,X.jsx)(op,{entry:a??{type:e,label:e},stats:[{label:Z(`engine.list.items`,T),value:s.length},{label:Z(`engine.list.filtered`,T),value:x.length},...C>0?[{label:Z(`engine.list.invalid`,T),value:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,X.jsx)(Ot,{className:`w-3.5 h-3.5`}),C]})}]:[]],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>y(e=>e+1),title:Z(`engine.list.refresh`,T),children:(0,X.jsx)(Zi,{className:`h-4 w-4`})}),(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>t(`./new`),children:[(0,X.jsx)(fn,{className:`h-4 w-4 mr-1`}),Z(`engine.list.create`,T)]})]}),children:(0,X.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,X.jsx)(Ai,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(K,{className:`pl-8`,placeholder:Z(`engine.list.search`,T),value:p,onChange:e=>m(e.target.value)})]}),(0,X.jsxs)(on,{value:h,onValueChange:g,children:[(0,X.jsx)(Tn,{className:`w-[180px]`,children:(0,X.jsx)(nt,{})}),(0,X.jsxs)(oa,{children:[(0,X.jsxs)(Oe,{value:`all`,children:[Z(`engine.list.allSources`,T),` (`,S.all,`)`]}),(0,X.jsxs)(Oe,{value:`artifact`,children:[Z(`engine.list.source.artifact`,T),` (`,S.artifact,`)`]}),(0,X.jsxs)(Oe,{value:`runtime`,children:[Z(`engine.list.source.runtime`,T),` (`,S.runtime,`)`]})]})]})]}),l&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[Z(`engine.edit.loading`,T),` `,e,`…`]}),d&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:d}),!l&&!d&&x.length===0&&(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:s.length===0?Zf(`engine.list.emptyType`,T,{type:E}):Zf(`engine.list.emptyQuery`,T,{query:p})}),(0,X.jsx)(rt,{children:o.emptyStateHint??(a?.allowOrgOverride||a?.allowRuntimeCreate?Zf(`engine.list.createHint`,T,{type:E}):Z(`engine.list.readOnlyHint`,T))})]}),!l&&x.length>0&&(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[w.map(e=>(0,X.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:D(e)},e.key)),(0,X.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:Z(`engine.list.col.source`,T)})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:x.map((e,t)=>{let n=o.primaryKey??`name`,i=String(e.item[n]??`(unnamed-${t})`),a=e.diagnostics?.valid===!1,s=e.diagnostics?.errors??[],c=a?s.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
14
|
-
`)+(s.length>3?`\n+${s.length-3} more`:``):``;return(0,X.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(a?`bg-destructive/[0.04]`:``),children:[w.map((t,n)=>{let o=e.item[t.key],l=t.render?t.render(o,e.item):_p(o);return(0,X.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[a&&(0,X.jsx)(`span`,{className:`inline-flex`,"aria-label":Z(`engine.list.invalidTitle`,T),title:`${Zf(`engine.list.invalidCount`,T,{count:s.length})}\n${c}`,children:(0,X.jsx)(Ot,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),(0,X.jsx)(r,{to:`./${encodeURIComponent(i)}`,className:`text-primary hover:underline font-mono`,children:l})]}):l},t.key)}),(0,X.jsx)(`td`,{className:`px-3 py-2 text-right align-top`,children:(0,X.jsx)(G,{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`?`${Z(`engine.list.source.artifactDesc`,T)}${e.item._packageId?` (${e.item._packageId})`:``}`:Z(`engine.list.source.runtimeDesc`,T),children:Z(`engine.list.source.${e.source}`,T)})})]},i+t)})})]})})]})})}function gp(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function _p(e){if(e==null||e===``)return(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,X.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var vp={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 yp(e,t){let n=bp(e)?e:{},r=bp(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`:xp(o)===xp(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 bp(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xp(e){try{return JSON.stringify(e,(e,t)=>bp(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Sp(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 Cp(e,t){if(e==null)return 0;let n=0;for(let r of yp(e,t))r.status!==`unchanged`&&(n+=1);return n}function wp({layered:e,loading:t,locale:n}){if(t)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:Z(`engine.edit.loading`,n)});if(!e)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:Z(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,X.jsxs)(_e,{defaultValue:`diff`,className:`w-full`,children:[(0,X.jsxs)(Oi,{className:`grid grid-cols-4 w-fit`,children:[(0,X.jsx)(ni,{value:`diff`,children:Z(`engine.layers.diff`,n)}),(0,X.jsxs)(ni,{value:`code`,children:[Z(`engine.layers.code`,n),(0,X.jsx)(G,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,X.jsxs)(ni,{value:`overlay`,children:[Z(`engine.layers.overlay`,n),r?(0,X.jsx)(G,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,X.jsx)(G,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,X.jsxs)(ni,{value:`effective`,children:[Z(`engine.layers.effective`,n),(0,X.jsx)(G,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,X.jsx)(_r,{value:`diff`,className:`mt-3`,children:(0,X.jsx)(Tp,{code:e.code,effective:e.effective,locale:n})}),(0,X.jsx)(_r,{value:`code`,className:`mt-3`,children:(0,X.jsx)(Dp,{payload:e.code,emptyHint:Z(`engine.layers.diff.noBaseline`,n)})}),(0,X.jsx)(_r,{value:`overlay`,className:`mt-3`,children:(0,X.jsx)(Dp,{payload:e.overlay,emptyHint:Z(`engine.layers.diff.noChanges`,n)})}),(0,X.jsx)(_r,{value:`effective`,className:`mt-3`,children:(0,X.jsx)(Dp,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Tp({code:e,effective:t,locale:n}){let[r,i]=Y.useState(!1);if(e==null)return(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:Z(`engine.layers.diff.noBaseline`,n)});let a=Y.useMemo(()=>yp(e,t),[e,t]),o=Y.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,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Zf(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,X.jsx)(qr,{checked:r,onCheckedChange:i,"aria-label":Z(`engine.layers.diff.showUnchanged`,n)}),Z(`engine.layers.diff.showUnchanged`,n),(0,X.jsx)(G,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:Z(`engine.layers.diff.noChanges`,n)}):(0,X.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,X.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,X.jsx)(`div`,{className:`px-3 py-2`,children:Z(`engine.layers.diff.field`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:Z(`engine.layers.diff.code`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:Z(`engine.layers.diff.effective`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:Z(`engine.layers.diff.status`,n)})]}),(0,X.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=vp[e.status];return(0,X.jsxs)(`div`,{className:gr(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,X.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,X.jsx)(Ep,{value:e.codeValue,muted:e.status===`added`}),(0,X.jsx)(Ep,{value:e.effectiveValue,muted:e.status===`removed`}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(`span`,{className:gr(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:Z(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function Ep({value:e,muted:t}){let n=Sp(e);return(0,X.jsx)(`div`,{className:gr(`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 Dp({payload:e,emptyHint:t}){if(e==null)return(0,X.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,X.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}function Op(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return kp(n.trim(),t)}catch{return!0}}function kp(e,t){let n=Ap(e,`||`);if(n.length>1)return n.some(e=>kp(e.trim(),t));let r=Ap(e,`&&`);if(r.length>1)return r.every(e=>kp(e.trim(),t));if(e.startsWith(`!`))return!kp(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=jp(i[1].trim(),t),n=Mp(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=jp(a[1].trim(),t),n=Mp(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!jp(e,t)}function Ap(e,t){let n=[],r=0,i=null,a=``;for(let o=0;o<e.length;o++){let s=e[o];if(i){a+=s,s===i&&e[o-1]!==`\\`&&(i=null);continue}if(s===`'`||s===`"`){i=s,a+=s;continue}if(s===`(`||s===`[`?r++:(s===`)`||s===`]`)&&r--,r===0&&e.slice(o,o+t.length)===t&&e[o+t.length]!==`=`){n.push(a),a=``,o+=t.length-1;continue}a+=s}return a&&n.push(a),n}function jp(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return Mp(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function Mp(e){let t=e.trim();if(t===`true`)return!0;if(t===`false`)return!1;if(t===`null`)return null;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`'`)&&t.endsWith(`'`)||t.startsWith(`"`)&&t.endsWith(`"`))return t.slice(1,-1);if(t.startsWith(`[`)&&t.endsWith(`]`))try{let e=t.replace(/'([^']*)'/g,(e,t)=>JSON.stringify(t));return JSON.parse(e)}catch{return[]}return t}function Np({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectNames??[],o=t==null?``:String(t);return i?.objectsLoading?(0,X.jsx)(K,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,X.jsx)(K,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,X.jsxs)(on,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,X.jsx)(Tn,{id:e,children:(0,X.jsx)(nt,{placeholder:`Select object…`})}),(0,X.jsx)(oa,{children:a.map(e=>(0,X.jsx)(Oe,{value:e,children:e},e))})]})}function Pp({id:e,value:t,onChange:n,readOnly:r,context:i,fieldSpec:a}){let o=i?.objectNames??[],s=a?.multiple??!1,c=Y.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),l=e=>{if(!r){if(!s){n(e);return}n(c.includes(e)?c.filter(t=>t!==e):[...c,e])}},u=e=>{if(r)return;let t=c.filter(t=>t!==e);n(s?t:``)};return i?.objectsLoading?(0,X.jsx)(K,{id:e,value:`Loading objects...`,readOnly:!0,disabled:!0}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[c.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,X.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,X.jsx)(`span`,{children:e}),!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e))}),(0,X.jsxs)(on,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,X.jsx)(Tn,{id:e,children:(0,X.jsx)(nt,{placeholder:s?`Add objects...`:`Select object...`})}),(0,X.jsx)(oa,{children:o.map(e=>(0,X.jsxs)(Oe,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function Fp({id:e,value:t,onChange:n,readOnly:r,fieldSpec:i,formData:a}){let[o,s]=Y.useState([]),[c,l]=Y.useState(!1),u=i?.dependsOn||i?.reference||`objectName`,d=Array.isArray(u)?u[0]:u,f=a?.[d];Y.useEffect(()=>{if(!f){s([]);return}l(!0),fetch(`/api/v1/objects/${f}/fields`).then(e=>e.json()).then(e=>{s(e.fields||[]),l(!1)}).catch(e=>{console.error(`Failed to load fields:`,e),s([]),l(!1)})},[f]);let p=i?.multiple??!1,m=Y.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),h=e=>{if(!r){if(!p){n(e);return}n(m.includes(e)?m.filter(t=>t!==e):[...m,e])}},g=e=>{if(r)return;let t=m.filter(t=>t!==e);n(p?t:``)};return f?c?(0,X.jsx)(K,{id:e,value:`Loading fields...`,readOnly:!0,disabled:!0}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[m.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>{let t=o.find(t=>t.name===e);return(0,X.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,X.jsx)(`span`,{children:t?.label||e}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:t?.type}),!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e)})}),(0,X.jsxs)(on,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,X.jsx)(Tn,{id:e,children:(0,X.jsx)(nt,{placeholder:p?`Add fields...`:`Select field...`})}),(0,X.jsx)(oa,{children:o.map(e=>(0,X.jsx)(Oe,{value:e.name,disabled:!p&&m.includes(e.name),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e.label||e.name}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.type}),m.includes(e.name)&&` ✓`]})},e.name))})]})]}):(0,X.jsx)(K,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function Ip({schema:e,value:t,onChange:n,readOnly:r,context:i}){let a=e;if(a?.anyOf||a?.oneOf){let e=(a.anyOf??a.oneOf).find(e=>e?.type===`array`&&e?.items?.type===`object`);e&&(a={...a,...e})}let o=a?.items??{},s=o.properties??{},c=new Set(Array.isArray(o.required)?o.required:[]),l=Array.isArray(t)?t:[],u=Object.keys(s);if(u.length===0)return(0,X.jsxs)(`div`,{className:`rounded border border-dashed border-amber-500/40 bg-amber-500/5 p-2 text-xs text-amber-700 dark:text-amber-300`,children:[`master-detail widget requires `,(0,X.jsx)(`code`,{children:`items.properties`}),` on the JSON schema (or an `,(0,X.jsx)(`code`,{children:`anyOf`}),` branch that has them).`]});function d(e,t){let r=l.slice();r[e]={...r[e]??{},...t},n(r)}function f(){n([...l,{}])}function p(e){let t=l.slice();t.splice(e,1),n(t)}return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`overflow-x-auto rounded border border-border/40`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40`,children:(0,X.jsxs)(`tr`,{children:[u.map(e=>(0,X.jsxs)(`th`,{className:`px-2 py-1.5 text-left text-xs font-medium text-muted-foreground`,children:[s[e]?.title??e,c.has(e)&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e)),(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsxs)(`tbody`,{children:[l.length===0&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:u.length+1,className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:`No rows. Click + to add.`})}),l.map((e,t)=>(0,X.jsxs)(`tr`,{className:`border-t border-border/30`,children:[u.map(n=>(0,X.jsx)(`td`,{className:`p-1`,children:(0,X.jsx)(Lp,{schema:s[n],value:(e??{})[n],readOnly:r,context:i,onChange:e=>d(t,{[n]:e})})},n)),(0,X.jsx)(`td`,{className:`p-1 text-right`,children:(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),disabled:r,className:`h-7 w-7 p-0`,"aria-label":`Remove row`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:r,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function Lp({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,X.jsx)(Np,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,X.jsxs)(on,{value:t==null?``:String(t),onValueChange:e=>i(e||void 0),disabled:n,children:[(0,X.jsx)(Tn,{className:`h-8 text-xs`,children:(0,X.jsx)(nt,{placeholder:`—`})}),(0,X.jsx)(oa,{children:a.map(e=>(0,X.jsx)(Oe,{value:String(e),children:String(e)},String(e)))})]}):e?.type===`boolean`?(0,X.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:n,onChange:e=>i(e.target.checked),className:`h-4 w-4`}):e?.type===`number`||e?.type===`integer`?(0,X.jsx)(K,{type:`number`,value:t==null?``:String(t),disabled:n,onChange:e=>{let t=e.target.valueAsNumber;i(Number.isFinite(t)?t:void 0)},className:`h-8 text-xs`}):(0,X.jsx)(K,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function Rp({id:e,value:t,onChange:n,readOnly:r}){let i=Array.isArray(t)?t:[],[a,o]=Y.useState(``);function s(e){let t=e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean);if(t.length===0)return;let r=[...i];for(let e of t)r.includes(e)||r.push(e);n(r),o(``)}function c(e){let t=i.slice();t.splice(e,1),n(t)}return(0,X.jsx)(`div`,{className:`rounded border border-input bg-background p-1.5`,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-xs`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),!r&&(0,X.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e}`,onClick:()=>c(t),className:`text-muted-foreground hover:text-destructive`,children:`×`})]},t)),(0,X.jsx)(`input`,{id:e,type:`text`,value:a,disabled:r,placeholder:i.length===0?`Type and press Enter…`:``,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),s(a)):e.key===`Backspace`&&!a&&i.length>0&&c(i.length-1)},onBlur:()=>a&&s(a),className:`min-w-[8rem] flex-1 bg-transparent text-sm outline-none`})]})})}var zp={"ref:object":Np,"object-selector":Pp,"field-selector":Fp,"master-detail":Ip,"string-tags":Rp,code:Hp,"filter-builder":Ip};function Bp(e,t){if(e?.language)return e.language;if(typeof t?.format==`string`){let e=t.format.toLowerCase();if(e===`sql`||e===`javascript`||e===`typescript`||e===`json`||e===`yaml`||e===`html`||e===`css`||e===`python`)return e}let n=e?.field?.toLowerCase()??``;return n.includes(`sql`)||n===`query`?`sql`:`javascript`}var Vp=Y.lazy(()=>m(()=>import(`./src-BJJhwsID.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function Hp({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=Bp(i,e),o=typeof t==`string`?t:t==null?``:String(t);return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/50 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 bg-muted/40 border-b border-border/30 text-[10px] font-mono text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:a}),r&&(0,X.jsx)(`span`,{children:`read-only`})]}),(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`h-[280px] flex items-center justify-center text-xs text-muted-foreground`,children:`Loading editor…`}),children:(0,X.jsx)(Vp,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var Up=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function Wp(e,t){if(!e)return e;let n=e.oneOf??e.anyOf;if(!Array.isArray(n)||n.length===0)return e;let r=typeof t==`object`&&!!t&&!Array.isArray(t),i=Array.isArray(t),a=r?new Set(Object.keys(t)):null,o=null,s=i&&t.length?t[0]:void 0,c=typeof s==`object`&&!!s&&!Array.isArray(s);for(let e of n){let n=0;if(e.type===`array`&&i){n+=5;let t=e.items?.type;(t===`object`&&c||t===`string`&&typeof s==`string`||t===`number`&&typeof s==`number`||t===`integer`&&typeof s==`number`)&&(n+=3)}if(e.type===`object`&&r&&(n+=5),e.type===`string`&&typeof t==`string`&&(n+=5),e.type===`number`&&typeof t==`number`&&(n+=5),e.type===`boolean`&&typeof t==`boolean`&&(n+=5),a&&Array.isArray(e.required))for(let t of e.required)a.has(t)&&(n+=1);(!o||n>o.score)&&(o={branch:e,score:n})}let l=o?.branch??n[0];return{...e,...l,oneOf:void 0,anyOf:void 0}}function Gp(e,t){if(e?.widget)return e.widget;if(e?.type){let t=e.type;if(t===`text`||t===`email`||t===`url`||t===`phone`||t===`password`)return`text`;if(t===`textarea`||t===`markdown`||t===`html`||t===`richtext`)return`textarea`;if(t===`number`||t===`currency`||t===`percent`)return`number`;if(t===`date`||t===`datetime`||t===`time`)return`date-picker`;if(t===`boolean`||t===`toggle`)return`switch`;if(t===`select`||t===`radio`)return e.multiple?`multiselect`:`select`;if(t===`multiselect`||t===`checkboxes`||t===`tags`)return`string-tags`;if(t===`composite`)return`composite`;if(t===`repeater`)return`repeater`;if(t===`record`)return`record`;if(t===`lookup`||t===`master_detail`||t===`tree`)return`ref-object`;if(t===`image`||t===`file`||t===`avatar`||t===`video`||t===`audio`)return`file-upload`;if(t===`code`)return`code`;if(t===`json`||t===`location`||t===`address`)return`json`;if(t===`color`)return`color-picker`;if(t===`rating`)return`number`;if(t===`slider`)return`slider`;if(t===`signature`)return`signature`;if(t===`qrcode`)return`qrcode`;if(t===`progress`)return`number`;if(t===`formula`||t===`summary`||t===`autonumber`)return`text`;if(t===`vector`)return`json`}if(t){let e=t.type;if(e===`array`&&t.items?.type===`string`)return`string-tags`;if(e===`array`&&t.items?.type===`object`)return`master-detail`;if(e===`object`)return`object-fields`;if(e===`boolean`)return`switch`;if(e===`number`||e===`integer`)return`number`;if(Array.isArray(t.enum))return`select`;if(e===`string`){if(t.format===`date`||t.format===`date-time`)return`date-picker`;if(t.format===`email`||t.format===`uri`||t.format===`uri-reference`)return`text`;if(t.format===`multiline`)return`textarea`}}}function Kp({schema:e,form:t,value:n,onChange:r,issues:i=[],hiddenFields:a=[],fieldOrder:o=[],readOnly:s=!1,createMode:c=!1,widgetContext:l}){let u=e;if(!u||typeof u!=`object`)if(n&&typeof n==`object`)u=nm(n);else return(0,X.jsx)(tm,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=am(Object.keys(d),o).filter(e=>!a.includes(e)),m=Y.useMemo(()=>{let e={};for(let t of i)(e[t.path]??=[]).push(t.message);return e},[i]),h=n??{};function g(e,t){let n={...h,[e]:t};(t===void 0||t===``)&&delete n[e],r(n)}if(t?.sections?.length){let e=[];for(let n of t.sections)for(let t of n.fields)e.push(typeof t==`string`?t:t.field);let n=e.filter(e=>d[e]).length;if(e.length===0||n>0)return(0,X.jsx)(Jp,{form:t,props:d,required:f,hiddenFields:a,issuesByPath:m,value:h,readOnly:s,createMode:c,widgetContext:l,onChange:g});typeof console<`u`&&console.warn(`[SchemaForm] form layout declares no fields that exist in the schema; falling back to flat schema-driven rendering. Declared:`,e,`Available:`,Object.keys(d))}return(0,X.jsx)(`div`,{className:`space-y-4`,children:p.map(e=>(0,X.jsx)(Yp,{name:e,schema:d[e],value:h[e],required:f.includes(e),issues:m[e],readOnly:s,widgetContext:l,formData:h,onChange:t=>g(e,t)},e))})}function qp(e){return typeof e==`string`?{field:e}:e}function Jp({form:e,props:t,required:n,hiddenFields:r,issuesByPath:i,value:a,readOnly:o,createMode:s,widgetContext:c,onChange:l}){let u=(e.sections??[]).filter(e=>!e.visibleOn||Op(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(qp).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!Op(e.visibleOn,{data:a})));if(d.length===0)return null;let f=e.columns??1;return(0,X.jsxs)(`section`,{className:`space-y-3 rounded-md border border-border/40 bg-card/30 p-4`,children:[e.label&&(0,X.jsxs)(`header`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-foreground/90`,children:e.label}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),(0,X.jsx)(`div`,{className:`grid gap-4`,style:{gridTemplateColumns:`repeat(${f}, minmax(0, 1fr))`},children:d.map(e=>{let r=t[e.field];return r?(0,X.jsx)(`div`,{style:{gridColumn:`span ${e.colSpan??1}`},children:(0,X.jsx)(Yp,{name:e.field,schema:{...r,...e.label?{title:e.label}:{},...e.helpText?{description:e.helpText}:{},...e.placeholder?{placeholder:e.placeholder}:{}},value:a[e.field],required:e.required??n.includes(e.field),issues:i[e.field],readOnly:o||e.readonly||e.immutable&&!s,fieldSpec:e,widgetContext:c,formData:a,onChange:t=>l(e.field,t)})},e.field):(0,X.jsxs)(`div`,{className:`rounded border border-dashed border-amber-500/40 bg-amber-500/5 p-2 text-xs text-amber-700 dark:text-amber-300`,style:{gridColumn:`span ${e.colSpan??1}`},children:[`⚠️ Field `,(0,X.jsx)(`code`,{children:e.field}),` declared in form layout but missing from schema. Skipping.`]},e.field)})})]},u)};if(d){let e=u.filter(e=>e.fields.map(qp).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||Op(e.visibleOn,{data:a}))));return e.length===0?null:(0,X.jsxs)(_e,{defaultValue:(e[0].label??`section-0`).toLowerCase(),className:`w-full`,children:[(0,X.jsx)(Oi,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,X.jsx)(ni,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,X.jsx)(_r,{value:(e.label??`section-${t}`).toLowerCase(),className:`mt-4`,children:f(e,t)},t))]})}return(0,X.jsx)(`div`,{className:`space-y-4`,children:u.map(f)})}function Yp({name:e,schema:t,value:n,required:r,issues:i,readOnly:a,fieldSpec:o,widgetContext:s,formData:c,onChange:l}){let u=o?.label||t?.title||im(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=Gp(o,t),m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=im(e).toLowerCase()===u.toLowerCase();return m?(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(Nr,{htmlFor:f,className:`text-sm font-medium cursor-pointer`,children:[u,g&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),d&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:d}),i?.map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs text-destructive mt-0.5`,children:e},t))]}),(0,X.jsx)(Xp,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c})]}):(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between gap-2`,children:(0,X.jsxs)(Nr,{htmlFor:f,className:`text-sm font-medium`,children:[u,g&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`}),!_&&(0,X.jsx)(`code`,{className:`ml-2 text-[10px] font-mono text-muted-foreground/70`,title:`Machine name`,children:e})]})}),(0,X.jsx)(Xp,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c}),d&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:d}),i?.map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:e},t))]})}function Xp({id:e,schema:t,value:n,onChange:r,readOnly:i,widget:a,fieldSpec:o,widgetContext:s,formData:c}){if(o?.type===`composite`)return(0,X.jsx)(Qp,{value:n,fields:o.fields?.length?o.fields:om(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,X.jsx)($p,{value:n,fields:o.fields?.length?o.fields:om(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(o?.type===`record`){let e=t?.additionalProperties??{};return(0,X.jsx)(em,{value:n,fields:o.fields?.length?o.fields:om(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,keyField:o.keyField,formData:c,onChange:r})}if(a){let l=zp[a];if(l)return(0,X.jsx)(l,{id:e,schema:t,value:n,onChange:r,readOnly:i,context:s,fieldSpec:o,formData:c});let u=Wp(t,n);if(u?.type===`object`&&u.properties&&typeof u.properties==`object`)return(0,X.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,X.jsx)(Kp,{schema:u,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(u?.type===`array`&&u.items&&typeof u.items==`object`){let e=Wp(u.items,Array.isArray(n)&&n.length?n[0]:void 0);if(e?.type===`object`&&e.properties&&typeof e.properties==`object`)return(0,X.jsx)($p,{value:n,fields:om(e),schema:{...u,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}if(!Up.has(a))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(tm,{value:n,onChange:e=>r(e),readOnly:i}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`widget `,(0,X.jsx)(`code`,{className:`font-mono`,children:a}),` — falling back to JSON until a custom renderer is registered.`]})]})}let l=Wp(t,n)??t,u=l?.type,d=o?.options,f=l?.enum??void 0;if(Array.isArray(d)&&d.length>0)return(0,X.jsxs)(on,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,X.jsx)(Tn,{id:e,children:(0,X.jsx)(nt,{placeholder:`Select…`})}),(0,X.jsx)(oa,{children:d.map(e=>(0,X.jsxs)(Oe,{value:e.value,children:[e.label,e.color&&(0,X.jsx)(`span`,{className:`ml-2 inline-block h-3 w-3 rounded`,style:{backgroundColor:e.color}})]},e.value))})]});if(Array.isArray(f)&&f.length>0)return(0,X.jsxs)(on,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,X.jsx)(Tn,{id:e,children:(0,X.jsx)(nt,{placeholder:`Select…`})}),(0,X.jsx)(oa,{children:f.map(e=>(0,X.jsx)(Oe,{value:String(e),children:String(e)},String(e)))})]});if(u===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,X.jsx)(qr,{id:e,checked:!!n,onCheckedChange:e=>r(e),disabled:i});if(u===`number`||u===`integer`){let t=o?.min,a=o?.max;return(0,X.jsx)(K,{id:e,type:`number`,value:n==null?``:String(n),min:t,max:a,onChange:e=>{let t=e.target.value;if(t===``)return r(void 0);let n=u===`integer`?parseInt(t,10):Number(t);r(Number.isFinite(n)?n:void 0)},readOnly:i})}if(u===`string`){let t=o?.maxLength;return l?.format===`multiline`||l?.contentMediaType===`text/markdown`||typeof n==`string`&&n.length>80?(0,X.jsx)(Yt,{id:e,rows:4,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,X.jsx)(K,{id:e,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i})}if(u===`array`){let t=l?.items??{};if(t.type===`string`||t.type===`number`||t.type===`integer`)return(0,X.jsx)(K,{id:e,value:(Array.isArray(n)?n:[]).map(String).join(`, `),placeholder:`comma, separated, values`,onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean);t.type===`number`||t.type===`integer`?r(n.map(e=>Number(e)).filter(e=>Number.isFinite(e))):r(n)},readOnly:i})}if(l?.type===`object`&&l.properties&&typeof l.properties==`object`)return(0,X.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,X.jsx)(Kp,{schema:l,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(l?.type===`array`&&l.items&&typeof l.items==`object`){let e=Wp(l.items,Array.isArray(n)&&n.length?n[0]:void 0);if(e?.type===`object`&&e.properties&&typeof e.properties==`object`)return(0,X.jsx)($p,{value:n,fields:om(e),schema:{...l,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}return(0,X.jsx)(tm,{value:n,onChange:r,readOnly:i,small:!0})}function Zp(e,t,n){if(!e)return{};let r;return r=t===`composite`?e.properties:t===`repeater`?e.items?.properties:e.additionalProperties?.properties,r?.[n]??{}}function Qp({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,onChange:a}){let o=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return(0,X.jsx)(`div`,{className:`rounded-md border border-border/50 bg-muted/20 p-3 space-y-3`,children:t.map(qp).map(e=>{let t=Zp(n,`composite`,e.field);return(0,X.jsx)(Yp,{name:e.field,schema:t,value:o[e.field],required:!!e.required,readOnly:r||e.readonly,fieldSpec:e,widgetContext:i,formData:o,onChange:t=>a({...o,[e.field]:t})},e.field)})})}function $p({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(qp),[l,u]=Y.useState(null),d=a===`grid`||a===`table`,f=(e,t)=>{o(s.map((n,r)=>r===e?{...n,...t}:n))},p=e=>o(s.filter((t,n)=>n!==e)),m=()=>{let e={};c.forEach(t=>{e[t.field]=void 0}),o([...s,e]),u(s.length)};return d?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border/50`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40`,children:(0,X.jsxs)(`tr`,{children:[c.map(e=>(0,X.jsxs)(`th`,{className:`px-2 py-1.5 text-left text-xs font-medium`,children:[e.label||im(e.field),e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e.field)),!r&&(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsxs)(`tbody`,{children:[s.length===0&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:c.length+1,className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:Z(`engine.repeater.empty`,Qf())})}),s.map((e,t)=>(0,X.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=Zp(n,`repeater`,a.field);return(0,X.jsx)(`td`,{className:`p-1.5`,children:(0,X.jsx)(Xp,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:Gp(a,o),fieldSpec:a,widgetContext:i,formData:e,onChange:e=>f(t,{[a.field]:e})})},a.field)}),!r&&(0,X.jsx)(`td`,{className:`p-1.5 text-right`,children:(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),!r&&(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5 mr-1`}),` Add`]})]}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,X.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:Z(`engine.list.empty`,Qf())}),s.map((e,t)=>{let a=l===t,o=c.map(t=>e?.[t.field]).find(e=>e!=null&&e!==``);return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-muted/10`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5 border-b border-border/30`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(a?null:t),className:`flex items-center gap-1.5 text-sm font-medium text-left flex-1 min-w-0`,children:[a?(0,X.jsx)(sn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(tr,{className:`h-3.5 w-3.5`}),(0,X.jsxs)(`span`,{className:`truncate`,children:[`#`,t+1,o==null?``:` — ${String(o)}`]})]}),!r&&(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),a&&(0,X.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=Zp(n,`repeater`,a.field);return(0,X.jsx)(Yp,{name:a.field,schema:o,value:e?.[a.field],required:!!a.required,readOnly:r||a.readonly,fieldSpec:a,widgetContext:i,formData:e,onChange:e=>f(t,{[a.field]:e})},a.field)})})]},t)}),!r&&(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function em({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,keyField:o,formData:s,onChange:c}){if(a){let o=zp[a];if(o)return(0,X.jsx)(o,{schema:n,value:e,onChange:c,readOnly:r,context:i,fieldSpec:{field:``,type:`record`,fields:t,widget:a},formData:s})}let l=o?.field??`name`,u=o?.label??im(l),d=o?.regex?new RegExp(o.regex):null,f=o?.immutable!==!1,p=e&&typeof e==`object`&&!Array.isArray(e)?e:{},m=Object.entries(p),h=t.map(qp).filter(e=>e.field!==l),[g,_]=Y.useState(null),[v,y]=Y.useState(``),[b,x]=Y.useState(null),S=e=>c(e),C=(e,t)=>{let n={};for(let[r,i]of m)n[r]=r===e?{...i,...t}:i;S(n)},w=e=>{let t={};for(let[n,r]of m)n!==e&&(t[n]=r);S(t)},T=(e,t)=>{if(t===e)return;if(p[t]){x(`Key "${t}" already exists`);return}if(d&&!d.test(t)){x(`Key must match ${d}`);return}let n={};for(let[r,i]of m)r===e?n[t]={...i,[l]:t}:n[r]=i;x(null),S(n)},E=()=>{let e=v.trim();if(!e){x(`Key is required`);return}if(p[e]){x(`Key "${e}" already exists`);return}if(d&&!d.test(e)){x(`Key must match ${d}`);return}let t={[l]:e};h.forEach(e=>{t[e.field]=void 0}),S({...p,[e]:t}),y(``),x(null),_(e)},[D,O]=Y.useState(null),[k,A]=Y.useState(null),j=(e,t)=>{if(e===t)return;let n=m.map(([e])=>e),r=n.indexOf(e),i=n.indexOf(t);if(r<0||i<0)return;n.splice(r,1),n.splice(i,0,e);let a={};for(let e of n)a[e]=p[e];S(a)};return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[m.length===0&&(0,X.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:Z(`engine.list.empty`,Qf())}),m.map(([e,t])=>{let a=g===e,s=h.map(e=>t?.[e.field]).find(e=>e!=null&&e!==``);return(0,X.jsxs)(`div`,{className:`rounded-md border bg-muted/10 ${k===e&&D&&D!==e?`border-primary border-2`:`border-border/50`}`,onDragOver:t=>{!D||r||(t.preventDefault(),k!==e&&A(e))},onDragLeave:()=>{k===e&&A(null)},onDrop:t=>{!D||r||(t.preventDefault(),j(D,e),O(null),A(null))},children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5 border-b border-border/30`,children:[!r&&(0,X.jsx)(`span`,{draggable:!0,onDragStart:t=>{O(e),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e)},onDragEnd:()=>{O(null),A(null)},className:`cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground`,"aria-label":`Drag to reorder`,title:`Drag to reorder`,children:(0,X.jsx)(Ce,{className:`h-3.5 w-3.5`})}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>_(a?null:e),className:`flex items-center gap-1.5 text-sm font-medium text-left flex-1 min-w-0`,children:[a?(0,X.jsx)(sn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(tr,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted/60`,children:e}),s!=null&&(0,X.jsxs)(`span`,{className:`truncate text-muted-foreground`,children:[`— `,String(s)]})]}),!r&&(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(e),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),a&&(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(Yp,{name:l,schema:{type:`string`},value:e,required:!0,readOnly:r||f,fieldSpec:{field:l,type:`text`,label:u,helpText:o?.helpText},widgetContext:i,formData:t,onChange:t=>T(e,String(t??``).trim())}),h.map(a=>{if(a.visibleOn&&!Op(a.visibleOn,{data:t}))return null;let o=Zp(n,`record`,a.field);return(0,X.jsx)(Yp,{name:a.field,schema:o,value:t?.[a.field],required:!!a.required,readOnly:r||a.readonly,fieldSpec:a,widgetContext:i,formData:t,onChange:t=>C(e,{[a.field]:t})},a.field)})]})]},e)}),!r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(K,{value:v,onChange:e=>{y(e.target.value),b&&x(null)},placeholder:o?.placeholder??u,className:`h-8 text-xs font-mono max-w-[220px]`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:E,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5 mr-1`}),` Add`]}),b&&(0,X.jsx)(`span`,{className:`text-xs text-destructive`,children:b})]})]})}function tm({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=Y.useState(()=>rm(e)),[o,s]=Y.useState(null);return Y.useEffect(()=>{a(rm(e)),s(null)},[JSON.stringify(e)]),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Yt,{rows:r?4:12,className:`font-mono text-xs`,value:i,readOnly:n,onChange:e=>{let n=e.target.value;if(a(n),!n.trim()){s(null),t(void 0);return}try{let e=JSON.parse(n);s(null),t(e)}catch(e){s(e?.message??`Invalid JSON`)}}}),o&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:o})]})}function nm(e){let t={};for(let[n,r]of Object.entries(e))if(!n.startsWith(`_`))if(r==null)t[n]={type:`string`};else if(typeof r==`string`)t[n]=r.length>80||r.includes(`
|
|
15
|
-
`)?{type:`string`,format:`multiline`}:{type:`string`};else if(typeof r==`number`)t[n]={type:Number.isInteger(r)?`integer`:`number`};else if(typeof r==`boolean`)t[n]={type:`boolean`};else if(Array.isArray(r))if(r.length>0&&typeof r[0]==`string`)t[n]={type:`array`,items:{type:`string`}};else if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let e=r[0],i={};for(let t of Object.keys(e))i[t]={type:`string`};t[n]={type:`array`,items:{type:`object`,properties:i}}}else t[n]={type:`array`,items:{type:`string`}};else typeof r==`object`?t[n]={type:`object`,additionalProperties:!0}:t[n]={type:`string`};return{type:`object`,properties:t,additionalProperties:!0}}function rm(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function im(e){return e.replace(/[_-]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function am(e,t){if(!t.length)return e;let n=new Set(e),r=t.filter(e=>n.has(e)),i=e.filter(e=>!t.includes(e));return[...r,...i]}function om(e){let t=e?.properties??{};return Object.keys(t)}function sm({type:e,name:t,parentItem:n,onOpen:r}){let i=zf(),a=v(),o=Y.useMemo(()=>dp(e),[e]),[s,c]=Y.useState([]),[l,u]=Y.useState(``),[d,f]=Y.useState({});if(Y.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(cm)}}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=>cm(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,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:`No related metadata`}),(0,X.jsxs)(rt,{children:[`No metadata types are configured to anchor at `,(0,X.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let p=s.reduce((e,t)=>e+t.items.length,0),m=s.some(e=>e.loading),h=l.trim().toLowerCase();return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,X.jsx)(Ai,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,X.jsx)(K,{placeholder:`Search related…`,value:l,onChange:e=>u(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:m?`Scanning…`:`${p} item${p===1?``:`s`}`})]}),s.map(n=>{let i=h?n.items.filter(e=>e.name.toLowerCase().includes(h)||(e.label??``).toLowerCase().includes(h)):n.items,o=d[n.childType]??!1;return!(!h||i.length>0)&&!n.loading?null:(0,X.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>f(e=>({...e,[n.childType]:!o})),children:[(0,X.jsx)(tr,{className:gr(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,X.jsx)(G,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,X.jsx)(q,{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,X.jsx)(fn,{className:`h-3.5 w-3.5`})})]}),!o&&(0,X.jsxs)(`div`,{children:[n.loading&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:h?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,X.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,X.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,X.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,X.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,X.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,X.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,X.jsx)(pt,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function cm(e){return{name:lm(e,[`name`,`id`,`key`])??`(unnamed)`,label:lm(e,[`label`,`title`,`displayName`]),description:lm(e,[`description`,`summary`]),raw:e}}function lm(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function um({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=zf(),{entries:c}=Bf(s),l=i?c.find(e=>e.type===i):void 0,u=!l?.schema&&i?fm[i]:void 0,d=l?.schema??u?.schema,f=l?.form??u?.form,[p,m]=Y.useState(a),[h,g]=Y.useState(!1),[_,v]=Y.useState(null),[y,b]=Y.useState([]),[x,S]=Y.useState(null);Y.useEffect(()=>{m(a),v(null),b([]),S(null)},[a,r,e,t]);let C=l!=null&&!l.allowOrgOverride&&!l.allowRuntimeCreate;async function w(){if(!n){v(`Cannot save: this item has no embeddedPath registered.`);return}g(!0),v(null),b([]);try{let i=await s.layered(e,t),a=dm(i.effective??i.code??{},n,r,p);await s.save(e,t,a),S(Date.now()),o?.(p)}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:String(e.message??`Invalid`)}});b(i),v(`Validation failed (${i.length} issue${i.length===1?``:`s`}).`)}else v(e?.message??String(e))}finally{g(!1)}}return d?(0,X.jsxs)(`div`,{className:`p-4 space-y-4`,children:[_&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:_}),x!=null&&!_&&(0,X.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:`Saved.`}),C&&(0,X.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:`The parent type is read-only — saving will still attempt a PUT and may be refused by the server.`}),(0,X.jsx)(Kp,{schema:d,form:f,value:p,onChange:m,issues:y}),(0,X.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,X.jsxs)(q,{onClick:w,disabled:h||!n,children:[h?(0,X.jsx)(jr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(li,{className:`h-4 w-4 mr-1`}),`Save into `,e]})}),!n&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Read-only`}),(0,X.jsx)(`div`,{children:`No embedded path registered — cannot determine where to write this item back.`})]})]}):(0,X.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`No form schema is registered for`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:i??`this item`}),`. Edit the raw JSON below; saving will splice it back into`,` `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[e,`/`,t,`.`,n,`.`,r]}),`.`]}),(0,X.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(p,null,2),onChange:e=>{try{m(JSON.parse(e.target.value)),v(null)}catch(e){v(`Invalid JSON: ${e.message}`)}}}),_&&(0,X.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,X.jsx)(Ot,{className:`h-4 w-4 inline mr-1`}),` `,_]}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)(q,{onClick:w,disabled:h||!n,children:[h?(0,X.jsx)(jr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(li,{className:`h-4 w-4 mr-1`}),`Save into parent`]})})]})}function dm(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 fm={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 pm({target:e,onClose:t,parentContext:n}){let r=v(),i=e?.kind===`metadata`,a=e?.kind===`embedded`,o=i?e.type:a?e.groupLabel:``,s=i?e.name:a?e.itemName:``;return(0,X.jsx)(kt,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,X.jsxs)(It,{side:`right`,className:gr(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,X.jsxs)(Ke,{className:`px-4 py-3 border-b space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(G,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,X.jsx)(ct,{className:`font-mono text-base truncate`,children:s}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,X.jsx)(pt,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,X.jsxs)(Jt,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,X.jsx)(Em,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,X.jsx)(um,{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 mm({type:e,name:t}){let n=a(),r=e??n.type??``,i=t??n.name??``,o=v(),s=zf(),{entries:c}=Bf(s),l=c.find(e=>e.type===r),[u,d]=Y.useState(0),[f,p]=Y.useState(0);return(0,X.jsx)(op,{entry:l??{type:r,label:r},itemName:i,subtitle:`Version history`,stats:[{label:`Events`,value:f}],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(i)}`),children:[(0,X.jsx)(dt,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>d(e=>e+1),children:(0,X.jsx)(Zi,{className:`h-4 w-4`})})]}),children:(0,X.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,X.jsx)(hm,{type:r,name:i,refreshKey:u,onCount:p,client:s,onRollback:()=>d(e=>e+1)})})})}function hm({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=Y.useState([]),[u,d]=Y.useState(!0),[f,p]=Y.useState(null),[m,h]=Y.useState(null),[g,_]=Y.useState(null),[v,y]=Y.useState(0);Y.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function b(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,X.jsxs)(X.Fragment,{children:[u&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,X.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,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:`No history yet`}),(0,X.jsx)(rt,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,X.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,X.jsxs)(`li`,{className:`relative`,children:[(0,X.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,X.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,X.jsx)(G,{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,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:gm(i)}),o&&(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),b(e.version)},children:g===e.version?(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Kn,{className:`h-3.5 w-3.5`})})]}),n&&(0,X.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:_m(e)})]})]},`${e.seq??t}-${t}`)})})]})}function gm(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function _m(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}var vm=new Map;function ym(e,t){vm.set(e,t)}function bm(e){return vm.get(e)}var xm=new Map;function Sm(e,t){xm.set(e,t)}function Cm(e){return xm.get(e)}var wm=hi;function Tm(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function Em({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=a(),o=e??i.type??``,s=t??i.name??``,c=v(),l=zf(),{entries:u}=Bf(l),d=u.find(e=>e.type===o),f=fp(o,d),p=Y.useMemo(()=>Qf(),[]),m=up(o);if(m?.EditPage&&!n){let e=m.EditPage;return(0,X.jsx)(e,{type:o,name:s})}if(m?.CreatePage&&n){let e=m.CreatePage;return(0,X.jsx)(e,{type:o})}let[h,g]=Y.useState(null),[_,y]=Y.useState(n?{name:``}:{}),[b,x]=Y.useState(null),[S,C]=Y.useState(!n),[w,T]=Y.useState(!1),[E,D]=Y.useState(null),[O,k]=Y.useState([]),[A,j]=Y.useState(null),[M,ee]=Y.useState(null),[te,ne]=Y.useState(!1),[N,P]=Y.useState(!1),[F,re]=Y.useState(0),[I,L]=Y.useState(!!n),[ie,ae]=Y.useState(null);Y.useEffect(()=>{ae(null)},[o,s]),Y.useEffect(()=>{I||ae(null)},[I]);let oe=Y.useRef(null),[se,ce]=Y.useState(null),[le,ue]=Y.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null?!0:e===`1`}catch{return!0}});Y.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,le?`1`:`0`)}catch{}},[le]);let R=Y.useRef(null),[de,fe]=Y.useState([]),[pe,z]=Y.useState(!0);Y.useEffect(()=>{let e=!1;return(async()=>{try{let t=await l.list(`object`);if(e)return;fe(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||fe([])}finally{e||z(!1)}})(),()=>{e=!0}},[l]);let me=Y.useMemo(()=>({objectNames:de,objectsLoading:pe}),[de,pe]);Y.useEffect(()=>{if(n){C(!1);return}let e=!1;return C(!0),D(null),(async()=>{try{let[t,n]=await Promise.all([l.layered(o,s),l.getDraft(o,s).catch(()=>null)]);if(e)return;g(t);let r=t?._diagnostics;r&&r.valid===!1&&Array.isArray(r.errors)?k(r.errors.map(e=>({path:e.path||``,message:e.message}))):k([]);let i=Tm(n),a=i??t.effective??t.code??{};y(a),oe.current=a,ne(!!i),C(!1)}catch(t){e||(D(t?.message??String(t)),C(!1))}})(),()=>{e=!0}},[l,o,s,n,F]);let[he,B]=Y.useState(!1);async function V(){if(!(b!=null||he)){B(!0);try{x(await l.references(o,s))}catch(e){x([]),console.error(`references() failed`,e)}finally{B(!1)}}}let[H,ge]=Y.useState(null),_e=Y.useMemo(()=>!n&&!r&&dp(o).length>0,[o,n,r]),ve=Y.useRef(null),[U,ye]=Y.useState(null),[be,xe]=Y.useState(`properties`);Y.useEffect(()=>{if(U===`references`&&V(),typeof window<`u`&&!r){let e=new URL(window.location.href);U?e.searchParams.set(`tab`,U):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[U,r]);let Se=`metadata-edit:inspector-collapsed`,Ce=`metadata-edit:inspector-size`,[we,Te]=Y.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Se)===`1`),W=Y.useRef(38);Y.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(Ce));Number.isFinite(e)&&e>=22&&e<=80&&(W.current=e)},[]);let Oe=Y.useRef(null),ke=Y.useCallback(()=>{Te(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Se,t?`1`:`0`),t})},[]);Y.useEffect(()=>{let e=Oe.current;if(e)if(we)e.resize?.(`0%`);else{let t=W.current||38;e.resize?.(`${t}%`)}},[we]);let[Ae,je]=Y.useState(!1),[Me,Ne]=Y.useState(!1);Y.useEffect(()=>{if(typeof document>`u`||!Me)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[Me]),Y.useEffect(()=>{if(typeof window>`u`||!Me)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Ne(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Me]);let Pe=Y.useRef(null);Y.useEffect(()=>{Pe.current=null},[o,s]),Y.useEffect(()=>{if(n||r||S)return;let e=`${o}/${s??``}`;Pe.current!==e&&bm(o)&&(h?.code==null?d?.allowOrgOverride||d?.allowRuntimeCreate:d?.allowOrgOverride)&&(Pe.current=e,L(!0))},[o,s,n,r,S,d,h]),Y.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),ke())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,ke]),Y.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`)&&ye(t),ve.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&ge({kind:`metadata`,type:e,name:t})}},[]),Y.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);H?.kind===`metadata`?e.searchParams.set(`open`,`${H.type}:${H.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[H,r]);async function Fe(e){T(!0),D(null),k([]);try{let t=n?{..._,name:String(_.name??s)}:_,r=String(t.name??s);if(!r){D(`A name is required.`),T(!1);return}await l.save(o,r,t,{force:e,mode:`draft`});let[i,a]=await Promise.all([l.layered(o,r),l.getDraft(o,r).catch(()=>null)]);g(i);let u=Tm(a);ne(!!u);let d=u??i.effective??t;y(d),oe.current=d,ce(new Date),R.current=JSON.stringify(d),j(null),ee(null);let f=!n&&!!bm(o);!n&&!f&&L(!1),n&&c(`../${encodeURIComponent(r)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];j(Array.isArray(t)?t:[]),ee(_)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:String(e.message??`Invalid`)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:e[2].trim()}]:[{path:``,message:r}]}k(n),n.length===1&&!n[0].path?D(n[0].message):n.length===1?D(`${n[0].path}: ${n[0].message}`):D(`Validation failed (${n.length} issues).`)}else D(e?.message??String(e))}finally{T(!1)}}async function Le(){let e=!n&&h?.code!=null;if(confirm(Zf(e?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,p,{type:o,name:s??``}))){T(!0),D(null);try{if(await l.reset(o,s),e){let e=await l.layered(o,s);g(e);let t=e.effective??e.code??{};y(t),oe.current=t,bm(o)?Pe.current=null:L(!1)}else c(`../`,{relative:`path`})}catch(e){D(e?.message??String(e))}finally{T(!1)}}}async function Re(){P(!0),D(null);try{await l.publish(o,s);let[e,t]=await Promise.all([l.layered(o,s),l.getDraft(o,s).catch(()=>null)]);g(e);let n=Tm(t);ne(!!n);let r=n??e.effective??_;y(r),oe.current=r}catch(e){D(e?.message??String(e))}finally{P(!1)}}async function ze(){if(confirm(Zf(`engine.edit.discardDraftConfirm`,p,{type:o,name:s??``}))){T(!0),D(null);try{await l.reset(o,s,{state:`draft`});let e=await l.layered(o,s);g(e);let t=e.effective??e.code??{};y(t),oe.current=t,ne(!1)}catch(e){D(e?.message??String(e))}finally{T(!1)}}}let Be=Y.useMemo(()=>{if(n)return Object.keys(_).length>0;let e=oe.current;if(!e)return!1;try{return JSON.stringify(_)!==JSON.stringify(e)}catch{return!1}},[_,n]),Ve=!n&&h?.code!=null,He=n?!!(d?.allowOrgOverride||d?.allowRuntimeCreate):Ve?!!d?.allowOrgOverride:!!(d?.allowOrgOverride||d?.allowRuntimeCreate),Ge=!He&&!n,qe=Y.useRef(Fe);if(Y.useEffect(()=>{qe.current=Fe}),Y.useEffect(()=>{if(!le||n||Ge||!I||!Be||w)return;let e;try{e=JSON.stringify(_)}catch{return}if(e===R.current)return;let t=window.setTimeout(()=>{R.current=e,qe.current(!1)},1500);return()=>window.clearTimeout(t)},[_,Be,I,w,n,Ge,le]),Y.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!He||Ge||!I&&!n)return;e.preventDefault(),!w&&(n||Be)&&qe.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[He,Ge,I,n,w,Be]),Y.useEffect(()=>{if(!Be)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Be]),Y.useEffect(()=>{if(!Be)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(Z(`engine.edit.unsavedLeaveConfirm`,p))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[Be,p]),S)return(0,X.jsx)(op,{entry:d,itemName:s,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` Loading `,o,`/`,s,`…`]})});let Je=d?.schema??f.defaultSchema,Ye=Ge&&Ve&&!!d?.allowRuntimeCreate,Xe=!n&&!r?bm(o):void 0,Qe=Cm(o);function $e(){oe.current&&y(oe.current),k([]),D(null),L(!1)}let et=Ge||!I&&!n,tt=(0,X.jsxs)(X.Fragment,{children:[(!n||_e)&&(0,X.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>ye(`layers`),title:Z(`engine.edit.layers`,p),className:`h-7 w-7 p-0 relative`,children:[(0,X.jsx)(Jr,{className:`h-3.5 w-3.5`}),h?.overlay&&(()=>{let e=Cp(h.code,h.effective);return e>0?(0,X.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:Z(`engine.layers.diff`,p),children:e}):null})()]}),!n&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>ye(`references`),title:Z(`engine.edit.references`,p),className:`h-7 w-7 p-0 relative`,children:[(0,X.jsx)(Hr,{className:`h-3.5 w-3.5`}),b&&b.length>0&&(0,X.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:b.length})]}),_e&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>ye(`related`),title:Z(`engine.edit.related`,p),className:`h-7 w-7 p-0`,children:(0,X.jsx)(Pt,{className:`h-3.5 w-3.5`})}),!n&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>ye(`history`),title:Z(`engine.edit.history`,p),className:`h-7 w-7 p-0`,children:(0,X.jsx)(Ie,{className:`h-3.5 w-3.5`})})]}),!n&&He&&h?.overlay&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:Le,disabled:w,title:Z(Ve?`engine.edit.reset`:`engine.edit.delete`,p),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Ve?(0,X.jsx)(Kn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})}),He&&!n&&!I&&!Xe&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>L(!0),className:`h-7`,children:[(0,X.jsx)(Ir,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.edit`,p)]}),He&&(I||n)&&(0,X.jsx)(km,{saving:w,isDirty:Be,autoSaveEnabled:le,lastSavedAt:se,createMode:!!n,locale:p}),He&&(I||n)&&!n&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>ue(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:Z(le?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,p),children:le?(0,X.jsx)($i,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,X.jsx)(nr,{className:`h-3.5 w-3.5`})}),He&&!n&&I&&!Xe&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:$e,disabled:w,className:`h-7 w-7 p-0`,title:Z(`engine.cancel`,p),children:(0,X.jsx)(Yi,{className:`h-3.5 w-3.5`})}),He&&(I||n)&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>Fe(!1),disabled:w||!n&&!Be,className:`h-7 w-7 p-0 relative`,title:w?Z(`engine.edit.saving`,p):!n&&!Be?Z(`engine.edit.noChanges`,p):`${Z(`engine.edit.save`,p)} (⌘S)`,children:[w?(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(li,{className:`h-3.5 w-3.5`}),Be&&!w&&(0,X.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),He&&!n&&te&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:ze,disabled:w||N,className:`h-7 w-7 p-0 text-muted-foreground`,title:Z(`engine.edit.discardDraft`,p),children:(0,X.jsx)(Ee,{className:`h-3.5 w-3.5`})}),He&&!n&&te&&(0,X.jsx)(q,{size:`sm`,onClick:Re,disabled:w||N||Be,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:Z(Be?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,p),children:N?(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ur,{className:`h-3.5 w-3.5 mr-1`}),(0,X.jsx)(`span`,{className:`text-xs`,children:Z(`engine.edit.publish`,p)})]})})]});return(0,X.jsxs)(op,{entry:d??{type:o,label:o},itemName:n?`(new)`:s,subtitle:n?Z(`engine.edit.createNew`,p):void 0,actions:Xe?null:tt,children:[(0,X.jsxs)(`div`,{className:Xe?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(E||Ge||te)&&(0,X.jsxs)(`div`,{className:Xe?`px-6 pt-4 space-y-3`:`space-y-3`,children:[E&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:E}),te&&!n&&(0,X.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,X.jsx)(Ur,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`flex-1`,children:Z(`engine.edit.draftPending`,p)}),He&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{size:`sm`,variant:`ghost`,onClick:ze,disabled:w||N,className:`h-7`,children:Z(`engine.edit.discardDraft`,p)}),(0,X.jsx)(q,{size:`sm`,onClick:Re,disabled:w||N||Be,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:N?(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}):Z(`engine.edit.publish`,p)})]})]}),Ge&&(0,X.jsxs)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-3 dark:text-amber-200 dark:border-amber-700/50 dark:bg-amber-950/30 flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`flex-1`,children:Ye?Z(`engine.edit.artifactLockedBanner`,p).split(/(\{type\})/).map((e,t)=>e===`{type}`?(0,X.jsx)(`code`,{className:`font-mono`,children:o},t):(0,X.jsx)(Y.Fragment,{children:e},t)):Z(`engine.edit.readOnlyTypeBanner`,p).split(/(\{flag\}|\{type\}|\{override\})/).map((e,t)=>e===`{flag}`?(0,X.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},t):e===`{type}`?(0,X.jsx)(`code`,{className:`font-mono`,children:o},t):e===`{override}`?(0,X.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},t):(0,X.jsx)(Y.Fragment,{children:e},t))}),Ye&&(0,X.jsx)(q,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>c(`../new`,{relative:`path`}),children:Z(`engine.list.create`,p)})]})]}),(0,X.jsx)(`div`,{className:Xe?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,X.jsxs)(`div`,{className:Xe?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!Xe&&et&&!Ge&&He&&!n&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,X.jsx)(`span`,{children:Z(`engine.edit.readOnlyBanner`,p).split(/\{edit\}/).map((e,t,n)=>(0,X.jsxs)(Y.Fragment,{children:[e,t<n.length-1&&(0,X.jsx)(`strong`,{children:Z(`engine.edit.edit`,p)})]},t))}),(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>L(!0),children:[(0,X.jsx)(Ir,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.edit`,p)]})]}),(()=>{let e=h?._diagnostics;if(!e||e.valid!==!1)return null;let t=e.errors??[],n=t.slice(0,3),r=Math.max(0,t.length-n.length);return(0,X.jsxs)(`div`,{className:`flex items-start gap-2 text-xs border rounded p-2.5 border-destructive/40 bg-destructive/[0.06] text-destructive`,children:[(0,X.jsx)(Ot,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:Zf(`engine.edit.diagnostics.title`,p,{count:t.length})}),(0,X.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,X.jsxs)(`li`,{className:`truncate`,children:[(0,X.jsx)(`span`,{className:`opacity-70`,children:e.path||`(root)`}),`: `,e.message]},t)),r>0&&(0,X.jsx)(`li`,{className:`opacity-70`,children:Zf(`engine.edit.diagnostics.more`,p,{count:r})})]})]})]})})(),Xe?(0,X.jsx)(`div`,{className:Me?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,X.jsxs)(wm,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${o}`,children:[(0,X.jsx)(vt,{defaultSize:62,minSize:30,children:(0,X.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b bg-background/95 backdrop-blur px-3 py-2 sticky top-0 z-10`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:He&&(0,X.jsxs)(`div`,{role:`tablist`,"aria-label":Z(`engine.edit.designer`,p),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Ae,onClick:()=>je(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ae?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:Z(`engine.edit.designMode`,p),children:[(0,X.jsx)(Dn,{className:`h-3.5 w-3.5`}),Z(`engine.edit.designMode`,p)]}),(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Ae,onClick:()=>je(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ae?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Z(`engine.edit.previewMode`,p),children:[(0,X.jsx)(En,{className:`h-3.5 w-3.5`}),Z(`engine.edit.previewMode`,p)]})]})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[tt,(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),Xe&&(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:ke,className:`h-7 w-7 p-0`,title:Z(we?`engine.edit.showInspector`:`engine.edit.hideInspector`,p)+` (⌘\\)`,children:we?(0,X.jsx)(Ue,{className:`h-3.5 w-3.5`}):(0,X.jsx)(at,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>Ne(e=>!e),className:`h-7 w-7 p-0`,title:Z(Me?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,p),children:Me?(0,X.jsx)(lt,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Zt,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4 bg-[radial-gradient(circle_at_1px_1px,theme(colors.border)_1px,transparent_0)] [background-size:16px_16px] bg-muted/30`,children:(0,X.jsx)(Xe,{type:o,name:s,draft:_,editing:I&&!Ae,selection:Ae?null:ie,onSelectionChange:ae,locale:p,onPatch:e=>y(t=>({...t,...e}))})})]})}),(0,X.jsx)(Ze,{withHandle:!0,className:we?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,X.jsx)(vt,{panelRef:Oe,defaultSize:W.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(W.current=t,typeof window<`u`&&window.localStorage.setItem(Ce,String(Math.round(t)))),Te(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Se,n?`1`:`0`),n))},children:(0,X.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,X.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,X.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":be===`properties`,onClick:()=>xe(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(be===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Z(`engine.edit.inspector.properties`,p),children:[(0,X.jsx)(Ti,{className:`h-3.5 w-3.5`}),Z(`engine.edit.inspector.properties`,p)]}),(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":be===`source`,onClick:()=>xe(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(be===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Z(`engine.edit.inspector.source`,p),children:[(0,X.jsx)(xn,{className:`h-3.5 w-3.5`}),Z(`engine.edit.inspector.source`,p)]})]}),Be&&(0,X.jsxs)(G,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,X.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),Z(`engine.edit.unsaved`,p)]})]}),(0,X.jsx)(`div`,{className:`p-4`,children:be===`source`?(0,X.jsx)(Om,{value:_,onChange:y,readOnly:et}):ie&&Qe?(0,X.jsx)(Qe,{type:o,name:s,draft:_,selection:ie,onPatch:e=>y(t=>({...t,...e})),onClearSelection:()=>ae(null),onSelectionChange:ae,readOnly:et,locale:p}):(0,X.jsx)(Kp,{schema:Je,form:d?.form,value:_,onChange:y,issues:O,hiddenFields:f.hiddenFields,fieldOrder:f.fieldOrder,readOnly:et,createMode:n,widgetContext:me})})]})})]})}):(0,X.jsx)(Kp,{schema:Je,form:d?.form,value:_,onChange:y,issues:O,hiddenFields:f.hiddenFields,fieldOrder:f.fieldOrder,readOnly:et,createMode:n,widgetContext:me})]})})]}),(0,X.jsx)(kt,{open:U===`layers`,onOpenChange:e=>!e&&ye(null),children:(0,X.jsxs)(It,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Ke,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(ct,{className:`text-base`,children:Z(`engine.edit.layers`,p)}),(0,X.jsxs)(Jt,{className:`text-xs`,children:[o,` / `,s]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(wp,{layered:h,locale:p})})]})}),(0,X.jsx)(kt,{open:U===`references`,onOpenChange:e=>!e&&ye(null),children:(0,X.jsxs)(It,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Ke,{className:`px-4 py-3 border-b`,children:[(0,X.jsxs)(ct,{className:`text-base`,children:[Z(`engine.edit.references`,p),b&&(0,X.jsx)(G,{variant:`outline`,className:`ml-2 text-[10px]`,children:b.length})]}),(0,X.jsxs)(Jt,{className:`text-xs`,children:[o,` / `,s]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(Dm,{refs:b,loading:he})})]})}),_e&&(0,X.jsx)(kt,{open:U===`related`,onOpenChange:e=>!e&&ye(null),children:(0,X.jsxs)(It,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Ke,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(ct,{className:`text-base`,children:Z(`engine.edit.related`,p)}),(0,X.jsxs)(Jt,{className:`text-xs`,children:[o,` / `,s]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(sm,{type:o,name:s,parentItem:_,onOpen:e=>ge(e)})})]})}),!n&&(0,X.jsx)(kt,{open:U===`history`,onOpenChange:e=>!e&&ye(null),children:(0,X.jsxs)(It,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Ke,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(ct,{className:`text-base`,children:Z(`engine.edit.history`,p)}),(0,X.jsxs)(Jt,{className:`text-xs`,children:[o,` / `,s]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(hm,{type:o,name:s,client:l,onRollback:()=>re(e=>e+1),rollbackLabel:Z(`engine.edit.rollback`,p),rollbackConfirm:e=>Z(`engine.edit.rollbackConfirm`,p).replace(`{version}`,String(e))})})]})}),(0,X.jsx)(pm,{target:H,onClose:()=>ge(null),parentContext:{type:o,name:s}}),(0,X.jsx)(We,{open:A!=null,onOpenChange:e=>{e||(j(null),ee(null))},children:(0,X.jsxs)(ot,{children:[(0,X.jsxs)(ia,{children:[(0,X.jsxs)(De,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ot,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,X.jsx)(xt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,X.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:A?.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,X.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,X.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,X.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{variant:`ghost`,onClick:()=>j(null),children:`Cancel`}),(0,X.jsx)(q,{variant:`destructive`,onClick:()=>Fe(!0),disabled:w,children:w?`Forcing…`:`Force save`})]})]})})]})}function Dm({refs:e,loading:t}){return t||e==null?(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:`No references found`}),(0,X.jsx)(rt,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,X.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,X.jsx)(`td`,{className:`px-3 py-2`,children:(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function Om({value:e,onChange:t,readOnly:n}){let r=Y.useCallback(e=>{try{return JSON.stringify(e??{},null,2)}catch{return`{}`}},[]),[i,a]=Y.useState(()=>r(e)),[o,s]=Y.useState(null),c=Y.useRef(i);Y.useEffect(()=>{let t=r(e);t!==c.current&&(a(t),c.current=t,s(null))},[e,r]);let l=e=>{a(e);try{let n=JSON.parse(e);n&&typeof n==`object`&&!Array.isArray(n)?(s(null),c.current=e,t(n)):s(`Root must be a JSON object`)}catch(e){s(e?.message??`Invalid JSON`)}};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`textarea`,{value:i,onChange:e=>l(e.target.value),readOnly:n,spellCheck:!1,className:`w-full min-h-[60vh] font-mono text-xs bg-muted/30 border rounded p-3 outline-none focus:ring-2 focus:ring-ring resize-y`}),o&&(0,X.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,X.jsx)(`span`,{children:o})]})]})}function km({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=Y.useReducer(e=>e+1,0);return Y.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,X.jsx)(jr,{className:`h-3 w-3 animate-spin`}),Z(`engine.edit.saving`,a)]}):t?i?null:(0,X.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),Z(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:Zf(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function Am({type:e}){let t=u(),[n]=o(),r=e??n.get(`type`)??``;if(!r)return(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:`Missing metadata type`}),(0,X.jsxs)(rt,{children:[`This page expects a `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,X.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let i=jm(t.pathname),a=i.split(`/`).filter(Boolean);return a.length===0?(0,X.jsx)(mp,{type:r}):a[0]===`new`&&a.length===1?(0,X.jsx)(Em,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,X.jsx)(mm,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,X.jsx)(Em,{type:r,name:decodeURIComponent(a[0])},`${r}:${a[0]}`):(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(Ve,{children:[(0,X.jsx)(ta,{children:`Unknown sub-path`}),(0,X.jsxs)(rt,{children:[`The path `,(0,X.jsx)(`code`,{className:`font-mono`,children:i}),` isn't recognized. Valid forms are `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function jm(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function Mm(e){return[{key:`allowCreate`,short:`C`,tip:Z(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:Z(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:Z(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:Z(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:Z(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:Z(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:Z(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:Z(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:Z(`perm.action.modifyAll`,e)}]}function Nm({type:e,name:t}){let n=v(),r=zf(),{entries:i}=Bf(r),a=i.find(t=>t.type===e),o=!!fp(e,a).allowOrgOverride,s=Y.useMemo(()=>Qf(),[]),c=Y.useCallback(e=>Z(e,s),[s]),l=Y.useMemo(()=>Mm(s),[s]),[u,d]=Y.useState({name:t,objects:{},fields:{}}),[f,p]=Y.useState([]),[m,h]=Y.useState({}),[g,_]=Y.useState(new Set),[y,b]=Y.useState(!0),[x,S]=Y.useState(!1),[C,w]=Y.useState(null),[T,E]=Y.useState(null),[D,O]=Y.useState(``),[k,A]=Y.useState(!1);Y.useEffect(()=>{let n=!1;return b(!0),(async()=>{try{let[i,a]=await Promise.all([r.layered(e,t).catch(()=>null),r.list(`object`).catch(()=>[])]);if(n)return;let o=i?.effective??i?.code??{name:t,objects:{}};d({...o,name:String(o?.name??t),objects:o?.objects??{},fields:o?.fields??{}}),p((a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name)))}catch(e){w(e?.message??String(e))}finally{n||b(!1)}})(),()=>{n=!0}},[r,e,t]);async function j(e){if(!m[e])try{let t=(await r.list(`field`)??[]).map(e=>e?.item??e).filter(t=>String(t?.object??``)===e).map(e=>({name:String(e?.name??``),label:e?.label})).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));h(n=>({...n,[e]:t}))}catch{h(t=>({...t,[e]:[]}))}}function M(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),j(e)),n})}function ee(e,t,n){d(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function te(e,t){d(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(l.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function ne(e,t,n,r){let i=`${e}.${t}`;d(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function N(t,n){let i=n??u;S(!0),w(null);try{await r.save(e,i.name,i,{force:t}),d((await r.layered(e,i.name)).effective??i),E(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];E({issues:Array.isArray(t)?t:[],pending:i})}else w(e?.message??String(e))}finally{S(!1)}}let P=Y.useMemo(()=>{let e=D.trim().toLowerCase();return f.filter(t=>{if(k){let e=u.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[f,D,k,u.objects]),F=[{label:c(`perm.stat.objectsGranted`),value:Object.values(u.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:c(`perm.stat.fieldOverrides`),value:Object.keys(u.fields??{}).length}];return y?(0,X.jsx)(op,{entry:a,itemName:t,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,X.jsxs)(op,{entry:a??{type:e,label:e},itemName:t,subtitle:u.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:F,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,X.jsx)(Ie,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>N(!1),disabled:x,children:[x?(0,X.jsx)(jr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(li,{className:`h-4 w-4 mr-1`}),c(`engine.edit.save`)]})]}),children:[(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[C&&(0,X.jsxs)(`div`,{className:`m-4 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive flex items-start gap-2`,children:[(0,X.jsx)(Ot,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{children:C})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Nr,{htmlFor:`perm-name`,className:`text-xs`,children:c(`perm.field.name`)}),(0,X.jsx)(K,{id:`perm-name`,value:u.name,disabled:!o,onChange:e=>d(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Nr,{htmlFor:`perm-label`,className:`text-xs`,children:c(`perm.field.label`)}),(0,X.jsx)(K,{id:`perm-label`,value:u.label??``,disabled:!o,onChange:e=>d(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,X.jsx)(qr,{id:`perm-is-profile`,checked:!!u.isProfile,disabled:!o,onCheckedChange:e=>d(t=>({...t,isProfile:!!e}))}),(0,X.jsx)(Nr,{htmlFor:`perm-is-profile`,className:`text-xs`,children:c(`perm.field.isProfile`)})]}),!o&&(0,X.jsx)(G,{variant:`secondary`,className:`ml-auto`,children:c(`perm.readOnly`)})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,X.jsx)(K,{placeholder:c(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(qr,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,X.jsx)(Nr,{htmlFor:`only-enabled`,className:`text-xs`,children:c(`perm.filter.onlyGranted`)})]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[P.length,` / `,f.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,X.jsx)(Pm,{objects:P,draft:u,expanded:g,fieldsByObject:m,writable:o,objectActions:l,t:c,onToggleExpand:M,onObjectPerm:ee,onFieldPerm:ne,onBulkSet:te})})]}),(0,X.jsx)(We,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,X.jsxs)(ot,{children:[(0,X.jsxs)(ia,{children:[(0,X.jsxs)(De,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ot,{className:`h-4 w-4 text-amber-500`}),` `,c(`engine.edit.destructive`)]}),(0,X.jsx)(xt,{children:c(`engine.edit.destructiveHint`)})]}),(0,X.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:T?.issues.map((e,t)=>(0,X.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,X.jsx)(G,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(q,{variant:`ghost`,onClick:()=>E(null),children:c(`engine.cancel`)}),(0,X.jsxs)(q,{variant:`destructive`,onClick:()=>T&&N(!0,T.pending),disabled:x,children:[x&&(0,X.jsx)(jr,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function Pm({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,X.jsxs)(`tbody`,{children:[e.length===0&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:a.length+2,className:`px-4 py-8 text-center text-muted-foreground`,children:o(`perm.filter.empty`)})}),e.map(e=>{let d=t.objects[e.name]??{},f=n.has(e.name);return(0,X.jsxs)(Y.Fragment,{children:[(0,X.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,X.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,X.jsx)(sn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(tr,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,X.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,X.jsx)(Ye,{checked:!!d[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,X.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`read`),children:o(`perm.bulk.read`)}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`crud`),children:o(`perm.bulk.crud`)}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`all`),children:o(`perm.bulk.all`)}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),f&&(0,X.jsx)(`tr`,{className:`bg-muted/10`,children:(0,X.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,X.jsx)(Fm,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function Fm({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,X.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,X.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,X.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,X.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(Ye,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(Ye,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function Im(){lp({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Lm(e.fields),groupLabel:`Fields`,order:5}]}),lp({type:`__object_index`,label:`Index`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`index`,embeddedPath:`indexes`,extract:e=>{let t=e.indexes;return Array.isArray(t)?t.map((e,t)=>{let n=Array.isArray(e.fields)?e.fields.join(`,`):``;return{name:n?`idx_${n}`:`index_${t}`,...e}}):[]},groupLabel:`Indexes`,order:10}]}),lp({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Lm(e.validations),groupLabel:`Embedded Validations`,order:15}]}),lp({type:`hook`,anchors:[{anchorType:`object`,match:sp(`object`),groupLabel:`Hooks`,order:20}]}),lp({type:`approval`,anchors:[{anchorType:`object`,match:sp(`object`),groupLabel:`Approval Processes`,order:70}]}),lp({type:`page`,anchors:[{anchorType:`object`,match:sp(`object`),groupLabel:`Pages`,order:40}]}),lp({type:`view`,anchors:[{anchorType:`object`,match:sp([`data.object`,`list.data.object`,`form.data.object`,`object`]),groupLabel:`Views`,order:30}]}),lp({type:`flow`,anchors:[{anchorType:`object`,match:sp([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}]}),lp({type:`workflow`,anchors:[{anchorType:`object`,match:sp([`object`,`on.object`]),groupLabel:`Workflow Rules`,order:51}]}),lp({type:`trigger`,anchors:[{anchorType:`object`,match:sp([`object`,`on.object`]),groupLabel:`Triggers`,order:52}]}),lp({type:`validation`,anchors:[{anchorType:`object`,match:sp(`object`),groupLabel:`Validations`,order:25}]}),lp({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}]}),lp({type:`action`,anchors:[{anchorType:`object`,match:sp([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}]}),lp({type:`dashboard`,anchors:[{anchorType:`object`,match:sp([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}]}),lp({type:`report`,anchors:[{anchorType:`object`,match:sp([`object`,`data.object`]),groupLabel:`Reports`,order:81}]}),lp({type:`object`,iconName:`database`,domain:`data`,searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function Lm(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Rm={name:{type:`string`,title:`Name`,description:`Machine name. snake_case, used as the URL path and DB key.`,pattern:`^[a-z_][a-z0-9_]*$`},label:{type:`string`,title:`Label`,description:`Human-readable display name.`},description:{type:`string`,title:`Description`,format:`multiline`}},zm={role:{type:`object`,title:`Role`,required:[`name`],properties:{...Rm,level:{type:`string`,title:`Level`,description:`Coarse seniority tier (used by UI / sort order).`,enum:[`member`,`lead`,`manager`,`director`,`executive`,`admin`]},parentRole:{type:`string`,title:`Parent Role`,description:`Optional parent role name for hierarchy.`}}},profile:{type:`object`,title:`Profile`,required:[`name`],properties:{...Rm,isProfile:{type:`boolean`,title:`Is profile`,description:`Profiles are mutually exclusive (one per user).`},objects:{type:`object`,title:`Object Permissions`,description:`Edit this via the Permission Matrix tab for a row-by-row UI.`}}},permission:{type:`object`,title:`Permission Set`,required:[`name`],properties:{...Rm,isProfile:{type:`boolean`,title:`Is profile`},objects:{type:`object`,title:`Object Permissions`},fields:{type:`object`,title:`Field Permissions`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...Rm.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Rm.label,description:Rm.description,locale:{type:`string`,title:`Locale`,description:`BCP-47 tag, e.g. en, zh-Hans, ja-JP.`},strings:{type:`object`,title:`Strings`,description:`Key → translated string map.`}}},tool:{type:`object`,title:`AI Tool`,required:[`name`],properties:{...Rm,kind:{type:`string`,title:`Kind`,enum:[`function`,`http`,`mcp`]},inputSchema:{type:`object`,title:`Input Schema (JSON Schema)`},outputSchema:{type:`object`,title:`Output Schema (JSON Schema)`}}},skill:{type:`object`,title:`AI Skill`,required:[`name`],properties:{...Rm,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Rm,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Rm,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Rm,type:{type:`string`,title:`View Type`,enum:[`grid`,`kanban`,`calendar`,`gantt`,`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]}}},dashboard:{type:`object`,title:`Dashboard`,required:[`name`],properties:{...Rm,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Rm,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...Rm,category:{type:`string`,title:`Category`,enum:[`auth`,`notification`,`workflow`,`marketing`,`custom`],default:`custom`},locale:{type:`string`,title:`Locale`,default:`en-US`,description:`BCP-47 tag (en-US, zh-CN, …)`},subject:{type:`string`,title:`Subject`,description:`Supports {{var.path}} interpolation`},bodyHtml:{type:`string`,title:`HTML Body`,format:`multiline`},bodyText:{type:`string`,title:`Plain-Text Body`,format:`multiline`},variables:{type:`array`,title:`Variables`,items:{type:`object`}},fromOverride:{type:`object`,title:`From Override`},replyTo:{type:`string`,title:`Reply-To`},active:{type:`boolean`,title:`Active`,default:!0},isSystem:{type:`boolean`,title:`System Template`,default:!1}}}};function Bm(){for(let[e,t]of Object.entries(zm))lp({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Q({toolbar:e,children:t}){return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,X.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,X.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function Vm({tone:e=`info`,children:t}){return(0,X.jsxs)(`div`,{className:`m-4 rounded border p-3 text-sm flex items-start gap-2 ${e===`warn`?`text-amber-800 bg-amber-50 border-amber-200`:e===`error`?`text-destructive bg-destructive/5 border-destructive/30`:`text-muted-foreground border-muted`}`,children:[e!==`info`&&(0,X.jsx)(Li,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`div`,{className:`flex-1`,children:t})]})}function Hm({icon:e,title:t,description:n,action:r,tone:i=`info`}){let a=i===`warn`?`text-amber-700 bg-amber-50/40 border-amber-200/60`:`text-muted-foreground border-dashed border-muted-foreground/25 bg-muted/10`,o=e??(0,X.jsx)(Ki,{className:`h-8 w-8 opacity-50`});return(0,X.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,X.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border ${a} px-6 py-10 flex flex-col items-center gap-3 text-center`,children:[(0,X.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,X.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,X.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Um=class extends Y.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,X.jsxs)(Vm,{tone:`error`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,X.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,X.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function Wm({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,X.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:gr(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,X.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:a??`Add`})]})]})]})}function Gm({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=Y.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=Y.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),d=Y.useMemo(()=>{if(u===`regions`){let t=e.regions,n=[];return t.forEach((e,t)=>{(Array.isArray(e.components)?e.components:[]).forEach((r,i)=>{n.push({id:`regions[${t}].components[${i}]`,label:r.id||r.type||`${e.name??`region ${t+1}`} · ${i+1}`})})}),n}return(Array.isArray(e.children)?e.children:[]).map((e,t)=>({id:`children[${t}]`,label:e.id||e.type||`block ${t+1}`}))},[e,u]),f=Y.useCallback(()=>{if(!c)return;let t={type:`container`};if(u===`regions`){let n=Array.isArray(e.regions)?[...e.regions]:[],a=n.length-1;a<0&&(n.push({name:`main`,components:[]}),a=0);let o={...n[a]},s=Array.isArray(o.components)?[...o.components]:[];s.push(t),o.components=s,n[a]=o,i({regions:n}),r?.({kind:`block`,id:`regions[${a}].components[${s.length-1}]`,label:t.type});return}let n=[...Array.isArray(e.children)?e.children:[],t];i({children:n}),r?.({kind:`block`,id:`children[${n.length-1}]`,label:t.type})},[c,e,i,r,u]);return!o||Object.keys(o).length<=1?(0,X.jsxs)(Q,{hint:`page${s?` · design`:``}`,children:[s&&(0,X.jsx)(Wm,{title:Z(`engine.inspector.pageBlock.outlineLabel`,a),entries:d,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?f:void 0,addLabel:Z(`engine.inspector.add.block`,a)}),(0,X.jsx)(Vm,{children:`Add components to the page to see a preview.`})]}):(0,X.jsx)(Q,{hint:`page${s?` · design`:``}`,children:(0,X.jsxs)(Um,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,X.jsx)(Wm,{title:Z(`engine.inspector.pageBlock.outlineLabel`,a),entries:d,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?f:void 0,addLabel:Z(`engine.inspector.add.block`,a)}),(0,X.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,X.jsx)(M,{schema:o})})]})})}var Km=[`list`,`form`,`kanban`,`calendar`,`gantt`,`map`,`gallery`,`timeline`,`feed`,`detail`];function qm(e){let t=[];for(let n of Km){let r=e[n];r&&typeof r==`object`&&!Array.isArray(r)&&t.push({key:n,schema:r})}return t}function Jm(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object,e.list?.data?.object,e.list?.object];for(let e of n)if(typeof e==`string`&&e)return e}function Ym({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a,locale:o}){let s=Y.useMemo(()=>qm(t),[t]),c=Y.useMemo(()=>Jm(t,s[0]?.schema),[t,s]),l=!!(n&&i),u=l&&!!a,d=r&&r.kind===`column`?r.id:null,f=Y.useCallback(e=>{if(!u)return;let n=t[e];if(!n)return;let r=Array.isArray(n.columns)?n.columns:[],o=r.length>0&&r.every(e=>typeof e==`string`)?``:{field:``,label:`New column`},s=[...r,o];a({[e]:{...n,columns:s}}),i?.({kind:`column`,id:`${e}.columns[${s.length-1}]`,label:`New column`})},[u,t,a,i]),p=l?(0,X.jsx)(X.Fragment,{children:s.map(e=>{let t=(Array.isArray(e.schema.columns)?e.schema.columns:[]).map((t,n)=>{let r;if(typeof t==`string`)r=t;else if(t&&typeof t==`object`){let e=t;r=String(e.label??e.header??e.field??e.accessorKey??`col ${n+1}`)}else r=`col ${n+1}`;return{id:`${e.key}.columns[${n}]`,label:s.length>1?`${e.key}.${r}`:r}});return t.length===0&&!u?null:(0,X.jsx)(Wm,{title:s.length>1?`${e.key} · ${Z(`engine.inspector.viewColumn.outlineLabel`,o)}`:Z(`engine.inspector.viewColumn.outlineLabel`,o),entries:t,selectedId:d,onSelect:e=>i?.({kind:`column`,id:e.id,label:e.label}),onAdd:u?()=>f(e.key):void 0,addLabel:Z(`engine.inspector.add.column`,o)},e.key)})}):null,{listViews:m,defaultViewId:h}=Y.useMemo(()=>{let n={},r=s.find(e=>e.key===`list`)??s[0],i=String(e)||r?.key||`default`;r&&(n[i]={...r.schema,label:r.schema.label??t.label??e});let a=t.listViews;if(a&&typeof a==`object`&&!Array.isArray(a))for(let[e,t]of Object.entries(a))t&&typeof t==`object`&&e!==i&&(n[e]=t);return{listViews:n,defaultViewId:r?i:void 0}},[t,s,e]);if(!s.length&&t.type){let e={...t};return(0,X.jsx)(Q,{hint:`view · ${e.type}${l?` · design`:``}`,children:(0,X.jsxs)(Um,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:[p,(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(M,{schema:e})})]})})}if(!c)return(0,X.jsx)(Q,{hint:`view`,children:(0,X.jsxs)(Vm,{tone:`warn`,children:[`This view has no object binding yet. Set `,(0,X.jsx)(`code`,{children:`list.data.object`}),` in the Form tab to fetch live data.`]})});let g=s[0]?.schema?.type??`grid`,_=Y.useMemo(()=>({type:`object-view`,objectName:c,defaultViewType:g,defaultListView:h,listViews:m,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[c,g,h,m]);return(0,X.jsx)(Q,{hint:`view · ${s.map(e=>e.key).slice(0,3).join(` · `)||`list`}${l?` · design`:``}`,children:(0,X.jsxs)(Um,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:[p,(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(M,{schema:_})})]})})}function Xm({kindLabel:e,title:t,onClose:n,closeLabel:r=`Close`,children:i,footer:a,headerActions:o}){return(0,X.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b px-4 py-2.5`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(G,{variant:`secondary`,className:`text-[10px] uppercase tracking-wider`,children:e}),(0,X.jsx)(`div`,{className:`mt-1 truncate text-sm font-medium`,title:t,children:t})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[o,(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:n,"aria-label":r,className:`h-7 w-7 p-0`,children:(0,X.jsx)(Yi,{className:`h-4 w-4`})})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto px-4 py-3 space-y-3`,children:i}),a&&(0,X.jsx)(`div`,{className:`border-t px-4 py-2.5`,children:a})]})}function Zm({index:e,total:t,onMove:n,upLabel:r=`Move up`,downLabel:i=`Move down`,disabled:a}){if(t<=1||e<0)return null;let o=!a&&e>0,s=!a&&e<t-1;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o&&n(e-1),disabled:!o,"aria-label":r,title:r,children:(0,X.jsx)(_n,{className:`h-4 w-4`})}),(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>s&&n(e+1),disabled:!s,"aria-label":i,title:i,children:(0,X.jsx)(zn,{className:`h-4 w-4`})})]})}function Qm({label:e,value:t,onCommit:n,placeholder:r,disabled:i,mono:a}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Nr,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(K,{value:t,onChange:e=>n(e.target.value),placeholder:r,disabled:i,className:gr(`h-8 text-sm`,a&&`font-mono`)})]})}function $m({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Nr,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(K,{type:`number`,value:t??``,onChange:e=>{let t=e.target.value;n(t===``?void 0:Number(t))},placeholder:r,disabled:i,className:`h-8 text-sm`})]})}function eh({label:e,value:t,options:n,onCommit:r,placeholder:i=`—`,disabled:a}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Nr,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsxs)(on,{value:t??``,onValueChange:r,disabled:a,children:[(0,X.jsx)(Tn,{className:`h-8 text-sm`,children:(0,X.jsx)(nt,{placeholder:i})}),(0,X.jsx)(oa,{children:n.map(e=>(0,X.jsx)(Oe,{value:e.value,children:e.label},e.value))})]})]})}function th({label:e,value:t,onCommit:n,disabled:r}){return(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer select-none`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:t,disabled:r,onChange:e=>n(e.target.checked),className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:e})]})}function nh({label:e,onClick:t,disabled:n}){return(0,X.jsx)(q,{variant:`destructive`,size:`sm`,onClick:t,disabled:n,className:`w-full`,children:e})}function rh({message:e}){return(0,X.jsx)(`div`,{className:`text-xs italic text-muted-foreground p-4 text-center`,children:e})}function ih(e,t,n){let r=Array.isArray(e)?[...e]:[];return n===null?r.splice(t,1):r[t]=n,r}function ah(e,t){let n=Array.isArray(e)?[...e]:[];return n.push(t),n}function oh(e,t,n){let r=Array.isArray(e)?[...e]:[];if(t<0||t>=r.length)return r;let i=Math.max(0,Math.min(r.length-1,n));if(i===t)return r;let[a]=r.splice(t,1);return r.splice(i,0,a),r}function sh(e,t){let n=new Set(t.filter(e=>typeof e==`string`));for(let t=1;t<1e4;t++){let r=`${e}_${t}`;if(!n.has(r))return r}return`${e}_${Date.now()}`}var ch=Y.lazy(()=>m(()=>import(`./plugin-dashboard-DqF5vvlQ.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function lh({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=he(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=Y.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=Y.useCallback(e=>{n&&n({widgets:e})},[n]),p=Y.useCallback(()=>{if(!l)return;let e=sh(`widget`,s.map(e=>e?.id).filter(Boolean));n({widgets:ah(s,{id:e,type:`metric`,title:`New widget`})}),i?.({kind:`widget`,id:e,label:`New widget`})},[l,s,n,i]),m=l?(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:p,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.widget`,a)]}):null;return s.length===0?(0,X.jsx)(Q,{hint:`dashboard${c?` · design`:``}`,toolbar:m,children:(0,X.jsx)(Vm,{children:`Add at least one widget to see a preview.`})}):(0,X.jsx)(Q,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:m,children:(0,X.jsx)(Um,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,X.jsx)(ch,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})})}var uh=Y.lazy(()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function dh({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=he(),s=e.object??e.objectName??e.data?.object,c=e.visualization?.type??e.type,l=!!(t&&r),u=l&&!!i,d=n&&n.kind===`column`?n.id:null,f=Y.useMemo(()=>(Array.isArray(e.columns)?e.columns:[]).map((e,t)=>({id:`columns[${t}]`,label:String(e.label??e.field??`col ${t+1}`)})),[e]),p=Y.useCallback(()=>{if(!u)return;let t=Array.isArray(e.columns)?e.columns:[],n={field:``,label:`New column`},a=[...t,n];i({columns:a}),r?.({kind:`column`,id:`columns[${a.length-1}]`,label:n.label})},[u,e,i,r]),m=Y.useMemo(()=>({columns:[],...e}),[e]);return s?Array.isArray(e.columns)&&e.columns.length>0?(0,X.jsx)(Q,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,X.jsxs)(Um,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,X.jsx)(Wm,{title:Z(`engine.inspector.reportColumn.outlineLabel`,a),entries:f,selectedId:d,onSelect:e=>r?.({kind:`column`,id:e.id,label:e.label}),onAdd:u?p:void 0,addLabel:Z(`engine.inspector.add.column`,a)}),(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 min-h-[300px] max-h-[70vh] overflow-auto`,children:(0,X.jsx)(uh,{schema:m,dataSource:o})})})]})}):(0,X.jsxs)(Q,{children:[l&&(0,X.jsx)(Wm,{title:Z(`engine.inspector.reportColumn.outlineLabel`,a),entries:f,selectedId:d,onSelect:e=>r?.({kind:`column`,id:e.id,label:e.label}),onAdd:u?p:void 0,addLabel:Z(`engine.inspector.add.column`,a)}),(0,X.jsx)(Hm,{icon:(0,X.jsx)(vi,{className:`h-8 w-8`}),title:`No columns yet`,description:u?`Add at least one column to preview the report against live data.`:`Define columns in the Properties tab to see a preview.`,action:u?(0,X.jsxs)(`button`,{type:`button`,onClick:p,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent transition-colors`,children:[(0,X.jsx)(fn,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,X.jsx)(Q,{children:(0,X.jsx)(Hm,{icon:(0,X.jsx)(Xt,{className:`h-8 w-8`}),title:`Pick a source object to preview the report`,description:`Reports need a source object — choose one in the Object Name field on the right panel to start designing.`})})}function fh(e){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let t=String(e.label??e.title??e.name??e.path??``).trim();if(!t&&!e.children)return null;let n=e.path??e.href??e.route??e.url??void 0,r;e.object||e.objectName?r=`object`:e.page||e.pageName?r=`page`:e.dashboard?r=`dashboard`:e.report?r=`report`:typeof n==`string`&&/^https?:/i.test(n)?r=`link`:Array.isArray(e.children)&&e.children.length&&(r=`group`);let i=Array.isArray(e.children)?fh(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function ph(e){switch(e){case`object`:return Xt;case`page`:return na;case`dashboard`:return ci;case`report`:return Pe;default:return ei}}function mh({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a,locale:o}){let s=String(t.name??e??``),c=t.label??s,l=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:u,navItems:d}=Y.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:fh(n)};return{rootKey:null,navItems:[]}},[t]),f=u??`nav`,p=!!(n&&i),m=p&&!!u,h=p&&!!a,g=r&&r.kind===`nav`?r.id:null,_=m?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,v=Y.useCallback(()=>{if(!h)return;let e=t[f]??[],n={label:`New item`,path:``},r=ah(e,n);a({[f]:r}),i?.({kind:`nav`,id:`${f}[${r.length-1}]`,label:n.label})},[h,f,t,a,i]),y=s?`/apps/${encodeURIComponent(s)}/`:null;return(0,X.jsx)(Q,{hint:`app`,toolbar:y&&(0,X.jsxs)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,X.jsx)(pt,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(c)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:s}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,X.jsx)(`code`,{className:`font-mono`,children:String(l)})]})]}),d.length===0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(Vm,{children:[`No top-level nav items. Add `,(0,X.jsx)(`code`,{children:`nav`}),` / `,(0,X.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}),h&&(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:v,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.nav`,o)]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`border rounded divide-y`,children:d.map((e,t)=>(0,X.jsx)(hh,{item:e,appName:s,depth:0,path:`${u}[${t}]`,onSelect:_,selectedId:g},t))}),h&&(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:v,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.nav`,o)]})]})]})})})}function hh({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=ph(e.kind),s=gh(t,e.path);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40 ${i?`cursor-pointer`:``} ${a===r?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+n*16}px`},onClick:i?t=>{t.stopPropagation(),i(r,e)}:void 0,children:[(0,X.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,X.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,X.jsx)(pt,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,X.jsx)(hh,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function gh(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function _h(e){return e?(Array.isArray(e)?e.map((e,t)=>({name:String(e?.name??`field_${t+1}`),def:e})).filter(e=>!!e.name):Object.entries(e).map(([e,t])=>({name:e,def:t}))).map(({name:e,def:t})=>({field:e,label:String(t?.label??e),type:t?.type})):[]}function vh({name:e,draft:t}){let n=String(t.name??e??``),r=Y.useMemo(()=>_h(t.fields),[t]),i=String(t.label??n),a=String(t.pluralLabel??`${i}s`);if(!n)return(0,X.jsx)(Q,{hint:`object`,children:(0,X.jsx)(Vm,{children:`Give the object a name in the Form tab to enable the preview.`})});if(r.length===0)return(0,X.jsx)(Q,{hint:`object · 0 fields`,children:(0,X.jsx)(Vm,{children:`Add at least one field in the Form tab to enable the preview.`})});let o={type:`object-grid`,objectName:n,label:a,columns:r};return(0,X.jsx)(Q,{hint:`object · ${r.length} field${r.length===1?``:`s`}`,children:(0,X.jsx)(Um,{fallbackHint:`The object metadata couldn't be rendered. Save the draft and reload to retry.`,children:(0,X.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,X.jsx)(ya,{schema:o})})})})}function yh(e){let t=new Set;for(let n of e.matchAll(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g))t.add(n[1]);for(let n of e.matchAll(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g))t.add(n[1]);return Array.from(t).sort()}function bh(e,t){return t[e]??``}function xh(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>bh(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>bh(n,t))}function Sh({draft:e}){let t=String(e.subject??``),n=String(e.from??e.fromAddress??``),r=String(e.to??``),i=String(e.bodyHtml??e.html??e.body??``),a=String(e.bodyText??e.text??``),o=Y.useMemo(()=>{let e=new Set;for(let n of yh(t))e.add(n);for(let t of yh(i))e.add(t);for(let t of yh(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=Y.useState({}),l=xh(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
16
|
-
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
17
|
-
a{color:#2563eb;}
|
|
18
|
-
</style></head><body>${(i?xh(i,s):xh(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(Vm,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,X.jsx)(`iframe`,{title:`Email preview`,srcDoc:u,sandbox:`allow-same-origin`,className:`w-full min-h-[400px] max-h-[60vh] border rounded bg-white`})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(wi,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,X.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,X.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,X.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,X.jsxs)(`label`,{className:`block`,children:[(0,X.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,X.jsx)(`input`,{type:`text`,value:s[e]??``,onChange:t=>c(n=>({...n,[e]:t.target.value})),placeholder:`sample for ${e}`,className:`w-full text-xs px-2 py-1 border rounded bg-background`})]},e))})]})]})})})}function Ch(e){switch(e){case`start`:return Ne;case`end`:return dr;case`decision`:case`branch`:case`gateway`:return Vn;case`wait`:case`timer`:return an;case`boundary_event`:case`signal`:return $i;case`subflow`:case`flow`:return je;default:return kr}}function wh(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Th(e,t){if(e.length===0)return[];let n=new Map(e.map(e=>[e.id,e])),r=new Map;for(let e of t)!n.has(e.source)||!n.has(e.target)||(r.has(e.source)||r.set(e.source,[]),r.get(e.source).push(e.target));let i=e.find(e=>e.type===`start`)??e[0],a=new Set,o=[],s=[i.id];for(;s.length;){let e=s.shift();if(a.has(e))continue;a.add(e);let t=n.get(e);t&&o.push(t);for(let t of r.get(e)??[])a.has(t)||s.push(t)}for(let t of e)a.has(t.id)||o.push(t);return o}function Eh({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=e,s=Array.isArray(o.nodes)?o.nodes:[],c=Array.isArray(o.edges)?o.edges:[],l=Array.isArray(o.variables)?o.variables:[],u=!!(t&&r),d=u&&!!i,f=n&&n.kind===`node`?n.id:null,p=e=>r?.({kind:`node`,id:e.id,label:e.label||e.id}),m=Y.useCallback(()=>{if(!d)return;let e={id:sh(`node`,s.map(e=>e.id).filter(Boolean)),type:`task`,label:`New node`};i({nodes:ah(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),h=Y.useMemo(()=>Th(s,c),[s,c]),g=Y.useMemo(()=>{let e=new Map;for(let t of c)e.has(t.source)||e.set(t.source,[]),e.get(t.source).push(t);return e},[c]),_=Y.useMemo(()=>new Map(s.map(e=>[e.id,e])),[s]),v=String(o.type??`autolaunched`),y=String(o.status??(o.active?`active`:`draft`)),b=String(o.runAs??`user`),x=o.version==null?void 0:String(o.version),S=o.errorHandling?.strategy;return s.length===0?(0,X.jsx)(Q,{hint:`flow${u?` · design`:``}`,children:d?(0,X.jsx)(`div`,{className:`p-3`,children:(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-2 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:m,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.node`,a)]})}):(0,X.jsx)(Vm,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,X.jsx)(Q,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,X.jsx)(Um,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,X.jsx)(Nh,{icon:$i,label:`Trigger`,value:v}),(0,X.jsx)(Nh,{icon:kr,label:`Status`,value:y,tone:y===`active`?`green`:y===`draft`?`gray`:`amber`}),(0,X.jsx)(Nh,{icon:ar,label:`Run as`,value:b}),x&&(0,X.jsx)(Nh,{label:`v`,value:x}),S&&(0,X.jsx)(Nh,{icon:jt,label:`On error`,value:S})]}),(0,X.jsx)(`ol`,{className:`space-y-2`,children:h.map((e,t)=>{let n=Ch(e.type),r=g.get(e.id)??[],i=e.type===`decision`||e.type===`branch`||e.type===`gateway`;return(0,X.jsxs)(`li`,{className:`rounded border bg-background ${u?`cursor-pointer hover:border-primary/50`:``} ${f===e.id?`ring-2 ring-primary border-primary`:``}`,onClick:u?t=>{t.stopPropagation(),p(e)}:void 0,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-mono`,children:t+1}),(0,X.jsx)(n,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.id}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.type})]}),Dh(e)&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5 font-mono break-all`,children:Dh(e)})]})]}),r.length>0&&(0,X.jsx)(`div`,{className:`border-t bg-muted/20 px-3 py-1.5 text-[11px] space-y-0.5`,children:r.map((e,t)=>{let n=wh(e.condition),r=_.get(e.target),a=i?e.isDefault?`else`:n?`if ${n}`:e.label??`branch`:e.label??(n?`when ${n}`:`next`);return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(zn,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:a}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:r?.label||e.target}),!r&&(0,X.jsx)(`span`,{className:`ml-1 text-amber-600`,children:`(unresolved)`})]},e.id||t)})})]},e.id||t)})}),d&&(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:m,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.node`,a)]})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(mn,{className:`h-3 w-3`}),` Variables`]}),l.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:l.map((e,t)=>(0,X.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,X.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,X.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]})]})})})}function Dh(e){let t=e.config;if(t){switch(e.type){case`get_record`:case`get_records`:case`find_records`:return Oh(`object`,t.objectName)+Oh(` · id`,t.recordId)+Oh(` → `,t.outputVariable);case`create_record`:case`create_records`:return Oh(`create`,t.objectName)+Ah(t.fields)+Oh(` → `,t.outputVariable);case`update_record`:case`update_records`:return Oh(`update`,t.objectName)+Oh(` #`,t.recordId)+Ah(t.fields);case`delete_record`:case`delete_records`:return Oh(`delete`,t.objectName)+Oh(` #`,t.recordId);case`decision`:case`branch`:case`gateway`:{let e=t.conditions;if(Array.isArray(e)){let t=e.slice(0,3).map(e=>e.label??e.expression??`?`).map(e=>String(e));return t.length?t.join(` | `)+(e.length>3?` …`:``):void 0}return kh(t.expression)}case`screen`:{let e=t.fields;if(Array.isArray(e)&&e.length>0){let t=e.slice(0,4).map(e=>e.name??e.label??`?`).join(`, `);return`${e.length} field(s): ${t}${e.length>4?` …`:``}`}return typeof t.message==`string`?`"${t.message}"`:void 0}case`assignment`:case`assign`:{let e=t.assignments;return Array.isArray(e)?e.slice(0,3).map(e=>`${e.variable??e.target??`?`} = ${jh(e.value??e.expression)}`).join(`; `)+(e.length>3?` …`:``):void 0}case`subflow`:case`flow`:return Oh(`flow`,t.flowName??t.flowId);case`action`:return Oh(`action`,t.actionName??t.actionId);case`wait`:case`timer`:return Oh(`wait`,t.duration??t.delayMs??t.until);case`loop`:case`for_each`:return Oh(`collection`,t.collection)+Oh(` as `,t.itemVariable);case`http_call`:return`${String(t.method??`POST`).toUpperCase()} ${t.url??`?`}`;case`send_email`:return Oh(`template`,t.template??t.templateName)+Oh(` → `,Mh(t.recipients??t.to));case`invoke_agent`:case`agent`:return Oh(`agent`,t.agentName??t.agentId);case`end`:case`start`:return}if(typeof t.objectName==`string`)return`object: ${t.objectName}`;if(typeof t.flowName==`string`)return`flow: ${t.flowName}`;if(typeof t.actionName==`string`)return`action: ${t.actionName}`;if(typeof t.eventType==`string`)return`event: ${t.eventType}`;if(typeof t.expression==`string`)return`expr: ${t.expression}`;try{let e=JSON.stringify(t);return e.length>100?e.slice(0,97)+`…`:e}catch{return}}}function Oh(e,t){return t==null||t===``?``:/[→=]\s*$/.test(e)?`${e}${String(t)}`:`${e}: ${String(t)}`}function kh(e){if(typeof e==`string`)return`if ${e}`;if(e&&typeof e==`object`&&typeof e.source==`string`)return`if ${e.source}`}function Ah(e){if(!e||typeof e!=`object`)return``;let t=Object.keys(e);return t.length===0?``:` {${t.slice(0,3).join(`, `)}${t.length>3?`, …`:``}}`}function jh(e){return e==null?`∅`:typeof e==`string`?`"${e}"`:typeof e==`object`&&typeof e.source==`string`?e.source:typeof e==`object`?JSON.stringify(e):String(e)}function Mh(e){return Array.isArray(e)?e.slice(0,3).join(`, `)+(e.length>3?`, …`:``):typeof e==`string`?e:``}function Nh({icon:e,label:t,value:n,tone:r=`gray`}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,X.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function Ph(e){switch(e){case`field_update`:return Ir;case`email_alert`:return wi;case`http_call`:case`webhook`:return Tt;case`task_creation`:return yi;case`push_notification`:return aa;case`custom_script`:return Zn;case`connector_action`:return Le;default:return Ge}}function Fh(e){switch(e.type){case`field_update`:return`${e.field??(e.objectName?`${e.objectName}.${e.fieldName??`?`}`:`?`)} = ${Ih(e.value)}`;case`email_alert`:return`template: ${e.template??e.templateName??`?`} → ${Lh(e)}`;case`http_call`:case`webhook`:return`${String(e.method??`POST`).toUpperCase()} ${e.url??e.endpoint??`?`}`;case`task_creation`:return`create ${e.taskObject??`?`}${e.assignedTo?` → ${e.assignedTo}`:``}${e.subject?`: "${e.subject}"`:``}`;case`push_notification`:return e.title?`"${e.title}"`:void 0;case`custom_script`:return e.language?`${e.language}${typeof e.code==`string`?` (${e.code.length} chars)`:``}`:e.scriptName??e.functionName??void 0;case`connector_action`:return`${e.connectorId??`?`}.${e.actionId??`?`}`;default:return}}function Ih(e){return e==null?`∅`:typeof e==`string`?`"${e}"`:typeof e==`object`?JSON.stringify(e):String(e)}function Lh(e){let t=e.recipients??e.to;return Array.isArray(t)?t.slice(0,3).join(`, `)+(t.length>3?`, …`:``):typeof t==`string`?t:`—`}function Rh({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=e,s=String(o.objectName??o.object??``),c=String(o.triggerType??o.trigger??`—`),l=o.criteria,u=typeof l==`string`?l:l&&typeof l==`object`&&typeof l.source==`string`?l.source:void 0,d=Array.isArray(o.actions)?o.actions:[],f=Array.isArray(o.timeTriggers)?o.timeTriggers:[],p=o.active!==!1,m=o.executionOrder,h=!!(t&&r),g=h&&!!i,_=n&&n.kind===`action`?n.id:null,v=(e,t)=>r?.({kind:`action`,id:t,label:e.name||e.type||t}),y=Y.useCallback(()=>{if(!g)return;let e={type:`field_update`,name:``},t=ah(d,e);i({actions:t});let n=`actions[${t.length-1}]`;r?.({kind:`action`,id:n,label:e.type})},[g,d,i,r]);return!s&&d.length===0&&f.length===0?(0,X.jsx)(Q,{hint:`workflow${h?` · design`:``}`,children:g?(0,X.jsx)(`div`,{className:`p-3`,children:(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-2 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:y,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.action`,a)]})}):(0,X.jsx)(Vm,{children:`Set the target object and at least one action to see the workflow preview.`})}):(0,X.jsx)(Q,{hint:`workflow · ${d.length+f.reduce((e,t)=>e+(t.actions?.length??0),0)} action(s)`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 text-xs space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,X.jsx)(Uh,{icon:je,label:`Object`,value:s||`—`,mono:!0}),(0,X.jsx)(Uh,{icon:Xr,label:`When`,value:c}),(0,X.jsx)(Uh,{icon:Vi,label:`Active`,value:p?`yes`:`no`,tone:p?`green`:`amber`}),m!=null&&(0,X.jsx)(Uh,{label:`Order`,value:String(m)})]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(He,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Criteria:`}),(0,X.jsx)(`code`,{className:`font-mono text-foreground break-all`,children:u||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`always`})})]})]}),(0,X.jsxs)(Vh,{title:`Immediate Actions`,count:d.length,children:[d.length===0?(0,X.jsx)(Hh,{children:`No immediate actions.`}):(0,X.jsx)(`ul`,{className:`divide-y rounded border bg-background`,children:d.map((e,t)=>{let n=`actions[${t}]`;return(0,X.jsx)(zh,{action:e,onClick:h?()=>v(e,n):void 0,selected:_===n},t)})}),g&&(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:y,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.action`,a)]})]}),f.length>0&&(0,X.jsx)(Vh,{title:`Time-Dependent Actions`,count:f.length,children:(0,X.jsx)(`ul`,{className:`space-y-2`,children:f.map((e,t)=>{let n=e.offset??0,r=e.unit??`hours`,i=e.baseField??e.baseEvent??`trigger`;return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs border-b bg-muted/20`,children:[(0,X.jsx)(Qt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[n>=0?`+`:``,n,` `,r]}),(0,X.jsx)(gt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`after`}),(0,X.jsx)(`code`,{className:`font-mono`,children:i})]}),Array.isArray(e.actions)&&e.actions.length>0?(0,X.jsx)(`ul`,{className:`divide-y`,children:e.actions.map((e,n)=>{let r=`timeTriggers[${t}].actions[${n}]`;return(0,X.jsx)(zh,{action:e,onClick:h?()=>v(e,r):void 0,selected:_===r},n)})}):(0,X.jsx)(Hh,{children:`No actions scheduled at this offset.`})]},t)})})})]})})})}function zh({action:e,onClick:t,selected:n}){let r=Ph(e.type),i=Fh(e),a=e.name;return(0,X.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${t?`cursor-pointer hover:bg-accent/40`:``} ${n?`bg-primary/5 ring-1 ring-primary`:``}`,onClick:t?e=>{e.stopPropagation(),t()}:void 0,children:[(0,X.jsx)(r,{className:`h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2 flex-wrap`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:Bh(e.type)}),a&&(0,X.jsx)(`code`,{className:`font-mono text-[10px] text-foreground`,children:a}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.type})]}),i&&(0,X.jsx)(`div`,{className:`text-muted-foreground font-mono break-all`,children:i})]})]})}function Bh(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Vh({title:e,count:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Hh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-2 py-1.5`,children:e})}function Uh({icon:e,label:t,value:n,tone:r=`gray`,mono:i=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,X.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`} ${i?`font-mono`:``}`,children:n})]})}function Wh({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.role??``),o=n.avatar||void 0,s=String(n.instructions??``),c=n.active!==!1,l=String(n.visibility??`organization`),u=n.model??{},d=Array.isArray(n.skills)?n.skills:[],f=Array.isArray(n.tools)?n.tools:[],p=n.knowledge,m=n.planning,h=n.memory,g=n.guardrails,_=Array.isArray(n.permissions)?n.permissions:[];if(!r&&!s&&d.length===0&&f.length===0)return(0,X.jsx)(Q,{hint:`agent`,children:(0,X.jsx)(Vm,{children:`Fill in label, role, and instructions in the Form tab to see the agent preview.`})});let v=r?`/console/ai/agents/${encodeURIComponent(r)}/chat`:null;return(0,X.jsx)(Q,{hint:`agent`,toolbar:v&&(0,X.jsxs)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open the saved version of this agent in a new chat`,children:[`Try in chat `,(0,X.jsx)(pt,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,X.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,X.jsx)(Ge,{className:`h-5 w-5 text-muted-foreground`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Qh,{icon:c?En:qe,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,X.jsx)(Qh,{icon:gi,label:l}),u.provider&&(0,X.jsx)(Qh,{icon:xe,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,X.jsx)(Qh,{icon:Ut,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,X.jsx)(Qh,{label:`max ${u.maxTokens}t`})]})]})]}),(0,X.jsx)(Kh,{title:`Instructions`,icon:ur,children:s?(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs whitespace-pre-wrap font-mono max-h-[40vh] overflow-auto`,children:s}):(0,X.jsx)(qh,{children:`No system prompt set yet.`})}),(0,X.jsx)(Kh,{title:`Capabilities`,icon:cn,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(Jh,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),mono:!0}),(0,X.jsx)(Jh,{label:`Tools`,emptyHint:`No direct tools (skills can provide them)`,items:f.map((e,t)=>({key:`${e.type??``}:${e.name??t}`,label:e.name??String(e),hint:e.type})),mono:!0})]})}),p&&Object.keys(p).length>0&&(0,X.jsx)(Kh,{title:`Knowledge (RAG)`,icon:Xt,children:(0,X.jsx)(Gh,{knowledge:p})})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,X.jsx)(Yh,{icon:Dt,title:`Planning`,children:(0,X.jsx)(Xh,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,X.jsx)(Yh,{icon:be,title:`Memory`,children:(0,X.jsx)(Xh,{data:{"short.maxMessages":h.shortTerm?.maxMessages,"long.enabled":h.longTerm?.enabled,"long.store":h.longTerm?.store},keys:[`short.maxMessages`,`long.enabled`,`long.store`]})}),g&&Object.keys(g).length>0&&(0,X.jsx)(Yh,{icon:_i,title:`Guardrails`,children:(0,X.jsx)(Xh,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,X.jsx)(Yh,{icon:gi,title:`Permissions`,children:(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,X.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function Gh({knowledge:e}){let t=Array.isArray(e.sources)?e.sources:[],n=Array.isArray(e.indexes)?e.indexes:[],r=[...t,...n];if(r.length===0){let t=Object.keys(e);return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:r.map((e,t)=>{let n=e??{},r=n.id??n.name??`source ${t+1}`,i=n.type??n.kind??``;return(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(Xt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Kh({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function qh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Jh({label:e,emptyHint:t,items:n,mono:r=!1}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] ${r?`font-mono`:``}`,children:[e.label,e.hint&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.hint})]},e.key))})]})}function Yh({icon:e,title:t,children:n}){return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,X.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function Xh({data:e,keys:t}){let n=t.map(t=>[t,Zh(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,X.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function Zh(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function Qh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function $h(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function eg(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${eg(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function tg(e){if(e.default!==void 0)return e.default;if(Array.isArray(e.enum)&&e.enum.length)return e.enum[0];switch(Array.isArray(e.type)?e.type[0]:e.type){case`string`:return e.format?`<${e.format}>`:`<string>`;case`number`:case`integer`:return 0;case`boolean`:return!1;case`array`:return[];case`object`:return{};default:return null}}function ng({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.description??``),o=n.category||void 0,s=n.objectName||void 0,c=!!n.requiresConfirmation,l=n.active!==!1,u=!!n.builtIn,d=n.parameters??{},f=n.outputSchema??void 0,p=$h(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=Y.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=tg(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=tg(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,X.jsx)(Q,{hint:`tool`,children:(0,X.jsx)(Vm,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,X.jsx)(Q,{hint:`tool`,toolbar:r&&(0,X.jsxs)(`a`,{href:`/developer/api-console?path=/api/v1/ai/tools/${encodeURIComponent(r)}/invoke`,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open API Console to test invocation`,children:[`Open in API Console `,(0,X.jsx)(pt,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(cn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,X.jsx)(og,{icon:wn,label:o}),s&&(0,X.jsx)(og,{icon:Xt,label:s,mono:!0}),(0,X.jsx)(og,{icon:Vi,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,X.jsx)(og,{icon:Ot,label:`Requires confirmation`,tone:`amber`}),u&&(0,X.jsx)(og,{label:`built-in`})]})]})]}),a&&(0,X.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,X.jsx)(ig,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,X.jsx)(ag,{children:`This tool takes no input parameters.`}):(0,X.jsx)(rg,{props:p,required:m})}),Object.keys(p).length>0&&(0,X.jsx)(ig,{title:`Example LLM Call`,icon:Qe,children:(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
|
|
19
|
-
"tool": "${r}",
|
|
20
|
-
"arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
|
|
21
|
-
`)}
|
|
22
|
-
}`})}),$h(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,X.jsx)(ig,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Kt,children:(0,X.jsx)(rg,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function rg({props:e,required:t}){return(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:Object.keys(e).map(n=>{let r=e[n],i=t.has(n);return(0,X.jsxs)(`tr`,{className:`align-top`,children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,X.jsx)(Tr,{className:`h-3 w-3 text-emerald-600`}):(0,X.jsx)(tr,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:eg(r)}),(0,X.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,X.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,X.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function ig({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function ag({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function og({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var sg=[{key:`allowCreate`,short:`C`,long:`Create`},{key:`allowRead`,short:`R`,long:`Read`},{key:`allowEdit`,short:`U`,long:`Edit`},{key:`allowDelete`,short:`D`,long:`Delete`},{key:`allowTransfer`,short:`T`,long:`Transfer`},{key:`allowRestore`,short:`Re`,long:`Restore`},{key:`allowPurge`,short:`P`,long:`Purge`,danger:!0},{key:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}];function cg(e){let t=[];for(let[n,r]of Object.entries(e))r.allowEdit&&!r.allowRead&&t.push({object:n,message:`Edit granted without Read (record updates will fail).`}),r.allowDelete&&!r.allowRead&&t.push({object:n,message:`Delete granted without Read.`}),r.modifyAllRecords&&!r.viewAllRecords&&t.push({object:n,message:`Modify All without View All — modifications may target invisible records.`}),r.allowPurge&&!r.allowDelete&&t.push({object:n,message:`Purge (hard delete) granted without Delete.`});return t}function lg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isProfile,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=Y.useMemo(()=>Object.keys(o).sort(),[o]),f=Y.useMemo(()=>cg(o),[o]),p=Y.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,X.jsx)(Q,{hint:`permission`,children:(0,X.jsx)(Vm,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,X.jsx)(Q,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,X.jsx)(_t,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,X.jsx)(Mr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(pg,{icon:Jr,label:`${d.length} objects`}),(0,X.jsx)(pg,{icon:wn,label:`${c.length} system perms`}),(0,X.jsx)(pg,{icon:En,label:`${Object.keys(l).length} tabs`}),(0,X.jsx)(pg,{icon:gi,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,X.jsxs)(fg,{title:`Object Permissions`,count:d.length,children:[(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),sg.map(e=>(0,X.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),sg.map(e=>(0,X.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,X.jsx)(ug,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,X.jsx)(dg,{})]}),p.size>0&&(0,X.jsx)(fg,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,X.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,X.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,X.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded border bg-muted/30 px-1.5 py-0.5`,title:`readable=${t.readable!==!1}, editable=${!!t.editable}`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,X.jsx)(fg,{title:`System Permissions`,count:c.length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),Object.keys(l).length>0&&(0,X.jsx)(fg,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),(0,X.jsx)(`span`,{className:t===`hidden`?`text-[9px] uppercase text-red-700`:t===`visible`||t===`default_on`?`text-[9px] uppercase text-emerald-700`:`text-[9px] uppercase text-muted-foreground`,children:t})]},e))})}),f.length>0&&(0,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,X.jsx)(Ot,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,X.jsxs)(`li`,{className:`text-amber-900`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function ug({granted:e,danger:t}){return e?(0,X.jsx)(Tr,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,X.jsx)(Gr,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function dg(){return(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Tr,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Tr,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Gr,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,X.jsx)(`span`,{className:`ml-auto font-mono`,children:`C R U D = CRUD · T Re P = Transfer/Restore/Purge · V* M* = View/Modify All`})]})}function fg({title:e,count:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function pg({icon:e,label:t}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{children:t})]})}function mg(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function hg(e){switch(e){case`url`:return Hr;case`modal`:return vr;case`flow`:return je;case`api`:return Tt;case`form`:return Ir;default:return Zn}}function gg(e){switch(e){case`primary`:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function _g(e,t,n){if(!t&&!n)return`No handler bound yet.`;switch(e){case`url`:return`Navigate to ${t}`;case`flow`:return`Run flow ${t}`;case`modal`:return`Open modal ${t}`;case`api`:return`Call API endpoint ${t}`;case`form`:return`Open form view ${t} (/console/forms/${t??`?`})`;case`script`:return n?`Run inline script body (L1 expression or L2 sandboxed JS).`:`Run named script ${t}`;default:return`Invoke ${t}`}}function vg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=mg(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target??n.execute,c=n.variant||void 0,l=String(n.component??``),u=Array.isArray(n.locations)?n.locations:[],d=n.shortcut||void 0,f=!!n.bulkEnabled,p=!!n.refreshAfter,m=n.aiExposed,h=mg(n.confirmText),g=mg(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,x=n.visible,S=n.disabled,C=hg(o),w=l===`action:icon`;return!r&&!i?(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(Vm,{children:`Set name and label to see the action preview.`})}):(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,X.jsx)(yg,{label:i,icon:a,variant:c,iconOnly:w,disabled:!!S&&typeof S==`boolean`})}),(0,X.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Eg,{icon:C,label:`type: ${o}`}),b&&(0,X.jsx)(Eg,{icon:ft,label:`object: ${b}`,mono:!0}),c&&(0,X.jsx)(Eg,{label:`variant: ${c}`}),l&&(0,X.jsx)(Eg,{icon:di,label:l}),d&&(0,X.jsx)(Eg,{icon:wr,label:d,mono:!0}),f&&(0,X.jsx)(Eg,{icon:yr,label:`bulk`,tone:`green`}),p&&(0,X.jsx)(Eg,{icon:Zi,label:`refresh after`}),m===!1&&(0,X.jsx)(Eg,{icon:Ge,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,X.jsx)(Eg,{icon:xe,label:`AI: exposed`})]}),u.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,X.jsx)(`span`,{className:`inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e},e))]}),!!(typeof x==`string`||x&&typeof x==`object`)&&(0,X.jsx)(wg,{label:`Visible when`,value:x,icon:En}),S!=null&&typeof S!=`boolean`&&(0,X.jsx)(wg,{label:`Disabled when`,value:S,icon:gi})]}),(0,X.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,X.jsx)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,X.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:_g(o,s,!!y?.source)}),h&&(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,X.jsx)(Ot,{className:`h-3 w-3 mt-0.5`}),(0,X.jsxs)(`span`,{children:[`First asks: `,(0,X.jsx)(`em`,{children:h})]})]}),g&&(0,X.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,X.jsx)(`em`,{children:g})]})]}),_.length>0&&(0,X.jsx)(Tg,{title:`Input Dialog`,count:_.length,children:(0,X.jsx)(xg,{title:i,params:_,variant:c})}),v&&(0,X.jsx)(Tg,{title:`Result Dialog`,icon:En,children:(0,X.jsx)(Cg,{dialog:v})}),y?.source&&(0,X.jsx)(Tg,{title:`Script Body (${y.language??`expression`})`,icon:Zn,children:(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap max-h-[200px] overflow-auto`,children:y.source})})]})})})}function yg({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${gg(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,X.jsx)(bg,{name:t}),!r&&(0,X.jsx)(`span`,{children:e})]})}function bg({name:e}){return(0,X.jsx)(`span`,{className:`inline-flex h-4 min-w-4 items-center justify-center rounded bg-white/30 px-1 text-[9px] uppercase font-mono`,children:e.slice(0,3)})}function xg({title:e,params:t,variant:n}){return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,X.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[mg(e.label)||n,e.required&&(0,X.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,X.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),Sg(e),e.helpText&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${gg(n||`primary`)}`,children:`OK`})]})]})}function Sg(e){let t=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,n=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),r=e.defaultValue;return Array.isArray(e.options)&&e.options.length>0?(0,X.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,X.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,X.jsx)(`option`,{value:e.value,children:mg(e.label)},t))]}):e.type===`boolean`?(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,X.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,X.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,X.jsx)(`input`,{type:e.type===`number`||e.type===`integer`?`number`:e.type===`date`?`date`:`text`,className:t,placeholder:n,value:r==null?``:String(r),readOnly:!0})}function Cg({dialog:e}){let t=mg(e.title)||`Result`,n=mg(e.description),r=mg(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,X.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,X.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,X.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:mg(t.label)||t.path}),(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,X.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,X.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded bg-primary text-primary-foreground pointer-events-none`,children:r})})]})}function wg({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,X.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function Tg({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Eg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Dg(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Og({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=e,s=String(o.object??``),c=!!o.active,l=o.lockRecord!==!1,u=o.approvalStatusField||void 0,d=Dg(o.entryCriteria),f=Array.isArray(o.steps)?o.steps:[],p=o.escalation,m={onSubmit:Array.isArray(o.onSubmit)?o.onSubmit:[],onFinalApprove:Array.isArray(o.onFinalApprove)?o.onFinalApprove:[],onFinalReject:Array.isArray(o.onFinalReject)?o.onFinalReject:[],onRecall:Array.isArray(o.onRecall)?o.onRecall:[]},h=!!(t&&r),g=h&&!!i,_=n&&n.kind===`step`?n.id:null,v=(e,t)=>{let n=e.name||`steps[${t}]`;r?.({kind:`step`,id:n,label:e.label||e.name||`Step ${t+1}`})},y=Y.useCallback(()=>{if(!g)return;let e=sh(`step`,f.map(e=>e.name).filter(Boolean)),t={name:e,label:`New step`,approvers:[]};i({steps:ah(f,t)}),r?.({kind:`step`,id:e,label:t.label||e})},[g,f,i,r]);return f.length===0&&!s?(0,X.jsx)(Q,{hint:`approval${h?` · design`:``}`,children:g?(0,X.jsx)(`div`,{className:`p-3`,children:(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-2 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:y,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.step`,a)]})}):(0,X.jsx)(Vm,{children:`Set the target object and at least one step to see the approval chain.`})}):(0,X.jsx)(Q,{hint:`approval · ${f.length} step${f.length===1?``:`s`}`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsx)(Mg,{icon:Vi,label:c?`Active`:`Inactive`,tone:c?`green`:`gray`}),(0,X.jsx)(Mg,{icon:Yn,label:`object: ${s||`—`}`,mono:!0}),(0,X.jsx)(Mg,{icon:gi,label:l?`lock during approval`:`unlocked`,tone:l?`amber`:`gray`}),u&&(0,X.jsx)(Mg,{label:`status field: ${u}`,mono:!0})]}),d&&(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(He,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Entry:`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:d})]})]}),p?.enabled&&(0,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-900`,children:[(0,X.jsx)(Qt,{className:`h-3.5 w-3.5`}),` SLA escalation enabled`]}),(0,X.jsxs)(`div`,{className:`mt-1 text-amber-900`,children:[`After `,(0,X.jsxs)(`code`,{className:`font-mono`,children:[p.timeoutHours,`h`]}),` on a pending step →`,` `,(0,X.jsx)(`span`,{className:`font-medium`,children:p.action??`notify`}),p.escalateTo&&(0,X.jsxs)(X.Fragment,{children:[` → `,(0,X.jsx)(`code`,{className:`font-mono`,children:p.escalateTo})]}),p.notifySubmitter&&(0,X.jsx)(`span`,{className:`ml-1 opacity-80`,children:`(notify submitter)`})]})]}),f.length===0?(0,X.jsx)(Vm,{children:`No steps defined yet.`}):(0,X.jsx)(`ol`,{className:`space-y-2`,children:f.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[(0,X.jsx)(kg,{step:e,index:t,onClick:h?()=>v(e,t):void 0,selected:_!=null&&(e.name===_||`steps[${t}]`===_)}),t<f.length-1&&(0,X.jsx)(`li`,{className:`flex justify-center`,"aria-hidden":!0,children:(0,X.jsx)(zn,{className:`h-3.5 w-3.5 text-muted-foreground`})})]},e.name||t))}),g&&(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:y,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),Z(`engine.inspector.add.step`,a)]}),(0,X.jsxs)(`div`,{className:`rounded border bg-muted/20 p-2.5 text-xs`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground uppercase tracking-wider text-[10px] mb-1`,children:`Global Hooks`}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[(0,X.jsx)(jg,{icon:Xr,label:`onSubmit`,actions:m.onSubmit}),(0,X.jsx)(jg,{icon:Tr,label:`onFinalApprove`,actions:m.onFinalApprove,tone:`green`}),(0,X.jsx)(jg,{icon:Mi,label:`onFinalReject`,actions:m.onFinalReject,tone:`red`}),(0,X.jsx)(jg,{icon:Ee,label:`onRecall`,actions:m.onRecall})]})]})]})})})}function kg({step:e,index:t,onClick:n,selected:r}){let i=e.approvers??[],a=Dg(e.entryCriteria);return(0,X.jsxs)(`li`,{className:`rounded border bg-background ${n?`cursor-pointer hover:border-primary/50`:``} ${r?`ring-2 ring-primary border-primary`:``}`,onClick:n?e=>{e.stopPropagation(),n()}:void 0,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-mono`,children:t+1}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.name||`Step ${t+1}`}),e.name&&(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name}),e.behavior&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.behavior===`unanimous`?`all must approve`:`first response wins`})]}),e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.description}),a&&(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,X.jsx)(He,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`When:`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:a})]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,X.jsx)(ze,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Approvers:`}),i.length===0?(0,X.jsx)(`span`,{className:`text-amber-700`,children:`none`}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:i.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px]`,children:[(0,X.jsx)(Bt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.value||`?`}),e.type&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type})]},t))})]})]})]}),((e.onApprove?.length??0)>0||(e.onReject?.length??0)>0||e.rejectionBehavior)&&(0,X.jsxs)(`div`,{className:`border-t bg-muted/20 px-3 py-1.5 text-[11px] space-y-0.5`,children:[e.onApprove&&e.onApprove.length>0&&(0,X.jsx)(Ag,{icon:Tr,tone:`green`,label:`on approve`,actions:e.onApprove}),e.onReject&&e.onReject.length>0&&(0,X.jsx)(Ag,{icon:Mi,tone:`red`,label:`on reject`,actions:e.onReject}),e.rejectionBehavior&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[e.rejectionBehavior===`back_to_previous`?(0,X.jsx)(Kn,{className:`h-3 w-3`}):(0,X.jsx)(Li,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[`Rejection: `,(0,X.jsx)(`code`,{className:`font-mono text-foreground`,children:e.rejectionBehavior})]})]})]})]})}function Ag({icon:e,tone:t,label:n,actions:r}){return(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(e,{className:`h-3 w-3 mt-0.5 ${t===`green`?`text-emerald-700`:`text-red-700`}`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[n,`:`]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted/40 px-1.5 py-0.5 font-mono text-[10px]`,children:[e.type??`action`,e.name&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`· `,e.name]})]},t))})]})}function jg({icon:e,label:t,actions:n,tone:r=`gray`}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${r===`green`?`text-emerald-700`:r===`red`?`text-red-700`:`text-muted-foreground`}`,children:[(0,X.jsx)(e,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`font-mono`,children:t}),(0,X.jsx)(`span`,{className:`rounded bg-muted px-1 text-[10px]`,children:n.length})]})}function Mg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Ng={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function Pg(e,t,n){let r={values:new Set,any:!1};if(e===`*`){for(let e=t;e<=n;e++)r.values.add(e);return r.any=!0,r}for(let i of e.split(`,`)){let e,a=i;if(i.includes(`/`)){let[t,n]=i.split(`/`);a=t,e=n}let o=e?Math.max(1,parseInt(e,10)||1):1,s=t,c=n;if(a!==`*`)if(a.includes(`-`)){let[e,t]=a.split(`-`).map(e=>parseInt(e,10));if(Number.isNaN(e)||Number.isNaN(t))return null;s=e,c=t}else{let e=parseInt(a,10);if(Number.isNaN(e))return null;s=e,c=e}for(let e=s;e<=c;e+=o)e>=t&&e<=n&&r.values.add(e)}return r}function Fg(e){let t=(Ng[e.trim()]??e.trim()).split(/\s+/);if(t.length!==5&&t.length!==6)return null;let[n,r,i,a,o]=t.length===6?t.slice(1):t,s=Pg(n,0,59),c=Pg(r,0,23),l=Pg(i,1,31),u=Pg(a,1,12),d=Pg(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function Ig(e,t,n){let r=Fg(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+366*24*60*60*1e3;for(;i.length<n&&a.getTime()<=o;)r.minute.values.has(a.getMinutes())&&r.hour.values.has(a.getHours())&&r.month.values.has(a.getMonth()+1)&&(r.dom.any||r.dow.any?r.dom.values.has(a.getDate())&&r.dow.values.has(a.getDay()):r.dom.values.has(a.getDate())||r.dow.values.has(a.getDay()))&&i.push(new Date(a.getTime())),a.setMinutes(a.getMinutes()+1);return i}function Lg(e){let t=/^(\d+)\s*(ms|s|m|h|d)$/.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;case`d`:return n*864e5;default:return null}}function Rg(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function zg(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Bg(e){if(e.schedule&&typeof e.schedule==`object`){let t=e.schedule,n=String(t.type??``),r=t.timezone??e.timezone??e.tz;if(n===`cron`){let e=t.expression;return{cron:typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0,timezone:r}}if(n===`interval`){let e=Number(t.intervalMs);return{every:Number.isFinite(e)&&e>0?Vg(e):void 0,timezone:r}}if(n===`once`)return{at:typeof t.at==`string`?t.at:void 0,timezone:r}}let t=typeof e.cron==`string`?e.cron:typeof e.schedule==`string`?e.schedule:void 0,n=e.every??e.interval;return{cron:t,every:typeof n==`string`?n:typeof n==`number`?Vg(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function Vg(e){return e%864e5==0?`${e/864e5}d`:e%36e5==0?`${e/36e5}h`:e%6e4==0?`${e/6e4}m`:e%1e3==0?`${e/1e3}s`:`${e}ms`}function Hg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,{cron:o,every:s,at:c,timezone:l}=Bg(n),u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.retryPolicy,p=f?.maxRetries??n.maxRetries??n.retries,m=f?.backoffMs,h=n.timeout??n.timeoutMs,g=n.concurrency,_=s?Lg(s):null,{nextFires:v,deltas:y}=Y.useMemo(()=>{let e=new Date,t=[];if(o)t=Ig(o,e,5);else if(_)t=Rg(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Ug(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(Vm,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Qt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Kg,{icon:Vi,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,X.jsx)(Kg,{icon:In,label:l,mono:!0}),p!=null&&(0,X.jsx)(Kg,{icon:Kn,label:`retries: ${p}${m?` (${Vg(m)} backoff)`:``}`}),h!=null&&(0,X.jsx)(Kg,{icon:st,label:`timeout: ${Vg(h)}`}),g!=null&&(0,X.jsx)(Kg,{label:`concurrency: ${g}`})]})]})]})}),(0,X.jsx)(Gg,{title:`Schedule`,icon:zt,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,X.jsx)(Wg,{label:`Cron`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,X.jsxs)(Wg,{label:`Every`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,X.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,X.jsx)(Wg,{label:`At`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,X.jsx)(Gg,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:oi,children:v.length===0?(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:b?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,X.jsx)(oi,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:zg(e)}),(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,X.jsx)(Gg,{title:`Handler`,icon:Zn,children:u?(0,X.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,X.jsx)(Xr,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Ug(e){if(e<=0)return`now`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<48?`${r}h`:`${Math.round(r/24)}d`}function Wg({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:`break-all`,children:t})]})}function Gg({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Kg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var qg=[{key:`objects`,label:`Objects`,icon:yi,flat:!1},{key:`apps`,label:`Apps`,icon:Un,flat:!1},{key:`messages`,label:`Messages`,icon:Hn,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Yn,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:sr,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:ci,flat:!1},{key:`settings`,label:`Settings`,icon:ar,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:na,flat:!1}];function Jg({name:e,draft:t}){let n=t,r=n.locale??n.language??`?`,i=n.label??n.name??e??``,a=n.description,o=n.data??n,s=qg.map(e=>{let t=o?.[e.key];if(!t||typeof t!=`object`)return{...e,count:0,sample:[]};let n=Object.entries(t);return{...e,count:n.length,sample:n.slice(0,5)}}),c=s.reduce((e,t)=>e+t.count,0),l=s.filter(e=>e.count>0).length,u=Math.round(l/qg.length*100);return c===0?(0,X.jsx)(Q,{hint:`translation · ${r}`,children:(0,X.jsx)(Vm,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,X.jsx)(Q,{hint:`translation · ${r} · ${c} keys`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Or,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[10px] font-mono text-emerald-800`,children:[(0,X.jsx)(In,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,X.jsx)(Ut,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,X.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,qg.length,` (`,u,`%)`]}),(0,X.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,X.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,X.jsx)(Yg,{cat:e},e.key))})]})})})}function Yg({cat:e}){let t=e.icon;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,X.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,X.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,X.jsx)(`span`,{className:`truncate text-foreground/80`,children:Xg(n,e.flat)})]},t)),e.count>e.sample.length&&(0,X.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function Xg(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Zg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.parent;return r?(0,X.jsx)(Q,{hint:`role`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(ze,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,X.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Bi,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,X.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,X.jsx)(ve,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,X.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(Mr,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,X.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,X.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,X.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,X.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,X.jsx)(Q,{hint:`role`,children:(0,X.jsx)(Vm,{children:`Give the role a name to see the preview.`})})}function Qg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.instructions??``,s=Array.isArray(n.tools)?n.tools:[],c=Array.isArray(n.triggerPhrases)?n.triggerPhrases:[],l=Array.isArray(n.triggerConditions)?n.triggerConditions:[],u=Array.isArray(n.permissions)?n.permissions:[],d=n.active!==!1,f=n.model??void 0;return r?(0,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(xe,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(e_,{icon:Vi,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,X.jsx)(e_,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,X.jsx)(e_,{icon:Mr,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,X.jsx)($g,{title:`Instructions`,icon:St,children:o?(0,X.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words max-h-64 overflow-auto`,children:o}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,X.jsxs)($g,{title:`Tools (${s.length})`,icon:cn,children:[s.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-mono border ${t?`border-amber-300 bg-amber-50 text-amber-900`:`border-border bg-muted/40`}`,children:[t&&(0,X.jsx)(et,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,X.jsx)(`div`,{className:`mt-1 text-[10px] text-amber-700`,children:`Wildcards expand to many tools at runtime — review the matching set in the agent before activating.`})]}),c.length>0&&(0,X.jsx)($g,{title:`Trigger Phrases (${c.length})`,icon:Ln,children:(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,X.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,X.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,X.jsx)($g,{title:`Trigger Conditions (${l.length})`,icon:He,children:(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})}),u.length>0&&(0,X.jsx)($g,{title:`Required Permissions`,icon:Mr,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})}):(0,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(Vm,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function $g({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function e_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var t_=/pass|secret|key|token|credential|auth/i;function n_(e){return t_.test(e)}function r_(e){return e==null||e===``?`∅`:`••••••`}function i_(e){return e==null?`∅`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`[${e.length}]`:typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e)}function a_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=Object.entries(l);return!r&&g.length===0?(0,X.jsx)(Q,{hint:`datasource`,children:(0,X.jsx)(Vm,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,X.jsx)(Q,{hint:`datasource · ${o}`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Xt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,X.jsx)(Lt,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,X.jsx)(c_,{icon:Vi,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,X.jsx)(c_,{icon:_t,label:`default`,tone:`amber`}),m.length>0&&(0,X.jsx)(c_,{icon:Ei,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),(0,X.jsx)(s_,{title:`Connection`,icon:gi,children:g.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:g.map(([e,t])=>{let n=n_(e);return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:r_(t)}),(0,X.jsx)(`span`,{className:`rounded bg-amber-50 border border-amber-200 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-800`,children:`redacted`})]}):i_(t)})]},e)})})})})}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(o_,{title:`Pool`,icon:be,value:u}),(0,X.jsx)(o_,{title:`SSL`,icon:Mr,value:typeof d==`boolean`?{enabled:d}:d}),(0,X.jsx)(o_,{title:`Retry Policy`,icon:Kn,value:f}),(0,X.jsx)(o_,{title:`Health Check`,icon:be,value:p})]}),h.length>0&&(0,X.jsx)(s_,{title:`Capabilities`,icon:Mr,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})})}function o_({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,X.jsx)(`dd`,{className:`font-mono truncate`,children:n_(e)?r_(t):i_(t)})]},e))}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function s_({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function c_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function l_(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function u_(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50`,text:`text-red-700`,icon:$e};case`warning`:return{ring:`border-amber-200 bg-amber-50`,text:`text-amber-800`,icon:Ot};default:return{ring:`border-blue-200 bg-blue-50`,text:`text-blue-800`,icon:$n}}}function d_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.type??`script`,s=n.object,c=n.message??``,l=n.severity??`error`,u=n.active!==!1,d=Array.isArray(n.events)?n.events:[],f=n.priority,p=Array.isArray(n.tags)?n.tags:[],m=u_(l);return r?(0,X.jsx)(Q,{hint:`validation · ${o}`,children:(0,X.jsx)(Um,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Yn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(h_,{icon:Vi,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,X.jsx)(h_,{label:`object: ${s}`,mono:!0}),f!=null&&(0,X.jsx)(h_,{label:`priority ${f}`}),d.length>0&&(0,X.jsx)(h_,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,X.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,X.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,X.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,X.jsx)(f_,{type:o,d:n}),p.length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,X.jsx)(`span`,{className:`inline-flex items-center rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})]})]})})}):(0,X.jsx)(Q,{hint:`validation`,children:(0,X.jsx)(Vm,{children:`Give the validation a name to see the preview.`})})}function f_({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,X.jsx)(m_,{title:`Condition`,icon:Zn,children:(0,X.jsx)(p_,{value:l_(t.condition)??l_(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=l_(t.scope)??l_(t.where);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(m_,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:yt,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,X.jsx)(`span`,{className:`text-xs text-amber-700`,children:`no fields set`}):e.map(e=>(0,X.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,X.jsx)(m_,{title:`Scope`,icon:$r,children:(0,X.jsx)(p_,{value:n})})]})}case`state_machine`:{let e=Array.isArray(t.transitions)?t.transitions:[],n=t.field;return(0,X.jsx)(m_,{title:`Transitions${n?` on ${n}`:``}`,icon:je,children:e.length===0?(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No transitions declared.`}):(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:Array.isArray(e.from)?e.from.join(` | `):e.from??`*`}),(0,X.jsx)(gt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono text-emerald-700`,children:e.to??`?`})]},t))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,X.jsx)(m_,{title:`Format`,icon:Ii,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,X.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,X.jsx)(`span`,{className:`text-amber-700`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=l_(t.condition);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(m_,{title:`Fields involved`,icon:$r,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,X.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e)),e.length===0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,X.jsx)(m_,{title:`Cross-field condition`,icon:Zn,children:(0,X.jsx)(p_,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,X.jsx)(m_,{title:`Async endpoint`,icon:In,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,X.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,X.jsx)(m_,{title:`Custom handler`,icon:Zn,children:(0,X.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,X.jsx)(`span`,{className:`text-amber-700`,children:`No handler set.`})})})}default:return(0,X.jsx)(m_,{title:`Rule`,icon:Yn,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs text-muted-foreground italic`,children:[`Unknown rule type "`,e,`". Showing common fields only.`]})})}}function p_({value:e}){return e?(0,X.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No expression set.`})}function m_({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function h_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function g_(){ym(`page`,Gm),ym(`view`,Ym),ym(`dashboard`,lh),ym(`report`,dh),ym(`app`,mh),ym(`action`,vg),ym(`object`,vh),ym(`datasource`,a_),ym(`validation`,d_),ym(`email_template`,Sh),ym(`translation`,Jg),ym(`flow`,Eh),ym(`workflow`,Rh),ym(`approval`,Og),ym(`job`,Hg),ym(`agent`,Wh),ym(`tool`,ng),ym(`skill`,Qg),ym(`permission`,lg),ym(`profile`,lg),ym(`role`,Zg)}var __=[{value:`metric`,label:`KPI Metric`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`table`,label:`Table`},{value:`grid`,label:`Grid`}],v_=[`count`,`sum`,`avg`,`min`,`max`],y_=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function b_(e,t){let n=Array.isArray(e.widgets)?e.widgets:[],r=n.findIndex(e=>e?.id===t);return r<0?null:{widget:n[r],index:r}}function x_({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,X.jsx)(C_,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=b_(e,t.id);if(!s)return(0,X.jsx)(C_,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:c,index:l}=s,u=Array.isArray(e.widgets)?e.widgets:[];function d(e){let t=[...u];t[l]={...t[l],...e},n({widgets:t})}function f(e){n({widgets:oh(u,l,e)}),c.id&&i?.({kind:`widget`,id:c.id,label:c.title??void 0})}return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:Z(`engine.inspector.widget.kind`,o)}),(0,X.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:c.title||t.label||`Widget ${l+1}`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,X.jsx)(Zm,{index:l,total:u.length,onMove:f,upLabel:Z(`engine.inspector.reorder.up`,o),downLabel:Z(`engine.inspector.reorder.down`,o),disabled:a}),(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:Z(`engine.inspector.widget.close`,o),"aria-label":Z(`engine.inspector.widget.close`,o),children:(0,X.jsx)(Yi,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(S_,{id:`widget-title`,label:Z(`engine.inspector.widget.title`,o),children:(0,X.jsx)(K,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,X.jsx)(S_,{id:`widget-type`,label:Z(`engine.inspector.widget.type`,o),children:(0,X.jsxs)(on,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,X.jsx)(Tn,{id:`widget-type`,children:(0,X.jsx)(nt,{})}),(0,X.jsx)(oa,{children:__.map(e=>(0,X.jsx)(Oe,{value:e.value,children:e.label},e.value))})]})}),(0,X.jsx)(S_,{id:`widget-object`,label:Z(`engine.inspector.widget.object`,o),children:(0,X.jsx)(K,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,X.jsx)(S_,{id:`widget-value-field`,label:Z(`engine.inspector.widget.valueField`,o),children:(0,X.jsx)(K,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,X.jsx)(S_,{id:`widget-category-field`,label:Z(`engine.inspector.widget.categoryField`,o),children:(0,X.jsx)(K,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,X.jsx)(S_,{id:`widget-aggregate`,label:Z(`engine.inspector.widget.aggregate`,o),children:(0,X.jsxs)(on,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,X.jsx)(Tn,{id:`widget-aggregate`,children:(0,X.jsx)(nt,{})}),(0,X.jsx)(oa,{children:v_.map(e=>(0,X.jsx)(Oe,{value:e,children:e},e))})]})}),(0,X.jsx)(S_,{id:`widget-color`,label:Z(`engine.inspector.widget.color`,o),children:(0,X.jsxs)(on,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,X.jsx)(Tn,{id:`widget-color`,children:(0,X.jsx)(nt,{})}),(0,X.jsx)(oa,{children:y_.map(e=>(0,X.jsx)(Oe,{value:e,children:e},e))})]})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(S_,{id:`widget-w`,label:Z(`engine.inspector.widget.width`,o),children:(0,X.jsx)(K,{id:`widget-w`,type:`number`,min:1,value:c.layout?.w??1,onChange:e=>d({layout:{...c.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,X.jsx)(S_,{id:`widget-h`,label:Z(`engine.inspector.widget.height`,o),children:(0,X.jsx)(K,{id:`widget-h`,type:`number`,min:1,value:c.layout?.h??1,onChange:e=>d({layout:{...c.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,X.jsx)(`div`,{className:`pt-2 border-t`,children:(0,X.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:text-destructive`,onClick:()=>{let t=Array.isArray(e.widgets)?[...e.widgets]:[];t.splice(l,1),n({widgets:t}),r()},children:Z(`engine.inspector.widget.remove`,o)})})]})}function S_({id:e,label:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(Nr,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function C_({message:e,onClose:t,locale:n}){return(0,X.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,X.jsx)(`p`,{children:e}),(0,X.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:Z(`engine.inspector.widget.close`,n)})]})}var w_=[`start`,`end`,`action`,`decision`,`branch`,`gateway`,`subflow`,`wait`,`loop`,`parallel`,`invoke`];function T_({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.nodes)?t.nodes:[],s=o.findIndex(t=>t?.id===e.id),c=s>=0?o[s]:null;if(!c)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.flowNode.close`,i),children:(0,X.jsx)(rh,{message:e.id})});let l=e=>{n({nodes:ih(o,s,{...c,...e})})},u=Y.useMemo(()=>{let{id:e,type:t,label:n,...r}=c;return JSON.stringify(r,null,2)},[c]),[d,f]=Y.useState(u),[p,m]=Y.useState(null);return Y.useEffect(()=>{f(u),m(null)},[u]),(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:Z(`engine.inspector.flowNode.close`,i),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.flowNode.remove`,i),onClick:()=>{n({nodes:ih(o,s,null)}),r()},disabled:a}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>l({id:e}),disabled:a,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>l({label:e}),disabled:a}),(0,X.jsx)(eh,{label:Z(`engine.inspector.flowNode.type`,i),value:c.type,options:w_.map(e=>({value:e,label:e})),onCommit:e=>l({type:e}),disabled:a}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:Z(`engine.inspector.flowNode.config`,i)}),(0,X.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),onBlur:()=>{try{let e=d.trim()===``?{}:JSON.parse(d);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not object`);m(null),n({nodes:ih(o,s,{id:c.id,type:c.type,label:c.label,...e})})}catch(e){m(String(e.message))}},disabled:a,rows:8,className:`w-full rounded border px-2 py-1.5 text-xs font-mono bg-background`}),p&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:p})]})]})}var E_=[{value:`unanimous`,label:`unanimous (all approve)`},{value:`first`,label:`first response wins`}],D_=[{value:`back_to_previous`,label:`back to previous step`},{value:`reject_process`,label:`reject entire process`}];function O_(e){return e==null?``:typeof e==`string`?e:e.source??``}function k_({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Array.isArray(t.steps)?t.steps:[],c=(()=>{let t=/^steps\[(\d+)\]$/.exec(e.id);return t?Number(t[1]):s.findIndex(t=>t?.name===e.id)})(),l=c>=0&&c<s.length?s[c]:null;if(!l)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.approvalStep.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.approvalStep.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let u=e=>{n({steps:ih(s,c,{...l,...e})})};return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.approvalStep.kind`,a),title:l.label||l.name||`Step ${c+1}`,onClose:r,closeLabel:Z(`engine.inspector.approvalStep.close`,a),headerActions:(0,X.jsx)(Zm,{index:c,total:s.length,onMove:e=>{n({steps:oh(s,c,e)});let t=l.name||`steps[${e}]`;i?.({kind:`step`,id:t,label:l.label||l.name||`Step ${e+1}`})},upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.approvalStep.remove`,a),onClick:()=>{n({steps:ih(s,c,null)}),r()},disabled:o}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.approvalStep.name`,a),value:l.name??``,onCommit:e=>u({name:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.approvalStep.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.approvalStep.description`,a),value:l.description??``,onCommit:e=>u({description:e}),disabled:o}),(0,X.jsx)(eh,{label:Z(`engine.inspector.approvalStep.behavior`,a),value:l.behavior,options:E_,onCommit:e=>u({behavior:e}),disabled:o}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.approvalStep.entryCriteria`,a),value:O_(l.entryCriteria),onCommit:e=>u({entryCriteria:e}),disabled:o,mono:!0}),(0,X.jsx)(eh,{label:Z(`engine.inspector.approvalStep.rejectionBehavior`,a),value:l.rejectionBehavior,options:D_,onCommit:e=>u({rejectionBehavior:e}),disabled:o})]})}var A_=[`field_update`,`email_alert`,`task_create`,`outbound_message`,`webhook`,`apex`,`flow_invoke`,`notification`];function j_(e){let t=/^actions\[(\d+)\]$/.exec(e);if(t)return{scope:`immediate`,i:Number(t[1])};let n=/^timeTriggers\[(\d+)\]\.actions\[(\d+)\]$/.exec(e);return n?{scope:`timed`,i:Number(n[1]),j:Number(n[2])}:null}function M_({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=j_(e.id),c=Array.isArray(t.actions)?t.actions:[],l=Array.isArray(t.timeTriggers)?t.timeTriggers:[],u=(()=>{if(!s)return null;if(s.scope===`immediate`)return c[s.i]??null;let e=l[s.i];return!e||!Array.isArray(e.actions)?null:e.actions[s.j]??null})();if(!u||!s)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.workflowAction.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.workflowAction.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let d=e=>{let t={...u,...e};if(s.scope===`immediate`)n({actions:ih(c,s.i,t)});else{let e=l[s.i],r=ih(e.actions??[],s.j,t);n({timeTriggers:ih(l,s.i,{...e,actions:r})})}},f=()=>{if(s.scope===`immediate`)n({actions:ih(c,s.i,null)});else{let e=l[s.i],t=ih(e.actions??[],s.j,null);n({timeTriggers:ih(l,s.i,{...e,actions:t})})}r()},p=Y.useMemo(()=>{let{type:e,name:t,...n}=u;return JSON.stringify(n,null,2)},[u]),[m,h]=Y.useState(p),[g,_]=Y.useState(null);Y.useEffect(()=>{h(p),_(null)},[p]);let v=()=>{try{let e=m.trim()===``?{}:JSON.parse(m);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not object`);_(null),d(e)}catch(e){_(String(e.message))}},{currentIndex:y,total:b}=(()=>{if(s.scope===`immediate`)return{currentIndex:s.i,total:c.length};let e=l[s.i],t=Array.isArray(e?.actions)?e.actions:[];return{currentIndex:s.j,total:t.length}})();return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.workflowAction.kind`,a),title:u.name||u.type||e.id,onClose:r,closeLabel:Z(`engine.inspector.workflowAction.close`,a),headerActions:(0,X.jsx)(Zm,{index:y,total:b,onMove:e=>{if(s.scope===`immediate`)n({actions:oh(c,s.i,e)}),i?.({kind:`action`,id:`actions[${e}]`,label:u.name||u.type});else{let t=l[s.i],r=oh(t.actions??[],s.j,e);n({timeTriggers:ih(l,s.i,{...t,actions:r})}),i?.({kind:`action`,id:`timeTriggers[${s.i}].actions[${e}]`,label:u.name||u.type})}},upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.workflowAction.remove`,a),onClick:f,disabled:o}),children:[(0,X.jsx)(eh,{label:Z(`engine.inspector.workflowAction.type`,a),value:u.type,options:A_.map(e=>({value:e,label:e})),onCommit:e=>d({type:e}),disabled:o}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.workflowAction.name`,a),value:u.name??``,onCommit:e=>d({name:e}),disabled:o}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:Z(`engine.inspector.workflowAction.config`,a)}),(0,X.jsx)(`textarea`,{value:m,onChange:e=>h(e.target.value),onBlur:v,disabled:o,rows:8,className:`w-full rounded border px-2 py-1.5 text-xs font-mono bg-background`}),g&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:g})]})]})}var N_=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function P_(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function F_(e,t){let n=e[t[0].key];if(!Array.isArray(n))return{parent:[],node:null,index:-1};let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r)return{parent:n,node:null,index:t[e].index};if(n=r[t[e].key],!Array.isArray(n))return{parent:[],node:null,index:-1};r=n[t[e].index]??null}return{parent:n,node:r,index:t[t.length-1].index}}function I_(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:ih(i,t[0].index,n)};let a=i,o=[];for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}};o.push({arr:a,index:t[e].index,node:n});let r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let s=ih(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function L_(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function R_({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=P_(e.id),{node:c,parent:l,index:u}=s?F_(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.appNav.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.appNav.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let d=c.label??c.title??c.name??c.path??e.id,f=c.path??c.href??c.route??``,p=e=>{n(I_(t,s,{...c,...e}))};return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:Z(`engine.inspector.appNav.close`,a),headerActions:(0,X.jsx)(Zm,{index:u,total:l.length,onMove:e=>{n(L_(t,s,oh(l,u,e)));let r=s.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),a=s[s.length-1].key,o=r?`${r}.${a}[${e}]`:`${a}[${e}]`;i?.({kind:`nav`,id:o,label:String(d)})},upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.appNav.remove`,a),onClick:()=>{n(I_(t,s,null)),r()},disabled:o}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.appNav.label`,a),value:String(c.label??c.title??c.name??``),onCommit:e=>p({label:e}),disabled:o}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,X.jsx)(eh,{label:Z(`engine.inspector.appNav.kindField`,a),value:c.kind,options:N_.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var z_=[{value:`left`,label:`left`},{value:`center`,label:`center`},{value:`right`,label:`right`}];function B_(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function V_(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function H_(e){return e.field??e.accessorKey??``}function U_(e){return e.label??e.header??H_(e)}function W_({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=B_(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(V_),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1;if(!s||!d)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.viewColumn.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let p=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=H_(e),i=!e.label&&!e.header&&e.width==null&&e.align==null&&e.sortable==null&&e.filterable==null;return n&&i&&r?r:e});n({[s.variant]:{...c,columns:t}})},m=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),p(ih(u,s.index,{...d,...r}))},h=()=>{p(ih(u,s.index,null)),r()},g=e=>{p(oh(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:U_(d)||`columns[${e}]`})},_=typeof d.width==`number`?d.width:typeof d.width==`string`&&Number(d.width.replace(/[^\d.]/g,``))||void 0;return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.viewColumn.kind`,a),title:U_(d)||e.id,onClose:r,closeLabel:Z(`engine.inspector.viewColumn.close`,a),headerActions:(0,X.jsx)(Zm,{index:s.index,total:u.length,onMove:g,upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.viewColumn.remove`,a),onClick:h,disabled:o}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.viewColumn.accessorKey`,a),value:H_(d),onCommit:e=>m({field:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.viewColumn.header`,a),value:U_(d)===H_(d)?``:U_(d),onCommit:e=>m({label:e}),disabled:o}),!f&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($m,{label:Z(`engine.inspector.viewColumn.width`,a),value:_,onCommit:e=>m({width:e}),disabled:o}),(0,X.jsx)(eh,{label:Z(`engine.inspector.viewColumn.align`,a),value:d.align,options:z_,onCommit:e=>m({align:e}),disabled:o}),(0,X.jsx)(th,{label:Z(`engine.inspector.viewColumn.sortable`,a),value:d.sortable!==!1,onCommit:e=>m({sortable:e}),disabled:o}),(0,X.jsx)(th,{label:Z(`engine.inspector.viewColumn.filterable`,a),value:d.filterable!==!1,onCommit:e=>m({filterable:e}),disabled:o})]})]})}function G_(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function K_(e,t){let n=e[t[0].key];if(!Array.isArray(n))return null;let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r||(n=r[t[e].key],!Array.isArray(n)))return null;r=n[t[e].index]??null}return r}function q_(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:ih(i,t[0].index,n)};let a=i;for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-1];return n===null?a.splice(o.index,1):a[o.index]=n,{[r]:i}}function J_(e,t){let n=e[t[0].key];if(!Array.isArray(n))return null;if(t.length===1)return{siblings:n,index:t[0].index};let r=n[t[0].index]??null;for(let e=1;e<t.length-1;e++){if(!r||(n=r[t[e].key],!Array.isArray(n)))return null;r=n[t[e].index]??null}if(!r)return null;let i=t[t.length-1],a=r[i.key];return Array.isArray(a)?{siblings:a,index:i.index}:null}function Y_(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function X_({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=G_(e.id),c=s?K_(t,s):null,l=s?J_(t,s):null;if(!s||!c)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.pageBlock.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let u=e=>n(q_(t,s,{...c,...e}));return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.pageBlock.kind`,a),title:String(c.id||c.type||e.id),onClose:r,closeLabel:Z(`engine.inspector.pageBlock.close`,a),headerActions:l?(0,X.jsx)(Zm,{index:l.index,total:l.siblings.length,onMove:e=>{if(!l)return;n(Y_(t,s,oh(l.siblings,l.index,e)));let r=s.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),a=s[s.length-1].key,o=r?`${r}.${a}[${e}]`:`${a}[${e}]`;i?.({kind:`block`,id:o,label:String(c.id||c.type||o)})},upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.pageBlock.remove`,a),onClick:()=>{n(q_(t,s,null)),r()},disabled:o}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.pageBlock.type`,a),value:c.type??``,onCommit:e=>u({type:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.pageBlock.id`,a),value:c.id??``,onCommit:e=>u({id:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.pageBlock.className`,a),value:c.className??``,onCommit:e=>u({className:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.pageBlock.hidden`,a),value:c.hidden??``,onCommit:e=>u({hidden:e}),disabled:o,mono:!0})]})}var Z_=`__none__`,Q_=[{value:Z_,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function $_(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function ev({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=$_(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,X.jsx)(Xm,{kindLabel:Z(`engine.inspector.reportColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Z(`engine.inspector.reportColumn.close`,a),children:(0,X.jsx)(rh,{message:e.id})});let u=e=>n({columns:ih(c,s,{...l,...e})});return(0,X.jsxs)(Xm,{kindLabel:Z(`engine.inspector.reportColumn.kind`,a),title:l.label||l.field||e.id,onClose:r,closeLabel:Z(`engine.inspector.reportColumn.close`,a),headerActions:(0,X.jsx)(Zm,{index:s,total:c.length,onMove:e=>{n({columns:oh(c,s,e)}),i?.({kind:`column`,id:`columns[${e}]`,label:l.label||l.field||`columns[${e}]`})},upLabel:Z(`engine.inspector.reorder.up`,a),downLabel:Z(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(nh,{label:Z(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:ih(c,s,null)}),r()},disabled:o}),children:[(0,X.jsx)(Qm,{label:Z(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,X.jsx)(Qm,{label:Z(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,X.jsx)(eh,{label:Z(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??Z_,options:Q_,onCommit:e=>u({aggregate:e===Z_?void 0:e}),disabled:o})]})}function tv(){Sm(`dashboard`,x_),Sm(`flow`,T_),Sm(`approval`,k_),Sm(`workflow`,M_),Sm(`app`,R_),Sm(`view`,W_),Sm(`page`,X_),Sm(`report`,ev)}var nv=t({MetadataDirectoryPage:()=>rp,MetadataResourceEditPage:()=>Em,MetadataResourceHistoryPage:()=>mm,MetadataResourceListPage:()=>mp});Im(),Bm(),g_(),tv(),Lf({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:rp}),Lf({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Am}),lp({type:`object`,label:`Objects`,description:`Domain entities — tables in the data model. Each object owns its fields, relationships, validations, and lifecycle hooks.`,domain:`data`,searchableFields:[`name`,`label`,`description`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`description`,label:`Description`}]}),lp({type:`field`,label:`Fields`,description:`Columns attached to objects — name, type, validation, and storage settings.`,domain:`data`,searchableFields:[`name`,`label`,`object`,`type`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`},{key:`label`,label:`Label`}]}),lp({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. Profiles are permission sets with isProfile=true.`,domain:`security`,EditPage:Nm,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`isProfile`,label:`Type`,width:`15%`,render:e=>e?`Profile`:`Permission set`}]}),lp({type:`view`,label:`Views`,description:`Saved list / kanban / calendar / gantt configurations on top of an object.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`},{key:`label`,label:`Label`}]}),lp({type:`dashboard`,label:`Dashboards`,description:`Composed dashboards with charts, KPIs, and tables.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}),lp({type:`page`,label:`Pages`,description:`Visual page layouts authored as JSON metadata.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`route`,label:`Route`}]});var rv=(0,Y.lazy)(()=>m(()=>import(`./SystemHubPage-DIKmhwy1.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),iv=(0,Y.lazy)(()=>m(()=>import(`./AppManagementPage-DuIaI8a2.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),av=(0,Y.lazy)(()=>m(()=>import(`./ProfilePage-4wnWye8l.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),ov=(0,Y.lazy)(()=>m(()=>import(`./ApprovalsInboxPage-BRv2RqN4.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),sv=(0,Y.lazy)(()=>m(()=>import(`./AiPendingActionsPage-DfPQB-bV.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),cv=(0,Y.lazy)(()=>m(()=>import(`./AuditLogPage-CDXmY4Lg.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),lv=(0,Y.lazy)(()=>m(()=>import(`./SettingsHub-B4d9Pn8t.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),uv=(0,Y.lazy)(()=>m(()=>import(`./SettingsView-cRQBVn6H.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),dv=(0,Y.lazy)(()=>m(()=>import(`./DeveloperHubPage-E4ydudW4.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),fv=(0,Y.lazy)(()=>m(()=>import(`./ApiConsolePage-CVt86JW9.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),pv=(0,Y.lazy)(()=>m(()=>import(`./FlowRunsPage-CF-nkx9E.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),mv=(0,Y.lazy)(()=>m(()=>import(`./PublicFormsPage-B1cdfwoQ.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function hv(){let{objectName:e}=a(),t=u().pathname.replace(/\/objects(\/.*)?$/,``);return(0,X.jsx)(p,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function gv(){let{metadataType:e,itemName:t}=a(),n=u().pathname.replace(/\/metadata(\/.*)?$/,``),r=`${n}/component/metadata/resource`;return(0,X.jsx)(p,{to:e?t?`${r}/${t}?type=${e}`:`${r}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var _v=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(g,{path:`system`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(rv,{})})}),(0,X.jsx)(g,{path:`system/apps`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(iv,{})})}),(0,X.jsx)(g,{path:`system/profile`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(av,{})})}),(0,X.jsx)(g,{path:`system/approvals`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(ov,{})})}),(0,X.jsx)(g,{path:`system/ai-approvals`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(sv,{})})}),(0,X.jsx)(g,{path:`system/audit-log`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(cv,{})})}),(0,X.jsx)(g,{path:`system/settings`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(lv,{})})}),(0,X.jsx)(g,{path:`system/settings/:namespace`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(uv,{})})}),(0,X.jsx)(g,{path:`developer`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(dv,{})})}),(0,X.jsx)(g,{path:`developer/api-console`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(fv,{})})}),(0,X.jsx)(g,{path:`developer/flow-runs`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(pv,{})})}),(0,X.jsx)(g,{path:`developer/public-forms`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(mv,{})})}),(0,X.jsx)(g,{path:`system/objects`,element:(0,X.jsx)(hv,{})}),(0,X.jsx)(g,{path:`system/objects/:objectName`,element:(0,X.jsx)(hv,{})}),(0,X.jsx)(g,{path:`system/metadata`,element:(0,X.jsx)(gv,{})}),(0,X.jsx)(g,{path:`system/metadata/:metadataType`,element:(0,X.jsx)(gv,{})}),(0,X.jsx)(g,{path:`system/metadata/:metadataType/:itemName`,element:(0,X.jsx)(gv,{})})]});function vv(){let e=(0,Y.useMemo)(()=>Cr({baseUrl:``}),[``]);return(0,X.jsx)(E,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,X.jsx)(hc,{}),children:(0,X.jsx)(Dr,{adapter:e,children:(0,X.jsx)(md,{extraRoutes:_v,extraRoutesNoApp:_v})})})}var yv=`/_account`;function bv(){return typeof window>`u`?`/`:window.location.pathname+window.location.search}function xv(e){let t=e??bv(),n=`${yv}/login?redirect=${encodeURIComponent(t)}`;window.location.assign(n)}function Sv(e){let t=e??bv(),n=`${yv}/register?redirect=${encodeURIComponent(t)}`;window.location.assign(n)}function Cv(){window.location.assign(`${yv}/forgot-password`)}function wv({redirect:e}={}){return(0,Y.useEffect)(()=>{xv(e)},[e]),(0,X.jsx)(`div`,{className:`flex min-h-screen w-full items-center justify-center bg-background`,children:(0,X.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-primary`})})}var Tv=[`cloud_control`];function Ev(){let{apps:e,loading:t}=F();if(t)return(0,X.jsx)(Ko,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Tv)if(n.has(e))return(0,X.jsx)(p,{to:`/apps/${e}`,replace:!0});return(0,X.jsx)(p,{to:`/home`,replace:!0})}var Dv=`/api/v1`;function Ov(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function kv(e){if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return{value:e,label:e};if(e&&typeof e==`object`){let t=String(e.value??e.id??``);return{value:t,label:String(e.label??e.name??t)}}return{value:String(e),label:String(e)}})}function Av(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Ov(e.columns),n=[];for(let t of e.fields??[]){let e=typeof t==`string`?{field:t}:{...t},i=r[e.field]??{type:`text`};n.push({name:e.field,label:e.label??i.label??e.field,type:i.type??`text`,required:e.required??i.required??!1,readonly:e.readonly??!1,hidden:e.hidden??!1,placeholder:e.placeholder??i.placeholder,helpText:e.helpText??i.helpText,defaultValue:i.defaultValue,options:kv(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function jv(e,t){let n={};for(let r of e){r.defaultValue!==void 0&&(n[r.name]=r.defaultValue);let e=t.get(`prefill_${r.name}`);e!==null&&(n[r.name]=e)}return n}async function Mv(e,t){return fetch(`${Dv}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function Nv(e){let t=await Mv(`/forms/${encodeURIComponent(e)}`);if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Failed to load form (${t.status}): ${e||t.statusText}`)}let n=await t.json();return{label:n.label??n.form?.label??n.object,object:n.object,form:n.form,objectSchema:n.objectSchema}}async function Pv(e){let t=await Mv(`/meta/view/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Form metadata not found: view/${e}`);let n=await t.json(),r=n?.item??n,i=r?.spec??r,a=i?.object;if(!a)throw Error(`FormView "${e}" is missing an "object" target`);let o=null;try{let e=await Mv(`/meta/object/${encodeURIComponent(a)}`);if(e.ok){let t=await e.json(),n=t?.item??t,r=n?.spec??n;r?.fields&&typeof r.fields==`object`&&(o={name:r.name??a,label:r.label,fields:r.fields})}}catch{}return{label:i?.label??e,object:a,form:i,objectSchema:o}}async function Fv(e,t){let n=await Mv(`/forms/${encodeURIComponent(e)}/submit`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Submit failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}async function Iv(e,t){let n=await Mv(`/data/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Create failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}var Lv=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function Rv({field:e,value:t,onChange:n}){let r={id:`f_${e.name}`,name:e.name,required:e.required,disabled:e.readonly,placeholder:e.placeholder,className:Lv},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,X.jsx)(`textarea`,{...r,rows:5,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)});case`number`:case`integer`:case`decimal`:case`currency`:return(0,X.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,X.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,X.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,X.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,X.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,X.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,X.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{id:r.id,name:r.name,type:`checkbox`,disabled:e.readonly,checked:!!i,onChange:e=>n(e.target.checked),className:`h-4 w-4 rounded border-input`}),(0,X.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,X.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,X.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,X.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,X.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function zv({mode:e}){let t=a(),[n]=o(),r=(e===`public`?t.slug:t.name)??``,[i,s]=(0,Y.useState)(!0),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)({}),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let t=!1;return s(!0),l(null),(e===`public`?Nv(r):Pv(r)).then(e=>{t||(d(e),p(jv(Av(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||l(e?.message??String(e))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,Y.useMemo)(()=>u?Av(u.form,u.objectSchema):[],[u]),y=u?.form?.submitBehavior??{kind:`thank-you`};return i?(0,X.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):c&&!u?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,X.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:c})}):u?g&&y.kind===`thank-you`?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,X.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,X.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,X.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,X.jsxs)(`header`,{className:`mb-6`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:u.label}),u.form?.label&&u.form.label!==u.label&&(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:u.form.label})]}),(0,X.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),u){h(!0),l(null);try{switch(e===`public`?await Fv(r,f):await Iv(u.object,f),J.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:p(jv(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);l(t),J.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,X.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,X.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,X.jsx)(`div`,{className:e.columns===1?`grid grid-cols-1 gap-4`:e.columns===2?`grid grid-cols-1 gap-4 sm:grid-cols-2`:e.columns===3?`grid grid-cols-1 gap-4 sm:grid-cols-3`:`grid grid-cols-1 gap-4 sm:grid-cols-4`,children:e.fields.filter(e=>!e.hidden).map(e=>(0,X.jsxs)(`div`,{className:e.colSpan===2?`sm:col-span-2`:e.colSpan===3?`sm:col-span-3`:e.colSpan===4?`sm:col-span-4`:``,children:[(0,X.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,X.jsx)(Rv,{field:e,value:f[e.name],onChange:t=>p(n=>({...n,[e.name]:t}))}),e.helpText&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),c&&(0,X.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:c}),(0,X.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,X.jsx)(`button`,{type:`submit`,disabled:m,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:m?`Submitting…`:`Submit`})})]})]}):null}function Bv({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!e||typeof window>`u`||typeof EventSource>`u`)return;let a=null,o=null,s=!1,c=e=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{try{J.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},l=e=>{try{let t=JSON.parse(e.data);c(t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`)}catch{c(`change`)}},u=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}c(t)},d=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`metadata-change`,l),a.addEventListener(`reload`,u),a.addEventListener(`error`,()=>{s||a?.readyState===EventSource.CLOSED&&(a=null,o=setTimeout(d,r))})}catch{o=setTimeout(d,r)}};return d(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}var Vv=e(c(),1);function Hv({message:e}){return typeof document>`u`?null:(0,Vv.createPortal)((0,X.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`fixed inset-0 z-[9999] flex items-center justify-center`,style:{background:`rgba(255,255,255,0.85)`,backdropFilter:`blur(4px)`},children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,style:{color:`#525252`,fontSize:14},children:[(0,X.jsx)(`div`,{style:{width:32,height:32,border:`2px solid #d4d4d4`,borderTopColor:`transparent`,borderRadius:`50%`,animation:`so-spin 0.8s linear infinite`}}),(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(`style`,{children:`@keyframes so-spin { to { transform: rotate(360deg); } }`})]})}),document.body)}function Uv(){let{user:e,isAuthenticated:t}=C(),n=(0,Y.useRef)(!1),[r,i]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(t||e){n.current=!0;return}if(n.current&&!r){i(!0);let e=window.setTimeout(()=>i(!1),8e3);return()=>window.clearTimeout(e)}},[t,e,r]),r?(0,X.jsx)(Hv,{message:`Signing you out…`}):null}function Wv(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``;return e?e.replace(/\/$/,``):typeof window<`u`?window.location.origin:``}function Gv(e){return typeof e.content==`string`&&e.content.trim()?e.content:Array.isArray(e.parts)?e.parts.map(e=>e.text??e.content??``).filter(Boolean).join(`
|
|
23
|
-
|
|
24
|
-
`):``}function Kv(){let{token:e}=a(),t=`${(0,Y.useMemo)(()=>Wv(),[])}/api/v1`,[n,r]=(0,Y.useState)(null),[i,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!0),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(null),h=(0,Y.useCallback)(async n=>{if(e){c(!0),o(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let a=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(a.status===401){u(!0),o(n?`Wrong password.`:null),c(!1);return}if(a.status===404){o(`This link is invalid or no longer available.`),c(!1);return}if(a.status===410){o(`This link has expired or was revoked.`),c(!1);return}if(!a.ok){o((await a.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${a.status}).`),c(!1);return}let s=await a.json();r(`data`in s?s.data:{record:s.record,link:s.link,redactedFields:s.redactFields}),u(!1)}catch(e){o(e?.message??`Failed to load shared content.`)}finally{c(!1)}}},[t,e]);if((0,Y.useEffect)(()=>{h()},[h]),(0,Y.useEffect)(()=>{if(!n||n.link.object_name!==`ai_conversations`)return;let e=`${t}/share-links/${encodeURIComponent(n.link.token)}/messages`;fetch(e,{headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>m(e?.data??[])).catch(()=>m([]))},[t,n]),s)return(0,X.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,X.jsx)(jr,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-4 px-4 text-center`,children:[(0,X.jsx)(Hr,{className:`h-8 w-8 text-muted-foreground`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,X.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,X.jsx)(Nr,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,X.jsx)(K,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,X.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,X.jsx)(q,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,X.jsx)(Ot,{className:`h-8 w-8 text-amber-500`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i})]});if(!n)return null;if(n.link.object_name===`ai_conversations`){let e=n.record;return(0,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,X.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,X.jsx)(Mn,{className:`h-5 w-5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,X.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,X.jsx)(G,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,X.jsx)(jr,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,X.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,X.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=Gv(e);if(!t)return null;let n=e.role===`user`;return(0,X.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,X.jsx)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm leading-relaxed ${n?`bg-primary text-primary-foreground`:`bg-muted text-foreground`}`,children:n?(0,X.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,X.jsx)(`footer`,{className:`border-t bg-muted/30 px-4 py-2 text-center text-[11px] text-muted-foreground`,children:`Powered by ObjectStack`})]})}return(0,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,X.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,X.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,X.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-3 text-[12px]`,children:JSON.stringify(n.record,null,2)}),n.redactedFields&&n.redactedFields.length>0&&(0,X.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}var qv=`/api/v1/auth`;function Jv(){try{if(typeof document>`u`)return`/`;let e=document.querySelector(`base`)?.getAttribute(`href`);return e&&new URL(e,window.location.origin).pathname.replace(/\/$/,``)||`/`}catch{return`/`}}var Yv=Jv();function Xv({children:e,requireOrganization:t=!0}){return(0,X.jsx)(D,{fallback:(0,X.jsx)(wv,{}),loadingFallback:(0,X.jsx)(Ko,{}),children:(0,X.jsx)(Jo,{children:t?(0,X.jsx)(Zo,{children:e}):e})})}function Zv(){return(0,Y.useEffect)(()=>{xv(new URLSearchParams(window.location.search).get(`redirect`)??void 0)},[]),(0,X.jsx)(Ko,{})}function Qv(){return(0,Y.useEffect)(()=>{Sv(new URLSearchParams(window.location.search).get(`redirect`)??void 0)},[]),(0,X.jsx)(Ko,{})}function $v(){return(0,Y.useEffect)(()=>{Cv()},[]),(0,X.jsx)(Ko,{})}function ey(){let{user:e}=C();return(0,X.jsx)(sf,{userId:e?.id,children:(0,X.jsx)(yf,{})})}function ty(){return(0,X.jsxs)(O,{authUrl:qv,children:[(0,X.jsx)(gc,{position:`bottom-right`}),(0,X.jsx)(Bv,{}),(0,X.jsx)(Uv,{}),(0,X.jsx)(l,{basename:Yv,children:(0,X.jsx)(qo,{children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`/login`,element:(0,X.jsx)(Zv,{})}),(0,X.jsx)(g,{path:`/register`,element:(0,X.jsx)(Qv,{})}),(0,X.jsx)(g,{path:`/forgot-password`,element:(0,X.jsx)($v,{})}),(0,X.jsx)(g,{path:`/f/:slug`,element:(0,X.jsx)(zv,{mode:`public`})}),(0,X.jsx)(g,{path:`/s/:token`,element:(0,X.jsx)(Kv,{})}),(0,X.jsx)(g,{path:`/forms/:name`,element:(0,X.jsx)(Xv,{children:(0,X.jsx)(zv,{mode:`internal`})})}),(0,X.jsx)(g,{path:`/home`,element:(0,X.jsx)(Xv,{children:(0,X.jsx)(ey,{})})}),(0,X.jsx)(g,{path:`/organizations`,element:(0,X.jsx)(Xv,{requireOrganization:!1,children:(0,X.jsx)(bf,{children:(0,X.jsx)(Tf,{})})})}),(0,X.jsx)(g,{path:`/system/*`,element:(0,X.jsx)(Qo,{})}),(0,X.jsx)(g,{path:`/ai`,element:(0,X.jsx)(Xv,{children:(0,X.jsx)(jf,{})})}),(0,X.jsx)(g,{path:`/ai/:conversationId`,element:(0,X.jsx)(Xv,{children:(0,X.jsx)(jf,{})})}),(0,X.jsx)(g,{path:`/apps/:appName/*`,element:(0,X.jsx)(Xv,{children:(0,X.jsx)(vv,{})})}),(0,X.jsx)(g,{path:`/`,element:(0,X.jsx)(Jo,{children:(0,X.jsx)(Ev,{})})}),(0,X.jsx)(g,{path:`*`,element:(0,X.jsx)(p,{to:`/`,replace:!0})})]})})})]})}async function ny(e){try{let t=await fetch(`/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,S(r)?y(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var ry=`auth-session-token`,iy=`auth-active-organization-id`;async function ay(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(ry)}catch{return}if(t)try{let n=await fetch(`${e}/get-session`,{method:`GET`,credentials:`omit`,headers:{Authorization:`Bearer ${t}`,Accept:`application/json`}});if(n.ok){let e=await n.json().catch(()=>null);if(e?.user??e?.data?.user??null)return}localStorage.removeItem(ry),localStorage.removeItem(iy)}catch{}}function oy(e,t){let n=Array.isArray(e.fields)?e.fields:Object.values(e.fields||{});return{id:e.name||`obj_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,pluralLabel:e.pluralLabel||e.plural_label||void 0,description:typeof e.description==`object`?e.description.defaultValue:e.description||void 0,icon:e.icon||void 0,group:e.name?.startsWith(`sys_`)?`System Objects`:`Custom Objects`,sortOrder:t,isSystem:e.name?.startsWith(`sys_`)||!1,enabled:e.enabled!==!1,fieldCount:n.length,relationships:Array.isArray(e.relationships)?e.relationships.map(e=>({relatedObject:e.object||e.relatedObject||``,type:e.type||`one-to-many`,label:e.label||e.name||void 0,foreignKey:e.foreign_key||e.foreignKey||void 0})):void 0}}function sy(e,t){return{id:e.name||`fld_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,type:e.type||`text`,group:e.group||void 0,sortOrder:t,description:e.description||e.help||void 0,required:e.required||!1,unique:e.unique||!1,readonly:e.readonly||!1,hidden:e.hidden||!1,defaultValue:e.defaultValue||e.default_value||void 0,placeholder:e.placeholder||void 0,options:Array.isArray(e.options)?e.options.map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label||e.value,value:e.value,color:e.color}):void 0,isSystem:e.readonly===!0&&(e.name===`id`||e.name===`createdAt`||e.name===`updatedAt`),externalId:e.externalId||!1,trackHistory:e.trackHistory||e.track_history||!1,indexed:e.indexed||!1,referenceTo:e.reference_to||e.referenceTo||void 0,formula:e.formula||void 0}}function cy(e){let{objects:t}=F(),n=(0,Y.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,Y.useMemo)(()=>n?oy(n,0):null,[n]),fields:(0,Y.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(sy):[],[n]),metadataObject:n}}function ly({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(t),[u,d]=(0,Y.useState)(!1),f=(0,Y.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,Y.useCallback)(async()=>{if(c===t){s(!1);return}d(!0);try{await n(c),s(!1)}catch{}finally{d(!1)}},[c,t,n]),h=()=>{l(t),s(!1)},g=e=>{e.key===`Enter`&&!r&&(e.preventDefault(),m()),e.key===`Escape`&&h()};return(0,X.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,X.jsx)(`dd`,{children:o?(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,X.jsx)(Yt,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,X.jsx)(K,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,X.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,X.jsx)(jr,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Ae,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:h,disabled:u,className:`mt-0.5 p-1 rounded text-muted-foreground hover:bg-accent shrink-0`,"aria-label":`Cancel`,children:(0,X.jsx)(Yi,{className:`h-3.5 w-3.5`})})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,X.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,X.jsx)(`button`,{onClick:p,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:bg-accent transition-opacity shrink-0`,"aria-label":`Edit ${e}`,children:(0,X.jsx)(Ir,{className:`h-3 w-3`})})]})})]})}function uy({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=cy(t),{refresh:a}=F(),o=Tu(),s=(0,Y.useCallback)(async(e,n)=>{if(!o||!i)return;let r={...i,[e]:n};try{await o.saveMetadataItem(`object`,t,r),await a(),J.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw J.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,X.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,X.jsx)(ly,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,X.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,X.jsx)(ly,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,X.jsx)(ly,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,X.jsx)(`div`,{className:`sm:col-span-2`,children:(0,X.jsx)(ly,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(G,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,X.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(G,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var dy=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function fy({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=cy(t),{refresh:i}=F(),a=Tu(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,Y.useCallback)(async()=>{if(!a||!r||!u.relatedObject.trim())return;let e={relatedObject:u.relatedObject.trim(),type:u.type,label:u.label.trim()||void 0,foreignKey:u.foreignKey.trim()||void 0},n={...r,relationships:[...Array.isArray(r.relationships)?r.relationships:[],e]};l(!0);try{await a.saveMetadataItem(`object`,t,n),await i(),J.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){J.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,Y.useCallback)(async e=>{if(!a||!r)return;let n=Array.isArray(r.relationships)?[...r.relationships]:[];n.splice(e,1);let o={...r,relationships:n};l(!0);try{await a.saveMetadataItem(`object`,t,o),await i(),J.success(`关联关系已删除`)}catch(e){J.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,X.jsx)(fn,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,X.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,X.jsx)(K,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,X.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:dy.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,X.jsx)(K,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,X.jsx)(K,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,X.jsxs)(q,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,X.jsx)(jr,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,X.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,X.jsx)(G,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:dy.find(t=>t.value===e.type)?.label||e.type}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,X.jsx)(`button`,{onClick:()=>void p(t),disabled:c,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-destructive hover:bg-destructive/10 transition-all shrink-0`,"aria-label":`删除关联`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,X.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,X.jsx)(Hr,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,X.jsx)(fn,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function py({schema:e}){let t=e.objectName,{fields:n}=cy(t),r=(0,Y.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,X.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,X.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,X.jsx)(G,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,X.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,X.jsx)(Fi,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function my(e){return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-forms`,children:[(0,X.jsx)(Wt,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-views`,children:[(0,X.jsx)(lr,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,X.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-dashboards`,children:[(0,X.jsx)(Pe,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function hy({schema:e}){let t=e.objectName,{object:n}=cy(t);return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,X.jsx)(tt,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function gy(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function _y(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=gy(i),o=(()=>{if(!r||!a)return null;try{let e=a.getItem(r);if(!e)return null;let t=JSON.parse(e);if(t&&t.v===1&&Array.isArray(t.past)&&Array.isArray(t.future))return t}catch{}return null})(),[s,c]=(0,Y.useState)(o?.current??e),l=(0,Y.useRef)(o?.past??[]),u=(0,Y.useRef)(o?.future??[]),[,d]=(0,Y.useState)(0),f=(0,Y.useCallback)(()=>d(e=>e+1),[]);(0,Y.useEffect)(()=>{if(!(!r||!a))try{let e={v:1,past:l.current,current:s,future:u.current};a.setItem(r,JSON.stringify(e))}catch{}},[s,r,a]);let p=(0,Y.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,Y.useCallback)(()=>{l.current.length!==0&&(c(e=>{let t=[...l.current],n=t.pop();return l.current=t,u.current=[e,...u.current],n}),f())},[f]),h=(0,Y.useCallback)(()=>{u.current.length!==0&&(c(e=>{let t=[...u.current],n=t.shift();return u.current=t,l.current=[...l.current,e],n}),f())},[f]),g=(0,Y.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,Y.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,Y.useCallback)(e=>{let t=l.current.length+1+u.current.length;e<0||e>=t||e!==l.current.length&&(c(t=>{let n=[...l.current,t,...u.current],r=n[e];return l.current=n.slice(0,e),u.current=n.slice(e+1),r}),f())},[f]);return{current:s,canUndo:l.current.length>0,canRedo:u.current.length>0,undoCount:l.current.length,redoCount:u.current.length,timeline:[...l.current,s,...u.current],currentIndex:l.current.length,push:p,undo:m,redo:h,reset:g,jumpTo:v,clearPersisted:_}}function vy(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),o=(0,Y.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,Y.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,Y.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,Y.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function yy(){let[e,t]=(0,Y.useState)(new Set);return{selectedIds:e,toggle:(0,Y.useCallback)((e,n=!1)=>{t(t=>{let r=new Set(n?t:[]);return t.has(e)&&n?r.delete(e):r.add(e),r})},[]),selectOne:(0,Y.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,Y.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,Y.useCallback)(()=>{t(new Set)},[]),isSelected:(0,Y.useCallback)(t=>e.has(t),[e]),count:e.size}}function by(){let[e,t]=(0,Y.useState)(null);return{clipboard:e,copy:(0,Y.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,Y.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function xy(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,Y.useState)(i),[s,c]=(0,Y.useState)({x:0,y:0}),l=(0,Y.useRef)(!1),u=(0,Y.useRef)({x:0,y:0}),d=(0,Y.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,Y.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,Y.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,Y.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,Y.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,Y.useCallback)(e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();let t=e.deltaY>0?-r:r;o(e=>d(e+t))}},[d,r]),startPan:(0,Y.useCallback)(e=>{if(e.button===1||e.button===0&&e.altKey){e.preventDefault(),l.current=!0,u.current={x:e.clientX,y:e.clientY};let t=e=>{if(!l.current)return;let t=e.clientX-u.current.x,n=e.clientY-u.current.y;u.current={x:e.clientX,y:e.clientY},c(e=>({x:e.x+t,y:e.y+n}))},n=()=>{l.current=!1,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)}},[]),transformStyle:{transform:`translate(${s.x}px, ${s.y}px) scale(${a})`,transformOrigin:`0 0`}}}function Sy(...e){return la(ca(e))}function Cy({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,X.jsx)(`dialog`,{ref:c,className:`fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50`,onClose:s,"aria-labelledby":`confirm-title`,"aria-describedby":`confirm-message`,children:(0,X.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,X.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,X.jsx)(Ot,{className:`h-5 w-5 text-destructive`})}),(0,X.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,X.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,X.jsx)(`button`,{onClick:o,className:Sy(`px-4 py-2 text-sm rounded-md font-medium`,a?`bg-destructive text-destructive-foreground hover:bg-destructive/90`:`bg-primary text-primary-foreground hover:bg-primary/90`),autoFocus:!0,children:r})]})]})}):null}function wy(...e){return la(ca(e))}function Ty({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,Y.useState)(new Set),o=(0,Y.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=t.reduce((e,t)=>{let n=t.group??`General`;return e[n]||(e[n]=[]),e[n].push(t),e},{});return(0,X.jsxs)(`div`,{className:wy(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,X.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,X.jsxs)(`button`,{onClick:()=>o(e),className:`w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50`,children:[i.has(e)?(0,X.jsx)(tr,{className:`h-3 w-3`}):(0,X.jsx)(sn,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,X.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,X.jsx)(Ey,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,X.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function Ey({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,X.jsx)(`input`,{type:`text`,value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`number`&&(0,X.jsx)(`input`,{type:`number`,value:Number(e.value??0),onChange:e=>n(Number(e.target.value)),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`boolean`&&(0,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,X.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,X.jsx)(`select`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`,children:e.options?.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{type:`color`,value:String(e.value??`#000000`),onChange:e=>n(e.target.value),className:`h-6 w-6 rounded border cursor-pointer`}),(0,X.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,X.jsx)(`textarea`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background resize-y`,rows:3}),e.description&&(0,X.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function Dy(...e){return la(ca(e))}function Oy({items:e,canvasWidth:t,canvasHeight:n,position:r=`bottom-right`,size:i=150,className:a}){let o=Math.min(i/t,i/n),s=t*o,c=n*o;return(0,X.jsx)(`div`,{className:Dy(`absolute border rounded bg-background/90 shadow-sm overflow-hidden`,{"top-left":`top-2 left-2`,"top-right":`top-2 right-2`,"bottom-left":`bottom-2 left-2`,"bottom-right":`bottom-2 right-2`}[r],a),role:`img`,"aria-label":`Canvas minimap`,children:(0,X.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,X.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,X.jsx)(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.selected?`hsl(var(--primary))`:e.color??`hsl(var(--foreground) / 0.3)`,rx:`2`},e.id))]})})}var ky=(0,Y.createContext)(null);ky.displayName=`CollaborationContext`;function Ay(){return(0,Y.useContext)(ky)}function jy(...e){return la(ca(e))}function My({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=Ny,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=_y(t),d=u.current,f=(0,Y.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=xy({initialZoom:e.zoom??1}),{zoom:m}=p,h=yy(),g=(0,Y.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,Y.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=by(),y=vy(),b=Ay(),x=(0,Y.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,Y.useState)(!0),[w,T]=(0,Y.useState)(!0),[E,D]=(0,Y.useState)(s),O=(0,Y.useRef)(null),k=(0,Y.useRef)(null),A=(0,Y.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(0,Y.useCallback)((e,t)=>{if(o)return;let r=n.flatMap(e=>e.items).find(t=>t.type===e),i=r?.defaultSize,a={id:`comp-${Date.now()}`,type:e,label:t,position:{x:100,y:100,width:i?.width??200,height:i?.height??100},props:r?.defaultProps??{}};f([...d,a]),h.selectOne(a.id),x({type:`insert`,elementId:a.id,data:{component:a}})},[d,o,n,f,h,x]),M=(0,Y.useCallback)(e=>{o||(f(d.filter(t=>t.id!==e)),h.isSelected(e)&&h.clearSelection(),x({type:`delete`,elementId:e,data:{}}))},[d,o,f,h,x]),ee=(0,Y.useCallback)(async()=>{if(o||h.count===0||!await y.confirm(`Delete components`,`Are you sure you want to delete ${h.count} component${h.count>1?`s`:``}?`))return;let e=h.selectedIds;f(d.filter(t=>!e.has(t.id))),h.clearSelection(),e.forEach(e=>{x({type:`delete`,elementId:e,data:{}})})},[o,h,y,d,f,x]),te=(0,Y.useCallback)((e,t)=>{o||!g||(f(d.map(n=>n.id===g?e===`label`?{...n,label:String(t)}:e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,props:{...n.props,[e]:t}}:n)),x({type:`update`,elementId:g,data:{[e]:t}}))},[o,g,d,f,x]),ne=(0,Y.useCallback)(()=>{let e=h.selectedIds;if(e.size===0)return;let t=d.filter(t=>e.has(t.id));v.copy(t)},[h,d,v]),N=(0,Y.useCallback)(()=>{if(o)return;let e=v.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));f([...d,...n]),h.selectMany(n.map(e=>e.id)),n.forEach(e=>{x({type:`insert`,elementId:e.id,data:{component:e}})})},[o,v,d,f,h,x]),P=(0,Y.useCallback)((e,t)=>{o||(O.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[o]),F=(0,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),re=(0,Y.useCallback)(e=>{e.preventDefault();let t=O.current;if(!t||o)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;f(d.map(e=>e.id===t.id?{...e,position:{...e.position,x:A(e.position.x+n),y:A(e.position.y+r)}}:e)),x({type:`move`,elementId:t.id,data:{}}),O.current=null},[o,m,d,f,A,x]),I=(0,Y.useMemo)(()=>_?[{name:`label`,label:`Label`,type:`text`,value:_.label??``,group:`General`},{name:`x`,label:`X`,type:`number`,value:_.position.x,group:`Position`},{name:`y`,label:`Y`,type:`number`,value:_.position.y,group:`Position`},{name:`width`,label:`Width`,type:`number`,value:_.position.width,group:`Size`},{name:`height`,label:`Height`,type:`number`,value:_.position.height,group:`Size`}]:[],[_]),L=(0,Y.useMemo)(()=>d.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:typeof e.position.width==`number`?e.position.width:100,height:typeof e.position.height==`number`?e.position.height:50,selected:h.isSelected(e.id)})),[d,h]);return(0,Y.useEffect)(()=>{let e=k.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&h.count>0&&!t){e.preventDefault(),ee();return}if(e.key===`Escape`){h.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&i&&!o){e.preventDefault(),u.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&i&&!o){e.preventDefault(),u.redo();return}if(n&&e.key===`c`){e.preventDefault(),ne();return}if(n&&e.key===`v`&&!o){e.preventDefault(),N();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,ee,i,o,u,ne,N,d]),(0,X.jsxs)(`div`,{ref:k,tabIndex:0,className:jy(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,X.jsx)(`div`,{className:jy(`border-r bg-muted/30 flex flex-col transition-[width] duration-200`,S?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component palette`,children:S&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,X.jsxs)(`div`,{className:`mb-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,X.jsxs)(`button`,{onClick:()=>j(e.type,e.label),className:`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left`,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,X.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:S?`Collapse palette`:`Expand palette`,"aria-label":S?`Collapse palette`:`Expand palette`,onClick:()=>C(e=>!e),children:(0,X.jsx)(nn,{className:jy(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,!u.canUndo&&`opacity-40 pointer-events-none`),title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,disabled:!u.canUndo,onClick:()=>u.undo(),children:(0,X.jsx)(Ee,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,!u.canRedo&&`opacity-40 pointer-events-none`),title:`Redo (Ctrl+Shift+Z)`,"aria-label":`Redo`,disabled:!u.canRedo,onClick:()=>u.redo(),children:(0,X.jsx)(qi,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:h.count===0,onClick:ne,children:(0,X.jsx)(Ei,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,!v.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!v.hasContent,onClick:N,children:(0,X.jsx)(Si,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Delete selected`,"aria-label":`Delete selected`,disabled:h.count===0,onClick:ee,children:(0,X.jsx)(qt,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,X.jsx)(En,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:jy(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,X.jsx)(U,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,X.jsx)(fi,{className:`h-3 w-3`})}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,X.jsx)(fn,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,X.jsx)(Zt,{className:`h-3 w-3`})})]}),r&&(0,X.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:w?`Collapse panel`:`Expand panel`,"aria-label":w?`Collapse panel`:`Expand panel`,onClick:()=>T(e=>!e),children:(0,X.jsx)(at,{className:jy(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:p.handleWheel,onMouseDown:p.startPan,onDragOver:F,onDrop:re,children:(0,X.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*m,height:e.height*m,transform:`translate(${p.panOffset.x}px, ${p.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*m}px ${e.gridSize*m}px`:void 0},children:[d.map(e=>{let t=h.isSelected(e.id);return(0,X.jsxs)(`div`,{draggable:!o,onDragStart:t=>P(t,e),className:jy(`absolute border rounded cursor-move select-none transition-shadow`,t?`border-primary ring-2 ring-primary/20 shadow-md`:`border-border hover:border-primary/50`),style:{left:e.position.x*m,top:e.position.y*m,width:typeof e.position.width==`number`?e.position.width*m:e.position.width,height:typeof e.position.height==`number`?e.position.height*m:e.position.height},onClick:t=>h.toggle(e.id,t.shiftKey),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,X.jsx)(Ce,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),M(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,X.jsx)(qt,{className:`h-3 w-3 text-destructive`})})]}),(0,X.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,X.jsx)(Oy,{items:L,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,X.jsx)(`div`,{className:jy(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,w?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component tree`,children:w&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,X.jsx)(Jr,{className:`h-4 w-4`}),`Component Tree`]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:`No components added yet. Click a component in the palette to add it to the canvas.`}):d.map(e=>(0,X.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:jy(`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left`,h.isSelected(e.id)?`bg-accent`:`hover:bg-accent/50`),children:(0,X.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,X.jsx)(`div`,{className:`border-t`,children:(0,X.jsx)(Ty,{title:`Properties – ${_.label??_.type}`,fields:I,onChange:te})}):_&&(0,X.jsxs)(`div`,{className:`border-t p-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,X.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,X.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,X.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,X.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,X.jsx)(Cy,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var Ny=[{name:`layout`,label:`Layout`,items:[{type:`container`,label:`Container`,defaultSize:{width:400,height:300}},{type:`flex`,label:`Flex`,defaultSize:{width:400,height:200}},{type:`grid`,label:`Grid`,defaultSize:{width:400,height:300}},{type:`card`,label:`Card`,defaultSize:{width:300,height:200}},{type:`tabs`,label:`Tabs`,defaultSize:{width:400,height:300}}]},{name:`form`,label:`Form`,items:[{type:`input`,label:`Input`,defaultSize:{width:300,height:60}},{type:`textarea`,label:`Textarea`,defaultSize:{width:300,height:120}},{type:`select`,label:`Select`,defaultSize:{width:300,height:60}},{type:`checkbox`,label:`Checkbox`,defaultSize:{width:200,height:40}},{type:`button`,label:`Button`,defaultSize:{width:120,height:40}}]},{name:`data`,label:`Data`,items:[{type:`table`,label:`Table`,defaultSize:{width:600,height:400}},{type:`chart`,label:`Chart`,defaultSize:{width:400,height:300}},{type:`list`,label:`List`,defaultSize:{width:300,height:400}},{type:`statistic`,label:`Statistic`,defaultSize:{width:200,height:100}}]}];function Py(e,t={}){return _y(e,t)}function Fy(...e){return la(ca(e))}var Iy=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function Ly(e,t=4,n=280,r=250,i=50,a=50){return e.map((e,o)=>({...e,position:{x:i+o%t*n,y:a+Math.floor(o/t)*r}}))}function Ry({entities:e=[],relationships:t=[],canvas:n={width:1200,height:800,showGrid:!0},showRelationshipLabels:r=!0,readOnly:i=!1,onEntitiesChange:a,onRelationshipsChange:o,className:s}){let c=(0,Y.useRef)(null),l=Py({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,Y.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=vy(),m=yy(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=by(),_=xy({minZoom:.25,maxZoom:3,zoomStep:.1}),v=Ay(),[y,b]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(!0),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(``),j=(0,Y.useRef)(null),M=(0,Y.useCallback)(()=>{if(i)return;let e=l.current,t={id:`entity-${Date.now()}`,name:`new_entity_${e.entities.length+1}`,label:`New Entity ${e.entities.length+1}`,fields:[{name:`id`,type:`uuid`,primaryKey:!0,required:!0},{name:`created_at`,type:`datetime`,required:!0},{name:`updated_at`,type:`datetime`,required:!0}],position:{x:50+e.entities.length%4*280,y:50+Math.floor(e.entities.length/4)*250}};f({entities:[...e.entities,t],relationships:e.relationships}),m.selectOne(t.id),v?.sendOperation({type:`insert`,userId:v?.currentUserId??``,elementId:t.id,data:{name:t.name,label:t.label}})},[i,l,f,m,v]),ee=(0,Y.useCallback)(async e=>{if(i)return;let t=u.find(t=>t.id===e);if(!await p.confirm(`Delete Entity`,`Are you sure you want to delete "${t?.label??e}"? This action cannot be undone.`))return;let n=l.current;f({entities:n.entities.filter(t=>t.id!==e),relationships:n.relationships.filter(t=>t.sourceEntity!==e&&t.targetEntity!==e)}),m.isSelected(e)&&m.clearSelection(),v?.sendOperation({type:`delete`,userId:v?.currentUserId??``,elementId:e,data:{}})},[i,u,p,l,f,m,v]),te=(0,Y.useCallback)(async()=>{if(i||m.count===0)return;let e=Array.from(m.selectedIds);if(!await p.confirm(`Delete Entities`,`Are you sure you want to delete ${e.length} selected entity(s)? This action cannot be undone.`))return;let t=l.current,n=new Set(e);f({entities:t.entities.filter(e=>!n.has(e.id)),relationships:t.relationships.filter(e=>!n.has(e.sourceEntity)&&!n.has(e.targetEntity))}),m.clearSelection()},[i,m,p,l,f]),ne=(0,Y.useCallback)(()=>{if(i)return;let e=l.current;f({entities:Ly(e.entities),relationships:e.relationships})},[i,l,f]),N=(0,Y.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),P=(0,Y.useCallback)(()=>{if(i)return;let e=g.paste();if(!e||e.length===0)return;let t=l.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));f({entities:[...t.entities,...n],relationships:t.relationships}),m.selectMany(n.map(e=>e.id))},[i,g,l,f,m]),F=(0,Y.useCallback)(e=>{if(i)return;let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[i,l,f]),re=(0,Y.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),I=(0,Y.useCallback)(()=>{if(!C)return;let e=T.trim();if(e===``){w(null);return}let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==C.entityId)return t;let n=t.fields.map((t,n)=>n===C.fieldIndex?{...t,name:e}:t);return{...t,fields:n}}),relationships:t.relationships}),w(null)},[C,T,l,f]),L=(0,Y.useCallback)(()=>{w(null)},[]),ie=(0,Y.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),ae=(0,Y.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),oe=(0,Y.useCallback)(()=>{O(null)},[]),se=(0,Y.useCallback)((e,t,n)=>{if(i)return;let r=l.current;f({entities:r.entities.map(r=>{if(r.id!==e)return r;let i=r.fields.map((e,r)=>r===t?{...e,type:n}:e);return{...r,fields:i}}),relationships:r.relationships})},[i,l,f]),ce=(0,Y.useCallback)((e,t)=>{if(i||!u.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();j.current={entityId:t,offsetX:e.clientX-n.left,offsetY:e.clientY-n.top},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[i,u]),le=(0,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ue=(0,Y.useCallback)(e=>{if(e.preventDefault(),!j.current)return;let t=e.currentTarget.getBoundingClientRect(),n=_.zoom,r=(e.clientX-t.left-_.panOffset.x)/n-j.current.offsetX,i=(e.clientY-t.top-_.panOffset.y)/n-j.current.offsetY,a=l.current;f({entities:a.entities.map(e=>e.id===j.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),j.current=null},[_.zoom,_.panOffset,l,f]),R=h?u.find(e=>e.id===h):null,de=R?[{name:`name`,label:`Name`,type:`text`,value:R.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:R.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:R.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:R.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:R.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:R.position.y,group:`Position`}]:[],fe=(0,Y.useCallback)((e,t)=>{if(!h)return;let n=l.current;f({entities:n.entities.map(n=>n.id===h?e===`position.x`?{...n,position:{...n.position,x:Number(t)}}:e===`position.y`?{...n,position:{...n.position,y:Number(t)}}:{...n,[e]:t}:n),relationships:n.relationships})},[h,l,f]);(0,Y.useEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{let t=e.target.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;n&&e.key===`z`?(e.preventDefault(),l.undo()):n&&(e.key===`y`||e.shiftKey&&e.key===`Z`)?(e.preventDefault(),l.redo()):n&&e.key===`c`?(e.preventDefault(),N()):n&&e.key===`v`?(e.preventDefault(),P()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),te()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,N,P,te,m]);let pe=u.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:240,height:40+e.fields.length*24,color:e.color,selected:m.isSelected(e.id)}));return(0,X.jsxs)(`div`,{ref:c,tabIndex:0,className:Fy(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{role:`toolbar`,"aria-label":`Designer toolbar`,className:`flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap`,children:[(0,X.jsx)(Xt,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,X.jsx)(`button`,{onClick:()=>l.undo(),disabled:!l.canUndo,"aria-label":`Undo`,title:`Undo (Ctrl+Z)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(Ee,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:()=>l.redo(),disabled:!l.canRedo,"aria-label":`Redo`,title:`Redo (Ctrl+Y)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(qi,{className:`h-3.5 w-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,X.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(Ri,{className:`h-3.5 w-3.5`})}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,X.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(qn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(Kn,{className:`h-3 w-3`})})]}),!i&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,X.jsx)(`button`,{onClick:N,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(Ei,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:P,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(Si,{className:`h-3.5 w-3.5`})})]}),!i&&(0,X.jsxs)(`button`,{onClick:ne,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,X.jsx)(Fr,{className:`h-3 w-3`}),` Auto Layout`]}),(0,X.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,X.jsx)(ze,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`button`,{onClick:M,"aria-label":`Add Entity`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),` Add Entity`]}),(0,X.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,X.jsx)(Hr,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,X.jsxs)(`div`,{role:`region`,"aria-label":`Canvas`,className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,onWheel:_.handleWheel,onMouseDown:_.startPan,onDragOver:le,onDrop:ue,children:[(0,X.jsxs)(`div`,{className:`relative`,style:{width:n.width,minHeight:n.height,..._.transformStyle,backgroundImage:n.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:n.showGrid?`20px 20px`:void 0},children:[(0,X.jsx)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:n.width,height:n.height,children:d.map(e=>{let t=u.find(t=>t.id===e.sourceEntity),n=u.find(t=>t.id===e.targetEntity);return!t||!n?null:(0,X.jsxs)(`g`,{children:[(0,X.jsx)(`line`,{x1:t.position.x+120,y1:t.position.y+50,x2:n.position.x+120,y2:n.position.y+50,stroke:`hsl(var(--primary))`,strokeWidth:`2`,strokeDasharray:e.type===`many-to-many`?`5,5`:void 0}),r&&e.label&&(0,X.jsx)(`text`,{x:(t.position.x+n.position.x)/2+120,y:(t.position.y+n.position.y)/2+50-8,textAnchor:`middle`,className:`text-xs fill-muted-foreground`,children:e.label})]},e.id)})}),u.length===0&&(0,X.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground text-sm`,children:`No entities in the model. Click 'Add Entity' to create your first entity.`}),u.map(e=>(0,X.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>ce(t,e.id),className:Fy(`absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing`,m.isSelected(e.id)?`border-primary ring-2 ring-primary/20`:`border-border hover:border-primary/50`),style:{left:e.position.x,top:e.position.y},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm`,style:{backgroundColor:e.color??`hsl(var(--primary) / 0.1)`},children:[(0,X.jsx)(Xt,{className:`h-3.5 w-3.5`}),D===e.id?(0,X.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:ae,onKeyDown:e=>{e.key===`Enter`&&ae(),e.key===`Escape`&&oe()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,X.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),ie(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ee(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,X.jsx)(qt,{className:`h-3 w-3 text-destructive`})})]}),(0,X.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,X.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:I,onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&L()},className:`font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation()}):(0,X.jsxs)(`span`,{className:Fy(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),re(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,X.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,X.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,X.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),se(e.id,n,t.target.value)},onClick:e=>e.stopPropagation(),className:`text-xs text-muted-foreground ml-auto bg-transparent border-none focus:ring-1 focus:ring-primary rounded cursor-pointer p-0`,"data-testid":`field-type-${e.id}-${n}`,children:Iy.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,X.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,X.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,X.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),F(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,X.jsx)(Oy,{items:pe,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,X.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,X.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b`,"aria-expanded":y,"aria-controls":`property-editor-panel`,children:[y?(0,X.jsx)(sn,{className:`h-3 w-3`}):(0,X.jsx)(tr,{className:`h-3 w-3`}),`Properties`]}),y&&(0,X.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,X.jsx)(Ty,{title:R?R.label:`Properties`,fields:de,onChange:fe})})]}),(0,X.jsx)(`div`,{className:`border-t`,children:(0,X.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full`,"aria-expanded":x,children:[x?(0,X.jsx)(sn,{className:`h-3 w-3`}):(0,X.jsx)(tr,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,X.jsx)(Cy,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function zy(...e){return la(ca(e))}var By=120,Vy=50;function Hy(e,t){if(e.length===0)return e;let n=new Map,r=new Map;for(let t of e)n.set(t.id,0),r.set(t.id,[]);for(let e of t)n.set(e.target,(n.get(e.target)??0)+1),r.get(e.source)?.push(e.target);let i=[],a=new Set,o=e.filter(e=>(n.get(e.id)??0)===0).map(e=>e.id);for(o.length===0&&(o=[e[0].id]);o.length>0;){i.push(o);for(let e of o)a.add(e);let e=new Set;for(let t of o)for(let n of r.get(t)??[])a.has(n)||e.add(n);o=Array.from(e)}let s=e.filter(e=>!a.has(e.id)).map(e=>e.id);s.length>0&&i.push(s);let c=new Map;for(let e=0;e<i.length;e++){let t=i[e];for(let n=0;n<t.length;n++)c.set(t[n],{x:80+e*200,y:80+n*100})}return e.map(e=>({...e,position:c.get(e.id)??e.position}))}function Uy({processName:e=`New Process`,nodes:t=[],edges:n=[],lanes:r,canvas:i={width:1400,height:800,showGrid:!0},showMinimap:a=!0,showToolbar:o=!0,readOnly:s=!1,onNodesChange:c,onEdgesChange:l,className:u}){let d=_y({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,Y.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=vy(),g=yy(),_=by(),v=xy({initialZoom:1}),y=Ay(),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(null),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,ee]=(0,Y.useState)({x:0,y:0}),te=(0,Y.useRef)(null),ne=(0,Y.useRef)(c),N=(0,Y.useRef)(l);ne.current=c,N.current=l,(0,Y.useEffect)(()=>{ne.current?.(f),N.current?.(p)},[d.current]);let P=(0,Y.useCallback)((e,t)=>{if(s)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+f.length*160,y:200}};m([...f,n],p),x(n.id),g.selectOne(n.id),y?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:y.currentUserId??``})},[f,p,s,m,g,y]),F=(0,Y.useCallback)(async e=>{if(s)return;let t=f.find(t=>t.id===e);await h.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(m(f.filter(t=>t.id!==e),p.filter(t=>t.source!==e&&t.target!==e)),b===e&&x(null),g.clearSelection(),y?.sendOperation({type:`delete`,elementId:e,data:{},userId:y.currentUserId??``}))},[f,p,b,s,m,h,g,y]),re=(0,Y.useCallback)(async()=>{if(s||g.count===0||!await h.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${g.count} selected node(s) and their connected edges?`))return;let e=g.selectedIds;m(f.filter(t=>!e.has(t.id)),p.filter(t=>!e.has(t.source)&&!e.has(t.target))),x(null),g.clearSelection()},[f,p,s,m,h,g]),I=(0,Y.useCallback)(()=>{let e=g.count>0?g.selectedIds:b?new Set([b]):new Set;if(e.size===0)return;let t=f.filter(t=>e.has(t.id));_.copy(t)},[f,b,g,_]),L=(0,Y.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),ie=(0,Y.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),ae=(0,Y.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),oe=(0,Y.useCallback)(()=>{s||f.length===0||m(Hy(f,p),p)},[f,p,s,m]),se=(0,Y.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;j(t);let n=e.target.getBoundingClientRect();ee({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[s,f]),ce=(0,Y.useCallback)(e=>{if(e.preventDefault(),s||!A)return;let t=e.currentTarget.getBoundingClientRect(),n=v.zoom,r=(e.clientX-t.left-v.panOffset.x)/n-M.x,i=(e.clientY-t.top-v.panOffset.y)/n-M.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);m(f.map(e=>e.id===A?{...e,position:{x:a,y:o}}:e),p),j(null)},[s,A,M,f,p,v.zoom,v.panOffset,m]),le=(0,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ue=(0,Y.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),R=(0,Y.useMemo)(()=>ue?[{name:`label`,label:`Name`,type:`text`,value:ue.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:ue.type,options:[{label:`Start Event`,value:`start-event`},{label:`End Event`,value:`end-event`},{label:`User Task`,value:`user-task`},{label:`Service Task`,value:`service-task`},{label:`Script Task`,value:`script-task`},{label:`Exclusive Gateway`,value:`exclusive-gateway`},{label:`Parallel Gateway`,value:`parallel-gateway`},{label:`Inclusive Gateway`,value:`inclusive-gateway`}],group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:ue.description??``,group:`General`}]:[],[ue]),de=(0,Y.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),fe=e=>{switch(e){case`start-event`:return`rounded-full bg-green-100 border-green-500 text-green-700`;case`end-event`:return`rounded-full bg-red-100 border-red-500 text-red-700`;case`exclusive-gateway`:case`parallel-gateway`:case`inclusive-gateway`:case`event-based-gateway`:return`rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700`;case`user-task`:return`rounded bg-blue-100 border-blue-500 text-blue-700`;case`service-task`:case`script-task`:return`rounded bg-purple-100 border-purple-500 text-purple-700`;default:return`rounded bg-gray-100 border-gray-500 text-gray-700`}},pe=(0,Y.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:By,height:Vy,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,Y.useEffect)(()=>{let e=te.current;if(!e)return;let t=e=>{let t=e.target?.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;if(n&&e.key===`z`&&!e.shiftKey){e.preventDefault(),d.undo();return}if(n&&e.key===`y`||n&&e.key===`z`&&e.shiftKey){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),I();return}if(n&&e.key===`v`){e.preventDefault(),L();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),re()):b&&(e.preventDefault(),F(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,I,L,F,re]);let z=(0,Y.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,X.jsxs)(`div`,{ref:te,tabIndex:0,className:zy(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,X.jsx)(Cy,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,X.jsx)(jt,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,X.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,X.jsx)(`div`,{className:`flex-1`}),!s&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{onClick:()=>d.undo(),disabled:!d.canUndo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,children:(0,X.jsx)(Ee,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>d.redo(),disabled:!d.canRedo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Redo (Ctrl+Y)`,"aria-label":`Redo`,children:(0,X.jsx)(qi,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsx)(`button`,{onClick:I,disabled:g.count===0&&!b,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Copy (Ctrl+C)`,"aria-label":`Copy`,children:(0,X.jsx)(Ei,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:L,disabled:!_.hasContent,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Paste (Ctrl+V)`,"aria-label":`Paste`,children:(0,X.jsx)(Si,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsxs)(`button`,{onClick:ie,className:zy(`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,S&&`bg-primary text-primary-foreground`),title:`Connect nodes`,"aria-label":`Connect nodes`,"aria-pressed":S,children:[(0,X.jsx)(ir,{className:`h-3 w-3`}),` Connect`]}),(0,X.jsxs)(`button`,{onClick:oe,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,X.jsx)(Mt,{className:`h-3 w-3`}),` Layout`]}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsx)(`button`,{onClick:v.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,X.jsx)(qn,{className:`h-3 w-3`})}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,X.jsx)(`button`,{onClick:v.zoomOut,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom out`,"aria-label":`Zoom out`,children:(0,X.jsx)(Ri,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:v.resetZoom,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Reset zoom`,"aria-label":`Reset zoom`,children:(0,X.jsx)(Kn,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsxs)(`button`,{onClick:()=>P(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,X.jsx)(Ne,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,X.jsx)(ft,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,X.jsx)(Vn,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,X.jsx)(ft,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsx)(`button`,{onClick:()=>k(e=>!e),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:O?`Hide properties`:`Show properties`,"aria-label":O?`Hide property panel`:`Show property panel`,"aria-expanded":O,children:O?(0,X.jsx)(at,{className:`h-3 w-3`}):(0,X.jsx)(Ue,{className:`h-3 w-3`})})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4`,role:`region`,"aria-label":`Process canvas`,onWheel:v.handleWheel,onMouseDown:v.startPan,children:(0,X.jsxs)(`div`,{className:`relative`,style:{...v.transformStyle,width:i.width,minHeight:i.height,backgroundImage:i.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:i.showGrid?`20px 20px`:void 0},onClick:z,onDrop:ce,onDragOver:le,children:[(0,X.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,X.jsx)(`defs`,{children:(0,X.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,X.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground))`})})}),p.map(e=>{let t=f.find(t=>t.id===e.source),n=f.find(t=>t.id===e.target);if(!t||!n)return null;t.position.x+By/2;let r=t.position.y+Vy/2;n.position.x+By/2;let i=n.position.y+Vy/2,a=t.position.x+By,o=r,s=n.position.x,c=i;return(0,X.jsxs)(`g`,{children:[(0,X.jsx)(`path`,{d:`M ${a} ${o} Q ${(a+s)/2} ${o}, ${(a+s)/2} ${(o+c)/2} T ${s} ${c}`,fill:`none`,stroke:`hsl(var(--foreground) / 0.5)`,strokeWidth:`2`,markerEnd:`url(#arrowhead)`}),e.label&&(0,X.jsx)(`text`,{x:(a+s)/2,y:(o+c)/2-8,textAnchor:`middle`,className:`text-[10px] fill-muted-foreground`,children:e.label})]},e.id)})]}),f.length===0&&(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm`,children:`No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events.`}),f.map(e=>{let t=g.isSelected(e.id)||b===e.id,n=w===e.id,r=E===e.id,i=S||r;return(0,X.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},role:`group`,"aria-label":e.label,draggable:!s&&!S,onDragStart:t=>se(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{ae(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,X.jsx)(`div`,{className:zy(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,fe(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,X.jsx)(`span`,{className:zy(`text-xs font-medium`,(e.type===`exclusive-gateway`||e.type===`parallel-gateway`||e.type===`inclusive-gateway`||e.type===`event-based-gateway`)&&`-rotate-45`),children:e.label})}),i&&!s&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:Vy/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),ae(e.id)}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:Vy/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?ae(e.id):(C(!0),T(e.id))}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:By/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ae(e.id)}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:By/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ae(e.id)}})]}),!s&&t&&!S&&(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),F(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,X.jsx)(qt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,X.jsx)(Oy,{items:pe,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,X.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,X.jsx)(Ty,{title:ue?`Properties: ${ue.label}`:`Properties`,fields:R,onChange:de})})]})]})}function Wy(...e){return la(ca(e))}var $={untitledReport:`Untitled Report`,reportCanvas:`Report canvas`,properties:`Properties`,propertiesPanel:`Properties panel`,designerToolbar:`Report designer toolbar`,selectElementPrompt:`Select an element to edit its properties`,addElementsPrompt:`Add elements using the buttons above`,addText:`Add Text`,addField:`Add Field`,addImage:`Add Image`,addChart:`Add Chart`,addTable:`Add Table`,undo:`Undo`,undoShortcut:`Undo (Ctrl+Z)`,redo:`Redo`,redoShortcut:`Redo (Ctrl+Shift+Z)`,copy:`Copy`,copyShortcut:`Copy (Ctrl+C)`,paste:`Paste`,pasteShortcut:`Paste (Ctrl+V)`,deleteSelected:`Delete selected`,deleteElement:`Delete element`,deleteElementsTitle:`Delete elements`,deleteElementMessage:e=>`Are you sure you want to delete ${e} element${e>1?`s`:``}?`,collapsePanel:`Collapse panel`,expandPanel:`Expand panel`,collaborationConnected:`Connected`,sectionHeader:`Report Header`,sectionPageHeader:`Page Header`,sectionGroupHeader:`Group Header`,sectionDetail:`Detail`,sectionGroupFooter:`Group Footer`,sectionPageFooter:`Page Footer`,sectionFooter:`Report Footer`,elementText:`Text`,elementImage:`🖼 Image`,elementChart:`📊 Chart`,elementTable:`📋 Table`,propLabel:`Label`,propX:`X`,propY:`Y`,propWidth:`Width`,propHeight:`Height`,propText:`Text`,propField:`Field`,groupPosition:`Position`,groupSize:`Size`,groupContent:`Content`,groupGeneral:`General`},Gy={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},Ky=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function qy({reportName:e=$.untitledReport,objectName:t,pageSize:n=`A4`,orientation:r=`portrait`,margins:i={top:40,right:40,bottom:40,left:40},sections:a=[],showToolbar:o=!0,showPropertyPanel:s=!0,readOnly:c=!1,onSectionsChange:l,className:u}){let d=_y(a.length>0?a:Ky),f=d.current,p=(0,Y.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=yy(),h=(0,Y.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=by(),_=vy(),v=Ay(),y=(0,Y.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,Y.useState)(!0),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=Gy[n],T=r===`landscape`?w.height:w.width,E=r===`landscape`?w.width:w.height,D=e=>{switch(e){case`header`:return $.sectionHeader;case`page-header`:return $.sectionPageHeader;case`group-header`:return $.sectionGroupHeader;case`detail`:return $.sectionDetail;case`group-footer`:return $.sectionGroupFooter;case`page-footer`:return $.sectionPageFooter;case`footer`:return $.sectionFooter;default:return e}},O=(0,Y.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,Y.useCallback)((e,t)=>{if(c)return;let n={id:`elem-${Date.now()}`,type:t,position:{x:i.left,y:10,width:200,height:30},properties:{text:t===`text`?`New Text`:void 0,field:t===`field`?`field_name`:void 0}};p(f.map((t,r)=>r===e?{...t,elements:[...t.elements,n]}:t)),m.selectOne(n.id),y({type:`insert`,elementId:n.id,data:{element:n}})},[f,i.left,c,p,m,y]),A=(0,Y.useCallback)(e=>{c||(p(f.map(t=>({...t,elements:t.elements.filter(t=>t.id!==e)}))),m.isSelected(e)&&m.clearSelection(),y({type:`delete`,elementId:e,data:{}}))},[f,c,p,m,y]),j=(0,Y.useCallback)(async()=>{if(c||m.count===0||!await _.confirm($.deleteElementsTitle,$.deleteElementMessage(m.count)))return;let e=m.selectedIds;p(f.map(t=>({...t,elements:t.elements.filter(t=>!e.has(t.id))}))),m.clearSelection(),e.forEach(e=>{y({type:`delete`,elementId:e,data:{}})})},[c,m,_,f,p,y]),M=(0,Y.useCallback)((e,t)=>{c||!h||(p(f.map(n=>({...n,elements:n.elements.map(n=>n.id===h?e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,properties:{...n.properties,[e]:t}}:n)}))),y({type:`update`,elementId:h,data:{[e]:t}}))},[c,h,f,p,y]),ee=(0,Y.useCallback)(()=>{let e=m.selectedIds;if(e.size===0)return;let t=f.flatMap(e=>e.elements).filter(t=>e.has(t.id));g.copy(t)},[m,f,g]),te=(0,Y.useCallback)(()=>{if(c)return;let e=g.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`elem-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}})),r=f.findIndex(e=>e.type===`detail`),i=r>=0?r:0;p(f.map((e,t)=>t===i?{...e,elements:[...e.elements,...n]}:e)),m.selectMany(n.map(e=>e.id)),n.forEach(e=>{y({type:`insert`,elementId:e.id,data:{element:e}})})},[c,g,f,p,m,y]),ne=(0,Y.useCallback)((e,t,n)=>{c||(S.current={id:t.id,sectionIndex:n,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[c]),N=(0,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),P=(0,Y.useCallback)((e,t)=>{e.preventDefault();let n=S.current;if(!n||c)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)p(f.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=f.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&p(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}y({type:`move`,elementId:n.id,data:{}}),S.current=null},[c,f,p,y]),F=(0,Y.useMemo)(()=>{if(!O)return[];let e=[{name:`x`,label:$.propX,type:`number`,value:O.position.x,group:$.groupPosition},{name:`y`,label:$.propY,type:`number`,value:O.position.y,group:$.groupPosition},{name:`width`,label:$.propWidth,type:`number`,value:O.position.width,group:$.groupSize},{name:`height`,label:$.propHeight,type:`number`,value:O.position.height,group:$.groupSize}];return O.type===`text`&&e.push({name:`text`,label:$.propText,type:`text`,value:O.properties.text??``,group:$.groupContent}),O.type===`field`&&e.push({name:`field`,label:$.propField,type:`text`,value:O.properties.field??``,group:$.groupContent}),e},[O]);return(0,Y.useEffect)(()=>{let e=C.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&m.count>0&&!t){e.preventDefault(),j();return}if(e.key===`Escape`){m.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&!c){e.preventDefault(),d.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&!c){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),ee();return}if(n&&e.key===`v`&&!c){e.preventDefault(),te();return}if(n&&e.key===`a`){e.preventDefault();let t=f.flatMap(e=>e.elements).map(e=>e.id);m.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[m,j,c,d,ee,te,f]),(0,X.jsxs)(`div`,{ref:C,tabIndex:0,className:Wy(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,X.jsxs)(`div`,{role:`toolbar`,"aria-label":$.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,X.jsx)(na,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,X.jsx)(`button`,{className:Wy(`p-1.5 rounded hover:bg-accent`,!d.canUndo&&`opacity-40 pointer-events-none`),title:$.undoShortcut,"aria-label":$.undo,disabled:!d.canUndo,onClick:()=>d.undo(),children:(0,X.jsx)(Ee,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:Wy(`p-1.5 rounded hover:bg-accent`,!d.canRedo&&`opacity-40 pointer-events-none`),title:$.redoShortcut,"aria-label":$.redo,disabled:!d.canRedo,onClick:()=>d.redo(),children:(0,X.jsx)(qi,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{className:Wy(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.copyShortcut,"aria-label":$.copy,disabled:m.count===0,onClick:ee,children:(0,X.jsx)(Ei,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:Wy(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:te,children:(0,X.jsx)(Si,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,X.jsx)(`button`,{className:Wy(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.deleteSelected,"aria-label":$.deleteSelected,disabled:m.count===0,onClick:j,children:(0,X.jsx)(qt,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),$.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,X.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:b?$.collapsePanel:$.expandPanel,"aria-label":b?$.collapsePanel:$.expandPanel,onClick:()=>x(e=>!e),children:(0,X.jsx)(at,{className:Wy(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,X.jsx)(`div`,{role:`region`,"aria-label":$.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,X.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:N,onDrop:e=>P(e,t),children:[(0,X.jsxs)(`div`,{className:`absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br`,children:[D(e.type),e.repeat&&` ↻`]}),!c&&(0,X.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,X.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:$.addText,"aria-label":$.addText,children:(0,X.jsx)(Rr,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,X.jsx)(fn,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,X.jsx)(ke,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:$.addChart,"aria-label":$.addChart,children:(0,X.jsx)(Pe,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:$.addTable,"aria-label":$.addTable,children:(0,X.jsx)(vn,{className:`h-3 w-3`})})]}),(0,X.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground text-center pt-4`,children:$.addElementsPrompt}),e.elements.map(e=>{let n=m.isSelected(e.id);return(0,X.jsxs)(`div`,{draggable:!c,onDragStart:n=>ne(n,e,t),className:Wy(`absolute border rounded px-2 py-1 text-xs cursor-pointer`,n?`border-primary ring-1 ring-primary/30 bg-primary/5`:`border-dashed border-gray-400 hover:border-primary/50`),style:{left:e.position.x,top:(typeof e.position.y==`number`?e.position.y:0)+24,width:e.position.width,height:e.position.height},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.type===`text`&&(e.properties.text??$.elementText),e.type===`field`&&`{${e.properties.field??`field`}}`,e.type===`image`&&$.elementImage,e.type===`chart`&&$.elementChart,e.type===`table`&&$.elementTable]}),!c&&n&&(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),A(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":$.deleteElement,children:(0,X.jsx)(qt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,X.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:Wy(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,X.jsx)(Ty,{title:`${$.properties} – ${O.type}`,fields:F,onChange:M}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:$.properties}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:$.selectElementPrompt})})]}))}),(0,X.jsx)(Cy,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var Jy={"appDesigner.basicInfo":`Basic Info`,"appDesigner.objects":`Objects`,"appDesigner.navigation":`Navigation`,"appDesigner.branding":`Branding`,"appDesigner.stepBasicDesc":`Name, title, and layout`,"appDesigner.stepObjectsDesc":`Select business objects`,"appDesigner.stepNavigationDesc":`Build navigation tree`,"appDesigner.stepBrandingDesc":`Logo, colors, and favicon`,"appDesigner.appName":`App Name`,"appDesigner.appTitle":`Title`,"appDesigner.appDescription":`Description`,"appDesigner.appIcon":`Icon`,"appDesigner.template":`Template`,"appDesigner.layout":`Layout`,"appDesigner.layoutSidebar":`Sidebar`,"appDesigner.layoutHeader":`Header`,"appDesigner.layoutEmpty":`Empty`,"appDesigner.snakeCaseHint":`Must be snake_case (e.g. my_app)`,"appDesigner.searchObjects":`Search objects…`,"appDesigner.selectAll":`Select All`,"appDesigner.deselectAll":`Deselect All`,"appDesigner.noObjectsFound":`No objects found.`,"appDesigner.addGroup":`Add Group`,"appDesigner.addUrl":`Add URL`,"appDesigner.addSeparator":`Add Separator`,"appDesigner.noNavItemsHint":`No navigation items yet. Select objects in the previous step or add items manually.`,"appDesigner.separatorLabel":`— Separator —`,"appDesigner.newGroup":`New Group`,"appDesigner.newLink":`New Link`,"appDesigner.logoUrl":`Logo URL`,"appDesigner.primaryColor":`Primary Color`,"appDesigner.faviconUrl":`Favicon URL`,"appDesigner.preview":`Preview`,"common.cancel":`Cancel`,"common.back":`Back`,"common.next":`Next`,"common.close":`Close`,"appDesigner.complete":`Complete`,"appDesigner.saveDraft":`Save Draft`,"appDesigner.cancelConfirmTitle":`Discard changes?`,"appDesigner.cancelConfirmMessage":`You have unsaved changes. Are you sure you want to cancel?`,"appDesigner.confirmDiscard":`Discard`,"appDesigner.keepEditing":`Keep Editing`,"appDesigner.navNoItems":`No navigation items. Click buttons above to add items.`,"appDesigner.navNoPreviewItems":`No items`,"appDesigner.navLivePreview":`Live Preview`,"appDesigner.navCollapseGroup":`Collapse group`,"appDesigner.navExpandGroup":`Expand group`,"appDesigner.navAddChild":`Add child`,"appDesigner.navMoveUp":`Move up`,"appDesigner.navMoveDown":`Move down`,"appDesigner.navRemove":`Remove`,"appDesigner.navObjectPage":`Object Page`,"appDesigner.navDashboard":`Dashboard`,"appDesigner.navPage":`Page`,"appDesigner.navReport":`Report`,"appDesigner.navGroup":`Group`,"appDesigner.navUrl":`URL`,"appDesigner.navSeparator":`Separator`,"appDesigner.navTypeObject":`Object`,"appDesigner.navTypeDashboard":`Dashboard`,"appDesigner.navTypePage":`Page`,"appDesigner.navTypeReport":`Report`,"appDesigner.navTypeUrl":`URL`,"appDesigner.navTypeGroup":`Group`,"appDesigner.navTypeSeparator":`Separator`,"appDesigner.navTypeAction":`Action`,"appDesigner.navEditIcon":`Edit icon`,"appDesigner.navToggleVisible":`Toggle visibility`,"appDesigner.navHidden":`Hidden`,"appDesigner.navExportSchema":`Export JSON`,"appDesigner.navImportSchema":`Import JSON`,"appDesigner.navExportSuccess":`Navigation schema exported`,"appDesigner.navImportSuccess":`Navigation schema imported`,"appDesigner.navImportError":`Invalid navigation JSON`,"appDesigner.navIconPlaceholder":`Icon name (e.g. Users)`,"appDesigner.dashboardEditor":`Dashboard Editor`,"appDesigner.noWidgets":`No widgets. Click a button above to add one.`,"appDesigner.widgetLayoutSize":`Layout Size`,"appDesigner.widgetWidth":`Width`,"appDesigner.widgetHeight":`Height`,"appDesigner.dashboardPreview":`Dashboard Preview`,"appDesigner.noWidgetsPreview":`No widgets to preview`,"appDesigner.pageCanvasEditor":`Page Canvas Editor`,"appDesigner.emptyPage":`Empty page. Click a button above to add a component.`,"appDesigner.pagePreview":`Page Preview`,"appDesigner.noComponentsPreview":`No components to preview`,"appDesigner.modePage":`Page`,"appDesigner.modeDashboard":`Dashboard`,"appDesigner.undo":`Undo`,"appDesigner.redo":`Redo`,"appDesigner.brandingEditor":`Branding Editor`,"appDesigner.brandingExport":`Export JSON`,"appDesigner.brandingImport":`Import JSON`,"appDesigner.brandingPreview":`Preview`,"appDesigner.brandingSampleButton":`Sample Button`,"appDesigner.brandingSampleText":`This is how your brand theme will look.`,"appDesigner.colorPalette":`Color Palette`,"appDesigner.fontFamily":`Font Family`,"appDesigner.fontDefault":`Default (System)`,"appDesigner.modeLight":`Light`,"appDesigner.modeDark":`Dark`,"appDesigner.mobilePreview":`Mobile Preview`,"appDesigner.objectManager.title":`Object Manager`,"appDesigner.objectManager.addObject":`New Object`,"appDesigner.objectManager.searchPlaceholder":`Search objects…`,"appDesigner.objectManager.noObjects":`No objects found.`,"appDesigner.objectManager.objectName":`API Name`,"appDesigner.objectManager.objectLabel":`Label`,"appDesigner.objectManager.pluralLabel":`Plural Label`,"appDesigner.objectManager.icon":`Icon`,"appDesigner.objectManager.selectIcon":`Select icon…`,"appDesigner.objectManager.group":`Group`,"appDesigner.objectManager.noGroup":`No Group`,"appDesigner.objectManager.sortOrder":`Sort Order`,"appDesigner.objectManager.enabled":`Enabled`,"appDesigner.objectManager.relationships":`Relationships`,"appDesigner.objectManager.systemBadge":`System`,"appDesigner.objectManager.fieldCount":`{{count}} fields`,"appDesigner.objectManager.ungrouped":`Ungrouped`,"appDesigner.objectManager.deleteConfirmTitle":`Delete Object?`,"appDesigner.objectManager.deleteConfirmMessage":`This will permanently delete the object and all its fields. This action cannot be undone.`,"appDesigner.fieldDesigner.title":`Field Designer`,"appDesigner.fieldDesigner.addField":`New Field`,"appDesigner.fieldDesigner.searchPlaceholder":`Search fields…`,"appDesigner.fieldDesigner.allTypes":`All Types`,"appDesigner.fieldDesigner.noFields":`No fields found.`,"appDesigner.fieldDesigner.fieldName":`API Name`,"appDesigner.fieldDesigner.fieldLabel":`Label`,"appDesigner.fieldDesigner.fieldType":`Type`,"appDesigner.fieldDesigner.fieldGroup":`Group`,"appDesigner.fieldDesigner.description":`Description`,"appDesigner.fieldDesigner.required":`Required`,"appDesigner.fieldDesigner.unique":`Unique`,"appDesigner.fieldDesigner.readOnly":`Read Only`,"appDesigner.fieldDesigner.hidden":`Hidden`,"appDesigner.fieldDesigner.indexed":`Indexed`,"appDesigner.fieldDesigner.externalId":`External ID`,"appDesigner.fieldDesigner.trackHistory":`Track History`,"appDesigner.fieldDesigner.defaultValue":`Default Value`,"appDesigner.fieldDesigner.placeholder":`Placeholder`,"appDesigner.fieldDesigner.referenceTo":`Reference To`,"appDesigner.fieldDesigner.formula":`Formula`,"appDesigner.fieldDesigner.options":`Options`,"appDesigner.fieldDesigner.addOption":`Add Option`,"appDesigner.fieldDesigner.validationRules":`Validation Rules`,"appDesigner.fieldDesigner.addRule":`Add Rule`,"appDesigner.fieldDesigner.systemBadge":`System`,"appDesigner.fieldDesigner.ungrouped":`General`,"appDesigner.fieldDesigner.deleteConfirmTitle":`Delete Field?`,"appDesigner.fieldDesigner.deleteConfirmMessage":`This will permanently delete the field. Existing data in this field will be lost.`,"appDesigner.fieldDesigner.basicSection":`Basic`,"appDesigner.fieldDesigner.typeSpecificSection":`Type Settings`,"appDesigner.fieldDesigner.advancedSection":`Advanced`,"appDesigner.fieldDesigner.typeCategory.text":`Text`,"appDesigner.fieldDesigner.typeCategory.number":`Number`,"appDesigner.fieldDesigner.typeCategory.date":`Date & Time`,"appDesigner.fieldDesigner.typeCategory.choice":`Choice`,"appDesigner.fieldDesigner.typeCategory.relation":`Relation`,"appDesigner.fieldDesigner.typeCategory.advanced":`Advanced`,"common.edit":`Edit`};function Yy(e){return(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}function Xy(){try{let e=R();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:Yy(Jy)}:{t:e.t}}catch{return{t:Yy(Jy)}}}function Zy(...e){return la(ca(e))}var Qy={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function $y(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var eb=0;function tb(e){return eb+=1,`${e}_${Date.now()}_${eb}`}function nb({steps:e,currentIndex:t,onStepClick:n}){return(0,X.jsx)(`nav`,{className:`flex items-center justify-center gap-0 px-4 py-6`,children:e.map((e,r)=>{let i=r<t,a=r===t;return(0,X.jsxs)(Y.Fragment,{children:[r>0&&(0,X.jsx)(`div`,{className:Zy(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,X.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:Zy(`flex flex-col items-center gap-1 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg px-2 py-1`,a&&`cursor-default`,!a&&`cursor-pointer`),children:[(0,X.jsx)(`div`,{className:Zy(`flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-colors`,i&&`bg-blue-500 text-white`,a&&`bg-blue-600 text-white ring-2 ring-blue-300`,!i&&!a&&`bg-gray-200 text-gray-500`),children:i?(0,X.jsx)(Ae,{className:`h-4 w-4`}):r+1}),(0,X.jsx)(`span`,{className:Zy(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function rb({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!fe(e.name);return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,X.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,X.jsx)(`input`,{id:`app-name`,"data-testid":`app-name-input`,type:`text`,value:e.name,onChange:e=>r({name:e.target.value}),placeholder:`my_app`,disabled:n,className:Zy(`block w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none transition-colors`,`focus:border-blue-500 focus:ring-1 focus:ring-blue-500`,`disabled:cursor-not-allowed disabled:bg-gray-50`,a?`border-red-400`:`border-gray-300`)}),a&&(0,X.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,X.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,X.jsx)(`input`,{id:`app-title`,"data-testid":`app-title-input`,type:`text`,value:e.title,onChange:e=>r({title:e.target.value}),placeholder:`My Application`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,X.jsx)(`textarea`,{id:`app-description`,"data-testid":`app-description-input`,value:e.description??``,onChange:e=>r({description:e.target.value}),rows:3,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 resize-none`})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,X.jsx)(`input`,{id:`app-icon`,type:`text`,value:e.icon??``,onChange:e=>r({icon:e.target.value}),placeholder:`LayoutDashboard`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),t.length>0&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,X.jsxs)(`select`,{id:`app-template`,value:e.template??``,onChange:e=>r({template:e.target.value}),disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`,children:[(0,X.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,X.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,X.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:bt},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:Mt},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:ki}].map(({value:t,labelKey:a,Icon:o})=>(0,X.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:Zy(`flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-lg border-2 p-3 transition-colors`,e.layout===t?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,n&&`pointer-events-none opacity-60`),children:[(0,X.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,X.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function ib({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,Y.useMemo)(()=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t))},[e,i]),c=e.length>0&&e.every(e=>e.selected);return e.every(e=>!e.selected),(0,X.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(Ai,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{"data-testid":`object-search`,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:o(`appDesigner.searchObjects`),className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500`})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>r(!c),disabled:t,className:`rounded-md border border-gray-300 px-3 py-2 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:o(c?`appDesigner.deselectAll`:`appDesigner.selectAll`)})]}),s.length===0?(0,X.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:Zy(`flex flex-col items-start gap-1 rounded-lg border-2 p-3 text-left transition-colors`,e.selected?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,t&&`pointer-events-none opacity-60`),children:[(0,X.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,X.jsx)(`div`,{className:Zy(`flex h-5 w-5 items-center justify-center rounded border transition-colors`,e.selected?`border-blue-500 bg-blue-500 text-white`:`border-gray-300`),children:e.selected&&(0,X.jsx)(Ae,{className:`h-3 w-3`})})]}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,X.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var ab={object:`bg-green-100 text-green-700`,group:`bg-purple-100 text-purple-700`,url:`bg-sky-100 text-sky-700`,separator:`bg-gray-100 text-gray-600`,dashboard:`bg-amber-100 text-amber-700`,page:`bg-teal-100 text-teal-700`,report:`bg-rose-100 text-rose-700`,action:`bg-orange-100 text-orange-700`};function ob({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`add-group-btn`,onClick:()=>n(`group`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(it,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,X.jsxs)(`button`,{type:`button`,"data-testid":`add-url-btn`,onClick:()=>n(`url`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(ir,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,X.jsxs)(`button`,{type:`button`,"data-testid":`add-separator-btn`,onClick:()=>n(`separator`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(fi,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,X.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,X.jsxs)(`li`,{"data-testid":`nav-item-${n.id}`,className:`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2`,children:[n.icon&&(0,X.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,X.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):P(n.label)}),(0,X.jsx)(`span`,{className:Zy(`rounded-full px-2 py-0.5 text-[10px] font-medium`,ab[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`up`),disabled:t||o===0,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,X.jsx)(Qi,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`down`),disabled:t||o===e.length-1,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,X.jsx)(sn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>r(n.id),disabled:t,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-red-500 disabled:opacity-30`,"aria-label":`Remove`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function sb({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ke,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`branding-logo`,"data-testid":`branding-logo-input`,type:`text`,value:e.logo??``,onChange:e=>r({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ra,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`branding-color`,"data-testid":`branding-color-input`,type:`text`,value:e.primaryColor??`#3b82f6`,onChange:e=>r({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`branding-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:e.favicon??``,onChange:e=>r({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,X.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,X.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,X.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function cb({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=Xy(),l=vy(),[u,d]=(0,Y.useState)(0),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(()=>({...Qy,objects:e.map(e=>({...e})),...n})),g=(0,Y.useMemo)(()=>[{id:`basic`,label:c(`appDesigner.basicInfo`),description:c(`appDesigner.stepBasicDesc`),icon:`Settings`},{id:`objects`,label:c(`appDesigner.objects`),description:c(`appDesigner.stepObjectsDesc`),icon:`Database`},{id:`navigation`,label:c(`appDesigner.navigation`),description:c(`appDesigner.stepNavigationDesc`),icon:`Menu`},{id:`branding`,label:c(`appDesigner.branding`),description:c(`appDesigner.stepBrandingDesc`),icon:`Palette`}],[c]),_=u===0,v=u===g.length-1,y=(0,Y.useMemo)(()=>m.name.length>0&&fe(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,Y.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,Y.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,Y.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,Y.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,Y.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,Y.useCallback)(e=>{let t={id:tb(e),type:e,label:e===`separator`?``:e===`group`?`New Group`:`New Link`,...e===`group`?{children:[]}:{},...e===`url`?{url:``}:{}};h(e=>({...e,navigation:[...e.navigation,t]}))},[]),E=(0,Y.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,Y.useCallback)((e,t)=>{h(n=>{let r=[...n.navigation],i=r.findIndex(t=>t.id===e);if(i<0)return n;let a=t===`up`?i-1:i+1;return a<0||a>=r.length?n:([r[i],r[a]]=[r[a],r[i]],{...n,navigation:r})})},[]),O=(0,Y.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:$y(e.objects)})),d(e=>e+1))},[u,v]),k=(0,Y.useCallback)(()=>{_||d(e=>e-1)},[_]),A=(0,Y.useCallback)(()=>{r?.(m)},[m,r]),j=(0,Y.useCallback)(async()=>{(m.name.length>0||m.title.length>0)&&i?await l.confirm(c(`appDesigner.cancelConfirmTitle`),c(`appDesigner.cancelConfirmMessage`))&&i():i?.()},[m.name,m.title,i,l,c]),M=(0,Y.useCallback)(()=>{a?.(m)},[m,a]),ee=(0,Y.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:$y(e.objects)})),d(e))},[u,b]);return(0,X.jsxs)(`div`,{className:Zy(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,X.jsx)(`div`,{"data-testid":`cancel-confirm-dialog`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,role:`dialog`,"aria-modal":`true`,children:(0,X.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,X.jsx)(`button`,{type:`button`,onClick:l.onCancel,className:`rounded p-1 text-gray-400 hover:text-gray-600`,"aria-label":c(`common.close`),children:(0,X.jsx)(Yi,{className:`h-4 w-4`})})]}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-keep`,onClick:l.onCancel,className:`rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50`,children:c(`appDesigner.keepEditing`)}),(0,X.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-discard`,onClick:l.onConfirm,className:`rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:c(`appDesigner.confirmDiscard`)})]})]})}),(0,X.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,X.jsx)(nb,{steps:g,currentIndex:u,onStepClick:ee})}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,X.jsx)(rb,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,X.jsx)(ib,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,X.jsx)(ob,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,X.jsx)(sb,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`wizard-cancel`,onClick:j,disabled:o,className:`rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`common.cancel`)}),a&&(0,X.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:M,disabled:o,className:`rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`appDesigner.saveDraft`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,X.jsxs)(`button`,{type:`button`,"data-testid":`wizard-back`,onClick:k,disabled:o,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(Ji,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,X.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:A,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(Ae,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,X.jsxs)(`button`,{type:`button`,"data-testid":`wizard-next`,onClick:O,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[c(`common.next`),(0,X.jsx)(tr,{className:`h-4 w-4`})]})]})]})]})}function lb(...e){return la(ca(e))}var ub=0;function db(e){return ub+=1,`${e}_${Date.now()}_${ub}`}var fb={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Xt},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:ci},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:na},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:Pe},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:ir},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:it},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:fi},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:gn}},pb=[{type:`object`,labelKey:`appDesigner.navObjectPage`},{type:`dashboard`,labelKey:`appDesigner.navDashboard`},{type:`page`,labelKey:`appDesigner.navPage`},{type:`report`,labelKey:`appDesigner.navReport`},{type:`group`,labelKey:`appDesigner.navGroup`},{type:`url`,labelKey:`appDesigner.navUrl`},{type:`separator`,labelKey:`appDesigner.navSeparator`}];function mb({item:e,depth:t,index:n,total:r,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m}){let[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(P(e.label)??``),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(e.icon||``),C=fb[e.type];e.type===`group`&&e.children&&e.children.length;let w=p.has(e.id),T=e.visible===!1,E=()=>{_.trim()?l(e.id,_.trim()):v(P(e.label)??``),g(!1)},D=()=>{u(e.id,x.trim()),b(!1)};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:lb(`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 transition-colors hover:bg-gray-50`,T&&`opacity-50`),style:{marginLeft:t*20},children:[(0,X.jsx)(Ce,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,X.jsx)(`button`,{type:`button`,onClick:()=>c(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":m(w?`appDesigner.navCollapseGroup`:`appDesigner.navExpandGroup`),children:w?(0,X.jsx)(sn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(tr,{className:`h-3.5 w-3.5`})}):(0,X.jsx)(`span`,{className:`w-5`}),y&&!i?(0,X.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),onBlur:D,onKeyDown:t=>{t.key===`Enter`&&D(),t.key===`Escape`&&(S(e.icon||``),b(!1))},autoFocus:!0,placeholder:m(`appDesigner.navIconPlaceholder`),"data-testid":`nav-designer-icon-input-${e.id}`,className:`w-24 rounded border border-blue-300 px-1 py-0.5 text-xs outline-none focus:ring-1 focus:ring-blue-400`}):(0,X.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>{S(e.icon||``),b(!0)},className:`rounded p-0.5 text-gray-300 hover:text-blue-500`,"aria-label":m(`appDesigner.navEditIcon`),"data-testid":`nav-designer-edit-icon-${e.id}`,children:(0,X.jsx)(Ir,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,X.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,X.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(P(e.label)??``),g(!1))},autoFocus:!0,className:`flex-1 rounded border border-blue-300 px-1.5 py-0.5 text-sm outline-none focus:ring-1 focus:ring-blue-400`}):(0,X.jsx)(`span`,{className:lb(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(P(e.label)??``),g(!0))},children:P(e.label)}),(0,X.jsx)(`span`,{className:lb(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,X.jsx)(`span`,{className:`rounded-full bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-500`,"data-testid":`nav-designer-hidden-badge-${e.id}`,children:m(`appDesigner.navHidden`)}),!i&&e.type!==`separator`&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>d(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-700`,"aria-label":m(`appDesigner.navToggleVisible`),"data-testid":`nav-designer-toggle-visible-${e.id}`,children:T?(0,X.jsx)(qe,{className:`h-3.5 w-3.5`}):(0,X.jsx)(En,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":m(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,X.jsx)(fn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:i||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveUp`),children:(0,X.jsx)(Qi,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),disabled:i||n===r-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveDown`),children:(0,X.jsx)(sn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),disabled:i,className:`rounded p-0.5 text-gray-400 hover:text-red-500 disabled:opacity-30`,"aria-label":m(`appDesigner.navRemove`),"data-testid":`nav-designer-remove-${e.id}`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,X.jsx)(X.Fragment,{children:e.children.map((n,r)=>(0,X.jsx)(mb,{item:n,depth:t+1,index:r,total:e.children.length,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m},n.id))})]})}function hb({items:e,t}){return(0,X.jsxs)(`div`,{"data-testid":`nav-designer-preview`,className:`w-56 shrink-0 rounded-lg border border-gray-200 bg-gray-50 p-3`,children:[(0,X.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,X.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,X.jsx)(gb,{item:e,depth:0},e.id))})]})}function gb({item:e,depth:t}){let n=fb[e.type];return e.type===`separator`?(0,X.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-700 hover:bg-gray-100`,style:{marginLeft:t*12},children:[(0,X.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,X.jsx)(`span`,{className:`truncate`,children:P(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,X.jsx)(gb,{item:e,depth:t+1},e.id))]})}function _b({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=Xy(),c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,Y.useCallback)(n=>{function r(e){return e.filter(e=>e.id!==n).map(e=>e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),f=(0,Y.useCallback)((n,r)=>{function i(e){let t=e.findIndex(e=>e.id===n);if(t>=0){let n=r===`up`?t-1:t+1;if(n>=0&&n<e.length){let r=[...e];return[r[t],r[n]]=[r[n],r[t]],r}return e}return e.map(e=>e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),p=(0,Y.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,label:r}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),m=(0,Y.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,icon:r||void 0}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),h=(0,Y.useCallback)(n=>{function r(e){return e.map(e=>e.id===n?{...e,visible:e.visible===!1}:e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),g=(0,Y.useCallback)((n,r)=>{let i={id:db(r),type:r,label:r===`separator`?``:`New ${s(fb[r].labelKey)}`,...r===`group`?{children:[]}:{},...r===`url`?{url:``}:{}};function a(e){return e.map(e=>e.id===n&&e.type===`group`?{...e,children:[...e.children||[],i]}:e.children?{...e,children:a(e.children)}:e)}t(a(e)),u(e=>new Set(e).add(n))},[e,t]),_=(0,Y.useCallback)(n=>{let r={id:db(n),type:n,label:n===`separator`?``:`New ${s(fb[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,Y.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,Y.useCallback)(()=>{if(a)a(e);else{let t=JSON.stringify(e,null,2),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`navigation-schema.json`,i.click(),URL.revokeObjectURL(r)}},[e,a]),b=(0,Y.useCallback)(e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);Array.isArray(n)&&(o?o(n):t(n))}catch{}},r.readAsText(n),c.current&&(c.current.value=``)},[t,o]);return(0,X.jsxs)(`div`,{"data-testid":`navigation-designer`,className:lb(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,X.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[pb.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=fb[e];return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:lb(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,X.jsx)(fn,{className:`h-3 w-3`}),s(t)]},e)}),(0,X.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,X.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:y,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,X.jsx)(jn,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,X.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:lb(`inline-flex cursor-pointer items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,n&&`cursor-not-allowed opacity-50`),children:[(0,X.jsx)(Br,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,X.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,X.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,X.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,X.jsx)(mb,{item:t,depth:0,index:r,total:e.length,readOnly:n,onRemove:d,onMoveUp:e=>f(e,`up`),onMoveDown:e=>f(e,`down`),onToggleExpand:v,onUpdateLabel:p,onUpdateIcon:m,onToggleVisible:h,onAddChild:g,expandedIds:l,t:s},t.id))})]}),r&&(0,X.jsx)(hb,{items:e,t:s})]})}function vb(...e){return la(ca(e))}var yb=[{type:`metric`,label:`KPI Metric`,Icon:Ft},{type:`bar`,label:`Bar Chart`,Icon:Pe},{type:`line`,label:`Line Chart`,Icon:Re},{type:`pie`,label:`Pie Chart`,Icon:pn},{type:`table`,label:`Table`,Icon:vn},{type:`grid`,label:`Grid`,Icon:vr}],bb=0;function xb(){return bb+=1,`widget_${Date.now()}_${bb}`}function Sb({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=yb.find(e=>e.type===l)||yb[0];return(0,X.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:vb(`group cursor-pointer rounded-lg border-2 p-3 transition-colors`,r?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`),children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ce,{className:`h-4 w-4 text-gray-300`}),(0,X.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:t===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,X.jsx)(Qi,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:t===n-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,X.jsx)(sn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`rounded p-0.5 text-gray-400 hover:text-red-500`,"aria-label":`Remove widget`,"data-testid":`dashboard-widget-remove-${e.id}`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:u.label}),e.object&&(0,X.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function Cb({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=Xy();return(0,X.jsxs)(`div`,{"data-testid":`widget-property-panel`,className:`shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,X.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,X.jsx)(Yi,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,X.jsx)(`input`,{id:`widget-title`,"data-testid":`widget-prop-title`,type:`text`,value:e.title??``,onChange:e=>n({title:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,X.jsx)(`select`,{id:`widget-type`,"data-testid":`widget-prop-type`,value:e.type??`metric`,onChange:e=>n({type:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:yb.map(e=>(0,X.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,X.jsx)(`input`,{id:`widget-object`,"data-testid":`widget-prop-object`,type:`text`,value:e.object??``,onChange:e=>n({object:e.target.value}),disabled:t,placeholder:`e.g. orders`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,X.jsx)(`input`,{id:`widget-value-field`,"data-testid":`widget-prop-value-field`,type:`text`,value:e.valueField??``,onChange:e=>n({valueField:e.target.value}),disabled:t,placeholder:`e.g. amount`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,X.jsxs)(`select`,{id:`widget-aggregate`,"data-testid":`widget-prop-aggregate`,value:e.aggregate??`count`,onChange:e=>n({aggregate:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,X.jsx)(`option`,{value:`count`,children:`Count`}),(0,X.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,X.jsx)(`option`,{value:`avg`,children:`Average`}),(0,X.jsx)(`option`,{value:`min`,children:`Min`}),(0,X.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,X.jsxs)(`select`,{id:`widget-color`,"data-testid":`widget-prop-color`,value:e.colorVariant??`default`,onChange:e=>n({colorVariant:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,X.jsx)(`option`,{value:`default`,children:`Default`}),(0,X.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,X.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,X.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,X.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,X.jsx)(`option`,{value:`success`,children:`Success`}),(0,X.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,X.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,X.jsx)(`input`,{id:`widget-width`,"data-testid":`widget-prop-width`,type:`number`,min:1,value:e.layout?.w??1,onChange:t=>n({layout:{...e.layout,w:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,X.jsxs)(`div`,{className:`flex-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,X.jsx)(`input`,{id:`widget-height`,"data-testid":`widget-prop-height`,type:`number`,min:1,value:e.layout?.h??1,onChange:t=>n({layout:{...e.layout,h:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]})]})]})]})}function wb({schema:e}){let{t}=Xy(),n=e.widgets||[];return(0,X.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,X.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,X.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=yb.find(t=>t.type===(e.type||`metric`))||yb[0];return(0,X.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,X.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function Tb({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=Xy(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null),m=(0,Y.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,Y.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=_y(e),w=(0,Y.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,Y.useCallback)(e=>{let t=xb(),n={id:t,title:``,type:e,layout:{x:0,y:T.length,w:v.columns??2,h:1}};w({...v,widgets:[...T,n]}),_(t)},[v,T,w,_]),O=(0,Y.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,Y.useCallback)((e,t)=>{let n=T.findIndex(t=>t.id===e);if(n<0)return;let r=t===`up`?n-1:n+1;if(r<0||r>=T.length)return;let i=[...T];[i[n],i[r]]=[i[r],i[n]],w({...v,widgets:i})},[v,T,w]),A=(0,Y.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,Y.useEffect)(()=>{let e=p.current;if(!e)return;let t=e=>{if(!n){if((e.ctrlKey||e.metaKey)&&e.key===`z`&&!e.shiftKey){e.preventDefault(),S();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),C();return}if((e.key===`Delete`||e.key===`Backspace`)&&g){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`SELECT`||t.tagName===`TEXTAREA`)return;e.preventDefault(),O(g)}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[n,S,C,g,O]);let j=(0,Y.useCallback)(()=>{i&&i(v)},[v,i]),M=(0,Y.useCallback)(()=>{m.current?.click()},[]),ee=(0,Y.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=()=>{try{let e=JSON.parse(n.result);e&&e.type===`dashboard`&&(w(e),a?.(e))}catch{}},n.readAsText(t),e.target.value=``},[w,a]);return(0,X.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:vb(`flex flex-col gap-4 outline-none`,r),children:[(0,X.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:ee}),E&&!d&&(0,X.jsx)(Cb,{widget:E,readOnly:n,onChange:A,onClose:()=>_(null)}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),yb.map(({type:e,label:t,Icon:r})=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>D(e),disabled:n||d,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,X.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-undo`,onClick:S,disabled:!y,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.undo`),children:(0,X.jsx)(Ee,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-redo`,onClick:C,disabled:!b,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.redo`),children:(0,X.jsx)(qi,{className:`h-4 w-4`})})]}),(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:j,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,X.jsx)(jn,{className:`h-4 w-4`})}),!n&&(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:M,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,X.jsx)(Br,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:vb(`rounded p-1.5 transition-colors`,d?`bg-blue-100 text-blue-600`:`text-gray-400 hover:text-gray-700`),"aria-label":c(d?`appDesigner.modeEdit`:`appDesigner.preview`),children:d?(0,X.jsx)(qe,{className:`h-4 w-4`}):(0,X.jsx)(En,{className:`h-4 w-4`})})]})]}),d?(0,X.jsx)(wb,{schema:v}):T.length===0?(0,X.jsx)(`div`,{className:`flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400`,children:c(`appDesigner.noWidgets`)}):(0,X.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,X.jsx)(Sb,{widget:e,index:t,total:T.length,selected:e.id===g,readOnly:n,onSelect:()=>_(e.id??null),onRemove:()=>O(e.id),onMoveUp:()=>k(e.id,`up`),onMoveDown:()=>k(e.id,`down`)},e.id))})]})]})}function Eb(...e){return la(ca(e))}var Db=[{hex:`#3b82f6`,name:`Blue`},{hex:`#6366f1`,name:`Indigo`},{hex:`#8b5cf6`,name:`Violet`},{hex:`#a855f7`,name:`Purple`},{hex:`#ec4899`,name:`Pink`},{hex:`#ef4444`,name:`Red`},{hex:`#f97316`,name:`Orange`},{hex:`#f59e0b`,name:`Amber`},{hex:`#eab308`,name:`Yellow`},{hex:`#22c55e`,name:`Green`},{hex:`#14b8a6`,name:`Teal`},{hex:`#06b6d4`,name:`Cyan`},{hex:`#0ea5e9`,name:`Sky`},{hex:`#64748b`,name:`Slate`},{hex:`#1e293b`,name:`Dark`},{hex:`#0f172a`,name:`Navy`}],Ob=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function kb({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=Xy(),[c,l]=(0,Y.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=_y(e),g=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,Y.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,Y.useCallback)(()=>{if(a){a(u);return}let e=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`branding.json`,n.click(),URL.revokeObjectURL(t)},[u,a]),y=(0,Y.useCallback)(()=>{if(o){o(u);return}let e=document.createElement(`input`);e.type=`file`,e.accept=`.json`,e.onchange=e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);if(typeof n==`object`&&n){let e={...u,...n};d(e),t(e)}}catch{}},r.readAsText(n)},e.click()},[u,d,t,o]),b=(0,Y.useCallback)(e=>{r||((e.ctrlKey||e.metaKey)&&e.key===`z`&&(e.preventDefault(),e.shiftKey?h():m()),(e.ctrlKey||e.metaKey)&&e.key===`y`&&(e.preventDefault(),h()))},[r,m,h]),x=u.primaryColor||`#3b82f6`,S=c===`dark`;return(0,X.jsxs)(`div`,{"data-testid":`branding-editor`,className:Eb(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,X.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,X.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:Eb(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,f&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.undo`),children:[(0,X.jsx)(Ee,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:Eb(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,p&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.redo`),children:[(0,X.jsx)(qi,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-export`,type:`button`,onClick:v,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm transition-colors hover:bg-gray-50`,title:s(`appDesigner.brandingExport`),children:[(0,X.jsx)(jn,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:Eb(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,r?`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`:`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`),title:s(`appDesigner.brandingImport`),children:[(0,X.jsx)(Br,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ke,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`be-logo`,"data-testid":`branding-logo-input`,type:`text`,value:u.logo??``,onChange:e=>_({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(ra,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`be-color`,"data-testid":`branding-color-input`,type:`text`,value:u.primaryColor??`#3b82f6`,onChange:e=>_({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,X.jsx)(`input`,{"data-testid":`branding-color-picker`,type:`color`,value:x,onChange:e=>_({primaryColor:e.target.value}),disabled:r,className:`h-9 w-9 cursor-pointer rounded-md border border-gray-300 p-0.5 disabled:cursor-not-allowed`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,X.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:Db.map(e=>(0,X.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:Eb(`h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 disabled:cursor-not-allowed`,x===e.hex?`border-gray-800 ring-2 ring-offset-1 ring-gray-400`:`border-transparent`),style:{backgroundColor:e.hex},title:e.name},e.hex))})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{id:`be-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:u.favicon??``,onChange:e=>_({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Rr,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.jsxs)(`select`,{id:`be-font`,"data-testid":`branding-font-select`,value:u.fontFamily??``,onChange:e=>_({fontFamily:e.target.value||void 0}),disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 appearance-none`,children:[(0,X.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),Ob.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,X.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,X.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:Eb(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`light`?`bg-blue-50 text-blue-700`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,X.jsx)(kn,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:Eb(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`dark`?`bg-gray-800 text-gray-100`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,X.jsx)(Je,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,X.jsxs)(`div`,{"data-testid":`branding-preview`,className:Eb(`rounded-lg border p-4 transition-colors`,S?`border-gray-700 bg-gray-900 text-gray-100`:`border-gray-200 bg-white text-gray-800`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,X.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,X.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,X.jsx)(`span`,{className:Eb(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,X.jsx)(`button`,{type:`button`,className:`rounded-md px-3 py-1.5 text-xs font-medium text-white transition-colors`,style:{backgroundColor:x},tabIndex:-1,children:s(`appDesigner.brandingSampleButton`)}),(0,X.jsx)(`p`,{className:Eb(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,X.jsx)(`span`,{className:Eb(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,X.jsxs)(`div`,{className:Eb(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,X.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:Eb(`mx-auto w-48 rounded-xl border-2 p-2 transition-colors`,S?`border-gray-700 bg-gray-900`:`border-gray-300 bg-white`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,X.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,X.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,X.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,X.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,X.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,X.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,X.jsx)(`div`,{className:Eb(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,X.jsx)(`div`,{className:Eb(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,X.jsx)(`div`,{className:Eb(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function Ab(...e){return la(ca(e))}var jb=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],Mb=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function Nb({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=Xy(),s=vy(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),f=(0,Y.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,Y.useMemo)(()=>new I({items:f}),[f]),m=(0,Y.useMemo)(()=>[{field:`name`,label:o(`appDesigner.objectManager.objectName`),width:160},{field:`label`,label:o(`appDesigner.objectManager.objectLabel`),width:160},{field:`group`,label:o(`appDesigner.objectManager.group`),width:130},{field:`fieldCount`,label:`Fields`,width:80},{field:`enabled`,label:o(`appDesigner.objectManager.enabled`),width:80}],[o]),h=(0,Y.useMemo)(()=>({type:`object-grid`,objectName:`object_definition`,columns:m,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:i?void 0:{create:!0,update:!0,delete:!0}}),[m,i]),g=(0,Y.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,Y.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,Y.useCallback)(async n=>{let r=e.find(e=>e.name===n.name);!r||r.isSystem||await s.confirm(o(`appDesigner.objectManager.deleteConfirmTitle`),o(`appDesigner.objectManager.deleteConfirmMessage`))&&t?.(e.filter(e=>e.id!==r.id))},[e,t,s,o]),y=(0,Y.useCallback)(()=>{d(null),l(!0)},[]),b=(0,Y.useCallback)(n=>{if(u){let r={...u,name:String(n.name||u.name),label:String(n.label||u.label),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,enabled:n.enabled!==!1};t?.(e.map(e=>e.id===u.id?r:e))}else{let r={id:`obj_${Date.now()}`,name:String(n.name||`new_object_${e.length+1}`),label:String(n.label||`New Object ${e.length+1}`),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,isSystem:!1,enabled:n.enabled!==!1,fieldCount:0};t?.([...e,r])}l(!1),d(null)},[u,e,t]),x=(0,Y.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,Y.useMemo)(()=>({type:`object-form`,formType:`modal`,objectName:`object_definition`,mode:u?`edit`:`create`,title:u?`${o(`common.edit`)} — ${u.label}`:o(`appDesigner.objectManager.addObject`),open:c,onOpenChange:x,modalSize:`lg`,customFields:[{name:`name`,label:o(`appDesigner.objectManager.objectName`),type:`text`,required:!0,placeholder:`api_name`,disabled:i||(u?.isSystem??!1)},{name:`label`,label:o(`appDesigner.objectManager.objectLabel`),type:`text`,required:!0,placeholder:`Display Name`,disabled:i},{name:`pluralLabel`,label:o(`appDesigner.objectManager.pluralLabel`),type:`text`,placeholder:`Display Names`,disabled:i},{name:`description`,label:o(`appDesigner.appDescription`),type:`textarea`,disabled:i},{name:`icon`,label:o(`appDesigner.objectManager.icon`),type:`select`,options:Mb.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:jb.map(e=>({label:e,value:e})),disabled:i},{name:`sortOrder`,label:o(`appDesigner.objectManager.sortOrder`),type:`number`,disabled:i},{name:`enabled`,label:o(`appDesigner.objectManager.enabled`),type:`boolean`,disabled:i}],initialValues:u?{name:u.name,label:u.label,pluralLabel:u.pluralLabel||``,description:u.description||``,icon:u.icon||``,group:u.group||``,sortOrder:u.sortOrder??0,enabled:u.enabled!==!1}:{enabled:!0},onSuccess:b,onCancel:()=>x(!1),readOnly:i}),[u,c,x,b,i,o]);return(0,X.jsxs)(`div`,{"data-testid":`object-manager`,className:Ab(`w-full space-y-3`,a),children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xt,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,X.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,X.jsx)(ya,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,X.jsx)(ba,{schema:S}),(0,X.jsx)(Cy,{isOpen:s.isOpen,title:s.title,message:s.message,confirmLabel:o(`common.delete`),cancelLabel:o(`common.cancel`),onConfirm:s.onConfirm,onCancel:s.onCancel,destructive:!0})]})}function Pb(...e){return la(ca(e))}var Fb={text:{label:`Text`,Icon:Rr},textarea:{label:`Text Area`,Icon:na},number:{label:`Number`,Icon:Me},boolean:{label:`Checkbox`,Icon:Ct},date:{label:`Date`,Icon:zt},datetime:{label:`Date/Time`,Icon:zt},time:{label:`Time`,Icon:zt},select:{label:`Picklist`,Icon:ri},email:{label:`Email`,Icon:Cn},phone:{label:`Phone`,Icon:we},url:{label:`URL`,Icon:Tt},password:{label:`Password`,Icon:gi},currency:{label:`Currency`,Icon:Me},percent:{label:`Percent`,Icon:Me},lookup:{label:`Lookup`,Icon:Hr},formula:{label:`Formula`,Icon:Pr},autonumber:{label:`Auto Number`,Icon:Me},file:{label:`File`,Icon:na},image:{label:`Image`,Icon:ke},markdown:{label:`Markdown`,Icon:na},html:{label:`Rich Text`,Icon:na},color:{label:`Color`,Icon:ra},code:{label:`Code`,Icon:Pr},location:{label:`Location`,Icon:mr},address:{label:`Address`,Icon:mr},rating:{label:`Rating`,Icon:_t},slider:{label:`Slider`,Icon:Ti}},Ib={text:[`text`,`textarea`,`email`,`phone`,`url`,`password`,`markdown`,`html`],number:[`number`,`currency`,`percent`,`autonumber`,`rating`,`slider`],date:[`date`,`datetime`,`time`],choice:[`boolean`,`select`],relation:[`lookup`],advanced:[`formula`,`file`,`image`,`color`,`code`,`location`,`address`]},Lb=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function Rb({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=Xy(),o=vy(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(``),p=(0,Y.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,Y.useMemo)(()=>new I({items:p}),[p]),h=(0,Y.useMemo)(()=>[{field:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),width:140},{field:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),width:160},{field:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),width:100},{field:`required`,label:a(`appDesigner.fieldDesigner.required`),width:80},{field:`unique`,label:a(`appDesigner.fieldDesigner.unique`),width:80},{field:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),width:120}],[a]),g=(0,Y.useMemo)(()=>({type:`object-grid`,objectName:`field_definition`,columns:h,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:r?void 0:{create:!0,update:!0,delete:!0}}),[h,r]),_=(0,Y.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,Y.useCallback)(async e=>{let r=t.find(t=>t.name===e.name);!r||r.isSystem||await o.confirm(a(`appDesigner.fieldDesigner.deleteConfirmTitle`),a(`appDesigner.fieldDesigner.deleteConfirmMessage`))&&n?.(t.filter(e=>e.id!==r.id))},[t,n,o,a]),y=(0,Y.useCallback)(()=>{u(null),c(!0)},[]),b=(0,Y.useCallback)(e=>{if(l){let r={...l,name:String(e.name||l.name),label:String(e.label||l.label),type:e.type||l.type,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0};n?.(t.map(e=>e.id===l.id?r:e))}else{let r={id:`fld_${Date.now()}`,name:String(e.name||`new_field_${t.length+1}`),label:String(e.label||`New Field ${t.length+1}`),type:e.type||`text`,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0,isSystem:!1};n?.([...t,r])}c(!1),u(null)},[l,t,n]),x=(0,Y.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,Y.useMemo)(()=>Lb.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:Ib[e].map(e=>({label:Fb[e].label,value:e}))})),[a]),C=(0,Y.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,Y.useMemo)(()=>({type:`object-form`,formType:`drawer`,objectName:`field_definition`,mode:l?`edit`:`create`,title:l?`${a(`common.edit`)} — ${l.label}`:a(`appDesigner.fieldDesigner.addField`),open:s,onOpenChange:x,drawerSide:`right`,drawerWidth:`480px`,sections:[{name:`basic`,label:a(`appDesigner.fieldDesigner.basicSection`),fields:[{name:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),type:`text`,required:!0,placeholder:`api_name`,disabled:r||(l?.isSystem??!1)},{name:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),type:`text`,required:!0,placeholder:`Display Label`,disabled:r},{name:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),type:`select`,required:!0,options:C,disabled:r||(l?.isSystem??!1)},{name:`required`,label:a(`appDesigner.fieldDesigner.required`),type:`boolean`,disabled:r},{name:`unique`,label:a(`appDesigner.fieldDesigner.unique`),type:`boolean`,disabled:r},{name:`description`,label:a(`appDesigner.fieldDesigner.description`),type:`textarea`,disabled:r}]},{name:`typeSpecific`,label:a(`appDesigner.fieldDesigner.typeSpecificSection`),fields:[{name:`referenceTo`,label:a(`appDesigner.fieldDesigner.referenceTo`),type:`text`,placeholder:`Referenced object`,disabled:r,condition:{field:`type`,equals:`lookup`}},{name:`formula`,label:a(`appDesigner.fieldDesigner.formula`),type:`textarea`,placeholder:`e.g. price * quantity`,disabled:r,condition:{field:`type`,equals:`formula`}},{name:`defaultValue`,label:a(`appDesigner.fieldDesigner.defaultValue`),type:`text`,placeholder:`Default value`,disabled:r},{name:`placeholder`,label:a(`appDesigner.fieldDesigner.placeholder`),type:`text`,placeholder:`Placeholder text`,disabled:r},{name:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),type:`text`,placeholder:`Field Group`,disabled:r}]},{name:`advanced`,label:a(`appDesigner.fieldDesigner.advancedSection`),collapsible:!0,collapsed:!0,fields:[{name:`indexed`,label:a(`appDesigner.fieldDesigner.indexed`),type:`boolean`,disabled:r},{name:`externalId`,label:a(`appDesigner.fieldDesigner.externalId`),type:`boolean`,disabled:r},{name:`trackHistory`,label:a(`appDesigner.fieldDesigner.trackHistory`),type:`boolean`,disabled:r},{name:`readonly`,label:a(`appDesigner.fieldDesigner.readOnly`),type:`boolean`,disabled:r},{name:`hidden`,label:a(`appDesigner.fieldDesigner.hidden`),type:`boolean`,disabled:r}]}],initialValues:l?{name:l.name,label:l.label,type:l.type,group:l.group||``,description:l.description||``,required:l.required||!1,unique:l.unique||!1,readonly:l.readonly||!1,hidden:l.hidden||!1,indexed:l.indexed||!1,externalId:l.externalId||!1,trackHistory:l.trackHistory||!1,defaultValue:l.defaultValue==null?``:String(l.defaultValue),placeholder:l.placeholder||``,referenceTo:l.referenceTo||``,formula:l.formula||``}:{type:`text`,required:!1,unique:!1},onSuccess:b,onCancel:()=>x(!1),readOnly:r}),[l,s,x,b,C,r,a]);return(0,X.jsxs)(`div`,{"data-testid":`field-designer`,className:Pb(`w-full space-y-3`,i),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(vi,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,X.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,X.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),"data-testid":`field-designer-type-filter`,className:`rounded-md border border-input bg-background px-2 py-1 text-xs outline-none transition-colors focus:border-primary focus:ring-1 focus:ring-primary`,children:[(0,X.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,X.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,X.jsx)(ya,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,X.jsx)(xa,{schema:w}),(0,X.jsx)(Cy,{isOpen:o.isOpen,title:o.title,message:o.message,confirmLabel:a(`common.delete`),cancelLabel:a(`common.cancel`),onConfirm:o.onConfirm,onCancel:o.onCancel,destructive:!0})]})}var zb=`objectui-app-wizard-draft`;function Bb(){let e=_(),{appName:t}=f(),{objects:n,refresh:r}=F(),i=he(),a=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),o=(0,Y.useCallback)(()=>{try{let e=localStorage.getItem(zb);if(e)return JSON.parse(e)}catch{}},[]),s=(0,Y.useCallback)(async t=>{try{let n=ue(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(zb),J.success(`Application "${t.title}" created successfully`),await r?.(),e(`/apps/${t.name}`)}catch(e){J.error(e?.message||`Failed to create application`)}},[e,r,i]),c=(0,Y.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),l=(0,Y.useCallback)(e=>{try{localStorage.setItem(zb,JSON.stringify(e)),J.info(`Draft saved`)}catch{}},[]);return(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,X.jsx)(cb,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function Vb(){let e=_(),{appName:t,editAppName:n}=f(),{apps:r,objects:i,refresh:a}=F(),o=he(),s=n||t,c=r.find(e=>e.name===s),l=(i||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:c?.navigation?.some(t=>t.type===`object`&&t.objectName===e.name)??!1})),u=(0,Y.useMemo)(()=>{if(c)return{name:c.name,title:c.title||c.label||``,description:c.description||``,icon:c.icon||``,layout:c.layout||`sidebar`,navigation:c.navigation||[],branding:{logo:c.branding?.logo||c.logo||``,primaryColor:c.branding?.primaryColor||`#3b82f6`,favicon:c.branding?.favicon||c.favicon||``}}},[c]),d=(0,Y.useCallback)(async t=>{try{let n=ue(t),r={...c,...n},i=o?.getClient();i&&await i.meta.saveItem(`app`,t.name,r),J.success(`Application "${t.title}" updated successfully`),await a?.(),e(`/apps/${t.name}`)}catch(e){J.error(e?.message||`Failed to update application`)}},[e,a,o,c]),p=(0,Y.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,Y.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${s}`,JSON.stringify(e)),J.info(`Draft saved`)}catch{}},[s]);return c?(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,X.jsx)(cb,{availableObjects:l,initialDraft:u,onComplete:d,onCancel:p,onSaveDraft:m})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,X.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,s,`" not found.`]})})}function Hb(){let e=_(),{dashboardName:t}=f(),n=he(),{dashboards:r,refresh:i}=F(),a=r?.find(e=>e.name===t),[o,s]=(0,Y.useState)(()=>a||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),c=(0,Y.useRef)(o);c.current=o;let l=(0,Y.useCallback)(async e=>{try{if(n)return await n.update(`sys_dashboard`,t,e),i().catch(()=>{}),!0}catch{}return!1},[n,t,i]),u=(0,Y.useCallback)(async e=>{s(e),await l(e)},[l]);(0,Y.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),l(c.current).then(e=>{e&&J.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let d=(0,Y.useCallback)(e=>{let n=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t||`dashboard`}.json`,i.click(),URL.revokeObjectURL(r),J.success(`Dashboard schema exported`)},[t]),p=(0,Y.useCallback)(e=>{J.success(`Dashboard schema imported`),u(e)},[u]);return a?(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`rounded p-1.5 text-muted-foreground hover:text-foreground`,"aria-label":`Go back`,"data-testid":`dashboard-design-back`,children:(0,X.jsx)(dt,{className:`h-4 w-4`})}),(0,X.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,a.label||a.title||t]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,X.jsx)(Tb,{schema:o,onChange:u,onExport:d,onImport:p})})]}):(0,X.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var Ub=t({AppCreationWizard:()=>cb,BrandingEditor:()=>kb,CreateAppPage:()=>Bb,DashboardDesignPage:()=>Hb,DashboardEditor:()=>Tb,DataModelDesigner:()=>Ry,EditAppPage:()=>Vb,FieldDesigner:()=>Rb,NavigationDesigner:()=>_b,ObjectManager:()=>Nb,PageDesigner:()=>My,ProcessDesigner:()=>Uy,ReportDesigner:()=>qy});z.register(`page-designer`,My,{namespace:`plugin-designer`,label:`Page Designer`,category:`Designer`,inputs:[{name:`canvas`,type:`code`,label:`Canvas Configuration`},{name:`components`,type:`code`,label:`Components`},{name:`showComponentTree`,type:`boolean`,label:`Show Component Tree`,defaultValue:!0},{name:`undoRedo`,type:`boolean`,label:`Undo/Redo`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`data-model-designer`,Ry,{namespace:`plugin-designer`,label:`Data Model Designer`,category:`Designer`,inputs:[{name:`entities`,type:`code`,label:`Entities`},{name:`relationships`,type:`code`,label:`Relationships`},{name:`autoLayout`,type:`boolean`,label:`Auto Layout`,defaultValue:!1},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`process-designer`,Uy,{namespace:`plugin-designer`,label:`Process Designer (BPMN)`,category:`Designer`,inputs:[{name:`processName`,type:`string`,label:`Process Name`},{name:`nodes`,type:`code`,label:`Nodes`},{name:`edges`,type:`code`,label:`Edges`},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`report-designer`,qy,{namespace:`plugin-designer`,label:`Report Designer`,category:`Designer`,inputs:[{name:`reportName`,type:`string`,label:`Report Name`},{name:`objectName`,type:`string`,label:`Data Source Object`},{name:`sections`,type:`code`,label:`Sections`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showPropertyPanel`,type:`boolean`,label:`Show Property Panel`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`app-creation-wizard`,cb,{namespace:`plugin-designer`,label:`App Creation Wizard`,category:`Designer`,inputs:[{name:`availableObjects`,type:`code`,label:`Available Objects`},{name:`templates`,type:`code`,label:`Templates`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`navigation-designer`,_b,{namespace:`plugin-designer`,label:`Navigation Designer`,category:`Designer`,inputs:[{name:`items`,type:`code`,label:`Navigation Items`},{name:`showPreview`,type:`boolean`,label:`Show Preview`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`dashboard-editor`,Tb,{namespace:`plugin-designer`,label:`Dashboard Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Dashboard Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`branding-editor`,kb,{namespace:`plugin-designer`,label:`Branding Editor`,category:`Designer`,inputs:[{name:`branding`,type:`code`,label:`Branding Config`},{name:`appTitle`,type:`string`,label:`App Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`object-manager`,Nb,{namespace:`plugin-designer`,label:`Object Manager`,category:`Designer`,inputs:[{name:`objects`,type:`code`,label:`Object Definitions`},{name:`showSystemObjects`,type:`boolean`,label:`Show System Objects`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),z.register(`field-designer`,Rb,{namespace:`plugin-designer`,label:`Field Designer`,category:`Designer`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`fields`,type:`code`,label:`Field Definitions`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]});function Wb(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function Gb(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var Kb=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=Wb(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(Gb)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function qb({schema:e}){let t=e.objectName,{objects:n,refresh:r}=F(),i=Tu(),a=(0,Y.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,Y.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(sy):[],[a]),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),d=s??o,f=(0,Y.useRef)(d),p=(0,Y.useCallback)(async e=>{let n=f.current;if(c(e),f.current=e,!i){J.error(`Service unavailable — changes saved locally only`);return}let a=Kb.diffFields(n,e),o=a?a.type===`create`?`Field "${a.field.label||a.field.name}" created`:a.type===`update`?`Field "${a.field.label||a.field.name}" updated`:`Field "${a.field.label||a.field.name}" deleted`:`Field configuration updated`;u(!0);try{await i.saveFields(t,e),await r(),J.success(o)}catch(e){c(n),f.current=n,J.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,X.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground bg-muted/50 rounded-md px-3 py-2`,"data-testid":`system-field-hint`,children:[(0,X.jsx)(Li,{className:`h-3.5 w-3.5 shrink-0`}),`System fields (e.g. id, createdAt, updatedAt) are read-only and cannot be edited or deleted.`]}),(0,X.jsx)(Rb,{objectName:t,fields:d,onFieldsChange:p})]})}function Jb({schema:e}){let t=e.objectName,[n,r]=(0,Y.useState)(`details`),i={type:`object-properties`,id:`${t}-properties`,objectName:t},a={type:`object-field-designer`,id:`${t}-field-designer`,objectName:t},o={type:`object-relationships`,id:`${t}-relationships`,objectName:t},s={type:`object-keys`,id:`${t}-keys`,objectName:t},c={type:`object-data-experience`,id:`${t}-data-experience`,objectName:t},l={type:`object-data-preview`,id:`${t}-data-preview`,objectName:t};return(0,X.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,X.jsxs)(_e,{value:n,onValueChange:r,className:`w-full`,children:[(0,X.jsxs)(Oi,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,X.jsxs)(ni,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,X.jsx)(ar,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,X.jsxs)(ni,{value:`fields`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,X.jsx)(vi,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,X.jsxs)(ni,{value:`relationships`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,X.jsx)(Hr,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,X.jsxs)(ni,{value:`data`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,X.jsx)(tt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,X.jsx)(_r,{value:`details`,className:`mt-6`,children:(0,X.jsx)(`div`,{className:`space-y-6`,children:(0,X.jsx)(M,{schema:i})})}),(0,X.jsx)(_r,{value:`fields`,className:`mt-6`,children:(0,X.jsx)(`div`,{className:`space-y-6`,children:(0,X.jsx)(M,{schema:a})})}),(0,X.jsx)(_r,{value:`relationships`,className:`mt-6`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(M,{schema:o}),(0,X.jsx)(M,{schema:s})]})}),(0,X.jsx)(_r,{value:`data`,className:`mt-6`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(M,{schema:l}),(0,X.jsx)(M,{schema:c})]})})]})})}var Yb={namespace:`console`,category:`system`};z.register(`object-detail-tabs`,Jb,{...Yb,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),z.register(`object-properties`,uy,{...Yb,label:`Object Properties`,icon:`Settings2`}),z.register(`object-relationships`,fy,{...Yb,label:`Object Relationships`,icon:`Link2`}),z.register(`object-keys`,py,{...Yb,label:`Object Keys`,icon:`KeyRound`}),z.register(`object-data-experience`,my,{...Yb,label:`Data Experience`,icon:`LayoutList`}),z.register(`object-data-preview`,hy,{...Yb,label:`Data Preview`,icon:`Table`}),z.register(`object-field-designer`,qb,{...Yb,label:`Field Designer`,icon:`Columns`});var Xb=(0,Y.lazy)(()=>m(()=>import(`./ApiConsolePage-CVt86JW9.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Zb=(0,Y.lazy)(()=>m(()=>import(`./FlowRunsPage-CF-nkx9E.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Qb=(0,Y.lazy)(()=>m(()=>import(`./PublicFormsPage-B1cdfwoQ.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function $b({label:e}){return(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Lf({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)($b,{label:`API console`}),children:(0,X.jsx)(Xb,{...e})})}),Lf({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)($b,{label:`flow runs`}),children:(0,X.jsx)(Zb,{...e})})}),Lf({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)($b,{label:`public forms`}),children:(0,X.jsx)(Qb,{...e})})});var ex=(0,Y.lazy)(()=>m(()=>import(`./ProfilePage-4wnWye8l.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function tx({label:e}){return(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Lf({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(tx,{label:`profile`}),children:(0,X.jsx)(ex,{...e})})});var nx=`/api/v1/auth`;xc(),z.registerLazy(`object-map`,()=>m(()=>import(`./plugin-map-CjA33cHV.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),z.registerLazy(`map`,()=>m(()=>import(`./plugin-map-CjA33cHV.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`dashboard`,`metric`,`metric-card`,`object-metric`,`pivot`,`object-pivot`,`dashboard-grid`,`object-data-table`])z.registerLazy(e,()=>m(()=>import(`./plugin-dashboard-DqF5vvlQ.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});z.registerLazy(`chart`,()=>m(()=>import(`./plugin-charts-Mt2y8Sdm.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])z.registerLazy(e,()=>m(()=>import(`./plugin-charts-Mt2y8Sdm.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});z.registerLazy(`object-gantt`,()=>m(()=>import(`./plugin-gantt-scBgVq2Q.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),z.registerLazy(`gantt`,()=>m(()=>import(`./plugin-gantt-scBgVq2Q.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),z.registerLazy(`markdown`,()=>m(()=>import(`./plugin-markdown-BPsaoDf-.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),z.registerLazy(`object-timeline`,()=>m(()=>import(`./plugin-timeline-Bmy8v-AN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),z.registerLazy(`timeline`,()=>m(()=>import(`./plugin-timeline-Bmy8v-AN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),z.registerLazy(`object-calendar`,()=>m(()=>import(`./plugin-calendar-wl24Whh9.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),z.registerLazy(`calendar`,()=>m(()=>import(`./plugin-calendar-wl24Whh9.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),z.registerLazy(`calendar-view`,()=>m(()=>import(`./plugin-calendar-wl24Whh9.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),z.registerLazy(`object-kanban`,()=>m(()=>import(`./plugin-kanban-0qj1Kr3T.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),z.registerLazy(`kanban`,()=>m(()=>import(`./plugin-kanban-0qj1Kr3T.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])z.registerLazy(e,()=>m(()=>import(`./plugin-kanban-0qj1Kr3T.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});z.registerLazy(`report`,()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`report-builder`,`spec-report`])z.registerLazy(e,()=>m(()=>import(`./plugin-report-C35V4A8F.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});un();var rx=``.replace(/\/+$/,``);Promise.all([nc(rx),ay(nx)]).finally(()=>{Wa.createRoot(document.getElementById(`root`)).render((0,X.jsx)(Y.StrictMode,{children:(0,X.jsx)(va,{pwa:{enabled:!0,name:ic(),shortName:ac()},children:(0,X.jsx)(le,{loadLanguage:ny,children:(0,X.jsx)(ty,{})})})}))});export{Ku as n,Rf as t};
|