@objectstack/console 7.9.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AiPendingActionsPage-jLWo6Ayv.js → AiPendingActionsPage-DvOWhD7g.js} +1 -1
- package/dist/assets/{ApiConsolePage-CWTG8Xo7.js → ApiConsolePage-Vl1bVDlg.js} +1 -1
- package/dist/assets/{AppManagementPage-GNlxvYjB.js → AppManagementPage-xylPiZXY.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-k11JteOF.js +1 -0
- package/dist/assets/{AuditLogPage-5XSTvoRE.js → AuditLogPage-BAgbEbjd.js} +1 -1
- package/dist/assets/{ComponentNavView-BSO_oEuH.js → ComponentNavView-Cu9EpRhc.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-Bmrpz8kU.js +1 -0
- package/dist/assets/DeveloperHubPage-D0U8y334.js +1 -0
- package/dist/assets/FlowRunsPage-Bct8RGca.js +1 -0
- package/dist/assets/IntegrationsPage-DlDdz6C1.js +82 -0
- package/dist/assets/ProfilePage-DmAxKVba.js +1 -0
- package/dist/assets/PublicFormsPage-DqmgJlHM.js +1 -0
- package/dist/assets/{RecentItemsProvider-C6mWTgDQ.js → RecentItemsProvider-PPHUem2M.js} +1 -1
- package/dist/assets/{SettingsHub-CIY42FH1.js → SettingsHub-CQQPAWJE.js} +1 -1
- package/dist/assets/{SettingsView-CegTe8Ea.js → SettingsView-DYZF-4ez.js} +1 -1
- package/dist/assets/{SystemHubPage-CrPlzy52.js → SystemHubPage-c5n8TmAu.js} +1 -1
- package/dist/assets/{data-adapter-ByiC1zK-.js → data-adapter-BEUY_KBa.js} +1 -1
- package/dist/assets/framework-D2TAXBd8.js +34 -0
- package/dist/assets/{highlighted-body-OFNGDK62-Cb0ueA71.js → highlighted-body-OFNGDK62-lqS5G44w.js} +1 -1
- package/dist/assets/index-BULCH_rU.js +32 -0
- package/dist/assets/index-TbUZx7_1.css +2 -0
- package/dist/assets/infrastructure-ai8_U_pI.js +3 -0
- package/dist/assets/mermaid-GHXKKRXX-9CQJi3nm.js +1 -0
- package/dist/assets/plugin-calendar-BJ7fznUX.js +1 -0
- package/dist/assets/{plugin-charts-CP4h02tQ.js → plugin-charts-wMrfjY7-.js} +2 -2
- package/dist/assets/plugin-chatbot-BbT-Zj0J.js +120 -0
- package/dist/assets/plugin-dashboard-PAzWRr0S.js +3 -0
- package/dist/assets/plugin-form-BCa4rKi8.js +1 -0
- package/dist/assets/plugin-gantt-C4jqziXn.js +1 -0
- package/dist/assets/plugin-grid-B3Vr31vQ.js +6 -0
- package/dist/assets/{plugin-kanban-B-o9RSK7.js → plugin-kanban-C45siRfB.js} +1 -1
- package/dist/assets/{plugin-map-Dogg70cr.js → plugin-map-BB0oqbKR.js} +1 -1
- package/dist/assets/{plugin-markdown-BR6MY8l8.js → plugin-markdown-BD_OCMP4.js} +1 -1
- package/dist/assets/plugin-report-DbF7QhyW.js +59 -0
- package/dist/assets/plugin-timeline-C7Y4YBw6.js +1 -0
- package/dist/assets/plugin-view-13J1AT1r.js +1 -0
- package/dist/assets/plugins-views-BfPWuVqp.js +4 -0
- package/dist/assets/{src-CefK1cl3.js → src-DSLdt1DW.js} +1 -1
- package/dist/assets/{types-uOhYwSbE.js → types-Bxt1180l.js} +1 -1
- package/dist/assets/ui-components-Df6BGPWS.js +42 -0
- package/dist/assets/{ui-layout-B_j0BM4b.js → ui-layout-C7asUpWR.js} +1 -1
- package/dist/assets/useMetadata-C-bbpJVP.js +7 -0
- package/dist/assets/{vendor-charts-BfGsKLn4.js → vendor-charts-4buVt82U.js} +1 -1
- package/dist/assets/vendor-objectstack-b2m3JVRu.js +83 -0
- package/dist/assets/vendor-ui-utils-CjuGfYLJ.js +1 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ApprovalsInboxPage-BjgnPpO0.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-CqIHTEt8.js +0 -1
- package/dist/assets/DeveloperHubPage-dAwpubU9.js +0 -1
- package/dist/assets/FlowRunsPage--fqUTSur.js +0 -1
- package/dist/assets/ProfilePage-BWTzOuUR.js +0 -1
- package/dist/assets/PublicFormsPage-BYCoo2T3.js +0 -1
- package/dist/assets/framework-Bg_8y02a.js +0 -34
- package/dist/assets/index--IqVdzh7.css +0 -2
- package/dist/assets/index-DKok_mql.js +0 -33
- package/dist/assets/infrastructure-xzEwJt5N.js +0 -3
- package/dist/assets/mermaid-GHXKKRXX-l3hYvjCm.js +0 -1
- package/dist/assets/plugin-calendar-C-9OPJzZ.js +0 -1
- package/dist/assets/plugin-chatbot-Byj2Ut9C.js +0 -120
- package/dist/assets/plugin-dashboard-T9rNXqHD.js +0 -3
- package/dist/assets/plugin-form-BOb7Pz1P.js +0 -1
- package/dist/assets/plugin-gantt-QTyZ46KN.js +0 -1
- package/dist/assets/plugin-grid-CIlCwKyp.js +0 -6
- package/dist/assets/plugin-report-AhX1YoV8.js +0 -59
- package/dist/assets/plugin-timeline-Dju0mfv_.js +0 -1
- package/dist/assets/plugin-view-DF7-Dd3a.js +0 -1
- package/dist/assets/plugins-views-rCdZtRbk.js +0 -4
- package/dist/assets/ui-components-C7AytqY9.js +0 -41
- package/dist/assets/vendor-objectstack-DCNcl1ou.js +0 -65
- package/dist/assets/vendor-ui-utils-CWvoJB0S.js +0 -1
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{_ 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-BMpe6Iqg.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 A,r as j,s as ee,u as te}from"./infrastructure-xzEwJt5N.js";import{N as M,c as ne,d as N,l as P}from"./vendor-objectstack-DCNcl1ou.js";import{C as re,E as ie,F as ae,N as F,O as oe,P as se,R as ce,S as le,V as ue,X as de,Z as fe,b as pe,d as me,dt as I,f as he,it as ge,j as _e,k as L,l as ve,n as R,nt as ye,ot as be,r as z,rt as xe,v as Se,x as Ce,y as we,z as Te}from"./framework-Bg_8y02a.js";import{n as Ee,r as De,t as Oe}from"./data-adapter-ByiC1zK-.js";import{$ as ke,$a as Ae,$i as je,$n as Me,$r as Ne,$t as Pe,Aa as Fe,Ai as Ie,An as Le,Ar as Re,At as ze,Bi as Be,Bn as Ve,Bo as He,Br as Ue,Bt as We,Ca as Ge,Co as Ke,Cr as qe,Da as B,Di as Je,Do as Ye,Dr as Xe,Ds as Ze,Dt as Qe,Ea as $e,Ei as et,Eo as tt,Er as nt,Es as rt,Et as it,F as at,Fa as ot,Fi as st,Fn as ct,Fo as lt,Fr as ut,Fs as dt,Ft as ft,Gi as pt,Gn as mt,Go as ht,Gs as gt,Gt as _t,Ho as vt,Hr as yt,Ht as bt,I as xt,Ia as St,In as Ct,Io as wt,Ir as Tt,Is as Et,It as Dt,Ja as Ot,Ji as kt,Jn as At,Jo as jt,Jr as Mt,Js as Nt,Ka as Pt,Ki as Ft,Kn as It,Ko as Lt,Kr as Rt,Ks as zt,Kt as Bt,La as Vt,Li as Ht,Ln as Ut,Lo as Wt,Lr as Gt,Ls as Kt,Lt as qt,M as Jt,Ma as Yt,Mi as Xt,Mn as Zt,Mo as Qt,Mr as $t,Mt as en,N as tn,Na as nn,Ni as rn,Nn as an,No as on,Nr as sn,Ns as cn,Nt as ln,Oa as un,Oi as dn,On as fn,Oo as pn,Or as mn,Os as hn,Ot as gn,P as _n,Pa as vn,Pn as yn,Po as bn,Pr as xn,Pt as Sn,Q as Cn,Qi as wn,Qn as V,Qo as Tn,Qr as En,Qt as Dn,Ra as On,Ri as kn,Rn as An,Ro as jn,Rr as Mn,Rs as Nn,Rt as Pn,Sa as Fn,Si as In,So as Ln,Sr as Rn,Ss as zn,St as Bn,T as Vn,Ta as Hn,Tr as Un,Tt as Wn,Ua as Gn,Uo as Kn,Ur as qn,Us as Jn,Ut as Yn,V as Xn,Va as Zn,Vi as Qn,Vo as $n,Vr as er,Vs as tr,Vt as nr,Wa as rr,Wi as ir,Wo as ar,Ws as or,X as sr,Xa as cr,Xi as lr,Xn as ur,Xo as dr,Xr as fr,Ya as pr,Yi as mr,Yn as hr,Yo as gr,Yr as _r,Ys as H,Z as vr,Za as yr,Zi as br,Zo as xr,Zr as Sr,Zs as Cr,Zt as wr,_ as Tr,_a as Er,_i as Dr,_o as Or,_r as kr,_s as Ar,_t as jr,aa as Mr,ai as Nr,an as Pr,ao as Fr,ar as Ir,as as Lr,at as Rr,ba as zr,bi as Br,bo as Vr,br as Hr,bs as Ur,bt as Wr,ca as Gr,cn as Kr,co as qr,cr as Jr,cs as Yr,ct as Xr,da as Zr,di as Qr,do as $r,dr as ei,ds as ti,dt as ni,ea as ri,ei as ii,en as U,eo as ai,er as oi,es as si,et as ci,fa as li,fi as ui,fo as di,fr as fi,fs as pi,ft as mi,g as hi,ga as gi,gi as _i,go as vi,gr as yi,gs as bi,gt as xi,h as Si,ha as Ci,hi as wi,ho as Ti,hs as Ei,ht as Di,ii as Oi,in as W,io as ki,is as Ai,it as ji,ja as Mi,ji as Ni,jn as Pi,jo as Fi,jr as Ii,js as Li,ka as Ri,ki as zi,kn as Bi,ko as Vi,kr as Hi,ks as Ui,kt as Wi,la as Gi,li as Ki,ln as qi,lo as Ji,lr as Yi,ls as Xi,lt as Zi,ma as Qi,mi as $i,mn as ea,mo as ta,mr as G,ms as na,mt as ra,na as ia,ni as aa,no as oa,ns as sa,nt as ca,oa as la,oi as ua,on as da,oo as fa,or as pa,os as ma,ot as ha,pa as ga,pi as _a,po as va,ps as ya,pt as ba,qa as xa,qi as Sa,qn as Ca,qo as wa,qr as Ta,qs as Ea,qt as Da,ra as Oa,ro as ka,rt as Aa,sa as ja,si as Ma,sn as Na,so as Pa,sr as Fa,ss as Ia,st as La,ta as Ra,ti as za,to as Ba,tr as Va,ts as Ha,tt as Ua,ua as Wa,ui as Ga,un as Ka,uo as qa,ur as Ja,us as Ya,v as Xa,va as Za,vi as Qa,vo as $a,vr as eo,vs as to,w as no,wa as ro,wo as io,wr as ao,ws as oo,wt as so,x as co,xa as lo,xi as uo,xo as fo,xr as po,xt as mo,ya as ho,yi as go,yr as _o,ys as vo,yt as yo,z as bo,za as xo,zi as K,zn as So,zs as Co,zt as wo}from"./ui-components-C7AytqY9.js";import{a as To,i as Eo,o as q,r as Do}from"./vendor-ui-utils-CWvoJB0S.js";import{a as Oo,c as ko,i as Ao,n as jo,o as Mo,r as No,s as Po,t as Fo}from"./RecentItemsProvider-C6mWTgDQ.js";import{n as Io,r as Lo,t as Ro}from"./ui-layout-B_j0BM4b.js";import{a as zo,n as Bo,o as Vo,s as Ho,t as Uo}from"./plugins-views-rCdZtRbk.js";import{i as Wo,r as Go}from"./plugin-grid-CIlCwKyp.js";import{n as Ko,r as qo,t as Jo}from"./plugin-form-BOb7Pz1P.js";import{a as Yo,c as Xo,d as Zo,f as Qo,i as $o,l as es,m as ts,n as ns,o as rs,p as is,r as as,s as os,t as ss,u as cs}from"./plugin-view-DF7-Dd3a.js";import{i as ls,n as us,r as ds}from"./plugin-dashboard-T9rNXqHD.js";import{d as fs,i as ps,l as ms,t as hs,u as gs}from"./plugin-chatbot-Byj2Ut9C.js";var J=e(b(),1),_s=e(r(),1),Y=g();function vs({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 Oe({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)(pe.Provider,{value:n,children:e})}var ys=300*1e3,bs=[`app`,`view`],xs={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},Ss=`objectui:metadata:`;function Cs(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var ws=Cs();function Ts(...e){ws&&console.debug(`[MetadataProvider]`,...e)}function Es(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function Ds(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Os(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function ks(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function As(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)ks(e)&&r.add(e.object);for(let e of t){if(ks(e)){let t=n[e.object]||={listViews:{},formViews:{}},r=e.name||`${e.object}.${e.viewKind}`,i=e.config&&typeof e.config==`object`?e.config:{},a={...i,name:r,label:e.label??i.label,isDefault:!!e.isDefault};e.viewKind===`form`?(t.formViews[r]=a,(e.isDefault||!t.form)&&(t.form=a)):(t.listViews[r]=a,e.isDefault&&(t.primary=a));continue}let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t||r.has(t))continue;let i=n[t]||={listViews:{},formViews:{}};if(e.list){i.primary=e.list;let t=e.list.name||`list`;i.listViews[t]=e.list}if(e.form&&(i.form=e.form),e.listViews&&typeof e.listViews==`object`)for(let[t,n]of Object.entries(e.listViews))i.listViews[t]=n;if(e.formViews&&typeof e.formViews==`object`)for(let[t,n]of Object.entries(e.formViews))i.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 js(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Ms(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(Ss+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ns(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(Ss+e,JSON.stringify(t))}catch{}}function Ps({children:e,adapter:t,ttlMs:n=ys}){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=js(),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 Ts(`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=Es(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)Os(e)&&t.byName.set(e.name,e);return e===`app`&&Ns(e,i),Ts(`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,Ts(`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 Ts(`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=Ds(i);return a&&n.byName.set(t,a),Ts(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Ts(`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),Ts(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Ts(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1,t=Ms(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Os(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of bs)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(xs.objects),n=e(`view`);return n.length?As(t,n):t},get dashboards(){return e(xs.dashboards)},get reports(){return e(xs.reports)},get pages(){return e(xs.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)(Ce.Provider,{value:v,children:e})}var Fs=(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 ge({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)(Fs.Provider,{value:a,children:(0,Y.jsx)(ae,{scope:o,children:e})})}function Ls(){let e=(0,J.useContext)(Fs);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new ge(e)}}return e}function Rs(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 zs({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let c=s(),{appName:l}=f(),{t:u}=z(),d=`/apps/${l}`,{execute:p,loading:m,error:h,runner:g}=se({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 Bs=(0,J.createContext)(void 0);function Vs({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)(Bs.Provider,{value:s,children:e})}function Hs(){return(0,J.useContext)(Bs)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Us(e){let{setRecordTitle:t}=Hs();(0,J.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Ws=`objectui-favorites`,Gs=`objectui-nav-pins`,Ks=20,qs=20;function Js(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>qs&&(r=!0)):(t++,t>Ks&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<qs&&(i.push(t),o++):a<Ks&&(i.push(t),a++);return i}function Ys(e){try{let t=localStorage.getItem(Oo(Ws,e));return t?JSON.parse(t):[]}catch{return[]}}function Xs(e,t){try{localStorage.setItem(Oo(Ws,t),JSON.stringify(e))}catch{}}function Zs(e){let t;try{t=localStorage.getItem(Gs)}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(Gs)}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 Qs=(0,J.createContext)(null);function $s({children:e}){let{user:t}=w(),n=t?.id??null,r=ko(`favorites`),[i,a]=(0,J.useState)(()=>Ys(n));(0,J.useEffect)(()=>{a(Ys(n))},[n]),Po(Oo(Ws,n),e=>{a(Array.isArray(e)?Js(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=Js((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Ys(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=Js([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Zs(f);h&&(f=Js(m),p=!0),a(f),Xs(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,J.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Zs(e);if(!r)return e;let i=Js(t);return Xs(i,n),i})},[r,n]);let s=(0,J.useMemo)(()=>Ao(async e=>{r&&await r.save(e)},500),[r]);(0,J.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,J.useCallback)(e=>{Xs(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=Js([{...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):Js([{...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)(Qs.Provider,{value:h,children:e})}function ec(){return(0,J.useContext)(Qs)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var tc=(0,J.createContext)({theme:`system`,setTheme:()=>null});function nc({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)(tc.Provider,{...r,value:o,children:e})}var rc=()=>{let e=(0,J.useContext)(tc);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function ic(){return(0,Y.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function ac({children:e}){return(0,Y.jsx)(nc,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Y.jsx)(Vs,{children:(0,Y.jsx)(No,{children:(0,Y.jsx)($s,{children:(0,Y.jsx)(Fo,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ic,{}),children:e})})})})})})}function oc({children:e}){return(0,Y.jsx)(vs,{children:(0,Y.jsx)(sc,{children:e})})}function sc({children:e}){let t=le(),{language:n}=z(),r=(0,J.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Y.jsx)(ue,{dataSource:t,children:(0,Y.jsxs)(Ps,{adapter:t,children:[(0,Y.jsx)(cc,{}),e]},n)}):(0,Y.jsx)(ic,{})}function cc(){let{user:e}=w(),t=le(),n=Mo();return(0,J.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=De({dataSource:t,userId:e.id,key:`ui.favorites`}),i=De({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 lc({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=w();return r?(0,Y.jsx)(ic,{}):((n??[]).length>0||t)&&!t?(0,Y.jsx)(_,{to:`/organizations`,replace:!0}):(0,Y.jsx)(Y.Fragment,{children:e})}function uc(){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 dc=null,fc=0,pc=0,mc=null,hc={editor:dc,openSeq:fc,reviewSeq:pc,reviewTarget:mc},gc=new Set;function _c(){hc={editor:dc,openSeq:fc,reviewSeq:pc,reviewTarget:mc};for(let e of gc)e()}function vc(e,t){return e===t?!0:JSON.stringify(e)===JSON.stringify(t)}var yc={subscribe(e){return gc.add(e),()=>{gc.delete(e)}},getSnapshot(){return hc},setEditor(e){vc(dc,e)||(dc=e,_c())},requestOpen(){fc+=1,_c()},requestReview(e){pc+=1,mc=e,_c()}};function bc(){return(0,J.useSyncExternalStore)(yc.subscribe,yc.getSnapshot,yc.getSnapshot)}function xc(e){(0,J.useEffect)(()=>(yc.setEditor(e),()=>yc.setEditor(null)),[e?JSON.stringify(e):``])}function Sc(){yc.requestOpen()}function Cc(e){yc.requestReview(e)}var wc=(0,J.lazy)(()=>c(()=>import(`./ConsoleFloatingChatbot-CqIHTEt8.js`),__vite__mapDeps([0]),import.meta.url)),Tc=()=>{c(()=>import(`./ConsoleFloatingChatbot-CqIHTEt8.js`),__vite__mapDeps([0]),import.meta.url)};function Ec(e){let[t,n]=(0,J.useState)(!1),{openSeq:r}=bc(),i=(0,J.useRef)(r);return(0,J.useEffect)(()=>{r!==i.current&&(i.current=r,n(!0))},[r]),t?(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(wc,{...e,defaultOpen:!0})}):(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:Tc,onFocus:Tc,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 Dc(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 Oc=new Set(vr),kc=new Map;function Ac(e){if(!e)return wt;let t=kc.get(e);if(t)return t;let n=Dc(e);if(!Oc.has(n))return kc.set(e,wt),wt;let r=e=>J.createElement(sr,{name:n,fallback:wt,...e});return r.displayName=`LucideIcon(${e})`,kc.set(e,r),r}var jc=20;function Mc(e,t=``){let{href:n,external:r}=Io(e,t);return r?n:!n||n===`#`?``:n}function Nc(e){return`nav:${e}`}function Pc(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=ec(),a=(0,J.useCallback)((e,i,a,o)=>{let s=Nc(e);i?(a&&t({id:s,label:a.label,href:Mc(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<jc;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 Fc(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 Ic(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 Lc(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 Rc(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 zc(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var Bc=`\0`,Vc=`[-\\u2013\\u2014|/·,:]`;function Hc(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===``?Bc:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Vc}\\s*${Bc}`,`g`),o=RegExp(`${Bc}\\s*${Vc}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(Bc,`g`),``).replace(/\s+/g,` `).trim(),i}function Uc(e,t){if(e?.titleFormat){let n=Hc(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 Wc=`__all__`;function Gc(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Kc(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 qc(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Gc(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 Jc(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=Kc(s),l=[],u=new Set;for(let e of c){if(!qc(e,o))continue;let t=Gc(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=Gc(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 Yc(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===Wc?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)(Xc,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function Xc({def:e,value:t,onChange:n,t:r}){let i=Jc(e),a=Ac(e.icon),o=Rc(e.label,r)||e.id,s=!!t&&t!==(e.allValue??``),c=J.useRef(!1);return J.useEffect(()=>{if(!c.current){if(s){c.current=!0;return}i.length>0&&(c.current=!0,n(i[0].value))}},[i,s]),(0,Y.jsxs)(Pn,{value:s?t:``,onValueChange:n,children:[(0,Y.jsx)(nr,{"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)(bt,{placeholder:`Select ${o}…`})]})}),(0,Y.jsx)(wo,{children:i.map(e=>(0,Y.jsx)(We,{value:e.value,children:e.label},e.value))})]})}function Zc(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 Qc({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=Wn(),r=o(),{t:a}=z(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=Cr(),{context:d,currentAppName:f}=Hs(),{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}=jo(),{favorites:h,removeFavorite:g}=ec(),{apps:_,objects:v}=re(),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}=Zc(x?.name||`home`),{togglePin:T,applyPins:E}=Pc(),D=x?.areas||[],[k,A]=J.useState(()=>D.length>0?D[0].id:null);J.useEffect(()=>{D.length>0?A(e=>D.some(t=>t.id===e)?e:D[0].id):A(null)},[x?.name,D.length]);let j=D.find(e=>e.id===k)?.navigation||x?.navigation||[],{contextValues:ee,element:te}=Yc(x?.name||`home`,x?.contextSelectors,a),M=J.useMemo(()=>[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[a]),ne=d===`home`?M:j,N=J.useMemo(()=>E(S(ne)),[ne,S,E]),[P,ie]=J.useState(!1),{evaluator:ae}=Ls(),F=J.useCallback(e=>Rs(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]),ce=J.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),le=J.useCallback((e,t)=>e===`object`?ce.size===0?!0:ce.has(t):!0,[ce]),ue=d===`app`&&x?`/apps/${x.name}`:``;return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(ni,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Y.jsx)(jr,{className:`border-b p-1.5`,children:(0,Y.jsx)(yo,{children:(0,Y.jsx)(Bn,{children:(0,Y.jsx)(mo,{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)(Ot,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Y.jsx)(mi,{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)(ra,{className:`group-data-[state=collapsed]:hidden`,children:[(0,Y.jsxs)(xi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Mr,{className:`h-3.5 w-3.5`}),a(`sidebar.scope`,{defaultValue:`范围`})]}),(0,Y.jsx)(Di,{children:te})]}),D.length>1&&(0,Y.jsxs)(ra,{children:[(0,Y.jsxs)(xi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Vt,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,Y.jsx)(Di,{children:(0,Y.jsx)(yo,{children:D.map(e=>{let t=Ac(e.icon);return(0,Y.jsx)(Bn,{children:(0,Y.jsxs)(mo,{isActive:e.id===k,tooltip:e.label,onClick:()=>A(e.id),children:[(0,Y.jsx)(t,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Y.jsx)(Ro,{items:N,basePath:ue,evaluateVisibility:F,checkPermission:se,checkCapability:le,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:ee}}),m.length>0&&(0,Y.jsxs)(ra,{children:[(0,Y.jsxs)(xi,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ie(e=>!e),children:[(0,Y.jsx)(Yr,{className:`h-3 w-3 transition-transform duration-150 ${P?`rotate-90`:``}`}),(0,Y.jsx)(ht,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),P&&(0,Y.jsx)(Di,{children:(0,Y.jsx)(yo,{children:m.slice(0,5).map(e=>(0,Y.jsx)(Bn,{children:(0,Y.jsx)(mo,{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)(ra,{children:[(0,Y.jsxs)(xi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(ii,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Y.jsx)(Di,{children:(0,Y.jsx)(yo,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Y.jsxs)(Bn,{children:[(0,Y.jsx)(mo,{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)(Wr,{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)(za,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ra,{children:(0,Y.jsx)(Di,{children:(0,Y.jsx)(yo,{children:M.map(e=>{let t=Ac(e.icon),n=r.pathname===e.url;return(0,Y.jsx)(Bn,{children:(0,Y.jsx)(mo,{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)(ra,{children:[(0,Y.jsxs)(xi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(ii,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Y.jsx)(Di,{children:(0,Y.jsx)(yo,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Y.jsxs)(Bn,{children:[(0,Y.jsx)(mo,{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)(Wr,{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)(za,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Y.jsx)(ba,{className:`border-t p-1`,children:(0,Y.jsx)(so,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function $c(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 el=0;function tl(){return el+=1,`conflict-${Date.now()}-${el}`}var nl=0;function rl(){return nl+=1,`ver-${Date.now()}-${nl}`}function il(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:rl(),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:rl(),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:rl(),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:rl(),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:tl()};o(e=>[...e,t])},[]),clearHistory:(0,J.useCallback)(()=>{i([]),o([])},[])}}var al={sm:24,md:32,lg:40},ol={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function sl(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function cl({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=al[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`}}):sl(e.userName),r&&J.createElement(`span`,{style:{...m,backgroundColor:ol[e.status]}}))))}var ll=J.createContext({});function ul(){let e=J.useContext(ll),[t,n]=J.useState([]);return J.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function dl(e,t){let n=J.useContext(ll),[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 fl(){let{theme:e,setTheme:t}=rc(),{t:n}=z();return(0,Y.jsxs)(Pr,{children:[(0,Y.jsx)(ea,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(Sr,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Y.jsx)(Zr,{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)(da,{align:`end`,children:[(0,Y.jsxs)(Kr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Y.jsx)(Sr,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Kr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Y.jsx)(Zr,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Kr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Y.jsx)(li,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var pl=[{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 ml(){let{t:e,language:t,changeLanguage:n}=z();return(0,Y.jsxs)(Pr,{children:[(0,Y.jsx)(ea,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(Ba,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Y.jsx)(da,{align:`end`,className:`max-h-72 overflow-y-auto`,children:pl.map(e=>(0,Y.jsxs)(Kr,{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 hl={connected:{label:`Connected`,color:`text-green-500`,icon:sa},connecting:{label:`Connecting...`,color:`text-yellow-500`,icon:B},reconnecting:{label:`Reconnecting...`,color:`text-yellow-500`,icon:B},disconnected:{label:`Disconnected`,color:`text-muted-foreground`,icon:ao},error:{label:`Connection Error`,color:`text-destructive`,icon:ao}};function gl({state:e,className:t}){let n=hl[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:H(`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:H(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function _l(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 vl({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=z(),c=s(),l=f(),{currentAppName:u}=Hs(),[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_inbox_message?view=mine`)},T=()=>{p(!1),c(`/apps/setup/sys_activity`)},E=e=>{a(e.id);let t=u??l.appName;if(e.action_url){p(!1);let n=e.action_url;if(/^https?:\/\//i.test(n)){window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`/apps/`)){c(n);return}let r=n.startsWith(`/`)?n:`/${n}`;c(t?`/apps/${t}${r}`:r);return}e.source_object&&e.source_id&&(p(!1),c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`))};return(0,Y.jsxs)(wr,{open:d,onOpenChange:p,children:[(0,Y.jsx)(Pe,{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)(cn,{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)(Dn,{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)(ke,{value:m,onValueChange:e=>h(e),className:`w-full`,children:[(0,Y.jsxs)(Ua,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Y.jsxs)(ca,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(cn,{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)(ca,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Nr,{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)(ca,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Nt,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Y.jsxs)(ci,{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:_l(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)(ci,{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)(Nr,{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)(ci,{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:[_l(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 yl({activeAppName:e,onAppChange:t}){let{apps:n}=re(),{t:r}=z(),{appLabel:i}=Cr(),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)(Pr,{children:[(0,Y.jsx)(ea,{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:Rc(s.label,r)})}),(0,Y.jsx)(Ya,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Y.jsxs)(da,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Y.jsx)(qi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,Y.jsx)(Ka,{}),o.map(e=>{let n=Ac(e.icon),a=i({name:e.name,label:Rc(e.label,r)}),o=s.name===e.name;return(0,Y.jsxs)(Kr,{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)(ti,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var bl=(0,J.createContext)(null);function xl({children:e}){let[t,n]=(0,J.useState)(null),r=(0,J.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Y.jsx)(bl.Provider,{value:r,children:e})}function Sl(){return(0,J.useContext)(bl)?.value??null}function Cl(e){let t=(0,J.useContext)(bl),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 wl(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),[]);Cl((0,J.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var Tl={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function El(e){Tl={...Tl,...e,features:{...Tl.features,...e.features??{}},branding:{...Tl.branding,...e.branding??{}}}}async function Dl(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;El({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):Tl.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??Tl.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??Tl.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:Tl.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():Tl.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():Tl.branding.productShortName}:Tl.branding})}catch{}}function Ol(){return Tl}function kl(){return Tl.branding?.productName||`ObjectOS`}function Al(){return Tl.branding?.productShortName||kl()}function jl(){return Tl.cloudUrl??``}function Ml(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Nl(){return(0,Y.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Pl=[];function Fl({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:_}=L(),{user:v,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:S,isOrganizationsLoading:C}=w(),T=le(),{t:E}=z(),{objectLabel:D,dashboardLabel:O,pageLabel:A,reportLabel:j,viewLabel:ee,appLabel:te}=Cr(),{apps:M,dashboards:ne,pages:N,reports:P}=re(),{currentAppName:ie,recordTitle:ae}=Hs(),F=Sl(),[oe,se]=(0,J.useState)(null),[ce,ue]=(0,J.useState)([]),de=(0,J.useRef)(!1),fe=(0,J.useRef)(!1),[pe,me]=(0,J.useState)(0),I=(0,J.useRef)(!1),he=(0,J.useCallback)(async()=>{if(!T||!p)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!de.current)try{let t=await T.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(de.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&se(e)}}catch{}},[T,p]);(0,J.useEffect)(()=>{he()},[he]),(0,J.useEffect)(()=>{if(!T||!p||!v?.id||fe.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=new Set([`read`,`clicked`,`dismissed`]),o=async()=>{try{let[t,i]=await Promise.all([T.find(`sys_inbox_message`,{$filter:{user_id:v.id},$orderby:{created_at:`desc`},$top:20}),T.find(`sys_notification_receipt`,{$filter:{user_id:v.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(e)return;let o=Array.isArray(t?.data)?t.data:[],s=Array.isArray(i?.data)?i.data:[],c=new Map;for(let e of s){let t=e?.notification_id==null?``:String(e.notification_id);if(!t)continue;let n=c.get(t);(!n||!a.has(n.state)&&a.has(e.state))&&c.set(t,{id:String(e.id),state:String(e.state)})}ue(o.map(e=>{let t=e?.notification_id==null?null:String(e.notification_id),n=t?c.get(t):void 0;return{id:String(e.id),notification_id:t,receipt_id:n?.id??null,type:e.topic??`notification`,title:e.title??``,body:e.body_md??null,action_url:e.action_url??null,is_read:n?a.has(n.state):!1,created_at:e.created_at}})),r=n}catch(e){if(i(e)){fe.current=!0;return}r=Math.min(r*2,12e4)}},s=()=>{if(e||fe.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await o(),s()},n)},c=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,o().finally(s))};return o().finally(s),typeof document<`u`&&document.addEventListener(`visibilitychange`,c),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,c)}},[T,p,v?.id]),(0,J.useEffect)(()=>{if(!p||!v?.id||I.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){I.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||me(r.size)}catch{}},a=()=>{n||I.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[p,v?.id]);let ge=ce.reduce((e,t)=>e+ +!t.is_read,0),_e=(0,J.useCallback)(async(e,t)=>{!T||!e.notification_id||(e.receipt_id?await T.update(`sys_notification_receipt`,e.receipt_id,{state:`read`,at:t}):await T.create(`sys_notification_receipt`,{notification_id:e.notification_id,user_id:v?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[T,v?.id]),ve=(0,J.useCallback)(async e=>{let t=ce.find(t=>t.id===e);if(ue(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await _e(t,new Date().toISOString())}catch{}},[ce,_e]),R=(0,J.useCallback)(async()=>{let e=ce.filter(e=>!e.is_read);if(!e.length)return;ue(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>_e(e,t).catch(()=>{})))},[ce,_e]),ye=ul(),be=a??(ye.length>0?ye:Pl),xe=c??oe??[],Se=C||(x??[]).length>0||!!S,Ce=m.pathname.split(`/`).filter(Boolean),we=h.appName||Ce[1],Te=Ce[2],Ee=`/apps/${we}`,De=n??[],Oe=l||ie||we,ke=(M||[]).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 Ne=(Ae.size>0?De.filter(e=>Ae.has(e.name)):De.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:D(e),href:`${Ee}/${e.name}`})),Pe=[];if(p){if(Te===`dashboard`){if(Pe.push({label:E(`console.breadcrumb.dashboards`),href:Ee}),Ce[3]){let e=Ce[3],t=(ne||[]).find(t=>t.name===e)?.label||Ml(e);Pe.push({label:O({name:e,label:t})})}}else if(Te===`page`){if(Pe.push({label:E(`console.breadcrumb.pages`),href:Ee}),Ce[3]){let e=Ce[3],t=(N||[]).find(t=>t.name===e)?.label||Ml(e);Pe.push({label:A({name:e,label:t})})}}else if(Te===`report`){if(Pe.push({label:E(`console.breadcrumb.reports`),href:Ee}),Ce[3]){let e=Ce[3],t=(P||[]).find(t=>t.name===e)?.label||Ml(e);Pe.push({label:j({name:e,label:t})})}}else if(Te===`system`)Pe.push({label:E(`console.breadcrumb.system`)}),Ce[3]&&Pe.push({label:Ml(Ce[3])});else if(Te){let e=De.find(e=>e.name===Te);if(e){if(Pe.push({label:D(e),href:`${Ee}/${Te}`,siblings:Ne}),Ce[3]===`record`&&Ce[4]){let e=Ce[4].length>12?`${Ce[4].slice(0,8)}…`:Ce[4],t=ae?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Pe.push({label:n||`#${e}`})}else if(Ce[3]===`view`&&Ce[4]){let t=Ce[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Ml(t),i=ee(e.name,t,r);Pe.push({label:i})}}}}let Fe=Pe[Pe.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:H(`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:kl(),children:(0,Y.jsx)(Vt,{className:`h-4 w-4`})}),d===`home`&&(0,Y.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:kl()}),d===`orgs`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Nl,{}),(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)(so,{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)(Nl,{})}),(0,Y.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(yl,{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)(Nl,{})}),(0,Y.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Pe.map((e,t)=>{let n=t===Pe.length-1;return(0,Y.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Y.jsx)(Nl,{}),e.siblings&&e.siblings.length>1?(0,Y.jsxs)(Pr,{children:[(0,Y.jsxs)(ea,{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)(Ya,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Y.jsxs)(da,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Y.jsx)(qi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Y.jsx)(Ka,{}),e.siblings.map(e=>(0,Y.jsx)(Kr,{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)}),F&&F.views.length>0?F.views.length>1?(0,Y.jsxs)(Pr,{children:[(0,Y.jsx)(ea,{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:F.triggerLabel??F.views.find(e=>e.id===F.activeViewId)?.label??Fe}),(0,Y.jsx)(Ya,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Y.jsx)(da,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:F.views.map(e=>{let t=e.id===F.activeViewId;return(0,Y.jsxs)(Kr,{onSelect:()=>{t||F.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)($e,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Y.jsx)(ti,{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:F.triggerLabel??F.views[0].label}):(0,Y.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Fe})]})]}),(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)(gl,{state:r}),p&&be.length>0&&(0,Y.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:`Users currently online`,children:(0,Y.jsx)(cl,{users:be,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)(go,{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)(go,{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)(vl,{notifications:ce,unreadCount:ge,pendingApprovalsCount:pe,activities:xe,onMarkAllRead:R,onMarkRead:ve}),(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)(Ui,{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)(Tn,{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)(Pr,{children:[(0,Y.jsx)(ea,{asChild:!0,children:(0,Y.jsx)(G,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Y.jsxs)(Me,{className:`h-7 w-7 rounded-full`,children:[(0,Y.jsx)(Va,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(oi,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:k(v)})]})})}),(0,Y.jsxs)(da,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Y.jsx)(qi,{className:`p-0 font-normal`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Y.jsxs)(Me,{className:`h-8 w-8 rounded-lg`,children:[(0,Y.jsx)(Va,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(oi,{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)(Ka,{}),(0,Y.jsxs)(Na,{children:[Se&&(0,Y.jsxs)(Kr,{onClick:()=>g(`/organizations`),className:`cursor-pointer`,children:[(0,Y.jsx)(Ze,{className:`mr-2 h-4 w-4`}),E(`organizations.mine`,{defaultValue:`My Organizations`})]}),(M||[]).filter(e=>e.active!==!1&&e.hidden===!0).map(e=>{let t=Ac(e.icon),n=te({name:e.name,label:Rc(e.label,E)});return(0,Y.jsxs)(Kr,{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)(Ka,{}),(0,Y.jsx)(qi,{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)(fl,{})]}),(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)(ml,{})]}),b&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ka,{}),(0,Y.jsxs)(Kr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Y.jsx)(Hn,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Il=768,Ll=1024;function Rl(){let{setOpen:e,isMobile:t}=Wn();(0,J.useEffect)(()=>{function t(){let t=window.innerWidth;t>=Il&&t<Ll&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}function zl({children:e}){return Rl(),(0,Y.jsx)(Y.Fragment,{children:e})}function Bl({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Rc(n?.label)||t,{isAiEnabled:c}=_e(),l=c||!1,{setContext:u,setCurrentAppName:d}=Hs();return(0,J.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Y.jsx)(xl,{children:(0,Y.jsxs)(Lo,{sidebar:(0,Y.jsx)(Qc,{activeAppName:t,onAppChange:r}),navbar:(0,Y.jsx)(Fl,{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?`${Rc(n.label)} — ${kl()}`:void 0}:void 0,children:[(0,Y.jsx)(zl,{children:e}),l&&(0,Y.jsx)(Ec,{appLabel:s,appName:t,defaultAgent:n?.defaultAgent,objects:i,userId:o})]})})}function Vl({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:H(`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:H(`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 Hl({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}=rc(),{evaluator:m}=Ls(),{t:h}=z();(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=Ul(t?.navigation||[]).filter(e=>Rs(e.visible??e.visibleOn,m)),{results:x,isSearching:S}=Se({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:Uc}),{recentItems:C}=jo(),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)(fn,{open:a,onOpenChange:o,children:[(0,Y.jsx)(Pi,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Y.jsxs)(an,{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)(Le,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Y.jsxs)(Zt,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Y.jsx)(go,{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)(Le,{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=Ac(e.icon);return(0,Y.jsxs)(Zt,{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)(Le,{heading:h(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=Ac(e.icon);return(0,Y.jsxs)(Zt,{value:`object ${Rc(e.label,h)} ${e.objectName}`,onSelect:()=>y(()=>u(Io(e,g,v).href)),children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:Rc(e.label,h)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Y.jsx)(Le,{heading:h(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Y.jsxs)(Zt,{value:`dashboard ${Rc(e.label,h)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Io(e,g,v).href)),children:[(0,Y.jsx)(St,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:Rc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Y.jsx)(Le,{heading:h(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Y.jsxs)(Zt,{value:`page ${Rc(e.label,h)} ${e.pageName}`,onSelect:()=>y(()=>u(Io(e,g,v).href)),children:[(0,Y.jsx)($a,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:Rc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Y.jsx)(Le,{heading:h(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Y.jsxs)(Zt,{value:`report ${Rc(e.label,h)} ${e.reportName}`,onSelect:()=>y(()=>u(Io(e,g,v).href)),children:[(0,Y.jsx)(to,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:Rc(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(yn,{}),(0,Y.jsx)(Le,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Ac(e.icon);return(0,Y.jsxs)(Zt,{value:`app ${Rc(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:Rc(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)(yn,{}),(0,Y.jsxs)(Le,{heading:h(`console.commandPalette.preferences`),children:[(0,Y.jsxs)(Zt,{value:`theme light`,onSelect:()=>y(()=>p(`light`)),children:[(0,Y.jsx)(Sr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Y.jsxs)(Zt,{value:`theme dark`,onSelect:()=>y(()=>p(`dark`)),children:[(0,Y.jsx)(Zr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Y.jsxs)(Zt,{value:`theme system`,onSelect:()=>y(()=>p(`system`)),children:[(0,Y.jsx)(li,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Y.jsx)(yn,{}),(0,Y.jsxs)(Le,{heading:h(`console.commandPalette.actions`),children:[(0,Y.jsxs)(Zt,{value:`create new app application`,onSelect:()=>y(()=>u(`${g}/create-app`)),children:[(0,Y.jsx)(K,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.createApp`)})]}),(0,Y.jsxs)(Zt,{value:`search all results full page`,onSelect:()=>y(()=>u(`${g}/search`)),children:[(0,Y.jsx)(go,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})]})]})]})}function Ul(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Ul(n.children)):t.push(n);return t}function Wl(){let{t:e}=z(),[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)(ct,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Ct,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:e(`console.shortcuts.title`)}),(0,Y.jsx)(Ut,{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 Gl(){return null}var Kl={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 ql({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,J.useState)(0),o=(0,J.useMemo)(()=>[Kl.steps.connecting,Kl.steps.loadingConfig,Kl.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)(wt,{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:kl()}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Kl.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)(Ai,{className:`h-5 w-5 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold`,children:Kl.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:Kl.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)(B,{className:`h-4 w-4 animate-spin`}),Kl.actions.retrying]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ni,{className:`h-4 w-4`}),Kl.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)(Jt,{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)(sa,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Y.jsx)(B,{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 Jl(e){let{theme:t=`system`}=rc();return(0,Y.jsx)(To,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,Y.jsx)(sa,{className:`h-4 w-4`}),info:(0,Y.jsx)(Gn,{className:`h-4 w-4`}),warning:(0,Y.jsx)(ut,{className:`h-4 w-4`}),error:(0,Y.jsx)(la,{className:`h-4 w-4`}),loading:(0,Y.jsx)(B,{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 Yl=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Xl({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(...Yl),e.offsetWidth,e.classList.add(...Yl))},[n.pathname]),(0,Y.jsx)(`div`,{ref:r,className:[...Yl,t??``].filter(Boolean).join(` `),children:e})}var Zl=null,Ql=null;function $l(){return Ql||(Ql=(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-BreXt3n4.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=tu(e.data.url)),e}}),Zl=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Ql)}function eu(e,t){if(Zl)try{Zl.captureException(e,t?{extra:t}:void 0)}catch{}}function tu(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 nu({error:e,onReset:t}){let{t:n}=z();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)(at,{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)(ut,{className:`h-6 w-6 text-destructive`})}),(0,Y.jsx)(bo,{children:n(`console.errors.somethingWentWrong`)}),(0,Y.jsx)(xt,{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)(et,{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)(Ot,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var ru=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),eu(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)(nu,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function iu({sections:e,open:t}){if(!t)return null;let{t:n}=z(),[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)(Ya,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Y.jsx)(Yr,{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)(ti,{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 au(){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 ou({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s}){let{t:c}=z(),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}=no(n===`create`?f:p,{mode:n,onUpdate:a});(0,J.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,J.useMemo)(()=>rs(i),[i.fields]),C=(0,J.useMemo)(()=>cs(m.filter),[m.filter]),w=(0,J.useMemo)(()=>Zo(m.sort),[m.sort]),T=(0,J.useMemo)(()=>ss({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]),A=c(n===`create`?`console.objectView.createView`:`console.objectView.configureView`),j=(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)(Dr,{className:`h-3.5 w-3.5`})});return(0,Y.jsx)(Xn,{open:e,onClose:t,schema:D,draft:m,isDirty:h,onFieldChange:g,onSave:O,onDiscard:k,onUndo:v,onRedo:y,canUndo:b,canRedo:x,undoLabel:c(`designer.undo`),redoLabel:c(`designer.redo`),objectDef:i,saveLabel:c(`console.objectView.save`),discardLabel:c(`console.objectView.discard`),panelRef:l,role:`complementary`,ariaLabel:A,tabIndex:-1,testId:`view-config-panel`,closeTitle:c(`console.objectView.closePanel`),footerTestId:`view-config-footer`,saveTestId:`view-config-save`,discardTestId:`view-config-discard`,headerExtra:j,className:`transition-all overflow-hidden`})}function su(e){return[{type:`grid`,icon:ot,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Oi,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Ur,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Pt,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:ht,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:ua,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:lo,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:to,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function cu(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var lu={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:as}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:$o},{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:$o},{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:$o},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:ns},{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=>Xo(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&os(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&os(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:as},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function uu({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=z(),s=(0,J.useMemo)(()=>su(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?rs(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(cu(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=lu[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=(lu[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=es(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)(ct,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Ct,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:o(`console.objectView.createView`)}),(0,Y.jsx)(Ut,{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:H(`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:H(`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:H(`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)(Ai,{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)(U,{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)(An,{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 du={config:{icon:Dr,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:$e,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:gt,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:$i,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 fu({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=du[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Y.jsx)(gn,{delayDuration:200,children:(0,Y.jsxs)(it,{children:[(0,Y.jsx)(Wi,{asChild:!0,children:(0,Y.jsxs)(V,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:H(`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)(Qe,{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 pu({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)(ze,{className:`h-7 w-56`}),(0,Y.jsx)(ze,{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)(ze,{className:`h-4 w-20`}),(0,Y.jsx)(ze,{className:`h-8 w-24`}),(0,Y.jsx)(ze,{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)(ze,{className:`h-5 w-32`}),(0,Y.jsx)(ze,{className:`h-5 w-5 rounded-full`})]}),(0,Y.jsx)(ze,{className:`h-40 w-full`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ze,{className:`h-3 w-16`}),(0,Y.jsx)(ze,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function mu({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)(ze,{className:`h-8 w-8 rounded`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(ze,{className:`h-6 w-48`}),(0,Y.jsx)(ze,{className:`h-4 w-32`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ze,{className:`h-9 w-20`}),(0,Y.jsx)(ze,{className:`h-9 w-20`})]})]}),(0,Y.jsx)(ze,{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)(ze,{className:`h-4 w-24`}),(0,Y.jsx)(ze,{className:`h-9 w-full`})]},`field-${t}`))}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,Y.jsx)(ze,{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)(ze,{className:`h-8 w-8 rounded-full`}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(ze,{className:`h-4 w-40`}),(0,Y.jsx)(ze,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var hu={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 gu(e){let t=hu[e?.managedBy??`platform`]??hu.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 _u=new Set([`record:discussion`,`record:chatter`]);function vu(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`&&_u.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 yu({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Y.jsx)(Ir,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Y.jsxs)(Jr,{children:[(0,Y.jsxs)(ei,{children:[(0,Y.jsx)(fi,{children:e.options?.title||`Confirm Action`}),(0,Y.jsx)(Yi,{children:e.message})]}),(0,Y.jsxs)(Ja,{children:[(0,Y.jsx)(Fa,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Y.jsx)(pa,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function bu({state:e,onOpenChange:t}){let{t:n}=z(),[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)(ct,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:n(`actionDialog.title`)}),(0,Y.jsx)(Ut,{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)(mt,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,Y.jsxs)(W,{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)(W,{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)(Pn,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,Y.jsx)(nr,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,Y.jsx)(bt,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Y.jsx)(wo,{children:e.options.map(e=>(0,Y.jsx)(We,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Y.jsx)(Xa,{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)(Cn,{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)(U,{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)(U,{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)(An,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Y.jsx)(G,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var xu=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Su=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)}})),Cu=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}}})),wu=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})),Tu=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})),Eu=n((e=>{var t=Su().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}})),Du=n((e=>{var t=Su().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Ou=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}})),ku=n((e=>{var t=Cu(),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}}})),Au=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]]}})),ju=n((e=>{var t=Au();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}})),Mu=n(((e,t)=>{var n=ju();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})),Nu=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Pu=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)}})),Fu=n((e=>{var t=Nu(),n=Pu();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}}})),Iu=n((e=>{var t=Su(),n=ku(),r=Cu(),i=Fu(),a=Nu(),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}})),Lu=n((e=>{var t=Su(),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}})),Ru=n(((e,t)=>{var n=Fu();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})),zu=n(((e,t)=>{var n=Fu(),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})),Bu=n(((e,t)=>{var n=Fu();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})),Vu=n(((e,t)=>{var n=Fu(),r=Su();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})),Hu=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)})),Uu=n((e=>{var t=Fu(),n=Ru(),r=zu(),i=Bu(),a=Vu(),o=Pu(),s=Su(),c=Hu();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()))}})),Wu=n((e=>{var t=Su(),n=Cu(),r=wu(),i=Tu(),a=Eu(),o=Du(),s=Ou(),c=ku(),l=Mu(),u=Iu(),d=Lu(),f=Fu(),p=Uu();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)}})),Gu=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}}})),Ku=n((e=>{var t=Gu();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)}})),qu=n((e=>{var t=Gu();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}})),Ju=n((e=>{var t=xu(),n=Wu(),r=Ku(),i=qu();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 Yu(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function Xu({state:e,onAcknowledge:t}){let{t:n}=z(),{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)(ct,{open:e.open,onOpenChange:e=>{},children:(0,Y.jsxs)(Ct,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,Y.jsx)(Ut,{children:r.description}):null]}),(0,Y.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,Y.jsx)(Zu,{field:e,value:e.path===``?i:Yu(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,Y.jsx)(An,{children:(0,Y.jsx)(G,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function Zu({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)(ed,{value:t}):null,a===`code-list`?(0,Y.jsx)(td,{value:t}):null,a===`secret`?(0,Y.jsx)(nd,{value:t}):null,a===`text`?(0,Y.jsx)(rd,{value:t}):null,a===`json`?(0,Y.jsx)(id,{value:t}):null]})}function Qu(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 $u({value:e,label:t}){let{copy:n,copied:r}=Qu(e);return(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,Y.jsx)(ti,{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 ed({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,Ju.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)($u,{value:e})]})]})}function td({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)($u,{value:e})]},`${t}-${e}`))})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)($u,{value:t,label:`Copy all`})})]})}function nd({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)(Ye,{className:`w-4 h-4`}):(0,Y.jsx)(tt,{className:`w-4 h-4`})}),(0,Y.jsx)($u,{value:e})]})}function rd({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)($u,{value:e})]})}function id({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)($u,{value:t})})]})}function ad(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function od({state:e,authFetch:t,baseUrl:n,onClose:r,onComplete:i}){let[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),[d,f]=(0,J.useState)({}),[p,m]=(0,J.useState)(!1);if((0,J.useEffect)(()=>{e&&(o(e.screen),c(e.runId),u(e.flowName),f(ad(e.screen)))},[e]),!e||!a)return null;let h=(e,t)=>f(n=>({...n,[e]:t}));return(0,Y.jsx)(ct,{open:!0,onOpenChange:e=>{!e&&!p&&r()},children:(0,Y.jsxs)(Ct,{className:`sm:max-w-md`,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:a.title||`Input`}),a.description&&(0,Y.jsx)(Ut,{children:a.description})]}),(0,Y.jsx)(`div`,{className:`space-y-4 py-2`,children:a.fields.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(W,{htmlFor:`ff-${e.name}`,className:`text-sm`,children:[e.label||e.name,e.required&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:` *`})]}),(0,Y.jsx)(sd,{field:e,value:d[e.name],onChange:t=>h(e.name,t)})]},e.name))}),(0,Y.jsxs)(An,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:r,disabled:p,children:`Cancel`}),(0,Y.jsx)(G,{onClick:async()=>{let e=a.fields.filter(e=>e.required&&(d[e.name]===void 0||d[e.name]===``||d[e.name]===null));if(e.length){q.error(`Please fill: ${e.map(e=>e.label||e.name).join(`, `)}`);return}m(!0);try{let e=await t(`${n}/api/v1/automation/${encodeURIComponent(l)}/runs/${encodeURIComponent(s)}/resume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({inputs:d})}),r=await e.json().catch(()=>null);if(!e.ok||r?.success===!1){q.error(r?.error||`Resume failed (HTTP ${e.status})`);return}let a=r?.data??{};if(a.success===!1||a.status===`failed`){q.error(a.error||`The flow failed to complete.`);return}a.status===`paused`&&a.screen?(o(a.screen),c(a.runId||s),f(ad(a.screen)),q.success(`Saved — next step`)):(q.success(`Done`),i())}catch(e){q.error(e.message)}finally{m(!1)}},disabled:p,children:p?`Submitting…`:`Submit`})]})]})})}function sd({field:e,value:t,onChange:n}){let r=`ff-${e.name}`,i=(e.type||`text`).toLowerCase();if(Array.isArray(e.options)&&e.options.length>0)return(0,Y.jsxs)(Pn,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,Y.jsx)(nr,{id:r,children:(0,Y.jsx)(bt,{placeholder:e.placeholder||`Select…`})}),(0,Y.jsx)(wo,{children:e.options.map((e,t)=>(0,Y.jsx)(We,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,Y.jsx)(mt,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,Y.jsx)(Cn,{id:r,value:t??``,placeholder:e.placeholder,onChange:e=>n(e.target.value)});let a=i===`number`||i===`currency`?`number`:i===`email`?`email`:i===`date`?`date`:`text`;return(0,Y.jsx)(U,{id:r,type:a,value:t??``,placeholder:e.placeholder,onChange:e=>n(a===`number`?e.target.value===``?void 0:Number(e.target.value):e.target.value)})}function cd(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 ld(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??cd(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 ud(e,t){return Array.isArray(e)?e.map(e=>ld(e,t)):[]}function dd(){return`${``.replace(/\/$/,``)}/api/v1`}async function fd(e,t){let n=await fetch(`${dd()}${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 pd(e,t,n){let[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(!0),[s,c]=(0,J.useState)([]),l=(0,J.useRef)(!1),u=(0,J.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{c((await fd(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`))?.data??[]),o(!0)}catch(e){(e?.status===404||e?.status===501)&&(l.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,J.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,J.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,J.useMemo)(()=>s.length===0?null:[...s].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[s]),p=!!d&&!!n&&(d.pending_approvers??[]).includes(n),m=(0,J.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await fd(`/approvals/requests/${encodeURIComponent(d.id)}/${e}`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...t?.comment?{comment:t.comment}:{}})});return await u(),r?.request},[d,n,u]);return{loading:r,available:a,pendingRequest:d,latestRequest:f,canDecide:p,approve:(0,J.useCallback)(e=>m(`approve`,e),[m]),reject:(0,J.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}var md=t({RecordDetailView:()=>xd}),hd={id:`current-user`,name:`Demo User`},gd=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),_d=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),vd=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],yd=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function bd(e,t){if(yd.has(t?.type))return!0;let n=e.toLowerCase();return vd.some(e=>n===e||n.endsWith(`_${e}`))}function xd({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}=au(),{user:h}=w(),g=s(),_=o().state?.from,{t:v}=z(),{objectLabel:y,viewLabel:b,sectionLabel:x,actionLabel:S,actionConfirm:C,actionSuccess:T,fieldLabel:E,fieldOptionLabel:O}=Cr(),{isFavorite:k,toggleFavorite:A,refreshLabel:j}=ec(),{addRecentItem:ee}=jo(),[te,M]=(0,J.useState)(!0),[ne,N]=(0,J.useState)([]),[P,re]=(0,J.useState)([]),[ae,F]=(0,J.useState)(0),[oe,se]=(0,J.useState)(null),[le,ue]=(0,J.useState)({}),[de,fe]=(0,J.useState)(null),[pe,I]=(0,J.useState)(!1),[ge,_e]=(0,J.useState)(),L=t.find(e=>e.name===d);Us(c?void 0:ge);let R=p,ye=dl(d,R),xe=(0,J.useMemo)(()=>!d||!R?null:{id:`record:${d}:${R}`,label:ge||R||``,href:`/apps/${u}/${d}/record/${R}`,type:`record`},[u,d,R,ge]),Se=xe?k(xe.id):!1,Ce=(0,J.useCallback)(()=>{xe&&A(xe)},[xe,A]),{page:Te,slots:Ee}=we(d),De=(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 L?.detail?.renderViaSchema!==!1},[L]),Oe=(0,J.useMemo)(()=>Te||!L||!De&&!Ee?null:Uo(L,Ee?{slots:Ee}:void 0),[De,Te,Ee,L]),ke=Te||Oe,[Ae,je]=(0,J.useState)(null),[Me,Ne]=(0,J.useState)(`idle`);(0,J.useEffect)(()=>{let t=!1;if(!ke||!R||!d||!e?.findOne){je(null),Ne(`idle`);return}let n=be(L?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{Ne(`loading`),(r?e.findOne(d,R,r):e.findOne(d,R)).then(e=>{t||(e&&typeof e==`object`?(je(e),Ne(`loaded`)):(je(null),Ne(`missing`)))}).catch(()=>{t||(je(null),Ne(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==d||String(t.recordId)!==String(R)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[ke,d,R,e,L]),(0,J.useEffect)(()=>{if(!Ae||typeof Ae!=`object`||!L)return;let e=Uc(L,Ae);e&&e!==`Untitled`&&e!==ge&&_e(e)},[Ae,L,ge]),(0,J.useEffect)(()=>{if(!d||!R||!u||!ge)return;let e=`record:${d}:${R}`;ee({id:e,label:ge,href:`/apps/${u}/${d}/record/${R}`,type:`record`}),j(e,ge)},[u,d,R,ge,ee,j]);let[Pe,Fe]=(0,J.useState)({open:!1,message:``}),[Ie,Le]=(0,J.useState)({open:!1,params:[]}),[Re,ze]=(0,J.useState)({open:!1}),Be=(0,J.useCallback)((e,t)=>new Promise(n=>{ze({open:!0,spec:e,data:t,resolve:n})}),[]),Ve=(0,J.useCallback)((e,t)=>new Promise(n=>{Fe({open:!0,message:e,options:t,resolve:n})}),[]),He=(0,J.useCallback)(e=>new Promise(n=>{Le({open:!0,params:ud(e,{objectName:d||L?.name||``,objects:t||[],fieldLabel:E,fieldOptionLabel:O}),resolve:n})}),[d,L,t,E,O]),Ue=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),We=(0,J.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):g(e)},[g]),Ge=(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,R,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(d,R,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(d,R,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(d,R,r);break}let i=t.refreshAfter===!0;return i&&F(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,d,R]),Ke=(0,J.useMemo)(()=>D(),[]),qe=(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 Ke(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:R,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=r?.data??{};if(i.status===`paused`&&i.screen)return se({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&F(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Ke,R,d]),B=(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`)}catch{r=null}try{let i=e.objectName||d||`global`,a=await Ke(`/api/v1/actions/${encodeURIComponent(i)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:R,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&&F(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`)}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}}},[Ke,R,d]),Je=pd(d,R,h?.id),Ye=(0,J.useRef)(Je);Ye.current=Je;let Xe=(0,J.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await Ye.current.approve({comment:n.comment});else if(t===`reject_request`)await Ye.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return F(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Ze=(0,J.useMemo)(()=>{if(!L||!t)return[];let e=new Set([`created_by`,`updated_by`,`owner_id`]),n=[],r=new Set;for(let i of t)if(i.name!==L.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)===L.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},[L,t]);(0,J.useEffect)(()=>{if(!e||!R||Ze.length===0)return;let t=!1;return Promise.all(Ze.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:R}}).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;ue(n)}),()=>{t=!0}},[e,R,Ze]);let Qe=(0,J.useMemo)(()=>!L||L.name===`sys_audit_log`||L.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[L,t]);(0,J.useEffect)(()=>{if(!e||!R||!L||!Qe){fe(null);return}let t=!1;return I(!0),e.find(`sys_audit_log`,{$filter:{record_id:R,object_name:L.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(L.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};fe(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),fe([]))}).finally(()=>{t||I(!1)}),()=>{t=!0}},[e,R,L,Qe]),(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))];re(o.length>0?o:n)}catch{if(t)return;re(n)}})(),()=>{t=!0}},[e,h?.id,h?.name,h?.email]);let $e=(0,J.useMemo)(()=>h?{id:h.id,name:h.name,avatar:h.image}:hd,[h?.id,h?.name,h?.image]);(0,J.useEffect)(()=>{if(!e||!d||!R)return;let t=`${d}:${R}`,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($e.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)}));N(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:R},$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&&N(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,R,$e]);let et=(0,J.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:$e.name,actorAvatarUrl:`avatar`in $e?$e.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(N(e=>[...e,n]),e){let r=`${d}:${R}`,i=Bo(t,P);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:$e.id,author_name:$e.name,author_avatar_url:`avatar`in $e?$e.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[$e,e,d,R,P]),tt=(0,J.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:$e.name,actorAvatarUrl:`avatar`in $e?$e.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(N(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${d}:${R}`,a=Bo(n,P);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:$e.id,author_name:$e.name,author_avatar_url:`avatar`in $e?$e.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[$e,e,d,R,P]),nt=(0,J.useCallback)((t,n)=>{N(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=$e.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}))},[$e.id,e]);(0,J.useEffect)(()=>{M(!0),queueMicrotask(()=>M(!1))},[d,p]);let rt=(0,J.useMemo)(()=>{if(!L)return{type:`detail-view`};let n=L.primaryField||Object.keys(L.fields||{}).find(e=>e===`name`||e===`title`),r=L.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?x(L.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!L.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=L.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${L.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(L.fields||{}).filter(e=>!gd.has(e)&&!_d.has(e)&&!L.fields[e]?.hidden),t=e=>{let t=L.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=>!bd(e,L.fields[e])),r=e.filter(e=>bd(e,L.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(L.name,`details`,v(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(L.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(L.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(L.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(L.name,e.name,e.successMessage)}}));if(Je.available&&Je.canDecide){let e={name:`comment`,label:v(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:v(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`default`,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:v(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:v(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,locations:[`record_header`],refreshAfter:!0,confirmText:v(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:v(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),o=L.views?.detail?.highlightFields??[],s=L.views?.detail?.sectionGroups??L.views?.form?.sectionGroups,l=u?`/apps/${u}`:``,d=Ze.map(({childObject:n,childLabel:r,referenceField:i})=>{let a=t.find(e=>e.name===n),o=R||``,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`})),ue(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:le[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=gu(L);return{type:`detail-view`,objectName:L.name,resourceId:R,showBack:!c,onBack:`history`,showEdit:f.edit,title:L.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...Qe&&{history:{entries:de??[],loading:pe&&de===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}]}}},[L?.name,R,le,ae,u,g,e,v,y,t,Qe,de,pe,Je.available,Je.canDecide,Je.pendingRequest,Je.latestRequest,c]);if(te)return(0,Y.jsx)(mu,{});if(!L)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(at,{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)(wt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:v(`empty.objectNotFound`)}),(0,Y.jsx)(xt,{children:v(`empty.objectNotFoundDescription`,{name:d})})]})});if(ke&&Me===`missing`)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(at,{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)(wt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:v(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Y.jsx)(xt,{children:v(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(ke){let t=ke?.disableDiscussion===!0,r=vu(ke),a=!t&&!r,o=(()=>{let e=rt.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=gu(L),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:R,objectName:d}}))}}),r.push({name:`sys_edit`,label:v(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:R})})),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,R),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(rt.related)?rt.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=rt.history?{entries:rt.history.entries??[],loading:!!rt.history.loading,emptyText:rt.history.emptyText}:void 0,h=Te?ke:Uo(L,{sections:rt.sections,highlightFields:Array.isArray(rt.highlightFields)?rt.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:l,related:f,history:p,hideReferenceRail:L?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:L?.detail?.hideRelatedTab===!0||void 0,...Ee?{slots:Ee}:{}});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:[ye.length>0&&(0,Y.jsx)(cl,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(fu,{managedBy:L?.managedBy})]}),(0,Y.jsx)(he,{objectName:d,recordId:R,data:Ae,objectSchema:L,dataSource:e,embedded:c,headerSystemActions:s,isFavorite:Se,onToggleFavorite:xe?Ce:void 0,children:(0,Y.jsx)(me,{children:(0,Y.jsx)(ve,{items:ne,onAddComment:et,onAddReply:tt,onToggleReaction:nt,mentionSuggestions:P,children:(0,Y.jsx)(ie,{context:{record:Ae||{},objectName:d,user:$e},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:B,modal:B,approval:Xe},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)(Xi,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:_.label})]}),(0,Y.jsx)(ce,{schema:h}),a&&(0,Y.jsx)(`div`,{className:`mt-6`,children:(0,Y.jsx)(zo,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:et,onAddReply:tt,onToggleReaction:nt,mentionSuggestions:P})})]}),(0,Y.jsx)(iu,{open:m,sections:[{title:`Page Schema`,data:h}]})]})})})})}),(0,Y.jsx)(yu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(bu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(Xu,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(od,{state:oe,authFetch:Ke,baseUrl:``,onClose:()=>se(null),onComplete:()=>{se(null),F(e=>e+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:[ye.length>0&&(0,Y.jsx)(cl,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(fu,{managedBy:L?.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)(ie,{context:{record:{},objectName:d,user:$e},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:B,modal:B,approval:Xe},children:(0,Y.jsx)(Vo,{schema:rt,dataSource:e,objectLabel:y({name:L.name,label:L.label}),isFavorite:Se,onToggleFavorite:xe?Ce:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=Uc(L,e);t&&t!==ge&&t!==`Untitled`&&_e(t)},onEdit:()=>{n({id:R})},discussionSlot:(0,Y.jsx)(zo,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:et,onAddReply:tt,onToggleReaction:nt})},ae)})}),(0,Y.jsx)(iu,{open:m,sections:[{title:`View Schema`,data:rt}]})]}),(0,Y.jsx)(yu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(bu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(Xu,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(od,{state:oe,authFetch:Ke,baseUrl:``,onClose:()=>se(null),onComplete:()=>{se(null),F(e=>e+1)}})]})}function Sd(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 Cd=(0,J.lazy)(()=>c(()=>import(`./plugin-charts-CP4h02tQ.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),wd=(0,J.lazy)(()=>c(()=>import(`./plugin-grid-CIlCwKyp.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Td={grid:_r,kanban:Oi,calendar:Ur,gallery:ot,timeline:Nt,gantt:ya,map:Fn,chart:to},Ed={id:`current-user`,name:`Demo User`};function Dd(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 Od(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 kd(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 Ad({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}=au(),{t:g}=z(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:S,actionSuccess:C,fieldLabel:T,fieldOptionLabel:E}=Cr(),{isFavorite:k,toggleFavorite:A}=ec(),[j,ee]=(0,J.useState)(!1),[te,M]=(0,J.useState)(`edit`),[ne,N]=(0,J.useState)(!1),[P,re]=(0,J.useState)(!1),[ae,oe]=(0,J.useState)(null),se=(0,J.useRef)({}),le=(0,J.useRef)({}),ue=(0,J.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!c||!t)return;let i=le.current[t]||{};le.current[t]={...i,...r};let a=se.current[t];a&&clearTimeout(a),se.current[t]=setTimeout(()=>{let r=le.current[t]||{};delete le.current[t],delete se.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),de=(0,J.useCallback)(t=>{if(oe(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]),fe=(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=Od(l,c,{defaultColumns:o}),n=await e.create(`sys_view`,t);r=n?.id??n?._id}}ee(!1),M(`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]),[pe,me]=(0,J.useState)(void 0),{user:I,activeOrganization:he}=w(),ge=I?.role===`admin`,{can:_e}=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)(at,{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)(_r,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:g(`console.objectView.objectNotFound`)}),(0,Y.jsxs)(xt,{children:[g(`console.objectView.objectNotFoundDescription`,{objectName:c}),` `,g(`console.objectView.objectNotFoundHint`)]})]})});let[ve,R]=(0,J.useState)(0),[ye,be]=(0,J.useState)(null),xe=(0,J.useMemo)(()=>gu(L),[L]);(0,J.useEffect)(()=>{r===void 0||r===0||R(e=>e+1)},[r]);let[Se,Ce]=(0,J.useState)(!1),[we,Te]=(0,J.useState)([]);(0,J.useEffect)(()=>{let t=!1;if(!c){Te([]);return}if(typeof e?.listViews==`function`)return e.listViews(c).then(e=>{t||Te((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||Te([])}),()=>{t=!0};if(!e?.find){Te([]);return}return e.find(`sys_view`,{$filter:[`object_name`,`=`,c],$orderby:[{field:`created_at`,order:`asc`}],$top:200}).then(e=>{t||Te((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(kd))}).catch(e=>{console.error(`[ObjectView] Failed to load sys_view records:`,e),t||Te([])}),()=>{t=!0}},[e,c,ve]);let[Ee,De]=(0,J.useState)({});(0,J.useEffect)(()=>{let t=!1;if(!e||!c){De({});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){De({});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||De(e)}),()=>{t=!0}},[e,c,L.listViews,L.list_views,L.list,ve]);let Oe=(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=Ee[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=Ee[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 we){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=we.find(t=>(t.id||t._id)===e.id),a=we.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,we,Ee,g]),ke=(0,J.useMemo)(()=>Oe.find(e=>e.isDefault)?.id,[Oe]),Ae=u||d.get(`view`)||ke||Oe[0]?.id,je=Oe.find(e=>e.id===Ae)||Oe[0],Me=ae&&ae.id===je?.id?{...je,...ae}:je,Ne=(0,J.useCallback)((e,t)=>{oe(n=>({...n||{},id:je?.id,[e]:t}))},[je?.id]),Pe=e=>{let t=Oe.find(t=>t.id===e);t&&(t.id!==Ae&&ee(!1),u?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Fe=(0,J.useMemo)(()=>(Oe||[]).map(e=>{let t=Td[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}}),[Oe,L.name,y]);wl({views:Fe,activeViewId:Ae??``,onChange:Pe,enabled:Fe.length>0&&!!Ae});let Ie=(0,J.useCallback)(()=>{N(!0)},[]),Le=(0,J.useCallback)((e,t)=>{if(e===`settings`){let e=Oe.find(e=>e.type===t);e&&Pe(e.id),M(`edit`),ee(!0)}},[Oe,Pe]),Re=(0,J.useCallback)(e=>we.some(t=>(t.id||t._id)===e),[we]),ze=(0,J.useCallback)(async(t,n)=>{if(!Re(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,Re,g]),[Be,Ve]=(0,J.useState)({open:!1,message:``}),[He,Ue]=(0,J.useState)({open:!1,params:[]}),[We,Ge]=(0,J.useState)({open:!1}),Ke=(0,J.useCallback)((e,t)=>new Promise(n=>{Ge({open:!0,spec:e,data:t,resolve:n})}),[]),qe=(0,J.useCallback)((e,t)=>new Promise(n=>{Ve({open:!0,message:e,options:t,resolve:n})}),[]),B=(0,J.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;Ue({open:!0,params:ud(e,{objectName:c||L?.name||``,objects:t||[],fieldLabel:T,fieldOptionLabel:E,row:i}),resolve:r})}),[c,L,t,T,E]),Je=(0,J.useCallback)(async t=>{if(!e)return;if(!Re(t)){q.error(g(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Oe.find(e=>e.id===t)?.label||t;if(await qe(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===Ae){let e=Oe.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,Re,Ae,Oe,u,i,g,qe]),Ye=(0,J.useCallback)(async t=>{if(!e)return;let n=Oe.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=Od(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,Oe,c,i,u]),Xe=(0,J.useCallback)(async(t,n)=>{if(e){if(!Re(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,Re,g]),Ze=(0,J.useCallback)(async t=>{if(e){if(!Re(t)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to mark a default.`);return}try{let n=typeof e?.updateView==`function`,r=we.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,we,Re,g]),Qe=(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(we.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,we,c]),$e=(0,J.useCallback)(e=>{if(!Re(e)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==Ae&&Pe(e),M(`edit`),ee(!0)},[Ae,Pe,Re,g]),et=(0,J.useCallback)(()=>{N(!0)},[]),tt=I?{id:I.id,name:I.name,avatar:I.image}:Ed,nt=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),rt=zs({objectName:L.name,objectLabel:L.label,dataSource:e,onEdit:n,onRefresh:()=>R(e=>e+1),onConfirm:qe,onToast:nt}),it=(0,J.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):i(e)},[i]),ot=(0,J.useMemo)(()=>D(),[]),st=(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&&he?.id&&(c.organizationId=he.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 ot(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,ot,he]),ct=(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=n._rowRecord;delete n._rowRecord;let i=n.recordId??r?.id;i!=null&&n.recordId==null&&(n.recordId=i);let a=await ot(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:i,objectName:L.name,params:n})}),o=await a.json().catch(()=>null);if(!a.ok||o&&o.success===!1)return{success:!1,error:o?.error||`Flow "${t}" failed (HTTP ${a.status})`};let s=o?.data??{};if(s.status===`paused`&&s.screen)return be({flowName:t,runId:s.runId,screen:s.screen}),{success:!0};let c=e.refreshAfter!==!1;return c&&R(e=>e+1),{success:!0,data:o?.data,reload:c}}catch(e){return{success:!1,error:e.message}}},[ot,L.name]),lt=(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=n._rowRecord;delete n._rowRecord;let i=e.recordIdField||`id`,a=n.recordId??r?.[i],o=null;if(e.opensInNewTab)try{o=window.open(`about:blank`,`_blank`)}catch{o=null}try{let r=e.objectName||L.name||`global`,i=await ot(`/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,params:n})}),s=await i.json().catch(()=>null);if(!i.ok||s&&s.success===!1){let e=s?.error||`Action "${t}" failed (HTTP ${i.status})`;if(o)try{o.close()}catch{}return{success:!1,error:e}}let c=e.refreshAfter!==!1;c&&R(e=>e+1);let l=s?.data,u=l&&typeof l==`object`&&typeof l.redirectUrl==`string`?l.redirectUrl:null;if(u)if(o)try{o.location.href=u}catch{try{o.close()}catch{}window.location.href=u}else{let e=null;try{e=window.open(u,`_blank`)}catch{e=null}e||(window.location.href=u)}else if(o)try{o.close()}catch{}return{success:!0,data:l,reload:c}}catch(e){if(o)try{o.close()}catch{}return{success:!1,error:e.message}}},[ot,L.name]),{lastMessage:ut}=$c({channel:`object:${L.name}`}),{hasConflicts:dt,resolveAllConflicts:ft}=il(L.name?`user-${L.name}`:`current-user`);(0,J.useEffect)(()=>{ut&&(dt&&ft(`remote`),R(e=>e+1))},[ut,dt,ft]),(0,J.useEffect)(()=>{e?.find&&L.name&&e.find(L.name,{limit:0}).then(e=>{typeof e?.total==`number`?me(e.total):Array.isArray(e?.data)?me(e.data.length):Array.isArray(e)&&me(e.length)}).catch(()=>{})},[e,L.name,ve]);let pt=(0,J.useMemo)(()=>Me?.navigation??L.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Me?.navigation,L.navigation]),mt=d.get(`recordId`),ht=(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()]),gt=(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,Me?.name??``,Me?.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,Me?.name,Me?.label,y,_]),_t=F({navigation:pt,objectName:L.name,onNavigate:gt}),vt=()=>{_t.close();let e=new URLSearchParams(d);e.delete(`recordId`),p(e)},yt=(0,J.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){_t.handleClick(e,t);return}if(_t.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),p(e);return}}_t.handleClick(e,t)},[_t,d,p]),bt=(0,J.useCallback)(()=>{let e=_t.selectedRecord,t=e&&(e.id??e._id);t!=null&&(vt(),gt(t))},[_t.selectedRecord,gt]);(0,J.useEffect)(()=>{mt&&!_t.isOpen?_t.open({id:mt}):!mt&&_t.isOpen&&_t.close()},[mt]);let St=(0,J.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=ve+(i||0),o=`${c}-${Me.id}-${a}`,s=Me;if(s.type===`chart`){let e=s.chart||{},n=e.xAxisField||`name`,r=Array.isArray(e.yAxisFields)&&e.yAxisFields[0]||`value`,i=e.aggregation||`count`,a=e.series&&e.series.length>0?e.series:[{dataKey:r,label:r}];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)(Cd,{dataSource:t,schema:{type:`object-chart`,objectName:L.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},o)}return(0,Y.jsx)(Ho,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=Dd(s.filter??e.filter,tt.id);return ht.length?[...Array.isArray(t)?t:[],...ht]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{ue(s.id,s,{densityMode:e})},onSortChange:e=>{ue(s.id,s,{sort:e})},onFilterChange:e=>{ue(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{ue(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{ue(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`)).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)}})):[],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??Sd(L?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=Dd([...Array.isArray(s.filter)?s.filter:[],...ht],tt.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&&rt.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&rt.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)=>{yt(e,t)},onSortChange:e=>{ue(s.id,s,{sort:e})},onFilterChange:e=>{ue(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{ue(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{ue(s.id,s,{columnState:e})},dataSource:t},o)},[Me,L,c,ve,_t,rt,ue,ht]),Ct=(0,J.useMemo)(()=>Oe.map(e=>e.id===Ae&&ae&&ae.id===e.id?{...e,...ae}:e),[Oe,Ae,ae]),wt=(0,J.useMemo)(()=>({type:`object-view`,objectName:L.name,layout:`page`,showSearch:Me?.showSearch!==!1,showFilters:Me?.showFilters!==!1,showSort:Me?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:ge,viewActions:ge?[{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,Me?.name??``,Me?.label??``)||_(L)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[L,n,Me?.showSearch,Me?.showFilters,Me?.showSort,Me?.name,Me?.label,i,u,ge,m.pathname,m.search,y,_]);return(0,Y.jsxs)(ie,{context:{objectName:L.name,user:tt,apiBase:``,activeOrganization:he?{id:he.id,slug:he.slug,name:he.name}:null},onConfirm:qe,onToast:nt,onNavigate:it,onParamCollection:B,onResultDialog:Ke,handlers:{api:st,flow:ct,script:lt,modal:lt},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)(Vl,{title:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:_(L)}),(0,Y.jsx)(fu,{managedBy:L?.managedBy})]}),description:L.description?v(L):void 0,icon:(0,Y.jsx)(Ac(L?.icon),{className:`h-4 w-4`}),actions:(0,Y.jsxs)(Y.Fragment,{children:[c&&(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>A({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)(ii,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)(za,{className:`h-4 w-4`})}),xe.create&&_e(L.name,`create`)&&(0,Y.jsxs)(G,{size:`sm`,onClick:rt.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Y.jsx)(K,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),xe.import&&_e(L.name,`create`)&&(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>Ce(!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)($t,{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)(ce,{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}})]})})}),xe.create&&_e(L.name,`create`)&&(0,Y.jsx)(`button`,{type:`button`,onClick:rt.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)(K,{className:`h-5 w-5`})}),Se&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(wd,{open:Se,onOpenChange:Ce,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}))}})}),Oe.length>=1&&(()=>{let e=Oe.map(e=>{let t=we.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)(is,{views:e,activeViewId:Ae,onViewChange:Pe,viewTypeIcons:Td,config:{reorderable:!1,showAddButton:ge,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:ge?et:void 0,onRenameView:ge?ze:void 0,onDeleteView:ge?Je:void 0,onDuplicateView:ge?Ye:void 0,onPinView:ge?Xe:void 0,onSetDefaultView:ge?Ze:void 0,onConfigView:ge?$e:void 0,onManageViews:ge?()=>re(!0):void 0}),ge&&(0,Y.jsx)(Qo,{open:P,onOpenChange:re,views:e,activeViewId:Ae,viewTypeIcons:Td,onRename:ze,onDelete:Je,onDuplicate:Ye,onSetDefault:Ze,onSetPinned:Xe,onReorder:Qe,onAddView:et,onConfigView:$e})]})})})(),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[_t.mode===`split`&&_t.isOpen?(0,Y.jsx)(tn,{..._t,setIsOpen:e=>{e||vt()},title:_(L),onExpand:bt,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)(ts,{schema:wt,dataSource:e,views:Ct,activeViewId:Ae,onViewChange:Pe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{yt(e,t)},renderListView:St,onCreateView:Ie,onViewAction:Le})})}),typeof pe==`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:pe})})]}),children:r=>{let i=r.id||r._id;return(0,Y.jsx)(xd,{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)(ts,{schema:wt,dataSource:e,views:Ct,activeViewId:Ae,onViewChange:Pe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{yt(e,t)},renderListView:St,onCreateView:Ie,onViewAction:Le})})})}),(0,Y.jsx)(iu,{open:h&&ge,sections:[{title:`View Configuration`,data:Me},{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 ${j&&ge?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Y.jsx)(ou,{open:j&&ge,onClose:()=>{ee(!1),M(`edit`)},mode:te,activeView:Me,objectDef:L,recordCount:pe,onSave:de,onViewUpdate:Ne,onCreate:fe})}),(0,Y.jsx)(uu,{open:ne&&ge,onOpenChange:N,existingLabels:Oe.map(e=>e.label).filter(Boolean),objectDef:L,onCreate:e=>fe(e)})]}),_t.mode!==`split`&&(0,Y.jsx)(tn,{..._t,setIsOpen:e=>{e||vt()},title:_(L),onExpand:bt,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)(xd,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}})]}),(0,Y.jsx)(yu,{state:Be,onOpenChange:e=>{e||Ve({open:!1,message:``})}}),(0,Y.jsx)(bu,{state:He,onOpenChange:e=>{e||Ue({open:!1,params:[]})}}),(0,Y.jsx)(Xu,{state:We,onAcknowledge:()=>{We.resolve?.(),Ge({open:!1})}}),(0,Y.jsx)(od,{state:ye,authFetch:ot,baseUrl:``,onClose:()=>be(null),onComplete:()=>{be(null),R(e=>e+1)}})]})}var jd=t({RecordFormPage:()=>Md});function Md({mode:e}){let{appName:t,objectName:n,recordId:r}=f(),a=s(),[o]=l(),c=le(),{objects:u,loading:d}=re(),{t:p}=z(),{objectLabel:m}=Cr(),{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]),A=(0,J.useMemo)(()=>h?{name:h.name,email:h.email,role:h.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[h]),j=(0,J.useMemo)(()=>new ge({user:A,app:{name:t},data:{}}),[A,t]),ee=(0,J.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:Rs(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>Rs(e.visible,j)).map(([e])=>e):[],[b,j]);return d?(0,Y.jsx)(mu,{}):b?(0,Y.jsx)(Is,{user:A,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)(Jn,{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)(fu,{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)(Jo,{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:ee,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)(at,{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)(wt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:p(`empty.objectNotFound`)}),(0,Y.jsx)(xt,{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)(Jn,{className:`mr-2 h-4 w-4`}),p(`empty.back`)]})})]})})}var Nd=t({DashboardView:()=>Ud}),Pd=[{type:`metric`,label:`KPI Metric`,Icon:Tt},{type:`bar`,label:`Bar Chart`,Icon:to},{type:`line`,label:`Line Chart`,Icon:Ar},{type:`pie`,label:`Pie Chart`,Icon:na},{type:`table`,label:`Table`,Icon:fr},{type:`pivot`,label:`Pivot`,Icon:ot}],Fd=0;function Id(){return Fd+=1,`widget_${Date.now()}_${Fd}`}function Ld(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:Id()})}}function Rd(e){let t=Pd.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var zd=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function Bd(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 Vd(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))zd.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 Hd(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 Ud({dataSource:e}){let{dashboardName:t}=f(),{showDebug:n}=au(),r=le(),{t:i}=z(),{dashboardLabel:a,dashboardDescription:o}=Cr(),[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}=re(),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(Ld(w)),u(!0),h(e=>e+1)},[w]),k=(0,J.useCallback)(()=>{u(!1),p(null)},[]),A=(0,J.useCallback)(e=>{if(!T)return;let t=Id(),n={id:t,title:Rd(e),type:e,layout:{x:0,y:T.widgets?.length??0,w:T.columns??2,h:1}},r={...T,widgets:[...T.widgets||[],n]};E(r),D(r),p(t),h(e=>e+1)},[T,D]),j=(0,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]),ee=(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)(()=>Hd(T||w),[m]),M=(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]),ne=(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]),N=T?.widgets?.find(e=>e.id===d),P=(0,J.useMemo)(()=>N?Bd(N):{},[d,m]),ie=(0,J.useCallback)(e=>{if(!T||!d||!N)return;let t=Vd(e,N),n={...T,widgets:T.widgets.map(e=>e.id===d?{...e,...t}:e)};E(n),D(n),h(e=>e+1)},[T,d,N,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=Bd(r);i[e]=t;let a=Vd(i,r);return{...n,widgets:n.widgets.map(e=>e.id===d?{...e,...a}:e)}})},[d]),F=(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=N?.object;if(!e||!S?.length)return;let t=S.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.filter(e=>e.name).map(e=>({value:e.name,label:e.label||e.name})):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e}))},[N?.object,S]),se=(0,J.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),ce=T||w,ue=(0,J.useMemo)(()=>{if(!ce||se.size===0)return ce;let e=ce.widgets;if(!Array.isArray(e)||e.length===0)return ce;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?se.has(t):!0});return t.length===e.length?ce:{...ce,widgets:t}},[ce,se]);return s?(0,Y.jsx)(pu,{}):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=Rc((ue||w).title,i),t=Rc(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:Rc(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:Pd.map(({type:e,label:t,Icon:n})=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>A(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,Y.jsx)(K,{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)(Ft,{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)(ls,{schema:ue,dataSource:e,designMode:l,selectedWidgetId:d,onWidgetClick:p,onWidgetsReorder:ee,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),N?(0,Y.jsx)(us,{open:l,onClose:k,config:P,onSave:ie,onFieldChange:ae,availableObjects:F,availableFields:oe,headerExtra:(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>j(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)(Mn,{className:`h-3.5 w-3.5`})})},d):(0,Y.jsx)(ds,{open:l,onClose:k,config:te,onSave:M,onFieldChange:ne}),(0,Y.jsx)(iu,{open:n,sections:[{title:`Dashboard Configuration`,data:ue}]})]}),g&&g.schema?.objectName?(0,Y.jsx)(Ko,{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)(ct,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,Y.jsx)(Ut,{children:g.schema.description})]}),(0,Y.jsxs)(An,{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)(at,{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)(St,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:i(`empty.dashboardNotFound`)}),(0,Y.jsx)(xt,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Wd=t({PageView:()=>Gd});function Gd(){let{t:e}=z(),{pageName:t}=f(),[n]=l(),{showDebug:r}=au(),{pages:i}=re(),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)(at,{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)($a,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:e(`empty.pageNotFound`)}),(0,Y.jsx)(xt,{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)(ce,{schema:{...a,type:a.type||`page`,context:{...a.context,params:o}}})}),(0,Y.jsx)(iu,{open:r,sections:[{title:`Page Configuration`,data:a}]})]})}var Kd=t({ReportView:()=>Zd}),qd=(0,J.lazy)(()=>c(()=>import(`./plugin-report-AhX1YoV8.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),Jd=(0,J.lazy)(()=>c(()=>import(`./plugin-report-AhX1YoV8.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),Yd=(0,J.lazy)(()=>c(()=>import(`./plugin-report-AhX1YoV8.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),Xd=[{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 Zd({dataSource:e}){let{t}=z(),{reportName:n}=f(),{showDebug:r}=au(),i=le(),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(0),{reports:l,objects:u,loading:d,refresh:p}=re(),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)??Xd},[_,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]),A=(0,J.useCallback)((e,t)=>{v(n=>({...n,[e]:t}))},[]);(0,J.useEffect)(()=>{g(m)},[m]),(0,J.useEffect)(()=>{a||v(null)},[m]);let j=_||h,ee=(0,J.useMemo)(()=>JSON.stringify(j?.filters),[j?.filters]),te=(0,J.useMemo)(()=>JSON.stringify(j?.dataSource),[j?.dataSource]),M=(0,J.useMemo)(()=>JSON.stringify(j?.data),[j?.data]);if((0,J.useEffect)(()=>{if(!j||!e){b([]);return}if(j.data&&Array.isArray(j.data)){b(j.data);return}if(j.dataSource){(async()=>{S(!0);try{let t=j.dataSource.object||j.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),b([]);return}b((await e.find(t,{$filter:j.dataSource.filter,$orderby:j.dataSource.sort,$top:j.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),b([])}finally{S(!1)}})();return}if(j.objectName){(async()=>{S(!0);try{b((await e.find(j.objectName,{$filter:j.filters,$orderby:j.sort,$top:j.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),b([])}finally{S(!1)}})();return}b([])},[j?.objectName,j?.limit,ee,te,M,e]),d)return(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsx)(B,{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)(at,{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)(to,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(bo,{children:t(`empty.reportNotFound`)}),(0,Y.jsx)(xt,{children:t(`empty.reportNotFoundDescription`,{name:n})})]})}):(0,Y.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Y.jsx)(B,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let ne=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?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},N=_||h,P=!!(N&&N.objectName&&(N.type===`matrix`||N.type===`joined`||N.type===`summary`||N.type===`tabular`||N.type===void 0||Array.isArray(N.groupingsAcross)&&N.groupingsAcross.length>0||Array.isArray(N.columns))),ie={type:`report-viewer`,report:ne(N),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:N.title||N.label||`Report Viewer`}),N.description&&(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:N.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)(Ft,{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:P?(0,Y.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Y.jsx)(Jd,{schema:N,dataSource:e})}):(0,Y.jsx)(qd,{schema:ie})})})}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Yd,{open:a,onClose:D,config:O,onSave:k,onFieldChange:A,availableFields:w,getFieldsForObject:C})}),(0,Y.jsx)(iu,{open:r,sections:[{title:`Report Configuration`,data:N}]})]})]})}var Qd=t({SearchResultsPage:()=>nf});function $d(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...$d(n.children)):t.push(n);return t}var ef={object:wt,dashboard:St,page:$a,report:to},tf={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 nf(){let{t:e}=z(),{appName:t}=f(),[n,r]=l(),[a,o]=(0,J.useState)(n.get(`q`)||``),{apps:s}=re(),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=$d(u.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=Io(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)(Jn,{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)(go,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(U,{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)(go,{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=ef[t]||wt,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)(V,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,Y.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=ef[t.type]||wt,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)(It,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Y.jsxs)(Ca,{className:`flex items-center gap-3 p-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${tf[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)(V,{variant:`outline`,className:`text-xs shrink-0`,children:e(r)})]})})},t.id)})})]},t)})})]})}function rf(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 af(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 of=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=rf(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(af)};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 sf(){let e=le();return(0,J.useMemo)(()=>e?new of(e):null,[e])}var cf=0;function lf(e=`nav`){return`${e}_${Date.now()}_${++cf}`}function uf(e,t){return[...e,t]}function df(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:df(e.children,t,n)}:e)}function ff(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:ff(i.children,t,n,r)}:i})}function pf(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function mf(){let e=le(),{apps:t,refresh:n}=re(),{t:r}=z(),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=uf(a,{id:lf(`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=uf(a,{id:lf(`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=df(i,`page`,t);if(pf(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=df(i,`dashboard`,t);if(pf(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=ff(a,`page`,t,n);if(pf(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=ff(a,`dashboard`,t,n);if(pf(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 hf(){let{pages:e,dashboards:t,apps:n}=re(),r=le(),i=(0,J.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=mf(),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 gf=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function _f(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function vf(e){try{return decodeURIComponent(e)}catch{return e}}function yf({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=jo(),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}:${vf(t)}`,label:vf(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!gf.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:_f(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:_f(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:_f(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var bf=`objectstack:ai-chat-conversation-id`;function xf(e,t){return t?`${bf}:${e}:${t}`:`${bf}:${e}`}function Sf(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Cf(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function wf(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 Tf(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=wf(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function Ef(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 Df(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 Of(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function kf(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=xf(t,n);return u(!0),(async()=>{try{if(i){let n=await Ef(r,i);if(e)return;if(n){Cf(s,n.id),o(n.id),c(Tf(n.messages)),f.current=t;return}Cf(s,void 0)}else{let n=Sf(s);if(n){let i=await Ef(r,n);if(e)return;if(i){o(i.id),c(Tf(i.messages)),f.current=t;return}Cf(s,void 0)}}let n=await Df(r);if(e)return;Cf(s,n.id),o(n.id),c(Tf(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=xf(t,n);u(!0);try{a&&await Of(r,a),Cf(e,void 0);let t=await Df(r);if(Cf(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 Af(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=jf(n.content);if(e)return e}}let t=e[e.length-1];return jf(t?.content)}function jf(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 Mf(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:Af(e.messages)}}function Nf(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(Mf).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 Pf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>md).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Ff=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Nd).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),If=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Wd).then(e=>({default:e.PageView})),void 0,import.meta.url)),Lf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Kd).then(e=>({default:e.ReportView})),void 0,import.meta.url)),Rf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Qd).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),zf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>jd).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),Bf=(0,J.lazy)(()=>c(()=>import(`./ComponentNavView-BSO_oEuH.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Vf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),Hf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),Uf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Wf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Gf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Kf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>MT).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),qf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>VO).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),Jf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>VO).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),Yf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>VO).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),Xf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ip).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),Zf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Gp).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),Qf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>qp).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function $f({appName:e}){let{reviewSeq:t,reviewTarget:n}=bc(),r=s(),i=(0,J.useRef)(t);return(0,J.useEffect)(()=>{if(t===i.current||!n||!e)return;i.current=t;let{type:a,name:o}=n;r(`/apps/${e}/metadata/${encodeURIComponent(a)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,r]),null}function ep({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,J.useState)(`disconnected`),{user:i,getAuthConfig:a}=w(),c=le(),[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}=re(),{t:S}=z(),{objectLabel:C}=Cr(),[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,A]=(0,J.useState)(!1),[j,ee]=(0,J.useState)(null),[te,M]=(0,J.useState)(0),{execute:ne,runner:N}=se();oe({dataSource:c??void 0,onUndo:e=>{q.info(`Undo: ${e.description}`,{duration:4e3}),M(e=>e+1)},onRedo:e=>{q.info(`Redo: ${e.description}`,{duration:3e3}),M(e=>e+1)}}),(0,J.useEffect)(()=>{N.registerHandler(`crud_success`,async e=>(A(!1),M(e=>e+1),q.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),N.registerHandler(`dialog_cancel`,async()=>(A(!1),{success:!0})),N.registerHandler(`navigate_create`,async e=>{let t=Ic({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=Lc({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 P=m.pathname.split(`/`).filter(Boolean)[2];(P===`view`||P===`record`||P===`page`||P===`dashboard`||P===`design`)&&(P=``);let ie=v.find(e=>e.name===P),ae=(0,J.useCallback)(()=>{let e=ie?C(ie):S(`common.record`,{defaultValue:`Record`});ne({type:`crud_success`,params:{message:j?S(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):S(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[ne,j,ie,C,S]),F=(0,J.useCallback)(()=>{ne({type:`dialog_cancel`})},[ne]);yf({pathname:m.pathname,appName:O?.name,objects:v});let ce=e=>{let t=Fc({objectDef:ie,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}ee(e),A(!0)},ue=e=>{p(`/apps/${e}`)},de=(0,J.useMemo)(()=>new ge({user:i?{name:i.name,email:i.email,role:i.role??`user`}:{},app:O||{},data:j||{}}),[i,O,j]);if(!c||b||!T)return(0,Y.jsx)(ql,{});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)(at,{children:[(0,Y.jsx)(bo,{children:S(`empty.noAppsConfigured`)}),(0,Y.jsx)(xt,{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)(ql,{}),children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(qf,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(Xf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Qf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Zf,{})}),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)(hf,{}),(0,Y.jsxs)(Bl,{activeAppName:O.name,activeApp:O,onAppChange:ue,objects:v,connectionState:n,userId:i?.id,children:[(0,Y.jsx)(Hl,{apps:g,activeApp:O,objects:v,onAppChange:ue,dataSource:c}),(0,Y.jsx)(Wl,{}),(0,Y.jsx)(Gl,{}),(0,Y.jsx)($f,{appName:h}),(0,Y.jsx)(ru,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(Xl,{className:`h-full`,children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/`,element:(()=>{let e=ip(O,{currentUserId:i?.id??null});return e?(0,Y.jsx)(_,{to:e,replace:!0}):(0,Y.jsx)(Hf,{})})()}),(0,Y.jsxs)(d,{path:`metadata`,children:[(0,Y.jsx)(d,{index:!0,element:(0,Y.jsx)(Vf,{})}),(0,Y.jsx)(d,{path:`_diagnostics`,element:(0,Y.jsx)(Kf,{})}),(0,Y.jsx)(d,{path:`:type`,element:(0,Y.jsx)(Uf,{})}),(0,Y.jsx)(d,{path:`:type/new`,element:(0,Y.jsx)(Wf,{createMode:!0})}),(0,Y.jsx)(d,{path:`:type/:name`,element:(0,Y.jsx)(Wf,{})}),(0,Y.jsx)(d,{path:`:type/:name/history`,element:(0,Y.jsx)(Gf,{})})]}),(0,Y.jsx)(d,{path:`:objectName`,element:(0,Y.jsx)(Ad,{dataSource:c,objects:v,onEdit:ce,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/new`,element:(0,Y.jsx)(zf,{mode:`create`})}),(0,Y.jsx)(d,{path:`:objectName/view/:viewId`,element:(0,Y.jsx)(Ad,{dataSource:c,objects:v,onEdit:ce,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId`,element:(0,Y.jsx)(Pf,{dataSource:c,objects:v,onEdit:ce},te)}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId/edit`,element:(0,Y.jsx)(zf,{mode:`edit`})}),(0,Y.jsx)(d,{path:`dashboard/:dashboardName`,element:(0,Y.jsx)(Ff,{dataSource:c})}),(0,Y.jsx)(d,{path:`report/:reportName`,element:(0,Y.jsx)(Lf,{dataSource:c})}),(0,Y.jsx)(d,{path:`page/:pageName`,element:(0,Y.jsx)(If,{})}),(0,Y.jsx)(d,{path:`component/:ns/:name/*`,element:(0,Y.jsx)(Bf,{})}),(0,Y.jsx)(d,{path:`component/metadata/directory`,element:(0,Y.jsx)(sp,{mode:`directory`})}),(0,Y.jsx)(d,{path:`component/metadata/resource/*`,element:(0,Y.jsx)(sp,{mode:`resource`})}),(0,Y.jsx)(d,{path:`design/dashboard/:dashboardName`,element:(0,Y.jsx)(Yf,{})}),(0,Y.jsx)(d,{path:`search`,element:(0,Y.jsx)(Rf,{})}),(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(qf,{})}),(0,Y.jsx)(d,{path:`edit-app/:editAppName`,element:(0,Y.jsx)(Jf,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(Xf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Qf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Zf,{})}),e,(0,Y.jsx)(d,{path:`:objectName/:maybeRecordId`,element:(0,Y.jsx)(cp,{})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(lp,{})})]})})})}),ie&&(0,Y.jsx)(Ko,{schema:{type:`object-form`,formType:`modal`,objectName:ie.name,mode:j?`edit`:`create`,recordId:j?.id,title:S(j?`form.editTitle`:`form.createTitle`,{object:C(ie)}),description:S(j?`form.editDescription`:`form.createDescription`,{object:C(ie)}),open:k,onOpenChange:A,layout:`vertical`,fields:ie.fields?Array.isArray(ie.fields)?ie.fields.filter(e=>typeof e==`string`?!0:Rs(e.visible,de)).map(e=>typeof e==`string`?e:e.name):Object.entries(ie.fields).filter(([e,t])=>Rs(t.visible,de)).map(([e])=>e):[],onSuccess:ae,onCancel:F,showSubmit:!0,showCancel:!0,submitText:j?S(`form.update`,{defaultValue:S(`common.save`,{defaultValue:`Save`})}):S(`form.create`,{defaultValue:S(`common.create`,{defaultValue:`Create`})}),cancelText:S(`common.cancel`)},dataSource:c},j?.id||`new`)]})]})}function tp(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=np(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=tp(n.children,t);if(e!==``)return e}}return``}function np(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Io(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function rp(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=rp(n.children,t);if(e)return e}}}function ip(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=np(rp(r,n),t);if(e)return e}return tp(r,t)}var ap=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function op(e){return!e||ap.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function sp({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 cp(){let{objectName:e,maybeRecordId:t}=f(),n=o();return e&&op(t)?(0,Y.jsx)(_,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Y.jsx)(lp,{})}function lp(){let e=s(),{t}=z();return(0,Y.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Y.jsx)(xt,{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 up({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 dp(){let e=s(),{appName:t}=f(),{t:n}=z(),r=t?`/apps/${t}`:`/`;return(0,Y.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,Y.jsx)(It,{children:(0,Y.jsxs)(Ca,{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)($e,{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 fp=`en`;function pp(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function mp(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function hp(e,t,n){if(!e)return;let r=pp(t),i=mp([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),fp]);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 gp(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 _p(e,t){let n=t||fp;return{displayName:hp(e.translations??void 0,n,`displayName`)??gp(e,`displayName`)??e.manifest_id,description:hp(e.translations??void 0,n,`description`)??gp(e,`description`),readme:hp(e.translations??void 0,n,`readme`)??gp(e,`readme`),tagline:hp(e.translations??void 0,n,`tagline`)??gp(e,`tagline`)}}var vp=``.replace(/\/$/,``),yp=`${vp}/api/v1/marketplace`;async function bp(e,t){let n=await fetch(`${yp}${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 xp(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 bp(`/packages${n?`?${n}`:``}`)}async function Sp(e){return bp(`/packages/${encodeURIComponent(e)}`)}async function Cp(e){if(jl()){let t=await fetch(`/api/v1/cloud-connection/install`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({package_id:e.packageId,seed_sample_data:!!e.seedSampleData})}),n=null;try{n=await t.json()}catch{}if(!t.ok||n?.success===!1){let e=n?.error?.code??n?.code??`HTTP_${t.status}`,r=n?.error?.message??n?.error??n?.message??t.statusText,i=Error(typeof r==`string`?r:`${e}`);throw i.code=e,i.status=t.status,i}return n?.data??n}let t=await fetch(`${vp}/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}})}),n=null;try{n=await t.json()}catch{}if(!t.ok){let e=n?.code??n?.error?.code??`HTTP_${t.status}`,r=n?.error??n?.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 wp(){let e=jl()||vp,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 Tp(){let e=jl()||vp,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 Ep(e){return`${jl()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function Dp(e,t){if(!e||!t)return null;let n=jl()||vp,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 Op(e){if(!e)return{ok:!1,error:`installation id required`};let t=jl()||vp;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 kp(e){if(!e)return{ok:!1,error:`installation id required`};let t=jl()||vp;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 Ap(e){let t=await fetch(`${yp}/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 jp(){try{let e=await fetch(`${yp}/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 Mp(e){let t=await fetch(`${yp}/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 Np(e,t){let n=await fetch(`${yp}/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 Pp(e){return Np(e,`reseed`)}function Fp(e){return Np(e,`purge`)}var Ip=t({MarketplacePage:()=>Rp});function Lp(){let{language:e,t}=z();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 Rp(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=z(),a=Lp(),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([xp({limit:100}),jp()]);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=_p(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)(En,{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)(_i,{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)(Xt,{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)(go,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(U,{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)(Ai,{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)(It,{children:[(0,Y.jsxs)(hr,{className:`pb-2`,children:[(0,Y.jsx)(ze,{className:`h-10 w-10 rounded-lg mb-2`}),(0,Y.jsx)(ze,{className:`h-5 w-3/4`}),(0,Y.jsx)(ze,{className:`h-4 w-1/2 mt-1`})]}),(0,Y.jsx)(Ca,{children:(0,Y.jsx)(ze,{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=_p(t,i);return(0,Y.jsxs)(It,{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)(hr,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Y.jsx)(up,{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)(ur,{className:`text-base truncate`,children:s.displayName}),(0,Y.jsx)(At,{className:`text-xs truncate`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,Y.jsx)(V,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,Y.jsxs)(Ca,{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)(V,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,Y.jsx)(sa,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,Y.jsxs)(V,{variant:`outline`,className:`text-xs`,children:[(0,Y.jsx)(Mr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,Y.jsx)(V,{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)(dp,{})}function zp(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 Bp(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 Vp({source:e,className:t}){let n=zp(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:Bp(e.text??``)},t);case`h2`:return(0,Y.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:Bp(e.text??``)},t);case`h3`:return(0,Y.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:Bp(e.text??``)},t);case`p`:return(0,Y.jsx)(`p`,{children:Bp(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:Bp(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:Bp(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 Hp={node:`In-process · full trust`,sandbox:`Sandboxed`,worker:`Out-of-process`};function Up({icon:e,label:t,items:n}){return!n||n.length===0?null:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(e,{className:`h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0`,"aria-hidden":`true`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:t}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:n.map(e=>(0,Y.jsx)(`code`,{className:`font-mono text-[11px] px-1 py-0.5 rounded bg-muted break-all`,children:e},e))})]})]})}function Wp({version:e}){let{t}=z();if(!e?.contains_code)return null;let n=e.permissions??{},r=(n.services?.length??0)+(n.hooks?.length??0)+(n.network?.length??0)+(n.fs?.length??0)>0;return(0,Y.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 space-y-3 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,Y.jsx)(ar,{className:`h-4 w-4 text-amber-600 shrink-0`,"aria-hidden":`true`}),t(`marketplace.disclosure.containsCode`,{defaultValue:`This package contains code`})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[e.runtime&&(0,Y.jsx)(V,{variant:`outline`,children:t(`marketplace.disclosure.runtime.${e.runtime}`,{defaultValue:Hp[e.runtime]??e.runtime})}),e.platform_verified?(0,Y.jsxs)(V,{variant:`outline`,className:`gap-1 border-green-500/40 text-green-700 dark:text-green-400`,children:[(0,Y.jsx)(_a,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.reviewed`,{defaultValue:`Reviewed & approved`})]}):(0,Y.jsxs)(V,{variant:`outline`,className:`gap-1 border-amber-500/40 text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)($i,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.unreviewed`,{defaultValue:`Not yet reviewed`})]}),e.signed&&(0,Y.jsxs)(V,{variant:`outline`,className:`gap-1`,children:[(0,Y.jsx)(sa,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.signed`,{defaultValue:`Signed`})]})]}),r?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.grantsIntro`,{defaultValue:`On install, this package will be granted:`})}),(0,Y.jsx)(Up,{icon:Ze,label:t(`marketplace.disclosure.services`,{defaultValue:`Platform services`}),items:n.services??void 0}),(0,Y.jsx)(Up,{icon:Un,label:t(`marketplace.disclosure.hooks`,{defaultValue:`Lifecycle hooks`}),items:n.hooks??void 0}),(0,Y.jsx)(Up,{icon:ja,label:t(`marketplace.disclosure.network`,{defaultValue:`Network access`}),items:n.network??void 0}),(0,Y.jsx)(Up,{icon:qa,label:t(`marketplace.disclosure.fs`,{defaultValue:`Filesystem access`}),items:n.fs??void 0})]}):(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.noPermissions`,{defaultValue:`Requests no special permissions.`})})]})}var Gp=t({MarketplacePackagePage:()=>Kp});function Kp(){let e=s(),{packageId:t,appName:n}=f(),r=C(),{t:i,language:a}=z(),o=n?`/apps/${n}`:``,{refresh:c}=re(),[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,A]=(0,J.useState)(!1),[j,ee]=(0,J.useState)(!1),[te,M]=(0,J.useState)(null),[ne,N]=(0,J.useState)(null),[P,ie]=(0,J.useState)(null),[ae,F]=(0,J.useState)(null),[oe,se]=(0,J.useState)(null),[ce,le]=(0,J.useState)([]),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)(null);(0,J.useEffect)(()=>{if(!Ol().features.installLocal)return;let e=!1;return(async()=>{let t=await jp();e||le(t)})(),()=>{e=!0}},[t,fe]),(0,J.useEffect)(()=>{if(!t)return;let e=Ol().defaultEnvironmentId;if(!e)return;let n=!1;return(async()=>{let r=await Dp(t,e);n||!r||(ie(r),N(r.version))})(),()=>{n=!0}},[t]),(0,J.useEffect)(()=>{let e=!1;return(async()=>{if(t){p(!0),h(null);try{let n=await Sp(t);e||u(n)}catch(t){e||h(t?.message??String(t))}finally{e||p(!1)}}})(),()=>{e=!0}},[t]);let me=async()=>{_(!0),M(null),w(null);let e=Ol().defaultEnvironmentId;if(e){x(!1),E(e),y([]);return}x(!0);try{let[e,t]=await Promise.all([wp(),Tp()]),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)}},I=async()=>{if(!(!t||!T)){ee(!0),M(null);try{N(((await Cp({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=Ol().defaultEnvironmentId||T;if(e){let n=await Dp(t,e);n&&ie(n)}}catch{}let e=Ol().defaultEnvironmentId;if(!e||e===T)try{if(typeof sessionStorage<`u`)for(let e of Object.keys(sessionStorage))e.startsWith(`objectui:metadata:`)&&sessionStorage.removeItem(e);await c()}catch{}M({ok:!0,message:i(`marketplace.install.success`)})}catch(e){M({ok:!1,message:e?.message??String(e)})}finally{ee(!1)}}},he=async()=>{if(t){de(!0),pe(null);try{let e=await Ap({packageId:t});try{await c(`app`)}catch{}pe({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?_p(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`)),pe({ok:!1,message:n})}finally{de(!1)}}},ge=async()=>{if(Se&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:Se.manifestId,version:Se.version}))){de(!0),pe(null);try{await Mp(Se.manifestId);try{await c(`app`)}catch{}pe({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:Se.manifestId})})}catch(e){pe({ok:!1,message:e?.message??String(e)})}finally{de(!1)}}},_e=async()=>{if(P){F(`reseed`),se(null);try{let e=await Op(P.installationId);e.ok?(ie({...P,withSampleData:!0}),se({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):se({ok:!1,text:e.error||`Re-seed failed`})}finally{F(null)}}},L=async()=>{if(P&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){F(`purge`),se(null);try{let e=await kp(P.installationId);if(e.ok){ie({...P,withSampleData:!1});let t=e.deleted??0;se({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 se({ok:!1,text:e.error||`Purge failed`})}finally{F(null)}}},ve=async()=>{if(Se){F(`reseed`),se(null);try{let e=await Pp(Se.manifestId);le(e=>e.map(e=>e.manifestId===Se.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;se({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){se({ok:!1,text:e?.message||`Re-seed failed`})}finally{F(null)}}},R=async()=>{if(Se&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){F(`purge`),se(null);try{let e=await Fp(Se.manifestId);le(e=>e.map(e=>e.manifestId===Se.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;se({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){se({ok:!1,text:e?.message||`Purge failed`})}finally{F(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)(ze,{className:`h-8 w-32`}),(0,Y.jsx)(ze,{className:`h-16 w-full`}),(0,Y.jsx)(ze,{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)(Jn,{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)(Ai,{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,be=_p(ye,a),xe=ye.latest_version?.version??l.versions[0]?.version??null,Se=ce.find(e=>e.manifestId===ye.manifest_id)??null,Ce=!!ye.latest_version?.contains_code,we=Ol().features.installLocal,Te=!xe||ue||j||!we&&!!ne,Ee=we?{label:i(ue?`marketplace.action.working`:Se?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:he}:{label:j?i(`marketplace.action.installing`):ne?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:me},De=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)(Jn,{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)(up,{iconUrl:ye.icon_url,displayName:be.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:be.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)(pn,{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}),xe&&(0,Y.jsx)(V,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:xe})}),ye.publisher&&ye.publisher!==`private`&&(0,Y.jsx)(V,{variant:ye.publisher===`objectstack`?`default`:`secondary`,children:ye.publisher}),De&&(0,Y.jsx)(V,{variant:`outline`,children:De}),ye.license&&(0,Y.jsx)(V,{variant:`outline`,className:`font-normal`,children:ye.license}),Se&&(0,Y.jsxs)(V,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(sa,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:Se.version})]}),!Se&&ne&&(0,Y.jsxs)(V,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(sa,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:ne})]})]}),be.description&&(0,Y.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:be.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,Y.jsxs)(G,{onClick:Ee.onClick,disabled:Te,size:`lg`,className:`min-w-[8rem]`,children:[(0,Y.jsx)(Qt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),Ee.label]}),Se&&(0,Y.jsxs)(Pr,{children:[(0,Y.jsx)(ea,{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)(Vi,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(da,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(Kr,{onSelect:ve,disabled:ae!==null,children:[ae===`reseed`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(wt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),Se.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(Kr,{onSelect:R,disabled:ae!==null||!Se.withSampleData,className:`text-destructive focus:text-destructive`,children:[ae===`purge`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Mn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,Y.jsxs)(Kr,{onSelect:ge,disabled:ue,className:`text-destructive focus:text-destructive`,children:[(0,Y.jsx)(Mn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!Se&&P&&(0,Y.jsxs)(Pr,{children:[(0,Y.jsx)(ea,{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)(Vi,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(da,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(Kr,{onSelect:_e,disabled:ae!==null,children:[ae===`reseed`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(wt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),P.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(Kr,{onSelect:L,disabled:ae!==null||!P.withSampleData,className:`text-destructive focus:text-destructive`,children:[ae===`purge`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Mn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),oe&&(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${oe.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:[oe.ok?(0,Y.jsx)(sa,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Ai,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:oe.text}),(0,Y.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>se(null),children:i(`marketplace.action.dismiss`)})]}),fe&&(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${fe.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:[fe.ok?(0,Y.jsx)(sa,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Ai,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:fe.message}),(0,Y.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>pe(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)(It,{children:[(0,Y.jsx)(hr,{children:(0,Y.jsx)(ur,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,Y.jsx)(Ca,{children:be.readme?(0,Y.jsx)(Vp,{source:be.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)(It,{children:[(0,Y.jsx)(hr,{children:(0,Y.jsx)(ur,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,Y.jsx)(Ca,{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)(Mr,{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)(V,{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)(ct,{open:g,onOpenChange:e=>{_(e),e||(M(null),A(!1))},children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:i(`marketplace.install.dialogTitle`,{name:be.displayName||ye.manifest_id})}),(0,Y.jsx)(Ut,{children:Ol().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),b?(0,Y.jsx)(ze,{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)(Ai,{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:Ep(ye.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,Y.jsx)(pn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):Ol().defaultEnvironmentId?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(mt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(W,{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)(W,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,Y.jsxs)(Pn,{value:T,onValueChange:E,children:[(0,Y.jsx)(nr,{id:`env-select`,children:(0,Y.jsx)(bt,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,Y.jsx)(wo,{children:v.map(e=>(0,Y.jsxs)(We,{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)(mt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(W,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),Ce&&!S&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(Wp,{version:ye.latest_version}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(mt,{id:`ack-perms`,checked:k,onCheckedChange:e=>A(e===!0)}),(0,Y.jsx)(W,{htmlFor:`ack-perms`,className:`text-sm font-normal cursor-pointer leading-snug`,children:i(`marketplace.disclosure.acknowledge`,{defaultValue:`I understand this package runs code and grants the permissions above.`})})]})]}),te&&(0,Y.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${te.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:te.message}),(0,Y.jsxs)(An,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:()=>_(!1),children:i(`marketplace.action.close`)}),!S&&(0,Y.jsx)(G,{onClick:I,disabled:!T||j||te?.ok===!0||Ce&&!k,children:i(j?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,Y.jsx)(dp,{})}var qp=t({MarketplaceInstalledPage:()=>Jp});function Jp(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=z(),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 jp())}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 Mp(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)(Jn,{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)(En,{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)(Xt,{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)(Ai,{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)(ze,{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)(It,{children:[(0,Y.jsxs)(hr,{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)(ur,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,Y.jsx)(V,{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)(pn,{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)(Mn,{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)(Ca,{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)(dp,{})}function Yp({children:e,userId:t}){let{setContext:n}=Hs(),{isAiEnabled:r}=_e(),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)(Fl,{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)(Ec,{appLabel:`Workspace`,objects:[],userId:t})]})}var Xp=[{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 Zp(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function Qp({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=z(),{appLabel:a,appDescription:o}=Cr(),{toggleFavorite:s}=ec(),c=Ac(e.icon),l=a({name:e.name,label:Rc(e.label,i)}),u=o({name:e.name,description:Rc(e.description,i)}),d=e.branding?.primaryColor,f=Xp[(Zp(e.name)+r)%Xp.length];return(0,Y.jsxs)(It,{role:`button`,tabIndex:0,"aria-label":l,className:H(`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:H(`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:H(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,f.from,f.to)}),(0,Y.jsxs)(Ca,{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)(ii,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)(za,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:H(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,d?``:H(`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:H(`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)(V,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,Y.jsx)(`p`,{className:H(`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)(Co,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var $p={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`},em={object:wt,record:$a,dashboard:St,page:Ti};function tm({items:e}){let t=s(),{t:n}=z();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)(ht,{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=em[e.type]||wt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:zc(e.type)}),a=$p[e.type]||$p.object;return(0,Y.jsx)(It,{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)(Ca,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:H(`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)(Co,{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 nm={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`},rm={object:wt,record:$a,dashboard:St,page:Ti};function im({items:e}){let t=s(),{t:n}=z();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)(ii,{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=rm[e.type]||wt,i=nm[e.type]||nm.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:zc(e.type)});return(0,Y.jsx)(It,{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)(Ca,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:H(`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)(Co,{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 am(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function om({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)(ii,{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)(ht,{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)(or,{className:`h-3.5 w-3.5`})]})]})})}function sm({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 cm(){let e=s(),{t}=z(),{apps:n,loading:r}=re(),{recentItems:i}=jo(),{favorites:a}=ec(),{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(am(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)(at,{children:[(0,Y.jsx)(bo,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Y.jsx)(xt,{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)(K,{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)(En,{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)(_i,{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)(Ma,{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)(sm,{icon:ot,tone:`text-indigo-600 dark:text-indigo-400`,value:l.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Y.jsx)(sm,{icon:ht,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)(sm,{icon:ii,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)(om,{t}),d.length>0&&(0,Y.jsx)(im,{items:d}),u.length>0&&(0,Y.jsx)(tm,{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)(ot,{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)(En,{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)(Qp,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function lm({children:e}){let{setContext:t}=Hs();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)(Fl,{variant:`orgs`})}),(0,Y.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function um(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function dm({open:e,onOpenChange:t,onCreated:n}){let{t:r}=z(),{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(um(o))},[o,u]),(0,J.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Y.jsx)(ct,{open:e,onOpenChange:t,children:(0,Y.jsx)(Ct,{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)(So,{children:[(0,Y.jsx)(Ve,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Y.jsx)(Ut,{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)(W,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Y.jsx)(U,{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)(An,{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)(B,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function fm(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 pm(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function mm(){let{t:e}=z(),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=fm()}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)(B,{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)(go,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(U,{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)(K,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),g.length===0?(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Y.jsx)(xt,{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)(K,{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)(Me,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Y.jsx)(Va,{src:n.logo,alt:n.name}),(0,Y.jsx)(oi,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:pm(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)(B,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Y.jsx)(dm,{open:u,onOpenChange:d,onCreated:y})]})}function hm(){let{t:e}=z(),t=s(),{slug:n}=f(),{organizations:r,activeOrganization:i,isOrganizationsLoading:o,switchOrganization:c}=w(),{setContext:l}=Hs();(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)(B,{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)(Fl,{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)(Jn,{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 gm(){return h()}function _m(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function vm({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=z(),{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=_m(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)(ct,{open:t,onOpenChange:n,children:(0,Y.jsx)(Ct,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Y.jsx)(Ut,{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)(W,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{readOnly:!0,value:_m(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)(ti,{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)(An,{children:(0,Y.jsx)(G,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Y.jsxs)(`form`,{onSubmit:v,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Y.jsx)(Ut,{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)(W,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Y.jsxs)(Pn,{value:c,onValueChange:e=>l(e),children:[(0,Y.jsx)(nr,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Y.jsx)(bt,{})}),(0,Y.jsxs)(wo,{children:[(0,Y.jsx)(We,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Y.jsx)(We,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Y.jsx)(We,{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)(An,{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)(B,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function ym(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function bm(){let{t:e}=z(),{org:t}=gm(),{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)(B,{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)(qt,{}),(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)(Me,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Y.jsx)(Va,{src:t.user.image,alt:t.user.name}),(0,Y.jsx)(oi,{className:`text-xs font-medium`,children:ym(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)(V,{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)(Pr,{children:[(0,Y.jsx)(ea,{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)(Vi,{className:`h-4 w-4`})})}),(0,Y.jsxs)(da,{align:`end`,children:[(0,Y.jsxs)(Kr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Y.jsx)(_a,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Y.jsxs)(Kr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Y.jsx)(_a,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Y.jsxs)(Kr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Y.jsx)(_a,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Y.jsxs)(Kr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Y.jsx)(Re,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Y.jsx)(Ir,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Y.jsxs)(Jr,{children:[(0,Y.jsxs)(ei,{children:[(0,Y.jsx)(fi,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Y.jsx)(Yi,{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)(Ja,{children:[(0,Y.jsx)(Fa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(pa,{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)(vm,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function xm(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function Sm(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function Cm(){let{t:e}=z(),{org:t}=gm(),{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=xm(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)(B,{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)(qt,{}),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)(Me,{className:`h-9 w-9 shrink-0`,children:(0,Y.jsx)(oi,{className:`text-xs`,children:(0,Y.jsx)(Ge,{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)(V,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Y.jsx)(V,{variant:Sm(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)(ti,{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)(po,{className:`h-4 w-4`})})]})]},t.id))}),(0,Y.jsx)(Ir,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Y.jsxs)(Jr,{children:[(0,Y.jsxs)(ei,{children:[(0,Y.jsx)(fi,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Y.jsx)(Yi,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Y.jsxs)(Ja,{children:[(0,Y.jsx)(Fa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(pa,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function wm(){let{t:e}=z(),{org:t}=gm(),{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}=Tr(),[x,S]=(0,J.useState)(null),[C,T]=(0,J.useState)(!0),[E,D]=(0,J.useState)(!1),[O,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(``),[ee,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 M=(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)(B,{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)(qt,{className:`my-4`}),x?(0,Y.jsxs)(`form`,{onSubmit:M,className:`space-y-4 max-w-md`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(W,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Y.jsx)(U,{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)(W,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(Me,{className:`size-16 rounded-md`,children:[p?(0,Y.jsx)(Va,{src:p,alt:l,className:`object-cover`}):null,(0,Y.jsx)(oi,{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)(B,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Y.jsx)($t,{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)(po,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Y.jsx)(U,{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)(B,{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)(qt,{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)(qt,{}),(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:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Y.jsx)(Ir,{open:E,onOpenChange:D,children:(0,Y.jsxs)(Jr,{children:[(0,Y.jsxs)(ei,{children:[(0,Y.jsx)(fi,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Y.jsx)(Yi,{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)(Ja,{children:[(0,Y.jsx)(Fa,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(pa,{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:ee,children:[ee&&(0,Y.jsx)(B,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Y.jsx)(Ir,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Y.jsxs)(Jr,{children:[(0,Y.jsxs)(ei,{children:[(0,Y.jsx)(fi,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Y.jsx)(Yi,{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)(W,{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)(U,{id:`delete-confirm-slug`,className:`mt-2`,value:A,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Y.jsxs)(Ja,{children:[(0,Y.jsx)(Fa,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(pa,{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:ee||A!==t.slug,children:[ee&&(0,Y.jsx)(B,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function Tm(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 Em({userId:e,apiBase:t,className:n,refreshKey:r}){let i=s(),{conversationId:a}=f(),{conversations:o,isLoading:c,error:l,remove:u,rename:d}=Nf({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:H(`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)(K,{className:`h-3.5 w-3.5`}),`New`]})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(go,{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)(U,{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)(Yn,{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)(at,{className:`px-3 py-8`,children:[(0,Y.jsx)(Er,{className:`h-8 w-8 text-muted-foreground`}),(0,Y.jsx)(bo,{children:`No chats yet`}),(0,Y.jsx)(xt,{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)(Dm,{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 Dm({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:H(`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)(U,{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)(ti,{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)(po,{className:`h-3.5 w-3.5`})})]})}):(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:H(`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)(Ft,{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)(Mn,{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:Tm(e.updatedAt??e.createdAt)})]})})}var Om=`/api/v1/ai`;function km(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(/\/$/,``)}${Om}`}function Am({apiBase:e,defaultAgent:t}={}){let{user:n}=w(),r=n?.id,{conversationId:i}=f(),a=s(),{setContext:o}=Hs();(0,J.useEffect)(()=>{o(`home`)},[o]);let c=(0,J.useMemo)(()=>km(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}=gs({apiBase:c}),[m,h]=(0,J.useState)(void 0);(0,J.useEffect)(()=>{if(!m&&u.length>0){let e=ms(u,t??l);e&&h(e)}},[u,m,t,l]);let g=m?`${c}/agents/${encodeURIComponent(m)}/chat`:void 0,{conversationId:_,initialMessages:v,isLoading:y}=kf({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)(Fl,{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)(wi,{className:`h-3.5 w-3.5`}),`Share`]})})]}),_&&(0,Y.jsx)(co,{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)(Em,{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)(jm,{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 jm({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 Pm(r,d)},[f.length,r,d]),{messages:m,isLoading:h,error:g,sendMessage:_,stop:v,reload:y,clear:b}=fs({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=hs({messages:m,apiBase:o,continueConversation:e=>{_(e)}}),S=(0,J.useCallback)((e,t)=>{_(e,t),u(e)},[_,u]);return(0,Y.jsx)(ps,{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)(Pn,{value:r,onValueChange:i,disabled:t,children:[(0,Y.jsx)(nr,{className:`h-7 w-[220px] text-xs`,"data-testid":`ai-chat-agent-picker`,children:(0,Y.jsx)(bt,{placeholder:`Choose agent...`})}),(0,Y.jsx)(wo,{align:`start`,children:e.map(e=>(0,Y.jsxs)(We,{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 Mm={data_chat:[`系统里有多少个用户?列出他们的邮箱。`,`帮我列出最近创建的 5 条记录。`,`统计每个对象的记录数。`],metadata_assistant:[`系统里注册了哪些对象类型?`,`sys_user 对象有哪些字段?`,`描述一下用户相关的对象关系。`]},Nm=[`What can you help me with?`,`List the available data objects.`,`Summarize my recent activity.`];function Pm(e,t){if(e&&Mm[e])return Mm[e];let n=(e??t).toLowerCase();return n.includes(`data`)?Mm.data_chat:n.includes(`metadata`)?Mm.metadata_assistant:Nm}var Fm=new Map;function Im(e){Fm.set(e.ref,e)}function Lm(e){return Fm.get(e)}function Rm(e){return(0,J.useMemo)(()=>{let t=new Ee({baseUrl:``});return e?t.withEnvironment(e):t},[e])}function zm(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 Bm(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(zm(i)),n(!1))}catch(e){t||(i(e?.message??String(e)),n(!1))}})(),()=>{t=!0}},[e]),{loading:t,error:r,entries:a}}function Vm(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 Hm(e,t=`error`,n){let[r,i]=(0,J.useState)(!0),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)({entries:[],total:0,scannedTypes:0,scannedItems:0,stats:{}}),[l,u]=(0,J.useState)(0);return(0,J.useEffect)(()=>{let r=!1;return i(!0),o(null),(async()=>{try{let a=await e.diagnostics(n?{severity:t,packageId:n}:{severity:t});if(r)return;c(a),i(!1)}catch(e){if(r)return;o(e?.message??String(e)),c({entries:[],total:0,scannedTypes:0,scannedItems:0,stats:{}}),i(!1)}})(),()=>{r=!0}},[e,t,n,l]),{loading:r,error:a,summary:s,byType:(0,J.useMemo)(()=>{let e={};for(let t of s.entries)(t.diagnostics?.errors?.length??0)>0&&(e[t.type]=(e[t.type]??0)+1);return e},[s]),warnByType:(0,J.useMemo)(()=>{let e={};for(let t of s.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},[s]),countsByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(s.stats??{}))e[t]=n.count;return e},[s]),lockedByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(s.stats??{}))typeof n.locked==`number`&&n.locked>0&&(e[t]=n.locked);return e},[s]),packagesByType:(0,J.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(s.stats??{}))e[t]=n.packages??[];return e},[s]),allPackages:(0,J.useMemo)(()=>{let e=new Set;for(let t of Object.values(s.stats??{}))for(let n of t.packages??[])e.add(n);return[...e].sort()},[s]),reload:()=>u(e=>e+1)}}var Um={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`,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`},Wm={object:`对象`,field:`字段`,trigger:`触发器`,validation:`校验规则`,hook:`钩子`,view:`视图`,page:`页面`,dashboard:`仪表板`,app:`应用`,action:`操作`,report:`报表`,flow:`流程`,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:`分析立方体`},Gm={data:`Data`,ui:`UI`,automation:`Automation`,ai:`AI`,system:`System`,platform:`Platform`,identity:`Identity`,security:`Security`,other:`Other`},Km={data:`数据`,ui:`界面`,automation:`自动化`,ai:`AI`,system:`系统`,platform:`平台`,identity:`身份`,security:`安全`,other:`其他`},qm={"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.description":`Description`,"engine.inspector.flowNode.configuration":`Configuration`,"engine.inspector.flowNode.config":`Config (JSON)`,"engine.inspector.flowNode.advanced":`Advanced (JSON)`,"engine.inspector.flowNode.advancedHint":`Optional custom keys not covered by the form above — most flows don’t need this.`,"engine.inspector.flowNode.noConfig":`No configuration needed for this node type.`,"engine.inspector.flowNode.kv.add":`Add entry`,"engine.inspector.flowNode.kv.key":`Key`,"engine.inspector.flowNode.kv.value":`Value`,"engine.inspector.flowNode.kv.remove":`Remove entry`,"engine.inspector.flowNode.kv.empty":`No entries yet.`,"engine.inspector.flowNode.list.add":`Add item`,"engine.inspector.flowNode.list.item":`Value`,"engine.inspector.flowNode.list.remove":`Remove item`,"engine.inspector.flowNode.list.empty":`No items yet.`,"engine.inspector.flowNode.remove":`Remove node`,"engine.inspector.flowEdge.kind":`Connection`,"engine.inspector.flowEdge.close":`Close connection`,"engine.inspector.flowEdge.missing":`This connection no longer exists.`,"engine.inspector.flowEdge.source":`From`,"engine.inspector.flowEdge.target":`To`,"engine.inspector.flowEdge.routing":`Routing`,"engine.inspector.flowEdge.label":`Branch label`,"engine.inspector.flowEdge.labelHint":`e.g. approve / reject`,"engine.inspector.flowEdge.condition":`Condition`,"engine.inspector.flowEdge.conditionHint":`CEL expression — taken when it evaluates true`,"engine.inspector.flowEdge.isDefault":`Default branch (else)`,"engine.inspector.flowEdge.hint":`The engine follows this connection when its branch label is selected or its condition is met. The default branch is taken when no other matches.`,"engine.inspector.flowEdge.remove":`Remove connection`,"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`,"designer.canvas.nameToStart":`Name the object in the Properties panel to start designing fields.`,"designer.canvas.noFields":`No fields yet`,"designer.canvas.noFieldsHint":`Add a field to start designing the form. Click any field to edit its properties on the right.`,"designer.canvas.addField":`Add field`,"designer.canvas.addSection":`Add section`,"designer.canvas.addFieldToSection":`Add field to this section`,"designer.canvas.searchFieldType":`Search field type…`,"designer.canvas.noMatchingTypes":`No matching types.`,"designer.canvas.ungrouped":`Ungrouped`,"designer.canvas.emptySection":`Empty section`,"designer.canvas.dropHint":`Drag fields here, or add one below`,"designer.canvas.dropToAssign":`drop to assign`,"designer.canvas.collapseAll":`Collapse all`,"designer.canvas.expandAll":`Expand all`,"designer.canvas.fields":`fields`,"designer.canvas.required":`required`,"designer.canvas.sections":`sections`,"designer.canvas.collapseSection":`Collapse section`,"designer.canvas.expandSection":`Expand section`,"designer.canvas.moveSectionUp":`Move section up`,"designer.canvas.moveSectionDown":`Move section down`,"designer.canvas.removeSection":`Remove section`,"designer.canvas.removeSectionHint":`Remove section (fields move to Ungrouped)`,"designer.canvas.renameHint":`Double-click to rename`,"designer.canvas.sectionN":`Section {n}`,"designer.stub.pickDate":`Pick a date…`,"designer.stub.off":`Off`,"designer.stub.select":`Select…`,"designer.stub.pickMulti":`Pick one or more…`,"designer.stub.uploadImage":`Upload image`,"designer.stub.uploadAvatar":`Upload avatar`,"designer.stub.upload":`Upload {type}`,"designer.stub.qrcode":`QR code`,"designer.stub.computed":`Computed value`,"designer.stub.composite":`Composite — nested sub-fields edit in the inspector.`,"designer.stub.repeater":`Repeater — repeating row group.`,"designer.stub.searchRef":`Search {ref}…`,"designer.stub.chooseRelated":`Choose related object…`,"designer.stub.latLng":`Lat, lng`,"designer.field.kind":`Field`,"designer.field.close":`Close`,"designer.field.missing":`This field no longer exists in the draft.`,"designer.field.remove":`Remove “{label}”`,"designer.field.section.basic":`Basic`,"designer.field.section.advanced":`Advanced`,"designer.field.section.options":`{type} options`,"designer.field.apiName":`API name`,"designer.field.label":`Label`,"designer.field.type":`Type`,"designer.field.required":`Required`,"designer.field.unique":`Unique`,"designer.field.description":`Description`,"designer.field.readonly":`Read-only`,"designer.field.hidden":`Hidden`,"designer.field.indexed":`Indexed`,"designer.field.externalId":`External ID`,"designer.field.trackHistory":`Track history`,"designer.field.placeholder":`Placeholder`,"designer.field.group":`Group`,"designer.field.noGroup":`— No group —`,"designer.field.picklistValues":`Picklist values`,"designer.field.noValues":`No values yet.`,"designer.field.addValue":`Add value`,"designer.field.optValue":`value`,"designer.field.optLabel":`Label`,"designer.field.optColor":`Color`,"designer.field.moveUp":`Move up`,"designer.field.moveDown":`Move down`,"designer.field.removeValue":`Remove`,"designer.field.relatedObject":`Related object`,"designer.field.relationshipName":`Relationship name`,"designer.field.relationshipNameHint":`Inverse collection key on the parent`,"designer.field.objectNamePlaceholder":`object_name`,"designer.field.formula":`Formula (CEL)`,"designer.field.precision":`Precision`,"designer.field.scale":`Scale`,"designer.field.min":`Min`,"designer.field.max":`Max`,"designer.field.maxLength":`Max length`,"designer.object.kind":`Object`,"designer.object.section.basic":`Basic info`,"designer.object.section.basicHint":`Identity, display names & classification`,"designer.object.name":`Name`,"designer.object.nameHint":`snake_case unique identifier (cannot change after create)`,"designer.object.namePlaceholder":`account`,"designer.object.label":`Label`,"designer.object.labelPlaceholder":`e.g. Account`,"designer.object.pluralLabel":`Plural label`,"designer.object.pluralPlaceholder":`e.g. Accounts`,"designer.object.icon":`Icon`,"designer.object.iconHint":`Lucide icon name (e.g. “building”, “users”)`,"designer.object.description":`Description`,"designer.object.descriptionPlaceholder":`What this object represents`,"designer.field.defaultValue":`Default value`,"designer.field.defaultNone":`— None —`,"designer.field.true":`True`,"designer.field.false":`False`,"designer.field.duplicate":`Duplicate field`,"designer.field.copySuffix":` copy`,"designer.field.helpText":`Help text`,"designer.field.helpTextPlaceholder":`Shown below the field on the form`,"designer.field.minLength":`Min length`,"designer.field.conditionalRequired":`Required when (CEL)`,"designer.field.conditionalRequiredHint":`Field becomes required when this predicate is true.`,"designer.canvas.bulkSelected":`{n} selected`,"designer.canvas.bulkMoveTo":`Move to section`,"designer.canvas.bulkDelete":`Delete`,"designer.canvas.bulkClear":`Clear`,"designer.canvas.bulkHint":`Ctrl/⌘-click or Shift-click to select multiple fields.`,"designer.canvas.reviewChanges":`Review changes`,"designer.canvas.reviewExit":`Exit review`,"designer.canvas.reviewVsPublished":`vs last published`,"designer.canvas.diffAdded":`Added`,"designer.canvas.diffChanged":`Changed`,"designer.canvas.diffRemoved":`Removed`,"designer.canvas.diffChangedKeys":`Changed: {keys}`,"designer.draftReview.title":`Review changes`,"designer.draftReview.badge":`{n} pending`,"designer.draftReview.empty":`No changes vs the published version.`,"designer.canvas.askAi":`Ask AI`,"designer.canvas.askAiGenerate":`Generate fields with AI`},Jm={"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.description":`描述`,"engine.inspector.flowNode.configuration":`配置`,"engine.inspector.flowNode.config":`配置(JSON)`,"engine.inspector.flowNode.advanced":`高级(JSON)`,"engine.inspector.flowNode.advancedHint":`上方表单未覆盖的可选自定义键 —— 大多数流程无需填写。`,"engine.inspector.flowNode.noConfig":`此节点类型无需配置。`,"engine.inspector.flowNode.kv.add":`添加条目`,"engine.inspector.flowNode.kv.key":`键`,"engine.inspector.flowNode.kv.value":`值`,"engine.inspector.flowNode.kv.remove":`删除条目`,"engine.inspector.flowNode.kv.empty":`暂无条目。`,"engine.inspector.flowNode.list.add":`添加项`,"engine.inspector.flowNode.list.item":`值`,"engine.inspector.flowNode.list.remove":`删除项`,"engine.inspector.flowNode.list.empty":`暂无项。`,"engine.inspector.flowNode.remove":`删除节点`,"engine.inspector.flowEdge.kind":`连线`,"engine.inspector.flowEdge.close":`关闭连线`,"engine.inspector.flowEdge.missing":`该连线已不存在。`,"engine.inspector.flowEdge.source":`起点`,"engine.inspector.flowEdge.target":`终点`,"engine.inspector.flowEdge.routing":`路由`,"engine.inspector.flowEdge.label":`分支标签`,"engine.inspector.flowEdge.labelHint":`例如 approve / reject`,"engine.inspector.flowEdge.condition":`条件`,"engine.inspector.flowEdge.conditionHint":`CEL 表达式 —— 为真时走此连线`,"engine.inspector.flowEdge.isDefault":`默认分支(else)`,"engine.inspector.flowEdge.hint":`当此连线的分支标签被选中、或其条件成立时,引擎会走这条连线。其余都不匹配时走默认分支。`,"engine.inspector.flowEdge.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":`代码基线`,"designer.canvas.nameToStart":`在右侧属性面板中为对象命名,即可开始设计字段。`,"designer.canvas.noFields":`尚无字段`,"designer.canvas.noFieldsHint":`添加字段以开始设计表单。点击任意字段可在右侧编辑其属性。`,"designer.canvas.addField":`添加字段`,"designer.canvas.addSection":`添加分组`,"designer.canvas.addFieldToSection":`向此分组添加字段`,"designer.canvas.searchFieldType":`搜索字段类型…`,"designer.canvas.noMatchingTypes":`没有匹配的类型。`,"designer.canvas.ungrouped":`未分组`,"designer.canvas.emptySection":`空分组`,"designer.canvas.dropHint":`将字段拖到此处,或在下方添加`,"designer.canvas.dropToAssign":`拖放以归入此分组`,"designer.canvas.collapseAll":`全部折叠`,"designer.canvas.expandAll":`全部展开`,"designer.canvas.fields":`个字段`,"designer.canvas.required":`个必填`,"designer.canvas.sections":`个分组`,"designer.canvas.collapseSection":`折叠分组`,"designer.canvas.expandSection":`展开分组`,"designer.canvas.moveSectionUp":`上移分组`,"designer.canvas.moveSectionDown":`下移分组`,"designer.canvas.removeSection":`删除分组`,"designer.canvas.removeSectionHint":`删除分组(字段移至未分组)`,"designer.canvas.renameHint":`双击重命名`,"designer.canvas.sectionN":`分组 {n}`,"designer.stub.pickDate":`选择日期…`,"designer.stub.off":`关闭`,"designer.stub.select":`请选择…`,"designer.stub.pickMulti":`选择一项或多项…`,"designer.stub.uploadImage":`上传图片`,"designer.stub.uploadAvatar":`上传头像`,"designer.stub.upload":`上传{type}`,"designer.stub.qrcode":`二维码`,"designer.stub.computed":`计算值`,"designer.stub.composite":`复合字段 — 子字段在右侧属性面板中编辑。`,"designer.stub.repeater":`重复字段 — 可重复的行分组。`,"designer.stub.searchRef":`搜索 {ref}…`,"designer.stub.chooseRelated":`选择关联对象…`,"designer.stub.latLng":`经纬度`,"designer.field.kind":`字段`,"designer.field.close":`关闭`,"designer.field.missing":`该字段已不在草稿中。`,"designer.field.remove":`删除“{label}”`,"designer.field.section.basic":`基础`,"designer.field.section.advanced":`高级`,"designer.field.section.options":`{type} 选项`,"designer.field.apiName":`API 名称`,"designer.field.label":`显示名`,"designer.field.type":`类型`,"designer.field.required":`必填`,"designer.field.unique":`唯一`,"designer.field.description":`描述`,"designer.field.readonly":`只读`,"designer.field.hidden":`隐藏`,"designer.field.indexed":`索引`,"designer.field.externalId":`外部 ID`,"designer.field.trackHistory":`记录历史`,"designer.field.placeholder":`占位符`,"designer.field.group":`分组`,"designer.field.noGroup":`— 无分组 —`,"designer.field.picklistValues":`选项值`,"designer.field.noValues":`暂无选项值。`,"designer.field.addValue":`添加选项`,"designer.field.optValue":`值`,"designer.field.optLabel":`显示名`,"designer.field.optColor":`颜色`,"designer.field.moveUp":`上移`,"designer.field.moveDown":`下移`,"designer.field.removeValue":`删除`,"designer.field.relatedObject":`关联对象`,"designer.field.relationshipName":`关系名称`,"designer.field.relationshipNameHint":`父对象上的反向集合键`,"designer.field.objectNamePlaceholder":`object_name`,"designer.field.formula":`公式 (CEL)`,"designer.field.precision":`精度`,"designer.field.scale":`小数位`,"designer.field.min":`最小值`,"designer.field.max":`最大值`,"designer.field.maxLength":`最大长度`,"designer.object.kind":`对象`,"designer.object.section.basic":`基础信息`,"designer.object.section.basicHint":`标识、显示名与分类`,"designer.object.name":`名称`,"designer.object.nameHint":`snake_case 唯一标识符(创建后不可修改)`,"designer.object.namePlaceholder":`account`,"designer.object.label":`显示名`,"designer.object.labelPlaceholder":`如:客户`,"designer.object.pluralLabel":`复数显示名`,"designer.object.pluralPlaceholder":`如:客户列表`,"designer.object.icon":`图标`,"designer.object.iconHint":`Lucide 图标名称(如 “building”、“users”)`,"designer.object.description":`描述`,"designer.object.descriptionPlaceholder":`该对象代表什么`,"designer.field.defaultValue":`默认值`,"designer.field.defaultNone":`— 无 —`,"designer.field.true":`是`,"designer.field.false":`否`,"designer.field.duplicate":`复制字段`,"designer.field.copySuffix":` 副本`,"designer.field.helpText":`帮助文本`,"designer.field.helpTextPlaceholder":`显示在表单字段下方`,"designer.field.minLength":`最小长度`,"designer.field.conditionalRequired":`条件必填 (CEL)`,"designer.field.conditionalRequiredHint":`当此表达式为真时,该字段变为必填。`,"designer.canvas.bulkSelected":`已选 {n} 项`,"designer.canvas.bulkMoveTo":`移至分组`,"designer.canvas.bulkDelete":`删除`,"designer.canvas.bulkClear":`取消选择`,"designer.canvas.bulkHint":`按住 Ctrl/⌘ 单击或 Shift 单击可多选字段。`,"designer.canvas.reviewChanges":`查看变更`,"designer.canvas.reviewExit":`退出查看`,"designer.canvas.reviewVsPublished":`对比已发布版本`,"designer.canvas.diffAdded":`新增`,"designer.canvas.diffChanged":`修改`,"designer.canvas.diffRemoved":`删除`,"designer.canvas.diffChangedKeys":`变更:{keys}`,"designer.draftReview.title":`查看变更`,"designer.draftReview.badge":`{n} 项待审`,"designer.draftReview.empty":`与已发布版本相比没有变更。`,"designer.canvas.askAi":`问 AI`,"designer.canvas.askAiGenerate":`用 AI 生成字段`};function Ym(e){return(e??``).toLowerCase().startsWith(`zh`)?{types:Wm,domains:Km,strings:Jm}:{types:Um,domains:Gm,strings:qm}}function Xm(e,t,n){return Ym(t).types[e]||(n??e)}function Zm(e,t){return Ym(t).domains[e]??e}function X(e,t){return Ym(t).strings[e]??e}function Qm(e,t,n){return X(e,t).replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):`{${t}}`)}function $m(){return typeof navigator<`u`&&/^zh/i.test(navigator.language)?`zh-CN`:`en-US`}function eh({appSlug:e}={}){let t=s(),n=Rm(),{entries:r}=Bm(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(()=>$m(),[]);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)||Xm(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)(ct,{open:i,onOpenChange:a,children:(0,Y.jsxs)(Ct,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(So,{className:`sr-only`,children:(0,Y.jsx)(Ve,{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)(go,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(U,{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)(_n,{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)(B,{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)(V,{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:Xm(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)($e,{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)(_n,{children:`↑`}),` `,(0,Y.jsx)(_n,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(_n,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(_n,{children:`⌘`}),(0,Y.jsx)(_n,{children:`⇧`}),(0,Y.jsx)(_n,{children:`M`}),` toggle`]})]})]})})}var th={data:wt,ui:Vt,automation:qe,ai:Ma,system:_i,platform:_i,identity:_a,security:_a},nh=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],rh=new Set([`field`]);function ih(){let e=Rm(),{loading:t,error:n,entries:r}=Bm(e),a=J.useMemo(()=>$m(),[]),[o,s]=J.useState(``),[c,u]=J.useState(`all`),[d,f]=J.useState(!1),[p,m]=l(),[h,g]=J.useState(null);J.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;let r=new Set([`system`,`cloud`]),i=(n??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),g(i.map(e=>({id:e.id,name:e.name})))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=J.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);J.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Hm(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>rh.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[r,v,w]),D=J.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||c!==`all`&&(e.domain??`other`)!==c)return!1;if(o){let t=o.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||Xm(e.type,a,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=J.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=nh.indexOf(e),r=nh.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,Y.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:X(`engine.directory.loading`,a)}):n?(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[X(`engine.directory.loadFailed`,a),`: `,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`,a)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:Qm(`engine.directory.description`,a,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(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)(go,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(U,{className:`pl-8`,placeholder:X(`engine.directory.search`,a),value:o,onChange:e=>s(e.target.value)})]}),(0,Y.jsxs)(G,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[X(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.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)(ut,{className:`h-3.5 w-3.5 mr-1`}),Qm(`engine.directory.diagnosticsLink`,a,{count:x.total})]})}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[X(`engine.directory.quickFind`,a),` `,(0,Y.jsx)(_n,{children:`⌘`}),(0,Y.jsx)(_n,{children:`⇧`}),(0,Y.jsx)(_n,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(ah,{domain:`all`,label:X(`engine.directory.all`,a),active:c===`all`,count:D.all??0,onClick:()=>u(`all`)}),nh.filter(e=>D[e]).map(e=>(0,Y.jsx)(ah,{domain:e,label:Zm(e,a),active:c===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:`No project packages installed`}),(0,Y.jsx)(xt,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:X(`engine.directory.noMatches`,a)}),(0,Y.jsx)(xt,{children:X(`engine.directory.noMatchesHint`,a)})]}),A.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)(th[e]??hn,{className:`h-3.5 w-3.5`}),Zm(e,a),` (`,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=S[e.type]??0;return(0,Y.jsx)(oh,{entry:e,locale:a,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,Y.jsx)(eh,{})]})}function ah({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 oh({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=Xm(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:Qm(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":Qm(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,Y.jsx)(ut,{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)(V,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:Qm(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),n>0&&(0,Y.jsx)(V,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:Qm(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,Y.jsx)(V,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:Qm(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),o>0&&(0,Y.jsxs)(V,{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)($e,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,Y.jsx)(V,{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)(V,{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)(V,{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 sh=`/api/v1/packages`;async function ch(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function lh({scope:e}){let t=e??`project`;return(0,Y.jsx)(V,{variant:t===`project`?`default`:t===`system`?`secondary`:`outline`,children:t})}function uh({pkg:e}){let t=e.enabled!==!1&&e.status!==`disabled`;return(0,Y.jsx)(V,{variant:t?`default`:`outline`,children:t?`enabled`:`disabled`})}var dh=/^[a-z0-9][a-z0-9._-]{1,254}$/i,fh=/^\d+\.\d+\.\d+$/;function ph({open:e,onOpenChange:t,onCreated:n}){let[r,i]=J.useState(``),[a,o]=J.useState(``),[s,c]=J.useState(`0.1.0`),[l,u]=J.useState(!1),[d,f]=J.useState(null);J.useEffect(()=>{e&&(i(``),o(``),c(`0.1.0`),f(null),u(!1))},[e]);let p=dh.test(r),m=fh.test(s),h=p&&m&&!!a.trim()&&!l;async function g(){if(h){u(!0),f(null);try{await ch(sh,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:r.trim(),name:a.trim(),version:s.trim(),type:`app`,scope:`project`}})}),n(r.trim()),t(!1)}catch(e){f(e?.message??`Failed to create package`)}finally{u(!1)}}}return(0,Y.jsx)(ct,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsx)(Ve,{children:`New Package`}),(0,Y.jsxs)(Ut,{children:[`Create a project-scoped package to author and publish your own metadata. The id should be reverse-domain (e.g.`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`com.acme.crm`}),`).`]})]}),(0,Y.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{htmlFor:`pkg-id`,children:`Package ID`}),(0,Y.jsx)(U,{id:`pkg-id`,placeholder:`com.acme.crm`,value:r,onChange:e=>i(e.target.value),"aria-invalid":!!r&&!p}),!!r&&!p&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:`Use letters, numbers, dot, dash or underscore (2–255 chars).`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{htmlFor:`pkg-name`,children:`Display name`}),(0,Y.jsx)(U,{id:`pkg-name`,placeholder:`Acme CRM`,value:a,onChange:e=>o(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{htmlFor:`pkg-version`,children:`Version`}),(0,Y.jsx)(U,{id:`pkg-version`,placeholder:`0.1.0`,value:s,onChange:e=>c(e.target.value),"aria-invalid":!!s&&!m}),!!s&&!m&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:`Use semantic version, e.g. 0.1.0`})]}),d&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,Y.jsx)(ut,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:d})]})]}),(0,Y.jsxs)(An,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:()=>t(!1),disabled:l,children:`Cancel`}),(0,Y.jsx)(G,{onClick:g,disabled:!h,children:l?`Creating…`:`Create package`})]})]})})}function mh({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function hh({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:a}){let[o,s]=J.useState(null),[c,l]=J.useState(null),[u,d]=J.useState(null);if(J.useEffect(()=>{l(null),s(null)},[e?.manifest.id]),J.useEffect(()=>{let t=e?.manifest.id;if(!n||!t){d(null);return}let r=!1;return ch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{r||d(e?.drafts??[])}).catch(()=>{r||d([])}),()=>{r=!0}},[n,e?.manifest.id]),!e)return null;let f=e.manifest.id,p=e.enabled!==!1&&e.status!==`disabled`,m=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function h(e,t,n){s(e),l(null);try{await t(),l({kind:`ok`,text:n}),a()}catch(e){l({kind:`err`,text:e?.message??`Action failed`})}finally{s(null)}}return(0,Y.jsx)(en,{open:n,onOpenChange:r,children:(0,Y.jsxs)(ln,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Y.jsxs)(ft,{children:[(0,Y.jsxs)(Dt,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Mr,{className:`h-4 w-4`}),e.manifest.name||f]}),(0,Y.jsx)(Sn,{className:`font-mono text-xs`,children:f})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(mh,{label:`Version`,children:e.manifest.version||`—`}),(0,Y.jsx)(mh,{label:`Type`,children:e.manifest.type||`—`}),(0,Y.jsx)(mh,{label:`Scope`,children:(0,Y.jsx)(lh,{scope:e.manifest.scope})}),(0,Y.jsx)(mh,{label:`Status`,children:(0,Y.jsx)(uh,{pkg:e})}),e.manifest.description&&(0,Y.jsx)(mh,{label:`Description`,children:e.manifest.description})]}),(0,Y.jsx)(qt,{className:`my-4`}),(0,Y.jsxs)(i,{to:`${t}/metadata/object?package=${encodeURIComponent(f)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,Y.jsx)(pn,{className:`h-3.5 w-3.5`}),`Browse this package's metadata`]}),u&&u.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(qt,{className:`my-4`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[`Pending changes`,(0,Y.jsx)(V,{variant:`secondary`,children:u.length})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Drafted, not yet published. Publish the whole app, or review each below.`}),!m&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>h(`publish-drafts`,()=>ch(`${sh}/${encodeURIComponent(f)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{d((await ch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(f)}`))?.drafts??[])}catch{d([])}if(e?.failedCount)throw Error(`Published ${e.publishedCount??0}; ${e.failedCount} failed.`);return e}),`App published — all drafts are now live.`),disabled:!!o,children:[(0,Y.jsx)($t,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?`Publishing…`:`Publish app (${u.length})`]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:u.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(i,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,Y.jsx)(Or,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`))})]})]}),(0,Y.jsx)(qt,{className:`my-4`}),m?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This is a platform kernel package. Authoring actions are disabled.`}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:`Actions`}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(G,{size:`sm`,onClick:()=>h(`publish`,()=>ch(`${sh}/${encodeURIComponent(f)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?`Publish blocked by ${t} validation error(s).`:e.validationErrors?.[0]?.message||`Nothing to publish.`)}return e}),`Package published.`),disabled:!!o,children:[(0,Y.jsx)($t,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish`?`Publishing…`:`Publish`]}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>h(`revert`,()=>ch(`${sh}/${encodeURIComponent(f)}/revert`,{method:`POST`}),`Reverted to last published state.`),disabled:!!o,children:[(0,Y.jsx)(sn,{className:`mr-1.5 h-3.5 w-3.5`}),`Revert`]}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>h(`toggle`,()=>ch(`${sh}/${encodeURIComponent(f)}/${p?`disable`:`enable`}`,{method:`PATCH`}),p?`Package disabled.`:`Package enabled.`),disabled:!!o,children:[p?(0,Y.jsx)(kn,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Y.jsx)(Ht,{className:`mr-1.5 h-3.5 w-3.5`}),p?`Disable`:`Enable`]}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>h(`export`,async()=>{let e=await ch(`${sh}/${encodeURIComponent(f)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${f}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},`Package exported.`),disabled:!!o,children:[(0,Y.jsx)(Qt,{className:`mr-1.5 h-3.5 w-3.5`}),o===`export`?`Exporting…`:`Export`]})]})]}),c&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${c.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:c.text})]})})}function gh(){let{pathname:e}=o(),t=J.useMemo(()=>{let t=e.indexOf(`/component`);return t>=0?e.slice(0,t):e},[e]),[n,r]=J.useState([]),[i,a]=J.useState(!0),[s,c]=J.useState(null),[l,u]=J.useState(``),[d,f]=J.useState(!1),[p,m]=J.useState(!1),[h,g]=J.useState(null),[_,v]=J.useState(!1),y=J.useRef(null),[b,x]=J.useState(!1),[S,C]=J.useState(null),w=J.useCallback(async()=>{a(!0),c(null);try{let e=await ch(sh),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),r(t)}catch(e){c(e?.message??`Failed to load packages`)}finally{a(!1)}},[]);J.useEffect(()=>{w()},[w]),J.useEffect(()=>{if(!h)return;let e=n.find(e=>e.manifest.id===h.manifest.id);e&&e!==h&&g(e)},[n,h]);let T=J.useMemo(()=>{let e=l.trim().toLowerCase();return n.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!d?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[n,l,d]),E=e=>{g(e),v(!0)},D=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){x(!0),C(null);try{let e=await t.text(),n;try{n=JSON.parse(e)}catch{throw Error(`Selected file is not valid JSON.`)}if(!n||typeof n!=`object`||!n.id&&!n.name)throw Error(`Invalid package file: missing "id" or "name".`);C({kind:`ok`,text:`Imported "${(await ch(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:n})}))?.manifestId??n.id}". Refresh the app switcher to use it.`}),await w()}catch(e){C({kind:`err`,text:e?.message??`Import failed`})}finally{x(!1)}}},O=n.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,Y.jsx)(Mr,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:`Packages`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Author, publish, and manage the packages installed in this environment.`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void w(),disabled:i,children:[(0,Y.jsx)(Ni,{className:`mr-1.5 h-3.5 w-3.5 ${i?`animate-spin`:``}`}),`Refresh`]}),(0,Y.jsx)(`input`,{ref:y,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:D}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>y.current?.click(),disabled:b,children:[(0,Y.jsx)(Or,{className:`mr-1.5 h-3.5 w-3.5`}),b?`Importing…`:`Import`]}),(0,Y.jsxs)(G,{size:`sm`,onClick:()=>m(!0),children:[(0,Y.jsx)(K,{className:`mr-1.5 h-3.5 w-3.5`}),`New Package`]})]})]}),S&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${S.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:S.text}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Y.jsx)(go,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(U,{className:`pl-8`,placeholder:`Search packages…`,value:l,onChange:e=>u(e.target.value)})]}),O>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Zi,{id:`show-kernel`,checked:d,onCheckedChange:f}),(0,Y.jsxs)(W,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:[`Show platform packages (`,O,`)`]})]})]}),(0,Y.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:i?(0,Y.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,Y.jsx)(ze,{className:`h-10 w-full`},e))}):s?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,Y.jsx)(ut,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:s})]}):T.length===0?(0,Y.jsx)(`div`,{className:`p-8`,children:(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:`No packages`}),(0,Y.jsx)(xt,{children:n.length===0?`Create your first package to start authoring metadata.`:`No packages match your filters.`})]})}):(0,Y.jsxs)(Aa,{children:[(0,Y.jsx)(La,{children:(0,Y.jsxs)(Xr,{children:[(0,Y.jsx)(ha,{children:`Name`}),(0,Y.jsx)(ha,{children:`ID`}),(0,Y.jsx)(ha,{className:`w-24`,children:`Version`}),(0,Y.jsx)(ha,{className:`w-24`,children:`Scope`}),(0,Y.jsx)(ha,{className:`w-24`,children:`Status`})]})}),(0,Y.jsx)(ji,{children:T.map(e=>(0,Y.jsxs)(Xr,{className:`cursor-pointer`,onClick:()=>E(e),children:[(0,Y.jsx)(Rr,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Y.jsx)(Rr,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Y.jsx)(Rr,{children:e.manifest.version||`—`}),(0,Y.jsx)(Rr,{children:(0,Y.jsx)(lh,{scope:e.manifest.scope})}),(0,Y.jsx)(Rr,{children:(0,Y.jsx)(uh,{pkg:e})})]},e.manifest.id))})]})}),(0,Y.jsx)(ph,{open:p,onOpenChange:m,onCreated:async()=>{await w()}}),(0,Y.jsx)(hh,{pkg:h,appBase:t,open:_,onOpenChange:v,onChanged:()=>void w()})]})}var _h=new Set([`field`]),vh={data:wt,ui:Vt,automation:qe,ai:Ma,system:_i,platform:_i,identity:_a,security:_a},yh={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`}},bh=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],xh=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Sh={object:fr,dashboard:St,page:$a,report:to,record:hn,metadata:Vt};function Ch(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function wh(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 Th(){let e=Rm(),{loading:t,entries:n}=Bm(e),{summary:r,countsByType:a,allPackages:o}=Hm(e,`warning`),{recentItems:s}=jo(),c=J.useMemo(()=>$m(),[]),l=J.useMemo(()=>n.filter(e=>!_h.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])=>(bh.indexOf(e)===-1?99:bh.indexOf(e))-(bh.indexOf(t)===-1?99:bh.indexOf(t)))},[l,a]),f=J.useMemo(()=>{let e=new Map(u.map(e=>[e.type,e]));return xh.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)(Ma,{className:`h-4 w-4`}),X(Ch(),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)(Vt,{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)(go,{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)(Eh,{value:l.length,label:X(`engine.home.statTypes`,c)}),(0,Y.jsx)(Eh,{value:u.length,label:X(`engine.home.statWritable`,c)}),(0,Y.jsx)(Eh,{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)(Dh,{icon:Vt,from:`from-indigo-500`,to:`to-violet-600`,value:l.length,label:X(`engine.home.statTypes`,c),to_link:`metadata`}),(0,Y.jsx)(Dh,{icon:sa,from:`from-sky-500`,to:`to-blue-600`,value:u.length,label:X(`engine.home.statWritable`,c),to_link:`metadata`}),(0,Y.jsx)(Dh,{icon:Mr,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)(sa,{className:`h-5 w-5`}):(0,Y.jsx)(ut,{className:`h-5 w-5`})}),(0,Y.jsx)(tr,{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)(Oh,{icon:K,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)(K,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),Qm(`engine.home.newItem`,c,{label:Xm(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)(Oh,{icon:Vt,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)(kh,{domain:e,group:t,countsByType:a,locale:c},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(Oh,{icon:ht,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=Sh[e.type]??hn;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:wh(e.visitedAt,c)})]}),(0,Y.jsx)(tr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(eh,{})]})}function Eh({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 Dh({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)(tr,{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 Oh({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 kh({domain:e,group:t,countsByType:n,locale:r}){let a=vh[e]??hn,o=yh[e]??yh.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:Zm(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:Xm(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 Ah({entry:e,itemName:t,subtitle:n,stats:r,actions:a,children:s}){let c=e?.type??``,l=J.useMemo(()=>$m(),[]),u=Xm(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)(Yr,{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)(Yr,{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)(V,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Zm(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(V,{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)(V,{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)(V,{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)(Yr,{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)(V,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Zm(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(V,{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)(V,{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)(V,{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})]})}var jh={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function Mh(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function Nh({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=J.useState(null),o=J.useMemo(()=>D(),[]),s=J.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(s.length===0)return null;let c=async e=>{let t=e.label??e.name;if(e.type!==`api`){q.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i=e.params??{},s={recordId:n,origin:window.location.origin},c=Mh(e.target??``,s,i);if(!c){q.error(`Action “${t}” has no target.`);return}let l=``.replace(/\/+$/,``),u=/^https?:\/\//i.test(c)?c:`${l}${c}`,d=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:d,headers:{"Content-Type":`application/json`},credentials:`include`};d!==`GET`&&d!==`DELETE`&&(n.body=JSON.stringify(i));let a=await o(u,n),s=null;try{s=await a.json()}catch{}if(!a.ok||s&&s.success===!1){let e=s?.error||s?.message||`HTTP ${a.status} ${a.statusText}`.trim();q.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;q.success(c),e.refreshAfter&&r?.()}catch(e){q.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,Y.jsx)(Y.Fragment,{children:s.map(e=>{let t=e.icon?Ac(e.icon):null,n=i===e.name;return(0,Y.jsxs)(G,{size:`sm`,variant:jh[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,Y.jsx)(B,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,Y.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)})})}function Ph(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 Fh=new Map;function Ih(e){let t=Fh.get(e.type);if(!t){Fh.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Fh.set(e.type,n)}function Lh(e){return Fh.get(e)}function Rh(e){let t=[];for(let n of Fh.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 zh(e,t){let n=Fh.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 Bh(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 Vh({type:e}){let t=f(),n=e??t.type??``,r=Lh(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(Hh,{type:n})}function Hh({type:e}){let t=s(),n=Rm(),{entries:r}=Bm(n),a=r.find(t=>t.type===e),o=zh(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(0),[C,w]=J.useState(null);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await n.list(`package`);if(e)return;let r=new Set([`system`,`cloud`]),i=(t??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!r.has(e.scope));i.sort((e,t)=>e.name.localeCompare(t.name)),w(i.map(e=>({id:e.id,name:e.name})))}catch{e||w([])}})(),()=>{e=!0}},[n]);let T=y.get(`package`),E=J.useMemo(()=>C?T&&C.some(e=>e.id===T)?T:C[0]?.id??null:null,[C,T]);J.useEffect(()=>{if(!C||C.length===0||T&&C.some(e=>e.id===T))return;let e=new URLSearchParams(y);e.set(`package`,C[0].id),b(e,{replace:!0})},[C,T]);let D=E?`?package=${encodeURIComponent(E)}`:``;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:Bh(t,e?.source),diagnostics:n}})),f(!1)}catch(e){t||(m(e?.message??String(e)),f(!1))}})(),()=>{t=!0}},[n,e,x]);let O=o.searchableFields??[`name`,`label`,`description`],k=c.filter(e=>{if(o.listFilter&&!o.listFilter(e.item)||!Vm(e.item,h,O)||_!==`all`&&e.source!==_||!E)return!1;let t=e.item?._packageId;return(!t||t===`sys_metadata`?null:t)===E}),A=J.useMemo(()=>{let e={all:c.length,artifact:0,runtime:0};for(let t of c)e[t.source]++;return e},[c]),j=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]),te=o.listColumns??Uh(o.primaryKey??`name`),M=$m(),ne=Xm(e,M,a?.label??e),N=e=>{let t=`engine.list.col.${e.key}`,n=X(t,M);return n===t?e.label:n};return(0,Y.jsx)(Ah,{entry:a??{type:e,label:e},stats:[{label:X(`engine.list.items`,M),value:c.length},{label:X(`engine.list.filtered`,M),value:k.length},...j>0?[{label:X(`engine.list.invalid`,M),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(ut,{className:`w-3.5 h-3.5`}),j]})}]:[],...ee>0?[{label:X(`engine.list.warnings`,M),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(ut,{className:`w-3.5 h-3.5`}),ee]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Nh,{entry:a,location:`list_toolbar`,onAfter:()=>S(e=>e+1)}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>S(e=>e+1),title:X(`engine.list.refresh`,M),children:(0,Y.jsx)(Ni,{className:`h-4 w-4`})}),(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,Y.jsxs)(G,{size:`sm`,variant:o.createFields?`default`:`outline`,onClick:()=>t(`./new${D}`),title:o.createFields?Qm(`engine.list.createHint`,M,{type:ne}):void 0,children:[(0,Y.jsx)(K,{className:`h-4 w-4 mr-1`}),X(`engine.list.create`,M)]})]}),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)(go,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(U,{className:`pl-8`,placeholder:X(`engine.list.search`,M),value:h,onChange:e=>g(e.target.value)})]}),(0,Y.jsxs)(Pn,{value:_,onValueChange:v,children:[(0,Y.jsx)(nr,{className:`w-[180px]`,children:(0,Y.jsx)(bt,{})}),(0,Y.jsxs)(wo,{children:[(0,Y.jsxs)(We,{value:`all`,children:[X(`engine.list.allSources`,M),` (`,A.all,`)`]}),(0,Y.jsxs)(We,{value:`artifact`,children:[X(`engine.list.source.artifact`,M),` (`,A.artifact,`)`]}),(0,Y.jsxs)(We,{value:`runtime`,children:[X(`engine.list.source.runtime`,M),` (`,A.runtime,`)`]})]})]})]}),(d||C===null)&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[X(`engine.edit.loading`,M),` `,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&&C!==null&&C.length===0&&(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:`No project packages installed`}),(0,Y.jsx)(xt,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!d&&!p&&C!==null&&C.length>0&&k.length===0&&(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:c.length===0?Qm(`engine.list.emptyType`,M,{type:ne}):Qm(`engine.list.emptyQuery`,M,{query:h})}),(0,Y.jsx)(xt,{children:o.emptyStateHint??(a?.allowOrgOverride||a?.allowRuntimeCreate?Qm(`engine.list.createHint`,M,{type:ne}):X(`engine.list.readOnlyHint`,M))}),c.length===0&&(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(G,{onClick:()=>t(`./new${D}`),children:[(0,Y.jsx)(K,{className:`h-4 w-4 mr-1`}),X(`engine.list.create`,M)]})})]}),!d&&k.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:[te.map(e=>(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:N(e)},e.key)),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:X(`engine.list.col.source`,M)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:k.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:[te.map((t,n)=>{let o=e.item[t.key],d=t.render?t.render(o,e.item):Wh(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`,M),title:`${Qm(`engine.list.invalidCount`,M,{count:s.length})}\n${u}`,children:(0,Y.jsx)(ut,{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`,M),title:`${Qm(`engine.list.warnCount`,M,{count:c.length})}\n${u}`,children:(0,Y.jsx)(ut,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,Y.jsx)(i,{to:`./${encodeURIComponent(r)}${D}`,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)($e,{className:`h-3 w-3`})}),(0,Y.jsx)(V,{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`,M)}${e.item._packageId?` (${e.item._packageId})`:``}`:X(`engine.list.source.runtimeDesc`,M),children:X(`engine.list.source.${e.source}`,M)})]})]},r+t)})})]})})]})})}function Uh(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Wh(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 Gh={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 Kh(e,t){let n=qh(e)?e:{},r=qh(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`:Jh(o)===Jh(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 qh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Jh(e){try{return JSON.stringify(e,(e,t)=>qh(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Yh(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 Xh(e,t){if(e==null)return 0;let n=0;for(let r of Kh(e,t))r.status!==`unchanged`&&(n+=1);return n}function Zh({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)(ke,{defaultValue:`diff`,className:`w-full`,children:[(0,Y.jsxs)(Ua,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(ca,{value:`diff`,children:X(`engine.layers.diff`,n)}),(0,Y.jsxs)(ca,{value:`code`,children:[X(`engine.layers.code`,n),(0,Y.jsx)(V,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Y.jsxs)(ca,{value:`overlay`,children:[X(`engine.layers.overlay`,n),r?(0,Y.jsx)(V,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Y.jsx)(V,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Y.jsxs)(ca,{value:`effective`,children:[X(`engine.layers.effective`,n),(0,Y.jsx)(V,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Y.jsx)(ci,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(Qh,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(ci,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(eg,{payload:e.code,emptyHint:X(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(ci,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(eg,{payload:e.overlay,emptyHint:X(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(ci,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(eg,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Qh({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(()=>Kh(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:Qm(`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)(Zi,{checked:r,onCheckedChange:i,"aria-label":X(`engine.layers.diff.showUnchanged`,n)}),X(`engine.layers.diff.showUnchanged`,n),(0,Y.jsx)(V,{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=Gh[e.status];return(0,Y.jsxs)(`div`,{className:H(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,Y.jsx)($h,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)($h,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:H(`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 $h({value:e,muted:t}){let n=Yh(e);return(0,Y.jsx)(`div`,{className:H(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function eg({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})}var tg={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},ng={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function rg(e,t){return X(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function ig(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function ag(e,t){let n=0;for(let r of Kh(e,t))r.status!==`unchanged`&&(n+=1);return n}function og({published:e,draft:t,locale:n,className:r}){let i=J.useMemo(()=>Kh(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:X(`designer.draftReview.empty`,n)}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${ng[t]}`,children:[(0,Y.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${tg[t]}`,children:rg(t,n)}),(0,Y.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:ig(e.effectiveValue)}):t===`removed`?(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:ig(e.codeValue)}):(0,Y.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:ig(e.codeValue)}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:ig(e.effectiveValue)})]})]},e.key)})})}function sg(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return cg(n.trim(),t)}catch{return!0}}function cg(e,t){let n=lg(e,`||`);if(n.length>1)return n.some(e=>cg(e.trim(),t));let r=lg(e,`&&`);if(r.length>1)return r.every(e=>cg(e.trim(),t));if(e.startsWith(`!`))return!cg(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=ug(i[1].trim(),t),n=dg(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=ug(a[1].trim(),t),n=dg(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!ug(e,t)}function lg(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 ug(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return dg(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function dg(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 fg({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)(U,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,Y.jsx)(U,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,Y.jsxs)(Pn,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:`Select object…`})}),(0,Y.jsx)(wo,{children:a.map(e=>(0,Y.jsx)(We,{value:e,children:e},e))})]})}function pg({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)(U,{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)(Pn,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:s?`Add objects...`:`Select object...`})}),(0,Y.jsx)(wo,{children:o.map(e=>(0,Y.jsxs)(We,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function mg({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)(U,{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)(Pn,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:p?`Add fields...`:`Select field...`})}),(0,Y.jsx)(wo,{children:o.map(e=>(0,Y.jsx)(We,{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)(U,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function hg({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)(gg,{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)(Mn,{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)(K,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function gg({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,Y.jsx)(fg,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,Y.jsxs)(Pn,{value:t==null?``:String(t),onValueChange:e=>i(e||void 0),disabled:n,children:[(0,Y.jsx)(nr,{className:`h-8 text-xs`,children:(0,Y.jsx)(bt,{placeholder:`—`})}),(0,Y.jsx)(wo,{children:a.map(e=>(0,Y.jsx)(We,{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)(U,{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)(U,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function _g({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 vg=`__none__`;function yg({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectFields??[],o=t==null?``:String(t),s=!o||a.some(e=>e.name===o);return(0,Y.jsxs)(Pn,{value:o||vg,onValueChange:e=>n(e===vg?``:e),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:a.length?`Select field…`:`No object bound`})}),(0,Y.jsxs)(wo,{children:[(0,Y.jsx)(We,{value:vg,children:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`— None —`})}),!s&&o&&(0,Y.jsxs)(We,{value:o,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:o}),(0,Y.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:`(not in object)`})]}),a.map(e=>(0,Y.jsx)(We,{value:e.name,children:(0,Y.jsxs)(`span`,{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.name})]})},e.name))]})]})}function bg({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectFields??[],o=Array.isArray(t)?t.map(String):typeof t==`string`&&t?t.split(`,`).map(e=>e.trim()).filter(Boolean):[],s=e=>a.find(t=>t.name===e)?.label||e,c=a.filter(e=>!o.includes(e.name)),l=e=>{o.includes(e)||n([...o,e])},u=e=>{let t=o.slice();t.splice(e,1),n(t)},d=(e,t)=>{let r=e+t;if(r<0||r>=o.length)return;let i=o.slice();[i[e],i[r]]=[i[r],i[e]],n(i)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o.length>0&&(0,Y.jsx)(`div`,{className:`space-y-1`,children:o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 rounded border border-input bg-background px-2 py-1 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`flex-1 truncate`,children:[s(e),(0,Y.jsx)(`code`,{className:`ml-2 text-xs text-muted-foreground`,children:e})]}),!r&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Move up`,disabled:t===0,onClick:()=>d(t,-1),className:`px-1 text-muted-foreground hover:text-foreground disabled:opacity-30`,children:`↑`}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Move down`,disabled:t===o.length-1,onClick:()=>d(t,1),className:`px-1 text-muted-foreground hover:text-foreground disabled:opacity-30`,children:`↓`}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e}`,onClick:()=>u(t),className:`px-1 text-muted-foreground hover:text-destructive`,children:`×`})]})]},e))}),!r&&(0,Y.jsxs)(Pn,{value:``,onValueChange:l,disabled:c.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:a.length?c.length?`Add field…`:`All fields added`:`No object bound`})}),(0,Y.jsx)(wo,{children:c.map(e=>(0,Y.jsx)(We,{value:e.name,children:(0,Y.jsxs)(`span`,{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.name})]})},e.name))})]})]})}var xg={"ref:object":fg,"object-selector":pg,"field-selector":mg,"field-ref":yg,"field-multi":bg,"master-detail":hg,"string-tags":_g,code:wg,"filter-builder":hg};function Sg(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 Cg=J.lazy(()=>c(()=>import(`./src-CefK1cl3.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function wg({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=Sg(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)(Cg,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var Tg=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function Eg(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 Dg(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 Og(e,t,n){if(n?.objectFields&&!Array.isArray(t?.enum)){if(t?.type===`array`&&t.items?.type===`string`&&(/Fields$/.test(e)||e===`columns`||e===`fieldOrder`))return`field-multi`;if((t?.type===`string`||Array.isArray(t?.anyOf)&&t.anyOf.some(e=>e?.type===`string`))&&(/.Field$/.test(e)||e===`field`))return`field-ref`}}function kg({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=zg(n);else return(0,Y.jsx)(Rg,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=Hg(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)(jg,{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)(Mg,{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 Ag(e){return typeof e==`string`?{field:e}:e}function jg({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||sg(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(Ag).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!sg(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)(Mg,{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(Ag).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||sg(e.visibleOn,{data:a}))));return e.length===0?null:(0,Y.jsxs)(ke,{defaultValue:(e[0].label??`section-0`).toLowerCase(),className:`w-full`,children:[(0,Y.jsx)(Ua,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,Y.jsx)(ca,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,Y.jsx)(ci,{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 Mg({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||Vg(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=Dg(o,t);if(!o?.widget){let n=Og(e,t,s);n&&(p=n)}let m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=Vg(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)(W,{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)(Ng,{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)(W,{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)(Ng,{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 Ng({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)(Fg,{value:n,fields:o.fields?.length?o.fields:Ug(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,Y.jsx)(Ig,{value:n,fields:o.fields?.length?o.fields:Ug(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(o?.type===`record`){let e=t?.additionalProperties??{};return(0,Y.jsx)(Lg,{value:n,fields:o.fields?.length?o.fields:Ug(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,keyField:o.keyField,formData:c,onChange:r})}if(a){let l=xg[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=Eg(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)(kg,{schema:u,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(u?.type===`array`&&u.items&&typeof u.items==`object`){let e=Eg(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)(Ig,{value:n,fields:Ug(e),schema:{...u,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}if(!Tg.has(a))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(Rg,{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=Eg(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)(Pn,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:`Select…`})}),(0,Y.jsx)(wo,{children:d.map(e=>(0,Y.jsxs)(We,{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)(Pn,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(bt,{placeholder:`Select…`})}),(0,Y.jsx)(wo,{children:f.map(e=>(0,Y.jsx)(We,{value:String(e),children:String(e)},String(e)))})]});if(u===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,Y.jsx)(Zi,{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)(U,{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)(Cn,{id:e,rows:4,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,Y.jsx)(U,{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)(U,{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)(kg,{schema:l,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(l?.type===`array`&&l.items&&typeof l.items==`object`){let e=Eg(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)(Ig,{value:n,fields:Ug(e),schema:{...l,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}return(0,Y.jsx)(Rg,{value:n,onChange:r,readOnly:i,small:!0})}function Pg(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 Fg({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(Ag).map(e=>{let t=Pg(n,`composite`,e.field);return(0,Y.jsx)(Mg,{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 Ig({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(Ag),[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||Vg(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`,$m())})}),s.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=Pg(n,`repeater`,a.field);return(0,Y.jsx)(`td`,{className:`p-1.5`,children:(0,Y.jsx)(Ng,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:Dg(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)(Mn,{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)(K,{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`,$m())}),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)(Ya,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Yr,{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)(Mn,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=Pg(n,`repeater`,a.field);return(0,Y.jsx)(Mg,{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)(K,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function Lg({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,keyField:o,formData:s,onChange:c}){if(a){let o=xg[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??Vg(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(Ag).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,A]=J.useState(null),j=(e,t)=>{if(e===t)return;let n=m.map(([e])=>e),r=n.indexOf(e),i=n.indexOf(t);if(r<0||i<0)return;n.splice(r,1),n.splice(i,0,e);let a={};for(let e of n)a[e]=p[e];S(a)};return(0,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`,$m())}),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&&A(e))},onDragLeave:()=>{k===e&&A(null)},onDrop:t=>{!D||r||(t.preventDefault(),j(D,e),O(null),A(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),A(null)},className:`cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground`,"aria-label":`Drag to reorder`,title:`Drag to reorder`,children:(0,Y.jsx)(Ae,{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)(Ya,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Yr,{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)(Mn,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(Mg,{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&&!sg(a.visibleOn,{data:t}))return null;let o=Pg(n,`record`,a.field);return(0,Y.jsx)(Mg,{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)(U,{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)(K,{className:`h-3.5 w-3.5 mr-1`}),` Add`]}),b&&(0,Y.jsx)(`span`,{className:`text-xs text-destructive`,children:b})]})]})}function Rg({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=J.useState(()=>Bg(e)),[o,s]=J.useState(null);return J.useEffect(()=>{a(Bg(e)),s(null)},[JSON.stringify(e)]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(Cn,{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 zg(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 Bg(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Vg(e){return e.replace(/[_-]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function Hg(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 Ug(e){let t=e?.properties??{};return Object.keys(t)}function Wg(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 Gg(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 Kg(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function qg(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function Jg(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return Wg(n);case`plural-en`:return Gg(n);case`titlecase`:return Kg(n);case`first-token`:return qg(n);default:return n}}function Yg(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=Jg(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 Xg(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 Zg({type:e,name:t,parentItem:n,onOpen:r}){let i=Rm(),a=s(),o=J.useMemo(()=>Rh(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(Qg)}}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=>Qg(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)(at,{children:[(0,Y.jsx)(bo,{children:`No related metadata`}),(0,Y.jsxs)(xt,{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)(go,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(U,{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)(Yr,{className:H(`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)(V,{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)(K,{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)(B,{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)(pn,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function Qg(e){return{name:$g(e,[`name`,`id`,`key`])??`(unnamed)`,label:$g(e,[`label`,`title`,`displayName`]),description:$g(e,[`description`,`summary`]),raw:e}}function $g(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function e_({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=Rm(),{entries:c}=Bm(s),l=i?c.find(e=>e.type===i):void 0,u=!l?.schema&&i?n_[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=t_(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)(kg,{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)(B,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(In,{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)(ut,{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)(B,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(In,{className:`h-4 w-4 mr-1`}),`Save into parent`]})})]})}function t_(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 n_={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 r_({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)(en,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)(ln,{side:`right`,className:H(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Y.jsxs)(ft,{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)(V,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,Y.jsx)(Dt,{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)(pn,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Y.jsxs)(Sn,{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)(gv,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,Y.jsx)(e_,{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 i_({type:e,name:t}){let n=f(),r=e??n.type??``,i=t??n.name??``,a=s(),o=Rm(),{entries:c}=Bm(o),l=c.find(e=>e.type===r),[u,d]=J.useState(0),[p,m]=J.useState(0);return(0,Y.jsx)(Ah,{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)(Jn,{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)(Ni,{className:`h-4 w-4`})})]}),children:(0,Y.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Y.jsx)(a_,{type:r,name:i,refreshKey:u,onCount:m,client:o,onRollback:()=>d(e=>e+1)})})})}function a_({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)(B,{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)(at,{children:[(0,Y.jsx)(bo,{children:`No history yet`}),(0,Y.jsx)(xt,{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)(V,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Y.jsxs)(V,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Y.jsx)(V,{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:o_(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)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(et,{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:s_(e)})]})]},`${e.seq??t}-${t}`)})})]})}function o_(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function s_(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function c_(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function l_(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:_a},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:Qr},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:$i}},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 u_({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)(B,{className:`h-3 w-3 animate-spin`}):(0,Y.jsx)(Ni,{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)(B,{className:`mr-2 h-3 w-3 animate-spin`}),X(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Y.jsxs)(at,{className:`py-10`,children:[(0,Y.jsx)(bo,{children:X(`engine.edit.auditEmptyTitle`,r)}),(0,Y.jsx)(xt,{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:c_(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)(V,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:l_(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 d_=new Map;function f_(e,t){d_.set(e,t)}function p_(e){return d_.get(e)}function m_(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 h_(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 g_(e,t){return e.entries.findIndex(e=>e.name===t)}function __(e,t,n){let r={type:t,label:n??v_(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function v_(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function y_(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 b_(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:``})).filter(e=>e.key):[]}function x_(e,t){let n=/[a-z0-9]/i.test(e)?y_(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function S_(e,t){let n=t.trim()||`New section`,r=x_(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function C_(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function w_(e,t){return e.filter(e=>e.key!==t)}function T_(e,t,n){let r=e.findIndex(e=>e.key===t);if(r<0)return e;let i=r+n;return i<0||i>=e.length?e:D_(e,r,i)}function E_(e,t){return{shape:e.shape,entries:e.entries.map(e=>e.def.group===t?{name:e.name,def:{...e.def,group:void 0}}:e)}}function D_(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function O_(e,t,n){let r=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],i=new Map;for(let e of r)i.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let a=new Set(r.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&a.has(e)?i.get(e).entries.push(t):(i.has(null)||i.set(null,{key:null,label:`Ungrouped`,entries:[]}),i.get(null).entries.push(t))}let o=!!n?.includeEmptyDeclared;return Array.from(i.values()).filter(e=>e.entries.length>0||o&&e.key!==null)}function k_(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function A_(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)k_(e[i],t[i])||r.push(i);return r.sort()}function j_(e,t){let n=m_(e),r=m_(t),i=new Map(n.entries.map(e=>[e.name,e])),a=new Set(r.entries.map(e=>e.name)),o={},s=0,c=0;for(let e of r.entries){let t=i.get(e.name);if(!t){o[e.name]={name:e.name,status:`added`,changedKeys:[]},s+=1;continue}let n=A_(t.def,e.def);n.length?(o[e.name]={name:e.name,status:`changed`,changedKeys:n},c+=1):o[e.name]={name:e.name,status:`unchanged`,changedKeys:[]}}let l=n.entries.filter(e=>!a.has(e.name));return{byName:o,removed:l,counts:{added:s,changed:c,removed:l.length}}}var M_=new Map;function N_(e,t){M_.set(e,t)}function P_(e){return M_.get(e)}var F_=new Map;function I_(e,t){F_.set(e,t)}function L_(e){return F_.get(e)}function R_(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&&V_(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&V_(e.charCodeAt(r)))for(r++;r<e.length&&V_(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&&V_(e.charCodeAt(r))){for(r++;r<e.length&&V_(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(B_(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(z_(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(z_(t));return o=15}if(B_(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&&!B_(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++,B_(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||!V_(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(z_(e)||B_(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 z_(e){return e===32||e===9}function B_(e){return e===10||e===13}function V_(e){return e>=48&&e<=57}var H_;(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`})(H_||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var U_=200;Array(U_).fill(0).map((e,t)=>`
|
|
19
|
-
`+` `.repeat(t)),Array(U_).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(U_).fill(0).map((e,t)=>`\r
|
|
20
|
-
`+` `.repeat(t)),Array(U_).fill(0).map((e,t)=>`
|
|
21
|
-
`+` `.repeat(t)),Array(U_).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(U_).fill(0).map((e,t)=>`\r
|
|
22
|
-
`+` `.repeat(t));var W_;(function(e){e.DEFAULT={allowTrailingComma:!1}})(W_||={});function G_(e,t=[],n=W_.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}q_(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:J_(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 K_(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 q_(e,t,n=W_.DEFAULT){let r=R_(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 J_(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 Y_;(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`})(Y_||={});var X_;(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`})(X_||={});var Z_=G_,Q_=K_,$_;(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`})($_||={});var ev=J.lazy(async()=>({default:(await c(()=>import(`./dist-BG5mNWi0.js`),[],import.meta.url)).default}));function tv(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function nv(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function rv({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let[a,o]=J.useState(()=>tv(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=Z_(a)}catch{i=void 0}let o=r.map(e=>{let r=nv(e.path),a=1,o=1,s=1,c=2,l=i?Q_(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=tv(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)(ze,{className:`w-full h-full`}),children:(0,Y.jsx)(ev,{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 iv={object:async()=>(await c(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.p);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await c(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.p);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await c(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.p);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await c(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.p);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await c(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await c(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await c(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await c(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await c(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await c(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await c(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.u);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await c(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.i);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await c(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.i);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await c(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.o);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await c(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.o);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await c(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.o);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await c(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await c(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await c(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await c(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await c(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-DCNcl1ou.js`).then(e=>e.a);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},av=new Set([`approval`,`connector_action`]),ov=/^nodes\.(\d+)\.type$/;function sv(e,t){let n=e?.nodes;if(!Array.isArray(n))return;let r=n[t];return typeof r?.type==`string`?r.type:void 0}var cv=new Map;async function lv(e){if(cv.has(e))return cv.get(e)??null;let t=iv[e];if(!t)return cv.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return cv.set(e,r),r}catch{return cv.set(e,null),null}}function uv(e){return e in iv}async function dv(e,t){let n=await lv(e);if(!n)return{ok:!0,issues:[]};let r=n.safeParse(t);if(r.success)return{ok:!0,issues:[]};let i=r.error?.issues??[];return e===`flow`&&(i=i.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=ov.exec(n);if(!r)return!0;let i=sv(t,Number(r[1]));return!(i&&av.has(i))})),i.length===0?{ok:!0,issues:[]}:{ok:!1,issues:i.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message}))}}var fv=Da,pv=new Set([`object`]),mv={object:[`fields`,`fieldGroups`]};function hv(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 gv({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=f(),a=e??i.type??``,o=t??i.name??``,s=Lh(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)(_v,{type:a,name:o,createMode:n,embedded:r})}function _v({type:e,name:t,createMode:n,embedded:r}){let i=s(),[a,o]=l(),c=Rm(),{entries:u}=Bm(c),d=u.find(t=>t.type===e),f=zh(e,d),p=(n&&f.createSchema?f.createSchema:d?.schema)??f.defaultSchema,m=J.useMemo(()=>$m(),[]),[h,g]=J.useState(null),_=f.identityField??`name`,[v,y]=J.useState(()=>n?{...f.createDefaults??{},[_]:``}:{}),[b,x]=J.useState(null),[S,C]=J.useState(!n),[w,T]=J.useState(!1),[E,D]=J.useState(null),[O,k]=J.useState([]),A=J.useCallback(e=>{y(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&&k(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[j,ee]=J.useState(null),[te,M]=J.useState(null),ne=J.useCallback(e=>{A(t=>({...t,...e}))},[A]),{markTouched:N}=Yg({rules:f.createDerive,draft:v,onPatch:ne,enabled:!!n}),P=J.useMemo(()=>{if(n)return f.createFields&&f.createFields.length>0?f.createFields:Xg(p?.properties??void 0,p?.required??void 0)},[n,f.createFields,p]),re=J.useMemo(()=>{let t=mv[e]??[];if(!n||!P)return t.length===0?f.hiddenFields:Array.from(new Set([...f.hiddenFields??[],...t]));let r=p?.properties??{},i=new Set(P),a=Object.keys(r).filter(e=>!i.has(e));if(f.hiddenFields)for(let e of f.hiddenFields)a.includes(e)||a.push(e);for(let e of t)a.includes(e)||a.push(e);return a},[n,P,p,f.hiddenFields,e]),ie=J.useMemo(()=>n&&P?P:f.fieldOrder,[n,P,f.fieldOrder]),ae=J.useCallback(e=>{if(n){let t=v,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])||N(e)}A(e)},[n,v,A,N]);J.useEffect(()=>{if(!uv(e))return;let t=!1,n=window.setTimeout(()=>{dv(e,v).then(e=>{t||k(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,v]);let[F,oe]=J.useState(!1),[se,ce]=J.useState(!1),[le,ue]=J.useState(0),[de,fe]=J.useState(!!n),[pe,me]=J.useState(null);J.useEffect(()=>{me(null)},[e,t]),J.useEffect(()=>{de||me(null)},[de]);let I=J.useRef(null),[he,ge]=J.useState(null),[_e,L]=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`,_e?`1`:`0`)}catch{}},[_e]);let ve=J.useRef(null),[R,ye]=J.useState([]),[be,z]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await c.list(`object`);if(e)return;ye(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||ye([])}finally{e||z(!1)}})(),()=>{e=!0}},[c]);let xe=J.useMemo(()=>({objectNames:R,objectsLoading:be}),[R,be]);J.useEffect(()=>{if(n){C(!1);return}let r=!1;return C(!0),D(null),(async()=>{try{let[n,i]=await Promise.all([c.layered(e,t),c.getDraft(e,t).catch(()=>null)]);if(r)return;g(n);let a=n?._diagnostics;a&&a.valid===!1&&Array.isArray(a.errors)?k(a.errors.map(e=>({path:e.path||``,message:e.message}))):k([]);let o=hv(i),s=o??n.effective??n.code??{},l=f.toDraft?f.toDraft(s):s;y(l),I.current=l,oe(!!o),C(!1)}catch(e){r||(D(e?.message??String(e)),C(!1))}})(),()=>{r=!0}},[c,e,t,n,le]);let[Se,Ce]=J.useState(!1);async function we(){if(!(b!=null||Se)){Ce(!0);try{x(await c.references(e,t))}catch(e){x([]),console.error(`references() failed`,e)}finally{Ce(!1)}}}let[Te,Ee]=J.useState(null),De=J.useMemo(()=>!n&&!r&&Rh(e).length>0,[e,n,r]),Oe=J.useRef(null),[ke,Ae]=J.useState(null),Me=a.get(`review`),Ne=J.useRef(!1);J.useEffect(()=>{if(!(Me!==`1`||n)){if(!Ne.current){Ne.current=!0,ue(e=>e+1);return}if(!S){F&&Ae(`review`);let e=new URLSearchParams(a);e.delete(`review`),o(e,{replace:!0}),Ne.current=!1}}},[Me,n,S,F]);let[Pe,Fe]=J.useState(`properties`);J.useEffect(()=>{if(ke===`references`&&we(),typeof window<`u`&&!r){let e=new URL(window.location.href);ke?e.searchParams.set(`tab`,ke):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[ke,r]);let Ie=`metadata-edit:inspector-collapsed`,Le=`metadata-edit:inspector-size`,[Re,ze]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Ie)===`1`),Be=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(Le));Number.isFinite(e)&&e>=22&&e<=80&&(Be.current=e)},[]);let He=J.useRef(null),Ue=J.useCallback(()=>{ze(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Ie,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=He.current;if(e)if(Re)e.resize?.(`0%`);else{let t=Be.current||38;e.resize?.(`${t}%`)}},[Re]);let[We,Ge]=J.useState(!1),[qe,Je]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!qe)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[qe]),J.useEffect(()=>{if(typeof window>`u`||!qe)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Je(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[qe]);let Ye=J.useRef(null);J.useEffect(()=>{Ye.current=null},[e,t]),J.useEffect(()=>{if(n||r||S)return;let i=`${e}/${t??``}`;Ye.current!==i&&p_(e)&&(h?.code==null?d?.allowOrgOverride||d?.allowRuntimeCreate:d?.allowOrgOverride)&&(Ye.current=i,fe(!0))},[e,t,n,r,S,d,h]),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(),Ue())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Ue]),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`)&&Ae(t),Oe.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&Ee({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);Te?.kind===`metadata`?e.searchParams.set(`open`,`${Te.type}:${Te.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[Te,r]);async function Xe(r){T(!0),D(null),k([]);try{let a=n?f.createBuildBody?f.createBuildBody(v):{...f.createDefaults??{},...v}:f.fromDraft?f.fromDraft(v):v,o=String(a[_]??v[_]??t),s=n?{...a,[_]:o}:a;if(!o){D(`A name is required.`),T(!1);return}let l=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await c.save(e,o,s,{force:r,mode:`draft`,...l?{packageId:l}:{}});let[u,d]=await Promise.all([c.layered(e,o),c.getDraft(e,o).catch(()=>null)]);g(u);let p=hv(d);oe(!!p);let m=p??u.effective??s,h=f.toDraft?f.toDraft(m):m;y(h),I.current=h,ge(new Date),ve.current=JSON.stringify(h),ee(null),M(null);let b=!n&&!!p_(e);!n&&!b&&fe(!1),n&&i(`../${encodeURIComponent(o)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];ee(Array.isArray(t)?t:[]),M(v)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:String(e.message??`Invalid`)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:e[2].trim()}]:[{path:``,message:r}]}k(n),n.length===1&&!n[0].path?D(n[0].message):n.length===1?D(`${n[0].path}: ${n[0].message}`):D(`Validation failed (${n.length} issues).`)}else D(e?.message??String(e))}finally{T(!1)}}async function Qe(){let r=!n&&h?.code!=null;if(confirm(Qm(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,m,{type:e,name:t??``}))){T(!0),D(null);try{if(await c.reset(e,t),r){let n=await c.layered(e,t);g(n);let r=n.effective??n.code??{};y(r),I.current=r,p_(e)?Ye.current=null:fe(!1)}else i(`../`,{relative:`path`})}catch(e){D(e?.message??String(e))}finally{T(!1)}}}async function nt(){ce(!0),D(null);try{await c.publish(e,t);let[n,r]=await Promise.all([c.layered(e,t),c.getDraft(e,t).catch(()=>null)]);g(n);let i=hv(r);oe(!!i);let a=i??n.effective??v;y(a),I.current=a}catch(e){D(e?.message??String(e))}finally{ce(!1)}}async function rt(){if(confirm(Qm(`engine.edit.discardDraftConfirm`,m,{type:e,name:t??``}))){T(!0),D(null);try{await c.reset(e,t,{state:`draft`});let n=await c.layered(e,t);g(n);let r=n.effective??n.code??{};y(r),I.current=r,oe(!1)}catch(e){D(e?.message??String(e))}finally{T(!1)}}}let it=J.useMemo(()=>{if(n)return Object.keys(v).length>0;let e=I.current;if(!e)return!1;try{return JSON.stringify(v)!==JSON.stringify(e)}catch{return!1}},[v,n]),at=!n&&h?.code!=null,ot=h?.editable!==!1,st=h?.deletable!==!1,lt=h?.resettable!==!1,dt=h?.lockReason,pt=h?.lock&&h.lock!==`none`,mt=(n?!!(d?.allowOrgOverride||d?.allowRuntimeCreate):at?!!d?.allowOrgOverride:!!(d?.allowOrgOverride||d?.allowRuntimeCreate))&&(n||ot),ht=!mt&&!n,gt=J.useRef(Xe);if(J.useEffect(()=>{gt.current=Xe}),J.useEffect(()=>{if(!_e||n||ht||!de||!it||w)return;let e;try{e=JSON.stringify(v)}catch{return}if(e===ve.current)return;let t=window.setTimeout(()=>{ve.current=e,gt.current(!1)},1500);return()=>window.clearTimeout(t)},[v,it,de,w,n,ht,_e]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!mt||ht||!de&&!n)return;e.preventDefault(),!w&&(n||it)&>.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[mt,ht,de,n,w,it]),J.useEffect(()=>{if(!it)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[it]),J.useEffect(()=>{if(!it)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`,m))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[it,m]),xc(J.useMemo(()=>{if(r)return null;let n=String(v.name??t??``);if(!n)return null;let i={type:e,name:n,label:typeof v.label==`string`?v.label:void 0};return e===`object`&&(i.fields=m_(v.fields).entries.slice(0,60).map(e=>({name:e.name,type:typeof e.def.type==`string`?e.def.type:void 0,label:typeof e.def.label==`string`?e.def.label:void 0,required:!!e.def.required||void 0}))),i},[r,e,t,v])),S)return(0,Y.jsx)(Ah,{entry:d,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let vt=ht&&at&&!!d?.allowRuntimeCreate,yt=pv.has(e),bt=!r&&(!n||yt)?p_(e):void 0,xt=P_(e),St=L_(e);function wt(){I.current&&y(I.current),k([]),D(null),fe(!1)}let Tt=ht||!de&&!n,Et=(0,Y.jsxs)(Y.Fragment,{children:[!n&&(0,Y.jsx)(Nh,{entry:d,location:`record_header`,recordId:t,onAfter:()=>ue(e=>e+1)}),(!n||De)&&(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:()=>Ae(`layers`),title:X(`engine.edit.layers`,m),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Vt,{className:`h-3.5 w-3.5`}),h?.overlay&&(()=>{let e=Xh(h.code,h.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`,m),children:e}):null})()]}),!n&&F&&(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`review`),title:X(`designer.draftReview.title`,m),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,Y.jsx)(ka,{className:`h-3.5 w-3.5`}),(()=>{let e=ag(h?.effective??null,v);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-amber-500 text-amber-50 text-[9px] leading-[14px] text-center font-medium`,title:Qm(`designer.draftReview.badge`,m,{n:e}),children:e}):null})()]}),!n&&(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`references`),title:X(`engine.edit.references`,m),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Yt,{className:`h-3.5 w-3.5`}),b&&b.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:b.length})]}),De&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`related`),title:X(`engine.edit.related`,m),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Ze,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`history`),title:X(`engine.edit.history`,m),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:()=>Ae(`audit`),title:X(`engine.edit.auditTab`,m),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(_a,{className:`h-3.5 w-3.5`})})]}),!n&&mt&&h?.overlay&&(at?lt:st)&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:Qe,disabled:w,title:X(at?`engine.edit.reset`:`engine.edit.delete`,m),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:at?(0,Y.jsx)(et,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Mn,{className:`h-3.5 w-3.5`})}),mt&&!n&&!de&&!bt&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>fe(!0),className:`h-7`,children:[(0,Y.jsx)(Ft,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,m)]}),mt&&(de||n)&&(0,Y.jsx)(yv,{saving:w,isDirty:it,autoSaveEnabled:_e,lastSavedAt:he,createMode:!!n,locale:m}),mt&&(de||n)&&!n&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>L(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:X(_e?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,m),children:_e?(0,Y.jsx)(_o,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(Hr,{className:`h-3.5 w-3.5`})}),mt&&!n&&de&&!bt&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:wt,disabled:w,className:`h-7 w-7 p-0`,title:X(`engine.cancel`,m),children:(0,Y.jsx)(po,{className:`h-3.5 w-3.5`})}),mt&&(de||n)&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>Xe(!1),disabled:w||!n&&!it,className:`h-7 w-7 p-0 relative`,title:w?X(`engine.edit.saving`,m):!n&&!it?X(`engine.edit.noChanges`,m):`${X(`engine.edit.save`,m)} (⌘S)`,children:[w?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(In,{className:`h-3.5 w-3.5`}),it&&!w&&(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`})]}),mt&&!n&&F&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:rt,disabled:w||se,className:`h-7 w-7 p-0 text-muted-foreground`,title:X(`engine.edit.discardDraft`,m),children:(0,Y.jsx)(sn,{className:`h-3.5 w-3.5`})}),mt&&!n&&F&&(0,Y.jsx)(G,{size:`sm`,onClick:nt,disabled:w||se||it,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:X(it?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,m),children:se?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qa,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:X(`engine.edit.publish`,m)})]})})]});return(0,Y.jsxs)(Ah,{entry:d??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?X(`engine.edit.createNew`,m):void 0,actions:bt?null:Et,children:[(0,Y.jsxs)(`div`,{className:bt?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(E||ht||F||pt)&&(0,Y.jsxs)(`div`,{className:bt?`px-6 pt-4 space-y-3`:`space-y-3`,children:[E&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:E}),pt&&(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)($e,{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:[h?.lock===`full`&&X(`engine.edit.lockFull`,m),h?.lock===`no-overlay`&&X(`engine.edit.lockNoOverlay`,m),h?.lock===`no-delete`&&X(`engine.edit.lockNoDelete`,m)]}),dt&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:dt}),h?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:h.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:[m===`zh-CN`?`查看文档`:`View docs`,` →`]}),h?.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:[h.packageId,h.packageVersion?`@${h.packageVersion}`:``]})})]}),vt&&(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`,m)})]}),F&&!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)(Qa,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:X(`engine.edit.draftPending`,m)}),mt&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{size:`sm`,variant:`ghost`,onClick:rt,disabled:w||se,className:`h-7`,children:X(`engine.edit.discardDraft`,m)}),(0,Y.jsx)(G,{size:`sm`,onClick:nt,disabled:w||se||it,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:se?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):X(`engine.edit.publish`,m)})]})]}),ht&&!pt&&(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:vt?X(`engine.edit.artifactLockedBanner`,m).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`,m).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))}),vt&&(0,Y.jsx)(G,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,m)})]})]}),(0,Y.jsx)(`div`,{className:bt?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:bt?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!bt&&Tt&&!ht&&mt&&!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`,m).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`,m)})]},t))}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:()=>fe(!0),children:[(0,Y.jsx)(Ft,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,m)]})]}),(()=>{let t=h?._diagnostics,n=uv(e)?O.map(e=>({path:e.path,message:e.message})):t?.errors??[],r=uv(e)?n.length===0:t?.valid!==!1;if(!t&&!uv(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)(ut,{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:Qm(a,m,{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:Qm(`engine.edit.diagnostics.more`,m,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),bt?(0,Y.jsx)(`div`,{className:qe?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(fv,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(Bt,{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:mt&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":X(`engine.edit.designer`,m),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":!We,onClick:()=>Ge(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(We?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:X(`engine.edit.designMode`,m),children:[(0,Y.jsx)(Wa,{className:`h-3.5 w-3.5`}),X(`engine.edit.designMode`,m)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":We,onClick:()=>Ge(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(We?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.previewMode`,m),children:[(0,Y.jsx)(tt,{className:`h-3.5 w-3.5`}),X(`engine.edit.previewMode`,m)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Et,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),bt&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:Ue,className:`h-7 w-7 p-0`,title:X(Re?`engine.edit.showInspector`:`engine.edit.hideInspector`,m)+` (⌘\\)`,children:Re?(0,Y.jsx)(wn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(je,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>Je(e=>!e),className:`h-7 w-7 p-0`,title:X(qe?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,m),children:qe?(0,Y.jsx)(Ci,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(zr,{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)(bt,{type:e,name:t,draft:v,baseline:n?void 0:h?.effective??void 0,editing:de&&!We,selection:We?null:pe,onSelectionChange:me,locale:m,onPatch:e=>A(t=>({...t,...e}))})})]})}),(0,Y.jsx)(_t,{withHandle:!0,className:Re?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(Bt,{panelRef:He,defaultSize:Be.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Be.current=t,typeof window<`u`&&window.localStorage.setItem(Le,String(Math.round(t)))),ze(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Ie,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":Pe===`properties`,onClick:()=>Fe(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Pe===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.properties`,m),children:[(0,Y.jsx)(Ki,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.properties`,m)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Pe===`source`,onClick:()=>Fe(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Pe===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.source`,m),children:[(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.source`,m)]})]}),it&&(0,Y.jsxs)(V,{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`,m)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:Pe===`source`?(0,Y.jsx)(rv,{value:v,onChange:A,readOnly:Tt,issues:O.map(e=>({path:e.path??``,message:e.message}))}):pe&&xt?(0,Y.jsx)(xt,{type:e,name:t,draft:v,selection:pe,onPatch:e=>A(t=>({...t,...e})),onClearSelection:()=>me(null),onSelectionChange:me,readOnly:Tt,locale:m}):!pe&&St?(0,Y.jsx)(St,{type:e,name:t,draft:v,onPatch:e=>A(t=>({...t,...e})),onSelectionChange:me,readOnly:Tt,locale:m}):(0,Y.jsx)(kg,{schema:p,form:n&&f.createSchema?void 0:d?.form,value:v,onChange:ae,issues:O,hiddenFields:re,fieldOrder:ie,readOnly:Tt,createMode:n,widgetContext:xe})})]})})]})}):(0,Y.jsx)(kg,{schema:p,form:n&&f.createSchema?void 0:d?.form,value:v,onChange:ae,issues:O,hiddenFields:re,fieldOrder:ie,readOnly:Tt,createMode:n,widgetContext:xe})]})})]}),(0,Y.jsx)(en,{open:ke===`layers`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Dt,{className:`text-base`,children:X(`engine.edit.layers`,m)}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Zh,{layered:h,locale:m})})]})}),(0,Y.jsx)(en,{open:ke===`review`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Dt,{className:`text-base`,children:X(`designer.draftReview.title`,m)}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t,` · `,X(`designer.canvas.reviewVsPublished`,m)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(og,{published:h?.effective??null,draft:v,locale:m})})]})}),(0,Y.jsx)(en,{open:ke===`references`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(Dt,{className:`text-base`,children:[X(`engine.edit.references`,m),b&&(0,Y.jsx)(V,{variant:`outline`,className:`ml-2 text-[10px]`,children:b.length})]}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(vv,{refs:b,loading:Se})})]})}),De&&(0,Y.jsx)(en,{open:ke===`related`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Dt,{className:`text-base`,children:X(`engine.edit.related`,m)}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Zg,{type:e,name:t,parentItem:v,onOpen:e=>Ee(e)})})]})}),!n&&(0,Y.jsx)(en,{open:ke===`history`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Dt,{className:`text-base`,children:X(`engine.edit.history`,m)}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(a_,{type:e,name:t,client:c,onRollback:()=>ue(e=>e+1),rollbackLabel:X(`engine.edit.rollback`,m),rollbackConfirm:e=>X(`engine.edit.rollbackConfirm`,m).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(en,{open:ke===`audit`,onOpenChange:e=>!e&&Ae(null),children:(0,Y.jsxs)(ln,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(ft,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Dt,{className:`text-base`,children:X(`engine.edit.auditTab`,m)}),(0,Y.jsxs)(Sn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(u_,{type:e,name:t,client:c,locale:m})})]})}),(0,Y.jsx)(r_,{target:Te,onClose:()=>Ee(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(ct,{open:j!=null,onOpenChange:e=>{e||(ee(null),M(null))},children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsxs)(Ve,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(Ut,{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:j?.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)(An,{children:[(0,Y.jsx)(G,{variant:`ghost`,onClick:()=>ee(null),children:`Cancel`}),(0,Y.jsx)(G,{variant:`destructive`,onClick:()=>Xe(!0),disabled:w,children:w?`Forcing…`:`Force save`})]})]})})]})}function vv({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)(B,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:`No references found`}),(0,Y.jsx)(xt,{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)(V,{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 yv({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)(B,{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:Qm(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function bv({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)(at,{children:[(0,Y.jsx)(bo,{children:`Missing metadata type`}),(0,Y.jsxs)(xt,{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=xv(t.pathname),a=i.split(`/`).filter(Boolean);return a.length===0?(0,Y.jsx)(Vh,{type:r}):a[0]===`new`&&a.length===1?(0,Y.jsx)(gv,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Y.jsx)(i_,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Y.jsx)(gv,{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)(at,{children:[(0,Y.jsx)(bo,{children:`Unknown sub-path`}),(0,Y.jsxs)(xt,{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 xv(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function Sv(){let e=Rm(),t=J.useMemo(()=>$m(),[]),[n,r]=J.useState(`error`),{loading:a,error:o,summary:s,reload:c}=Hm(e,n),{entries:l}=Bm(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=Xm(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)(Jn,{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)(ut,{className:`h-5 w-5 text-destructive`}),X(`engine.diagnostics.title`,t)]}),(0,Y.jsx)(V,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:Qm(`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)(Ni,{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:Qm(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(at,{children:[(0,Y.jsx)(bo,{children:X(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(xt,{children:Qm(`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)(V,{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)(V,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:Qm(`engine.diagnostics.errorN`,t,{count:a.length})}),o.length>0&&(0,Y.jsx)(V,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:Qm(`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:Qm(`engine.diagnostics.more`,t,{count:c})})]})})]},r.name)})})]})})]},e))]})]})}function Cv(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 wv({type:e,name:t}){let n=s(),r=Rm(),{entries:i}=Bm(r),a=i.find(t=>t.type===e),o=!!zh(e,a).allowOrgOverride,c=J.useMemo(()=>$m(),[]),l=J.useCallback(e=>X(e,c),[c]),u=J.useMemo(()=>Cv(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,A]=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 j(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 ee(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),j(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 M(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 ne(e,t,n,r){let i=`${e}.${t}`;f(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function N(t,n){let i=n??d;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 P=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]),re=[{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)(Ah,{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)(B,{className:`h-4 w-4 animate-spin`}),` `,l(`perm.loading`).replace(`{name}`,t)]})}):(0,Y.jsxs)(Ah,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?l(`perm.subtitle.profile`):l(`perm.subtitle.set`),stats:re,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)(pr,{className:`h-4 w-4 mr-1`}),` `,l(`engine.edit.history`)]}),o&&(0,Y.jsxs)(G,{size:`sm`,onClick:()=>N(!1),disabled:x,children:[x?(0,Y.jsx)(B,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(In,{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)(ut,{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)(W,{htmlFor:`perm-name`,className:`text-xs`,children:l(`perm.field.name`)}),(0,Y.jsx)(U,{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)(W,{htmlFor:`perm-label`,className:`text-xs`,children:l(`perm.field.label`)}),(0,Y.jsx)(U,{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)(Zi,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,Y.jsx)(W,{htmlFor:`perm-is-profile`,className:`text-xs`,children:l(`perm.field.isProfile`)})]}),!o&&(0,Y.jsx)(V,{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)(U,{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)(Zi,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,Y.jsx)(W,{htmlFor:`only-enabled`,className:`text-xs`,children:l(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[P.length,` / `,p.length,` `,l(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Y.jsx)(Tv,{objects:P,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:u,t:l,onToggleExpand:ee,onObjectPerm:te,onFieldPerm:ne,onBulkSet:M})})]}),(0,Y.jsx)(ct,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Y.jsxs)(Ct,{children:[(0,Y.jsxs)(So,{children:[(0,Y.jsxs)(Ve,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{className:`h-4 w-4 text-amber-500`}),` `,l(`engine.edit.destructive`)]}),(0,Y.jsx)(Ut,{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)(V,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Y.jsxs)(An,{children:[(0,Y.jsx)(G,{variant:`ghost`,onClick:()=>E(null),children:l(`engine.cancel`)}),(0,Y.jsxs)(G,{variant:`destructive`,onClick:()=>T&&N(!0,T.pending),disabled:x,children:[x&&(0,Y.jsx)(B,{className:`h-4 w-4 mr-1 animate-spin`}),l(`engine.edit.forceSave`)]})]})]})})]})}function Tv({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)(Ya,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Yr,{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)(mt,{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)(Ev,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function Ev({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)(mt,{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)(mt,{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)(B,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function Dv(){Ih({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Ov(e.fields),groupLabel:`Fields`,order:5}]}),Ih({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}]}),Ih({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Ov(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Ih({type:`hook`,anchors:[{anchorType:`object`,match:Ph(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Ih({type:`page`,anchors:[{anchorType:`object`,match:Ph(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`description`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{regions:[]}}),Ih({type:`view`,anchors:[{anchorType:`object`,match:Ph([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`kind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`View key (snake_case). Qualified to <object>.<key> on save.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,description:`The object this view displays.`},kind:{type:`string`,title:`View kind`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``);return{name:n.includes(`.`)||!t?n:`${t}.${n}`,object:t,viewKind:`list`,label:e.label,config:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}}}}}),Ih({type:`flow`,anchors:[{anchorType:`object`,match:Ph([`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:[]}}),Ih({type:`trigger`,anchors:[{anchorType:`object`,match:Ph([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ih({type:`validation`,anchors:[{anchorType:`object`,match:Ph(`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`}}),Ih({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:{}}}),Ih({type:`action`,anchors:[{anchorType:`object`,match:Ph([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ih({type:`dashboard`,anchors:[{anchorType:`object`,match:Ph([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Ih({type:`report`,anchors:[{anchorType:`object`,match:Ph([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Ih({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 Ov(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var kv={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`}},Av={role:{type:`object`,title:`Role`,required:[`name`],properties:{...kv,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:{...kv,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:{...kv.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:kv.label,description:kv.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:{...kv,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:{...kv,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...kv,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...kv,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...kv,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:{...kv,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...kv,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:{...kv,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 jv(){for(let[e,t]of Object.entries(Av))Ih({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Mv({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 Nv({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)(Ai,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function Pv({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)(rr,{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 Fv=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)(Nv,{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 Iv({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:H(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,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)(K,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var Lv={"page:header":{label:`Header`,category:`layout`,Icon:lr},"page:footer":{label:`Footer`,category:`layout`,Icon:ia},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:ri},"page:tabs":{label:`Tabs`,category:`layout`,Icon:qr},"page:accordion":{label:`Accordion`,category:`layout`,Icon:Lr},"page:card":{label:`Card`,category:`layout`,Icon:aa},"page:section":{label:`Section`,category:`layout`,Icon:Vt},"record:details":{label:`Record details`,category:`record`,Icon:$a},"record:highlights":{label:`Highlights`,category:`record`,Icon:Mt},"record:related_list":{label:`Related list`,category:`record`,Icon:Fe},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Nt},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Er},"record:path":{label:`Stage path`,category:`record`,Icon:$n},"record:alert":{label:`Alert banner`,category:`record`,Icon:ut},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:_o},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Li},"record:history":{label:`History`,category:`record`,Icon:pr},"app:launcher":{label:`App launcher`,category:`navigation`,Icon:Je},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:ho},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:$n},"global:search":{label:`Global search`,category:`navigation`,Icon:go},"global:notifications":{label:`Notifications`,category:`navigation`,Icon:cn},"user:profile":{label:`User profile`,category:`navigation`,Icon:Hi},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:Ui},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:Ma},"element:text":{label:`Text`,category:`element`,Icon:xn},"element:number":{label:`Number`,category:`element`,Icon:cr},"element:image":{label:`Image`,category:`element`,Icon:Pt},"element:divider":{label:`Divider`,category:`element`,Icon:Qi},"element:button":{label:`Button`,category:`element`,Icon:Gi},"element:filter":{label:`Filter`,category:`element`,Icon:Pa},"element:form":{label:`Form`,category:`element`,Icon:wa},"element:record_picker":{label:`Record picker`,category:`element`,Icon:Rt}},Rv={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},zv=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Lv))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)})(),Bv=hn,Vv={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 Hv(e){return Vv[Lv[e]?.category??`misc`]}function Uv(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 Wv(e,t,n){return e===`children`?`children[${n}]`:`regions[${t}].components[${n}]`}function Gv(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 Kv=`text/x-objectui-pageblock`;function qv({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>Uv(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:Gv(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:Gv(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)(K,{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)(Jv,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(e,n)=>r?.({kind:`block`,id:`regions[${t}].components[${e}]`,label:Gv(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)(K,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function Jv({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:H(`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(Kv)||(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(Kv);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)(Yv,{block:e,regionIdx:t,compIdx:s,selected:Wv(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)(Xv,{onPick:e=>s(t,e)})})]})]})}function Yv({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Lv[c]?.Icon??Bv,u=Hv(c),d=Gv(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(Kv,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(Kv))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(Kv);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:H(`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:H(`group w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:(0,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)(Ae,{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:H(`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:H(`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)(V,{variant:`outline`,className:H(`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 Xv({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?zv.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Lv[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):zv,[a]);return(0,Y.jsxs)(wr,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Pe,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(Dn,{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:Rv[t.category]}),t.types.map(t=>{let r=Lv[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:H(`h-3.5 w-3.5 shrink-0`,Hv(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 Zv({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)(Mv,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Y.jsx)(qv,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(Iv,{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)(Nv,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Y.jsx)(Mv,{hint:`page · design`,children:(0,Y.jsx)(qv,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Y.jsx)(Mv,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(Fv,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(Iv,{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)(ce,{schema:o})})]})})}var Qv=new Set([`form`,`detail`]);function $v(e){return Qv.has(e)}function ey(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ty(e,t){return typeof e==`string`&&Qv.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Qv.has(t)?`form`:`list`}function ny(e){let t=e.config;return ey(t)?[{storeKey:`config`,familyKey:ty(e.viewKind,t.type),schema:t}]:[]}function ry(e){return ny(e)[0]}function iy(e,t){return ry(e)}function ay(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object];for(let e of n)if(typeof e==`string`&&e)return e}var oy=new Set([`simple`,`tabbed`,`wizard`,`split`]);function sy(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.name;return n?{...t,name:n,readOnly:t.readOnly??t.readonly}:t}return String(e)}function cy(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:oy.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(sy):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function ly({name:e,draft:t,editing:n}){let r=J.useMemo(()=>ry(t)?.schema,[t]),i=J.useMemo(()=>ay(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=J.useMemo(()=>{if(!r)return{listViews:{},defaultViewId:void 0,defaultViewType:`grid`};let n=String(e)||`default`;return{listViews:{[n]:{...r,label:r.label??t.label??e}},defaultViewId:n,defaultViewType:r.type??`grid`}},[r,t,e]);if(!r&&t.type){let e={...t};return(0,Y.jsx)(Mv,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(Fv,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(ce,{schema:e})})})})}if(!i)return(0,Y.jsx)(Mv,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(Nv,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,Y.jsx)(`code`,{children:`Object`}),` in the right panel to fetch live data and field options.`]})});if(t.viewKind===`form`&&r){let e=String(r.type??`simple`),t=cy(i,r);return(0,Y.jsx)(Mv,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(Fv,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(ce,{schema:t})})})})}let l=J.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);return(0,Y.jsx)(Mv,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(Fv,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(ce,{schema:l})})})})}function uy({kindLabel:e,title:t,onClose:n,closeLabel:r=`Close`,children:i,footer:a,headerActions:o,hideClose:s}){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)(V,{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,!s&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,onClick:n,"aria-label":r,className:`h-7 w-7 p-0`,children:(0,Y.jsx)(po,{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 dy({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)(Nn,{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)(or,{className:`h-4 w-4`})})]})}function fy({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)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(U,{value:t,onChange:e=>n(e.target.value),placeholder:r,disabled:i,className:H(`h-8 text-sm`,a&&`font-mono`)})]})}function py({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(U,{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 my({label:e,value:t,options:n,onCommit:r,placeholder:i=`—`,disabled:a}){let o=e=>e===``?hy:e,s=e=>e===hy?``:e;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(Pn,{value:o(t??``),onValueChange:e=>r(s(e)),disabled:a,children:[(0,Y.jsx)(nr,{className:`h-8 text-sm`,children:(0,Y.jsx)(bt,{placeholder:i})}),(0,Y.jsx)(wo,{children:n.map(e=>(0,Y.jsx)(We,{value:o(e.value),children:e.label},e.value))})]})]})}var hy=`__inspector_select_none__`;function gy({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 _y({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 vy({message:e}){return(0,Y.jsx)(`div`,{className:`text-xs italic text-muted-foreground p-4 text-center`,children:e})}function yy(e,t,n){let r=Array.isArray(e)?[...e]:[];return n===null?r.splice(t,1):r[t]=n,r}function by(e,t){let n=Array.isArray(e)?[...e]:[];return n.push(t),n}function xy(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 Sy(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 Cy={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:cr},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:bi},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:Ei},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Ar},area:{id:`area`,label:`Area chart`,category:`chart`,icon:vo},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:na},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:on},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:pi},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Gt},table:{id:`table`,label:`Data table`,category:`data`,icon:fr},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:wt},list:{id:`list`,label:`Record list`,category:`data`,icon:un},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:ar}},wy={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},Ty=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(Cy).filter(t=>t.category===e)})),Ey=Nt;function Dy({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?Ty.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):Ty},[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)(K,{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)(go,{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:wy[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)(Cy[t.id]?.icon??Ey,{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 Oy=J.lazy(()=>c(()=>import(`./plugin-dashboard-T9rNXqHD.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function ky({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=le(),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=Sy(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Cy[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:by(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)(Dy,{onAdd:p,label:X(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(Mv,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(Nv,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(Mv,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(Fv,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(Ay,{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)(B,{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)(Oy,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})]})})}function Ay({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=Cy[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)(ti,{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)(Ft,{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)(po,{className:`h-3.5 w-3.5`})})]})}var jy=J.lazy(()=>c(()=>import(`./plugin-report-AhX1YoV8.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function My({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=le(),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)(Mv,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,Y.jsxs)(Fv,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,Y.jsx)(Iv,{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)(B,{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)(jy,{schema:m,dataSource:o})})})]})}):(0,Y.jsxs)(Mv,{children:[l&&(0,Y.jsx)(Iv,{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)(Pv,{icon:(0,Y.jsx)(vt,{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)(K,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,Y.jsx)(Mv,{children:(0,Y.jsx)(Pv,{icon:(0,Y.jsx)(wt,{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 Ny=`text/x-objectui-nav`;function Py(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 Fy(e){switch(e){case`object`:return wt;case`page`:return $a;case`dashboard`:return St;case`report`:return to;case`link`:return Mi;case`group`:return Ji;default:return $n}}var Iy={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 Ly(e){return Iy[e]??Iy.item}function Ry(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function zy(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function By({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=by(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(yy(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=J.useCallback((e,r)=>{n&&(l(yy(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=xy(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Ry(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)(V,{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)(K,{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(Ny)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Ny)&&(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)(Vy,{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 Vy({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)(Hy,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Ry(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)(Vy,{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 Hy({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=Py(e),p=Fy(f),m=Ly(f),h=zy(e),[g,_]=J.useState(!1),[v,y]=J.useState(Ry(e,t)),[b,x]=J.useState(!1),[S,C]=J.useState(null);return J.useEffect(()=>{g||y(Ry(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(Ny,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Ny)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Ny)&&(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)(Ae,{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:H(`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!==Ry(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Ry(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:Ry(e,t)}),(0,Y.jsx)(V,{variant:`outline`,className:H(`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)(Mn,{className:`h-3 w-3`})})]})]})}function Uy(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)?Uy(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Wy(e){switch(e){case`object`:return wt;case`page`:return $a;case`dashboard`:return St;case`report`:return to;default:return $n}}function Gy({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:Uy(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)(Mv,{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)(pn,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Fv,{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)(By,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(Nv,{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)(Ky,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Ky({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Wy(e.kind),s=qy(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)(pn,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(Ky,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function qy(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}`}var Z=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),Jy={text:Z(`text`,`Text`,`单行文本`,`text`,xn),textarea:Z(`textarea`,`Text Area`,`多行文本`,`text`,qn),email:Z(`email`,`Email`,`邮箱`,`text`,Et),url:Z(`url`,`URL`,`网址`,`text`,Ba),phone:Z(`phone`,`Phone`,`电话`,`text`,ir),password:Z(`password`,`Password`,`密码`,`text`,$e),markdown:Z(`markdown`,`Markdown`,`Markdown`,`text`,$a),html:Z(`html`,`HTML`,`HTML`,`text`,Kn),richtext:Z(`richtext`,`Rich Text`,`富文本`,`text`,Ma),number:Z(`number`,`Number`,`数字`,`number`,cr),currency:Z(`currency`,`Currency`,`货币`,`number`,bn),percent:Z(`percent`,`Percent`,`百分比`,`number`,pt),date:Z(`date`,`Date`,`日期`,`date`,Ur),datetime:Z(`datetime`,`Date/Time`,`日期时间`,`date`,Ur),time:Z(`time`,`Time`,`时间`,`date`,ht),boolean:Z(`boolean`,`Checkbox`,`复选框`,`logic`,Nr),toggle:Z(`toggle`,`Toggle`,`开关`,`logic`,er),select:Z(`select`,`Picklist`,`下拉选择`,`selection`,Ri),multiselect:Z(`multiselect`,`Multi-Select`,`多选`,`selection`,Fe),radio:Z(`radio`,`Radio`,`单选`,`selection`,Ha),checkboxes:Z(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Fe),lookup:Z(`lookup`,`Lookup`,`查找关系`,`relation`,Yt),master_detail:Z(`master_detail`,`Master-Detail`,`主从关系`,`relation`,qe),tree:Z(`tree`,`Tree`,`树形关系`,`relation`,ja),image:Z(`image`,`Image`,`图片`,`media`,Pt),file:Z(`file`,`File`,`文件`,`media`,kt),avatar:Z(`avatar`,`Avatar`,`头像`,`media`,dr),video:Z(`video`,`Video`,`视频`,`media`,nt),audio:Z(`audio`,`Audio`,`音频`,`media`,Gr),formula:Z(`formula`,`Formula`,`公式`,`calculated`,zn),summary:Z(`summary`,`Rollup`,`汇总`,`calculated`,Ga),autonumber:Z(`autonumber`,`Auto Number`,`自动编号`,`calculated`,cr),composite:Z(`composite`,`Composite`,`复合字段`,`advanced`,Ze),repeater:Z(`repeater`,`Repeater`,`重复字段`,`advanced`,zi),location:Z(`location`,`Location`,`地理坐标`,`advanced`,Fn),address:Z(`address`,`Address`,`地址`,`advanced`,lo),code:Z(`code`,`Code`,`代码`,`advanced`,Kn),json:Z(`json`,`JSON`,`JSON`,`advanced`,io),color:Z(`color`,`Color`,`颜色`,`advanced`,Oa),rating:Z(`rating`,`Rating`,`评分`,`advanced`,ii),slider:Z(`slider`,`Slider`,`滑块`,`advanced`,Ki),signature:Z(`signature`,`Signature`,`签名`,`advanced`,Sa),qrcode:Z(`qrcode`,`QR Code`,`二维码`,`advanced`,st),progress:Z(`progress`,`Progress`,`进度条`,`advanced`,to),tags:Z(`tags`,`Tags`,`标签`,`advanced`,Ta),vector:Z(`vector`,`Vector`,`向量`,`advanced`,dt)},Yy=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],Xy={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},Zy={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`}};function Qy(e){return Zy[tb(e).category]}var $y={text:`文本`,number:`数值`,date:`日期/时间`,logic:`逻辑`,selection:`选择`,relation:`关系`,media:`媒体`,calculated:`计算`,advanced:`高级`},eb=Yy.map(e=>({category:e,types:Object.keys(Jy).filter(t=>Jy[t].category===e)}));function tb(e){return typeof e==`string`&&e in Jy?Jy[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:xn}}function nb(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(rb,{...e,icon:t===`password`?(0,Y.jsx)($e,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(Et,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(Ba,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(ir,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(cr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(Ur,{className:`h-3.5 w-3.5`}),placeholder:X(`designer.stub.pickDate`,n)});case`time`:return(0,Y.jsx)(rb,{...e,icon:(0,Y.jsx)(ht,{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)(ib,{...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)(Zi,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??X(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Y.jsx)(ab,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(ab,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(ob,{...e});case`image`:case`avatar`:return(0,Y.jsx)(sb,{icon:(0,Y.jsx)(Pt,{className:`h-4 w-4`}),label:X(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(sb,{icon:(0,Y.jsx)(kt,{className:`h-4 w-4`}),label:Qm(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Y.jsx)(sb,{icon:(0,Y.jsx)(kt,{className:`h-4 w-4`}),label:X(`designer.stub.qrcode`,n)});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)(Oa,{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)(ii,{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)(rb,{...e,icon:(0,Y.jsx)(Fn,{className:`h-3.5 w-3.5`}),placeholder:X(`designer.stub.latLng`,n)});case`address`:return(0,Y.jsx)(ib,{...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}`:`ƒ ${X(`designer.stub.computed`,n)}`});case`composite`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:X(`designer.stub.composite`,n)});case`repeater`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:X(`designer.stub.repeater`,n)});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)(U,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Y.jsx)(V,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function rb({placeholder:e,icon:t}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(U,{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 ib({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 ab({options:e,placeholder:t,single:n,locale:r}){let i=e??[],a=i.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,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:a[0]?.label||a[0]?.value||t||X(`designer.stub.select`,r)}),(0,Y.jsx)(Ya,{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:[a.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||X(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,Y.jsx)(V,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function ob({referenceTo:e,placeholder:t,locale:n}){let r=e?Jy.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)(Yt,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?Qm(`designer.stub.searchRef`,n,{ref:e}):X(`designer.stub.chooseRelated`,n))}),e&&(0,Y.jsxs)(V,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Y.jsx)(go,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function sb({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})]})}var cb=e=>(e??``).toLowerCase().startsWith(`zh`),lb=(e,t)=>e?cb(t)?e.labelZh:e.label:void 0,ub=(e,t)=>(cb(t)?$y:Xy)[e];function db({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,c=J.useMemo(()=>m_(t.fields),[t]),l=J.useMemo(()=>n?j_(n.fields,t.fields):null,[n,t]),u=l?l.counts.added+l.counts.changed+l.counts.removed:0,[d,f]=J.useState(!1);J.useEffect(()=>{d&&u===0&&f(!1)},[d,u]);let p=d&&u>0,m=e=>p?l?.byName[e]?.status:void 0,h=e=>p?l?.byName[e]?.changedKeys??[]:[],g=J.useMemo(()=>b_(t.fieldGroups),[t]),_=g.length>0,v=J.useMemo(()=>O_(c,g,{includeEmptyDeclared:!s}),[c,g,s]),[y,b]=J.useState({}),x=e=>e??`__ungrouped__`,S=J.useCallback(e=>{let t=e??`__ungrouped__`;b(e=>({...e,[t]:!e[t]}))},[]),C=v.length>0&&v.every(e=>y[x(e.key)]),w=J.useCallback(e=>{b(()=>{let t={};for(let n of v)t[x(n.key)]=e;return t})},[v]),T=i?.kind===`field`?String(i.id):null,E=c.entries.filter(e=>!!e.def.required).length,D=J.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[O,k]=J.useState(()=>new Set),A=J.useRef(null),j=J.useMemo(()=>v.flatMap(e=>e.entries.map(e=>e.name)),[v]);J.useEffect(()=>{k(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>c.entries.some(t=>t.name===e)));return t.size===e.size?e:t})},[c]);let ee=J.useCallback((e,t)=>{let n=e.name;if(!s&&t&&(t.metaKey||t.ctrlKey)){k(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),A.current=n;return}if(!s&&t&&t.shiftKey&&A.current&&A.current!==n){let e=j.indexOf(A.current),t=j.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];k(new Set(j.slice(n,r+1)));return}}O.size&&k(new Set),A.current=n,D(e)},[s,j,O,D]),te=J.useCallback(()=>k(new Set),[]),M=J.useCallback(()=>{if(!r||O.size===0)return;let e=c.entries.filter(e=>!O.has(e.name));r({fields:h_({shape:c.shape,entries:e})}),T&&O.has(T)&&a?.(null),k(new Set)},[r,O,c,T,a]),ne=J.useCallback(e=>{if(!r||O.size===0)return;let t=c.entries.map(t=>O.has(t.name)?{name:t.name,def:{...t.def,group:e??void 0}}:t);r({fields:h_({shape:c.shape,entries:t})})},[r,O,c]),N=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(e=>e.name),i=e===`select`?`status`:e,o=1,s=i;for(;n.includes(s);)o+=1,s=`${i}_${o}`;let l=__(s,e);t&&(l.def={...l.def,group:t});let u=c.entries.length;if(t){for(let e=c.entries.length-1;e>=0;--e)if(c.entries[e].def.group===t){u=e+1;break}}let d=c.entries.slice();d.splice(u,0,l),r({fields:h_({shape:c.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(l.def.label??s)})},[r,a,c]),P=J.useCallback(()=>{if(!r)return;let e=S_(g,Qm(`designer.canvas.sectionN`,o,{n:g.length+1})),t=e[e.length-1];r({fieldGroups:e}),b(e=>({...e,[t.key]:!1}))},[r,g,o]),re=J.useCallback((e,t)=>{r&&r({fieldGroups:C_(g,e,t)})},[r,g]),ie=J.useCallback(e=>{if(!r)return;let t=E_(c,e);r({fieldGroups:w_(g,e),fields:h_(t)})},[r,g,c]),ae=J.useCallback((e,t)=>{r&&r({fieldGroups:T_(g,e,t)})},[r,g]),F=J.useCallback((e,t,n)=>{if(!r||e===t)return;let i=c.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[o]=i.splice(a,1),s=i.findIndex(e=>e.name===t),l=s>=0?i[s]:void 0;if(l){let e=typeof l.def.group==`string`?l.def.group:void 0;e!==(typeof o.def.group==`string`?o.def.group:void 0)&&(o.def={...o.def,group:e})}s<0?i.push(o):i.splice(n===`before`?s:s+1,0,o),r({fields:h_({shape:c.shape,entries:i})})},[r,c]),oe=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let a=typeof n[i].def.group==`string`?n[i].def.group:null,o=i+t;for(;o>=0&&o<n.length&&(typeof n[o].def.group==`string`?n[o].def.group:null)!==a;)o+=t;if(o<0||o>=n.length)return;let s=n[i];n[i]=n[o],n[o]=s,r({fields:h_({shape:c.shape,entries:n})})},[r,c]),se=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let[a]=n.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){n.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let o=n.length;for(let e=n.length-1;e>=0;--e)if((typeof n[e].def.group==`string`?n[e].def.group:null)===t){o=e+1;break}n.splice(o,0,a),r({fields:h_({shape:c.shape,entries:n})})},[r,c]),ce=J.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);r({fields:h_({shape:c.shape,entries:n})})},[r,c]),le=J.useCallback(e=>{e.target===e.currentTarget&&T&&a?.(null)},[a,T]),ue=c.entries.length===0,de=_||v.length>1;return(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:le,"data-object-name":e,children:[!s&&O.size>0&&(0,Y.jsx)(pb,{count:O.size,groups:g,onMoveToGroup:ne,onDelete:M,onClear:te,locale:o}),(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:le,children:[!ue&&(0,Y.jsx)(fb,{fieldCount:c.entries.length,requiredCount:E,sectionCount:g.length,allCollapsed:C,onToggleAll:de?()=>w(!C):void 0,reviewAvailable:u>0,reviewing:p,diffCounts:l?.counts,onToggleReview:()=>f(e=>!e),locale:o}),ue?(0,Y.jsx)(vb,{onAdd:s?void 0:N,locale:o}):(0,Y.jsx)(`div`,{className:`space-y-5`,children:v.map(e=>{let t=e.key?g.findIndex(t=>t.key===e.key):-1;return(0,Y.jsxs)(mb,{groupKey:e.key,label:e.key===null?X(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:de,collapsed:!!y[x(e.key)],onToggleCollapse:()=>S(e.key),readOnly:s,locale:o,canMoveUp:t>0,canMoveDown:t>=0&&t<g.length-1,onRename:e.key?t=>re(e.key,t):void 0,onRemove:e.key?()=>ie(e.key):void 0,onMove:e.key?t=>ae(e.key,t):void 0,onAddField:s?void 0:t=>N(t,e.key),onDropField:s?void 0:se,children:[e.entries.map(e=>(0,Y.jsx)(_b,{entry:e,selected:e.name===T,multiSelected:O.has(e.name),diffStatus:m(e.name),changedKeys:h(e.name),readOnly:s,locale:o,onClick:t=>ee(e,t),onReorder:s?void 0:F,onRenameLabel:s?void 0:ce,onMoveOffset:s?void 0:t=>oe(e.name,t)},e.name)),e.entries.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:X(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),p&&l&&l.removed.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:X(`designer.canvas.diffRemoved`,o)}),l.removed.map(e=>(0,Y.jsx)(gb,{entry:e,locale:o},e.name))]}),!ue&&!s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(yb,{onPick:e=>N(e),locale:o}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:P,children:[(0,Y.jsx)($r,{className:`h-3.5 w-3.5`}),X(`designer.canvas.addSection`,o)]}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>Sc(),children:[(0,Y.jsx)(Ma,{className:`h-3.5 w-3.5`}),X(`designer.canvas.askAi`,o)]})]})]})]})}function fb({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,X(`designer.canvas.diffAdded`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,X(`designer.canvas.diffChanged`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,X(`designer.canvas.diffRemoved`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:X(`designer.canvas.reviewVsPublished`,l)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,X(`designer.canvas.fields`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,X(`designer.canvas.required`,l),n>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,X(`designer.canvas.sections`,l)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,Y.jsxs)(`button`,{type:`button`,onClick:c,className:H(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 transition-colors`,o?`bg-primary/10 text-primary hover:bg-primary/15`:`hover:bg-accent hover:text-foreground`),children:[(0,Y.jsx)(ka,{className:`h-3 w-3`}),X(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:[r?(0,Y.jsx)(Lr,{className:`h-3 w-3`}):(0,Y.jsx)(ma,{className:`h-3 w-3`}),X(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function pb({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=J.useState(!1);return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-20 flex items-center gap-2 border-b border-primary/20 bg-primary/10 backdrop-blur px-6 py-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:Qm(`designer.canvas.bulkSelected`,a,{n:e})}),(0,Y.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:X(`designer.canvas.bulkHint`,a)}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,Y.jsxs)(wr,{open:o,onOpenChange:s,children:[(0,Y.jsx)(Pe,{asChild:!0,children:(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,Y.jsx)(va,{className:`h-3.5 w-3.5`}),X(`designer.canvas.bulkMoveTo`,a),(0,Y.jsx)(Ya,{className:`h-3 w-3`})]})}),(0,Y.jsxs)(Dn,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(null),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent`,children:X(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(e.key),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent truncate`,children:e.label||e.key},e.key))]})]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,Y.jsx)(Mn,{className:`h-3.5 w-3.5`}),X(`designer.canvas.bulkDelete`,a)]}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,Y.jsx)(po,{className:`h-3.5 w-3.5`}),X(`designer.canvas.bulkClear`,a)]})]})]})}function mb({groupKey:e,label:t,count:n,showHeader:r,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,onRename:u,onRemove:d,onMove:f,onAddField:p,onDropField:m,children:h}){let[g,_]=J.useState(!1);return(0,Y.jsxs)(`section`,{className:H(`space-y-2.5 rounded-md transition-colors`,g&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!m)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(!0))},onDragLeave:e=>{e.currentTarget===e.target&&_(!1)},onDrop:t=>{if(!m)return;if(t.defaultPrevented){_(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);_(!1),n&&m(n,e)},children:[r&&(0,Y.jsx)(hb,{label:t,count:n,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,dropActive:g,onRename:u,onRemove:d,onMove:f,onAddField:p}),!i&&(0,Y.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function hb({label:e,count:t,collapsed:n,onToggleCollapse:r,readOnly:i,locale:a,canMoveUp:o,canMoveDown:s,dropActive:c,onRename:l,onRemove:u,onMove:d,onAddField:f}){let[p,m]=J.useState(!1),[h,g]=J.useState(e);J.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?Yr:Ya;return(0,Y.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-accent hover:text-foreground transition-colors shrink-0`,"aria-label":X(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,Y.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,Y.jsx)(`input`,{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`?(t.preventDefault(),_()):t.key===`Escape`&&(t.preventDefault(),g(e),m(!1))},onBlur:_,className:`text-[11px] font-medium uppercase tracking-wider px-1 py-0.5 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1 max-w-[220px]`}):(0,Y.jsx)(`span`,{className:H(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?X(`designer.canvas.renameHint`,a):void 0,children:e}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:X(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 opacity-0 group-hover/sec:opacity-100 focus-within:opacity-100 transition-opacity`,children:[f&&(0,Y.jsx)(yb,{onPick:f,compact:!0,locale:a}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(-1),disabled:!o,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":X(`designer.canvas.moveSectionUp`,a),children:(0,Y.jsx)(Nn,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(1),disabled:!s,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":X(`designer.canvas.moveSectionDown`,a),children:(0,Y.jsx)(or,{className:`h-3 w-3`})})]}),u&&(0,Y.jsx)(`button`,{type:`button`,onClick:u,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":X(`designer.canvas.removeSection`,a),title:X(`designer.canvas.removeSectionHint`,a),children:(0,Y.jsx)(Mn,{className:`h-3 w-3`})})]})]})}function gb({entry:e,locale:t}){let n=e.def,r=Jy[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-destructive/30 bg-destructive/[0.03] px-3.5 py-2.5 opacity-80`,children:(0,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`,children:[r&&(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,Y.jsx)(V,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:X(`designer.canvas.diffRemoved`,t)})]})})}function _b({entry:e,selected:t,multiSelected:n,diffStatus:r,changedKeys:i,readOnly:a,locale:o,onClick:s,onReorder:c,onRenameLabel:l,onMoveOffset:u}){let d=e.def,f=typeof d.type==`string`?d.type:`text`,p=Jy[f],m=p?.Icon,h=Zy[p?.category??`advanced`],g=typeof d.label==`string`?d.label:e.name,_=!!d.required,v=typeof d.description==`string`?d.description:null,y=Array.isArray(d.options)?d.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,b=typeof d.reference==`string`?d.reference:void 0,x=typeof d.formula==`string`?d.formula:void 0,S=typeof d.placeholder==`string`?d.placeholder:void 0,[C,w]=J.useState(null),T=!!c,[E,D]=J.useState(!1),[O,k]=J.useState(g);J.useEffect(()=>{k(g)},[g]);let A=e=>{l&&(e.preventDefault(),e.stopPropagation(),k(g),D(!0))},j=()=>{if(!l){D(!1);return}let t=O.trim();t&&t!==g&&l(e.name,t),D(!1)},ee=()=>{k(g),D(!1)};return(0,Y.jsxs)(`div`,{className:H(`relative`,C===`before`&&`pt-1.5`),onDragOver:e=>{if(!T)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();w(e.clientY-n.top<n.height/2?`before`:`after`)},onDragLeave:()=>w(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);w(null),n&&n!==e.name&&c(n,e.name,C??`before`)},children:[C===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:a?-1:0,onClick:s,onKeyDown:e=>{if(e.target===e.currentTarget){if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u&&(e.preventDefault(),u(e.key===`ArrowUp`?-1:1));return}(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s?.())}},draggable:T,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:H(`group block w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,t?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,n&&`border-primary/60 ring-2 ring-primary/40 bg-primary/[0.04]`,r===`added`&&`border-l-[3px] border-l-emerald-500`,r===`changed`&&`border-l-[3px] border-l-amber-500`,a&&`cursor-default`,T&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,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:[n&&(0,Y.jsx)(Nr,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),T&&!n&&(0,Y.jsx)(Ae,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,Y.jsx)(m,{className:H(`h-3.5 w-3.5 shrink-0`,h.icon)}),E?(0,Y.jsx)(`input`,{autoFocus:!0,value:O,onChange:e=>k(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),j()):e.key===`Escape`&&(e.preventDefault(),ee())},onBlur:j,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:H(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:A,title:l?X(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(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.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,Y.jsx)(V,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:X(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,Y.jsx)(V,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?Qm(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:X(`designer.canvas.diffChanged`,o)}),(0,Y.jsx)(V,{variant:`outline`,className:H(`text-[10px] font-medium`,h.badge),children:lb(p,o)??f})]})]}),v&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,Y.jsx)(nb,{type:f,label:g,placeholder:S,options:y,referenceTo:b,formula:x,locale:o})]}),C===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function vb({onAdd:e,locale:t}){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:X(`designer.canvas.noFields`,t)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:X(`designer.canvas.noFieldsHint`,t)}),e&&(0,Y.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,Y.jsx)(yb,{onPick:e,locale:t}),(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>Sc(),children:[(0,Y.jsx)(Ma,{className:`h-3.5 w-3.5`}),X(`designer.canvas.askAiGenerate`,t)]})]})]})}function yb({onPick:e,compact:t,locale:n}){let[r,i]=J.useState(!1),[a,o]=J.useState(``),s=a.trim().toLowerCase(),c=J.useMemo(()=>s?eb.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Jy[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):eb,[s,a]);return(0,Y.jsxs)(wr,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,Y.jsx)(Pe,{asChild:!0,children:t?(0,Y.jsx)(`button`,{type:`button`,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":X(`designer.canvas.addFieldToSection`,n),title:X(`designer.canvas.addFieldToSection`,n),children:(0,Y.jsx)(K,{className:`h-3 w-3`})}):(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5`}),X(`designer.canvas.addField`,n)]})}),(0,Y.jsxs)(Dn,{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:a,onChange:e=>o(e.target.value),placeholder:X(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:X(`designer.canvas.noMatchingTypes`,n)}):c.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:ub(t.category,n)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=Jy[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),i(!1),o(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,Zy[r.category].icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:lb(r,n)})]},t)})})]},t.category))})]})]})}function bb({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,Y.jsx)(Mv,{hint:`object · designer`,children:(0,Y.jsx)(Fv,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Y.jsx)(db,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,Y.jsx)(Mv,{hint:`object`,children:(0,Y.jsx)(Nv,{children:X(`designer.canvas.nameToStart`,o)})})}function xb(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 Sb(e,t){return t[e]??``}function Cb(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Sb(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Sb(n,t))}function wb({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 xb(t))e.add(n);for(let t of xb(i))e.add(t);for(let t of xb(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=J.useState({}),l=Cb(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?Cb(i,s):Cb(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Y.jsx)(Mv,{hint:`email_template`,children:(0,Y.jsx)(Nv,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Y.jsx)(Mv,{hint:`email_template`,children:(0,Y.jsx)(Fv,{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)(Ge,{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 Tb(e){return typeof e==`number`&&Number.isFinite(e)}function Eb(e){return Tb(e.ui?.x)&&Tb(e.ui?.y)}function Db(e,t){let n=new Map;if(e.length===0)return n;let r=new Map(e.map(e=>[e.id,e])),i=new Map(e.map((e,t)=>[e.id,t])),a=new Map,o=new Map;for(let t of e)o.set(t.id,0);for(let e of t)!r.has(e.source)||!r.has(e.target)||e.source===e.target||(a.has(e.source)||a.set(e.source,[]),a.get(e.source).push(e.target),o.set(e.target,(o.get(e.target)??0)+1));let s=[];for(let t of e)t.type===`start`&&s.push(t.id);for(let t of e)(o.get(t.id)??0)===0&&!s.includes(t.id)&&s.push(t.id);s.length===0&&s.push(e[0].id);let c=new Map,l=[];for(let e of s)c.set(e,0),l.push(e);let u=e.length*Math.max(1,t.length)+e.length+1,d=0;for(;l.length&&d<u;){d+=1;let e=l.shift(),t=c.get(e)??0;for(let n of a.get(e)??[]){let e=t+1;(c.get(n)??-1)<e&&(c.set(n,e),l.push(n))}}let f=0;for(let e of c.values())f=Math.max(f,e);for(let t of e)c.has(t.id)||(f+=1,c.set(t.id,f));let p=new Map;for(let t of e){let e=c.get(t.id)??0;p.has(e)||p.set(e,[]),p.get(e).push(t.id)}for(let e of p.values())e.sort((e,t)=>(i.get(e)??0)-(i.get(t)??0));let m=[...p.keys()].sort((e,t)=>e-t);for(let e of m){let t=p.get(e),r=-(t.length*240+(t.length-1)*44)/2;t.forEach((t,i)=>{n.set(t,{x:r+i*284,y:e*122})})}let h=1/0,g=1/0;for(let e of n.values())h=Math.min(h,e.x),g=Math.min(g,e.y);if(Number.isFinite(h)&&Number.isFinite(g)){let e=28-h,t=28-g;for(let[r,i]of n)n.set(r,{x:i.x+e,y:i.y+t})}for(let t of e)Eb(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function Ob(e){let t=0,n=0;for(let r of e.values())t=Math.max(t,r.x+240),n=Math.max(n,r.y+66);return{width:t+28,height:n+28}}function kb(e){return{x:e.x+240/2,y:e.y+66}}function Ab(e){return{x:e.x+240/2,y:e.y}}function jb(e,t){let n=Math.max(Math.abs(t.y-e.y)*.5,24),r={x:e.x,y:e.y+n},i={x:t.x,y:t.y-n};return`M ${e.x},${e.y} C ${r.x},${r.y} ${i.x},${i.y} ${t.x},${t.y}`}function Mb(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Nb(e,t){return e.id||`${e.source}->${e.target}#${t}`}function Pb(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Fb(e){switch(e){case`start`:return Qn;case`end`:return xr;case`decision`:case`branch`:case`gateway`:return lt;case`wait`:case`timer`:case`delay`:return yt;case`boundary_event`:case`signal`:return _o;case`subflow`:case`flow`:return qe;case`create_record`:return fo;case`update_record`:return Ln;case`delete_record`:return vi;case`get_record`:return Vr;case`http_request`:case`webhook`:return Ba;case`script`:case`script_task`:return Kn;case`screen`:case`user_task`:return ga;case`approval`:return Ii;case`connector_action`:case`service_task`:return Be;case`assignment`:return Xe;case`loop`:case`for_each`:return dn;case`parallel_gateway`:case`join_gateway`:case`parallel`:return oa;default:return Ha}}var Ib={start:{icon:`text-emerald-600 dark:text-emerald-400`,accent:`border-l-emerald-500`,label:`text-emerald-600 dark:text-emerald-400`,chip:`bg-emerald-500/10 ring-1 ring-inset ring-emerald-500/20 dark:bg-emerald-400/10`},end:{icon:`text-rose-600 dark:text-rose-400`,accent:`border-l-rose-500`,label:`text-rose-600 dark:text-rose-400`,chip:`bg-rose-500/10 ring-1 ring-inset ring-rose-500/20 dark:bg-rose-400/10`},decision:{icon:`text-amber-600 dark:text-amber-400`,accent:`border-l-amber-500`,label:`text-amber-600 dark:text-amber-400`,chip:`bg-amber-500/10 ring-1 ring-inset ring-amber-500/20 dark:bg-amber-400/10`},wait:{icon:`text-blue-600 dark:text-blue-400`,accent:`border-l-blue-500`,label:`text-blue-600 dark:text-blue-400`,chip:`bg-blue-500/10 ring-1 ring-inset ring-blue-500/20 dark:bg-blue-400/10`},signal:{icon:`text-violet-600 dark:text-violet-400`,accent:`border-l-violet-500`,label:`text-violet-600 dark:text-violet-400`,chip:`bg-violet-500/10 ring-1 ring-inset ring-violet-500/20 dark:bg-violet-400/10`},subflow:{icon:`text-indigo-600 dark:text-indigo-400`,accent:`border-l-indigo-500`,label:`text-indigo-600 dark:text-indigo-400`,chip:`bg-indigo-500/10 ring-1 ring-inset ring-indigo-500/20 dark:bg-indigo-400/10`},task:{icon:`text-slate-500 dark:text-slate-400`,accent:`border-l-slate-400`,label:`text-slate-500 dark:text-slate-400`,chip:`bg-slate-500/10 ring-1 ring-inset ring-slate-500/20 dark:bg-slate-400/10`},record:{icon:`text-cyan-600 dark:text-cyan-400`,accent:`border-l-cyan-500`,label:`text-cyan-600 dark:text-cyan-400`,chip:`bg-cyan-500/10 ring-1 ring-inset ring-cyan-500/20 dark:bg-cyan-400/10`},integration:{icon:`text-fuchsia-600 dark:text-fuchsia-400`,accent:`border-l-fuchsia-500`,label:`text-fuchsia-600 dark:text-fuchsia-400`,chip:`bg-fuchsia-500/10 ring-1 ring-inset ring-fuchsia-500/20 dark:bg-fuchsia-400/10`},approval:{icon:`text-teal-600 dark:text-teal-400`,accent:`border-l-teal-500`,label:`text-teal-600 dark:text-teal-400`,chip:`bg-teal-500/10 ring-1 ring-inset ring-teal-500/20 dark:bg-teal-400/10`},loop:{icon:`text-sky-600 dark:text-sky-400`,accent:`border-l-sky-500`,label:`text-sky-600 dark:text-sky-400`,chip:`bg-sky-500/10 ring-1 ring-inset ring-sky-500/20 dark:bg-sky-400/10`},screen:{icon:`text-pink-600 dark:text-pink-400`,accent:`border-l-pink-500`,label:`text-pink-600 dark:text-pink-400`,chip:`bg-pink-500/10 ring-1 ring-inset ring-pink-500/20 dark:bg-pink-400/10`},assignment:{icon:`text-purple-600 dark:text-purple-400`,accent:`border-l-purple-500`,label:`text-purple-600 dark:text-purple-400`,chip:`bg-purple-500/10 ring-1 ring-inset ring-purple-500/20 dark:bg-purple-400/10`}};function Lb(e){switch(e){case`start`:return Ib.start;case`end`:return Ib.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return Ib.decision;case`wait`:case`timer`:case`delay`:return Ib.wait;case`boundary_event`:case`signal`:return Ib.signal;case`subflow`:case`flow`:return Ib.subflow;case`approval`:return Ib.approval;case`loop`:case`for_each`:return Ib.loop;case`screen`:case`user_task`:return Ib.screen;case`assignment`:return Ib.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return Ib.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return Ib.integration;default:return Ib.task}}function Rb({type:e,className:t}){return J.createElement(Fb(e),{className:t,"aria-hidden":!0})}var zb=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Bb(e){switch(e){case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return`Data`;case`decision`:case`branch`:case`gateway`:case`loop`:case`for_each`:case`assignment`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return`Logic`;case`approval`:case`screen`:case`user_task`:return`Human`;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return`Integration`;default:return`Flow`}}var Vb=[{type:`create_record`,label:`Create record`,hint:`Insert a new record`,category:`Data`},{type:`update_record`,label:`Update record`,hint:`Modify an existing record`,category:`Data`},{type:`get_record`,label:`Get record`,hint:`Query records`,category:`Data`},{type:`delete_record`,label:`Delete record`,hint:`Remove matching records`,category:`Data`},{type:`decision`,label:`Decision`,hint:`Branch on a condition`,category:`Logic`},{type:`loop`,label:`Loop`,hint:`Iterate over a collection`,category:`Logic`},{type:`assignment`,label:`Set variables`,hint:`Assign flow variables`,category:`Logic`},{type:`parallel_gateway`,label:`Parallel split`,hint:`Fork into concurrent branches`,category:`Logic`},{type:`join_gateway`,label:`Parallel join`,hint:`Wait for concurrent branches`,category:`Logic`},{type:`approval`,label:`Approval`,hint:`Pause for a human decision`,category:`Human`},{type:`screen`,label:`Screen`,hint:`Collect input from a user`,category:`Human`},{type:`http_request`,label:`HTTP request`,hint:`Call an external API`,category:`Integration`},{type:`connector_action`,label:`Connector`,hint:`Run an integration action`,category:`Integration`},{type:`script`,label:`Script`,hint:`Run custom code`,category:`Integration`},{type:`subflow`,label:`Subflow`,hint:`Invoke another flow`,category:`Flow`},{type:`wait`,label:`Wait`,hint:`Pause for an event or timer`,category:`Flow`},{type:`end`,label:`End`,hint:`Terminate the flow`,category:`Flow`}];function Hb(e){let t=Vb.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Ub(e){switch(e){case`start`:return{};case`wait`:return{waitEventConfig:{eventType:`timer`,onTimeout:`fail`}};case`connector_action`:return{connectorConfig:{connectorId:``,actionId:``,input:{}}};case`boundary_event`:return{boundaryConfig:{attachedToNodeId:``,eventType:`error`,interrupting:!0}};case`approval`:return{config:{approvers:[{type:`manager`}],behavior:`first_response`,lockRecord:!0}};case`http_request`:return{config:{method:`GET`}};case`script`:return{};default:return{}}}function Wb({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=Lb(e);return(0,Y.jsxs)(`div`,{className:`absolute transition-opacity duration-200`,style:{left:r.x,top:r.y,width:240,height:66,opacity:s?.35:1},children:[(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":i,onPointerDown:c,onClick:e=>{e.stopPropagation(),l?.()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),l?.())},className:H(`group flex h-full w-full items-center gap-3 rounded-xl border bg-card px-2.5 py-2 text-left shadow-sm outline-none`,`transition-[transform,box-shadow,border-color] duration-150 ease-out will-change-transform`,`hover:-translate-y-0.5 hover:shadow-lg hover:shadow-foreground/[0.06] focus-visible:ring-2 focus-visible:ring-primary/40`,a?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o===`active`?`border-sky-500 shadow-md shadow-sky-500/20 ring-2 ring-sky-400/60`:o===`visited`?`border-emerald-500/70 ring-1 ring-emerald-400/40`:i?`border-primary shadow-md ring-2 ring-primary/30`:`border-border/80`),children:[(0,Y.jsx)(`div`,{className:H(`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-transform duration-150 group-hover:scale-105`,d.chip,o===`active`&&`animate-pulse`),children:(0,Y.jsx)(Rb,{type:e,className:H(`h-[18px] w-[18px]`,d.icon)})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{title:t,className:`truncate text-[13px] font-semibold leading-tight text-foreground`,children:t}),(0,Y.jsxs)(`div`,{className:`mt-1 flex items-baseline gap-1.5 leading-tight`,children:[(0,Y.jsx)(`span`,{className:H(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.08em]`,d.label),children:e}),n&&(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,title:n,children:n})]})]})]}),a&&e!==`end`&&(0,Y.jsx)(`button`,{type:`button`,title:`Add connected node`,"aria-label":`Add connected node`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),u?.()},className:H(`absolute left-1/2 -bottom-3 z-10 inline-flex h-6 w-6 -translate-x-1/2 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm transition-colors`,`opacity-0 hover:border-primary hover:text-primary group-hover:opacity-100 focus-visible:opacity-100`),children:(0,Y.jsx)(K,{className:`h-3.5 w-3.5`})})]})}function Gb({items:e=Vb,onPick:t,onClose:n}){let r=J.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??Bb(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return zb.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=Lb(e.type);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.type),className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:H(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,Y.jsx)(Rb,{type:e.type,className:H(`h-[15px] w-[15px]`,n.icon)})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate text-[13px] font-medium`,children:e.label}),e.hint&&(0,Y.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.hint})]})]},e.type)};return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 z-20`,onClick:n,"aria-hidden":!0}),(0,Y.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-1.5 max-h-[66vh] w-60 overflow-y-auto rounded-xl border bg-popover/95 p-1.5 shadow-xl shadow-foreground/[0.08] ring-1 ring-black/[0.03] backdrop-blur-md`,children:r.map(([e,t],n)=>(0,Y.jsxs)(`div`,{className:H(n>0&&`mt-1 border-t border-border/60 pt-1`),children:[(0,Y.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground`,children:e}),t.map(i)]},e))})]})}function Kb(){return`${``.replace(/\/$/,``)}/api/v1`}function qb(e,t){let n=new Map;for(let t of e)n.set(t.type,t);for(let e of t){if(!e?.type||e.deprecated||Array.isArray(e.paradigms)&&e.paradigms.length>0&&!e.paradigms.includes(`flow`))continue;let t=n.get(e.type);n.set(e.type,{type:e.type,label:e.name||t?.label||e.type,hint:e.description||t?.hint,category:t?.category??Bb(e.type)})}return[...n.values()]}function Jb(){let[e,t]=(0,J.useState)([]),n=(0,J.useRef)(!0);return(0,J.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${Kb()}/automation/actions`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!r.ok)return;let i=(await r.json())?.data?.actions;if(!Array.isArray(i)||i.length===0)return;n.current&&t(i)}catch{}})(),()=>{n.current=!1,e.abort()}},[]),e}function Yb(){let e=Jb();return(0,J.useMemo)(()=>e.length?qb(Vb,e):Vb,[e])}function Xb(){let e=Jb();return(0,J.useMemo)(()=>{let t={};for(let n of e)n?.type&&n.configSchema!==void 0&&n.configSchema!==null&&(t[n.type]=n.configSchema);return t},[e])}var Zb=.4,Qb=1.6,$b=4;function ex({nodes:e,edges:t,editable:n,designMode:r,selectedId:i,selectedEdgeId:a,locale:o,activeNodeId:s,visitedNodeIds:c,traversedEdgeIds:l,onSelect:u,onSelectEdge:d,onPatch:f}){let p=J.useRef(null),[m,h]=J.useState(1),[g,_]=J.useState({x:0,y:0}),[v,y]=J.useState(!1),b=Yb(),[x,S]=J.useState(null),C=J.useRef(null),w=J.useRef(null),T=J.useMemo(()=>Db(e,t),[e,t]),E=J.useMemo(()=>Ob(T),[T]),D=J.useMemo(()=>new Set(c??[]),[c]),O=J.useMemo(()=>new Set(l??[]),[l]),k=(c?.length??0)>0||!!s,A=J.useCallback(e=>x&&x.id===e?{x:x.x,y:x.y}:T.get(e)??{x:0,y:0},[x,T]),j=J.useCallback((t,n,r)=>{if(!f)return;let i=e.findIndex(e=>e.id===t);if(i<0)return;let a=e[i];f({nodes:yy(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),ee=J.useCallback((n,r)=>{if(!f)return;let i=Sy(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Hb(n),o=r?.at,s={id:i,type:n,label:a,...Ub(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:by(e,s)};r?.from&&(c.edges=by(t,{id:Sy(`edge`,t.map(e=>e.id).filter(Boolean)),source:r.from,target:i})),f(c),u(s),y(!1)},[t,e,f,u,A]),te=J.useCallback((n,r=`create_record`)=>{if(!f)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=Sy(`node`,e.map(e=>e.id).filter(Boolean)),o=A(n.source),s=A(n.target),c={x:(o.x+s.x)/2,y:(o.y+s.y)/2},l={id:a,type:r,label:Hb(r),...Ub(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:Sy(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=yy(t,i,d);f({nodes:by(e,l),edges:by(m,p)}),u(l)},[t,e,f,u,A]),M=J.useCallback(n=>{f&&(f({nodes:e.filter(e=>e.id!==n),edges:t.filter(e=>e.source!==n&&e.target!==n)}),u(null))},[t,e,f,u]),ne=J.useCallback(e=>t=>{if(!n||t.button!==0)return;t.stopPropagation();let r=A(e);C.current={nodeId:e,startX:t.clientX,startY:t.clientY,originX:r.x,originY:r.y,moved:!1},t.currentTarget.setPointerCapture?.(t.pointerId)},[n,A]),N=J.useCallback(e=>{let t=C.current;if(!t)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;!t.moved&&Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<$b||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),P=J.useCallback(e=>{let t=C.current;C.current=null,t&&(e.currentTarget.releasePointerCapture?.(e.pointerId),t.moved&&x&&j(t.nodeId,Math.round(x.x),Math.round(x.y)),S(null))},[x,j]),re=J.useCallback(e=>{e.button===0&&(u(null),w.current={startX:e.clientX,startY:e.clientY,originX:g.x,originY:g.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[u,g.x,g.y]),ie=J.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),ae=J.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),F=e=>Math.min(Qb,Math.max(Zb,e)),oe=J.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=F(Math.min(t,n,1));h(r),_({x:(e.clientWidth-E.width*r)/2,y:Math.max(16,(e.clientHeight-E.height*r)/2)})},[E.height,E.width]),se=J.useCallback(e=>{if(!(!n||!i)&&(e.key===`Delete`||e.key===`Backspace`)){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;e.preventDefault(),M(i)}},[M,n,i]);return(0,Y.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`absolute right-2 top-2 z-30 flex items-center gap-1.5`,children:[n&&(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`inline-flex items-center gap-1.5 rounded-lg border bg-background/90 px-2.5 py-1.5 text-xs font-medium shadow-sm backdrop-blur-sm transition-colors hover:border-primary/50 hover:bg-accent hover:text-foreground`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5`}),X(`engine.inspector.add.node`,o)]}),v&&(0,Y.jsx)(Gb,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>ee(e,{from:i??void 0})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-background/90 shadow-sm backdrop-blur-sm`,children:[(0,Y.jsx)(`button`,{type:`button`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>h(e=>F(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(eo,{className:`h-3.5 w-3.5`})}),(0,Y.jsxs)(`span`,{className:`w-10 text-center text-[11px] tabular-nums text-muted-foreground`,children:[Math.round(m*100),`%`]}),(0,Y.jsx)(`button`,{type:`button`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>h(e=>F(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(kr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:oe,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(zr,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:se,onPointerDown:re,onPointerMove:e=>{ie(e),N(e)},onPointerUp:e=>{ae(e),P(e)},className:H(`h-full w-full cursor-grab outline-none active:cursor-grabbing`,`bg-muted/15 dark:bg-background/30`,`shadow-[inset_0_0_90px_rgba(0,0,0,0.05)]`),style:{backgroundImage:`radial-gradient(circle at 1px 1px, hsl(var(--border)) 1px, transparent 0)`,backgroundSize:`${18*m}px ${18*m}px`,backgroundPosition:`${g.x}px ${g.y}px`},children:(0,Y.jsxs)(`div`,{className:`relative origin-top-left`,style:{width:E.width,height:E.height,transform:`translate(${g.x}px, ${g.y}px) scale(${m})`},children:[(0,Y.jsxs)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:E.width,height:E.height,children:[(0,Y.jsx)(`defs`,{children:(0,Y.jsx)(`marker`,{id:`flow-arrow`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Y.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground/55`})})}),t.map((e,t)=>{let i=T.get(e.source),o=T.get(e.target);if(!i||!o)return null;let s=kb(x?.id===e.source?A(e.source):i),c=Ab(x?.id===e.target?A(e.target):o),l=Mb(s,c),u=Pb(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=Nb(e,t),m=O.has(p),h=a===p,g=jb(s,c),_=r&&!!d;return(0,Y.jsxs)(`g`,{children:[(0,Y.jsx)(`path`,{d:g,strokeLinecap:`round`,className:H(`fill-none transition-[stroke] duration-150`,m?`stroke-sky-500`:h?`stroke-primary`:k?`stroke-muted-foreground/20`:`stroke-muted-foreground/40`),strokeWidth:m||h?2.5:1.75,markerEnd:`url(#flow-arrow)`}),_&&(0,Y.jsx)(`path`,{d:g,className:`pointer-events-auto cursor-pointer fill-none stroke-transparent`,strokeWidth:14,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),d(e,p)},children:(0,Y.jsx)(`title`,{children:`${e.source} → ${e.target}`})}),f&&(0,Y.jsx)(`foreignObject`,{x:l.x-60,y:l.y-11,width:120,height:22,className:H(_&&`pointer-events-auto`),children:(0,Y.jsx)(`div`,{className:`flex justify-center`,children:(0,Y.jsx)(`span`,{onPointerDown:_?e=>e.stopPropagation():void 0,onClick:_?t=>{t.stopPropagation(),d(e,p)}:void 0,className:H(`max-w-full truncate rounded-full border bg-background/95 px-2 py-0.5 text-[10px] font-medium shadow-sm backdrop-blur-sm transition-colors`,_&&`cursor-pointer hover:border-primary/60`,h?`border-primary text-primary`:`border-border text-muted-foreground`),children:f})})}),n&&(0,Y.jsx)(`foreignObject`,{x:l.x-11,y:l.y-11,width:22,height:22,className:`pointer-events-auto`,children:(0,Y.jsx)(`button`,{type:`button`,title:`Insert node here`,"aria-label":`Insert node here`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),te(e)},className:`inline-flex h-[22px] w-[22px] items-center justify-center rounded-full border bg-background/90 text-muted-foreground opacity-50 shadow-sm backdrop-blur-sm transition-all hover:scale-110 hover:border-primary hover:bg-background hover:text-primary hover:opacity-100 focus-visible:opacity-100`,children:(0,Y.jsx)(K,{className:`h-3 w-3`})})})]},e.id||`${e.source}-${e.target}-${t}`)})]}),e.map(e=>{let t=s===e.id?`active`:D.has(e.id)?`visited`:void 0;return(0,Y.jsx)(Wb,{id:e.id,type:e.type,label:e.label||e.id,summary:tx(e),position:A(e.id),selected:i===e.id,editable:n,runState:t,dimmed:k&&!t,onPointerDown:ne(e.id),onSelect:()=>r&&u(e),onAppend:()=>ee(`create_record`,{from:e.id})},e.id)})]})})]})}function tx(e){let t=e.config,n=e=>typeof e==`string`&&e?e:void 0,r=(t,r)=>{let i=e[t];return i&&typeof i==`object`?n(i[r]):void 0},i=e=>t?n(t[e]):void 0;if(e.type===`start`)return i(`condition`)||i(`criteria`)||i(`objectName`)||i(`cron`)||i(`schedule`)||i(`triggerType`);if(e.type===`decision`){let e=t?.conditions;if(Array.isArray(e)&&e.length){let t=e.map(e=>e&&typeof e==`object`?n(e.label):void 0).filter(Boolean);return t.length?t.join(` / `):`${e.length} branches`}return i(`condition`)}if(e.type===`script`)return i(`actionType`)||i(`template`)||(t&&t.script?`code`:void 0);if(e.type===`approval`){let e=t?.approvers,n=Array.isArray(e)?e.length:0,r=i(`behavior`);return n>0?`${n} approver${n===1?``:`s`}${r===`unanimous`?` · all`:``}`:r||void 0}return i(`objectName`)||r(`connectorConfig`,`actionId`)||r(`waitEventConfig`,`timerDuration`)||r(`waitEventConfig`,`eventType`)||r(`boundaryConfig`,`eventType`)||i(`condition`)||i(`flowName`)||i(`url`)||i(`collection`)||i(`action`)||i(`flow`)||i(`event`)||i(`duration`)||void 0}var nx=e=>typeof e==`string`?e:void 0;function rx(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new ge({...t,data:t});return{result:(/\$\{/.test(n)?e.evaluate(n,{throwOnError:!0}):e.evaluateExpression(n))===!0}}catch(e){return{result:!1,error:e.message||`Evaluation failed.`}}}function ix(e,t){let n=[],r=[],i=e.map(e=>e.id),a=new Set;for(let e of i){if(!e){n.push({level:`error`,message:`A node is missing an id.`});continue}a.has(e)&&n.push({level:`error`,nodeId:e,message:`Duplicate node id "${e}".`}),a.add(e)}for(let e of t)a.has(e.source)||n.push({level:`error`,message:`Edge source "${e.source}" does not exist.`}),a.has(e.target)||n.push({level:`error`,message:`Edge target "${e.target}" does not exist.`});let o=new Set(t.map(e=>e.target)),s=e.filter(e=>e.type===`start`),c=e.filter(e=>!o.has(e.id)),l;s.length===1?(l=s[0].id,o.has(l)&&r.push({level:`warning`,nodeId:l,message:`Start node has an incoming edge.`})):s.length>1?n.push({level:`error`,message:`Flow has ${s.length} start nodes; expected one.`}):c.length===1?(l=c[0].id,r.push({level:`warning`,nodeId:l,message:`No "start" node; using the only root node as the entry.`})):c.length===0?n.push({level:`error`,message:`No entry node (every node has an incoming edge — the graph is fully cyclic).`}):n.push({level:`error`,message:`Cannot determine a single entry node (${c.length} candidates). Add a "start" node.`});for(let i of e){if(i.type!==`decision`)continue;let e=t.filter(e=>e.source===i.id),a=e.filter(e=>e.isDefault);a.length>1&&n.push({level:`error`,nodeId:i.id,message:`Decision "${i.id}" has ${a.length} default branches.`}),e.length===0?r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no outgoing branches.`}):a.length===0&&e.every(e=>nx(e.condition))&&r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no default branch; it may dead-end when no condition matches.`})}if(l){let n=new Set([l]),i=[l];for(;i.length;){let e=i.shift();for(let r of t)r.source===e&&a.has(r.target)&&!n.has(r.target)&&(n.add(r.target),i.push(r.target))}for(let t of e)n.has(t.id)||r.push({level:`warning`,nodeId:t.id,message:`Node "${t.id}" is unreachable from the entry.`})}return{errors:n,warnings:r,startNodeId:l}}var ax=500,ox=new Set([`start`,`assignment`]),sx=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),cx=new Set([`join_gateway`,`subflow`,`boundary_event`]),lx=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,ux=e=>typeof e==`string`?e:void 0,dx=e=>typeof e==`string`&&e?e:void 0,fx=class{nodes=new Map;edges=[];mocks={};seq=0;state={status:`idle`,variables:{},steps:[],frontier:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[]};constructor(e,t){for(let t of e)this.nodes.set(t.id,t);this.edges=t}reset(e={},t={}){let n=ix([...this.nodes.values()],this.edges);return this.mocks=t,this.seq=0,this.state={status:n.errors.length?`error`:`idle`,variables:{...e},steps:[],frontier:n.startNodeId?[n.startNodeId]:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[],error:n.errors.length?n.errors[0].message:void 0},n}get done(){return this.state.status===`done`||this.state.status===`error`}step(){let e=this.state;if(e.status===`error`||e.status===`done`||e.status===`paused`)return null;if(this.seq>=ax)return e.status=`error`,e.error=`Step limit (${ax}) exceeded — the flow may contain an infinite loop.`,null;let t=e.frontier.shift();if(!t)return e.status=`done`,e.activeNodeId=null,null;let n=this.nodes.get(t);if(!n)return this.record(t,`unknown`,t,`error`,{error:`Node "${t}" not found.`});e.status=`running`,e.activeNodeId=t,e.visitedNodeIds.includes(t)||e.visitedNodeIds.push(t);let r=this.execute(n);return e.status===`running`&&e.frontier.length===0&&(e.status=`done`,e.activeNodeId=null),r}runToEnd(){let e=0;for(;this.state.status!==`done`&&this.state.status!==`error`&&this.state.status!==`paused`&&!(++e>505);)this.step();return this.state}resume(e){let t=this.state;if(t.status!==`paused`||!t.activeNodeId)return;let n=this.nodes.get(t.activeNodeId);e&&n?.type===`screen`&&Object.assign(t.variables,e),t.pausedReason=void 0,t.status=`running`,n&&this.enqueueSuccessors(n),t.frontier.length===0&&(t.status=`done`,t.activeNodeId=null)}execute(e){let t=e.type;if(t===`end`)return this.record(e.id,t,e.label,`ok`,{note:`Flow end reached.`});if(t===`decision`)return this.executeDecision(e);if(cx.has(t))return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`skipped`,{note:`"${t}" is not modelled by the simulator; passing through without its real semantics.`});if(t===`parallel_gateway`)return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:`Parallel split — branches fan out (no join synchronization is simulated).`});if(t===`wait`)return this.state.status=`paused`,this.state.pausedReason=`wait`,this.record(e.id,t,e.label,`paused`,{note:`Wait reached — continue manually.`});if(t===`screen`)return this.state.status=`paused`,this.state.pausedReason=`screen`,this.record(e.id,t,e.label,`paused`,{note:`Screen reached — provide inputs, then continue.`});if(t===`loop`){let t=this.executeLoop(e);return this.enqueueSuccessors(e),t}if(sx.has(t)||t===`script`){let n=this.applyMock(e);return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`mocked`,{wrote:n,note:this.mockNote(e)})}return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:ox.has(t)?void 0:`Type "${t}" treated as pass-through.`})}executeDecision(e){let t=this.edges.map((e,t)=>({e,i:t})).filter(t=>t.e.source===e.id),n=[],r,i;for(let{e,i:a}of t){if(e.isDefault)continue;let t=ux(e.condition);if(!t){n.push({edgeId:lx(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=rx(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:lx(e,a),target:e.target,condition:t,result:o.result,error:o.error,selected:s})}if(!r){let e=t.find(e=>e.e.isDefault);e&&(r=e,n.push({edgeId:lx(e.e,e.i),target:e.e.target,isDefault:!0,result:!0,selected:!0}))}let a=n.filter(e=>e.result&&!e.isDefault).length>1;return r&&this.traverse(r.e,r.i),this.record(e.id,`decision`,e.label,r?`ok`:`error`,{edges:n,error:r?void 0:i??`No branch matched and there is no default branch.`,note:a?`Multiple conditions matched; the first declared branch was taken.`:void 0})}executeLoop(e){let t=dx(e.config?.collection),n=dx(e.config?.iteratorVariable),r=`Loop simulated as a single pass (body re-execution is not modelled).`;if(t){let e=this.resolveRef(t);Array.isArray(e)?(r=`Collection "${t}" has ${e.length} item(s); simulated as a single pass.`,n&&e.length&&(this.state.variables[n]=e[0])):e!==void 0&&(r=`Collection "${t}" is not an array; loop may not run at runtime.`)}return this.record(e.id,`loop`,e.label,`ok`,{note:r})}resolveRef(e){let t=e.match(/^\{(.+)\}$/),n=(t?t[1]:e).trim();return this.state.variables[n]}applyMock(e){let t=e.config??{},n=this.mocks[e.id],r={},i=dx(t.outputVariable);i&&(r[i]=n===void 0?{}:n,this.state.variables[i]=r[i]);let a=Array.isArray(t.outputVariables)?t.outputVariables:[];if(a.length){let e=n&&typeof n==`object`?n:{};for(let t of a)typeof t==`string`&&(r[t]=t in e?e[t]:void 0,this.state.variables[t]=r[t])}return Object.keys(r).length?r:void 0}mockNote(e){if(e.type===`script`){let t=dx(e.config?.actionType);if(t&&t!==`code`){let n=Array.isArray(e.config?.recipients)?e.config.recipients.length:0;return`Mocked ${t} notification${n?` to ${n} recipient(s)`:``}.`}return`Mocked code script (no real code executed).`}return`Mocked ${e.type.replace(/_/g,` `)} (no backend call).`}enqueueSuccessors(e){this.edges.forEach((t,n)=>{t.source===e.id&&this.traverse(t,n)})}traverse(e,t){let n=lx(e,t);this.state.traversedEdgeIds.includes(n)||this.state.traversedEdgeIds.push(n),this.nodes.has(e.target)&&this.state.frontier.push(e.target)}record(e,t,n,r,i={}){let a={seq:this.seq++,nodeId:e,type:t,label:n||e,status:r,...i};return this.state.steps.push(a),r===`error`&&this.state.status!==`paused`&&(this.state.status=`error`,this.state.error=i.error),a}};function px(e){let t=e.trim();if(t!==``){if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}}var mx=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function hx(e){let t=[];for(let n of e){if(!mx.has(n.type))continue;let e=n.config??{},r=[];if(typeof e.outputVariable==`string`&&e.outputVariable&&r.push(e.outputVariable),Array.isArray(e.outputVariables))for(let t of e.outputVariables)typeof t==`string`&&r.push(t);t.push({id:n.id,label:n.label||n.id,type:n.type,outputs:r})}return t}var gx={ok:`bg-emerald-100 text-emerald-700`,mocked:`bg-violet-100 text-violet-700`,paused:`bg-amber-100 text-amber-700`,skipped:`bg-zinc-100 text-zinc-600`,error:`bg-rose-100 text-rose-700`};function _x({nodes:e,edges:t,variables:n,onRunStateChange:r}){let i=J.useRef(null),[a,o]=J.useState(null),[s,c]=J.useState(null),l=J.useMemo(()=>n.filter(e=>e.isInput),[n]),u=J.useMemo(()=>hx(e),[e]),[d,f]=J.useState({}),[p,m]=J.useState([]),[h,g]=J.useState({}),_=J.useCallback(()=>{let e=i.current;if(!e)return;let t=e.state;o({...t,steps:[...t.steps],variables:{...t.variables},frontier:[...t.frontier],visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]}),r?.({activeNodeId:t.activeNodeId,visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]})},[r]),v=J.useCallback(()=>{let e={};for(let t of l){let n=d[t.name],r=n==null?void 0:px(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=px(t.v))}return e},[l,d,p]),y=J.useCallback(()=>{let e={};for(let[t,n]of Object.entries(h))n!=null&&n.trim()!==``&&(e[t]=px(n));return e},[h]),b=J.useCallback(()=>{let n=new fx(e,t);i.current=n,c(n.reset(v(),y())),_()},[e,t,v,y,_]),x=J.useCallback(()=>(i.current||b(),i.current),[b]),S=()=>{let e=i.current;e&&e.state.status===`paused`?e.resume():(b(),e=i.current),e.runToEnd(),_()},C=()=>{x().step(),_()},w=()=>{let e=x();e.resume(),e.runToEnd(),_()},T=()=>{i.current=null,o(null),c(null),r?.(null)},E=a?.status??`idle`,D=(s?.errors.length??0)>0;return(0,Y.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(G,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:D,children:[(0,Y.jsx)(Qn,{className:`h-3.5 w-3.5`}),` Run`]}),(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:D||E===`done`||E===`error`,children:[(0,Y.jsx)(Ne,{className:`h-3.5 w-3.5`}),` Step`]}),E===`paused`&&(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,Y.jsx)(Yr,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,Y.jsxs)(G,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:T,children:[(0,Y.jsx)(et,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Y.jsx)(`span`,{className:H(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,gx[E===`idle`||E===`running`?`ok`:E]??`bg-muted`),children:E})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-auto p-3`,children:[s&&(s.errors.length>0||s.warnings.length>0)&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[s.errors.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-rose-200 bg-rose-50 px-2 py-1 text-rose-700`,children:[(0,Y.jsx)(Ai,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{children:e.message})]},`e${t}`)),s.warnings.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-amber-200 bg-amber-50 px-2 py-1 text-amber-700`,children:[(0,Y.jsx)(ut,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{children:e.message})]},`w${t}`))]}),l.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Inputs`}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,Y.jsx)(U,{value:d[e.name]??(e.defaultValue==null?``:String(e.defaultValue)),onChange:t=>f(n=>({...n,[e.name]:t.target.value})),placeholder:e.type??`value`,className:`h-7 flex-1 text-xs`})]},e.name))]}),(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:`Set variables`}),(0,Y.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[10px] hover:bg-muted/50`,onClick:()=>m(e=>[...e,{k:``,v:``}]),children:[(0,Y.jsx)(K,{className:`h-3 w-3`}),` Add`]})]}),p.length===0?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Override or inject any variable (wins over inputs and mocks at start).`}):p.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{value:e.k,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,k:e.target.value}:n)),placeholder:`name`,className:`h-7 w-24 shrink-0 font-mono text-[11px]`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,Y.jsx)(U,{value:e.v,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,v:e.target.value}:n)),placeholder:`value`,className:`h-7 flex-1 text-xs`}),(0,Y.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-1 text-muted-foreground hover:bg-muted/50 hover:text-rose-600`,onClick:()=>m(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove variable`,children:(0,Y.jsx)(Mn,{className:`h-3 w-3`})})]},t))]}),u.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Mock outputs`}),u.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(W,{className:`flex items-baseline gap-1.5 text-[11px]`,title:e.id,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type.replace(/_/g,` `)}),e.outputs.length>0&&(0,Y.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-violet-600`,children:[`→ `,e.outputs.join(`, `)]})]}),(0,Y.jsx)(U,{value:h[e.id]??``,onChange:t=>g(n=>({...n,[e.id]:t.target.value})),placeholder:e.type===`script`&&e.outputs.length?`{ "${e.outputs[0]}": … }`:`mocked result (JSON)`,className:`h-7 w-full font-mono text-[11px]`})]},e.id))]}),a&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Variables`}),Object.keys(a.variables).length===0?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No variables set.`}):(0,Y.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(a.variables).map(([e,t])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-1.5 rounded border bg-background px-1.5 py-1`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-[11px]`,children:e}),(0,Y.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:[`= `,typeof t==`object`?JSON.stringify(t):String(t)]})]},e))})]}),a&&a.steps.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Timeline`}),(0,Y.jsx)(`ol`,{className:`space-y-1`,children:a.steps.map(e=>(0,Y.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.seq+1}),(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),(0,Y.jsx)(`span`,{className:H(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,gx[e.status]),children:e.status})]}),e.note&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e.note}),e.error&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-[10px] text-rose-600`,children:e.error}),e.wrote&&(0,Y.jsxs)(`div`,{className:`mt-0.5 truncate font-mono text-[10px] text-violet-600`,children:[`→ `,Object.keys(e.wrote).join(`, `)]}),e.edges&&e.edges.length>0&&(0,Y.jsx)(`ul`,{className:`mt-0.5 space-y-0.5`,children:e.edges.map(e=>(0,Y.jsxs)(`li`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:H(`flex items-center gap-1 font-mono text-[10px]`,e.selected?`text-sky-700`:`text-muted-foreground`),children:[(0,Y.jsx)(`span`,{children:e.selected?`▶`:`·`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.isDefault?`else`:e.condition}),(0,Y.jsx)(`span`,{className:H(`ml-auto`,e.error&&`text-rose-600`),children:e.error?`error`:e.result?`true`:`false`})]}),e.error&&(0,Y.jsx)(`div`,{className:`pl-3 text-[10px] text-rose-600`,children:e.error})]},e.edgeId))})]},e.seq))})]}),!a&&!D&&(0,Y.jsx)(`p`,{className:`italic text-muted-foreground`,children:`Press Run to simulate, or Step to walk node by node. Side effects are mocked — no backend is called.`})]})]})}function vx({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=e,s=Array.isArray(o.nodes)?o.nodes:[],c=Array.isArray(o.edges)?o.edges:[],l=Array.isArray(o.variables)?o.variables:[],u=!!(t&&r),d=u&&!!i,f=n&&n.kind===`node`?n.id:null,p=n&&n.kind===`edge`?n.id:null,[m,h]=J.useState(!1),[g,_]=J.useState(!0),[v,y]=J.useState(null),b=J.useCallback(()=>{if(!d)return;let e={id:Sy(`node`,s.map(e=>e.id).filter(Boolean)),type:`task`,label:`New node`};i({nodes:by(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),x=String(o.type??`autolaunched`),S=String(o.status??(o.active?`active`:`draft`)),C=String(o.runAs??`user`),w=o.version==null?void 0:String(o.version),T=o.errorHandling?.strategy;return s.length===0?(0,Y.jsx)(Mv,{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:b,children:[(0,Y.jsx)(K,{className:`h-3 w-3`}),X(`engine.inspector.add.node`,a)]})}):(0,Y.jsx)(Nv,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Y.jsx)(Mv,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Y.jsx)(Fv,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,Y.jsxs)(`div`,{className:`grid gap-0 h-full min-h-[440px] `+(m||g?`lg:grid-cols-[1fr_240px]`:`grid-cols-1`),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col min-w-0 min-h-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded-none border-b bg-muted/30 px-3 py-2 text-xs flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,Y.jsx)(yx,{icon:_o,label:`Trigger`,value:x}),(0,Y.jsx)(yx,{icon:Ha,label:`Status`,value:S,tone:S===`active`?`green`:S===`draft`?`gray`:`amber`}),(0,Y.jsx)(yx,{icon:Dr,label:`Run as`,value:C}),w&&(0,Y.jsx)(yx,{label:`v`,value:w}),T&&(0,Y.jsx)(yx,{icon:ki,label:`On error`,value:T}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!m&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(g?`border-violet-500 bg-violet-50 text-violet-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:g?`Hide variables panel`:`Show variables panel`,children:[(0,Y.jsx)(br,{className:`h-3 w-3`}),` Variables`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(m?`border-sky-500 bg-sky-50 text-sky-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),children:[(0,Y.jsx)(oo,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Y.jsx)(ex,{nodes:s,edges:c,editable:d,designMode:u,selectedId:f,selectedEdgeId:p,locale:a,activeNodeId:v?.activeNodeId??null,visitedNodeIds:v?.visitedNodeIds,traversedEdgeIds:v?.traversedEdgeIds,onSelect:e=>e?r?.({kind:`node`,id:e.id,label:e.label||e.id}):r?.(null),onSelectEdge:(e,t)=>e?r?.({kind:`edge`,id:t,label:`${e.source} → ${e.target}`}):r?.(null),onPatch:i})})]}),m?(0,Y.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Y.jsx)(_x,{nodes:s,edges:c,variables:l,onRunStateChange:y})}):g?(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)(Xe,{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))})]}):null]})})})}function yx({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 bx({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)(Mv,{hint:`agent`,children:(0,Y.jsx)(Nv,{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)(Mv,{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)(pn,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Fv,{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)(Ui,{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)(kx,{icon:c?tt:Ye,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Y.jsx)(kx,{icon:$e,label:l}),u.provider&&(0,Y.jsx)(kx,{icon:Ma,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Y.jsx)(kx,{icon:Fr,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Y.jsx)(kx,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Y.jsx)(Sx,{title:`Instructions`,icon:Br,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)(Cx,{children:`No system prompt set yet.`})}),(0,Y.jsx)(Sx,{title:`Capabilities`,icon:Rn,children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(Tx,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:Ma,tone:`violet`,mono:!0}),(0,Y.jsx)(Tx,{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:Rn,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Y.jsx)(Sx,{title:`Knowledge (RAG)`,icon:wt,children:(0,Y.jsx)(xx,{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)(Ex,{icon:rt,title:`Planning`,children:(0,Y.jsx)(Dx,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Y.jsx)(Ex,{icon:Nt,title:`Memory`,children:(0,Y.jsx)(Dx,{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)(Ex,{icon:ui,title:`Guardrails`,children:(0,Y.jsx)(Dx,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Y.jsx)(Ex,{icon:$e,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 xx({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)(wt,{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 Sx({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 Cx({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var wx={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 Tx({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?wx[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:H(`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px]`,o?o.chip:`bg-background`,a&&`font-mono`),children:[r&&(0,Y.jsx)(r,{className:H(`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 Ex({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 Dx({data:e,keys:t}){let n=t.map(t=>[t,Ox(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 Ox(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function kx({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 Ax(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function jx(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${jx(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Mx(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 Nx({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=Ax(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]=Mx(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Mx(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Y.jsx)(Mv,{hint:`tool`,children:(0,Y.jsx)(Nv,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Y.jsx)(Mv,{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)(pn,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Fv,{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)(Rn,{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)(Lx,{icon:Mt,label:o}),s&&(0,Y.jsx)(Lx,{icon:wt,label:s,mono:!0}),(0,Y.jsx)(Lx,{icon:Ht,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Y.jsx)(Lx,{icon:ut,label:`Requires confirmation`,tone:`amber`}),u&&(0,Y.jsx)(Lx,{label:`built-in`})]})]})]}),a&&(0,Y.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Y.jsx)(Fx,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Y.jsx)(Ix,{children:`This tool takes no input parameters.`}):(0,Y.jsx)(Px,{props:p,required:m})}),Object.keys(p).length>0&&(0,Y.jsx)(Fx,{title:`Example LLM Call`,icon:io,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
|
-
}`})}),Ax(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Fx,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:hn,children:(0,Y.jsx)(Px,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Px({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)(sa,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(Yr,{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:jx(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 Fx({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 Ix({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Lx({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 Rx=[{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 zx(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 Bx({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(()=>zx(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)(Mv,{hint:`permission`,children:(0,Y.jsx)(Nv,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(Mv,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(Fv,{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)(ii,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(_a,{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)(Wx,{icon:Vt,label:`${d.length} objects`}),(0,Y.jsx)(Wx,{icon:Mt,label:`${c.length} system perms`}),(0,Y.jsx)(Wx,{icon:tt,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(Wx,{icon:$e,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Ux,{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`}),Rx.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}),Rx.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(Vx,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Hx,{})]}),p.size>0&&(0,Y.jsx)(Ux,{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)(Ux,{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)(Ux,{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)(ut,{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 Vx({granted:e,danger:t}){return e?(0,Y.jsx)(sa,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(jt,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Hx(){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)(sa,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(sa,{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)(jt,{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 Ux({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 Wx({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 Gx(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 Kx(e){switch(e){case`url`:return Yt;case`modal`:return ot;case`flow`:return qe;case`api`:return Ba;case`form`:return Ft;default:return ar}}function qx(e){switch(e){case`primary`:case`default`:case void 0:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:case`destructive`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function Jx(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 Yx({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Gx(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=Gx(n.confirmText),g=Gx(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=Kx(o),w=l===`action:icon`;return!r&&!i?(0,Y.jsx)(Mv,{hint:`action`,children:(0,Y.jsx)(Nv,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(Mv,{hint:`action`,children:(0,Y.jsx)(Fv,{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)(Xx,{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)(rS,{icon:C,label:`type: ${o}`}),b&&(0,Y.jsx)(rS,{icon:aa,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(rS,{label:`variant: ${c}`}),l&&(0,Y.jsx)(rS,{icon:Vi,label:l}),d&&(0,Y.jsx)(rS,{icon:xo,label:d,mono:!0}),f&&(0,Y.jsx)(rS,{icon:uo,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(rS,{icon:Ni,label:`refresh after`}),m===!1&&(0,Y.jsx)(rS,{icon:Ui,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(rS,{icon:Ma,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)(tS,{label:`Visible when`,value:x,icon:tt}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(tS,{label:`Disabled when`,value:S,icon:$e})]}),(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:Jx(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)(ut,{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)(nS,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(Qx,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(nS,{title:`Result Dialog`,icon:tt,children:(0,Y.jsx)(eS,{dialog:v})}),y?.source&&(0,Y.jsx)(nS,{title:`Script Body (${y.language??`expression`})`,icon:ar,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 Xx({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 ${qx(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(Zx,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function Zx({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=yi[t===`Home`?`House`:t];return n?(0,Y.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(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 Qx({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:[Gx(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})]}),$x(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 ${qx(n||`primary`)}`,children:`OK`})]})]})}function $x(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:Gx(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 eS({dialog:e}){let t=Gx(e.title)||`Result`,n=Gx(e.description),r=Gx(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:Gx(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 tS({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 nS({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 rS({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 iS={"@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 aS(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 oS(e){let t=(iS[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=aS(n,0,59),c=aS(r,0,23),l=aS(i,1,31),u=aS(a,1,12),d=aS(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function sS(e,t,n){let r=oS(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 cS(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 lS(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function uS(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function dS(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?fS(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`?fS(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function fS(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 pS({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}=dS(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?cS(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=sS(o,e,5);else if(_)t=lS(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>mS(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(Mv,{hint:`job`,children:(0,Y.jsx)(Nv,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(Mv,{hint:`job`,children:(0,Y.jsx)(Fv,{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)(Ea,{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)(_S,{icon:Ht,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(_S,{icon:Fi,label:l,mono:!0}),p!=null&&(0,Y.jsx)(_S,{icon:et,label:`retries: ${p}${m?` (${fS(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(_S,{icon:Ue,label:`timeout: ${fS(h)}`}),g!=null&&(0,Y.jsx)(_S,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(gS,{title:`Schedule`,icon:Ur,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(hS,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(hS,{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)(hS,{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)(gS,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:ht,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)(ht,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:uS(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(gS,{title:`Handler`,icon:ar,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)(si,{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 mS(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 hS({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 gS({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 _S({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 vS=[{key:`objects`,label:`Objects`,icon:Fe,flat:!1},{key:`apps`,label:`Apps`,icon:zt,flat:!1},{key:`messages`,label:`Messages`,icon:Za,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:$i,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:wa,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:St,flat:!1},{key:`settings`,label:`Settings`,icon:Dr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:$a,flat:!1}];function yS({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=vS.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/vS.length*100);return c===0?(0,Y.jsx)(Mv,{hint:`translation · ${r}`,children:(0,Y.jsx)(Nv,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(Mv,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(Fv,{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.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)(Fi,{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)(Fr,{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,`/`,vS.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)(bS,{cat:e},e.key))})]})})})}function bS({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:xS(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 xS(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function SS({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)(Mv,{hint:`role`,children:(0,Y.jsx)(Fv,{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)(mn,{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)(xa,{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)(jn,{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)(_a,{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)(Mv,{hint:`role`,children:(0,Y.jsx)(Nv,{children:`Give the role a name to see the preview.`})})}function CS({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)(Mv,{hint:`skill`,children:(0,Y.jsx)(Fv,{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)(Ma,{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)(TS,{icon:Ht,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(TS,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(TS,{icon:_a,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(wS,{title:`Instructions`,icon:Li,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)(wS,{title:`Tools (${s.length})`,icon:Rn,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)(Kt,{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)(wS,{title:`Trigger Phrases (${c.length})`,icon:gi,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)(wS,{title:`Trigger Conditions (${l.length})`,icon:Pa,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)(wS,{title:`Required Permissions`,icon:_a,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)(Mv,{hint:`skill`,children:(0,Y.jsx)(Nv,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function wS({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 TS({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 ES=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},DS=D();function OS(){return``.replace(/\/+$/,``)}function kS(e){return`${OS()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function AS(e){if(e.status===503){let t;try{t=await e.json()}catch{t=void 0}if((t&&typeof t==`object`&&`error`in t?String(t.error):``)===`external_service_unavailable`)throw new ES}if(!e.ok){let t=`${e.status} ${e.statusText}`;try{let n=await e.json();n&&typeof n==`object`&&`error`in n&&(t=String(n.error))}catch{}throw Error(t)}return await e.json()}async function jS(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await AS(await DS(`${kS(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function MS(e,t,n={}){return(await AS(await DS(`${kS(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function NS(e){return(await AS(await DS(`${kS(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function PS(e){return AS(await DS(`${kS(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function FS(e){await AS(await DS(`${OS()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function IS({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=J.useState(`loading`),[s,c]=J.useState(null),[l,u]=J.useState(null);J.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await MS(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof ES?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=J.useCallback(async()=>{if(s){o(`importing`),u(null);try{await FS(s),o(`done`),i?.(s.name)}catch(e){u(e instanceof Error?e.message:String(e)),o(`ready`)}}},[s,i]),f=t?[t.schema,t.name].filter(Boolean).join(`.`):``;return(0,Y.jsx)(ct,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Ct,{className:`max-w-2xl`,children:[(0,Y.jsxs)(So,{children:[(0,Y.jsxs)(Ve,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(Ut,{children:[`Map remote table `,(0,Y.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,Y.jsx)(B,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Y.jsx)(sa,{className:`h-8 w-8 text-emerald-500`}),(0,Y.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Review its binding and run validation to confirm it matches the remote table.`})]}),(a===`ready`||a===`importing`)&&s&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,Y.jsx)(ut,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,Y.jsx)(`ul`,{className:`mt-1.5 space-y-1 text-[11px] text-amber-900/90 dark:text-amber-200/80`,children:s.review.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,Y.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(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:[(0,Y.jsx)(Ke,{className:`h-3 w-3`}),` Generated source`]}),(0,Y.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/30 p-2.5 text-[11px] leading-relaxed font-mono`,children:s.source})]})]}),(0,Y.jsx)(An,{children:a===`done`?(0,Y.jsx)(G,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(G,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function LS({datasource:e}){let[t,n]=J.useState(`idle`),[r,i]=J.useState([]),[a,o]=J.useState(null),[s,c]=J.useState(``),[l,u]=J.useState(null),[d,f]=J.useState(!1),p=J.useCallback(async()=>{n(`loading`),o(null);try{i(await jS(e)),n(`loaded`)}catch(e){e instanceof ES?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);J.useEffect(()=>{p()},[p]);let m=J.useMemo(()=>{let e=s.trim().toLowerCase();return e?r.filter(t=>[t.schema,t.name].filter(Boolean).join(`.`).toLowerCase().includes(e)):r},[r,s]),h=e=>{u(e),f(!0)};return t===`unavailable`?(0,Y.jsx)(RS,{}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(go,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Filter tables…`,className:`w-full rounded border bg-background pl-7 pr-2 py-1.5 text-xs outline-none focus:ring-1 focus:ring-ring`})]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Ni,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:a}),t===`loading`&&r.length===0&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(B,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,Y.jsx)(`div`,{className:`py-10 text-center text-sm text-muted-foreground`,children:r.length===0?`No remote tables found (check the datasource’s allowedSchemas).`:`No tables match the filter.`}),m.length>0&&(0,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`,{className:`bg-muted/40 text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,Y.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,Y.jsx)(fr,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(vt,{className:`h-3 w-3`}),e.columnCount]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums text-muted-foreground`,children:typeof e.rowCountEstimate==`number`?e.rowCountEstimate.toLocaleString():`—`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(Qt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(IS,{datasource:e,table:l,open:d,onOpenChange:f})]})}function RS(){return(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:[`Federation is not enabled on this server. The`,(0,Y.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var zS={missing_table:`Missing table`,missing_column:`Missing column`,type_mismatch:`Type mismatch`,nullability_mismatch:`Nullability mismatch`,unmapped_column:`Unmapped column`,pk_mismatch:`Primary-key mismatch`};function BS({datasource:e}){let[t,n]=J.useState(`idle`),[r,i]=J.useState([]),[a,o]=J.useState(null),[s,c]=J.useState(null),l=J.useCallback(async()=>{n(`running`),c(null);try{let t=await PS(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof ES?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,Y.jsx)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:`Federation is not enabled on this server, so validation is unavailable.`}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(si,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:s}),t===`done`&&a!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded border p-2.5 text-sm ${a?`border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 text-emerald-800 dark:text-emerald-300`:`border-destructive/40 bg-destructive/5 text-destructive`}`,children:[a?(0,Y.jsx)(sa,{className:`h-4 w-4`}):(0,Y.jsx)($i,{className:`h-4 w-4`}),a?`All ${r.length} object${r.length===1?``:`s`} match the remote schema.`:`${r.filter(e=>!e.ok).length} of ${r.length} object${r.length===1?``:`s`} diverge from the remote schema.`]}),t===`done`&&r.length===0&&(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No federated objects are bound to this datasource yet. Import a table from the Tables tab to get started.`}),r.length>0&&(0,Y.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsx)(VS,{result:e},e.object))})]})}function VS({result:e}){return(0,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,Y.jsx)(_a,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)($i,{className:`h-3.5 w-3.5 text-destructive`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[e.diffs.length,` diff`,e.diffs.length===1?``:`s`]})]}),e.diffs.length>0&&(0,Y.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,Y.jsx)(HS,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function HS({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,Y.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-2.5 py-1.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`rounded px-1 py-0.5 font-medium uppercase tracking-wide text-[9px] ${e.severity===`error`?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:zS[e.kind]??e.kind}),t&&(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function US({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=J.useState(null),[a,o]=J.useState(!1),[s,c]=J.useState(null),l=J.useCallback(async()=>{if(e){o(!0),c(null);try{i(await NS(e))}catch(e){c(e instanceof ES?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,Y.jsx)(Wt,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:t??`external`}),(0,Y.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`:`bg-muted text-muted-foreground`}`,children:n?`writes allowed`:`read-only`}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(ht,{className:`h-3 w-3`}),`snapshot `,WS(r.snapshotAt)]}),(0,Y.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Ni,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,Y.jsxs)(ke,{defaultValue:`tables`,className:`p-3`,children:[(0,Y.jsxs)(Ua,{children:[(0,Y.jsx)(ca,{value:`tables`,children:`Tables`}),(0,Y.jsx)(ca,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(ci,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(LS,{datasource:e})}),(0,Y.jsx)(ci,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(BS,{datasource:e})})]})]}):(0,Y.jsx)(`div`,{className:`rounded border bg-muted/20 p-3 text-xs text-muted-foreground`,children:`Save the datasource first to browse its remote tables and validate federated objects.`})}function WS(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var GS=/pass|secret|key|token|credential|auth/i;function KS(e){return GS.test(e)}function qS(e){return e==null||e===``?`∅`:`••••••`}function JS(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 YS({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=n.schemaMode??`managed`,_=g!==`managed`,v=!!(n.external??void 0)?.allowWrites,y=Object.entries(l);return!r&&y.length===0?(0,Y.jsx)(Mv,{hint:`datasource`,children:(0,Y.jsx)(Nv,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(Mv,{hint:`datasource · ${o}`,children:(0,Y.jsx)(Fv,{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)(wt,{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)(yr,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(QS,{icon:Ht,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(QS,{icon:ii,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(QS,{icon:He,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(US,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(ZS,{title:`Connection`,icon:$e,children:y.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:y.map(([e,t])=>{let n=KS(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:qS(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`})]}):JS(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(XS,{title:`Pool`,icon:Nt,value:u}),(0,Y.jsx)(XS,{title:`SSL`,icon:_a,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)(XS,{title:`Retry Policy`,icon:et,value:f}),(0,Y.jsx)(XS,{title:`Health Check`,icon:Nt,value:p})]}),h.length>0&&(0,Y.jsx)(ZS,{title:`Capabilities`,icon:_a,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 XS({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:KS(e)?qS(t):JS(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function ZS({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 QS({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 $S(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function eC(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:ut};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:Gn}}}function tC({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=eC(l);return r?(0,Y.jsx)(Mv,{hint:`validation · ${o}`,children:(0,Y.jsx)(Fv,{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)($i,{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)(aC,{icon:Ht,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(aC,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(aC,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(aC,{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)(nC,{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)(Mv,{hint:`validation`,children:(0,Y.jsx)(Nv,{children:`Give the validation a name to see the preview.`})})}function nC({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(iC,{title:`Condition`,icon:ar,children:(0,Y.jsx)(rC,{value:$S(t.condition)??$S(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=$S(t.scope)??$S(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(iC,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:ta,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)(iC,{title:`Scope`,icon:Ga,children:(0,Y.jsx)(rC,{value:n})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field;return(0,Y.jsx)(iC,{title:`Transitions${r?` on ${r}`:``}`,icon:qe,children:n.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:n.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:e}),(0,Y.jsx)(tr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:Array.isArray(t)&&t.length>0?t.join(` | `):`∅ (dead-end)`})]},e))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,Y.jsx)(iC,{title:`Format`,icon:Ie,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=$S(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(iC,{title:`Fields involved`,icon:Ga,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)(iC,{title:`Cross-field condition`,icon:ar,children:(0,Y.jsx)(rC,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(iC,{title:`Async endpoint`,icon:Fi,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)(iC,{title:`Custom handler`,icon:ar,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)(iC,{title:`Rule`,icon:$i,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 rC({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 iC({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 aC({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 oC(){f_(`page`,Zv),f_(`view`,ly),f_(`dashboard`,ky),f_(`report`,My),f_(`app`,Gy),f_(`action`,Yx),f_(`object`,bb),f_(`datasource`,YS),f_(`validation`,tC),f_(`email_template`,wb),f_(`translation`,yS),f_(`flow`,vx),f_(`job`,pS),f_(`agent`,bx),f_(`tool`,Nx),f_(`skill`,CS),f_(`permission`,Bx),f_(`profile`,Bx),f_(`role`,SS)}var sC=[{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`}],cC=[`count`,`sum`,`avg`,`min`,`max`],lC=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function uC(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 dC({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Y.jsx)(pC,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=uC(e,t.id);if(!s)return(0,Y.jsx)(pC,{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:xy(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)(dy,{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)(po,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(fC,{id:`widget-title`,label:X(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(U,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,Y.jsx)(fC,{id:`widget-type`,label:X(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(Pn,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-type`,children:(0,Y.jsx)(bt,{})}),(0,Y.jsx)(wo,{children:sC.map(e=>(0,Y.jsx)(We,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsx)(fC,{id:`widget-object`,label:X(`engine.inspector.widget.object`,o),children:(0,Y.jsx)(U,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,Y.jsx)(fC,{id:`widget-value-field`,label:X(`engine.inspector.widget.valueField`,o),children:(0,Y.jsx)(U,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,Y.jsx)(fC,{id:`widget-category-field`,label:X(`engine.inspector.widget.categoryField`,o),children:(0,Y.jsx)(U,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,Y.jsx)(fC,{id:`widget-aggregate`,label:X(`engine.inspector.widget.aggregate`,o),children:(0,Y.jsxs)(Pn,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-aggregate`,children:(0,Y.jsx)(bt,{})}),(0,Y.jsx)(wo,{children:cC.map(e=>(0,Y.jsx)(We,{value:e,children:e},e))})]})}),(0,Y.jsx)(fC,{id:`widget-color`,label:X(`engine.inspector.widget.color`,o),children:(0,Y.jsxs)(Pn,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-color`,children:(0,Y.jsx)(bt,{})}),(0,Y.jsx)(wo,{children:lC.map(e=>(0,Y.jsx)(We,{value:e,children:e},e))})]})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(fC,{id:`widget-w`,label:X(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(U,{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)(fC,{id:`widget-h`,label:X(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(U,{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 fC({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function pC({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)})]})}function Q(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function mC(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var hC=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),gC={start:[Q(`triggerType`,`Trigger`,`select`,{help:`When this flow starts. Record triggers fire on data changes; schedule triggers fire on a cron.`,options:[{value:`record-after-create`,label:`Record created`},{value:`record-after-update`,label:`Record updated`},{value:`record-before-update`,label:`Record before update`},{value:`record-after-delete`,label:`Record deleted`},{value:`record-change`,label:`Record changed (any)`},{value:`schedule`,label:`Schedule (cron)`},{value:`manual`,label:`Manual / autolaunched`},{value:`webhook`,label:`Webhook / API`},{value:`event`,label:`Platform event`}]}),Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`crm_lead`,help:`Target object for record / scheduled-scan triggers.`}),Q(`condition`,`Entry condition`,`expression`,{placeholder:`status == "qualifying" && previous.status != "qualifying"`,help:`CEL predicate — the flow runs only when this is true. Leave empty to run on every event.`}),Q(`cron`,`Cron schedule`,`text`,{placeholder:`0 7 * * *`,help:`Cron expression for scheduled triggers.`,showWhen:{field:`triggerType`,equals:[`schedule`]}}),Q(`criteria`,`Entry condition (legacy)`,`expression`,{placeholder:`status == "active"`,help:`Legacy key — prefer "Entry condition" (condition).`,showWhen:{field:`__legacy__`,equals:[]}}),Q(`schedule`,`Cron schedule (legacy)`,`text`,{placeholder:`0 9 * * *`,help:`Legacy key — prefer "Cron schedule" (cron).`,showWhen:{field:`__legacy__`,equals:[]}})],end:[Q(`outcome`,`Outcome`,`text`,{placeholder:`success · failure`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})],decision:[Q(`conditions`,`Branches`,`objectList`,{help:`Each branch has a label and a CEL expression (spec decision shape). A branch whose expression is "true" is the default/else path.`,columns:[{key:`label`,label:`Label`,kind:`text`,placeholder:`Has deals`},{key:`expression`,label:`Expression`,kind:`expression`,placeholder:`expiring_deals.length > 0`}]}),Q(`condition`,`Condition (single)`,`expression`,{placeholder:`amount > 10000`,help:`Legacy single-branch condition (CEL). Prefer Branches above; per-edge conditions also live on the outgoing edges.`,showWhen:{field:`__legacy__`,equals:[]}})],assignment:[Q(`assignments`,`Assignments`,`keyValue`,{help:`Set variables: each key is a variable, each value an expression or literal.`})],loop:[Q(`collection`,`Collection`,`expression`,{placeholder:`{leadList}`,help:`Expression resolving to the items to iterate.`}),Q(`iteratorVariable`,`Item variable`,`text`,{placeholder:`currentItem`})],create_record:[Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),Q(`fields`,`Field values`,`keyValue`,{help:`Field values to write on the new record.`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`newRecord`})],update_record:[Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),Q(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to update (e.g. id → {recordId}).`}),Q(`fields`,`Field values`,`keyValue`,{help:`Field values to write.`})],delete_record:[Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),Q(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to delete.`})],get_record:[Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),Q(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs to match (e.g. status → active). Operator values like {"$ne": null} are preserved.`}),Q(`limit`,`Limit`,`number`,{placeholder:`100`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`records`})],http_request:[Q(`method`,`Method`,`select`,{options:hC,defaultValue:`GET`}),Q(`url`,`URL`,`text`,{placeholder:`https://api.example.com/v1/contracts`}),Q(`headers`,`Headers`,`keyValue`,{help:`Request headers (e.g. Authorization, Content-Type).`}),Q(`body`,`Body`,`textarea`,{placeholder:`{ "key": "value" }`,help:`Request payload (JSON or expression).`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`response`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],script:[Q(`actionType`,`Action type`,`select`,{options:[{value:`code`,label:`Code`},{value:`email`,label:`Email`},{value:`sms`,label:`SMS`},{value:`notification`,label:`Notification`}],defaultValue:`code`,help:`How this step runs. Leave as Code for a raw script.`}),Q(`template`,`Template`,`reference`,{ref:{kindFrom:`actionType`,map:{email:`email-template`}},placeholder:`case_escalated`,help:`Message template id.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),Q(`recipients`,`Recipients`,`stringList`,{help:`One recipient per row (user id, field ref, or address).`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),Q(`variables`,`Template variables`,`keyValue`,{help:`Values injected into the template.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),Q(`script`,`Code`,`textarea`,{placeholder:`return { ok: true };`,help:`Script body (JS/TS).`,showWhen:{field:`actionType`,equals:[`code`]}}),Q(`outputVariables`,`Output variables`,`stringList`,{help:`Names of variables this script writes back.`,showWhen:{field:`actionType`,equals:[`code`]}}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],screen:[Q(`fields`,`Fields`,`objectList`,{help:`Fields presented on this screen.`,columns:[{key:`name`,label:`Name`,kind:`text`,placeholder:`discount`},{key:`label`,label:`Label`,kind:`text`,placeholder:`Discount %`},{key:`type`,label:`Type`,kind:`text`,placeholder:`number`},{key:`required`,label:`Required`,kind:`boolean`},{key:`visibleWhen`,label:`Visible when`,kind:`expression`,placeholder:`stage == "review"`}]})],approval:[Q(`approvers`,`Approvers`,`objectList`,{help:`Who may act on this step. Wire the node’s out-edges with labels "approve" and "reject".`,columns:[{key:`type`,label:`Type`,kind:`select`,options:[{value:`user`,label:`User`},{value:`role`,label:`Role`},{value:`team`,label:`Team`},{value:`department`,label:`Department`},{value:`manager`,label:`Manager`},{value:`field`,label:`Field`},{value:`queue`,label:`Queue`}]},{key:`value`,label:`Value`,kind:`reference`,placeholder:`user id / role / field — per type`,ref:{kindFrom:`type`,objectSource:`$trigger`,map:{user:`user`,role:`role`,team:`team`,department:`department`,field:`object-field`,queue:`queue`}}}]}),Q(`behavior`,`Behavior`,`select`,{options:[{value:`first_response`,label:`First response wins`},{value:`unanimous`,label:`Unanimous (all approve)`}],defaultValue:`first_response`,help:`How multiple approvers combine.`}),Q(`lockRecord`,`Lock record`,`boolean`,{help:`Lock the triggering record from edits while this node is pending.`}),Q(`approvalStatusField`,`Status field`,`reference`,{ref:{kind:`object-field`,objectSource:`$trigger`},placeholder:`approval_status`,help:`Business-object field to mirror request status onto (pending/approved/rejected). Should be readonly.`}),{id:`escalation.enabled`,path:[`config`,`escalation`,`enabled`],label:`SLA escalation`,kind:`boolean`,defaultValue:`false`,help:`Escalate when a decision is not recorded within the timeout.`},{id:`escalation.timeoutHours`,path:[`config`,`escalation`,`timeoutHours`],label:`Timeout (hours)`,kind:`number`,placeholder:`24`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.action`,path:[`config`,`escalation`,`action`],label:`On timeout`,kind:`select`,defaultValue:`notify`,options:[{value:`notify`,label:`Notify`},{value:`reassign`,label:`Reassign`},{value:`auto_approve`,label:`Auto-approve`},{value:`auto_reject`,label:`Auto-reject`}],showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.escalateTo`,path:[`config`,`escalation`,`escalateTo`],label:`Escalate to`,kind:`reference`,ref:{kind:`role`},placeholder:`user id / role / manager level`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.notifySubmitter`,path:[`config`,`escalation`,`notifySubmitter`],label:`Notify submitter`,kind:`boolean`,showWhen:{field:`escalation.enabled`,equals:[`true`]}}],wait:[mC(`waitEventConfig`,`eventType`,`Wait for`,`select`,{options:[{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`webhook`,label:`Webhook`},{value:`manual`,label:`Manual`},{value:`condition`,label:`Condition`}],defaultValue:`timer`}),mC(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),mC(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),mC(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),mC(`waitEventConfig`,`onTimeout`,`On timeout`,`select`,{options:[{value:`fail`,label:`Fail`},{value:`continue`,label:`Continue`}],defaultValue:`fail`})],subflow:[Q(`flowName`,`Flow`,`reference`,{ref:{kind:`flow`},placeholder:`escalation_flow`}),Q(`input`,`Input mapping`,`keyValue`,{help:`Values passed to the subflow’s input variables.`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`subResult`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`60000`}],connector_action:[mC(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),mC(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),mC(`connectorConfig`,`input`,`Input`,`keyValue`,{help:`Mapped inputs for the connector action.`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],parallel_gateway:[],join_gateway:[],boundary_event:[mC(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),mC(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),mC(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),mC(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),mC(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),mC(`boundaryConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.cancelled`,showWhen:{field:`boundaryConfig.eventType`,equals:[`signal`]}})],legacy_action:[Q(`action`,`Action`,`text`,{placeholder:`sendEmail · createTask · update · query`}),Q(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),Q(`recordId`,`Record`,`expression`,{placeholder:`record.id`}),Q(`params`,`Parameters`,`keyValue`,{help:`Action inputs. Values auto-typed: 3 → number, true → boolean.`}),Q(`fields`,`Field values`,`keyValue`),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})]},_C={action:`legacy_action`,branch:`decision`,gateway:`decision`,condition:`decision`,timer:`wait`,delay:`wait`,flow:`subflow`,invoke:`subflow`,task:`legacy_action`,user_task:`screen`,service_task:`connector_action`,script_task:`script`,notification:`connector_action`,signal:`boundary_event`,webhook:`connector_action`,for_each:`loop`,parallel:`parallel_gateway`};function vC(e){return e?gC[_C[e]??e]??[]:[]}function yC(e,t){let n=e;for(let e of t.path)if(n&&typeof n==`object`&&!Array.isArray(n))n=n[e];else return;return n}function bC(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function xC(e,t,n){if(!e.showWhen)return!0;let r=yC(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=yC(t,i),o=a==null||a===``?i.defaultValue:a,s=typeof o==`boolean`?String(o):o;return typeof s==`string`&&e.showWhen.equals.includes(s)}var SC=[`start`,`create_record`,`update_record`,`delete_record`,`get_record`,`decision`,`assignment`,`loop`,`http_request`,`script`,`screen`,`approval`,`wait`,`subflow`,`connector_action`,`parallel_gateway`,`join_gateway`,`boundary_event`,`end`],CC=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function wC(e){let t=e.xRef;if(!t||typeof t!=`object`)return;let n=typeof t.objectSource==`string`&&t.objectSource?{objectSource:t.objectSource}:{};if(typeof t.kindFrom==`string`&&t.kindFrom&&t.map&&typeof t.map==`object`){let e={};for(let[n,r]of Object.entries(t.map))typeof r==`string`&&CC.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&CC.has(t.kind))return{kind:t.kind,...n}}function TC(e){let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim();return t?t.split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):e}function EC(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function DC(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`);if(typeof e.type==`string`)return e.type;if(Array.isArray(e.enum))return`string`;if(e.properties)return`object`;if(e.items)return`array`}function OC(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:TC(e)}))}function kC(e){if(!(e.default===void 0||e.default===null)){if(typeof e.default==`boolean`||typeof e.default==`number`)return String(e.default);if(typeof e.default==`string`)return e.default}}function AC(e){if(Array.isArray(e.enum))return`select`;let t=DC(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function jC(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!EC(r))continue;let t=DC(r),i,a,o=wC(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=OC(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||TC(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function MC(e,t){return{label:e.title||TC(t),...e.description?{help:e.description}:{},...kC(e)?{defaultValue:kC(e)}:{}}}function NC(e){if(!EC(e)||DC(e)!==`object`||!EC(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!EC(r))continue;let e=DC(r);if(e===`array`){let e=EC(r.items)?r.items:void 0,i=e?DC(e):void 0;e&&i===`object`&&EC(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:jC(e),...MC(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...MC(r,n)});continue}if(e===`object`&&EC(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>EC(e)),i=e.some(([e,t])=>e===`enabled`&&DC(t)===`boolean`);for(let[a,o]of e){let e=o,s=wC(e),c=s?`reference`:AC(e);if(!c)continue;let l=`${n}.${a}`,u=i&&a===`enabled`,d={id:l,path:[`config`,n,a],kind:c,...u?{label:r.title||TC(n),...r.description?{help:r.description}:{},...kC(e)?{defaultValue:kC(e)}:{}}:MC(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:OC(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=wC(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...MC(r,n)});continue}let a=AC(r);a&&t.push({id:n,path:[`config`,n],kind:a,...MC(r,n),...a===`select`&&Array.isArray(r.enum)?{options:OC(r.enum)}:{}})}return t}function PC(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function FC(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function IC(e){let t=e.trim();if(t===``)return``;if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function LC(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=Sy(`kv`,n);return n.push(r),{id:r,key:e,raw:FC(t)}})}function RC(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=IC(n.raw))}return t}function zC(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function BC({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=PC(t)?t:{},[d,f]=J.useState(()=>LC(u,[])),p=J.useRef(zC(u));J.useEffect(()=>{let e=zC(u);e!==p.current&&(f(LC(u,[])),p.current=e)},[u]);let m=e=>{let t=RC(e);p.current=zC(t),n(Object.keys(t).length?t:void 0)},h=(e,t)=>{f(n=>n.map(n=>n.id===e?{...n,...t}:n))},g=()=>{f(e=>[...e,{id:Sy(`kv`,e.map(e=>e.id)),key:``,raw:``}])},_=e=>{f(t=>{let n=t.filter(t=>t.id!==e);return m(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[d.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),d.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{value:e.key,onChange:t=>h(e.id,{key:t.target.value}),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:r,className:`h-8 flex-1 font-mono text-xs`}),(0,Y.jsx)(U,{value:e.raw,onChange:t=>h(e.id,{raw:t.target.value}),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:s,disabled:r,className:`h-8 flex-1 text-xs`}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>_(e.id),disabled:r,"aria-label":c,title:c,children:(0,Y.jsx)(po,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,Y.jsx)(K,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function VC(e,t){let n=[...t];return e.map(e=>{let t=Sy(`sl`,n);return n.push(t),{id:t,value:e}})}function HC(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function UC({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=J.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=J.useState(()=>VC(c,[])),d=J.useRef(JSON.stringify(c));J.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(VC(c,[])),d.current=e)},[c]);let f=e=>{let t=HC(e);d.current=JSON.stringify(t),n(t.length?t:void 0)},p=(e,t)=>{u(n=>n.map(n=>n.id===e?{...n,value:t}:n))},m=()=>{u(e=>[...e,{id:Sy(`sl`,e.map(e=>e.id)),value:``}])},h=e=>{u(t=>{let n=t.filter(t=>t.id!==e);return f(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{value:e.value,onChange:t=>p(e.id,t.target.value),onBlur:()=>f(l),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:a,disabled:r,className:`h-8 flex-1 text-xs`}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(e.id),disabled:r,"aria-label":o,title:o,children:(0,Y.jsx)(po,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(K,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}function WC(e){let t=Rm(),[n,r]=J.useState({fields:[],loading:!!e,error:null});return J.useEffect(()=>{if(!e){r({fields:[],loading:!1,error:null});return}let n=!1;return r(e=>({...e,loading:!0,error:null})),t.get(`object`,e).then(e=>{if(!n){if(!e){r({fields:[],loading:!1,error:`Object not found`});return}r({fields:m_(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`&&e.def.label?e.def.label:e.name,type:typeof e.def.type==`string`?e.def.type:`text`,hidden:e.def.hidden===!0})),loading:!1,error:null})}}).catch(e=>{n||r({fields:[],loading:!1,error:e?.message??String(e)})}),()=>{n=!0}},[t,e]),n}var GC={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function KC(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource};if(e.kindFrom&&e.map){let n=t(e.kindFrom),r=typeof n==`string`?e.map[n]:void 0;if(r)return{kind:r,objectSource:e.objectSource}}}}function qC(e,t){let n=e?.config;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[t];return typeof r==`string`&&r?r:void 0}function JC(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?qC((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):qC(n.node,r)}function YC(e){let t=Rm(),[n,r]=J.useState({options:[],loading:!!e});return J.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{n||r({options:(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)})),loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}function XC({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=J.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?JC(e.kind,e.objectSource,l):void 0,{fields:f}=WC(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?GC[u]:void 0,{options:m}=YC(p),h=J.useMemo(()=>{if(u===`object-field`)return f.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(u===`node`){let e=Array.isArray(l.draft.nodes)?l.draft.nodes:[],t=typeof l.node?.id==`string`?l.node.id:void 0;return e.filter(e=>typeof e?.id==`string`&&e.id&&e.id!==t).map(e=>{let t=String(e.id);return{value:t,label:typeof e.label==`string`&&e.label?`${e.label} (${t})`:t}})}return p?m:[]},[u,p,f,m,l.draft,l.node]),g=u===`object-field`&&!d;return(0,Y.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,Y.jsx)(U,{list:h.length?c:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:a,disabled:i,className:`h-8 text-sm`}),h.length>0&&(0,Y.jsx)(`datalist`,{id:c,children:h.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&g&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`})]})}function ZC({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=KC(e.ref,e=>qC(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(XC,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function QC(e,t){let n=[];return e.map(e=>{let r=Sy(`ol`,n);n.push(r);let i={};for(let n of t){let t=e[n.key];n.kind===`boolean`?i[n.key]=t===!0:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function $C(e,t){let n=[];for(let r of e){let e={},i=!1;for(let n of t){let t=r.values[n.key];n.kind===`boolean`?t===!0&&(e[n.key]=!0,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function ew({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,context:c}){let l=J.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[u,d]=J.useState(()=>QC(l,t)),f=J.useRef(JSON.stringify(l));J.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(QC(l,t)),f.current=e)},[l,t]);let p=e=>{let n=$C(e,t);f.current=JSON.stringify(n),r(n.length?n:void 0)},m=(e,t,n)=>{d(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},h=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:``;d(t=>[...t,{id:Sy(`ol`,t.map(e=>e.id)),values:e}])},g=e=>{d(t=>{let n=t.filter(t=>t.id!==e);return p(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[u.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),u.map(e=>(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,Y.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>g(e.id),disabled:i,"aria-label":o,title:o,children:(0,Y.jsx)(po,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(mt,{checked:e.values[t.key]===!0,onCheckedChange:n=>{d(r=>{let i=r.map(r=>r.id===e.id?{...r,values:{...r.values,[t.key]:n===!0}}:r);return p(i),i})},disabled:i}):t.kind===`reference`?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(XC,{resolved:KC(t.ref,t=>e.values[t]),value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>m(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>p(u),placeholder:t.placeholder,disabled:i,context:c,showHint:!1})}):(0,Y.jsx)(U,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>m(e.id,t.key,n.target.value),onBlur:()=>p(u),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:t.placeholder,disabled:i,className:`h-8 flex-1 text-xs${t.kind===`expression`?` font-mono`:``}`})]},t.key))})]},e.id))]}),(0,Y.jsxs)(G,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,Y.jsx)(K,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var tw=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function nw(e,t,n){let r=0;for(let i of e)if(i===t)r++;else if(i===n&&(r--,r<0))return!1;return r===0}function rw(e,t){let n=``,r;if(typeof t==`string`)n=t;else if(t&&typeof t==`object`){let e=t;r=e.dialect,n=e.source??``}if(!n.trim())return null;if(e===`template`){if(r&&r!==`template`)return{message:`Expected a text template but got a \`${r}\` expression.`};nw(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=tw.exec(n);return e?{message:`Single-brace \`{${e[1]}}\` is not a valid template hole — use double braces: \`{{ ${e[1]} }}\`.`}:null}if(r&&r!==`cel`)return{message:`Expected a CEL expression but got a \`${r}\` dialect.`};let i=tw.exec(n);return i?{message:`It looks like a \`{${i[1]}}\` template brace was used inside a condition — \`{…}\` parses as a CEL map literal and fails. Write the bare reference instead, e.g. \`${i[1]}\`. Conditions are bare CEL (e.g. \`record.rating >= 4\`).`}:nw(n,`(`,`)`)?nw(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function iw({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){let o=(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(ZC,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(BC,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:X(`engine.inspector.flowNode.kv.add`,i),keyLabel:X(`engine.inspector.flowNode.kv.key`,i),valueLabel:X(`engine.inspector.flowNode.kv.value`,i),removeLabel:X(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:X(`engine.inspector.flowNode.kv.empty`,i)});case`stringList`:return(0,Y.jsx)(UC,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:X(`engine.inspector.flowNode.list.add`,i),itemLabel:X(`engine.inspector.flowNode.list.item`,i),removeLabel:X(`engine.inspector.flowNode.list.remove`,i),emptyLabel:X(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Y.jsx)(ew,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:X(`engine.inspector.flowNode.list.add`,i),removeLabel:X(`engine.inspector.flowNode.list.remove`,i),emptyLabel:X(`engine.inspector.flowNode.list.empty`,i),context:a});case`number`:return(0,Y.jsx)(py,{label:e.label,value:typeof t==`number`?t:t!=null&&t!==``?Number(t):void 0,placeholder:e.placeholder,onCommit:e=>n(e),disabled:r});case`boolean`:return(0,Y.jsx)(gy,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(my,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(`textarea`,{value:t==null?``:String(t),onChange:e=>n(e.target.value),placeholder:e.placeholder,disabled:r,rows:4,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`})]});default:return(0,Y.jsx)(fy,{label:e.label,value:t==null?``:String(t),placeholder:e.placeholder,onCommit:e=>n(e),disabled:r,mono:e.kind===`expression`})}})(),s=e.kind===`expression`?rw(`predicate`,t):null;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[o,s&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:s.message}),e.help&&!s&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}function aw(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function ow(e,t,n){let[r,...i]=t,a={...e};if(i.length===0)n==null||n===``?delete a[r]:a[r]=n;else{let e=a[r],t=ow(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function sw({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.nodes)?t.nodes:[],s=o.findIndex(t=>t?.id===e.id),c=s>=0?o[s]:null,l=Xb(),u=J.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:NC(e))??vC(c?.type)},[l,c?.type]),d=aw(c),f=u.filter(e=>xC(e,c,u)),p=J.useMemo(()=>{let e=new Set;for(let t of u){let n=bC(t);n&&e.add(n)}return e},[u]),m=J.useMemo(()=>{let e=Object.fromEntries(Object.entries(d).filter(([e])=>!p.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[c,p]),[h,g]=J.useState(m),[_,v]=J.useState(null),[y,b]=J.useState(m.trim()!==``),[x,S]=J.useState(!1);if(J.useEffect(()=>{g(m),v(null),b(m.trim()!==``),S(!1)},[m]),!c)return(0,Y.jsx)(uy,{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)(vy,{message:e.id})});let C=e=>{n({nodes:yy(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:yy(o,s,ow(c,e,t))})},E=()=>{try{let e=h.trim()===``?{}:JSON.parse(h);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(d).filter(([e])=>p.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!p.has(e))),i={...t,...r};v(null);let a={...c};Object.keys(i).length===0?delete a.config:a.config=i,n({nodes:yy(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:yy(o,s,null)}),r()},O=SC.includes(c.type)?[...SC]:[...SC,c.type??``].filter(Boolean);return(0,Y.jsxs)(uy,{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)(_y,{label:X(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,Y.jsx)(fy,{label:X(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,Y.jsx)(my,{label:X(`engine.inspector.flowNode.type`,i),value:c.type,options:O.map(e=>({value:e,label:e})),onCommit:e=>C({type:e}),disabled:a}),(0,Y.jsx)(fy,{label:X(`engine.inspector.flowNode.description`,i),value:c.description??``,onCommit:e=>C({description:e||void 0}),disabled:a}),u.length===0?(0,Y.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:X(`engine.inspector.flowNode.noConfig`,i)}):f.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:X(`engine.inspector.flowNode.configuration`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),f.map(e=>(0,Y.jsx)(iw,{field:e,value:yC(c,e),onCommit:t=>T(e.path,t),disabled:a,locale:i,context:{draft:t,node:c}},e.id)),w||x?(0,Y.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:y,onToggle:e=>b(e.target.open),children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:X(`engine.inspector.flowNode.advanced`,i)}),(0,Y.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:X(`engine.inspector.flowNode.advancedHint`,i)}),(0,Y.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),onBlur:E,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),_&&(0,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:_})]})]}):!a&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{S(!0),b(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,Y.jsx)(K,{className:`h-3 w-3`}),X(`engine.inspector.flowNode.advanced`,i)]})]})}function cw({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`div`,{className:`flex h-8 items-center rounded border bg-muted/30 px-2 font-mono text-sm text-muted-foreground`,children:t})]})}function lw({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.edges)?t.edges:[],s=o.findIndex((t,n)=>Nb(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,Y.jsx)(uy,{kindLabel:X(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:X(`engine.inspector.flowEdge.close`,i),children:(0,Y.jsx)(vy,{message:X(`engine.inspector.flowEdge.missing`,i)})});let l=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}n({edges:yy(o,s,t)})},u=c.isDefault===!0;return(0,Y.jsxs)(uy,{kindLabel:X(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:X(`engine.inspector.flowEdge.close`,i),footer:(0,Y.jsx)(_y,{label:X(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:yy(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(cw,{label:X(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(cw,{label:X(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:X(`engine.inspector.flowEdge.routing`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Y.jsx)(fy,{label:X(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>l({label:e}),placeholder:X(`engine.inspector.flowEdge.labelHint`,i),disabled:a||u}),(0,Y.jsx)(fy,{label:X(`engine.inspector.flowEdge.condition`,i),value:Pb(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:X(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(()=>{let e=u?null:rw(`predicate`,c.condition);return e?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message}):null})(),(0,Y.jsx)(gy,{label:X(`engine.inspector.flowEdge.isDefault`,i),value:u,onCommit:e=>l(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:X(`engine.inspector.flowEdge.hint`,i)})]})}function uw(e){return e.selection.kind===`edge`?(0,Y.jsx)(lw,{...e}):(0,Y.jsx)(sw,{...e})}var dw=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function fw(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 pw(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 mw(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:yy(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=yy(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function hw(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 gw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=fw(e.id),{node:c,parent:l,index:u}=s?pw(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Y.jsx)(uy,{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)(vy,{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(mw(t,s,{...c,...e}))};return(0,Y.jsxs)(uy,{kindLabel:X(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:X(`engine.inspector.appNav.close`,a),headerActions:(0,Y.jsx)(dy,{index:u,total:l.length,onMove:e=>{n(hw(t,s,xy(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)(_y,{label:X(`engine.inspector.appNav.remove`,a),onClick:()=>{n(mw(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(fy,{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)(fy,{label:X(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Y.jsx)(my,{label:X(`engine.inspector.appNav.kindField`,a),value:c.kind,options:dw.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var _w={io:`input`,unrepresentable:`any`},vw=new Set([`columns`,`data`,`name`]),yw,bw=!1;function xw(){if(yw||bw)return yw;try{yw=M(P,_w)}catch(e){bw=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return yw}function Sw(){return xw()?.properties?.list}function Cw(){return xw()?.properties?.form}var ww,Tw=!1;function Ew(){if(ww||Tw)return ww;try{ww=M(ne,_w)}catch(e){Tw=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return ww}var Dw;function Ow(){if(Dw)return Dw;if(!(!N||typeof N!=`object`)){try{let e=JSON.parse(JSON.stringify(N));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!vw.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Dw=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Dw}}var kw=`text/x-objectui-viewcol`;function Aw({type:e}){let t=tb(e),n=Qy(e),r=t.Icon;return(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function jw({index:e,label:t,fieldName:n,fieldType:r,selected:i,canEdit:a,dragging:o,dropBefore:s,onSelect:c,onRemove:l,onDragStart:u,onDragEnd:d,onDragOverRow:f,onDropRow:p}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[s&&(0,Y.jsx)(`span`,{className:`pointer-events-none absolute -top-0.5 left-0 right-0 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,draggable:a,"aria-pressed":i,onDragStart:t=>{a&&(t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(kw,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(kw)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(kw)&&(e.preventDefault(),e.stopPropagation(),p())},onClick:c,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),c())},className:`group flex items-center gap-2 rounded-md border bg-card px-2 py-1.5 text-xs transition-colors hover:border-primary/40 `+(i?`border-primary ring-1 ring-primary `:`border-border `)+(a?`cursor-grab active:cursor-grabbing`:``),children:[a&&(0,Y.jsx)(Ae,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,Y.jsx)(Aw,{type:r}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:t}),n&&n!==t&&(0,Y.jsx)(`code`,{className:`max-w-[7rem] shrink-0 truncate text-[10px] text-muted-foreground`,children:n}),a&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,"aria-label":`Remove ${t}`,onClick:e=>{e.stopPropagation(),l()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),l())},className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/60 hover:bg-destructive/10 hover:text-destructive`,children:(0,Y.jsx)(po,{className:`h-3 w-3`})})]})]})}function Mw({fields:e,usedNames:t,loading:n,error:r,onAdd:i}){let[a,o]=J.useState(!1),[s,c]=J.useState(``),l=J.useMemo(()=>{let t=s.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)):e},[e,s]);return(0,Y.jsxs)(wr,{open:a,onOpenChange:o,children:[(0,Y.jsx)(Pe,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-md border border-dashed px-2 py-1 text-xs text-muted-foreground hover:border-primary/40 hover:bg-accent/40 hover:text-foreground`,children:[(0,Y.jsx)(K,{className:`h-3.5 w-3.5`}),` Add field`]})}),(0,Y.jsxs)(Dn,{align:`start`,className:`w-72 p-0`,children:[(0,Y.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,Y.jsx)(go,{className:`pointer-events-none absolute left-4 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(`input`,{autoFocus:!0,value:s,onChange:e=>c(e.target.value),placeholder:`Search fields…`,className:`h-8 w-full rounded border border-input bg-background pl-7 pr-2 text-xs outline-none focus:border-primary`})]}),(0,Y.jsx)(`div`,{className:`max-h-72 overflow-auto p-1`,children:n?(0,Y.jsx)(Nw,{children:`Loading fields…`}):r?(0,Y.jsxs)(Nw,{tone:`warn`,children:[`No object fields (`,r,`).`]}):l.length===0?(0,Y.jsx)(Nw,{children:s?`No matching fields.`:`No fields on this object.`}):l.map(e=>{let n=t.has(e.name);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(Aw,{type:e.type}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label}),e.name!==e.label&&(0,Y.jsx)(`code`,{className:`max-w-[6rem] truncate text-[10px] text-muted-foreground`,children:e.name}),n&&(0,Y.jsx)(V,{variant:`secondary`,className:`px-1 py-0 text-[9px]`,children:`Added`})]},e.name)})})]})]})}function Nw({children:e,tone:t}){return(0,Y.jsx)(`div`,{className:`px-2 py-4 text-center text-[11px] `+(t===`warn`?`text-amber-600 dark:text-amber-300`:`text-muted-foreground`),children:e})}function Pw(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 Fw(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function Iw(e){let t=new Set;for(let n of e){let e=Fw(n);e&&t.add(e)}return t}function Lw(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Rw(e,t){return e===t?null:e>t?e-1:e}function zw(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Bw({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,selectedIndex:a,readOnly:o,onPatch:s,onSelectionChange:c}){let l=!o,{fields:u,loading:d,error:f}=WC(i||void 0),p=J.useMemo(()=>{let e=new Map;for(let t of u)e.set(t.name,t.type);return e},[u]),[m,h]=J.useState(null),[g,_]=J.useState(null),v=J.useCallback(n=>{s({[e]:{...t,columns:n}})},[s,e,t]),y=J.useCallback(t=>{let i=by(n,Lw(r,t.name,t.label));v(i),c?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,v,e,c]),b=J.useCallback(t=>{let r=yy(n,t,null);if(v(r),a!=null){let n=Rw(a,t);n==null?c?.(null):c?.({kind:`column`,id:`${e}.columns[${n}]`,label:Pw(r[n],n)})}},[n,v,a,e,c]),x=J.useCallback((t,r)=>{if(t===r)return;let i=xy(n,t,r);if(v(i),a!=null){let n=zw(a,t,r);c?.({kind:`column`,id:`${e}.columns[${n}]`,label:Pw(i[n],n)})}},[n,v,a,e,c]),S=J.useCallback(t=>{c?.({kind:`column`,id:`${e}.columns[${t}]`,label:Pw(n[t],t)})},[n,e,c]),C=Iw(n);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)(W,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,Y.jsx)(V,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Y.jsx)(jw,{index:t,label:Pw(e,t),fieldName:Fw(e),fieldType:p.get(Fw(e)??``)??`text`,selected:a===t,canEdit:l,dragging:m!==null,dropBefore:g===t&&m!==null&&m!==t,onSelect:()=>S(t),onRemove:()=>b(t),onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOverRow:()=>_(t),onDropRow:()=>{m!=null&&m!==t&&x(m,t),h(null),_(null)}},t))}),l&&(0,Y.jsx)(Mw,{fields:u,usedNames:C,loading:d,error:f,onAdd:y})]})}var Vw=[`field`,`label`,`accessorKey`,`header`];function Hw(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function Uw(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function Ww(e){return e.field??e.accessorKey??``}function Gw(e){return e.label??e.header??Ww(e)}function Kw(e){return Object.keys(e).some(e=>!Vw.includes(e))}function qw(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function Jw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=Hw(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(Uw),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=J.useMemo(()=>Ew(),[]),m=qw(c),{fields:h}=WC(m||void 0),g=d?Ww(d):``,_=J.useMemo(()=>{let e=h.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} · ${e.name}`:e.name}));return g&&!e.some(e=>e.value===g)&&e.unshift({value:g,label:`${g} (not in object)`}),e},[h,g]);if(!s||!d)return(0,Y.jsx)(uy,{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)(vy,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=Ww(e);return n&&!Kw(e)&&!e.label&&!e.header&&r?r:e});n({[s.variant]:{...c,columns:t}})},y=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),v(yy(u,s.index,{...d,...r}))};return(0,Y.jsxs)(uy,{kindLabel:X(`engine.inspector.viewColumn.kind`,a),title:Gw(d)||e.id,onClose:r,closeLabel:X(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(dy,{index:s.index,total:u.length,onMove:e=>{v(xy(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:Gw(d)||`columns[${e}]`})},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(_y,{label:X(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(yy(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(Bw,{variantKey:s.variant,schema:c,columns:l,allStrings:l.length>0&&l.every(e=>typeof e==`string`),objectName:m||void 0,selectedIndex:s.index,readOnly:o,onPatch:n,onSelectionChange:i})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,Y.jsx)(my,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:Ww(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(fy,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:Ww(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.viewColumn.header`,a),value:Gw(d)===Ww(d)?``:Gw(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(kg,{schema:p,value:d,hiddenFields:Vw,readOnly:o,onChange:e=>{v(yy(u,s.index,e))}})}):null]})]})}var Yw={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`},Xw=[`columns`,`data`,`name`];function Zw(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function Qw(e){return J.useMemo(()=>{let t=Sw()?.properties?.type?.enum,n=(Array.isArray(t)&&t.length?t.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:Yw[e]??e}));return!n.some(t=>t.value===e)&&e&&n.push({value:e,label:e}),n},[e])}function $w({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s}){let c=e[t]??{},l=$v(n??t),u=typeof c.type==`string`?c.type:`grid`,d=Qw(u),f=Zw(c,e),p=typeof e.label==`string`&&e.label||(typeof c.label==`string`?c.label:``)||``,m=Array.isArray(c.columns)?c.columns:[],h=m.length>0&&m.every(e=>typeof e==`string`),{fields:g}=WC(f.value||void 0),_=J.useMemo(()=>({objectFields:g.map(e=>({name:e.name,label:e.label,type:e.type}))}),[g]),v=l?void 0:Ow(),y=l?Cw():Sw(),b=e=>{i({[t]:{...c,...e}})};return(0,Y.jsxs)(uy,{kindLabel:`View`,title:String(p||e.name||t),onClose:()=>o?.(),closeLabel:`Close`,hideClose:r,children:[(0,Y.jsx)(fy,{label:`Label`,value:p,onCommit:e=>{i({label:e,[t]:{...c,label:e}})},placeholder:`e.g. All Leads`,disabled:a}),(0,Y.jsx)(my,{label:`View type`,value:u,options:d,onCommit:e=>b({type:e}),disabled:a}),(0,Y.jsx)(fy,{label:`Object`,value:f.value,onCommit:e=>{let n={object:e};c.data&&typeof c.data==`object`?n[t]={...c,data:{...c.data,object:e}}:f.path===`object`&&(n[t]={...c,object:e}),i(n)},placeholder:`e.g. crm_lead`,disabled:a,mono:!0}),!l&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Bw,{variantKey:t,schema:c,columns:m,allStrings:h,objectName:f.value||void 0,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:y?(0,Y.jsx)(kg,{schema:y,form:v,value:c,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:_,onChange:e=>{let n={...e};for(let e of Xw)e in c?n[e]=c[e]:delete n[e];i({[t]:n})}}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Spec schema unavailable — basic properties only.`})})]})}function eT(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(Jw,{...e});let n=iy(e.draft,t.id||void 0)??ry(e.draft);return(0,Y.jsx)($w,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function tT(e){let t=ry(e.draft);return(0,Y.jsx)($w,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}function nT(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 rT(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 iT(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:yy(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 aT(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 oT(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 sT({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=nT(e.id),c=s?rT(t,s):null,l=s?aT(t,s):null;if(!s||!c)return(0,Y.jsx)(uy,{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)(vy,{message:e.id})});let u=e=>n(iT(t,s,{...c,...e}));return(0,Y.jsxs)(uy,{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)(dy,{index:l.index,total:l.siblings.length,onMove:e=>{if(!l)return;n(oT(t,s,xy(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)(_y,{label:X(`engine.inspector.pageBlock.remove`,a),onClick:()=>{n(iT(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(fy,{label:X(`engine.inspector.pageBlock.type`,a),value:c.type??``,onCommit:e=>u({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.pageBlock.id`,a),value:c.id??``,onCommit:e=>u({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.pageBlock.className`,a),value:c.className??``,onCommit:e=>u({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.pageBlock.hidden`,a),value:c.hidden??``,onCommit:e=>u({hidden:e}),disabled:o,mono:!0})]})}var cT=`__none__`,lT=[{value:cT,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function uT(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function dT({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=uT(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,Y.jsx)(uy,{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)(vy,{message:e.id})});let u=e=>n({columns:yy(c,s,{...l,...e})});return(0,Y.jsxs)(uy,{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)(dy,{index:s,total:c.length,onMove:e=>{n({columns:xy(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)(_y,{label:X(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:yy(c,s,null)}),r()},disabled:o}),children:[(0,Y.jsx)(fy,{label:X(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(fy,{label:X(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Y.jsx)(my,{label:X(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??cT,options:lT,onCommit:e=>u({aggregate:e===cT?void 0:e}),disabled:o})]})}var fT=e=>(e??``).toLowerCase().startsWith(`zh`);function pT(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 mT(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function hT(e){return e===`lookup`||e===`master_detail`||e===`tree`}function gT(e){return e===`formula`||e===`summary`}function _T(e){return e===`number`||e===`currency`||e===`percent`}function vT(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function yT(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}function bT(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?$y:Xy;return eb.flatMap(e=>e.types.map(r=>{let i=Jy[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function xT({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=J.useCallback(e=>X(e,o),[o]),c=J.useMemo(()=>bT(o),[o]),l=J.useMemo(()=>m_(t.fields),[t]),u=String(e.id),d=g_(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=DT();if(!f)return(0,Y.jsx)(uy,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Y.jsx)(vy,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=Jy[g],v=e=>{n({fields:h_(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=y_(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},v({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(h.label??t)})},x=()=>{let e=l.entries.filter((e,t)=>t!==d);v({shape:l.shape,entries:e}),r()},S=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof h.label==`string`&&h.label?h.label:``,o={name:n,def:{...h,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),v({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},C=e=>{v({shape:l.shape,entries:xy(l.entries,d,e)})},w=pT(h),T=e=>{y({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},E=(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:S,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,Y.jsx)(He,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(dy,{index:d,total:l.entries.length,onMove:C,disabled:a})]}),D=(0,Y.jsx)(_y,{label:Qm(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:x,disabled:a}),O=fT(o)?_?.labelZh:_?.label;return(0,Y.jsxs)(uy,{kindLabel:s(`designer.field.kind`),title:typeof h.label==`string`&&h.label?h.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:E,footer:D,children:[(0,Y.jsxs)(ST,{title:s(`designer.field.section.basic`),children:[(0,Y.jsx)(fy,{label:s(`designer.field.apiName`),value:f.name,onCommit:b,disabled:a,mono:!0}),(0,Y.jsx)(fy,{label:s(`designer.field.label`),value:typeof h.label==`string`?h.label:``,onCommit:e=>y({label:e}),disabled:a}),(0,Y.jsx)(my,{label:s(`designer.field.type`),value:g,options:c,onCommit:e=>y({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(gy,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,Y.jsx)(gy,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(wT,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),yT(g)&&(0,Y.jsx)(CT,{kind:yT(g),value:h.defaultValue,options:w,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,Y.jsx)(wT,{label:s(`designer.field.helpText`),value:typeof h.inlineHelpText==`string`?h.inlineHelpText:``,onCommit:e=>y({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(mT(g)||hT(g)||gT(g)||_T(g)||vT(g))&&(0,Y.jsxs)(ST,{title:Qm(`designer.field.section.options`,o,{type:O??g}),children:[mT(g)&&(0,Y.jsx)(ET,{options:w,onChange:T,disabled:a,locale:o}),hT(g)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(TT,{label:s(`designer.field.relatedObject`),value:typeof h.reference==`string`?h.reference:``,options:m,onCommit:e=>y({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(fy,{label:s(`designer.field.relationshipName`),value:typeof h.relationshipName==`string`?h.relationshipName:``,onCommit:e=>y({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)})]}),gT(g)&&(0,Y.jsx)(wT,{label:s(`designer.field.formula`),value:typeof h.formula==`string`?h.formula:``,onCommit:e=>y({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),_T(g)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(py,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,Y.jsx)(py,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,Y.jsx)(py,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,Y.jsx)(py,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),vT(g)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(py,{label:s(`designer.field.minLength`),value:typeof h.minLength==`number`?h.minLength:void 0,onCommit:e=>y({minLength:e}),disabled:a,placeholder:`0`}),(0,Y.jsx)(py,{label:s(`designer.field.maxLength`),value:typeof h.maxLength==`number`?h.maxLength:void 0,onCommit:e=>y({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,Y.jsxs)(ST,{title:s(`designer.field.section.advanced`),children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(gy,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(gy,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(gy,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(gy,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(gy,{label:s(`designer.field.trackHistory`),value:!!h.trackHistory,onCommit:e=>y({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(fy,{label:s(`designer.field.placeholder`),value:typeof h.placeholder==`string`?h.placeholder:``,onCommit:e=>y({placeholder:e||void 0}),disabled:a}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(fy,{label:s(`designer.field.conditionalRequired`),value:typeof h.conditionalRequired==`string`?h.conditionalRequired:``,onCommit:e=>y({conditionalRequired:e||void 0}),disabled:a,mono:!0,placeholder:`record.status == 'closed'`}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRequiredHint`)})]}),p.length>0&&(0,Y.jsx)(my,{label:s(`designer.field.group`),value:typeof h.group==`string`?h.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>y({group:e||void 0}),disabled:a})]})]})}function ST({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 CT({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=X(`designer.field.defaultValue`,a),s=X(`designer.field.defaultNone`,a);return e===`bool`?(0,Y.jsx)(my,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:X(`designer.field.true`,a)},{value:`false`,label:X(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Y.jsx)(py,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Y.jsx)(my,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,Y.jsx)(fy,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function wT({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)(W,{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 TT({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=J.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(U,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,Y.jsx)(`datalist`,{id:o,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function ET({options:e,onChange:t,disabled:n,locale:r}){let i=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},a=n=>t(e.filter((e,t)=>t!==n)),o=(n,r)=>t(xy(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)(W,{className:`text-xs text-muted-foreground`,children:X(`designer.field.picklistValues`,r)}),(0,Y.jsx)(V,{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:X(`designer.field.noValues`,r)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:e.map((t,s)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(U,{value:t.value,onChange:e=>i(s,{value:e.target.value}),placeholder:X(`designer.field.optValue`,r),disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,Y.jsx)(U,{value:t.label??``,onChange:e=>i(s,{label:e.target.value}),placeholder:X(`designer.field.optLabel`,r),disabled:n,className:`h-7 text-xs flex-1`}),(0,Y.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>i(s,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:X(`designer.field.optColor`,r)}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o(s,s-1),disabled:n||s===0,"aria-label":X(`designer.field.moveUp`,r),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`,onClick:()=>o(s,s+1),disabled:n||s===e.length-1,"aria-label":X(`designer.field.moveDown`,r),children:(0,Y.jsx)(or,{className:`h-3 w-3`})}),(0,Y.jsx)(G,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>a(s),disabled:n,"aria-label":X(`designer.field.removeValue`,r),children:(0,Y.jsx)(po,{className:`h-3 w-3`})})]},s))}),!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)(K,{className:`h-3 w-3`}),X(`designer.field.addValue`,r)]})]})}function DT(){let e=Rm(),[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 OT({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=J.useCallback(e=>X(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=J.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=y_(e)),n(t)},u=e=>{c.current=!0,n({name:y_(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Y.jsx)(uy,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,Y.jsxs)(kT,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Y.jsx)(AT,{hint:a(`designer.object.nameHint`),children:(0,Y.jsx)(fy,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Y.jsx)(fy,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Y.jsx)(fy,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,Y.jsx)(AT,{hint:a(`designer.object.iconHint`),children:(0,Y.jsx)(fy,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(W,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,Y.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]})})}function kT({title:e,hint:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:n})]})}function AT({hint:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}function jT(){N_(`dashboard`,dC),N_(`flow`,uw),N_(`app`,gw),N_(`view`,eT),I_(`view`,tT),N_(`page`,sT),N_(`report`,dT),N_(`object`,xT),I_(`object`,OT)}var MT=t({MetadataDiagnosticsPage:()=>Sv,MetadataDirectoryPage:()=>ih,MetadataResourceEditPage:()=>gv,MetadataResourceHistoryPage:()=>i_,MetadataResourceListPage:()=>Vh,StudioHomePage:()=>Th});Dv(),jv(),oC(),jT();function NT(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function PT(e){return!NT(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function FT(e){if(!NT(e))return;let t=e.config;if(NT(t)&&typeof t.type==`string`)return t.type;if(typeof e.type==`string`)return e.type;if(e.viewKind===`form`)return`form`;if(e.viewKind===`list`)return`list`}Im({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:ih}),Im({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:bv}),Im({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:gh}),Ih({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`}]}),Ih({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`}]}),Ih({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:wv,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`}]}),Ih({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%`,render:(e,t)=>FT(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!PT(e)}),Ih({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`}]}),Ih({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 IT=(0,J.lazy)(()=>c(()=>import(`./SystemHubPage-CrPlzy52.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),LT=(0,J.lazy)(()=>c(()=>import(`./AppManagementPage-GNlxvYjB.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),RT=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-BWTzOuUR.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),zT=(0,J.lazy)(()=>c(()=>import(`./ApprovalsInboxPage-BjgnPpO0.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),BT=(0,J.lazy)(()=>c(()=>import(`./AiPendingActionsPage-jLWo6Ayv.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),VT=(0,J.lazy)(()=>c(()=>import(`./AuditLogPage-5XSTvoRE.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),HT=(0,J.lazy)(()=>c(()=>import(`./SettingsHub-CIY42FH1.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),UT=(0,J.lazy)(()=>c(()=>import(`./SettingsView-CegTe8Ea.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),WT=(0,J.lazy)(()=>c(()=>import(`./DeveloperHubPage-dAwpubU9.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),GT=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-CWTG8Xo7.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),KT=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage--fqUTSur.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),qT=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BYCoo2T3.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function JT(){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 YT(){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 XT=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{path:`system`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(IT,{})})}),(0,Y.jsx)(d,{path:`system/apps`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(LT,{})})}),(0,Y.jsx)(d,{path:`system/profile`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(RT,{})})}),(0,Y.jsx)(d,{path:`system/approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(zT,{})})}),(0,Y.jsx)(d,{path:`system/ai-approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(BT,{})})}),(0,Y.jsx)(d,{path:`system/audit-log`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(VT,{})})}),(0,Y.jsx)(d,{path:`system/settings`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(HT,{})})}),(0,Y.jsx)(d,{path:`system/settings/:namespace`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(UT,{})})}),(0,Y.jsx)(d,{path:`developer`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(WT,{})})}),(0,Y.jsx)(d,{path:`developer/api-console`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(GT,{})})}),(0,Y.jsx)(d,{path:`developer/flow-runs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(KT,{})})}),(0,Y.jsx)(d,{path:`developer/public-forms`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(qT,{})})}),(0,Y.jsx)(d,{path:`system/objects`,element:(0,Y.jsx)(JT,{})}),(0,Y.jsx)(d,{path:`system/objects/:objectName`,element:(0,Y.jsx)(JT,{})}),(0,Y.jsx)(d,{path:`system/metadata`,element:(0,Y.jsx)(YT,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType`,element:(0,Y.jsx)(YT,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType/:itemName`,element:(0,Y.jsx)(YT,{})})]});function ZT(){let e=(0,J.useMemo)(()=>hi({baseUrl:``}),[``]);return(0,Y.jsx)(j,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Y.jsx)(ql,{}),children:(0,Y.jsx)(Si,{adapter:e,children:(0,Y.jsx)(ep,{extraRoutes:XT,extraRoutesNoApp:XT})})})}var QT=[`cloud_control`];function $T(){let{apps:e,loading:t}=re();if(t)return(0,Y.jsx)(ic,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of QT)if(n.has(e))return(0,Y.jsx)(_,{to:`/apps/${e}`,replace:!0});return(0,Y.jsx)(_,{to:`/home`,replace:!0})}var eE=`/api/v1`;function tE(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function nE(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 rE(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=tE(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:nE(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function iE(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 aE(e,t){return fetch(`${eE}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function oE(e){let t=await aE(`/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 sE(e){let t=await aE(`/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 aE(`/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 cE(e,t){let n=await aE(`/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 lE(e,t){let n=await aE(`/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 uE=`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 dE({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:uE},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 fE({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`?oE(r):sE(r)).then(e=>{t||(u(e),p(iE(rE(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?rE(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 cE(r,d):await lE(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(iE(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)(dE,{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 pE({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 mE(){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 hE(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 gE(){let{token:e}=f(),t=`${(0,J.useMemo)(()=>mE(),[])}/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)(B,{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)(Yt,{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)(W,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Y.jsx)(U,{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)(ut,{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)(Er,{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)(V,{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)(B,{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=hE(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 _E(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function vE(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function yE(){return typeof window>`u`?null:window.location.host||null}function bE(){let e=kl();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 xE({children:e,formWidth:t=`sm`}){let{t:n}=z(),r=t===`md`?`max-w-md`:`max-w-sm`,i=yE(),a=!!i&&!_E(i)&&!vE(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:H(`flex w-full flex-col gap-5`,r),children:[(0,Y.jsx)(bE,{}),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 SE(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function CE(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function wE(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function TE(){let{t:e}=z(),[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(CE(SE(n)?n:`/`));return}window.location.assign(CE(`/organizations`));return}p||window.location.assign(CE(SE(n)?n:`/`))}},[r,s,a,o,p,n,c]),i&&!h||r)return(0,Y.jsx)(xE,{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)(xE,{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)(It,{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)(EE,{registerUrl:d?void 0:v,redirect:n})})]})})}function EE({registerUrl:e,redirect:t}){let{t:n}=z(),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:wE,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 DE(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function OE(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function kE(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function AE(){let{t:e}=z(),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(OE(DE(r)?r:`/`));return}window.location.assign(OE(`/organizations`));return}h||window.location.assign(OE(DE(r)?r:`/`))}},[i,u,o,c,h,r,d]),p===null||a&&!_||i)return(0,Y.jsx)(xE,{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)(xE,{formWidth:`md`,children:(0,Y.jsx)(It,{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:kE,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 jE(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function ME(){let{t:e}=z();return(0,Y.jsx)(xE,{formWidth:`md`,children:(0,Y.jsx)(It,{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)(ee,{loginUrl:`/login`,linkComponent:jE,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 NE(){let{t:e}=z(),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)(xE,{children:(0,Y.jsxs)(It,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Y.jsx)(At,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Y.jsx)(Ca,{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)(W,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(U,{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 PE=`/api/v1/auth`;function FE(){let{t:e}=z(),[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(`${PE}/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)(xE,{children:(0,Y.jsxs)(It,{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)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Y.jsx)(At,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Y.jsx)(Ca,{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)(hr,{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)(sa,{className:`size-6`})}),(0,Y.jsx)(ur,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Y.jsx)(At,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Y.jsx)(Ca,{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)(hr,{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)(gr,{className:`size-6`})}),(0,Y.jsx)(ur,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Y.jsx)(At,{children:o||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Y.jsx)(Ca,{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 IE(){let{t:e}=z(),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)(xE,{children:(0,Y.jsxs)(It,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(hr,{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)(ro,{className:`size-8 text-primary`})}),(0,Y.jsx)(ur,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Y.jsx)(At,{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)(Ca,{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)(Ni,{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)(Ni,{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 LE=`/api/v1/auth`;function RE(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function zE(){let{t:e}=z(),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(`${LE}/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)(It,{children:[(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Y.jsx)(At,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Y.jsx)(Ca,{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:RE(e)}),n=t.id):n=(await c({name:e,slug:RE(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)(W,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(U,{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)(W,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Y.jsx)(U,{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 BE=`/api/v1/auth`;function VE(){let{t:e}=z(),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(`${BE}/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(`${BE}/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)(It,{className:`w-full max-w-md`,children:[(0,Y.jsxs)(hr,{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)(Zn,{className:`h-7 w-7 text-muted-foreground`})}),(0,Y.jsx)(ur,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,Y.jsx)(At,{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)(Ca,{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)(ti,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{children:HE(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)(po,{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)(ti,{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 HE(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 UE=`/api/v1/auth`;function WE({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)(fa,{className:`size-4`})}),`ObjectStack`]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function GE(){let{t:e}=z(),[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)(WE,{children:(0,Y.jsx)(It,{children:(0,Y.jsx)(hr,{className:`text-center`,children:(0,Y.jsx)(At,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?f?(0,Y.jsx)(WE,{children:(0,Y.jsx)(It,{children:(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(sa,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Y.jsx)(ur,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Y.jsx)(At,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):m?(0,Y.jsx)(WE,{children:(0,Y.jsx)(It,{children:(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Y.jsx)(At,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Y.jsx)(WE,{children:(0,Y.jsxs)(It,{children:[(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Y.jsx)(At,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Y.jsxs)(Ca,{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(`${UE}/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(`${UE}/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)(WE,{children:(0,Y.jsx)(It,{children:(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Y.jsx)(At,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function KE(){let{t:e}=z(),{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)(It,{children:[(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Y.jsx)(At,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Y.jsxs)(Ca,{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)(It,{className:`w-full max-w-sm`,children:(0,Y.jsxs)(hr,{className:`text-center`,children:[(0,Y.jsx)(ur,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Y.jsx)(At,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var qE=`/api/v1/auth`;function JE(){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 YE=JE();function XE(){let e=o(),t=e.pathname+e.search;return(0,Y.jsx)(_,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function ZE({children:e,requireOrganization:t=!0}){return(0,Y.jsx)(te,{fallback:(0,Y.jsx)(XE,{}),loadingFallback:(0,Y.jsx)(ic,{}),children:(0,Y.jsx)(oc,{children:t?(0,Y.jsx)(lc,{children:e}):e})})}function QE(){let{user:e}=w();return(0,Y.jsx)(Yp,{userId:e?.id,children:(0,Y.jsx)(cm,{})})}function $E(){return(0,Y.jsxs)(A,{authUrl:qE,children:[(0,Y.jsx)(Jl,{position:`bottom-right`}),(0,Y.jsx)(pE,{}),(0,Y.jsx)(u,{basename:YE,children:(0,Y.jsx)(ac,{children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/login`,element:(0,Y.jsx)(TE,{})}),(0,Y.jsx)(d,{path:`/register`,element:(0,Y.jsx)(AE,{})}),(0,Y.jsx)(d,{path:`/forgot-password`,element:(0,Y.jsx)(ME,{})}),(0,Y.jsx)(d,{path:`/reset-password`,element:(0,Y.jsx)(NE,{})}),(0,Y.jsx)(d,{path:`/verify-email`,element:(0,Y.jsx)(FE,{})}),(0,Y.jsx)(d,{path:`/verify-email-prompt`,element:(0,Y.jsx)(IE,{})}),(0,Y.jsx)(d,{path:`/setup`,element:(0,Y.jsx)(zE,{})}),(0,Y.jsx)(d,{path:`/oauth/consent`,element:(0,Y.jsx)(VE,{})}),(0,Y.jsx)(d,{path:`/auth/device`,element:(0,Y.jsx)(GE,{})}),(0,Y.jsx)(d,{path:`/accept-invitation/:invitationId`,element:(0,Y.jsx)(KE,{})}),(0,Y.jsx)(d,{path:`/f/:slug`,element:(0,Y.jsx)(fE,{mode:`public`})}),(0,Y.jsx)(d,{path:`/s/:token`,element:(0,Y.jsx)(gE,{})}),(0,Y.jsx)(d,{path:`/forms/:name`,element:(0,Y.jsx)(ZE,{children:(0,Y.jsx)(fE,{mode:`internal`})})}),(0,Y.jsx)(d,{path:`/home`,element:(0,Y.jsx)(ZE,{children:(0,Y.jsx)(QE,{})})}),(0,Y.jsx)(d,{path:`/organizations`,element:(0,Y.jsx)(ZE,{requireOrganization:!1,children:(0,Y.jsx)(lm,{children:(0,Y.jsx)(mm,{})})})}),(0,Y.jsxs)(d,{path:`/organizations/:slug`,element:(0,Y.jsx)(ZE,{requireOrganization:!1,children:(0,Y.jsx)(hm,{})}),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)(bm,{})}),(0,Y.jsx)(d,{path:`invitations`,element:(0,Y.jsx)(Cm,{})}),(0,Y.jsx)(d,{path:`settings`,element:(0,Y.jsx)(wm,{})})]}),(0,Y.jsx)(d,{path:`/system/*`,element:(0,Y.jsx)(uc,{})}),(0,Y.jsx)(d,{path:`/ai`,element:(0,Y.jsx)(ZE,{children:(0,Y.jsx)(Am,{})})}),(0,Y.jsx)(d,{path:`/ai/:conversationId`,element:(0,Y.jsx)(ZE,{children:(0,Y.jsx)(Am,{})})}),(0,Y.jsx)(d,{path:`/apps/:appName/*`,element:(0,Y.jsx)(ZE,{children:(0,Y.jsx)(ZT,{})})}),(0,Y.jsx)(d,{path:`/`,element:(0,Y.jsx)(oc,{children:(0,Y.jsx)($T,{})})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(_,{to:`/`,replace:!0})})]})})})]})}async function eD(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 tD=`auth-session-token`,nD=`auth-active-organization-id`;async function rD(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(tD)}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(tD),localStorage.removeItem(nD)}catch{}}function iD(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 aD(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 oD(e){let{objects:t}=re(),n=(0,J.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,J.useMemo)(()=>n?iD(n,0):null,[n]),fields:(0,J.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(aD):[],[n]),metadataObject:n}}function sD({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)(Cn,{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)(U,{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)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(ti,{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)(po,{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)(Ft,{className:`h-3 w-3`})})]})})]})}function cD({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=oD(t),{refresh:a}=re(),o=sf(),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)(sD,{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)(sD,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Y.jsx)(sD,{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)(sD,{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)(V,{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)(V,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var lD=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function uD({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=oD(t),{refresh:i}=re(),a=sf(),[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)(K,{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)(U,{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:lD.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)(U,{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)(U,{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)(B,{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)(V,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:lD.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)(Mn,{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)(Yt,{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)(K,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function dD({schema:e}){let t=e.objectName,{fields:n}=oD(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)(V,{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)(Zn,{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 fD(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)(lr,{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)(vn,{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)(to,{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 pD({schema:e}){let t=e.objectName,{object:n}=oD(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)(_r,{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 mD(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function hD(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=mD(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 gD(){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 _D(){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 vD(){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 yD(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 bD(...e){return Do(Eo(e))}function xD({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)(ut,{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:bD(`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 SD(...e){return Do(Eo(e))}function CD({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:SD(`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)(Yr,{className:`h-3 w-3`}):(0,Y.jsx)(Ya,{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)(wD,{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 wD({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 TD(...e){return Do(Eo(e))}function ED({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:TD(`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 DD=(0,J.createContext)(null);DD.displayName=`CollaborationContext`;function OD(){return(0,J.useContext)(DD)}function kD(...e){return Do(Eo(e))}function AD({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=jD,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=hD(t),d=u.current,f=(0,J.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=yD({initialZoom:e.zoom??1}),{zoom:m}=p,h=_D(),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=vD(),y=gD(),b=OD(),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),A=(0,J.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(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]),ee=(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]),M=(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]),ne=(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]),N=(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]),P=(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]),re=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ie=(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:A(e.position.x+n),y:A(e.position.y+r)}}:e)),x({type:`move`,elementId:t.id,data:{}}),O.current=null},[o,m,d,f,A,x]),ae=(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`}]:[],[_]),F=(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(),ne();return}if(n&&e.key===`v`&&!o){e.preventDefault(),N();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,te,i,o,u,ne,N,d]),(0,Y.jsxs)(`div`,{ref:k,tabIndex:0,className:kD(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Y.jsx)(`div`,{className:kD(`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:()=>j(e.type,e.label),className:`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left`,children:[(0,Y.jsx)(K,{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)(Ra,{className:kD(`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:kD(`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)(sn,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:kD(`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)(rn,{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:kD(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:h.count===0,onClick:ne,children:(0,Y.jsx)(He,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:kD(`p-1.5 rounded hover:bg-accent`,!v.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!v.hasContent,onClick:N,children:(0,Y.jsx)(Lt,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsx)(`button`,{className:kD(`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)(Mn,{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)(tt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:kD(`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)(lo,{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)(Qi,{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)(K,{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)(zr,{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)(je,{className:kD(`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:re,onDrop:ie,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=>P(t,e),className:kD(`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)(Ae,{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(),ee(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,Y.jsx)(Mn,{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)(ED,{items:F,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Y.jsx)(`div`,{className:kD(`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)(Vt,{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:kD(`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)(CD,{title:`Properties – ${_.label??_.type}`,fields:ae,onChange:M})}):_&&(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)(xD,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var jD=[{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 MD(e,t={}){return hD(e,t)}function ND(...e){return Do(Eo(e))}var PD=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function FD(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 ID({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=MD({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=gD(),m=_D(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=vD(),_=yD({minZoom:.25,maxZoom:3,zoomStep:.1}),v=OD(),[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,A]=(0,J.useState)(``),j=(0,J.useRef)(null),ee=(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]),M=(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]),ne=(0,J.useCallback)(()=>{if(i)return;let e=l.current;f({entities:FD(e.entities),relationships:e.relationships})},[i,l,f]),N=(0,J.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),P=(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]),re=(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]),ie=(0,J.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),ae=(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]),F=(0,J.useCallback)(()=>{w(null)},[]),oe=(0,J.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),se=(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]),ce=(0,J.useCallback)(()=>{O(null)},[]),le=(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]),ue=(0,J.useCallback)((e,t)=>{if(i||!u.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();j.current={entityId:t,offsetX:e.clientX-n.left,offsetY:e.clientY-n.top},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[i,u]),de=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),fe=(0,J.useCallback)(e=>{if(e.preventDefault(),!j.current)return;let t=e.currentTarget.getBoundingClientRect(),n=_.zoom,r=(e.clientX-t.left-_.panOffset.x)/n-j.current.offsetX,i=(e.clientY-t.top-_.panOffset.y)/n-j.current.offsetY,a=l.current;f({entities:a.entities.map(e=>e.id===j.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),j.current=null},[_.zoom,_.panOffset,l,f]),pe=h?u.find(e=>e.id===h):null,me=pe?[{name:`name`,label:`Name`,type:`text`,value:pe.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:pe.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:pe.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:pe.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:pe.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:pe.position.y,group:`Position`}]:[],I=(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(),N()):n&&e.key===`v`?(e.preventDefault(),P()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),M()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,N,P,M,m]);let he=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:ND(`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)(wt,{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)(sn,{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)(rn,{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)(eo,{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)(kr,{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)(et,{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:N,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:P,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Y.jsxs)(`button`,{onClick:ne,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,Y.jsx)(ai,{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)(mn,{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:ee,"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)(K,{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)(Yt,{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:de,onDrop:fe,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=>ue(t,e.id),className:ND(`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)(wt,{className:`h-3.5 w-3.5`}),D===e.id?(0,Y.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:se,onKeyDown:e=>{e.key===`Enter`&&se(),e.key===`Escape`&&ce()},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(),oe(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)(Mn,{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:ae,onKeyDown:e=>{e.key===`Enter`&&ae(),e.key===`Escape`&&F()},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:ND(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),ie(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(),le(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:PD.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(),re(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)(K,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Y.jsx)(ED,{items:he,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)(Ya,{className:`h-3 w-3`}):(0,Y.jsx)(Yr,{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)(CD,{title:pe?pe.label:`Properties`,fields:me,onChange:I})})]}),(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)(Ya,{className:`h-3 w-3`}):(0,Y.jsx)(Yr,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Y.jsx)(xD,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function LD(...e){return Do(Eo(e))}var RD=120,zD=50;function BD(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 VD({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=hD({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=gD(),g=_D(),_=vD(),v=yD({initialZoom:1}),y=OD(),[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),[A,j]=(0,J.useState)(null),[ee,te]=(0,J.useState)({x:0,y:0}),M=(0,J.useRef)(null),ne=(0,J.useRef)(c),N=(0,J.useRef)(l);ne.current=c,N.current=l,(0,J.useEffect)(()=>{ne.current?.(f),N.current?.(p)},[d.current]);let P=(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]),re=(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]),ie=(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]),ae=(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,_]),F=(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]),oe=(0,J.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),se=(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]),ce=(0,J.useCallback)(()=>{s||f.length===0||m(BD(f,p),p)},[f,p,s,m]),le=(0,J.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;j(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]),ue=(0,J.useCallback)(e=>{if(e.preventDefault(),s||!A)return;let t=e.currentTarget.getBoundingClientRect(),n=v.zoom,r=(e.clientX-t.left-v.panOffset.x)/n-ee.x,i=(e.clientY-t.top-v.panOffset.y)/n-ee.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);m(f.map(e=>e.id===A?{...e,position:{x:a,y:o}}:e),p),j(null)},[s,A,ee,f,p,v.zoom,v.panOffset,m]),de=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),fe=(0,J.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),pe=(0,J.useMemo)(()=>fe?[{name:`label`,label:`Name`,type:`text`,value:fe.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:fe.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:fe.description??``,group:`General`}]:[],[fe]),me=(0,J.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),I=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`}},he=(0,J.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:RD,height:zD,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,J.useEffect)(()=>{let e=M.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(),ae();return}if(n&&e.key===`v`){e.preventDefault(),F();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),ie()):b&&(e.preventDefault(),re(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,ae,F,re,ie]);let ge=(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:M,tabIndex:0,className:LD(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsx)(xD,{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)(ki,{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)(sn,{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)(rn,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:ae,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:F,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)(Lt,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:oe,className:LD(`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)(Mi,{className:`h-3 w-3`}),` Connect`]}),(0,Y.jsxs)(`button`,{onClick:ce,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)(mr,{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)(kr,{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)(eo,{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)(et,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:()=>P(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,Y.jsx)(Qn,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Y.jsxs)(`button`,{onClick:()=>P(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,Y.jsx)(aa,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Y.jsxs)(`button`,{onClick:()=>P(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,Y.jsx)(lt,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Y.jsxs)(`button`,{onClick:()=>P(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,Y.jsx)(aa,{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)(je,{className:`h-3 w-3`}):(0,Y.jsx)(wn,{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:ge,onDrop:ue,onDragOver:de,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+RD/2;let r=t.position.y+zD/2;n.position.x+RD/2;let i=n.position.y+zD/2,a=t.position.x+RD,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=>le(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{se(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Y.jsx)(`div`,{className:LD(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,I(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:LD(`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:zD/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),se(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:zD/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?se(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:RD/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),se(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:RD/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),se(e.id)}})]}),!s&&t&&!S&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),re(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)(Mn,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Y.jsx)(ED,{items:he,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)(CD,{title:fe?`Properties: ${fe.label}`:`Properties`,fields:pe,onChange:me})})]})]})}function HD(...e){return Do(Eo(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`},UD={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}},WD=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function GD({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=hD(a.length>0?a:WD),f=d.current,p=(0,J.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=_D(),h=(0,J.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=vD(),_=gD(),v=OD(),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=UD[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]),A=(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]),j=(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]),ee=(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]),M=(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]),ne=(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]),N=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),P=(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]),re=(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(),j();return}if(e.key===`Escape`){m.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&!c){e.preventDefault(),d.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&!c){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),te();return}if(n&&e.key===`v`&&!c){e.preventDefault(),M();return}if(n&&e.key===`a`){e.preventDefault();let t=f.flatMap(e=>e.elements).map(e=>e.id);m.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[m,j,c,d,te,M,f]),(0,Y.jsxs)(`div`,{ref:C,tabIndex:0,className:HD(`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)($a,{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:HD(`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)(sn,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:HD(`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)(rn,{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:HD(`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:HD(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:M,children:(0,Y.jsx)(Lt,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsx)(`button`,{className:HD(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.deleteSelected,"aria-label":$.deleteSelected,disabled:m.count===0,onClick:j,children:(0,Y.jsx)(Mn,{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)(je,{className:HD(`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:N,onDrop:e=>P(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)(xn,{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)(K,{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)(Pt,{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)(to,{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)(fr,{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=>ne(n,e,t),className:HD(`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(),A(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":$.deleteElement,children:(0,Y.jsx)(Mn,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Y.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:HD(`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)(CD,{title:`${$.properties} – ${O.type}`,fields:re,onChange:ee}):(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)(xD,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var KD={"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 qD(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 JD(){try{let e=z();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:qD(KD)}:{t:e.t}}catch{return{t:qD(KD)}}}function YD(...e){return Do(Eo(e))}var XD={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function ZD(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var QD=0;function $D(e){return QD+=1,`${e}_${Date.now()}_${QD}`}function eO({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:YD(`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:YD(`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:YD(`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)(ti,{className:`h-4 w-4`}):r+1}),(0,Y.jsx)(`span`,{className:YD(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function tO({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!ye(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:YD(`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:ri},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:mr},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:nn}].map(({value:t,labelKey:a,Icon:o})=>(0,Y.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:YD(`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 nO({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)(go,{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:YD(`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:YD(`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)(ti,{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 rO={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 iO({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)(di,{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)(Mi,{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)(Qi,{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`):Te(n.label)}),(0,Y.jsx)(`span`,{className:YD(`rounded-full px-2 py-0.5 text-[10px] font-medium`,rO[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)(Ia,{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)(Ya,{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)(Mn,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function aO({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)(Pt,{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)(Oa,{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)(Ba,{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 oO({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=JD(),l=gD(),[u,d]=(0,J.useState)(0),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(()=>({...XD,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&&ye(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:$D(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:ZD(e.objects)})),d(e=>e+1))},[u,v]),k=(0,J.useCallback)(()=>{_||d(e=>e-1)},[_]),A=(0,J.useCallback)(()=>{r?.(m)},[m,r]),j=(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]),ee=(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:ZD(e.objects)})),d(e))},[u,b]);return(0,Y.jsxs)(`div`,{className:YD(`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)(po,{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)(eO,{steps:g,currentIndex:u,onStepClick:te})}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Y.jsx)(tO,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Y.jsx)(nO,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Y.jsx)(iO,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Y.jsx)(aO,{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:j,disabled:o,className:`rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`common.cancel`)}),a&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:ee,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)(Xi,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:A,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(ti,{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)(Yr,{className:`h-4 w-4`})]})]})]})]})}function sO(...e){return Do(Eo(e))}var cO=0;function lO(e){return cO+=1,`${e}_${Date.now()}_${cO}`}var uO={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:wt},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:St},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:$a},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:to},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Mi},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:di},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:Qi},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:Gi}},dO=[{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 fO({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)(Te(e.label)??``),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(e.icon||``),C=uO[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(Te(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:sO(`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)(Ae,{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)(Ya,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Yr,{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)(Ft,{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(Te(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:sO(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(Te(e.label)??``),g(!0))},children:Te(e.label)}),(0,Y.jsx)(`span`,{className:sO(`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)(Ye,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(tt,{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)(K,{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)(Ia,{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)(Ya,{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)(Mn,{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)(fO,{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 pO({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)(mO,{item:e,depth:0},e.id))})]})}function mO({item:e,depth:t}){let n=uO[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:Te(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Y.jsx)(mO,{item:e,depth:t+1},e.id))]})}function hO({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=JD(),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:lO(r),type:r,label:r===`separator`?``:`New ${s(uO[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:lO(n),type:n,label:n===`separator`?``:`New ${s(uO[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:sO(`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:[dO.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=uO[e];return(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:sO(`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)(K,{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)(Qt,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Y.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:sO(`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)($t,{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)(fO,{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)(pO,{items:e,t:s})]})}function gO(...e){return Do(Eo(e))}var _O=[{type:`metric`,label:`KPI Metric`,Icon:Tt},{type:`bar`,label:`Bar Chart`,Icon:to},{type:`line`,label:`Line Chart`,Icon:Ar},{type:`pie`,label:`Pie Chart`,Icon:na},{type:`table`,label:`Table`,Icon:fr},{type:`grid`,label:`Grid`,Icon:ot}],vO=0;function yO(){return vO+=1,`widget_${Date.now()}_${vO}`}function bO({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=_O.find(e=>e.type===l)||_O[0];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:gO(`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)(Ae,{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)(Ia,{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)(Ya,{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)(Mn,{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 xO({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=JD();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)(po,{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:_O.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 SO({schema:e}){let{t}=JD(),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=_O.find(t=>t.type===(e.type||`metric`))||_O[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 CO({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=JD(),[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}=hD(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=yO(),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]),A=(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 j=(0,J.useCallback)(()=>{i&&i(v)},[v,i]),ee=(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:gO(`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)(xO,{widget:E,readOnly:n,onChange:A,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`),`:`]}),_O.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)(sn,{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)(rn,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:j,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,Y.jsx)(Qt,{className:`h-4 w-4`})}),!n&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:ee,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,Y.jsx)($t,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:gO(`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)(Ye,{className:`h-4 w-4`}):(0,Y.jsx)(tt,{className:`h-4 w-4`})})]})]}),d?(0,Y.jsx)(SO,{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)(bO,{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 wO(...e){return Do(Eo(e))}var TO=[{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`}],EO=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function DO({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=JD(),[c,l]=(0,J.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=hD(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:wO(`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:wO(`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)(sn,{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:wO(`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)(rn,{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)(Qt,{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:wO(`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)($t,{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)(Pt,{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)(Oa,{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:TO.map(e=>(0,Y.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:wO(`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)(Ba,{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)(xn,{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`)}),EO.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:wO(`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)(Sr,{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:wO(`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)(Zr,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview`,className:wO(`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:wO(`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:wO(`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:wO(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Y.jsxs)(`div`,{className:wO(`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:wO(`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:wO(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:wO(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:wO(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function OO(...e){return Do(Eo(e))}var kO=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],AO=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function jO({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=JD(),s=gD(),[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 fe({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:AO.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:kO.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:OO(`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)(wt,{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)(Go,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Y.jsx)(Ko,{schema:S}),(0,Y.jsx)(xD,{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 MO(...e){return Do(Eo(e))}var NO={text:{label:`Text`,Icon:xn},textarea:{label:`Text Area`,Icon:$a},number:{label:`Number`,Icon:cr},boolean:{label:`Checkbox`,Icon:er},date:{label:`Date`,Icon:Ur},datetime:{label:`Date/Time`,Icon:Ur},time:{label:`Time`,Icon:Ur},select:{label:`Picklist`,Icon:Ri},email:{label:`Email`,Icon:Et},phone:{label:`Phone`,Icon:ir},url:{label:`URL`,Icon:Ba},password:{label:`Password`,Icon:$e},currency:{label:`Currency`,Icon:cr},percent:{label:`Percent`,Icon:cr},lookup:{label:`Lookup`,Icon:Yt},formula:{label:`Formula`,Icon:Kn},autonumber:{label:`Auto Number`,Icon:cr},file:{label:`File`,Icon:$a},image:{label:`Image`,Icon:Pt},markdown:{label:`Markdown`,Icon:$a},html:{label:`Rich Text`,Icon:$a},color:{label:`Color`,Icon:Oa},code:{label:`Code`,Icon:Kn},location:{label:`Location`,Icon:Fn},address:{label:`Address`,Icon:Fn},rating:{label:`Rating`,Icon:ii},slider:{label:`Slider`,Icon:Ki}},PO={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`]},FO=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function IO({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=JD(),o=gD(),[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 fe({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)(()=>FO.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:PO[e].map(e=>({label:NO[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:MO(`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)(vt,{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)(Go,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Y.jsx)(qo,{schema:w}),(0,Y.jsx)(xD,{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 LO=`objectui-app-wizard-draft`;function RO(){let e=v(),{appName:t}=p(),{objects:n,refresh:r}=re(),i=le(),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(LO);if(e)return JSON.parse(e)}catch{}},[]),s=(0,J.useCallback)(async t=>{try{let n=xe(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(LO),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(LO,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)(oO,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function zO(){let e=v(),{appName:t,editAppName:n}=p(),{apps:r,objects:i,refresh:a}=re(),o=le(),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=xe(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)(oO,{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 BO(){let e=v(),{dashboardName:t}=p(),n=le(),{dashboards:r,refresh:i}=re(),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)(Jn,{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)(CO,{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 VO=t({AppCreationWizard:()=>oO,BrandingEditor:()=>DO,CreateAppPage:()=>RO,DashboardDesignPage:()=>BO,DashboardEditor:()=>CO,DataModelDesigner:()=>ID,EditAppPage:()=>zO,FieldDesigner:()=>IO,NavigationDesigner:()=>hO,ObjectManager:()=>jO,PageDesigner:()=>AD,ProcessDesigner:()=>VD,ReportDesigner:()=>GD});I.register(`page-designer`,AD,{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}]}),I.register(`data-model-designer`,ID,{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}]}),I.register(`process-designer`,VD,{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}]}),I.register(`report-designer`,GD,{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}]}),I.register(`app-creation-wizard`,oO,{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}]}),I.register(`navigation-designer`,hO,{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}]}),I.register(`dashboard-editor`,CO,{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}]}),I.register(`branding-editor`,DO,{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}]}),I.register(`object-manager`,jO,{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}]}),I.register(`field-designer`,IO,{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 HO(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 UO(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 WO=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=HO(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(UO)};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 GO({schema:e}){let t=e.objectName,{objects:n,refresh:r}=re(),i=sf(),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(aD):[],[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=WO.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)(B,{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)(Ai,{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)(IO,{objectName:t,fields:d,onFieldsChange:p})]})}function KO({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)(ke,{value:n,onValueChange:r,className:`w-full`,children:[(0,Y.jsxs)(Ua,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Y.jsxs)(ca,{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)(Dr,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Y.jsxs)(ca,{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)(vt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Y.jsxs)(ca,{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)(Yt,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Y.jsxs)(ca,{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)(_r,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Y.jsx)(ci,{value:`details`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(ce,{schema:i})})}),(0,Y.jsx)(ci,{value:`fields`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(ce,{schema:a})})}),(0,Y.jsx)(ci,{value:`relationships`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(ce,{schema:o}),(0,Y.jsx)(ce,{schema:s})]})}),(0,Y.jsx)(ci,{value:`data`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(ce,{schema:l}),(0,Y.jsx)(ce,{schema:c})]})})]})})}var qO={namespace:`console`,category:`system`};I.register(`object-detail-tabs`,KO,{...qO,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),I.register(`object-properties`,cD,{...qO,label:`Object Properties`,icon:`Settings2`}),I.register(`object-relationships`,uD,{...qO,label:`Object Relationships`,icon:`Link2`}),I.register(`object-keys`,dD,{...qO,label:`Object Keys`,icon:`KeyRound`}),I.register(`object-data-experience`,fD,{...qO,label:`Data Experience`,icon:`LayoutList`}),I.register(`object-data-preview`,pD,{...qO,label:`Data Preview`,icon:`Table`}),I.register(`object-field-designer`,GO,{...qO,label:`Field Designer`,icon:`Columns`});var JO=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-CWTG8Xo7.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),YO=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage--fqUTSur.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),XO=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BYCoo2T3.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function ZO({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Im({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ZO,{label:`API console`}),children:(0,Y.jsx)(JO,{...e})})}),Im({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ZO,{label:`flow runs`}),children:(0,Y.jsx)(YO,{...e})})}),Im({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(ZO,{label:`public forms`}),children:(0,Y.jsx)(XO,{...e})})});var QO=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-BWTzOuUR.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function $O({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Im({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)($O,{label:`profile`}),children:(0,Y.jsx)(QO,{...e})})});var ek=`/api/v1/auth`;$l(),I.registerLazy(`object-map`,()=>c(()=>import(`./plugin-map-Dogg70cr.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),I.registerLazy(`map`,()=>c(()=>import(`./plugin-map-Dogg70cr.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`])I.registerLazy(e,()=>c(()=>import(`./plugin-dashboard-T9rNXqHD.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});I.registerLazy(`chart`,()=>c(()=>import(`./plugin-charts-CP4h02tQ.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`])I.registerLazy(e,()=>c(()=>import(`./plugin-charts-CP4h02tQ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});I.registerLazy(`object-gantt`,()=>c(()=>import(`./plugin-gantt-QTyZ46KN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),I.registerLazy(`gantt`,()=>c(()=>import(`./plugin-gantt-QTyZ46KN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`markdown`,()=>c(()=>import(`./plugin-markdown-BR6MY8l8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),I.registerLazy(`object-timeline`,()=>c(()=>import(`./plugin-timeline-Dju0mfv_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),I.registerLazy(`timeline`,()=>c(()=>import(`./plugin-timeline-Dju0mfv_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`object-calendar`,()=>c(()=>import(`./plugin-calendar-C-9OPJzZ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`calendar`,()=>c(()=>import(`./plugin-calendar-C-9OPJzZ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`calendar-view`,()=>c(()=>import(`./plugin-calendar-C-9OPJzZ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`object-kanban`,()=>c(()=>import(`./plugin-kanban-B-o9RSK7.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),I.registerLazy(`kanban`,()=>c(()=>import(`./plugin-kanban-B-o9RSK7.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])I.registerLazy(e,()=>c(()=>import(`./plugin-kanban-B-o9RSK7.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});I.registerLazy(`report`,()=>c(()=>import(`./plugin-report-AhX1YoV8.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`])I.registerLazy(e,()=>c(()=>import(`./plugin-report-AhX1YoV8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});Vn();var tk=``.replace(/\/+$/,``);Promise.all([Dl(tk),rD(ek)]).finally(()=>{_s.createRoot(document.getElementById(`root`)).render((0,Y.jsx)(J.StrictMode,{children:(0,Y.jsx)(Wo,{pwa:{enabled:!0,name:kl(),shortName:Al()},children:(0,Y.jsx)(R,{loadLanguage:eD,children:(0,Y.jsx)($E,{})})})}))});export{bc as i,kf as n,Cc as r,Lm as t};
|