@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
|
@@ -0,0 +1,33 @@
|
|
|
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{_ as r,a as i,c as a,d as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y,y as b}from"./vendor-react-CyVA1SE-.js";import{a as x,c as S,d as C,f as w,i as T,l as E,m as D,n as O,o as k,p as ee,r as A,s as j,u as te}from"./infrastructure-IQKE4Vv8.js";import{A as ne,B as re,D as M,L as N,M as ie,N as ae,O as P,P as oe,R as se,S as ce,T as le,X as ue,Y as de,_ as fe,at as pe,b as me,c as he,d as ge,n as _e,nt as ve,r as F,rt as I,tt as L,u as ye,ut as R,v as be,x as z,y as xe}from"./framework-DVkqUSPj.js";import{n as Se,r as Ce,t as we}from"./data-adapter-Bi1Re1fK.js";import{$ as Te,$a as Ee,$n as De,$o as Oe,$r as ke,$t as Ae,Aa as je,Ai as Me,An as Ne,Ao as Pe,Ar as Fe,As as B,At as V,Ba as Ie,Bi as Le,Bn as Re,Br as ze,Bt as Be,Ca as Ve,Co as He,Cr as Ue,Da as We,Di as Ge,Do as Ke,Dr as qe,Ds as Je,Dt as Ye,Ea as Xe,Ei as Ze,Eo as Qe,Er as $e,Es as et,Et as tt,F as nt,Fa as rt,Fi as H,Fn as it,Fo as at,Fr as ot,Ft as st,Ga as ct,Gi as lt,Gn as ut,Go as dt,Gr as ft,Gt as pt,Ha as mt,Hi as ht,Ho as gt,Hr as _t,Ht as vt,I as yt,Ii as bt,In as xt,Ir as St,It as Ct,Ja as wt,Ji as Tt,Jn as Et,Jo as Dt,Jr as Ot,Ki as kt,Kn as At,Ko as jt,Kr as Mt,Kt as Nt,La as Pt,Li as Ft,Ln as It,Lo as Lt,Lr as Rt,Lt as zt,M as Bt,Ma as Vt,Mi as Ht,Mn as Ut,Mo as Wt,Mr as Gt,Ms as Kt,Mt as qt,N as Jt,Na as Yt,Nn as Xt,No as Zt,Nr as Qt,Nt as $t,Oa as en,Oi as tn,On as nn,Oo as rn,Or as an,Os as on,Ot as sn,P as cn,Pi as ln,Pn as un,Po as dn,Pr as fn,Pt as pn,Q as mn,Qa as hn,Qi as gn,Qn as U,Qo as _n,Qr as vn,Qt as yn,Ra as bn,Rn as xn,Ro as Sn,Rt as Cn,Sa as wn,Sr as Tn,Ss as En,St as Dn,T as On,Ta as kn,Ti as An,To as jn,Tr as Mn,Ts as Nn,Tt as Pn,Ua as Fn,Ui as In,Uo as Ln,Ut as Rn,V as zn,Va as Bn,Vi as Vn,Vo as Hn,Vr as Un,Vt as Wn,Wa as Gn,Wi as Kn,Wo as qn,X as Jn,Xa as Yn,Xi as Xn,Xn as Zn,Xo as Qn,Xr as $n,Ya as er,Yi as tr,Yn as nr,Yo as rr,Yr as ir,Z as ar,Za as or,Zi as sr,Zo as cr,Zr as lr,Zt as ur,_ as dr,_a as fr,_i as pr,_o as mr,_r as hr,_s as gr,_t as _r,aa as vr,ai as yr,an as br,ao as xr,ar as Sr,ba as Cr,bi as wr,bo as Tr,br as Er,bs as Dr,bt as Or,ca as kr,ci as Ar,cn as jr,co as Mr,cr as Nr,cs as Pr,da as Fr,di as Ir,do as Lr,dr as Rr,dt as zr,ea as Br,ei as Vr,en as W,eo as Hr,er as Ur,es as Wr,et as Gr,fa as Kr,fi as qr,fo as Jr,fr as Yr,fs as Xr,ft as Zr,g as Qr,ga as $r,gi as ei,go as ti,gs as ni,gt as ri,h as ii,ha as ai,hi as oi,ho as si,ht as ci,ia as li,ii as ui,in as di,io as fi,is as pi,ja as mi,jn as hi,jo as gi,jr as _i,ka as vi,ki as yi,kn as bi,ko as xi,kr as Si,ks as Ci,kt as wi,la as Ti,li as Ei,ln as Di,lr as Oi,ls as ki,lt as Ai,ma as ji,mi as Mi,mn as Ni,mr as G,ms as Pi,mt as Fi,na as Ii,ni as Li,no as Ri,ns as zi,nt as Bi,oa as Vi,on as Hi,or as Ui,pa as Wi,pi as Gi,po as Ki,pt as qi,qa as Ji,qi as Yi,qn as Xi,qo as Zi,qr as Qi,qt as $i,ra as ea,ri as ta,ro as na,sa as ra,si as ia,sn as aa,so as oa,sr as sa,ss as ca,ta as la,to as ua,tr as da,ts as fa,tt as pa,ua as ma,ui as ha,un as ga,uo as _a,ur as va,us as ya,v as ba,va as xa,vi as Sa,vo as Ca,vr as wa,vs as Ta,w as Ea,wa as Da,wi as Oa,wo as ka,wr as Aa,ws as ja,wt as Ma,x as Na,xa as K,xo as Pa,xr as Fa,xt as Ia,ya as La,yi as Ra,yo as za,yr as Ba,ys as Va,yt as Ha,z as Ua,zn as Wa,zo as Ga,zr as Ka,zt as qa}from"./ui-components-CIdYg6m3.js";import{a as Ja,i as Ya,o as q,r as Xa}from"./vendor-ui-utils-BbOuugky.js";import{a as Za,c as Qa,i as $a,n as eo,o as to,r as no,s as ro,t as io}from"./RecentItemsProvider-Dt0K6V1V.js";import{n as ao,r as oo,t as so}from"./ui-layout-DGPxy1gI.js";import{a as co,n as lo,o as uo,s as fo,t as po}from"./plugins-views-DUx-xpiH.js";import{i as mo,r as ho}from"./plugin-grid-DGQxmfxn.js";import{n as go,r as _o,t as vo}from"./plugin-form-KOOMD5ZY.js";import{a as yo,c as bo,d as xo,f as So,i as Co,l as wo,m as To,n as Eo,o as Do,p as Oo,r as ko,s as Ao,t as jo,u as Mo}from"./plugin-view-DspcF1Mc.js";import{i as No,n as Po,r as Fo}from"./plugin-dashboard-BRn9AjyQ.js";import{i as Io,l as Lo,t as Ro,u as zo}from"./plugin-chatbot-CiVctLlf.js";var J=e(b(),1),Bo=e(r(),1),Y=g();function Vo({children:e,adapter:t}){let[n,r]=(0,J.useState)(t??null);return(0,J.useEffect)(()=>{if(t){r(t);return}let e=!1;async function n(){try{let t=new we({baseUrl:``,fetch:D(),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,Y.jsx)(xe.Provider,{value:n,children:e})}var Ho=300*1e3,Uo=[`app`,`view`],Wo={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},Go=`objectui:metadata:`;function Ko(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var qo=Ko();function Jo(...e){qo&&console.debug(`[MetadataProvider]`,...e)}function Yo(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function Xo(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Zo(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Qo(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 $o(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function es(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(Go+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function ts(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(Go+e,JSON.stringify(t))}catch{}}function ns({children:e,adapter:t,ttlMs:n=Ho}){let r=(0,J.useRef)(new Map),i=(0,J.useRef)(new Map),a=(0,J.useRef)(t);a.current=t;let[o,s]=(0,J.useState)(0),c=(0,J.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>s(e=>e+1)):Promise.resolve().then(()=>s(e=>e+1))},[]),l=(0,J.useCallback)(e=>{let t=r.current.get(e);return t||(t=$o(),r.current.set(e,t)),t},[]),u=(0,J.useCallback)(e=>{let t=l(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return Jo(`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=Yo(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)Zo(e)&&t.byName.set(e.name,e);return e===`app`&&ts(e,i),Jo(`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,Jo(`fetch failed type=${e}`,r),c(),[]});return t.promise=i,i},[c,l,n]),d=(0,J.useCallback)((e,t)=>{let n=l(e);if(n.byName.has(t))return Jo(`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=Xo(i);return a&&n.byName.set(t,a),Jo(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Jo(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,c),c},[l]),f=(0,J.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,J.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),Jo(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Jo(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1,t=es(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Zo(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of Uo)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,J.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(Wo.objects),n=e(`view`);return n.length?Qo(t,n):t},get dashboards(){return e(Wo.dashboards)},get reports(){return e(Wo.reports)},get pages(){return e(Wo.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,Y.jsx)(me.Provider,{value:v,children:e})}var rs=(0,J.createContext)(null);function is({children:e,user:t={},app:n={},data:r={},features:i={}}){let a=(0,J.useMemo)(()=>({user:t,app:n,data:r,features:i,evaluator:new I({user:t,app:n,data:r,features:i})}),[t,n,r,i]),o=(0,J.useMemo)(()=>({user:t,app:n,data:r,features:i}),[t,n,r,i]);return(0,Y.jsx)(rs.Provider,{value:a,children:(0,Y.jsx)(oe,{scope:o,children:e})})}function as(){let e=(0,J.useContext)(rs);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new I(e)}}return e}function os(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 ss({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let c=s(),{appName:l}=f(),{t:u}=F(),d=`/apps/${l}`,{execute:p,loading:m,error:h,runner:g}=ae({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:a,onToast:o});return(0,J.useEffect)(()=>{g.registerHandler(`create`,async()=>(r?.(null),{success:!0})),g.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?(q.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0}):(q.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?.(),q.success(u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return q.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),g.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),g.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[g,e,n,r,i,c,d,u,t]),{execute:p,create:(0,J.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,J.useCallback)(async e=>p({type:`delete`,confirmText:u(`objectActions.deleteConfirm`),params:{recordId:e}}),[p,u]),navigateToView:(0,J.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,J.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:m,error:h}}var cs=(0,J.createContext)(void 0);function ls({children:e}){let[t,n]=(0,J.useState)(`home`),[r,i]=(0,J.useState)(),[a,o]=(0,J.useState)(),s=(0,J.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,Y.jsx)(cs.Provider,{value:s,children:e})}function us(){return(0,J.useContext)(cs)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function ds(e){let{setRecordTitle:t}=us();(0,J.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var fs=`objectui-favorites`,ps=`objectui-nav-pins`,ms=20,hs=20;function gs(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>hs&&(r=!0)):(t++,t>ms&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<hs&&(i.push(t),o++):a<ms&&(i.push(t),a++);return i}function _s(e){try{let t=localStorage.getItem(Za(fs,e));return t?JSON.parse(t):[]}catch{return[]}}function vs(e,t){try{localStorage.setItem(Za(fs,t),JSON.stringify(e))}catch{}}function ys(e){let t;try{t=localStorage.getItem(ps)}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(ps)}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 bs=(0,J.createContext)(null);function xs({children:e}){let{user:t}=w(),n=t?.id??null,r=Qa(`favorites`),[i,a]=(0,J.useState)(()=>_s(n));(0,J.useEffect)(()=>{a(_s(n))},[n]),ro(Za(fs,n),e=>{a(Array.isArray(e)?gs(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,J.useRef)(0);(0,J.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=gs((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=_s(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=gs([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=ys(f);h&&(f=gs(m),p=!0),a(f),vs(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,J.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=ys(e);if(!r)return e;let i=gs(t);return vs(i,n),i})},[r,n]);let s=(0,J.useMemo)(()=>$a(async e=>{r&&await r.save(e)},500),[r]);(0,J.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,J.useCallback)(e=>{vs(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,J.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=gs([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),u=(0,J.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),d=(0,J.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):gs([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),f=(0,J.useCallback)(()=>{a([]),c([])},[c]),p=(0,J.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,J.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,J.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,Y.jsx)(bs.Provider,{value:h,children:e})}function Ss(){return(0,J.useContext)(bs)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Cs=(0,J.createContext)({theme:`system`,setTheme:()=>null});function ws({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,J.useState)(()=>localStorage.getItem(n)||t);(0,J.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,Y.jsx)(Cs.Provider,{...r,value:o,children:e})}var Ts=()=>{let e=(0,J.useContext)(Cs);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Es(){return(0,Y.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Ds({children:e}){return(0,Y.jsx)(ws,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Y.jsx)(ls,{children:(0,Y.jsx)(no,{children:(0,Y.jsx)(xs,{children:(0,Y.jsx)(io,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Es,{}),children:e})})})})})})}function Os({children:e}){return(0,Y.jsx)(Vo,{children:(0,Y.jsx)(ks,{children:e})})}function ks({children:e}){let t=z();return t?(0,Y.jsx)(re,{dataSource:t,children:(0,Y.jsxs)(ns,{adapter:t,children:[(0,Y.jsx)(As,{}),e]})}):(0,Y.jsx)(Es,{})}function As(){let{user:e}=w(),t=z(),n=to();return(0,J.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=Ce({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Ce({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 js({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=w();return r?(0,Y.jsx)(Es,{}):((n??[]).length>0||t)&&!t?(0,Y.jsx)(_,{to:`/organizations`,replace:!0}):(0,Y.jsx)(Y.Fragment,{children:e})}function Ms(){let e=o(),t=e.pathname.replace(/^\/system/,``);return(0,Y.jsx)(_,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var Ns=(0,J.lazy)(()=>c(()=>import(`./ConsoleFloatingChatbot-DJW7zeKU.js`),__vite__mapDeps([0]),import.meta.url)),Ps=()=>{c(()=>import(`./ConsoleFloatingChatbot-DJW7zeKU.js`),__vite__mapDeps([0]),import.meta.url)};function Fs(e){let[t,n]=(0,J.useState)(!1);return t?(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Ns,{...e,defaultOpen:!0})}):(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:Ps,onFocus:Ps,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,Y.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,Y.jsx)(`path`,{d:`M12 3v3`}),(0,Y.jsx)(`path`,{d:`M12 18v3`}),(0,Y.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,Y.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,Y.jsx)(`path`,{d:`M3 12h3`}),(0,Y.jsx)(`path`,{d:`M18 12h3`}),(0,Y.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,Y.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,Y.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function Is(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 Ls=new Set(ar),Rs=new Map;function zs(e){if(!e)return Tr;let t=Rs.get(e);if(t)return t;let n=Is(e);if(!Ls.has(n))return Rs.set(e,Tr),Tr;let r=e=>J.createElement(Jn,{name:n,fallback:Tr,...e});return r.displayName=`LucideIcon(${e})`,Rs.set(e,r),r}var Bs=20;function Vs(e,t=``){let{href:n,external:r}=ao(e,t);return r?n:!n||n===`#`?``:n}function Hs(e){return`nav:${e}`}function Us(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Ss(),a=(0,J.useCallback)((e,i,a,o)=>{let s=Hs(e);i?(a&&t({id:s,label:a.label,href:Vs(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,J.useCallback)(e=>i.has(e),[i]),s=(0,J.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<Bs;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,J.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,J.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}function Ws(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 Gs(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 Ks(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 qs(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 Js(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var Ys=`\0`,Xs=`[-\\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===``?Ys:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Xs}\\s*${Ys}`,`g`),o=RegExp(`${Ys}\\s*${Xs}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(Ys,`g`),``).replace(/\s+/g,` `).trim(),i}function Qs(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`}var $s=`__all__`;function ec(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function tc(e){if(Array.isArray(e))return e;let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.packages)?t.packages:Array.isArray(t?.items)?t.items:Array.isArray(e?.items)?e.items:[]}function nc(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=ec(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1;break}}return!0}function rc(e){let[t,n]=J.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]);return J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)return;let s=await t.json();if(e)return;let c=tc(s),l=[],u=new Set;for(let e of c){if(!nc(e,o))continue;let t=ec(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=ec(e,a);l.push({value:t,label:typeof n==`string`&&n?n:t})}l.sort((e,t)=>e.label.localeCompare(t.label)),n(l)}catch{}})(),()=>{e=!0}},[r,i,a,s]),t}function ic(e,t,n){let r=Array.isArray(t)?t:[],i=s(),a=o(),c=new URLSearchParams(a.search),l=J.useRef(!1);J.useEffect(()=>{if(l.current)return;l.current=!0;let t=new URLSearchParams(a.search),n=!1;for(let i of r)if(i.persist!==`none`&&!t.get(`package`))try{let r=sessionStorage.getItem(`objectui-ctx-${e}-${i.id}`);r&&(t.set(`package`,r),n=!0)}catch{}n&&i({pathname:a.pathname,search:t.toString()},{replace:!0})},[]);let u=J.useCallback((t,n)=>{let r=n===$s?t.allValue??``:n;try{let n=`objectui-ctx-${e}-${t.id}`;r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}let o=new URLSearchParams(a.search);r?o.set(`package`,r):o.delete(`package`),i({pathname:a.pathname,search:o.toString()},{replace:!0})},[e,a.pathname,a.search,i]),d={};for(let e of r)d[e.id]=c.get(`package`)??e.allValue??``;return{contextValues:d,element:r.length===0?null:(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Y.jsx)(ac,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function ac({def:e,value:t,onChange:n,t:r}){let i=rc(e),a=zs(e.icon),o=qs(e.label,r)||e.id,s=e.includeAll!==!1;return(0,Y.jsxs)(Cn,{value:t&&t!==(e.allValue??``)?t:$s,onValueChange:n,children:[(0,Y.jsx)(Wn,{"aria-label":o,className:`h-8 w-full gap-1.5 rounded-md border-sidebar-border/60 bg-sidebar-accent/40 px-2 text-xs font-medium text-sidebar-foreground shadow-none hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent`,children:(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 truncate`,children:[(0,Y.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 opacity-60`}),(0,Y.jsx)(vt,{placeholder:`All ${o}`})]})}),(0,Y.jsxs)(qa,{children:[s&&(0,Y.jsx)(Be,{value:$s,children:`All ${o}`}),i.map(e=>(0,Y.jsx)(Be,{value:e.value,children:e.label},e.value))]})]})}function oc(e){let t=`objectui-nav-order-${e}`,[n,r]=J.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=J.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:J.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:J.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function sc({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=Pn(),r=o(),{t:a}=F(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=Kt(),{context:d,currentAppName:f}=us(),{user:p}=w();J.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}=eo(),{favorites:h,removeFavorite:g}=Ss(),{apps:_,objects:v}=ce(),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:C}=oc(x?.name||`home`),{togglePin:T,applyPins:E}=Us(),D=x?.areas||[],[k,ee]=J.useState(()=>D.length>0?D[0].id:null);J.useEffect(()=>{D.length>0?ee(e=>D.some(t=>t.id===e)?e:D[0].id):ee(null)},[x?.name,D.length]);let A=D.find(e=>e.id===k)?.navigation||x?.navigation||[],{contextValues:j,element:te}=ic(x?.name||`home`,x?.contextSelectors,a),ne=J.useMemo(()=>[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[a]),re=d===`home`?ne:A,M=J.useMemo(()=>E(S(re)),[re,S,E]),[N,ie]=J.useState(!1),{evaluator:ae}=as(),P=J.useCallback(e=>os(e,ae),[ae]),{can:oe}=O(),se=J.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return oe(n,r)}),[oe]),le=J.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),ue=J.useCallback((e,t)=>e===`object`?le.size===0?!0:le.has(t):!0,[le]),de=d===`app`&&x?`/apps/${x.name}`:``;return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(zr,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Y.jsx)(_r,{className:`border-b p-1.5`,children:(0,Y.jsx)(Ha,{children:(0,Y.jsx)(Dn,{children:(0,Y.jsx)(Ia,{asChild:!0,className:`h-9 text-sm font-medium`,children:(0,Y.jsxs)(i,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Y.jsx)(mt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Y.jsx)(Zr,{className:`pt-2`,children:(0,Y.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&x?(0,Y.jsxs)(Y.Fragment,{children:[te&&(0,Y.jsxs)(Fi,{className:`group-data-[state=collapsed]:hidden`,children:[(0,Y.jsxs)(ri,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5`}),a(`sidebar.scope`,{defaultValue:`范围`})]}),(0,Y.jsx)(ci,{children:te})]}),D.length>1&&(0,Y.jsxs)(Fi,{children:[(0,Y.jsxs)(ri,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(mi,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,Y.jsx)(ci,{children:(0,Y.jsx)(Ha,{children:D.map(e=>{let t=zs(e.icon);return(0,Y.jsx)(Dn,{children:(0,Y.jsxs)(Ia,{isActive:e.id===k,tooltip:e.label,onClick:()=>ee(e.id),children:[(0,Y.jsx)(t,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Y.jsx)(so,{items:M,basePath:de,evaluateVisibility:P,checkPermission:se,checkCapability:ue,enablePinning:!t,onPinToggle:T,enableReorder:!t,onReorder:C,resolveObjectLabel:(e,t)=>s({name:e,label:t}),resolveDashboardLabel:(e,t)=>c({name:e,label:t}),resolveGroupLabel:x?(e,t)=>l(x.name,e,t):void 0,resolveItemLabel:x?(e,t)=>l(x.name,e,t):void 0,resolveViewLabel:(e,t,n)=>u(e,t,n),t:a,templateContext:{currentUserId:p?.id??null,contextValues:j}}),m.length>0&&(0,Y.jsxs)(Fi,{children:[(0,Y.jsxs)(ri,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ie(e=>!e),children:[(0,Y.jsx)(qn,{className:`h-3 w-3 transition-transform duration-150 ${N?`rotate-90`:``}`}),(0,Y.jsx)(rn,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),N&&(0,Y.jsx)(ci,{children:(0,Y.jsx)(Ha,{children:m.slice(0,5).map(e=>(0,Y.jsx)(Dn,{children:(0,Y.jsx)(Ia,{asChild:!0,tooltip:e.label,children:(0,Y.jsxs)(i,{to:e.href,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),h.some(e=>e.type!==`nav`)&&(0,Y.jsxs)(Fi,{children:[(0,Y.jsxs)(ri,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Y.jsx)(ci,{children:(0,Y.jsx)(Ha,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Y.jsxs)(Dn,{children:[(0,Y.jsx)(Ia,{asChild:!0,tooltip:e.label,children:(0,Y.jsxs)(i,{to:e.href,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Y.jsx)(Or,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)(ke,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Fi,{children:(0,Y.jsx)(ci,{children:(0,Y.jsx)(Ha,{children:ne.map(e=>{let t=zs(e.icon),n=r.pathname===e.url;return(0,Y.jsx)(Dn,{children:(0,Y.jsx)(Ia,{asChild:!0,tooltip:e.label,isActive:n,children:(0,Y.jsxs)(i,{to:e.url||`/home`,children:[(0,Y.jsx)(t,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Y.jsxs)(Fi,{children:[(0,Y.jsxs)(ri,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Y.jsx)(ci,{children:(0,Y.jsx)(Ha,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Y.jsxs)(Dn,{children:[(0,Y.jsx)(Ia,{asChild:!0,tooltip:e.label,children:(0,Y.jsxs)(i,{to:e.href,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Y.jsx)(Or,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)(ke,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Y.jsx)(qi,{className:`border-t p-1`,children:(0,Y.jsx)(Ma,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function cc(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,J.useState)(`disconnected`),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)([]),[p,m]=(0,J.useState)(null),h=(0,J.useRef)(null),g=(0,J.useRef)(0),_=(0,J.useRef)(null),v=(0,J.useRef)(new Map),y=(0,J.useRef)([]),b=(0,J.useRef)(!0),x=(0,J.useRef)(!1),S=(0,J.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,J.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,J.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,J.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,J.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,J.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,J.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,J.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 lc=0;function uc(){return lc+=1,`conflict-${Date.now()}-${lc}`}var dc=0;function fc(){return dc+=1,`ver-${Date.now()}-${dc}`}function pc(e,t,n){let[r,i]=(0,J.useState)([]),[a,o]=(0,J.useState)([]);return{versions:r,currentVersion:(0,J.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,J.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:fc(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,J.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:fc(),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,J.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:fc(),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,J.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:fc(),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,J.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,J.useCallback)(e=>{let t={...e,id:uc()};o(e=>[...e,t])},[]),clearHistory:(0,J.useCallback)(()=>{i([]),o([])},[])}}var mc={sm:24,md:32,lg:40},hc={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function gc(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function _c({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=mc[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,J.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,J.useMemo)(()=>[...l].reverse(),[l]);return J.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&J.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>J.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?J.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):gc(e.userName),r&&J.createElement(`span`,{style:{...m,backgroundColor:hc[e.status]}}))))}var vc=J.createContext({});function yc(){let e=J.useContext(vc),[t,n]=J.useState([]);return J.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function bc(e,t){let n=J.useContext(vc),[r,i]=J.useState([]);return J.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 xc(){let{theme:e,setTheme:t}=Ts(),{t:n}=F();return(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)($n,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Y.jsx)(Vi,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,Y.jsxs)(Hi,{align:`end`,children:[(0,Y.jsxs)(jr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Y.jsx)($n,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(jr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Y.jsx)(Vi,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(jr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Y.jsx)(ra,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var Sc=[{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 Cc(){let{t:e,language:t,changeLanguage:n}=F();return(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(er,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Y.jsx)(Hi,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Sc.map(e=>(0,Y.jsxs)(jr,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var wc={connected:{label:`Connected`,color:`text-green-500`,icon:Ga},connecting:{label:`Connecting...`,color:`text-yellow-500`,icon:K},reconnecting:{label:`Reconnecting...`,color:`text-yellow-500`,icon:K},disconnected:{label:`Disconnected`,color:`text-muted-foreground`,icon:Aa},error:{label:`Connection Error`,color:`text-destructive`,icon:Aa}};function Tc({state:e,className:t}){let n=wc[e],r=n.icon,[i,a]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{if(e===`connected`){a(!0);let e=setTimeout(()=>a(!1),2e3);return()=>clearTimeout(e)}a(!1)},[e]),e===`connected`&&!i?null:(0,Y.jsxs)(`div`,{className:B(`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,Y.jsx)(r,{className:B(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Ec(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 Dc({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=F(),c=s(),l=f(),{currentAppName:u}=us(),[d,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(`notifications`),[g,_]=(0,J.useState)(`unread`),v=t+n,y=o(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,J.useRef)(null),[x,S]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let e=b.current;if(e!==null&&v>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=v},[v]),(0,J.useEffect)(()=>{x||(b.current=v)},[x,v]);let C=()=>{p(!1);let e=u??l.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{p(!1),c(`/apps/setup/sys_notification?view=mine`)},T=()=>{p(!1),c(`/apps/setup/sys_activity`)},E=e=>{if(a(e.id),e.source_object&&e.source_id){p(!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,Y.jsxs)(ur,{open:d,onOpenChange:p,children:[(0,Y.jsx)(Ae,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${x?`motion-safe:animate-bounce`:``}`,"aria-label":y,title:o(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,Y.jsx)(Pi,{className:`h-4 w-4`}),v>0&&(0,Y.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:v>9?`9+`:v},v)]})}),(0,Y.jsxs)(yn,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold`,children:o(`sidebar.inbox`,{defaultValue:`Inbox`})}),m===`notifications`&&t>0&&(0,Y.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:o(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Y.jsxs)(Te,{value:m,onValueChange:e=>h(e),className:`w-full`,children:[(0,Y.jsxs)(pa,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Y.jsxs)(Bi,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Pi,{className:`h-3.5 w-3.5`}),o(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,Y.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,Y.jsxs)(Bi,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(ta,{className:`h-3.5 w-3.5`}),o(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,Y.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,Y.jsxs)(Bi,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Ci,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Y.jsxs)(Gr,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[o(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:o(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=g===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,Y.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:g===`unread`?o(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):o(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Y.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,Y.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,Y.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,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:Ec(e.created_at)})]})]})})},e.id))})})(),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:o(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Y.jsx)(Gr,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,Y.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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ta,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,Y.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:o(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Y.jsx)(G,{size:`sm`,className:`mt-3`,onClick:C,children:o(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:o(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Y.jsxs)(Gr,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,Y.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:o(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,Y.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,Y.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,Y.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[Ec(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:o(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function Oc({activeAppName:e,onAppChange:t}){let{apps:n}=ce(),{t:r}=F(),{appLabel:i}=Kt(),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,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.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,Y.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:qs(s.label,r)})}),(0,Y.jsx)(jt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Y.jsxs)(Hi,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Y.jsx)(Di,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,Y.jsx)(ga,{}),o.map(e=>{let n=zs(e.icon),a=i({name:e.name,label:qs(e.label,r)}),o=s.name===e.name;return(0,Y.jsxs)(jr,{onClick:()=>t(e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,Y.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,Y.jsx)(n,{className:`size-3`})}),(0,Y.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,Y.jsx)(Zi,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var kc=(0,J.createContext)(null);function Ac({children:e}){let[t,n]=(0,J.useState)(null),r=(0,J.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Y.jsx)(kc.Provider,{value:r,children:e})}function jc(){return(0,J.useContext)(kc)?.value??null}function Mc(e){let t=(0,J.useContext)(kc),n=(0,J.useRef)(null);(0,J.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Nc(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,J.useRef)(r);o.current=r;let s=(0,J.useCallback)(e=>o.current(e),[]);Mc((0,J.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var Pc={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function Fc(e){Pc={...Pc,...e,features:{...Pc.features,...e.features??{}},branding:{...Pc.branding,...e.branding??{}}}}async function Ic(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;Fc({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):Pc.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??Pc.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??Pc.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:Pc.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():Pc.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():Pc.branding.productShortName}:Pc.branding})}catch{}}function Lc(){return Pc}function Rc(){return Pc.branding?.productName||`ObjectOS`}function zc(){return Pc.branding?.productShortName||Rc()}function Bc(){return Pc.cloudUrl??``}function Vc(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Hc(){return(0,Y.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Uc=[];function Wc({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:a,activities:c,activeAppName:l,onAppChange:u}){let d=e??(t?`app`:`home`),p=d===`app`,m=o(),h=f(),g=s(),{isOnline:_}=P(),{user:v,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:S,isOrganizationsLoading:C}=w(),T=z(),{t:E}=F(),{objectLabel:D,dashboardLabel:O,pageLabel:ee,reportLabel:A,viewLabel:j,appLabel:te}=Kt(),{apps:ne,dashboards:re,pages:M,reports:N}=ce(),{currentAppName:ie,recordTitle:ae}=us(),oe=jc(),[se,le]=(0,J.useState)(null),[ue,de]=(0,J.useState)([]),fe=(0,J.useRef)(!1),pe=(0,J.useRef)(!1),[me,he]=(0,J.useState)(0),ge=(0,J.useRef)(!1),_e=(0,J.useCallback)(async()=>{if(!T||!p)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!fe.current)try{let t=await T.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(fe.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&le(e)}}catch{}},[T,p]);(0,J.useEffect)(()=>{_e()},[_e]),(0,J.useEffect)(()=>{if(!T||!p||!v?.id||pe.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 T.find(`sys_notification`,{$filter:{recipient_id:v.id},$orderby:{created_at:`desc`},$top:20});if(e)return;Array.isArray(t?.data)&&de(t.data),r=n}catch(e){if(i(e)){pe.current=!0;return}r=Math.min(r*2,12e4)}},o=()=>{if(e||pe.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)}},[T,p,v?.id]),(0,J.useEffect)(()=>{if(!p||!v?.id||ge.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];v.id&&t.push(v.id),v.email&&t.push(v.email);for(let e of v.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){ge.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||he(r.size)}catch{}},a=()=>{n||ge.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[p,v?.id]);let ve=ue.reduce((e,t)=>e+ +!t.is_read,0),I=(0,J.useCallback)(async e=>{if(de(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),T)try{await T.update(`sys_notification`,e,{is_read:!0,read_at:new Date().toISOString()})}catch{}},[T]),L=(0,J.useCallback)(async()=>{let e=ue.filter(e=>!e.is_read);if(!e.length||(de(e=>e.map(e=>({...e,is_read:!0}))),!T))return;let t=new Date().toISOString(),n=e.map(e=>e.id),r=T;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=>T.update(`sys_notification`,e.id,{is_read:!0,read_at:t}).catch(()=>{})))},[T,ue]),ye=yc(),R=a??(ye.length>0?ye:Uc),be=c??se??[],xe=C||(x??[]).length>0||!!S,Se=m.pathname.split(`/`).filter(Boolean),Ce=h.appName||Se[1],we=Se[2],Te=`/apps/${Ce}`,Ee=n??[],Oe=l||ie||Ce,ke=(ne||[]).find(e=>e.name===Oe),Ae=new Set,je=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ae.add(t.objectName),t.children&&je(t.children)};je(ke?.navigation||[]);for(let e of ke?.areas||[])je(e.navigation||[]);let Me=(Ae.size>0?Ee.filter(e=>Ae.has(e.name)):Ee.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:D(e),href:`${Te}/${e.name}`})),Ne=[];if(p){if(we===`dashboard`){if(Ne.push({label:E(`console.breadcrumb.dashboards`),href:Te}),Se[3]){let e=Se[3],t=(re||[]).find(t=>t.name===e)?.label||Vc(e);Ne.push({label:O({name:e,label:t})})}}else if(we===`page`){if(Ne.push({label:E(`console.breadcrumb.pages`),href:Te}),Se[3]){let e=Se[3],t=(M||[]).find(t=>t.name===e)?.label||Vc(e);Ne.push({label:ee({name:e,label:t})})}}else if(we===`report`){if(Ne.push({label:E(`console.breadcrumb.reports`),href:Te}),Se[3]){let e=Se[3],t=(N||[]).find(t=>t.name===e)?.label||Vc(e);Ne.push({label:A({name:e,label:t})})}}else if(we===`system`)Ne.push({label:E(`console.breadcrumb.system`)}),Se[3]&&Ne.push({label:Vc(Se[3])});else if(we){let e=Ee.find(e=>e.name===we);if(e){if(Ne.push({label:D(e),href:`${Te}/${we}`,siblings:Me}),Se[3]===`record`&&Se[4]){let e=Se[4].length>12?`${Se[4].slice(0,8)}…`:Se[4],t=ae?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Ne.push({label:n||`#${e}`})}else if(Se[3]===`view`&&Se[4]){let t=Se[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Vc(t),i=j(e.name,t,r);Ne.push({label:i})}}}}let Pe=Ne[Ne.length-1]?.label||t||``;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,Y.jsx)(i,{to:`/home`,className:B(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,p&&`hidden sm:flex`),title:Rc(),children:(0,Y.jsx)(mi,{className:`h-4 w-4`})}),d===`home`&&(0,Y.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:Rc()}),d===`orgs`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Hc,{}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:E(`organizations.title`,{defaultValue:`Organizations`})})]}),p&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ma,{className:`md:hidden shrink-0 ml-1`,"aria-label":E(`common.toggleSidebar`)||`Toggle sidebar`}),l&&u?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(Hc,{})}),(0,Y.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(Oc,{activeAppName:l,onAppChange:u})})]}):t?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(Hc,{})}),(0,Y.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Ne.map((e,t)=>{let n=t===Ne.length-1;return(0,Y.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Y.jsx)(Hc,{}),e.siblings&&e.siblings.length>1?(0,Y.jsxs)(br,{children:[(0,Y.jsxs)(Ni,{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,Y.jsx)(jt,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Y.jsxs)(Hi,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Y.jsx)(Di,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Y.jsx)(ga,{}),e.siblings.map(e=>(0,Y.jsx)(jr,{asChild:!0,children:(0,Y.jsx)(i,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Y.jsx)(i,{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,Y.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)}),oe&&oe.views.length>0?oe.views.length>1?(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.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,Y.jsx)(`span`,{className:`truncate max-w-[180px]`,children:oe.triggerLabel??oe.views.find(e=>e.id===oe.activeViewId)?.label??Pe}),(0,Y.jsx)(jt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Y.jsx)(Hi,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:oe.views.map(e=>{let t=e.id===oe.activeViewId;return(0,Y.jsxs)(jr,{onSelect:()=>{t||oe.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,Y.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,Y.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,Y.jsx)(Cr,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Y.jsx)(Zi,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,Y.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:oe.triggerLabel??oe.views[0].label}):(0,Y.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Pe})]})]}),(0,Y.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:[!_&&(0,Y.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,Y.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),`Offline`]}),p&&r&&(0,Y.jsx)(Tc,{state:r}),p&&R.length>0&&(0,Y.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:`Users currently online`,children:(0,Y.jsx)(_c,{users:R,size:`sm`,maxVisible:3,showStatus:!0})}),(0,Y.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,Y.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,Y.jsx)(pr,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:E(`console.search`,{defaultValue:`Search…`})}),(0,Y.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,Y.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,Y.jsx)(G,{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":E(`console.search`,{defaultValue:`Search…`}),children:(0,Y.jsx)(pr,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,Y.jsx)(Dc,{notifications:ue,unreadCount:ve,pendingApprovalsCount:me,activities:be,onMarkAllRead:L,onMarkRead:I}),(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":E(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Y.jsx)(i,{to:`/ai`,children:(0,Y.jsx)(ya,{className:`h-4 w-4`})})}),(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,asChild:!0,"aria-label":E(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Y.jsx)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:(0,Y.jsx)(at,{className:`h-4 w-4`})})})]}),(0,Y.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Y.jsxs)(De,{className:`h-7 w-7 rounded-full`,children:[(0,Y.jsx)(da,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(Ur,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:k(v)})]})})}),(0,Y.jsxs)(Hi,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Y.jsx)(Di,{className:`p-0 font-normal`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Y.jsxs)(De,{className:`h-8 w-8 rounded-lg`,children:[(0,Y.jsx)(da,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(Ur,{className:`rounded-lg bg-primary text-primary-foreground`,children:k(v)})]}),(0,Y.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Y.jsx)(`span`,{className:`truncate font-semibold`,children:v?.name??`User`}),(0,Y.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:v?.email??``})]})]})}),(0,Y.jsx)(ga,{}),(0,Y.jsxs)(aa,{children:[xe&&(0,Y.jsxs)(jr,{onClick:()=>g(`/organizations`),className:`cursor-pointer`,children:[(0,Y.jsx)(Pr,{className:`mr-2 h-4 w-4`}),E(`organizations.mine`,{defaultValue:`My Organizations`})]}),(ne||[]).filter(e=>e.active!==!1&&e.hidden===!0).map(e=>{let t=zs(e.icon),n=te({name:e.name,label:qs(e.label,E)});return(0,Y.jsxs)(jr,{onClick:()=>g(`/apps/${e.name}`),className:`cursor-pointer`,children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,Y.jsx)(ga,{}),(0,Y.jsx)(Di,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:E(`user.preferences`,{defaultValue:`Preferences`})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-foreground/80`,children:E(`user.theme`,{defaultValue:`Theme`})}),(0,Y.jsx)(xc,{})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-foreground/80`,children:E(`user.language`,{defaultValue:`Language`})}),(0,Y.jsx)(Cc,{})]}),b&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ga,{}),(0,Y.jsxs)(jr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Y.jsx)(La,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Gc=768,Kc=1024;function qc(){let{setOpen:e,isMobile:t}=Pn();(0,J.useEffect)(()=>{function t(){let t=window.innerWidth;t>=Gc&&t<Kc&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}function Jc({children:e}){return qc(),(0,Y.jsx)(Y.Fragment,{children:e})}function Yc({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=qs(n?.label)||t,{isAiEnabled:c}=ne(),l=c||!1,{setContext:u,setCurrentAppName:d}=us();return(0,J.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Y.jsx)(Ac,{children:(0,Y.jsxs)(oo,{sidebar:(0,Y.jsx)(sc,{activeAppName:t,onAppChange:r}),navbar:(0,Y.jsx)(Wc,{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?`${qs(n.label)} — ${Rc()}`:void 0}:void 0,children:[(0,Y.jsx)(Jc,{children:e}),l&&(0,Y.jsx)(Fs,{appLabel:s,objects:i,userId:o})]})})}function Xc({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,Y.jsxs)(`div`,{style:{"--page-header-accent":i||`hsl(var(--primary))`},className:B(`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,Y.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,Y.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,Y.jsx)(`div`,{className:B(`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,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,Y.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,Y.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function Zc({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let[a,o]=(0,J.useState)(!1),[c,l]=(0,J.useState)(``),u=s(),{appName:d}=f(),{setTheme:p}=Ts(),{evaluator:m}=as(),{t:h}=F();(0,J.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),o(e=>!e))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,J.useEffect)(()=>{a||l(``)},[a]);let g=`/apps/${d||t?.name}`,{user:_}=w(),v=(0,J.useMemo)(()=>({currentUserId:_?.id??null}),[_?.id]),y=(0,J.useCallback)(e=>{o(!1),e()},[]),b=Qc(t?.navigation||[]).filter(e=>os(e.visible??e.visibleOn,m)),{results:x,isSearching:S}=fe({query:c,objects:n,dataSource:i,objectNames:(0,J.useMemo)(()=>b.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,b.map(e=>e.objectName||``).join(`|`)]),enabled:a&&!!i,getDisplayName:Qs}),{recentItems:C}=eo(),T=(0,J.useMemo)(()=>C.filter(e=>e.type===`record`).slice(0,5),[C]),E=a&&c.trim().length===0&&T.length>0;return(0,Y.jsxs)(nn,{open:a,onOpenChange:o,children:[(0,Y.jsx)(hi,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Y.jsxs)(Xt,{children:[(0,Y.jsx)(bi,{children:S?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`}),h(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):h(`console.commandPalette.noResults`)}),E&&(0,Y.jsx)(Ne,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Y.jsxs)(Ut,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Y.jsx)(pr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),x.length>0&&(0,Y.jsx)(Ne,{heading:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[h(`console.commandPalette.records`,{defaultValue:`Records`}),S&&(0,Y.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=zs(e.icon);return(0,Y.jsxs)(Ut,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>y(()=>u(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.display}),(0,Y.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,Y.jsx)(Ne,{heading:h(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=zs(e.icon);return(0,Y.jsxs)(Ut,{value:`object ${qs(e.label,h)} ${e.objectName}`,onSelect:()=>y(()=>u(ao(e,g,v).href)),children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:qs(e.label,h)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Y.jsx)(Ne,{heading:h(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Y.jsxs)(Ut,{value:`dashboard ${qs(e.label,h)} ${e.dashboardName}`,onSelect:()=>y(()=>u(ao(e,g,v).href)),children:[(0,Y.jsx)(je,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:qs(e.label,h)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Y.jsx)(Ne,{heading:h(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Y.jsxs)(Ut,{value:`page ${qs(e.label,h)} ${e.pageName}`,onSelect:()=>y(()=>u(ao(e,g,v).href)),children:[(0,Y.jsx)(xr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:qs(e.label,h)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Y.jsx)(Ne,{heading:h(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Y.jsxs)(Ut,{value:`report ${qs(e.label,h)} ${e.reportName}`,onSelect:()=>y(()=>u(ao(e,g,v).href)),children:[(0,Y.jsx)(Wr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:qs(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(un,{}),(0,Y.jsx)(Ne,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=zs(e.icon);return(0,Y.jsxs)(Ut,{value:`app ${qs(e.label,h)} ${e.name}`,onSelect:()=>y(()=>r(e.name)),children:[(0,Y.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:qs(e.label,h)}),e.name===t?.name&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:h(`console.commandPalette.current`)})]},e.name)})})]}),(0,Y.jsx)(un,{}),(0,Y.jsxs)(Ne,{heading:h(`console.commandPalette.preferences`),children:[(0,Y.jsxs)(Ut,{value:`theme light`,onSelect:()=>y(()=>p(`light`)),children:[(0,Y.jsx)($n,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Y.jsxs)(Ut,{value:`theme dark`,onSelect:()=>y(()=>p(`dark`)),children:[(0,Y.jsx)(Vi,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Y.jsxs)(Ut,{value:`theme system`,onSelect:()=>y(()=>p(`system`)),children:[(0,Y.jsx)(ra,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Y.jsx)(un,{}),(0,Y.jsxs)(Ne,{heading:h(`console.commandPalette.actions`),children:[(0,Y.jsxs)(Ut,{value:`create new app application`,onSelect:()=>y(()=>u(`${g}/create-app`)),children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.createApp`)})]}),(0,Y.jsxs)(Ut,{value:`search all results full page`,onSelect:()=>y(()=>u(`${g}/search`)),children:[(0,Y.jsx)(pr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})]})]})]})}function Qc(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Qc(n.children)):t.push(n);return t}function $c(){let{t:e}=F(),[t,n]=(0,J.useState)(!1),r=(0,J.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,J.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,Y.jsx)(it,{open:t,onOpenChange:n,children:(0,Y.jsxs)(xt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:e(`console.shortcuts.title`)}),(0,Y.jsx)(It,{children:e(`console.shortcuts.description`)})]}),(0,Y.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Y.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 el(){return null}var tl={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 nl({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,J.useState)(0),o=(0,J.useMemo)(()=>[tl.steps.connecting,tl.steps.loadingConfig,tl.steps.preparingWorkspace],[]);return(0,J.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,Y.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,Y.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,Y.jsx)(Tr,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,Y.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:Rc()}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:tl.initializing})]}),t?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,Y.jsx)(Hn,{className:`h-5 w-5 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold`,children:tl.error.connectionFailed})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:tl.error.checkServer})]}),n&&(0,Y.jsx)(G,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),tl.actions.retrying]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(tn,{className:`h-4 w-4`}),tl.actions.retry]})})]}):e?(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,Y.jsx)(Bt,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:o.map((e,t)=>(0,Y.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,Y.jsx)(Ga,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Y.jsx)(K,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,Y.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,Y.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}function rl(e){let{theme:t=`system`}=Ts();return(0,Y.jsx)(Ja,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,Y.jsx)(Ga,{className:`h-4 w-4`}),info:(0,Y.jsx)(Pt,{className:`h-4 w-4`}),warning:(0,Y.jsx)(fn,{className:`h-4 w-4`}),error:(0,Y.jsx)(la,{className:`h-4 w-4`}),loading:(0,Y.jsx)(K,{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 il=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function al({children:e,className:t}){let n=o(),r=J.useRef(null),i=J.useRef(n.pathname);return J.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...il),e.offsetWidth,e.classList.add(...il))},[n.pathname]),(0,Y.jsx)(`div`,{ref:r,className:[...il,t??``].filter(Boolean).join(` `),children:e})}var ol=null,sl=null;function cl(){return sl||(sl=(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 c(()=>import(`./vendor-sentry-DjMgMAaz.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=ul(e.data.url)),e}}),ol=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),sl)}function ll(e,t){if(ol)try{ol.captureException(e,t?{extra:t}:void 0)}catch{}}function ul(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 dl({error:e,onReset:t}){let{t:n}=F();return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,Y.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,Y.jsx)(fn,{className:`h-6 w-6 text-destructive`})}),(0,Y.jsx)(Ua,{children:n(`console.errors.somethingWentWrong`)}),(0,Y.jsx)(yt,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Y.jsx)(Oa,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Y.jsx)(mt,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var fl=class extends J.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),ll(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,Y.jsx)(dl,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function pl({sections:e,open:t}){if(!t)return null;let{t:n}=F(),[r,i]=(0,J.useState)([`0`]),[a,o]=(0,J.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,Y.jsxs)(`div`,{className:`w-80 border-l bg-background p-0 overflow-hidden flex flex-col shrink-0 z-20 transition-all`,children:[(0,Y.jsxs)(`div`,{className:`px-4 py-3 border-b bg-muted/5 flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:n(`layout.metadata.panelTitle`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60`,children:n(`layout.metadata.jsonBadge`)})]}),(0,Y.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,Y.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 hover:bg-muted/5 transition-colors`,children:[(0,Y.jsxs)(`button`,{onClick:()=>c(i),className:`flex-1 flex items-center justify-between text-left`,children:[(0,Y.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:e.title}),o?(0,Y.jsx)(jt,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Y.jsx)(qn,{className:`h-3 w-3 text-muted-foreground ml-2`})]}),(0,Y.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,Y.jsx)(Zi,{className:`h-3 w-3 text-green-600`}):(0,Y.jsx)(He,{className:`h-3 w-3 text-muted-foreground`})})]}),o&&(0,Y.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Y.jsx)(`div`,{className:`relative rounded-md border border-border/50 bg-muted/5 overflow-hidden`,children:(0,Y.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 ml(){let[e,t]=(0,J.useState)((0,J.useMemo)(()=>{try{return typeof window<`u`?de(window.location.search).enabled:!1}catch{return!1}},[]));return{showDebug:e,toggleDebug:()=>t(e=>!e)}}function hl({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s}){let{t:c}=F(),l=(0,J.useRef)(null),[u,d]=(0,J.useState)(!1);(0,J.useEffect)(()=>{e||d(!1)},[e]);let f=(0,J.useMemo)(()=>({id:`view_${Date.now()}`,label:c(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[],showSearch:!0,showFilters:!0,showSort:!0}),[]),p=(0,J.useMemo)(()=>({...r}),[n===`create`?`create`:r.id]),{draft:m,isDirty:h,updateField:g,discard:_,undo:v,redo:y,canUndo:b,canRedo:x}=Ea(n===`create`?f:p,{mode:n,onUpdate:a});(0,J.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,J.useMemo)(()=>Do(i),[i.fields]),C=(0,J.useMemo)(()=>Mo(m.filter),[m.filter]),w=(0,J.useMemo)(()=>xo(m.sort),[m.sort]),T=(0,J.useMemo)(()=>jo({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,J.useMemo)(()=>({...T,breadcrumb:[c(`console.objectView.page`),yo[E]||E]}),[T,c,E]),O=(0,J.useCallback)(()=>{n===`create`?s?.(m):o?.(m),_()},[m,o,s,n,_]),k=(0,J.useCallback)(()=>{if(n===`create`){t();return}_()},[_,n,t]),ee=c(n===`create`?`console.objectView.createView`:`console.objectView.configureView`),A=(0,Y.jsx)(G,{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,Y.jsx)(oi,{className:`h-3.5 w-3.5`})});return(0,Y.jsx)(zn,{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:ee,tabIndex:-1,testId:`view-config-panel`,closeTitle:c(`console.objectView.closePanel`),footerTestId:`view-config-footer`,saveTestId:`view-config-save`,discardTestId:`view-config-discard`,headerExtra:A,className:`transition-all overflow-hidden`})}function gl(e){return[{type:`grid`,icon:vi,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Li,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:zi,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Ie,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:rn,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:ui,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:ai,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Wr,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function _l(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var vl={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:ko}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:Co},{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:Co},{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:Co},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Eo},{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=>bo(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&Ao(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&Ao(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:ko},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function yl({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=F(),s=(0,J.useMemo)(()=>gl(o),[o]),c=(0,J.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,J.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,J.useMemo)(()=>a?Do(a):[],[a]),[d,f]=(0,J.useState)(c[0]?.type??`grid`),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)({});(0,J.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,J.useEffect)(()=>{h||m(_l(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=vl[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,J.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(vl[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,J.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=wo(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,Y.jsx)(it,{open:e,onOpenChange:t,children:(0,Y.jsxs)(xt,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:o(`console.objectView.createView`)}),(0,Y.jsx)(It,{children:o(`console.objectView.createViewDesc`)})]}),(0,Y.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,Y.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:B(`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,Y.jsx)(r,{className:B(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,Y.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,Y.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,Y.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,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,Y.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Y.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:B(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,Y.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,Y.jsx)(Hn,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Y.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Y.jsx)(W,{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,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Y.jsxs)(xn,{className:`mt-2`,children:[(0,Y.jsx)(G,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Y.jsx)(G,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var bl={config:{icon:oi,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:Cr,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:et,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:qr,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 xl({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=bl[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Y.jsx)(sn,{delayDuration:200,children:(0,Y.jsxs)(tt,{children:[(0,Y.jsx)(wi,{asChild:!0,children:(0,Y.jsxs)(U,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:B(`gap-1 font-normal text-[11px] leading-none py-0.5 px-1.5 cursor-help`,r.tone,n),children:[(0,Y.jsx)(i,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{children:r.short})]})}),(0,Y.jsxs)(Ye,{side:`bottom`,align:`start`,className:`max-w-xs text-xs leading-relaxed`,children:[(0,Y.jsx)(`p`,{className:`font-semibold mb-1`,children:r.title}),(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:r.body(a)})]})]})})}function Sl({cards:e=6}){return(0,Y.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(V,{className:`h-7 w-56`}),(0,Y.jsx)(V,{className:`h-4 w-80`})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:Array.from({length:4}).map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-20`}),(0,Y.jsx)(V,{className:`h-8 w-24`}),(0,Y.jsx)(V,{className:`h-3 w-16`})]},`stat-${t}`))}),(0,Y.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,Y.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(V,{className:`h-5 w-32`}),(0,Y.jsx)(V,{className:`h-5 w-5 rounded-full`})]}),(0,Y.jsx)(V,{className:`h-40 w-full`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3 w-16`}),(0,Y.jsx)(V,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Cl({fields:e=8,columns:t=2}){return(0,Y.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(V,{className:`h-8 w-8 rounded`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(V,{className:`h-6 w-48`}),(0,Y.jsx)(V,{className:`h-4 w-32`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-9 w-20`}),(0,Y.jsx)(V,{className:`h-9 w-20`})]})]}),(0,Y.jsx)(V,{className:`h-5 w-24`}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 ${t===2?`md:grid-cols-2`:``} gap-4`,children:Array.from({length:e}).map((e,t)=>(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-24`}),(0,Y.jsx)(V,{className:`h-9 w-full`})]},`field-${t}`))}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,Y.jsx)(V,{className:`h-5 w-32`}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:3}).map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 py-2`,children:[(0,Y.jsx)(V,{className:`h-8 w-8 rounded-full`}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(V,{className:`h-4 w-40`}),(0,Y.jsx)(V,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var wl={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 Tl(e){let t=wl[e?.managedBy??`platform`]??wl.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 El=new Set([`record:discussion`,`record:chatter`]);function Dl(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`&&El.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 Ol({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Y.jsx)(Sr,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Y.jsxs)(Nr,{children:[(0,Y.jsxs)(Rr,{children:[(0,Y.jsx)(Yr,{children:e.options?.title||`Confirm Action`}),(0,Y.jsx)(Oi,{children:e.message})]}),(0,Y.jsxs)(va,{children:[(0,Y.jsx)(sa,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Y.jsx)(Ui,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function kl({state:e,onOpenChange:t}){let{t:n}=F(),[r,i]=(0,J.useState)({}),[a,o]=(0,J.useState)({});(0,J.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,Y.jsx)(it,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(xt,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:n(`actionDialog.title`)}),(0,Y.jsx)(It,{children:n(`actionDialog.description`)})]}),(0,Y.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,Y.jsxs)(`div`,{className:`grid gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ut,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,Y.jsxs)(di,{htmlFor:e.name,className:`font-normal cursor-pointer`,children:[e.label,e.required&&(0,Y.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),a[e.name]&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Y.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,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsxs)(di,{htmlFor:e.name,children:[e.label,e.required&&(0,Y.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,Y.jsxs)(Cn,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,Y.jsx)(Wn,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,Y.jsx)(vt,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Y.jsx)(qa,{children:e.options.map(e=>(0,Y.jsx)(Be,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Y.jsx)(ba,{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,Y.jsx)(mn,{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,Y.jsx)(W,{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,Y.jsx)(W,{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,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Y.jsx)(G,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var Al=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),jl=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)}})),Ml=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}}})),Nl=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})),Pl=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})),Fl=n((e=>{var t=jl().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}})),Il=n((e=>{var t=jl().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Ll=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}})),Rl=n((e=>{var t=Ml(),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}}})),zl=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]]}})),Bl=n((e=>{var t=zl();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}})),Vl=n(((e,t)=>{var n=Bl();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})),Hl=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Ul=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)}})),Wl=n((e=>{var t=Hl(),n=Ul();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}}})),Gl=n((e=>{var t=jl(),n=Rl(),r=Ml(),i=Wl(),a=Hl(),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}})),Kl=n((e=>{var t=jl(),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}})),ql=n(((e,t)=>{var n=Wl();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})),Jl=n(((e,t)=>{var n=Wl(),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})),Yl=n(((e,t)=>{var n=Wl();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})),Xl=n(((e,t)=>{var n=Wl(),r=jl();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})),Zl=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)})),Ql=n((e=>{var t=Wl(),n=ql(),r=Jl(),i=Yl(),a=Xl(),o=Ul(),s=jl(),c=Zl();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()))}})),$l=n((e=>{var t=jl(),n=Ml(),r=Nl(),i=Pl(),a=Fl(),o=Il(),s=Ll(),c=Rl(),l=Vl(),u=Gl(),d=Kl(),f=Wl(),p=Ql();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)}})),eu=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}}})),tu=n((e=>{var t=eu();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)}})),nu=n((e=>{var t=eu();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}})),ru=n((e=>{var t=Al(),n=$l(),r=tu(),i=nu();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 iu(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function au({state:e,onAcknowledge:t}){let{t:n}=F(),{spec:r,data:i}=e,a=(0,J.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,Y.jsx)(it,{open:e.open,onOpenChange:e=>{},children:(0,Y.jsxs)(xt,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,Y.jsx)(It,{children:r.description}):null]}),(0,Y.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,Y.jsx)(ou,{field:e,value:e.path===``?i:iu(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,Y.jsx)(xn,{children:(0,Y.jsx)(G,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function ou({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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,Y.jsx)(lu,{value:t}):null,a===`code-list`?(0,Y.jsx)(uu,{value:t}):null,a===`secret`?(0,Y.jsx)(du,{value:t}):null,a===`text`?(0,Y.jsx)(fu,{value:t}):null,a===`json`?(0,Y.jsx)(pu,{value:t}):null]})}function su(e){let[t,n]=(0,J.useState)(!1);return(0,J.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 cu({value:e,label:t}){let{copy:n,copied:r}=su(e);return(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,Y.jsx)(Zi,{className:`w-4 h-4`}):(0,Y.jsx)(He,{className:`w-4 h-4`}),t?(0,Y.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function lu({value:e}){let[t,n]=(0,J.useState)(null);return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,Y.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,Y.jsx)(`canvas`,{ref:t=>{!t||!e||(0,ru.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,Y.jsx)(cu,{value:e})]})]})}function uu({value:e}){let t=e.join(`
|
|
10
|
+
`);return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,Y.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,Y.jsx)(cu,{value:e})]},`${t}-${e}`))})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(cu,{value:t,label:`Copy all`})})]})}function du({value:e}){let[t,n]=(0,J.useState)(!1);return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.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,Y.jsx)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,Y.jsx)(Lr,{className:`w-4 h-4`}):(0,Y.jsx)(_a,{className:`w-4 h-4`})}),(0,Y.jsx)(cu,{value:e})]})}function fu({value:e}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,Y.jsx)(cu,{value:e})]})}function pu({value:e}){let t=(0,J.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(cu,{value:t})})]})}function mu(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 hu(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??mu(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 gu(e,t){return Array.isArray(e)?e.map(e=>hu(e,t)):[]}function _u(){return`${``.replace(/\/$/,``)}/api/v1`}async function vu(e,t){let n=await fetch(`${_u()}${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 yu(e,t,n){let[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(!0),[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)([]),d=(0,J.useRef)(!1),f=(0,J.useCallback)(async()=>{if(!(!e||!t)&&!d.current){i(!0);try{let[n,r]=await Promise.all([vu(`/approvals/processes?object=${encodeURIComponent(e)}&activeOnly=true`),vu(`/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,J.useEffect)(()=>{if(!e||!t){c([]),u([]);return}f()},[e,t,f]);let p=(0,J.useMemo)(()=>l.find(e=>e.status===`pending`)??null,[l]);return{loading:r,available:a,processes:s,pendingRequest:p,latestRequest:(0,J.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,J.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 vu(`/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,J.useCallback)(async e=>{if(!p)throw Error(`No pending request`);let t=await vu(`/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 bu=t({RecordDetailView:()=>Du}),xu={id:`current-user`,name:`Demo User`},Su=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Cu=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),wu=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],Tu=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function Eu(e,t){if(Tu.has(t?.type))return!0;let n=e.toLowerCase();return wu.some(e=>n===e||n.endsWith(`_${e}`))}function Du({dataSource:e,objects:t,onEdit:n,objectNameOverride:r,recordIdOverride:a,embedded:c}){let l=f(),u=l.appName,d=r??l.objectName,p=a??l.recordId,{showDebug:m}=ml(),{user:h}=w(),g=s(),_=o().state?.from,{t:v}=F(),{objectLabel:y,viewLabel:b,sectionLabel:x,actionLabel:S,actionConfirm:C,actionSuccess:T,fieldLabel:E,fieldOptionLabel:O}=Kt(),{isFavorite:k,toggleFavorite:ee,refreshLabel:A}=Ss(),{addRecentItem:j}=eo(),[te,ne]=(0,J.useState)(!0),[re,M]=(0,J.useState)([]),[ie,ae]=(0,J.useState)([]),[P,oe]=(0,J.useState)(0),[se,ce]=(0,J.useState)({}),[ue,de]=(0,J.useState)(null),[fe,me]=(0,J.useState)(!1),[_e,ve]=(0,J.useState)(),I=t.find(e=>e.name===d);ds(c?void 0:_e);let L=p,R=bc(d,L),z=(0,J.useMemo)(()=>!d||!L?null:{id:`record:${d}:${L}`,label:_e||L||``,href:`/apps/${u}/${d}/record/${L}`,type:`record`},[u,d,L,_e]),xe=z?k(z.id):!1,Se=(0,J.useCallback)(()=>{z&&ee(z)},[z,ee]),{page:Ce,slots:we}=be(d),Te=(0,J.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 I?.detail?.renderViaSchema!==!1},[I]),Ee=(0,J.useMemo)(()=>Ce||!I||!Te&&!we?null:po(I,we?{slots:we}:void 0),[Te,Ce,we,I]),De=Ce||Ee,[Oe,ke]=(0,J.useState)(null),[Ae,je]=(0,J.useState)(`idle`);(0,J.useEffect)(()=>{let t=!1;if(!De||!L||!d||!e?.findOne){ke(null),je(`idle`);return}let n=pe(I?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{je(`loading`),(r?e.findOne(d,L,r):e.findOne(d,L)).then(e=>{t||(e&&typeof e==`object`?(ke(e),je(`loaded`)):(ke(null),je(`missing`)))}).catch(()=>{t||(ke(null),je(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==d||String(t.recordId)!==String(L)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[De,d,L,e,I]),(0,J.useEffect)(()=>{if(!Oe||typeof Oe!=`object`||!I)return;let e=Qs(I,Oe);e&&e!==`Untitled`&&e!==_e&&ve(e)},[Oe,I,_e]),(0,J.useEffect)(()=>{if(!d||!L||!u||!_e)return;let e=`record:${d}:${L}`;j({id:e,label:_e,href:`/apps/${u}/${d}/record/${L}`,type:`record`}),A(e,_e)},[u,d,L,_e,j,A]);let[Me,Ne]=(0,J.useState)({open:!1,message:``}),[Pe,Fe]=(0,J.useState)({open:!1,params:[]}),[B,V]=(0,J.useState)({open:!1}),Ie=(0,J.useCallback)((e,t)=>new Promise(n=>{V({open:!0,spec:e,data:t,resolve:n})}),[]),Le=(0,J.useCallback)((e,t)=>new Promise(n=>{Ne({open:!0,message:e,options:t,resolve:n})}),[]),Re=(0,J.useCallback)(e=>new Promise(n=>{Fe({open:!0,params:gu(e,{objectName:d||I?.name||``,objects:t||[],fieldLabel:E,fieldOptionLabel:O}),resolve:n})}),[d,I,t,E,O]),ze=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),Be=(0,J.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):g(e)},[g]),Ve=(0,J.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(d,L,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(d,L,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(d,L,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(d,L,r);break}let i=t.refreshAfter===!0;return i&&oe(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,d,L]),He=(0,J.useMemo)(()=>D(),[]),Ue=(0,J.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 He(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:L,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&&oe(e=>e+1),{success:!0,data:r?.data,reload:i}}catch(e){return{success:!1,error:e.message}}},[He,L,d]),We=(0,J.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 He(`/api/v1/actions/${encodeURIComponent(i)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:L,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&&oe(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}}},[He,L,d]),Ge=yu(d,L,h?.id),Ke=(0,J.useRef)(Ge);Ke.current=Ge;let qe=(0,J.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`submit_approval`)await Ke.current.submit({processName:n.processName,comment:n.comment});else if(t===`recall_approval`)await Ke.current.recall({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return oe(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Je=(0,J.useMemo)(()=>{if(!I||!t)return[];let e=new Set([`created_by`,`updated_by`,`owner_id`]),n=[],r=new Set;for(let i of t)if(i.name!==I.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)===I.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},[I,t]);(0,J.useEffect)(()=>{if(!e||!L||Je.length===0)return;let t=!1;return Promise.all(Je.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:L}}).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;ce(n)}),()=>{t=!0}},[e,L,Je]);let Ye=(0,J.useMemo)(()=>!I||I.name===`sys_audit_log`||I.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[I,t]);(0,J.useEffect)(()=>{if(!e||!L||!I||!Ye){de(null);return}let t=!1;return me(!0),e.find(`sys_audit_log`,{$filter:{record_id:L,object_name:I.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(I.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||me(!1)}),()=>{t=!0}},[e,L,I,Ye]),(0,J.useEffect)(()=>{if(!e)return;let t=!1,n=h?[{id:String(h.id),label:h.name||h.email||String(h.id),avatarUrl:h.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))];ae(o.length>0?o:n)}catch{if(t)return;ae(n)}})(),()=>{t=!0}},[e,h?.id,h?.name,h?.email]);let Xe=(0,J.useMemo)(()=>h?{id:h.id,name:h.name,avatar:h.image}:xu,[h?.id,h?.name,h?.image]);(0,J.useEffect)(()=>{if(!e||!d||!L)return;let t=`${d}:${L}`,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(Xe.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)}));M(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:L},$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&&M(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,L,Xe]);let Ze=(0,J.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Xe.name,actorAvatarUrl:`avatar`in Xe?Xe.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(M(e=>[...e,n]),e){let r=`${d}:${L}`,i=lo(t,ie);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Xe.id,author_name:Xe.name,author_avatar_url:`avatar`in Xe?Xe.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Xe,e,d,L,ie]),Qe=(0,J.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Xe.name,actorAvatarUrl:`avatar`in Xe?Xe.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(M(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${d}:${L}`,a=lo(n,ie);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Xe.id,author_name:Xe.name,author_avatar_url:`avatar`in Xe?Xe.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Xe,e,d,L,ie]),$e=(0,J.useCallback)((t,n)=>{M(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=Xe.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}))},[Xe.id,e]);(0,J.useEffect)(()=>{ne(!0),queueMicrotask(()=>ne(!1))},[d,p]);let et=(0,J.useMemo)(()=>{if(!I)return{type:`detail-view`};let n=I.primaryField||Object.keys(I.fields||{}).find(e=>e===`name`||e===`title`),r=I.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?x(I.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!I.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=I.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${I.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(I.fields||{}).filter(e=>!Su.has(e)&&!Cu.has(e)&&!I.fields[e]?.hidden),t=e=>{let t=I.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=>!Eu(e,I.fields[e])),r=e.filter(e=>Eu(e,I.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:e.map(t)}]:[{showBorder:!1,fields:n.map(t)},{name:`details`,title:x(I.name,`details`,v(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(I.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:S(I.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(I.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(I.name,e.name,e.successMessage)}}));return Ge.available&&Ge.processes.length>0&&(Ge.canSubmit&&t.push({name:`submit_approval`,type:`approval`,target:`submit_approval`,label:v(`approvals.submitForApproval`,{defaultValue:`Submit for Approval`}),icon:`send`,variant:`default`,locations:[`record_header`],refreshAfter:!0,successMessage:v(`approvals.submitSuccess`,{defaultValue:`Approval request submitted`}),...Ge.processes.length===1?{params:{processName:Ge.processes[0].name}}:{collectParams:[{name:`processName`,label:v(`approvals.process`,{defaultValue:`Process`}),type:`select`,required:!0,options:Ge.processes.map(e=>({value:e.name,label:e.label||e.name}))},{name:`comment`,label:v(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0}]}}),Ge.canRecall&&t.push({name:`recall_approval`,type:`approval`,target:`recall_approval`,label:v(`approvals.recall`,{defaultValue:`Recall`}),icon:`undo`,variant:`outline`,locations:[`record_header`],refreshAfter:!0,confirmText:v(`approvals.recallConfirm`,{defaultValue:`Recall this pending approval request?`}),successMessage:v(`approvals.recallSuccess`,{defaultValue:`Approval recalled`})})),t})(),o=I.views?.detail?.highlightFields??[],s=I.views?.detail?.sectionGroups??I.views?.form?.sectionGroups,l=u?`/apps/${u}`:``,d=Je.map(({childObject:n,childLabel:r,referenceField:i})=>{let a=t.find(e=>e.name===n),o=L||``,s=a?y({name:a.name,label:a.label||r}):r,c=()=>{let e=new URLSearchParams({[i]:o}).toString();return`${l}/${n}/new${e?`?${e}`:``}`},u=()=>{let e=new URLSearchParams({[`filter[${i}]`]:o}).toString();return`${l}/${n}${e?`?${e}`:``}`},d=e=>{let t=e?.id||e?._id;return t?`${l}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},f=e=>{let t=e?.id||e?._id;return t?`${l}/${n}/record/${encodeURIComponent(String(t))}`:null},p=l?()=>g(c()):void 0,m=l?()=>g(u()):void 0,h=l?e=>{let t=f(e);t&&g(t)}:void 0,_=l?e=>{let t=d(e);t&&g(t)}:void 0,b=e&&o?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),q.success(v(`detail.deleteSuccess`,{defaultValue:`Deleted`})),ce(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){q.error(e?.message||v(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:s,type:`table`,api:n,data:se[n]||[],referenceField:i,icon:a?.icon,displayField:a?.displayNameField||(Array.isArray(a?.compactLayout)?a.compactLayout[0]:void 0),onNew:p,onViewAll:m,onRowClick:h,onRowEdit:_,onRowDelete:b}}),f=Tl(I);return{type:`detail-view`,objectName:I.name,resourceId:L,showBack:!c,onBack:`history`,showEdit:f.edit,title:I.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...Ye&&{history:{entries:ue??[],loading:fe&&ue===null}},...d.length>0&&{related:d},...o.length>0&&{highlightFields:o},...s&&s.length>0&&{sectionGroups:s},...a.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:a}]}}},[I?.name,L,se,P,u,g,e,v,y,t,Ye,ue,fe,Ge.available,Ge.processes,Ge.canSubmit,Ge.canRecall,Ge.pendingRequest,Ge.latestRequest,c]);if(te)return(0,Y.jsx)(Cl,{});if(!I)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(Tr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:v(`empty.objectNotFound`)}),(0,Y.jsx)(yt,{children:v(`empty.objectNotFoundDescription`,{name:d})})]})});if(De&&Ae===`missing`)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(Tr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:v(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Y.jsx)(yt,{children:v(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(De){let t=De?.disableDiscussion===!0,r=Dl(De),a=!t&&!r,o=(()=>{let e=et.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),s=(()=>{let t=Tl(I),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:v(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:L,objectName:d}}))}}),r.push({name:`sys_edit`,label:v(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:L})})),r.push({name:`sys_share`,label:v(`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),q.success(v(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){q.error(v(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:v(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=v(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(d,L),q.success(v(`detail.deleted`,{defaultValue:`Record deleted`})),g(`${u?`/apps/${u}`:``}/${d}`,{replace:!0})}catch(e){q.error(e?.message||`Delete failed`)}}}),r})(),l=o.length>0?o:void 0,f=Array.isArray(et.related)?et.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,p=et.history?{entries:et.history.entries??[],loading:!!et.history.loading,emptyText:et.history.emptyText}:void 0,h=Ce?De:po(I,{sections:et.sections,highlightFields:Array.isArray(et.highlightFields)?et.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:l,related:f,history:p,hideReferenceRail:I?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:I?.detail?.hideRelatedTab===!0||void 0,...we?{slots:we}:{}});return(0,Y.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,Y.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[R.length>0&&(0,Y.jsx)(_c,{users:R,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(xl,{managedBy:I?.managedBy})]}),(0,Y.jsx)(ge,{objectName:d,recordId:L,data:Oe,objectSchema:I,dataSource:e,embedded:c,headerSystemActions:s,isFavorite:xe,onToggleFavorite:z?Se:void 0,children:(0,Y.jsx)(ye,{children:(0,Y.jsx)(he,{items:re,onAddComment:Ze,onAddReply:Qe,onToggleReaction:$e,mentionSuggestions:ie,children:(0,Y.jsx)(le,{context:{record:Oe||{},objectName:d,user:Xe},onConfirm:Le,onToast:ze,onNavigate:Be,onParamCollection:Re,onResultDialog:Ie,handlers:{api:Ve,flow:Ue,script:We,modal:We,approval:qe},children:(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[_?.pathname&&_?.label&&(0,Y.jsxs)(i,{to:_.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Y.jsx)(dt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:_.label})]}),(0,Y.jsx)(N,{schema:h}),a&&(0,Y.jsx)(`div`,{className:`mt-6`,children:(0,Y.jsx)(co,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:re,onAddComment:Ze,onAddReply:Qe,onToggleReaction:$e,mentionSuggestions:ie})})]}),(0,Y.jsx)(pl,{open:m,sections:[{title:`Page Schema`,data:h}]})]})})})})}),(0,Y.jsx)(Ol,{state:Me,onOpenChange:e=>{e||Ne(e=>({...e,open:!1}))}}),(0,Y.jsx)(kl,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(au,{state:B,onAcknowledge:()=>{B.resolve?.(),V({open:!1})}})]})}return(0,Y.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,Y.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[R.length>0&&(0,Y.jsx)(_c,{users:R,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(xl,{managedBy:I?.managedBy})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,Y.jsx)(le,{context:{record:{},objectName:d,user:Xe},onConfirm:Le,onToast:ze,onNavigate:Be,onParamCollection:Re,onResultDialog:Ie,handlers:{api:Ve,flow:Ue,script:We,modal:We,approval:qe},children:(0,Y.jsx)(uo,{schema:et,dataSource:e,objectLabel:y({name:I.name,label:I.label}),isFavorite:xe,onToggleFavorite:z?Se:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=Qs(I,e);t&&t!==_e&&t!==`Untitled`&&ve(t)},onEdit:()=>{n({id:L})},discussionSlot:(0,Y.jsx)(co,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:re,onAddComment:Ze,onAddReply:Qe,onToggleReaction:$e})},P)})}),(0,Y.jsx)(pl,{open:m,sections:[{title:`View Schema`,data:et}]})]}),(0,Y.jsx)(Ol,{state:Me,onOpenChange:e=>{e||Ne(e=>({...e,open:!1}))}}),(0,Y.jsx)(kl,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(au,{state:B,onAcknowledge:()=>{B.resolve?.(),V({open:!1})}})]})}function Ou(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 ku=(0,J.lazy)(()=>c(()=>import(`./plugin-charts-DrCI3cJo.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),Au=(0,J.lazy)(()=>c(()=>import(`./plugin-grid-DGQxmfxn.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),ju={grid:Ot,kanban:Li,calendar:zi,gallery:vi,timeline:Ci,gantt:rr,map:$r,chart:Wr},Mu={id:`current-user`,name:`Demo User`};function Nu(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 Pu(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 Fu(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 Iu({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=s(),{appName:a,objectName:c,viewId:u}=f(),[d,p]=l(),m=o(),{showDebug:h}=ml(),{t:g}=F(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:S,actionSuccess:C,fieldLabel:T,fieldOptionLabel:E}=Kt(),{isFavorite:k,toggleFavorite:ee}=Ss(),[A,j]=(0,J.useState)(!1),[te,ne]=(0,J.useState)(`edit`),[re,M]=(0,J.useState)(!1),[ae,P]=(0,J.useState)(!1),[oe,se]=(0,J.useState)(null),ce=(0,J.useRef)({}),ue=(0,J.useRef)({}),de=(0,J.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!c||!t)return;let i=ue.current[t]||{};ue.current[t]={...i,...r};let a=ce.current[t];a&&clearTimeout(a),ce.current[t]=setTimeout(()=>{let r=ue.current[t]||{};delete ue.current[t],delete ce.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),fe=(0,J.useCallback)(t=>{if(se(t),R(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]),pe=(0,J.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=Pu(l,c,{defaultColumns:o}),n=await e.create(`sys_view`,t);r=n?.id??n?._id}}j(!1),ne(`edit`),R(e=>e+1),r&&(u?i(`../${r}`,{relative:`path`}):i(`view/${r}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,c,t,i,u]),[me,he]=(0,J.useState)(void 0),{user:ge,activeOrganization:_e}=w(),ve=ge?.role===`admin`,{can:I}=O(),L=t.find(e=>e.name===c);if(!L)return(0,Y.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(Ot,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:g(`console.objectView.objectNotFound`)}),(0,Y.jsxs)(yt,{children:[g(`console.objectView.objectNotFoundDescription`,{objectName:c}),` `,g(`console.objectView.objectNotFoundHint`)]})]})});let[ye,R]=(0,J.useState)(0),be=(0,J.useMemo)(()=>Tl(L),[L]);(0,J.useEffect)(()=>{r===void 0||r===0||R(e=>e+1)},[r]);let[z,xe]=(0,J.useState)(!1),[Se,Ce]=(0,J.useState)([]);(0,J.useEffect)(()=>{let t=!1;if(!c){Ce([]);return}if(typeof e?.listViews==`function`)return e.listViews(c).then(e=>{t||Ce((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||Ce([])}),()=>{t=!0};if(!e?.find){Ce([]);return}return e.find(`sys_view`,{$filter:[`object_name`,`=`,c],$orderby:[{field:`created_at`,order:`asc`}],$top:200}).then(e=>{t||Ce((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(Fu))}).catch(e=>{console.error(`[ObjectView] Failed to load sys_view records:`,e),t||Ce([])}),()=>{t=!0}},[e,c,ye]);let[we,Te]=(0,J.useState)({});(0,J.useEffect)(()=>{let t=!1;if(!e||!c){Te({});return}let n=L.listViews||L.list_views||{},r=Object.keys(n),i=L.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){Te({});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||Te(e)}),()=>{t=!0}},[e,c,L.listViews,L.list_views,L.list,ye]);let Ee=(0,J.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(L.compactLayout)&&L.compactLayout.length>0?L.compactLayout.filter(e=>L.fields?.[e]):L.fields?Object.entries(L.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=L.listViews||L.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=we[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=L.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=we[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:g(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of Se){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:${L.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=Se.find(t=>(t.id||t._id)===e.id),a=Se.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},[L,Se,we,g]),De=(0,J.useMemo)(()=>Ee.find(e=>e.isDefault)?.id,[Ee]),Oe=u||d.get(`view`)||De||Ee[0]?.id,Ae=Ee.find(e=>e.id===Oe)||Ee[0],je=oe&&oe.id===Ae?.id?{...Ae,...oe}:Ae,Me=(0,J.useCallback)((e,t)=>{se(n=>({...n||{},id:Ae?.id,[e]:t}))},[Ae?.id]),Ne=e=>{let t=Ee.find(t=>t.id===e);t&&(t.id!==Oe&&j(!1),u?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Pe=(0,J.useMemo)(()=>(Ee||[]).map(e=>{let t=ju[e.type];return{id:e.id,label:y(L.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Y.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Ee,L.name,y]);Nc({views:Pe,activeViewId:Oe??``,onChange:Ne,enabled:Pe.length>0&&!!Oe});let Fe=(0,J.useCallback)(()=>{M(!0)},[]),B=(0,J.useCallback)((e,t)=>{if(e===`settings`){let e=Ee.find(e=>e.type===t);e&&Ne(e.id),ne(`edit`),j(!0)}},[Ee,Ne]),V=(0,J.useCallback)(e=>Se.some(t=>(t.id||t._id)===e),[Se]),Ie=(0,J.useCallback)(async(t,n)=>{if(!V(t)){q.error(g(`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}),R(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),q.error(g(`objectViewActions.renameFailed`))}},[e,c,V,g]),[Le,Re]=(0,J.useState)({open:!1,message:``}),[ze,Be]=(0,J.useState)({open:!1,params:[]}),[Ve,He]=(0,J.useState)({open:!1}),Ue=(0,J.useCallback)((e,t)=>new Promise(n=>{He({open:!0,spec:e,data:t,resolve:n})}),[]),We=(0,J.useCallback)((e,t)=>new Promise(n=>{Re({open:!0,message:e,options:t,resolve:n})}),[]),Ge=(0,J.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;Be({open:!0,params:gu(e,{objectName:c||L?.name||``,objects:t||[],fieldLabel:T,fieldOptionLabel:E,row:i}),resolve:r})}),[c,L,t,T,E]),Ke=(0,J.useCallback)(async t=>{if(!e)return;if(!V(t)){q.error(g(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Ee.find(e=>e.id===t)?.label||t;if(await We(g(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:g(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:g(`console.objectView.delete`)||`Delete`,cancelText:g(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`?await e.deleteView(c,t):e?.delete&&await e.delete(`sys_view`,t),t===Oe){let e=Ee.find(e=>e.id!==t);e&&i(u?`../${e.id}`:`view/${e.id}`,u?{relative:`path`}:void 0)}R(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),q.error(g(`objectViewActions.deleteFailed`))}},[e,V,Oe,Ee,u,i,g,We]),qe=(0,J.useCallback)(async t=>{if(!e)return;let n=Ee.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},l;if(typeof e?.createView==`function`)l=(await e.createView(c,s))?.name||r;else if(e?.create){let t=Pu(s,c),n=await e.create(`sys_view`,t);l=n?.id??n?._id}R(e=>e+1),l&&(u?i(`../${l}`,{relative:`path`}):i(`view/${l}`))}catch(e){console.error(`[ViewTabBar] Failed to duplicate view:`,e),q.error(`Failed to duplicate view`)}},[e,Ee,c,i,u]),Je=(0,J.useCallback)(async(t,n)=>{if(e){if(!V(t)){q.error(g(`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}),R(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,c,V,g]),Ye=(0,J.useCallback)(async t=>{if(e){if(!V(t)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to mark a default.`);return}try{let n=typeof e?.updateView==`function`,r=Se.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),R(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),q.error(`Failed to set default view`)}}},[e,c,Se,V,g]),Xe=(0,J.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(Se.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)}}R(e=>e+1)},[e,Se,c]),Ze=(0,J.useCallback)(e=>{if(!V(e)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==Oe&&Ne(e),ne(`edit`),j(!0)},[Oe,Ne,V,g]),Qe=(0,J.useCallback)(()=>{M(!0)},[]),$e=ge?{id:ge.id,name:ge.name,avatar:ge.image}:Mu,et=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),tt=ss({objectName:L.name,objectLabel:L.label,dataSource:e,onEdit:n,onRefresh:()=>R(e=>e+1),onConfirm:We,onToast:et}),rt=(0,J.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):i(e)},[i]),it=(0,J.useMemo)(()=>D(),[]),at=(0,J.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&&_e?.id&&(c.organizationId=_e.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 it(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&&R(e=>e+1),{success:!0,data:f,reload:t.refreshAfter!==!1}}typeof e.execute==`function`?await e.execute(L.name,n,r):r.recordId&&Object.keys(r).length>1&&typeof e.update==`function`&&await e.update(L.name,r.recordId,r);let a=t.refreshAfter!==!1;return a&&R(e=>e+1),{success:!0,reload:a}}catch(e){return{success:!1,error:e.message}}},[e,L.name,it,_e]),ot=(0,J.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 it(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,objectName:L.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&&R(e=>e+1),{success:!0,data:i?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[it,L.name]),st=(0,J.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||L.name||`global`,i=await it(`/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&&R(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[it,L.name]),{lastMessage:ct}=cc({channel:`object:${L.name}`}),{hasConflicts:lt,resolveAllConflicts:ut}=pc(L.name?`user-${L.name}`:`current-user`);(0,J.useEffect)(()=>{ct&&(lt&&ut(`remote`),R(e=>e+1))},[ct,lt,ut]),(0,J.useEffect)(()=>{e?.find&&L.name&&e.find(L.name,{limit:0}).then(e=>{typeof e?.total==`number`?he(e.total):Array.isArray(e?.data)?he(e.data.length):Array.isArray(e)&&he(e.length)}).catch(()=>{})},[e,L.name,ye]);let dt=(0,J.useMemo)(()=>je?.navigation??L.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[je?.navigation,L.navigation]),ft=d.get(`recordId`),pt=(0,J.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()]),mt=(0,J.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:m.pathname+(m.search||``),label:y(L.name,je?.name??``,je?.label??``)||_(L)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,u,m.pathname,m.search,L,je?.name,je?.label,y,_]),ht=ie({navigation:dt,objectName:L.name,onNavigate:mt}),gt=()=>{ht.close();let e=new URLSearchParams(d);e.delete(`recordId`),p(e)},_t=(0,J.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){ht.handleClick(e,t);return}if(ht.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),p(e);return}}ht.handleClick(e,t)},[ht,d,p]),vt=(0,J.useCallback)(()=>{let e=ht.selectedRecord,t=e&&(e.id??e._id);t!=null&&(gt(),mt(t))},[ht.selectedRecord,mt]);(0,J.useEffect)(()=>{ft&&!ht.isOpen?ht.open({id:ft}):!ft&&ht.isOpen&&ht.close()},[ft]);let bt=(0,J.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=ye+(i||0),o=`${c}-${je.id}-${a}`,s=je;if(s.type===`chart`){let e=s.chart||{};return(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Y.jsx)(ku,{dataSource:t,schema:{type:`object-chart`,objectName:L.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,Y.jsx)(fo,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=Nu(s.filter??e.filter,$e.id);return pt.length?[...Array.isArray(t)?t:[],...pt]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{de(s.id,s,{densityMode:e})},onSortChange:e=>{de(s.id,s,{sort:e})},onFilterChange:e=>{de(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{de(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{de(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(L?.actions)?L.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(L.name,s.name||s.id||``,s.emptyState??e.emptyState??Ou(L?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=Nu([...Array.isArray(s.filter)?s.filter:[],...pt],$e.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||L.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||L.titleField||`name`,descriptionField:s.timeline?.descriptionField},map:{locationField:s.map?.locationField,titleField:s.map?.titleField||L.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||L.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&&tt.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&tt.execute({type:`delete`,confirmText:g(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{_t(e,t)},onSortChange:e=>{de(s.id,s,{sort:e})},onFilterChange:e=>{de(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{de(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{de(s.id,s,{columnState:e})},dataSource:t},o)},[je,L,c,ye,ht,tt,de,pt]),xt=(0,J.useMemo)(()=>Ee.map(e=>e.id===Oe&&oe&&oe.id===e.id?{...e,...oe}:e),[Ee,Oe,oe]),St=(0,J.useMemo)(()=>({type:`object-view`,objectName:L.name,layout:`page`,showSearch:je?.showSearch!==!1,showFilters:je?.showFilters!==!1,showSort:je?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:ve,viewActions:ve?[{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:m.pathname+(m.search||``),label:y(L.name,je?.name??``,je?.label??``)||_(L)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[L,n,je?.showSearch,je?.showFilters,je?.showSort,je?.name,je?.label,i,u,ve,m.pathname,m.search,y,_]);return(0,Y.jsxs)(le,{context:{objectName:L.name,user:$e,apiBase:``,activeOrganization:_e?{id:_e.id,slug:_e.slug,name:_e.name}:null},onConfirm:We,onToast:et,onNavigate:rt,onParamCollection:Ge,onResultDialog:Ue,handlers:{api:at,flow:ot,script:st,modal:st},children:[(0,Y.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`hidden sm:block`,children:(0,Y.jsx)(Xc,{title:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:_(L)}),(0,Y.jsx)(xl,{managedBy:L?.managedBy})]}),description:L.description?v(L):void 0,icon:(0,Y.jsx)(zs(L?.icon),{className:`h-4 w-4`}),actions:(0,Y.jsxs)(Y.Fragment,{children:[c&&(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>ee({id:`object:${c}`,label:_(L),href:`/apps/${a}/${c}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":k(`object:${c}`),"aria-label":k(`object:${c}`)?g(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):g(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${c}`,children:k(`object:${c}`)?(0,Y.jsx)(vn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)(ke,{className:`h-4 w-4`})}),be.create&&I(L.name,`create`)&&(0,Y.jsxs)(G,{size:`sm`,onClick:tt.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Y.jsx)(H,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),be.import&&I(L.name,`create`)&&(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>xe(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:g(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Y.jsx)(_i,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.import`)})]}),L.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,Y.jsx)(N,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(L.actions||[]).map(e=>({...e,label:x(L.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:S(L.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:C(L.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),be.create&&I(L.name,`create`)&&(0,Y.jsx)(`button`,{type:`button`,onClick:tt.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":g(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Y.jsx)(H,{className:`h-5 w-5`})}),z&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Au,{open:z,onOpenChange:xe,objectName:L.name,objectLabel:_(L),fields:Object.entries(L.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{R(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?q.warning(g(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&q.success(g(`console.objectView.importedToast`,{count:t}))}})}),Ee.length>=1&&(()=>{let e=Ee.map(e=>{let t=Se.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(L.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?g(`console.objectView.systemViewReadonly`)||`System view defined in code — duplicate to customize.`:void 0}});return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,Y.jsx)(Oo,{views:e,activeViewId:Oe,onViewChange:Ne,viewTypeIcons:ju,config:{reorderable:!1,showAddButton:ve,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:ve?Qe:void 0,onRenameView:ve?Ie:void 0,onDeleteView:ve?Ke:void 0,onDuplicateView:ve?qe:void 0,onPinView:ve?Je:void 0,onSetDefaultView:ve?Ye:void 0,onConfigView:ve?Ze:void 0,onManageViews:ve?()=>P(!0):void 0}),ve&&(0,Y.jsx)(So,{open:ae,onOpenChange:P,views:e,activeViewId:Oe,viewTypeIcons:ju,onRename:Ie,onDelete:Ke,onDuplicate:qe,onSetDefault:Ye,onSetPinned:Je,onReorder:Xe,onAddView:Qe,onConfigView:Ze})]})})})(),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[ht.mode===`split`&&ht.isOpen?(0,Y.jsx)(Jt,{...ht,setIsOpen:e=>{e||gt()},title:_(L),onExpand:vt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${L.name}`,mainContent:(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Y.jsx)(To,{schema:St,dataSource:e,views:xt,activeViewId:Oe,onViewChange:Ne,onEdit:e=>n?.(e),onRowClick:(e,t)=>{_t(e,t)},renderListView:bt,onCreateView:Fe,onViewAction:B})})}),typeof me==`number`&&(0,Y.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:g(`console.objectView.recordCount`,{count:me})})]}),children:r=>{let i=r.id||r._id;return(0,Y.jsx)(Du,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}}):(0,Y.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,Y.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Y.jsx)(To,{schema:St,dataSource:e,views:xt,activeViewId:Oe,onViewChange:Ne,onEdit:e=>n?.(e),onRowClick:(e,t)=>{_t(e,t)},renderListView:bt,onCreateView:Fe,onViewAction:B})})})}),(0,Y.jsx)(pl,{open:h&&ve,sections:[{title:`View Configuration`,data:je},{title:`Object Definition`,data:L}]}),(0,Y.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${A&&ve?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Y.jsx)(hl,{open:A&&ve,onClose:()=>{j(!1),ne(`edit`)},mode:te,activeView:je,objectDef:L,recordCount:me,onSave:fe,onViewUpdate:Me,onCreate:pe})}),(0,Y.jsx)(yl,{open:re&&ve,onOpenChange:M,existingLabels:Ee.map(e=>e.label).filter(Boolean),objectDef:L,onCreate:e=>pe(e)})]}),ht.mode!==`split`&&(0,Y.jsx)(Jt,{...ht,setIsOpen:e=>{e||gt()},title:_(L),onExpand:vt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${L.name}`,children:r=>{let i=r.id||r._id;return(0,Y.jsx)(Du,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}})]}),(0,Y.jsx)(Ol,{state:Le,onOpenChange:e=>{e||Re({open:!1,message:``})}}),(0,Y.jsx)(kl,{state:ze,onOpenChange:e=>{e||Be({open:!1,params:[]})}}),(0,Y.jsx)(au,{state:Ve,onAcknowledge:()=>{Ve.resolve?.(),He({open:!1})}})]})}var Lu=t({RecordFormPage:()=>Ru});function Ru({mode:e}){let{appName:t,objectName:n,recordId:r}=f(),a=s(),[o]=l(),c=z(),{objects:u,loading:d}=ce(),{t:p}=F(),{objectLabel:m}=Kt(),{user:h,getAuthConfig:g}=w(),[_,v]=(0,J.useState)({});(0,J.useEffect)(()=>{let e=!1;return g().then(t=>{e||v(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[g]);let y=(0,J.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of o.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,o.toString()]),b=(0,J.useMemo)(()=>u.find(e=>e.name===n),[u,n]),x=`/apps/${t}`,S=`${x}/${n}`,C=e===`edit`&&r?`${x}/${n}/record/${encodeURIComponent(r)}`:S,T=(0,J.useCallback)(()=>{typeof window<`u`&&window.history.length>1?a(-1):a(C,{replace:!0})},[a,C]),E=b?m(b):n??``,D=e===`create`?p(`form.createTitle`,{object:E,defaultValue:`New ${E}`}):p(`form.editTitle`,{object:E,defaultValue:`Edit ${E}`}),O=(0,J.useCallback)(()=>{q.success(e===`create`?p(`form.createSuccess`,{object:E,defaultValue:`${E} created successfully`}):p(`form.updateSuccess`,{object:E,defaultValue:`${E} updated successfully`})),T()},[e,p,E,T]),k=(0,J.useCallback)(()=>{T()},[T]),ee=(0,J.useMemo)(()=>h?{name:h.name,email:h.email,role:h.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[h]),A=(0,J.useMemo)(()=>new I({user:ee,app:{name:t},data:{}}),[ee,t]),j=(0,J.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:os(e.visible,A)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>os(e.visible,A)).map(([e])=>e):[],[b,A]);return d?(0,Y.jsx)(Cl,{}):b?(0,Y.jsx)(is,{user:ee,app:{name:t},data:{},features:_,children:(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,Y.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,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":p(`common.back`,{defaultValue:`Back`}),children:(0,Y.jsx)(ja,{className:`h-4 w-4`})}),(0,Y.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Y.jsx)(i,{to:S,className:`hover:text-foreground transition-colors`,children:E}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:D}),(0,Y.jsx)(xl,{managedBy:b?.managedBy,className:`ml-1`})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,Y.jsx)(vo,{schema:{type:`object-form`,formType:`simple`,objectName:b.name,mode:e,recordId:e===`edit`?r:void 0,...y&&{initialValues:y},title:D,description:e===`create`?p(`form.createDescription`,{object:E,defaultValue:`Create a new ${E}.`}):p(`form.editDescription`,{object:E,defaultValue:`Edit this ${E}.`}),layout:`vertical`,fields:j,onSuccess:O,onCancel:k,showSubmit:!0,showCancel:!0,submitText:p(`form.saveRecord`,{defaultValue:`Save`}),cancelText:p(`common.cancel`,{defaultValue:`Cancel`})},dataSource:c??void 0},`${e}:${n}:${r??`new`}`)})})]})}):(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(Tr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:p(`empty.objectNotFound`)}),(0,Y.jsx)(yt,{children:p(`empty.objectNotFoundDescription`,{name:n})}),(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(G,{variant:`outline`,onClick:()=>a(x),children:[(0,Y.jsx)(ja,{className:`mr-2 h-4 w-4`}),p(`empty.back`)]})})]})})}var zu=t({DashboardView:()=>Yu}),Bu=[{type:`metric`,label:`KPI Metric`,Icon:ot},{type:`bar`,label:`Bar Chart`,Icon:Wr},{type:`line`,label:`Line Chart`,Icon:Oe},{type:`pie`,label:`Pie Chart`,Icon:Qn},{type:`table`,label:`Table`,Icon:ir},{type:`pivot`,label:`Pivot`,Icon:vi}],Vu=0;function Hu(){return Vu+=1,`widget_${Date.now()}_${Vu}`}function Uu(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:Hu()})}}function Wu(e){let t=Bu.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var Gu=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function Ku(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 qu(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))Gu.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 Ju(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 Yu({dataSource:e}){let{dashboardName:t}=f(),{showDebug:n}=ml(),r=z(),{t:i}=F(),{dashboardLabel:a,dashboardDescription:o}=Kt(),[s,c]=(0,J.useState)(!0),[l,u]=(0,J.useState)(!1),[d,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(0),[g,_]=(0,J.useState)(null),v=(0,J.useCallback)(e=>{_(t=>(t&&t.resolve(e),null))},[]),y=(0,J.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,J.useMemo)(()=>({export_dashboard_pdf:async()=>{q.info(i(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return q.error(i(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(q.info(i(`dashboardActions.forecastSoon`)),{success:!0})}),[i]);(0,J.useEffect)(()=>{c(!0),E(null),u(!1),p(null),queueMicrotask(()=>c(!1))},[t]);let{dashboards:x,objects:S,refresh:C}=ce(),w=x?.find(e=>e.name===t),[T,E]=(0,J.useState)(null);(0,J.useEffect)(()=>{l||E(null)},[w]);let D=(0,J.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),q.error(`Failed to save dashboard: ${t}`)}},[r,t,C]),O=(0,J.useCallback)(()=>{E(Uu(w)),u(!0),h(e=>e+1)},[w]),k=(0,J.useCallback)(()=>{u(!1),p(null)},[]),ee=(0,J.useCallback)(e=>{if(!T)return;let t=Hu(),n={id:t,title:Wu(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]),A=(0,J.useCallback)(e=>{if(!T)return;let t={...T,widgets:T.widgets.filter(t=>t.id!==e)};E(t),D(t),d===e&&p(null)},[T,d,D]),j=(0,J.useCallback)(e=>{let t=T||w;if(!t)return;let n={...t,widgets:e};E(n),D(n)},[T,w,D]),te=(0,J.useMemo)(()=>Ju(T||w),[m]),ne=(0,J.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]),re=(0,J.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]),M=T?.widgets?.find(e=>e.id===d),N=(0,J.useMemo)(()=>M?Ku(M):{},[d,m]),ie=(0,J.useCallback)(e=>{if(!T||!d||!M)return;let t=qu(e,M),n={...T,widgets:T.widgets.map(e=>e.id===d?{...e,...t}:e)};E(n),D(n),h(e=>e+1)},[T,d,M,D]),ae=(0,J.useCallback)((e,t)=>{d&&E(n=>{if(!n)return n;let r=n.widgets?.find(e=>e.id===d);if(!r)return n;let i=Ku(r);i[e]=t;let a=qu(i,r);return{...n,widgets:n.widgets.map(e=>e.id===d?{...e,...a}:e)}})},[d]),P=(0,J.useMemo)(()=>{if(S?.length)return S.map(e=>({value:e.name,label:e.label||e.name}))},[S]),oe=(0,J.useMemo)(()=>{let e=M?.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}))},[M?.object,S]),se=(0,J.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),le=T||w,ue=(0,J.useMemo)(()=>{if(!le||se.size===0)return le;let e=le.widgets;if(!Array.isArray(e)||e.length===0)return le;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?se.has(t):!0});return t.length===e.length?le:{...le,widgets:t}},[le,se]);return s?(0,Y.jsx)(Sl,{}):w?(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=qs((ue||w).title,i),t=qs(w.label,i),n=a({name:w.name,label:t});return(0,Y.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||w.name})})(),(()=>{let e=(ue||w).description??w.description,t=o({name:w.name,description:qs(e,i)});return t?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,Y.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[l&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:Bu.map(({type:e,label:t,Icon:n})=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>ee(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,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,Y.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,Y.jsx)(ht,{className:`h-3.5 w-3.5`}),i(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,Y.jsx)(No,{schema:ue,dataSource:e,designMode:l,selectedWidgetId:d,onWidgetClick:p,onWidgetsReorder:j,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),M?(0,Y.jsx)(Po,{open:l,onClose:k,config:N,onSave:ie,onFieldChange:ae,availableObjects:P,availableFields:oe,headerExtra:(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>A(d),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"data-testid":`widget-delete-button`,title:`Delete widget`,children:(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})},d):(0,Y.jsx)(Fo,{open:l,onClose:k,config:te,onSave:ne,onFieldChange:re}),(0,Y.jsx)(pl,{open:n,sections:[{title:`Dashboard Configuration`,data:ue}]})]}),g&&g.schema?.objectName?(0,Y.jsx)(go,{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,Y.jsx)(it,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,Y.jsxs)(xt,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,Y.jsx)(It,{children:g.schema.description})]}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:()=>v({success:!1}),children:i(`actionDialog.cancel`)}),(0,Y.jsx)(G,{onClick:()=>v({success:!0}),children:i(`actionDialog.ok`)})]})]})}):null]}):(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(je,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:i(`empty.dashboardNotFound`)}),(0,Y.jsx)(yt,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Xu=t({PageView:()=>Zu});function Zu(){let{t:e}=F(),{pageName:t}=f(),[n]=l(),{showDebug:r}=ml(),{pages:i}=ce(),a=i?.find(e=>e.name===t);if(!a)return(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(xr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:e(`empty.pageNotFound`)}),(0,Y.jsx)(yt,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let o=Object.fromEntries(n.entries());return(0,Y.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:(0,Y.jsx)(N,{schema:{...a,type:a.type||`page`,context:{...a.context,params:o}}})}),(0,Y.jsx)(pl,{open:r,sections:[{title:`Page Configuration`,data:a}]})]})}var Qu=t({ReportView:()=>rd}),$u=(0,J.lazy)(()=>c(()=>import(`./plugin-report-CJSBthhg.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),ed=(0,J.lazy)(()=>c(()=>import(`./plugin-report-CJSBthhg.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),td=(0,J.lazy)(()=>c(()=>import(`./plugin-report-CJSBthhg.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),nd=[{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 rd({dataSource:e}){let{t}=F(),{reportName:n}=f(),{showDebug:r}=ml(),i=z(),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(0),{reports:l,objects:u,loading:d,refresh:p}=ce(),m=l?.find(e=>e.name===n),[h,g]=(0,J.useState)(m),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)([]),[x,S]=(0,J.useState)(!1),C=(0,J.useCallback)(e=>{if(!e||!u?.length)return;let t=u.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`}))},[u]),w=(0,J.useMemo)(()=>{let e=_||h;return C(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??nd},[_,h,C]),T=(0,J.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,J.useCallback)(()=>{v(h),o(!0),c(e=>e+1)},[h]),D=(0,J.useCallback)(()=>{o(!1)},[]),O=(0,J.useMemo)(()=>_||h,[s]),k=(0,J.useCallback)(e=>{v(e),T(e),c(e=>e+1)},[T]),ee=(0,J.useCallback)((e,t)=>{v(n=>({...n,[e]:t}))},[]);(0,J.useEffect)(()=>{g(m)},[m]),(0,J.useEffect)(()=>{a||v(null)},[m]);let A=_||h,j=(0,J.useMemo)(()=>JSON.stringify(A?.filters),[A?.filters]),te=(0,J.useMemo)(()=>JSON.stringify(A?.dataSource),[A?.dataSource]),ne=(0,J.useMemo)(()=>JSON.stringify(A?.data),[A?.data]);if((0,J.useEffect)(()=>{if(!A||!e){b([]);return}if(A.data&&Array.isArray(A.data)){b(A.data);return}if(A.dataSource){(async()=>{S(!0);try{let t=A.dataSource.object||A.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),b([]);return}b((await e.find(t,{$filter:A.dataSource.filter,$orderby:A.dataSource.sort,$top:A.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),b([])}finally{S(!1)}})();return}if(A.objectName){(async()=>{S(!0);try{b((await e.find(A.objectName,{$filter:A.filters,$orderby:A.sort,$top:A.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),b([])}finally{S(!1)}})();return}b([])},[A?.objectName,A?.limit,j,te,ne,e]),d)return(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsx)(K,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!m||!h)return!d&&!m?(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Y.jsx)(Wr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(Ua,{children:t(`empty.reportNotFound`)}),(0,Y.jsx)(yt,{children:t(`empty.reportNotFoundDescription`,{name:n})})]})}):(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsx)(K,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let re=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?u?.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},M=_||h,N=!!(M&&M.objectName&&(M.type===`matrix`||M.type===`joined`||M.type===`summary`||M.type===`tabular`||M.type===void 0||Array.isArray(M.groupingsAcross)&&M.groupingsAcross.length>0||Array.isArray(M.columns))),ie={type:`report-viewer`,report:re(M),data:y,showToolbar:!0,allowExport:!0,loading:x};return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:M.title||M.label||`Report Viewer`}),M.description&&(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:M.description})]}),(0,Y.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,Y.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,Y.jsx)(ht,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,Y.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:N?(0,Y.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Y.jsx)(ed,{schema:M,dataSource:e})}):(0,Y.jsx)($u,{schema:ie})})})}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(td,{open:a,onClose:D,config:O,onSave:k,onFieldChange:ee,availableFields:w,getFieldsForObject:C})}),(0,Y.jsx)(pl,{open:r,sections:[{title:`Report Configuration`,data:M}]})]})]})}var id=t({SearchResultsPage:()=>cd});function ad(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...ad(n.children)):t.push(n);return t}var od={object:Tr,dashboard:je,page:xr,report:Wr},sd={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 cd(){let{t:e}=F(),{appName:t}=f(),[n,r]=l(),[a,o]=(0,J.useState)(n.get(`q`)||``),{apps:s}=ce(),c=s||[],u=c.find(e=>e.name===t)||c[0],d=`/apps/${t}`,{user:p}=w(),m=(0,J.useMemo)(()=>{if(!u)return[];let e=ad(u.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=ao(e,d,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!==`#`)},[u,d,p?.id]),h=(0,J.useMemo)(()=>{if(!a.trim())return m;let e=a.toLowerCase();return m.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[m,a]),g=e=>{o(e),r(e?{q:e}:{})},_=(0,J.useMemo)(()=>{let e={};for(let t of h)(e[t.type]||=[]).push(t);return e},[h]);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(i,{to:d,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Y.jsx)(ja,{className:`h-4 w-4`}),e(`search.back`)]}),(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`search.title`)})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:e(`search.placeholder`)}),(0,Y.jsx)(pr,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{id:`search-results-input`,value:a,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.trim()?e(h.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:h.length,query:a}):e(`search.itemsAvailable`,{count:m.length})}),h.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,Y.jsx)(pr,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,Y.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:e(`search.noResults`)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:e(`search.noResultsHint`)})]}):(0,Y.jsx)(`div`,{className:`space-y-6`,children:Object.entries(_).map(([t,n])=>{let r=od[t]||Tr,a=`search.type${t.charAt(0).toUpperCase()}${t.slice(1)}s`;return`${t.charAt(0).toUpperCase()}${t.slice(1)}`,(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,Y.jsx)(r,{className:`h-4 w-4`}),e(a),(0,Y.jsx)(U,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,Y.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=od[t.type]||Tr,r=`search.badge${t.type.charAt(0).toUpperCase()}${t.type.slice(1)}`;return(0,Y.jsx)(i,{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,Y.jsx)(At,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Y.jsxs)(Xi,{className:`flex items-center gap-3 p-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${sd[t.type]||``}`,children:(0,Y.jsx)(n,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium truncate`,children:t.label}),t.description&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:t.description})]}),(0,Y.jsx)(U,{variant:`outline`,className:`text-xs shrink-0`,children:e(r)})]})})},t.id)})})]},t)})})]})}function ld(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 ud(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 dd=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=ld(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(ud)};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 fd(){let e=z();return(0,J.useMemo)(()=>e?new dd(e):null,[e])}var pd=0;function md(e=`nav`){return`${e}_${Date.now()}_${++pd}`}function hd(e,t){return[...e,t]}function gd(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:gd(e.children,t,n)}:e)}function _d(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:_d(i.children,t,n,r)}:i})}function vd(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function yd(){let e=z(),{apps:t,refresh:n}=ce(),{t:r}=F(),i=(0,J.useRef)(e);i.current=e;let a=(0,J.useRef)(n);a.current=n;let o=(0,J.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,J.useCallback)(e=>t.find(t=>t.name===e),[t]),c=(0,J.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=hd(a,{id:md(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,J.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=hd(a,{id:md(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=gd(i,`page`,t);if(vd(a,i))return;let c={...n,navigation:a};try{await o(e,c),q.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=gd(i,`dashboard`,t);if(vd(a,i))return;let c={...n,navigation:a};try{await o(e,c),q.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,J.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=_d(a,`page`,t,n);if(vd(c,a))return;let l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,J.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=_d(a,`dashboard`,t,n);if(vd(c,a))return;let l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.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,J.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,J.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,J.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,J.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,J.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,J.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await p(t,e,n)}},[t,p])}}function bd(){let{pages:e,dashboards:t,apps:n}=ce(),r=z(),i=(0,J.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=yd(),l=(0,J.useRef)(null),u=(0,J.useRef)(null),d=(0,J.useRef)(0),f=(0,J.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,J.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 xd=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Sd(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Cd(e){try{return decodeURIComponent(e)}catch{return e}}function wd({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=eo(),o=(0,J.useRef)(n);o.current=n,(0,J.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===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${Cd(t)}`,label:Cd(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!xd.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:Sd(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Sd(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Sd(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Td=`objectstack:ai-chat-conversation-id`;function Ed(e,t){return t?`${Td}:${e}:${t}`:`${Td}:${e}`}function Dd(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Od(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function kd(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 Ad(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=kd(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function jd(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 Md(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 Nd(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Pd(e){let{userId:t,scope:n,apiBase:r,activeId:i}=e,[a,o]=(0,J.useState)(void 0),[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(!!t),d=(0,J.useRef)(!0),f=(0,J.useRef)(void 0);return(0,J.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]),(0,J.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=Ed(t,n);return u(!0),(async()=>{try{if(i){let n=await jd(r,i);if(e)return;if(n){Od(s,n.id),o(n.id),c(Ad(n.messages)),f.current=t;return}Od(s,void 0)}else{let n=Dd(s);if(n){let i=await jd(r,n);if(e)return;if(i){o(i.id),c(Ad(i.messages)),f.current=t;return}Od(s,void 0)}}let n=await Md(r);if(e)return;Od(s,n.id),o(n.id),c(Ad(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,J.useCallback)(async()=>{if(!t)return;let e=Ed(t,n);u(!0);try{a&&await Nd(r,a),Od(e,void 0);let t=await Md(r);if(Od(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 Fd(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=Id(n.content);if(e)return e}}let t=e[e.length-1];return Id(t?.content)}function Id(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 Ld(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:Fd(e.messages)}}function Rd(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,J.useState)([]),[s,c]=(0,J.useState)(!!t),[l,u]=(0,J.useState)(void 0),[d,f]=(0,J.useState)(0),p=(0,J.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,J.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,J.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,J.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(Ld).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 zd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>bu).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Bd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>zu).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),Vd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Xu).then(e=>({default:e.PageView})),void 0,import.meta.url)),Hd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Qu).then(e=>({default:e.ReportView})),void 0,import.meta.url)),Ud=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>id).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),Wd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Lu).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),Gd=(0,J.lazy)(()=>c(()=>import(`./ComponentNavView-g_X1YUdk.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Kd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),qd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),Jd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Yd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Xd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Zd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sx).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),Qd=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ow).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),$d=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ow).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),ef=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ow).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),tf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Vf).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),nf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>qf).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),rf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Yf).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function af({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,J.useState)(`disconnected`),{user:i,getAuthConfig:a}=w(),c=z(),[l,u]=(0,J.useState)({});(0,J.useEffect)(()=>{let e=!1;return a().then(t=>{e||u(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[a]);let p=s(),m=o(),{appName:h}=f(),{apps:g,objects:v,loading:b,ensureType:x}=ce(),{t:S}=F(),{objectLabel:C}=Kt(),[T,E]=(0,J.useState)(!x);(0,J.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=g.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),O=g.find(e=>e.name===h)||D.find(e=>e.isDefault===!0)||D[0],[k,ee]=(0,J.useState)(!1),[A,j]=(0,J.useState)(null),[te,ne]=(0,J.useState)(0),{execute:re,runner:N}=ae();M({dataSource:c??void 0,onUndo:e=>{q.info(`Undo: ${e.description}`,{duration:4e3}),ne(e=>e+1)},onRedo:e=>{q.info(`Redo: ${e.description}`,{duration:3e3}),ne(e=>e+1)}}),(0,J.useEffect)(()=>{N.registerHandler(`crud_success`,async e=>(ee(!1),ne(e=>e+1),q.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),N.registerHandler(`dialog_cancel`,async()=>(ee(!1),{success:!0})),N.registerHandler(`navigate_create`,async e=>{let t=Gs({action:e,context:N.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(p(t.url),{success:!0}):t}),N.registerHandler(`navigate_edit`,async e=>{let t=Ks({action:e,context:N.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(p(t.url),{success:!0}):t})},[N,p,h]),(0,J.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 ie=m.pathname.split(`/`).filter(Boolean)[2];(ie===`view`||ie===`record`||ie===`page`||ie===`dashboard`||ie===`design`)&&(ie=``);let P=v.find(e=>e.name===ie),oe=(0,J.useCallback)(()=>{let e=P?C(P):S(`common.record`,{defaultValue:`Record`});re({type:`crud_success`,params:{message:A?S(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):S(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[re,A,P,C,S]),se=(0,J.useCallback)(()=>{re({type:`dialog_cancel`})},[re]);wd({pathname:m.pathname,appName:O?.name,objects:v});let le=e=>{let t=Ws({objectDef:P,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}j(e),ee(!0)},ue=e=>{p(`/apps/${e}`)},de=(0,J.useMemo)(()=>new I({user:i?{name:i.name,email:i.email,role:i.role??`user`}:{},app:O||{},data:A||{}}),[i,O,A]);if(!c||b||!T)return(0,Y.jsx)(nl,{});let fe=m.pathname.endsWith(`/create-app`),pe=m.pathname.includes(`/system`);return!O&&!fe&&!pe?(0,Y.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:S(`empty.noAppsConfigured`)}),(0,Y.jsx)(yt,{children:S(`empty.noAppsConfiguredDescription`)}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Y.jsx)(G,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:S(`empty.createFirstApp`)}),(0,Y.jsx)(G,{variant:`outline`,onClick:()=>p(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:S(`empty.systemSettings`)})]})]})}):!O&&(fe||pe)?(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Qd,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(tf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(rf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(nf,{})}),t]})}):(0,Y.jsxs)(is,{user:i?{name:i.name,email:i.email,role:i.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:O,data:{},features:l,children:[(0,Y.jsx)(bd,{}),(0,Y.jsxs)(Yc,{activeAppName:O.name,activeApp:O,onAppChange:ue,objects:v,connectionState:n,userId:i?.id,children:[(0,Y.jsx)(Zc,{apps:g,activeApp:O,objects:v,onAppChange:ue,dataSource:c}),(0,Y.jsx)($c,{}),(0,Y.jsx)(el,{}),(0,Y.jsx)(fl,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(al,{className:`h-full`,children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/`,element:(()=>{let e=lf(O,{currentUserId:i?.id??null});return e?(0,Y.jsx)(_,{to:e,replace:!0}):(0,Y.jsx)(qd,{})})()}),(0,Y.jsxs)(d,{path:`metadata`,children:[(0,Y.jsx)(d,{index:!0,element:(0,Y.jsx)(Kd,{})}),(0,Y.jsx)(d,{path:`_diagnostics`,element:(0,Y.jsx)(Zd,{})}),(0,Y.jsx)(d,{path:`:type`,element:(0,Y.jsx)(Jd,{})}),(0,Y.jsx)(d,{path:`:type/new`,element:(0,Y.jsx)(Yd,{createMode:!0})}),(0,Y.jsx)(d,{path:`:type/:name`,element:(0,Y.jsx)(Yd,{})}),(0,Y.jsx)(d,{path:`:type/:name/history`,element:(0,Y.jsx)(Xd,{})})]}),(0,Y.jsx)(d,{path:`:objectName`,element:(0,Y.jsx)(Iu,{dataSource:c,objects:v,onEdit:le,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/new`,element:(0,Y.jsx)(Wd,{mode:`create`})}),(0,Y.jsx)(d,{path:`:objectName/view/:viewId`,element:(0,Y.jsx)(Iu,{dataSource:c,objects:v,onEdit:le,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId`,element:(0,Y.jsx)(zd,{dataSource:c,objects:v,onEdit:le},te)}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId/edit`,element:(0,Y.jsx)(Wd,{mode:`edit`})}),(0,Y.jsx)(d,{path:`dashboard/:dashboardName`,element:(0,Y.jsx)(Bd,{dataSource:c})}),(0,Y.jsx)(d,{path:`report/:reportName`,element:(0,Y.jsx)(Hd,{dataSource:c})}),(0,Y.jsx)(d,{path:`page/:pageName`,element:(0,Y.jsx)(Vd,{})}),(0,Y.jsx)(d,{path:`component/:ns/:name/*`,element:(0,Y.jsx)(Gd,{})}),(0,Y.jsx)(d,{path:`component/metadata/directory`,element:(0,Y.jsx)(ff,{mode:`directory`})}),(0,Y.jsx)(d,{path:`component/metadata/resource/*`,element:(0,Y.jsx)(ff,{mode:`resource`})}),(0,Y.jsx)(d,{path:`design/dashboard/:dashboardName`,element:(0,Y.jsx)(ef,{})}),(0,Y.jsx)(d,{path:`search`,element:(0,Y.jsx)(Ud,{})}),(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Qd,{})}),(0,Y.jsx)(d,{path:`edit-app/:editAppName`,element:(0,Y.jsx)($d,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(tf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(rf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(nf,{})}),e,(0,Y.jsx)(d,{path:`:objectName/:maybeRecordId`,element:(0,Y.jsx)(pf,{})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(mf,{})})]})})})}),P&&(0,Y.jsx)(go,{schema:{type:`object-form`,formType:`modal`,objectName:P.name,mode:A?`edit`:`create`,recordId:A?.id,title:S(A?`form.editTitle`:`form.createTitle`,{object:C(P)}),description:S(A?`form.editDescription`:`form.createDescription`,{object:C(P)}),open:k,onOpenChange:ee,layout:`vertical`,fields:P.fields?Array.isArray(P.fields)?P.fields.filter(e=>typeof e==`string`?!0:os(e.visible,de)).map(e=>typeof e==`string`?e:e.name):Object.entries(P.fields).filter(([e,t])=>os(t.visible,de)).map(([e])=>e):[],onSuccess:oe,onCancel:se,showSubmit:!0,showCancel:!0,submitText:A?S(`form.update`,{defaultValue:S(`common.save`,{defaultValue:`Save`})}):S(`form.create`,{defaultValue:S(`common.create`,{defaultValue:`Create`})}),cancelText:S(`common.cancel`)},dataSource:c},A?.id||`new`)]})]})}function of(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=sf(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=of(n.children,t);if(e!==``)return e}}return``}function sf(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=ao(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function cf(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=cf(n.children,t);if(e)return e}}}function lf(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=sf(cf(r,n),t);if(e)return e}return of(r,t)}var uf=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function df(e){return!e||uf.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function ff({mode:e}){let t=o(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Y.jsx)(_,{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,Y.jsx)(_,{to:r?`${n}/metadata/${encodeURIComponent(r)}${i}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function pf(){let{objectName:e,maybeRecordId:t}=f(),n=o();return e&&df(t)?(0,Y.jsx)(_,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Y.jsx)(mf,{})}function mf(){let e=s(),{t}=F();return(0,Y.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Y.jsx)(yt,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsx)(G,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function hf({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,J.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,Y.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,Y.jsx)(`span`,{className:i,children:s})})}function gf(){let e=s(),{appName:t}=f(),{t:n}=F(),r=t?`/apps/${t}`:`/`;return(0,Y.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,Y.jsx)(At,{children:(0,Y.jsxs)(Xi,{className:`flex flex-col items-center gap-4 py-12 text-center`,children:[(0,Y.jsx)(`div`,{className:`rounded-full bg-muted p-3`,children:(0,Y.jsx)(Cr,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:n(`marketplace.accessDenied.title`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:n(`marketplace.accessDenied.description`)})]}),(0,Y.jsx)(G,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var _f=`en`;function vf(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function yf(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function bf(e,t,n){if(!e)return;let r=vf(t),i=yf([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),_f]);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 xf(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 Sf(e,t){let n=t||_f;return{displayName:bf(e.translations??void 0,n,`displayName`)??xf(e,`displayName`)??e.manifest_id,description:bf(e.translations??void 0,n,`description`)??xf(e,`description`),readme:bf(e.translations??void 0,n,`readme`)??xf(e,`readme`),tagline:bf(e.translations??void 0,n,`tagline`)??xf(e,`tagline`)}}var Cf=``.replace(/\/$/,``),wf=`${Cf}/api/v1/marketplace`;async function Tf(e,t){let n=await fetch(`${wf}${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 Ef(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 Tf(`/packages${n?`?${n}`:``}`)}async function Df(e){return Tf(`/packages/${encodeURIComponent(e)}`)}async function Of(e){let t=Bc()||Cf,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 kf(){let e=Bc()||Cf,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 Af(){let e=Bc()||Cf,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 jf(e){return`${Bc()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function Mf(e,t){if(!e||!t)return null;let n=Bc()||Cf,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 Nf(e){if(!e)return{ok:!1,error:`installation id required`};let t=Bc()||Cf;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 Pf(e){if(!e)return{ok:!1,error:`installation id required`};let t=Bc()||Cf;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 Ff(e){let t=await fetch(`${wf}/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 If(){try{let e=await fetch(`${wf}/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 Lf(e){let t=await fetch(`${wf}/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 Rf(e,t){let n=await fetch(`${wf}/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 zf(e){return Rf(e,`reseed`)}function Bf(e){return Rf(e,`purge`)}var Vf=t({MarketplacePage:()=>Uf});function Hf(){let{language:e,t}=F();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 Uf(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=F(),a=Hf(),o=t?`/apps/${t}`:``,[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(!0),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(``),[y,b]=(0,J.useState)([]),x=(0,J.useMemo)(()=>{let e=new Map;for(let t of y)e.set(t.manifestId,t);return e},[y]),S=async()=>{d(!0),m(null);try{let[e,t]=await Promise.all([Ef({limit:100}),If()]);l(e.items??[]),b(t)}catch(e){m(e?.message??String(e)),l([])}finally{d(!1)}};(0,J.useEffect)(()=>{S()},[]);let w=(0,J.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,J.useMemo)(()=>{let e=h.trim().toLowerCase();return c.filter(t=>{if(_&&t.category!==_)return!1;if(!e)return!0;let n=Sf(t,i);return`${n.displayName} ${t.manifest_id} ${n.description??``}`.toLowerCase().includes(e)})},[c,h,_,i]);return n?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lr,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,Y.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.title`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:r(`marketplace.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/installed`),children:[(0,Y.jsx)(Mi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),y.length>0?r(`marketplace.installedCount`,{count:y.length}):r(`marketplace.installed`)]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void S(),disabled:u,children:[(0,Y.jsx)(yi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(pr,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{value:h,onChange:e=>g(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,Y.jsx)(G,{size:`sm`,variant:_===``?`default`:`outline`,onClick:()=>v(``),children:r(`marketplace.all`)}),w.map(e=>(0,Y.jsx)(G,{size:`sm`,variant:_===e?`default`:`outline`,onClick:()=>v(e),children:T(e)},e))]})]}),p&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium text-destructive`,children:r(`marketplace.load.failed`)}),(0,Y.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:p}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2`,dangerouslySetInnerHTML:{__html:r(`marketplace.load.failedHint`)}})]})]}),u&&c.length===0?(0,Y.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,Y.jsxs)(At,{children:[(0,Y.jsxs)(nr,{className:`pb-2`,children:[(0,Y.jsx)(V,{className:`h-10 w-10 rounded-lg mb-2`}),(0,Y.jsx)(V,{className:`h-5 w-3/4`}),(0,Y.jsx)(V,{className:`h-4 w-1/2 mt-1`})]}),(0,Y.jsx)(Xi,{children:(0,Y.jsx)(V,{className:`h-12 w-full`})})]},t))}):E.length===0?(0,Y.jsx)(`div`,{className:`text-center py-12 text-sm text-muted-foreground`,children:c.length===0?r(`marketplace.noApprovedYet`):r(`marketplace.noMatchFilters`)}):(0,Y.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:E.map(t=>{let n=x.get(t.manifest_id),s=Sf(t,i);return(0,Y.jsxs)(At,{className:`cursor-pointer transition-colors hover:bg-accent/50 flex flex-col`,onClick:()=>e(`${o}/system/marketplace/${t.id}`),role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(`${o}/system/marketplace/${t.id}`))},"data-testid":`marketplace-card-${t.manifest_id}`,children:[(0,Y.jsxs)(nr,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Y.jsx)(hf,{iconUrl:t.icon_url,displayName:s.displayName,manifestId:t.manifest_id}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(Zn,{className:`text-base truncate`,children:s.displayName}),(0,Y.jsx)(Et,{className:`text-xs truncate`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,Y.jsx)(U,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,Y.jsxs)(Xi,{className:`flex-1 flex flex-col gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:s.description||r(`marketplace.noDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-auto pt-2 flex-wrap`,children:[n&&(0,Y.jsxs)(U,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,Y.jsx)(Ga,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,Y.jsxs)(U,{variant:`outline`,className:`text-xs`,children:[(0,Y.jsx)(Br,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,Y.jsx)(U,{variant:`outline`,className:`text-xs`,children:T(t.category)}),t.latest_version?.published_at&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:a(t.latest_version.published_at)})]})]})]},t.id)})})]}):(0,Y.jsx)(gf,{})}function Wf(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 Gf(e){let t=[],n=e,r=0,i=[{re:/`([^`]+)`/,render:e=>(0,Y.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,Y.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e[1]},`k${r++}`)},{re:/\*([^*]+)\*/,render:e=>(0,Y.jsx)(`em`,{children:e[1]},`k${r++}`)},{re:/\[([^\]]+)\]\(([^)]+)\)/,render:e=>(0,Y.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,Y.jsx)(Y.Fragment,{children:t.map((e,t)=>(0,Y.jsx)(J.Fragment,{children:e},t))})}function Kf({source:e,className:t}){let n=Wf(e);return(0,Y.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,Y.jsx)(`h2`,{className:`mt-2 text-xl font-bold tracking-tight`,children:Gf(e.text??``)},t);case`h2`:return(0,Y.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:Gf(e.text??``)},t);case`h3`:return(0,Y.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:Gf(e.text??``)},t);case`p`:return(0,Y.jsx)(`p`,{children:Gf(e.text??``)},t);case`ul`:return(0,Y.jsx)(`ul`,{className:`ml-1 flex list-none flex-col gap-1.5`,children:(e.items??[]).map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Y.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,Y.jsx)(`span`,{children:Gf(e)})]},t))},t);case`ol`:return(0,Y.jsx)(`ol`,{className:`ml-5 flex list-decimal flex-col gap-1.5 marker:text-muted-foreground`,children:(e.items??[]).map((e,t)=>(0,Y.jsx)(`li`,{className:`pl-1`,children:Gf(e)},t))},t);case`code`:return(0,Y.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border bg-muted/40 p-3 text-xs leading-relaxed`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:e.text})},t)}return null})})}var qf=t({MarketplacePackagePage:()=>Jf});function Jf(){let e=s(),{packageId:t,appName:n}=f(),r=C(),{t:i,language:a}=F(),o=n?`/apps/${n}`:``,{refresh:c}=ce(),[l,u]=(0,J.useState)(null),[d,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)([]),[b,x]=(0,J.useState)(!1),[S,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(!1),[k,ee]=(0,J.useState)(!1),[A,j]=(0,J.useState)(null),[te,ne]=(0,J.useState)(null),[re,M]=(0,J.useState)(null),[N,ie]=(0,J.useState)(null),[ae,P]=(0,J.useState)(null),[oe,se]=(0,J.useState)([]),[le,ue]=(0,J.useState)(!1),[de,fe]=(0,J.useState)(null);(0,J.useEffect)(()=>{if(!Lc().features.installLocal)return;let e=!1;return(async()=>{let t=await If();e||se(t)})(),()=>{e=!0}},[t,de]),(0,J.useEffect)(()=>{if(!t)return;let e=Lc().defaultEnvironmentId;if(!e)return;let n=!1;return(async()=>{let r=await Mf(t,e);n||!r||(M(r),ne(r.version))})(),()=>{n=!0}},[t]),(0,J.useEffect)(()=>{let e=!1;return(async()=>{if(t){p(!0),h(null);try{let n=await Df(t);e||u(n)}catch(t){e||h(t?.message??String(t))}finally{e||p(!1)}}})(),()=>{e=!0}},[t]);let pe=async()=>{_(!0),j(null),w(null);let e=Lc().defaultEnvironmentId;if(e){x(!1),E(e),y([]);return}x(!0);try{let[e,t]=await Promise.all([kf(),Af()]),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{x(!1)}},me=async()=>{if(!(!t||!T)){ee(!0),j(null);try{ne(((await Of({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=Lc().defaultEnvironmentId||T;if(e){let n=await Mf(t,e);n&&M(n)}}catch{}let e=Lc().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{}j({ok:!0,message:i(`marketplace.install.success`)})}catch(e){j({ok:!1,message:e?.message??String(e)})}finally{ee(!1)}}},he=async()=>{if(t){ue(!0),fe(null);try{let e=await Ff({packageId:t});try{await c(`app`)}catch{}fe({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?Sf(l.package,a).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`)),fe({ok:!1,message:n})}finally{ue(!1)}}},ge=async()=>{if(z&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:z.manifestId,version:z.version}))){ue(!0),fe(null);try{await Lf(z.manifestId);try{await c(`app`)}catch{}fe({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:z.manifestId})})}catch(e){fe({ok:!1,message:e?.message??String(e)})}finally{ue(!1)}}},_e=async()=>{if(re){ie(`reseed`),P(null);try{let e=await Nf(re.installationId);e.ok?(M({...re,withSampleData:!0}),P({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):P({ok:!1,text:e.error||`Re-seed failed`})}finally{ie(null)}}},ve=async()=>{if(re&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ie(`purge`),P(null);try{let e=await Pf(re.installationId);if(e.ok){M({...re,withSampleData:!1});let t=e.deleted??0;P({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 P({ok:!1,text:e.error||`Purge failed`})}finally{ie(null)}}},I=async()=>{if(z){ie(`reseed`),P(null);try{let e=await zf(z.manifestId);se(e=>e.map(e=>e.manifestId===z.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;P({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){P({ok:!1,text:e?.message||`Re-seed failed`})}finally{ie(null)}}},L=async()=>{if(z&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ie(`purge`),P(null);try{let e=await Bf(z.manifestId);se(e=>e.map(e=>e.manifestId===z.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;P({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){P({ok:!1,text:e?.message||`Purge failed`})}finally{ie(null)}}};if(d)return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Y.jsx)(V,{className:`h-8 w-32`}),(0,Y.jsx)(V,{className:`h-16 w-full`}),(0,Y.jsx)(V,{className:`h-64 w-full`})]});if(m||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Y.jsx)(ja,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium text-destructive`,children:i(`marketplace.load.packageFailed`)}),(0,Y.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:m??i(`marketplace.load.notFound`)})]})]})]});let ye=l.package,R=Sf(ye,a),be=ye.latest_version?.version??l.versions[0]?.version??null,z=oe.find(e=>e.manifestId===ye.manifest_id)??null,xe=Lc().features.installLocal,Se=!be||le||k||!xe&&!!te,Ce=xe?{label:i(le?`marketplace.action.working`:z?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:he}:{label:k?i(`marketplace.action.installing`):te?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:pe},we=ye.category?i(`marketplace.category.${ye.category}`,{defaultValue:ye.category}):null;return r?(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Y.jsx)(ja,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,Y.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,Y.jsx)(hf,{iconUrl:ye.icon_url,displayName:R.displayName,manifestId:ye.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:R.displayName||ye.manifest_id}),ye.homepage_url&&(0,Y.jsxs)(`a`,{href:ye.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,Y.jsx)(Jr,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`marketplace.detail.homepage`)})]})]}),(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`code`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:ye.manifest_id}),be&&(0,Y.jsx)(U,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:be})}),ye.publisher&&ye.publisher!==`private`&&(0,Y.jsx)(U,{variant:ye.publisher===`objectstack`?`default`:`secondary`,children:ye.publisher}),we&&(0,Y.jsx)(U,{variant:`outline`,children:we}),ye.license&&(0,Y.jsx)(U,{variant:`outline`,className:`font-normal`,children:ye.license}),z&&(0,Y.jsxs)(U,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(Ga,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:z.version})]}),!z&&te&&(0,Y.jsxs)(U,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(Ga,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:te})]})]}),R.description&&(0,Y.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:R.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,Y.jsxs)(G,{onClick:Ce.onClick,disabled:Se,size:`lg`,className:`min-w-[8rem]`,children:[(0,Y.jsx)(ti,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),Ce.label]}),z&&(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsx)(G,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`),children:(0,Y.jsx)(Ki,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(Hi,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(jr,{onSelect:I,disabled:N!==null,children:[N===`reseed`?(0,Y.jsx)(K,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Tr,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),z.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(jr,{onSelect:L,disabled:N!==null||!z.withSampleData,className:`text-destructive focus:text-destructive`,children:[N===`purge`?(0,Y.jsx)(K,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Rt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,Y.jsxs)(jr,{onSelect:ge,disabled:le,className:`text-destructive focus:text-destructive`,children:[(0,Y.jsx)(Rt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!z&&re&&(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsx)(G,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`)||`More options`,children:(0,Y.jsx)(Ki,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(Hi,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(jr,{onSelect:_e,disabled:N!==null,children:[N===`reseed`?(0,Y.jsx)(K,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Tr,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),re.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(jr,{onSelect:ve,disabled:N!==null||!re.withSampleData,className:`text-destructive focus:text-destructive`,children:[N===`purge`?(0,Y.jsx)(K,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Rt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),ae&&(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${ae.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:[ae.ok?(0,Y.jsx)(Ga,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:ae.text}),(0,Y.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>P(null),children:i(`marketplace.action.dismiss`)})]}),de&&(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${de.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:[de.ok?(0,Y.jsx)(Ga,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:de.message}),(0,Y.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>fe(null),children:i(`marketplace.action.dismiss`)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,children:[(0,Y.jsx)(`div`,{className:`lg:col-span-2 space-y-4`,children:(0,Y.jsxs)(At,{children:[(0,Y.jsx)(nr,{children:(0,Y.jsx)(Zn,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,Y.jsx)(Xi,{children:R.readme?(0,Y.jsx)(Kf,{source:R.readme}):(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noReadme`)})})]})}),(0,Y.jsx)(`div`,{className:`space-y-4`,children:(0,Y.jsxs)(At,{children:[(0,Y.jsx)(nr,{children:(0,Y.jsx)(Zn,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,Y.jsx)(Xi,{children:l.versions.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noApprovedVersions`)}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:l.versions.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsxs)(`code`,{className:`font-mono`,children:[`v`,e.version]}),e.is_prerelease&&(0,Y.jsx)(U,{variant:`outline`,className:`text-xs`,children:i(`marketplace.detail.prerelease`)})]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.published_at?new Date(e.published_at).toLocaleDateString():`—`})]},e.id))})})]})})]}),(0,Y.jsx)(it,{open:g,onOpenChange:e=>{_(e),e||j(null)},children:(0,Y.jsxs)(xt,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:i(`marketplace.install.dialogTitle`,{name:R.displayName||ye.manifest_id})}),(0,Y.jsx)(It,{children:Lc().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),b?(0,Y.jsx)(V,{className:`h-10 w-full`}):S?(0,Y.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 text-sm space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 text-amber-600`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:S})]}),(0,Y.jsx)(`a`,{href:jf(ye.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,Y.jsx)(Jr,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):Lc().defaultEnvironmentId?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(di,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]}):v.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.install.noEnvs`)}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(di,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,Y.jsxs)(Cn,{value:T,onValueChange:E,children:[(0,Y.jsx)(Wn,{id:`env-select`,children:(0,Y.jsx)(vt,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,Y.jsx)(qa,{children:v.map(e=>(0,Y.jsxs)(Be,{value:e.id,children:[e.display_name||e.hostname||e.id,e.plan&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.plan]})]},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(di,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),A&&(0,Y.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${A.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:A.message}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:()=>_(!1),children:i(`marketplace.action.close`)}),!S&&(0,Y.jsx)(G,{onClick:me,disabled:!T||k||A?.ok===!0,children:i(k?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,Y.jsx)(gf,{})}var Yf=t({MarketplaceInstalledPage:()=>Xf});function Xf(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=F(),a=t?`/apps/${t}`:``,[o,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(!0),[d,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),g=async()=>{u(!0);try{c(await If())}finally{u(!1)}};(0,J.useEffect)(()=>{g()},[]);let _=async e=>{if(confirm(r(`marketplace.uninstall.confirm`,{manifestId:e.manifestId,version:e.version}))){p(e.manifestId),h(null);try{await Lf(e.manifestId),h({ok:!0,message:r(`marketplace.uninstall.successInList`,{manifestId:e.manifestId})}),await g()}catch(e){h({ok:!1,message:e?.message??String(e)})}finally{p(null)}}};return n?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-5xl`,children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`self-start`,onClick:()=>e(`${a}/system/marketplace`),children:[(0,Y.jsx)(ja,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.back`)]}),(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lr,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,Y.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.installedTitle`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedSubtitle`)}})]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void g(),disabled:l,children:[(0,Y.jsx)(yi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]}),m&&(0,Y.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${m.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,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{children:m.message})]})}),l&&o.length===0?(0,Y.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:3}).map((e,t)=>(0,Y.jsx)(V,{className:`h-20 w-full`},t))}):o.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-12 text-sm text-muted-foreground border rounded-md`,children:[(0,Y.jsx)(`p`,{children:r(`marketplace.installedEmpty`)}),(0,Y.jsx)(G,{variant:`link`,className:`mt-2`,onClick:()=>e(`${a}/system/marketplace`),children:r(`marketplace.browseLink`)})]}):(0,Y.jsx)(`div`,{className:`grid gap-3`,children:o.map(t=>(0,Y.jsxs)(At,{children:[(0,Y.jsxs)(nr,{className:`flex flex-row items-start justify-between gap-3 pb-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(Zn,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,Y.jsx)(U,{variant:`outline`,children:r(`marketplace.versionBadge`,{version:t.version})})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap gap-x-3 gap-y-1`,children:[(0,Y.jsx)(`span`,{children:r(`marketplace.installedAt`,{when:new Date(t.installedAt).toLocaleString(i||void 0)})}),t.installedBy&&(0,Y.jsx)(`span`,{children:r(`marketplace.installedBy`,{user:t.installedBy})}),(0,Y.jsxs)(`span`,{children:[r(`marketplace.installedPackageId`),` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:t.packageId})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>e(`${a}/system/marketplace/${t.packageId}`),children:[(0,Y.jsx)(Jr,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.action.details`)]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void _(t),disabled:d===t.manifestId,children:[(0,Y.jsx)(Rt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),d===t.manifestId?r(`marketplace.action.uninstalling`):r(`marketplace.action.uninstall`)]})]})]}),(0,Y.jsx)(Xi,{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,Y.jsx)(`p`,{className:`text-xs text-muted-foreground border-t pt-4`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedAdditiveNote`)}})]}):(0,Y.jsx)(gf,{})}function Zf({children:e,userId:t}){let{setContext:n}=us(),{isAiEnabled:r}=ne(),i=r||!1;return(0,J.useEffect)(()=>{n(`home`)},[n]),(0,Y.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,Y.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,Y.jsx)(Wc,{variant:`home`})}),(0,Y.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,Y.jsx)(Fs,{appLabel:`Workspace`,objects:[],userId:t})]})}var Qf=[{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 $f(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function ep({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=F(),{appLabel:a,appDescription:o}=Kt(),{toggleFavorite:s}=Ss(),c=zs(e.icon),l=a({name:e.name,label:qs(e.label,i)}),u=o({name:e.name,description:qs(e.description,i)}),d=e.branding?.primaryColor,f=Qf[($f(e.name)+r)%Qf.length];return(0,Y.jsxs)(At,{role:`button`,tabIndex:0,"aria-label":l,className:B(`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,Y.jsx)(`div`,{"aria-hidden":!0,className:B(`absolute inset-x-0 top-0 h-1`,d?``:f.solid),style:d?{backgroundColor:d}:void 0}),!d&&(0,Y.jsx)(`div`,{"aria-hidden":!0,className:B(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,f.from,f.to)}),(0,Y.jsxs)(Xi,{className:`relative p-5`,children:[(0,Y.jsx)(G,{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,Y.jsx)(vn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)(ke,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:B(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,d?``:B(`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,Y.jsx)(c,{className:B(`h-7 w-7`,d?``:f.text),style:d?{color:d}:void 0})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h3`,{className:`font-semibold text-base sm:text-lg leading-tight truncate`,children:l}),e.isDefault&&(0,Y.jsx)(U,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,Y.jsx)(`p`,{className:B(`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,Y.jsx)(`div`,{className:`mt-4 flex items-center justify-between text-xs font-medium`,children:(0,Y.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,Y.jsx)(Dr,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var tp={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`},np={object:Tr,record:xr,dashboard:je,page:fi};function rp({items:e}){let t=s(),{t:n}=F();return e.length===0?null:(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Y.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,Y.jsx)(rn,{className:`h-4 w-4`})}),(0,Y.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,Y.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=np[e.type]||Tr,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Js(e.type)}),a=tp[e.type]||tp.object;return(0,Y.jsx)(At,{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,Y.jsx)(Xi,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:B(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,a),children:(0,Y.jsx)(r,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,Y.jsx)(Dr,{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 ip={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`},ap={object:Tr,record:xr,dashboard:je,page:fi};function op({items:e}){let t=s(),{t:n}=F();return e.length===0?null:(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Y.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,Y.jsx)(vn,{className:`h-4 w-4 fill-current`})}),(0,Y.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,Y.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=ap[e.type]||Tr,i=ip[e.type]||ip.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Js(e.type)});return(0,Y.jsx)(At,{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,Y.jsx)(Xi,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:B(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,i),children:(0,Y.jsx)(r,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]}),(0,Y.jsx)(Dr,{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 sp(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function cp({t:e}){return(0,Y.jsx)(`section`,{"data-testid":`home-getting-started`,className:`rounded-2xl border border-border bg-card p-6 sm:p-8 shadow-sm`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Y.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,Y.jsx)(vn,{className:`h-5 w-5`})}),(0,Y.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,Y.jsx)(rn,{className:`h-5 w-5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:e(`home.gettingStarted.title`,{defaultValue:`Make this home yours`})}),(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:e(`home.gettingStarted.cta`,{defaultValue:`Browse all applications`})}),(0,Y.jsx)(Nn,{className:`h-3.5 w-3.5`})]})]})})}function lp({icon:e,value:t,label:n,tone:r}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full border border-border bg-card px-3 py-1.5 text-sm shadow-sm`,children:[(0,Y.jsx)(e,{className:`h-4 w-4 ${r}`}),(0,Y.jsx)(`span`,{className:`font-semibold tabular-nums`,children:t}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n})]})}function up(){let e=s(),{t}=F(),{apps:n,loading:r}=ce(),{recentItems:i}=eo(),{favorites:a}=Ss(),{user:o}=w(),c=C(),l=n.filter(e=>e.active!==!1&&e.hidden!==!0),u=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),d=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,8),f=(0,J.useMemo)(()=>t(sp(new Date().getHours()),{defaultValue:`Welcome`}),[t]),p=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,Y.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):l.length===0?(0,Y.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Y.jsx)(yt,{children:t(`home.welcomeDescription`,{defaultValue:`Get started by creating your first application or configure your system settings.`})}),(0,Y.jsxs)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Y.jsxs)(G,{onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),t(`home.createFirstApp`,{defaultValue:`Create Your First App`})]}),c&&(0,Y.jsxs)(G,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-empty-btn`,children:[(0,Y.jsx)(lr,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]}),(0,Y.jsxs)(G,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,Y.jsx)(Mi,{className:`mr-2 h-4 w-4`}),t(`home.systemSettings`,{defaultValue:`System Settings`})]})]})]})}):(0,Y.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Y.jsx)(`section`,{className:`px-4 sm:px-6 lg:px-8 pt-10 pb-6`,children:(0,Y.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-3`,children:[(0,Y.jsx)(yr,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`uppercase tracking-wider`,children:t(`home.title`,{defaultValue:`Home`})})]}),(0,Y.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-pretty`,children:[(0,Y.jsxs)(`span`,{className:`text-foreground`,children:[f,p?`, `:``]}),p&&(0,Y.jsx)(`span`,{className:`bg-gradient-to-r from-indigo-600 via-violet-600 to-fuchsia-600 bg-clip-text text-transparent dark:from-indigo-400 dark:via-violet-400 dark:to-fuchsia-400`,children:p}),(0,Y.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Y.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,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Y.jsx)(lp,{icon:vi,tone:`text-indigo-600 dark:text-indigo-400`,value:l.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Y.jsx)(lp,{icon:rn,tone:`text-sky-600 dark:text-sky-400`,value:i.length,label:t(`home.recentApps.title`,{defaultValue:`Recently Accessed`})}),a.length>0&&(0,Y.jsx)(lp,{icon:vn,tone:`text-amber-500 dark:text-amber-400`,value:a.length,label:t(`home.starredApps.title`,{defaultValue:`Starred`})})]})]})}),(0,Y.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pb-16`,children:(0,Y.jsxs)(`div`,{className:`max-w-7xl mx-auto space-y-10`,children:[d.length===0&&u.length===0&&(0,Y.jsx)(cp,{t}),d.length>0&&(0,Y.jsx)(op,{items:d}),u.length>0&&(0,Y.jsx)(rp,{items:u}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-end justify-between mb-5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Y.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground`,children:(0,Y.jsx)(vi,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[l.length,` · `,t(`home.stats.apps`,{defaultValue:`Applications`})]})]})]}),c&&(0,Y.jsxs)(G,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,Y.jsx)(lr,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:l.map((t,n)=>(0,Y.jsx)(ep,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function dp({children:e}){let{setContext:t}=us();return(0,J.useEffect)(()=>{t(`home`)},[t]),(0,Y.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,Y.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,Y.jsx)(Wc,{variant:`orgs`})}),(0,Y.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function fp(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function pp({open:e,onOpenChange:t,onCreated:n}){let{t:r}=F(),{createOrganization:i,getAuthConfig:a}=w(),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,J.useEffect)(()=>{u||l(fp(o))},[o,u]),(0,J.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Y.jsx)(it,{open:e,onOpenChange:t,children:(0,Y.jsx)(xt,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Y.jsxs)(`form`,{onSubmit:(0,J.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,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Y.jsx)(It,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,Y.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Y.jsx)(W,{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,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Y.jsx)(W,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,Y.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(G,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function mp(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 hp(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function gp(){let{t:e}=F(),t=s(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a,getAuthConfig:o}=w(),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(!0);(0,J.useEffect)(()=>{let e=!1;return o().then(t=>{e||t?.features?.multiOrgEnabled===!1&&h(!1)}).catch(()=>{}),()=>{e=!0}},[o]);let g=n??[],_=(0,J.useMemo)(()=>{let e=c.trim().toLowerCase();return e?g.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):g},[g,c]),v=async e=>{p(e.id);try{e.id!==r?.id&&await a(e.id),window.location.href=mp()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),p(null)}},y=e=>{d(!1),v(e)},b=(0,J.useRef)(!1);(0,J.useEffect)(()=>{b.current||i||g.length===1&&(b.current=!0,v(g[0]))},[i,g.length]);let x=!i&&g.length===1;return i||x?(0,Y.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Y.jsx)(K,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,Y.jsxs)(`div`,{className:`mb-8`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,Y.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,Y.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,Y.jsx)(pr,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(W,{value:c,onChange:e=>l(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),m&&(0,Y.jsxs)(G,{onClick:()=>d(!0),"data-testid":`organizations-new`,children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),g.length===0?(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Y.jsx)(yt,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),m&&(0,Y.jsxs)(G,{className:`mt-6`,onClick:()=>d(!0),children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):_.length===0?(0,Y.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,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:_.map(n=>{let i=n.id===r?.id,a=f===n.id;return(0,Y.jsxs)(`button`,{onClick:()=>v(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,Y.jsxs)(De,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Y.jsx)(da,{src:n.logo,alt:n.name}),(0,Y.jsx)(Ur,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:hp(n.name)})]}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,Y.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,Y.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,Y.jsx)(K,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Y.jsx)(pp,{open:u,onOpenChange:d,onCreated:y})]})}function _p(){let{t:e}=F(),t=s(),{slug:n}=f(),{organizations:r,activeOrganization:i,isOrganizationsLoading:o,switchOrganization:c}=w(),{setContext:l}=us();(0,J.useEffect)(()=>{l(`home`)},[l]);let u=(0,J.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,J.useEffect)(()=>{u&&i?.id!==u.id&&c(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,i,c]),o)return(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Y.jsx)(K,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,Y.jsx)(G,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let d=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,Y.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,Y.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,Y.jsx)(Wc,{variant:`orgs`})}),(0,Y.jsx)(`div`,{className:`border-b`,children:(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(0,Y.jsxs)(`button`,{onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,Y.jsx)(ja,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,Y.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:d.map(e=>(0,Y.jsx)(m,{to:e.to,end:!0,className:({isActive:e})=>`border-b-2 px-3 py-2 text-sm font-medium transition-colors ${e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e.label},e.to))})]})}),(0,Y.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,Y.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,Y.jsx)(a,{context:{org:u}})})})]})}function vp(){return h()}function yp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function bp({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=F(),{inviteMember:a}=w(),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(`member`),[u,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(!1);(0,J.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),_(!1))},[t]);let v=(0,J.useCallback)(async t=>{if(t.preventDefault(),o.trim()){d(!0),p(null);try{let t=await a({organizationId:e,email:o.trim(),role:c});h(t),r?.(t)}catch(e){p(e instanceof Error?e.message:`Failed to invite member`)}finally{d(!1)}}},[o,c,e,a,r]),y=(0,J.useCallback)(async()=>{if(!m)return;let e=yp(m.id);try{await navigator.clipboard.writeText(e),_(!0),q.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>_(!1),2e3)}catch{q.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Y.jsx)(it,{open:t,onOpenChange:n,children:(0,Y.jsx)(xt,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Y.jsx)(It,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,Y.jsx)(di,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{readOnly:!0,value:yp(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Y.jsx)(G,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,Y.jsx)(Zi,{className:`h-4 w-4`}):(0,Y.jsx)(He,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:m.email,role:m.role})})]}),(0,Y.jsx)(xn,{children:(0,Y.jsx)(G,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Y.jsxs)(`form`,{onSubmit:v,children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsx)(Re,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Y.jsx)(It,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,Y.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(W,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Y.jsxs)(Cn,{value:c,onValueChange:e=>l(e),children:[(0,Y.jsx)(Wn,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Y.jsx)(vt,{})}),(0,Y.jsxs)(qa,{children:[(0,Y.jsx)(Be,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Y.jsx)(Be,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Y.jsx)(Be,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,Y.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(G,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function xp(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Sp(){let{t:e}=F(),{org:t}=vp(),{getMembers:n,removeMember:r,updateMemberRole:i}=w(),[a,o]=(0,J.useState)([]),[s,c]=(0,J.useState)(!0),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(null),h=(0,J.useCallback)(async()=>{c(!0),u(null);try{o(await n(t.id))}catch(e){u(e instanceof Error?e.message:`Failed to load members`)}finally{c(!1)}},[t.id,n]);(0,J.useEffect)(()=>{h()},[h]);let g=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),q.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){q.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return s?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Y.jsx)(K,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,Y.jsx)(G,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,Y.jsx)(G,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Y.jsx)(zt,{}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,Y.jsxs)(De,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Y.jsx)(da,{src:t.user.image,alt:t.user.name}),(0,Y.jsx)(Ur,{className:`text-xs font-medium`,children:xp(t.user?.name)})]}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,Y.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,Y.jsx)(U,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),t.createdAt&&(0,Y.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),(0,Y.jsxs)(br,{children:[(0,Y.jsx)(Ni,{asChild:!0,children:(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Y.jsx)(Ki,{className:`h-4 w-4`})})}),(0,Y.jsxs)(Hi,{align:`end`,children:[(0,Y.jsxs)(jr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Y.jsx)(Ir,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Y.jsxs)(jr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Y.jsx)(Ir,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Y.jsxs)(jr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Y.jsx)(Ir,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Y.jsxs)(jr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Y.jsx)(Si,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Y.jsx)(Sr,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Y.jsxs)(Nr,{children:[(0,Y.jsxs)(Rr,{children:[(0,Y.jsx)(Yr,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Y.jsx)(Oi,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:p?.user?.name??p?.userId??``})})]}),(0,Y.jsxs)(va,{children:[(0,Y.jsx)(sa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(Ui,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),q.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){q.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,Y.jsx)(bp,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function Cp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function wp(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function Tp(){let{t:e}=F(),{org:t}=vp(),{listInvitations:n,cancelInvitation:r}=w(),[i,a]=(0,J.useState)([]),[o,s]=(0,J.useState)(!0),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(`all`),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),g=(0,J.useCallback)(async()=>{s(!0),l(null);try{a(await n(t.id))}catch(e){l(e instanceof Error?e.message:`Failed to load invitations`)}finally{s(!1)}},[t.id,n]);(0,J.useEffect)(()=>{g()},[g]);let _=async t=>{let n=Cp(t.id);try{await navigator.clipboard.writeText(n),h(t.id),q.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{q.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},v=async()=>{if(f)try{await r(f.id),q.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){q.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},y=u===`all`?i:i.filter(e=>e.status===u),b={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Y.jsx)(K,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,Y.jsx)(G,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,Y.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,Y.jsxs)(`button`,{onClick:()=>d(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${u===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),b[t]>0&&(0,Y.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:b[t]})]},t))}),(0,Y.jsx)(zt,{}),y.length===0?(0,Y.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:y.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Y.jsx)(De,{className:`h-9 w-9 shrink-0`,children:(0,Y.jsx)(Ur,{className:`text-xs`,children:(0,Y.jsx)(fr,{className:`h-4 w-4`})})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,Y.jsx)(U,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Y.jsx)(U,{variant:wp(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Y.jsx)(Zi,{className:`h-4 w-4 text-green-600`}):(0,Y.jsx)(He,{className:`h-4 w-4`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>p(t),"aria-label":`Cancel invitation`,children:(0,Y.jsx)(Fa,{className:`h-4 w-4`})})]})]},t.id))}),(0,Y.jsx)(Sr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Y.jsxs)(Nr,{children:[(0,Y.jsxs)(Rr,{children:[(0,Y.jsx)(Yr,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Y.jsx)(Oi,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Y.jsxs)(va,{children:[(0,Y.jsx)(sa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(Ui,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function Ep(){let{t:e}=F(),{org:t}=vp(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=w(),c=s(),[l,u]=(0,J.useState)(t.name),[d,f]=(0,J.useState)(t.slug??``),[p,m]=(0,J.useState)(t.logo??``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(!1),y=(0,J.useRef)(null),{upload:b}=dr(),[x,S]=(0,J.useState)(null),[C,T]=(0,J.useState)(!0),[E,D]=(0,J.useState)(!1),[O,k]=(0,J.useState)(!1),[ee,A]=(0,J.useState)(``),[j,te]=(0,J.useState)(!1);(0,J.useEffect)(()=>{u(t.name),f(t.slug??``),m(t.logo??``)},[t]),(0,J.useEffect)(()=>{let e=!1;return T(!0),r(t.id).then(t=>{e||S(t.find(e=>e.userId===n?.id)?.role===`owner`)}).catch(()=>{e||S(!1)}).finally(()=>{e||T(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let ne=(0,J.useCallback)(async n=>{n.preventDefault(),g(!0);try{await i(t.id,{name:l.trim(),slug:d.trim()||void 0,logo:p.trim()||void 0}),q.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){q.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{g(!1)}},[t.id,l,d,p,i,e]);return C?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Y.jsx)(K,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Y.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,Y.jsx)(zt,{className:`my-4`}),x?(0,Y.jsxs)(`form`,{onSubmit:ne,className:`space-y-4 max-w-md`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Y.jsx)(W,{id:`org-name`,value:l,onChange:e=>u(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Y.jsx)(W,{id:`org-slug`,value:d,onChange:e=>f(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(di,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(De,{className:`size-16 rounded-md`,children:[p?(0,Y.jsx)(da,{src:p,alt:l,className:`object-cover`}):null,(0,Y.jsx)(Ur,{className:`rounded-md text-base`,children:(l||`O`).slice(0,2).toUpperCase()})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{m((await b(n)).url),q.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){q.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{v(!1)}}},"data-testid":`settings-logo-file`}),(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,disabled:_,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[_?(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Y.jsx)(_i,{className:`mr-2 h-4 w-4`}),p?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),p&&(0,Y.jsxs)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Y.jsx)(Fa,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Y.jsx)(W,{id:`org-logo`,type:`url`,value:p,onChange:e=>m(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Y.jsxs)(G,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,Y.jsx)(`div`,{className:`rounded-lg border bg-muted/50 p-4 text-sm text-muted-foreground`,children:e(`organization.settings.readOnlyNote`,{defaultValue:`Only owners can change settings.`})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,Y.jsx)(zt,{className:`my-4`}),(0,Y.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,Y.jsx)(G,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Y.jsx)(zt,{}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Y.jsx)(G,{variant:`destructive`,size:`sm`,onClick:()=>{A(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Y.jsx)(Sr,{open:E,onOpenChange:D,children:(0,Y.jsxs)(Nr,{children:[(0,Y.jsxs)(Rr,{children:[(0,Y.jsx)(Yr,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Y.jsx)(Oi,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,Y.jsxs)(va,{children:[(0,Y.jsx)(sa,{disabled:j,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(Ui,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{te(!0);try{await o(t.id),q.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),c(`/organizations`)}catch(t){q.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{te(!1)}},disabled:j,children:[j&&(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Y.jsx)(Sr,{open:O,onOpenChange:e=>{k(e),e||A(``)},children:(0,Y.jsxs)(Nr,{children:[(0,Y.jsxs)(Rr,{children:[(0,Y.jsx)(Yr,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Y.jsx)(Oi,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,Y.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,Y.jsx)(di,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,Y.jsx)(W,{id:`delete-confirm-slug`,className:`mt-2`,value:ee,onChange:e=>A(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Y.jsxs)(va,{children:[(0,Y.jsx)(sa,{disabled:j,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(Ui,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{te(!0);try{await a(t.id),q.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),c(`/organizations`)}catch(t){q.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{te(!1)}},disabled:j||ee!==t.slug,children:[j&&(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function Dp(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 Op({userId:e,apiBase:t,className:n,refreshKey:r}){let i=s(),{conversationId:a}=f(),{conversations:o,isLoading:c,error:l,remove:u,rename:d}=Rd({userId:e,apiBase:t,refreshKey:r}),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(void 0),_=(0,J.useMemo)(()=>{let e=p.trim().toLowerCase();return e?o.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):o},[o,p]),v=(0,J.useCallback)(()=>i(`/ai`),[i]),y=(0,J.useCallback)(async(e,t)=>{e.stopPropagation(),await u(t),t===a&&i(`/ai`,{replace:!0})},[u,a,i]),b=(0,J.useCallback)(async(e,t)=>{g(void 0);try{await d(e,t)}catch{}},[d]);return(0,Y.jsxs)(`aside`,{className:B(`flex h-full min-h-0 flex-col bg-muted/30`,n),"data-testid":`ai-conversations-sidebar`,children:[(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:`Chats`}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:v,"data-testid":`ai-new-chat`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`New`]})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(pr,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(W,{value:p,onChange:e=>m(e.target.value),placeholder:`Search chats...`,className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Y.jsx)(Rn,{className:`flex-1 min-h-0`,children:c&&o.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`Loading…`}):l?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:l.message}):o.length===0?(0,Y.jsxs)(nt,{className:`px-3 py-8`,children:[(0,Y.jsx)(Fr,{className:`h-8 w-8 text-muted-foreground`}),(0,Y.jsx)(Ua,{children:`No chats yet`}),(0,Y.jsx)(yt,{children:`Start a new conversation to see it here.`})]}):_.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`No matching chats.`}):(0,Y.jsx)(`ul`,{className:`flex flex-col py-1`,children:_.map(e=>(0,Y.jsx)(kp,{conversation:e,active:e.id===a,renaming:e.id===h,onSelect:()=>i(`/ai/${e.id}`),onDelete:t=>y(t,e.id),onStartRename:()=>g(e.id),onCancelRename:()=>g(void 0),onSubmitRename:t=>b(e.id,t)},e.id))})})]})}function kp({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,J.useState)(c),d=(0,J.useRef)(null);return(0,J.useEffect)(()=>{n&&(u(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>d.current?.select(),0))},[n,e.title,e.preview]),n?(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`div`,{className:B(`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,Y.jsx)(W,{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,Y.jsx)(G,{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,Y.jsx)(Zi,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:o,"aria-label":`Cancel rename`,children:(0,Y.jsx)(Fa,{className:`h-3.5 w-3.5`})})]})}):(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:B(`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,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`line-clamp-1 flex-1 font-medium`,children:c}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Y.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,Y.jsx)(ht,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]}),e.preview&&e.preview!==c?(0,Y.jsx)(`span`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:e.preview}):null,(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Dp(e.updatedAt??e.createdAt)})]})})}var Ap=`/api/v1/ai`;function jp(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(/\/$/,``)}${Ap}`}function Mp({apiBase:e,defaultAgent:t}={}){let{user:n}=w(),r=n?.id,{conversationId:i}=f(),a=s(),{setContext:o}=us();(0,J.useEffect)(()=>{o(`home`)},[o]);let c=(0,J.useMemo)(()=>jp(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:p}=Lo({apiBase:c}),[m,h]=(0,J.useState)(void 0);(0,J.useEffect)(()=>{if(!m&&u.length>0){let e=t??l;h(((e?u.find(t=>t.name===e):void 0)??u[0]).name)}},[u,m,t,l]);let g=m?`${c}/agents/${encodeURIComponent(m)}/chat`:void 0,{conversationId:_,initialMessages:v,isLoading:y}=Pd({userId:r,scope:m,apiBase:c,activeId:i}),[b,x]=(0,J.useState)(0),[S,C]=(0,J.useState)(!1),T=(0,J.useMemo)(()=>c.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[c]);(0,J.useEffect)(()=>{!i&&_&&a(`/ai/${_}`,{replace:!0})},[i,_,a]);let E=(0,J.useRef)(new Set);(0,J.useEffect)(()=>{_&&v.length>0&&E.current.add(_)},[_,v.length]);let D=(0,J.useCallback)(e=>{if(x(e=>e+1),!e||!_||E.current.has(_))return;E.current.add(_);let t=()=>x(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[_]);return(0,Y.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,Y.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,Y.jsx)(Wc,{variant:`home`}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>C(!0),disabled:!_,"data-testid":`ai-chat-share-button`,title:_?`Share this conversation`:`Start chatting to enable sharing`,children:[(0,Y.jsx)(Gi,{className:`h-3.5 w-3.5`}),`Share`]})})]}),_&&(0,Y.jsx)(Na,{open:S,onOpenChange:C,objectName:`ai_conversations`,recordId:_,recordLabel:`this conversation`,apiBase:T}),(0,Y.jsxs)(`div`,{className:`flex flex-1 min-h-0 w-full`,children:[(0,Y.jsx)(Op,{userId:r,apiBase:c,refreshKey:b,className:`hidden w-72 shrink-0 border-r md:flex`}),(0,Y.jsx)(`main`,{className:`flex flex-1 min-w-0 flex-col`,children:(0,Y.jsx)(Np,{agents:u,agentsLoading:d,agentsError:p,activeAgent:m,onAgentChange:h,chatApi:g,apiBase:c,conversationId:_,initialMessages:v,hydrating:y,onSent:D},`${g??`local`}:${_??`pending`}`)})]})]})}function Np({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,J.useMemo)(()=>e.find(e=>e.name===r)?.label??r??`Assistant`,[e,r]),f=(0,J.useMemo)(()=>c.map(e=>({id:e.id,role:e.role,content:e.parts.map(e=>e.text).join(``)})),[c]),p=(0,J.useMemo)(()=>{if(!(f.length>0))return Ip(r,d)},[f.length,r,d]),{messages:m,isLoading:h,error:g,sendMessage:_,stop:v,reload:y,clear:b}=zo({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=Ro({messages:m,apiBase:o,continueConversation:e=>{_(e)}}),S=(0,J.useCallback)((e,t)=>{_(e,t),u(e)},[_,u]);return(0,Y.jsx)(Io,{className:`flex-1 min-h-0 rounded-none border-0`,maxHeight:`100%`,headerSlot:e.length>0?(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Agent:`}),(0,Y.jsxs)(Cn,{value:r,onValueChange:i,disabled:t,children:[(0,Y.jsx)(Wn,{className:`h-7 w-[220px] text-xs`,"data-testid":`ai-chat-agent-picker`,children:(0,Y.jsx)(vt,{placeholder:`Choose agent...`})}),(0,Y.jsx)(qa,{align:`start`,children:e.map(e=>(0,Y.jsxs)(Be,{value:e.name,className:`text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,Y.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}),l?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Loading history…`}):null,n?(0,Y.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 Pp={data_chat:[`系统里有多少个用户?列出他们的邮箱。`,`帮我列出最近创建的 5 条记录。`,`统计每个对象的记录数。`],metadata_assistant:[`系统里注册了哪些对象类型?`,`sys_user 对象有哪些字段?`,`描述一下用户相关的对象关系。`]},Fp=[`What can you help me with?`,`List the available data objects.`,`Summarize my recent activity.`];function Ip(e,t){if(e&&Pp[e])return Pp[e];let n=(e??t).toLowerCase();return n.includes(`data`)?Pp.data_chat:n.includes(`metadata`)?Pp.metadata_assistant:Fp}var Lp=new Map;function Rp(e){Lp.set(e.ref,e)}function zp(e){return Lp.get(e)}function Bp(e){return(0,J.useMemo)(()=>{let t=new Se({baseUrl:``});return e?t.withEnvironment(e):t},[e])}function Vp(e){let t=new Set(e.map(e=>e.type));return e.filter(e=>{if(!/[A-Z]/.test(e.type))return!0;let n=e.type.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`);return!(n!==e.type&&t.has(n))})}function Hp(e){let[t,n]=(0,J.useState)(!0),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)([]);return(0,J.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(Vp(i)),n(!1))}catch(e){t||(i(e?.message??String(e)),n(!1))}})(),()=>{t=!0}},[e]),{loading:t,error:r,entries:a}}function Up(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}function Wp(e,t=`error`){let[n,r]=(0,J.useState)(!0),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)({entries:[],total:0,scannedTypes:0,scannedItems:0,stats:{}}),[c,l]=(0,J.useState)(0);return(0,J.useEffect)(()=>{let n=!1;return r(!0),a(null),(async()=>{try{let i=await e.diagnostics({severity:t});if(n)return;s(i),r(!1)}catch(e){if(n)return;a(e?.message??String(e)),s({entries:[],total:0,scannedTypes:0,scannedItems:0,stats:{}}),r(!1)}})(),()=>{n=!0}},[e,t,c]),{loading:n,error:i,summary:o,byType:(0,J.useMemo)(()=>{let e={};for(let t of o.entries)(t.diagnostics?.errors?.length??0)>0&&(e[t.type]=(e[t.type]??0)+1);return e},[o]),warnByType:(0,J.useMemo)(()=>{let e={};for(let t of o.entries){let n=t.diagnostics?.errors?.length??0,r=t.diagnostics?.warnings?.length??0;n===0&&r>0&&(e[t.type]=(e[t.type]??0)+1)}return e},[o]),countsByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(o.stats??{}))e[t]=n.count;return e},[o]),lockedByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(o.stats??{}))typeof n.locked==`number`&&n.locked>0&&(e[t]=n.locked);return e},[o]),packagesByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(o.stats??{}))e[t]=n.packages??[];return e},[o]),allPackages:(0,J.useMemo)(()=>{let e=new Set;for(let t of Object.values(o.stats??{}))for(let n of t.packages??[])e.add(n);return[...e].sort()},[o]),reload:()=>l(e=>e+1)}}var Gp={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`,api:`API Endpoint`,connector:`Connector`,mapping:`Field Mapping`,policy:`Policy`,webhook:`Webhook`,theme:`Theme`,sharing_rule:`Sharing Rule`,analytics_cube:`Analytics Cube`},Kp={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:`后台任务`,api:`API 端点`,connector:`连接器`,mapping:`字段映射`,policy:`策略`,webhook:`Webhook`,theme:`主题`,sharing_rule:`共享规则`,analytics_cube:`分析立方体`},qp={data:`Data`,ui:`UI`,automation:`Automation`,ai:`AI`,system:`System`,platform:`Platform`,identity:`Identity`,security:`Security`,other:`Other`},Jp={data:`数据`,ui:`界面`,automation:`自动化`,ai:`AI`,system:`系统`,platform:`平台`,identity:`身份`,security:`安全`,other:`其他`},Yp={"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.directory.diagnosticsLink":`View all issues ({count})`,"engine.directory.invalidTooltip":`{count} invalid item(s) — click to fix`,"engine.directory.warnTooltip":`{count} item(s) with warnings`,"engine.directory.itemCountTooltip":`{count} item(s) of this type`,"engine.directory.allPackages":`All packages`,"engine.directory.packageFilter":`Package`,"engine.home.greetingMorning":`Good morning`,"engine.home.greetingAfternoon":`Good afternoon`,"engine.home.greetingEvening":`Good evening`,"engine.home.subtitle":`Your control center for modeling data, designing experiences, and automating the platform.`,"engine.home.statTypes":`Metadata types`,"engine.home.statWritable":`Runtime-writable`,"engine.home.statPackages":`Packages`,"engine.home.statIssues":`Open issues`,"engine.home.allHealthy":`All healthy`,"engine.home.allHealthyHint":`No validation issues across your metadata.`,"engine.home.issuesHint":`{count} item(s) need attention.`,"engine.home.explore":`Explore`,"engine.home.exploreHint":`Jump into any domain of the platform.`,"engine.home.quickActions":`Quick actions`,"engine.home.quickActionsHint":`Create new metadata in one click.`,"engine.home.newItem":`New {label}`,"engine.home.recent":`Recently viewed`,"engine.home.recentEmpty":`Nothing here yet — items you open will appear for quick access.`,"engine.home.browseAll":`Browse all metadata`,"engine.home.openDiagnostics":`Review diagnostics`,"engine.home.viewDomain":`View`,"engine.home.typesLower":`types`,"engine.home.loading":`Loading your workspace…`,"engine.diagnostics.title":`Metadata Diagnostics`,"engine.diagnostics.description":`Every metadata item that failed load-time validation, grouped by type. Errors block features that depend on the item; warnings are advisory.`,"engine.diagnostics.back":`Back to metadata`,"engine.diagnostics.refresh":`Refresh`,"engine.diagnostics.loading":`Scanning metadata…`,"engine.diagnostics.loadFailed":`Failed to load diagnostics: {error}`,"engine.diagnostics.summary":`{count} issue(s) across {items} items in {types} types`,"engine.diagnostics.cleanTitle":`All clear`,"engine.diagnostics.cleanHint":`Scanned {items} item(s) across {types} type(s) — no issues found.`,"engine.diagnostics.severity.error":`Errors`,"engine.diagnostics.severity.warning":`Errors + Warnings`,"engine.diagnostics.col.name":`Item`,"engine.diagnostics.col.issues":`Issues`,"engine.diagnostics.errorN":`{count} error(s)`,"engine.diagnostics.warnN":`{count} warning(s)`,"engine.diagnostics.more":`+{count} more…`,"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.warnings":`Warnings`,"engine.list.invalidTitle":`Invalid metadata`,"engine.list.invalidCount":`{count} validation error(s):`,"engine.list.warnTitle":`Metadata warnings`,"engine.list.warnCount":`{count} warning(s):`,"engine.list.allSources":`All sources`,"engine.list.allPackages":`All packages`,"engine.list.packageFilter":`Package`,"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.lockFull":`This item is locked and cannot be edited or deleted.`,"engine.edit.lockNoOverlay":`This item is locked and cannot be edited.`,"engine.edit.lockNoDelete":`This item is locked and cannot be deleted.`,"engine.edit.history":`History`,"engine.edit.auditTab":`Audit log`,"engine.edit.auditCount":`events`,"engine.edit.auditEmptyTitle":`No audit events yet`,"engine.edit.auditEmptyDescription":`No save, publish, rollback, delete or reset attempts have been recorded for this item. Once someone tries to change it (allowed or denied), the attempt will appear here.`,"engine.edit.auditColTime":`Time`,"engine.edit.auditColActor":`Actor`,"engine.edit.auditColOperation":`Operation`,"engine.edit.auditColOutcome":`Outcome`,"engine.edit.auditColLock":`Lock`,"engine.edit.auditColNote":`Note`,"engine.edit.refresh":`Refresh`,"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.warnTitle":`{count} warning(s) — review recommended.`,"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`},Xp={"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.directory.diagnosticsLink":`查看全部问题({count})`,"engine.directory.invalidTooltip":`{count} 个无效项 — 点击修复`,"engine.directory.warnTooltip":`{count} 个条目带有警告`,"engine.directory.itemCountTooltip":`此类型共 {count} 项`,"engine.directory.allPackages":`全部软件包`,"engine.directory.packageFilter":`软件包`,"engine.home.greetingMorning":`早上好`,"engine.home.greetingAfternoon":`下午好`,"engine.home.greetingEvening":`晚上好`,"engine.home.subtitle":`建模数据、设计体验、编排自动化的控制中心。`,"engine.home.statTypes":`元数据类型`,"engine.home.statWritable":`可运行时覆盖`,"engine.home.statPackages":`软件包`,"engine.home.statIssues":`待处理问题`,"engine.home.allHealthy":`一切正常`,"engine.home.allHealthyHint":`所有元数据均无校验问题。`,"engine.home.issuesHint":`{count} 项需要关注。`,"engine.home.explore":`探索`,"engine.home.exploreHint":`快速进入平台的各个领域。`,"engine.home.quickActions":`快捷操作`,"engine.home.quickActionsHint":`一键创建新的元数据。`,"engine.home.newItem":`新建{label}`,"engine.home.recent":`最近访问`,"engine.home.recentEmpty":`暂无记录 — 你打开过的项目会显示在这里,方便快速访问。`,"engine.home.browseAll":`浏览全部元数据`,"engine.home.openDiagnostics":`查看诊断`,"engine.home.viewDomain":`查看`,"engine.home.typesLower":`个类型`,"engine.home.loading":`正在加载工作区…`,"engine.diagnostics.title":`元数据诊断`,"engine.diagnostics.description":`所有加载时校验失败的元数据条目,按类型分组。错误会阻塞依赖该条目的功能;警告仅提示。`,"engine.diagnostics.back":`返回元数据`,"engine.diagnostics.refresh":`刷新`,"engine.diagnostics.loading":`正在扫描元数据…`,"engine.diagnostics.loadFailed":`加载诊断失败:{error}`,"engine.diagnostics.summary":`{items} 个条目({types} 个类型)中共发现 {count} 个问题`,"engine.diagnostics.cleanTitle":`一切正常`,"engine.diagnostics.cleanHint":`已扫描 {items} 个条目({types} 个类型),未发现问题。`,"engine.diagnostics.severity.error":`错误`,"engine.diagnostics.severity.warning":`错误 + 警告`,"engine.diagnostics.col.name":`条目`,"engine.diagnostics.col.issues":`问题`,"engine.diagnostics.errorN":`{count} 个错误`,"engine.diagnostics.warnN":`{count} 个警告`,"engine.diagnostics.more":`另有 {count} 个…`,"engine.list.create":`新建`,"engine.list.refresh":`刷新`,"engine.list.search":`搜索名称、标签或描述…`,"engine.list.empty":`暂无数据。`,"engine.list.items":`条目`,"engine.list.filtered":`已筛选`,"engine.list.invalid":`无效`,"engine.list.warnings":`警告`,"engine.list.invalidTitle":`元数据无效`,"engine.list.invalidCount":`{count} 个校验错误:`,"engine.list.warnTitle":`元数据警告`,"engine.list.warnCount":`{count} 个警告:`,"engine.list.allSources":`全部来源`,"engine.list.allPackages":`全部软件包`,"engine.list.packageFilter":`软件包`,"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.lockFull":`该元数据已锁定,不可编辑或删除。`,"engine.edit.lockNoOverlay":`该元数据已锁定,不可编辑。`,"engine.edit.lockNoDelete":`该元数据已锁定,不可删除。`,"engine.edit.history":`历史`,"engine.edit.auditTab":`审计日志`,"engine.edit.auditCount":`条记录`,"engine.edit.auditEmptyTitle":`暂无审计记录`,"engine.edit.auditEmptyDescription":`该元数据尚未发生任何保存、发布、回滚、删除或重置操作。一旦有人尝试修改(无论允许或拒绝),都会在此显示。`,"engine.edit.auditColTime":`时间`,"engine.edit.auditColActor":`操作人`,"engine.edit.auditColOperation":`操作`,"engine.edit.auditColOutcome":`结果`,"engine.edit.auditColLock":`锁状态`,"engine.edit.auditColNote":`备注`,"engine.edit.refresh":`刷新`,"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.warnTitle":`{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 Zp(e){return(e??``).toLowerCase().startsWith(`zh`)?{types:Kp,domains:Jp,strings:Xp}:{types:Gp,domains:qp,strings:Yp}}function Qp(e,t,n){return Zp(t).types[e]||(n??e)}function $p(e,t){return Zp(t).domains[e]??e}function X(e,t){return Zp(t).strings[e]??e}function em(e,t,n){return X(e,t).replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):`{${t}}`)}function tm(){return typeof navigator<`u`&&/^zh/i.test(navigator.language)?`zh-CN`:`en-US`}function nm({appSlug:e}={}){let t=s(),n=Bp(),{entries:r}=Hp(n),[i,a]=J.useState(!1),[o,c]=J.useState(``),[l,u]=J.useState(null),[d,f]=J.useState(!1),[p,m]=J.useState(0),h=J.useMemo(()=>tm(),[]);J.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),a(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),J.useEffect(()=>{if(!i||l!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||u(t)}finally{e||f(!1)}})(),()=>{e=!0}},[i,l,d,r,n]);let g=J.useMemo(()=>{let e=o.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||Qp(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(l??[]).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,l]);J.useEffect(()=>{m(0)},[o,i]);function _(n){a(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,Y.jsx)(it,{open:i,onOpenChange:a,children:(0,Y.jsxs)(xt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(Wa,{className:`sr-only`,children:(0,Y.jsx)(Re,{children:X(`engine.quickfind.title`,h)})}),(0,Y.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Y.jsx)(pr,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(W,{autoFocus:!0,placeholder:X(`engine.quickfind.placeholder`,h),value:o,onChange:e=>c(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Y.jsx)(cn,{children:`esc`})]}),(0,Y.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,Y.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}),X(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:X(`engine.quickfind.noMatches`,h)}),(0,Y.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate`,children:Qp(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,Y.jsx)(Cr,{className:`h-3 w-3`})}),e.name,e.label&&(0,Y.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,Y.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,Y.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(cn,{children:`↑`}),` `,(0,Y.jsx)(cn,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(cn,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(cn,{children:`⌘`}),(0,Y.jsx)(cn,{children:`⇧`}),(0,Y.jsx)(cn,{children:`M`}),` toggle`]})]})]})})}var rm={data:Tr,ui:mi,automation:Ue,ai:yr,system:Mi,platform:Mi,identity:Ir,security:Ir},im=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],am=new Set([`field`]);function om(){let e=Bp(),{loading:t,error:n,entries:r}=Hp(e),{byType:a,warnByType:o,summary:s,countsByType:c,lockedByType:l,packagesByType:u,allPackages:d}=Wp(e,`warning`),f=J.useMemo(()=>tm(),[]),[p,m]=J.useState(``),[h,g]=J.useState(`all`),[_,v]=J.useState(!1),[y,b]=J.useState(`all`),x=J.useMemo(()=>{let e=r.filter(e=>!am.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},[r]),S=r.filter(e=>!am.has(e.type)&&(e.allowOrgOverride||e.allowRuntimeCreate)).length,C=r.filter(e=>{if(am.has(e.type)||_&&!(e.allowOrgOverride||e.allowRuntimeCreate)||h!==`all`&&(e.domain??`other`)!==h||y!==`all`&&!(u[e.type]??[]).includes(y))return!1;if(p){let t=p.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||Qp(e.type,f,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),w=J.useMemo(()=>{let e={};for(let t of C)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=im.indexOf(e),r=im.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[C]);return t?(0,Y.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:X(`engine.directory.loading`,f)}):n?(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[X(`engine.directory.loadFailed`,f),`: `,n]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:X(`engine.directory.title`,f)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:em(`engine.directory.description`,f,{count:`<strong class="text-foreground">${r.filter(e=>!am.has(e.type)).length}</strong>`,writable:S})}}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,Y.jsx)(pr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(W,{className:`pl-8`,placeholder:X(`engine.directory.search`,f),value:p,onChange:e=>m(e.target.value)})]}),(0,Y.jsxs)(G,{variant:_?`default`:`outline`,size:`sm`,onClick:()=>v(e=>!e),children:[X(`engine.directory.writableOnly`,f),` (`,S,`)`]}),d.length>0&&(0,Y.jsxs)(Cn,{value:y,onValueChange:b,children:[(0,Y.jsxs)(Wn,{className:`h-8 w-[220px] text-xs`,children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5 mr-1 text-muted-foreground`}),(0,Y.jsx)(vt,{placeholder:X(`engine.directory.allPackages`,f)})]}),(0,Y.jsxs)(qa,{children:[(0,Y.jsxs)(Be,{value:`all`,children:[X(`engine.directory.allPackages`,f),` (`,d.length,`)`]}),d.map(e=>(0,Y.jsx)(Be,{value:e,children:(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e})},e))]})]}),s.total>0&&(0,Y.jsx)(G,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,Y.jsxs)(i,{to:`./_diagnostics`,children:[(0,Y.jsx)(fn,{className:`h-3.5 w-3.5 mr-1`}),em(`engine.directory.diagnosticsLink`,f,{count:s.total})]})}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[X(`engine.directory.quickFind`,f),` `,(0,Y.jsx)(cn,{children:`⌘`}),(0,Y.jsx)(cn,{children:`⇧`}),(0,Y.jsx)(cn,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(sm,{domain:`all`,label:X(`engine.directory.all`,f),active:h===`all`,count:x.all??0,onClick:()=>g(`all`)}),im.filter(e=>x[e]).map(e=>(0,Y.jsx)(sm,{domain:e,label:$p(e,f),active:h===e,count:x[e]??0,onClick:()=>g(e)},e))]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[C.length===0&&(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:X(`engine.directory.noMatches`,f)}),(0,Y.jsx)(yt,{children:X(`engine.directory.noMatchesHint`,f)})]}),w.map(([e,t])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,Y.jsx)(rm[e]??ki,{className:`h-3.5 w-3.5`}),$p(e,f),` (`,t.length,`)`]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=c[e.type]??0,n=y!==`all`;return(0,Y.jsx)(cm,{entry:e,locale:f,invalidCount:a[e.type]??0,warnCount:o[e.type]??0,lockedCount:l[e.type]??0,itemCount:t,packageFilter:n?y:void 0},e.type)})})]},e))]}),(0,Y.jsx)(nm,{})]})}function sm({domain:e,label:t,active:n,count:r,onClick:i}){return(0,Y.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,Y.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function cm({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=Qp(e.type,t,e.label);return(0,Y.jsxs)(i,{to:s?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(s)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(n>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[n>0&&(0,Y.jsx)(`span`,{title:em(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":em(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,Y.jsx)(fn,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),c]}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(U,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:em(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),n>0&&(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:em(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:em(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),o>0&&(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${o} locked item${o===1?``:`s`} — see ADR-0010`,"aria-label":`${o} locked items`,children:[(0,Y.jsx)(Cr,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,Y.jsx)(U,{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:X(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Y.jsx)(U,{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:X(`engine.badge.createOnly`,t)}):(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:X(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var lm=new Set([`field`]),um={data:Tr,ui:mi,automation:Ue,ai:yr,system:Mi,platform:Mi,identity:Ir,security:Ir},dm={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},fm=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],pm=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],mm={object:ir,dashboard:je,page:xr,report:Wr,record:ki,metadata:mi};function hm(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function gm(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function _m(){let e=Bp(),{loading:t,entries:n}=Hp(e),{summary:r,countsByType:a,allPackages:o}=Wp(e,`warning`),{recentItems:s}=eo(),c=J.useMemo(()=>tm(),[]),l=J.useMemo(()=>n.filter(e=>!lm.has(e.type)),[n]),u=J.useMemo(()=>l.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[l]),d=J.useMemo(()=>{let e={};for(let t of l)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(a[t.type]??0)-(a[e.type]??0));return Object.entries(e).sort(([e],[t])=>(fm.indexOf(e)===-1?99:fm.indexOf(e))-(fm.indexOf(t)===-1?99:fm.indexOf(t)))},[l,a]),f=J.useMemo(()=>{let e=new Map(u.map(e=>[e.type,e]));return pm.map(t=>e.get(t)).filter(Boolean)},[u]),p=r.total,m=!t&&p===0;return t?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:X(`engine.home.loading`,c)}):(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,Y.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`max-w-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,Y.jsx)(yr,{className:`h-4 w-4`}),X(hm(),c)]}),(0,Y.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:X(`engine.home.subtitle`,c)}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Y.jsx)(G,{asChild:!0,size:`sm`,className:`bg-white text-violet-700 shadow-sm hover:bg-white/90`,children:(0,Y.jsxs)(i,{to:`metadata`,children:[(0,Y.jsx)(mi,{className:`mr-1.5 h-4 w-4`}),X(`engine.home.browseAll`,c)]})}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white/90 backdrop-blur-sm`,children:[(0,Y.jsx)(pr,{className:`h-3.5 w-3.5`}),X(`engine.directory.quickFind`,c),` ⌘⇧M`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsx)(vm,{value:l.length,label:X(`engine.home.statTypes`,c)}),(0,Y.jsx)(vm,{value:u.length,label:X(`engine.home.statWritable`,c)}),(0,Y.jsx)(vm,{value:o.length,label:X(`engine.home.statPackages`,c)})]})]})]}),(0,Y.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Y.jsx)(ym,{icon:mi,from:`from-indigo-500`,to:`to-violet-600`,value:l.length,label:X(`engine.home.statTypes`,c),to_link:`metadata`}),(0,Y.jsx)(ym,{icon:Ga,from:`from-sky-500`,to:`to-blue-600`,value:u.length,label:X(`engine.home.statWritable`,c),to_link:`metadata`}),(0,Y.jsx)(ym,{icon:Br,from:`from-emerald-500`,to:`to-teal-600`,value:o.length,label:X(`engine.home.statPackages`,c),to_link:`metadata`}),(0,Y.jsxs)(i,{to:m?`metadata`:`metadata/_diagnostics`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(m?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(m?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:m?(0,Y.jsx)(Ga,{className:`h-5 w-5`}):(0,Y.jsx)(fn,{className:`h-5 w-5`})}),(0,Y.jsx)(En,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:m?X(`engine.home.allHealthy`,c):p}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:X(m?`engine.home.allHealthyHint`:`engine.home.statIssues`,c)})]})]})]}),f.length>0&&(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(bm,{icon:H,title:X(`engine.home.quickActions`,c),hint:X(`engine.home.quickActionsHint`,c)}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:f.map(e=>(0,Y.jsx)(G,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-dashed hover:border-solid hover:border-primary hover:bg-primary/5`,children:(0,Y.jsxs)(i,{to:`metadata/${encodeURIComponent(e.type)}/new`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),em(`engine.home.newItem`,c,{label:Qp(e.type,c,e.label)})]})},e.type))})]}),(0,Y.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,Y.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,Y.jsx)(bm,{icon:mi,title:X(`engine.home.explore`,c),hint:X(`engine.home.exploreHint`,c)}),(0,Y.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:d.map(([e,t])=>(0,Y.jsx)(xm,{domain:e,group:t,countsByType:a,locale:c},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(bm,{icon:rn,title:X(`engine.home.recent`,c)}),(0,Y.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:s.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:X(`engine.home.recentEmpty`,c)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:s.slice(0,8).map(e=>{let t=mm[e.type]??ki;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(i,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,Y.jsx)(t,{className:`h-4 w-4`})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:gm(e.visitedAt,c)})]}),(0,Y.jsx)(En,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(nm,{})]})}function vm({value:e,label:t}){return(0,Y.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function ym({icon:e,from:t,to:n,value:r,label:a,to_link:o}){return(0,Y.jsxs)(i,{to:o,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${n} text-white shadow-sm`,children:(0,Y.jsx)(e,{className:`h-5 w-5`})}),(0,Y.jsx)(En,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:a})]})]})}function bm({icon:e,title:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,Y.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,Y.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function xm({domain:e,group:t,countsByType:n,locale:r}){let a=um[e]??ki,o=dm[e]??dm.other,s=t.slice(0,6),c=t.length-s.length;return(0,Y.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${o.ring}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${o.from} ${o.to} text-white shadow-sm`,children:(0,Y.jsx)(a,{className:`h-[18px] w-[18px]`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:$p(e,r)}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,X(`engine.home.typesLower`,r)]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[s.map(e=>(0,Y.jsxs)(i,{to:`metadata/${encodeURIComponent(e.type)}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:Qp(e.type,r,e.label)}),(0,Y.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:n[e.type]??0})]},e.type)),c>0&&(0,Y.jsxs)(i,{to:`metadata`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${o.text} hover:underline`,children:[`+`,c]})]})]})}function Sm({entry:e,itemName:t,subtitle:n,stats:r,actions:a,children:s}){let c=e?.type??``,l=J.useMemo(()=>tm(),[]),u=Qp(c,l,e?.label),{pathname:d}=o(),f=J.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,Y.jsx)(i,{to:f,className:`hover:text-foreground shrink-0`,children:X(`engine.breadcrumb.allTypes`,l)}),(0,Y.jsx)(qn,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(i,{to:`${f}/${encodeURIComponent(c)}`,className:`hover:text-foreground shrink-0`,children:u}),(0,Y.jsx)(qn,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:$p(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(U,{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:X(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,Y.jsx)(U,{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:X(`engine.badge.createOnly`,l)}):(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:X(`engine.badge.readOnly`,l)})]}),n&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),a]})]}):(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,Y.jsx)(i,{to:f,className:`hover:text-foreground`,children:X(`engine.breadcrumb.allTypes`,l)}),(0,Y.jsx)(qn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:u})]}),(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:u}),(0,Y.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:c}),e?.domain&&(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:$p(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(U,{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:X(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,Y.jsx)(U,{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:X(`engine.badge.createOnly`,l)}):(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:X(`engine.badge.readOnly`,l)})]}),n&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),a]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:s})]})}function Cm(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 wm=new Map;function Tm(e){let t=wm.get(e.type);if(!t){wm.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);wm.set(e.type,n)}function Em(e){return wm.get(e)}function Dm(e){let t=[];for(let n of wm.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 Om(e,t){let n=wm.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 km(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 Am({type:e}){let t=f(),n=e??t.type??``,r=Em(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(jm,{type:n})}function jm({type:e}){let t=s(),n=Bp(),{entries:r}=Hp(n),a=r.find(t=>t.type===e),o=Om(e,a),[c,u]=J.useState([]),[d,f]=J.useState(!0),[p,m]=J.useState(null),[h,g]=J.useState(``),[_,v]=J.useState(`all`),[y,b]=l(),[x,S]=J.useState(y.get(`package`)??`all`),[C,w]=J.useState(0);J.useEffect(()=>{if((y.get(`package`)??`all`)!==x){let e=new URLSearchParams(y);x===`all`?e.delete(`package`):e.set(`package`,x),b(e,{replace:!0})}},[x]),J.useEffect(()=>{let e=y.get(`package`)??`all`;e!==x&&S(e)},[y]),J.useEffect(()=>{let t=!1;return f(!0),m(null),(async()=>{try{let r=await n.list(e);if(t)return;u((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:km(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,C]);let T=o.searchableFields??[`name`,`label`,`description`],E=c.filter(e=>{if(!Up(e.item,h,T)||_!==`all`&&e.source!==_)return!1;if(x!==`all`){let t=e.item?._packageId;if((!t||t===`sys_metadata`?null:t)!==x)return!1}return!0}),D=J.useMemo(()=>{let e=new Map;for(let t of c){let n=t.item?._packageId;!n||n===`sys_metadata`||e.set(n,(e.get(n)??0)+1)}return Array.from(e.entries()).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({id:e,count:t}))},[c]),O=J.useMemo(()=>{let e={all:c.length,artifact:0,runtime:0};for(let t of c)e[t.source]++;return e},[c]),k=J.useMemo(()=>c.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[c]),ee=J.useMemo(()=>c.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[c]),A=o.listColumns??Mm(o.primaryKey??`name`),j=tm(),te=Qp(e,j,a?.label??e),ne=e=>{let t=`engine.list.col.${e.key}`,n=X(t,j);return n===t?e.label:n};return(0,Y.jsx)(Sm,{entry:a??{type:e,label:e},stats:[{label:X(`engine.list.items`,j),value:c.length},{label:X(`engine.list.filtered`,j),value:E.length},...k>0?[{label:X(`engine.list.invalid`,j),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(fn,{className:`w-3.5 h-3.5`}),k]})}]:[],...ee>0?[{label:X(`engine.list.warnings`,j),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(fn,{className:`w-3.5 h-3.5`}),ee]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>w(e=>e+1),title:X(`engine.list.refresh`,j),children:(0,Y.jsx)(tn,{className:`h-4 w-4`})}),(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,Y.jsxs)(G,{size:`sm`,variant:o.createFields?`default`:`outline`,onClick:()=>t(`./new`),title:o.createFields?em(`engine.list.createHint`,j,{type:te}):void 0,children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),X(`engine.list.create`,j)]})]}),children:(0,Y.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,Y.jsx)(pr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(W,{className:`pl-8`,placeholder:X(`engine.list.search`,j),value:h,onChange:e=>g(e.target.value)})]}),(0,Y.jsxs)(Cn,{value:_,onValueChange:v,children:[(0,Y.jsx)(Wn,{className:`w-[180px]`,children:(0,Y.jsx)(vt,{})}),(0,Y.jsxs)(qa,{children:[(0,Y.jsxs)(Be,{value:`all`,children:[X(`engine.list.allSources`,j),` (`,O.all,`)`]}),(0,Y.jsxs)(Be,{value:`artifact`,children:[X(`engine.list.source.artifact`,j),` (`,O.artifact,`)`]}),(0,Y.jsxs)(Be,{value:`runtime`,children:[X(`engine.list.source.runtime`,j),` (`,O.runtime,`)`]})]})]}),D.length>0&&(0,Y.jsxs)(Cn,{value:x,onValueChange:S,children:[(0,Y.jsxs)(Wn,{className:`w-[240px]`,children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5 mr-1 text-muted-foreground shrink-0`}),(0,Y.jsx)(vt,{placeholder:X(`engine.list.allPackages`,j)})]}),(0,Y.jsxs)(qa,{children:[(0,Y.jsxs)(Be,{value:`all`,children:[X(`engine.list.allPackages`,j),` (`,D.length,`)`]}),D.map(e=>(0,Y.jsxs)(Be,{value:e.id,children:[(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.id}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[`(`,e.count,`)`]})]},e.id))]})]})]}),d&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[X(`engine.edit.loading`,j),` `,e,`…`]}),p&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:p}),!d&&!p&&E.length===0&&(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:c.length===0?em(`engine.list.emptyType`,j,{type:te}):em(`engine.list.emptyQuery`,j,{query:h})}),(0,Y.jsx)(yt,{children:o.emptyStateHint??(a?.allowOrgOverride||a?.allowRuntimeCreate?em(`engine.list.createHint`,j,{type:te}):X(`engine.list.readOnlyHint`,j))}),c.length===0&&(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(G,{onClick:()=>t(`./new`),children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),X(`engine.list.create`,j)]})})]}),!d&&E.length>0&&(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[A.map(e=>(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:ne(e)},e.key)),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:X(`engine.list.col.source`,j)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:E.map((e,t)=>{let n=o.primaryKey??`name`,r=String(e.item[n]??`(unnamed-${t})`),a=e.diagnostics?.valid===!1,s=e.diagnostics?.errors??[],c=e.diagnostics?.warnings??[],l=!a&&c.length>0,u=a?s.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
14
|
+
`)+(s.length>3?`\n+${s.length-3} more`:``):l?c.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
15
|
+
`)+(c.length>3?`\n+${c.length-3} more`:``):``;return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(a?`bg-destructive/[0.04]`:l?`bg-amber-500/[0.05]`:``),children:[A.map((t,n)=>{let o=e.item[t.key],d=t.render?t.render(o,e.item):Nm(o);return(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[a&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":X(`engine.list.invalidTitle`,j),title:`${em(`engine.list.invalidCount`,j,{count:s.length})}\n${u}`,children:(0,Y.jsx)(fn,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),l&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":X(`engine.list.warnTitle`,j),title:`${em(`engine.list.warnCount`,j,{count:c.length})}\n${u}`,children:(0,Y.jsx)(fn,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,Y.jsx)(i,{to:`./${encodeURIComponent(r)}`,className:`text-primary hover:underline font-mono`,children:d})]}):d},t.key)}),(0,Y.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,Y.jsx)(`span`,{className:`inline-flex items-center mr-1 text-amber-600 dark:text-amber-400`,title:e.item._lockReason??`_lock=${String(e.item._lock)}`,children:(0,Y.jsx)(Cr,{className:`h-3 w-3`})}),(0,Y.jsx)(U,{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`?`${X(`engine.list.source.artifactDesc`,j)}${e.item._packageId?` (${e.item._packageId})`:``}`:X(`engine.list.source.runtimeDesc`,j),children:X(`engine.list.source.${e.source}`,j)})]})]},r+t)})})]})})]})})}function Mm(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Nm(e){if(e==null||e===``)return(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,Y.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Pm={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 Fm(e,t){let n=Im(e)?e:{},r=Im(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`:Lm(o)===Lm(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 Im(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Lm(e){try{return JSON.stringify(e,(e,t)=>Im(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Rm(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 zm(e,t){if(e==null)return 0;let n=0;for(let r of Fm(e,t))r.status!==`unchanged`&&(n+=1);return n}function Bm({layered:e,loading:t,locale:n}){if(t)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:X(`engine.edit.loading`,n)});if(!e)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:X(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,Y.jsxs)(Te,{defaultValue:`diff`,className:`w-full`,children:[(0,Y.jsxs)(pa,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(Bi,{value:`diff`,children:X(`engine.layers.diff`,n)}),(0,Y.jsxs)(Bi,{value:`code`,children:[X(`engine.layers.code`,n),(0,Y.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Y.jsxs)(Bi,{value:`overlay`,children:[X(`engine.layers.overlay`,n),r?(0,Y.jsx)(U,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Y.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Y.jsxs)(Bi,{value:`effective`,children:[X(`engine.layers.effective`,n),(0,Y.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Y.jsx)(Gr,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(Vm,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(Gr,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(Um,{payload:e.code,emptyHint:X(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(Gr,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(Um,{payload:e.overlay,emptyHint:X(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(Gr,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(Um,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Vm({code:e,effective:t,locale:n}){let[r,i]=J.useState(!1);if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:X(`engine.layers.diff.noBaseline`,n)});let a=J.useMemo(()=>Fm(e,t),[e,t]),o=J.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]),s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:em(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,Y.jsx)(Ai,{checked:r,onCheckedChange:i,"aria-label":X(`engine.layers.diff.showUnchanged`,n)}),X(`engine.layers.diff.showUnchanged`,n),(0,Y.jsx)(U,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:X(`engine.layers.diff.noChanges`,n)}):(0,Y.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,Y.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,Y.jsx)(`div`,{className:`px-3 py-2`,children:X(`engine.layers.diff.field`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:X(`engine.layers.diff.code`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:X(`engine.layers.diff.effective`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:X(`engine.layers.diff.status`,n)})]}),(0,Y.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Pm[e.status];return(0,Y.jsxs)(`div`,{className:B(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,Y.jsx)(Hm,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)(Hm,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:B(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:X(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function Hm({value:e,muted:t}){let n=Rm(e);return(0,Y.jsx)(`div`,{className:B(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function Um({payload:e,emptyHint:t}){if(e==null)return(0,Y.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,Y.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}function Wm(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return Gm(n.trim(),t)}catch{return!0}}function Gm(e,t){let n=Km(e,`||`);if(n.length>1)return n.some(e=>Gm(e.trim(),t));let r=Km(e,`&&`);if(r.length>1)return r.every(e=>Gm(e.trim(),t));if(e.startsWith(`!`))return!Gm(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=qm(i[1].trim(),t),n=Jm(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=qm(a[1].trim(),t),n=Jm(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!qm(e,t)}function Km(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 qm(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return Jm(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function Jm(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 Ym({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectNames??[],o=t==null?``:String(t);return i?.objectsLoading?(0,Y.jsx)(W,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,Y.jsx)(W,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,Y.jsxs)(Cn,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,Y.jsx)(Wn,{id:e,children:(0,Y.jsx)(vt,{placeholder:`Select object…`})}),(0,Y.jsx)(qa,{children:a.map(e=>(0,Y.jsx)(Be,{value:e,children:e},e))})]})}function Xm({id:e,value:t,onChange:n,readOnly:r,context:i,fieldSpec:a}){let o=i?.objectNames??[],s=a?.multiple??!1,c=J.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,Y.jsx)(W,{id:e,value:`Loading objects...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[c.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:e}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e))}),(0,Y.jsxs)(Cn,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,Y.jsx)(Wn,{id:e,children:(0,Y.jsx)(vt,{placeholder:s?`Add objects...`:`Select object...`})}),(0,Y.jsx)(qa,{children:o.map(e=>(0,Y.jsxs)(Be,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function Zm({id:e,value:t,onChange:n,readOnly:r,fieldSpec:i,formData:a}){let[o,s]=J.useState([]),[c,l]=J.useState(!1),u=i?.dependsOn||i?.reference||`objectName`,d=Array.isArray(u)?u[0]:u,f=a?.[d];J.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=J.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,Y.jsx)(W,{id:e,value:`Loading fields...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[m.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>{let t=o.find(t=>t.name===e);return(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:t?.label||e}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:t?.type}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e)})}),(0,Y.jsxs)(Cn,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,Y.jsx)(Wn,{id:e,children:(0,Y.jsx)(vt,{placeholder:p?`Add fields...`:`Select field...`})}),(0,Y.jsx)(qa,{children:o.map(e=>(0,Y.jsx)(Be,{value:e.name,disabled:!p&&m.includes(e.name),children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.type}),m.includes(e.name)&&` ✓`]})},e.name))})]})]}):(0,Y.jsx)(W,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function Qm({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,Y.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,Y.jsx)(`code`,{children:`items.properties`}),` on the JSON schema (or an `,(0,Y.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,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto rounded border border-border/40`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Y.jsxs)(`tr`,{children:[u.map(e=>(0,Y.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,Y.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e)),(0,Y.jsx)(`th`,{className:`w-8`})]})}),(0,Y.jsxs)(`tbody`,{children:[l.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.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,Y.jsxs)(`tr`,{className:`border-t border-border/30`,children:[u.map(n=>(0,Y.jsx)(`td`,{className:`p-1`,children:(0,Y.jsx)($m,{schema:s[n],value:(e??{})[n],readOnly:r,context:i,onChange:e=>d(t,{[n]:e})})},n)),(0,Y.jsx)(`td`,{className:`p-1 text-right`,children:(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),disabled:r,className:`h-7 w-7 p-0`,"aria-label":`Remove row`,children:(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:r,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function $m({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,Y.jsx)(Ym,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,Y.jsxs)(Cn,{value:t==null?``:String(t),onValueChange:e=>i(e||void 0),disabled:n,children:[(0,Y.jsx)(Wn,{className:`h-8 text-xs`,children:(0,Y.jsx)(vt,{placeholder:`—`})}),(0,Y.jsx)(qa,{children:a.map(e=>(0,Y.jsx)(Be,{value:String(e),children:String(e)},String(e)))})]}):e?.type===`boolean`?(0,Y.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,Y.jsx)(W,{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,Y.jsx)(W,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function eh({id:e,value:t,onChange:n,readOnly:r}){let i=Array.isArray(t)?t:[],[a,o]=J.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,Y.jsx)(`div`,{className:`rounded border border-input bg-background p-1.5`,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map((e,t)=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),!r&&(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e}`,onClick:()=>c(t),className:`text-muted-foreground hover:text-destructive`,children:`×`})]},t)),(0,Y.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 th={"ref:object":Ym,"object-selector":Xm,"field-selector":Zm,"master-detail":Qm,"string-tags":eh,code:ih,"filter-builder":Qm};function nh(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 rh=J.lazy(()=>c(()=>import(`./src-DL8N52oz.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function ih({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=nh(i,e),o=typeof t==`string`?t:t==null?``:String(t);return(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/50 overflow-hidden`,children:[(0,Y.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,Y.jsx)(`span`,{children:a}),r&&(0,Y.jsx)(`span`,{children:`read-only`})]}),(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`h-[280px] flex items-center justify-center text-xs text-muted-foreground`,children:`Loading editor…`}),children:(0,Y.jsx)(rh,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var ah=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function oh(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 sh(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 ch({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=vh(n);else return(0,Y.jsx)(_h,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=xh(Object.keys(d),o).filter(e=>!a.includes(e)),m=J.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,Y.jsx)(uh,{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,Y.jsx)(`div`,{className:`space-y-4`,children:p.map(e=>(0,Y.jsx)(dh,{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 lh(e){return typeof e==`string`?{field:e}:e}function uh({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||Wm(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(lh).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!Wm(e.visibleOn,{data:a})));if(d.length===0)return null;let f=e.columns??1;return(0,Y.jsxs)(`section`,{className:`space-y-3 rounded-md border border-border/40 bg-card/30 p-4`,children:[e.label&&(0,Y.jsxs)(`header`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-foreground/90`,children:e.label}),e.description&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),(0,Y.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,Y.jsx)(`div`,{style:{gridColumn:`span ${e.colSpan??1}`},children:(0,Y.jsx)(dh,{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,Y.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,Y.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(lh).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||Wm(e.visibleOn,{data:a}))));return e.length===0?null:(0,Y.jsxs)(Te,{defaultValue:(e[0].label??`section-0`).toLowerCase(),className:`w-full`,children:[(0,Y.jsx)(pa,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,Y.jsx)(Bi,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,Y.jsx)(Gr,{value:(e.label??`section-${t}`).toLowerCase(),className:`mt-4`,children:f(e,t)},t))]})}return(0,Y.jsx)(`div`,{className:`space-y-4`,children:u.map(f)})}function dh({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||bh(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=sh(o,t),m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=bh(e).toLowerCase()===u.toLowerCase();return m?(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(di,{htmlFor:f,className:`text-sm font-medium cursor-pointer`,children:[u,g&&(0,Y.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),d&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:d}),i?.map((e,t)=>(0,Y.jsx)(`div`,{className:`text-xs text-destructive mt-0.5`,children:e},t))]}),(0,Y.jsx)(fh,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c})]}):(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between gap-2`,children:(0,Y.jsxs)(di,{htmlFor:f,className:`text-sm font-medium`,children:[u,g&&(0,Y.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`}),!_&&(0,Y.jsx)(`code`,{className:`ml-2 text-[10px] font-mono text-muted-foreground/70`,title:`Machine name`,children:e})]})}),(0,Y.jsx)(fh,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c}),d&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:d}),i?.map((e,t)=>(0,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:e},t))]})}function fh({id:e,schema:t,value:n,onChange:r,readOnly:i,widget:a,fieldSpec:o,widgetContext:s,formData:c}){if(o?.type===`composite`)return(0,Y.jsx)(mh,{value:n,fields:o.fields?.length?o.fields:Sh(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,Y.jsx)(hh,{value:n,fields:o.fields?.length?o.fields:Sh(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(o?.type===`record`){let e=t?.additionalProperties??{};return(0,Y.jsx)(gh,{value:n,fields:o.fields?.length?o.fields:Sh(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,keyField:o.keyField,formData:c,onChange:r})}if(a){let l=th[a];if(l)return(0,Y.jsx)(l,{id:e,schema:t,value:n,onChange:r,readOnly:i,context:s,fieldSpec:o,formData:c});let u=oh(t,n);if(u?.type===`object`&&u.properties&&typeof u.properties==`object`)return(0,Y.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,Y.jsx)(ch,{schema:u,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(u?.type===`array`&&u.items&&typeof u.items==`object`){let e=oh(u.items,Array.isArray(n)&&n.length?n[0]:void 0);if(e?.type===`object`&&e.properties&&typeof e.properties==`object`)return(0,Y.jsx)(hh,{value:n,fields:Sh(e),schema:{...u,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}if(!ah.has(a))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(_h,{value:n,onChange:e=>r(e),readOnly:i}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`widget `,(0,Y.jsx)(`code`,{className:`font-mono`,children:a}),` — falling back to JSON until a custom renderer is registered.`]})]})}let l=oh(t,n)??t,u=l?.type,d=o?.options,f=l?.enum??void 0;if(Array.isArray(d)&&d.length>0)return(0,Y.jsxs)(Cn,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(Wn,{id:e,children:(0,Y.jsx)(vt,{placeholder:`Select…`})}),(0,Y.jsx)(qa,{children:d.map(e=>(0,Y.jsxs)(Be,{value:e.value,children:[e.label,e.color&&(0,Y.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,Y.jsxs)(Cn,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(Wn,{id:e,children:(0,Y.jsx)(vt,{placeholder:`Select…`})}),(0,Y.jsx)(qa,{children:f.map(e=>(0,Y.jsx)(Be,{value:String(e),children:String(e)},String(e)))})]});if(u===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,Y.jsx)(Ai,{id:e,checked:!!n,onCheckedChange:e=>r(e),disabled:i});if(u===`number`||u===`integer`){let t=o?.min,a=o?.max;return(0,Y.jsx)(W,{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,Y.jsx)(mn,{id:e,rows:4,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,Y.jsx)(W,{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,Y.jsx)(W,{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,Y.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,Y.jsx)(ch,{schema:l,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(l?.type===`array`&&l.items&&typeof l.items==`object`){let e=oh(l.items,Array.isArray(n)&&n.length?n[0]:void 0);if(e?.type===`object`&&e.properties&&typeof e.properties==`object`)return(0,Y.jsx)(hh,{value:n,fields:Sh(e),schema:{...l,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}return(0,Y.jsx)(_h,{value:n,onChange:r,readOnly:i,small:!0})}function ph(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 mh({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,onChange:a}){let o=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return(0,Y.jsx)(`div`,{className:`rounded-md border border-border/50 bg-muted/20 p-3 space-y-3`,children:t.map(lh).map(e=>{let t=ph(n,`composite`,e.field);return(0,Y.jsx)(dh,{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 hh({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(lh),[l,u]=J.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,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border/50`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Y.jsxs)(`tr`,{children:[c.map(e=>(0,Y.jsxs)(`th`,{className:`px-2 py-1.5 text-left text-xs font-medium`,children:[e.label||bh(e.field),e.required&&(0,Y.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e.field)),!r&&(0,Y.jsx)(`th`,{className:`w-8`})]})}),(0,Y.jsxs)(`tbody`,{children:[s.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:c.length+1,className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:X(`engine.repeater.empty`,tm())})}),s.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=ph(n,`repeater`,a.field);return(0,Y.jsx)(`td`,{className:`p-1.5`,children:(0,Y.jsx)(fh,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:sh(a,o),fieldSpec:a,widgetContext:i,formData:e,onChange:e=>f(t,{[a.field]:e})})},a.field)}),!r&&(0,Y.jsx)(`td`,{className:`p-1.5 text-right`,children:(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),!r&&(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:X(`engine.list.empty`,tm())}),s.map((e,t)=>{let a=l===t,o=c.map(t=>e?.[t.field]).find(e=>e!=null&&e!==``);return(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-muted/10`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5 border-b border-border/30`,children:[(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(qn,{className:`h-3.5 w-3.5`}),(0,Y.jsxs)(`span`,{className:`truncate`,children:[`#`,t+1,o==null?``:` — ${String(o)}`]})]}),!r&&(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=ph(n,`repeater`,a.field);return(0,Y.jsx)(dh,{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,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function gh({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,keyField:o,formData:s,onChange:c}){if(a){let o=th[a];if(o)return(0,Y.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??bh(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(lh).filter(e=>e.field!==l),[g,_]=J.useState(null),[v,y]=J.useState(``),[b,x]=J.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]=J.useState(null),[k,ee]=J.useState(null),A=(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,Y.jsxs)(`div`,{className:`space-y-2`,children:[m.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:X(`engine.list.empty`,tm())}),m.map(([e,t])=>{let a=g===e,s=h.map(e=>t?.[e.field]).find(e=>e!=null&&e!==``);return(0,Y.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&&ee(e))},onDragLeave:()=>{k===e&&ee(null)},onDrop:t=>{!D||r||(t.preventDefault(),A(D,e),O(null),ee(null))},children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5 border-b border-border/30`,children:[!r&&(0,Y.jsx)(`span`,{draggable:!0,onDragStart:t=>{O(e),t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e)},onDragEnd:()=>{O(null),ee(null)},className:`cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground`,"aria-label":`Drag to reorder`,title:`Drag to reorder`,children:(0,Y.jsx)(Ji,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(qn,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted/60`,children:e}),s!=null&&(0,Y.jsxs)(`span`,{className:`truncate text-muted-foreground`,children:[`— `,String(s)]})]}),!r&&(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(e),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(dh,{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&&!Wm(a.visibleOn,{data:t}))return null;let o=ph(n,`record`,a.field);return(0,Y.jsx)(dh,{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,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{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,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:E,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]}),b&&(0,Y.jsx)(`span`,{className:`text-xs text-destructive`,children:b})]})]})}function _h({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=J.useState(()=>yh(e)),[o,s]=J.useState(null);return J.useEffect(()=>{a(yh(e)),s(null)},[JSON.stringify(e)]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(mn,{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,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:o})]})}function vh(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(`
|
|
16
|
+
`)?{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 yh(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function bh(e){return e.replace(/[_-]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function xh(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 Sh(e){let t=e?.properties??{};return Object.keys(t)}function Ch(e){if(typeof e!=`string`)return``;let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``);return/^\d/.test(t)&&(t=`n_${t}`),t.length>64&&(t=t.slice(0,64).replace(/_+$/g,``)),t}function wh(e){if(typeof e!=`string`)return``;let t=e.trim();return t?!/[A-Za-z]/.test(t)||/(s|ses|xes|zes|ches|shes|ies)$/i.test(t)?t:/[^aeiou]y$/i.test(t)?t.replace(/y$/i,`ies`):/(s|x|z|ch|sh)$/i.test(t)?`${t}es`:`${t}s`:``}function Th(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function Eh(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function Dh(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return Ch(n);case`plural-en`:return wh(n);case`titlecase`:return Th(n);case`first-token`:return Eh(n);default:return n}}function Oh(e){let{rules:t,draft:n,onPatch:r,enabled:i=!0}=e,a=(0,J.useRef)(new Set),o=(0,J.useRef)({}),s=(0,J.useCallback)(e=>{a.current.add(e)},[]);return(0,J.useEffect)(()=>{if(!i||!t||t.length===0)return;let e={},s=o.current,c={};for(let r of t){let t=n[r.from];if(c[r.from]=t,Object.is(s[r.from],t)||r.untilUserEdits!==!1&&a.current.has(r.to)||r.to in e)continue;let i=Dh(r.transform,t);n[r.to]!==i&&(e[r.to]=i)}o.current={...s,...c},Object.keys(e).length>0&&r(e)},[n,i]),{markTouched:s,touched:a.current}}function kh(e,t){let n=e?Object.keys(e):[],r=[],i=e=>{!r.includes(e)&&n.includes(e)&&r.push(e)};for(let e of n)t?.includes(e)&&i(e);for(let e of[`label`,`pluralLabel`,`name`,`description`])i(e);return r}function Ah({type:e,name:t,parentItem:n,onOpen:r}){let i=Bp(),a=s(),o=J.useMemo(()=>Dm(e),[e]),[c,l]=J.useState([]),[u,d]=J.useState(``),[f,p]=J.useState({});if(J.useEffect(()=>{if(o.length===0){l([]);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(jh)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return l(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=>jh(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||l(t)}),()=>{e=!0}},[i,e,t,o,n]),o.length===0)return(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:`No related metadata`}),(0,Y.jsxs)(yt,{children:[`No metadata types are configured to anchor at `,(0,Y.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let m=c.reduce((e,t)=>e+t.items.length,0),h=c.some(e=>e.loading),g=u.trim().toLowerCase();return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,Y.jsx)(pr,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(W,{placeholder:`Search related…`,value:u,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),c.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,o=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!o})),children:[(0,Y.jsx)(qn,{className:B(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,Y.jsx)(G,{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,Y.jsx)(H,{className:`h-3.5 w-3.5`})})]}),!o&&(0,Y.jsxs)(`div`,{children:[n.loading&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:g?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,Y.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,Y.jsx)(`th`,{className:`w-8`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,Y.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,Y.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,Y.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,Y.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,Y.jsx)(Jr,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function jh(e){return{name:Mh(e,[`name`,`id`,`key`])??`(unnamed)`,label:Mh(e,[`label`,`title`,`displayName`]),description:Mh(e,[`description`,`summary`]),raw:e}}function Mh(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function Nh({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=Bp(),{entries:c}=Hp(s),l=i?c.find(e=>e.type===i):void 0,u=!l?.schema&&i?Fh[i]:void 0,d=l?.schema??u?.schema,f=l?.form??u?.form,[p,m]=J.useState(a),[h,g]=J.useState(!1),[_,v]=J.useState(null),[y,b]=J.useState([]),[x,S]=J.useState(null);J.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=Ph(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,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[_&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:_}),x!=null&&!_&&(0,Y.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:`Saved.`}),C&&(0,Y.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,Y.jsx)(ch,{schema:d,form:f,value:p,onChange:m,issues:y}),(0,Y.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,Y.jsxs)(G,{onClick:w,disabled:h||!n,children:[h?(0,Y.jsx)(K,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(wr,{className:`h-4 w-4 mr-1`}),`Save into `,e]})}),!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Read-only`}),(0,Y.jsx)(`div`,{children:`No embedded path registered — cannot determine where to write this item back.`})]})]}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`No form schema is registered for`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:i??`this item`}),`. Edit the raw JSON below; saving will splice it back into`,` `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[e,`/`,t,`.`,n,`.`,r]}),`.`]}),(0,Y.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,Y.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,Y.jsx)(fn,{className:`h-4 w-4 inline mr-1`}),` `,_]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsxs)(G,{onClick:w,disabled:h||!n,children:[h?(0,Y.jsx)(K,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(wr,{className:`h-4 w-4 mr-1`}),`Save into parent`]})})]})}function Ph(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 Fh={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 Ih({target:e,onClose:t,parentContext:n}){let r=s(),i=e?.kind===`metadata`,a=e?.kind===`embedded`,o=i?e.type:a?e.groupLabel:``,c=i?e.name:a?e.itemName:``;return(0,Y.jsx)(qt,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)($t,{side:`right`,className:B(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,Y.jsx)(Ct,{className:`font-mono text-base truncate`,children:c}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,Y.jsx)(Jr,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Y.jsxs)(pn,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,Y.jsx)(Cg,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,Y.jsx)(Nh,{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 Lh({type:e,name:t}){let n=f(),r=e??n.type??``,i=t??n.name??``,a=s(),o=Bp(),{entries:c}=Hp(o),l=c.find(e=>e.type===r),[u,d]=J.useState(0),[p,m]=J.useState(0);return(0,Y.jsx)(Sm,{entry:l??{type:r,label:r},itemName:i,subtitle:`Version history`,stats:[{label:`Events`,value:p}],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>a(`../${encodeURIComponent(i)}`),children:[(0,Y.jsx)(ja,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>d(e=>e+1),children:(0,Y.jsx)(tn,{className:`h-4 w-4`})})]}),children:(0,Y.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Y.jsx)(Rh,{type:r,name:i,refreshKey:u,onCount:m,client:o,onRollback:()=>d(e=>e+1)})})})}function Rh({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=J.useState([]),[u,d]=J.useState(!0),[f,p]=J.useState(null),[m,h]=J.useState(null),[g,_]=J.useState(null),[v,y]=J.useState(0);J.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function b(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,Y.jsxs)(Y.Fragment,{children:[u&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,Y.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,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:`No history yet`}),(0,Y.jsx)(yt,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,Y.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,Y.jsxs)(`li`,{className:`relative`,children:[(0,Y.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Y.jsx)(U,{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,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:zh(i)}),o&&(0,Y.jsx)(G,{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,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Oa,{className:`h-3.5 w-3.5`})})]}),n&&(0,Y.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:Bh(e)})]})]},`${e.seq??t}-${t}`)})})]})}function zh(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function Bh(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Vh(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Hh(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:Ir},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:Ei},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:qr}},n=t[e]??t.allowed;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${n.cls}`,children:[(0,Y.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function Uh({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=J.useState(!1),[o,s]=J.useState(null),[c,l]=J.useState(null),u=J.useCallback(async()=>{a(!0),s(null);try{l((await n.audit(e,t,{limit:100})).events??[])}catch(e){s(String(e?.message??e)),l([])}finally{a(!1)}},[n,e,t]);return J.useEffect(()=>{u()},[u]),(0,Y.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,X(`engine.edit.auditCount`,r)]}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:X(`engine.edit.refresh`,r),children:[i?(0,Y.jsx)(K,{className:`h-3 w-3 animate-spin`}):(0,Y.jsx)(tn,{className:`h-3 w-3`}),X(`engine.edit.refresh`,r)]})]}),o&&(0,Y.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,Y.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,Y.jsx)(K,{className:`mr-2 h-3 w-3 animate-spin`}),X(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Y.jsxs)(nt,{className:`py-10`,children:[(0,Y.jsx)(Ua,{children:X(`engine.edit.auditEmptyTitle`,r)}),(0,Y.jsx)(yt,{children:X(`engine.edit.auditEmptyDescription`,r)})]}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColTime`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColActor`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColOperation`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColOutcome`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColLock`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:X(`engine.edit.auditColNote`,r)})]})}),(0,Y.jsx)(`tbody`,{children:c.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:Vh(e.occurredAt)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:Hh(e.outcome)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,Y.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,Y.jsx)(`td`,{className:`max-w-[28ch] truncate px-2 py-1.5 text-muted-foreground`,title:e.note??e.code,children:e.note??e.code})]},String(e.id)))})]})})]})}var Wh=new Map;function Gh(e,t){Wh.set(e,t)}function Kh(e){return Wh.get(e)}var qh=new Map;function Jh(e,t){qh.set(e,t)}function Yh(e){return qh.get(e)}function Xh(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&$h(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&$h(e.charCodeAt(r)))for(r++;r<e.length&&$h(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&$h(e.charCodeAt(r))){for(r++;r<e.length&&$h(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
17
|
+
`;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(Qh(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(Zh(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Zh(t));return o=15}if(Qh(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
18
|
+
`),s++,l=r,o=14;switch(t){case 123:return r++,o=1;case 125:return r++,o=2;case 91:return r++,o=3;case 93:return r++,o=4;case 58:return r++,o=6;case 44:return r++,o=5;case 34:return r++,i=h(),o=10;case 47:let c=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Qh(e.charCodeAt(r));)r++;return i=e.substring(c,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;let t=n-1,a=!1;for(;r<t;){let t=e.charCodeAt(r);if(t===42&&e.charCodeAt(r+1)===47){r+=2,a=!0;break}r++,Qh(t)&&(t===13&&e.charCodeAt(r)===10&&r++,s++,l=r)}return a||(r++,d=1),i=e.substring(c,r),o=13}return i+=String.fromCharCode(t),r++,o=16;case 45:if(i+=String.fromCharCode(t),r++,r===n||!$h(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=m(),o=11;default:for(;r<n&&_(t);)r++,t=e.charCodeAt(r);if(a!==r){switch(i=e.substring(a,r),i){case`true`:return o=8;case`false`:return o=9;case`null`:return o=7}return o=16}return i+=String.fromCharCode(t),r++,o=16}}function _(e){if(Zh(e)||Qh(e))return!1;switch(e){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function v(){let e;do e=g();while(e>=12&&e<=15);return e}return{setPosition:p,getPosition:()=>r,scan:t?v:g,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>a,getTokenLength:()=>r-a,getTokenStartLine:()=>c,getTokenStartCharacter:()=>a-u,getTokenError:()=>d}}function Zh(e){return e===32||e===9}function Qh(e){return e===10||e===13}function $h(e){return e>=48&&e<=57}var eg;(function(e){e[e.lineFeed=10]=`lineFeed`,e[e.carriageReturn=13]=`carriageReturn`,e[e.space=32]=`space`,e[e._0=48]=`_0`,e[e._1=49]=`_1`,e[e._2=50]=`_2`,e[e._3=51]=`_3`,e[e._4=52]=`_4`,e[e._5=53]=`_5`,e[e._6=54]=`_6`,e[e._7=55]=`_7`,e[e._8=56]=`_8`,e[e._9=57]=`_9`,e[e.a=97]=`a`,e[e.b=98]=`b`,e[e.c=99]=`c`,e[e.d=100]=`d`,e[e.e=101]=`e`,e[e.f=102]=`f`,e[e.g=103]=`g`,e[e.h=104]=`h`,e[e.i=105]=`i`,e[e.j=106]=`j`,e[e.k=107]=`k`,e[e.l=108]=`l`,e[e.m=109]=`m`,e[e.n=110]=`n`,e[e.o=111]=`o`,e[e.p=112]=`p`,e[e.q=113]=`q`,e[e.r=114]=`r`,e[e.s=115]=`s`,e[e.t=116]=`t`,e[e.u=117]=`u`,e[e.v=118]=`v`,e[e.w=119]=`w`,e[e.x=120]=`x`,e[e.y=121]=`y`,e[e.z=122]=`z`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.asterisk=42]=`asterisk`,e[e.backslash=92]=`backslash`,e[e.closeBrace=125]=`closeBrace`,e[e.closeBracket=93]=`closeBracket`,e[e.colon=58]=`colon`,e[e.comma=44]=`comma`,e[e.dot=46]=`dot`,e[e.doubleQuote=34]=`doubleQuote`,e[e.minus=45]=`minus`,e[e.openBrace=123]=`openBrace`,e[e.openBracket=91]=`openBracket`,e[e.plus=43]=`plus`,e[e.slash=47]=`slash`,e[e.formFeed=12]=`formFeed`,e[e.tab=9]=`tab`})(eg||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var tg=200;Array(tg).fill(0).map((e,t)=>`
|
|
19
|
+
`+` `.repeat(t)),Array(tg).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(tg).fill(0).map((e,t)=>`\r
|
|
20
|
+
`+` `.repeat(t)),Array(tg).fill(0).map((e,t)=>`
|
|
21
|
+
`+` `.repeat(t)),Array(tg).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(tg).fill(0).map((e,t)=>`\r
|
|
22
|
+
`+` `.repeat(t));var ng;(function(e){e.DEFAULT={allowTrailingComma:!1}})(ng||={});function rg(e,t=[],n=ng.DEFAULT){let r={type:`array`,offset:-1,length:-1,children:[],parent:void 0};function i(e){r.type===`property`&&(r.length=e-r.offset,r=r.parent)}function a(e){return r.children.push(e),e}ag(e,{onObjectBegin:e=>{r=a({type:`object`,offset:e,length:-1,parent:r,children:[]})},onObjectProperty:(e,t,n)=>{r=a({type:`property`,offset:t,length:-1,parent:r,children:[]}),r.children.push({type:`string`,value:e,offset:t,length:n,parent:r})},onObjectEnd:(e,t)=>{i(e+t),r.length=e+t-r.offset,r=r.parent,i(e+t)},onArrayBegin:(e,t)=>{r=a({type:`array`,offset:e,length:-1,parent:r,children:[]})},onArrayEnd:(e,t)=>{r.length=e+t-r.offset,r=r.parent,i(e+t)},onLiteralValue:(e,t,n)=>{a({type:og(e),offset:t,length:n,parent:r,value:e}),i(t+n)},onSeparator:(e,t,n)=>{r.type===`property`&&(e===`:`?r.colonOffset=t:e===`,`&&i(t))},onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n);let o=r.children[0];return o&&delete o.parent,o}function ig(e,t){if(!e)return;let n=e;for(let e of t)if(typeof e==`string`){if(n.type!==`object`||!Array.isArray(n.children))return;let t=!1;for(let r of n.children)if(Array.isArray(r.children)&&r.children[0].value===e&&r.children.length===2){n=r.children[1],t=!0;break}if(!t)return}else{let t=e;if(n.type!==`array`||t<0||!Array.isArray(n.children)||t>=n.children.length)return;n=n.children[t]}return n}function ag(e,t,n=ng.DEFAULT){let r=Xh(e,!1),i=[],a=0;function o(e){return e?()=>a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function s(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function c(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function l(e){return e?()=>{a>0?a++:e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(a=1)}:()=>!0}function u(e){return e?()=>{a>0&&a--,a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}let d=l(t.onObjectBegin),f=c(t.onObjectProperty),p=u(t.onObjectEnd),m=l(t.onArrayBegin),h=u(t.onArrayEnd),g=c(t.onLiteralValue),_=s(t.onSeparator),v=o(t.onComment),y=s(t.onError),b=n&&n.disallowComments,x=n&&n.allowTrailingComma;function S(){for(;;){let e=r.scan();switch(r.getTokenError()){case 4:C(14);break;case 5:C(15);break;case 3:C(13);break;case 1:b||C(11);break;case 2:C(12);break;case 6:C(16);break}switch(e){case 12:case 13:b?C(10):v();break;case 16:C(1);break;case 15:case 14:break;default:return e}}}function C(e,t=[],n=[]){if(y(e),t.length+n.length>0){let e=r.getToken();for(;e!==17;){if(t.indexOf(e)!==-1){S();break}else if(n.indexOf(e)!==-1)break;e=S()}}}function w(e){let t=r.getTokenValue();return e?g(t):(f(t),i.push(t)),S(),!0}function T(){switch(r.getToken()){case 11:let e=r.getTokenValue(),t=Number(e);isNaN(t)&&(C(2),t=0),g(t);break;case 7:g(null);break;case 8:g(!0);break;case 9:g(!1);break;default:return!1}return S(),!0}function E(){return r.getToken()===10?(w(!1),r.getToken()===6?(_(`:`),S(),k()||C(4,[],[2,5])):C(5,[],[2,5]),i.pop(),!0):(C(3,[],[2,5]),!1)}function D(){d(),S();let e=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(e||C(4,[],[]),_(`,`),S(),r.getToken()===2&&x)break}else e&&C(6,[],[]);E()||C(4,[],[2,5]),e=!0}return p(),r.getToken()===2?S():C(7,[2],[]),!0}function O(){m(),S();let e=!0,t=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(t||C(4,[],[]),_(`,`),S(),r.getToken()===4&&x)break}else t&&C(6,[],[]);e?(i.push(0),e=!1):i[i.length-1]++,k()||C(4,[],[4,5]),t=!0}return h(),e||i.pop(),r.getToken()===4?S():C(8,[4],[]),!0}function k(){switch(r.getToken()){case 3:return O();case 1:return D();case 10:return w(!0);default:return T()}}return S(),r.getToken()===17?n.allowEmptyContent?!0:(C(4,[],[]),!1):k()?(r.getToken()!==17&&C(9,[],[]),!0):(C(4,[],[]),!1)}function og(e){switch(typeof e){case`boolean`:return`boolean`;case`number`:return`number`;case`string`:return`string`;case`object`:return e?Array.isArray(e)?`array`:`object`:`null`;default:return`null`}}var sg;(function(e){e[e.None=0]=`None`,e[e.UnexpectedEndOfComment=1]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=2]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=3]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=4]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=5]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=6]=`InvalidCharacter`})(sg||={});var cg;(function(e){e[e.OpenBraceToken=1]=`OpenBraceToken`,e[e.CloseBraceToken=2]=`CloseBraceToken`,e[e.OpenBracketToken=3]=`OpenBracketToken`,e[e.CloseBracketToken=4]=`CloseBracketToken`,e[e.CommaToken=5]=`CommaToken`,e[e.ColonToken=6]=`ColonToken`,e[e.NullKeyword=7]=`NullKeyword`,e[e.TrueKeyword=8]=`TrueKeyword`,e[e.FalseKeyword=9]=`FalseKeyword`,e[e.StringLiteral=10]=`StringLiteral`,e[e.NumericLiteral=11]=`NumericLiteral`,e[e.LineCommentTrivia=12]=`LineCommentTrivia`,e[e.BlockCommentTrivia=13]=`BlockCommentTrivia`,e[e.LineBreakTrivia=14]=`LineBreakTrivia`,e[e.Trivia=15]=`Trivia`,e[e.Unknown=16]=`Unknown`,e[e.EOF=17]=`EOF`})(cg||={});var lg=rg,ug=ig,dg;(function(e){e[e.InvalidSymbol=1]=`InvalidSymbol`,e[e.InvalidNumberFormat=2]=`InvalidNumberFormat`,e[e.PropertyNameExpected=3]=`PropertyNameExpected`,e[e.ValueExpected=4]=`ValueExpected`,e[e.ColonExpected=5]=`ColonExpected`,e[e.CommaExpected=6]=`CommaExpected`,e[e.CloseBraceExpected=7]=`CloseBraceExpected`,e[e.CloseBracketExpected=8]=`CloseBracketExpected`,e[e.EndOfFileExpected=9]=`EndOfFileExpected`,e[e.InvalidCommentToken=10]=`InvalidCommentToken`,e[e.UnexpectedEndOfComment=11]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=12]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=13]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=14]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=15]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=16]=`InvalidCharacter`})(dg||={});var fg=J.lazy(async()=>({default:(await c(()=>import(`./dist-Dal4BOHf.js`),[],import.meta.url)).default}));function pg(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function mg(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function hg({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let[a,o]=J.useState(()=>pg(e)),[s,c]=J.useState(null),l=J.useRef(a),u=J.useRef(null),d=J.useRef(null),[f,p]=J.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);J.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>p(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let m=J.useCallback(()=>{let e=u.current,t=d.current;if(!e||!t)return;let n=e.getModel();if(!n)return;if(!r||r.length===0){t.editor.setModelMarkers(n,`objectui-diagnostics`,[]);return}let i;try{i=lg(a)}catch{i=void 0}let o=r.map(e=>{let r=mg(e.path),a=1,o=1,s=1,c=2,l=i?ug(i,r):void 0;if(l){let e=n.getPositionAt(l.offset),t=n.getPositionAt(l.offset+l.length);a=e.lineNumber,o=e.column,s=t.lineNumber,c=t.column}return{severity:e.severity===`warning`?t.MarkerSeverity.Warning:t.MarkerSeverity.Error,message:e.path?`${e.path}: ${e.message}`:e.message,startLineNumber:a,startColumn:o,endLineNumber:s,endColumn:c,source:`metadata`}});t.editor.setModelMarkers(n,`objectui-diagnostics`,o)},[r,a]);return J.useEffect(()=>{m()},[m]),J.useEffect(()=>{let t=pg(e);t!==l.current&&(o(t),l.current=t,c(null))},[e]),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`border rounded overflow-hidden bg-background`,style:{height:typeof i==`number`?`${i}px`:i},children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(V,{className:`w-full h-full`}),children:(0,Y.jsx)(fg,{value:a,language:`json`,theme:f,onChange:e=>{let n=e??``;o(n);try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)?(c(null),l.current=n,t(e)):c(`Root must be a JSON object`)}catch(e){c(e?.message??`Invalid JSON`)}},onMount:(e,t)=>{u.current=e,d.current=t,setTimeout(m,0)},options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,renderLineHighlight:`line`,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),s&&(0,Y.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,Y.jsx)(`span`,{children:s})]})]})}var gg={object:async()=>(await c(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.a);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await c(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.a);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await c(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.a);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await c(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.a);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await c(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await c(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await c(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await c(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await c(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await c(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await c(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.t);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await c(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.o);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,workflow:async()=>(await c(async()=>{let{WorkflowRuleSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.o);return{WorkflowRuleSchema:e}},[],import.meta.url)).WorkflowRuleSchema,approval:async()=>(await c(async()=>{let{ApprovalProcessSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.o);return{ApprovalProcessSchema:e}},[],import.meta.url)).ApprovalProcessSchema,webhook:async()=>(await c(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.o);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await c(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.c);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await c(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.c);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await c(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.c);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await c(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.n);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await c(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.n);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.r);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.r);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await c(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.r);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await c(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.i);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await c(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-B3zP6Fz_.js`).then(e=>e.s);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},_g=new Map;async function vg(e){if(_g.has(e))return _g.get(e)??null;let t=gg[e];if(!t)return _g.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return _g.set(e,r),r}catch{return _g.set(e,null),null}}function yg(e){return e in gg}async function bg(e,t){let n=await vg(e);if(!n)return{ok:!0,issues:[]};let r=n.safeParse(t);return r.success?{ok:!0,issues:[]}:{ok:!1,issues:(r.error?.issues??[]).map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message}))}}var xg=$i;function Sg(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 Cg({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=f(),a=e??i.type??``,o=t??i.name??``,s=Em(a);if(s?.EditPage&&!n){let e=s.EditPage;return(0,Y.jsx)(e,{type:a,name:o})}if(s?.CreatePage&&n){let e=s.CreatePage;return(0,Y.jsx)(e,{type:a})}return(0,Y.jsx)(wg,{type:a,name:o,createMode:n,embedded:r})}function wg({type:e,name:t,createMode:n,embedded:r}){let i=s(),a=Bp(),{entries:o}=Hp(a),c=o.find(t=>t.type===e),l=Om(e,c),u=(n&&l.createSchema?l.createSchema:c?.schema)??l.defaultSchema,d=J.useMemo(()=>tm(),[]),[f,p]=J.useState(null),m=l.identityField??`name`,[h,g]=J.useState(()=>n?{...l.createDefaults??{},[m]:``}:{}),[_,v]=J.useState(null),[y,b]=J.useState(!n),[x,S]=J.useState(!1),[C,w]=J.useState(null),[T,E]=J.useState([]),D=J.useCallback(e=>{g(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&E(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[O,k]=J.useState(null),[ee,A]=J.useState(null),j=J.useCallback(e=>{D(t=>({...t,...e}))},[D]),{markTouched:te}=Oh({rules:l.createDerive,draft:h,onPatch:j,enabled:!!n}),ne=J.useMemo(()=>{if(n)return l.createFields&&l.createFields.length>0?l.createFields:kh(u?.properties??void 0,u?.required??void 0)},[n,l.createFields,u]),re=J.useMemo(()=>{if(!n||!ne)return l.hiddenFields;let e=u?.properties??{},t=new Set(ne),r=Object.keys(e).filter(e=>!t.has(e));if(l.hiddenFields)for(let e of l.hiddenFields)r.includes(e)||r.push(e);return r},[n,ne,u,l.hiddenFields]),M=J.useMemo(()=>n&&ne?ne:l.fieldOrder,[n,ne,l.fieldOrder]),N=J.useCallback(e=>{if(n){let t=h,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||te(e)}D(e)},[n,h,D,te]);J.useEffect(()=>{if(!yg(e))return;let t=!1,n=window.setTimeout(()=>{bg(e,h).then(e=>{t||E(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,h]);let[ie,ae]=J.useState(!1),[P,oe]=J.useState(!1),[se,ce]=J.useState(0),[le,ue]=J.useState(!!n),[de,fe]=J.useState(null);J.useEffect(()=>{fe(null)},[e,t]),J.useEffect(()=>{le||fe(null)},[le]);let pe=J.useRef(null),[me,he]=J.useState(null),[ge,_e]=J.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null?!0:e===`1`}catch{return!0}});J.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,ge?`1`:`0`)}catch{}},[ge]);let ve=J.useRef(null),[F,I]=J.useState([]),[L,ye]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`object`);if(e)return;I(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||I([])}finally{e||ye(!1)}})(),()=>{e=!0}},[a]);let R=J.useMemo(()=>({objectNames:F,objectsLoading:L}),[F,L]);J.useEffect(()=>{if(n){b(!1);return}let r=!1;return b(!0),w(null),(async()=>{try{let[n,i]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);if(r)return;p(n);let o=n?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?E(o.errors.map(e=>({path:e.path||``,message:e.message}))):E([]);let s=Sg(i),c=s??n.effective??n.code??{};g(c),pe.current=c,ae(!!s),b(!1)}catch(e){r||(w(e?.message??String(e)),b(!1))}})(),()=>{r=!0}},[a,e,t,n,se]);let[be,z]=J.useState(!1);async function xe(){if(!(_!=null||be)){z(!0);try{v(await a.references(e,t))}catch(e){v([]),console.error(`references() failed`,e)}finally{z(!1)}}}let[Se,Ce]=J.useState(null),we=J.useMemo(()=>!n&&!r&&Dm(e).length>0,[e,n,r]),Te=J.useRef(null),[Ee,De]=J.useState(null),[Oe,ke]=J.useState(`properties`);J.useEffect(()=>{if(Ee===`references`&&xe(),typeof window<`u`&&!r){let e=new URL(window.location.href);Ee?e.searchParams.set(`tab`,Ee):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[Ee,r]);let Ae=`metadata-edit:inspector-collapsed`,je=`metadata-edit:inspector-size`,[Me,Ne]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Ae)===`1`),Pe=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(je));Number.isFinite(e)&&e>=22&&e<=80&&(Pe.current=e)},[]);let Fe=J.useRef(null),B=J.useCallback(()=>{Ne(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Ae,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=Fe.current;if(e)if(Me)e.resize?.(`0%`);else{let t=Pe.current||38;e.resize?.(`${t}%`)}},[Me]);let[V,Ie]=J.useState(!1),[Le,ze]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!Le)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[Le]),J.useEffect(()=>{if(typeof window>`u`||!Le)return;function e(e){e.key===`Escape`&&(e.preventDefault(),ze(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Le]);let Be=J.useRef(null);J.useEffect(()=>{Be.current=null},[e,t]),J.useEffect(()=>{if(n||r||y)return;let i=`${e}/${t??``}`;Be.current!==i&&Kh(e)&&(f?.code==null?c?.allowOrgOverride||c?.allowRuntimeCreate:c?.allowOrgOverride)&&(Be.current=i,ue(!0))},[e,t,n,r,y,c,f]),J.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),B())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,B]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&De(t),Te.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&Ce({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);Se?.kind===`metadata`?e.searchParams.set(`open`,`${Se.type}:${Se.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[Se,r]);async function Ve(r){S(!0),w(null),E([]);try{let o=n?l.createBuildBody?l.createBuildBody(h):{...l.createDefaults??{},...h}:h,s=String(o[m]??h[m]??t),c=n?{...o,[m]:s}:o;if(!s){w(`A name is required.`),S(!1);return}await a.save(e,s,c,{force:r,mode:`draft`});let[u,d]=await Promise.all([a.layered(e,s),a.getDraft(e,s).catch(()=>null)]);p(u);let f=Sg(d);ae(!!f);let _=f??u.effective??c;g(_),pe.current=_,he(new Date),ve.current=JSON.stringify(_),k(null),A(null);let v=!n&&!!Kh(e);!n&&!v&&ue(!1),n&&i(`../${encodeURIComponent(s)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];k(Array.isArray(t)?t:[]),A(h)}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}]}E(n),n.length===1&&!n[0].path?w(n[0].message):n.length===1?w(`${n[0].path}: ${n[0].message}`):w(`Validation failed (${n.length} issues).`)}else w(e?.message??String(e))}finally{S(!1)}}async function He(){let r=!n&&f?.code!=null;if(confirm(em(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{if(await a.reset(e,t),r){let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),pe.current=r,Kh(e)?Be.current=null:ue(!1)}else i(`../`,{relative:`path`})}catch(e){w(e?.message??String(e))}finally{S(!1)}}}async function Ue(){oe(!0),w(null);try{await a.publish(e,t);let[n,r]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);p(n);let i=Sg(r);ae(!!i);let o=i??n.effective??h;g(o),pe.current=o}catch(e){w(e?.message??String(e))}finally{oe(!1)}}async function We(){if(confirm(em(`engine.edit.discardDraftConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{await a.reset(e,t,{state:`draft`});let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),pe.current=r,ae(!1)}catch(e){w(e?.message??String(e))}finally{S(!1)}}}let Ge=J.useMemo(()=>{if(n)return Object.keys(h).length>0;let e=pe.current;if(!e)return!1;try{return JSON.stringify(h)!==JSON.stringify(e)}catch{return!1}},[h,n]),Ke=!n&&f?.code!=null,qe=f?.editable!==!1,Je=f?.deletable!==!1,Ye=f?.resettable!==!1,Ze=f?.lockReason,Qe=f?.lock&&f.lock!==`none`,$e=(n?!!(c?.allowOrgOverride||c?.allowRuntimeCreate):Ke?!!c?.allowOrgOverride:!!(c?.allowOrgOverride||c?.allowRuntimeCreate))&&(n||qe),et=!$e&&!n,tt=J.useRef(Ve);if(J.useEffect(()=>{tt.current=Ve}),J.useEffect(()=>{if(!ge||n||et||!le||!Ge||x)return;let e;try{e=JSON.stringify(h)}catch{return}if(e===ve.current)return;let t=window.setTimeout(()=>{ve.current=e,tt.current(!1)},1500);return()=>window.clearTimeout(t)},[h,Ge,le,x,n,et,ge]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!$e||et||!le&&!n)return;e.preventDefault(),!x&&(n||Ge)&&tt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[$e,et,le,n,x,Ge]),J.useEffect(()=>{if(!Ge)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ge]),J.useEffect(()=>{if(!Ge)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(X(`engine.edit.unsavedLeaveConfirm`,d))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[Ge,d]),y)return(0,Y.jsx)(Sm,{entry:c,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let nt=et&&Ke&&!!c?.allowRuntimeCreate,rt=!n&&!r?Kh(e):void 0,H=Yh(e);function at(){pe.current&&g(pe.current),E([]),w(null),ue(!1)}let ot=et||!le&&!n,ct=(0,Y.jsxs)(Y.Fragment,{children:[(!n||we)&&(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>De(`layers`),title:X(`engine.edit.layers`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(mi,{className:`h-3.5 w-3.5`}),f?.overlay&&(()=>{let e=zm(f.code,f.effective);return e>0?(0,Y.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:X(`engine.layers.diff`,d),children:e}):null})()]}),!n&&(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>De(`references`),title:X(`engine.edit.references`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`}),_&&_.length>0&&(0,Y.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:_.length})]}),we&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>De(`related`),title:X(`engine.edit.related`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Pr,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>De(`history`),title:X(`engine.edit.history`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Fn,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>De(`audit`),title:X(`engine.edit.auditTab`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5`})})]}),!n&&$e&&f?.overlay&&(Ke?Ye:Je)&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:He,disabled:x,title:X(Ke?`engine.edit.reset`:`engine.edit.delete`,d),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Ke?(0,Y.jsx)(Oa,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})}),$e&&!n&&!le&&!rt&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>ue(!0),className:`h-7`,children:[(0,Y.jsx)(ht,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]}),$e&&(le||n)&&(0,Y.jsx)(Eg,{saving:x,isDirty:Ge,autoSaveEnabled:ge,lastSavedAt:me,createMode:!!n,locale:d}),$e&&(le||n)&&!n&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>_e(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:X(ge?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,d),children:ge?(0,Y.jsx)(Ba,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(Er,{className:`h-3.5 w-3.5`})}),$e&&!n&&le&&!rt&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:at,disabled:x,className:`h-7 w-7 p-0`,title:X(`engine.cancel`,d),children:(0,Y.jsx)(Fa,{className:`h-3.5 w-3.5`})}),$e&&(le||n)&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>Ve(!1),disabled:x||!n&&!Ge,className:`h-7 w-7 p-0 relative`,title:x?X(`engine.edit.saving`,d):!n&&!Ge?X(`engine.edit.noChanges`,d):`${X(`engine.edit.save`,d)} (⌘S)`,children:[x?(0,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(wr,{className:`h-3.5 w-3.5`}),Ge&&!x&&(0,Y.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`})]}),$e&&!n&&ie&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:We,disabled:x||P,className:`h-7 w-7 p-0 text-muted-foreground`,title:X(`engine.edit.discardDraft`,d),children:(0,Y.jsx)(Gt,{className:`h-3.5 w-3.5`})}),$e&&!n&&ie&&(0,Y.jsx)(G,{size:`sm`,onClick:Ue,disabled:x||P||Ge,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:X(Ge?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,d),children:P?(0,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ei,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:X(`engine.edit.publish`,d)})]})})]});return(0,Y.jsxs)(Sm,{entry:c??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?X(`engine.edit.createNew`,d):void 0,actions:rt?null:ct,children:[(0,Y.jsxs)(`div`,{className:rt?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(C||et||ie||Qe)&&(0,Y.jsxs)(`div`,{className:rt?`px-6 pt-4 space-y-3`:`space-y-3`,children:[C&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:C}),Qe&&(0,Y.jsxs)(`div`,{className:`text-xs text-amber-900 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-2.5`,children:[(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`font-medium`,children:[f?.lock===`full`&&X(`engine.edit.lockFull`,d),f?.lock===`no-overlay`&&X(`engine.edit.lockNoOverlay`,d),f?.lock===`no-delete`&&X(`engine.edit.lockNoDelete`,d)]}),Ze&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Ze}),f?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:f.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[d===`zh-CN`?`查看文档`:`View docs`,` →`]}),f?.packageId&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Y.jsxs)(`code`,{className:`font-mono`,children:[f.packageId,f.packageVersion?`@${f.packageVersion}`:``]})})]}),nt&&(0,Y.jsx)(G,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]}),ie&&!n&&(0,Y.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,Y.jsx)(ei,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:X(`engine.edit.draftPending`,d)}),$e&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:We,disabled:x||P,className:`h-7`,children:X(`engine.edit.discardDraft`,d)}),(0,Y.jsx)(G,{size:`sm`,onClick:Ue,disabled:x||P||Ge,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:P?(0,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}):X(`engine.edit.publish`,d)})]})]}),et&&!Qe&&(0,Y.jsxs)(`div`,{className:`text-xs text-amber-800 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex-1`,children:nt?X(`engine.edit.artifactLockedBanner`,d).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Y.jsx)(J.Fragment,{children:t},n)):X(`engine.edit.readOnlyTypeBanner`,d).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Y.jsx)(J.Fragment,{children:t},n))}),nt&&(0,Y.jsx)(G,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]})]}),(0,Y.jsx)(`div`,{className:rt?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:rt?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!rt&&ot&&!et&&$e&&!n&&(0,Y.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,Y.jsx)(`span`,{children:X(`engine.edit.readOnlyBanner`,d).split(/\{edit\}/).map((e,t,n)=>(0,Y.jsxs)(J.Fragment,{children:[e,t<n.length-1&&(0,Y.jsx)(`strong`,{children:X(`engine.edit.edit`,d)})]},t))}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>ue(!0),children:[(0,Y.jsx)(ht,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]})]}),(()=>{let t=f?._diagnostics,n=yg(e)?T.map(e=>({path:e.path,message:e.message})):t?.errors??[],r=yg(e)?n.length===0:t?.valid!==!1;if(!t&&!yg(e))return null;let i=n,a=t?.warnings??[],o=!r&&i.length>0,s=a.length>0;if(!o&&!s)return null;let c=(e,t)=>{let n=t.slice(0,3),r=Math.max(0,t.length-n.length),i=e===`error`?`border-destructive/40 bg-destructive/[0.06] text-destructive`:`border-amber-500/40 bg-amber-500/[0.08] text-amber-800 dark:text-amber-200`,a=e===`error`?`engine.edit.diagnostics.title`:`engine.edit.diagnostics.warnTitle`;return(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs border rounded p-2.5 ${i}`,children:[(0,Y.jsx)(fn,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:em(a,d,{count:t.length})}),(0,Y.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`opacity-70`,children:e.path||`(root)`}),`: `,e.message]},t)),r>0&&(0,Y.jsx)(`li`,{className:`opacity-70`,children:em(`engine.edit.diagnostics.more`,d,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),rt?(0,Y.jsx)(`div`,{className:Le?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(xg,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(Nt,{defaultSize:62,minSize:30,children:(0,Y.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,Y.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,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:$e&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":X(`engine.edit.designer`,d),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!V,onClick:()=>Ie(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(V?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:X(`engine.edit.designMode`,d),children:[(0,Y.jsx)(vr,{className:`h-3.5 w-3.5`}),X(`engine.edit.designMode`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":V,onClick:()=>Ie(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(V?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.previewMode`,d),children:[(0,Y.jsx)(_a,{className:`h-3.5 w-3.5`}),X(`engine.edit.previewMode`,d)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ct,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),rt&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:B,className:`h-7 w-7 p-0`,title:X(Me?`engine.edit.showInspector`:`engine.edit.hideInspector`,d)+` (⌘\\)`,children:Me?(0,Y.jsx)(Yi,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Tt,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>ze(e=>!e),className:`h-7 w-7 p-0`,title:X(Le?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,d),children:Le?(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ji,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.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,Y.jsx)(rt,{type:e,name:t,draft:h,editing:le&&!V,selection:V?null:de,onSelectionChange:fe,locale:d,onPatch:e=>D(t=>({...t,...e}))})})]})}),(0,Y.jsx)(pt,{withHandle:!0,className:Me?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(Nt,{panelRef:Fe,defaultSize:Pe.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Pe.current=t,typeof window<`u`&&window.localStorage.setItem(je,String(Math.round(t)))),Ne(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Ae,n?`1`:`0`),n))},children:(0,Y.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Y.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,Y.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`properties`,onClick:()=>ke(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.properties`,d),children:[(0,Y.jsx)(ia,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.properties`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`source`,onClick:()=>ke(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.source`,d),children:[(0,Y.jsx)(oa,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.source`,d)]})]}),Ge&&(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,Y.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),X(`engine.edit.unsaved`,d)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:Oe===`source`?(0,Y.jsx)(hg,{value:h,onChange:D,readOnly:ot,issues:T.map(e=>({path:e.path??``,message:e.message}))}):de&&H?(0,Y.jsx)(H,{type:e,name:t,draft:h,selection:de,onPatch:e=>D(t=>({...t,...e})),onClearSelection:()=>fe(null),onSelectionChange:fe,readOnly:ot,locale:d}):(0,Y.jsx)(ch,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:N,issues:T,hiddenFields:re,fieldOrder:M,readOnly:ot,createMode:n,widgetContext:R})})]})})]})}):(0,Y.jsx)(ch,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:N,issues:T,hiddenFields:re,fieldOrder:M,readOnly:ot,createMode:n,widgetContext:R})]})})]}),(0,Y.jsx)(qt,{open:Ee===`layers`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)($t,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ct,{className:`text-base`,children:X(`engine.edit.layers`,d)}),(0,Y.jsxs)(pn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Bm,{layered:f,locale:d})})]})}),(0,Y.jsx)(qt,{open:Ee===`references`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)($t,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(Ct,{className:`text-base`,children:[X(`engine.edit.references`,d),_&&(0,Y.jsx)(U,{variant:`outline`,className:`ml-2 text-[10px]`,children:_.length})]}),(0,Y.jsxs)(pn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Tg,{refs:_,loading:be})})]})}),we&&(0,Y.jsx)(qt,{open:Ee===`related`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)($t,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ct,{className:`text-base`,children:X(`engine.edit.related`,d)}),(0,Y.jsxs)(pn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Ah,{type:e,name:t,parentItem:h,onOpen:e=>Ce(e)})})]})}),!n&&(0,Y.jsx)(qt,{open:Ee===`history`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)($t,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ct,{className:`text-base`,children:X(`engine.edit.history`,d)}),(0,Y.jsxs)(pn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Rh,{type:e,name:t,client:a,onRollback:()=>ce(e=>e+1),rollbackLabel:X(`engine.edit.rollback`,d),rollbackConfirm:e=>X(`engine.edit.rollbackConfirm`,d).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(qt,{open:Ee===`audit`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)($t,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(st,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ct,{className:`text-base`,children:X(`engine.edit.auditTab`,d)}),(0,Y.jsxs)(pn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(Uh,{type:e,name:t,client:a,locale:d})})]})}),(0,Y.jsx)(Ih,{target:Se,onClose:()=>Ce(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(it,{open:O!=null,onOpenChange:e=>{e||(k(null),A(null))},children:(0,Y.jsxs)(xt,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsxs)(Re,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(fn,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(It,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Y.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:O?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Y.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Y.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{variant:`ghost`,onClick:()=>k(null),children:`Cancel`}),(0,Y.jsx)(G,{variant:`destructive`,onClick:()=>Ve(!0),disabled:x,children:x?`Forcing…`:`Force save`})]})]})})]})}function Tg({refs:e,loading:t}){return t||e==null?(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:`No references found`}),(0,Y.jsx)(yt,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function Eg({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=J.useReducer(e=>e+1,0);return J.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(K,{className:`h-3 w-3 animate-spin`}),X(`engine.edit.saving`,a)]}):t?i?null:(0,Y.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),X(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:em(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function Dg({type:e}){let t=o(),[n]=l(),r=e??n.get(`type`)??``;if(!r)return(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:`Missing metadata type`}),(0,Y.jsxs)(yt,{children:[`This page expects a `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,Y.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let i=Og(t.pathname),a=i.split(`/`).filter(Boolean);return a.length===0?(0,Y.jsx)(Am,{type:r}):a[0]===`new`&&a.length===1?(0,Y.jsx)(Cg,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Y.jsx)(Lh,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Y.jsx)(Cg,{type:r,name:decodeURIComponent(a[0])},`${r}:${a[0]}`):(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:`Unknown sub-path`}),(0,Y.jsxs)(yt,{children:[`The path `,(0,Y.jsx)(`code`,{className:`font-mono`,children:i}),` isn't recognized. Valid forms are `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function Og(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function kg(){let e=Bp(),t=J.useMemo(()=>tm(),[]),[n,r]=J.useState(`error`),{loading:a,error:o,summary:s,reload:c}=Wp(e,n),{entries:l}=Hp(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=Qp(n.type,t,n.label);return e},[l,t]),d=J.useMemo(()=>{let e={};for(let t of s.entries)(e[t.type]??=[]).push(t);return Object.entries(e).sort(([,e],[,t])=>t.length-e.length)},[s]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,Y.jsxs)(i,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(ja,{className:`h-3 w-3`}),X(`engine.diagnostics.back`,t)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(fn,{className:`h-5 w-5 text-destructive`}),X(`engine.diagnostics.title`,t)]}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:em(`engine.diagnostics.summary`,t,{count:s.total,items:s.scannedItems,types:s.scannedTypes})}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsx)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5 text-xs`,children:[`error`,`warning`].map(e=>(0,Y.jsx)(`button`,{role:`tab`,type:`button`,"aria-selected":n===e,onClick:()=>r(e),className:`px-2.5 py-1 rounded transition-colors `+(n===e?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),children:X(`engine.diagnostics.severity.${e}`,t)},e))}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,Y.jsx)(tn,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.diagnostics.refresh`,t)]})]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:X(`engine.diagnostics.description`,t)})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[a&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:X(`engine.diagnostics.loading`,t)}),!a&&o&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:em(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(nt,{children:[(0,Y.jsx)(Ua,{children:X(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(yt,{children:em(`engine.diagnostics.cleanHint`,t,{items:s.scannedItems,types:s.scannedTypes})})]}),d.map(([e,r])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(i,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:u[e]??e}),(0,Y.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:r.length})]}),(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:X(`engine.diagnostics.col.name`,t)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:X(`engine.diagnostics.col.issues`,t)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:r.map(r=>{let a=r.diagnostics.errors??[],o=r.diagnostics.warnings??[],s=(n===`warning`&&a.length===0?o:a).slice(0,3),c=Math.max(0,(a.length||o.length)-s.length);return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,Y.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,Y.jsx)(i,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(r.name)}`,className:`text-primary hover:underline font-mono`,children:r.name}),a.length>0&&(0,Y.jsx)(U,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:em(`engine.diagnostics.errorN`,t,{count:a.length})}),o.length>0&&(0,Y.jsx)(U,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:em(`engine.diagnostics.warnN`,t,{count:o.length})})]}),(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,Y.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[s.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),c>0&&(0,Y.jsx)(`li`,{className:`text-muted-foreground`,children:em(`engine.diagnostics.more`,t,{count:c})})]})})]},r.name)})})]})})]},e))]})]})}function Ag(e){return[{key:`allowCreate`,short:`C`,tip:X(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:X(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:X(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:X(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:X(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:X(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:X(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:X(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:X(`perm.action.modifyAll`,e)}]}function jg({type:e,name:t}){let n=s(),r=Bp(),{entries:i}=Hp(r),a=i.find(t=>t.type===e),o=!!Om(e,a).allowOrgOverride,c=J.useMemo(()=>tm(),[]),l=J.useCallback(e=>X(e,c),[c]),u=J.useMemo(()=>Ag(c),[c]),[d,f]=J.useState({name:t,objects:{},fields:{}}),[p,m]=J.useState([]),[h,g]=J.useState({}),[_,v]=J.useState(new Set),[y,b]=J.useState(!0),[x,S]=J.useState(!1),[C,w]=J.useState(null),[T,E]=J.useState(null),[D,O]=J.useState(``),[k,ee]=J.useState(!1);J.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:{}};f({...o,name:String(o?.name??t),objects:o?.objects??{},fields:o?.fields??{}}),m((a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name)))}catch(e){w(e?.message??String(e))}finally{n||b(!1)}})(),()=>{n=!0}},[r,e,t]);async function A(e){if(!h[e])try{let t=(await r.list(`field`)??[]).map(e=>e?.item??e).filter(t=>String(t?.object??``)===e).map(e=>({name:String(e?.name??``),label:e?.label})).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));g(n=>({...n,[e]:t}))}catch{g(t=>({...t,[e]:[]}))}}function j(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),A(e)),n})}function te(e,t,n){f(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function ne(e,t){f(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(u.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 re(e,t,n,r){let i=`${e}.${t}`;f(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function M(t,n){let i=n??d;S(!0),w(null);try{await r.save(e,i.name,i,{force:t}),f((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 N=J.useMemo(()=>{let e=D.trim().toLowerCase();return p.filter(t=>{if(k){let e=d.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[p,D,k,d.objects]),ie=[{label:l(`perm.stat.objectsGranted`),value:Object.values(d.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:l(`perm.stat.fieldOverrides`),value:Object.keys(d.fields??{}).length}];return y?(0,Y.jsx)(Sm,{entry:a,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` `,l(`perm.loading`).replace(`{name}`,t)]})}):(0,Y.jsxs)(Sm,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?l(`perm.subtitle.profile`):l(`perm.subtitle.set`),stats:ie,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(Fn,{className:`h-4 w-4 mr-1`}),` `,l(`engine.edit.history`)]}),o&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>M(!1),disabled:x,children:[x?(0,Y.jsx)(K,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(wr,{className:`h-4 w-4 mr-1`}),l(`engine.edit.save`)]})]}),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[C&&(0,Y.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,Y.jsx)(fn,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:C})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{htmlFor:`perm-name`,className:`text-xs`,children:l(`perm.field.name`)}),(0,Y.jsx)(W,{id:`perm-name`,value:d.name,disabled:!o,onChange:e=>f(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{htmlFor:`perm-label`,className:`text-xs`,children:l(`perm.field.label`)}),(0,Y.jsx)(W,{id:`perm-label`,value:d.label??``,disabled:!o,onChange:e=>f(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,Y.jsx)(Ai,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,Y.jsx)(di,{htmlFor:`perm-is-profile`,className:`text-xs`,children:l(`perm.field.isProfile`)})]}),!o&&(0,Y.jsx)(U,{variant:`secondary`,className:`ml-auto`,children:l(`perm.readOnly`)})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,Y.jsx)(W,{placeholder:l(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ai,{id:`only-enabled`,checked:k,onCheckedChange:e=>ee(!!e)}),(0,Y.jsx)(di,{htmlFor:`only-enabled`,className:`text-xs`,children:l(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[N.length,` / `,p.length,` `,l(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Y.jsx)(Mg,{objects:N,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:u,t:l,onToggleExpand:j,onObjectPerm:te,onFieldPerm:re,onBulkSet:ne})})]}),(0,Y.jsx)(it,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Y.jsxs)(xt,{children:[(0,Y.jsxs)(Wa,{children:[(0,Y.jsxs)(Re,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(fn,{className:`h-4 w-4 text-amber-500`}),` `,l(`engine.edit.destructive`)]}),(0,Y.jsx)(It,{children:l(`engine.edit.destructiveHint`)})]}),(0,Y.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:T?.issues.map((e,t)=>(0,Y.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,Y.jsx)(U,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Y.jsxs)(xn,{children:[(0,Y.jsx)(G,{variant:`ghost`,onClick:()=>E(null),children:l(`engine.cancel`)}),(0,Y.jsxs)(G,{variant:`destructive`,onClick:()=>T&&M(!0,T.pending),disabled:x,children:[x&&(0,Y.jsx)(K,{className:`h-4 w-4 mr-1 animate-spin`}),l(`engine.edit.forceSave`)]})]})]})})]})}function Mg({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,Y.jsxs)(`tbody`,{children:[e.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.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,Y.jsxs)(J.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,Y.jsx)(jt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(qn,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,Y.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,Y.jsx)(ut,{checked:!!d[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,Y.jsx)(G,{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,Y.jsx)(G,{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,Y.jsx)(G,{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,Y.jsx)(G,{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,Y.jsx)(`tr`,{className:`bg-muted/10`,children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,Y.jsx)(Ng,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function Ng({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,Y.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,Y.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,Y.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(ut,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(ut,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function Pg(){Tm({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Fg(e.fields),groupLabel:`Fields`,order:5}]}),Tm({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}]}),Tm({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Fg(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Tm({type:`hook`,anchors:[{anchorType:`object`,match:Cm(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Tm({type:`approval`,anchors:[{anchorType:`object`,match:Cm(`object`),groupLabel:`Approval Processes`,order:70}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{active:!0,lockRecord:!0,steps:[{name:`step_1`,label:`First approval`,approvers:[{type:`manager`,value:`manager`}],behavior:`first_response`,rejectionBehavior:`reject_process`}]}}),Tm({type:`page`,anchors:[{anchorType:`object`,match:Cm(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`description`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{regions:[]}}),Tm({type:`view`,anchors:[{anchorType:`object`,match:Cm([`data.object`,`list.data.object`,`form.data.object`,`object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`kind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,description:`The object this view displays.`},kind:{type:`string`,title:`View kind`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`}}},createBuildBody:e=>({list:{name:e.name,label:e.label,type:e.kind||`grid`,columns:[],data:{provider:`object`,object:e.object}}})}),Tm({type:`flow`,anchors:[{anchorType:`object`,match:Cm([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{nodes:[],edges:[]}}),Tm({type:`workflow`,anchors:[{anchorType:`object`,match:Cm([`object`,`on.object`]),groupLabel:`Workflow Rules`,order:51}],createFields:[`name`,`objectName`,`triggerType`,`description`]}),Tm({type:`trigger`,anchors:[{anchorType:`object`,match:Cm([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Tm({type:`validation`,anchors:[{anchorType:`object`,match:Cm(`object`),groupLabel:`Validations`,order:25}],createFields:[`label`,`name`,`message`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`message`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable rule name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},message:{type:`string`,title:`Error message`,description:`Shown to the user when the rule blocks save.`}}},createDefaults:{type:`script`,active:!0,events:[`insert`,`update`],priority:10,severity:`error`,condition:`false`}}),Tm({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}],createFields:[`label`,`name`,`isProfile`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),Tm({type:`action`,anchors:[{anchorType:`object`,match:Cm([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Tm({type:`dashboard`,anchors:[{anchorType:`object`,match:Cm([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Tm({type:`report`,anchors:[{anchorType:`object`,match:Cm([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Tm({type:`object`,iconName:`database`,domain:`data`,createFields:[`label`,`pluralLabel`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0},{from:`label`,to:`pluralLabel`,transform:`plural-en`,untilUserEdits:!0}],createDefaults:{fields:{}},searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function Fg(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Ig={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`}},Lg={role:{type:`object`,title:`Role`,required:[`name`],properties:{...Ig,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:{...Ig,isProfile:{type:`boolean`,title:`Is profile`,description:`Profiles are mutually exclusive (one per user).`},objects:{type:`object`,title:`Object Permissions`,description:`Edit this via the Permission Matrix tab for a row-by-row UI.`}}},permission:{type:`object`,title:`Permission`,required:[`id`,`resource`,`actions`,`description`],properties:{id:{type:`string`,title:`ID`,description:`Stable identifier (e.g. crm.account.read).`},resource:{type:`string`,title:`Resource`,description:`What this permission applies to.`,enum:[`data.object`,`data.record`,`data.field`,`ui.view`,`ui.dashboard`,`ui.report`,`system.config`,`system.plugin`,`system.api`,`system.service`,`storage.file`,`storage.database`,`network.http`,`network.websocket`,`process.spawn`,`process.env`]},actions:{type:`array`,title:`Actions`,description:`Permitted operations on the resource.`,items:{type:`string`,enum:[`create`,`read`,`update`,`delete`,`execute`,`admin`,`manage`,`configure`,`import`,`export`,`share`]}},description:{type:`string`,title:`Description`,description:`Why this permission exists (shown in admin UIs).`},scope:{type:`string`,title:`Scope`,enum:[`tenant`,`user`,`plugin`,`global`,`resource`],default:`tenant`},required:{type:`boolean`,title:`Required`,description:`Must be present for the holder to function.`},justification:{type:`string`,title:`Justification`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...Ig.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Ig.label,description:Ig.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:{...Ig,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:{...Ig,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Ig,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Ig,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Ig,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:{...Ig,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Ig,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:{...Ig,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 Rg(){for(let[e,t]of Object.entries(Lg))Tm({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Z({toolbar:e,children:t}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,Y.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function zg({tone:e=`info`,children:t}){return(0,Y.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,Y.jsx)(Hn,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function Bg({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,Y.jsx)(bn,{className:`h-8 w-8 opacity-50`});return(0,Y.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,Y.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,Y.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,Y.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,Y.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Vg=class extends J.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,Y.jsxs)(zg,{tone:`error`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,Y.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,Y.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function Hg({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:B(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var Ug={"page:header":{label:`Header`,category:`layout`,Icon:kt},"page:footer":{label:`Footer`,category:`layout`,Icon:sr},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:tr},"page:tabs":{label:`Tabs`,category:`layout`,Icon:Hr},"page:accordion":{label:`Accordion`,category:`layout`,Icon:gt},"page:card":{label:`Card`,category:`layout`,Icon:Vr},"page:section":{label:`Section`,category:`layout`,Icon:mi},"record:details":{label:`Record details`,category:`record`,Icon:xr},"record:highlights":{label:`Highlights`,category:`record`,Icon:Qi},"record:related_list":{label:`Related list`,category:`record`,Icon:Da},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Ci},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Fr},"record:path":{label:`Stage path`,category:`record`,Icon:ka},"record:alert":{label:`Alert banner`,category:`record`,Icon:fn},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:Ba},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Xr},"record:history":{label:`History`,category:`record`,Icon:Fn},"app:launcher":{label:`App launcher`,category:`navigation`,Icon:An},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Wi},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:ka},"global:search":{label:`Global search`,category:`navigation`,Icon:pr},"global:notifications":{label:`Notifications`,category:`navigation`,Icon:Pi},"user:profile":{label:`User profile`,category:`navigation`,Icon:an},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:ya},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:yr},"element:text":{label:`Text`,category:`element`,Icon:Qt},"element:number":{label:`Number`,category:`element`,Icon:Gn},"element:image":{label:`Image`,category:`element`,Icon:Ie},"element:divider":{label:`Divider`,category:`element`,Icon:kr},"element:button":{label:`Button`,category:`element`,Icon:li},"element:filter":{label:`Filter`,category:`element`,Icon:Ee},"element:form":{label:`Form`,category:`element`,Icon:Pe},"element:record_picker":{label:`Record picker`,category:`element`,Icon:ft}},Wg={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Gg=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Ug))e[n.category].push(t);return[`layout`,`record`,`element`,`navigation`,`ai`,`misc`].map(t=>({category:t,types:e[t]})).filter(e=>e.types.length>0)})(),Kg=ki,qg={layout:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},record:{icon:`text-blue-500 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},navigation:{icon:`text-indigo-500 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},element:{icon:`text-teal-500 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},ai:{icon:`text-violet-500 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},misc:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function Jg(e){return qg[Ug[e]?.category??`misc`]}function Yg(e){let t=e.regions;if(Array.isArray(t))return{regions:t,shape:`regions`};let n=e.children;return Array.isArray(n)?{regions:[{name:`children`,components:n}],shape:`children`}:{regions:[],shape:`regions`}}function Xg(e,t,n){return e===`children`?`children[${n}]`:`regions[${t}].components[${n}]`}function Zg(e){return typeof e.label==`string`&&e.label||typeof e.title==`string`&&e.title||typeof e.id==`string`&&e.id||String(e.type??`block`)}var Qg=`text/x-objectui-pageblock`;function $g({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>Yg(e),[e]),s=n?.kind===`block`?String(n.id):null,c=J.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else t?.({regions:e})},[t,o]),l=J.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e.region]?.components;if(!o)return;let[s]=o.splice(e.comp,1);if(!s)return;let l=i[n.region]?.components;if(!l)return;let u=l.length;if(`appendEnd`in n)u=l.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,u=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,u=t}l.splice(u,0,s),c(i);let d=`regions[${n.region}].components[${u}]`;r?.({kind:`block`,id:d,label:Zg(s)})},[t,r,a,c]),u=J.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]}));i[e]||(i[e]={name:`region_${e+1}`,components:[]});let o={type:n};i[e].components.push(o),c(i);let s=i[e].components.length-1;r?.({kind:`block`,id:`regions[${e}].components[${s}]`,label:Zg(o)})},[t,r,a,c]),d=J.useCallback((e,n,r)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e]?.components?.[n];o&&(i[e].components[n]={...o,label:r||void 0},c(i))},[t,a,c]),f=J.useCallback(()=>{t&&c([...a,{name:`region_${a.length+1}`,components:[]}])},[t,a,c]),p=J.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:p,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`A Page is composed of regions (header / main / sidebar / …). Add a region to start dropping blocks into it.`}),!i&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:p,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:p,children:[a.map((e,t)=>(0,Y.jsx)(e_,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(e,n)=>r?.({kind:`block`,id:`regions[${t}].components[${e}]`,label:Zg(n)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function e_({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c}){let l=Array.isArray(e.components)?e.components:[],[u,d]=J.useState(!1);return(0,Y.jsxs)(`section`,{className:B(`rounded-md transition-colors`,u&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(i)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(Qg)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,d(!0))},onDragLeave:e=>{e.currentTarget===e.target&&d(!1)},onDrop:e=>{if(i||(d(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(Qg);if(n)try{let e=JSON.parse(n);if(typeof e.region!=`number`||typeof e.comp!=`number`)return;o(e,{region:t,appendEnd:!0})}catch{}},children:[(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,Y.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),u&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[l.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:`Empty region — drop a block here or use the add button below.`}):l.map((e,s)=>(0,Y.jsx)(t_,{block:e,regionIdx:t,compIdx:s,selected:Xg(n,t,s)===r,readOnly:i,onClick:()=>a(s,e),onMoveBlock:o,onRenameLabel:e=>c(t,s,e)},`${t}:${s}`)),!i&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(n_,{onPick:e=>s(t,e)})})]})]})}function t_({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Ug[c]?.Icon??Kg,u=Jg(c),d=Zg(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(Qg,JSON.stringify({region:t,comp:n})),e.dataTransfer.effectAllowed=`move`},g=e=>{if(!f)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(Qg))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();m(e.clientY-n.top<n.height/2?`before`:`after`)},_=()=>m(null),v=e=>{if(i)return;e.preventDefault(),e.stopPropagation();let r=p??`before`;m(null);let a=e.dataTransfer.getData(Qg);if(a)try{let e=JSON.parse(a);if(e.region===t&&e.comp===n)return;o(e,r===`before`?{region:t,before:n}:{region:t,after:n})}catch{}},[y,b]=J.useState(!1),[x,S]=J.useState(d);J.useEffect(()=>{S(d)},[d]);let C=e=>{i||(e.preventDefault(),e.stopPropagation(),S(d),b(!0))},w=()=>{if(i){b(!1);return}let e=x.trim();e&&e!==d&&s(e),b(!1)},T=()=>{S(d),b(!1)};return(0,Y.jsxs)(`div`,{className:B(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:B(`group w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,Y.jsx)(Ji,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,Y.jsx)(l,{className:B(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,Y.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),w()):e.key===`Escape`&&(e.preventDefault(),T())},onBlur:w,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:B(`text-sm font-medium truncate`,!i&&`cursor-text`),onDoubleClick:C,title:i?void 0:`Double-click to rename`,children:d}),e.id&&e.id!==d&&(0,Y.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,Y.jsx)(U,{variant:`outline`,className:B(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]})}),p===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function n_({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?Gg.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Ug[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Gg,[a]);return(0,Y.jsxs)(ur,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Ae,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(yn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search block type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:Wg[t.category]}),t.types.map(t=>{let r=Ug[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent text-left`,children:[(0,Y.jsx)(a,{className:B(`h-3.5 w-3.5 shrink-0`,Jg(t).icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function r_({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=J.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=J.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),d=J.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=J.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,Y.jsxs)(Z,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Y.jsx)($g,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(Hg,{title:X(`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:X(`engine.inspector.add.block`,a)}):null,!s&&(0,Y.jsx)(zg,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Y.jsx)(Z,{hint:`page · design`,children:(0,Y.jsx)($g,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Y.jsx)(Z,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(Vg,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(Hg,{title:X(`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:X(`engine.inspector.add.block`,a)}),(0,Y.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Y.jsx)(N,{schema:o})})]})})}function i_({kindLabel:e,title:t,onClose:n,closeLabel:r=`Close`,children:i,footer:a,headerActions:o}){return(0,Y.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b px-4 py-2.5`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(U,{variant:`secondary`,className:`text-[10px] uppercase tracking-wider`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 truncate text-sm font-medium`,title:t,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[o,(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:n,"aria-label":r,className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Fa,{className:`h-4 w-4`})})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto px-4 py-3 space-y-3`,children:i}),a&&(0,Y.jsx)(`div`,{className:`border-t px-4 py-2.5`,children:a})]})}function a_({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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{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,Y.jsx)(Va,{className:`h-4 w-4`})}),(0,Y.jsx)(G,{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,Y.jsx)(Nn,{className:`h-4 w-4`})})]})}function o_({label:e,value:t,onCommit:n,placeholder:r,disabled:i,mono:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{value:t,onChange:e=>n(e.target.value),placeholder:r,disabled:i,className:B(`h-8 text-sm`,a&&`font-mono`)})]})}function s_({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{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 c_({label:e,value:t,options:n,onCommit:r,placeholder:i=`—`,disabled:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(Cn,{value:t??``,onValueChange:r,disabled:a,children:[(0,Y.jsx)(Wn,{className:`h-8 text-sm`,children:(0,Y.jsx)(vt,{placeholder:i})}),(0,Y.jsx)(qa,{children:n.map(e=>(0,Y.jsx)(Be,{value:e.value,children:e.label},e.value))})]})]})}function l_({label:e,value:t,onCommit:n,disabled:r}){return(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer select-none`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t,disabled:r,onChange:e=>n(e.target.checked),className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{children:e})]})}function u_({label:e,onClick:t,disabled:n}){return(0,Y.jsx)(G,{variant:`destructive`,size:`sm`,onClick:t,disabled:n,className:`w-full`,children:e})}function d_({message:e}){return(0,Y.jsx)(`div`,{className:`text-xs italic text-muted-foreground p-4 text-center`,children:e})}function f_(e,t,n){let r=Array.isArray(e)?[...e]:[];return n===null?r.splice(t,1):r[t]=n,r}function p_(e,t){let n=Array.isArray(e)?[...e]:[];return n.push(t),n}function m_(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 h_(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 g_=`text/x-objectui-viewcol`;function __(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function v_(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`?n:void 0}}function y_({draft:e,variants:t,onPatch:n,selection:r,onSelectionChange:i}){let[a,o]=J.useState(null),s=r&&r.kind===`column`?r.id:null,c=J.useCallback((t,r)=>{if(!n)return;let i=e[t];i&&n({[t]:{...i,columns:r}})},[e,n]),l=J.useCallback(e=>{if(!n)return;let t=e.allStrings?``:{field:``,label:`New column`},r=p_(e.columns,t);c(e.key,r),i?.({kind:`column`,id:`${e.key}.columns[${r.length-1}]`,label:`New column`})},[n,c,i]),u=J.useCallback((e,t)=>{if(!n)return;let r=f_(e.columns,t,null);c(e.key,r),s===`${e.key}.columns[${t}]`&&i?.(null)},[n,c,s,i]),d=J.useCallback((e,t,r)=>{if(!n)return;let a=e.columns[t],o;if(typeof a==`string`)o=r;else if(a&&typeof a==`object`){let e=a;o=`header`in e?{...e,header:r}:{...e,label:r}}else o={label:r};let l=f_(e.columns,t,o);c(e.key,l),s===`${e.key}.columns[${t}]`&&i?.({kind:`column`,id:`${e.key}.columns[${t}]`,label:r})},[n,c,s,i]),f=J.useCallback((e,r)=>{if(!n)return;let a=t.find(t=>t.key===e.variant),o=t.find(e=>e.key===r.variant);if(!a||!o)return;if(e.variant===r.variant){let t=r.index;if(e.index<r.index&&(t=r.index-1),t===e.index)return;let n=m_(a.columns,e.index,t);c(e.variant,n),i?.({kind:`column`,id:`${e.variant}.columns[${t}]`,label:__(n[t],t)});return}let s=a.columns[e.index],l=s;o.allStrings&&typeof s!=`string`?l=v_(s)??__(s,e.index):!o.allStrings&&typeof s==`string`&&(l={field:s,label:s});let u=f_(a.columns,e.index,null),d=[...o.columns];d.splice(r.index,0,l),n({[e.variant]:{...a.schema,columns:u},[r.variant]:{...o.schema,columns:d}}),i?.({kind:`column`,id:`${r.variant}.columns[${r.index}]`,label:__(l,r.index)})},[t,n,c,i]);return(0,Y.jsxs)(`div`,{className:`space-y-3 p-3`,children:[t.length===0&&n&&(0,Y.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-xs text-muted-foreground`,children:[`No variants on this view yet. Add a `,(0,Y.jsx)(`code`,{children:`list`}),` or `,(0,Y.jsx)(`code`,{children:`kanban`}),` block in the Form tab to start.`]}),t.map(e=>(0,Y.jsx)(b_,{variant:e,canEdit:!!n,selectedId:s,drag:a,onDragChange:o,onAdd:()=>l(e),onRemove:t=>u(e,t),onRename:(t,n)=>d(e,t,n),onMove:f,onSelectionChange:i},e.key))]})}function b_({variant:e,canEdit:t,selectedId:n,drag:r,onDragChange:i,onAdd:a,onRemove:o,onRename:s,onMove:c,onSelectionChange:l}){let[u,d]=J.useState(!1);return(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card/40`,onDragOver:e=>{t&&e.dataTransfer.types.includes(g_)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,d(!0))},onDragLeave:()=>d(!1),onDrop:n=>{t&&n.dataTransfer.types.includes(g_)&&(n.preventDefault(),d(!1),r&&(c(r,{variant:e.key,index:e.columns.length}),i(null)))},children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-mono uppercase tracking-wide text-muted-foreground`,children:e.key}),(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px]`,children:[e.columns.length,` `,e.columns.length===1?`column`:`columns`]})]}),t&&(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:a,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` Add column`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2 ${u?`bg-primary/5`:``}`,children:e.columns.length===0?(0,Y.jsx)(`div`,{onDragOver:e=>{t&&e.dataTransfer.types.includes(g_)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:n=>{t&&n.dataTransfer.types.includes(g_)&&(n.preventDefault(),n.stopPropagation(),r&&(c(r,{variant:e.key,index:0}),i(null)))},className:`rounded border-2 border-dashed px-3 py-6 text-center text-[11px] transition ${u?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground`}`,children:u?`Drop to add to this variant`:t?`Empty — drop a column here or use Add column`:`no columns yet`}):e.columns.map((a,u)=>(0,Y.jsx)(x_,{column:a,index:u,variantKey:e.key,path:`${e.key}.columns[${u}]`,isSelected:n===`${e.key}.columns[${u}]`,canEdit:t,onClick:()=>l?.({kind:`column`,id:`${e.key}.columns[${u}]`,label:__(a,u)}),onRename:e=>s(u,e),onRemove:()=>o(u),onDragStart:()=>i({variant:e.key,index:u}),onDragEnd:()=>i(null),onDropBefore:()=>{r&&(c(r,{variant:e.key,index:u}),i(null))}},u))})]})}function x_({column:e,index:t,path:n,isSelected:r,canEdit:i,onClick:a,onRename:o,onRemove:s,onDragStart:c,onDragEnd:l,onDropBefore:u}){let[d,f]=J.useState(!1),[p,m]=J.useState(__(e,t)),[h,g]=J.useState(!1),[_,v]=J.useState(null);J.useEffect(()=>{d||m(__(e,t))},[e,t,d]);let y=v_(e);return(0,Y.jsxs)(`div`,{className:`relative`,children:[_===`before`&&(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`button`,{type:`button`,draggable:i&&!d,onDragStart:e=>{i&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(g_,n),c())},onDragEnd:l,onDragOver:e=>{i&&e.dataTransfer.types.includes(g_)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,v(`before`))},onDragLeave:()=>v(null),onDrop:e=>{i&&e.dataTransfer.types.includes(g_)&&(e.preventDefault(),e.stopPropagation(),v(null),u())},onClick:a,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),"aria-pressed":r,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${r?`border-primary ring-1 ring-primary`:`border-border`} ${i&&!d?`cursor-grab active:cursor-grabbing`:``}`,children:[(0,Y.jsx)(Ji,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}),(0,Y.jsx)(jn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),d?(0,Y.jsx)(`input`,{autoFocus:!0,value:p,onChange:e=>m(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(!1);let n=p.trim();n&&n!==__(e,t)&&o(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),m(__(e,t)),f(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{i&&(e.stopPropagation(),f(!0))},children:__(e,t)}),y&&y!==__(e,t)&&(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground truncate max-w-[8rem]`,children:y}),i&&h&&!d&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),s())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":`Remove column`,children:(0,Y.jsx)(Rt,{className:`h-3 w-3`})})]})]})}var S_=[`list`,`form`,`kanban`,`calendar`,`gantt`,`map`,`gallery`,`timeline`,`feed`,`detail`];function C_(e){let t=[];for(let n of S_){let r=e[n];r&&typeof r==`object`&&!Array.isArray(r)&&t.push({key:n,schema:r})}return t}function w_(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 T_({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=J.useMemo(()=>C_(t),[t]),s=J.useMemo(()=>w_(t,o[0]?.schema),[t,o]),c=!!(n&&i),l=c&&!!a,u=J.useMemo(()=>o.map(e=>{let t=Array.isArray(e.schema.columns)?e.schema.columns:[],n=t.length>0&&t.every(e=>typeof e==`string`);return{key:e.key,schema:e.schema,columns:t,allStrings:n}}),[o]),d=c?(0,Y.jsx)(y_,{draft:t,variants:u,onPatch:l?a:void 0,selection:r??null,onSelectionChange:i}):null,{listViews:f,defaultViewId:p}=J.useMemo(()=>{let n={},r=o.find(e=>e.key===`list`)??o[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,o,e]);if(!o.length&&t.type){let e={...t};return(0,Y.jsx)(Z,{hint:`view · ${e.type}${c?` · design`:``}`,children:(0,Y.jsxs)(Vg,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:[d,(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(N,{schema:e})})]})})}if(!s)return(0,Y.jsx)(Z,{hint:`view`,children:(0,Y.jsxs)(zg,{tone:`warn`,children:[`This view has no object binding yet. Set `,(0,Y.jsx)(`code`,{children:`list.data.object`}),` in the Form tab to fetch live data.`]})});let m=o[0]?.schema?.type??`grid`,h=J.useMemo(()=>({type:`object-view`,objectName:s,defaultViewType:m,defaultListView:p,listViews:f,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[s,m,p,f]);return(0,Y.jsx)(Z,{hint:`view · ${o.map(e=>e.key).slice(0,3).join(` · `)||`list`}${c?` · design`:``}`,children:(0,Y.jsxs)(Vg,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:[d,(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(N,{schema:h})})]})})}var E_={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:Gn},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:_n},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:cr},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Oe},area:{id:`area`,label:`Area chart`,category:`chart`,icon:fa},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:Qn},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:mr},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Dt},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:St},table:{id:`table`,label:`Data table`,category:`data`,icon:ir},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:Tr},list:{id:`list`,label:`Record list`,category:`data`,icon:wn},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:Ke}},D_={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},O_=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(E_).filter(t=>t.category===e)})),k_=Ci;function A_({onAdd:e,label:t=`Add widget`}){let[n,r]=J.useState(!1),[i,a]=J.useState(``),o=J.useRef(null),s=J.useRef(null);J.useEffect(()=>{if(!n){a(``);return}let e=e=>{o.current?.contains(e.target)||r(!1)},t=e=>{e.key===`Escape`&&r(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),queueMicrotask(()=>s.current?.focus()),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[n]);let c=J.useMemo(()=>{let e=i.trim().toLowerCase();return e?O_.map(t=>({category:t.category,types:t.types.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))})).filter(e=>e.types.length):O_},[i]);return(0,Y.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Y.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:()=>r(e=>!e),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),t]}),n&&(0,Y.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-md border bg-popover shadow-md`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Y.jsx)(pr,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:s,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search widgets…`,className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground`})]}),(0,Y.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:c.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):c.map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:D_[t.category]}),t.types.map(t=>(0,Y.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{e(t.id),r(!1)},children:[(0,Y.jsx)(E_[t.id]?.icon??k_,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var j_=J.lazy(()=>c(()=>import(`./plugin-dashboard-BRn9AjyQ.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function M_({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=z(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=J.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=J.useCallback(e=>{n&&n({widgets:e})},[n]),p=J.useCallback(e=>{if(!l)return;let t=h_(`widget`,s.map(e=>e?.id).filter(Boolean)),r=E_[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:p_(s,{id:t,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),m=J.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),h=u?s.find(e=>e?.id===u)??null:null,g=l?(0,Y.jsx)(A_,{onAdd:p,label:X(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(Z,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(zg,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(Z,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(Vg,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(N_,{widget:h,onRename:e=>m(h.id,e),onClose:()=>i?.(null)}):null,(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(j_,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})]})})}function N_({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=J.useState(!1),[o,s]=J.useState(r),c=J.useRef(null);J.useEffect(()=>{s(r),a(!1)},[e.id,r]),J.useEffect(()=>{i&&c.current?.select()},[i]);let l=()=>{let e=o.trim();e&&e!==r&&t(e),a(!1)},u=()=>{s(r),a(!1)},d=E_[e.type]?.icon??null;return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-primary/5 px-3 py-1.5 text-xs`,children:[d?(0,Y.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,Y.jsx)(`span`,{className:`rounded bg-primary px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-foreground`,children:`Selected`}),i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`input`,{ref:c,value:o,onChange:e=>s(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),u())},className:`flex-1 min-w-0 rounded border bg-background px-2 py-0.5 text-xs outline-none focus:ring-1 focus:ring-primary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,Y.jsx)(Zi,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`flex-1 min-w-0 truncate text-left font-medium hover:underline`,title:`Click to rename`,children:r||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,Y.jsx)(ht,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,Y.jsx)(Fa,{className:`h-3.5 w-3.5`})})]})}var P_=J.lazy(()=>c(()=>import(`./plugin-report-CJSBthhg.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function F_({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=z(),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=J.useMemo(()=>(Array.isArray(e.columns)?e.columns:[]).map((e,t)=>({id:`columns[${t}]`,label:String(e.label??e.field??`col ${t+1}`)})),[e]),p=J.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=J.useMemo(()=>({columns:[],...e}),[e]);return s?Array.isArray(e.columns)&&e.columns.length>0?(0,Y.jsx)(Z,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,Y.jsxs)(Vg,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,Y.jsx)(Hg,{title:X(`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:X(`engine.inspector.add.column`,a)}),(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 min-h-[300px] max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(P_,{schema:m,dataSource:o})})})]})}):(0,Y.jsxs)(Z,{children:[l&&(0,Y.jsx)(Hg,{title:X(`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:X(`engine.inspector.add.column`,a)}),(0,Y.jsx)(Bg,{icon:(0,Y.jsx)(jn,{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,Y.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,Y.jsx)(H,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,Y.jsx)(Z,{children:(0,Y.jsx)(Bg,{icon:(0,Y.jsx)(Tr,{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.`})})}var I_=`text/x-objectui-nav`;function L_(e){if(e.kind)return String(e.kind);if(e.object||e.objectName)return`object`;if(e.page||e.pageName)return`page`;if(e.dashboard)return`dashboard`;if(e.report)return`report`;if(Array.isArray(e.children)&&e.children.length)return`group`;let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&/^https?:/i.test(t)?`link`:`item`}function R_(e){switch(e){case`object`:return Tr;case`page`:return xr;case`dashboard`:return je;case`report`:return Wr;case`link`:return kn;case`group`:return ua;default:return ka}}var z_={object:{icon:`text-blue-500`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},page:{icon:`text-violet-500`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},dashboard:{icon:`text-teal-500`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},report:{icon:`text-amber-500`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},link:{icon:`text-indigo-500`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},group:{icon:`text-slate-500`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},item:{icon:`text-zinc-500`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function B_(e){return z_[e]??z_.item}function V_(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function H_(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function U_({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=J.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),o=r&&r.kind===`nav`?r.id:null,[s,c]=J.useState(null),l=J.useCallback(e=>{n&&n({[t]:e})},[n,t]),u=J.useCallback(()=>{if(!n)return;let e=p_(a,{label:`New item`,path:``});l(e),i?.({kind:`nav`,id:`${t}[${e.length-1}]`,label:`New item`})},[n,a,l,t,i]),d=J.useCallback(e=>{n&&(l(f_(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=J.useCallback((e,r)=>{n&&(l(f_(a,e,{...a[e]??{},label:r})),o===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r}))},[n,a,l,t,o,i]),p=J.useCallback((e,r)=>{if(!n)return;let o=r;if(e<r&&(o=r-1),o===e)return;let s=m_(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:V_(s[o]??{},o)})},[n,a,l,t,i]);return(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-mono uppercase tracking-wide text-muted-foreground`,children:t}),(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px]`,children:[a.length,` `,a.length===1?`item`:`items`]})]}),n&&(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:u,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` Add nav item`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(I_)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(I_)&&(e.preventDefault(),s!=null&&(p(s,a.length),c(null)))},children:a.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:n?`Empty — click "Add nav item" to start`:`No top-level nav items yet`}):a.map((e,r)=>(0,Y.jsx)(W_,{item:e,index:r,depth:0,path:`${t}[${r}]`,selectedId:o,canEdit:!!n,onClick:(e,t)=>i?.({kind:`nav`,id:e,label:t}),onRename:e=>f(r,e),onRemove:()=>d(r),onDragStart:()=>c(r),onDragEnd:()=>c(null),onDropBefore:()=>{s!=null&&(p(s,r),c(null))}},r))})]})}function W_({item:e,index:t,depth:n,path:r,selectedId:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G_,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,V_(e,t)),onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}),Array.isArray(e.children)&&e.children.map((e,t)=>{let s=`${r}.children[${t}]`;return(0,Y.jsx)(W_,{item:e,index:t,depth:n+1,path:s,selectedId:i,canEdit:a,onClick:o,onRename:()=>void 0,onRemove:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onDropBefore:()=>void 0},t)})]})}function G_({item:e,index:t,depth:n,path:r,isSelected:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){let f=L_(e),p=R_(f),m=B_(f),h=H_(e),[g,_]=J.useState(!1),[v,y]=J.useState(V_(e,t)),[b,x]=J.useState(!1),[S,C]=J.useState(null);return J.useEffect(()=>{g||y(V_(e,t))},[e,t,g]),(0,Y.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[S===`before`&&(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`button`,{type:`button`,draggable:a&&!g,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(I_,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(I_)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(I_)&&(e.preventDefault(),e.stopPropagation(),C(null),d())},onClick:o,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),"aria-pressed":i,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${i?`border-primary ring-1 ring-primary`:`border-border`} ${a&&!g?`cursor-grab active:cursor-grabbing`:``}`,children:[a?(0,Y.jsx)(Ji,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,Y.jsx)(`span`,{className:`w-3.5`}),(0,Y.jsx)(p,{className:B(`h-3.5 w-3.5 shrink-0`,m.icon)}),g?(0,Y.jsx)(`input`,{autoFocus:!0,value:v,onChange:e=>y(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{_(!1);let n=v.trim();n&&n!==V_(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(V_(e,t)),_(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),_(!0))},children:V_(e,t)}),(0,Y.jsx)(U,{variant:`outline`,className:B(`text-[10px] font-medium`,m.badge),children:f}),h&&(0,Y.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:h}),a&&b&&!g&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":`Remove nav item`,children:(0,Y.jsx)(Rt,{className:`h-3 w-3`})})]})]})}function K_(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)?K_(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function q_(e){switch(e){case`object`:return Tr;case`page`:return xr;case`dashboard`:return je;case`report`:return Wr;default:return ka}}function J_({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,c=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:l,navItems:u}=J.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:K_(n)};return{rootKey:null,navItems:[]}},[t]),d=l??`nav`,f=!!(n&&i),p=f&&!!a,m=r&&r.kind===`nav`?r.id:null,h=f?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,g=o?`/apps/${encodeURIComponent(o)}/`:null;return(0,Y.jsx)(Z,{hint:`app`,toolbar:g&&(0,Y.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,Y.jsx)(Jr,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,Y.jsx)(U_,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(zg,{children:[`No top-level nav items. Add `,(0,Y.jsx)(`code`,{children:`nav`}),` / `,(0,Y.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,Y.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,Y.jsx)(Y_,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Y_({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=q_(e.kind),s=X_(t,e.path);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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,Y.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,Y.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,Y.jsx)(Jr,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(Y_,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function X_(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 Z_(e){return Array.isArray(e)?{shape:`array`,entries:e.map((e,t)=>{let{name:n,...r}=e??{};return{name:typeof n==`string`&&n?n:`field_${t+1}`,def:r}})}:e&&typeof e==`object`?{shape:`record`,entries:Object.entries(e).map(([e,t])=>({name:e,def:{...t??{}}}))}:{shape:`record`,entries:[]}}function Q_(e){if(e.shape===`array`)return e.entries.map(e=>({name:e.name,...e.def}));let t={};for(let n of e.entries)t[n.name]=n.def;return t}function $_(e,t){return e.entries.findIndex(e=>e.name===t)}function ev(e,t,n){let r={type:t,label:n??tv(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function tv(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function nv(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/_{2,}/g,`_`);return t?/^[a-z_]/.test(t)?t:`f_${t}`:`field`}function rv(e,t){let n=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],r=new Map;for(let e of n)r.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let i=new Set(n.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&i.has(e)?r.get(e).entries.push(t):(r.has(null)||r.set(null,{key:null,label:`Ungrouped`,entries:[]}),r.get(null).entries.push(t))}return Array.from(r.values()).filter(e=>e.entries.length>0)}var Q=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),iv={text:Q(`text`,`Text`,`单行文本`,`text`,Qt),textarea:Q(`textarea`,`Text Area`,`多行文本`,`text`,_t),email:Q(`email`,`Email`,`邮箱`,`text`,gr),url:Q(`url`,`URL`,`网址`,`text`,er),phone:Q(`phone`,`Phone`,`电话`,`text`,Le),password:Q(`password`,`Password`,`密码`,`text`,Cr),markdown:Q(`markdown`,`Markdown`,`Markdown`,`text`,xr),html:Q(`html`,`HTML`,`HTML`,`text`,Qe),richtext:Q(`richtext`,`Rich Text`,`富文本`,`text`,yr),number:Q(`number`,`Number`,`数字`,`number`,Gn),currency:Q(`currency`,`Currency`,`货币`,`number`,Ca),percent:Q(`percent`,`Percent`,`百分比`,`number`,Vn),date:Q(`date`,`Date`,`日期`,`date`,zi),datetime:Q(`datetime`,`Date/Time`,`日期时间`,`date`,zi),time:Q(`time`,`Time`,`时间`,`date`,rn),boolean:Q(`boolean`,`Checkbox`,`复选框`,`logic`,ta),toggle:Q(`toggle`,`Toggle`,`开关`,`logic`,ze),select:Q(`select`,`Picklist`,`下拉选择`,`selection`,Ve),multiselect:Q(`multiselect`,`Multi-Select`,`多选`,`selection`,Da),radio:Q(`radio`,`Radio`,`单选`,`selection`,Sn),checkboxes:Q(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Da),lookup:Q(`lookup`,`Lookup`,`查找关系`,`relation`,Xe),master_detail:Q(`master_detail`,`Master-Detail`,`主从关系`,`relation`,Ue),tree:Q(`tree`,`Tree`,`树形关系`,`relation`,Ii),image:Q(`image`,`Image`,`图片`,`media`,Ie),file:Q(`file`,`File`,`文件`,`media`,Kn),avatar:Q(`avatar`,`Avatar`,`头像`,`media`,Zt),video:Q(`video`,`Video`,`视频`,`media`,Mn),audio:Q(`audio`,`Audio`,`音频`,`media`,ea),formula:Q(`formula`,`Formula`,`公式`,`calculated`,pi),summary:Q(`summary`,`Rollup`,`汇总`,`calculated`,Ar),autonumber:Q(`autonumber`,`Auto Number`,`自动编号`,`calculated`,Gn),composite:Q(`composite`,`Composite`,`复合字段`,`advanced`,Pr),repeater:Q(`repeater`,`Repeater`,`重复字段`,`advanced`,Ze),location:Q(`location`,`Location`,`地理坐标`,`advanced`,$r),address:Q(`address`,`Address`,`地址`,`advanced`,ai),code:Q(`code`,`Code`,`代码`,`advanced`,Qe),json:Q(`json`,`JSON`,`JSON`,`advanced`,Mr),color:Q(`color`,`Color`,`颜色`,`advanced`,gn),rating:Q(`rating`,`Rating`,`评分`,`advanced`,vn),slider:Q(`slider`,`Slider`,`滑块`,`advanced`,ia),signature:Q(`signature`,`Signature`,`签名`,`advanced`,In),qrcode:Q(`qrcode`,`QR Code`,`二维码`,`advanced`,Ht),progress:Q(`progress`,`Progress`,`进度条`,`advanced`,Wr),tags:Q(`tags`,`Tags`,`标签`,`advanced`,Mt),vector:Q(`vector`,`Vector`,`向量`,`advanced`,ni)},av=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],ov={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},sv={text:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-600 dark:border-slate-700/50 dark:bg-slate-800/40 dark:text-slate-300`},number:{icon:`text-blue-600 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800/50 dark:bg-blue-950/40 dark:text-blue-300`},date:{icon:`text-violet-600 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-800/50 dark:bg-violet-950/40 dark:text-violet-300`},logic:{icon:`text-amber-600 dark:text-amber-400`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800/50 dark:bg-amber-950/40 dark:text-amber-300`},selection:{icon:`text-teal-600 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-800/50 dark:bg-teal-950/40 dark:text-teal-300`},relation:{icon:`text-indigo-600 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-800/50 dark:bg-indigo-950/40 dark:text-indigo-300`},media:{icon:`text-pink-600 dark:text-pink-400`,badge:`border-pink-200 bg-pink-50 text-pink-700 dark:border-pink-800/50 dark:bg-pink-950/40 dark:text-pink-300`},calculated:{icon:`text-emerald-600 dark:text-emerald-400`,badge:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-800/50 dark:bg-emerald-950/40 dark:text-emerald-300`},advanced:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-700/50 dark:bg-zinc-800/40 dark:text-zinc-300`}},cv=av.map(e=>({category:e,types:Object.keys(iv).filter(t=>iv[t].category===e)}));function lv(e){let{type:t}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(uv,{...e,icon:t===`password`?(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(gr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(er,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(Le,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(Gn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(zi,{className:`h-3.5 w-3.5`}),placeholder:`Pick a date…`});case`time`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)(rn,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,Y.jsx)(dv,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(Ai,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??`Off`})]});case`select`:case`radio`:return(0,Y.jsx)(fv,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(fv,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(pv,{...e});case`image`:case`avatar`:return(0,Y.jsx)(mv,{icon:(0,Y.jsx)(Ie,{className:`h-4 w-4`}),label:t===`avatar`?`Upload avatar`:`Upload image`});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(mv,{icon:(0,Y.jsx)(Kn,{className:`h-4 w-4`}),label:`Upload ${t}`});case`qrcode`:return(0,Y.jsx)(mv,{icon:(0,Y.jsx)(Kn,{className:`h-4 w-4`}),label:`QR code`});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(gn,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,Y.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,Y.jsx)(vn,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,Y.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,Y.jsx)(uv,{...e,icon:(0,Y.jsx)($r,{className:`h-3.5 w-3.5`}),placeholder:`Lat, lng`});case`address`:return(0,Y.jsx)(dv,{...e,placeholder:e.placeholder??`Street
|
|
23
|
+
City, State ZIP
|
|
24
|
+
Country`});case`formula`:case`summary`:return(0,Y.jsx)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:e.formula?`ƒ ${e.formula}`:`ƒ Computed value`});case`composite`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:`Composite — nested sub-fields edit in the inspector.`});case`repeater`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:`Repeater — repeating row group.`});case`vector`:return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:[`[0.124, 0.337, …] `,e.placeholder?`(${e.placeholder})`:``]});default:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function uv({placeholder:e,icon:t}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(W,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,Y.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function dv({placeholder:e,mono:t}){return(0,Y.jsx)(`textarea`,{disabled:!0,placeholder:e??``,className:`w-full min-h-[60px] text-sm rounded-md border bg-background px-2 py-1.5 disabled:opacity-100 `+(t?`font-mono text-xs`:``)})}function fv({options:e,placeholder:t,single:n}){let r=e??[],i=r.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:i[0]?.label||i[0]?.value||t||`Select…`}),(0,Y.jsx)(jt,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,Y.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[i.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||`Pick one or more…`}):i.map((e,t)=>(0,Y.jsx)(U,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),r.length>i.length&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,r.length-i.length]})]})}function pv({referenceTo:e,placeholder:t}){let n=e?iv.lookup:null;return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?`Search ${e}…`:`Choose related object…`)}),e&&(0,Y.jsxs)(U,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Y.jsx)(pr,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),n&&null]})}function mv({icon:e,label:t}){return(0,Y.jsxs)(`div`,{className:`h-16 w-full border-2 border-dashed rounded flex flex-col items-center justify-center gap-1 text-muted-foreground bg-muted/20`,children:[e,(0,Y.jsx)(`span`,{className:`text-[11px]`,children:t})]})}function hv({objectName:e,draft:t,onPatch:n,selection:r,onSelectionChange:i}){let a=!n,o=J.useMemo(()=>Z_(t.fields),[t]),s=Array.isArray(t.fieldGroups)?t.fieldGroups:void 0,c=J.useMemo(()=>rv(o,s),[o,s]),l=r?.kind===`field`?String(r.id):null,u=J.useCallback(e=>{i&&i({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[i]),d=J.useCallback(e=>{if(!n)return;let t=o.entries.map(e=>e.name),r=e===`select`?`status`:e,a=1,s=r;for(;t.includes(s);)a+=1,s=`${r}_${a}`;let c=ev(s,e);n({fields:Q_({shape:o.shape,entries:[...o.entries,c]})}),i?.({kind:`field`,id:s,label:String(c.def.label??s)})},[n,i,o]),f=J.useCallback((e,t,r)=>{if(!n||e===t)return;let i=o.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[s]=i.splice(a,1),c=i.findIndex(e=>e.name===t),l=c>=0?i[c]:void 0;if(l){let e=typeof l.def.group==`string`?l.def.group:void 0;e!==(typeof s.def.group==`string`?s.def.group:void 0)&&(s.def={...s.def,group:e})}c<0?i.push(s):i.splice(r===`before`?c:c+1,0,s),n({fields:Q_({shape:o.shape,entries:i})})},[n,o]),p=J.useCallback((e,t)=>{if(!n)return;let r=o.entries.slice(),i=r.findIndex(t=>t.name===e);if(i<0)return;let[a]=r.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){r.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let s=r.length;for(let e=r.length-1;e>=0;--e)if((typeof r[e].def.group==`string`?r[e].def.group:null)===t){s=e+1;break}r.splice(s,0,a),n({fields:Q_({shape:o.shape,entries:r})})},[n,o]),m=J.useCallback((e,t)=>{if(!n)return;let r=o.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);n({fields:Q_({shape:o.shape,entries:r})})},[n,o]),h=J.useCallback(e=>{e.target===e.currentTarget&&l&&i?.(null)},[i,l]),g=o.entries.length===0;return(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:h,"data-object-name":e,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-6`,onClick:h,children:[g?(0,Y.jsx)(vv,{onAdd:a?void 0:d}):c.map(e=>(0,Y.jsx)(gv,{groupKey:e.key,label:e.label,showHeader:c.length>1,onDropField:a?void 0:p,children:e.entries.map(e=>(0,Y.jsx)(_v,{entry:e,selected:e.name===l,readOnly:a,onClick:()=>u(e),onReorder:a?void 0:f,onRenameLabel:a?void 0:m},e.name))},e.key??`__ungrouped__`)),!g&&!a&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(yv,{onPick:d})})]})})}function gv({groupKey:e,label:t,showHeader:n,onDropField:r,children:i}){let[a,o]=J.useState(!1);return(0,Y.jsxs)(`section`,{className:B(`space-y-2.5 rounded-md transition-colors`,a&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!r)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,o(!0))},onDragLeave:e=>{e.currentTarget===e.target&&o(!1)},onDrop:t=>{if(!r)return;if(t.defaultPrevented){o(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);o(!1),n&&r(n,e)},children:[n&&(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 flex items-center gap-1.5`,children:[t,a&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop to assign`})]}),(0,Y.jsx)(`div`,{className:`space-y-2.5`,children:i})]})}function _v({entry:e,selected:t,readOnly:n,onClick:r,onReorder:i,onRenameLabel:a}){let o=e.def,s=typeof o.type==`string`?o.type:`text`,c=iv[s],l=c?.Icon,u=sv[c?.category??`advanced`],d=typeof o.label==`string`?o.label:e.name,f=!!o.required,p=typeof o.description==`string`?o.description:null,m=Array.isArray(o.options)?o.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,h=typeof o.reference==`string`?o.reference:void 0,g=typeof o.formula==`string`?o.formula:void 0,_=typeof o.placeholder==`string`?o.placeholder:void 0,[v,y]=J.useState(null),b=!!i,[x,S]=J.useState(!1),[C,w]=J.useState(d);J.useEffect(()=>{w(d)},[d]);let T=e=>{a&&(e.preventDefault(),e.stopPropagation(),w(d),S(!0))},E=()=>{if(!a){S(!1);return}let t=C.trim();t&&t!==d&&a(e.name,t),S(!1)},D=()=>{w(d),S(!1)};return(0,Y.jsxs)(`div`,{className:B(`relative`,v===`before`&&`pt-1.5`),onDragOver:e=>{if(!b)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();y(e.clientY-n.top<n.height/2?`before`:`after`)},onDragLeave:()=>y(null),onDrop:t=>{if(!i)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);y(null),n&&n!==e.name&&i(n,e.name,v??`before`)},children:[v===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:r,draggable:b,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:B(`group w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card`,t?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,n&&`cursor-default`,b&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[b&&(0,Y.jsx)(Ji,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),l&&(0,Y.jsx)(l,{className:B(`h-3.5 w-3.5 shrink-0`,u.icon)}),x?(0,Y.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),E()):e.key===`Escape`&&(e.preventDefault(),D())},onBlur:E,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:B(`text-sm font-medium truncate`,a&&`cursor-text`),onDoubleClick:T,title:a?`Double-click to rename`:void 0,children:d}),f&&(0,Y.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,Y.jsx)(U,{variant:`outline`,className:B(`text-[10px] shrink-0 font-medium`,u.badge),children:c?.label??s})]}),p&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:p}),(0,Y.jsx)(lv,{type:s,label:d,placeholder:_,options:m,referenceTo:h,formula:g})]}),v===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function vv({onAdd:e}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No fields yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Add a field to start designing the form. Click any field to edit its properties on the right.`}),e&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsx)(yv,{onPick:e})})]})}function yv({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?cv.map(e=>({category:e.category,types:e.types.filter(e=>{let t=iv[e];return e.includes(a)||t.label.toLowerCase().includes(a)||t.labelZh.includes(r.trim())})})).filter(e=>e.types.length>0):cv,[a,r]);return(0,Y.jsxs)(ur,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Ae,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add field`]})}),(0,Y.jsxs)(yn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search field type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:ov[t.category]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=iv[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(a,{className:B(`h-3.5 w-3.5 shrink-0`,sv[r.category].icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label})]},t)})})]},t.category))})]})]})}function bv({name:e,draft:t,onPatch:n,selection:r,onSelectionChange:i}){let a=String(t.name??e??``);return a?(0,Y.jsx)(Z,{hint:`object · designer`,children:(0,Y.jsx)(Vg,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Y.jsx)(hv,{objectName:a,draft:t,onPatch:n,selection:r,onSelectionChange:i})})}):(0,Y.jsx)(Z,{hint:`object`,children:(0,Y.jsx)(zg,{children:`Give the object a name in the Form tab to enable the preview.`})})}function xv(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 Sv(e,t){return t[e]??``}function Cv(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Sv(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Sv(n,t))}function wv({draft:e}){let t=String(e.subject??``),n=String(e.from??e.fromAddress??``),r=String(e.to??``),i=String(e.bodyHtml??e.html??e.body??``),a=String(e.bodyText??e.text??``),o=J.useMemo(()=>{let e=new Set;for(let n of xv(t))e.add(n);for(let t of xv(i))e.add(t);for(let t of xv(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=J.useState({}),l=Cv(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
25
|
+
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
26
|
+
a{color:#2563eb;}
|
|
27
|
+
</style></head><body>${(i?Cv(i,s):Cv(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Y.jsx)(Z,{hint:`email_template`,children:(0,Y.jsx)(zg,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Y.jsx)(Z,{hint:`email_template`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,Y.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,Y.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,Y.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,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)(fr,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,Y.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,Y.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,Y.jsxs)(`label`,{className:`block`,children:[(0,Y.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,Y.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 Tv(e){switch(e){case`start`:return Ft;case`end`:return dn;case`decision`:case`branch`:case`gateway`:return za;case`wait`:case`timer`:return Un;case`boundary_event`:case`signal`:return Ba;case`subflow`:case`flow`:return Ue;default:return Sn}}var Ev={start:{icon:`text-emerald-600 dark:text-emerald-400`,chip:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300`},end:{icon:`text-rose-600 dark:text-rose-400`,chip:`border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-300`},decision:{icon:`text-amber-600 dark:text-amber-400`,chip:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},wait:{icon:`text-blue-600 dark:text-blue-400`,chip:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},signal:{icon:`text-violet-600 dark:text-violet-400`,chip:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},subflow:{icon:`text-indigo-600 dark:text-indigo-400`,chip:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},task:{icon:`text-slate-500 dark:text-slate-400`,chip:`border-slate-200 bg-slate-100 text-slate-600 dark:border-slate-800 dark:bg-slate-900/60 dark:text-slate-300`}};function Dv(e){switch(e){case`start`:return Ev.start;case`end`:return Ev.end;case`decision`:case`branch`:case`gateway`:return Ev.decision;case`wait`:case`timer`:return Ev.wait;case`boundary_event`:case`signal`:return Ev.signal;case`subflow`:case`flow`:return Ev.subflow;default:return Ev.task}}function Ov(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function kv(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 Av({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=J.useCallback(()=>{if(!d)return;let e={id:h_(`node`,s.map(e=>e.id).filter(Boolean)),type:`task`,label:`New node`};i({nodes:p_(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),h=J.useMemo(()=>kv(s,c),[s,c]),g=J.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]),_=J.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,Y.jsx)(Z,{hint:`flow${u?` · design`:``}`,children:d?(0,Y.jsx)(`div`,{className:`p-3`,children:(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.node`,a)]})}):(0,Y.jsx)(zg,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Y.jsx)(Z,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Y.jsx)(Vg,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,Y.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Y.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,Y.jsx)(Lv,{icon:Ba,label:`Trigger`,value:v}),(0,Y.jsx)(Lv,{icon:Sn,label:`Status`,value:y,tone:y===`active`?`green`:y===`draft`?`gray`:`amber`}),(0,Y.jsx)(Lv,{icon:oi,label:`Run as`,value:b}),x&&(0,Y.jsx)(Lv,{label:`v`,value:x}),S&&(0,Y.jsx)(Lv,{icon:Yn,label:`On error`,value:S})]}),(0,Y.jsx)(`ol`,{className:`space-y-2`,children:h.map((e,t)=>{let n=Tv(e.type),r=Dv(e.type),i=g.get(e.id)??[],a=e.type===`decision`||e.type===`branch`||e.type===`gateway`;return(0,Y.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,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,Y.jsx)(`span`,{className:B(`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full border text-[10px] font-mono`,r.chip),children:t+1}),(0,Y.jsx)(n,{className:B(`h-4 w-4 mt-0.5 shrink-0`,r.icon)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.id}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,Y.jsx)(`span`,{className:B(`text-[10px] uppercase tracking-wider font-medium`,r.icon),children:e.type})]}),jv(e)&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5 font-mono break-all`,children:jv(e)})]})]}),i.length>0&&(0,Y.jsx)(`div`,{className:`border-t bg-muted/20 px-3 py-1.5 text-[11px] space-y-0.5`,children:i.map((e,t)=>{let n=Ov(e.condition),r=_.get(e.target),i=a?e.isDefault?`else`:n?`if ${n}`:e.label??`branch`:e.label??(n?`when ${n}`:`next`);return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Nn,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:i}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:r?.label||e.target}),!r&&(0,Y.jsx)(`span`,{className:`ml-1 text-amber-600`,children:`(unresolved)`})]},e.id||t)})})]},e.id||t)})}),d&&(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.node`,a)]})]}),(0,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)($e,{className:`h-3 w-3`}),` Variables`]}),l.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:l.map((e,t)=>(0,Y.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]})]})})})}function jv(e){let t=e.config;if(t){switch(e.type){case`get_record`:case`get_records`:case`find_records`:return Mv(`object`,t.objectName)+Mv(` · id`,t.recordId)+Mv(` → `,t.outputVariable);case`create_record`:case`create_records`:return Mv(`create`,t.objectName)+Pv(t.fields)+Mv(` → `,t.outputVariable);case`update_record`:case`update_records`:return Mv(`update`,t.objectName)+Mv(` #`,t.recordId)+Pv(t.fields);case`delete_record`:case`delete_records`:return Mv(`delete`,t.objectName)+Mv(` #`,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 Nv(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??`?`} = ${Fv(e.value??e.expression)}`).join(`; `)+(e.length>3?` …`:``):void 0}case`subflow`:case`flow`:return Mv(`flow`,t.flowName??t.flowId);case`action`:return Mv(`action`,t.actionName??t.actionId);case`wait`:case`timer`:return Mv(`wait`,t.duration??t.delayMs??t.until);case`loop`:case`for_each`:return Mv(`collection`,t.collection)+Mv(` as `,t.itemVariable);case`http_call`:return`${String(t.method??`POST`).toUpperCase()} ${t.url??`?`}`;case`send_email`:return Mv(`template`,t.template??t.templateName)+Mv(` → `,Iv(t.recipients??t.to));case`invoke_agent`:case`agent`:return Mv(`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 Mv(e,t){return t==null||t===``?``:/[→=]\s*$/.test(e)?`${e}${String(t)}`:`${e}: ${String(t)}`}function Nv(e){if(typeof e==`string`)return`if ${e}`;if(e&&typeof e==`object`&&typeof e.source==`string`)return`if ${e.source}`}function Pv(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 Fv(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 Iv(e){return Array.isArray(e)?e.slice(0,3).join(`, `)+(e.length>3?`, …`:``):typeof e==`string`?e:``}function Lv({icon:e,label:t,value:n,tone:r=`gray`}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,Y.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function Rv(e){switch(e){case`field_update`:return ht;case`email_alert`:return fr;case`http_call`:case`webhook`:return er;case`task_creation`:return Da;case`push_notification`:return Pi;case`custom_script`:return Ke;case`connector_action`:return bt;default:return ya}}var zv={field_update:{icon:`text-blue-600 dark:text-blue-400`,chip:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`},email_alert:{icon:`text-violet-600 dark:text-violet-400`,chip:`border-violet-200 bg-violet-50 dark:border-violet-900 dark:bg-violet-950/40`},http_call:{icon:`text-indigo-600 dark:text-indigo-400`,chip:`border-indigo-200 bg-indigo-50 dark:border-indigo-900 dark:bg-indigo-950/40`},task_creation:{icon:`text-emerald-600 dark:text-emerald-400`,chip:`border-emerald-200 bg-emerald-50 dark:border-emerald-900 dark:bg-emerald-950/40`},push_notification:{icon:`text-amber-600 dark:text-amber-400`,chip:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`},custom_script:{icon:`text-teal-600 dark:text-teal-400`,chip:`border-teal-200 bg-teal-50 dark:border-teal-900 dark:bg-teal-950/40`},connector_action:{icon:`text-rose-600 dark:text-rose-400`,chip:`border-rose-200 bg-rose-50 dark:border-rose-900 dark:bg-rose-950/40`},default:{icon:`text-slate-500 dark:text-slate-400`,chip:`border-slate-200 bg-slate-100 dark:border-slate-800 dark:bg-slate-900/60`}};function Bv(e){switch(e){case`field_update`:return zv.field_update;case`email_alert`:return zv.email_alert;case`http_call`:case`webhook`:return zv.http_call;case`task_creation`:return zv.task_creation;case`push_notification`:return zv.push_notification;case`custom_script`:return zv.custom_script;case`connector_action`:return zv.connector_action;default:return zv.default}}function Vv(e){switch(e.type){case`field_update`:return`${e.field??(e.objectName?`${e.objectName}.${e.fieldName??`?`}`:`?`)} = ${Hv(e.value)}`;case`email_alert`:return`template: ${e.template??e.templateName??`?`} → ${Uv(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 Hv(e){return e==null?`∅`:typeof e==`string`?`"${e}"`:typeof e==`object`?JSON.stringify(e):String(e)}function Uv(e){let t=e.recipients??e.to;return Array.isArray(t)?t.slice(0,3).join(`, `)+(t.length>3?`, …`:``):typeof t==`string`?t:`—`}function Wv({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=J.useCallback(()=>{if(!g)return;let e={type:`field_update`,name:``},t=p_(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,Y.jsx)(Z,{hint:`workflow${h?` · design`:``}`,children:g?(0,Y.jsx)(`div`,{className:`p-3`,children:(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.action`,a)]})}):(0,Y.jsx)(zg,{children:`Set the target object and at least one action to see the workflow preview.`})}):(0,Y.jsx)(Z,{hint:`workflow · ${d.length+f.reduce((e,t)=>e+(t.actions?.length??0),0)} action(s)`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 text-xs space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,Y.jsx)(Yv,{icon:Ue,label:`Object`,value:s||`—`,mono:!0}),(0,Y.jsx)(Yv,{icon:Lt,label:`When`,value:c}),(0,Y.jsx)(Yv,{icon:ln,label:`Active`,value:p?`yes`:`no`,tone:p?`green`:`amber`}),m!=null&&(0,Y.jsx)(Yv,{label:`Order`,value:String(m)})]}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(Ee,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Criteria:`}),(0,Y.jsx)(`code`,{className:`font-mono text-foreground break-all`,children:u||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`always`})})]})]}),(0,Y.jsxs)(qv,{title:`Immediate Actions`,count:d.length,children:[d.length===0?(0,Y.jsx)(Jv,{children:`No immediate actions.`}):(0,Y.jsx)(`ul`,{className:`divide-y rounded border bg-background`,children:d.map((e,t)=>{let n=`actions[${t}]`;return(0,Y.jsx)(Gv,{action:e,onClick:h?()=>v(e,n):void 0,selected:_===n},t)})}),g&&(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.action`,a)]})]}),f.length>0&&(0,Y.jsx)(qv,{title:`Time-Dependent Actions`,count:f.length,children:(0,Y.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,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs border-b bg-muted/20`,children:[(0,Y.jsx)(on,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[n>=0?`+`:``,n,` `,r]}),(0,Y.jsx)(En,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`after`}),(0,Y.jsx)(`code`,{className:`font-mono`,children:i})]}),Array.isArray(e.actions)&&e.actions.length>0?(0,Y.jsx)(`ul`,{className:`divide-y`,children:e.actions.map((e,n)=>{let r=`timeTriggers[${t}].actions[${n}]`;return(0,Y.jsx)(Gv,{action:e,onClick:h?()=>v(e,r):void 0,selected:_===r},n)})}):(0,Y.jsx)(Jv,{children:`No actions scheduled at this offset.`})]},t)})})})]})})})}function Gv({action:e,onClick:t,selected:n}){let r=Rv(e.type),i=Bv(e.type),a=Vv(e),o=e.name;return(0,Y.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,Y.jsx)(`span`,{className:B(`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded border`,i.chip),children:(0,Y.jsx)(r,{className:B(`h-3 w-3`,i.icon)})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:Kv(e.type)}),o&&(0,Y.jsx)(`code`,{className:`font-mono text-[10px] text-foreground`,children:o}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.type})]}),a&&(0,Y.jsx)(`div`,{className:`text-muted-foreground font-mono break-all`,children:a})]})]})}function Kv(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function qv({title:e,count:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Jv({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-2 py-1.5`,children:e})}function Yv({icon:e,label:t,value:n,tone:r=`gray`,mono:i=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,Y.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`} ${i?`font-mono`:``}`,children:n})]})}function Xv({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,Y.jsx)(Z,{hint:`agent`,children:(0,Y.jsx)(zg,{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,Y.jsx)(Z,{hint:`agent`,toolbar:v&&(0,Y.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,Y.jsx)(Jr,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,Y.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,Y.jsx)(ya,{className:`h-5 w-5 text-muted-foreground`})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(ay,{icon:c?_a:Lr,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Y.jsx)(ay,{icon:Cr,label:l}),u.provider&&(0,Y.jsx)(ay,{icon:yr,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Y.jsx)(ay,{icon:or,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Y.jsx)(ay,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Y.jsx)(Qv,{title:`Instructions`,icon:Sa,children:s?(0,Y.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,Y.jsx)($v,{children:`No system prompt set yet.`})}),(0,Y.jsx)(Qv,{title:`Capabilities`,icon:Tn,children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(ty,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:yr,tone:`violet`,mono:!0}),(0,Y.jsx)(ty,{label:`Tools`,emptyHint:`No direct tools (skills can provide them)`,items:f.map((e,t)=>({key:`${e.type??``}:${e.name??t}`,label:e.name??String(e),hint:e.type})),icon:Tn,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Y.jsx)(Qv,{title:`Knowledge (RAG)`,icon:Tr,children:(0,Y.jsx)(Zv,{knowledge:p})})]}),(0,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,Y.jsx)(ny,{icon:ca,title:`Planning`,children:(0,Y.jsx)(ry,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Y.jsx)(ny,{icon:Ci,title:`Memory`,children:(0,Y.jsx)(ry,{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,Y.jsx)(ny,{icon:ha,title:`Guardrails`,children:(0,Y.jsx)(ry,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Y.jsx)(ny,{icon:Cr,title:`Permissions`,children:(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,Y.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function Zv({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,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,Y.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,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(Tr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Qv({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function $v({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var ey={violet:{chip:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`,icon:`text-violet-500 dark:text-violet-400`},blue:{chip:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`,icon:`text-blue-500 dark:text-blue-400`}};function ty({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?ey[i]:null;return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,Y.jsxs)(`span`,{className:B(`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px]`,o?o.chip:`bg-background`,a&&`font-mono`),children:[r&&(0,Y.jsx)(r,{className:B(`h-3 w-3 shrink-0`,o?.icon)}),e.label,e.hint&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase opacity-70`,children:e.hint})]},e.key))})]})}function ny({icon:e,title:t,children:n}){return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,Y.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function ry({data:e,keys:t}){let n=t.map(t=>[t,iy(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,Y.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function iy(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function ay({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function oy(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function sy(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${sy(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function cy(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 ly({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=oy(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=J.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=cy(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=cy(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Y.jsx)(Z,{hint:`tool`,children:(0,Y.jsx)(zg,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Y.jsx)(Z,{hint:`tool`,toolbar:r&&(0,Y.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,Y.jsx)(Jr,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,Y.jsx)(py,{icon:Qi,label:o}),s&&(0,Y.jsx)(py,{icon:Tr,label:s,mono:!0}),(0,Y.jsx)(py,{icon:ln,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Y.jsx)(py,{icon:fn,label:`Requires confirmation`,tone:`amber`}),u&&(0,Y.jsx)(py,{label:`built-in`})]})]})]}),a&&(0,Y.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Y.jsx)(dy,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Y.jsx)(fy,{children:`This tool takes no input parameters.`}):(0,Y.jsx)(uy,{props:p,required:m})}),Object.keys(p).length>0&&(0,Y.jsx)(dy,{title:`Example LLM Call`,icon:Mr,children:(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
|
|
28
|
+
"tool": "${r}",
|
|
29
|
+
"arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
|
|
30
|
+
`)}
|
|
31
|
+
}`})}),oy(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(dy,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:ki,children:(0,Y.jsx)(uy,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function uy({props:e,required:t}){return(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:Object.keys(e).map(n=>{let r=e[n],i=t.has(n);return(0,Y.jsxs)(`tr`,{className:`align-top`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,Y.jsx)(Ga,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(qn,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:sy(r)}),(0,Y.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,Y.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function dy({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function fy({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function py({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var my=[{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 hy(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 gy({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isProfile,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=J.useMemo(()=>Object.keys(o).sort(),[o]),f=J.useMemo(()=>hy(o),[o]),p=J.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,Y.jsx)(Z,{hint:`permission`,children:(0,Y.jsx)(zg,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(Z,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,Y.jsx)(vn,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(Ir,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(by,{icon:mi,label:`${d.length} objects`}),(0,Y.jsx)(by,{icon:Qi,label:`${c.length} system perms`}),(0,Y.jsx)(by,{icon:_a,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(by,{icon:Cr,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(yy,{title:`Object Permissions`,count:d.length,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),my.map(e=>(0,Y.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),my.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(_y,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(vy,{})]}),p.size>0&&(0,Y.jsx)(yy,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,Y.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,Y.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,Y.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,Y.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,Y.jsx)(yy,{title:`System Permissions`,count:c.length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,Y.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,Y.jsx)(yy,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.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,Y.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,Y.jsx)(fn,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,Y.jsxs)(`li`,{className:`text-amber-900`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function _y({granted:e,danger:t}){return e?(0,Y.jsx)(Ga,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(gi,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function vy(){return(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ga,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ga,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(gi,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,Y.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 yy({title:e,count:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function by({icon:e,label:t}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:t})]})}function xy(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 Sy(e){switch(e){case`url`:return Xe;case`modal`:return vi;case`flow`:return Ue;case`api`:return er;case`form`:return ht;default:return Ke}}function Cy(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 wy(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 Ty({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=xy(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=xy(n.confirmText),g=xy(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=Sy(o),w=l===`action:icon`;return!r&&!i?(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(zg,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,Y.jsx)(Ey,{label:i,icon:a,variant:c,iconOnly:w,disabled:!!S&&typeof S==`boolean`})}),(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Ny,{icon:C,label:`type: ${o}`}),b&&(0,Y.jsx)(Ny,{icon:Vr,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(Ny,{label:`variant: ${c}`}),l&&(0,Y.jsx)(Ny,{icon:Ki,label:l}),d&&(0,Y.jsx)(Ny,{icon:Yt,label:d,mono:!0}),f&&(0,Y.jsx)(Ny,{icon:Ra,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(Ny,{icon:tn,label:`refresh after`}),m===!1&&(0,Y.jsx)(Ny,{icon:ya,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(Ny,{icon:yr,label:`AI: exposed`})]}),u.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,Y.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,Y.jsx)(jy,{label:`Visible when`,value:x,icon:_a}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(jy,{label:`Disabled when`,value:S,icon:Cr})]}),(0,Y.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,Y.jsx)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,Y.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:wy(o,s,!!y?.source)}),h&&(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,Y.jsx)(fn,{className:`h-3 w-3 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[`First asks: `,(0,Y.jsx)(`em`,{children:h})]})]}),g&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,Y.jsx)(`em`,{children:g})]})]}),_.length>0&&(0,Y.jsx)(My,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(Oy,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(My,{title:`Result Dialog`,icon:_a,children:(0,Y.jsx)(Ay,{dialog:v})}),y?.source&&(0,Y.jsx)(My,{title:`Script Body (${y.language??`expression`})`,icon:Ke,children:(0,Y.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 Ey({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,Y.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 ${Cy(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(Dy,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function Dy({name:e}){return(0,Y.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 Oy({title:e,params:t,variant:n}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,Y.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[xy(e.label)||n,e.required&&(0,Y.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,Y.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),ky(e),e.helpText&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${Cy(n||`primary`)}`,children:`OK`})]})]})}function ky(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,Y.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,Y.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,Y.jsx)(`option`,{value:e.value,children:xy(e.label)},t))]}):e.type===`boolean`?(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,Y.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,Y.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 Ay({dialog:e}){let t=xy(e.title)||`Result`,n=xy(e.description),r=xy(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,Y.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:xy(t.label)||t.path}),(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,Y.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 jy({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,Y.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function My({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Ny({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Py(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Fy({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=Py(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=J.useCallback(()=>{if(!g)return;let e=h_(`step`,f.map(e=>e.name).filter(Boolean)),t={name:e,label:`New step`,approvers:[]};i({steps:p_(f,t)}),r?.({kind:`step`,id:e,label:t.label||e})},[g,f,i,r]);return f.length===0&&!s?(0,Y.jsx)(Z,{hint:`approval${h?` · design`:``}`,children:g?(0,Y.jsx)(`div`,{className:`p-3`,children:(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.step`,a)]})}):(0,Y.jsx)(zg,{children:`Set the target object and at least one step to see the approval chain.`})}):(0,Y.jsx)(Z,{hint:`approval · ${f.length} step${f.length===1?``:`s`}`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Y.jsx)(zy,{icon:ln,label:c?`Active`:`Inactive`,tone:c?`green`:`gray`}),(0,Y.jsx)(zy,{icon:qr,label:`object: ${s||`—`}`,mono:!0}),(0,Y.jsx)(zy,{icon:Cr,label:l?`lock during approval`:`unlocked`,tone:l?`amber`:`gray`}),u&&(0,Y.jsx)(zy,{label:`status field: ${u}`,mono:!0})]}),d&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(Ee,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Entry:`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:d})]})]}),p?.enabled&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40 p-2.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-900 dark:text-amber-200`,children:[(0,Y.jsx)(on,{className:`h-3.5 w-3.5`}),` SLA escalation enabled`]}),(0,Y.jsxs)(`div`,{className:`mt-1 text-amber-900 dark:text-amber-200`,children:[`After `,(0,Y.jsxs)(`code`,{className:`font-mono`,children:[p.timeoutHours,`h`]}),` on a pending step →`,` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:p.action??`notify`}),p.escalateTo&&(0,Y.jsxs)(Y.Fragment,{children:[` → `,(0,Y.jsx)(`code`,{className:`font-mono`,children:p.escalateTo})]}),p.notifySubmitter&&(0,Y.jsx)(`span`,{className:`ml-1 opacity-80`,children:`(notify submitter)`})]})]}),f.length===0?(0,Y.jsx)(zg,{children:`No steps defined yet.`}):(0,Y.jsx)(`ol`,{className:`space-y-2`,children:f.map((e,t)=>(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsx)(Iy,{step:e,index:t,onClick:h?()=>v(e,t):void 0,selected:_!=null&&(e.name===_||`steps[${t}]`===_)}),t<f.length-1&&(0,Y.jsx)(`li`,{className:`flex justify-center`,"aria-hidden":!0,children:(0,Y.jsx)(Nn,{className:`h-3.5 w-3.5 text-muted-foreground`})})]},e.name||t))}),g&&(0,Y.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,Y.jsx)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.step`,a)]}),(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/20 p-2.5 text-xs`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[(0,Y.jsx)(Ry,{icon:Lt,label:`onSubmit`,actions:m.onSubmit}),(0,Y.jsx)(Ry,{icon:Ga,label:`onFinalApprove`,actions:m.onFinalApprove,tone:`green`}),(0,Y.jsx)(Ry,{icon:Wt,label:`onFinalReject`,actions:m.onFinalReject,tone:`red`}),(0,Y.jsx)(Ry,{icon:Gt,label:`onRecall`,actions:m.onRecall})]})]})]})})})}function Iy({step:e,index:t,onClick:n,selected:r}){let i=e.approvers??[],a=Py(e.entryCriteria);return(0,Y.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,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,Y.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,Y.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.name||`Step ${t+1}`}),e.name&&(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name}),e.behavior&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.behavior===`unanimous`?`all must approve`:`first response wins`})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.description}),a&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,Y.jsx)(Ee,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`When:`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:a})]}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,Y.jsx)(qe,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Approvers:`}),i.length===0?(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`none`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:i.map((e,t)=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px]`,children:[(0,Y.jsx)(Fe,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:e.value||`?`}),e.type&&(0,Y.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,Y.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,Y.jsx)(Ly,{icon:Ga,tone:`green`,label:`on approve`,actions:e.onApprove}),e.onReject&&e.onReject.length>0&&(0,Y.jsx)(Ly,{icon:Wt,tone:`red`,label:`on reject`,actions:e.onReject}),e.rejectionBehavior&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[e.rejectionBehavior===`back_to_previous`?(0,Y.jsx)(Oa,{className:`h-3 w-3`}):(0,Y.jsx)(Hn,{className:`h-3 w-3`}),(0,Y.jsxs)(`span`,{children:[`Rejection: `,(0,Y.jsx)(`code`,{className:`font-mono text-foreground`,children:e.rejectionBehavior})]})]})]})]})}function Ly({icon:e,tone:t,label:n,actions:r}){return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(e,{className:`h-3 w-3 mt-0.5 ${t===`green`?`text-emerald-700 dark:text-emerald-400`:`text-red-700 dark:text-red-400`}`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[n,`:`]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map((e,t)=>(0,Y.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,Y.jsxs)(`span`,{className:`opacity-70`,children:[`· `,e.name]})]},t))})]})}function Ry({icon:e,label:t,actions:n,tone:r=`gray`}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${r===`green`?`text-emerald-700 dark:text-emerald-400`:r===`red`?`text-red-700 dark:text-red-400`:`text-muted-foreground`}`,children:[(0,Y.jsx)(e,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:t}),(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1 text-[10px]`,children:n.length})]})}function zy({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:n===`amber`?`text-amber-700 dark:text-amber-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var By={"@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 Vy(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 Hy(e){let t=(By[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=Vy(n,0,59),c=Vy(r,0,23),l=Vy(i,1,31),u=Vy(a,1,12),d=Vy(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function Uy(e,t,n){let r=Hy(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 Wy(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 Gy(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function Ky(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function qy(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?Jy(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`?Jy(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function Jy(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 Yy({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}=qy(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?Wy(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=Uy(o,e,5);else if(_)t=Gy(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Xy(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(zg,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(on,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)($y,{icon:ln,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)($y,{icon:si,label:l,mono:!0}),p!=null&&(0,Y.jsx)($y,{icon:Oa,label:`retries: ${p}${m?` (${Jy(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)($y,{icon:Ka,label:`timeout: ${Jy(h)}`}),g!=null&&(0,Y.jsx)($y,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(Qy,{title:`Schedule`,icon:zi,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(Zy,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(Zy,{label:`Every`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,Y.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,Y.jsx)(Zy,{label:`At`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,Y.jsx)(Qy,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:rn,children:v.length===0?(0,Y.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,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,Y.jsx)(rn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:Ky(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(Qy,{title:`Handler`,icon:Ke,children:u?(0,Y.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Xy(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 Zy({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`break-all`,children:t})]})}function Qy({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function $y({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var eb=[{key:`objects`,label:`Objects`,icon:Da,flat:!1},{key:`apps`,label:`Apps`,icon:Je,flat:!1},{key:`messages`,label:`Messages`,icon:Kr,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:qr,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Pe,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:je,flat:!1},{key:`settings`,label:`Settings`,icon:oi,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:xr,flat:!1}];function tb({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=eb.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/eb.length*100);return c===0?(0,Y.jsx)(Z,{hint:`translation · ${r}`,children:(0,Y.jsx)(zg,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(Z,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Vt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.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,Y.jsx)(si,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,Y.jsx)(or,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,Y.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,eb.length,` (`,u,`%)`]}),(0,Y.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,Y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,Y.jsx)(nb,{cat:e},e.key))})]})})})}function nb({cat:e}){let t=e.icon;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,Y.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,Y.jsx)(`span`,{className:`truncate text-foreground/80`,children:rb(n,e.flat)})]},t)),e.count>e.sample.length&&(0,Y.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function rb(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function ib({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,Y.jsx)(Z,{hint:`role`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(qe,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,Y.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Bn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,Y.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,Y.jsx)(Pa,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.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,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.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,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,Y.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,Y.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,Y.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,Y.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,Y.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,Y.jsx)(Z,{hint:`role`,children:(0,Y.jsx)(zg,{children:`Give the role a name to see the preview.`})})}function ab({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,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(yr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(sb,{icon:ln,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(sb,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(sb,{icon:Ir,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(ob,{title:`Instructions`,icon:Xr,children:o?(0,Y.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,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,Y.jsxs)(ob,{title:`Tools (${s.length})`,icon:Tn,children:[s.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,Y.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,Y.jsx)(Ta,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,Y.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,Y.jsx)(ob,{title:`Trigger Phrases (${c.length})`,icon:ma,children:(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,Y.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,Y.jsx)(ob,{title:`Trigger Conditions (${l.length})`,icon:Ee,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,Y.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,Y.jsx)(ob,{title:`Required Permissions`,icon:Ir,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,Y.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,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(zg,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function ob({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function sb({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var cb=/pass|secret|key|token|credential|auth/i;function lb(e){return cb.test(e)}function ub(e){return e==null||e===``?`∅`:`••••••`}function db(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 fb({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,Y.jsx)(Z,{hint:`datasource`,children:(0,Y.jsx)(zg,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(Z,{hint:`datasource · ${o}`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Tr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,Y.jsx)(ct,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(hb,{icon:ln,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(hb,{icon:vn,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(hb,{icon:He,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(mb,{title:`Connection`,icon:Cr,children:g.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:g.map(([e,t])=>{let n=lb(e);return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:ub(t)}),(0,Y.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`})]}):db(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(pb,{title:`Pool`,icon:Ci,value:u}),(0,Y.jsx)(pb,{title:`SSL`,icon:Ir,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)(pb,{title:`Retry Policy`,icon:Oa,value:f}),(0,Y.jsx)(pb,{title:`Health Check`,icon:Ci,value:p})]}),h.length>0&&(0,Y.jsx)(mb,{title:`Capabilities`,icon:Ir,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,Y.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 pb({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`dd`,{className:`font-mono truncate`,children:lb(e)?ub(t):db(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function mb({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function hb({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function gb(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function _b(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/40`,text:`text-red-700 dark:text-red-300`,icon:la};case`warning`:return{ring:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`,text:`text-amber-800 dark:text-amber-300`,icon:fn};default:return{ring:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`,text:`text-blue-800 dark:text-blue-300`,icon:Pt}}}function vb({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=_b(l);return r?(0,Y.jsx)(Z,{hint:`validation · ${o}`,children:(0,Y.jsx)(Vg,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(qr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Sb,{icon:ln,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(Sb,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(Sb,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(Sb,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,Y.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,Y.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,Y.jsx)(yb,{type:o,d:n}),p.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,Y.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,Y.jsx)(Z,{hint:`validation`,children:(0,Y.jsx)(zg,{children:`Give the validation a name to see the preview.`})})}function yb({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(xb,{title:`Condition`,icon:Ke,children:(0,Y.jsx)(bb,{value:gb(t.condition)??gb(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=gb(t.scope)??gb(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(xb,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:na,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,Y.jsx)(xb,{title:`Scope`,icon:Ar,children:(0,Y.jsx)(bb,{value:n})})]})}case`state_machine`:{let e=Array.isArray(t.transitions)?t.transitions:[],n=t.field;return(0,Y.jsx)(xb,{title:`Transitions${n?` on ${n}`:``}`,icon:Ue,children:e.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:e.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:Array.isArray(e.from)?e.from.join(` | `):e.from??`*`}),(0,Y.jsx)(En,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:e.to??`?`})]},t))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,Y.jsx)(xb,{title:`Format`,icon:Ge,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=gb(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(xb,{title:`Fields involved`,icon:Ar,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,Y.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,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,Y.jsx)(xb,{title:`Cross-field condition`,icon:Ke,children:(0,Y.jsx)(bb,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(xb,{title:`Async endpoint`,icon:si,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,Y.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,Y.jsx)(xb,{title:`Custom handler`,icon:Ke,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,Y.jsx)(xb,{title:`Rule`,icon:qr,children:(0,Y.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 bb({value:e}){return e?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function xb({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Sb({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Cb(){Gh(`page`,r_),Gh(`view`,T_),Gh(`dashboard`,M_),Gh(`report`,F_),Gh(`app`,J_),Gh(`action`,Ty),Gh(`object`,bv),Gh(`datasource`,fb),Gh(`validation`,vb),Gh(`email_template`,wv),Gh(`translation`,tb),Gh(`flow`,Av),Gh(`workflow`,Wv),Gh(`approval`,Fy),Gh(`job`,Yy),Gh(`agent`,Xv),Gh(`tool`,ly),Gh(`skill`,ab),Gh(`permission`,gy),Gh(`profile`,gy),Gh(`role`,ib)}var wb=[{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`}],Tb=[`count`,`sum`,`avg`,`min`,`max`],Eb=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function Db(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 Ob({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Y.jsx)(Ab,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=Db(e,t.id);if(!s)return(0,Y.jsx)(Ab,{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:m_(u,l,e)}),c.id&&i?.({kind:`widget`,id:c.id,label:c.title??void 0})}return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:X(`engine.inspector.widget.kind`,o)}),(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:c.title||t.label||`Widget ${l+1}`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(a_,{index:l,total:u.length,onMove:f,upLabel:X(`engine.inspector.reorder.up`,o),downLabel:X(`engine.inspector.reorder.down`,o),disabled:a}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:X(`engine.inspector.widget.close`,o),"aria-label":X(`engine.inspector.widget.close`,o),children:(0,Y.jsx)(Fa,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(kb,{id:`widget-title`,label:X(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(W,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,Y.jsx)(kb,{id:`widget-type`,label:X(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(Cn,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Y.jsx)(Wn,{id:`widget-type`,children:(0,Y.jsx)(vt,{})}),(0,Y.jsx)(qa,{children:wb.map(e=>(0,Y.jsx)(Be,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsx)(kb,{id:`widget-object`,label:X(`engine.inspector.widget.object`,o),children:(0,Y.jsx)(W,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,Y.jsx)(kb,{id:`widget-value-field`,label:X(`engine.inspector.widget.valueField`,o),children:(0,Y.jsx)(W,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,Y.jsx)(kb,{id:`widget-category-field`,label:X(`engine.inspector.widget.categoryField`,o),children:(0,Y.jsx)(W,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,Y.jsx)(kb,{id:`widget-aggregate`,label:X(`engine.inspector.widget.aggregate`,o),children:(0,Y.jsxs)(Cn,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Y.jsx)(Wn,{id:`widget-aggregate`,children:(0,Y.jsx)(vt,{})}),(0,Y.jsx)(qa,{children:Tb.map(e=>(0,Y.jsx)(Be,{value:e,children:e},e))})]})}),(0,Y.jsx)(kb,{id:`widget-color`,label:X(`engine.inspector.widget.color`,o),children:(0,Y.jsxs)(Cn,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Y.jsx)(Wn,{id:`widget-color`,children:(0,Y.jsx)(vt,{})}),(0,Y.jsx)(qa,{children:Eb.map(e=>(0,Y.jsx)(Be,{value:e,children:e},e))})]})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(kb,{id:`widget-w`,label:X(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(W,{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,Y.jsx)(kb,{id:`widget-h`,label:X(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(W,{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,Y.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Y.jsx)(G,{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:X(`engine.inspector.widget.remove`,o)})})]})}function kb({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(di,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function Ab({message:e,onClose:t,locale:n}){return(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,Y.jsx)(`p`,{children:e}),(0,Y.jsx)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:X(`engine.inspector.widget.close`,n)})]})}var jb=[`start`,`end`,`action`,`decision`,`branch`,`gateway`,`subflow`,`wait`,`loop`,`parallel`,`invoke`];function Mb({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,Y.jsx)(i_,{kindLabel:X(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.flowNode.close`,i),children:(0,Y.jsx)(d_,{message:e.id})});let l=e=>{n({nodes:f_(o,s,{...c,...e})})},u=J.useMemo(()=>{let{id:e,type:t,label:n,...r}=c;return JSON.stringify(r,null,2)},[c]),[d,f]=J.useState(u),[p,m]=J.useState(null);return J.useEffect(()=>{f(u),m(null)},[u]),(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:X(`engine.inspector.flowNode.close`,i),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.flowNode.remove`,i),onClick:()=>{n({nodes:f_(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>l({id:e}),disabled:a,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>l({label:e}),disabled:a}),(0,Y.jsx)(c_,{label:X(`engine.inspector.flowNode.type`,i),value:c.type,options:jb.map(e=>({value:e,label:e})),onCommit:e=>l({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:X(`engine.inspector.flowNode.config`,i)}),(0,Y.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:f_(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,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:p})]})]})}var Nb=[{value:`unanimous`,label:`unanimous (all approve)`},{value:`first`,label:`first response wins`}],Pb=[{value:`back_to_previous`,label:`back to previous step`},{value:`reject_process`,label:`reject entire process`}];function Fb(e){return e==null?``:typeof e==`string`?e:e.source??``}function Ib({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,Y.jsx)(i_,{kindLabel:X(`engine.inspector.approvalStep.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.approvalStep.close`,a),children:(0,Y.jsx)(d_,{message:e.id})});let u=e=>{n({steps:f_(s,c,{...l,...e})})};return(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.approvalStep.kind`,a),title:l.label||l.name||`Step ${c+1}`,onClose:r,closeLabel:X(`engine.inspector.approvalStep.close`,a),headerActions:(0,Y.jsx)(a_,{index:c,total:s.length,onMove:e=>{n({steps:m_(s,c,e)});let t=l.name||`steps[${e}]`;i?.({kind:`step`,id:t,label:l.label||l.name||`Step ${e+1}`})},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.approvalStep.remove`,a),onClick:()=>{n({steps:f_(s,c,null)}),r()},disabled:o}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.approvalStep.name`,a),value:l.name??``,onCommit:e=>u({name:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.approvalStep.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Y.jsx)(o_,{label:X(`engine.inspector.approvalStep.description`,a),value:l.description??``,onCommit:e=>u({description:e}),disabled:o}),(0,Y.jsx)(c_,{label:X(`engine.inspector.approvalStep.behavior`,a),value:l.behavior,options:Nb,onCommit:e=>u({behavior:e}),disabled:o}),(0,Y.jsx)(o_,{label:X(`engine.inspector.approvalStep.entryCriteria`,a),value:Fb(l.entryCriteria),onCommit:e=>u({entryCriteria:e}),disabled:o,mono:!0}),(0,Y.jsx)(c_,{label:X(`engine.inspector.approvalStep.rejectionBehavior`,a),value:l.rejectionBehavior,options:Pb,onCommit:e=>u({rejectionBehavior:e}),disabled:o})]})}var Lb=[`field_update`,`email_alert`,`task_create`,`outbound_message`,`webhook`,`apex`,`flow_invoke`,`notification`];function Rb(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 zb({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Rb(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,Y.jsx)(i_,{kindLabel:X(`engine.inspector.workflowAction.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.workflowAction.close`,a),children:(0,Y.jsx)(d_,{message:e.id})});let d=e=>{let t={...u,...e};if(s.scope===`immediate`)n({actions:f_(c,s.i,t)});else{let e=l[s.i],r=f_(e.actions??[],s.j,t);n({timeTriggers:f_(l,s.i,{...e,actions:r})})}},f=()=>{if(s.scope===`immediate`)n({actions:f_(c,s.i,null)});else{let e=l[s.i],t=f_(e.actions??[],s.j,null);n({timeTriggers:f_(l,s.i,{...e,actions:t})})}r()},p=J.useMemo(()=>{let{type:e,name:t,...n}=u;return JSON.stringify(n,null,2)},[u]),[m,h]=J.useState(p),[g,_]=J.useState(null);J.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,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.workflowAction.kind`,a),title:u.name||u.type||e.id,onClose:r,closeLabel:X(`engine.inspector.workflowAction.close`,a),headerActions:(0,Y.jsx)(a_,{index:y,total:b,onMove:e=>{if(s.scope===`immediate`)n({actions:m_(c,s.i,e)}),i?.({kind:`action`,id:`actions[${e}]`,label:u.name||u.type});else{let t=l[s.i],r=m_(t.actions??[],s.j,e);n({timeTriggers:f_(l,s.i,{...t,actions:r})}),i?.({kind:`action`,id:`timeTriggers[${s.i}].actions[${e}]`,label:u.name||u.type})}},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.workflowAction.remove`,a),onClick:f,disabled:o}),children:[(0,Y.jsx)(c_,{label:X(`engine.inspector.workflowAction.type`,a),value:u.type,options:Lb.map(e=>({value:e,label:e})),onCommit:e=>d({type:e}),disabled:o}),(0,Y.jsx)(o_,{label:X(`engine.inspector.workflowAction.name`,a),value:u.name??``,onCommit:e=>d({name:e}),disabled:o}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:X(`engine.inspector.workflowAction.config`,a)}),(0,Y.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,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:g})]})]})}var Bb=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function Vb(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 Hb(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 Ub(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:f_(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=f_(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function Wb(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 Gb({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Vb(e.id),{node:c,parent:l,index:u}=s?Hb(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Y.jsx)(i_,{kindLabel:X(`engine.inspector.appNav.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.appNav.close`,a),children:(0,Y.jsx)(d_,{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(Ub(t,s,{...c,...e}))};return(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:X(`engine.inspector.appNav.close`,a),headerActions:(0,Y.jsx)(a_,{index:u,total:l.length,onMove:e=>{n(Wb(t,s,m_(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:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.appNav.remove`,a),onClick:()=>{n(Ub(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.appNav.label`,a),value:String(c.label??c.title??c.name??``),onCommit:e=>p({label:e}),disabled:o}),(0,Y.jsx)(o_,{label:X(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Y.jsx)(c_,{label:X(`engine.inspector.appNav.kindField`,a),value:c.kind,options:Bb.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var Kb=[{value:`left`,label:`left`},{value:`center`,label:`center`},{value:`right`,label:`right`}];function qb(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function Jb(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function Yb(e){return e.field??e.accessorKey??``}function Xb(e){return e.label??e.header??Yb(e)}function Zb({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=qb(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(Jb),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1;if(!s||!d)return(0,Y.jsx)(i_,{kindLabel:X(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.viewColumn.close`,a),children:(0,Y.jsx)(d_,{message:e.id})});let p=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=Yb(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(f_(u,s.index,{...d,...r}))},h=()=>{p(f_(u,s.index,null)),r()},g=e=>{p(m_(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:Xb(d)||`columns[${e}]`})},_=typeof d.width==`number`?d.width:typeof d.width==`string`&&Number(d.width.replace(/[^\d.]/g,``))||void 0;return(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.viewColumn.kind`,a),title:Xb(d)||e.id,onClose:r,closeLabel:X(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(a_,{index:s.index,total:u.length,onMove:g,upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.viewColumn.remove`,a),onClick:h,disabled:o}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:Yb(d),onCommit:e=>m({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.viewColumn.header`,a),value:Xb(d)===Yb(d)?``:Xb(d),onCommit:e=>m({label:e}),disabled:o}),!f&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s_,{label:X(`engine.inspector.viewColumn.width`,a),value:_,onCommit:e=>m({width:e}),disabled:o}),(0,Y.jsx)(c_,{label:X(`engine.inspector.viewColumn.align`,a),value:d.align,options:Kb,onCommit:e=>m({align:e}),disabled:o}),(0,Y.jsx)(l_,{label:X(`engine.inspector.viewColumn.sortable`,a),value:d.sortable!==!1,onCommit:e=>m({sortable:e}),disabled:o}),(0,Y.jsx)(l_,{label:X(`engine.inspector.viewColumn.filterable`,a),value:d.filterable!==!1,onCommit:e=>m({filterable:e}),disabled:o})]})]})}function Qb(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 $b(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 ex(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:f_(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 tx(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 nx(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 rx({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Qb(e.id),c=s?$b(t,s):null,l=s?tx(t,s):null;if(!s||!c)return(0,Y.jsx)(i_,{kindLabel:X(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.pageBlock.close`,a),children:(0,Y.jsx)(d_,{message:e.id})});let u=e=>n(ex(t,s,{...c,...e}));return(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.pageBlock.kind`,a),title:String(c.id||c.type||e.id),onClose:r,closeLabel:X(`engine.inspector.pageBlock.close`,a),headerActions:l?(0,Y.jsx)(a_,{index:l.index,total:l.siblings.length,onMove:e=>{if(!l)return;n(nx(t,s,m_(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:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.pageBlock.remove`,a),onClick:()=>{n(ex(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.pageBlock.type`,a),value:c.type??``,onCommit:e=>u({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.pageBlock.id`,a),value:c.id??``,onCommit:e=>u({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.pageBlock.className`,a),value:c.className??``,onCommit:e=>u({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.pageBlock.hidden`,a),value:c.hidden??``,onCommit:e=>u({hidden:e}),disabled:o,mono:!0})]})}var ix=`__none__`,ax=[{value:ix,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function ox(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function sx({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=ox(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,Y.jsx)(i_,{kindLabel:X(`engine.inspector.reportColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.reportColumn.close`,a),children:(0,Y.jsx)(d_,{message:e.id})});let u=e=>n({columns:f_(c,s,{...l,...e})});return(0,Y.jsxs)(i_,{kindLabel:X(`engine.inspector.reportColumn.kind`,a),title:l.label||l.field||e.id,onClose:r,closeLabel:X(`engine.inspector.reportColumn.close`,a),headerActions:(0,Y.jsx)(a_,{index:s,total:c.length,onMove:e=>{n({columns:m_(c,s,e)}),i?.({kind:`column`,id:`columns[${e}]`,label:l.label||l.field||`columns[${e}]`})},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(u_,{label:X(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:f_(c,s,null)}),r()},disabled:o}),children:[(0,Y.jsx)(o_,{label:X(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(o_,{label:X(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Y.jsx)(c_,{label:X(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??ix,options:ax,onCommit:e=>u({aggregate:e===ix?void 0:e}),disabled:o})]})}function cx(e){let t=e.options;return Array.isArray(t)?t.map(e=>({value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0})):[]}function lx(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function ux(e){return e===`lookup`||e===`master_detail`||e===`tree`}function dx(e){return e===`formula`||e===`summary`}function fx(e){return e===`number`||e===`currency`||e===`percent`}function px(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}var mx=cv.flatMap(e=>e.types.map(t=>({value:t,label:`${ov[e.category]} · ${iv[t].label}`})));function hx({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a}){let o=J.useMemo(()=>Z_(t.fields),[t]),s=String(e.id),c=$_(o,s),l=c>=0?o.entries[c]:null,u=Array.isArray(t.fieldGroups)?t.fieldGroups:[],d=bx();if(!l)return(0,Y.jsx)(i_,{kindLabel:`Field`,title:s||`Field`,onClose:r,children:(0,Y.jsx)(d_,{message:`This field no longer exists in the draft.`})});let f=l.def,p=typeof f.type==`string`?f.type:`text`,m=iv[p],h=e=>{n({fields:Q_(e)})},g=e=>{let t=[...o.entries];t[c]={...l,def:{...f,...e}},h({shape:o.shape,entries:t})},_=e=>{let t=nv(e);if(!t||t===l.name||o.entries.some((e,n)=>n!==c&&e.name===t))return;let n=[...o.entries];n[c]={...l,name:t},h({shape:o.shape,entries:n}),i?.({kind:`field`,id:t,label:String(f.label??t)})},v=()=>{let e=o.entries.filter((e,t)=>t!==c);h({shape:o.shape,entries:e}),r()},y=e=>{h({shape:o.shape,entries:m_(o.entries,c,e)})},b=cx(f),x=e=>{g({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},S=(0,Y.jsx)(a_,{index:c,total:o.entries.length,onMove:y,disabled:a}),C=(0,Y.jsx)(u_,{label:`Remove “${typeof f.label==`string`?f.label:l.name}”`,onClick:v,disabled:a});return(0,Y.jsxs)(i_,{kindLabel:`Field`,title:typeof f.label==`string`&&f.label?f.label:l.name,onClose:r,headerActions:S,footer:C,children:[(0,Y.jsxs)(gx,{title:`Basic`,children:[(0,Y.jsx)(o_,{label:`API name`,value:l.name,onCommit:_,disabled:a,mono:!0}),(0,Y.jsx)(o_,{label:`Label`,value:typeof f.label==`string`?f.label:``,onCommit:e=>g({label:e}),disabled:a}),(0,Y.jsx)(c_,{label:`Type`,value:p,options:mx,onCommit:e=>g({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(l_,{label:`Required`,value:!!f.required,onCommit:e=>g({required:e||void 0}),disabled:a}),(0,Y.jsx)(l_,{label:`Unique`,value:!!f.unique,onCommit:e=>g({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(_x,{label:`Description`,value:typeof f.description==`string`?f.description:``,onCommit:e=>g({description:e||void 0}),disabled:a,rows:2})]}),(lx(p)||ux(p)||dx(p)||fx(p)||px(p))&&(0,Y.jsxs)(gx,{title:`${m?.label??p} options`,children:[lx(p)&&(0,Y.jsx)(yx,{options:b,onChange:x,disabled:a}),ux(p)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(vx,{label:`Related object`,value:typeof f.reference==`string`?f.reference:``,options:d,onCommit:e=>g({reference:e||void 0}),disabled:a}),(0,Y.jsx)(o_,{label:`Relationship name`,value:typeof f.relationshipName==`string`?f.relationshipName:``,onCommit:e=>g({relationshipName:e||void 0}),disabled:a,placeholder:`Inverse collection key on the parent`})]}),dx(p)&&(0,Y.jsx)(_x,{label:`Formula (CEL)`,value:typeof f.formula==`string`?f.formula:``,onCommit:e=>g({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),fx(p)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(s_,{label:`Precision`,value:typeof f.precision==`number`?f.precision:void 0,onCommit:e=>g({precision:e}),disabled:a}),(0,Y.jsx)(s_,{label:`Scale`,value:typeof f.scale==`number`?f.scale:void 0,onCommit:e=>g({scale:e}),disabled:a}),(0,Y.jsx)(s_,{label:`Min`,value:typeof f.min==`number`?f.min:void 0,onCommit:e=>g({min:e}),disabled:a}),(0,Y.jsx)(s_,{label:`Max`,value:typeof f.max==`number`?f.max:void 0,onCommit:e=>g({max:e}),disabled:a})]}),px(p)&&(0,Y.jsx)(s_,{label:`Max length`,value:typeof f.maxLength==`number`?f.maxLength:void 0,onCommit:e=>g({maxLength:e}),disabled:a,placeholder:`255`})]}),(0,Y.jsxs)(gx,{title:`Advanced`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(l_,{label:`Read-only`,value:!!f.readonly,onCommit:e=>g({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(l_,{label:`Hidden`,value:!!f.hidden,onCommit:e=>g({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(l_,{label:`Indexed`,value:!!f.indexed,onCommit:e=>g({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(l_,{label:`External ID`,value:!!f.externalId,onCommit:e=>g({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(l_,{label:`Track history`,value:!!f.trackHistory,onCommit:e=>g({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(o_,{label:`Placeholder`,value:typeof f.placeholder==`string`?f.placeholder:``,onCommit:e=>g({placeholder:e||void 0}),disabled:a}),u.length>0&&(0,Y.jsx)(c_,{label:`Group`,value:typeof f.group==`string`?f.group:``,options:[{value:``,label:`— No group —`},...u.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>g({group:e||void 0}),disabled:a})]})]})}function gx({title:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:t})]})}function _x({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:t,disabled:r,rows:i,placeholder:o,onChange:e=>n(e.target.value),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary `+(a?`font-mono text-xs `:``)})]})}function vx({label:e,value:t,options:n,onCommit:r,disabled:i}){let a=J.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{list:a,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:`object_name`}),(0,Y.jsx)(`datalist`,{id:a,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function yx({options:e,onChange:t,disabled:n}){let r=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},i=n=>t(e.filter((e,t)=>t!==n)),a=(n,r)=>t(m_(e,n,r));return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(di,{className:`text-xs text-muted-foreground`,children:`Picklist values`}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px]`,children:e.length})]}),e.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:`No values yet.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:e.map((t,o)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(W,{value:t.value,onChange:e=>r(o,{value:e.target.value}),placeholder:`value`,disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,Y.jsx)(W,{value:t.label??``,onChange:e=>r(o,{label:e.target.value}),placeholder:`Label`,disabled:n,className:`h-7 text-xs flex-1`}),(0,Y.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>r(o,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:`Color`}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o-1),disabled:n||o===0,"aria-label":`Move up`,children:(0,Y.jsx)(Va,{className:`h-3 w-3`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o+1),disabled:n||o===e.length-1,"aria-label":`Move down`,children:(0,Y.jsx)(Nn,{className:`h-3 w-3`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>i(o),disabled:n,"aria-label":`Remove`,children:(0,Y.jsx)(Fa,{className:`h-3 w-3`})})]},o))}),!n&&(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),`Add value`]})]})}function bx(){let e=Bp(),[t,n]=J.useState([]);return J.useEffect(()=>{let t=!1;return e.list(`object`).then(e=>{t||n(e.filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{t=!0}},[e]),t}function xx(){Jh(`dashboard`,Ob),Jh(`flow`,Mb),Jh(`approval`,Ib),Jh(`workflow`,zb),Jh(`app`,Gb),Jh(`view`,Zb),Jh(`page`,rx),Jh(`report`,sx),Jh(`object`,hx)}var Sx=t({MetadataDiagnosticsPage:()=>kg,MetadataDirectoryPage:()=>om,MetadataResourceEditPage:()=>Cg,MetadataResourceHistoryPage:()=>Lh,MetadataResourceListPage:()=>Am,StudioHomePage:()=>_m});Pg(),Rg(),Cb(),xx(),Rp({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:om}),Rp({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Dg}),Tm({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`}]}),Tm({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`}]}),Tm({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:jg,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`}]}),Tm({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`}]}),Tm({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`}]}),Tm({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 Cx=(0,J.lazy)(()=>c(()=>import(`./SystemHubPage-DRRxgNWV.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),wx=(0,J.lazy)(()=>c(()=>import(`./AppManagementPage-BnwBNW_m.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Tx=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-DPGkAZWG.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),Ex=(0,J.lazy)(()=>c(()=>import(`./ApprovalsInboxPage-CQQmK4Pz.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Dx=(0,J.lazy)(()=>c(()=>import(`./AiPendingActionsPage-DYX4ANzZ.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Ox=(0,J.lazy)(()=>c(()=>import(`./AuditLogPage-C1CgKWC8.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),kx=(0,J.lazy)(()=>c(()=>import(`./SettingsHub-4RDkAyKq.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Ax=(0,J.lazy)(()=>c(()=>import(`./SettingsView-_5h2mExc.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),jx=(0,J.lazy)(()=>c(()=>import(`./DeveloperHubPage-CcV4mWRr.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),Mx=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-C70S6MYv.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Nx=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-Rtd6u1e_.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Px=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BNIOSFr1.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Fx(){let{objectName:e}=f(),t=o().pathname.replace(/\/objects(\/.*)?$/,``);return(0,Y.jsx)(_,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function Ix(){let{metadataType:e,itemName:t}=f(),n=o().pathname.replace(/\/metadata(\/.*)?$/,``),r=`${n}/component/metadata/resource`;return(0,Y.jsx)(_,{to:e?t?`${r}/${t}?type=${e}`:`${r}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var Lx=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{path:`system`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Cx,{})})}),(0,Y.jsx)(d,{path:`system/apps`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(wx,{})})}),(0,Y.jsx)(d,{path:`system/profile`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Tx,{})})}),(0,Y.jsx)(d,{path:`system/approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Ex,{})})}),(0,Y.jsx)(d,{path:`system/ai-approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Dx,{})})}),(0,Y.jsx)(d,{path:`system/audit-log`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Ox,{})})}),(0,Y.jsx)(d,{path:`system/settings`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(kx,{})})}),(0,Y.jsx)(d,{path:`system/settings/:namespace`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Ax,{})})}),(0,Y.jsx)(d,{path:`developer`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(jx,{})})}),(0,Y.jsx)(d,{path:`developer/api-console`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Mx,{})})}),(0,Y.jsx)(d,{path:`developer/flow-runs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Nx,{})})}),(0,Y.jsx)(d,{path:`developer/public-forms`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(Px,{})})}),(0,Y.jsx)(d,{path:`system/objects`,element:(0,Y.jsx)(Fx,{})}),(0,Y.jsx)(d,{path:`system/objects/:objectName`,element:(0,Y.jsx)(Fx,{})}),(0,Y.jsx)(d,{path:`system/metadata`,element:(0,Y.jsx)(Ix,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType`,element:(0,Y.jsx)(Ix,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType/:itemName`,element:(0,Y.jsx)(Ix,{})})]});function Rx(){let e=(0,J.useMemo)(()=>Qr({baseUrl:``}),[``]);return(0,Y.jsx)(A,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Y.jsx)(nl,{}),children:(0,Y.jsx)(ii,{adapter:e,children:(0,Y.jsx)(af,{extraRoutes:Lx,extraRoutesNoApp:Lx})})})}var zx=[`cloud_control`];function Bx(){let{apps:e,loading:t}=ce();if(t)return(0,Y.jsx)(Es,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of zx)if(n.has(e))return(0,Y.jsx)(_,{to:`/apps/${e}`,replace:!0});return(0,Y.jsx)(_,{to:`/home`,replace:!0})}var Vx=`/api/v1`;function Hx(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Ux(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 Wx(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Hx(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:Ux(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Gx(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 Kx(e,t){return fetch(`${Vx}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function qx(e){let t=await Kx(`/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 Jx(e){let t=await Kx(`/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 Kx(`/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 Yx(e,t){let n=await Kx(`/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 Xx(e,t){let n=await Kx(`/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 Zx=`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 Qx({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:Zx},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,Y.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,Y.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,Y.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,Y.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,Y.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,Y.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,Y.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,Y.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,Y.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,Y.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,Y.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,Y.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,Y.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function $x({mode:e}){let t=f(),[n]=l(),r=(e===`public`?t.slug:t.name)??``,[i,a]=(0,J.useState)(!0),[o,s]=(0,J.useState)(null),[c,u]=(0,J.useState)(null),[d,p]=(0,J.useState)({}),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let t=!1;return a(!0),s(null),(e===`public`?qx(r):Jx(r)).then(e=>{t||(u(e),p(Gx(Wx(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||s(e?.message??String(e))}).finally(()=>{t||a(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,J.useMemo)(()=>c?Wx(c.form,c.objectSchema):[],[c]),y=c?.form?.submitBehavior??{kind:`thank-you`};return i?(0,Y.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):o&&!c?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Y.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:o})}):c?g&&y.kind===`thank-you`?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,Y.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,Y.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,Y.jsxs)(`header`,{className:`mb-6`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:c.label}),c.form?.label&&c.form.label!==c.label&&(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:c.form.label})]}),(0,Y.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),c){h(!0),s(null);try{switch(e===`public`?await Yx(r,d):await Xx(c.object,d),q.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:p(Gx(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);s(t),q.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,Y.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,Y.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,Y.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,Y.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,Y.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,Y.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,Y.jsx)(Qx,{field:e,value:d[e.name],onChange:t=>p(n=>({...n,[e.name]:t}))}),e.helpText&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),o&&(0,Y.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:o}),(0,Y.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,Y.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 eS({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,J.useRef)(null);return(0,J.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{q.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}function tS(){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 nS(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(`
|
|
32
|
+
|
|
33
|
+
`):``}function rS(){let{token:e}=f(),t=`${(0,J.useMemo)(()=>tS(),[])}/api/v1`,[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(!0),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),[p,m]=(0,J.useState)(null),h=(0,J.useCallback)(async n=>{if(e){s(!0),a(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let o=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(o.status===401){l(!0),a(n?`Wrong password.`:null),s(!1);return}if(o.status===404){a(`This link is invalid or no longer available.`),s(!1);return}if(o.status===410){a(`This link has expired or was revoked.`),s(!1);return}if(!o.ok){a((await o.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${o.status}).`),s(!1);return}let c=await o.json();r(`data`in c?c.data:{record:c.record,link:c.link,redactedFields:c.redactFields}),l(!1)}catch(e){a(e?.message??`Failed to load shared content.`)}finally{s(!1)}}},[t,e]);if((0,J.useEffect)(()=>{h()},[h]),(0,J.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]),o)return(0,Y.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(c)return(0,Y.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,Y.jsx)(Xe,{className:`h-8 w-8 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,Y.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(u)},children:[(0,Y.jsx)(di,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Y.jsx)(W,{id:`share-pw`,type:`password`,value:u,onChange:e=>d(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Y.jsx)(G,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,Y.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,Y.jsx)(fn,{className:`h-8 w-8 text-amber-500`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,Y.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,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Y.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,Y.jsx)(Fr,{className:`h-5 w-5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,Y.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,Y.jsx)(U,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,Y.jsx)(K,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,Y.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,Y.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=nS(e);if(!t)return null;let n=e.role===`user`;return(0,Y.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,Y.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,Y.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,Y.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,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Y.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,Y.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,Y.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,Y.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}function iS(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function aS(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function oS(){return typeof window>`u`?null:window.location.host||null}function sS(){let e=Rc();return(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,Y.jsx)(`span`,{className:`inline-flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 text-white shadow-sm shadow-indigo-500/30`,children:(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,Y.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,Y.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,Y.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,Y.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function cS({children:e,formWidth:t=`sm`}){let{t:n}=F(),r=t===`md`?`max-w-md`:`max-w-sm`,i=oS(),a=!!i&&!iS(i)&&!aS(i);return(0,J.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,Y.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,Y.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 opacity-[0.35] dark:opacity-[0.25] [mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)] [-webkit-mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)]`,style:{backgroundImage:`radial-gradient(hsl(var(--border)) 1px, transparent 1px)`,backgroundSize:`22px 22px`}}),(0,Y.jsx)(`div`,{className:`absolute left-1/2 top-1/2 h-[34rem] w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-br from-indigo-500/10 to-indigo-600/10 blur-3xl dark:from-indigo-500/10 dark:to-indigo-600/10`})]}),(0,Y.jsxs)(`div`,{className:B(`flex w-full flex-col gap-5`,r),children:[(0,Y.jsx)(sS,{}),a?(0,Y.jsx)(`div`,{className:`flex justify-center`,children:(0,Y.jsx)(`span`,{className:`rounded-full border border-border/60 bg-background/60 px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide text-muted-foreground`,title:n(`auth.shell.tenantHostHint`,{defaultValue:`You are signing in to this workspace`}),children:i})}):null,e]})]})}function lS(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function uS(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function dS(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function fS(){let{t:e}=F(),[t]=l(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:s,switchOrganization:c,getAuthConfig:u}=w(),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(!1);(0,J.useLayoutEffect)(()=>{i||g(!0)},[i]);let _=(0,J.useMemo)(()=>{if(typeof window>`u`)return null;let e=new URLSearchParams(window.location.search),t=e.get(`redirect_uri`);if(!e.has(`client_id`)||!t)return null;try{return new URL(t).host}catch{return null}},[]);if((0,J.useEffect)(()=>{let e=!1;return u().then(t=>{e||f(t?.emailPassword?.disableSignUp===!0)}).catch(()=>{}),()=>{e=!0}},[u]),(0,J.useEffect)(()=>{if(r){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!s){if(o||p)return;if(a.length===1){m(!0),c(a[0].id).catch(()=>void 0).finally(()=>m(!1));return}if(a.length===0){window.location.assign(uS(lS(n)?n:`/`));return}window.location.assign(uS(`/organizations`));return}p||window.location.assign(uS(lS(n)?n:`/`))}},[r,s,a,o,p,n,c]),i&&!h||r)return(0,Y.jsx)(cS,{children:(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,Y.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let v=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,Y.jsx)(cS,{formWidth:`md`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[_?(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-3 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-foreground`,children:[(0,Y.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,Y.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:_,defaultValue:`Continue to ${_}`})})]}):null,(0,Y.jsx)(At,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(pS,{registerUrl:d?void 0:v,redirect:n})})]})})}function pS({registerUrl:e,redirect:t}){let{t:n}=F(),r=s(),i=(0,J.useRef)(``);return(0,J.useEffect)(()=>{let e=e=>{let t=e.target;t?.id===`login-email`&&(i.current=t.value)};return document.addEventListener(`input`,e,!0),()=>document.removeEventListener(`input`,e,!0)},[]),(0,Y.jsx)(E,{onError:e=>{let n=e.message||``,a=e.code,o=n.toLowerCase();if(a===`EMAIL_NOT_VERIFIED`||o.includes(`email`)&&(o.includes(`verif`)||o.includes(`not verified`))){let e=new URLSearchParams;i.current&&e.set(`email`,i.current),t&&e.set(`redirect`,t),r(`/verify-email-prompt?${e.toString()}`)}},title:n(`auth.login.title`,{defaultValue:`Sign in to your account`}),description:n(`auth.login.description`,{defaultValue:`Enter your email and password to continue`}),registerUrl:e,forgotPasswordUrl:`/forgot-password`,linkComponent:dS,errorMessages:{INVALID_EMAIL_OR_PASSWORD:n(`auth.login.errors.invalidCredentials`,{defaultValue:`Invalid email or password`}),EMAIL_NOT_VERIFIED:n(`auth.login.errors.emailNotVerified`,{defaultValue:`Please verify your email address before signing in.`})},labels:{emailLabel:n(`auth.login.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:n(`auth.login.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:n(`auth.login.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:n(`auth.login.passwordPlaceholder`,{defaultValue:`Enter your password`}),forgotPasswordText:n(`auth.login.forgotPasswordText`,{defaultValue:`Forgot password?`}),submitButton:n(`auth.login.submitButton`,{defaultValue:`Sign In`}),submittingButton:n(`auth.login.submittingButton`,{defaultValue:`Signing in…`}),noAccountText:n(`auth.login.noAccountText`,{defaultValue:`Don't have an account?`}),signUpText:n(`auth.login.signUpText`,{defaultValue:`Sign up`})}})}function mS(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function hS(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function gS(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function _S(){let{t:e}=F(),t=s(),[n]=l(),r=n.get(`redirect`),{user:i,isLoading:a,organizations:o,isOrganizationsLoading:c,activeOrganization:u,switchOrganization:d,getAuthConfig:f}=w(),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(!1);if((0,J.useLayoutEffect)(()=>{a||v(!0)},[a]),(0,J.useEffect)(()=>{let e=!1;return f().then(n=>{if(e)return;let i=n?.emailPassword?.disableSignUp===!0;m(i),i&&t(`/login${r?`?redirect=${encodeURIComponent(r)}`:``}`,{replace:!0})}).catch(()=>{e||m(!1)}),()=>{e=!0}},[f,t,r]),(0,J.useEffect)(()=>{if(i){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!u){if(c||h)return;if(o.length===1){g(!0),d(o[0].id).catch(()=>void 0).finally(()=>g(!1));return}if(o.length===0){window.location.assign(hS(mS(r)?r:`/`));return}window.location.assign(hS(`/organizations`));return}h||window.location.assign(hS(mS(r)?r:`/`))}},[i,u,o,c,h,r,d]),p===null||a&&!_||i)return(0,Y.jsx)(cS,{children:(0,Y.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,Y.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`})})});let y=r?`/login?redirect=${encodeURIComponent(r)}`:`/login`;return(0,Y.jsx)(cS,{formWidth:`md`,children:(0,Y.jsx)(At,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(S,{title:e(`auth.register.title`,{defaultValue:`Create your account`}),description:e(`auth.register.description`,{defaultValue:`Sign up to get started`}),loginUrl:y,linkComponent:gS,errorMessages:{USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`}),USER_ALREADY_EXISTS:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`})},onVerificationRequired:e=>{let n=new URLSearchParams;n.set(`email`,e),r&&n.set(`redirect`,r),t(`/verify-email-prompt?${n.toString()}`,{replace:!0})},labels:{nameLabel:e(`auth.register.nameLabel`,{defaultValue:`Name`}),namePlaceholder:e(`auth.register.namePlaceholder`,{defaultValue:`John Doe`}),emailLabel:e(`auth.register.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.register.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:e(`auth.register.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:e(`auth.register.passwordPlaceholder`,{defaultValue:`Create a password (min. 8 characters)`}),confirmPasswordLabel:e(`auth.register.confirmPasswordLabel`,{defaultValue:`Confirm password`}),confirmPasswordPlaceholder:e(`auth.register.confirmPasswordPlaceholder`,{defaultValue:`Confirm your password`}),passwordMismatchError:e(`auth.register.passwordMismatchError`,{defaultValue:`Passwords do not match`}),passwordTooShortError:e(`auth.register.passwordTooShortError`,{defaultValue:`Password must be at least 8 characters`}),submitButton:e(`auth.register.submitButton`,{defaultValue:`Create account`}),submittingButton:e(`auth.register.submittingButton`,{defaultValue:`Creating account…`}),hasAccountText:e(`auth.register.hasAccountText`,{defaultValue:`Already have an account?`}),signInText:e(`auth.register.signInText`,{defaultValue:`Sign in`})}})})})}function vS(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function yS(){let{t:e}=F();return(0,Y.jsx)(cS,{formWidth:`md`,children:(0,Y.jsx)(At,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(j,{loginUrl:`/login`,linkComponent:vS,title:e(`auth.forgotPassword.title`,{defaultValue:`Reset your password`}),description:e(`auth.forgotPassword.description`,{defaultValue:`Enter your email and we'll send you a reset link.`}),labels:{emailLabel:e(`auth.forgotPassword.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`,{defaultValue:`name@example.com`}),submitButton:e(`auth.forgotPassword.submitButton`,{defaultValue:`Send reset link`}),submittingButton:e(`auth.forgotPassword.submittingButton`,{defaultValue:`Sending…`}),successTitle:e(`auth.forgotPassword.successTitle`,{defaultValue:`Check your email`}),successDescription:e(`auth.forgotPassword.successDescription`,{defaultValue:`If an account exists, a reset link has been sent.`}),backToSignInText:e(`auth.forgotPassword.backToSignInText`,{defaultValue:`Back to sign in`}),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`,{defaultValue:`Remember your password?`}),signInText:e(`auth.forgotPassword.signInText`,{defaultValue:`Sign in`})}})})})}function bS(){let{t:e}=F(),t=s(),[n]=l(),r=n.get(`token`),{resetPassword:a}=w(),[o,c]=(0,J.useState)(``),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(!1);return(0,Y.jsx)(cS,{children:(0,Y.jsxs)(At,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Y.jsx)(Et,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Y.jsx)(Xi,{children:r?(0,Y.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o!==u){q.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!r){q.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}p(!0);try{await a(r,o),q.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){q.error(e(`auth.resetPassword.failed`,{defaultValue:`Reset failed`}),{description:t.message})}finally{p(!1)}},className:`flex flex-col gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(W,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:o,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(W,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsx)(G,{type:`submit`,className:`w-full`,disabled:f,children:f?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,Y.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.resetPassword.invalidToken`,{defaultValue:`This reset link is invalid or has expired.`}),` `,(0,Y.jsx)(i,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}var xS=`/api/v1/auth`;function SS(){let{t:e}=F(),[t]=l(),n=t.get(`token`),[r,a]=(0,J.useState)(`loading`),[o,s]=(0,J.useState)(``);return(0,J.useEffect)(()=>{if(!n){a(`error`),s(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${xS}/verify-email`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({token:n})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t?.message||`Verification failed: ${e.status}`)}t||a(`success`)}catch(n){t||(a(`error`),s(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[n,e]),(0,Y.jsx)(cS,{children:(0,Y.jsxs)(At,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[r===`loading`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Y.jsx)(Et,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Y.jsx)(Xi,{className:`flex justify-center py-6`,children:(0,Y.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),r===`success`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500 ring-1 ring-emerald-500/30`,children:(0,Y.jsx)(Ga,{className:`size-6`})}),(0,Y.jsx)(Zn,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Y.jsx)(Et,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Y.jsx)(Xi,{className:`text-center`,children:(0,Y.jsx)(i,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.signInLink`,{defaultValue:`Go to sign in`})})})]}),r===`error`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-1 ring-destructive/30`,children:(0,Y.jsx)(Wt,{className:`size-6`})}),(0,Y.jsx)(Zn,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Y.jsx)(Et,{children:o||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Y.jsx)(Xi,{className:`text-center`,children:(0,Y.jsx)(i,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.backToSignIn`,{defaultValue:`Back to sign in`})})})]})]})})}function CS(){let{t:e}=F(),t=s(),[n]=l(),r=n.get(`email`)??``,i=n.get(`redirect`)??``,{sendVerificationEmail:a}=w(),[o,c]=(0,J.useState)(!1),[u,d]=(0,J.useState)(!1);return(0,Y.jsx)(cS,{children:(0,Y.jsxs)(At,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,Y.jsx)(xa,{className:`size-8 text-primary`})}),(0,Y.jsx)(Zn,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Y.jsx)(Et,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,Y.jsx)(Xi,{children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r?(0,Y.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:r})]}):null,(0,Y.jsx)(G,{onClick:async()=>{if(!r){q.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:e(`auth.verifyEmail.emailMissing`,{defaultValue:`Email address is missing`})});return}c(!0);try{await a(r,i||`/`),d(!0),q.success(e(`auth.verifyEmail.resentSuccess`,{defaultValue:`Verification email sent!`}),{description:e(`auth.verifyEmail.resentDescription`,{defaultValue:`Please check your inbox and click the verification link.`})})}catch(t){q.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Failed to resend verification email`}),{description:t.message})}finally{c(!1)}},disabled:o||u,className:`w-full`,variant:u?`outline`:`default`,children:o?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(tn,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):u?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(tn,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,Y.jsx)(`span`,{className:`w-full border-t`})}),(0,Y.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,Y.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,Y.jsx)(G,{onClick:()=>{t(`/login${i?`?redirect=${encodeURIComponent(i)}`:``}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,Y.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.verifyEmail.checkSpam`,{defaultValue:`Didn't receive the email? Check your spam folder or contact support.`})})]})})]})})}var wS=`/api/v1/auth`;function TS(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function ES(){let{t:e}=F(),t=s(),{user:n,signUp:r,organizations:i,refreshOrganizations:a,updateOrganization:o,createOrganization:c,switchOrganization:l}=w(),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(null);return(0,J.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${wS}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||x(n.hasOwner===!0)}catch{e||x(!1)}})(),()=>{e=!0}},[]),(0,J.useEffect)(()=>{b===!0&&!n&&t(`/login`,{replace:!0})},[b,n,t]),(0,J.useEffect)(()=>{n&&window.location.assign(`/`)},[n]),b===null?(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,Y.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,Y.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,Y.jsxs)(At,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Y.jsx)(Et,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Y.jsx)(Xi,{children:(0,Y.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),y(!0);try{await r(u,f,m);let e=g.trim();if(e)try{await a();let t=i[0],n;t?.id?(await o(t.id,{name:e,slug:TS(e)}),n=t.id):n=(await c({name:e,slug:TS(e)}))?.id,n&&await l(n).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(`/`)}catch(t){q.error(e(`auth.setup.failed`,{defaultValue:`Setup failed`}),{description:t.message})}finally{y(!1)}},className:`flex flex-col gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Y.jsx)(W,{id:`name`,autoComplete:`name`,required:!0,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Y.jsx)(W,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(W,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:f,onChange:e=>p(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(di,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Y.jsx)(W,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:m,onChange:e=>h(e.target.value)})]}),(0,Y.jsx)(G,{type:`submit`,className:`mt-2 w-full`,disabled:v,children:v?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}var DS=`/api/v1/auth`;function OS(){let{t:e}=F(),t=s(),{user:n,isLoading:r}=w(),[i,a]=(0,J.useState)(!1),[o,c]=(0,J.useState)(null),l=typeof window<`u`?window.location.search:``,u=l.startsWith(`?`)?l.slice(1):l,d=new URLSearchParams(u),f=d.get(`client_id`)??void 0,p=d.get(`scope`)??``;(0,J.useEffect)(()=>{if(!r&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,r,t]),(0,J.useEffect)(()=>{if(!f)return;let e=!1;return fetch(`${DS}/oauth2/applications/${encodeURIComponent(f)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));e||c(n?.data??n)}).catch(()=>{}),()=>{e=!0}},[f]);let m=p.split(/\s+/).filter(Boolean),h=async t=>{a(!0);try{let n=await fetch(`${DS}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:u})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r?.message||`Consent failed: ${n.status}`);let i=r.redirect_uri??r.redirectURI??r.url;if(i){window.location.href=i;return}q(t?e(`oauth.consent.granted`,{defaultValue:`Access granted`}):e(`oauth.consent.denied`,{defaultValue:`Access denied`}),{description:e(`oauth.consent.noRedirect`,{defaultValue:`No redirect URL returned by the server.`})})}catch(t){q.error(e(`oauth.consent.failed`,{defaultValue:`Consent failed`}),{description:t.message})}finally{a(!1)}},g=o?.name??o?.client_name??f??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,Y.jsxs)(At,{className:`w-full max-w-md`,children:[(0,Y.jsxs)(nr,{className:`items-center text-center`,children:[(0,Y.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:o?.icon||o?.logo_uri?(0,Y.jsx)(`img`,{src:o.icon||o.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,Y.jsx)(rt,{className:`h-7 w-7 text-muted-foreground`})}),(0,Y.jsx)(Zn,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,Y.jsx)(Et,{children:e(`oauth.consent.request`,{appName:g,suffix:n?.email?` (${n.email})`:``,defaultValue:`${g} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,Y.jsxs)(Xi,{className:`space-y-4`,children:[m.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,Y.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:m.map(t=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Zi,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{children:kS(t,e)})]},t))})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Y.jsxs)(G,{variant:`outline`,onClick:()=>h(!1),disabled:i,children:[(0,Y.jsx)(Fa,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Y.jsxs)(G,{onClick:()=>h(!0),disabled:i,children:[(0,Y.jsx)(Zi,{className:`mr-2 h-4 w-4`}),i?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,Y.jsx)(`p`,{className:`pt-2 text-center text-xs text-muted-foreground`,children:e(`oauth.consent.footer`,{defaultValue:`You can revoke access at any time from your account settings.`})})]})]})})}function kS(e,t){switch(e){case`openid`:return t(`oauth.consent.scope.openid`,{defaultValue:`Confirm your identity`});case`profile`:return t(`oauth.consent.scope.profile`,{defaultValue:`Read your basic profile (name, picture)`});case`email`:return t(`oauth.consent.scope.email`,{defaultValue:`Read your email address`});case`offline_access`:return t(`oauth.consent.scope.offlineAccess`,{defaultValue:`Stay signed in (refresh access)`});default:return e}}var AS=`/api/v1/auth`;function jS({children:e}){return(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,Y.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,Y.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground`,children:(0,Y.jsx)(hn,{className:`size-4`})}),`ObjectStack`]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function MS(){let{t:e}=F(),[t]=l(),n=t.get(`user_code`)??t.get(`code`)??``,{user:r,isLoading:i}=w(),a=s(),[o,c]=(0,J.useState)(!1),[u,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,v]=(0,J.useState)(``);return n?i?(0,Y.jsx)(jS,{children:(0,Y.jsx)(At,{children:(0,Y.jsx)(nr,{className:`text-center`,children:(0,Y.jsx)(Et,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?f?(0,Y.jsx)(jS,{children:(0,Y.jsx)(At,{children:(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Ga,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Y.jsx)(Zn,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Y.jsx)(Et,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):m?(0,Y.jsx)(jS,{children:(0,Y.jsx)(At,{children:(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Y.jsx)(Et,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Y.jsx)(jS,{children:(0,Y.jsxs)(At,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Y.jsx)(Et,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Y.jsxs)(Xi,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,Y.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:n})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:e(`auth.device.loggedInAs`,{email:r.email,defaultValue:`Signed in as ${r.email}`})}),g&&(0,Y.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:g}),(0,Y.jsx)(G,{onClick:async()=>{v(``),c(!0);try{let t=await fetch(`${AS}/device/approve`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:n})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n?.message??n?.error?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}p(!0),q.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){v(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{c(!1)}},className:`w-full`,disabled:o||u,children:o?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,Y.jsx)(G,{onClick:async()=>{v(``),d(!0);try{await fetch(`${AS}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:n})}),h(!0)}catch(t){v(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{d(!1)}},variant:`outline`,className:`w-full`,disabled:o||u,children:u?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,Y.jsx)(`div`,{className:`text-center`,children:(0,Y.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>a(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})}):(0,Y.jsx)(_,{to:`/login?redirect=${encodeURIComponent(`/auth/device?user_code=${encodeURIComponent(n)}`)}`,replace:!0}):(0,Y.jsx)(jS,{children:(0,Y.jsx)(At,{children:(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Y.jsx)(Et,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function NS(){let{t:e}=F(),{invitationId:t}=f(),n=s(),{user:r,isLoading:i,acceptInvitation:a,rejectInvitation:o,refreshOrganizations:c}=w(),[l,u]=(0,J.useState)(!1),[d,p]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{if(!i&&!r&&t){let e=`/accept-invitation/${t}`;n(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[i,r,t,n]),t?(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Y.jsx)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:(0,Y.jsxs)(At,{children:[(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Y.jsx)(Et,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Y.jsxs)(Xi,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(G,{className:`w-full`,onClick:async()=>{u(!0);try{await a(t),await c().catch(()=>void 0),q.success(e(`acceptInvitation.accepted`,{defaultValue:`Invitation accepted`})),n(`/organizations`)}catch(t){q.error(e(`acceptInvitation.acceptFailed`,{defaultValue:`Could not accept`}),{description:t.message})}finally{u(!1)}},disabled:l||d,children:l?e(`acceptInvitation.accepting`,{defaultValue:`Accepting…`}):e(`acceptInvitation.accept`,{defaultValue:`Accept invitation`})}),(0,Y.jsx)(G,{variant:`outline`,className:`w-full`,onClick:async()=>{p(!0);try{await o(t),q.success(e(`acceptInvitation.declined`,{defaultValue:`Invitation declined`})),n(`/organizations`)}catch(t){q.error(e(`acceptInvitation.declineFailed`,{defaultValue:`Could not decline`}),{description:t.message})}finally{p(!1)}},disabled:l||d,children:d?e(`acceptInvitation.declining`,{defaultValue:`Declining…`}):e(`acceptInvitation.decline`,{defaultValue:`Decline`})})]})]})})}):(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center bg-muted p-6`,children:(0,Y.jsx)(At,{className:`w-full max-w-sm`,children:(0,Y.jsxs)(nr,{className:`text-center`,children:[(0,Y.jsx)(Zn,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Y.jsx)(Et,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var PS=`/api/v1/auth`;function FS(){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 IS=FS();function LS(){let e=o(),t=e.pathname+e.search;return(0,Y.jsx)(_,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function RS({children:e,requireOrganization:t=!0}){return(0,Y.jsx)(te,{fallback:(0,Y.jsx)(LS,{}),loadingFallback:(0,Y.jsx)(Es,{}),children:(0,Y.jsx)(Os,{children:t?(0,Y.jsx)(js,{children:e}):e})})}function zS(){let{user:e}=w();return(0,Y.jsx)(Zf,{userId:e?.id,children:(0,Y.jsx)(up,{})})}function BS(){return(0,Y.jsxs)(ee,{authUrl:PS,children:[(0,Y.jsx)(rl,{position:`bottom-right`}),(0,Y.jsx)(eS,{}),(0,Y.jsx)(u,{basename:IS,children:(0,Y.jsx)(Ds,{children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/login`,element:(0,Y.jsx)(fS,{})}),(0,Y.jsx)(d,{path:`/register`,element:(0,Y.jsx)(_S,{})}),(0,Y.jsx)(d,{path:`/forgot-password`,element:(0,Y.jsx)(yS,{})}),(0,Y.jsx)(d,{path:`/reset-password`,element:(0,Y.jsx)(bS,{})}),(0,Y.jsx)(d,{path:`/verify-email`,element:(0,Y.jsx)(SS,{})}),(0,Y.jsx)(d,{path:`/verify-email-prompt`,element:(0,Y.jsx)(CS,{})}),(0,Y.jsx)(d,{path:`/setup`,element:(0,Y.jsx)(ES,{})}),(0,Y.jsx)(d,{path:`/oauth/consent`,element:(0,Y.jsx)(OS,{})}),(0,Y.jsx)(d,{path:`/auth/device`,element:(0,Y.jsx)(MS,{})}),(0,Y.jsx)(d,{path:`/accept-invitation/:invitationId`,element:(0,Y.jsx)(NS,{})}),(0,Y.jsx)(d,{path:`/f/:slug`,element:(0,Y.jsx)($x,{mode:`public`})}),(0,Y.jsx)(d,{path:`/s/:token`,element:(0,Y.jsx)(rS,{})}),(0,Y.jsx)(d,{path:`/forms/:name`,element:(0,Y.jsx)(RS,{children:(0,Y.jsx)($x,{mode:`internal`})})}),(0,Y.jsx)(d,{path:`/home`,element:(0,Y.jsx)(RS,{children:(0,Y.jsx)(zS,{})})}),(0,Y.jsx)(d,{path:`/organizations`,element:(0,Y.jsx)(RS,{requireOrganization:!1,children:(0,Y.jsx)(dp,{children:(0,Y.jsx)(gp,{})})})}),(0,Y.jsxs)(d,{path:`/organizations/:slug`,element:(0,Y.jsx)(RS,{requireOrganization:!1,children:(0,Y.jsx)(_p,{})}),children:[(0,Y.jsx)(d,{index:!0,element:(0,Y.jsx)(_,{to:`members`,replace:!0})}),(0,Y.jsx)(d,{path:`members`,element:(0,Y.jsx)(Sp,{})}),(0,Y.jsx)(d,{path:`invitations`,element:(0,Y.jsx)(Tp,{})}),(0,Y.jsx)(d,{path:`settings`,element:(0,Y.jsx)(Ep,{})})]}),(0,Y.jsx)(d,{path:`/system/*`,element:(0,Y.jsx)(Ms,{})}),(0,Y.jsx)(d,{path:`/ai`,element:(0,Y.jsx)(RS,{children:(0,Y.jsx)(Mp,{})})}),(0,Y.jsx)(d,{path:`/ai/:conversationId`,element:(0,Y.jsx)(RS,{children:(0,Y.jsx)(Mp,{})})}),(0,Y.jsx)(d,{path:`/apps/:appName/*`,element:(0,Y.jsx)(RS,{children:(0,Y.jsx)(Rx,{})})}),(0,Y.jsx)(d,{path:`/`,element:(0,Y.jsx)(Os,{children:(0,Y.jsx)(Bx,{})})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(_,{to:`/`,replace:!0})})]})})})]})}async function VS(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,T(r)?x(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var HS=`auth-session-token`,US=`auth-active-organization-id`;async function WS(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(HS)}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(HS),localStorage.removeItem(US)}catch{}}function GS(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 KS(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 qS(e){let{objects:t}=ce(),n=(0,J.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,J.useMemo)(()=>n?GS(n,0):null,[n]),fields:(0,J.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(KS):[],[n]),metadataObject:n}}function JS({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(t),[u,d]=(0,J.useState)(!1),f=(0,J.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,J.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,Y.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Y.jsx)(`dd`,{children:o?(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,Y.jsx)(mn,{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,Y.jsx)(W,{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,Y.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,Y.jsx)(K,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Zi,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Fa,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,Y.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,Y.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,Y.jsx)(ht,{className:`h-3 w-3`})})]})})]})}function YS({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=qS(t),{refresh:a}=ce(),o=fd(),s=(0,J.useCallback)(async(e,n)=>{if(!o||!i)return;let r={...i,[e]:n};try{await o.saveMetadataItem(`object`,t,r),await a(),q.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw q.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,Y.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,Y.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,Y.jsx)(JS,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,Y.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,Y.jsx)(JS,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Y.jsx)(JS,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,Y.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Y.jsx)(JS,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,Y.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,Y.jsx)(`dd`,{children:(0,Y.jsx)(U,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,Y.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,Y.jsx)(`dd`,{children:(0,Y.jsx)(U,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var XS=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function ZS({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=qS(t),{refresh:i}=ce(),a=fd(),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,J.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(),q.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){q.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,J.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(),q.success(`关联关系已删除`)}catch(e){q.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Y.jsx)(W,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Y.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:XS.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Y.jsx)(W,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Y.jsx)(W,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Y.jsxs)(G,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,Y.jsx)(K,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,Y.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,Y.jsx)(U,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:XS.find(t=>t.value===e.type)?.label||e.type}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,Y.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,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,Y.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Y.jsx)(Xe,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function QS({schema:e}){let t=e.objectName,{fields:n}=qS(t),r=(0,J.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,Y.jsx)(U,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,Y.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Y.jsx)(rt,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function $S(e){return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Y.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,Y.jsx)(kt,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,Y.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,Y.jsx)(en,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,Y.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,Y.jsx)(Wr,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function eC({schema:e}){let t=e.objectName,{object:n}=qS(t);return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,Y.jsx)(Ot,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function tC(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function nC(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=tC(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,J.useState)(o?.current??e),l=(0,J.useRef)(o?.past??[]),u=(0,J.useRef)(o?.future??[]),[,d]=(0,J.useState)(0),f=(0,J.useCallback)(()=>d(e=>e+1),[]);(0,J.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,J.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,J.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,J.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,J.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,J.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,J.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 rC(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(``),[i,a]=(0,J.useState)(``),o=(0,J.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,J.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,J.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,J.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function iC(){let[e,t]=(0,J.useState)(new Set);return{selectedIds:e,toggle:(0,J.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,J.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,J.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,J.useCallback)(()=>{t(new Set)},[]),isSelected:(0,J.useCallback)(t=>e.has(t),[e]),count:e.size}}function aC(){let[e,t]=(0,J.useState)(null);return{clipboard:e,copy:(0,J.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,J.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function oC(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,J.useState)(i),[s,c]=(0,J.useState)({x:0,y:0}),l=(0,J.useRef)(!1),u=(0,J.useRef)({x:0,y:0}),d=(0,J.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,J.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,J.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,J.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,J.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,J.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,J.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 sC(...e){return Xa(Ya(e))}function cC({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,Y.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,Y.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,Y.jsx)(fn,{className:`h-5 w-5 text-destructive`})}),(0,Y.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,Y.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,Y.jsx)(`button`,{onClick:o,className:sC(`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 lC(...e){return Xa(Ya(e))}function uC({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,J.useState)(new Set),o=(0,J.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,Y.jsxs)(`div`,{className:lC(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Y.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,Y.jsx)(qn,{className:`h-3 w-3`}):(0,Y.jsx)(jt,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,Y.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,Y.jsx)(dC,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function dC({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,Y.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,Y.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,Y.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,Y.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,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.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,Y.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,Y.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,Y.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function fC(...e){return Xa(Ya(e))}function pC({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,Y.jsx)(`div`,{className:fC(`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,Y.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,Y.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,Y.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 mC=(0,J.createContext)(null);mC.displayName=`CollaborationContext`;function hC(){return(0,J.useContext)(mC)}function gC(...e){return Xa(Ya(e))}function _C({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=vC,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=nC(t),d=u.current,f=(0,J.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=oC({initialZoom:e.zoom??1}),{zoom:m}=p,h=iC(),g=(0,J.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,J.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=aC(),y=rC(),b=hC(),x=(0,J.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,J.useState)(!0),[w,T]=(0,J.useState)(!0),[E,D]=(0,J.useState)(s),O=(0,J.useRef)(null),k=(0,J.useRef)(null),ee=(0,J.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),A=(0,J.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]),j=(0,J.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]),te=(0,J.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]),ne=(0,J.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]),re=(0,J.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]),M=(0,J.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]),N=(0,J.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]),ie=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ae=(0,J.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:ee(e.position.x+n),y:ee(e.position.y+r)}}:e)),x({type:`move`,elementId:t.id,data:{}}),O.current=null},[o,m,d,f,ee,x]),P=(0,J.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`}]:[],[_]),oe=(0,J.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,J.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(),te();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(),re();return}if(n&&e.key===`v`&&!o){e.preventDefault(),M();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,te,i,o,u,re,M,d]),(0,Y.jsxs)(`div`,{ref:k,tabIndex:0,className:gC(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Y.jsx)(`div`,{className:gC(`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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,Y.jsxs)(`div`,{className:`mb-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>A(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,Y.jsx)(H,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Y.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,Y.jsx)(Xn,{className:gC(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Y.jsx)(`button`,{className:gC(`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,Y.jsx)(Gt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:gC(`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,Y.jsx)(Me,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{className:gC(`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:re,children:(0,Y.jsx)(He,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:gC(`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:M,children:(0,Y.jsx)(xi,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsx)(`button`,{className:gC(`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:te,children:(0,Y.jsx)(Rt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,Y.jsx)(_a,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:gC(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,Y.jsx)(ai,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,Y.jsx)(kr,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Y.jsx)(ji,{className:`h-3 w-3`})})]}),r&&(0,Y.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,Y.jsx)(Tt,{className:gC(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Y.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:ie,onDrop:ae,children:(0,Y.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,Y.jsxs)(`div`,{draggable:!o,onDragStart:t=>N(t,e),className:gC(`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,Y.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,Y.jsx)(Ji,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),j(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,Y.jsx)(Rt,{className:`h-3 w-3 text-destructive`})})]}),(0,Y.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,Y.jsx)(pC,{items:oe,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Y.jsx)(`div`,{className:gC(`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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,Y.jsx)(mi,{className:`h-4 w-4`}),`Component Tree`]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,Y.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,Y.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:gC(`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,Y.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,Y.jsx)(`div`,{className:`border-t`,children:(0,Y.jsx)(uC,{title:`Properties – ${_.label??_.type}`,fields:P,onChange:ne})}):_&&(0,Y.jsxs)(`div`,{className:`border-t p-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,Y.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,Y.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,Y.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,Y.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,Y.jsx)(cC,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var vC=[{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 yC(e,t={}){return nC(e,t)}function bC(...e){return Xa(Ya(e))}var xC=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function SC(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 CC({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,J.useRef)(null),l=yC({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,J.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=rC(),m=iC(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=aC(),_=oC({minZoom:.25,maxZoom:3,zoomStep:.1}),v=hC(),[y,b]=(0,J.useState)(!0),[x,S]=(0,J.useState)(!0),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(null),[k,ee]=(0,J.useState)(``),A=(0,J.useRef)(null),j=(0,J.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]),te=(0,J.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]),ne=(0,J.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]),re=(0,J.useCallback)(()=>{if(i)return;let e=l.current;f({entities:SC(e.entities),relationships:e.relationships})},[i,l,f]),M=(0,J.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),N=(0,J.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]),ie=(0,J.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]),ae=(0,J.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),P=(0,J.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]),oe=(0,J.useCallback)(()=>{w(null)},[]),se=(0,J.useCallback)((e,t)=>{i||(O(e),ee(t))},[i]),ce=(0,J.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]),le=(0,J.useCallback)(()=>{O(null)},[]),ue=(0,J.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]),de=(0,J.useCallback)((e,t)=>{if(i||!u.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();A.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]),fe=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),pe=(0,J.useCallback)(e=>{if(e.preventDefault(),!A.current)return;let t=e.currentTarget.getBoundingClientRect(),n=_.zoom,r=(e.clientX-t.left-_.panOffset.x)/n-A.current.offsetX,i=(e.clientY-t.top-_.panOffset.y)/n-A.current.offsetY,a=l.current;f({entities:a.entities.map(e=>e.id===A.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),A.current=null},[_.zoom,_.panOffset,l,f]),me=h?u.find(e=>e.id===h):null,he=me?[{name:`name`,label:`Name`,type:`text`,value:me.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:me.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:me.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:me.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:me.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:me.position.y,group:`Position`}]:[],ge=(0,J.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,J.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(),M()):n&&e.key===`v`?(e.preventDefault(),N()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),ne()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,M,N,ne,m]);let _e=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,Y.jsxs)(`div`,{ref:c,tabIndex:0,className:bC(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,Y.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,Y.jsx)(Tr,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,Y.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,Y.jsx)(Gt,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Me,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Y.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(wa,{className:`h-3.5 w-3.5`})}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,Y.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(hr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(Oa,{className:`h-3 w-3`})})]}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Y.jsx)(`button`,{onClick:M,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(He,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:N,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(xi,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Y.jsxs)(`button`,{onClick:re,"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,Y.jsx)(wt,{className:`h-3 w-3`}),` Auto Layout`]}),(0,Y.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Y.jsx)(qe,{className:`h-3 w-3`}),(0,Y.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{onClick:j,"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,Y.jsx)(H,{className:`h-3 w-3`}),` Add Entity`]}),(0,Y.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,Y.jsx)(Xe,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,Y.jsxs)(`div`,{role:`region`,"aria-label":`Canvas`,className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,onWheel:_.handleWheel,onMouseDown:_.startPan,onDragOver:fe,onDrop:pe,children:[(0,Y.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,Y.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,Y.jsxs)(`g`,{children:[(0,Y.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,Y.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,Y.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,Y.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>de(t,e.id),className:bC(`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,Y.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,Y.jsx)(Tr,{className:`h-3.5 w-3.5`}),D===e.id?(0,Y.jsx)(`input`,{type:`text`,value:k,onChange:e=>ee(e.target.value),onBlur:ce,onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&le()},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,Y.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),se(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),te(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Y.jsx)(Rt,{className:`h-3 w-3 text-destructive`})})]}),(0,Y.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,Y.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:P,onKeyDown:e=>{e.key===`Enter`&&P(),e.key===`Escape`&&oe()},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,Y.jsxs)(`span`,{className:bC(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),ae(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Y.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Y.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),ue(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:xC.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Y.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Y.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),ie(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,Y.jsx)(H,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Y.jsx)(pC,{items:_e,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,Y.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Y.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,Y.jsx)(jt,{className:`h-3 w-3`}):(0,Y.jsx)(qn,{className:`h-3 w-3`}),`Properties`]}),y&&(0,Y.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,Y.jsx)(uC,{title:me?me.label:`Properties`,fields:he,onChange:ge})})]}),(0,Y.jsx)(`div`,{className:`border-t`,children:(0,Y.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,Y.jsx)(jt,{className:`h-3 w-3`}):(0,Y.jsx)(qn,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Y.jsx)(cC,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function wC(...e){return Xa(Ya(e))}var TC=120,EC=50;function DC(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 OC({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=nC({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,J.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=rC(),g=iC(),_=aC(),v=oC({initialZoom:1}),y=hC(),[b,x]=(0,J.useState)(null),[S,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(null),[O,k]=(0,J.useState)(!0),[ee,A]=(0,J.useState)(null),[j,te]=(0,J.useState)({x:0,y:0}),ne=(0,J.useRef)(null),re=(0,J.useRef)(c),M=(0,J.useRef)(l);re.current=c,M.current=l,(0,J.useEffect)(()=>{re.current?.(f),M.current?.(p)},[d.current]);let N=(0,J.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]),ie=(0,J.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]),ae=(0,J.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]),P=(0,J.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,_]),oe=(0,J.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]),se=(0,J.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),ce=(0,J.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]),le=(0,J.useCallback)(()=>{s||f.length===0||m(DC(f,p),p)},[f,p,s,m]),ue=(0,J.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;A(t);let n=e.target.getBoundingClientRect();te({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[s,f]),de=(0,J.useCallback)(e=>{if(e.preventDefault(),s||!ee)return;let t=e.currentTarget.getBoundingClientRect(),n=v.zoom,r=(e.clientX-t.left-v.panOffset.x)/n-j.x,i=(e.clientY-t.top-v.panOffset.y)/n-j.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===ee?{...e,position:{x:a,y:o}}:e),p),A(null)},[s,ee,j,f,p,v.zoom,v.panOffset,m]),fe=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),pe=(0,J.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),me=(0,J.useMemo)(()=>pe?[{name:`label`,label:`Name`,type:`text`,value:pe.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:pe.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:pe.description??``,group:`General`}]:[],[pe]),he=(0,J.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),ge=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`}},_e=(0,J.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:TC,height:EC,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,J.useEffect)(()=>{let e=ne.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(),P();return}if(n&&e.key===`v`){e.preventDefault(),oe();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),ae()):b&&(e.preventDefault(),ie(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,P,oe,ie,ae]);let ve=(0,J.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,Y.jsxs)(`div`,{ref:ne,tabIndex:0,className:wC(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsx)(cC,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,Y.jsx)(`div`,{className:`flex-1`}),!s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.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,Y.jsx)(Gt,{className:`h-3 w-3`})}),(0,Y.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,Y.jsx)(Me,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:P,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,Y.jsx)(He,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:oe,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,Y.jsx)(xi,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:se,className:wC(`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,Y.jsx)(kn,{className:`h-3 w-3`}),` Connect`]}),(0,Y.jsxs)(`button`,{onClick:le,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,Y.jsx)(lt,{className:`h-3 w-3`}),` Layout`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.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,Y.jsx)(hr,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,Y.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,Y.jsx)(wa,{className:`h-3 w-3`})}),(0,Y.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,Y.jsx)(Oa,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:()=>N(`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,Y.jsx)(Ft,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Y.jsxs)(`button`,{onClick:()=>N(`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,Y.jsx)(Vr,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Y.jsxs)(`button`,{onClick:()=>N(`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,Y.jsx)(za,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Y.jsxs)(`button`,{onClick:()=>N(`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,Y.jsx)(Vr,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.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,Y.jsx)(Tt,{className:`h-3 w-3`}):(0,Y.jsx)(Yi,{className:`h-3 w-3`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,Y.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,Y.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:ve,onDrop:de,onDragOver:fe,children:[(0,Y.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,Y.jsx)(`defs`,{children:(0,Y.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,Y.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+TC/2;let r=t.position.y+EC/2;n.position.x+TC/2;let i=n.position.y+EC/2,a=t.position.x+TC,o=r,s=n.position.x,c=i;return(0,Y.jsxs)(`g`,{children:[(0,Y.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,Y.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,Y.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,Y.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=>ue(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{ce(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Y.jsx)(`div`,{className:wC(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,ge(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,Y.jsx)(`span`,{className:wC(`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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:EC/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:EC/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?ce(e.id):(C(!0),T(e.id))}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:TC/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:TC/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}})]}),!s&&t&&!S&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ie(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,Y.jsx)(Rt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Y.jsx)(pC,{items:_e,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,Y.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,Y.jsx)(uC,{title:pe?`Properties: ${pe.label}`:`Properties`,fields:me,onChange:he})})]})]})}function kC(...e){return Xa(Ya(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`},AC={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}},jC=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function MC({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=nC(a.length>0?a:jC),f=d.current,p=(0,J.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=iC(),h=(0,J.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=aC(),_=rC(),v=hC(),y=(0,J.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,J.useState)(!0),S=(0,J.useRef)(null),C=(0,J.useRef)(null),w=AC[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,J.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,J.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]),ee=(0,J.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]),A=(0,J.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]),j=(0,J.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]),te=(0,J.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]),ne=(0,J.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]),re=(0,J.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]),M=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),N=(0,J.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]),ie=(0,J.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,J.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(),A();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(),te();return}if(n&&e.key===`v`&&!c){e.preventDefault(),ne();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,A,c,d,te,ne,f]),(0,Y.jsxs)(`div`,{ref:C,tabIndex:0,className:kC(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,Y.jsxs)(`div`,{role:`toolbar`,"aria-label":$.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,Y.jsx)(xr,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Y.jsx)(`button`,{className:kC(`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,Y.jsx)(Gt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:kC(`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,Y.jsx)(Me,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{className:kC(`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:te,children:(0,Y.jsx)(He,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:kC(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:ne,children:(0,Y.jsx)(xi,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsx)(`button`,{className:kC(`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:A,children:(0,Y.jsx)(Rt,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),$.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,Y.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,Y.jsx)(Tt,{className:kC(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,Y.jsx)(`div`,{role:`region`,"aria-label":$.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,Y.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,Y.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:M,onDrop:e=>N(e,t),children:[(0,Y.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,Y.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,Y.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:$.addText,"aria-label":$.addText,children:(0,Y.jsx)(Qt,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,Y.jsx)(Ie,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:$.addChart,"aria-label":$.addChart,children:(0,Y.jsx)(Wr,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:$.addTable,"aria-label":$.addTable,children:(0,Y.jsx)(ir,{className:`h-3 w-3`})})]}),(0,Y.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,Y.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,Y.jsxs)(`div`,{draggable:!c,onDragStart:n=>re(n,e,t),className:kC(`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,Y.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,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ee(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":$.deleteElement,children:(0,Y.jsx)(Rt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Y.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:kC(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,Y.jsx)(uC,{title:`${$.properties} – ${O.type}`,fields:ie,onChange:j}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:$.properties}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:$.selectElementPrompt})})]}))}),(0,Y.jsx)(cC,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var NC={"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 PC(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 FC(){try{let e=F();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:PC(NC)}:{t:e.t}}catch{return{t:PC(NC)}}}function IC(...e){return Xa(Ya(e))}var LC={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function RC(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var zC=0;function BC(e){return zC+=1,`${e}_${Date.now()}_${zC}`}function VC({steps:e,currentIndex:t,onStepClick:n}){return(0,Y.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,Y.jsxs)(J.Fragment,{children:[r>0&&(0,Y.jsx)(`div`,{className:IC(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:IC(`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,Y.jsx)(`div`,{className:IC(`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,Y.jsx)(Zi,{className:`h-4 w-4`}):r+1}),(0,Y.jsx)(`span`,{className:IC(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function HC({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!L(e.name);return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,Y.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Y.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:IC(`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,Y.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,Y.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,Y.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,Y.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,Y.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,Y.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:tr},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:lt},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:We}].map(({value:t,labelKey:a,Icon:o})=>(0,Y.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:IC(`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,Y.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,Y.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function UC({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,J.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,Y.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(pr,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.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,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:IC(`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,Y.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,Y.jsx)(`div`,{className:IC(`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,Y.jsx)(Zi,{className:`h-3 w-3`})})]}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,Y.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var WC={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 GC({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.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,Y.jsx)(Ri,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,Y.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,Y.jsx)(kn,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,Y.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,Y.jsx)(kr,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,Y.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,Y.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,Y.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):se(n.label)}),(0,Y.jsx)(`span`,{className:IC(`rounded-full px-2 py-0.5 text-[10px] font-medium`,WC[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.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,Y.jsx)(Ln,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function KC({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ie,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(gn,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(er,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,Y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,Y.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function qC({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=FC(),l=rC(),[u,d]=(0,J.useState)(0),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(()=>({...LC,objects:e.map(e=>({...e})),...n})),g=(0,J.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,J.useMemo)(()=>m.name.length>0&&L(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,J.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,J.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,J.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,J.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,J.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,J.useCallback)(e=>{let t={id:BC(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,J.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,J.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,J.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:RC(e.objects)})),d(e=>e+1))},[u,v]),k=(0,J.useCallback)(()=>{_||d(e=>e-1)},[_]),ee=(0,J.useCallback)(()=>{r?.(m)},[m,r]),A=(0,J.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]),j=(0,J.useCallback)(()=>{a?.(m)},[m,a]),te=(0,J.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:RC(e.objects)})),d(e))},[u,b]);return(0,Y.jsxs)(`div`,{className:IC(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,Y.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,Y.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,Y.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,Y.jsx)(Fa,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Y.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,Y.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,Y.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,Y.jsx)(VC,{steps:g,currentIndex:u,onStepClick:te})}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Y.jsx)(HC,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Y.jsx)(UC,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Y.jsx)(GC,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Y.jsx)(KC,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,"data-testid":`wizard-cancel`,onClick:A,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,Y.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:j,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,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,Y.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,Y.jsx)(dt,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:ee,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,Y.jsx)(Zi,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,Y.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,Y.jsx)(qn,{className:`h-4 w-4`})]})]})]})]})}function JC(...e){return Xa(Ya(e))}var YC=0;function XC(e){return YC+=1,`${e}_${Date.now()}_${YC}`}var ZC={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Tr},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:je},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:xr},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:Wr},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:kn},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:Ri},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:kr},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:li}},QC=[{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 $C({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,J.useState)(!1),[_,v]=(0,J.useState)(se(e.label)??``),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(e.icon||``),C=ZC[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(se(e.label)??``),g(!1)},D=()=>{u(e.id,x.trim()),b(!1)};return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:JC(`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,Y.jsx)(Ji,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(qn,{className:`h-3.5 w-3.5`})}):(0,Y.jsx)(`span`,{className:`w-5`}),y&&!i?(0,Y.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,Y.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,Y.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,Y.jsx)(ht,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,Y.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,Y.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(se(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,Y.jsx)(`span`,{className:JC(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(se(e.label)??``),g(!0))},children:se(e.label)}),(0,Y.jsx)(`span`,{className:JC(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,Y.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,Y.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,Y.jsx)(Lr,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(_a,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Y.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,Y.jsx)(H,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Ln,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,Y.jsx)(Y.Fragment,{children:e.children.map((n,r)=>(0,Y.jsx)($C,{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 ew({items:e,t}){return(0,Y.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,Y.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,Y.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,Y.jsx)(tw,{item:e,depth:0},e.id))})]})}function tw({item:e,depth:t}){let n=ZC[e.type];return e.type===`separator`?(0,Y.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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,Y.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Y.jsx)(`span`,{className:`truncate`,children:se(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Y.jsx)(tw,{item:e,depth:t+1},e.id))]})}function nw({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=FC(),c=(0,J.useRef)(null),[l,u]=(0,J.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,J.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,J.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,J.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,J.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,J.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,J.useCallback)((n,r)=>{let i={id:XC(r),type:r,label:r===`separator`?``:`New ${s(ZC[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,J.useCallback)(n=>{let r={id:XC(n),type:n,label:n===`separator`?``:`New ${s(ZC[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,J.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,J.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,J.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,Y.jsxs)(`div`,{"data-testid":`navigation-designer`,className:JC(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,Y.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[QC.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=ZC[e];return(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:JC(`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,Y.jsx)(H,{className:`h-3 w-3`}),s(t)]},e)}),(0,Y.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Y.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,Y.jsx)(ti,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Y.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:JC(`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,Y.jsx)(_i,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,Y.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,Y.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,Y.jsx)($C,{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,Y.jsx)(ew,{items:e,t:s})]})}function rw(...e){return Xa(Ya(e))}var iw=[{type:`metric`,label:`KPI Metric`,Icon:ot},{type:`bar`,label:`Bar Chart`,Icon:Wr},{type:`line`,label:`Line Chart`,Icon:Oe},{type:`pie`,label:`Pie Chart`,Icon:Qn},{type:`table`,label:`Table`,Icon:ir},{type:`grid`,label:`Grid`,Icon:vi}],aw=0;function ow(){return aw+=1,`widget_${Date.now()}_${aw}`}function sw({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=iw.find(e=>e.type===l)||iw[0];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:rw(`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,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ji,{className:`h-4 w-4 text-gray-300`}),(0,Y.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Y.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,Y.jsx)(Ln,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(jt,{className:`h-3.5 w-3.5`})}),(0,Y.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,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,Y.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,Y.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function cw({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=FC();return(0,Y.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,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,Y.jsx)(Fa,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,Y.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:iw.map(e=>(0,Y.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,Y.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,Y.jsx)(`option`,{value:`count`,children:`Count`}),(0,Y.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,Y.jsx)(`option`,{value:`avg`,children:`Average`}),(0,Y.jsx)(`option`,{value:`min`,children:`Min`}),(0,Y.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,Y.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,Y.jsx)(`option`,{value:`default`,children:`Default`}),(0,Y.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,Y.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,Y.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,Y.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,Y.jsx)(`option`,{value:`success`,children:`Success`}),(0,Y.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,Y.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,Y.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,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,Y.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 lw({schema:e}){let{t}=FC(),n=e.widgets||[];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,Y.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,Y.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=iw.find(t=>t.type===(e.type||`metric`))||iw[0];return(0,Y.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function uw({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=FC(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),p=(0,J.useRef)(null),m=(0,J.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,J.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=nC(e),w=(0,J.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,J.useCallback)(e=>{let t=ow(),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,J.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,J.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]),ee=(0,J.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,J.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 A=(0,J.useCallback)(()=>{i&&i(v)},[v,i]),j=(0,J.useCallback)(()=>{m.current?.click()},[]),te=(0,J.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,Y.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:rw(`flex flex-col gap-4 outline-none`,r),children:[(0,Y.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:te}),E&&!d&&(0,Y.jsx)(cw,{widget:E,readOnly:n,onChange:ee,onClose:()=>_(null)}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),iw.map(({type:e,label:t,Icon:r})=>(0,Y.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,Y.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.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,Y.jsx)(Gt,{className:`h-4 w-4`})}),(0,Y.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,Y.jsx)(Me,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:A,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,Y.jsx)(ti,{className:`h-4 w-4`})}),!n&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:j,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,Y.jsx)(_i,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:rw(`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,Y.jsx)(Lr,{className:`h-4 w-4`}):(0,Y.jsx)(_a,{className:`h-4 w-4`})})]})]}),d?(0,Y.jsx)(lw,{schema:v}):T.length===0?(0,Y.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,Y.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,Y.jsx)(sw,{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 dw(...e){return Xa(Ya(e))}var fw=[{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`}],pw=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function mw({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=FC(),[c,l]=(0,J.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=nC(e),g=(0,J.useRef)(!0);(0,J.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,J.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,J.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,J.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,J.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,Y.jsxs)(`div`,{"data-testid":`branding-editor`,className:dw(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,Y.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,Y.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:dw(`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,Y.jsx)(Gt,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:dw(`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,Y.jsx)(Me,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,Y.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,Y.jsx)(ti,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:dw(`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,Y.jsx)(_i,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ie,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(gn,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.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,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,Y.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:fw.map(e=>(0,Y.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:dw(`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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(er,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Qt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.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,Y.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),pw.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,Y.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,Y.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:dw(`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,Y.jsx)($n,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:dw(`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,Y.jsx)(Vi,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview`,className:dw(`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,Y.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,Y.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,Y.jsx)(`span`,{className:dw(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,Y.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,Y.jsx)(`p`,{className:dw(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Y.jsx)(`span`,{className:dw(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Y.jsxs)(`div`,{className:dw(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:dw(`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,Y.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,Y.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,Y.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,Y.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,Y.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,Y.jsx)(`div`,{className:dw(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:dw(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:dw(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function hw(...e){return Xa(Ya(e))}var gw=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],_w=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function vw({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=FC(),s=rC(),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(null),f=(0,J.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,J.useMemo)(()=>new ue({items:f}),[f]),m=(0,J.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,J.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,J.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,J.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,J.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,J.useCallback)(()=>{d(null),l(!0)},[]),b=(0,J.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,J.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,J.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:_w.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:gw.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,Y.jsxs)(`div`,{"data-testid":`object-manager`,className:hw(`w-full space-y-3`,a),children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Tr,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,Y.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,Y.jsx)(ho,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Y.jsx)(go,{schema:S}),(0,Y.jsx)(cC,{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 yw(...e){return Xa(Ya(e))}var bw={text:{label:`Text`,Icon:Qt},textarea:{label:`Text Area`,Icon:xr},number:{label:`Number`,Icon:Gn},boolean:{label:`Checkbox`,Icon:ze},date:{label:`Date`,Icon:zi},datetime:{label:`Date/Time`,Icon:zi},time:{label:`Time`,Icon:zi},select:{label:`Picklist`,Icon:Ve},email:{label:`Email`,Icon:gr},phone:{label:`Phone`,Icon:Le},url:{label:`URL`,Icon:er},password:{label:`Password`,Icon:Cr},currency:{label:`Currency`,Icon:Gn},percent:{label:`Percent`,Icon:Gn},lookup:{label:`Lookup`,Icon:Xe},formula:{label:`Formula`,Icon:Qe},autonumber:{label:`Auto Number`,Icon:Gn},file:{label:`File`,Icon:xr},image:{label:`Image`,Icon:Ie},markdown:{label:`Markdown`,Icon:xr},html:{label:`Rich Text`,Icon:xr},color:{label:`Color`,Icon:gn},code:{label:`Code`,Icon:Qe},location:{label:`Location`,Icon:$r},address:{label:`Address`,Icon:$r},rating:{label:`Rating`,Icon:vn},slider:{label:`Slider`,Icon:ia}},xw={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`]},Sw=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function Cw({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=FC(),o=rC(),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(``),p=(0,J.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,J.useMemo)(()=>new ue({items:p}),[p]),h=(0,J.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,J.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,J.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,J.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,J.useCallback)(()=>{u(null),c(!0)},[]),b=(0,J.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,J.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,J.useMemo)(()=>Sw.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:xw[e].map(e=>({label:bw[e].label,value:e}))})),[a]),C=(0,J.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,J.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,Y.jsxs)(`div`,{"data-testid":`field-designer`,className:yw(`w-full space-y-3`,i),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(jn,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,Y.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,Y.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,Y.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,Y.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,Y.jsx)(ho,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Y.jsx)(_o,{schema:w}),(0,Y.jsx)(cC,{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 ww=`objectui-app-wizard-draft`;function Tw(){let e=v(),{appName:t}=p(),{objects:n,refresh:r}=ce(),i=z(),a=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),o=(0,J.useCallback)(()=>{try{let e=localStorage.getItem(ww);if(e)return JSON.parse(e)}catch{}},[]),s=(0,J.useCallback)(async t=>{try{let n=ve(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(ww),q.success(`Application "${t.title}" created successfully`),await r?.(),e(`/apps/${t.name}`)}catch(e){q.error(e?.message||`Failed to create application`)}},[e,r,i]),c=(0,J.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),l=(0,J.useCallback)(e=>{try{localStorage.setItem(ww,JSON.stringify(e)),q.info(`Draft saved`)}catch{}},[]);return(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,Y.jsx)(qC,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function Ew(){let e=v(),{appName:t,editAppName:n}=p(),{apps:r,objects:i,refresh:a}=ce(),o=z(),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,J.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,J.useCallback)(async t=>{try{let n=ve(t),r={...c,...n},i=o?.getClient();i&&await i.meta.saveItem(`app`,t.name,r),q.success(`Application "${t.title}" updated successfully`),await a?.(),e(`/apps/${t.name}`)}catch(e){q.error(e?.message||`Failed to update application`)}},[e,a,o,c]),f=(0,J.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,J.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${s}`,JSON.stringify(e)),q.info(`Draft saved`)}catch{}},[s]);return c?(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,Y.jsx)(qC,{availableObjects:l,initialDraft:u,onComplete:d,onCancel:f,onSaveDraft:m})}):(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,Y.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,s,`" not found.`]})})}function Dw(){let e=v(),{dashboardName:t}=p(),n=z(),{dashboards:r,refresh:i}=ce(),a=r?.find(e=>e.name===t),[o,s]=(0,J.useState)(()=>a||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),c=(0,J.useRef)(o);c.current=o;let l=(0,J.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,J.useCallback)(async e=>{s(e),await l(e)},[l]);(0,J.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),l(c.current).then(e=>{e&&q.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let d=(0,J.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),q.success(`Dashboard schema exported`)},[t]),f=(0,J.useCallback)(e=>{q.success(`Dashboard schema imported`),u(e)},[u]);return a?(0,Y.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,Y.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,Y.jsx)(ja,{className:`h-4 w-4`})}),(0,Y.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,a.label||a.title||t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Y.jsx)(uw,{schema:o,onChange:u,onExport:d,onImport:f})})]}):(0,Y.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var Ow=t({AppCreationWizard:()=>qC,BrandingEditor:()=>mw,CreateAppPage:()=>Tw,DashboardDesignPage:()=>Dw,DashboardEditor:()=>uw,DataModelDesigner:()=>CC,EditAppPage:()=>Ew,FieldDesigner:()=>Cw,NavigationDesigner:()=>nw,ObjectManager:()=>vw,PageDesigner:()=>_C,ProcessDesigner:()=>OC,ReportDesigner:()=>MC});R.register(`page-designer`,_C,{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}]}),R.register(`data-model-designer`,CC,{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}]}),R.register(`process-designer`,OC,{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}]}),R.register(`report-designer`,MC,{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}]}),R.register(`app-creation-wizard`,qC,{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}]}),R.register(`navigation-designer`,nw,{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}]}),R.register(`dashboard-editor`,uw,{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}]}),R.register(`branding-editor`,mw,{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}]}),R.register(`object-manager`,vw,{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}]}),R.register(`field-designer`,Cw,{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 kw(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 Aw(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 jw=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=kw(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(Aw)};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 Mw({schema:e}){let t=e.objectName,{objects:n,refresh:r}=ce(),i=fd(),a=(0,J.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,J.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(KS):[],[a]),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(!1),d=s??o,f=(0,J.useRef)(d),p=(0,J.useCallback)(async e=>{let n=f.current;if(c(e),f.current=e,!i){q.error(`Service unavailable — changes saved locally only`);return}let a=jw.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(),q.success(o)}catch(e){c(n),f.current=n,q.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,Y.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,Y.jsx)(K,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,Y.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,Y.jsx)(Hn,{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,Y.jsx)(Cw,{objectName:t,fields:d,onFieldsChange:p})]})}function Nw({schema:e}){let t=e.objectName,[n,r]=(0,J.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,Y.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,Y.jsxs)(Te,{value:n,onValueChange:r,className:`w-full`,children:[(0,Y.jsxs)(pa,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Y.jsxs)(Bi,{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,Y.jsx)(oi,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Y.jsxs)(Bi,{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,Y.jsx)(jn,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Y.jsxs)(Bi,{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,Y.jsx)(Xe,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Y.jsxs)(Bi,{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,Y.jsx)(Ot,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Y.jsx)(Gr,{value:`details`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(N,{schema:i})})}),(0,Y.jsx)(Gr,{value:`fields`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(N,{schema:a})})}),(0,Y.jsx)(Gr,{value:`relationships`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(N,{schema:o}),(0,Y.jsx)(N,{schema:s})]})}),(0,Y.jsx)(Gr,{value:`data`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(N,{schema:l}),(0,Y.jsx)(N,{schema:c})]})})]})})}var Pw={namespace:`console`,category:`system`};R.register(`object-detail-tabs`,Nw,{...Pw,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),R.register(`object-properties`,YS,{...Pw,label:`Object Properties`,icon:`Settings2`}),R.register(`object-relationships`,ZS,{...Pw,label:`Object Relationships`,icon:`Link2`}),R.register(`object-keys`,QS,{...Pw,label:`Object Keys`,icon:`KeyRound`}),R.register(`object-data-experience`,$S,{...Pw,label:`Data Experience`,icon:`LayoutList`}),R.register(`object-data-preview`,eC,{...Pw,label:`Data Preview`,icon:`Table`}),R.register(`object-field-designer`,Mw,{...Pw,label:`Field Designer`,icon:`Columns`});var Fw=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-C70S6MYv.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Iw=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-Rtd6u1e_.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Lw=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BNIOSFr1.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Rw({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Rp({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Rw,{label:`API console`}),children:(0,Y.jsx)(Fw,{...e})})}),Rp({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Rw,{label:`flow runs`}),children:(0,Y.jsx)(Iw,{...e})})}),Rp({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Rw,{label:`public forms`}),children:(0,Y.jsx)(Lw,{...e})})});var zw=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-DPGkAZWG.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function Bw({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Rp({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Bw,{label:`profile`}),children:(0,Y.jsx)(zw,{...e})})});var Vw=`/api/v1/auth`;cl(),R.registerLazy(`object-map`,()=>c(()=>import(`./plugin-map-DRf0LmJy.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),R.registerLazy(`map`,()=>c(()=>import(`./plugin-map-DRf0LmJy.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`])R.registerLazy(e,()=>c(()=>import(`./plugin-dashboard-BRn9AjyQ.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});R.registerLazy(`chart`,()=>c(()=>import(`./plugin-charts-DrCI3cJo.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`])R.registerLazy(e,()=>c(()=>import(`./plugin-charts-DrCI3cJo.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});R.registerLazy(`object-gantt`,()=>c(()=>import(`./plugin-gantt-D3OFukY1.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),R.registerLazy(`gantt`,()=>c(()=>import(`./plugin-gantt-D3OFukY1.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`markdown`,()=>c(()=>import(`./plugin-markdown-BVFW0U6V.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),R.registerLazy(`object-timeline`,()=>c(()=>import(`./plugin-timeline-RAn1F_nX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),R.registerLazy(`timeline`,()=>c(()=>import(`./plugin-timeline-RAn1F_nX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`object-calendar`,()=>c(()=>import(`./plugin-calendar-D1wyyvEx.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),R.registerLazy(`calendar`,()=>c(()=>import(`./plugin-calendar-D1wyyvEx.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`calendar-view`,()=>c(()=>import(`./plugin-calendar-D1wyyvEx.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),R.registerLazy(`object-kanban`,()=>c(()=>import(`./plugin-kanban-C-qMP4VL.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),R.registerLazy(`kanban`,()=>c(()=>import(`./plugin-kanban-C-qMP4VL.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])R.registerLazy(e,()=>c(()=>import(`./plugin-kanban-C-qMP4VL.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});R.registerLazy(`report`,()=>c(()=>import(`./plugin-report-CJSBthhg.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`])R.registerLazy(e,()=>c(()=>import(`./plugin-report-CJSBthhg.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});On();var Hw=``.replace(/\/+$/,``);Promise.all([Ic(Hw),WS(Vw)]).finally(()=>{Bo.createRoot(document.getElementById(`root`)).render((0,Y.jsx)(J.StrictMode,{children:(0,Y.jsx)(mo,{pwa:{enabled:!0,name:Rc(),shortName:zc()},children:(0,Y.jsx)(_e,{loadLanguage:VS,children:(0,Y.jsx)(BS,{})})})}))});export{Pd as n,zp as t};
|