@objectstack/console 7.4.0 → 7.5.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-C2C3Ja_n.js → AiPendingActionsPage-lmvGLNua.js} +1 -1
- package/dist/assets/{ApiConsolePage-ePJcxhf9.js → ApiConsolePage-2Hfplikq.js} +1 -1
- package/dist/assets/{AppManagementPage-CFHAXcEw.js → AppManagementPage-CvdaGmZp.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-DuHpUtLO.js → ApprovalsInboxPage-DDI1tDfy.js} +1 -1
- package/dist/assets/{AuditLogPage-Dw6wpFTf.js → AuditLogPage-B_XhBMoJ.js} +1 -1
- package/dist/assets/{ComponentNavView-DyNUAEnY.js → ComponentNavView-DscbHf4h.js} +1 -1
- package/dist/assets/{ConsoleFloatingChatbot-vOXH4hva.js → ConsoleFloatingChatbot-CIW0GtvK.js} +1 -1
- package/dist/assets/{DeveloperHubPage-Di9VELMr.js → DeveloperHubPage-CJ7NZxLQ.js} +1 -1
- package/dist/assets/{FlowRunsPage-C2ElJEUw.js → FlowRunsPage-0KW8LdCn.js} +1 -1
- package/dist/assets/{ProfilePage-DbEzcgM3.js → ProfilePage-wEhY3kyx.js} +1 -1
- package/dist/assets/{PublicFormsPage-CFO_htk4.js → PublicFormsPage-BkfIcEml.js} +1 -1
- package/dist/assets/{SettingsHub-RgZdAo3g.js → SettingsHub-BLGHmF-y.js} +1 -1
- package/dist/assets/{SettingsView-C4bpsbjP.js → SettingsView-tuRcbYy6.js} +1 -1
- package/dist/assets/{SystemHubPage-DCtNkrqu.js → SystemHubPage-B-apkIco.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-DolMghKp.js → highlighted-body-OFNGDK62-DzZ5rNlx.js} +1 -1
- package/dist/assets/{index-D8443YMB.js → index-CiY4zPLP.js} +7 -7
- package/dist/assets/index-ljRQeZRW.css +2 -0
- package/dist/assets/mermaid-GHXKKRXX-CwDRCmSe.js +1 -0
- package/dist/assets/{plugin-calendar-CQDuOrA8.js → plugin-calendar-CHvFKG6D.js} +1 -1
- package/dist/assets/plugin-charts-BvH5iWMS.js +7 -0
- package/dist/assets/{plugin-chatbot-MXXPNrIm.js → plugin-chatbot-CeHz9iQm.js} +3 -3
- package/dist/assets/plugin-dashboard-CXLv53tc.js +3 -0
- package/dist/assets/{plugin-form-DGz9Ldoi.js → plugin-form-CoZn3nk3.js} +1 -1
- package/dist/assets/{plugin-gantt-Bv3kYo78.js → plugin-gantt-DY4QgxI_.js} +1 -1
- package/dist/assets/{plugin-grid-X6RP2gd8.js → plugin-grid-CNT3y-BZ.js} +1 -1
- package/dist/assets/{plugin-kanban-BhsP-1E9.js → plugin-kanban-DSD6E3zx.js} +1 -1
- package/dist/assets/{plugin-map-Bl9-aL25.js → plugin-map-dgG_mKQS.js} +1 -1
- package/dist/assets/{plugin-markdown-DSLEFWrT.js → plugin-markdown-CWpRZuHu.js} +1 -1
- package/dist/assets/{plugin-report-DcNaFUN2.js → plugin-report-BFZ-T3Th.js} +1 -1
- package/dist/assets/{plugin-timeline-Bb7f-Qd7.js → plugin-timeline-Dk3Nk3zI.js} +1 -1
- package/dist/assets/plugin-view-B8Wznem_.js +1 -0
- package/dist/assets/plugins-views-CBhDf8Cj.js +4 -0
- package/dist/assets/{src-AD-6EnzK.js → src-CwB7sUUJ.js} +1 -1
- package/dist/assets/{types-BYLUnF0C.js → types-B9HyZbLK.js} +1 -1
- package/dist/assets/ui-components-Dv0hQu4t.js +41 -0
- package/dist/assets/{ui-layout-C9W0Gcnt.js → ui-layout-fny5eaNl.js} +1 -1
- package/dist/assets/vendor-charts-BWpBMKWq.js +39 -0
- package/dist/index.html +3 -3
- package/package.json +1 -1
- package/dist/assets/index-C2SC5SiS.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-qaGVEVOV.js +0 -1
- package/dist/assets/plugin-charts-BDWqi8DX.js +0 -7
- package/dist/assets/plugin-dashboard-Do4xOja1.js +0 -3
- package/dist/assets/plugin-view-DoIbSHeI.js +0 -1
- package/dist/assets/plugins-views-BNDN6gD4.js +0 -4
- package/dist/assets/ui-components-D0tUqjB3.js +0 -41
- package/dist/assets/vendor-charts-Ba_-W-di.js +0 -36
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as r,a as i,c as a,d as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y,y as b}from"./vendor-react-CyVA1SE-.js";import{a as x,c as S,d as C,f as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as ee,u as te}from"./infrastructure-CFhpdDcd.js";import{N as M,c as ne,d as N,l as re}from"./vendor-objectstack-D6pAOWWu.js";import{C as ie,E as ae,F as oe,N as P,O as se,P as ce,R as F,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-Bsl5NTfe.js";import{n as Ee,r as De,t as Oe}from"./data-adapter-BI1S6gix.js";import{$ as ke,$a as Ae,$i as je,$n as Me,$o as Ne,$r as Pe,$t as Fe,Aa as Ie,Ai as Le,An as Re,Ao as ze,Ar as Be,As as Ve,At as He,Ba as Ue,Bi as We,Bn as Ge,Bo as Ke,Br as qe,Bs as Je,Bt as Ye,Ca as Xe,Co as Ze,Cr as Qe,Cs as $e,Da as et,Di as tt,Do as nt,Dr as rt,Ds as it,Dt as at,Ea as B,Ei as ot,Eo as st,Er as ct,Et as lt,F as ut,Fa as dt,Fn as ft,Fo as pt,Fr as mt,Fs as ht,Ft as gt,Ga as _t,Gi as vt,Gn as yt,Go as bt,Gr as xt,Gs as St,Gt as Ct,Ha as wt,Ho as Tt,Hr as Et,Hs as Dt,Ht as Ot,I as kt,Ia as At,Ii as jt,In as Mt,Io as Nt,Ir as Pt,It as Ft,Ja as It,Ji as Lt,Jn as Rt,Jr as zt,Ka as Bt,Ki as Vt,Kn as Ht,Ko as Ut,Kr as Wt,Kt as Gt,La as Kt,Li as qt,Ln as Jt,Lo as Yt,Lr as Xt,Ls as Zt,Lt as Qt,M as $t,Ma as en,Mi as tn,Mn as nn,Mo as rn,Mr as an,Ms as on,Mt as sn,N as cn,Na as ln,Nn as un,No as dn,Nr as fn,Ns as pn,Nt as mn,Oa as hn,Oi as gn,On as _n,Oo as vn,Or as yn,Ot as bn,P as xn,Pa as Sn,Pi as Cn,Pn as wn,Pr as Tn,Pt as En,Q as Dn,Qa as On,Qi as kn,Qn as V,Qr as An,Qt as jn,Ra as Mn,Ri as H,Rn as Nn,Ro as Pn,Rs as Fn,Rt as In,Sa as Ln,So as Rn,Sr as zn,Ss as Bn,St as Vn,T as Hn,Ta as Un,Ti as Wn,Tr as Gn,Ts as Kn,Tt as qn,Ua as Jn,Ui as Yn,Uo as Xn,Us as U,Ut as Zn,V as Qn,Vo as $n,Vr as er,Vs as tr,Vt as nr,Wi as rr,Wo as ir,X as ar,Xa as or,Xi as sr,Xn as cr,Xo as lr,Xr as ur,Ya as dr,Yi as fr,Yn as pr,Yo as mr,Yr as hr,Z as gr,Zi as _r,Zo as vr,Zr as yr,Zt as br,_ as xr,_a as Sr,_i as Cr,_o as wr,_r as Tr,_t as Er,aa as Dr,ai as Or,an as kr,ao as Ar,ar as jr,as as Mr,at as Nr,ba as Pr,bi as Fr,br as Ir,bs as Lr,bt as Rr,ca as zr,ci as Br,cn as Vr,co as Hr,cr as Ur,cs as Wr,ct as Gr,da as Kr,di as qr,do as Jr,dr as Yr,ds as Xr,dt as Zr,ea as Qr,ei as $r,en as W,eo as ei,er as ti,es as ni,et as ri,fa as ii,fi as ai,fo as oi,fr as si,fs as ci,ft as li,g as ui,ga as di,gi as fi,go as pi,gr as mi,gs as hi,gt as gi,h as _i,ha as vi,hi as yi,ho as bi,ht as xi,ia as Si,ii as Ci,in as G,io as wi,is as Ti,it as Ei,ja as Di,ji as Oi,jn as ki,jo as Ai,jr as ji,js as Mi,ka as Ni,ki as Pi,kn as Fi,ko as Ii,kr as Li,ks as Ri,kt as zi,la as Bi,li as Vi,ln as Hi,lo as Ui,lr as Wi,ls as Gi,lt as Ki,ma as qi,mi as Ji,mn as Yi,mr as K,ms as Xi,mt as Zi,na as Qi,no as $i,ns as ea,nt as ta,oa as na,oi as ra,on as ia,oo as aa,or as oa,os as sa,ot as ca,pa as la,pi as ua,po as da,ps as fa,pt as pa,qa as ma,qi as ha,qn as ga,qo as _a,qr as va,qt as ya,ri as ba,ro as xa,rs as Sa,rt as Ca,sa as wa,sn as Ta,so as Ea,sr as Da,ss as Oa,st as ka,ta as Aa,ti as ja,to as Ma,tr as Na,ts as Pa,tt as Fa,ua as Ia,ui as La,un as Ra,uo as za,ur as Ba,us as Va,v as Ha,va as Ua,vi as Wa,vo as Ga,vr as Ka,vs as qa,w as Ja,wa as Ya,wo as Xa,wr as Za,wt as Qa,x as $a,xa as eo,xi as to,xo as no,xr as ro,xs as io,xt as ao,ya as oo,yi as so,yo as co,yr as lo,yt as uo,z as fo,zi as po,zn as mo,zo as ho,zr as go,zs as _o,zt as vo}from"./ui-components-D0tUqjB3.js";import{a as yo,i as bo,o as q,r as xo}from"./vendor-ui-utils-BbOuugky.js";import{a as So,c as Co,i as wo,n as To,o as Eo,r as Do,s as Oo,t as ko}from"./RecentItemsProvider-VqVTd5Ra.js";import{n as Ao,r as jo,t as Mo}from"./ui-layout-C9W0Gcnt.js";import{a as No,n as Po,o as Fo,s as Io,t as Lo}from"./plugins-views-BNDN6gD4.js";import{i as Ro,r as zo}from"./plugin-grid-X6RP2gd8.js";import{n as Bo,r as Vo,t as Ho}from"./plugin-form-DGz9Ldoi.js";import{a as Uo,c as Wo,d as Go,f as Ko,i as qo,l as Jo,m as Yo,n as Xo,o as Zo,p as Qo,r as $o,s as es,t as ts,u as ns}from"./plugin-view-DoIbSHeI.js";import{i as rs,n as is,r as as}from"./plugin-dashboard-Do4xOja1.js";import{d as os,i as ss,l as cs,t as ls,u as us}from"./plugin-chatbot-MXXPNrIm.js";var J=e(b(),1),ds=e(r(),1),Y=g();function fs({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 ps=300*1e3,ms=[`app`,`view`],hs={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},gs=`objectui:metadata:`;function _s(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var vs=_s();function ys(...e){vs&&console.debug(`[MetadataProvider]`,...e)}function bs(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function xs(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Ss(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Cs(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function ws(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)Cs(e)&&r.add(e.object);for(let e of t){if(Cs(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 Ts(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Es(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(gs+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ds(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(gs+e,JSON.stringify(t))}catch{}}function Os({children:e,adapter:t,ttlMs:n=ps}){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=Ts(),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 ys(`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=bs(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)Ss(e)&&t.byName.set(e.name,e);return e===`app`&&Ds(e,i),ys(`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,ys(`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 ys(`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=xs(i);return a&&n.byName.set(t,a),ys(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),ys(`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),ys(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,ys(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1,t=Es(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Ss(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of ms)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(hs.objects),n=e(`view`);return n.length?ws(t,n):t},get dashboards(){return e(hs.dashboards)},get reports(){return e(hs.reports)},get pages(){return e(hs.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 ks=(0,J.createContext)(null);function As({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)(ks.Provider,{value:a,children:(0,Y.jsx)(oe,{scope:o,children:e})})}function js(){let e=(0,J.useContext)(ks);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new ge(e)}}return e}function Ms(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 Ns({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}=ce({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 Ps=(0,J.createContext)(void 0);function Fs({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)(Ps.Provider,{value:s,children:e})}function Is(){return(0,J.useContext)(Ps)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Ls(e){let{setRecordTitle:t}=Is();(0,J.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Rs=`objectui-favorites`,zs=`objectui-nav-pins`,Bs=20,Vs=20;function Hs(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Vs&&(r=!0)):(t++,t>Bs&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Vs&&(i.push(t),o++):a<Bs&&(i.push(t),a++);return i}function Us(e){try{let t=localStorage.getItem(So(Rs,e));return t?JSON.parse(t):[]}catch{return[]}}function Ws(e,t){try{localStorage.setItem(So(Rs,t),JSON.stringify(e))}catch{}}function Gs(e){let t;try{t=localStorage.getItem(zs)}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(zs)}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 Ks=(0,J.createContext)(null);function qs({children:e}){let{user:t}=w(),n=t?.id??null,r=Co(`favorites`),[i,a]=(0,J.useState)(()=>Us(n));(0,J.useEffect)(()=>{a(Us(n))},[n]),Oo(So(Rs,n),e=>{a(Array.isArray(e)?Hs(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=Hs((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Us(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=Hs([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Gs(f);h&&(f=Hs(m),p=!0),a(f),Ws(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,J.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Gs(e);if(!r)return e;let i=Hs(t);return Ws(i,n),i})},[r,n]);let s=(0,J.useMemo)(()=>wo(async e=>{r&&await r.save(e)},500),[r]);(0,J.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,J.useCallback)(e=>{Ws(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=Hs([{...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):Hs([{...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)(Ks.Provider,{value:h,children:e})}function Js(){return(0,J.useContext)(Ks)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Ys=(0,J.createContext)({theme:`system`,setTheme:()=>null});function Xs({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)(Ys.Provider,{...r,value:o,children:e})}var Zs=()=>{let e=(0,J.useContext)(Ys);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Qs(){return(0,Y.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function $s({children:e}){return(0,Y.jsx)(Xs,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Y.jsx)(Fs,{children:(0,Y.jsx)(Do,{children:(0,Y.jsx)(qs,{children:(0,Y.jsx)(ko,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Qs,{}),children:e})})})})})})}function ec({children:e}){return(0,Y.jsx)(fs,{children:(0,Y.jsx)(tc,{children:e})})}function tc({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)(Os,{adapter:t,children:[(0,Y.jsx)(nc,{}),e]},n)}):(0,Y.jsx)(Qs,{})}function nc(){let{user:e}=w(),t=le(),n=Eo();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 rc({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=w();return r?(0,Y.jsx)(Qs,{}):((n??[]).length>0||t)&&!t?(0,Y.jsx)(_,{to:`/organizations`,replace:!0}):(0,Y.jsx)(Y.Fragment,{children:e})}function ic(){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 ac=(0,J.lazy)(()=>c(()=>import(`./ConsoleFloatingChatbot-vOXH4hva.js`),__vite__mapDeps([0]),import.meta.url)),oc=()=>{c(()=>import(`./ConsoleFloatingChatbot-vOXH4hva.js`),__vite__mapDeps([0]),import.meta.url)};function sc(e){let[t,n]=(0,J.useState)(!1);return t?(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(ac,{...e,defaultOpen:!0})}):(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:oc,onFocus:oc,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 cc(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 lc=new Set(gr),uc=new Map;function dc(e){if(!e)return Ai;let t=uc.get(e);if(t)return t;let n=cc(e);if(!lc.has(n))return uc.set(e,Ai),Ai;let r=e=>J.createElement(ar,{name:n,fallback:Ai,...e});return r.displayName=`LucideIcon(${e})`,uc.set(e,r),r}var fc=20;function pc(e,t=``){let{href:n,external:r}=Ao(e,t);return r?n:!n||n===`#`?``:n}function mc(e){return`nav:${e}`}function hc(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Js(),a=(0,J.useCallback)((e,i,a,o)=>{let s=mc(e);i?(a&&t({id:s,label:a.label,href:pc(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<fc;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 gc(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 _c(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 vc(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 yc(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 bc(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var xc=`\0`,Sc=`[-\\u2013\\u2014|/·,:]`;function Cc(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===``?xc:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Sc}\\s*${xc}`,`g`),o=RegExp(`${xc}\\s*${Sc}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(xc,`g`),``).replace(/\s+/g,` `).trim(),i}function wc(e,t){if(e?.titleFormat){let n=Cc(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 Tc=`__all__`;function Ec(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Dc(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 Oc(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Ec(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1;break}}return!0}function kc(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=Dc(s),l=[],u=new Set;for(let e of c){if(!Oc(e,o))continue;let t=Ec(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=Ec(e,a);l.push({value:t,label:typeof n==`string`&&n?n:t})}l.sort((e,t)=>e.label.localeCompare(t.label)),n(l)}catch{}})(),()=>{e=!0}},[r,i,a,s]),t}function Ac(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===Tc?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)(jc,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function jc({def:e,value:t,onChange:n,t:r}){let i=kc(e),a=dc(e.icon),o=yc(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)(In,{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)(Ot,{placeholder:`Select ${o}…`})]})}),(0,Y.jsx)(vo,{children:i.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}function Mc(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 Nc({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=qn(),r=o(),{t:a}=z(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=St(),{context:d,currentAppName:f}=Is(),{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}=To(),{favorites:h,removeFavorite:g}=Js(),{apps:_,objects:v}=ie(),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}=Mc(x?.name||`home`),{togglePin:T,applyPins:E}=hc(),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}=Ac(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]),[re,ae]=J.useState(!1),{evaluator:oe}=js(),P=J.useCallback(e=>Ms(e,oe),[oe]),{can:se}=O(),ce=J.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return se(n,r)}),[se]),F=J.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),le=J.useCallback((e,t)=>e===`object`?F.size===0?!0:F.has(t):!0,[F]),ue=d===`app`&&x?`/apps/${x.name}`:``;return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(Zr,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Y.jsx)(Er,{className:`border-b p-1.5`,children:(0,Y.jsx)(uo,{children:(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(ma,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Y.jsx)(li,{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)(Zi,{className:`group-data-[state=collapsed]:hidden`,children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Si,{className:`h-3.5 w-3.5`}),a(`sidebar.scope`,{defaultValue:`范围`})]}),(0,Y.jsx)(xi,{children:te})]}),D.length>1&&(0,Y.jsxs)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:D.map(e=>{let t=dc(e.icon);return(0,Y.jsx)(Vn,{children:(0,Y.jsxs)(ao,{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)(Mo,{items:N,basePath:ue,evaluateVisibility:P,checkPermission:ce,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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ae(e=>!e),children:[(0,Y.jsx)(ea,{className:`h-3 w-3 transition-transform duration-150 ${re?`rotate-90`:``}`}),(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),re&&(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:m.slice(0,5).map(e=>(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Y.jsxs)(Vn,{children:[(0,Y.jsx)(ao,{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)(Rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)($r,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Zi,{children:(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:M.map(e=>{let t=dc(e.icon),n=r.pathname===e.url;return(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Y.jsxs)(Vn,{children:[(0,Y.jsx)(ao,{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)(Rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)($r,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Y.jsx)(pa,{className:`border-t p-1`,children:(0,Y.jsx)(Qa,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Pc(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 Fc=0;function Ic(){return Fc+=1,`conflict-${Date.now()}-${Fc}`}var Lc=0;function Rc(){return Lc+=1,`ver-${Date.now()}-${Lc}`}function zc(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:Rc(),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:Rc(),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:Rc(),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:Rc(),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:Ic()};o(e=>[...e,t])},[]),clearHistory:(0,J.useCallback)(()=>{i([]),o([])},[])}}var Bc={sm:24,md:32,lg:40},Vc={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Hc(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Uc({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=Bc[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`}}):Hc(e.userName),r&&J.createElement(`span`,{style:{...m,backgroundColor:Vc[e.status]}}))))}var Wc=J.createContext({});function Gc(){let e=J.useContext(Wc),[t,n]=J.useState([]);return J.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function Kc(e,t){let n=J.useContext(Wc),[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 qc(){let{theme:e,setTheme:t}=Zs(),{t:n}=z();return(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(ur,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Y.jsx)(Ia,{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)(ia,{align:`end`,children:[(0,Y.jsxs)(Vr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Y.jsx)(ur,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Vr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Y.jsx)(Ia,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Vr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Y.jsx)(Kr,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var Jc=[{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 Yc(){let{t:e,language:t,changeLanguage:n}=z();return(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(ei,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Y.jsx)(ia,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Jc.map(e=>(0,Y.jsxs)(Vr,{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 Xc={connected:{label:`Connected`,color:`text-green-500`,icon:vr},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:Za},error:{label:`Connection Error`,color:`text-destructive`,icon:Za}};function Zc({state:e,className:t}){let n=Xc[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:U(`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:U(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Qc(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 $c({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=z(),c=s(),l=f(),{currentAppName:u}=Is(),[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)(br,{open:d,onOpenChange:p,children:[(0,Y.jsx)(Fe,{asChild:!0,children:(0,Y.jsxs)(K,{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)(it,{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)(jn,{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)(Fa,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Y.jsxs)(ta,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(it,{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)(ta,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Ci,{className:`h-3.5 w-3.5`}),o(`sidebar.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)(ta,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Y.jsxs)(ri,{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:Qc(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)(ri,{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)(Ci,{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)(K,{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)(ri,{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:[Qc(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 el({activeAppName:e,onAppChange:t}){let{apps:n}=ie(),{t:r}=z(),{appLabel:i}=St(),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)(kr,{children:[(0,Y.jsx)(Yi,{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:yc(s.label,r)})}),(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Y.jsxs)(ia,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Y.jsx)(Hi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,Y.jsx)(Ra,{}),o.map(e=>{let n=dc(e.icon),a=i({name:e.name,label:yc(e.label,r)}),o=s.name===e.name;return(0,Y.jsxs)(Vr,{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)(Mr,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var tl=(0,J.createContext)(null);function nl({children:e}){let[t,n]=(0,J.useState)(null),r=(0,J.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Y.jsx)(tl.Provider,{value:r,children:e})}function rl(){return(0,J.useContext)(tl)?.value??null}function il(e){let t=(0,J.useContext)(tl),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 al(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),[]);il((0,J.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var ol={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function sl(e){ol={...ol,...e,features:{...ol.features,...e.features??{}},branding:{...ol.branding,...e.branding??{}}}}async function cl(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;sl({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):ol.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??ol.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??ol.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:ol.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():ol.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():ol.branding.productShortName}:ol.branding})}catch{}}function ll(){return ol}function ul(){return ol.branding?.productName||`ObjectOS`}function dl(){return ol.branding?.productShortName||ul()}function fl(){return ol.cloudUrl??``}function pl(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function ml(){return(0,Y.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var hl=[];function gl({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}=St(),{apps:M,dashboards:ne,pages:N,reports:re}=ie(),{currentAppName:ae,recordTitle:oe}=Is(),P=rl(),[se,ce]=(0,J.useState)(null),[F,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&&ce(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=F.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=F.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{}},[F,_e]),R=(0,J.useCallback)(async()=>{let e=F.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(()=>{})))},[F,_e]),ye=Gc(),be=a??(ye.length>0?ye:hl),xe=c??se??[],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||ae||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||pl(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||pl(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=(re||[]).find(t=>t.name===e)?.label||pl(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:pl(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=oe?.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)||pl(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:U(`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:ul(),children:(0,Y.jsx)(At,{className:`h-4 w-4`})}),d===`home`&&(0,Y.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:ul()}),d===`orgs`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ml,{}),(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)(Qa,{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)(ml,{})}),(0,Y.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(el,{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)(ml,{})}),(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)(ml,{}),e.siblings&&e.siblings.length>1?(0,Y.jsxs)(kr,{children:[(0,Y.jsxs)(Yi,{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)(Ti,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Y.jsxs)(ia,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Y.jsx)(Hi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Y.jsx)(Ra,{}),e.siblings.map(e=>(0,Y.jsx)(Vr,{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)}),P&&P.views.length>0?P.views.length>1?(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{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:P.triggerLabel??P.views.find(e=>e.id===P.activeViewId)?.label??Fe}),(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Y.jsx)(ia,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:P.views.map(e=>{let t=e.id===P.activeViewId;return(0,Y.jsxs)(Vr,{onSelect:()=>{t||P.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)(Un,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Y.jsx)(Mr,{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:P.triggerLabel??P.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)(Zc,{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)(Uc,{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)(Wa,{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)(K,{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)(Wa,{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)($c,{notifications:F,unreadCount:ge,pendingApprovalsCount:pe,activities:xe,onMarkAllRead:R,onMarkRead:ve}),(0,Y.jsx)(K,{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)($e,{className:`h-4 w-4`})})}),(0,Y.jsx)(K,{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)(_a,{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)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsx)(K,{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)(Na,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(ti,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:k(v)})]})})}),(0,Y.jsxs)(ia,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Y.jsx)(Hi,{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)(Na,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(ti,{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)(Ra,{}),(0,Y.jsxs)(Ta,{children:[Se&&(0,Y.jsxs)(Vr,{onClick:()=>g(`/organizations`),className:`cursor-pointer`,children:[(0,Y.jsx)(io,{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=dc(e.icon),n=te({name:e.name,label:yc(e.label,E)});return(0,Y.jsxs)(Vr,{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)(Ra,{}),(0,Y.jsx)(Hi,{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)(qc,{})]}),(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)(Yc,{})]}),b&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ra,{}),(0,Y.jsxs)(Vr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Y.jsx)(Ya,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var _l=768,vl=1024;function yl(){let{setOpen:e,isMobile:t}=qn();(0,J.useEffect)(()=>{function t(){let t=window.innerWidth;t>=_l&&t<vl&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}function bl({children:e}){return yl(),(0,Y.jsx)(Y.Fragment,{children:e})}function xl({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=yc(n?.label)||t,{isAiEnabled:c}=_e(),l=c||!1,{setContext:u,setCurrentAppName:d}=Is();return(0,J.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Y.jsx)(nl,{children:(0,Y.jsxs)(jo,{sidebar:(0,Y.jsx)(Nc,{activeAppName:t,onAppChange:r}),navbar:(0,Y.jsx)(gl,{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?`${yc(n.label)} — ${ul()}`:void 0}:void 0,children:[(0,Y.jsx)(bl,{children:e}),l&&(0,Y.jsx)(sc,{appLabel:s,appName:t,defaultAgent:n?.defaultAgent,objects:i,userId:o})]})})}function Sl({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:U(`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:U(`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 Cl({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}=Zs(),{evaluator:m}=js(),{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=wl(t?.navigation||[]).filter(e=>Ms(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:wc}),{recentItems:C}=To(),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)(_n,{open:a,onOpenChange:o,children:[(0,Y.jsx)(ki,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Y.jsxs)(un,{children:[(0,Y.jsx)(Fi,{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)(Re,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Y.jsxs)(nn,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Y.jsx)(Wa,{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)(Re,{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=dc(e.icon);return(0,Y.jsxs)(nn,{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)(Re,{heading:h(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=dc(e.icon);return(0,Y.jsxs)(nn,{value:`object ${yc(e.label,h)} ${e.objectName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Y.jsxs)(nn,{value:`dashboard ${yc(e.label,h)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(dt,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Y.jsxs)(nn,{value:`page ${yc(e.label,h)} ${e.pageName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(da,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Y.jsxs)(nn,{value:`report ${yc(e.label,h)} ${e.reportName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(ci,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wn,{}),(0,Y.jsx)(Re,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=dc(e.icon);return(0,Y.jsxs)(nn,{value:`app ${yc(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:yc(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)(wn,{}),(0,Y.jsxs)(Re,{heading:h(`console.commandPalette.preferences`),children:[(0,Y.jsxs)(nn,{value:`theme light`,onSelect:()=>y(()=>p(`light`)),children:[(0,Y.jsx)(ur,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Y.jsxs)(nn,{value:`theme dark`,onSelect:()=>y(()=>p(`dark`)),children:[(0,Y.jsx)(Ia,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Y.jsxs)(nn,{value:`theme system`,onSelect:()=>y(()=>p(`system`)),children:[(0,Y.jsx)(Kr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Y.jsx)(wn,{}),(0,Y.jsxs)(Re,{heading:h(`console.commandPalette.actions`),children:[(0,Y.jsxs)(nn,{value:`create new app application`,onSelect:()=>y(()=>u(`${g}/create-app`)),children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.createApp`)})]}),(0,Y.jsxs)(nn,{value:`search all results full page`,onSelect:()=>y(()=>u(`${g}/search`)),children:[(0,Y.jsx)(Wa,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})]})]})]})}function wl(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...wl(n.children)):t.push(n);return t}function Tl(){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)(ft,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Mt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:e(`console.shortcuts.title`)}),(0,Y.jsx)(Jt,{children:e(`console.shortcuts.description`)})]}),(0,Y.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Y.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function El(){return null}var Dl={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 Ol({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,J.useState)(0),o=(0,J.useMemo)(()=>[Dl.steps.connecting,Dl.steps.loadingConfig,Dl.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)(Ai,{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:ul()}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Dl.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)(Ne,{className:`h-5 w-5 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold`,children:Dl.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:Dl.error.checkServer})]}),n&&(0,Y.jsx)(K,{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`}),Dl.actions.retrying]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Le,{className:`h-4 w-4`}),Dl.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)($t,{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)(vr,{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 kl(e){let{theme:t=`system`}=Zs();return(0,Y.jsx)(yo,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,Y.jsx)(vr,{className:`h-4 w-4`}),info:(0,Y.jsx)(wt,{className:`h-4 w-4`}),warning:(0,Y.jsx)(Tn,{className:`h-4 w-4`}),error:(0,Y.jsx)(Dr,{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 Al=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function jl({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(...Al),e.offsetWidth,e.classList.add(...Al))},[n.pathname]),(0,Y.jsx)(`div`,{ref:r,className:[...Al,t??``].filter(Boolean).join(` `),children:e})}var Ml=null,Nl=null;function Pl(){return Nl||(Nl=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_SENTRY_DSN;if(!t)return!1;try{let n=await c(()=>import(`./vendor-sentry-DjMgMAaz.js`).then(e=>e.t),[],import.meta.url),r=Number(e.VITE_SENTRY_TRACES_SAMPLE_RATE??`0.1`);return n.init({dsn:t,environment:e.VITE_SENTRY_ENVIRONMENT||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:Number.isFinite(r)?r:.1,sendDefaultPii:e.VITE_SENTRY_SEND_DEFAULT_PII!==`false`,replaysSessionSampleRate:0,replaysOnErrorSampleRate:e.VITE_SENTRY_REPLAY===`true`?.1:0,integrations:[n.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=Il(e.data.url)),e}}),Ml=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Nl)}function Fl(e,t){if(Ml)try{Ml.captureException(e,t?{extra:t}:void 0)}catch{}}function Il(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 Ll({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)(ut,{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)(Tn,{className:`h-6 w-6 text-destructive`})}),(0,Y.jsx)(fo,{children:n(`console.errors.somethingWentWrong`)}),(0,Y.jsx)(kt,{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)(K,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Y.jsx)(Wn,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Y.jsx)(ma,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Rl=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),Fl(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)(Ll,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function zl({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)(Ti,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Y.jsx)(ea,{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)(Mr,{className:`h-3 w-3 text-green-600`}):(0,Y.jsx)(pt,{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 Bl(){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 Vl({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}=Ja(n===`create`?f:p,{mode:n,onUpdate:a});(0,J.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,J.useMemo)(()=>Zo(i),[i.fields]),C=(0,J.useMemo)(()=>ns(m.filter),[m.filter]),w=(0,J.useMemo)(()=>Go(m.sort),[m.sort]),T=(0,J.useMemo)(()=>ts({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`),Uo[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)(K,{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)(fi,{className:`h-3.5 w-3.5`})});return(0,Y.jsx)(Qn,{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 Hl(e){return[{type:`grid`,icon:Sn,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:ba,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Xi,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:_t,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:Ke,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Or,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:Pr,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:ci,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function Ul(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Wl={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:$o}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:qo},{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:qo},{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:qo},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Xo},{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=>Wo(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&es(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&es(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:$o},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function Gl({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=z(),s=(0,J.useMemo)(()=>Hl(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?Zo(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(Ul(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Wl[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=(Wl[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=Jo(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)(ft,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Mt,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:o(`console.objectView.createView`)}),(0,Y.jsx)(Jt,{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:U(`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:U(`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:U(`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)(Ne,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Y.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Y.jsx)(W,{id:`create-view-name-input`,"data-testid":`create-view-name-input`,autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(!0)},onKeyDown:e=>{e.key===`Enter`&&D&&O()},placeholder:o(`console.objectView.newView`),className:`h-9`}),T&&(0,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Y.jsxs)(Nn,{className:`mt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Y.jsx)(K,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var Kl={config:{icon:fi,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:Un,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:_o,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:ua,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 ql({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=Kl[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Y.jsx)(bn,{delayDuration:200,children:(0,Y.jsxs)(lt,{children:[(0,Y.jsx)(zi,{asChild:!0,children:(0,Y.jsxs)(V,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:U(`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)(at,{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 Jl({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)(He,{className:`h-7 w-56`}),(0,Y.jsx)(He,{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)(He,{className:`h-4 w-20`}),(0,Y.jsx)(He,{className:`h-8 w-24`}),(0,Y.jsx)(He,{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)(He,{className:`h-5 w-32`}),(0,Y.jsx)(He,{className:`h-5 w-5 rounded-full`})]}),(0,Y.jsx)(He,{className:`h-40 w-full`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(He,{className:`h-3 w-16`}),(0,Y.jsx)(He,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Yl({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)(He,{className:`h-8 w-8 rounded`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(He,{className:`h-6 w-48`}),(0,Y.jsx)(He,{className:`h-4 w-32`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(He,{className:`h-9 w-20`}),(0,Y.jsx)(He,{className:`h-9 w-20`})]})]}),(0,Y.jsx)(He,{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)(He,{className:`h-4 w-24`}),(0,Y.jsx)(He,{className:`h-9 w-full`})]},`field-${t}`))}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,Y.jsx)(He,{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)(He,{className:`h-8 w-8 rounded-full`}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(He,{className:`h-4 w-40`}),(0,Y.jsx)(He,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var Xl={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 Zl(e){let t=Xl[e?.managedBy??`platform`]??Xl.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 Ql=new Set([`record:discussion`,`record:chatter`]);function $l(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`&&Ql.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 eu({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Y.jsx)(jr,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e.options?.title||`Confirm Action`}),(0,Y.jsx)(Wi,{children:e.message})]}),(0,Y.jsxs)(Ba,{children:[(0,Y.jsx)(Da,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Y.jsx)(oa,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function tu({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)(ft,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:n(`actionDialog.title`)}),(0,Y.jsx)(Jt,{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)(yt,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,Y.jsxs)(G,{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)(G,{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)(In,{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)(Ot,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Y.jsx)(vo,{children:e.options.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Y.jsx)(Ha,{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)(Dn,{id:e.name,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):e.type===`number`?(0,Y.jsx)(W,{id:e.name,type:`number`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value===``?void 0:t.target.valueAsNumber),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):(0,Y.jsx)(W,{id:e.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(e.type)?e.type:`text`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder||(t?n(`actionDialog.lookupPlaceholder`,{label:e.label}):void 0),className:a[e.name]?`border-destructive`:``}),a[e.name]&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Y.jsx)(K,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var nu=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),ru=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)}})),iu=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}}})),au=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})),ou=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})),su=n((e=>{var t=ru().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}})),cu=n((e=>{var t=ru().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),lu=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}})),uu=n((e=>{var t=iu(),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}}})),du=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]]}})),fu=n((e=>{var t=du();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}})),pu=n(((e,t)=>{var n=fu();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})),mu=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),hu=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
|
|
2
|
+
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as r,a as i,c as a,d as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y,y as b}from"./vendor-react-CyVA1SE-.js";import{a as x,c as S,d as C,f as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as ee,u as te}from"./infrastructure-CFhpdDcd.js";import{N as M,c as ne,d as N,l as re}from"./vendor-objectstack-D6pAOWWu.js";import{C as ie,E as ae,F as oe,N as P,O as se,P as ce,R as F,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-Bsl5NTfe.js";import{n as Ee,r as De,t as Oe}from"./data-adapter-BI1S6gix.js";import{$ as ke,$a as Ae,$i as je,$n as Me,$o as Ne,$r as Pe,$t as Fe,Aa as Ie,Ai as Le,An as Re,Ao as ze,Ar as Be,As as Ve,At as He,Ba as Ue,Bi as We,Bn as Ge,Bo as Ke,Br as qe,Bs as Je,Bt as Ye,Ca as Xe,Co as Ze,Cr as Qe,Cs as $e,Da as et,Di as tt,Do as nt,Dr as rt,Ds as it,Dt as at,Ea as B,Ei as ot,Eo as st,Er as ct,Et as lt,F as ut,Fa as dt,Fn as ft,Fo as pt,Fr as mt,Fs as ht,Ft as gt,Ga as _t,Gi as vt,Gn as yt,Go as bt,Gr as xt,Gs as St,Gt as Ct,Ha as wt,Ho as Tt,Hr as Et,Hs as Dt,Ht as Ot,I as kt,Ia as At,Ii as jt,In as Mt,Io as Nt,Ir as Pt,It as Ft,Ja as It,Ji as Lt,Jn as Rt,Jr as zt,Ka as Bt,Ki as Vt,Kn as Ht,Ko as Ut,Kr as Wt,Kt as Gt,La as Kt,Li as qt,Ln as Jt,Lo as Yt,Lr as Xt,Ls as Zt,Lt as Qt,M as $t,Ma as en,Mi as tn,Mn as nn,Mo as rn,Mr as an,Ms as on,Mt as sn,N as cn,Na as ln,Nn as un,No as dn,Nr as fn,Ns as pn,Nt as mn,Oa as hn,Oi as gn,On as _n,Oo as vn,Or as yn,Ot as bn,P as xn,Pa as Sn,Pi as Cn,Pn as wn,Pr as Tn,Pt as En,Q as Dn,Qa as On,Qi as kn,Qn as V,Qr as An,Qt as jn,Ra as Mn,Ri as H,Rn as Nn,Ro as Pn,Rs as Fn,Rt as In,Sa as Ln,So as Rn,Sr as zn,Ss as Bn,St as Vn,T as Hn,Ta as Un,Ti as Wn,Tr as Gn,Ts as Kn,Tt as qn,Ua as Jn,Ui as Yn,Uo as Xn,Us as U,Ut as Zn,V as Qn,Vo as $n,Vr as er,Vs as tr,Vt as nr,Wi as rr,Wo as ir,X as ar,Xa as or,Xi as sr,Xn as cr,Xo as lr,Xr as ur,Ya as dr,Yi as fr,Yn as pr,Yo as mr,Yr as hr,Z as gr,Zi as _r,Zo as vr,Zr as yr,Zt as br,_ as xr,_a as Sr,_i as Cr,_o as wr,_r as Tr,_t as Er,aa as Dr,ai as Or,an as kr,ao as Ar,ar as jr,as as Mr,at as Nr,ba as Pr,bi as Fr,br as Ir,bs as Lr,bt as Rr,ca as zr,ci as Br,cn as Vr,co as Hr,cr as Ur,cs as Wr,ct as Gr,da as Kr,di as qr,do as Jr,dr as Yr,ds as Xr,dt as Zr,ea as Qr,ei as $r,en as W,eo as ei,er as ti,es as ni,et as ri,fa as ii,fi as ai,fo as oi,fr as si,fs as ci,ft as li,g as ui,ga as di,gi as fi,go as pi,gr as mi,gs as hi,gt as gi,h as _i,ha as vi,hi as yi,ho as bi,ht as xi,ia as Si,ii as Ci,in as G,io as wi,is as Ti,it as Ei,ja as Di,ji as Oi,jn as ki,jo as Ai,jr as ji,js as Mi,ka as Ni,ki as Pi,kn as Fi,ko as Ii,kr as Li,ks as Ri,kt as zi,la as Bi,li as Vi,ln as Hi,lo as Ui,lr as Wi,ls as Gi,lt as Ki,ma as qi,mi as Ji,mn as Yi,mr as K,ms as Xi,mt as Zi,na as Qi,no as $i,ns as ea,nt as ta,oa as na,oi as ra,on as ia,oo as aa,or as oa,os as sa,ot as ca,pa as la,pi as ua,po as da,ps as fa,pt as pa,qa as ma,qi as ha,qn as ga,qo as _a,qr as va,qt as ya,ri as ba,ro as xa,rs as Sa,rt as Ca,sa as wa,sn as Ta,so as Ea,sr as Da,ss as Oa,st as ka,ta as Aa,ti as ja,to as Ma,tr as Na,ts as Pa,tt as Fa,ua as Ia,ui as La,un as Ra,uo as za,ur as Ba,us as Va,v as Ha,va as Ua,vi as Wa,vo as Ga,vr as Ka,vs as qa,w as Ja,wa as Ya,wo as Xa,wr as Za,wt as Qa,x as $a,xa as eo,xi as to,xo as no,xr as ro,xs as io,xt as ao,ya as oo,yi as so,yo as co,yr as lo,yt as uo,z as fo,zi as po,zn as mo,zo as ho,zr as go,zs as _o,zt as vo}from"./ui-components-Dv0hQu4t.js";import{a as yo,i as bo,o as q,r as xo}from"./vendor-ui-utils-BbOuugky.js";import{a as So,c as Co,i as wo,n as To,o as Eo,r as Do,s as Oo,t as ko}from"./RecentItemsProvider-VqVTd5Ra.js";import{n as Ao,r as jo,t as Mo}from"./ui-layout-fny5eaNl.js";import{a as No,n as Po,o as Fo,s as Io,t as Lo}from"./plugins-views-CBhDf8Cj.js";import{i as Ro,r as zo}from"./plugin-grid-CNT3y-BZ.js";import{n as Bo,r as Vo,t as Ho}from"./plugin-form-CoZn3nk3.js";import{a as Uo,c as Wo,d as Go,f as Ko,i as qo,l as Jo,m as Yo,n as Xo,o as Zo,p as Qo,r as $o,s as es,t as ts,u as ns}from"./plugin-view-B8Wznem_.js";import{i as rs,n as is,r as as}from"./plugin-dashboard-CXLv53tc.js";import{d as os,i as ss,l as cs,t as ls,u as us}from"./plugin-chatbot-CeHz9iQm.js";var J=e(b(),1),ds=e(r(),1),Y=g();function fs({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 ps=300*1e3,ms=[`app`,`view`],hs={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},gs=`objectui:metadata:`;function _s(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var vs=_s();function ys(...e){vs&&console.debug(`[MetadataProvider]`,...e)}function bs(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function xs(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Ss(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Cs(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function ws(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)Cs(e)&&r.add(e.object);for(let e of t){if(Cs(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 Ts(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Es(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(gs+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ds(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(gs+e,JSON.stringify(t))}catch{}}function Os({children:e,adapter:t,ttlMs:n=ps}){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=Ts(),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 ys(`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=bs(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)Ss(e)&&t.byName.set(e.name,e);return e===`app`&&Ds(e,i),ys(`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,ys(`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 ys(`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=xs(i);return a&&n.byName.set(t,a),ys(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),ys(`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),ys(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,ys(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(null);(0,J.useEffect)(()=>{let e=!1,t=Es(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Ss(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of ms)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(hs.objects),n=e(`view`);return n.length?ws(t,n):t},get dashboards(){return e(hs.dashboards)},get reports(){return e(hs.reports)},get pages(){return e(hs.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 ks=(0,J.createContext)(null);function As({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)(ks.Provider,{value:a,children:(0,Y.jsx)(oe,{scope:o,children:e})})}function js(){let e=(0,J.useContext)(ks);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new ge(e)}}return e}function Ms(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 Ns({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}=ce({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 Ps=(0,J.createContext)(void 0);function Fs({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)(Ps.Provider,{value:s,children:e})}function Is(){return(0,J.useContext)(Ps)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Ls(e){let{setRecordTitle:t}=Is();(0,J.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Rs=`objectui-favorites`,zs=`objectui-nav-pins`,Bs=20,Vs=20;function Hs(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Vs&&(r=!0)):(t++,t>Bs&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Vs&&(i.push(t),o++):a<Bs&&(i.push(t),a++);return i}function Us(e){try{let t=localStorage.getItem(So(Rs,e));return t?JSON.parse(t):[]}catch{return[]}}function Ws(e,t){try{localStorage.setItem(So(Rs,t),JSON.stringify(e))}catch{}}function Gs(e){let t;try{t=localStorage.getItem(zs)}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(zs)}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 Ks=(0,J.createContext)(null);function qs({children:e}){let{user:t}=w(),n=t?.id??null,r=Co(`favorites`),[i,a]=(0,J.useState)(()=>Us(n));(0,J.useEffect)(()=>{a(Us(n))},[n]),Oo(So(Rs,n),e=>{a(Array.isArray(e)?Hs(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=Hs((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Us(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=Hs([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Gs(f);h&&(f=Hs(m),p=!0),a(f),Ws(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,J.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Gs(e);if(!r)return e;let i=Hs(t);return Ws(i,n),i})},[r,n]);let s=(0,J.useMemo)(()=>wo(async e=>{r&&await r.save(e)},500),[r]);(0,J.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,J.useCallback)(e=>{Ws(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=Hs([{...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):Hs([{...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)(Ks.Provider,{value:h,children:e})}function Js(){return(0,J.useContext)(Ks)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Ys=(0,J.createContext)({theme:`system`,setTheme:()=>null});function Xs({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)(Ys.Provider,{...r,value:o,children:e})}var Zs=()=>{let e=(0,J.useContext)(Ys);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Qs(){return(0,Y.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function $s({children:e}){return(0,Y.jsx)(Xs,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Y.jsx)(Fs,{children:(0,Y.jsx)(Do,{children:(0,Y.jsx)(qs,{children:(0,Y.jsx)(ko,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Qs,{}),children:e})})})})})})}function ec({children:e}){return(0,Y.jsx)(fs,{children:(0,Y.jsx)(tc,{children:e})})}function tc({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)(Os,{adapter:t,children:[(0,Y.jsx)(nc,{}),e]},n)}):(0,Y.jsx)(Qs,{})}function nc(){let{user:e}=w(),t=le(),n=Eo();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 rc({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=w();return r?(0,Y.jsx)(Qs,{}):((n??[]).length>0||t)&&!t?(0,Y.jsx)(_,{to:`/organizations`,replace:!0}):(0,Y.jsx)(Y.Fragment,{children:e})}function ic(){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 ac=(0,J.lazy)(()=>c(()=>import(`./ConsoleFloatingChatbot-CIW0GtvK.js`),__vite__mapDeps([0]),import.meta.url)),oc=()=>{c(()=>import(`./ConsoleFloatingChatbot-CIW0GtvK.js`),__vite__mapDeps([0]),import.meta.url)};function sc(e){let[t,n]=(0,J.useState)(!1);return t?(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(ac,{...e,defaultOpen:!0})}):(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:oc,onFocus:oc,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 cc(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 lc=new Set(gr),uc=new Map;function dc(e){if(!e)return Ai;let t=uc.get(e);if(t)return t;let n=cc(e);if(!lc.has(n))return uc.set(e,Ai),Ai;let r=e=>J.createElement(ar,{name:n,fallback:Ai,...e});return r.displayName=`LucideIcon(${e})`,uc.set(e,r),r}var fc=20;function pc(e,t=``){let{href:n,external:r}=Ao(e,t);return r?n:!n||n===`#`?``:n}function mc(e){return`nav:${e}`}function hc(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Js(),a=(0,J.useCallback)((e,i,a,o)=>{let s=mc(e);i?(a&&t({id:s,label:a.label,href:pc(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<fc;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 gc(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 _c(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 vc(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 yc(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 bc(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var xc=`\0`,Sc=`[-\\u2013\\u2014|/·,:]`;function Cc(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===``?xc:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Sc}\\s*${xc}`,`g`),o=RegExp(`${xc}\\s*${Sc}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(xc,`g`),``).replace(/\s+/g,` `).trim(),i}function wc(e,t){if(e?.titleFormat){let n=Cc(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 Tc=`__all__`;function Ec(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Dc(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 Oc(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Ec(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1;break}}return!0}function kc(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=Dc(s),l=[],u=new Set;for(let e of c){if(!Oc(e,o))continue;let t=Ec(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=Ec(e,a);l.push({value:t,label:typeof n==`string`&&n?n:t})}l.sort((e,t)=>e.label.localeCompare(t.label)),n(l)}catch{}})(),()=>{e=!0}},[r,i,a,s]),t}function Ac(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===Tc?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)(jc,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function jc({def:e,value:t,onChange:n,t:r}){let i=kc(e),a=dc(e.icon),o=yc(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)(In,{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)(Ot,{placeholder:`Select ${o}…`})]})}),(0,Y.jsx)(vo,{children:i.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}function Mc(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 Nc({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=qn(),r=o(),{t:a}=z(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=St(),{context:d,currentAppName:f}=Is(),{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}=To(),{favorites:h,removeFavorite:g}=Js(),{apps:_,objects:v}=ie(),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}=Mc(x?.name||`home`),{togglePin:T,applyPins:E}=hc(),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}=Ac(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]),[re,ae]=J.useState(!1),{evaluator:oe}=js(),P=J.useCallback(e=>Ms(e,oe),[oe]),{can:se}=O(),ce=J.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return se(n,r)}),[se]),F=J.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),le=J.useCallback((e,t)=>e===`object`?F.size===0?!0:F.has(t):!0,[F]),ue=d===`app`&&x?`/apps/${x.name}`:``;return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(Zr,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Y.jsx)(Er,{className:`border-b p-1.5`,children:(0,Y.jsx)(uo,{children:(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(ma,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Y.jsx)(li,{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)(Zi,{className:`group-data-[state=collapsed]:hidden`,children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Si,{className:`h-3.5 w-3.5`}),a(`sidebar.scope`,{defaultValue:`范围`})]}),(0,Y.jsx)(xi,{children:te})]}),D.length>1&&(0,Y.jsxs)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:D.map(e=>{let t=dc(e.icon);return(0,Y.jsx)(Vn,{children:(0,Y.jsxs)(ao,{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)(Mo,{items:N,basePath:ue,evaluateVisibility:P,checkPermission:ce,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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ae(e=>!e),children:[(0,Y.jsx)(ea,{className:`h-3 w-3 transition-transform duration-150 ${re?`rotate-90`:``}`}),(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),re&&(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:m.slice(0,5).map(e=>(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Y.jsxs)(Vn,{children:[(0,Y.jsx)(ao,{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)(Rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)($r,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Zi,{children:(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:M.map(e=>{let t=dc(e.icon),n=r.pathname===e.url;return(0,Y.jsx)(Vn,{children:(0,Y.jsx)(ao,{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)(Zi,{children:[(0,Y.jsxs)(gi,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Y.jsx)(xi,{children:(0,Y.jsx)(uo,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Y.jsxs)(Vn,{children:[(0,Y.jsx)(ao,{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)(Rr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Y.jsx)($r,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Y.jsx)(pa,{className:`border-t p-1`,children:(0,Y.jsx)(Qa,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Pc(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 Fc=0;function Ic(){return Fc+=1,`conflict-${Date.now()}-${Fc}`}var Lc=0;function Rc(){return Lc+=1,`ver-${Date.now()}-${Lc}`}function zc(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:Rc(),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:Rc(),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:Rc(),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:Rc(),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:Ic()};o(e=>[...e,t])},[]),clearHistory:(0,J.useCallback)(()=>{i([]),o([])},[])}}var Bc={sm:24,md:32,lg:40},Vc={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Hc(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Uc({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=Bc[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`}}):Hc(e.userName),r&&J.createElement(`span`,{style:{...m,backgroundColor:Vc[e.status]}}))))}var Wc=J.createContext({});function Gc(){let e=J.useContext(Wc),[t,n]=J.useState([]);return J.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function Kc(e,t){let n=J.useContext(Wc),[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 qc(){let{theme:e,setTheme:t}=Zs(),{t:n}=z();return(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(ur,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Y.jsx)(Ia,{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)(ia,{align:`end`,children:[(0,Y.jsxs)(Vr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Y.jsx)(ur,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Vr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Y.jsx)(Ia,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Y.jsxs)(Vr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Y.jsx)(Kr,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Y.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var Jc=[{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 Yc(){let{t:e,language:t,changeLanguage:n}=z();return(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Y.jsx)(ei,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Y.jsx)(ia,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Jc.map(e=>(0,Y.jsxs)(Vr,{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 Xc={connected:{label:`Connected`,color:`text-green-500`,icon:vr},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:Za},error:{label:`Connection Error`,color:`text-destructive`,icon:Za}};function Zc({state:e,className:t}){let n=Xc[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:U(`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:U(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function Qc(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 $c({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=z(),c=s(),l=f(),{currentAppName:u}=Is(),[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)(br,{open:d,onOpenChange:p,children:[(0,Y.jsx)(Fe,{asChild:!0,children:(0,Y.jsxs)(K,{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)(it,{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)(jn,{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)(Fa,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Y.jsxs)(ta,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(it,{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)(ta,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Ci,{className:`h-3.5 w-3.5`}),o(`sidebar.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)(ta,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Y.jsxs)(ri,{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:Qc(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)(ri,{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)(Ci,{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)(K,{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)(ri,{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:[Qc(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 el({activeAppName:e,onAppChange:t}){let{apps:n}=ie(),{t:r}=z(),{appLabel:i}=St(),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)(kr,{children:[(0,Y.jsx)(Yi,{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:yc(s.label,r)})}),(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Y.jsxs)(ia,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Y.jsx)(Hi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,Y.jsx)(Ra,{}),o.map(e=>{let n=dc(e.icon),a=i({name:e.name,label:yc(e.label,r)}),o=s.name===e.name;return(0,Y.jsxs)(Vr,{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)(Mr,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var tl=(0,J.createContext)(null);function nl({children:e}){let[t,n]=(0,J.useState)(null),r=(0,J.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Y.jsx)(tl.Provider,{value:r,children:e})}function rl(){return(0,J.useContext)(tl)?.value??null}function il(e){let t=(0,J.useContext)(tl),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 al(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),[]);il((0,J.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var ol={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function sl(e){ol={...ol,...e,features:{...ol.features,...e.features??{}},branding:{...ol.branding,...e.branding??{}}}}async function cl(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;sl({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):ol.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??ol.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??ol.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:ol.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():ol.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():ol.branding.productShortName}:ol.branding})}catch{}}function ll(){return ol}function ul(){return ol.branding?.productName||`ObjectOS`}function dl(){return ol.branding?.productShortName||ul()}function fl(){return ol.cloudUrl??``}function pl(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function ml(){return(0,Y.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var hl=[];function gl({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}=St(),{apps:M,dashboards:ne,pages:N,reports:re}=ie(),{currentAppName:ae,recordTitle:oe}=Is(),P=rl(),[se,ce]=(0,J.useState)(null),[F,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&&ce(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=F.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=F.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{}},[F,_e]),R=(0,J.useCallback)(async()=>{let e=F.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(()=>{})))},[F,_e]),ye=Gc(),be=a??(ye.length>0?ye:hl),xe=c??se??[],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||ae||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||pl(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||pl(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=(re||[]).find(t=>t.name===e)?.label||pl(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:pl(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=oe?.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)||pl(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:U(`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:ul(),children:(0,Y.jsx)(At,{className:`h-4 w-4`})}),d===`home`&&(0,Y.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:ul()}),d===`orgs`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ml,{}),(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)(Qa,{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)(ml,{})}),(0,Y.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Y.jsx)(el,{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)(ml,{})}),(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)(ml,{}),e.siblings&&e.siblings.length>1?(0,Y.jsxs)(kr,{children:[(0,Y.jsxs)(Yi,{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)(Ti,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Y.jsxs)(ia,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Y.jsx)(Hi,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Y.jsx)(Ra,{}),e.siblings.map(e=>(0,Y.jsx)(Vr,{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)}),P&&P.views.length>0?P.views.length>1?(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{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:P.triggerLabel??P.views.find(e=>e.id===P.activeViewId)?.label??Fe}),(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Y.jsx)(ia,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:P.views.map(e=>{let t=e.id===P.activeViewId;return(0,Y.jsxs)(Vr,{onSelect:()=>{t||P.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)(Un,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Y.jsx)(Mr,{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:P.triggerLabel??P.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)(Zc,{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)(Uc,{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)(Wa,{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)(K,{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)(Wa,{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)($c,{notifications:F,unreadCount:ge,pendingApprovalsCount:pe,activities:xe,onMarkAllRead:R,onMarkRead:ve}),(0,Y.jsx)(K,{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)($e,{className:`h-4 w-4`})})}),(0,Y.jsx)(K,{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)(_a,{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)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsx)(K,{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)(Na,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(ti,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:k(v)})]})})}),(0,Y.jsxs)(ia,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Y.jsx)(Hi,{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)(Na,{src:v?.image,alt:v?.name??`User`}),(0,Y.jsx)(ti,{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)(Ra,{}),(0,Y.jsxs)(Ta,{children:[Se&&(0,Y.jsxs)(Vr,{onClick:()=>g(`/organizations`),className:`cursor-pointer`,children:[(0,Y.jsx)(io,{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=dc(e.icon),n=te({name:e.name,label:yc(e.label,E)});return(0,Y.jsxs)(Vr,{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)(Ra,{}),(0,Y.jsx)(Hi,{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)(qc,{})]}),(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)(Yc,{})]}),b&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ra,{}),(0,Y.jsxs)(Vr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Y.jsx)(Ya,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var _l=768,vl=1024;function yl(){let{setOpen:e,isMobile:t}=qn();(0,J.useEffect)(()=>{function t(){let t=window.innerWidth;t>=_l&&t<vl&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}function bl({children:e}){return yl(),(0,Y.jsx)(Y.Fragment,{children:e})}function xl({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=yc(n?.label)||t,{isAiEnabled:c}=_e(),l=c||!1,{setContext:u,setCurrentAppName:d}=Is();return(0,J.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Y.jsx)(nl,{children:(0,Y.jsxs)(jo,{sidebar:(0,Y.jsx)(Nc,{activeAppName:t,onAppChange:r}),navbar:(0,Y.jsx)(gl,{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?`${yc(n.label)} — ${ul()}`:void 0}:void 0,children:[(0,Y.jsx)(bl,{children:e}),l&&(0,Y.jsx)(sc,{appLabel:s,appName:t,defaultAgent:n?.defaultAgent,objects:i,userId:o})]})})}function Sl({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:U(`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:U(`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 Cl({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}=Zs(),{evaluator:m}=js(),{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=wl(t?.navigation||[]).filter(e=>Ms(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:wc}),{recentItems:C}=To(),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)(_n,{open:a,onOpenChange:o,children:[(0,Y.jsx)(ki,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Y.jsxs)(un,{children:[(0,Y.jsx)(Fi,{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)(Re,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Y.jsxs)(nn,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Y.jsx)(Wa,{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)(Re,{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=dc(e.icon);return(0,Y.jsxs)(nn,{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)(Re,{heading:h(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=dc(e.icon);return(0,Y.jsxs)(nn,{value:`object ${yc(e.label,h)} ${e.objectName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Y.jsxs)(nn,{value:`dashboard ${yc(e.label,h)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(dt,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Y.jsxs)(nn,{value:`page ${yc(e.label,h)} ${e.pageName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(da,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Y.jsx)(Re,{heading:h(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Y.jsxs)(nn,{value:`report ${yc(e.label,h)} ${e.reportName}`,onSelect:()=>y(()=>u(Ao(e,g,v).href)),children:[(0,Y.jsx)(ci,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:yc(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wn,{}),(0,Y.jsx)(Re,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=dc(e.icon);return(0,Y.jsxs)(nn,{value:`app ${yc(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:yc(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)(wn,{}),(0,Y.jsxs)(Re,{heading:h(`console.commandPalette.preferences`),children:[(0,Y.jsxs)(nn,{value:`theme light`,onSelect:()=>y(()=>p(`light`)),children:[(0,Y.jsx)(ur,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Y.jsxs)(nn,{value:`theme dark`,onSelect:()=>y(()=>p(`dark`)),children:[(0,Y.jsx)(Ia,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Y.jsxs)(nn,{value:`theme system`,onSelect:()=>y(()=>p(`system`)),children:[(0,Y.jsx)(Kr,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Y.jsx)(wn,{}),(0,Y.jsxs)(Re,{heading:h(`console.commandPalette.actions`),children:[(0,Y.jsxs)(nn,{value:`create new app application`,onSelect:()=>y(()=>u(`${g}/create-app`)),children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.createApp`)})]}),(0,Y.jsxs)(nn,{value:`search all results full page`,onSelect:()=>y(()=>u(`${g}/search`)),children:[(0,Y.jsx)(Wa,{className:`mr-2 h-4 w-4`}),(0,Y.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})]})]})]})}function wl(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...wl(n.children)):t.push(n);return t}function Tl(){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)(ft,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Mt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:e(`console.shortcuts.title`)}),(0,Y.jsx)(Jt,{children:e(`console.shortcuts.description`)})]}),(0,Y.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Y.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function El(){return null}var Dl={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 Ol({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,J.useState)(0),o=(0,J.useMemo)(()=>[Dl.steps.connecting,Dl.steps.loadingConfig,Dl.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)(Ai,{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:ul()}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Dl.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)(Ne,{className:`h-5 w-5 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold`,children:Dl.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:Dl.error.checkServer})]}),n&&(0,Y.jsx)(K,{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`}),Dl.actions.retrying]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Le,{className:`h-4 w-4`}),Dl.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)($t,{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)(vr,{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 kl(e){let{theme:t=`system`}=Zs();return(0,Y.jsx)(yo,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,Y.jsx)(vr,{className:`h-4 w-4`}),info:(0,Y.jsx)(wt,{className:`h-4 w-4`}),warning:(0,Y.jsx)(Tn,{className:`h-4 w-4`}),error:(0,Y.jsx)(Dr,{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 Al=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function jl({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(...Al),e.offsetWidth,e.classList.add(...Al))},[n.pathname]),(0,Y.jsx)(`div`,{ref:r,className:[...Al,t??``].filter(Boolean).join(` `),children:e})}var Ml=null,Nl=null;function Pl(){return Nl||(Nl=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_SENTRY_DSN;if(!t)return!1;try{let n=await c(()=>import(`./vendor-sentry-DjMgMAaz.js`).then(e=>e.t),[],import.meta.url),r=Number(e.VITE_SENTRY_TRACES_SAMPLE_RATE??`0.1`);return n.init({dsn:t,environment:e.VITE_SENTRY_ENVIRONMENT||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:Number.isFinite(r)?r:.1,sendDefaultPii:e.VITE_SENTRY_SEND_DEFAULT_PII!==`false`,replaysSessionSampleRate:0,replaysOnErrorSampleRate:e.VITE_SENTRY_REPLAY===`true`?.1:0,integrations:[n.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=Il(e.data.url)),e}}),Ml=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Nl)}function Fl(e,t){if(Ml)try{Ml.captureException(e,t?{extra:t}:void 0)}catch{}}function Il(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 Ll({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)(ut,{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)(Tn,{className:`h-6 w-6 text-destructive`})}),(0,Y.jsx)(fo,{children:n(`console.errors.somethingWentWrong`)}),(0,Y.jsx)(kt,{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)(K,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Y.jsx)(Wn,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Y.jsx)(ma,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Rl=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),Fl(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)(Ll,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function zl({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)(Ti,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Y.jsx)(ea,{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)(Mr,{className:`h-3 w-3 text-green-600`}):(0,Y.jsx)(pt,{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 Bl(){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 Vl({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}=Ja(n===`create`?f:p,{mode:n,onUpdate:a});(0,J.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,J.useMemo)(()=>Zo(i),[i.fields]),C=(0,J.useMemo)(()=>ns(m.filter),[m.filter]),w=(0,J.useMemo)(()=>Go(m.sort),[m.sort]),T=(0,J.useMemo)(()=>ts({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`),Uo[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)(K,{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)(fi,{className:`h-3.5 w-3.5`})});return(0,Y.jsx)(Qn,{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 Hl(e){return[{type:`grid`,icon:Sn,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:ba,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Xi,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:_t,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:Ke,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Or,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:Pr,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:ci,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function Ul(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Wl={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:$o}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:qo},{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:qo},{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:qo},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Xo},{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=>Wo(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&es(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&es(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:$o},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function Gl({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=z(),s=(0,J.useMemo)(()=>Hl(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?Zo(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(Ul(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Wl[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=(Wl[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=Jo(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)(ft,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Mt,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:o(`console.objectView.createView`)}),(0,Y.jsx)(Jt,{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:U(`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:U(`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:U(`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)(Ne,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Y.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Y.jsx)(W,{id:`create-view-name-input`,"data-testid":`create-view-name-input`,autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(!0)},onKeyDown:e=>{e.key===`Enter`&&D&&O()},placeholder:o(`console.objectView.newView`),className:`h-9`}),T&&(0,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Y.jsxs)(Nn,{className:`mt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Y.jsx)(K,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var Kl={config:{icon:fi,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:Un,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:_o,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:ua,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 ql({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=Kl[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Y.jsx)(bn,{delayDuration:200,children:(0,Y.jsxs)(lt,{children:[(0,Y.jsx)(zi,{asChild:!0,children:(0,Y.jsxs)(V,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:U(`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)(at,{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 Jl({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)(He,{className:`h-7 w-56`}),(0,Y.jsx)(He,{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)(He,{className:`h-4 w-20`}),(0,Y.jsx)(He,{className:`h-8 w-24`}),(0,Y.jsx)(He,{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)(He,{className:`h-5 w-32`}),(0,Y.jsx)(He,{className:`h-5 w-5 rounded-full`})]}),(0,Y.jsx)(He,{className:`h-40 w-full`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(He,{className:`h-3 w-16`}),(0,Y.jsx)(He,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Yl({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)(He,{className:`h-8 w-8 rounded`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(He,{className:`h-6 w-48`}),(0,Y.jsx)(He,{className:`h-4 w-32`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(He,{className:`h-9 w-20`}),(0,Y.jsx)(He,{className:`h-9 w-20`})]})]}),(0,Y.jsx)(He,{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)(He,{className:`h-4 w-24`}),(0,Y.jsx)(He,{className:`h-9 w-full`})]},`field-${t}`))}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,Y.jsx)(He,{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)(He,{className:`h-8 w-8 rounded-full`}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(He,{className:`h-4 w-40`}),(0,Y.jsx)(He,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var Xl={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 Zl(e){let t=Xl[e?.managedBy??`platform`]??Xl.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 Ql=new Set([`record:discussion`,`record:chatter`]);function $l(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`&&Ql.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 eu({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Y.jsx)(jr,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e.options?.title||`Confirm Action`}),(0,Y.jsx)(Wi,{children:e.message})]}),(0,Y.jsxs)(Ba,{children:[(0,Y.jsx)(Da,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Y.jsx)(oa,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function tu({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)(ft,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:n(`actionDialog.title`)}),(0,Y.jsx)(Jt,{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)(yt,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,Y.jsxs)(G,{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)(G,{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)(In,{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)(Ot,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Y.jsx)(vo,{children:e.options.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Y.jsx)(Ha,{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)(Dn,{id:e.name,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):e.type===`number`?(0,Y.jsx)(W,{id:e.name,type:`number`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value===``?void 0:t.target.valueAsNumber),placeholder:e.placeholder,className:a[e.name]?`border-destructive`:``}):(0,Y.jsx)(W,{id:e.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(e.type)?e.type:`text`,value:r[e.name]??``,onChange:t=>u(e.name,t.target.value),placeholder:e.placeholder||(t?n(`actionDialog.lookupPlaceholder`,{label:e.label}):void 0),className:a[e.name]?`border-destructive`:``}),a[e.name]&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Y.jsx)(K,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var nu=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),ru=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)}})),iu=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}}})),au=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})),ou=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})),su=n((e=>{var t=ru().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}})),cu=n((e=>{var t=ru().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),lu=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}})),uu=n((e=>{var t=iu(),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}}})),du=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]]}})),fu=n((e=>{var t=du();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}})),pu=n(((e,t)=>{var n=fu();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})),mu=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),hu=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
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)}})),gu=n((e=>{var t=mu(),n=hu();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}}})),_u=n((e=>{var t=ru(),n=uu(),r=iu(),i=gu(),a=mu(),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}})),vu=n((e=>{var t=ru(),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}})),yu=n(((e,t)=>{var n=gu();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})),bu=n(((e,t)=>{var n=gu(),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})),xu=n(((e,t)=>{var n=gu();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})),Su=n(((e,t)=>{var n=gu(),r=ru();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
4
|
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),Cu=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)})),wu=n((e=>{var t=gu(),n=yu(),r=bu(),i=xu(),a=Su(),o=hu(),s=ru(),c=Cu();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
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()))}})),Tu=n((e=>{var t=ru(),n=iu(),r=au(),i=ou(),a=su(),o=cu(),s=lu(),c=uu(),l=pu(),u=_u(),d=vu(),f=gu(),p=wu();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(`
|
|
@@ -7,27 +7,27 @@ The chosen QR Code version cannot contain this amount of data.
|
|
|
7
7
|
Minimum version required to store current data is: `+c+`.
|
|
8
8
|
`);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),Eu=n((e=>{function t(e){if(typeof e==`number`&&(e=e.toString()),typeof e!=`string`)throw Error(`Color should be defined as hex string`);let t=e.slice().replace(`#`,``).split(``);if(t.length<3||t.length===5||t.length>8)throw Error(`Invalid hex color: `+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),t.length===6&&t.push(`F`,`F`);let n=parseInt(t.join(``),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:`#`+t.slice(0,6).join(``)}}e.getOptions=function(e){e||={},e.color||={};let n=e.margin===void 0||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||`#000000ff`),light:t(e.color.light||`#ffffffff`)},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale},e.getImageWidth=function(t,n){let r=e.getScale(t,n);return Math.floor((t+n.margin*2)*r)},e.qrToImageData=function(t,n,r){let i=n.modules.size,a=n.modules.data,o=e.getScale(i,r),s=Math.floor((i+r.margin*2)*o),c=r.margin*o,l=[r.color.light,r.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=(e*s+n)*4,d=r.color.light;if(e>=c&&n>=c&&e<s-c&&n<s-c){let t=Math.floor((e-c)/o),r=Math.floor((n-c)/o);d=l[+!!a[t*i+r]]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}})),Du=n((e=>{var t=Eu();function n(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||={},t.height=n,t.width=n,t.style.height=n+`px`,t.style.width=n+`px`}function r(){try{return document.createElement(`canvas`)}catch{throw Error(`You need to specify a canvas element`)}}e.render=function(e,i,a){let o=a,s=i;o===void 0&&(!i||!i.getContext)&&(o=i,i=void 0),i||(s=r()),o=t.getOptions(o);let c=t.getImageWidth(e.modules.size,o),l=s.getContext(`2d`),u=l.createImageData(c,c);return t.qrToImageData(u.data,e,o),n(l,s,c),l.putImageData(u,0,0),s},e.renderToDataURL=function(t,n,r){let i=r;i===void 0&&(!n||!n.getContext)&&(i=n,n=void 0),i||={};let a=e.render(t,n,i),o=i.type||`image/png`,s=i.rendererOpts||{};return a.toDataURL(o,s.quality)}})),Ou=n((e=>{var t=Eu();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
|
|
9
9
|
`;return typeof a==`function`&&a(null,p),p}})),ku=n((e=>{var t=nu(),n=Tu(),r=Du(),i=Ou();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 Au(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function ju({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)(ft,{open:e.open,onOpenChange:e=>{},children:(0,Y.jsxs)(Mt,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,Y.jsx)(Jt,{children:r.description}):null]}),(0,Y.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,Y.jsx)(Mu,{field:e,value:e.path===``?i:Au(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,Y.jsx)(Nn,{children:(0,Y.jsx)(K,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function Mu({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)(Fu,{value:t}):null,a===`code-list`?(0,Y.jsx)(Iu,{value:t}):null,a===`secret`?(0,Y.jsx)(Lu,{value:t}):null,a===`text`?(0,Y.jsx)(Ru,{value:t}):null,a===`json`?(0,Y.jsx)(zu,{value:t}):null]})}function Nu(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 Pu({value:e,label:t}){let{copy:n,copied:r}=Nu(e);return(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,Y.jsx)(Mr,{className:`w-4 h-4`}):(0,Y.jsx)(pt,{className:`w-4 h-4`}),t?(0,Y.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function Fu({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,ku.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)(Pu,{value:e})]})]})}function Iu({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)(Pu,{value:e})]},`${t}-${e}`))})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(Pu,{value:t,label:`Copy all`})})]})}function Lu({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)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,Y.jsx)(Rn,{className:`w-4 h-4`}):(0,Y.jsx)(no,{className:`w-4 h-4`})}),(0,Y.jsx)(Pu,{value:e})]})}function Ru({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)(Pu,{value:e})]})}function zu({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)(Pu,{value:t})})]})}function Bu(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function Vu({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(Bu(e.screen)))},[e]),!e||!a)return null;let h=(e,t)=>f(n=>({...n,[e]:t}));return(0,Y.jsx)(ft,{open:!0,onOpenChange:e=>{!e&&!p&&r()},children:(0,Y.jsxs)(Mt,{className:`sm:max-w-md`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:a.title||`Input`}),a.description&&(0,Y.jsx)(Jt,{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)(G,{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)(Hu,{field:e,value:d[e.name],onChange:t=>h(e.name,t)})]},e.name))}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:r,disabled:p,children:`Cancel`}),(0,Y.jsx)(K,{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(Bu(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 Hu({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)(In,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,Y.jsx)(nr,{id:r,children:(0,Y.jsx)(Ot,{placeholder:e.placeholder||`Select…`})}),(0,Y.jsx)(vo,{children:e.options.map((e,t)=>(0,Y.jsx)(Ye,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,Y.jsx)(yt,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,Y.jsx)(Dn,{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)(W,{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 Uu(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 Wu(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??Uu(a.options,i,e.field,t.fieldOptionLabel),c=e.label??t.fieldLabel(i,e.field,a.label??e.field),l=o===`lookup`||o===`reference`?{referenceTo:a.reference_to??a.reference,displayField:a.display_field??a.reference_field,idField:a.id_field,descriptionField:a.description_field,multiple:a.multiple,titleFormat:a.title_format,lookupColumns:a.lookup_columns,lookupFilters:a.lookup_filters,lookupPageSize:a.lookup_page_size,dependsOn:a.depends_on}:{};return{name:e.name??e.field,label:c,type:o,required:e.required??a.required??!1,options:s,placeholder:e.placeholder??a.placeholder,helpText:e.helpText??a.help??a.description,defaultValue:r??e.defaultValue??a.defaultValue,...l}}function Gu(e,t){return Array.isArray(e)?e.map(e=>Wu(e,t)):[]}function Ku(){return`${``.replace(/\/$/,``)}/api/v1`}async function qu(e,t){let n=await fetch(`${Ku()}${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 Ju(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 qu(`/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 qu(`/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 Yu=t({RecordDetailView:()=>nd}),Xu={id:`current-user`,name:`Demo User`},Zu=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Qu=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),$u=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],ed=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function td(e,t){if(ed.has(t?.type))return!0;let n=e.toLowerCase();return $u.some(e=>n===e||n.endsWith(`_${e}`))}function nd({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}=Bl(),{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}=St(),{isFavorite:k,toggleFavorite:A,refreshLabel:j}=Js(),{addRecentItem:ee}=To(),[te,M]=(0,J.useState)(!0),[ne,N]=(0,J.useState)([]),[re,ie]=(0,J.useState)([]),[oe,P]=(0,J.useState)(0),[se,ce]=(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);Ls(c?void 0:ge);let R=p,ye=Kc(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:Lo(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=wc(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:Gu(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&&P(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 ce({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&P(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Ke,R,d]),Je=(0,J.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{},r=null;if(e.opensInNewTab)try{r=window.open(`about:blank`,`_blank`,`noopener,noreferrer`)}catch{r=null}try{let i=e.objectName||d||`global`,a=await 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&&P(e=>e+1);let c=o?.data;if(c&&typeof c==`object`&&typeof c.redirectUrl==`string`){let e=c.redirectUrl;if(r)try{r.location.href=e}catch{try{r.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`,`noopener,noreferrer`)}catch{t=null}t||(window.location.href=e)}}else if(r)try{r.close()}catch{}return{success:!0,data:c,reload:s}}catch(e){if(r)try{r.close()}catch{}return{success:!1,error:e.message}}},[Ke,R,d]),Ye=Ju(d,R,h?.id),Xe=(0,J.useRef)(Ye);Xe.current=Ye;let Ze=(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 Xe.current.approve({comment:n.comment});else if(t===`reject_request`)await Xe.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return P(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Qe=(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||Qe.length===0)return;let t=!1;return Promise.all(Qe.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,Qe]);let $e=(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||!$e){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,$e]),(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))];ie(o.length>0?o:n)}catch{if(t)return;ie(n)}})(),()=>{t=!0}},[e,h?.id,h?.name,h?.email]);let et=(0,J.useMemo)(()=>h?{id:h.id,name:h.name,avatar:h.image}:Xu,[h?.id,h?.name,h?.image]);(0,J.useEffect)(()=>{if(!e||!d||!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(et.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,et]);let tt=(0,J.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:et.name,actorAvatarUrl:`avatar`in et?et.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(N(e=>[...e,n]),e){let r=`${d}:${R}`,i=Po(t,re);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:et.id,author_name:et.name,author_avatar_url:`avatar`in et?et.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[et,e,d,R,re]),nt=(0,J.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:et.name,actorAvatarUrl:`avatar`in et?et.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=Po(n,re);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:et.id,author_name:et.name,author_avatar_url:`avatar`in et?et.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[et,e,d,R,re]),rt=(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=et.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}))},[et.id,e]);(0,J.useEffect)(()=>{M(!0),queueMicrotask(()=>M(!1))},[d,p]);let it=(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=>!Zu.has(e)&&!Qu.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=>!td(e,L.fields[e])),r=e.filter(e=>td(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(Ye.available&&Ye.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=Qe.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=Zl(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,...$e&&{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,oe,u,g,e,v,y,t,$e,de,pe,Ye.available,Ye.canDecide,Ye.pendingRequest,Ye.latestRequest,c]);if(te)return(0,Y.jsx)(Yl,{});if(!L)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:v(`empty.objectNotFound`)}),(0,Y.jsx)(kt,{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)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:v(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Y.jsx)(kt,{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=$l(ke),a=!t&&!r,o=(()=>{let e=it.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=Zl(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(it.related)?it.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=it.history?{entries:it.history.entries??[],loading:!!it.history.loading,emptyText:it.history.emptyText}:void 0,h=Te?ke:Lo(L,{sections:it.sections,highlightFields:Array.isArray(it.highlightFields)?it.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)(Uc,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(ql,{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:tt,onAddReply:nt,onToggleReaction:rt,mentionSuggestions:re,children:(0,Y.jsx)(ae,{context:{record:Ae||{},objectName:d,user:et},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:Je,modal:Je,approval:Ze},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)(Sa,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:_.label})]}),(0,Y.jsx)(F,{schema:h}),a&&(0,Y.jsx)(`div`,{className:`mt-6`,children:(0,Y.jsx)(No,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:tt,onAddReply:nt,onToggleReaction:rt,mentionSuggestions:re})})]}),(0,Y.jsx)(zl,{open:m,sections:[{title:`Page Schema`,data:h}]})]})})})})}),(0,Y.jsx)(eu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(tu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(ju,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(Vu,{state:se,authFetch:Ke,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),P(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)(Uc,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(ql,{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)(ae,{context:{record:{},objectName:d,user:et},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:Je,modal:Je,approval:Ze},children:(0,Y.jsx)(Fo,{schema:it,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=wc(L,e);t&&t!==ge&&t!==`Untitled`&&_e(t)},onEdit:()=>{n({id:R})},discussionSlot:(0,Y.jsx)(No,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:tt,onAddReply:nt,onToggleReaction:rt})},oe)})}),(0,Y.jsx)(zl,{open:m,sections:[{title:`View Schema`,data:it}]})]}),(0,Y.jsx)(eu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(tu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(ju,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(Vu,{state:se,authFetch:Ke,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),P(e=>e+1)}})]})}function rd(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 id=(0,J.lazy)(()=>c(()=>import(`./plugin-charts-BDWqi8DX.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),ad=(0,J.lazy)(()=>c(()=>import(`./plugin-grid-X6RP2gd8.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),od={grid:zt,kanban:ba,calendar:Xi,gallery:Sn,timeline:Dt,gantt:Oa,map:eo,chart:ci},sd={id:`current-user`,name:`Demo User`};function cd(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 ld(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 ud(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 dd({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}=Bl(),{t:g}=z(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:S,actionSuccess:C,fieldLabel:T,fieldOptionLabel:E}=St(),{isFavorite:k,toggleFavorite:A}=Js(),[j,ee]=(0,J.useState)(!1),[te,M]=(0,J.useState)(`edit`),[ne,N]=(0,J.useState)(!1),[re,ie]=(0,J.useState)(!1),[oe,se]=(0,J.useState)(null),ce=(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=ce.current[t];a&&clearTimeout(a),ce.current[t]=setTimeout(()=>{let r=le.current[t]||{};delete le.current[t],delete ce.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),de=(0,J.useCallback)(t=>{if(se(t),R(e=>e+1),e?.updateViewConfig){let n=c,r=t.id;n&&r?e.updateViewConfig(n,r,t).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing objectName or viewId.`)}else console.warn(`[ViewConfigPanel] dataSource.updateViewConfig is not available. View config saved locally only.`)},[e,c]),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=ld(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)(ut,{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)(zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:g(`console.objectView.objectNotFound`)}),(0,Y.jsxs)(kt,{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)(()=>Zl(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(ud))}).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=oe&&oe.id===je?.id?{...je,...oe}:je,Ne=(0,J.useCallback)((e,t)=>{se(n=>({...n||{},id:je?.id,[e]:t}))},[je?.id]),Fe=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}`))},Ie=(0,J.useMemo)(()=>(Oe||[]).map(e=>{let t=od[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]);al({views:Ie,activeViewId:Ae??``,onChange:Fe,enabled:Ie.length>0&&!!Ae});let Le=(0,J.useCallback)(()=>{N(!0)},[]),Re=(0,J.useCallback)((e,t)=>{if(e===`settings`){let e=Oe.find(e=>e.type===t);e&&Fe(e.id),M(`edit`),ee(!0)}},[Oe,Fe]),ze=(0,J.useCallback)(e=>we.some(t=>(t.id||t._id)===e),[we]),Be=(0,J.useCallback)(async(t,n)=>{if(!ze(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,ze,g]),[Ve,He]=(0,J.useState)({open:!1,message:``}),[Ue,We]=(0,J.useState)({open:!1,params:[]}),[Ge,Ke]=(0,J.useState)({open:!1}),qe=(0,J.useCallback)((e,t)=>new Promise(n=>{Ke({open:!0,spec:e,data:t,resolve:n})}),[]),Je=(0,J.useCallback)((e,t)=>new Promise(n=>{He({open:!0,message:e,options:t,resolve:n})}),[]),Ye=(0,J.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;We({open:!0,params:Gu(e,{objectName:c||L?.name||``,objects:t||[],fieldLabel:T,fieldOptionLabel:E,row:i}),resolve:r})}),[c,L,t,T,E]),Xe=(0,J.useCallback)(async t=>{if(!e)return;if(!ze(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 Je(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,ze,Ae,Oe,u,i,g,Je]),Ze=(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=ld(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]),Qe=(0,J.useCallback)(async(t,n)=>{if(e){if(!ze(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,ze,g]),$e=(0,J.useCallback)(async t=>{if(e){if(!ze(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,ze,g]),et=(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]),tt=(0,J.useCallback)(e=>{if(!ze(e)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==Ae&&Fe(e),M(`edit`),ee(!0)},[Ae,Fe,ze,g]),nt=(0,J.useCallback)(()=>{N(!0)},[]),rt=I?{id:I.id,name:I.name,avatar:I.image}:sd,it=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),at=Ns({objectName:L.name,objectLabel:L.label,dataSource:e,onEdit:n,onRefresh:()=>R(e=>e+1),onConfirm:Je,onToast:it}),B=(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:{};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:n.recordId,params:n})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1)return{success:!1,error:a?.error||`Action "${t}" failed (HTTP ${i.status})`};let o=e.refreshAfter!==!1;return o&&R(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[ot,L.name]),{lastMessage:dt}=Pc({channel:`object:${L.name}`}),{hasConflicts:ft,resolveAllConflicts:pt}=zc(L.name?`user-${L.name}`:`current-user`);(0,J.useEffect)(()=>{dt&&(ft&&pt(`remote`),R(e=>e+1))},[dt,ft,pt]),(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 mt=(0,J.useMemo)(()=>Me?.navigation??L.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Me?.navigation,L.navigation]),ht=d.get(`recordId`),gt=(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()]),_t=(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,_]),vt=P({navigation:mt,objectName:L.name,onNavigate:_t}),yt=()=>{vt.close();let e=new URLSearchParams(d);e.delete(`recordId`),p(e)},bt=(0,J.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){vt.handleClick(e,t);return}if(vt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),p(e);return}}vt.handleClick(e,t)},[vt,d,p]),xt=(0,J.useCallback)(()=>{let e=vt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(yt(),_t(t))},[vt.selectedRecord,_t]);(0,J.useEffect)(()=>{ht&&!vt.isOpen?vt.open({id:ht}):!ht&&vt.isOpen&&vt.close()},[ht]);let Ct=(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||{};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)(id,{dataSource:t,schema:{type:`object-chart`,objectName:L.name,chartType:e.chartType,xAxisField:e.xAxisField,yAxisFields:e.yAxisFields,aggregation:e.aggregation,series:e.series,config:e.config,filter:e.filter}})},o)}return(0,Y.jsx)(Io,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=cd(s.filter??e.filter,rt.id);return gt.length?[...Array.isArray(t)?t:[],...gt]: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`)):[],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??rd(L?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=cd([...Array.isArray(s.filter)?s.filter:[],...gt],rt.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&&at.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&at.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)=>{bt(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,vt,at,ue,gt]),wt=(0,J.useMemo)(()=>Oe.map(e=>e.id===Ae&&oe&&oe.id===e.id?{...e,...oe}:e),[Oe,Ae,oe]),Tt=(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)(ae,{context:{objectName:L.name,user:rt,apiBase:``,activeOrganization:he?{id:he.id,slug:he.slug,name:he.name}:null},onConfirm:Je,onToast:it,onNavigate:B,onParamCollection:Ye,onResultDialog:qe,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)(Sl,{title:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:_(L)}),(0,Y.jsx)(ql,{managedBy:L?.managedBy})]}),description:L.description?v(L):void 0,icon:(0,Y.jsx)(dc(L?.icon),{className:`h-4 w-4`}),actions:(0,Y.jsxs)(Y.Fragment,{children:[c&&(0,Y.jsx)(K,{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)(Pe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)($r,{className:`h-4 w-4`})}),xe.create&&_e(L.name,`create`)&&(0,Y.jsxs)(K,{size:`sm`,onClick:at.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Y.jsx)(H,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),xe.import&&_e(L.name,`create`)&&(0,Y.jsxs)(K,{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)(ji,{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)(F,{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:at.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":g(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Y.jsx)(H,{className:`h-5 w-5`})}),Se&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(ad,{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)(Qo,{views:e,activeViewId:Ae,onViewChange:Fe,viewTypeIcons:od,config:{reorderable:!1,showAddButton:ge,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:ge?nt:void 0,onRenameView:ge?Be:void 0,onDeleteView:ge?Xe:void 0,onDuplicateView:ge?Ze:void 0,onPinView:ge?Qe:void 0,onSetDefaultView:ge?$e:void 0,onConfigView:ge?tt:void 0,onManageViews:ge?()=>ie(!0):void 0}),ge&&(0,Y.jsx)(Ko,{open:re,onOpenChange:ie,views:e,activeViewId:Ae,viewTypeIcons:od,onRename:Be,onDelete:Xe,onDuplicate:Ze,onSetDefault:$e,onSetPinned:Qe,onReorder:et,onAddView:nt,onConfigView:tt})]})})})(),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[vt.mode===`split`&&vt.isOpen?(0,Y.jsx)(cn,{...vt,setIsOpen:e=>{e||yt()},title:_(L),onExpand:xt,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)(Yo,{schema:Tt,dataSource:e,views:wt,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{bt(e,t)},renderListView:Ct,onCreateView:Le,onViewAction:Re})})}),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)(nd,{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)(Yo,{schema:Tt,dataSource:e,views:wt,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{bt(e,t)},renderListView:Ct,onCreateView:Le,onViewAction:Re})})})}),(0,Y.jsx)(zl,{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)(Vl,{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)(Gl,{open:ne&&ge,onOpenChange:N,existingLabels:Oe.map(e=>e.label).filter(Boolean),objectDef:L,onCreate:e=>fe(e)})]}),vt.mode!==`split`&&(0,Y.jsx)(cn,{...vt,setIsOpen:e=>{e||yt()},title:_(L),onExpand:xt,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)(nd,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}})]}),(0,Y.jsx)(eu,{state:Ve,onOpenChange:e=>{e||He({open:!1,message:``})}}),(0,Y.jsx)(tu,{state:Ue,onOpenChange:e=>{e||We({open:!1,params:[]})}}),(0,Y.jsx)(ju,{state:Ge,onAcknowledge:()=>{Ge.resolve?.(),Ke({open:!1})}}),(0,Y.jsx)(Vu,{state:ye,authFetch:ot,baseUrl:``,onClose:()=>be(null),onComplete:()=>{be(null),R(e=>e+1)}})]})}var fd=t({RecordFormPage:()=>pd});function pd({mode:e}){let{appName:t,objectName:n,recordId:r}=f(),a=s(),[o]=l(),c=le(),{objects:u,loading:d}=ie(),{t:p}=z(),{objectLabel:m}=St(),{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:Ms(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>Ms(e.visible,j)).map(([e])=>e):[],[b,j]);return d?(0,Y.jsx)(Yl,{}):b?(0,Y.jsx)(As,{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)(K,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":p(`common.back`,{defaultValue:`Back`}),children:(0,Y.jsx)(Zt,{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)(ql,{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)(Ho,{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)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:p(`empty.objectNotFound`)}),(0,Y.jsx)(kt,{children:p(`empty.objectNotFoundDescription`,{name:n})}),(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>a(x),children:[(0,Y.jsx)(Zt,{className:`mr-2 h-4 w-4`}),p(`empty.back`)]})})]})})}var md=t({DashboardView:()=>wd}),hd=[{type:`metric`,label:`KPI Metric`,Icon:mt},{type:`bar`,label:`Bar Chart`,Icon:ci},{type:`line`,label:`Line Chart`,Icon:Xr},{type:`pie`,label:`Pie Chart`,Icon:Wr},{type:`table`,label:`Table`,Icon:hr},{type:`pivot`,label:`Pivot`,Icon:Sn}],gd=0;function _d(){return gd+=1,`widget_${Date.now()}_${gd}`}function vd(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:_d()})}}function yd(e){let t=hd.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var bd=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function xd(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 Sd(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))bd.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 Cd(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 wd({dataSource:e}){let{dashboardName:t}=f(),{showDebug:n}=Bl(),r=le(),{t:i}=z(),{dashboardLabel:a,dashboardDescription:o}=St(),[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}=ie(),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(vd(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=_d(),n={id:t,title:yd(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)(()=>Cd(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),re=(0,J.useMemo)(()=>N?xd(N):{},[d,m]),ae=(0,J.useCallback)(e=>{if(!T||!d||!N)return;let t=Sd(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]),oe=(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=xd(r);i[e]=t;let a=Sd(i,r);return{...n,widgets:n.widgets.map(e=>e.id===d?{...e,...a}:e)}})},[d]),P=(0,J.useMemo)(()=>{if(S?.length)return S.map(e=>({value:e.name,label:e.label||e.name}))},[S]),se=(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]),ce=(0,J.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),F=T||w,ue=(0,J.useMemo)(()=>{if(!F||ce.size===0)return F;let e=F.widgets;if(!Array.isArray(e)||e.length===0)return F;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?ce.has(t):!0});return t.length===e.length?F:{...F,widgets:t}},[F,ce]);return s?(0,Y.jsx)(Jl,{}):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=yc((ue||w).title,i),t=yc(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:yc(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:hd.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)(H,{className:`h-3 w-3`}),(0,Y.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,Y.jsxs)(`button`,{type:`button`,onClick:O,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,Y.jsx)(vt,{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)(rs,{schema:ue,dataSource:e,designMode:l,selectedWidgetId:d,onWidgetClick:p,onWidgetsReorder:ee,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),N?(0,Y.jsx)(is,{open:l,onClose:k,config:re,onSave:ae,onFieldChange:oe,availableObjects:P,availableFields:se,headerExtra:(0,Y.jsx)(K,{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)(Xt,{className:`h-3.5 w-3.5`})})},d):(0,Y.jsx)(as,{open:l,onClose:k,config:te,onSave:M,onFieldChange:ne}),(0,Y.jsx)(zl,{open:n,sections:[{title:`Dashboard Configuration`,data:ue}]})]}),g&&g.schema?.objectName?(0,Y.jsx)(Bo,{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)(ft,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,Y.jsx)(Jt,{children:g.schema.description})]}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:()=>v({success:!1}),children:i(`actionDialog.cancel`)}),(0,Y.jsx)(K,{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)(ut,{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)(dt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:i(`empty.dashboardNotFound`)}),(0,Y.jsx)(kt,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Td=t({PageView:()=>Ed});function Ed(){let{t:e}=z(),{pageName:t}=f(),[n]=l(),{showDebug:r}=Bl(),{pages:i}=ie(),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)(ut,{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)(da,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:e(`empty.pageNotFound`)}),(0,Y.jsx)(kt,{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)(F,{schema:{...a,type:a.type||`page`,context:{...a.context,params:o}}})}),(0,Y.jsx)(zl,{open:r,sections:[{title:`Page Configuration`,data:a}]})]})}var Dd=t({ReportView:()=>Md}),Od=(0,J.lazy)(()=>c(()=>import(`./plugin-report-DcNaFUN2.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),kd=(0,J.lazy)(()=>c(()=>import(`./plugin-report-DcNaFUN2.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),Ad=(0,J.lazy)(()=>c(()=>import(`./plugin-report-DcNaFUN2.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),jd=[{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 Md({dataSource:e}){let{t}=z(),{reportName:n}=f(),{showDebug:r}=Bl(),i=le(),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(0),{reports:l,objects:u,loading:d,refresh:p}=ie(),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)??jd},[_,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)(ut,{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)(ci,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:t(`empty.reportNotFound`)}),(0,Y.jsx)(kt,{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,re=!!(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))),ae={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)(vt,{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:re?(0,Y.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Y.jsx)(kd,{schema:N,dataSource:e})}):(0,Y.jsx)(Od,{schema:ae})})})}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Ad,{open:a,onClose:D,config:O,onSave:k,onFieldChange:A,availableFields:w,getFieldsForObject:C})}),(0,Y.jsx)(zl,{open:r,sections:[{title:`Report Configuration`,data:N}]})]})]})}var Nd=t({SearchResultsPage:()=>Ld});function Pd(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Pd(n.children)):t.push(n);return t}var Fd={object:Ai,dashboard:dt,page:da,report:ci},Id={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 Ld(){let{t:e}=z(),{appName:t}=f(),[n,r]=l(),[a,o]=(0,J.useState)(n.get(`q`)||``),{apps:s}=ie(),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=Pd(u.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=Ao(e,d,t);return{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:n,type:e.type,description:e.description}}).filter(e=>e.href!==`#`)},[u,d,p?.id]),h=(0,J.useMemo)(()=>{if(!a.trim())return m;let e=a.toLowerCase();return m.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[m,a]),g=e=>{o(e),r(e?{q:e}:{})},_=(0,J.useMemo)(()=>{let e={};for(let t of h)(e[t.type]||=[]).push(t);return e},[h]);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(i,{to:d,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Y.jsx)(Zt,{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)(Wa,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{id:`search-results-input`,value:a,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.trim()?e(h.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:h.length,query:a}):e(`search.itemsAvailable`,{count:m.length})}),h.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,Y.jsx)(Wa,{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=Fd[t]||Ai,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=Fd[t.type]||Ai,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)(Ht,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Y.jsxs)(ga,{className:`flex items-center gap-3 p-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${Id[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 Rd(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 zd(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 Bd=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=Rd(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(zd)};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 Vd(){let e=le();return(0,J.useMemo)(()=>e?new Bd(e):null,[e])}var Hd=0;function Ud(e=`nav`){return`${e}_${Date.now()}_${++Hd}`}function Wd(e,t){return[...e,t]}function Gd(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:Gd(e.children,t,n)}:e)}function Kd(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:Kd(i.children,t,n,r)}:i})}function qd(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Jd(){let e=le(),{apps:t,refresh:n}=ie(),{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=Wd(a,{id:Ud(`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=Wd(a,{id:Ud(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Gd(i,`page`,t);if(qd(a,i))return;let c={...n,navigation:a};try{await o(e,c),q.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Gd(i,`dashboard`,t);if(qd(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=Kd(a,`page`,t,n);if(qd(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=Kd(a,`dashboard`,t,n);if(qd(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 Yd(){let{pages:e,dashboards:t,apps:n}=ie(),r=le(),i=(0,J.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=Jd(),l=(0,J.useRef)(null),u=(0,J.useRef)(null),d=(0,J.useRef)(0),f=(0,J.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,J.useEffect)(()=>{if(f.current)return;let r=new Set((e??[]).map(e=>e.name).filter(Boolean)),i=new Set((t??[]).map(e=>e.name).filter(Boolean)),m=l.current,h=u.current;if(m===null||h===null){l.current=r,u.current=i;return}let g=[...r].filter(e=>!m.has(e)),_=[...m].filter(e=>!r.has(e)),v=[...i].filter(e=>!h.has(e)),y=[...h].filter(e=>!i.has(e));if(g.length===0&&_.length===0&&v.length===0&&y.length===0){l.current=r,u.current=i;return}let b=++d.current;f.current=!0;let x=!1;return(async()=>{try{for(let e of n){if(x||d.current!==b)break;let t=p(e);if(t){for(let e of g){if(x)break;await a(t,e)}for(let e of _){if(x)break;await s(t,e)}for(let e of v){if(x)break;await o(t,e)}for(let e of y){if(x)break;await c(t,e)}}}}finally{d.current===b&&(l.current=r,u.current=i,f.current=!1)}})(),()=>{x=!0}},[e,t,n,a,o,s,c]),null}var Xd=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Zd(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Qd(e){try{return decodeURIComponent(e)}catch{return e}}function $d({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=To(),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}:${Qd(t)}`,label:Qd(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Xd.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:Zd(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Zd(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Zd(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var ef=`objectstack:ai-chat-conversation-id`;function tf(e,t){return t?`${ef}:${e}:${t}`:`${ef}:${e}`}function nf(e){try{return localStorage.getItem(e)??void 0}catch{return}}function rf(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function af(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 of(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=af(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function sf(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 cf(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 lf(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function uf(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=tf(t,n);return u(!0),(async()=>{try{if(i){let n=await sf(r,i);if(e)return;if(n){rf(s,n.id),o(n.id),c(of(n.messages)),f.current=t;return}rf(s,void 0)}else{let n=nf(s);if(n){let i=await sf(r,n);if(e)return;if(i){o(i.id),c(of(i.messages)),f.current=t;return}rf(s,void 0)}}let n=await cf(r);if(e)return;rf(s,n.id),o(n.id),c(of(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=tf(t,n);u(!0);try{a&&await lf(r,a),rf(e,void 0);let t=await cf(r);if(rf(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 df(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=ff(n.content);if(e)return e}}let t=e[e.length-1];return ff(t?.content)}function ff(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 pf(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:df(e.messages)}}function mf(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(pf).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 hf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Yu).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),gf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>md).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),_f=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Td).then(e=>({default:e.PageView})),void 0,import.meta.url)),vf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Dd).then(e=>({default:e.ReportView})),void 0,import.meta.url)),yf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Nd).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),bf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>fd).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),xf=(0,J.lazy)(()=>c(()=>import(`./ComponentNavView-DyNUAEnY.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Sf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),Cf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),wf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Tf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Ef=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Df=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ww).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),Of=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ND).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),kf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ND).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),Af=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ND).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),jf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>gp).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),Mf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sp).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),Nf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>wp).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function Pf({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}=ie(),{t:S}=z(),{objectLabel:C}=St(),[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}=ce();se({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=_c({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=vc({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 re=m.pathname.split(`/`).filter(Boolean)[2];(re===`view`||re===`record`||re===`page`||re===`dashboard`||re===`design`)&&(re=``);let ae=v.find(e=>e.name===re),oe=(0,J.useCallback)(()=>{let e=ae?C(ae):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,ae,C,S]),P=(0,J.useCallback)(()=>{ne({type:`dialog_cancel`})},[ne]);$d({pathname:m.pathname,appName:O?.name,objects:v});let F=e=>{let t=gc({objectDef:ae,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)(Ol,{});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)(ut,{children:[(0,Y.jsx)(fo,{children:S(`empty.noAppsConfigured`)}),(0,Y.jsx)(kt,{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)(K,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:S(`empty.createFirstApp`)}),(0,Y.jsx)(K,{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)(Ol,{}),children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Of,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(jf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Nf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Mf,{})}),t]})}):(0,Y.jsxs)(As,{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)(Yd,{}),(0,Y.jsxs)(xl,{activeAppName:O.name,activeApp:O,onAppChange:ue,objects:v,connectionState:n,userId:i?.id,children:[(0,Y.jsx)(Cl,{apps:g,activeApp:O,objects:v,onAppChange:ue,dataSource:c}),(0,Y.jsx)(Tl,{}),(0,Y.jsx)(El,{}),(0,Y.jsx)(Rl,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(jl,{className:`h-full`,children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/`,element:(()=>{let e=Rf(O,{currentUserId:i?.id??null});return e?(0,Y.jsx)(_,{to:e,replace:!0}):(0,Y.jsx)(Cf,{})})()}),(0,Y.jsxs)(d,{path:`metadata`,children:[(0,Y.jsx)(d,{index:!0,element:(0,Y.jsx)(Sf,{})}),(0,Y.jsx)(d,{path:`_diagnostics`,element:(0,Y.jsx)(Df,{})}),(0,Y.jsx)(d,{path:`:type`,element:(0,Y.jsx)(wf,{})}),(0,Y.jsx)(d,{path:`:type/new`,element:(0,Y.jsx)(Tf,{createMode:!0})}),(0,Y.jsx)(d,{path:`:type/:name`,element:(0,Y.jsx)(Tf,{})}),(0,Y.jsx)(d,{path:`:type/:name/history`,element:(0,Y.jsx)(Ef,{})})]}),(0,Y.jsx)(d,{path:`:objectName`,element:(0,Y.jsx)(dd,{dataSource:c,objects:v,onEdit:F,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/new`,element:(0,Y.jsx)(bf,{mode:`create`})}),(0,Y.jsx)(d,{path:`:objectName/view/:viewId`,element:(0,Y.jsx)(dd,{dataSource:c,objects:v,onEdit:F,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId`,element:(0,Y.jsx)(hf,{dataSource:c,objects:v,onEdit:F},te)}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId/edit`,element:(0,Y.jsx)(bf,{mode:`edit`})}),(0,Y.jsx)(d,{path:`dashboard/:dashboardName`,element:(0,Y.jsx)(gf,{dataSource:c})}),(0,Y.jsx)(d,{path:`report/:reportName`,element:(0,Y.jsx)(vf,{dataSource:c})}),(0,Y.jsx)(d,{path:`page/:pageName`,element:(0,Y.jsx)(_f,{})}),(0,Y.jsx)(d,{path:`component/:ns/:name/*`,element:(0,Y.jsx)(xf,{})}),(0,Y.jsx)(d,{path:`component/metadata/directory`,element:(0,Y.jsx)(Vf,{mode:`directory`})}),(0,Y.jsx)(d,{path:`component/metadata/resource/*`,element:(0,Y.jsx)(Vf,{mode:`resource`})}),(0,Y.jsx)(d,{path:`design/dashboard/:dashboardName`,element:(0,Y.jsx)(Af,{})}),(0,Y.jsx)(d,{path:`search`,element:(0,Y.jsx)(yf,{})}),(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Of,{})}),(0,Y.jsx)(d,{path:`edit-app/:editAppName`,element:(0,Y.jsx)(kf,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(jf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Nf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Mf,{})}),e,(0,Y.jsx)(d,{path:`:objectName/:maybeRecordId`,element:(0,Y.jsx)(Hf,{})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(Uf,{})})]})})})}),ae&&(0,Y.jsx)(Bo,{schema:{type:`object-form`,formType:`modal`,objectName:ae.name,mode:j?`edit`:`create`,recordId:j?.id,title:S(j?`form.editTitle`:`form.createTitle`,{object:C(ae)}),description:S(j?`form.editDescription`:`form.createDescription`,{object:C(ae)}),open:k,onOpenChange:A,layout:`vertical`,fields:ae.fields?Array.isArray(ae.fields)?ae.fields.filter(e=>typeof e==`string`?!0:Ms(e.visible,de)).map(e=>typeof e==`string`?e:e.name):Object.entries(ae.fields).filter(([e,t])=>Ms(t.visible,de)).map(([e])=>e):[],onSuccess:oe,onCancel:P,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 Ff(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=If(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Ff(n.children,t);if(e!==``)return e}}return``}function If(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Ao(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function Lf(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=Lf(n.children,t);if(e)return e}}}function Rf(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=If(Lf(r,n),t);if(e)return e}return Ff(r,t)}var zf=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function Bf(e){return!e||zf.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function Vf({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 Hf(){let{objectName:e,maybeRecordId:t}=f(),n=o();return e&&Bf(t)?(0,Y.jsx)(_,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Y.jsx)(Uf,{})}function Uf(){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)(ut,{children:[(0,Y.jsx)(fo,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Y.jsx)(kt,{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)(K,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Wf({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,J.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,Y.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,Y.jsx)(`span`,{className:i,children:s})})}function Gf(){let e=s(),{appName:t}=f(),{t:n}=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)(Ht,{children:(0,Y.jsxs)(ga,{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)(Un,{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)(K,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var Kf=`en`;function qf(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function Jf(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function Yf(e,t,n){if(!e)return;let r=qf(t),i=Jf([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),Kf]);for(let t of i){let r=e[t];if(!r)continue;let i=r[n];if(typeof i==`string`&&i.length>0)return i}}function Xf(e,t){let n=e[{displayName:`display_name`,description:`description`,readme:`readme`,tagline:`tagline`,screenshotCaptions:`screenshotCaptions`}[t]]??e[t];return typeof n==`string`&&n.length>0?n:void 0}function Zf(e,t){let n=t||Kf;return{displayName:Yf(e.translations??void 0,n,`displayName`)??Xf(e,`displayName`)??e.manifest_id,description:Yf(e.translations??void 0,n,`description`)??Xf(e,`description`),readme:Yf(e.translations??void 0,n,`readme`)??Xf(e,`readme`),tagline:Yf(e.translations??void 0,n,`tagline`)??Xf(e,`tagline`)}}var Qf=``.replace(/\/$/,``),$f=`${Qf}/api/v1/marketplace`;async function ep(e,t){let n=await fetch(`${$f}${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 tp(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 ep(`/packages${n?`?${n}`:``}`)}async function np(e){return ep(`/packages/${encodeURIComponent(e)}`)}async function rp(e){let t=fl()||Qf,n=await fetch(`${t}/api/v1/actions/sys_package/install_package`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({recordId:e.packageId,params:{environment_id:e.environmentId,seed_sample_data:!!e.seedSampleData}})}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??r?.error?.code??`HTTP_${n.status}`,t=r?.error??r?.message??n.statusText,i=Error(typeof t==`string`?t:`${e}`);throw i.code=e,i.status=n.status,i}return r?.data??r}async function ip(){let e=fl()||Qf,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 ap(){let e=fl()||Qf,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 op(e){return`${fl()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function sp(e,t){if(!e||!t)return null;let n=fl()||Qf,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 cp(e){if(!e)return{ok:!1,error:`installation id required`};let t=fl()||Qf;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 lp(e){if(!e)return{ok:!1,error:`installation id required`};let t=fl()||Qf;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 up(e){let t=await fetch(`${$f}/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 dp(){try{let e=await fetch(`${$f}/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 fp(e){let t=await fetch(`${$f}/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 pp(e,t){let n=await fetch(`${$f}/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 mp(e){return pp(e,`reseed`)}function hp(e){return pp(e,`purge`)}var gp=t({MarketplacePage:()=>vp});function _p(){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 vp(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=z(),a=_p(),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([tp({limit:100}),dp()]);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=Zf(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)(yr,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/installed`),children:[(0,Y.jsx)(yi,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>void S(),disabled:u,children:[(0,Y.jsx)(Oi,{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)(Wa,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{value:h,onChange:e=>g(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,Y.jsx)(K,{size:`sm`,variant:_===``?`default`:`outline`,onClick:()=>v(``),children:r(`marketplace.all`)}),w.map(e=>(0,Y.jsx)(K,{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)(Ne,{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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`pb-2`,children:[(0,Y.jsx)(He,{className:`h-10 w-10 rounded-lg mb-2`}),(0,Y.jsx)(He,{className:`h-5 w-3/4`}),(0,Y.jsx)(He,{className:`h-4 w-1/2 mt-1`})]}),(0,Y.jsx)(ga,{children:(0,Y.jsx)(He,{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=Zf(t,i);return(0,Y.jsxs)(Ht,{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)(pr,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Y.jsx)(Wf,{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)(cr,{className:`text-base truncate`,children:s.displayName}),(0,Y.jsx)(Rt,{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)(ga,{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)(vr,{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)(Si,{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)(Gf,{})}function yp(e){let t=e.replace(/\r\n/g,`
|
|
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)(Pu,{value:e})]},`${t}-${e}`))})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(Pu,{value:t,label:`Copy all`})})]})}function Lu({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)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,Y.jsx)(Rn,{className:`w-4 h-4`}):(0,Y.jsx)(no,{className:`w-4 h-4`})}),(0,Y.jsx)(Pu,{value:e})]})}function Ru({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)(Pu,{value:e})]})}function zu({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)(Pu,{value:t})})]})}function Bu(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function Vu({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(Bu(e.screen)))},[e]),!e||!a)return null;let h=(e,t)=>f(n=>({...n,[e]:t}));return(0,Y.jsx)(ft,{open:!0,onOpenChange:e=>{!e&&!p&&r()},children:(0,Y.jsxs)(Mt,{className:`sm:max-w-md`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:a.title||`Input`}),a.description&&(0,Y.jsx)(Jt,{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)(G,{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)(Hu,{field:e,value:d[e.name],onChange:t=>h(e.name,t)})]},e.name))}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:r,disabled:p,children:`Cancel`}),(0,Y.jsx)(K,{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(Bu(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 Hu({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)(In,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,Y.jsx)(nr,{id:r,children:(0,Y.jsx)(Ot,{placeholder:e.placeholder||`Select…`})}),(0,Y.jsx)(vo,{children:e.options.map((e,t)=>(0,Y.jsx)(Ye,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,Y.jsx)(yt,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,Y.jsx)(Dn,{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)(W,{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 Uu(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 Wu(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??Uu(a.options,i,e.field,t.fieldOptionLabel),c=e.label??t.fieldLabel(i,e.field,a.label??e.field),l=o===`lookup`||o===`reference`?{referenceTo:a.reference_to??a.reference,displayField:a.display_field??a.reference_field,idField:a.id_field,descriptionField:a.description_field,multiple:a.multiple,titleFormat:a.title_format,lookupColumns:a.lookup_columns,lookupFilters:a.lookup_filters,lookupPageSize:a.lookup_page_size,dependsOn:a.depends_on}:{};return{name:e.name??e.field,label:c,type:o,required:e.required??a.required??!1,options:s,placeholder:e.placeholder??a.placeholder,helpText:e.helpText??a.help??a.description,defaultValue:r??e.defaultValue??a.defaultValue,...l}}function Gu(e,t){return Array.isArray(e)?e.map(e=>Wu(e,t)):[]}function Ku(){return`${``.replace(/\/$/,``)}/api/v1`}async function qu(e,t){let n=await fetch(`${Ku()}${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 Ju(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 qu(`/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 qu(`/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 Yu=t({RecordDetailView:()=>nd}),Xu={id:`current-user`,name:`Demo User`},Zu=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Qu=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),$u=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],ed=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function td(e,t){if(ed.has(t?.type))return!0;let n=e.toLowerCase();return $u.some(e=>n===e||n.endsWith(`_${e}`))}function nd({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}=Bl(),{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}=St(),{isFavorite:k,toggleFavorite:A,refreshLabel:j}=Js(),{addRecentItem:ee}=To(),[te,M]=(0,J.useState)(!0),[ne,N]=(0,J.useState)([]),[re,ie]=(0,J.useState)([]),[oe,P]=(0,J.useState)(0),[se,ce]=(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);Ls(c?void 0:ge);let R=p,ye=Kc(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:Lo(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=wc(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:Gu(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&&P(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 ce({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&P(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Ke,R,d]),Je=(0,J.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{},r=null;if(e.opensInNewTab)try{r=window.open(`about:blank`,`_blank`,`noopener,noreferrer`)}catch{r=null}try{let i=e.objectName||d||`global`,a=await 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&&P(e=>e+1);let c=o?.data;if(c&&typeof c==`object`&&typeof c.redirectUrl==`string`){let e=c.redirectUrl;if(r)try{r.location.href=e}catch{try{r.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`,`noopener,noreferrer`)}catch{t=null}t||(window.location.href=e)}}else if(r)try{r.close()}catch{}return{success:!0,data:c,reload:s}}catch(e){if(r)try{r.close()}catch{}return{success:!1,error:e.message}}},[Ke,R,d]),Ye=Ju(d,R,h?.id),Xe=(0,J.useRef)(Ye);Xe.current=Ye;let Ze=(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 Xe.current.approve({comment:n.comment});else if(t===`reject_request`)await Xe.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return P(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Qe=(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||Qe.length===0)return;let t=!1;return Promise.all(Qe.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,Qe]);let $e=(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||!$e){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,$e]),(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))];ie(o.length>0?o:n)}catch{if(t)return;ie(n)}})(),()=>{t=!0}},[e,h?.id,h?.name,h?.email]);let et=(0,J.useMemo)(()=>h?{id:h.id,name:h.name,avatar:h.image}:Xu,[h?.id,h?.name,h?.image]);(0,J.useEffect)(()=>{if(!e||!d||!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(et.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,et]);let tt=(0,J.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:et.name,actorAvatarUrl:`avatar`in et?et.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(N(e=>[...e,n]),e){let r=`${d}:${R}`,i=Po(t,re);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:et.id,author_name:et.name,author_avatar_url:`avatar`in et?et.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[et,e,d,R,re]),nt=(0,J.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:et.name,actorAvatarUrl:`avatar`in et?et.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=Po(n,re);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:et.id,author_name:et.name,author_avatar_url:`avatar`in et?et.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[et,e,d,R,re]),rt=(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=et.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}))},[et.id,e]);(0,J.useEffect)(()=>{M(!0),queueMicrotask(()=>M(!1))},[d,p]);let it=(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=>!Zu.has(e)&&!Qu.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=>!td(e,L.fields[e])),r=e.filter(e=>td(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(Ye.available&&Ye.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=Qe.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=Zl(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,...$e&&{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,oe,u,g,e,v,y,t,$e,de,pe,Ye.available,Ye.canDecide,Ye.pendingRequest,Ye.latestRequest,c]);if(te)return(0,Y.jsx)(Yl,{});if(!L)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Y.jsxs)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:v(`empty.objectNotFound`)}),(0,Y.jsx)(kt,{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)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:v(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Y.jsx)(kt,{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=$l(ke),a=!t&&!r,o=(()=>{let e=it.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=Zl(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(it.related)?it.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=it.history?{entries:it.history.entries??[],loading:!!it.history.loading,emptyText:it.history.emptyText}:void 0,h=Te?ke:Lo(L,{sections:it.sections,highlightFields:Array.isArray(it.highlightFields)?it.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)(Uc,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(ql,{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:tt,onAddReply:nt,onToggleReaction:rt,mentionSuggestions:re,children:(0,Y.jsx)(ae,{context:{record:Ae||{},objectName:d,user:et},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:Je,modal:Je,approval:Ze},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)(Sa,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:_.label})]}),(0,Y.jsx)(F,{schema:h}),a&&(0,Y.jsx)(`div`,{className:`mt-6`,children:(0,Y.jsx)(No,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:tt,onAddReply:nt,onToggleReaction:rt,mentionSuggestions:re})})]}),(0,Y.jsx)(zl,{open:m,sections:[{title:`Page Schema`,data:h}]})]})})})})}),(0,Y.jsx)(eu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(tu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(ju,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(Vu,{state:se,authFetch:Ke,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),P(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)(Uc,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Y.jsx)(ql,{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)(ae,{context:{record:{},objectName:d,user:et},onConfirm:Ve,onToast:Ue,onNavigate:We,onParamCollection:He,onResultDialog:Be,handlers:{api:Ge,flow:qe,script:Je,modal:Je,approval:Ze},children:(0,Y.jsx)(Fo,{schema:it,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=wc(L,e);t&&t!==ge&&t!==`Untitled`&&_e(t)},onEdit:()=>{n({id:R})},discussionSlot:(0,Y.jsx)(No,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:tt,onAddReply:nt,onToggleReaction:rt})},oe)})}),(0,Y.jsx)(zl,{open:m,sections:[{title:`View Schema`,data:it}]})]}),(0,Y.jsx)(eu,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Y.jsx)(tu,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Y.jsx)(ju,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Y.jsx)(Vu,{state:se,authFetch:Ke,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),P(e=>e+1)}})]})}function rd(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 id=(0,J.lazy)(()=>c(()=>import(`./plugin-charts-BvH5iWMS.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),ad=(0,J.lazy)(()=>c(()=>import(`./plugin-grid-CNT3y-BZ.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),od={grid:zt,kanban:ba,calendar:Xi,gallery:Sn,timeline:Dt,gantt:Oa,map:eo,chart:ci},sd={id:`current-user`,name:`Demo User`};function cd(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 ld(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 ud(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 dd({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}=Bl(),{t:g}=z(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:S,actionSuccess:C,fieldLabel:T,fieldOptionLabel:E}=St(),{isFavorite:k,toggleFavorite:A}=Js(),[j,ee]=(0,J.useState)(!1),[te,M]=(0,J.useState)(`edit`),[ne,N]=(0,J.useState)(!1),[re,ie]=(0,J.useState)(!1),[oe,se]=(0,J.useState)(null),ce=(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=ce.current[t];a&&clearTimeout(a),ce.current[t]=setTimeout(()=>{let r=le.current[t]||{};delete le.current[t],delete ce.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),de=(0,J.useCallback)(t=>{if(se(t),R(e=>e+1),e?.updateViewConfig){let n=c,r=t.id;n&&r?e.updateViewConfig(n,r,t).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing objectName or viewId.`)}else console.warn(`[ViewConfigPanel] dataSource.updateViewConfig is not available. View config saved locally only.`)},[e,c]),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=ld(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)(ut,{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)(zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:g(`console.objectView.objectNotFound`)}),(0,Y.jsxs)(kt,{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)(()=>Zl(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(ud))}).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=oe&&oe.id===je?.id?{...je,...oe}:je,Ne=(0,J.useCallback)((e,t)=>{se(n=>({...n||{},id:je?.id,[e]:t}))},[je?.id]),Fe=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}`))},Ie=(0,J.useMemo)(()=>(Oe||[]).map(e=>{let t=od[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]);al({views:Ie,activeViewId:Ae??``,onChange:Fe,enabled:Ie.length>0&&!!Ae});let Le=(0,J.useCallback)(()=>{N(!0)},[]),Re=(0,J.useCallback)((e,t)=>{if(e===`settings`){let e=Oe.find(e=>e.type===t);e&&Fe(e.id),M(`edit`),ee(!0)}},[Oe,Fe]),ze=(0,J.useCallback)(e=>we.some(t=>(t.id||t._id)===e),[we]),Be=(0,J.useCallback)(async(t,n)=>{if(!ze(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,ze,g]),[Ve,He]=(0,J.useState)({open:!1,message:``}),[Ue,We]=(0,J.useState)({open:!1,params:[]}),[Ge,Ke]=(0,J.useState)({open:!1}),qe=(0,J.useCallback)((e,t)=>new Promise(n=>{Ke({open:!0,spec:e,data:t,resolve:n})}),[]),Je=(0,J.useCallback)((e,t)=>new Promise(n=>{He({open:!0,message:e,options:t,resolve:n})}),[]),Ye=(0,J.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;We({open:!0,params:Gu(e,{objectName:c||L?.name||``,objects:t||[],fieldLabel:T,fieldOptionLabel:E,row:i}),resolve:r})}),[c,L,t,T,E]),Xe=(0,J.useCallback)(async t=>{if(!e)return;if(!ze(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 Je(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,ze,Ae,Oe,u,i,g,Je]),Ze=(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=ld(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]),Qe=(0,J.useCallback)(async(t,n)=>{if(e){if(!ze(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,ze,g]),$e=(0,J.useCallback)(async t=>{if(e){if(!ze(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,ze,g]),et=(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]),tt=(0,J.useCallback)(e=>{if(!ze(e)){q.error(g(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==Ae&&Fe(e),M(`edit`),ee(!0)},[Ae,Fe,ze,g]),nt=(0,J.useCallback)(()=>{N(!0)},[]),rt=I?{id:I.id,name:I.name,avatar:I.image}:sd,it=(0,J.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),at=Ns({objectName:L.name,objectLabel:L.label,dataSource:e,onEdit:n,onRefresh:()=>R(e=>e+1),onConfirm:Je,onToast:it}),B=(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:{};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:n.recordId,params:n})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1)return{success:!1,error:a?.error||`Action "${t}" failed (HTTP ${i.status})`};let o=e.refreshAfter!==!1;return o&&R(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[ot,L.name]),{lastMessage:dt}=Pc({channel:`object:${L.name}`}),{hasConflicts:ft,resolveAllConflicts:pt}=zc(L.name?`user-${L.name}`:`current-user`);(0,J.useEffect)(()=>{dt&&(ft&&pt(`remote`),R(e=>e+1))},[dt,ft,pt]),(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 mt=(0,J.useMemo)(()=>Me?.navigation??L.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Me?.navigation,L.navigation]),ht=d.get(`recordId`),gt=(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()]),_t=(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,_]),vt=P({navigation:mt,objectName:L.name,onNavigate:_t}),yt=()=>{vt.close();let e=new URLSearchParams(d);e.delete(`recordId`),p(e)},bt=(0,J.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){vt.handleClick(e,t);return}if(vt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),p(e);return}}vt.handleClick(e,t)},[vt,d,p]),xt=(0,J.useCallback)(()=>{let e=vt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(yt(),_t(t))},[vt.selectedRecord,_t]);(0,J.useEffect)(()=>{ht&&!vt.isOpen?vt.open({id:ht}):!ht&&vt.isOpen&&vt.close()},[ht]);let Ct=(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)(id,{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)(Io,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=cd(s.filter??e.filter,rt.id);return gt.length?[...Array.isArray(t)?t:[],...gt]: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`)):[],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??rd(L?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=cd([...Array.isArray(s.filter)?s.filter:[],...gt],rt.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&&at.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&at.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)=>{bt(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,vt,at,ue,gt]),wt=(0,J.useMemo)(()=>Oe.map(e=>e.id===Ae&&oe&&oe.id===e.id?{...e,...oe}:e),[Oe,Ae,oe]),Tt=(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)(ae,{context:{objectName:L.name,user:rt,apiBase:``,activeOrganization:he?{id:he.id,slug:he.slug,name:he.name}:null},onConfirm:Je,onToast:it,onNavigate:B,onParamCollection:Ye,onResultDialog:qe,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)(Sl,{title:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:_(L)}),(0,Y.jsx)(ql,{managedBy:L?.managedBy})]}),description:L.description?v(L):void 0,icon:(0,Y.jsx)(dc(L?.icon),{className:`h-4 w-4`}),actions:(0,Y.jsxs)(Y.Fragment,{children:[c&&(0,Y.jsx)(K,{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)(Pe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)($r,{className:`h-4 w-4`})}),xe.create&&_e(L.name,`create`)&&(0,Y.jsxs)(K,{size:`sm`,onClick:at.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Y.jsx)(H,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),xe.import&&_e(L.name,`create`)&&(0,Y.jsxs)(K,{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)(ji,{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)(F,{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:at.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":g(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Y.jsx)(H,{className:`h-5 w-5`})}),Se&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(ad,{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)(Qo,{views:e,activeViewId:Ae,onViewChange:Fe,viewTypeIcons:od,config:{reorderable:!1,showAddButton:ge,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:ge?nt:void 0,onRenameView:ge?Be:void 0,onDeleteView:ge?Xe:void 0,onDuplicateView:ge?Ze:void 0,onPinView:ge?Qe:void 0,onSetDefaultView:ge?$e:void 0,onConfigView:ge?tt:void 0,onManageViews:ge?()=>ie(!0):void 0}),ge&&(0,Y.jsx)(Ko,{open:re,onOpenChange:ie,views:e,activeViewId:Ae,viewTypeIcons:od,onRename:Be,onDelete:Xe,onDuplicate:Ze,onSetDefault:$e,onSetPinned:Qe,onReorder:et,onAddView:nt,onConfigView:tt})]})})})(),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[vt.mode===`split`&&vt.isOpen?(0,Y.jsx)(cn,{...vt,setIsOpen:e=>{e||yt()},title:_(L),onExpand:xt,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)(Yo,{schema:Tt,dataSource:e,views:wt,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{bt(e,t)},renderListView:Ct,onCreateView:Le,onViewAction:Re})})}),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)(nd,{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)(Yo,{schema:Tt,dataSource:e,views:wt,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{bt(e,t)},renderListView:Ct,onCreateView:Le,onViewAction:Re})})})}),(0,Y.jsx)(zl,{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)(Vl,{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)(Gl,{open:ne&&ge,onOpenChange:N,existingLabels:Oe.map(e=>e.label).filter(Boolean),objectDef:L,onCreate:e=>fe(e)})]}),vt.mode!==`split`&&(0,Y.jsx)(cn,{...vt,setIsOpen:e=>{e||yt()},title:_(L),onExpand:xt,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)(nd,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}})]}),(0,Y.jsx)(eu,{state:Ve,onOpenChange:e=>{e||He({open:!1,message:``})}}),(0,Y.jsx)(tu,{state:Ue,onOpenChange:e=>{e||We({open:!1,params:[]})}}),(0,Y.jsx)(ju,{state:Ge,onAcknowledge:()=>{Ge.resolve?.(),Ke({open:!1})}}),(0,Y.jsx)(Vu,{state:ye,authFetch:ot,baseUrl:``,onClose:()=>be(null),onComplete:()=>{be(null),R(e=>e+1)}})]})}var fd=t({RecordFormPage:()=>pd});function pd({mode:e}){let{appName:t,objectName:n,recordId:r}=f(),a=s(),[o]=l(),c=le(),{objects:u,loading:d}=ie(),{t:p}=z(),{objectLabel:m}=St(),{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:Ms(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>Ms(e.visible,j)).map(([e])=>e):[],[b,j]);return d?(0,Y.jsx)(Yl,{}):b?(0,Y.jsx)(As,{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)(K,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":p(`common.back`,{defaultValue:`Back`}),children:(0,Y.jsx)(Zt,{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)(ql,{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)(Ho,{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)(ut,{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)(Ai,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:p(`empty.objectNotFound`)}),(0,Y.jsx)(kt,{children:p(`empty.objectNotFoundDescription`,{name:n})}),(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>a(x),children:[(0,Y.jsx)(Zt,{className:`mr-2 h-4 w-4`}),p(`empty.back`)]})})]})})}var md=t({DashboardView:()=>wd}),hd=[{type:`metric`,label:`KPI Metric`,Icon:mt},{type:`bar`,label:`Bar Chart`,Icon:ci},{type:`line`,label:`Line Chart`,Icon:Xr},{type:`pie`,label:`Pie Chart`,Icon:Wr},{type:`table`,label:`Table`,Icon:hr},{type:`pivot`,label:`Pivot`,Icon:Sn}],gd=0;function _d(){return gd+=1,`widget_${Date.now()}_${gd}`}function vd(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:_d()})}}function yd(e){let t=hd.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var bd=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function xd(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 Sd(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))bd.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 Cd(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 wd({dataSource:e}){let{dashboardName:t}=f(),{showDebug:n}=Bl(),r=le(),{t:i}=z(),{dashboardLabel:a,dashboardDescription:o}=St(),[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}=ie(),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(vd(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=_d(),n={id:t,title:yd(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)(()=>Cd(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),re=(0,J.useMemo)(()=>N?xd(N):{},[d,m]),ae=(0,J.useCallback)(e=>{if(!T||!d||!N)return;let t=Sd(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]),oe=(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=xd(r);i[e]=t;let a=Sd(i,r);return{...n,widgets:n.widgets.map(e=>e.id===d?{...e,...a}:e)}})},[d]),P=(0,J.useMemo)(()=>{if(S?.length)return S.map(e=>({value:e.name,label:e.label||e.name}))},[S]),se=(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]),ce=(0,J.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),F=T||w,ue=(0,J.useMemo)(()=>{if(!F||ce.size===0)return F;let e=F.widgets;if(!Array.isArray(e)||e.length===0)return F;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?ce.has(t):!0});return t.length===e.length?F:{...F,widgets:t}},[F,ce]);return s?(0,Y.jsx)(Jl,{}):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=yc((ue||w).title,i),t=yc(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:yc(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:hd.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)(H,{className:`h-3 w-3`}),(0,Y.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,Y.jsxs)(`button`,{type:`button`,onClick:O,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,Y.jsx)(vt,{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)(rs,{schema:ue,dataSource:e,designMode:l,selectedWidgetId:d,onWidgetClick:p,onWidgetsReorder:ee,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),N?(0,Y.jsx)(is,{open:l,onClose:k,config:re,onSave:ae,onFieldChange:oe,availableObjects:P,availableFields:se,headerExtra:(0,Y.jsx)(K,{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)(Xt,{className:`h-3.5 w-3.5`})})},d):(0,Y.jsx)(as,{open:l,onClose:k,config:te,onSave:M,onFieldChange:ne}),(0,Y.jsx)(zl,{open:n,sections:[{title:`Dashboard Configuration`,data:ue}]})]}),g&&g.schema?.objectName?(0,Y.jsx)(Bo,{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)(ft,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,Y.jsx)(Jt,{children:g.schema.description})]}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:()=>v({success:!1}),children:i(`actionDialog.cancel`)}),(0,Y.jsx)(K,{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)(ut,{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)(dt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:i(`empty.dashboardNotFound`)}),(0,Y.jsx)(kt,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Td=t({PageView:()=>Ed});function Ed(){let{t:e}=z(),{pageName:t}=f(),[n]=l(),{showDebug:r}=Bl(),{pages:i}=ie(),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)(ut,{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)(da,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:e(`empty.pageNotFound`)}),(0,Y.jsx)(kt,{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)(F,{schema:{...a,type:a.type||`page`,context:{...a.context,params:o}}})}),(0,Y.jsx)(zl,{open:r,sections:[{title:`Page Configuration`,data:a}]})]})}var Dd=t({ReportView:()=>Md}),Od=(0,J.lazy)(()=>c(()=>import(`./plugin-report-BFZ-T3Th.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),kd=(0,J.lazy)(()=>c(()=>import(`./plugin-report-BFZ-T3Th.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),Ad=(0,J.lazy)(()=>c(()=>import(`./plugin-report-BFZ-T3Th.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),jd=[{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 Md({dataSource:e}){let{t}=z(),{reportName:n}=f(),{showDebug:r}=Bl(),i=le(),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(0),{reports:l,objects:u,loading:d,refresh:p}=ie(),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)??jd},[_,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)(ut,{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)(ci,{className:`h-6 w-6 text-muted-foreground`})}),(0,Y.jsx)(fo,{children:t(`empty.reportNotFound`)}),(0,Y.jsx)(kt,{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,re=!!(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))),ae={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)(vt,{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:re?(0,Y.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Y.jsx)(kd,{schema:N,dataSource:e})}):(0,Y.jsx)(Od,{schema:ae})})})}),(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(Ad,{open:a,onClose:D,config:O,onSave:k,onFieldChange:A,availableFields:w,getFieldsForObject:C})}),(0,Y.jsx)(zl,{open:r,sections:[{title:`Report Configuration`,data:N}]})]})]})}var Nd=t({SearchResultsPage:()=>Ld});function Pd(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Pd(n.children)):t.push(n);return t}var Fd={object:Ai,dashboard:dt,page:da,report:ci},Id={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 Ld(){let{t:e}=z(),{appName:t}=f(),[n,r]=l(),[a,o]=(0,J.useState)(n.get(`q`)||``),{apps:s}=ie(),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=Pd(u.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=Ao(e,d,t);return{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:n,type:e.type,description:e.description}}).filter(e=>e.href!==`#`)},[u,d,p?.id]),h=(0,J.useMemo)(()=>{if(!a.trim())return m;let e=a.toLowerCase();return m.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[m,a]),g=e=>{o(e),r(e?{q:e}:{})},_=(0,J.useMemo)(()=>{let e={};for(let t of h)(e[t.type]||=[]).push(t);return e},[h]);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(i,{to:d,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Y.jsx)(Zt,{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)(Wa,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{id:`search-results-input`,value:a,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.trim()?e(h.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:h.length,query:a}):e(`search.itemsAvailable`,{count:m.length})}),h.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,Y.jsx)(Wa,{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=Fd[t]||Ai,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=Fd[t.type]||Ai,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)(Ht,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Y.jsxs)(ga,{className:`flex items-center gap-3 p-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${Id[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 Rd(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 zd(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 Bd=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=Rd(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(zd)};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 Vd(){let e=le();return(0,J.useMemo)(()=>e?new Bd(e):null,[e])}var Hd=0;function Ud(e=`nav`){return`${e}_${Date.now()}_${++Hd}`}function Wd(e,t){return[...e,t]}function Gd(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:Gd(e.children,t,n)}:e)}function Kd(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:Kd(i.children,t,n,r)}:i})}function qd(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Jd(){let e=le(),{apps:t,refresh:n}=ie(),{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=Wd(a,{id:Ud(`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=Wd(a,{id:Ud(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),q.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Gd(i,`page`,t);if(qd(a,i))return;let c={...n,navigation:a};try{await o(e,c),q.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),q.info(r(`navigationSync.undone`))}catch{q.error(r(`navigationSync.undoFailed`))}}}})}catch{q.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,J.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Gd(i,`dashboard`,t);if(qd(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=Kd(a,`page`,t,n);if(qd(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=Kd(a,`dashboard`,t,n);if(qd(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 Yd(){let{pages:e,dashboards:t,apps:n}=ie(),r=le(),i=(0,J.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=Jd(),l=(0,J.useRef)(null),u=(0,J.useRef)(null),d=(0,J.useRef)(0),f=(0,J.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,J.useEffect)(()=>{if(f.current)return;let r=new Set((e??[]).map(e=>e.name).filter(Boolean)),i=new Set((t??[]).map(e=>e.name).filter(Boolean)),m=l.current,h=u.current;if(m===null||h===null){l.current=r,u.current=i;return}let g=[...r].filter(e=>!m.has(e)),_=[...m].filter(e=>!r.has(e)),v=[...i].filter(e=>!h.has(e)),y=[...h].filter(e=>!i.has(e));if(g.length===0&&_.length===0&&v.length===0&&y.length===0){l.current=r,u.current=i;return}let b=++d.current;f.current=!0;let x=!1;return(async()=>{try{for(let e of n){if(x||d.current!==b)break;let t=p(e);if(t){for(let e of g){if(x)break;await a(t,e)}for(let e of _){if(x)break;await s(t,e)}for(let e of v){if(x)break;await o(t,e)}for(let e of y){if(x)break;await c(t,e)}}}}finally{d.current===b&&(l.current=r,u.current=i,f.current=!1)}})(),()=>{x=!0}},[e,t,n,a,o,s,c]),null}var Xd=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Zd(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Qd(e){try{return decodeURIComponent(e)}catch{return e}}function $d({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=To(),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}:${Qd(t)}`,label:Qd(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Xd.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:Zd(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Zd(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Zd(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var ef=`objectstack:ai-chat-conversation-id`;function tf(e,t){return t?`${ef}:${e}:${t}`:`${ef}:${e}`}function nf(e){try{return localStorage.getItem(e)??void 0}catch{return}}function rf(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function af(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 of(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=af(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function sf(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 cf(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 lf(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function uf(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=tf(t,n);return u(!0),(async()=>{try{if(i){let n=await sf(r,i);if(e)return;if(n){rf(s,n.id),o(n.id),c(of(n.messages)),f.current=t;return}rf(s,void 0)}else{let n=nf(s);if(n){let i=await sf(r,n);if(e)return;if(i){o(i.id),c(of(i.messages)),f.current=t;return}rf(s,void 0)}}let n=await cf(r);if(e)return;rf(s,n.id),o(n.id),c(of(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=tf(t,n);u(!0);try{a&&await lf(r,a),rf(e,void 0);let t=await cf(r);if(rf(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 df(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=ff(n.content);if(e)return e}}let t=e[e.length-1];return ff(t?.content)}function ff(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 pf(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:df(e.messages)}}function mf(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(pf).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 hf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Yu).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),gf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>md).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),_f=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Td).then(e=>({default:e.PageView})),void 0,import.meta.url)),vf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Dd).then(e=>({default:e.ReportView})),void 0,import.meta.url)),yf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Nd).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),bf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>fd).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),xf=(0,J.lazy)(()=>c(()=>import(`./ComponentNavView-DscbHf4h.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Sf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),Cf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),wf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Tf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Ef=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Df=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Ew).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),Of=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>FD).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),kf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>FD).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),Af=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>FD).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),jf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>gp).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),Mf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Sp).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),Nf=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>wp).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function Pf({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}=ie(),{t:S}=z(),{objectLabel:C}=St(),[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}=ce();se({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=_c({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=vc({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 re=m.pathname.split(`/`).filter(Boolean)[2];(re===`view`||re===`record`||re===`page`||re===`dashboard`||re===`design`)&&(re=``);let ae=v.find(e=>e.name===re),oe=(0,J.useCallback)(()=>{let e=ae?C(ae):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,ae,C,S]),P=(0,J.useCallback)(()=>{ne({type:`dialog_cancel`})},[ne]);$d({pathname:m.pathname,appName:O?.name,objects:v});let F=e=>{let t=gc({objectDef:ae,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)(Ol,{});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)(ut,{children:[(0,Y.jsx)(fo,{children:S(`empty.noAppsConfigured`)}),(0,Y.jsx)(kt,{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)(K,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:S(`empty.createFirstApp`)}),(0,Y.jsx)(K,{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)(Ol,{}),children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Of,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(jf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Nf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Mf,{})}),t]})}):(0,Y.jsxs)(As,{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)(Yd,{}),(0,Y.jsxs)(xl,{activeAppName:O.name,activeApp:O,onAppChange:ue,objects:v,connectionState:n,userId:i?.id,children:[(0,Y.jsx)(Cl,{apps:g,activeApp:O,objects:v,onAppChange:ue,dataSource:c}),(0,Y.jsx)(Tl,{}),(0,Y.jsx)(El,{}),(0,Y.jsx)(Rl,{children:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(jl,{className:`h-full`,children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/`,element:(()=>{let e=Rf(O,{currentUserId:i?.id??null});return e?(0,Y.jsx)(_,{to:e,replace:!0}):(0,Y.jsx)(Cf,{})})()}),(0,Y.jsxs)(d,{path:`metadata`,children:[(0,Y.jsx)(d,{index:!0,element:(0,Y.jsx)(Sf,{})}),(0,Y.jsx)(d,{path:`_diagnostics`,element:(0,Y.jsx)(Df,{})}),(0,Y.jsx)(d,{path:`:type`,element:(0,Y.jsx)(wf,{})}),(0,Y.jsx)(d,{path:`:type/new`,element:(0,Y.jsx)(Tf,{createMode:!0})}),(0,Y.jsx)(d,{path:`:type/:name`,element:(0,Y.jsx)(Tf,{})}),(0,Y.jsx)(d,{path:`:type/:name/history`,element:(0,Y.jsx)(Ef,{})})]}),(0,Y.jsx)(d,{path:`:objectName`,element:(0,Y.jsx)(dd,{dataSource:c,objects:v,onEdit:F,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/new`,element:(0,Y.jsx)(bf,{mode:`create`})}),(0,Y.jsx)(d,{path:`:objectName/view/:viewId`,element:(0,Y.jsx)(dd,{dataSource:c,objects:v,onEdit:F,externalRefreshKey:te})}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId`,element:(0,Y.jsx)(hf,{dataSource:c,objects:v,onEdit:F},te)}),(0,Y.jsx)(d,{path:`:objectName/record/:recordId/edit`,element:(0,Y.jsx)(bf,{mode:`edit`})}),(0,Y.jsx)(d,{path:`dashboard/:dashboardName`,element:(0,Y.jsx)(gf,{dataSource:c})}),(0,Y.jsx)(d,{path:`report/:reportName`,element:(0,Y.jsx)(vf,{dataSource:c})}),(0,Y.jsx)(d,{path:`page/:pageName`,element:(0,Y.jsx)(_f,{})}),(0,Y.jsx)(d,{path:`component/:ns/:name/*`,element:(0,Y.jsx)(xf,{})}),(0,Y.jsx)(d,{path:`component/metadata/directory`,element:(0,Y.jsx)(Vf,{mode:`directory`})}),(0,Y.jsx)(d,{path:`component/metadata/resource/*`,element:(0,Y.jsx)(Vf,{mode:`resource`})}),(0,Y.jsx)(d,{path:`design/dashboard/:dashboardName`,element:(0,Y.jsx)(Af,{})}),(0,Y.jsx)(d,{path:`search`,element:(0,Y.jsx)(yf,{})}),(0,Y.jsx)(d,{path:`create-app`,element:(0,Y.jsx)(Of,{})}),(0,Y.jsx)(d,{path:`edit-app/:editAppName`,element:(0,Y.jsx)(kf,{})}),(0,Y.jsx)(d,{path:`system/marketplace`,element:(0,Y.jsx)(jf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/installed`,element:(0,Y.jsx)(Nf,{})}),(0,Y.jsx)(d,{path:`system/marketplace/:packageId`,element:(0,Y.jsx)(Mf,{})}),e,(0,Y.jsx)(d,{path:`:objectName/:maybeRecordId`,element:(0,Y.jsx)(Hf,{})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(Uf,{})})]})})})}),ae&&(0,Y.jsx)(Bo,{schema:{type:`object-form`,formType:`modal`,objectName:ae.name,mode:j?`edit`:`create`,recordId:j?.id,title:S(j?`form.editTitle`:`form.createTitle`,{object:C(ae)}),description:S(j?`form.editDescription`:`form.createDescription`,{object:C(ae)}),open:k,onOpenChange:A,layout:`vertical`,fields:ae.fields?Array.isArray(ae.fields)?ae.fields.filter(e=>typeof e==`string`?!0:Ms(e.visible,de)).map(e=>typeof e==`string`?e:e.name):Object.entries(ae.fields).filter(([e,t])=>Ms(t.visible,de)).map(([e])=>e):[],onSuccess:oe,onCancel:P,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 Ff(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=If(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Ff(n.children,t);if(e!==``)return e}}return``}function If(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Ao(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function Lf(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=Lf(n.children,t);if(e)return e}}}function Rf(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=If(Lf(r,n),t);if(e)return e}return Ff(r,t)}var zf=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function Bf(e){return!e||zf.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function Vf({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 Hf(){let{objectName:e,maybeRecordId:t}=f(),n=o();return e&&Bf(t)?(0,Y.jsx)(_,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Y.jsx)(Uf,{})}function Uf(){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)(ut,{children:[(0,Y.jsx)(fo,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Y.jsx)(kt,{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)(K,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Wf({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,J.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,Y.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,Y.jsx)(`span`,{className:i,children:s})})}function Gf(){let e=s(),{appName:t}=f(),{t:n}=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)(Ht,{children:(0,Y.jsxs)(ga,{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)(Un,{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)(K,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var Kf=`en`;function qf(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function Jf(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function Yf(e,t,n){if(!e)return;let r=qf(t),i=Jf([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),Kf]);for(let t of i){let r=e[t];if(!r)continue;let i=r[n];if(typeof i==`string`&&i.length>0)return i}}function Xf(e,t){let n=e[{displayName:`display_name`,description:`description`,readme:`readme`,tagline:`tagline`,screenshotCaptions:`screenshotCaptions`}[t]]??e[t];return typeof n==`string`&&n.length>0?n:void 0}function Zf(e,t){let n=t||Kf;return{displayName:Yf(e.translations??void 0,n,`displayName`)??Xf(e,`displayName`)??e.manifest_id,description:Yf(e.translations??void 0,n,`description`)??Xf(e,`description`),readme:Yf(e.translations??void 0,n,`readme`)??Xf(e,`readme`),tagline:Yf(e.translations??void 0,n,`tagline`)??Xf(e,`tagline`)}}var Qf=``.replace(/\/$/,``),$f=`${Qf}/api/v1/marketplace`;async function ep(e,t){let n=await fetch(`${$f}${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 tp(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 ep(`/packages${n?`?${n}`:``}`)}async function np(e){return ep(`/packages/${encodeURIComponent(e)}`)}async function rp(e){let t=fl()||Qf,n=await fetch(`${t}/api/v1/actions/sys_package/install_package`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({recordId:e.packageId,params:{environment_id:e.environmentId,seed_sample_data:!!e.seedSampleData}})}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??r?.error?.code??`HTTP_${n.status}`,t=r?.error??r?.message??n.statusText,i=Error(typeof t==`string`?t:`${e}`);throw i.code=e,i.status=n.status,i}return r?.data??r}async function ip(){let e=fl()||Qf,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 ap(){let e=fl()||Qf,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 op(e){return`${fl()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function sp(e,t){if(!e||!t)return null;let n=fl()||Qf,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 cp(e){if(!e)return{ok:!1,error:`installation id required`};let t=fl()||Qf;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 lp(e){if(!e)return{ok:!1,error:`installation id required`};let t=fl()||Qf;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 up(e){let t=await fetch(`${$f}/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 dp(){try{let e=await fetch(`${$f}/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 fp(e){let t=await fetch(`${$f}/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 pp(e,t){let n=await fetch(`${$f}/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 mp(e){return pp(e,`reseed`)}function hp(e){return pp(e,`purge`)}var gp=t({MarketplacePage:()=>vp});function _p(){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 vp(){let e=s(),{appName:t}=f(),n=C(),{t:r,language:i}=z(),a=_p(),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([tp({limit:100}),dp()]);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=Zf(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)(yr,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/installed`),children:[(0,Y.jsx)(yi,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>void S(),disabled:u,children:[(0,Y.jsx)(Oi,{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)(Wa,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Y.jsx)(W,{value:h,onChange:e=>g(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,Y.jsx)(K,{size:`sm`,variant:_===``?`default`:`outline`,onClick:()=>v(``),children:r(`marketplace.all`)}),w.map(e=>(0,Y.jsx)(K,{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)(Ne,{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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`pb-2`,children:[(0,Y.jsx)(He,{className:`h-10 w-10 rounded-lg mb-2`}),(0,Y.jsx)(He,{className:`h-5 w-3/4`}),(0,Y.jsx)(He,{className:`h-4 w-1/2 mt-1`})]}),(0,Y.jsx)(ga,{children:(0,Y.jsx)(He,{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=Zf(t,i);return(0,Y.jsxs)(Ht,{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)(pr,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Y.jsx)(Wf,{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)(cr,{className:`text-base truncate`,children:s.displayName}),(0,Y.jsx)(Rt,{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)(ga,{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)(vr,{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)(Si,{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)(Gf,{})}function yp(e){let t=e.replace(/\r\n/g,`
|
|
11
11
|
`).split(`
|
|
12
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
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 xp({source:e,className:t}){let n=yp(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 Sp=t({MarketplacePackagePage:()=>Cp});function Cp(){let e=s(),{packageId:t,appName:n}=f(),r=C(),{t:i,language:a}=z(),o=n?`/apps/${n}`:``,{refresh:c}=ie(),[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)(null),[te,M]=(0,J.useState)(null),[ne,N]=(0,J.useState)(null),[re,ae]=(0,J.useState)(null),[oe,P]=(0,J.useState)(null),[se,ce]=(0,J.useState)([]),[F,le]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(null);(0,J.useEffect)(()=>{if(!ll().features.installLocal)return;let e=!1;return(async()=>{let t=await dp();e||ce(t)})(),()=>{e=!0}},[t,ue]),(0,J.useEffect)(()=>{if(!t)return;let e=ll().defaultEnvironmentId;if(!e)return;let n=!1;return(async()=>{let r=await sp(t,e);n||!r||(N(r),M(r.version))})(),()=>{n=!0}},[t]),(0,J.useEffect)(()=>{let e=!1;return(async()=>{if(t){p(!0),h(null);try{let n=await np(t);e||u(n)}catch(t){e||h(t?.message??String(t))}finally{e||p(!1)}}})(),()=>{e=!0}},[t]);let fe=async()=>{_(!0),ee(null),w(null);let e=ll().defaultEnvironmentId;if(e){x(!1),E(e),y([]);return}x(!0);try{let[e,t]=await Promise.all([ip(),ap()]),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)}},pe=async()=>{if(!(!t||!T)){A(!0),ee(null);try{M(((await rp({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=ll().defaultEnvironmentId||T;if(e){let n=await sp(t,e);n&&N(n)}}catch{}let e=ll().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{}ee({ok:!0,message:i(`marketplace.install.success`)})}catch(e){ee({ok:!1,message:e?.message??String(e)})}finally{A(!1)}}},me=async()=>{if(t){le(!0),de(null);try{let e=await up({packageId:t});try{await c(`app`)}catch{}de({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?Zf(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`)),de({ok:!1,message:n})}finally{le(!1)}}},I=async()=>{if(be&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:be.manifestId,version:be.version}))){le(!0),de(null);try{await fp(be.manifestId);try{await c(`app`)}catch{}de({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:be.manifestId})})}catch(e){de({ok:!1,message:e?.message??String(e)})}finally{le(!1)}}},he=async()=>{if(ne){ae(`reseed`),P(null);try{let e=await cp(ne.installationId);e.ok?(N({...ne,withSampleData:!0}),P({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):P({ok:!1,text:e.error||`Re-seed failed`})}finally{ae(null)}}},ge=async()=>{if(ne&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ae(`purge`),P(null);try{let e=await lp(ne.installationId);if(e.ok){N({...ne,withSampleData:!1});let t=e.deleted??0;P({ok:!0,text:t>0?i(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:i(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}else P({ok:!1,text:e.error||`Purge failed`})}finally{ae(null)}}},_e=async()=>{if(be){ae(`reseed`),P(null);try{let e=await mp(be.manifestId);ce(e=>e.map(e=>e.manifestId===be.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;P({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){P({ok:!1,text:e?.message||`Re-seed failed`})}finally{ae(null)}}},L=async()=>{if(be&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ae(`purge`),P(null);try{let e=await hp(be.manifestId);ce(e=>e.map(e=>e.manifestId===be.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;P({ok:!0,text:t>0?i(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:i(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}catch(e){P({ok:!1,text:e?.message||`Purge failed`})}finally{ae(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)(He,{className:`h-8 w-32`}),(0,Y.jsx)(He,{className:`h-16 w-full`}),(0,Y.jsx)(He,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Y.jsx)(Zt,{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)(Ne,{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 ve=l.package,R=Zf(ve,a),ye=ve.latest_version?.version??l.versions[0]?.version??null,be=se.find(e=>e.manifestId===ve.manifest_id)??null,xe=ll().features.installLocal,Se=!ye||F||k||!xe&&!!te,Ce=xe?{label:i(F?`marketplace.action.working`:be?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:me}:{label:k?i(`marketplace.action.installing`):te?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:fe},we=ve.category?i(`marketplace.category.${ve.category}`,{defaultValue:ve.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)(K,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Y.jsx)(Zt,{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)(Wf,{iconUrl:ve.icon_url,displayName:R.displayName,manifestId:ve.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:R.displayName||ve.manifest_id}),ve.homepage_url&&(0,Y.jsxs)(`a`,{href:ve.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)(Ze,{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:ve.manifest_id}),ye&&(0,Y.jsx)(V,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:ye})}),ve.publisher&&ve.publisher!==`private`&&(0,Y.jsx)(V,{variant:ve.publisher===`objectstack`?`default`:`secondary`,children:ve.publisher}),we&&(0,Y.jsx)(V,{variant:`outline`,children:we}),ve.license&&(0,Y.jsx)(V,{variant:`outline`,className:`font-normal`,children:ve.license}),be&&(0,Y.jsxs)(V,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(vr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:be.version})]}),!be&&te&&(0,Y.jsxs)(V,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Y.jsx)(vr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:te})]})]}),R.description&&(0,Y.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:R.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,Y.jsxs)(K,{onClick:Ce.onClick,disabled:Se,size:`lg`,className:`min-w-[8rem]`,children:[(0,Y.jsx)(nt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),Ce.label]}),be&&(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsx)(K,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`),children:(0,Y.jsx)(Xa,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(ia,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(Vr,{onSelect:_e,disabled:re!==null,children:[re===`reseed`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Ai,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),be.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(Vr,{onSelect:L,disabled:re!==null||!be.withSampleData,className:`text-destructive focus:text-destructive`,children:[re===`purge`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Xt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,Y.jsxs)(Vr,{onSelect:I,disabled:F,className:`text-destructive focus:text-destructive`,children:[(0,Y.jsx)(Xt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!be&&ne&&(0,Y.jsxs)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsx)(K,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`)||`More options`,children:(0,Y.jsx)(Xa,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Y.jsxs)(ia,{align:`end`,className:`w-56`,children:[(0,Y.jsxs)(Vr,{onSelect:he,disabled:re!==null,children:[re===`reseed`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Ai,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),ne.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Y.jsxs)(Vr,{onSelect:ge,disabled:re!==null||!ne.withSampleData,className:`text-destructive focus:text-destructive`,children:[re===`purge`?(0,Y.jsx)(B,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(Xt,{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)(vr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Ne,{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:()=>P(null),children:i(`marketplace.action.dismiss`)})]}),ue&&(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${ue.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:[ue.ok?(0,Y.jsx)(vr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(Ne,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:ue.message}),(0,Y.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>de(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)(Ht,{children:[(0,Y.jsx)(pr,{children:(0,Y.jsx)(cr,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,Y.jsx)(ga,{children:R.readme?(0,Y.jsx)(xp,{source:R.readme}):(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noReadme`)})})]})}),(0,Y.jsx)(`div`,{className:`space-y-4`,children:(0,Y.jsxs)(Ht,{children:[(0,Y.jsx)(pr,{children:(0,Y.jsx)(cr,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,Y.jsx)(ga,{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)(Si,{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)(ft,{open:g,onOpenChange:e=>{_(e),e||ee(null)},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:i(`marketplace.install.dialogTitle`,{name:R.displayName||ve.manifest_id})}),(0,Y.jsx)(Jt,{children:ll().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),b?(0,Y.jsx)(He,{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)(Ne,{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:op(ve.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,Y.jsx)(Ze,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):ll().defaultEnvironmentId?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(yt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(G,{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)(G,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,Y.jsxs)(In,{value:T,onValueChange:E,children:[(0,Y.jsx)(nr,{id:`env-select`,children:(0,Y.jsx)(Ot,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,Y.jsx)(vo,{children:v.map(e=>(0,Y.jsxs)(Ye,{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)(yt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Y.jsx)(G,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),j&&(0,Y.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${j.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:j.message}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:()=>_(!1),children:i(`marketplace.action.close`)}),!S&&(0,Y.jsx)(K,{onClick:pe,disabled:!T||k||j?.ok===!0,children:i(k?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,Y.jsx)(Gf,{})}var wp=t({MarketplaceInstalledPage:()=>Tp});function Tp(){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 dp())}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 fp(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)(K,{variant:`ghost`,size:`sm`,className:`self-start`,onClick:()=>e(`${a}/system/marketplace`),children:[(0,Y.jsx)(Zt,{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)(yr,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>void g(),disabled:l,children:[(0,Y.jsx)(Oi,{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)(Ne,{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)(He,{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)(K,{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)(Ht,{children:[(0,Y.jsxs)(pr,{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)(cr,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>e(`${a}/system/marketplace/${t.packageId}`),children:[(0,Y.jsx)(Ze,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.action.details`)]}),(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void _(t),disabled:d===t.manifestId,children:[(0,Y.jsx)(Xt,{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)(ga,{className:`pt-0 text-xs text-muted-foreground`,dangerouslySetInnerHTML:{__html:r(`marketplace.cachedAs`,{path:`.objectstack/installed-packages/${t.manifestId.replace(/[^a-zA-Z0-9._-]/g,`_`)}.json`})}})]},t.manifestId))}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground border-t pt-4`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedAdditiveNote`)}})]}):(0,Y.jsx)(Gf,{})}function Ep({children:e,userId:t}){let{setContext:n}=Is(),{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)(gl,{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)(sc,{appLabel:`Workspace`,objects:[],userId:t})]})}var Dp=[{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 Op(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function kp({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=z(),{appLabel:a,appDescription:o}=St(),{toggleFavorite:s}=Js(),c=dc(e.icon),l=a({name:e.name,label:yc(e.label,i)}),u=o({name:e.name,description:yc(e.description,i)}),d=e.branding?.primaryColor,f=Dp[(Op(e.name)+r)%Dp.length];return(0,Y.jsxs)(Ht,{role:`button`,tabIndex:0,"aria-label":l,className:U(`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:U(`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:U(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,f.from,f.to)}),(0,Y.jsxs)(ga,{className:`relative p-5`,children:[(0,Y.jsx)(K,{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)(Pe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Y.jsx)($r,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:U(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,d?``:U(`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:U(`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:U(`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)(pn,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var Ap={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`},jp={object:Ai,record:da,dashboard:dt,page:za};function Mp({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)(Ke,{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=jp[e.type]||Ai,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:bc(e.type)}),a=Ap[e.type]||Ap.object;return(0,Y.jsx)(Ht,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`recent-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,Y.jsx)(ga,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:U(`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)(pn,{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 Np={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`},Pp={object:Ai,record:da,dashboard:dt,page:za};function Fp({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)(Pe,{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=Pp[e.type]||Ai,i=Np[e.type]||Np.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:bc(e.type)});return(0,Y.jsx)(Ht,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`starred-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,Y.jsx)(ga,{className:`p-3.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:U(`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)(pn,{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 Ip(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Lp({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)(Pe,{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)(Ke,{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)(Fn,{className:`h-3.5 w-3.5`})]})]})})}function Rp({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 zp(){let e=s(),{t}=z(),{apps:n,loading:r}=ie(),{recentItems:i}=To(),{favorites:a}=Js(),{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(Ip(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)(ut,{children:[(0,Y.jsx)(fo,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Y.jsx)(kt,{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)(K,{onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),t(`home.createFirstApp`,{defaultValue:`Create Your First App`})]}),c&&(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-empty-btn`,children:[(0,Y.jsx)(yr,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]}),(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,Y.jsx)(yi,{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)(ra,{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)(Rp,{icon:Sn,tone:`text-indigo-600 dark:text-indigo-400`,value:l.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Y.jsx)(Rp,{icon:Ke,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)(Rp,{icon:Pe,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)(Lp,{t}),d.length>0&&(0,Y.jsx)(Fp,{items:d}),u.length>0&&(0,Y.jsx)(Mp,{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)(Sn,{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)(K,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,Y.jsx)(yr,{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)(kp,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function Bp({children:e}){let{setContext:t}=Is();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)(gl,{variant:`orgs`})}),(0,Y.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function Vp(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function Hp({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(Vp(o))},[o,u]),(0,J.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Y.jsx)(ft,{open:e,onOpenChange:t,children:(0,Y.jsx)(Mt,{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)(mo,{children:[(0,Y.jsx)(Ge,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Y.jsx)(Jt,{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)(G,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Y.jsx)(W,{id:`workspace-name`,placeholder:r(`workspace.namePlaceholder`,{defaultValue:`e.g., Acme Inc`}),value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`workspace-name-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Y.jsx)(W,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,Y.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(K,{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 Up(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 Wp(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Gp(){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=Up()}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)(Wa,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(W,{value:c,onChange:e=>l(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),m&&(0,Y.jsxs)(K,{onClick:()=>d(!0),"data-testid":`organizations-new`,children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),g.length===0?(0,Y.jsxs)(ut,{children:[(0,Y.jsx)(fo,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Y.jsx)(kt,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),m&&(0,Y.jsxs)(K,{className:`mt-6`,onClick:()=>d(!0),children:[(0,Y.jsx)(H,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):_.length===0?(0,Y.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No organizations match your search.`})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:_.map(n=>{let i=n.id===r?.id,a=f===n.id;return(0,Y.jsxs)(`button`,{onClick:()=>v(n),disabled:a,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,Y.jsxs)(Me,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Y.jsx)(Na,{src:n.logo,alt:n.name}),(0,Y.jsx)(ti,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Wp(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)(Hp,{open:u,onOpenChange:d,onCreated:y})]})}function Kp(){let{t:e}=z(),t=s(),{slug:n}=f(),{organizations:r,activeOrganization:i,isOrganizationsLoading:o,switchOrganization:c}=w(),{setContext:l}=Is();(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)(K,{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)(gl,{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)(Zt,{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 qp(){return h()}function Jp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function Yp({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=Jp(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)(ft,{open:t,onOpenChange:n,children:(0,Y.jsx)(Mt,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Y.jsx)(Jt,{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)(G,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{readOnly:!0,value:Jp(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Y.jsx)(K,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,Y.jsx)(Mr,{className:`h-4 w-4`}):(0,Y.jsx)(pt,{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)(Nn,{children:(0,Y.jsx)(K,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Y.jsxs)(`form`,{onSubmit:v,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Y.jsx)(Jt,{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)(G,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(W,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Y.jsxs)(In,{value:c,onValueChange:e=>l(e),children:[(0,Y.jsx)(nr,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsxs)(vo,{children:[(0,Y.jsx)(Ye,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Y.jsx)(Ye,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Y.jsx)(Ye,{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)(Nn,{children:[(0,Y.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(K,{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 Xp(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Zp(){let{t:e}=z(),{org:t}=qp(),{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)(K,{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)(K,{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)(Na,{src:t.user.image,alt:t.user.name}),(0,Y.jsx)(ti,{className:`text-xs font-medium`,children:Xp(t.user?.name)})]}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,Y.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,Y.jsx)(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)(kr,{children:[(0,Y.jsx)(Yi,{asChild:!0,children:(0,Y.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Y.jsx)(Xa,{className:`h-4 w-4`})})}),(0,Y.jsxs)(ia,{align:`end`,children:[(0,Y.jsxs)(Vr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Y.jsx)(ai,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Y.jsxs)(Vr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Y.jsx)(ai,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Y.jsxs)(Vr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Y.jsx)(ai,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Y.jsxs)(Vr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Y.jsx)(Li,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Y.jsx)(jr,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Y.jsx)(Wi,{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)(Ba,{children:[(0,Y.jsx)(Da,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(oa,{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)(Yp,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function Qp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function $p(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function em(){let{t:e}=z(),{org:t}=qp(),{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=Qp(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)(K,{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)(ti,{className:`text-xs`,children:(0,Y.jsx)(Ln,{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:$p(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)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Y.jsx)(Mr,{className:`h-4 w-4 text-green-600`}):(0,Y.jsx)(pt,{className:`h-4 w-4`})}),(0,Y.jsx)(K,{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)(ro,{className:`h-4 w-4`})})]})]},t.id))}),(0,Y.jsx)(jr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Y.jsx)(Wi,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Y.jsxs)(Ba,{children:[(0,Y.jsx)(Da,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsx)(oa,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function tm(){let{t:e}=z(),{org:t}=qp(),{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}=xr(),[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)(G,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Y.jsx)(W,{id:`org-name`,value:l,onChange:e=>u(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Y.jsx)(W,{id:`org-slug`,value:d,onChange:e=>f(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Y.jsx)(G,{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)(Na,{src:p,alt:l,className:`object-cover`}):null,(0,Y.jsx)(ti,{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)(K,{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)(ji,{className:`mr-2 h-4 w-4`}),p?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),p&&(0,Y.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Y.jsx)(ro,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Y.jsx)(W,{id:`org-logo`,type:`url`,value:p,onChange:e=>m(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Y.jsxs)(K,{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)(K,{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)(K,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Y.jsx)(jr,{open:E,onOpenChange:D,children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Y.jsx)(Wi,{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)(Ba,{children:[(0,Y.jsx)(Da,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(oa,{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)(jr,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Y.jsxs)(Ur,{children:[(0,Y.jsxs)(Yr,{children:[(0,Y.jsx)(si,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Y.jsx)(Wi,{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)(G,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,Y.jsx)(W,{id:`delete-confirm-slug`,className:`mt-2`,value:A,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Y.jsxs)(Ba,{children:[(0,Y.jsx)(Da,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Y.jsxs)(oa,{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 nm(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 rm({userId:e,apiBase:t,className:n,refreshKey:r}){let i=s(),{conversationId:a}=f(),{conversations:o,isLoading:c,error:l,remove:u,rename:d}=mf({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:U(`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)(K,{size:`sm`,variant:`outline`,onClick:v,"data-testid":`ai-new-chat`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`New`]})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Wa,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(W,{value:p,onChange:e=>m(e.target.value),placeholder:`Search chats...`,className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Y.jsx)(Zn,{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)(ut,{className:`px-3 py-8`,children:[(0,Y.jsx)(di,{className:`h-8 w-8 text-muted-foreground`}),(0,Y.jsx)(fo,{children:`No chats yet`}),(0,Y.jsx)(kt,{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)(im,{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 im({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:U(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,t?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,Y.jsx)(W,{ref:d,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s(l)):e.key===`Escape`&&(e.preventDefault(),o())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":`Rename conversation`}),(0,Y.jsx)(K,{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)(Mr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:o,"aria-label":`Cancel rename`,children:(0,Y.jsx)(ro,{className:`h-3.5 w-3.5`})})]})}):(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:U(`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)(vt,{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)(Xt,{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:nm(e.updatedAt??e.createdAt)})]})})}var am=`/api/v1/ai`;function om(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(/\/$/,``)}${am}`}function sm({apiBase:e,defaultAgent:t}={}){let{user:n}=w(),r=n?.id,{conversationId:i}=f(),a=s(),{setContext:o}=Is();(0,J.useEffect)(()=>{o(`home`)},[o]);let c=(0,J.useMemo)(()=>om(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}=us({apiBase:c}),[m,h]=(0,J.useState)(void 0);(0,J.useEffect)(()=>{if(!m&&u.length>0){let e=cs(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}=uf({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)(gl,{variant:`home`}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,Y.jsxs)(K,{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)(Ji,{className:`h-3.5 w-3.5`}),`Share`]})})]}),_&&(0,Y.jsx)($a,{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)(rm,{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)(cm,{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 cm({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 dm(r,d)},[f.length,r,d]),{messages:m,isLoading:h,error:g,sendMessage:_,stop:v,reload:y,clear:b}=os({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=ls({messages:m,apiBase:o,continueConversation:e=>{_(e)}}),S=(0,J.useCallback)((e,t)=>{_(e,t),u(e)},[_,u]);return(0,Y.jsx)(ss,{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)(In,{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)(Ot,{placeholder:`Choose agent...`})}),(0,Y.jsx)(vo,{align:`start`,children:e.map(e=>(0,Y.jsxs)(Ye,{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 lm={data_chat:[`系统里有多少个用户?列出他们的邮箱。`,`帮我列出最近创建的 5 条记录。`,`统计每个对象的记录数。`],metadata_assistant:[`系统里注册了哪些对象类型?`,`sys_user 对象有哪些字段?`,`描述一下用户相关的对象关系。`]},um=[`What can you help me with?`,`List the available data objects.`,`Summarize my recent activity.`];function dm(e,t){if(e&&lm[e])return lm[e];let n=(e??t).toLowerCase();return n.includes(`data`)?lm.data_chat:n.includes(`metadata`)?lm.metadata_assistant:um}var fm=new Map;function pm(e){fm.set(e.ref,e)}function mm(e){return fm.get(e)}function hm(e){return(0,J.useMemo)(()=>{let t=new Ee({baseUrl:``});return e?t.withEnvironment(e):t},[e])}function gm(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 _m(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(gm(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 ym(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 bm={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`},xm={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:`分析立方体`},Sm={data:`Data`,ui:`UI`,automation:`Automation`,ai:`AI`,system:`System`,platform:`Platform`,identity:`Identity`,security:`Security`,other:`Other`},Cm={data:`数据`,ui:`界面`,automation:`自动化`,ai:`AI`,system:`系统`,platform:`平台`,identity:`身份`,security:`安全`,other:`其他`},wm={"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`},Tm={"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":`代码基线`};function Em(e){return(e??``).toLowerCase().startsWith(`zh`)?{types:xm,domains:Cm,strings:Tm}:{types:bm,domains:Sm,strings:wm}}function Dm(e,t,n){return Em(t).types[e]||(n??e)}function Om(e,t){return Em(t).domains[e]??e}function X(e,t){return Em(t).strings[e]??e}function km(e,t,n){return X(e,t).replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):`{${t}}`)}function Am(){return typeof navigator<`u`&&/^zh/i.test(navigator.language)?`zh-CN`:`en-US`}function jm({appSlug:e}={}){let t=s(),n=hm(),{entries:r}=_m(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(()=>Am(),[]);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)||Dm(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)(ft,{open:i,onOpenChange:a,children:(0,Y.jsxs)(Mt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(mo,{className:`sr-only`,children:(0,Y.jsx)(Ge,{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)(Wa,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(W,{autoFocus:!0,placeholder:X(`engine.quickfind.placeholder`,h),value:o,onChange:e=>c(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Y.jsx)(xn,{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:Dm(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)(Un,{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)(xn,{children:`↑`}),` `,(0,Y.jsx)(xn,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(xn,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(xn,{children:`⌘`}),(0,Y.jsx)(xn,{children:`⇧`}),(0,Y.jsx)(xn,{children:`M`}),` toggle`]})]})]})})}var Mm={data:Ai,ui:At,automation:Qe,ai:ra,system:yi,platform:yi,identity:ai,security:ai},Nm=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Pm=new Set([`field`]);function Fm(){let e=hm(),{loading:t,error:n,entries:r}=_m(e),a=J.useMemo(()=>Am(),[]),[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}=ym(e,`warning`,v??void 0),E=J.useMemo(()=>r.filter(e=>Pm.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)||Dm(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=Nm.indexOf(e),r=Nm.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:km(`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)(Wa,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(W,{className:`pl-8`,placeholder:X(`engine.directory.search`,a),value:o,onChange:e=>s(e.target.value)})]}),(0,Y.jsxs)(K,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[X(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.total>0&&(0,Y.jsx)(K,{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)(Tn,{className:`h-3.5 w-3.5 mr-1`}),km(`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)(xn,{children:`⌘`}),(0,Y.jsx)(xn,{children:`⇧`}),(0,Y.jsx)(xn,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(Im,{domain:`all`,label:X(`engine.directory.all`,a),active:c===`all`,count:D.all??0,onClick:()=>u(`all`)}),Nm.filter(e=>D[e]).map(e=>(0,Y.jsx)(Im,{domain:e,label:Om(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)(ut,{children:[(0,Y.jsx)(fo,{children:`No project packages installed`}),(0,Y.jsx)(kt,{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)(ut,{children:[(0,Y.jsx)(fo,{children:X(`engine.directory.noMatches`,a)}),(0,Y.jsx)(kt,{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)(Mm[e]??Bn,{className:`h-3.5 w-3.5`}),Om(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)(Lm,{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)(jm,{})]})}function Im({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 Lm({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=Dm(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:km(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":km(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,Y.jsx)(Tn,{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:km(`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:km(`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:km(`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)(Un,{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 Rm=`/api/v1/packages`;async function zm(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 Bm({scope:e}){let t=e??`project`;return(0,Y.jsx)(V,{variant:t===`project`?`default`:t===`system`?`secondary`:`outline`,children:t})}function Vm({pkg:e}){let t=e.enabled!==!1&&e.status!==`disabled`;return(0,Y.jsx)(V,{variant:t?`default`:`outline`,children:t?`enabled`:`disabled`})}var Hm=/^[a-z0-9][a-z0-9._-]{1,254}$/i,Um=/^\d+\.\d+\.\d+$/;function Wm({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=Hm.test(r),m=Um.test(s),h=p&&m&&!!a.trim()&&!l;async function g(){if(h){u(!0),f(null);try{await zm(Rm,{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)(ft,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(Ge,{children:`New Package`}),(0,Y.jsxs)(Jt,{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)(G,{htmlFor:`pkg-id`,children:`Package ID`}),(0,Y.jsx)(W,{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)(G,{htmlFor:`pkg-name`,children:`Display name`}),(0,Y.jsx)(W,{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)(G,{htmlFor:`pkg-version`,children:`Version`}),(0,Y.jsx)(W,{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)(Tn,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:d})]})]}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`outline`,onClick:()=>t(!1),disabled:l,children:`Cancel`}),(0,Y.jsx)(K,{onClick:g,disabled:!h,children:l?`Creating…`:`Create package`})]})]})})}function Gm({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 Km({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:a}){let[o,s]=J.useState(null),[c,l]=J.useState(null);if(J.useEffect(()=>{l(null),s(null)},[e?.manifest.id]),!e)return null;let u=e.manifest.id,d=e.enabled!==!1&&e.status!==`disabled`,f=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function p(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)(sn,{open:n,onOpenChange:r,children:(0,Y.jsxs)(mn,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Y.jsxs)(gt,{children:[(0,Y.jsxs)(Ft,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Si,{className:`h-4 w-4`}),e.manifest.name||u]}),(0,Y.jsx)(En,{className:`font-mono text-xs`,children:u})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(Gm,{label:`Version`,children:e.manifest.version||`—`}),(0,Y.jsx)(Gm,{label:`Type`,children:e.manifest.type||`—`}),(0,Y.jsx)(Gm,{label:`Scope`,children:(0,Y.jsx)(Bm,{scope:e.manifest.scope})}),(0,Y.jsx)(Gm,{label:`Status`,children:(0,Y.jsx)(Vm,{pkg:e})}),e.manifest.description&&(0,Y.jsx)(Gm,{label:`Description`,children:e.manifest.description})]}),(0,Y.jsx)(Qt,{className:`my-4`}),(0,Y.jsxs)(i,{to:`${t}/metadata/object?package=${encodeURIComponent(u)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,Y.jsx)(Ze,{className:`h-3.5 w-3.5`}),`Browse this package's metadata`]}),(0,Y.jsx)(Qt,{className:`my-4`}),f?(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)(K,{size:`sm`,onClick:()=>p(`publish`,()=>zm(`${Rm}/${encodeURIComponent(u)}/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)(ji,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish`?`Publishing…`:`Publish`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>p(`revert`,()=>zm(`${Rm}/${encodeURIComponent(u)}/revert`,{method:`POST`}),`Reverted to last published state.`),disabled:!!o,children:[(0,Y.jsx)(an,{className:`mr-1.5 h-3.5 w-3.5`}),`Revert`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>p(`toggle`,()=>zm(`${Rm}/${encodeURIComponent(u)}/${d?`disable`:`enable`}`,{method:`PATCH`}),d?`Package disabled.`:`Package enabled.`),disabled:!!o,children:[d?(0,Y.jsx)(qt,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Y.jsx)(jt,{className:`mr-1.5 h-3.5 w-3.5`}),d?`Disable`:`Enable`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>p(`export`,async()=>{let e=await zm(`${Rm}/${encodeURIComponent(u)}/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=`${u}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},`Package exported.`),disabled:!!o,children:[(0,Y.jsx)(nt,{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 qm(){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 zm(Rm),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 zm(`/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)(Si,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>void w(),disabled:i,children:[(0,Y.jsx)(Le,{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)(K,{variant:`outline`,size:`sm`,onClick:()=>y.current?.click(),disabled:b,children:[(0,Y.jsx)(oi,{className:`mr-1.5 h-3.5 w-3.5`}),b?`Importing…`:`Import`]}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>m(!0),children:[(0,Y.jsx)(H,{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)(Wa,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(W,{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)(Ki,{id:`show-kernel`,checked:d,onCheckedChange:f}),(0,Y.jsxs)(G,{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)(He,{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)(Tn,{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)(ut,{children:[(0,Y.jsx)(fo,{children:`No packages`}),(0,Y.jsx)(kt,{children:n.length===0?`Create your first package to start authoring metadata.`:`No packages match your filters.`})]})}):(0,Y.jsxs)(Ca,{children:[(0,Y.jsx)(ka,{children:(0,Y.jsxs)(Gr,{children:[(0,Y.jsx)(ca,{children:`Name`}),(0,Y.jsx)(ca,{children:`ID`}),(0,Y.jsx)(ca,{className:`w-24`,children:`Version`}),(0,Y.jsx)(ca,{className:`w-24`,children:`Scope`}),(0,Y.jsx)(ca,{className:`w-24`,children:`Status`})]})}),(0,Y.jsx)(Ei,{children:T.map(e=>(0,Y.jsxs)(Gr,{className:`cursor-pointer`,onClick:()=>E(e),children:[(0,Y.jsx)(Nr,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Y.jsx)(Nr,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Y.jsx)(Nr,{children:e.manifest.version||`—`}),(0,Y.jsx)(Nr,{children:(0,Y.jsx)(Bm,{scope:e.manifest.scope})}),(0,Y.jsx)(Nr,{children:(0,Y.jsx)(Vm,{pkg:e})})]},e.manifest.id))})]})}),(0,Y.jsx)(Wm,{open:p,onOpenChange:m,onCreated:async()=>{await w()}}),(0,Y.jsx)(Km,{pkg:h,appBase:t,open:_,onOpenChange:v,onChanged:()=>void w()})]})}var Jm=new Set([`field`]),Ym={data:Ai,ui:At,automation:Qe,ai:ra,system:yi,platform:yi,identity:ai,security:ai},Xm={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`}},Zm=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Qm=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],$m={object:hr,dashboard:dt,page:da,report:ci,record:Bn,metadata:At};function eh(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function th(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 nh(){let e=hm(),{loading:t,entries:n}=_m(e),{summary:r,countsByType:a,allPackages:o}=ym(e,`warning`),{recentItems:s}=To(),c=J.useMemo(()=>Am(),[]),l=J.useMemo(()=>n.filter(e=>!Jm.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])=>(Zm.indexOf(e)===-1?99:Zm.indexOf(e))-(Zm.indexOf(t)===-1?99:Zm.indexOf(t)))},[l,a]),f=J.useMemo(()=>{let e=new Map(u.map(e=>[e.type,e]));return Qm.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)(ra,{className:`h-4 w-4`}),X(eh(),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)(K,{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)(At,{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)(Wa,{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)(rh,{value:l.length,label:X(`engine.home.statTypes`,c)}),(0,Y.jsx)(rh,{value:u.length,label:X(`engine.home.statWritable`,c)}),(0,Y.jsx)(rh,{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)(ih,{icon:At,from:`from-indigo-500`,to:`to-violet-600`,value:l.length,label:X(`engine.home.statTypes`,c),to_link:`metadata`}),(0,Y.jsx)(ih,{icon:vr,from:`from-sky-500`,to:`to-blue-600`,value:u.length,label:X(`engine.home.statWritable`,c),to_link:`metadata`}),(0,Y.jsx)(ih,{icon:Si,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)(vr,{className:`h-5 w-5`}):(0,Y.jsx)(Tn,{className:`h-5 w-5`})}),(0,Y.jsx)(ht,{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)(ah,{icon:H,title:X(`engine.home.quickActions`,c),hint:X(`engine.home.quickActionsHint`,c)}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:f.map(e=>(0,Y.jsx)(K,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-dashed hover:border-solid hover:border-primary hover:bg-primary/5`,children:(0,Y.jsxs)(i,{to:`metadata/${encodeURIComponent(e.type)}/new`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),km(`engine.home.newItem`,c,{label:Dm(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)(ah,{icon:At,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)(oh,{domain:e,group:t,countsByType:a,locale:c},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(ah,{icon:Ke,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=$m[e.type]??Bn;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:th(e.visitedAt,c)})]}),(0,Y.jsx)(ht,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(jm,{})]})}function rh({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 ih({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)(ht,{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 ah({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 oh({domain:e,group:t,countsByType:n,locale:r}){let a=Ym[e]??Bn,o=Xm[e]??Xm.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:Om(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:Dm(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 sh({entry:e,itemName:t,subtitle:n,stats:r,actions:a,children:s}){let c=e?.type??``,l=J.useMemo(()=>Am(),[]),u=Dm(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)(ea,{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)(ea,{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:Om(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)(ea,{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:Om(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 ch={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function lh(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 uh({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=lh(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?dc(e.icon):null,n=i===e.name;return(0,Y.jsxs)(K,{size:`sm`,variant:ch[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 dh(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 ph(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 mh(e){return fh.get(e)}function hh(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 gh(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 _h(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=mh(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(yh,{type:n})}function yh({type:e}){let t=s(),n=hm(),{entries:r}=_m(n),a=r.find(t=>t.type===e),o=gh(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:_h(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??bh(o.primaryKey??`name`),M=Am(),ne=Dm(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)(sh,{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)(Tn,{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)(Tn,{className:`w-3.5 h-3.5`}),ee]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(uh,{entry:a,location:`list_toolbar`,onAfter:()=>S(e=>e+1)}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>S(e=>e+1),title:X(`engine.list.refresh`,M),children:(0,Y.jsx)(Le,{className:`h-4 w-4`})}),(a?.allowOrgOverride||a?.allowRuntimeCreate)&&(0,Y.jsxs)(K,{size:`sm`,variant:o.createFields?`default`:`outline`,onClick:()=>t(`./new${D}`),title:o.createFields?km(`engine.list.createHint`,M,{type:ne}):void 0,children:[(0,Y.jsx)(H,{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)(Wa,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(W,{className:`pl-8`,placeholder:X(`engine.list.search`,M),value:h,onChange:e=>g(e.target.value)})]}),(0,Y.jsxs)(In,{value:_,onValueChange:v,children:[(0,Y.jsx)(nr,{className:`w-[180px]`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsxs)(vo,{children:[(0,Y.jsxs)(Ye,{value:`all`,children:[X(`engine.list.allSources`,M),` (`,A.all,`)`]}),(0,Y.jsxs)(Ye,{value:`artifact`,children:[X(`engine.list.source.artifact`,M),` (`,A.artifact,`)`]}),(0,Y.jsxs)(Ye,{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)(ut,{children:[(0,Y.jsx)(fo,{children:`No project packages installed`}),(0,Y.jsx)(kt,{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)(ut,{children:[(0,Y.jsx)(fo,{children:c.length===0?km(`engine.list.emptyType`,M,{type:ne}):km(`engine.list.emptyQuery`,M,{query:h})}),(0,Y.jsx)(kt,{children:o.emptyStateHint??(a?.allowOrgOverride||a?.allowRuntimeCreate?km(`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)(K,{onClick:()=>t(`./new${D}`),children:[(0,Y.jsx)(H,{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
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):xh(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:`${km(`engine.list.invalidCount`,M,{count:s.length})}\n${u}`,children:(0,Y.jsx)(Tn,{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:`${km(`engine.list.warnCount`,M,{count:c.length})}\n${u}`,children:(0,Y.jsx)(Tn,{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)(Un,{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 bh(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function xh(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 Sh={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 Ch(e,t){let n=wh(e)?e:{},r=wh(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`:Th(o)===Th(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 wh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Th(e){try{return JSON.stringify(e,(e,t)=>wh(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Eh(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 Dh(e,t){if(e==null)return 0;let n=0;for(let r of Ch(e,t))r.status!==`unchanged`&&(n+=1);return n}function Oh({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)(Fa,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(ta,{value:`diff`,children:X(`engine.layers.diff`,n)}),(0,Y.jsxs)(ta,{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)(ta,{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)(ta,{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)(ri,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(kh,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(ri,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.code,emptyHint:X(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(ri,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.overlay,emptyHint:X(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(ri,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function kh({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(()=>Ch(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:km(`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)(Ki,{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=Sh[e.status];return(0,Y.jsxs)(`div`,{className:U(`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)(Ah,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)(Ah,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:U(`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 Ah({value:e,muted:t}){let n=Eh(e);return(0,Y.jsx)(`div`,{className:U(`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 jh({payload:e,emptyHint:t}){if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,Y.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}function Mh(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return Nh(n.trim(),t)}catch{return!0}}function Nh(e,t){let n=Ph(e,`||`);if(n.length>1)return n.some(e=>Nh(e.trim(),t));let r=Ph(e,`&&`);if(r.length>1)return r.every(e=>Nh(e.trim(),t));if(e.startsWith(`!`))return!Nh(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=Fh(i[1].trim(),t),n=Ih(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=Fh(a[1].trim(),t),n=Ih(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!Fh(e,t)}function Ph(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 Fh(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return Ih(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function Ih(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 Lh({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectNames??[],o=t==null?``:String(t);return i?.objectsLoading?(0,Y.jsx)(W,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,Y.jsx)(W,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,Y.jsxs)(In,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select object…`})}),(0,Y.jsx)(vo,{children:a.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}function Rh({id:e,value:t,onChange:n,readOnly:r,context:i,fieldSpec:a}){let o=i?.objectNames??[],s=a?.multiple??!1,c=J.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),l=e=>{if(!r){if(!s){n(e);return}n(c.includes(e)?c.filter(t=>t!==e):[...c,e])}},u=e=>{if(r)return;let t=c.filter(t=>t!==e);n(s?t:``)};return i?.objectsLoading?(0,Y.jsx)(W,{id:e,value:`Loading objects...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[c.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:e}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e))}),(0,Y.jsxs)(In,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:s?`Add objects...`:`Select object...`})}),(0,Y.jsx)(vo,{children:o.map(e=>(0,Y.jsxs)(Ye,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function zh({id:e,value:t,onChange:n,readOnly:r,fieldSpec:i,formData:a}){let[o,s]=J.useState([]),[c,l]=J.useState(!1),u=i?.dependsOn||i?.reference||`objectName`,d=Array.isArray(u)?u[0]:u,f=a?.[d];J.useEffect(()=>{if(!f){s([]);return}l(!0),fetch(`/api/v1/objects/${f}/fields`).then(e=>e.json()).then(e=>{s(e.fields||[]),l(!1)}).catch(e=>{console.error(`Failed to load fields:`,e),s([]),l(!1)})},[f]);let p=i?.multiple??!1,m=J.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),h=e=>{if(!r){if(!p){n(e);return}n(m.includes(e)?m.filter(t=>t!==e):[...m,e])}},g=e=>{if(r)return;let t=m.filter(t=>t!==e);n(p?t:``)};return f?c?(0,Y.jsx)(W,{id:e,value:`Loading fields...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[m.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>{let t=o.find(t=>t.name===e);return(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:t?.label||e}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:t?.type}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e)})}),(0,Y.jsxs)(In,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:p?`Add fields...`:`Select field...`})}),(0,Y.jsx)(vo,{children:o.map(e=>(0,Y.jsx)(Ye,{value:e.name,disabled:!p&&m.includes(e.name),children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.type}),m.includes(e.name)&&` ✓`]})},e.name))})]})]}):(0,Y.jsx)(W,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function Bh({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)(Vh,{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)(K,{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)(Xt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:r,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function Vh({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,Y.jsx)(Lh,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,Y.jsxs)(In,{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)(Ot,{placeholder:`—`})}),(0,Y.jsx)(vo,{children:a.map(e=>(0,Y.jsx)(Ye,{value:String(e),children:String(e)},String(e)))})]}):e?.type===`boolean`?(0,Y.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:n,onChange:e=>i(e.target.checked),className:`h-4 w-4`}):e?.type===`number`||e?.type===`integer`?(0,Y.jsx)(W,{type:`number`,value:t==null?``:String(t),disabled:n,onChange:e=>{let t=e.target.valueAsNumber;i(Number.isFinite(t)?t:void 0)},className:`h-8 text-xs`}):(0,Y.jsx)(W,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function Hh({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 Uh=`__none__`;function Wh({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)(In,{value:o||Uh,onValueChange:e=>n(e===Uh?``:e),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:a.length?`Select field…`:`No object bound`})}),(0,Y.jsxs)(vo,{children:[(0,Y.jsx)(Ye,{value:Uh,children:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`— None —`})}),!s&&o&&(0,Y.jsxs)(Ye,{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)(Ye,{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 Gh({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)(In,{value:``,onValueChange:l,disabled:c.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:a.length?c.length?`Add field…`:`All fields added`:`No object bound`})}),(0,Y.jsx)(vo,{children:c.map(e=>(0,Y.jsx)(Ye,{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 Kh={"ref:object":Lh,"object-selector":Rh,"field-selector":zh,"field-ref":Wh,"field-multi":Gh,"master-detail":Bh,"string-tags":Hh,code:Yh,"filter-builder":Bh};function qh(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 Jh=J.lazy(()=>c(()=>import(`./src-AD-6EnzK.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function Yh({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=qh(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)(Jh,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var Xh=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function Zh(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 Qh(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 $h(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 eg({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=ug(n);else return(0,Y.jsx)(lg,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=pg(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)(ng,{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)(rg,{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 tg(e){return typeof e==`string`?{field:e}:e}function ng({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||Mh(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(tg).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!Mh(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)(rg,{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(tg).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||Mh(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)(Fa,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,Y.jsx)(ta,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,Y.jsx)(ri,{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 rg({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||fg(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=Qh(o,t);if(!o?.widget){let n=$h(e,t,s);n&&(p=n)}let m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=fg(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)(G,{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)(ig,{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)(G,{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)(ig,{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 ig({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)(og,{value:n,fields:o.fields?.length?o.fields:mg(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,Y.jsx)(sg,{value:n,fields:o.fields?.length?o.fields:mg(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(o?.type===`record`){let e=t?.additionalProperties??{};return(0,Y.jsx)(cg,{value:n,fields:o.fields?.length?o.fields:mg(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,keyField:o.keyField,formData:c,onChange:r})}if(a){let l=Kh[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=Zh(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)(eg,{schema:u,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(u?.type===`array`&&u.items&&typeof u.items==`object`){let e=Zh(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)(sg,{value:n,fields:mg(e),schema:{...u,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}if(!Xh.has(a))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(lg,{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=Zh(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)(In,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select…`})}),(0,Y.jsx)(vo,{children:d.map(e=>(0,Y.jsxs)(Ye,{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)(In,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select…`})}),(0,Y.jsx)(vo,{children:f.map(e=>(0,Y.jsx)(Ye,{value:String(e),children:String(e)},String(e)))})]});if(u===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,Y.jsx)(Ki,{id:e,checked:!!n,onCheckedChange:e=>r(e),disabled:i});if(u===`number`||u===`integer`){let t=o?.min,a=o?.max;return(0,Y.jsx)(W,{id:e,type:`number`,value:n==null?``:String(n),min:t,max:a,onChange:e=>{let t=e.target.value;if(t===``)return r(void 0);let n=u===`integer`?parseInt(t,10):Number(t);r(Number.isFinite(n)?n:void 0)},readOnly:i})}if(u===`string`){let t=o?.maxLength;return l?.format===`multiline`||l?.contentMediaType===`text/markdown`||typeof n==`string`&&n.length>80?(0,Y.jsx)(Dn,{id:e,rows:4,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,Y.jsx)(W,{id:e,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i})}if(u===`array`){let t=l?.items??{};if(t.type===`string`||t.type===`number`||t.type===`integer`)return(0,Y.jsx)(W,{id:e,value:(Array.isArray(n)?n:[]).map(String).join(`, `),placeholder:`comma, separated, values`,onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean);t.type===`number`||t.type===`integer`?r(n.map(e=>Number(e)).filter(e=>Number.isFinite(e))):r(n)},readOnly:i})}if(l?.type===`object`&&l.properties&&typeof l.properties==`object`)return(0,Y.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,Y.jsx)(eg,{schema:l,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(l?.type===`array`&&l.items&&typeof l.items==`object`){let e=Zh(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)(sg,{value:n,fields:mg(e),schema:{...l,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}return(0,Y.jsx)(lg,{value:n,onChange:r,readOnly:i,small:!0})}function ag(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 og({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(tg).map(e=>{let t=ag(n,`composite`,e.field);return(0,Y.jsx)(rg,{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 sg({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(tg),[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||fg(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`,Am())})}),s.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=ag(n,`repeater`,a.field);return(0,Y.jsx)(`td`,{className:`p-1.5`,children:(0,Y.jsx)(ig,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:Qh(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)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),!r&&(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:X(`engine.list.empty`,Am())}),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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{className:`h-3.5 w-3.5`}),(0,Y.jsxs)(`span`,{className:`truncate`,children:[`#`,t+1,o==null?``:` — ${String(o)}`]})]}),!r&&(0,Y.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=ag(n,`repeater`,a.field);return(0,Y.jsx)(rg,{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)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function cg({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,keyField:o,formData:s,onChange:c}){if(a){let o=Kh[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??fg(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(tg).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`,Am())}),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)(On,{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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(e),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(rg,{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&&!Mh(a.visibleOn,{data:t}))return null;let o=ag(n,`record`,a.field);return(0,Y.jsx)(rg,{name:a.field,schema:o,value:t?.[a.field],required:!!a.required,readOnly:r||a.readonly,fieldSpec:a,widgetContext:i,formData:t,onChange:t=>C(e,{[a.field]:t})},a.field)})]})]},e)}),!r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{value:v,onChange:e=>{y(e.target.value),b&&x(null)},placeholder:o?.placeholder??u,className:`h-8 text-xs font-mono max-w-[220px]`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:E,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]}),b&&(0,Y.jsx)(`span`,{className:`text-xs text-destructive`,children:b})]})]})}function lg({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=J.useState(()=>dg(e)),[o,s]=J.useState(null);return J.useEffect(()=>{a(dg(e)),s(null)},[JSON.stringify(e)]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(Dn,{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 ug(e){let t={};for(let[n,r]of Object.entries(e))if(!n.startsWith(`_`))if(r==null)t[n]={type:`string`};else if(typeof r==`string`)t[n]=r.length>80||r.includes(`
|
|
15
|
+
`)+(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):xh(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:`${km(`engine.list.invalidCount`,M,{count:s.length})}\n${u}`,children:(0,Y.jsx)(Tn,{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:`${km(`engine.list.warnCount`,M,{count:c.length})}\n${u}`,children:(0,Y.jsx)(Tn,{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)(Un,{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 bh(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function xh(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 Sh={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 Ch(e,t){let n=wh(e)?e:{},r=wh(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`:Th(o)===Th(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 wh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Th(e){try{return JSON.stringify(e,(e,t)=>wh(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Eh(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 Dh(e,t){if(e==null)return 0;let n=0;for(let r of Ch(e,t))r.status!==`unchanged`&&(n+=1);return n}function Oh({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)(Fa,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(ta,{value:`diff`,children:X(`engine.layers.diff`,n)}),(0,Y.jsxs)(ta,{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)(ta,{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)(ta,{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)(ri,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(kh,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(ri,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.code,emptyHint:X(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(ri,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.overlay,emptyHint:X(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(ri,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(jh,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function kh({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(()=>Ch(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:km(`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)(Ki,{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=Sh[e.status];return(0,Y.jsxs)(`div`,{className:U(`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)(Ah,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)(Ah,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:U(`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 Ah({value:e,muted:t}){let n=Eh(e);return(0,Y.jsx)(`div`,{className:U(`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 jh({payload:e,emptyHint:t}){if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,Y.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}function Mh(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return Nh(n.trim(),t)}catch{return!0}}function Nh(e,t){let n=Ph(e,`||`);if(n.length>1)return n.some(e=>Nh(e.trim(),t));let r=Ph(e,`&&`);if(r.length>1)return r.every(e=>Nh(e.trim(),t));if(e.startsWith(`!`))return!Nh(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=Fh(i[1].trim(),t),n=Ih(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=Fh(a[1].trim(),t),n=Ih(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!Fh(e,t)}function Ph(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 Fh(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return Ih(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function Ih(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 Lh({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectNames??[],o=t==null?``:String(t);return i?.objectsLoading?(0,Y.jsx)(W,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,Y.jsx)(W,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,Y.jsxs)(In,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select object…`})}),(0,Y.jsx)(vo,{children:a.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}function Rh({id:e,value:t,onChange:n,readOnly:r,context:i,fieldSpec:a}){let o=i?.objectNames??[],s=a?.multiple??!1,c=J.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),l=e=>{if(!r){if(!s){n(e);return}n(c.includes(e)?c.filter(t=>t!==e):[...c,e])}},u=e=>{if(r)return;let t=c.filter(t=>t!==e);n(s?t:``)};return i?.objectsLoading?(0,Y.jsx)(W,{id:e,value:`Loading objects...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[c.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:e}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e))}),(0,Y.jsxs)(In,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:s?`Add objects...`:`Select object...`})}),(0,Y.jsx)(vo,{children:o.map(e=>(0,Y.jsxs)(Ye,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function zh({id:e,value:t,onChange:n,readOnly:r,fieldSpec:i,formData:a}){let[o,s]=J.useState([]),[c,l]=J.useState(!1),u=i?.dependsOn||i?.reference||`objectName`,d=Array.isArray(u)?u[0]:u,f=a?.[d];J.useEffect(()=>{if(!f){s([]);return}l(!0),fetch(`/api/v1/objects/${f}/fields`).then(e=>e.json()).then(e=>{s(e.fields||[]),l(!1)}).catch(e=>{console.error(`Failed to load fields:`,e),s([]),l(!1)})},[f]);let p=i?.multiple??!1,m=J.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),h=e=>{if(!r){if(!p){n(e);return}n(m.includes(e)?m.filter(t=>t!==e):[...m,e])}},g=e=>{if(r)return;let t=m.filter(t=>t!==e);n(p?t:``)};return f?c?(0,Y.jsx)(W,{id:e,value:`Loading fields...`,readOnly:!0,disabled:!0}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[m.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>{let t=o.find(t=>t.name===e);return(0,Y.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:t?.label||e}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:t?.type}),!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e)})}),(0,Y.jsxs)(In,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:p?`Add fields...`:`Select field...`})}),(0,Y.jsx)(vo,{children:o.map(e=>(0,Y.jsx)(Ye,{value:e.name,disabled:!p&&m.includes(e.name),children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.type}),m.includes(e.name)&&` ✓`]})},e.name))})]})]}):(0,Y.jsx)(W,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function Bh({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)(Vh,{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)(K,{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)(Xt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:r,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function Vh({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,Y.jsx)(Lh,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,Y.jsxs)(In,{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)(Ot,{placeholder:`—`})}),(0,Y.jsx)(vo,{children:a.map(e=>(0,Y.jsx)(Ye,{value:String(e),children:String(e)},String(e)))})]}):e?.type===`boolean`?(0,Y.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:n,onChange:e=>i(e.target.checked),className:`h-4 w-4`}):e?.type===`number`||e?.type===`integer`?(0,Y.jsx)(W,{type:`number`,value:t==null?``:String(t),disabled:n,onChange:e=>{let t=e.target.valueAsNumber;i(Number.isFinite(t)?t:void 0)},className:`h-8 text-xs`}):(0,Y.jsx)(W,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function Hh({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 Uh=`__none__`;function Wh({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)(In,{value:o||Uh,onValueChange:e=>n(e===Uh?``:e),disabled:r,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:a.length?`Select field…`:`No object bound`})}),(0,Y.jsxs)(vo,{children:[(0,Y.jsx)(Ye,{value:Uh,children:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`— None —`})}),!s&&o&&(0,Y.jsxs)(Ye,{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)(Ye,{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 Gh({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)(In,{value:``,onValueChange:l,disabled:c.length===0,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:a.length?c.length?`Add field…`:`All fields added`:`No object bound`})}),(0,Y.jsx)(vo,{children:c.map(e=>(0,Y.jsx)(Ye,{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 Kh={"ref:object":Lh,"object-selector":Rh,"field-selector":zh,"field-ref":Wh,"field-multi":Gh,"master-detail":Bh,"string-tags":Hh,code:Yh,"filter-builder":Bh};function qh(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 Jh=J.lazy(()=>c(()=>import(`./src-CwB7sUUJ.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function Yh({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=qh(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)(Jh,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var Xh=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function Zh(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 Qh(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 $h(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 eg({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=ug(n);else return(0,Y.jsx)(lg,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=pg(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)(ng,{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)(rg,{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 tg(e){return typeof e==`string`?{field:e}:e}function ng({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||Mh(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(tg).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!Mh(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)(rg,{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(tg).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||Mh(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)(Fa,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,Y.jsx)(ta,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,Y.jsx)(ri,{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 rg({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||fg(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=Qh(o,t);if(!o?.widget){let n=$h(e,t,s);n&&(p=n)}let m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=fg(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)(G,{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)(ig,{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)(G,{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)(ig,{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 ig({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)(og,{value:n,fields:o.fields?.length?o.fields:mg(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,Y.jsx)(sg,{value:n,fields:o.fields?.length?o.fields:mg(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(o?.type===`record`){let e=t?.additionalProperties??{};return(0,Y.jsx)(cg,{value:n,fields:o.fields?.length?o.fields:mg(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,keyField:o.keyField,formData:c,onChange:r})}if(a){let l=Kh[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=Zh(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)(eg,{schema:u,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(u?.type===`array`&&u.items&&typeof u.items==`object`){let e=Zh(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)(sg,{value:n,fields:mg(e),schema:{...u,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}if(!Xh.has(a))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(lg,{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=Zh(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)(In,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select…`})}),(0,Y.jsx)(vo,{children:d.map(e=>(0,Y.jsxs)(Ye,{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)(In,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,Y.jsx)(nr,{id:e,children:(0,Y.jsx)(Ot,{placeholder:`Select…`})}),(0,Y.jsx)(vo,{children:f.map(e=>(0,Y.jsx)(Ye,{value:String(e),children:String(e)},String(e)))})]});if(u===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,Y.jsx)(Ki,{id:e,checked:!!n,onCheckedChange:e=>r(e),disabled:i});if(u===`number`||u===`integer`){let t=o?.min,a=o?.max;return(0,Y.jsx)(W,{id:e,type:`number`,value:n==null?``:String(n),min:t,max:a,onChange:e=>{let t=e.target.value;if(t===``)return r(void 0);let n=u===`integer`?parseInt(t,10):Number(t);r(Number.isFinite(n)?n:void 0)},readOnly:i})}if(u===`string`){let t=o?.maxLength;return l?.format===`multiline`||l?.contentMediaType===`text/markdown`||typeof n==`string`&&n.length>80?(0,Y.jsx)(Dn,{id:e,rows:4,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,Y.jsx)(W,{id:e,value:n??``,maxLength:t,onChange:e=>r(e.target.value||void 0),readOnly:i})}if(u===`array`){let t=l?.items??{};if(t.type===`string`||t.type===`number`||t.type===`integer`)return(0,Y.jsx)(W,{id:e,value:(Array.isArray(n)?n:[]).map(String).join(`, `),placeholder:`comma, separated, values`,onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean);t.type===`number`||t.type===`integer`?r(n.map(e=>Number(e)).filter(e=>Number.isFinite(e))):r(n)},readOnly:i})}if(l?.type===`object`&&l.properties&&typeof l.properties==`object`)return(0,Y.jsx)(`div`,{className:`rounded-md border border-border/40 bg-card/30 p-3`,children:(0,Y.jsx)(eg,{schema:l,value:n??{},onChange:e=>r(e),readOnly:i,widgetContext:s})});if(l?.type===`array`&&l.items&&typeof l.items==`object`){let e=Zh(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)(sg,{value:n,fields:mg(e),schema:{...l,items:e},readOnly:i,widgetContext:s,widget:o?.widget,onChange:r})}return(0,Y.jsx)(lg,{value:n,onChange:r,readOnly:i,small:!0})}function ag(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 og({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(tg).map(e=>{let t=ag(n,`composite`,e.field);return(0,Y.jsx)(rg,{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 sg({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(tg),[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||fg(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`,Am())})}),s.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=ag(n,`repeater`,a.field);return(0,Y.jsx)(`td`,{className:`p-1.5`,children:(0,Y.jsx)(ig,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:Qh(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)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),!r&&(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:X(`engine.list.empty`,Am())}),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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{className:`h-3.5 w-3.5`}),(0,Y.jsxs)(`span`,{className:`truncate`,children:[`#`,t+1,o==null?``:` — ${String(o)}`]})]}),!r&&(0,Y.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=ag(n,`repeater`,a.field);return(0,Y.jsx)(rg,{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)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function cg({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,keyField:o,formData:s,onChange:c}){if(a){let o=Kh[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??fg(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(tg).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`,Am())}),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)(On,{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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(e),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})})]}),a&&(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(rg,{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&&!Mh(a.visibleOn,{data:t}))return null;let o=ag(n,`record`,a.field);return(0,Y.jsx)(rg,{name:a.field,schema:o,value:t?.[a.field],required:!!a.required,readOnly:r||a.readonly,fieldSpec:a,widgetContext:i,formData:t,onChange:t=>C(e,{[a.field]:t})},a.field)})]})]},e)}),!r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{value:v,onChange:e=>{y(e.target.value),b&&x(null)},placeholder:o?.placeholder??u,className:`h-8 text-xs font-mono max-w-[220px]`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:E,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5 mr-1`}),` Add`]}),b&&(0,Y.jsx)(`span`,{className:`text-xs text-destructive`,children:b})]})]})}function lg({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=J.useState(()=>dg(e)),[o,s]=J.useState(null);return J.useEffect(()=>{a(dg(e)),s(null)},[JSON.stringify(e)]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(Dn,{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 ug(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
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 dg(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function fg(e){return e.replace(/[_-]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function pg(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 mg(e){let t=e?.properties??{};return Object.keys(t)}function hg(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 _g(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function vg(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function yg(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return hg(n);case`plural-en`:return gg(n);case`titlecase`:return _g(n);case`first-token`:return vg(n);default:return n}}function bg(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=yg(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 Sg({type:e,name:t,parentItem:n,onOpen:r}){let i=hm(),a=s(),o=J.useMemo(()=>hh(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(Cg)}}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=>Cg(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)(ut,{children:[(0,Y.jsx)(fo,{children:`No related metadata`}),(0,Y.jsxs)(kt,{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)(Wa,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(W,{placeholder:`Search related…`,value:u,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),c.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,o=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!o})),children:[(0,Y.jsx)(ea,{className:U(`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)(K,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>{if(n.anchor.source===`embedded`){if(typeof window<`u`){let e=new URL(window.location.href);e.searchParams.set(`tab`,`form`),e.searchParams.delete(`open`),window.location.assign(e.toString())}return}a(`../../${encodeURIComponent(n.childType)}/_new?anchor=${encodeURIComponent(`${e}:${t}`)}`)},title:n.anchor.source===`embedded`?`Edit in Form tab`:`New ${n.childType}`,children:(0,Y.jsx)(H,{className:`h-3.5 w-3.5`})})]}),!o&&(0,Y.jsxs)(`div`,{children:[n.loading&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(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)(Ze,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function Cg(e){return{name:wg(e,[`name`,`id`,`key`])??`(unnamed)`,label:wg(e,[`label`,`title`,`displayName`]),description:wg(e,[`description`,`summary`]),raw:e}}function wg(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function Tg({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=hm(),{entries:c}=_m(s),l=i?c.find(e=>e.type===i):void 0,u=!l?.schema&&i?Dg[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=Eg(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)(eg,{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)(K,{onClick:w,disabled:h||!n,children:[h?(0,Y.jsx)(B,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(to,{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)(Tn,{className:`h-4 w-4 inline mr-1`}),` `,_]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsxs)(K,{onClick:w,disabled:h||!n,children:[h?(0,Y.jsx)(B,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(to,{className:`h-4 w-4 mr-1`}),`Save into parent`]})})]})}function Eg(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 Dg={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 Og({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)(sn,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)(mn,{side:`right`,className:U(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Y.jsxs)(gt,{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)(Ft,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,Y.jsx)(Ze,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Y.jsxs)(En,{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)(x_,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,Y.jsx)(Tg,{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 kg({type:e,name:t}){let n=f(),r=e??n.type??``,i=t??n.name??``,a=s(),o=hm(),{entries:c}=_m(o),l=c.find(e=>e.type===r),[u,d]=J.useState(0),[p,m]=J.useState(0);return(0,Y.jsx)(sh,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>a(`../${encodeURIComponent(i)}`),children:[(0,Y.jsx)(Zt,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>d(e=>e+1),children:(0,Y.jsx)(Le,{className:`h-4 w-4`})})]}),children:(0,Y.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Y.jsx)(Ag,{type:r,name:i,refreshKey:u,onCount:m,client:o,onRollback:()=>d(e=>e+1)})})})}function Ag({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)(ut,{children:[(0,Y.jsx)(fo,{children:`No history yet`}),(0,Y.jsx)(kt,{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:jg(i)}),o&&(0,Y.jsx)(K,{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)(Wn,{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:Mg(e)})]})]},`${e.seq??t}-${t}`)})})]})}function jg(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function Mg(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Ng(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Pg(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:ai},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:La},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:ua}},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 Fg({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)(K,{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)(Le,{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)(ut,{className:`py-10`,children:[(0,Y.jsx)(fo,{children:X(`engine.edit.auditEmptyTitle`,r)}),(0,Y.jsx)(kt,{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:Ng(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:Pg(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 Ig=new Map;function Lg(e,t){Ig.set(e,t)}function Rg(e){return Ig.get(e)}var zg=new Map;function Bg(e,t){zg.set(e,t)}function Vg(e){return zg.get(e)}var Hg=new Map;function Ug(e,t){Hg.set(e,t)}function Wg(e){return Hg.get(e)}function Gg(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&&Jg(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Jg(e.charCodeAt(r)))for(r++;r<e.length&&Jg(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&&Jg(e.charCodeAt(r))){for(r++;r<e.length&&Jg(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
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(qg(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(Kg(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Kg(t));return o=15}if(qg(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
18
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&&!qg(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++,qg(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||!Jg(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(Kg(e)||qg(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 Kg(e){return e===32||e===9}function qg(e){return e===10||e===13}function Jg(e){return e>=48&&e<=57}var Yg;(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`})(Yg||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var Xg=200;Array(Xg).fill(0).map((e,t)=>`
|
|
19
19
|
`+` `.repeat(t)),Array(Xg).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Xg).fill(0).map((e,t)=>`\r
|
|
20
20
|
`+` `.repeat(t)),Array(Xg).fill(0).map((e,t)=>`
|
|
21
21
|
`+` `.repeat(t)),Array(Xg).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Xg).fill(0).map((e,t)=>`\r
|
|
22
|
-
`+` `.repeat(t));var Zg;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Zg||={});function Qg(e,t=[],n=Zg.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}e_(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:t_(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 $g(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 e_(e,t,n=Zg.DEFAULT){let r=Gg(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 t_(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 n_;(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`})(n_||={});var r_;(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`})(r_||={});var i_=Qg,a_=$g,o_;(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`})(o_||={});var s_=J.lazy(async()=>({default:(await c(()=>import(`./dist-Dal4BOHf.js`),[],import.meta.url)).default}));function c_(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function l_(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function u_({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let[a,o]=J.useState(()=>c_(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=i_(a)}catch{i=void 0}let o=r.map(e=>{let r=l_(e.path),a=1,o=1,s=1,c=2,l=i?a_(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=c_(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)(He,{className:`w-full h-full`}),children:(0,Y.jsx)(s_,{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 d_={object:async()=>(await c(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await c(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await c(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await c(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await c(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await c(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await c(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await c(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await c(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await c(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await c(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await c(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.a);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await c(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.a);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await c(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await c(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await c(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await c(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await c(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await c(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await c(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await c(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.o);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},f_=new Set([`approval`,`connector_action`]),p_=/^nodes\.(\d+)\.type$/;function m_(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 h_=new Map;async function g_(e){if(h_.has(e))return h_.get(e)??null;let t=d_[e];if(!t)return h_.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return h_.set(e,r),r}catch{return h_.set(e,null),null}}function __(e){return e in d_}async function v_(e,t){let n=await g_(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=p_.exec(n);if(!r)return!0;let i=m_(t,Number(r[1]));return!(i&&f_.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 y_=ya;function b_(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 x_({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=f(),a=e??i.type??``,o=t??i.name??``,s=mh(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)(S_,{type:a,name:o,createMode:n,embedded:r})}function S_({type:e,name:t,createMode:n,embedded:r}){let i=s(),a=hm(),{entries:o}=_m(a),c=o.find(t=>t.type===e),l=gh(e,c),u=(n&&l.createSchema?l.createSchema:c?.schema)??l.defaultSchema,d=J.useMemo(()=>Am(),[]),[f,p]=J.useState(null),m=l.identityField??`name`,[h,g]=J.useState(()=>n?{...l.createDefaults??{},[m]:``}:{}),[_,v]=J.useState(null),[y,b]=J.useState(!n),[x,S]=J.useState(!1),[C,w]=J.useState(null),[T,E]=J.useState([]),D=J.useCallback(e=>{g(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&E(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[O,k]=J.useState(null),[A,j]=J.useState(null),ee=J.useCallback(e=>{D(t=>({...t,...e}))},[D]),{markTouched:te}=bg({rules:l.createDerive,draft:h,onPatch:ee,enabled:!!n}),M=J.useMemo(()=>{if(n)return l.createFields&&l.createFields.length>0?l.createFields:xg(u?.properties??void 0,u?.required??void 0)},[n,l.createFields,u]),ne=J.useMemo(()=>{if(!n||!M)return l.hiddenFields;let e=u?.properties??{},t=new Set(M),r=Object.keys(e).filter(e=>!t.has(e));if(l.hiddenFields)for(let e of l.hiddenFields)r.includes(e)||r.push(e);return r},[n,M,u,l.hiddenFields]),N=J.useMemo(()=>n&&M?M:l.fieldOrder,[n,M,l.fieldOrder]),re=J.useCallback(e=>{if(n){let t=h,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||te(e)}D(e)},[n,h,D,te]);J.useEffect(()=>{if(!__(e))return;let t=!1,n=window.setTimeout(()=>{v_(e,h).then(e=>{t||E(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,h]);let[ie,ae]=J.useState(!1),[oe,P]=J.useState(!1),[se,ce]=J.useState(0),[F,le]=J.useState(!!n),[ue,de]=J.useState(null);J.useEffect(()=>{de(null)},[e,t]),J.useEffect(()=>{F||de(null)},[F]);let fe=J.useRef(null),[pe,me]=J.useState(null),[I,he]=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`,I?`1`:`0`)}catch{}},[I]);let ge=J.useRef(null),[_e,L]=J.useState([]),[ve,R]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`object`);if(e)return;L(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||L([])}finally{e||R(!1)}})(),()=>{e=!0}},[a]);let ye=J.useMemo(()=>({objectNames:_e,objectsLoading:ve}),[_e,ve]);J.useEffect(()=>{if(n){b(!1);return}let r=!1;return b(!0),w(null),(async()=>{try{let[n,i]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);if(r)return;p(n);let o=n?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?E(o.errors.map(e=>({path:e.path||``,message:e.message}))):E([]);let s=b_(i),c=s??n.effective??n.code??{},u=l.toDraft?l.toDraft(c):c;g(u),fe.current=u,ae(!!s),b(!1)}catch(e){r||(w(e?.message??String(e)),b(!1))}})(),()=>{r=!0}},[a,e,t,n,se]);let[be,z]=J.useState(!1);async function xe(){if(!(_!=null||be)){z(!0);try{v(await a.references(e,t))}catch(e){v([]),console.error(`references() failed`,e)}finally{z(!1)}}}let[Se,Ce]=J.useState(null),we=J.useMemo(()=>!n&&!r&&hh(e).length>0,[e,n,r]),Te=J.useRef(null),[Ee,De]=J.useState(null),[Oe,ke]=J.useState(`properties`);J.useEffect(()=>{if(Ee===`references`&&xe(),typeof window<`u`&&!r){let e=new URL(window.location.href);Ee?e.searchParams.set(`tab`,Ee):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[Ee,r]);let Ae=`metadata-edit:inspector-collapsed`,je=`metadata-edit:inspector-size`,[Me,Ne]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Ae)===`1`),Pe=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(je));Number.isFinite(e)&&e>=22&&e<=80&&(Pe.current=e)},[]);let Fe=J.useRef(null),Ie=J.useCallback(()=>{Ne(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Ae,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=Fe.current;if(e)if(Me)e.resize?.(`0%`);else{let t=Pe.current||38;e.resize?.(`${t}%`)}},[Me]);let[Le,Re]=J.useState(!1),[ze,Be]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!ze)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[ze]),J.useEffect(()=>{if(typeof window>`u`||!ze)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Be(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ze]);let Ve=J.useRef(null);J.useEffect(()=>{Ve.current=null},[e,t]),J.useEffect(()=>{if(n||r||y)return;let i=`${e}/${t??``}`;Ve.current!==i&&Rg(e)&&(f?.code==null?c?.allowOrgOverride||c?.allowRuntimeCreate:c?.allowOrgOverride)&&(Ve.current=i,le(!0))},[e,t,n,r,y,c,f]),J.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),Ie())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Ie]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&De(t),Te.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&Ce({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);Se?.kind===`metadata`?e.searchParams.set(`open`,`${Se.type}:${Se.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[Se,r]);async function He(r){S(!0),w(null),E([]);try{let o=n?l.createBuildBody?l.createBuildBody(h):{...l.createDefaults??{},...h}:l.fromDraft?l.fromDraft(h):h,s=String(o[m]??h[m]??t),c=n?{...o,[m]:s}:o;if(!s){w(`A name is required.`),S(!1);return}let u=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await a.save(e,s,c,{force:r,mode:`draft`,...u?{packageId:u}:{}});let[d,f]=await Promise.all([a.layered(e,s),a.getDraft(e,s).catch(()=>null)]);p(d);let _=b_(f);ae(!!_);let v=_??d.effective??c,y=l.toDraft?l.toDraft(v):v;g(y),fe.current=y,me(new Date),ge.current=JSON.stringify(y),k(null),j(null);let b=!n&&!!Rg(e);!n&&!b&&le(!1),n&&i(`../${encodeURIComponent(s)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];k(Array.isArray(t)?t:[]),j(h)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:String(e.message??`Invalid`)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:e[2].trim()}]:[{path:``,message:r}]}E(n),n.length===1&&!n[0].path?w(n[0].message):n.length===1?w(`${n[0].path}: ${n[0].message}`):w(`Validation failed (${n.length} issues).`)}else w(e?.message??String(e))}finally{S(!1)}}async function Ue(){let r=!n&&f?.code!=null;if(confirm(km(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{if(await a.reset(e,t),r){let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),fe.current=r,Rg(e)?Ve.current=null:le(!1)}else i(`../`,{relative:`path`})}catch(e){w(e?.message??String(e))}finally{S(!1)}}}async function We(){P(!0),w(null);try{await a.publish(e,t);let[n,r]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);p(n);let i=b_(r);ae(!!i);let o=i??n.effective??h;g(o),fe.current=o}catch(e){w(e?.message??String(e))}finally{P(!1)}}async function Ke(){if(confirm(km(`engine.edit.discardDraftConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{await a.reset(e,t,{state:`draft`});let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),fe.current=r,ae(!1)}catch(e){w(e?.message??String(e))}finally{S(!1)}}}let qe=J.useMemo(()=>{if(n)return Object.keys(h).length>0;let e=fe.current;if(!e)return!1;try{return JSON.stringify(h)!==JSON.stringify(e)}catch{return!1}},[h,n]),Je=!n&&f?.code!=null,Ye=f?.editable!==!1,Xe=f?.deletable!==!1,Ze=f?.resettable!==!1,Qe=f?.lockReason,$e=f?.lock&&f.lock!==`none`,et=(n?!!(c?.allowOrgOverride||c?.allowRuntimeCreate):Je?!!c?.allowOrgOverride:!!(c?.allowOrgOverride||c?.allowRuntimeCreate))&&(n||Ye),tt=!et&&!n,nt=J.useRef(He);if(J.useEffect(()=>{nt.current=He}),J.useEffect(()=>{if(!I||n||tt||!F||!qe||x)return;let e;try{e=JSON.stringify(h)}catch{return}if(e===ge.current)return;let t=window.setTimeout(()=>{ge.current=e,nt.current(!1)},1500);return()=>window.clearTimeout(t)},[h,qe,F,x,n,tt,I]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!et||tt||!F&&!n)return;e.preventDefault(),!x&&(n||qe)&&nt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[et,tt,F,n,x,qe]),J.useEffect(()=>{if(!qe)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[qe]),J.useEffect(()=>{if(!qe)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(X(`engine.edit.unsavedLeaveConfirm`,d))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[qe,d]),y)return(0,Y.jsx)(sh,{entry:c,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let rt=tt&&Je&&!!c?.allowRuntimeCreate,it=!n&&!r?Rg(e):void 0,at=Vg(e),ot=Wg(e);function st(){fe.current&&g(fe.current),E([]),w(null),le(!1)}let ct=tt||!F&&!n,lt=(0,Y.jsxs)(Y.Fragment,{children:[!n&&(0,Y.jsx)(uh,{entry:c,location:`record_header`,recordId:t,onAfter:()=>ce(e=>e+1)}),(!n||we)&&(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`layers`),title:X(`engine.edit.layers`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),f?.overlay&&(()=>{let e=Dh(f.code,f.effective);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:X(`engine.layers.diff`,d),children:e}):null})()]}),!n&&(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`references`),title:X(`engine.edit.references`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Di,{className:`h-3.5 w-3.5`}),_&&_.length>0&&(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:_.length})]}),we&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`related`),title:X(`engine.edit.related`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(io,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`history`),title:X(`engine.edit.history`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(It,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`audit`),title:X(`engine.edit.auditTab`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(ai,{className:`h-3.5 w-3.5`})})]}),!n&&et&&f?.overlay&&(Je?Ze:Xe)&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ue,disabled:x,title:X(Je?`engine.edit.reset`:`engine.edit.delete`,d),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Je?(0,Y.jsx)(Wn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})}),et&&!n&&!F&&!it&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>le(!0),className:`h-7`,children:[(0,Y.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]}),et&&(F||n)&&(0,Y.jsx)(w_,{saving:x,isDirty:qe,autoSaveEnabled:I,lastSavedAt:pe,createMode:!!n,locale:d}),et&&(F||n)&&!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>he(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:X(I?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,d),children:I?(0,Y.jsx)(lo,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5`})}),et&&!n&&F&&!it&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:st,disabled:x,className:`h-7 w-7 p-0`,title:X(`engine.cancel`,d),children:(0,Y.jsx)(ro,{className:`h-3.5 w-3.5`})}),et&&(F||n)&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>He(!1),disabled:x||!n&&!qe,className:`h-7 w-7 p-0 relative`,title:x?X(`engine.edit.saving`,d):!n&&!qe?X(`engine.edit.noChanges`,d):`${X(`engine.edit.save`,d)} (⌘S)`,children:[x?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(to,{className:`h-3.5 w-3.5`}),qe&&!x&&(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),et&&!n&&ie&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ke,disabled:x||oe,className:`h-7 w-7 p-0 text-muted-foreground`,title:X(`engine.edit.discardDraft`,d),children:(0,Y.jsx)(an,{className:`h-3.5 w-3.5`})}),et&&!n&&ie&&(0,Y.jsx)(K,{size:`sm`,onClick:We,disabled:x||oe||qe,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:X(qe?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,d),children:oe?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:X(`engine.edit.publish`,d)})]})})]});return(0,Y.jsxs)(sh,{entry:c??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?X(`engine.edit.createNew`,d):void 0,actions:it?null:lt,children:[(0,Y.jsxs)(`div`,{className:it?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(C||tt||ie||$e)&&(0,Y.jsxs)(`div`,{className:it?`px-6 pt-4 space-y-3`:`space-y-3`,children:[C&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:C}),$e&&(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)(Un,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`font-medium`,children:[f?.lock===`full`&&X(`engine.edit.lockFull`,d),f?.lock===`no-overlay`&&X(`engine.edit.lockNoOverlay`,d),f?.lock===`no-delete`&&X(`engine.edit.lockNoDelete`,d)]}),Qe&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Qe}),f?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:f.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[d===`zh-CN`?`查看文档`:`View docs`,` →`]}),f?.packageId&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Y.jsxs)(`code`,{className:`font-mono`,children:[f.packageId,f.packageVersion?`@${f.packageVersion}`:``]})})]}),rt&&(0,Y.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]}),ie&&!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:X(`engine.edit.draftPending`,d)}),et&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:Ke,disabled:x||oe,className:`h-7`,children:X(`engine.edit.discardDraft`,d)}),(0,Y.jsx)(K,{size:`sm`,onClick:We,disabled:x||oe||qe,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:oe?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):X(`engine.edit.publish`,d)})]})]}),tt&&!$e&&(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:rt?X(`engine.edit.artifactLockedBanner`,d).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Y.jsx)(J.Fragment,{children:t},n)):X(`engine.edit.readOnlyTypeBanner`,d).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Y.jsx)(J.Fragment,{children:t},n))}),rt&&(0,Y.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]})]}),(0,Y.jsx)(`div`,{className:it?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:it?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!it&&ct&&!tt&&et&&!n&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,Y.jsx)(`span`,{children:X(`engine.edit.readOnlyBanner`,d).split(/\{edit\}/).map((e,t,n)=>(0,Y.jsxs)(J.Fragment,{children:[e,t<n.length-1&&(0,Y.jsx)(`strong`,{children:X(`engine.edit.edit`,d)})]},t))}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>le(!0),children:[(0,Y.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]})]}),(()=>{let t=f?._diagnostics,n=__(e)?T.map(e=>({path:e.path,message:e.message})):t?.errors??[],r=__(e)?n.length===0:t?.valid!==!1;if(!t&&!__(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)(Tn,{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:km(a,d,{count:t.length})}),(0,Y.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`opacity-70`,children:e.path||`(root)`}),`: `,e.message]},t)),r>0&&(0,Y.jsx)(`li`,{className:`opacity-70`,children:km(`engine.edit.diagnostics.more`,d,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),it?(0,Y.jsx)(`div`,{className:ze?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(y_,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(Gt,{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:et&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":X(`engine.edit.designer`,d),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Le,onClick:()=>Re(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Le?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:X(`engine.edit.designMode`,d),children:[(0,Y.jsx)(Bi,{className:`h-3.5 w-3.5`}),X(`engine.edit.designMode`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Le,onClick:()=>Re(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Le?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.previewMode`,d),children:[(0,Y.jsx)(no,{className:`h-3.5 w-3.5`}),X(`engine.edit.previewMode`,d)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[lt,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),it&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ie,className:`h-7 w-7 p-0`,title:X(Me?`engine.edit.showInspector`:`engine.edit.hideInspector`,d)+` (⌘\\)`,children:Me?(0,Y.jsx)(_r,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(kn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Be(e=>!e),className:`h-7 w-7 p-0`,title:X(ze?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,d),children:ze?(0,Y.jsx)(qi,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(oo,{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)(it,{type:e,name:t,draft:h,editing:F&&!Le,selection:Le?null:ue,onSelectionChange:de,locale:d,onPatch:e=>D(t=>({...t,...e}))})})]})}),(0,Y.jsx)(Ct,{withHandle:!0,className:Me?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(Gt,{panelRef:Fe,defaultSize:Pe.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Pe.current=t,typeof window<`u`&&window.localStorage.setItem(je,String(Math.round(t)))),Ne(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Ae,n?`1`:`0`),n))},children:(0,Y.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,Y.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`properties`,onClick:()=>ke(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.properties`,d),children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.properties`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`source`,onClick:()=>ke(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.source`,d),children:[(0,Y.jsx)(Ga,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.source`,d)]})]}),qe&&(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`,d)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:Oe===`source`?(0,Y.jsx)(u_,{value:h,onChange:D,readOnly:ct,issues:T.map(e=>({path:e.path??``,message:e.message}))}):ue&&at?(0,Y.jsx)(at,{type:e,name:t,draft:h,selection:ue,onPatch:e=>D(t=>({...t,...e})),onClearSelection:()=>de(null),onSelectionChange:de,readOnly:ct,locale:d}):!ue&&ot?(0,Y.jsx)(ot,{type:e,name:t,draft:h,onPatch:e=>D(t=>({...t,...e})),onSelectionChange:de,readOnly:ct,locale:d}):(0,Y.jsx)(eg,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:re,issues:T,hiddenFields:ne,fieldOrder:N,readOnly:ct,createMode:n,widgetContext:ye})})]})})]})}):(0,Y.jsx)(eg,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:re,issues:T,hiddenFields:ne,fieldOrder:N,readOnly:ct,createMode:n,widgetContext:ye})]})})]}),(0,Y.jsx)(sn,{open:Ee===`layers`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.layers`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Oh,{layered:f,locale:d})})]})}),(0,Y.jsx)(sn,{open:Ee===`references`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(Ft,{className:`text-base`,children:[X(`engine.edit.references`,d),_&&(0,Y.jsx)(V,{variant:`outline`,className:`ml-2 text-[10px]`,children:_.length})]}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(C_,{refs:_,loading:be})})]})}),we&&(0,Y.jsx)(sn,{open:Ee===`related`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.related`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Sg,{type:e,name:t,parentItem:h,onOpen:e=>Ce(e)})})]})}),!n&&(0,Y.jsx)(sn,{open:Ee===`history`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.history`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Ag,{type:e,name:t,client:a,onRollback:()=>ce(e=>e+1),rollbackLabel:X(`engine.edit.rollback`,d),rollbackConfirm:e=>X(`engine.edit.rollbackConfirm`,d).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(sn,{open:Ee===`audit`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.auditTab`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(Fg,{type:e,name:t,client:a,locale:d})})]})}),(0,Y.jsx)(Og,{target:Se,onClose:()=>Ce(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(ft,{open:O!=null,onOpenChange:e=>{e||(k(null),j(null))},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(Jt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Y.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:O?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Y.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Y.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>k(null),children:`Cancel`}),(0,Y.jsx)(K,{variant:`destructive`,onClick:()=>He(!0),disabled:x,children:x?`Forcing…`:`Force save`})]})]})})]})}function C_({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)(ut,{children:[(0,Y.jsx)(fo,{children:`No references found`}),(0,Y.jsx)(kt,{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 w_({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:km(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function T_({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)(ut,{children:[(0,Y.jsx)(fo,{children:`Missing metadata type`}),(0,Y.jsxs)(kt,{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=E_(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)(x_,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Y.jsx)(kg,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Y.jsx)(x_,{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)(ut,{children:[(0,Y.jsx)(fo,{children:`Unknown sub-path`}),(0,Y.jsxs)(kt,{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 E_(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function D_(){let e=hm(),t=J.useMemo(()=>Am(),[]),[n,r]=J.useState(`error`),{loading:a,error:o,summary:s,reload:c}=ym(e,n),{entries:l}=_m(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=Dm(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)(Zt,{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)(Tn,{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:km(`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)(K,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,Y.jsx)(Le,{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:km(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(ut,{children:[(0,Y.jsx)(fo,{children:X(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(kt,{children:km(`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:km(`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:km(`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:km(`engine.diagnostics.more`,t,{count:c})})]})})]},r.name)})})]})})]},e))]})]})}function O_(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 k_({type:e,name:t}){let n=s(),r=hm(),{entries:i}=_m(r),a=i.find(t=>t.type===e),o=!!gh(e,a).allowOrgOverride,c=J.useMemo(()=>Am(),[]),l=J.useCallback(e=>X(e,c),[c]),u=J.useMemo(()=>O_(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 re=J.useMemo(()=>{let e=D.trim().toLowerCase();return p.filter(t=>{if(k){let e=d.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[p,D,k,d.objects]),ie=[{label:l(`perm.stat.objectsGranted`),value:Object.values(d.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:l(`perm.stat.fieldOverrides`),value:Object.keys(d.fields??{}).length}];return y?(0,Y.jsx)(sh,{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)(sh,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?l(`perm.subtitle.profile`):l(`perm.subtitle.set`),stats:ie,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(It,{className:`h-4 w-4 mr-1`}),` `,l(`engine.edit.history`)]}),o&&(0,Y.jsxs)(K,{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)(to,{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)(Tn,{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)(G,{htmlFor:`perm-name`,className:`text-xs`,children:l(`perm.field.name`)}),(0,Y.jsx)(W,{id:`perm-name`,value:d.name,disabled:!o,onChange:e=>f(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{htmlFor:`perm-label`,className:`text-xs`,children:l(`perm.field.label`)}),(0,Y.jsx)(W,{id:`perm-label`,value:d.label??``,disabled:!o,onChange:e=>f(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,Y.jsx)(Ki,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,Y.jsx)(G,{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)(W,{placeholder:l(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ki,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,Y.jsx)(G,{htmlFor:`only-enabled`,className:`text-xs`,children:l(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[re.length,` / `,p.length,` `,l(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Y.jsx)(A_,{objects:re,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:u,t:l,onToggleExpand:ee,onObjectPerm:te,onFieldPerm:ne,onBulkSet:M})})]}),(0,Y.jsx)(ft,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-amber-500`}),` `,l(`engine.edit.destructive`)]}),(0,Y.jsx)(Jt,{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)(Nn,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>E(null),children:l(`engine.cancel`)}),(0,Y.jsxs)(K,{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 A_({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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(yt,{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)(K,{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)(K,{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)(K,{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)(K,{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)(j_,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function j_({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)(yt,{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)(yt,{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 M_(){ph({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>N_(e.fields),groupLabel:`Fields`,order:5}]}),ph({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}]}),ph({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>N_(e.validations),groupLabel:`Embedded Validations`,order:15}]}),ph({type:`hook`,anchors:[{anchorType:`object`,match:dh(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),ph({type:`page`,anchors:[{anchorType:`object`,match:dh(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`description`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{regions:[]}}),ph({type:`view`,anchors:[{anchorType:`object`,match:dh([`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}}}}}),ph({type:`flow`,anchors:[{anchorType:`object`,match:dh([`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:[]}}),ph({type:`trigger`,anchors:[{anchorType:`object`,match:dh([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),ph({type:`validation`,anchors:[{anchorType:`object`,match:dh(`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`}}),ph({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:{}}}),ph({type:`action`,anchors:[{anchorType:`object`,match:dh([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),ph({type:`dashboard`,anchors:[{anchorType:`object`,match:dh([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),ph({type:`report`,anchors:[{anchorType:`object`,match:dh([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),ph({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 N_(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var P_={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`}},F_={role:{type:`object`,title:`Role`,required:[`name`],properties:{...P_,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:{...P_,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:{...P_.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:P_.label,description:P_.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:{...P_,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:{...P_,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...P_,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...P_,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...P_,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:{...P_,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...P_,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:{...P_,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 I_(){for(let[e,t]of Object.entries(F_))ph({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function L_({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 R_({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)(Ne,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function z_({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)(Jn,{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 B_=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)(R_,{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 V_({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:U(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var H_={"page:header":{label:`Header`,category:`layout`,Icon:fr},"page:footer":{label:`Footer`,category:`layout`,Icon:Aa},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:je},"page:tabs":{label:`Tabs`,category:`layout`,Icon:aa},"page:accordion":{label:`Accordion`,category:`layout`,Icon:ni},"page:card":{label:`Card`,category:`layout`,Icon:ja},"page:section":{label:`Section`,category:`layout`,Icon:At},"record:details":{label:`Record details`,category:`record`,Icon:da},"record:highlights":{label:`Highlights`,category:`record`,Icon:va},"record:related_list":{label:`Related list`,category:`record`,Icon:Ni},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Dt},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:di},"record:path":{label:`Stage path`,category:`record`,Icon:Nt},"record:alert":{label:`Alert banner`,category:`record`,Icon:Tn},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:lo},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Kn},"record:history":{label:`History`,category:`record`,Icon:It},"app:launcher":{label:`App launcher`,category:`navigation`,Icon:ot},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Ua},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:Nt},"global:search":{label:`Global search`,category:`navigation`,Icon:Wa},"global:notifications":{label:`Notifications`,category:`navigation`,Icon:it},"user:profile":{label:`User profile`,category:`navigation`,Icon:yn},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:$e},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:ra},"element:text":{label:`Text`,category:`element`,Icon:fn},"element:number":{label:`Number`,category:`element`,Icon:dr},"element:image":{label:`Image`,category:`element`,Icon:_t},"element:divider":{label:`Divider`,category:`element`,Icon:la},"element:button":{label:`Button`,category:`element`,Icon:zr},"element:filter":{label:`Filter`,category:`element`,Icon:Ar},"element:form":{label:`Form`,category:`element`,Icon:Tt},"element:record_picker":{label:`Record picker`,category:`element`,Icon:xt}},U_={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},W_=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(H_))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)})(),G_=Bn,K_={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 q_(e){return K_[H_[e]?.category??`misc`]}function J_(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 Y_(e,t,n){return e===`children`?`children[${n}]`:`regions[${t}].components[${n}]`}function X_(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 Z_=`text/x-objectui-pageblock`;function Q_({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>J_(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:X_(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:X_(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)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:p,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:p,children:[a.map((e,t)=>(0,Y.jsx)($_,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(e,n)=>r?.({kind:`block`,id:`regions[${t}].components[${e}]`,label:X_(n)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function $_({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:U(`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(Z_)||(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(Z_);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)(ev,{block:e,regionIdx:t,compIdx:s,selected:Y_(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)(tv,{onPick:e=>s(t,e)})})]})]})}function ev({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=H_[c]?.Icon??G_,u=q_(c),d=X_(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(Z_,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(Z_))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(Z_);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:U(`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:U(`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)(On,{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:U(`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:U(`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:U(`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 tv({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?W_.map(e=>({category:e.category,types:e.types.filter(e=>{let t=H_[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):W_,[a]);return(0,Y.jsxs)(br,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Fe,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(jn,{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:U_[t.category]}),t.types.map(t=>{let r=H_[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:U(`h-3.5 w-3.5 shrink-0`,q_(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 nv({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)(L_,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Y.jsx)(Q_,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(V_,{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)(R_,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Y.jsx)(L_,{hint:`page · design`,children:(0,Y.jsx)(Q_,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Y.jsx)(L_,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(B_,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(V_,{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)(F,{schema:o})})]})})}var rv=new Set([`form`,`detail`]);function iv(e){return rv.has(e)}function av(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ov(e,t){return typeof e==`string`&&rv.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&rv.has(t)?`form`:`list`}function sv(e){let t=e.config;return av(t)?[{storeKey:`config`,familyKey:ov(e.viewKind,t.type),schema:t}]:[]}function cv(e){return sv(e)[0]}function lv(e,t){return cv(e)}function uv(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 dv=new Set([`simple`,`tabbed`,`wizard`,`split`]);function fv(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 pv(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:dv.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(fv):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function mv({name:e,draft:t,editing:n}){let r=J.useMemo(()=>cv(t)?.schema,[t]),i=J.useMemo(()=>uv(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)(L_,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:e})})})})}if(!i)return(0,Y.jsx)(L_,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(R_,{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=pv(i,r);return(0,Y.jsx)(L_,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:t})})})})}let l=J.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);return(0,Y.jsx)(L_,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:l})})})})}function hv({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)(K,{variant:`ghost`,size:`sm`,onClick:n,"aria-label":r,className:`h-7 w-7 p-0`,children:(0,Y.jsx)(ro,{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 gv({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)(K,{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)(on,{className:`h-4 w-4`})}),(0,Y.jsx)(K,{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)(Fn,{className:`h-4 w-4`})})]})}function _v({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)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{value:t,onChange:e=>n(e.target.value),placeholder:r,disabled:i,className:U(`h-8 text-sm`,a&&`font-mono`)})]})}function vv({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{type:`number`,value:t??``,onChange:e=>{let t=e.target.value;n(t===``?void 0:Number(t))},placeholder:r,disabled:i,className:`h-8 text-sm`})]})}function yv({label:e,value:t,options:n,onCommit:r,placeholder:i=`—`,disabled:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(In,{value:t??``,onValueChange:r,disabled:a,children:[(0,Y.jsx)(nr,{className:`h-8 text-sm`,children:(0,Y.jsx)(Ot,{placeholder:i})}),(0,Y.jsx)(vo,{children:n.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})]})}function bv({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 xv({label:e,onClick:t,disabled:n}){return(0,Y.jsx)(K,{variant:`destructive`,size:`sm`,onClick:t,disabled:n,className:`w-full`,children:e})}function Sv({message:e}){return(0,Y.jsx)(`div`,{className:`text-xs italic text-muted-foreground p-4 text-center`,children:e})}function Cv(e,t,n){let r=Array.isArray(e)?[...e]:[];return n===null?r.splice(t,1):r[t]=n,r}function wv(e,t){let n=Array.isArray(e)?[...e]:[];return n.push(t),n}function Tv(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 Ev(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 Dv={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:dr},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:Va},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:Gi},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Xr},area:{id:`area`,label:`Area chart`,category:`chart`,icon:fa},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:Wr},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:vn},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:sa},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Pt},table:{id:`table`,label:`Data table`,category:`data`,icon:hr},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:Ai},list:{id:`list`,label:`Record list`,category:`data`,icon:et},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:ho}},Ov={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},kv=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(Dv).filter(t=>t.category===e)})),Av=Dt;function jv({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?kv.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):kv},[i]);return(0,Y.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:()=>r(e=>!e),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),t]}),n&&(0,Y.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-md border bg-popover shadow-md`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Y.jsx)(Wa,{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:Ov[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)(Dv[t.id]?.icon??Av,{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 Mv=J.lazy(()=>c(()=>import(`./plugin-dashboard-Do4xOja1.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Nv({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=Ev(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Dv[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:wv(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)(jv,{onAdd:p,label:X(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(L_,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(R_,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(L_,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(B_,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(Pv,{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)(Mv,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})]})})}function Pv({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=Dv[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)(Mr,{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)(vt,{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)(ro,{className:`h-3.5 w-3.5`})})]})}var Fv=J.lazy(()=>c(()=>import(`./plugin-report-DcNaFUN2.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Iv({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)(L_,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,Y.jsxs)(B_,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,Y.jsx)(V_,{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)(Fv,{schema:m,dataSource:o})})})]})}):(0,Y.jsxs)(L_,{children:[l&&(0,Y.jsx)(V_,{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)(z_,{icon:(0,Y.jsx)(Yt,{className:`h-8 w-8`}),title:`No columns yet`,description:u?`Add at least one column to preview the report against live data.`:`Define columns in the Properties tab to see a preview.`,action:u?(0,Y.jsxs)(`button`,{type:`button`,onClick:p,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent transition-colors`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,Y.jsx)(L_,{children:(0,Y.jsx)(z_,{icon:(0,Y.jsx)(Ai,{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 Lv=`text/x-objectui-nav`;function Rv(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 zv(e){switch(e){case`object`:return Ai;case`page`:return da;case`dashboard`:return dt;case`report`:return ci;case`link`:return Ie;case`group`:return Ea;default:return Nt}}var Bv={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 Vv(e){return Bv[e]??Bv.item}function Hv(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Uv(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Wv({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=wv(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(Cv(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=J.useCallback((e,r)=>{n&&(l(Cv(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=Tv(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Hv(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)(H,{className:`h-3 w-3`}),` Add nav item`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Lv)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Lv)&&(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)(Gv,{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 Gv({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)(Kv,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Hv(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)(Gv,{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 Kv({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=Rv(e),p=zv(f),m=Vv(f),h=Uv(e),[g,_]=J.useState(!1),[v,y]=J.useState(Hv(e,t)),[b,x]=J.useState(!1),[S,C]=J.useState(null);return J.useEffect(()=>{g||y(Hv(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(Lv,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Lv)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Lv)&&(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)(On,{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:U(`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!==Hv(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Hv(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:Hv(e,t)}),(0,Y.jsx)(V,{variant:`outline`,className:U(`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)(Xt,{className:`h-3 w-3`})})]})]})}function qv(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)?qv(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Jv(e){switch(e){case`object`:return Ai;case`page`:return da;case`dashboard`:return dt;case`report`:return ci;default:return Nt}}function Yv({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:qv(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)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)(Wv,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(R_,{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)(Xv,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Xv({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Jv(e.kind),s=Zv(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)(Ze,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(Xv,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function Zv(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function Qv(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 $v(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 ey(e,t){return e.entries.findIndex(e=>e.name===t)}function ty(e,t,n){let r={type:t,label:n??ny(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function ny(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function ry(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 iy(e,t){let n=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],r=new Map;for(let e of n)r.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let i=new Set(n.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&i.has(e)?r.get(e).entries.push(t):(r.has(null)||r.set(null,{key:null,label:`Ungrouped`,entries:[]}),r.get(null).entries.push(t))}return Array.from(r.values()).filter(e=>e.entries.length>0)}var Z=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),ay={text:Z(`text`,`Text`,`单行文本`,`text`,fn),textarea:Z(`textarea`,`Text Area`,`多行文本`,`text`,Et),email:Z(`email`,`Email`,`邮箱`,`text`,Ve),url:Z(`url`,`URL`,`网址`,`text`,ei),phone:Z(`phone`,`Phone`,`电话`,`text`,Yn),password:Z(`password`,`Password`,`密码`,`text`,Un),markdown:Z(`markdown`,`Markdown`,`Markdown`,`text`,da),html:Z(`html`,`HTML`,`HTML`,`text`,Pn),richtext:Z(`richtext`,`Rich Text`,`富文本`,`text`,ra),number:Z(`number`,`Number`,`数字`,`number`,dr),currency:Z(`currency`,`Currency`,`货币`,`number`,Ii),percent:Z(`percent`,`Percent`,`百分比`,`number`,rr),date:Z(`date`,`Date`,`日期`,`date`,Xi),datetime:Z(`datetime`,`Date/Time`,`日期时间`,`date`,Xi),time:Z(`time`,`Time`,`时间`,`date`,Ke),boolean:Z(`boolean`,`Checkbox`,`复选框`,`logic`,Ci),toggle:Z(`toggle`,`Toggle`,`开关`,`logic`,qe),select:Z(`select`,`Picklist`,`下拉选择`,`selection`,hn),multiselect:Z(`multiselect`,`Multi-Select`,`多选`,`selection`,Ni),radio:Z(`radio`,`Radio`,`单选`,`selection`,lr),checkboxes:Z(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Ni),lookup:Z(`lookup`,`Lookup`,`查找关系`,`relation`,Di),master_detail:Z(`master_detail`,`Master-Detail`,`主从关系`,`relation`,Qe),tree:Z(`tree`,`Tree`,`树形关系`,`relation`,na),image:Z(`image`,`Image`,`图片`,`media`,_t),file:Z(`file`,`File`,`文件`,`media`,ha),avatar:Z(`avatar`,`Avatar`,`头像`,`media`,bt),video:Z(`video`,`Video`,`视频`,`media`,Gn),audio:Z(`audio`,`Audio`,`音频`,`media`,wa),formula:Z(`formula`,`Formula`,`公式`,`calculated`,hi),summary:Z(`summary`,`Rollup`,`汇总`,`calculated`,Vi),autonumber:Z(`autonumber`,`Auto Number`,`自动编号`,`calculated`,dr),composite:Z(`composite`,`Composite`,`复合字段`,`advanced`,io),repeater:Z(`repeater`,`Repeater`,`重复字段`,`advanced`,gn),location:Z(`location`,`Location`,`地理坐标`,`advanced`,eo),address:Z(`address`,`Address`,`地址`,`advanced`,Pr),code:Z(`code`,`Code`,`代码`,`advanced`,Pn),json:Z(`json`,`JSON`,`JSON`,`advanced`,co),color:Z(`color`,`Color`,`颜色`,`advanced`,Qi),rating:Z(`rating`,`Rating`,`评分`,`advanced`,Pe),slider:Z(`slider`,`Slider`,`滑块`,`advanced`,Br),signature:Z(`signature`,`Signature`,`签名`,`advanced`,Vt),qrcode:Z(`qrcode`,`QR Code`,`二维码`,`advanced`,Cn),progress:Z(`progress`,`Progress`,`进度条`,`advanced`,ci),tags:Z(`tags`,`Tags`,`标签`,`advanced`,Wt),vector:Z(`vector`,`Vector`,`向量`,`advanced`,Ri)},oy=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],sy={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},cy={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 ly(e){return cy[dy(e).category]}var uy=oy.map(e=>({category:e,types:Object.keys(ay).filter(t=>ay[t].category===e)}));function dy(e){return typeof e==`string`&&e in ay?ay[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:fn}}function fy(e){let{type:t}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(py,{...e,icon:t===`password`?(0,Y.jsx)(Un,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(ei,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Yn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(dr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Xi,{className:`h-3.5 w-3.5`}),placeholder:`Pick a date…`});case`time`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Ke,{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)(my,{...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)(Ki,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??`Off`})]});case`select`:case`radio`:return(0,Y.jsx)(hy,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(hy,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(gy,{...e});case`image`:case`avatar`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(_t,{className:`h-4 w-4`}),label:t===`avatar`?`Upload avatar`:`Upload image`});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(ha,{className:`h-4 w-4`}),label:`Upload ${t}`});case`qrcode`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(ha,{className:`h-4 w-4`}),label:`QR code`});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(Qi,{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)(Pe,{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)(py,{...e,icon:(0,Y.jsx)(eo,{className:`h-3.5 w-3.5`}),placeholder:`Lat, lng`});case`address`:return(0,Y.jsx)(my,{...e,placeholder:e.placeholder??`Street
|
|
22
|
+
`+` `.repeat(t));var Zg;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Zg||={});function Qg(e,t=[],n=Zg.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}e_(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:t_(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 $g(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 e_(e,t,n=Zg.DEFAULT){let r=Gg(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 t_(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 n_;(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`})(n_||={});var r_;(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`})(r_||={});var i_=Qg,a_=$g,o_;(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`})(o_||={});var s_=J.lazy(async()=>({default:(await c(()=>import(`./dist-Dal4BOHf.js`),[],import.meta.url)).default}));function c_(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function l_(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function u_({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let[a,o]=J.useState(()=>c_(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=i_(a)}catch{i=void 0}let o=r.map(e=>{let r=l_(e.path),a=1,o=1,s=1,c=2,l=i?a_(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=c_(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)(He,{className:`w-full h-full`}),children:(0,Y.jsx)(s_,{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 d_={object:async()=>(await c(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await c(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await c(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await c(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.i);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await c(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await c(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await c(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await c(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await c(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await c(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await c(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.u);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await c(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.a);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await c(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.a);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await c(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await c(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await c(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.s);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await c(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await c(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await c(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await c(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await c(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await c(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-D6pAOWWu.js`).then(e=>e.o);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},f_=new Set([`approval`,`connector_action`]),p_=/^nodes\.(\d+)\.type$/;function m_(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 h_=new Map;async function g_(e){if(h_.has(e))return h_.get(e)??null;let t=d_[e];if(!t)return h_.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return h_.set(e,r),r}catch{return h_.set(e,null),null}}function __(e){return e in d_}async function v_(e,t){let n=await g_(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=p_.exec(n);if(!r)return!0;let i=m_(t,Number(r[1]));return!(i&&f_.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 y_=ya;function b_(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 x_({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=f(),a=e??i.type??``,o=t??i.name??``,s=mh(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)(S_,{type:a,name:o,createMode:n,embedded:r})}function S_({type:e,name:t,createMode:n,embedded:r}){let i=s(),a=hm(),{entries:o}=_m(a),c=o.find(t=>t.type===e),l=gh(e,c),u=(n&&l.createSchema?l.createSchema:c?.schema)??l.defaultSchema,d=J.useMemo(()=>Am(),[]),[f,p]=J.useState(null),m=l.identityField??`name`,[h,g]=J.useState(()=>n?{...l.createDefaults??{},[m]:``}:{}),[_,v]=J.useState(null),[y,b]=J.useState(!n),[x,S]=J.useState(!1),[C,w]=J.useState(null),[T,E]=J.useState([]),D=J.useCallback(e=>{g(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&E(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[O,k]=J.useState(null),[A,j]=J.useState(null),ee=J.useCallback(e=>{D(t=>({...t,...e}))},[D]),{markTouched:te}=bg({rules:l.createDerive,draft:h,onPatch:ee,enabled:!!n}),M=J.useMemo(()=>{if(n)return l.createFields&&l.createFields.length>0?l.createFields:xg(u?.properties??void 0,u?.required??void 0)},[n,l.createFields,u]),ne=J.useMemo(()=>{if(!n||!M)return l.hiddenFields;let e=u?.properties??{},t=new Set(M),r=Object.keys(e).filter(e=>!t.has(e));if(l.hiddenFields)for(let e of l.hiddenFields)r.includes(e)||r.push(e);return r},[n,M,u,l.hiddenFields]),N=J.useMemo(()=>n&&M?M:l.fieldOrder,[n,M,l.fieldOrder]),re=J.useCallback(e=>{if(n){let t=h,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||te(e)}D(e)},[n,h,D,te]);J.useEffect(()=>{if(!__(e))return;let t=!1,n=window.setTimeout(()=>{v_(e,h).then(e=>{t||E(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,h]);let[ie,ae]=J.useState(!1),[oe,P]=J.useState(!1),[se,ce]=J.useState(0),[F,le]=J.useState(!!n),[ue,de]=J.useState(null);J.useEffect(()=>{de(null)},[e,t]),J.useEffect(()=>{F||de(null)},[F]);let fe=J.useRef(null),[pe,me]=J.useState(null),[I,he]=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`,I?`1`:`0`)}catch{}},[I]);let ge=J.useRef(null),[_e,L]=J.useState([]),[ve,R]=J.useState(!0);J.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`object`);if(e)return;L(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||L([])}finally{e||R(!1)}})(),()=>{e=!0}},[a]);let ye=J.useMemo(()=>({objectNames:_e,objectsLoading:ve}),[_e,ve]);J.useEffect(()=>{if(n){b(!1);return}let r=!1;return b(!0),w(null),(async()=>{try{let[n,i]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);if(r)return;p(n);let o=n?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?E(o.errors.map(e=>({path:e.path||``,message:e.message}))):E([]);let s=b_(i),c=s??n.effective??n.code??{},u=l.toDraft?l.toDraft(c):c;g(u),fe.current=u,ae(!!s),b(!1)}catch(e){r||(w(e?.message??String(e)),b(!1))}})(),()=>{r=!0}},[a,e,t,n,se]);let[be,z]=J.useState(!1);async function xe(){if(!(_!=null||be)){z(!0);try{v(await a.references(e,t))}catch(e){v([]),console.error(`references() failed`,e)}finally{z(!1)}}}let[Se,Ce]=J.useState(null),we=J.useMemo(()=>!n&&!r&&hh(e).length>0,[e,n,r]),Te=J.useRef(null),[Ee,De]=J.useState(null),[Oe,ke]=J.useState(`properties`);J.useEffect(()=>{if(Ee===`references`&&xe(),typeof window<`u`&&!r){let e=new URL(window.location.href);Ee?e.searchParams.set(`tab`,Ee):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[Ee,r]);let Ae=`metadata-edit:inspector-collapsed`,je=`metadata-edit:inspector-size`,[Me,Ne]=J.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Ae)===`1`),Pe=J.useRef(38);J.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(je));Number.isFinite(e)&&e>=22&&e<=80&&(Pe.current=e)},[]);let Fe=J.useRef(null),Ie=J.useCallback(()=>{Ne(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Ae,t?`1`:`0`),t})},[]);J.useEffect(()=>{let e=Fe.current;if(e)if(Me)e.resize?.(`0%`);else{let t=Pe.current||38;e.resize?.(`${t}%`)}},[Me]);let[Le,Re]=J.useState(!1),[ze,Be]=J.useState(!1);J.useEffect(()=>{if(typeof document>`u`||!ze)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[ze]),J.useEffect(()=>{if(typeof window>`u`||!ze)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Be(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ze]);let Ve=J.useRef(null);J.useEffect(()=>{Ve.current=null},[e,t]),J.useEffect(()=>{if(n||r||y)return;let i=`${e}/${t??``}`;Ve.current!==i&&Rg(e)&&(f?.code==null?c?.allowOrgOverride||c?.allowRuntimeCreate:c?.allowOrgOverride)&&(Ve.current=i,le(!0))},[e,t,n,r,y,c,f]),J.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),Ie())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Ie]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&De(t),Te.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&Ce({kind:`metadata`,type:e,name:t})}},[]),J.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);Se?.kind===`metadata`?e.searchParams.set(`open`,`${Se.type}:${Se.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[Se,r]);async function He(r){S(!0),w(null),E([]);try{let o=n?l.createBuildBody?l.createBuildBody(h):{...l.createDefaults??{},...h}:l.fromDraft?l.fromDraft(h):h,s=String(o[m]??h[m]??t),c=n?{...o,[m]:s}:o;if(!s){w(`A name is required.`),S(!1);return}let u=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await a.save(e,s,c,{force:r,mode:`draft`,...u?{packageId:u}:{}});let[d,f]=await Promise.all([a.layered(e,s),a.getDraft(e,s).catch(()=>null)]);p(d);let _=b_(f);ae(!!_);let v=_??d.effective??c,y=l.toDraft?l.toDraft(v):v;g(y),fe.current=y,me(new Date),ge.current=JSON.stringify(y),k(null),j(null);let b=!n&&!!Rg(e);!n&&!b&&le(!1),n&&i(`../${encodeURIComponent(s)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];k(Array.isArray(t)?t:[]),j(h)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:String(e.message??`Invalid`)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:e[2].trim()}]:[{path:``,message:r}]}E(n),n.length===1&&!n[0].path?w(n[0].message):n.length===1?w(`${n[0].path}: ${n[0].message}`):w(`Validation failed (${n.length} issues).`)}else w(e?.message??String(e))}finally{S(!1)}}async function Ue(){let r=!n&&f?.code!=null;if(confirm(km(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{if(await a.reset(e,t),r){let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),fe.current=r,Rg(e)?Ve.current=null:le(!1)}else i(`../`,{relative:`path`})}catch(e){w(e?.message??String(e))}finally{S(!1)}}}async function We(){P(!0),w(null);try{await a.publish(e,t);let[n,r]=await Promise.all([a.layered(e,t),a.getDraft(e,t).catch(()=>null)]);p(n);let i=b_(r);ae(!!i);let o=i??n.effective??h;g(o),fe.current=o}catch(e){w(e?.message??String(e))}finally{P(!1)}}async function Ke(){if(confirm(km(`engine.edit.discardDraftConfirm`,d,{type:e,name:t??``}))){S(!0),w(null);try{await a.reset(e,t,{state:`draft`});let n=await a.layered(e,t);p(n);let r=n.effective??n.code??{};g(r),fe.current=r,ae(!1)}catch(e){w(e?.message??String(e))}finally{S(!1)}}}let qe=J.useMemo(()=>{if(n)return Object.keys(h).length>0;let e=fe.current;if(!e)return!1;try{return JSON.stringify(h)!==JSON.stringify(e)}catch{return!1}},[h,n]),Je=!n&&f?.code!=null,Ye=f?.editable!==!1,Xe=f?.deletable!==!1,Ze=f?.resettable!==!1,Qe=f?.lockReason,$e=f?.lock&&f.lock!==`none`,et=(n?!!(c?.allowOrgOverride||c?.allowRuntimeCreate):Je?!!c?.allowOrgOverride:!!(c?.allowOrgOverride||c?.allowRuntimeCreate))&&(n||Ye),tt=!et&&!n,nt=J.useRef(He);if(J.useEffect(()=>{nt.current=He}),J.useEffect(()=>{if(!I||n||tt||!F||!qe||x)return;let e;try{e=JSON.stringify(h)}catch{return}if(e===ge.current)return;let t=window.setTimeout(()=>{ge.current=e,nt.current(!1)},1500);return()=>window.clearTimeout(t)},[h,qe,F,x,n,tt,I]),J.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!et||tt||!F&&!n)return;e.preventDefault(),!x&&(n||qe)&&nt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[et,tt,F,n,x,qe]),J.useEffect(()=>{if(!qe)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[qe]),J.useEffect(()=>{if(!qe)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(X(`engine.edit.unsavedLeaveConfirm`,d))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[qe,d]),y)return(0,Y.jsx)(sh,{entry:c,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let rt=tt&&Je&&!!c?.allowRuntimeCreate,it=!n&&!r?Rg(e):void 0,at=Vg(e),ot=Wg(e);function st(){fe.current&&g(fe.current),E([]),w(null),le(!1)}let ct=tt||!F&&!n,lt=(0,Y.jsxs)(Y.Fragment,{children:[!n&&(0,Y.jsx)(uh,{entry:c,location:`record_header`,recordId:t,onAfter:()=>ce(e=>e+1)}),(!n||we)&&(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`layers`),title:X(`engine.edit.layers`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),f?.overlay&&(()=>{let e=Dh(f.code,f.effective);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:X(`engine.layers.diff`,d),children:e}):null})()]}),!n&&(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`references`),title:X(`engine.edit.references`,d),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Di,{className:`h-3.5 w-3.5`}),_&&_.length>0&&(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:_.length})]}),we&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`related`),title:X(`engine.edit.related`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(io,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`history`),title:X(`engine.edit.history`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(It,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>De(`audit`),title:X(`engine.edit.auditTab`,d),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(ai,{className:`h-3.5 w-3.5`})})]}),!n&&et&&f?.overlay&&(Je?Ze:Xe)&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ue,disabled:x,title:X(Je?`engine.edit.reset`:`engine.edit.delete`,d),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Je?(0,Y.jsx)(Wn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Xt,{className:`h-3.5 w-3.5`})}),et&&!n&&!F&&!it&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>le(!0),className:`h-7`,children:[(0,Y.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]}),et&&(F||n)&&(0,Y.jsx)(w_,{saving:x,isDirty:qe,autoSaveEnabled:I,lastSavedAt:pe,createMode:!!n,locale:d}),et&&(F||n)&&!n&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>he(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:X(I?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,d),children:I?(0,Y.jsx)(lo,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5`})}),et&&!n&&F&&!it&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:st,disabled:x,className:`h-7 w-7 p-0`,title:X(`engine.cancel`,d),children:(0,Y.jsx)(ro,{className:`h-3.5 w-3.5`})}),et&&(F||n)&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>He(!1),disabled:x||!n&&!qe,className:`h-7 w-7 p-0 relative`,title:x?X(`engine.edit.saving`,d):!n&&!qe?X(`engine.edit.noChanges`,d):`${X(`engine.edit.save`,d)} (⌘S)`,children:[x?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(to,{className:`h-3.5 w-3.5`}),qe&&!x&&(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),et&&!n&&ie&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ke,disabled:x||oe,className:`h-7 w-7 p-0 text-muted-foreground`,title:X(`engine.edit.discardDraft`,d),children:(0,Y.jsx)(an,{className:`h-3.5 w-3.5`})}),et&&!n&&ie&&(0,Y.jsx)(K,{size:`sm`,onClick:We,disabled:x||oe||qe,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:X(qe?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,d),children:oe?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:X(`engine.edit.publish`,d)})]})})]});return(0,Y.jsxs)(sh,{entry:c??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?X(`engine.edit.createNew`,d):void 0,actions:it?null:lt,children:[(0,Y.jsxs)(`div`,{className:it?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(C||tt||ie||$e)&&(0,Y.jsxs)(`div`,{className:it?`px-6 pt-4 space-y-3`:`space-y-3`,children:[C&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:C}),$e&&(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)(Un,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`font-medium`,children:[f?.lock===`full`&&X(`engine.edit.lockFull`,d),f?.lock===`no-overlay`&&X(`engine.edit.lockNoOverlay`,d),f?.lock===`no-delete`&&X(`engine.edit.lockNoDelete`,d)]}),Qe&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Qe}),f?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:f.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[d===`zh-CN`?`查看文档`:`View docs`,` →`]}),f?.packageId&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Y.jsxs)(`code`,{className:`font-mono`,children:[f.packageId,f.packageVersion?`@${f.packageVersion}`:``]})})]}),rt&&(0,Y.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]}),ie&&!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:X(`engine.edit.draftPending`,d)}),et&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:Ke,disabled:x||oe,className:`h-7`,children:X(`engine.edit.discardDraft`,d)}),(0,Y.jsx)(K,{size:`sm`,onClick:We,disabled:x||oe||qe,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:oe?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):X(`engine.edit.publish`,d)})]})]}),tt&&!$e&&(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:rt?X(`engine.edit.artifactLockedBanner`,d).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Y.jsx)(J.Fragment,{children:t},n)):X(`engine.edit.readOnlyTypeBanner`,d).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Y.jsx)(J.Fragment,{children:t},n))}),rt&&(0,Y.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:X(`engine.list.create`,d)})]})]}),(0,Y.jsx)(`div`,{className:it?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:it?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!it&&ct&&!tt&&et&&!n&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,Y.jsx)(`span`,{children:X(`engine.edit.readOnlyBanner`,d).split(/\{edit\}/).map((e,t,n)=>(0,Y.jsxs)(J.Fragment,{children:[e,t<n.length-1&&(0,Y.jsx)(`strong`,{children:X(`engine.edit.edit`,d)})]},t))}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>le(!0),children:[(0,Y.jsx)(vt,{className:`h-3.5 w-3.5 mr-1`}),X(`engine.edit.edit`,d)]})]}),(()=>{let t=f?._diagnostics,n=__(e)?T.map(e=>({path:e.path,message:e.message})):t?.errors??[],r=__(e)?n.length===0:t?.valid!==!1;if(!t&&!__(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)(Tn,{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:km(a,d,{count:t.length})}),(0,Y.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`opacity-70`,children:e.path||`(root)`}),`: `,e.message]},t)),r>0&&(0,Y.jsx)(`li`,{className:`opacity-70`,children:km(`engine.edit.diagnostics.more`,d,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),it?(0,Y.jsx)(`div`,{className:ze?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(y_,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(Gt,{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:et&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":X(`engine.edit.designer`,d),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Le,onClick:()=>Re(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Le?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:X(`engine.edit.designMode`,d),children:[(0,Y.jsx)(Bi,{className:`h-3.5 w-3.5`}),X(`engine.edit.designMode`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Le,onClick:()=>Re(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Le?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.previewMode`,d),children:[(0,Y.jsx)(no,{className:`h-3.5 w-3.5`}),X(`engine.edit.previewMode`,d)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[lt,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),it&&(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Ie,className:`h-7 w-7 p-0`,title:X(Me?`engine.edit.showInspector`:`engine.edit.hideInspector`,d)+` (⌘\\)`,children:Me?(0,Y.jsx)(_r,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(kn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Be(e=>!e),className:`h-7 w-7 p-0`,title:X(ze?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,d),children:ze?(0,Y.jsx)(qi,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(oo,{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)(it,{type:e,name:t,draft:h,editing:F&&!Le,selection:Le?null:ue,onSelectionChange:de,locale:d,onPatch:e=>D(t=>({...t,...e}))})})]})}),(0,Y.jsx)(Ct,{withHandle:!0,className:Me?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(Gt,{panelRef:Fe,defaultSize:Pe.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Pe.current=t,typeof window<`u`&&window.localStorage.setItem(je,String(Math.round(t)))),Ne(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Ae,n?`1`:`0`),n))},children:(0,Y.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,Y.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`properties`,onClick:()=>ke(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.properties`,d),children:[(0,Y.jsx)(Br,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.properties`,d)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Oe===`source`,onClick:()=>ke(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Oe===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:X(`engine.edit.inspector.source`,d),children:[(0,Y.jsx)(Ga,{className:`h-3.5 w-3.5`}),X(`engine.edit.inspector.source`,d)]})]}),qe&&(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`,d)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:Oe===`source`?(0,Y.jsx)(u_,{value:h,onChange:D,readOnly:ct,issues:T.map(e=>({path:e.path??``,message:e.message}))}):ue&&at?(0,Y.jsx)(at,{type:e,name:t,draft:h,selection:ue,onPatch:e=>D(t=>({...t,...e})),onClearSelection:()=>de(null),onSelectionChange:de,readOnly:ct,locale:d}):!ue&&ot?(0,Y.jsx)(ot,{type:e,name:t,draft:h,onPatch:e=>D(t=>({...t,...e})),onSelectionChange:de,readOnly:ct,locale:d}):(0,Y.jsx)(eg,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:re,issues:T,hiddenFields:ne,fieldOrder:N,readOnly:ct,createMode:n,widgetContext:ye})})]})})]})}):(0,Y.jsx)(eg,{schema:u,form:n&&l.createSchema?void 0:c?.form,value:h,onChange:re,issues:T,hiddenFields:ne,fieldOrder:N,readOnly:ct,createMode:n,widgetContext:ye})]})})]}),(0,Y.jsx)(sn,{open:Ee===`layers`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.layers`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Oh,{layered:f,locale:d})})]})}),(0,Y.jsx)(sn,{open:Ee===`references`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(Ft,{className:`text-base`,children:[X(`engine.edit.references`,d),_&&(0,Y.jsx)(V,{variant:`outline`,className:`ml-2 text-[10px]`,children:_.length})]}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(C_,{refs:_,loading:be})})]})}),we&&(0,Y.jsx)(sn,{open:Ee===`related`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.related`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Sg,{type:e,name:t,parentItem:h,onOpen:e=>Ce(e)})})]})}),!n&&(0,Y.jsx)(sn,{open:Ee===`history`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.history`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Ag,{type:e,name:t,client:a,onRollback:()=>ce(e=>e+1),rollbackLabel:X(`engine.edit.rollback`,d),rollbackConfirm:e=>X(`engine.edit.rollbackConfirm`,d).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(sn,{open:Ee===`audit`,onOpenChange:e=>!e&&De(null),children:(0,Y.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(gt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(Ft,{className:`text-base`,children:X(`engine.edit.auditTab`,d)}),(0,Y.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(Fg,{type:e,name:t,client:a,locale:d})})]})}),(0,Y.jsx)(Og,{target:Se,onClose:()=>Ce(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(ft,{open:O!=null,onOpenChange:e=>{e||(k(null),j(null))},children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(Jt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Y.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:O?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Y.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Y.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Y.jsxs)(Nn,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>k(null),children:`Cancel`}),(0,Y.jsx)(K,{variant:`destructive`,onClick:()=>He(!0),disabled:x,children:x?`Forcing…`:`Force save`})]})]})})]})}function C_({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)(ut,{children:[(0,Y.jsx)(fo,{children:`No references found`}),(0,Y.jsx)(kt,{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 w_({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:km(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function T_({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)(ut,{children:[(0,Y.jsx)(fo,{children:`Missing metadata type`}),(0,Y.jsxs)(kt,{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=E_(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)(x_,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Y.jsx)(kg,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Y.jsx)(x_,{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)(ut,{children:[(0,Y.jsx)(fo,{children:`Unknown sub-path`}),(0,Y.jsxs)(kt,{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 E_(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function D_(){let e=hm(),t=J.useMemo(()=>Am(),[]),[n,r]=J.useState(`error`),{loading:a,error:o,summary:s,reload:c}=ym(e,n),{entries:l}=_m(e),u=J.useMemo(()=>{let e={};for(let n of l)e[n.type]=Dm(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)(Zt,{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)(Tn,{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:km(`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)(K,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,Y.jsx)(Le,{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:km(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(ut,{children:[(0,Y.jsx)(fo,{children:X(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(kt,{children:km(`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:km(`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:km(`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:km(`engine.diagnostics.more`,t,{count:c})})]})})]},r.name)})})]})})]},e))]})]})}function O_(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 k_({type:e,name:t}){let n=s(),r=hm(),{entries:i}=_m(r),a=i.find(t=>t.type===e),o=!!gh(e,a).allowOrgOverride,c=J.useMemo(()=>Am(),[]),l=J.useCallback(e=>X(e,c),[c]),u=J.useMemo(()=>O_(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 re=J.useMemo(()=>{let e=D.trim().toLowerCase();return p.filter(t=>{if(k){let e=d.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[p,D,k,d.objects]),ie=[{label:l(`perm.stat.objectsGranted`),value:Object.values(d.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:l(`perm.stat.fieldOverrides`),value:Object.keys(d.fields??{}).length}];return y?(0,Y.jsx)(sh,{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)(sh,{entry:a??{type:e,label:e},itemName:t,subtitle:d.isProfile?l(`perm.subtitle.profile`):l(`perm.subtitle.set`),stats:ie,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(It,{className:`h-4 w-4 mr-1`}),` `,l(`engine.edit.history`)]}),o&&(0,Y.jsxs)(K,{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)(to,{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)(Tn,{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)(G,{htmlFor:`perm-name`,className:`text-xs`,children:l(`perm.field.name`)}),(0,Y.jsx)(W,{id:`perm-name`,value:d.name,disabled:!o,onChange:e=>f(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{htmlFor:`perm-label`,className:`text-xs`,children:l(`perm.field.label`)}),(0,Y.jsx)(W,{id:`perm-label`,value:d.label??``,disabled:!o,onChange:e=>f(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,Y.jsx)(Ki,{id:`perm-is-profile`,checked:!!d.isProfile,disabled:!o,onCheckedChange:e=>f(t=>({...t,isProfile:!!e}))}),(0,Y.jsx)(G,{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)(W,{placeholder:l(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ki,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,Y.jsx)(G,{htmlFor:`only-enabled`,className:`text-xs`,children:l(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[re.length,` / `,p.length,` `,l(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Y.jsx)(A_,{objects:re,draft:d,expanded:_,fieldsByObject:h,writable:o,objectActions:u,t:l,onToggleExpand:ee,onObjectPerm:te,onFieldPerm:ne,onBulkSet:M})})]}),(0,Y.jsx)(ft,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Y.jsxs)(Mt,{children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-amber-500`}),` `,l(`engine.edit.destructive`)]}),(0,Y.jsx)(Jt,{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)(Nn,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>E(null),children:l(`engine.cancel`)}),(0,Y.jsxs)(K,{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 A_({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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(yt,{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)(K,{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)(K,{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)(K,{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)(K,{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)(j_,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function j_({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)(yt,{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)(yt,{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 M_(){ph({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>N_(e.fields),groupLabel:`Fields`,order:5}]}),ph({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}]}),ph({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>N_(e.validations),groupLabel:`Embedded Validations`,order:15}]}),ph({type:`hook`,anchors:[{anchorType:`object`,match:dh(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),ph({type:`page`,anchors:[{anchorType:`object`,match:dh(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`description`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{regions:[]}}),ph({type:`view`,anchors:[{anchorType:`object`,match:dh([`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}}}}}),ph({type:`flow`,anchors:[{anchorType:`object`,match:dh([`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:[]}}),ph({type:`trigger`,anchors:[{anchorType:`object`,match:dh([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),ph({type:`validation`,anchors:[{anchorType:`object`,match:dh(`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`}}),ph({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:{}}}),ph({type:`action`,anchors:[{anchorType:`object`,match:dh([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),ph({type:`dashboard`,anchors:[{anchorType:`object`,match:dh([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),ph({type:`report`,anchors:[{anchorType:`object`,match:dh([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),ph({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 N_(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var P_={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`}},F_={role:{type:`object`,title:`Role`,required:[`name`],properties:{...P_,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:{...P_,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:{...P_.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:P_.label,description:P_.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:{...P_,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:{...P_,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...P_,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...P_,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...P_,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:{...P_,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...P_,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:{...P_,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 I_(){for(let[e,t]of Object.entries(F_))ph({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function L_({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 R_({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)(Ne,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function z_({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)(Jn,{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 B_=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)(R_,{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 V_({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:U(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var H_={"page:header":{label:`Header`,category:`layout`,Icon:fr},"page:footer":{label:`Footer`,category:`layout`,Icon:Aa},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:je},"page:tabs":{label:`Tabs`,category:`layout`,Icon:aa},"page:accordion":{label:`Accordion`,category:`layout`,Icon:ni},"page:card":{label:`Card`,category:`layout`,Icon:ja},"page:section":{label:`Section`,category:`layout`,Icon:At},"record:details":{label:`Record details`,category:`record`,Icon:da},"record:highlights":{label:`Highlights`,category:`record`,Icon:va},"record:related_list":{label:`Related list`,category:`record`,Icon:Ni},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Dt},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:di},"record:path":{label:`Stage path`,category:`record`,Icon:Nt},"record:alert":{label:`Alert banner`,category:`record`,Icon:Tn},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:lo},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Kn},"record:history":{label:`History`,category:`record`,Icon:It},"app:launcher":{label:`App launcher`,category:`navigation`,Icon:ot},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Ua},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:Nt},"global:search":{label:`Global search`,category:`navigation`,Icon:Wa},"global:notifications":{label:`Notifications`,category:`navigation`,Icon:it},"user:profile":{label:`User profile`,category:`navigation`,Icon:yn},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:$e},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:ra},"element:text":{label:`Text`,category:`element`,Icon:fn},"element:number":{label:`Number`,category:`element`,Icon:dr},"element:image":{label:`Image`,category:`element`,Icon:_t},"element:divider":{label:`Divider`,category:`element`,Icon:la},"element:button":{label:`Button`,category:`element`,Icon:zr},"element:filter":{label:`Filter`,category:`element`,Icon:Ar},"element:form":{label:`Form`,category:`element`,Icon:Tt},"element:record_picker":{label:`Record picker`,category:`element`,Icon:xt}},U_={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},W_=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(H_))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)})(),G_=Bn,K_={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 q_(e){return K_[H_[e]?.category??`misc`]}function J_(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 Y_(e,t,n){return e===`children`?`children[${n}]`:`regions[${t}].components[${n}]`}function X_(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 Z_=`text/x-objectui-pageblock`;function Q_({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=J.useMemo(()=>J_(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:X_(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:X_(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)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:p,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:p,children:[a.map((e,t)=>(0,Y.jsx)($_,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(e,n)=>r?.({kind:`block`,id:`regions[${t}].components[${e}]`,label:X_(n)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function $_({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:U(`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(Z_)||(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(Z_);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)(ev,{block:e,regionIdx:t,compIdx:s,selected:Y_(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)(tv,{onPick:e=>s(t,e)})})]})]})}function ev({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=H_[c]?.Icon??G_,u=q_(c),d=X_(e),f=!i,[p,m]=J.useState(null),h=e=>{e.dataTransfer.setData(Z_,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(Z_))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(Z_);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:U(`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:U(`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)(On,{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:U(`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:U(`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:U(`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 tv({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?W_.map(e=>({category:e.category,types:e.types.filter(e=>{let t=H_[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):W_,[a]);return(0,Y.jsxs)(br,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Fe,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(jn,{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:U_[t.category]}),t.types.map(t=>{let r=H_[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:U(`h-3.5 w-3.5 shrink-0`,q_(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 nv({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)(L_,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Y.jsx)(Q_,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(V_,{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)(R_,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Y.jsx)(L_,{hint:`page · design`,children:(0,Y.jsx)(Q_,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Y.jsx)(L_,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(B_,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(V_,{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)(F,{schema:o})})]})})}var rv=new Set([`form`,`detail`]);function iv(e){return rv.has(e)}function av(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ov(e,t){return typeof e==`string`&&rv.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&rv.has(t)?`form`:`list`}function sv(e){let t=e.config;return av(t)?[{storeKey:`config`,familyKey:ov(e.viewKind,t.type),schema:t}]:[]}function cv(e){return sv(e)[0]}function lv(e,t){return cv(e)}function uv(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 dv=new Set([`simple`,`tabbed`,`wizard`,`split`]);function fv(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 pv(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:dv.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(fv):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function mv({name:e,draft:t,editing:n}){let r=J.useMemo(()=>cv(t)?.schema,[t]),i=J.useMemo(()=>uv(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)(L_,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:e})})})})}if(!i)return(0,Y.jsx)(L_,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(R_,{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=pv(i,r);return(0,Y.jsx)(L_,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:t})})})})}let l=J.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);return(0,Y.jsx)(L_,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(B_,{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)(F,{schema:l})})})})}function hv({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)(K,{variant:`ghost`,size:`sm`,onClick:n,"aria-label":r,className:`h-7 w-7 p-0`,children:(0,Y.jsx)(ro,{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 gv({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)(K,{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)(on,{className:`h-4 w-4`})}),(0,Y.jsx)(K,{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)(Fn,{className:`h-4 w-4`})})]})}function _v({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)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{value:t,onChange:e=>n(e.target.value),placeholder:r,disabled:i,className:U(`h-8 text-sm`,a&&`font-mono`)})]})}function vv({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{type:`number`,value:t??``,onChange:e=>{let t=e.target.value;n(t===``?void 0:Number(t))},placeholder:r,disabled:i,className:`h-8 text-sm`})]})}function yv({label:e,value:t,options:n,onCommit:r,placeholder:i=`—`,disabled:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(In,{value:t??``,onValueChange:r,disabled:a,children:[(0,Y.jsx)(nr,{className:`h-8 text-sm`,children:(0,Y.jsx)(Ot,{placeholder:i})}),(0,Y.jsx)(vo,{children:n.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})]})}function bv({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 xv({label:e,onClick:t,disabled:n}){return(0,Y.jsx)(K,{variant:`destructive`,size:`sm`,onClick:t,disabled:n,className:`w-full`,children:e})}function Sv({message:e}){return(0,Y.jsx)(`div`,{className:`text-xs italic text-muted-foreground p-4 text-center`,children:e})}function Cv(e,t,n){let r=Array.isArray(e)?[...e]:[];return n===null?r.splice(t,1):r[t]=n,r}function wv(e,t){let n=Array.isArray(e)?[...e]:[];return n.push(t),n}function Tv(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 Ev(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 Dv={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:dr},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:Va},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:Gi},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Xr},area:{id:`area`,label:`Area chart`,category:`chart`,icon:fa},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:Wr},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:vn},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:sa},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Pt},table:{id:`table`,label:`Data table`,category:`data`,icon:hr},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:Ai},list:{id:`list`,label:`Record list`,category:`data`,icon:et},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:ho}},Ov={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},kv=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(Dv).filter(t=>t.category===e)})),Av=Dt;function jv({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?kv.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):kv},[i]);return(0,Y.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:()=>r(e=>!e),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),t]}),n&&(0,Y.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-md border bg-popover shadow-md`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Y.jsx)(Wa,{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:Ov[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)(Dv[t.id]?.icon??Av,{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 Mv=J.lazy(()=>c(()=>import(`./plugin-dashboard-CXLv53tc.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Nv({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=Ev(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Dv[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:wv(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)(jv,{onAdd:p,label:X(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(L_,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(R_,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(L_,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(B_,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(Pv,{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)(Mv,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})]})})}function Pv({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=Dv[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)(Mr,{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)(vt,{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)(ro,{className:`h-3.5 w-3.5`})})]})}var Fv=J.lazy(()=>c(()=>import(`./plugin-report-BFZ-T3Th.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Iv({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)(L_,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,Y.jsxs)(B_,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,Y.jsx)(V_,{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)(Fv,{schema:m,dataSource:o})})})]})}):(0,Y.jsxs)(L_,{children:[l&&(0,Y.jsx)(V_,{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)(z_,{icon:(0,Y.jsx)(Yt,{className:`h-8 w-8`}),title:`No columns yet`,description:u?`Add at least one column to preview the report against live data.`:`Define columns in the Properties tab to see a preview.`,action:u?(0,Y.jsxs)(`button`,{type:`button`,onClick:p,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent transition-colors`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,Y.jsx)(L_,{children:(0,Y.jsx)(z_,{icon:(0,Y.jsx)(Ai,{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 Lv=`text/x-objectui-nav`;function Rv(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 zv(e){switch(e){case`object`:return Ai;case`page`:return da;case`dashboard`:return dt;case`report`:return ci;case`link`:return Ie;case`group`:return Ea;default:return Nt}}var Bv={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 Vv(e){return Bv[e]??Bv.item}function Hv(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Uv(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Wv({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=wv(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(Cv(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=J.useCallback((e,r)=>{n&&(l(Cv(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=Tv(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Hv(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)(H,{className:`h-3 w-3`}),` Add nav item`]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Lv)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Lv)&&(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)(Gv,{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 Gv({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)(Kv,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Hv(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)(Gv,{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 Kv({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=Rv(e),p=zv(f),m=Vv(f),h=Uv(e),[g,_]=J.useState(!1),[v,y]=J.useState(Hv(e,t)),[b,x]=J.useState(!1),[S,C]=J.useState(null);return J.useEffect(()=>{g||y(Hv(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(Lv,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Lv)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Lv)&&(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)(On,{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:U(`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!==Hv(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Hv(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:Hv(e,t)}),(0,Y.jsx)(V,{variant:`outline`,className:U(`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)(Xt,{className:`h-3 w-3`})})]})]})}function qv(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)?qv(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Jv(e){switch(e){case`object`:return Ai;case`page`:return da;case`dashboard`:return dt;case`report`:return ci;default:return Nt}}function Yv({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:qv(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)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)(Wv,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(R_,{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)(Xv,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Xv({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Jv(e.kind),s=Zv(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)(Ze,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(Xv,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function Zv(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function Qv(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 $v(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 ey(e,t){return e.entries.findIndex(e=>e.name===t)}function ty(e,t,n){let r={type:t,label:n??ny(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function ny(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function ry(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 iy(e,t){let n=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],r=new Map;for(let e of n)r.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let i=new Set(n.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&i.has(e)?r.get(e).entries.push(t):(r.has(null)||r.set(null,{key:null,label:`Ungrouped`,entries:[]}),r.get(null).entries.push(t))}return Array.from(r.values()).filter(e=>e.entries.length>0)}var Z=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),ay={text:Z(`text`,`Text`,`单行文本`,`text`,fn),textarea:Z(`textarea`,`Text Area`,`多行文本`,`text`,Et),email:Z(`email`,`Email`,`邮箱`,`text`,Ve),url:Z(`url`,`URL`,`网址`,`text`,ei),phone:Z(`phone`,`Phone`,`电话`,`text`,Yn),password:Z(`password`,`Password`,`密码`,`text`,Un),markdown:Z(`markdown`,`Markdown`,`Markdown`,`text`,da),html:Z(`html`,`HTML`,`HTML`,`text`,Pn),richtext:Z(`richtext`,`Rich Text`,`富文本`,`text`,ra),number:Z(`number`,`Number`,`数字`,`number`,dr),currency:Z(`currency`,`Currency`,`货币`,`number`,Ii),percent:Z(`percent`,`Percent`,`百分比`,`number`,rr),date:Z(`date`,`Date`,`日期`,`date`,Xi),datetime:Z(`datetime`,`Date/Time`,`日期时间`,`date`,Xi),time:Z(`time`,`Time`,`时间`,`date`,Ke),boolean:Z(`boolean`,`Checkbox`,`复选框`,`logic`,Ci),toggle:Z(`toggle`,`Toggle`,`开关`,`logic`,qe),select:Z(`select`,`Picklist`,`下拉选择`,`selection`,hn),multiselect:Z(`multiselect`,`Multi-Select`,`多选`,`selection`,Ni),radio:Z(`radio`,`Radio`,`单选`,`selection`,lr),checkboxes:Z(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Ni),lookup:Z(`lookup`,`Lookup`,`查找关系`,`relation`,Di),master_detail:Z(`master_detail`,`Master-Detail`,`主从关系`,`relation`,Qe),tree:Z(`tree`,`Tree`,`树形关系`,`relation`,na),image:Z(`image`,`Image`,`图片`,`media`,_t),file:Z(`file`,`File`,`文件`,`media`,ha),avatar:Z(`avatar`,`Avatar`,`头像`,`media`,bt),video:Z(`video`,`Video`,`视频`,`media`,Gn),audio:Z(`audio`,`Audio`,`音频`,`media`,wa),formula:Z(`formula`,`Formula`,`公式`,`calculated`,hi),summary:Z(`summary`,`Rollup`,`汇总`,`calculated`,Vi),autonumber:Z(`autonumber`,`Auto Number`,`自动编号`,`calculated`,dr),composite:Z(`composite`,`Composite`,`复合字段`,`advanced`,io),repeater:Z(`repeater`,`Repeater`,`重复字段`,`advanced`,gn),location:Z(`location`,`Location`,`地理坐标`,`advanced`,eo),address:Z(`address`,`Address`,`地址`,`advanced`,Pr),code:Z(`code`,`Code`,`代码`,`advanced`,Pn),json:Z(`json`,`JSON`,`JSON`,`advanced`,co),color:Z(`color`,`Color`,`颜色`,`advanced`,Qi),rating:Z(`rating`,`Rating`,`评分`,`advanced`,Pe),slider:Z(`slider`,`Slider`,`滑块`,`advanced`,Br),signature:Z(`signature`,`Signature`,`签名`,`advanced`,Vt),qrcode:Z(`qrcode`,`QR Code`,`二维码`,`advanced`,Cn),progress:Z(`progress`,`Progress`,`进度条`,`advanced`,ci),tags:Z(`tags`,`Tags`,`标签`,`advanced`,Wt),vector:Z(`vector`,`Vector`,`向量`,`advanced`,Ri)},oy=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],sy={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},cy={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 ly(e){return cy[dy(e).category]}var uy=oy.map(e=>({category:e,types:Object.keys(ay).filter(t=>ay[t].category===e)}));function dy(e){return typeof e==`string`&&e in ay?ay[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:fn}}function fy(e){let{type:t}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(py,{...e,icon:t===`password`?(0,Y.jsx)(Un,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(ei,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Yn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(dr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Xi,{className:`h-3.5 w-3.5`}),placeholder:`Pick a date…`});case`time`:return(0,Y.jsx)(py,{...e,icon:(0,Y.jsx)(Ke,{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)(my,{...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)(Ki,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??`Off`})]});case`select`:case`radio`:return(0,Y.jsx)(hy,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(hy,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(gy,{...e});case`image`:case`avatar`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(_t,{className:`h-4 w-4`}),label:t===`avatar`?`Upload avatar`:`Upload image`});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(ha,{className:`h-4 w-4`}),label:`Upload ${t}`});case`qrcode`:return(0,Y.jsx)(_y,{icon:(0,Y.jsx)(ha,{className:`h-4 w-4`}),label:`QR code`});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(Qi,{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)(Pe,{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)(py,{...e,icon:(0,Y.jsx)(eo,{className:`h-3.5 w-3.5`}),placeholder:`Lat, lng`});case`address`:return(0,Y.jsx)(my,{...e,placeholder:e.placeholder??`Street
|
|
23
23
|
City, State ZIP
|
|
24
24
|
Country`});case`formula`:case`summary`:return(0,Y.jsx)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:e.formula?`ƒ ${e.formula}`:`ƒ Computed value`});case`composite`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:`Composite — nested sub-fields edit in the inspector.`});case`repeater`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:`Repeater — repeating row group.`});case`vector`:return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:[`[0.124, 0.337, …] `,e.placeholder?`(${e.placeholder})`:``]});default:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Y.jsx)(V,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function py({placeholder:e,icon:t}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(W,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,Y.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function my({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 hy({options:e,placeholder:t,single:n}){let r=e??[],i=r.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:i[0]?.label||i[0]?.value||t||`Select…`}),(0,Y.jsx)(Ti,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,Y.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[i.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||`Pick one or more…`}):i.map((e,t)=>(0,Y.jsx)(V,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),r.length>i.length&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,r.length-i.length]})]})}function gy({referenceTo:e,placeholder:t}){let n=e?ay.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)(Di,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?`Search ${e}…`:`Choose related object…`)}),e&&(0,Y.jsxs)(V,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Y.jsx)(Wa,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),n&&null]})}function _y({icon:e,label:t}){return(0,Y.jsxs)(`div`,{className:`h-16 w-full border-2 border-dashed rounded flex flex-col items-center justify-center gap-1 text-muted-foreground bg-muted/20`,children:[e,(0,Y.jsx)(`span`,{className:`text-[11px]`,children:t})]})}function vy({objectName:e,draft:t,onPatch:n,selection:r,onSelectionChange:i}){let a=!n,o=J.useMemo(()=>Qv(t.fields),[t]),s=Array.isArray(t.fieldGroups)?t.fieldGroups:void 0,c=J.useMemo(()=>iy(o,s),[o,s]),l=r?.kind===`field`?String(r.id):null,u=J.useCallback(e=>{i&&i({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[i]),d=J.useCallback(e=>{if(!n)return;let t=o.entries.map(e=>e.name),r=e===`select`?`status`:e,a=1,s=r;for(;t.includes(s);)a+=1,s=`${r}_${a}`;let c=ty(s,e);n({fields:$v({shape:o.shape,entries:[...o.entries,c]})}),i?.({kind:`field`,id:s,label:String(c.def.label??s)})},[n,i,o]),f=J.useCallback((e,t,r)=>{if(!n||e===t)return;let i=o.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[s]=i.splice(a,1),c=i.findIndex(e=>e.name===t),l=c>=0?i[c]:void 0;if(l){let e=typeof l.def.group==`string`?l.def.group:void 0;e!==(typeof s.def.group==`string`?s.def.group:void 0)&&(s.def={...s.def,group:e})}c<0?i.push(s):i.splice(r===`before`?c:c+1,0,s),n({fields:$v({shape:o.shape,entries:i})})},[n,o]),p=J.useCallback((e,t)=>{if(!n)return;let r=o.entries.slice(),i=r.findIndex(t=>t.name===e);if(i<0)return;let[a]=r.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){r.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let s=r.length;for(let e=r.length-1;e>=0;--e)if((typeof r[e].def.group==`string`?r[e].def.group:null)===t){s=e+1;break}r.splice(s,0,a),n({fields:$v({shape:o.shape,entries:r})})},[n,o]),m=J.useCallback((e,t)=>{if(!n)return;let r=o.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);n({fields:$v({shape:o.shape,entries:r})})},[n,o]),h=J.useCallback(e=>{e.target===e.currentTarget&&l&&i?.(null)},[i,l]),g=o.entries.length===0;return(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:h,"data-object-name":e,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-6`,onClick:h,children:[g?(0,Y.jsx)(xy,{onAdd:a?void 0:d}):c.map(e=>(0,Y.jsx)(yy,{groupKey:e.key,label:e.label,showHeader:c.length>1,onDropField:a?void 0:p,children:e.entries.map(e=>(0,Y.jsx)(by,{entry:e,selected:e.name===l,readOnly:a,onClick:()=>u(e),onReorder:a?void 0:f,onRenameLabel:a?void 0:m},e.name))},e.key??`__ungrouped__`)),!g&&!a&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(Sy,{onPick:d})})]})})}function yy({groupKey:e,label:t,showHeader:n,onDropField:r,children:i}){let[a,o]=J.useState(!1);return(0,Y.jsxs)(`section`,{className:U(`space-y-2.5 rounded-md transition-colors`,a&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!r)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,o(!0))},onDragLeave:e=>{e.currentTarget===e.target&&o(!1)},onDrop:t=>{if(!r)return;if(t.defaultPrevented){o(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);o(!1),n&&r(n,e)},children:[n&&(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 flex items-center gap-1.5`,children:[t,a&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop to assign`})]}),(0,Y.jsx)(`div`,{className:`space-y-2.5`,children:i})]})}function by({entry:e,selected:t,readOnly:n,onClick:r,onReorder:i,onRenameLabel:a}){let o=e.def,s=typeof o.type==`string`?o.type:`text`,c=ay[s],l=c?.Icon,u=cy[c?.category??`advanced`],d=typeof o.label==`string`?o.label:e.name,f=!!o.required,p=typeof o.description==`string`?o.description:null,m=Array.isArray(o.options)?o.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,h=typeof o.reference==`string`?o.reference:void 0,g=typeof o.formula==`string`?o.formula:void 0,_=typeof o.placeholder==`string`?o.placeholder:void 0,[v,y]=J.useState(null),b=!!i,[x,S]=J.useState(!1),[C,w]=J.useState(d);J.useEffect(()=>{w(d)},[d]);let T=e=>{a&&(e.preventDefault(),e.stopPropagation(),w(d),S(!0))},E=()=>{if(!a){S(!1);return}let t=C.trim();t&&t!==d&&a(e.name,t),S(!1)},D=()=>{w(d),S(!1)};return(0,Y.jsxs)(`div`,{className:U(`relative`,v===`before`&&`pt-1.5`),onDragOver:e=>{if(!b)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();y(e.clientY-n.top<n.height/2?`before`:`after`)},onDragLeave:()=>y(null),onDrop:t=>{if(!i)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);y(null),n&&n!==e.name&&i(n,e.name,v??`before`)},children:[v===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:n?-1:0,onClick:r,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r?.())},draggable:b,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:U(`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&&`cursor-default`,b&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[b&&(0,Y.jsx)(On,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),l&&(0,Y.jsx)(l,{className:U(`h-3.5 w-3.5 shrink-0`,u.icon)}),x?(0,Y.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),E()):e.key===`Escape`&&(e.preventDefault(),D())},onBlur:E,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:U(`text-sm font-medium truncate`,a&&`cursor-text`),onDoubleClick:T,title:a?`Double-click to rename`:void 0,children:d}),f&&(0,Y.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,Y.jsx)(V,{variant:`outline`,className:U(`text-[10px] shrink-0 font-medium`,u.badge),children:c?.label??s})]}),p&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:p}),(0,Y.jsx)(fy,{type:s,label:d,placeholder:_,options:m,referenceTo:h,formula:g})]}),v===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function xy({onAdd:e}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No fields yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Add a field to start designing the form. Click any field to edit its properties on the right.`}),e&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsx)(Sy,{onPick:e})})]})}function Sy({onPick:e}){let[t,n]=J.useState(!1),[r,i]=J.useState(``),a=r.trim().toLowerCase(),o=J.useMemo(()=>a?uy.map(e=>({category:e.category,types:e.types.filter(e=>{let t=ay[e];return e.includes(a)||t.label.toLowerCase().includes(a)||t.labelZh.includes(r.trim())})})).filter(e=>e.types.length>0):uy,[a,r]);return(0,Y.jsxs)(br,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Fe,{asChild:!0,children:(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add field`]})}),(0,Y.jsxs)(jn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search field type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:sy[t.category]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=ay[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(a,{className:U(`h-3.5 w-3.5 shrink-0`,cy[r.category].icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label})]},t)})})]},t.category))})]})]})}function Cy({name:e,draft:t,onPatch:n,selection:r,onSelectionChange:i}){let a=String(t.name??e??``);return a?(0,Y.jsx)(L_,{hint:`object · designer`,children:(0,Y.jsx)(B_,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Y.jsx)(vy,{objectName:a,draft:t,onPatch:n,selection:r,onSelectionChange:i})})}):(0,Y.jsx)(L_,{hint:`object`,children:(0,Y.jsx)(R_,{children:`Give the object a name in the Form tab to enable the preview.`})})}function wy(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 Ty(e,t){return t[e]??``}function Ey(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Ty(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Ty(n,t))}function Dy({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 wy(t))e.add(n);for(let t of wy(i))e.add(t);for(let t of wy(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=J.useState({}),l=Ey(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
25
25
|
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
26
26
|
a{color:#2563eb;}
|
|
27
|
-
</style></head><body>${(i?Ey(i,s):Ey(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Y.jsx)(L_,{hint:`email_template`,children:(0,Y.jsx)(R_,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Y.jsx)(L_,{hint:`email_template`,children:(0,Y.jsx)(B_,{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)(Ln,{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 Oy(e){return typeof e==`number`&&Number.isFinite(e)}function ky(e){return Oy(e.ui?.x)&&Oy(e.ui?.y)}function Ay(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*188+(t.length-1)*40)/2;t.forEach((t,i)=>{n.set(t,{x:r+i*228,y:e*118})})}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)ky(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function jy(e){let t=0,n=0;for(let r of e.values())t=Math.max(t,r.x+188),n=Math.max(n,r.y+62);return{width:t+28,height:n+28}}function My(e){return{x:e.x+188/2,y:e.y+62}}function Ny(e){return{x:e.x+188/2,y:e.y}}function Py(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 Fy(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Iy(e,t){return e.id||`${e.source}->${e.target}#${t}`}function Ly(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Ry(e){switch(e){case`start`:return We;case`end`:return Ut;case`decision`:case`branch`:case`gateway`:return ze;case`wait`:case`timer`:case`delay`:return er;case`boundary_event`:case`signal`:return lo;case`subflow`:case`flow`:return Qe;case`create_record`:return pi;case`update_record`:return wr;case`delete_record`:return Jr;case`get_record`:return bi;case`http_request`:case`webhook`:return ei;case`script`:case`script_task`:return Pn;case`screen`:case`user_task`:return ii;case`approval`:return Be;case`connector_action`:case`service_task`:return po;case`assignment`:return ct;case`loop`:case`for_each`:return tt;case`parallel_gateway`:case`join_gateway`:case`parallel`:return Ma;default:return lr}}var zy={start:{icon:`text-emerald-600 dark:text-emerald-400`,accent:`border-l-emerald-500`,label:`text-emerald-600 dark:text-emerald-400`},end:{icon:`text-rose-600 dark:text-rose-400`,accent:`border-l-rose-500`,label:`text-rose-600 dark:text-rose-400`},decision:{icon:`text-amber-600 dark:text-amber-400`,accent:`border-l-amber-500`,label:`text-amber-600 dark:text-amber-400`},wait:{icon:`text-blue-600 dark:text-blue-400`,accent:`border-l-blue-500`,label:`text-blue-600 dark:text-blue-400`},signal:{icon:`text-violet-600 dark:text-violet-400`,accent:`border-l-violet-500`,label:`text-violet-600 dark:text-violet-400`},subflow:{icon:`text-indigo-600 dark:text-indigo-400`,accent:`border-l-indigo-500`,label:`text-indigo-600 dark:text-indigo-400`},task:{icon:`text-slate-500 dark:text-slate-400`,accent:`border-l-slate-400`,label:`text-slate-500 dark:text-slate-400`},record:{icon:`text-cyan-600 dark:text-cyan-400`,accent:`border-l-cyan-500`,label:`text-cyan-600 dark:text-cyan-400`},integration:{icon:`text-fuchsia-600 dark:text-fuchsia-400`,accent:`border-l-fuchsia-500`,label:`text-fuchsia-600 dark:text-fuchsia-400`},approval:{icon:`text-teal-600 dark:text-teal-400`,accent:`border-l-teal-500`,label:`text-teal-600 dark:text-teal-400`}};function By(e){switch(e){case`start`:return zy.start;case`end`:return zy.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return zy.decision;case`wait`:case`timer`:case`delay`:return zy.wait;case`boundary_event`:case`signal`:return zy.signal;case`subflow`:case`flow`:return zy.subflow;case`approval`:return zy.approval;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return zy.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return zy.integration;default:return zy.task}}function Vy({type:e,className:t}){return J.createElement(Ry(e),{className:t,"aria-hidden":!0})}var Hy=[{type:`create_record`,label:`Create record`,hint:`Insert a new record`},{type:`update_record`,label:`Update record`,hint:`Modify an existing record`},{type:`get_record`,label:`Get record`,hint:`Query records`},{type:`decision`,label:`Decision`,hint:`Branch on a condition`},{type:`loop`,label:`Loop`,hint:`Iterate over a collection`},{type:`http_request`,label:`HTTP request`,hint:`Call an external API`},{type:`connector_action`,label:`Connector`,hint:`Run an integration action`},{type:`script`,label:`Script`,hint:`Run custom code`},{type:`approval`,label:`Approval`,hint:`Pause for a human decision`},{type:`subflow`,label:`Subflow`,hint:`Invoke another flow`},{type:`wait`,label:`Wait`,hint:`Pause for an event or timer`},{type:`end`,label:`End`,hint:`Terminate the flow`}];function Uy(e){let t=Hy.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Wy(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 Gy({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=By(e);return(0,Y.jsxs)(`div`,{className:`absolute transition-opacity`,style:{left:r.x,top:r.y,width:188,height:62,opacity:s?.4: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:U(`group flex h-full w-full items-center gap-2.5 rounded-lg border border-l-[3px] bg-card px-3 py-2 text-left shadow-sm transition-all outline-none`,`hover:shadow-md focus-visible:ring-2 focus-visible:ring-primary/40`,d.accent,a?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o===`active`?`border-sky-500 ring-2 ring-sky-400/60 animate-pulse`:o===`visited`?`border-emerald-500/70 ring-1 ring-emerald-400/40`:i?`border-primary ring-2 ring-primary/30`:`border-border`),children:[(0,Y.jsx)(Vy,{type:e,className:U(`h-4 w-4 shrink-0`,d.icon)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-medium leading-tight`,children:t}),(0,Y.jsx)(`div`,{className:U(`truncate text-[10px] font-medium uppercase tracking-wide`,d.label),children:e})]}),n&&(0,Y.jsx)(`div`,{className:`max-w-[40%] shrink-0 truncate font-mono text-[10px] text-muted-foreground`,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:U(`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)(H,{className:`h-3.5 w-3.5`})})]})}function Ky({items:e=Hy,onPick:t,onClose:n}){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 max-h-[60vh] w-56 overflow-y-auto rounded-lg border bg-popover p-1 shadow-lg`,children:e.map(e=>{let n=By(e.type);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.type),className:`flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-accent`,children:[(0,Y.jsx)(Vy,{type:e.type,className:U(`h-4 w-4 shrink-0`,n.icon)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.label}),e.hint&&(0,Y.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.hint})]})]},e.type)})})]})}function qy(){return`${``.replace(/\/$/,``)}/api/v1`}function Jy(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})}return[...n.values()]}function Yy(){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(`${qy()}/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 Xy(){let e=Yy();return(0,J.useMemo)(()=>e.length?Jy(Hy,e):Hy,[e])}function Zy(){let e=Yy();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 Qy=.4,$y=1.6,eb=4;function tb({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=Xy(),[x,S]=J.useState(null),C=J.useRef(null),w=J.useRef(null),T=J.useMemo(()=>Ay(e,t),[e,t]),E=J.useMemo(()=>jy(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:Cv(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),ee=J.useCallback((n,r)=>{if(!f)return;let i=Ev(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Uy(n),o=r?.at??(r?.from?(()=>{let e=A(r.from);return{x:e.x,y:e.y+62+56}})():void 0),s={id:i,type:n,label:a,...Wy(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:wv(e,s)};r?.from&&(c.edges=wv(t,{id:Ev(`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=Ev(`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:Uy(r),...Wy(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:Ev(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=Cv(t,i,d);f({nodes:wv(e,l),edges:wv(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)<eb||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),re=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]),ie=J.useCallback(e=>{e.button===0&&(u(null),w.current={startX:e.clientX,startY:e.clientY,originX:g.x,originY:g.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[u,g.x,g.y]),ae=J.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),oe=J.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),P=e=>Math.min($y,Math.max(Qy,e)),se=J.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=P(Math.min(t,n,1));h(r),_({x:(e.clientWidth-E.width*r)/2,y:Math.max(16,(e.clientHeight-E.height*r)/2)})},[E.height,E.width]),ce=J.useCallback(e=>{if(!(!n||!i)&&(e.key===`Delete`||e.key===`Backspace`)){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;e.preventDefault(),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`,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 rounded-md border bg-background px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors hover:bg-accent`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),X(`engine.inspector.add.node`,o)]}),v&&(0,Y.jsx)(Ky,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>ee(e,{from:i??void 0})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background shadow-sm`,children:[(0,Y.jsx)(`button`,{type:`button`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>h(e=>P(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Ka,{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=>P(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:se,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(oo,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:ce,onPointerDown:ie,onPointerMove:e=>{ae(e),N(e)},onPointerUp:e=>{oe(e),re(e)},className:U(`h-full w-full cursor-grab outline-none active:cursor-grabbing`,`bg-[radial-gradient(circle_at_1px_1px,theme(colors.border)_1px,transparent_0)] [background-size:16px_16px] bg-muted/20`),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/60`})})}),t.map((e,t)=>{let i=T.get(e.source),o=T.get(e.target);if(!i||!o)return null;let s=My(x?.id===e.source?A(e.source):i),c=Ny(x?.id===e.target?A(e.target):o),l=Fy(s,c),u=Ly(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=Iy(e,t),m=O.has(p),h=a===p,g=Py(s,c),_=r&&!!d;return(0,Y.jsxs)(`g`,{children:[(0,Y.jsx)(`path`,{d:g,className:U(`fill-none`,m?`stroke-sky-500`:h?`stroke-primary`:k?`stroke-muted-foreground/25`:`stroke-muted-foreground/50`),strokeWidth:m||h?2.5:1.5,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:U(_&&`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:U(`max-w-full truncate rounded border bg-background px-1.5 py-0.5 text-[10px] font-medium shadow-sm`,_&&`cursor-pointer`,h?`border-primary text-primary`:`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 text-muted-foreground opacity-60 shadow-sm transition-all hover:scale-110 hover:border-primary hover:text-primary hover:opacity-100 focus-visible:opacity-100`,children:(0,Y.jsx)(H,{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)(Gy,{id:e.id,type:e.type,label:e.label||e.id,summary:nb(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 nb(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 rb=e=>typeof e==`string`?e:void 0;function ib(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 ab(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=>rb(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 ob=500,sb=new Set([`start`,`assignment`]),cb=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),lb=new Set([`join_gateway`,`subflow`,`boundary_event`]),ub=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,db=e=>typeof e==`string`?e:void 0,fb=e=>typeof e==`string`&&e?e:void 0,pb=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=ab([...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>=ob)return e.status=`error`,e.error=`Step limit (${ob}) 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(lb.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(cb.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:sb.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=db(e.condition);if(!t){n.push({edgeId:ub(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=ib(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:ub(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:ub(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=fb(e.config?.collection),n=fb(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=fb(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=fb(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=ub(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 mb(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 hb=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function gb(e){let t=[];for(let n of e){if(!hb.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 _b={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 vb({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(()=>gb(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:mb(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=mb(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]=mb(n));return e},[h]),b=J.useCallback(()=>{let n=new pb(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)(K,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:D,children:[(0,Y.jsx)(We,{className:`h-3.5 w-3.5`}),` Run`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:D||E===`done`||E===`error`,children:[(0,Y.jsx)(An,{className:`h-3.5 w-3.5`}),` Step`]}),E===`paused`&&(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,Y.jsx)(ea,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:T,children:[(0,Y.jsx)(Wn,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Y.jsx)(`span`,{className:U(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,_b[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)(Ne,{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)(Tn,{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)(G,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,Y.jsx)(W,{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)(H,{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)(W,{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)(W,{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)(Xt,{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)(G,{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)(W,{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:U(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,_b[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:U(`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:U(`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 yb({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:Ev(`node`,s.map(e=>e.id).filter(Boolean)),type:`task`,label:`New node`};i({nodes:wv(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)(L_,{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)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.node`,a)]})}):(0,Y.jsx)(R_,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Y.jsx)(L_,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Y.jsx)(B_,{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)(bb,{icon:lo,label:`Trigger`,value:x}),(0,Y.jsx)(bb,{icon:lr,label:`Status`,value:S,tone:S===`active`?`green`:S===`draft`?`gray`:`amber`}),(0,Y.jsx)(bb,{icon:fi,label:`Run as`,value:C}),w&&(0,Y.jsx)(bb,{label:`v`,value:w}),T&&(0,Y.jsx)(bb,{icon:$i,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)(sr,{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)(qa,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Y.jsx)(tb,{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)(vb,{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)(ct,{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 bb({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 xb({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)(L_,{hint:`agent`,children:(0,Y.jsx)(R_,{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)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)($e,{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)(Ab,{icon:c?no:Rn,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Y.jsx)(Ab,{icon:Un,label:l}),u.provider&&(0,Y.jsx)(Ab,{icon:ra,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Y.jsx)(Ab,{icon:xa,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Y.jsx)(Ab,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Y.jsx)(Cb,{title:`Instructions`,icon:so,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)(wb,{children:`No system prompt set yet.`})}),(0,Y.jsx)(Cb,{title:`Capabilities`,icon:zn,children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(Eb,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:ra,tone:`violet`,mono:!0}),(0,Y.jsx)(Eb,{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:zn,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Y.jsx)(Cb,{title:`Knowledge (RAG)`,icon:Ai,children:(0,Y.jsx)(Sb,{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)(Db,{icon:Lr,title:`Planning`,children:(0,Y.jsx)(Ob,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Y.jsx)(Db,{icon:Dt,title:`Memory`,children:(0,Y.jsx)(Ob,{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)(Db,{icon:qr,title:`Guardrails`,children:(0,Y.jsx)(Ob,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Y.jsx)(Db,{icon:Un,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 Sb({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)(Ai,{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 Cb({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 wb({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var Tb={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 Eb({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?Tb[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:U(`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:U(`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 Db({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 Ob({data:e,keys:t}){let n=t.map(t=>[t,kb(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 kb(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function Ab({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 jb(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function Mb(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${Mb(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Nb(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 Pb({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=jb(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]=Nb(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Nb(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Y.jsx)(L_,{hint:`tool`,children:(0,Y.jsx)(R_,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Y.jsx)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)(zn,{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)(Rb,{icon:va,label:o}),s&&(0,Y.jsx)(Rb,{icon:Ai,label:s,mono:!0}),(0,Y.jsx)(Rb,{icon:jt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Y.jsx)(Rb,{icon:Tn,label:`Requires confirmation`,tone:`amber`}),u&&(0,Y.jsx)(Rb,{label:`built-in`})]})]})]}),a&&(0,Y.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Y.jsx)(Ib,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Y.jsx)(Lb,{children:`This tool takes no input parameters.`}):(0,Y.jsx)(Fb,{props:p,required:m})}),Object.keys(p).length>0&&(0,Y.jsx)(Ib,{title:`Example LLM Call`,icon:co,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:`{
|
|
27
|
+
</style></head><body>${(i?Ey(i,s):Ey(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Y.jsx)(L_,{hint:`email_template`,children:(0,Y.jsx)(R_,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Y.jsx)(L_,{hint:`email_template`,children:(0,Y.jsx)(B_,{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)(Ln,{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 Oy(e){return typeof e==`number`&&Number.isFinite(e)}function ky(e){return Oy(e.ui?.x)&&Oy(e.ui?.y)}function Ay(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)ky(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function jy(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 My(e){return{x:e.x+240/2,y:e.y+66}}function Ny(e){return{x:e.x+240/2,y:e.y}}function Py(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 Fy(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function Iy(e,t){return e.id||`${e.source}->${e.target}#${t}`}function Ly(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Ry(e){switch(e){case`start`:return We;case`end`:return Ut;case`decision`:case`branch`:case`gateway`:return ze;case`wait`:case`timer`:case`delay`:return er;case`boundary_event`:case`signal`:return lo;case`subflow`:case`flow`:return Qe;case`create_record`:return pi;case`update_record`:return wr;case`delete_record`:return Jr;case`get_record`:return bi;case`http_request`:case`webhook`:return ei;case`script`:case`script_task`:return Pn;case`screen`:case`user_task`:return ii;case`approval`:return Be;case`connector_action`:case`service_task`:return po;case`assignment`:return ct;case`loop`:case`for_each`:return tt;case`parallel_gateway`:case`join_gateway`:case`parallel`:return Ma;default:return lr}}var zy={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 By(e){switch(e){case`start`:return zy.start;case`end`:return zy.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return zy.decision;case`wait`:case`timer`:case`delay`:return zy.wait;case`boundary_event`:case`signal`:return zy.signal;case`subflow`:case`flow`:return zy.subflow;case`approval`:return zy.approval;case`loop`:case`for_each`:return zy.loop;case`screen`:case`user_task`:return zy.screen;case`assignment`:return zy.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return zy.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return zy.integration;default:return zy.task}}function Vy({type:e,className:t}){return J.createElement(Ry(e),{className:t,"aria-hidden":!0})}var Hy=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Uy(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 Wy=[{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 Gy(e){let t=Wy.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Ky(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 qy({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=By(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:U(`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:U(`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)(Vy,{type:e,className:U(`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:U(`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:U(`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)(H,{className:`h-3.5 w-3.5`})})]})}function Jy({items:e=Wy,onPick:t,onClose:n}){let r=J.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??Uy(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return Hy.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=By(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:U(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,Y.jsx)(Vy,{type:e.type,className:U(`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:U(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 Yy(){return`${``.replace(/\/$/,``)}/api/v1`}function Xy(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??Uy(e.type)})}return[...n.values()]}function Zy(){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(`${Yy()}/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 Qy(){let e=Zy();return(0,J.useMemo)(()=>e.length?Xy(Wy,e):Wy,[e])}function $y(){let e=Zy();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 eb=.4,tb=1.6,nb=4;function rb({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=Qy(),[x,S]=J.useState(null),C=J.useRef(null),w=J.useRef(null),T=J.useMemo(()=>Ay(e,t),[e,t]),E=J.useMemo(()=>jy(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:Cv(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),ee=J.useCallback((n,r)=>{if(!f)return;let i=Ev(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Gy(n),o=r?.at,s={id:i,type:n,label:a,...Ky(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:wv(e,s)};r?.from&&(c.edges=wv(t,{id:Ev(`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=Ev(`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:Gy(r),...Ky(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:Ev(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=Cv(t,i,d);f({nodes:wv(e,l),edges:wv(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)<nb||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),re=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]),ie=J.useCallback(e=>{e.button===0&&(u(null),w.current={startX:e.clientX,startY:e.clientY,originX:g.x,originY:g.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[u,g.x,g.y]),ae=J.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),oe=J.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),P=e=>Math.min(tb,Math.max(eb,e)),se=J.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=P(Math.min(t,n,1));h(r),_({x:(e.clientWidth-E.width*r)/2,y:Math.max(16,(e.clientHeight-E.height*r)/2)})},[E.height,E.width]),ce=J.useCallback(e=>{if(!(!n||!i)&&(e.key===`Delete`||e.key===`Backspace`)){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;e.preventDefault(),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)(H,{className:`h-3.5 w-3.5`}),X(`engine.inspector.add.node`,o)]}),v&&(0,Y.jsx)(Jy,{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=>P(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Ka,{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=>P(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:se,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(oo,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:ce,onPointerDown:ie,onPointerMove:e=>{ae(e),N(e)},onPointerUp:e=>{oe(e),re(e)},className:U(`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=My(x?.id===e.source?A(e.source):i),c=Ny(x?.id===e.target?A(e.target):o),l=Fy(s,c),u=Ly(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=Iy(e,t),m=O.has(p),h=a===p,g=Py(s,c),_=r&&!!d;return(0,Y.jsxs)(`g`,{children:[(0,Y.jsx)(`path`,{d:g,strokeLinecap:`round`,className:U(`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:U(_&&`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:U(`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)(H,{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)(qy,{id:e.id,type:e.type,label:e.label||e.id,summary:ib(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 ib(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 ab=e=>typeof e==`string`?e:void 0;function ob(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 sb(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=>ab(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 cb=500,lb=new Set([`start`,`assignment`]),ub=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),db=new Set([`join_gateway`,`subflow`,`boundary_event`]),fb=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,pb=e=>typeof e==`string`?e:void 0,mb=e=>typeof e==`string`&&e?e:void 0,hb=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=sb([...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>=cb)return e.status=`error`,e.error=`Step limit (${cb}) 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(db.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(ub.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:lb.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=pb(e.condition);if(!t){n.push({edgeId:fb(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=ob(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:fb(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:fb(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=mb(e.config?.collection),n=mb(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=mb(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=mb(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=fb(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 gb(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 _b=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function vb(e){let t=[];for(let n of e){if(!_b.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 yb={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 bb({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(()=>vb(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:gb(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=gb(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]=gb(n));return e},[h]),b=J.useCallback(()=>{let n=new hb(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)(K,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:D,children:[(0,Y.jsx)(We,{className:`h-3.5 w-3.5`}),` Run`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:D||E===`done`||E===`error`,children:[(0,Y.jsx)(An,{className:`h-3.5 w-3.5`}),` Step`]}),E===`paused`&&(0,Y.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,Y.jsx)(ea,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,Y.jsxs)(K,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:T,children:[(0,Y.jsx)(Wn,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Y.jsx)(`span`,{className:U(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,yb[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)(Ne,{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)(Tn,{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)(G,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,Y.jsx)(W,{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)(H,{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)(W,{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)(W,{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)(Xt,{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)(G,{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)(W,{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:U(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,yb[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:U(`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:U(`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 xb({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:Ev(`node`,s.map(e=>e.id).filter(Boolean)),type:`task`,label:`New node`};i({nodes:wv(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)(L_,{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)(H,{className:`h-3 w-3`}),X(`engine.inspector.add.node`,a)]})}):(0,Y.jsx)(R_,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Y.jsx)(L_,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Y.jsx)(B_,{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)(Sb,{icon:lo,label:`Trigger`,value:x}),(0,Y.jsx)(Sb,{icon:lr,label:`Status`,value:S,tone:S===`active`?`green`:S===`draft`?`gray`:`amber`}),(0,Y.jsx)(Sb,{icon:fi,label:`Run as`,value:C}),w&&(0,Y.jsx)(Sb,{label:`v`,value:w}),T&&(0,Y.jsx)(Sb,{icon:$i,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)(sr,{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)(qa,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Y.jsx)(rb,{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)(bb,{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)(ct,{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 Sb({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 Cb({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)(L_,{hint:`agent`,children:(0,Y.jsx)(R_,{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)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)($e,{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)(Mb,{icon:c?no:Rn,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Y.jsx)(Mb,{icon:Un,label:l}),u.provider&&(0,Y.jsx)(Mb,{icon:ra,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Y.jsx)(Mb,{icon:xa,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Y.jsx)(Mb,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Y.jsx)(Tb,{title:`Instructions`,icon:so,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)(Eb,{children:`No system prompt set yet.`})}),(0,Y.jsx)(Tb,{title:`Capabilities`,icon:zn,children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(Ob,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:ra,tone:`violet`,mono:!0}),(0,Y.jsx)(Ob,{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:zn,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Y.jsx)(Tb,{title:`Knowledge (RAG)`,icon:Ai,children:(0,Y.jsx)(wb,{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)(kb,{icon:Lr,title:`Planning`,children:(0,Y.jsx)(Ab,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Y.jsx)(kb,{icon:Dt,title:`Memory`,children:(0,Y.jsx)(Ab,{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)(kb,{icon:qr,title:`Guardrails`,children:(0,Y.jsx)(Ab,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Y.jsx)(kb,{icon:Un,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 wb({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)(Ai,{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 Tb({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 Eb({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var Db={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 Ob({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?Db[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:U(`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:U(`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 kb({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 Ab({data:e,keys:t}){let n=t.map(t=>[t,jb(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 jb(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function Mb({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 Nb(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function Pb(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${Pb(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Fb(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 Ib({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=Nb(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]=Fb(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Fb(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Y.jsx)(L_,{hint:`tool`,children:(0,Y.jsx)(R_,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Y.jsx)(L_,{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)(Ze,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(B_,{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)(zn,{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)(Bb,{icon:va,label:o}),s&&(0,Y.jsx)(Bb,{icon:Ai,label:s,mono:!0}),(0,Y.jsx)(Bb,{icon:jt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Y.jsx)(Bb,{icon:Tn,label:`Requires confirmation`,tone:`amber`}),u&&(0,Y.jsx)(Bb,{label:`built-in`})]})]})]}),a&&(0,Y.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Y.jsx)(Rb,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Y.jsx)(zb,{children:`This tool takes no input parameters.`}):(0,Y.jsx)(Lb,{props:p,required:m})}),Object.keys(p).length>0&&(0,Y.jsx)(Rb,{title:`Example LLM Call`,icon:co,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
28
|
"tool": "${r}",
|
|
29
29
|
"arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
|
|
30
30
|
`)}
|
|
31
|
-
}`})}),jb(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Ib,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Bn,children:(0,Y.jsx)(Fb,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Fb({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)(vr,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(ea,{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:Mb(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 Ib({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 Lb({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Rb({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 zb=[{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 Bb(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 Vb({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(()=>Bb(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)(L_,{hint:`permission`,children:(0,Y.jsx)(R_,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(L_,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(B_,{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)(Pe,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(ai,{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)(Gb,{icon:At,label:`${d.length} objects`}),(0,Y.jsx)(Gb,{icon:va,label:`${c.length} system perms`}),(0,Y.jsx)(Gb,{icon:no,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(Gb,{icon:Un,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Wb,{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`}),zb.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}),zb.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(Hb,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Ub,{})]}),p.size>0&&(0,Y.jsx)(Wb,{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)(Wb,{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)(Wb,{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)(Tn,{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 Hb({granted:e,danger:t}){return e?(0,Y.jsx)(vr,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(Xn,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Ub(){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)(vr,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(vr,{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)(Xn,{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 Wb({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 Gb({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 Kb(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 qb(e){switch(e){case`url`:return Di;case`modal`:return Sn;case`flow`:return Qe;case`api`:return ei;case`form`:return vt;default:return ho}}function Jb(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 Yb(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 Xb({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Kb(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=Kb(n.confirmText),g=Kb(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=qb(o),w=l===`action:icon`;return!r&&!i?(0,Y.jsx)(L_,{hint:`action`,children:(0,Y.jsx)(R_,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(L_,{hint:`action`,children:(0,Y.jsx)(B_,{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)(Zb,{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)(ix,{icon:C,label:`type: ${o}`}),b&&(0,Y.jsx)(ix,{icon:ja,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(ix,{label:`variant: ${c}`}),l&&(0,Y.jsx)(ix,{icon:Xa,label:l}),d&&(0,Y.jsx)(ix,{icon:Mn,label:d,mono:!0}),f&&(0,Y.jsx)(ix,{icon:Fr,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(ix,{icon:Le,label:`refresh after`}),m===!1&&(0,Y.jsx)(ix,{icon:$e,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(ix,{icon:ra,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)(nx,{label:`Visible when`,value:x,icon:no}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(nx,{label:`Disabled when`,value:S,icon:Un})]}),(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:Yb(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)(Tn,{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)(rx,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)($b,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(rx,{title:`Result Dialog`,icon:no,children:(0,Y.jsx)(tx,{dialog:v})}),y?.source&&(0,Y.jsx)(rx,{title:`Script Body (${y.language??`expression`})`,icon:ho,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 Zb({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 ${Jb(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(Qb,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function Qb({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=mi[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 $b({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:[Kb(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})]}),ex(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 ${Jb(n||`primary`)}`,children:`OK`})]})]})}function ex(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:Kb(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 tx({dialog:e}){let t=Kb(e.title)||`Result`,n=Kb(e.description),r=Kb(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:Kb(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 nx({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 rx({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({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 ax={"@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 ox(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 sx(e){let t=(ax[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=ox(n,0,59),c=ox(r,0,23),l=ox(i,1,31),u=ox(a,1,12),d=ox(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function cx(e,t,n){let r=sx(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 lx(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 ux(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function dx(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function fx(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?px(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`?px(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function px(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 mx({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}=fx(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?lx(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=cx(o,e,5);else if(_)t=ux(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>hx(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(L_,{hint:`job`,children:(0,Y.jsx)(R_,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(L_,{hint:`job`,children:(0,Y.jsx)(B_,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(tr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(vx,{icon:jt,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(vx,{icon:st,label:l,mono:!0}),p!=null&&(0,Y.jsx)(vx,{icon:Wn,label:`retries: ${p}${m?` (${px(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(vx,{icon:go,label:`timeout: ${px(h)}`}),g!=null&&(0,Y.jsx)(vx,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(_x,{title:`Schedule`,icon:Xi,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(gx,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(gx,{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)(gx,{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)(_x,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:Ke,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)(Ke,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:dx(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(_x,{title:`Handler`,icon:ho,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)(mr,{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 hx(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 gx({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 _x({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 vx({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 yx=[{key:`objects`,label:`Objects`,icon:Ni,flat:!1},{key:`apps`,label:`Apps`,icon:Je,flat:!1},{key:`messages`,label:`Messages`,icon:Sr,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:ua,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Tt,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:dt,flat:!1},{key:`settings`,label:`Settings`,icon:fi,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:da,flat:!1}];function bx({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=yx.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/yx.length*100);return c===0?(0,Y.jsx)(L_,{hint:`translation · ${r}`,children:(0,Y.jsx)(R_,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(L_,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(B_,{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)(Kt,{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)(st,{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)(xa,{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,`/`,yx.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)(xx,{cat:e},e.key))})]})})})}function xx({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:Sx(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 Sx(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Cx({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)(L_,{hint:`role`,children:(0,Y.jsx)(B_,{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)(rt,{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)(Bt,{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)(dn,{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)(ai,{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)(L_,{hint:`role`,children:(0,Y.jsx)(R_,{children:`Give the role a name to see the preview.`})})}function wx({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)(L_,{hint:`skill`,children:(0,Y.jsx)(B_,{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)(ra,{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)(Ex,{icon:jt,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(Ex,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(Ex,{icon:ai,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(Tx,{title:`Instructions`,icon:Kn,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)(Tx,{title:`Tools (${s.length})`,icon:zn,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)(Mi,{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)(Tx,{title:`Trigger Phrases (${c.length})`,icon:vi,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)(Tx,{title:`Trigger Conditions (${l.length})`,icon:Ar,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)(Tx,{title:`Required Permissions`,icon:ai,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)(L_,{hint:`skill`,children:(0,Y.jsx)(R_,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Tx({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 Ex({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 Dx=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Ox=D();function kx(){return``.replace(/\/+$/,``)}function Ax(e){return`${kx()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function jx(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 Dx}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 Mx(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await jx(await Ox(`${Ax(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Nx(e,t,n={}){return(await jx(await Ox(`${Ax(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Px(e){return(await jx(await Ox(`${Ax(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Fx(e){return jx(await Ox(`${Ax(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Ix(e){await jx(await Ox(`${kx()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Lx({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 Nx(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof Dx?`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 Ix(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)(ft,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Mt,{className:`max-w-2xl`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ai,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(Jt,{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)(vr,{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)(Tn,{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)(Ga,{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)(Nn,{children:a===`done`?(0,Y.jsx)(K,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(K,{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 Rx({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 Mx(e)),n(`loaded`)}catch(e){e instanceof Dx?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)(zx,{}):(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)(Wa,{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)(K,{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)(Le,{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)(hr,{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)(Yt,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(Lx,{datasource:e,table:l,open:d,onOpenChange:f})]})}function zx(){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 Bx={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 Vx({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 Fx(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof Dx?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)(K,{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)(mr,{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)(vr,{className:`h-4 w-4`}):(0,Y.jsx)(ua,{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)(Hx,{result:e},e.object))})]})}function Hx({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)(ai,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(ua,{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)(Ux,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Ux({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:Bx[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 Wx({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 Px(e))}catch(e){c(e instanceof Dx?`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)(rn,{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)(Ke,{className:`h-3 w-3`}),`snapshot `,Gx(r.snapshotAt)]}),(0,Y.jsxs)(K,{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)(Le,{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)(Fa,{children:[(0,Y.jsx)(ta,{value:`tables`,children:`Tables`}),(0,Y.jsx)(ta,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(ri,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(Rx,{datasource:e})}),(0,Y.jsx)(ri,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(Vx,{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 Gx(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Kx=/pass|secret|key|token|credential|auth/i;function qx(e){return Kx.test(e)}function Jx(e){return e==null||e===``?`∅`:`••••••`}function Yx(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 Xx({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)(L_,{hint:`datasource`,children:(0,Y.jsx)(R_,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(L_,{hint:`datasource · ${o}`,children:(0,Y.jsx)(B_,{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)(Ai,{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)(or,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)($x,{icon:jt,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)($x,{icon:Pe,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)($x,{icon:pt,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(Wx,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(Qx,{title:`Connection`,icon:Un,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=qx(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:Jx(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`})]}):Yx(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(Zx,{title:`Pool`,icon:Dt,value:u}),(0,Y.jsx)(Zx,{title:`SSL`,icon:ai,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)(Zx,{title:`Retry Policy`,icon:Wn,value:f}),(0,Y.jsx)(Zx,{title:`Health Check`,icon:Dt,value:p})]}),h.length>0&&(0,Y.jsx)(Qx,{title:`Capabilities`,icon:ai,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 Zx({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:qx(e)?Jx(t):Yx(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function Qx({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 $x({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 eS(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function tS(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:Dr};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:Tn};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:wt}}}function nS({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=tS(l);return r?(0,Y.jsx)(L_,{hint:`validation · ${o}`,children:(0,Y.jsx)(B_,{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)(ua,{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)(oS,{icon:jt,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(oS,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(oS,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(oS,{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)(rS,{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)(L_,{hint:`validation`,children:(0,Y.jsx)(R_,{children:`Give the validation a name to see the preview.`})})}function rS({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(aS,{title:`Condition`,icon:ho,children:(0,Y.jsx)(iS,{value:eS(t.condition)??eS(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=eS(t.scope)??eS(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(aS,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Ui,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)(aS,{title:`Scope`,icon:Vi,children:(0,Y.jsx)(iS,{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)(aS,{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)(ht,{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)(aS,{title:`Format`,icon:Pi,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=eS(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(aS,{title:`Fields involved`,icon:Vi,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)(aS,{title:`Cross-field condition`,icon:ho,children:(0,Y.jsx)(iS,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(aS,{title:`Async endpoint`,icon:st,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)(aS,{title:`Custom handler`,icon:ho,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)(aS,{title:`Rule`,icon:ua,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 iS({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 aS({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 oS({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 sS(){Lg(`page`,nv),Lg(`view`,mv),Lg(`dashboard`,Nv),Lg(`report`,Iv),Lg(`app`,Yv),Lg(`action`,Xb),Lg(`object`,Cy),Lg(`datasource`,Xx),Lg(`validation`,nS),Lg(`email_template`,Dy),Lg(`translation`,bx),Lg(`flow`,yb),Lg(`job`,mx),Lg(`agent`,xb),Lg(`tool`,Pb),Lg(`skill`,wx),Lg(`permission`,Vb),Lg(`profile`,Vb),Lg(`role`,Cx)}var cS=[{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`}],lS=[`count`,`sum`,`avg`,`min`,`max`],uS=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function dS(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 fS({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Y.jsx)(mS,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=dS(e,t.id);if(!s)return(0,Y.jsx)(mS,{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:Tv(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)(gv,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(pS,{id:`widget-title`,label:X(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(W,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,Y.jsx)(pS,{id:`widget-type`,label:X(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(In,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-type`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:cS.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsx)(pS,{id:`widget-object`,label:X(`engine.inspector.widget.object`,o),children:(0,Y.jsx)(W,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,Y.jsx)(pS,{id:`widget-value-field`,label:X(`engine.inspector.widget.valueField`,o),children:(0,Y.jsx)(W,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,Y.jsx)(pS,{id:`widget-category-field`,label:X(`engine.inspector.widget.categoryField`,o),children:(0,Y.jsx)(W,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,Y.jsx)(pS,{id:`widget-aggregate`,label:X(`engine.inspector.widget.aggregate`,o),children:(0,Y.jsxs)(In,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-aggregate`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:lS.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Y.jsx)(pS,{id:`widget-color`,label:X(`engine.inspector.widget.color`,o),children:(0,Y.jsxs)(In,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-color`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:uS.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(pS,{id:`widget-w`,label:X(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(W,{id:`widget-w`,type:`number`,min:1,value:c.layout?.w??1,onChange:e=>d({layout:{...c.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,Y.jsx)(pS,{id:`widget-h`,label:X(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(W,{id:`widget-h`,type:`number`,min:1,value:c.layout?.h??1,onChange:e=>d({layout:{...c.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,Y.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Y.jsx)(K,{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 pS({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(G,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function mS({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)(K,{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 hS(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var gS=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),_S={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:gS,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:[hS(`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`}),hS(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),hS(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),hS(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),hS(`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:[hS(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),hS(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),hS(`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:[hS(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),hS(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),hS(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),hS(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),hS(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),hS(`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`})]},vS={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 yS(e){return e?_S[vS[e]??e]??[]:[]}function bS(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 xS(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function SS(e,t,n){if(!e.showWhen)return!0;let r=bS(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=bS(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 CS=[`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`],wS=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function TS(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`&&wS.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&wS.has(t.kind))return{kind:t.kind,...n}}function ES(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 DS(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function OS(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 kS(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:ES(e)}))}function AS(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 jS(e){if(Array.isArray(e.enum))return`select`;let t=OS(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function MS(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!DS(r))continue;let t=OS(r),i,a,o=TS(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=kS(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||ES(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function NS(e,t){return{label:e.title||ES(t),...e.description?{help:e.description}:{},...AS(e)?{defaultValue:AS(e)}:{}}}function PS(e){if(!DS(e)||OS(e)!==`object`||!DS(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!DS(r))continue;let e=OS(r);if(e===`array`){let e=DS(r.items)?r.items:void 0,i=e?OS(e):void 0;e&&i===`object`&&DS(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:MS(e),...NS(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...NS(r,n)});continue}if(e===`object`&&DS(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>DS(e)),i=e.some(([e,t])=>e===`enabled`&&OS(t)===`boolean`);for(let[a,o]of e){let e=o,s=TS(e),c=s?`reference`:jS(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||ES(n),...r.description?{help:r.description}:{},...AS(e)?{defaultValue:AS(e)}:{}}:NS(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:kS(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=TS(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...NS(r,n)});continue}let a=jS(r);a&&t.push({id:n,path:[`config`,n],kind:a,...NS(r,n),...a===`select`&&Array.isArray(r.enum)?{options:kS(r.enum)}:{}})}return t}function FS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function IS(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function LS(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 RS(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=Ev(`kv`,n);return n.push(r),{id:r,key:e,raw:IS(t)}})}function zS(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=LS(n.raw))}return t}function BS(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function VS({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=FS(t)?t:{},[d,f]=J.useState(()=>RS(u,[])),p=J.useRef(BS(u));J.useEffect(()=>{let e=BS(u);e!==p.current&&(f(RS(u,[])),p.current=e)},[u]);let m=e=>{let t=zS(e);p.current=BS(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:Ev(`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)(G,{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)(W,{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)(W,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,Y.jsx)(H,{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 HS(e,t){let n=[...t];return e.map(e=>{let t=Ev(`sl`,n);return n.push(t),{id:t,value:e}})}function US(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function WS({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(()=>HS(c,[])),d=J.useRef(JSON.stringify(c));J.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(HS(c,[])),d.current=e)},[c]);let f=e=>{let t=US(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:Ev(`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)(G,{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)(W,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}function GS(e){let t=hm(),[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:Qv(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 KS={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function qS(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 JS(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 YS(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?JS((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):JS(n.node,r)}function XS(e){let t=hm(),[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 ZS({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?YS(e.kind,e.objectSource,l):void 0,{fields:f}=GS(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?KS[u]:void 0,{options:m}=XS(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)(W,{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 QS({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=qS(e.ref,e=>JS(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(ZS,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function $S(e,t){let n=[];return e.map(e=>{let r=Ev(`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 eC(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 tC({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(()=>$S(l,t)),f=J.useRef(JSON.stringify(l));J.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d($S(l,t)),f.current=e)},[l,t]);let p=e=>{let n=eC(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:Ev(`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)(G,{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)(K,{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)(ro,{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)(G,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(yt,{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)(ZS,{resolved:qS(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)(W,{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)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function nC({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(QS,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(VS,{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)(WS,{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)(tC,{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)(vv,{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)(bv,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(yv,{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)(G,{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)(_v,{label:e.label,value:t==null?``:String(t),placeholder:e.placeholder,onCommit:e=>n(e),disabled:r,mono:e.kind===`expression`})}})(),e.help&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}function rC(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function iC(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=iC(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function aC({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=Zy(),u=J.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:PS(e))??yS(c?.type)},[l,c?.type]),d=rC(c),f=u.filter(e=>SS(e,c,u)),p=J.useMemo(()=>{let e=new Set;for(let t of u){let n=xS(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)(hv,{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)(Sv,{message:e.id})});let C=e=>{n({nodes:Cv(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:Cv(o,s,iC(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:Cv(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:Cv(o,s,null)}),r()},O=CS.includes(c.type)?[...CS]:[...CS,c.type??``].filter(Boolean);return(0,Y.jsxs)(hv,{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)(xv,{label:X(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,Y.jsx)(yv,{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)(_v,{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)(nC,{field:e,value:bS(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)(H,{className:`h-3 w-3`}),X(`engine.inspector.flowNode.advanced`,i)]})]})}function oC({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{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 sC({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)=>Iy(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,Y.jsx)(hv,{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)(Sv,{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:Cv(o,s,t)})},u=c.isDefault===!0;return(0,Y.jsxs)(hv,{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)(xv,{label:X(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:Cv(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(oC,{label:X(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(oC,{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)(_v,{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)(_v,{label:X(`engine.inspector.flowEdge.condition`,i),value:Ly(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:X(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(0,Y.jsx)(bv,{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 cC(e){return e.selection.kind===`edge`?(0,Y.jsx)(sC,{...e}):(0,Y.jsx)(aC,{...e})}var lC=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function uC(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 dC(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 fC(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:Cv(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=Cv(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function pC(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 mC({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=uC(e.id),{node:c,parent:l,index:u}=s?dC(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Y.jsx)(hv,{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)(Sv,{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(fC(t,s,{...c,...e}))};return(0,Y.jsxs)(hv,{kindLabel:X(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:X(`engine.inspector.appNav.close`,a),headerActions:(0,Y.jsx)(gv,{index:u,total:l.length,onMove:e=>{n(pC(t,s,Tv(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)(xv,{label:X(`engine.inspector.appNav.remove`,a),onClick:()=>{n(fC(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(_v,{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)(_v,{label:X(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Y.jsx)(yv,{label:X(`engine.inspector.appNav.kindField`,a),value:c.kind,options:lC.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var hC={io:`input`,unrepresentable:`any`},gC=new Set([`columns`,`data`,`name`]),_C,vC=!1;function yC(){if(_C||vC)return _C;try{_C=M(re,hC)}catch(e){vC=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return _C}function bC(){return yC()?.properties?.list}function xC(){return yC()?.properties?.form}var SC,CC=!1;function wC(){if(SC||CC)return SC;try{SC=M(ne,hC)}catch(e){CC=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return SC}var TC;function EC(){if(TC)return TC;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!gC.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),TC=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return TC}}var DC=`text/x-objectui-viewcol`;function OC({type:e}){let t=dy(e),n=ly(e),r=t.Icon;return(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function kC({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(DC,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(DC)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(DC)&&(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)(On,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,Y.jsx)(OC,{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)(ro,{className:`h-3 w-3`})})]})]})}function AC({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)(br,{open:a,onOpenChange:o,children:[(0,Y.jsx)(Fe,{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)(H,{className:`h-3.5 w-3.5`}),` Add field`]})}),(0,Y.jsxs)(jn,{align:`start`,className:`w-72 p-0`,children:[(0,Y.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,Y.jsx)(Wa,{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)(jC,{children:`Loading fields…`}):r?(0,Y.jsxs)(jC,{tone:`warn`,children:[`No object fields (`,r,`).`]}):l.length===0?(0,Y.jsx)(jC,{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)(OC,{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 jC({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 MC(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 NC(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 PC(e){let t=new Set;for(let n of e){let e=NC(n);e&&t.add(e)}return t}function FC(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function IC(e,t){return e===t?null:e>t?e-1:e}function LC(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function RC({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}=GS(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=wv(n,FC(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=Cv(n,t,null);if(v(r),a!=null){let n=IC(a,t);n==null?c?.(null):c?.({kind:`column`,id:`${e}.columns[${n}]`,label:MC(r[n],n)})}},[n,v,a,e,c]),x=J.useCallback((t,r)=>{if(t===r)return;let i=Tv(n,t,r);if(v(i),a!=null){let n=LC(a,t,r);c?.({kind:`column`,id:`${e}.columns[${n}]`,label:MC(i[n],n)})}},[n,v,a,e,c]),S=J.useCallback(t=>{c?.({kind:`column`,id:`${e}.columns[${t}]`,label:MC(n[t],t)})},[n,e,c]),C=PC(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)(G,{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)(kC,{index:t,label:MC(e,t),fieldName:NC(e),fieldType:p.get(NC(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)(AC,{fields:u,usedNames:C,loading:d,error:f,onAdd:y})]})}var zC=[`field`,`label`,`accessorKey`,`header`];function BC(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function VC(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function HC(e){return e.field??e.accessorKey??``}function UC(e){return e.label??e.header??HC(e)}function WC(e){return Object.keys(e).some(e=>!zC.includes(e))}function GC(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function KC({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=BC(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(VC),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=J.useMemo(()=>wC(),[]),m=GC(c),{fields:h}=GS(m||void 0),g=d?HC(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)(hv,{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)(Sv,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=HC(e);return n&&!WC(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(Cv(u,s.index,{...d,...r}))};return(0,Y.jsxs)(hv,{kindLabel:X(`engine.inspector.viewColumn.kind`,a),title:UC(d)||e.id,onClose:r,closeLabel:X(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(gv,{index:s.index,total:u.length,onMove:e=>{v(Tv(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:UC(d)||`columns[${e}]`})},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(xv,{label:X(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(Cv(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(RC,{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)(yv,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:HC(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(_v,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:HC(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.viewColumn.header`,a),value:UC(d)===HC(d)?``:UC(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(eg,{schema:p,value:d,hiddenFields:zC,readOnly:o,onChange:e=>{v(Cv(u,s.index,e))}})}):null]})]})}var qC={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`},JC=[`columns`,`data`,`name`];function YC(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 XC(e){return J.useMemo(()=>{let t=bC()?.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:qC[e]??e}));return!n.some(t=>t.value===e)&&e&&n.push({value:e,label:e}),n},[e])}function ZC({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s}){let c=e[t]??{},l=iv(n??t),u=typeof c.type==`string`?c.type:`grid`,d=XC(u),f=YC(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}=GS(f.value||void 0),_=J.useMemo(()=>({objectFields:g.map(e=>({name:e.name,label:e.label,type:e.type}))}),[g]),v=l?void 0:EC(),y=l?xC():bC(),b=e=>{i({[t]:{...c,...e}})};return(0,Y.jsxs)(hv,{kindLabel:`View`,title:String(p||e.name||t),onClose:()=>o?.(),closeLabel:`Close`,hideClose:r,children:[(0,Y.jsx)(_v,{label:`Label`,value:p,onCommit:e=>{i({label:e,[t]:{...c,label:e}})},placeholder:`e.g. All Leads`,disabled:a}),(0,Y.jsx)(yv,{label:`View type`,value:u,options:d,onCommit:e=>b({type:e}),disabled:a}),(0,Y.jsx)(_v,{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)(RC,{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)(eg,{schema:y,form:v,value:c,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:_,onChange:e=>{let n={...e};for(let e of JC)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 QC(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(KC,{...e});let n=lv(e.draft,t.id||void 0)??cv(e.draft);return(0,Y.jsx)(ZC,{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 $C(e){let t=cv(e.draft);return(0,Y.jsx)(ZC,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}function ew(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 tw(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 nw(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:Cv(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 rw(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 iw(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 aw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=ew(e.id),c=s?tw(t,s):null,l=s?rw(t,s):null;if(!s||!c)return(0,Y.jsx)(hv,{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)(Sv,{message:e.id})});let u=e=>n(nw(t,s,{...c,...e}));return(0,Y.jsxs)(hv,{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)(gv,{index:l.index,total:l.siblings.length,onMove:e=>{if(!l)return;n(iw(t,s,Tv(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)(xv,{label:X(`engine.inspector.pageBlock.remove`,a),onClick:()=>{n(nw(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.type`,a),value:c.type??``,onCommit:e=>u({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.id`,a),value:c.id??``,onCommit:e=>u({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.className`,a),value:c.className??``,onCommit:e=>u({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.hidden`,a),value:c.hidden??``,onCommit:e=>u({hidden:e}),disabled:o,mono:!0})]})}var ow=`__none__`,sw=[{value:ow,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function cw(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function lw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=cw(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,Y.jsx)(hv,{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)(Sv,{message:e.id})});let u=e=>n({columns:Cv(c,s,{...l,...e})});return(0,Y.jsxs)(hv,{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)(gv,{index:s,total:c.length,onMove:e=>{n({columns:Tv(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)(xv,{label:X(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:Cv(c,s,null)}),r()},disabled:o}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Y.jsx)(yv,{label:X(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??ow,options:sw,onCommit:e=>u({aggregate:e===ow?void 0:e}),disabled:o})]})}function uw(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 dw(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function fw(e){return e===`lookup`||e===`master_detail`||e===`tree`}function pw(e){return e===`formula`||e===`summary`}function mw(e){return e===`number`||e===`currency`||e===`percent`}function hw(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}var gw=uy.flatMap(e=>e.types.map(t=>({value:t,label:`${sy[e.category]} · ${ay[t].label}`})));function _w({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a}){let o=J.useMemo(()=>Qv(t.fields),[t]),s=String(e.id),c=ey(o,s),l=c>=0?o.entries[c]:null,u=Array.isArray(t.fieldGroups)?t.fieldGroups:[],d=Sw();if(!l)return(0,Y.jsx)(hv,{kindLabel:`Field`,title:s||`Field`,onClose:r,children:(0,Y.jsx)(Sv,{message:`This field no longer exists in the draft.`})});let f=l.def,p=typeof f.type==`string`?f.type:`text`,m=ay[p],h=e=>{n({fields:$v(e)})},g=e=>{let t=[...o.entries];t[c]={...l,def:{...f,...e}},h({shape:o.shape,entries:t})},_=e=>{let t=ry(e);if(!t||t===l.name||o.entries.some((e,n)=>n!==c&&e.name===t))return;let n=[...o.entries];n[c]={...l,name:t},h({shape:o.shape,entries:n}),i?.({kind:`field`,id:t,label:String(f.label??t)})},v=()=>{let e=o.entries.filter((e,t)=>t!==c);h({shape:o.shape,entries:e}),r()},y=e=>{h({shape:o.shape,entries:Tv(o.entries,c,e)})},b=uw(f),x=e=>{g({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},S=(0,Y.jsx)(gv,{index:c,total:o.entries.length,onMove:y,disabled:a}),C=(0,Y.jsx)(xv,{label:`Remove “${typeof f.label==`string`?f.label:l.name}”`,onClick:v,disabled:a});return(0,Y.jsxs)(hv,{kindLabel:`Field`,title:typeof f.label==`string`&&f.label?f.label:l.name,onClose:r,headerActions:S,footer:C,children:[(0,Y.jsxs)(vw,{title:`Basic`,children:[(0,Y.jsx)(_v,{label:`API name`,value:l.name,onCommit:_,disabled:a,mono:!0}),(0,Y.jsx)(_v,{label:`Label`,value:typeof f.label==`string`?f.label:``,onCommit:e=>g({label:e}),disabled:a}),(0,Y.jsx)(yv,{label:`Type`,value:p,options:gw,onCommit:e=>g({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(bv,{label:`Required`,value:!!f.required,onCommit:e=>g({required:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Unique`,value:!!f.unique,onCommit:e=>g({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(yw,{label:`Description`,value:typeof f.description==`string`?f.description:``,onCommit:e=>g({description:e||void 0}),disabled:a,rows:2})]}),(dw(p)||fw(p)||pw(p)||mw(p)||hw(p))&&(0,Y.jsxs)(vw,{title:`${m?.label??p} options`,children:[dw(p)&&(0,Y.jsx)(xw,{options:b,onChange:x,disabled:a}),fw(p)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bw,{label:`Related object`,value:typeof f.reference==`string`?f.reference:``,options:d,onCommit:e=>g({reference:e||void 0}),disabled:a}),(0,Y.jsx)(_v,{label:`Relationship name`,value:typeof f.relationshipName==`string`?f.relationshipName:``,onCommit:e=>g({relationshipName:e||void 0}),disabled:a,placeholder:`Inverse collection key on the parent`})]}),pw(p)&&(0,Y.jsx)(yw,{label:`Formula (CEL)`,value:typeof f.formula==`string`?f.formula:``,onCommit:e=>g({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),mw(p)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(vv,{label:`Precision`,value:typeof f.precision==`number`?f.precision:void 0,onCommit:e=>g({precision:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Scale`,value:typeof f.scale==`number`?f.scale:void 0,onCommit:e=>g({scale:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Min`,value:typeof f.min==`number`?f.min:void 0,onCommit:e=>g({min:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Max`,value:typeof f.max==`number`?f.max:void 0,onCommit:e=>g({max:e}),disabled:a})]}),hw(p)&&(0,Y.jsx)(vv,{label:`Max length`,value:typeof f.maxLength==`number`?f.maxLength:void 0,onCommit:e=>g({maxLength:e}),disabled:a,placeholder:`255`})]}),(0,Y.jsxs)(vw,{title:`Advanced`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(bv,{label:`Read-only`,value:!!f.readonly,onCommit:e=>g({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Hidden`,value:!!f.hidden,onCommit:e=>g({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Indexed`,value:!!f.indexed,onCommit:e=>g({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`External ID`,value:!!f.externalId,onCommit:e=>g({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Track history`,value:!!f.trackHistory,onCommit:e=>g({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(_v,{label:`Placeholder`,value:typeof f.placeholder==`string`?f.placeholder:``,onCommit:e=>g({placeholder:e||void 0}),disabled:a}),u.length>0&&(0,Y.jsx)(yv,{label:`Group`,value:typeof f.group==`string`?f.group:``,options:[{value:``,label:`— No group —`},...u.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>g({group:e||void 0}),disabled:a})]})]})}function vw({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 yw({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)(G,{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 bw({label:e,value:t,options:n,onCommit:r,disabled:i}){let a=J.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{list:a,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:`object_name`}),(0,Y.jsx)(`datalist`,{id:a,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function xw({options:e,onChange:t,disabled:n}){let r=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},i=n=>t(e.filter((e,t)=>t!==n)),a=(n,r)=>t(Tv(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)(G,{className:`text-xs text-muted-foreground`,children:`Picklist values`}),(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:`No values yet.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:e.map((t,o)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(W,{value:t.value,onChange:e=>r(o,{value:e.target.value}),placeholder:`value`,disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,Y.jsx)(W,{value:t.label??``,onChange:e=>r(o,{label:e.target.value}),placeholder:`Label`,disabled:n,className:`h-7 text-xs flex-1`}),(0,Y.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>r(o,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:`Color`}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o-1),disabled:n||o===0,"aria-label":`Move up`,children:(0,Y.jsx)(on,{className:`h-3 w-3`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o+1),disabled:n||o===e.length-1,"aria-label":`Move down`,children:(0,Y.jsx)(Fn,{className:`h-3 w-3`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>i(o),disabled:n,"aria-label":`Remove`,children:(0,Y.jsx)(ro,{className:`h-3 w-3`})})]},o))}),!n&&(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),`Add value`]})]})}function Sw(){let e=hm(),[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 Cw(){Bg(`dashboard`,fS),Bg(`flow`,cC),Bg(`app`,mC),Bg(`view`,QC),Ug(`view`,$C),Bg(`page`,aw),Bg(`report`,lw),Bg(`object`,_w)}var ww=t({MetadataDiagnosticsPage:()=>D_,MetadataDirectoryPage:()=>Fm,MetadataResourceEditPage:()=>x_,MetadataResourceHistoryPage:()=>kg,MetadataResourceListPage:()=>vh,StudioHomePage:()=>nh});M_(),I_(),sS(),Cw();function Tw(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ew(e){return!Tw(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function Dw(e){if(!Tw(e))return;let t=e.config;if(Tw(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`}pm({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:Fm}),pm({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:T_}),pm({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:qm}),ph({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`}]}),ph({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`}]}),ph({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:k_,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`}]}),ph({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)=>Dw(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!Ew(e)}),ph({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`}]}),ph({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 Ow=(0,J.lazy)(()=>c(()=>import(`./SystemHubPage-DCtNkrqu.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),kw=(0,J.lazy)(()=>c(()=>import(`./AppManagementPage-CFHAXcEw.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Aw=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-DbEzcgM3.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),jw=(0,J.lazy)(()=>c(()=>import(`./ApprovalsInboxPage-DuHpUtLO.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Mw=(0,J.lazy)(()=>c(()=>import(`./AiPendingActionsPage-C2C3Ja_n.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Nw=(0,J.lazy)(()=>c(()=>import(`./AuditLogPage-Dw6wpFTf.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Pw=(0,J.lazy)(()=>c(()=>import(`./SettingsHub-RgZdAo3g.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Fw=(0,J.lazy)(()=>c(()=>import(`./SettingsView-C4bpsbjP.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),Iw=(0,J.lazy)(()=>c(()=>import(`./DeveloperHubPage-Di9VELMr.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),Lw=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-ePJcxhf9.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Rw=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-C2ElJEUw.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),zw=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-CFO_htk4.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Bw(){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 Vw(){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 Hw=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{path:`system`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Ow,{})})}),(0,Y.jsx)(d,{path:`system/apps`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(kw,{})})}),(0,Y.jsx)(d,{path:`system/profile`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Aw,{})})}),(0,Y.jsx)(d,{path:`system/approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(jw,{})})}),(0,Y.jsx)(d,{path:`system/ai-approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Mw,{})})}),(0,Y.jsx)(d,{path:`system/audit-log`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Nw,{})})}),(0,Y.jsx)(d,{path:`system/settings`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Pw,{})})}),(0,Y.jsx)(d,{path:`system/settings/:namespace`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Fw,{})})}),(0,Y.jsx)(d,{path:`developer`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Iw,{})})}),(0,Y.jsx)(d,{path:`developer/api-console`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Lw,{})})}),(0,Y.jsx)(d,{path:`developer/flow-runs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Rw,{})})}),(0,Y.jsx)(d,{path:`developer/public-forms`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(zw,{})})}),(0,Y.jsx)(d,{path:`system/objects`,element:(0,Y.jsx)(Bw,{})}),(0,Y.jsx)(d,{path:`system/objects/:objectName`,element:(0,Y.jsx)(Bw,{})}),(0,Y.jsx)(d,{path:`system/metadata`,element:(0,Y.jsx)(Vw,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType`,element:(0,Y.jsx)(Vw,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType/:itemName`,element:(0,Y.jsx)(Vw,{})})]});function Uw(){let e=(0,J.useMemo)(()=>ui({baseUrl:``}),[``]);return(0,Y.jsx)(j,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(_i,{adapter:e,children:(0,Y.jsx)(Pf,{extraRoutes:Hw,extraRoutesNoApp:Hw})})})}var Ww=[`cloud_control`];function Gw(){let{apps:e,loading:t}=ie();if(t)return(0,Y.jsx)(Qs,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Ww)if(n.has(e))return(0,Y.jsx)(_,{to:`/apps/${e}`,replace:!0});return(0,Y.jsx)(_,{to:`/home`,replace:!0})}var Kw=`/api/v1`;function qw(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Jw(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 Yw(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=qw(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:Jw(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Xw(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 Zw(e,t){return fetch(`${Kw}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function Qw(e){let t=await Zw(`/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 $w(e){let t=await Zw(`/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 Zw(`/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 eT(e,t){let n=await Zw(`/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 tT(e,t){let n=await Zw(`/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 nT=`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 rT({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:nT},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 iT({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`?Qw(r):$w(r)).then(e=>{t||(u(e),p(Xw(Yw(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?Yw(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 eT(r,d):await tT(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(Xw(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)(rT,{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 aT({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 oT(){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 sT(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(`
|
|
31
|
+
}`})}),Nb(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Rb,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Bn,children:(0,Y.jsx)(Lb,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Lb({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)(vr,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(ea,{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:Pb(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 Rb({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 zb({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Bb({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 Vb=[{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 Hb(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 Ub({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(()=>Hb(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)(L_,{hint:`permission`,children:(0,Y.jsx)(R_,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(L_,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(B_,{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)(Pe,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(ai,{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)(qb,{icon:At,label:`${d.length} objects`}),(0,Y.jsx)(qb,{icon:va,label:`${c.length} system perms`}),(0,Y.jsx)(qb,{icon:no,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(qb,{icon:Un,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Kb,{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`}),Vb.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}),Vb.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(Wb,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Gb,{})]}),p.size>0&&(0,Y.jsx)(Kb,{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)(Kb,{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)(Kb,{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)(Tn,{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 Wb({granted:e,danger:t}){return e?(0,Y.jsx)(vr,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(Xn,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Gb(){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)(vr,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(vr,{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)(Xn,{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 Kb({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 qb({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 Jb(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 Yb(e){switch(e){case`url`:return Di;case`modal`:return Sn;case`flow`:return Qe;case`api`:return ei;case`form`:return vt;default:return ho}}function Xb(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 Zb(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 Qb({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Jb(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=Jb(n.confirmText),g=Jb(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=Yb(o),w=l===`action:icon`;return!r&&!i?(0,Y.jsx)(L_,{hint:`action`,children:(0,Y.jsx)(R_,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(L_,{hint:`action`,children:(0,Y.jsx)(B_,{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)($b,{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)(ox,{icon:C,label:`type: ${o}`}),b&&(0,Y.jsx)(ox,{icon:ja,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(ox,{label:`variant: ${c}`}),l&&(0,Y.jsx)(ox,{icon:Xa,label:l}),d&&(0,Y.jsx)(ox,{icon:Mn,label:d,mono:!0}),f&&(0,Y.jsx)(ox,{icon:Fr,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(ox,{icon:Le,label:`refresh after`}),m===!1&&(0,Y.jsx)(ox,{icon:$e,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(ox,{icon:ra,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)(ix,{label:`Visible when`,value:x,icon:no}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(ix,{label:`Disabled when`,value:S,icon:Un})]}),(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:Zb(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)(Tn,{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)(ax,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(tx,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(ax,{title:`Result Dialog`,icon:no,children:(0,Y.jsx)(rx,{dialog:v})}),y?.source&&(0,Y.jsx)(ax,{title:`Script Body (${y.language??`expression`})`,icon:ho,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 $b({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 ${Xb(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(ex,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function ex({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=mi[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 tx({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:[Jb(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})]}),nx(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 ${Xb(n||`primary`)}`,children:`OK`})]})]})}function nx(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:Jb(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 rx({dialog:e}){let t=Jb(e.title)||`Result`,n=Jb(e.description),r=Jb(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:Jb(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 ix({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 ax({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 ox({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 sx={"@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 cx(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 lx(e){let t=(sx[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=cx(n,0,59),c=cx(r,0,23),l=cx(i,1,31),u=cx(a,1,12),d=cx(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function ux(e,t,n){let r=lx(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 dx(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 fx(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function px(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function mx(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?hx(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`?hx(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function hx(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 gx({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}=mx(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?dx(s):null,{nextFires:v,deltas:y}=J.useMemo(()=>{let e=new Date,t=[];if(o)t=ux(o,e,5);else if(_)t=fx(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>_x(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(L_,{hint:`job`,children:(0,Y.jsx)(R_,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(L_,{hint:`job`,children:(0,Y.jsx)(B_,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(tr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(bx,{icon:jt,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(bx,{icon:st,label:l,mono:!0}),p!=null&&(0,Y.jsx)(bx,{icon:Wn,label:`retries: ${p}${m?` (${hx(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(bx,{icon:go,label:`timeout: ${hx(h)}`}),g!=null&&(0,Y.jsx)(bx,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(yx,{title:`Schedule`,icon:Xi,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(vx,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(vx,{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)(vx,{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)(yx,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:Ke,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)(Ke,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:px(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(yx,{title:`Handler`,icon:ho,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)(mr,{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 _x(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 vx({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 yx({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 bx({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 xx=[{key:`objects`,label:`Objects`,icon:Ni,flat:!1},{key:`apps`,label:`Apps`,icon:Je,flat:!1},{key:`messages`,label:`Messages`,icon:Sr,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:ua,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Tt,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:dt,flat:!1},{key:`settings`,label:`Settings`,icon:fi,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:da,flat:!1}];function Sx({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=xx.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/xx.length*100);return c===0?(0,Y.jsx)(L_,{hint:`translation · ${r}`,children:(0,Y.jsx)(R_,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(L_,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(B_,{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)(Kt,{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)(st,{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)(xa,{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,`/`,xx.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)(Cx,{cat:e},e.key))})]})})})}function Cx({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:wx(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 wx(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Tx({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)(L_,{hint:`role`,children:(0,Y.jsx)(B_,{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)(rt,{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)(Bt,{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)(dn,{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)(ai,{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)(L_,{hint:`role`,children:(0,Y.jsx)(R_,{children:`Give the role a name to see the preview.`})})}function Ex({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)(L_,{hint:`skill`,children:(0,Y.jsx)(B_,{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)(ra,{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)(Ox,{icon:jt,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(Ox,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(Ox,{icon:ai,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(Dx,{title:`Instructions`,icon:Kn,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)(Dx,{title:`Tools (${s.length})`,icon:zn,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)(Mi,{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)(Dx,{title:`Trigger Phrases (${c.length})`,icon:vi,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)(Dx,{title:`Trigger Conditions (${l.length})`,icon:Ar,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)(Dx,{title:`Required Permissions`,icon:ai,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)(L_,{hint:`skill`,children:(0,Y.jsx)(R_,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Dx({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 Ox({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 kx=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Ax=D();function jx(){return``.replace(/\/+$/,``)}function Mx(e){return`${jx()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function Nx(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 kx}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 Px(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await Nx(await Ax(`${Mx(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Fx(e,t,n={}){return(await Nx(await Ax(`${Mx(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Ix(e){return(await Nx(await Ax(`${Mx(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Lx(e){return Nx(await Ax(`${Mx(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Rx(e){await Nx(await Ax(`${jx()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function zx({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 Fx(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof kx?`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 Rx(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)(ft,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Mt,{className:`max-w-2xl`,children:[(0,Y.jsxs)(mo,{children:[(0,Y.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ai,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(Jt,{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)(vr,{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)(Tn,{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)(Ga,{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)(Nn,{children:a===`done`?(0,Y.jsx)(K,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(K,{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 Bx({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 Px(e)),n(`loaded`)}catch(e){e instanceof kx?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)(Vx,{}):(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)(Wa,{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)(K,{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)(Le,{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)(hr,{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)(Yt,{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)(K,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(zx,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Vx(){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 Hx={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 Ux({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 Lx(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof kx?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)(K,{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)(mr,{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)(vr,{className:`h-4 w-4`}):(0,Y.jsx)(ua,{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)(Wx,{result:e},e.object))})]})}function Wx({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)(ai,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(ua,{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)(Gx,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Gx({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:Hx[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 Kx({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 Ix(e))}catch(e){c(e instanceof kx?`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)(rn,{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)(Ke,{className:`h-3 w-3`}),`snapshot `,qx(r.snapshotAt)]}),(0,Y.jsxs)(K,{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)(Le,{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)(Fa,{children:[(0,Y.jsx)(ta,{value:`tables`,children:`Tables`}),(0,Y.jsx)(ta,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(ri,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(Bx,{datasource:e})}),(0,Y.jsx)(ri,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(Ux,{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 qx(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Jx=/pass|secret|key|token|credential|auth/i;function Yx(e){return Jx.test(e)}function Xx(e){return e==null||e===``?`∅`:`••••••`}function Zx(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 Qx({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)(L_,{hint:`datasource`,children:(0,Y.jsx)(R_,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(L_,{hint:`datasource · ${o}`,children:(0,Y.jsx)(B_,{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)(Ai,{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)(or,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(tS,{icon:jt,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(tS,{icon:Pe,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(tS,{icon:pt,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(Kx,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(eS,{title:`Connection`,icon:Un,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=Yx(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:Xx(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`})]}):Zx(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)($x,{title:`Pool`,icon:Dt,value:u}),(0,Y.jsx)($x,{title:`SSL`,icon:ai,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)($x,{title:`Retry Policy`,icon:Wn,value:f}),(0,Y.jsx)($x,{title:`Health Check`,icon:Dt,value:p})]}),h.length>0&&(0,Y.jsx)(eS,{title:`Capabilities`,icon:ai,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 $x({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:Yx(e)?Xx(t):Zx(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function eS({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`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function nS(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function rS(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:Dr};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:Tn};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:wt}}}function iS({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=rS(l);return r?(0,Y.jsx)(L_,{hint:`validation · ${o}`,children:(0,Y.jsx)(B_,{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)(ua,{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)(cS,{icon:jt,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(cS,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(cS,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(cS,{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)(aS,{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)(L_,{hint:`validation`,children:(0,Y.jsx)(R_,{children:`Give the validation a name to see the preview.`})})}function aS({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(sS,{title:`Condition`,icon:ho,children:(0,Y.jsx)(oS,{value:nS(t.condition)??nS(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=nS(t.scope)??nS(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(sS,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Ui,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)(sS,{title:`Scope`,icon:Vi,children:(0,Y.jsx)(oS,{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)(sS,{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)(ht,{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)(sS,{title:`Format`,icon:Pi,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=nS(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(sS,{title:`Fields involved`,icon:Vi,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)(sS,{title:`Cross-field condition`,icon:ho,children:(0,Y.jsx)(oS,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(sS,{title:`Async endpoint`,icon:st,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)(sS,{title:`Custom handler`,icon:ho,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)(sS,{title:`Rule`,icon:ua,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 oS({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 sS({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 cS({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 lS(){Lg(`page`,nv),Lg(`view`,mv),Lg(`dashboard`,Nv),Lg(`report`,Iv),Lg(`app`,Yv),Lg(`action`,Qb),Lg(`object`,Cy),Lg(`datasource`,Qx),Lg(`validation`,iS),Lg(`email_template`,Dy),Lg(`translation`,Sx),Lg(`flow`,xb),Lg(`job`,gx),Lg(`agent`,Cb),Lg(`tool`,Ib),Lg(`skill`,Ex),Lg(`permission`,Ub),Lg(`profile`,Ub),Lg(`role`,Tx)}var uS=[{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`}],dS=[`count`,`sum`,`avg`,`min`,`max`],fS=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function pS(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 mS({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Y.jsx)(gS,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=pS(e,t.id);if(!s)return(0,Y.jsx)(gS,{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:Tv(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)(gv,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(hS,{id:`widget-title`,label:X(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(W,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,Y.jsx)(hS,{id:`widget-type`,label:X(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(In,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-type`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:uS.map(e=>(0,Y.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsx)(hS,{id:`widget-object`,label:X(`engine.inspector.widget.object`,o),children:(0,Y.jsx)(W,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,Y.jsx)(hS,{id:`widget-value-field`,label:X(`engine.inspector.widget.valueField`,o),children:(0,Y.jsx)(W,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,Y.jsx)(hS,{id:`widget-category-field`,label:X(`engine.inspector.widget.categoryField`,o),children:(0,Y.jsx)(W,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,Y.jsx)(hS,{id:`widget-aggregate`,label:X(`engine.inspector.widget.aggregate`,o),children:(0,Y.jsxs)(In,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-aggregate`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:dS.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Y.jsx)(hS,{id:`widget-color`,label:X(`engine.inspector.widget.color`,o),children:(0,Y.jsxs)(In,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Y.jsx)(nr,{id:`widget-color`,children:(0,Y.jsx)(Ot,{})}),(0,Y.jsx)(vo,{children:fS.map(e=>(0,Y.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(hS,{id:`widget-w`,label:X(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(W,{id:`widget-w`,type:`number`,min:1,value:c.layout?.w??1,onChange:e=>d({layout:{...c.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,Y.jsx)(hS,{id:`widget-h`,label:X(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(W,{id:`widget-h`,type:`number`,min:1,value:c.layout?.h??1,onChange:e=>d({layout:{...c.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,Y.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Y.jsx)(K,{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 hS({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(G,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function gS({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)(K,{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 _S(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var vS=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),yS={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:vS,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:[_S(`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`}),_S(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),_S(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),_S(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),_S(`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:[_S(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),_S(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),_S(`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:[_S(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),_S(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),_S(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),_S(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),_S(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),_S(`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`})]},bS={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 xS(e){return e?yS[bS[e]??e]??[]:[]}function SS(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 CS(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function wS(e,t,n){if(!e.showWhen)return!0;let r=SS(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=SS(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 TS=[`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`],ES=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function DS(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`&&ES.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&ES.has(t.kind))return{kind:t.kind,...n}}function OS(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 kS(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function AS(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 jS(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:OS(e)}))}function MS(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 NS(e){if(Array.isArray(e.enum))return`select`;let t=AS(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function PS(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!kS(r))continue;let t=AS(r),i,a,o=DS(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=jS(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||OS(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function FS(e,t){return{label:e.title||OS(t),...e.description?{help:e.description}:{},...MS(e)?{defaultValue:MS(e)}:{}}}function IS(e){if(!kS(e)||AS(e)!==`object`||!kS(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!kS(r))continue;let e=AS(r);if(e===`array`){let e=kS(r.items)?r.items:void 0,i=e?AS(e):void 0;e&&i===`object`&&kS(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:PS(e),...FS(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...FS(r,n)});continue}if(e===`object`&&kS(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>kS(e)),i=e.some(([e,t])=>e===`enabled`&&AS(t)===`boolean`);for(let[a,o]of e){let e=o,s=DS(e),c=s?`reference`:NS(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||OS(n),...r.description?{help:r.description}:{},...MS(e)?{defaultValue:MS(e)}:{}}:FS(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:jS(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=DS(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...FS(r,n)});continue}let a=NS(r);a&&t.push({id:n,path:[`config`,n],kind:a,...FS(r,n),...a===`select`&&Array.isArray(r.enum)?{options:jS(r.enum)}:{}})}return t}function LS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function RS(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function zS(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 BS(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=Ev(`kv`,n);return n.push(r),{id:r,key:e,raw:RS(t)}})}function VS(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=zS(n.raw))}return t}function HS(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function US({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=LS(t)?t:{},[d,f]=J.useState(()=>BS(u,[])),p=J.useRef(HS(u));J.useEffect(()=>{let e=HS(u);e!==p.current&&(f(BS(u,[])),p.current=e)},[u]);let m=e=>{let t=VS(e);p.current=HS(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:Ev(`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)(G,{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)(W,{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)(W,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,Y.jsx)(H,{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 WS(e,t){let n=[...t];return e.map(e=>{let t=Ev(`sl`,n);return n.push(t),{id:t,value:e}})}function GS(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function KS({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(()=>WS(c,[])),d=J.useRef(JSON.stringify(c));J.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(WS(c,[])),d.current=e)},[c]);let f=e=>{let t=GS(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:Ev(`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)(G,{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)(W,{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)(K,{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)(ro,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}function qS(e){let t=hm(),[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:Qv(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 JS={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function YS(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 XS(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 ZS(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?XS((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):XS(n.node,r)}function QS(e){let t=hm(),[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 $S({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?ZS(e.kind,e.objectSource,l):void 0,{fields:f}=qS(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?JS[u]:void 0,{options:m}=QS(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)(W,{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 eC({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=YS(e.ref,e=>XS(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)($S,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function tC(e,t){let n=[];return e.map(e=>{let r=Ev(`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 nC(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 rC({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(()=>tC(l,t)),f=J.useRef(JSON.stringify(l));J.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(tC(l,t)),f.current=e)},[l,t]);let p=e=>{let n=nC(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:Ev(`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)(G,{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)(K,{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)(ro,{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)(G,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(yt,{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)($S,{resolved:YS(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)(W,{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)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function iC({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(eC,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(US,{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)(KS,{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)(rC,{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)(vv,{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)(bv,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(yv,{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)(G,{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)(_v,{label:e.label,value:t==null?``:String(t),placeholder:e.placeholder,onCommit:e=>n(e),disabled:r,mono:e.kind===`expression`})}})(),e.help&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}function aC(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function oC(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=oC(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function sC({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=$y(),u=J.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:IS(e))??xS(c?.type)},[l,c?.type]),d=aC(c),f=u.filter(e=>wS(e,c,u)),p=J.useMemo(()=>{let e=new Set;for(let t of u){let n=CS(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)(hv,{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)(Sv,{message:e.id})});let C=e=>{n({nodes:Cv(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:Cv(o,s,oC(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:Cv(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:Cv(o,s,null)}),r()},O=TS.includes(c.type)?[...TS]:[...TS,c.type??``].filter(Boolean);return(0,Y.jsxs)(hv,{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)(xv,{label:X(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,Y.jsx)(yv,{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)(_v,{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)(iC,{field:e,value:SS(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)(H,{className:`h-3 w-3`}),X(`engine.inspector.flowNode.advanced`,i)]})]})}function cC({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{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 lC({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)=>Iy(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,Y.jsx)(hv,{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)(Sv,{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:Cv(o,s,t)})},u=c.isDefault===!0;return(0,Y.jsxs)(hv,{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)(xv,{label:X(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:Cv(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(cC,{label:X(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(cC,{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)(_v,{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)(_v,{label:X(`engine.inspector.flowEdge.condition`,i),value:Ly(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:X(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(0,Y.jsx)(bv,{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 uC(e){return e.selection.kind===`edge`?(0,Y.jsx)(lC,{...e}):(0,Y.jsx)(sC,{...e})}var dC=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function fC(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 pC(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 mC(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:Cv(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=Cv(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function hC(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 gC({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=fC(e.id),{node:c,parent:l,index:u}=s?pC(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Y.jsx)(hv,{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)(Sv,{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(mC(t,s,{...c,...e}))};return(0,Y.jsxs)(hv,{kindLabel:X(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:X(`engine.inspector.appNav.close`,a),headerActions:(0,Y.jsx)(gv,{index:u,total:l.length,onMove:e=>{n(hC(t,s,Tv(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)(xv,{label:X(`engine.inspector.appNav.remove`,a),onClick:()=>{n(mC(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(_v,{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)(_v,{label:X(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Y.jsx)(yv,{label:X(`engine.inspector.appNav.kindField`,a),value:c.kind,options:dC.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var _C={io:`input`,unrepresentable:`any`},vC=new Set([`columns`,`data`,`name`]),yC,bC=!1;function xC(){if(yC||bC)return yC;try{yC=M(re,_C)}catch(e){bC=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return yC}function SC(){return xC()?.properties?.list}function CC(){return xC()?.properties?.form}var wC,TC=!1;function EC(){if(wC||TC)return wC;try{wC=M(ne,_C)}catch(e){TC=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return wC}var DC;function OC(){if(DC)return DC;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!vC.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),DC=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return DC}}var kC=`text/x-objectui-viewcol`;function AC({type:e}){let t=dy(e),n=ly(e),r=t.Icon;return(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function jC({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(kC,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(kC)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(kC)&&(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)(On,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,Y.jsx)(AC,{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)(ro,{className:`h-3 w-3`})})]})]})}function MC({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)(br,{open:a,onOpenChange:o,children:[(0,Y.jsx)(Fe,{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)(H,{className:`h-3.5 w-3.5`}),` Add field`]})}),(0,Y.jsxs)(jn,{align:`start`,className:`w-72 p-0`,children:[(0,Y.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,Y.jsx)(Wa,{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)(NC,{children:`Loading fields…`}):r?(0,Y.jsxs)(NC,{tone:`warn`,children:[`No object fields (`,r,`).`]}):l.length===0?(0,Y.jsx)(NC,{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)(AC,{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 NC({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 PC(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 FC(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 IC(e){let t=new Set;for(let n of e){let e=FC(n);e&&t.add(e)}return t}function LC(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function RC(e,t){return e===t?null:e>t?e-1:e}function zC(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function BC({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}=qS(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=wv(n,LC(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=Cv(n,t,null);if(v(r),a!=null){let n=RC(a,t);n==null?c?.(null):c?.({kind:`column`,id:`${e}.columns[${n}]`,label:PC(r[n],n)})}},[n,v,a,e,c]),x=J.useCallback((t,r)=>{if(t===r)return;let i=Tv(n,t,r);if(v(i),a!=null){let n=zC(a,t,r);c?.({kind:`column`,id:`${e}.columns[${n}]`,label:PC(i[n],n)})}},[n,v,a,e,c]),S=J.useCallback(t=>{c?.({kind:`column`,id:`${e}.columns[${t}]`,label:PC(n[t],t)})},[n,e,c]),C=IC(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)(G,{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)(jC,{index:t,label:PC(e,t),fieldName:FC(e),fieldType:p.get(FC(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)(MC,{fields:u,usedNames:C,loading:d,error:f,onAdd:y})]})}var VC=[`field`,`label`,`accessorKey`,`header`];function HC(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function UC(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function WC(e){return e.field??e.accessorKey??``}function GC(e){return e.label??e.header??WC(e)}function KC(e){return Object.keys(e).some(e=>!VC.includes(e))}function qC(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function JC({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=HC(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(UC),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=J.useMemo(()=>EC(),[]),m=qC(c),{fields:h}=qS(m||void 0),g=d?WC(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)(hv,{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)(Sv,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=WC(e);return n&&!KC(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(Cv(u,s.index,{...d,...r}))};return(0,Y.jsxs)(hv,{kindLabel:X(`engine.inspector.viewColumn.kind`,a),title:GC(d)||e.id,onClose:r,closeLabel:X(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(gv,{index:s.index,total:u.length,onMove:e=>{v(Tv(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:GC(d)||`columns[${e}]`})},upLabel:X(`engine.inspector.reorder.up`,a),downLabel:X(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(xv,{label:X(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(Cv(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(BC,{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)(yv,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:WC(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(_v,{label:X(`engine.inspector.viewColumn.accessorKey`,a),value:WC(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.viewColumn.header`,a),value:GC(d)===WC(d)?``:GC(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(eg,{schema:p,value:d,hiddenFields:VC,readOnly:o,onChange:e=>{v(Cv(u,s.index,e))}})}):null]})]})}var YC={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`},XC=[`columns`,`data`,`name`];function ZC(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 QC(e){return J.useMemo(()=>{let t=SC()?.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:YC[e]??e}));return!n.some(t=>t.value===e)&&e&&n.push({value:e,label:e}),n},[e])}function $C({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s}){let c=e[t]??{},l=iv(n??t),u=typeof c.type==`string`?c.type:`grid`,d=QC(u),f=ZC(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}=qS(f.value||void 0),_=J.useMemo(()=>({objectFields:g.map(e=>({name:e.name,label:e.label,type:e.type}))}),[g]),v=l?void 0:OC(),y=l?CC():SC(),b=e=>{i({[t]:{...c,...e}})};return(0,Y.jsxs)(hv,{kindLabel:`View`,title:String(p||e.name||t),onClose:()=>o?.(),closeLabel:`Close`,hideClose:r,children:[(0,Y.jsx)(_v,{label:`Label`,value:p,onCommit:e=>{i({label:e,[t]:{...c,label:e}})},placeholder:`e.g. All Leads`,disabled:a}),(0,Y.jsx)(yv,{label:`View type`,value:u,options:d,onCommit:e=>b({type:e}),disabled:a}),(0,Y.jsx)(_v,{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)(BC,{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)(eg,{schema:y,form:v,value:c,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:_,onChange:e=>{let n={...e};for(let e of XC)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 ew(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(JC,{...e});let n=lv(e.draft,t.id||void 0)??cv(e.draft);return(0,Y.jsx)($C,{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 tw(e){let t=cv(e.draft);return(0,Y.jsx)($C,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}function nw(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 rw(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 iw(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:Cv(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 aw(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 ow(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 sw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=nw(e.id),c=s?rw(t,s):null,l=s?aw(t,s):null;if(!s||!c)return(0,Y.jsx)(hv,{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)(Sv,{message:e.id})});let u=e=>n(iw(t,s,{...c,...e}));return(0,Y.jsxs)(hv,{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)(gv,{index:l.index,total:l.siblings.length,onMove:e=>{if(!l)return;n(ow(t,s,Tv(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)(xv,{label:X(`engine.inspector.pageBlock.remove`,a),onClick:()=>{n(iw(t,s,null)),r()},disabled:o}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.type`,a),value:c.type??``,onCommit:e=>u({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.id`,a),value:c.id??``,onCommit:e=>u({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.className`,a),value:c.className??``,onCommit:e=>u({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.pageBlock.hidden`,a),value:c.hidden??``,onCommit:e=>u({hidden:e}),disabled:o,mono:!0})]})}var cw=`__none__`,lw=[{value:cw,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function uw(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function dw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=uw(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,Y.jsx)(hv,{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)(Sv,{message:e.id})});let u=e=>n({columns:Cv(c,s,{...l,...e})});return(0,Y.jsxs)(hv,{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)(gv,{index:s,total:c.length,onMove:e=>{n({columns:Tv(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)(xv,{label:X(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:Cv(c,s,null)}),r()},disabled:o}),children:[(0,Y.jsx)(_v,{label:X(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(_v,{label:X(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Y.jsx)(yv,{label:X(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??cw,options:lw,onCommit:e=>u({aggregate:e===cw?void 0:e}),disabled:o})]})}function fw(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 pw(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function mw(e){return e===`lookup`||e===`master_detail`||e===`tree`}function hw(e){return e===`formula`||e===`summary`}function gw(e){return e===`number`||e===`currency`||e===`percent`}function _w(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}var vw=uy.flatMap(e=>e.types.map(t=>({value:t,label:`${sy[e.category]} · ${ay[t].label}`})));function yw({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a}){let o=J.useMemo(()=>Qv(t.fields),[t]),s=String(e.id),c=ey(o,s),l=c>=0?o.entries[c]:null,u=Array.isArray(t.fieldGroups)?t.fieldGroups:[],d=ww();if(!l)return(0,Y.jsx)(hv,{kindLabel:`Field`,title:s||`Field`,onClose:r,children:(0,Y.jsx)(Sv,{message:`This field no longer exists in the draft.`})});let f=l.def,p=typeof f.type==`string`?f.type:`text`,m=ay[p],h=e=>{n({fields:$v(e)})},g=e=>{let t=[...o.entries];t[c]={...l,def:{...f,...e}},h({shape:o.shape,entries:t})},_=e=>{let t=ry(e);if(!t||t===l.name||o.entries.some((e,n)=>n!==c&&e.name===t))return;let n=[...o.entries];n[c]={...l,name:t},h({shape:o.shape,entries:n}),i?.({kind:`field`,id:t,label:String(f.label??t)})},v=()=>{let e=o.entries.filter((e,t)=>t!==c);h({shape:o.shape,entries:e}),r()},y=e=>{h({shape:o.shape,entries:Tv(o.entries,c,e)})},b=fw(f),x=e=>{g({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},S=(0,Y.jsx)(gv,{index:c,total:o.entries.length,onMove:y,disabled:a}),C=(0,Y.jsx)(xv,{label:`Remove “${typeof f.label==`string`?f.label:l.name}”`,onClick:v,disabled:a});return(0,Y.jsxs)(hv,{kindLabel:`Field`,title:typeof f.label==`string`&&f.label?f.label:l.name,onClose:r,headerActions:S,footer:C,children:[(0,Y.jsxs)(bw,{title:`Basic`,children:[(0,Y.jsx)(_v,{label:`API name`,value:l.name,onCommit:_,disabled:a,mono:!0}),(0,Y.jsx)(_v,{label:`Label`,value:typeof f.label==`string`?f.label:``,onCommit:e=>g({label:e}),disabled:a}),(0,Y.jsx)(yv,{label:`Type`,value:p,options:vw,onCommit:e=>g({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(bv,{label:`Required`,value:!!f.required,onCommit:e=>g({required:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Unique`,value:!!f.unique,onCommit:e=>g({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(xw,{label:`Description`,value:typeof f.description==`string`?f.description:``,onCommit:e=>g({description:e||void 0}),disabled:a,rows:2})]}),(pw(p)||mw(p)||hw(p)||gw(p)||_w(p))&&(0,Y.jsxs)(bw,{title:`${m?.label??p} options`,children:[pw(p)&&(0,Y.jsx)(Cw,{options:b,onChange:x,disabled:a}),mw(p)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Sw,{label:`Related object`,value:typeof f.reference==`string`?f.reference:``,options:d,onCommit:e=>g({reference:e||void 0}),disabled:a}),(0,Y.jsx)(_v,{label:`Relationship name`,value:typeof f.relationshipName==`string`?f.relationshipName:``,onCommit:e=>g({relationshipName:e||void 0}),disabled:a,placeholder:`Inverse collection key on the parent`})]}),hw(p)&&(0,Y.jsx)(xw,{label:`Formula (CEL)`,value:typeof f.formula==`string`?f.formula:``,onCommit:e=>g({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),gw(p)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(vv,{label:`Precision`,value:typeof f.precision==`number`?f.precision:void 0,onCommit:e=>g({precision:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Scale`,value:typeof f.scale==`number`?f.scale:void 0,onCommit:e=>g({scale:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Min`,value:typeof f.min==`number`?f.min:void 0,onCommit:e=>g({min:e}),disabled:a}),(0,Y.jsx)(vv,{label:`Max`,value:typeof f.max==`number`?f.max:void 0,onCommit:e=>g({max:e}),disabled:a})]}),_w(p)&&(0,Y.jsx)(vv,{label:`Max length`,value:typeof f.maxLength==`number`?f.maxLength:void 0,onCommit:e=>g({maxLength:e}),disabled:a,placeholder:`255`})]}),(0,Y.jsxs)(bw,{title:`Advanced`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(bv,{label:`Read-only`,value:!!f.readonly,onCommit:e=>g({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Hidden`,value:!!f.hidden,onCommit:e=>g({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Indexed`,value:!!f.indexed,onCommit:e=>g({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`External ID`,value:!!f.externalId,onCommit:e=>g({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(bv,{label:`Track history`,value:!!f.trackHistory,onCommit:e=>g({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(_v,{label:`Placeholder`,value:typeof f.placeholder==`string`?f.placeholder:``,onCommit:e=>g({placeholder:e||void 0}),disabled:a}),u.length>0&&(0,Y.jsx)(yv,{label:`Group`,value:typeof f.group==`string`?f.group:``,options:[{value:``,label:`— No group —`},...u.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>g({group:e||void 0}),disabled:a})]})]})}function bw({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 xw({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)(G,{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 Sw({label:e,value:t,options:n,onCommit:r,disabled:i}){let a=J.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(W,{list:a,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:`object_name`}),(0,Y.jsx)(`datalist`,{id:a,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Cw({options:e,onChange:t,disabled:n}){let r=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},i=n=>t(e.filter((e,t)=>t!==n)),a=(n,r)=>t(Tv(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)(G,{className:`text-xs text-muted-foreground`,children:`Picklist values`}),(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:`No values yet.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:e.map((t,o)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(W,{value:t.value,onChange:e=>r(o,{value:e.target.value}),placeholder:`value`,disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,Y.jsx)(W,{value:t.label??``,onChange:e=>r(o,{label:e.target.value}),placeholder:`Label`,disabled:n,className:`h-7 text-xs flex-1`}),(0,Y.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>r(o,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:`Color`}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o-1),disabled:n||o===0,"aria-label":`Move up`,children:(0,Y.jsx)(on,{className:`h-3 w-3`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>a(o,o+1),disabled:n||o===e.length-1,"aria-label":`Move down`,children:(0,Y.jsx)(Fn,{className:`h-3 w-3`})}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>i(o),disabled:n,"aria-label":`Remove`,children:(0,Y.jsx)(ro,{className:`h-3 w-3`})})]},o))}),!n&&(0,Y.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),`Add value`]})]})}function ww(){let e=hm(),[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 Tw(){Bg(`dashboard`,mS),Bg(`flow`,uC),Bg(`app`,gC),Bg(`view`,ew),Ug(`view`,tw),Bg(`page`,sw),Bg(`report`,dw),Bg(`object`,yw)}var Ew=t({MetadataDiagnosticsPage:()=>D_,MetadataDirectoryPage:()=>Fm,MetadataResourceEditPage:()=>x_,MetadataResourceHistoryPage:()=>kg,MetadataResourceListPage:()=>vh,StudioHomePage:()=>nh});M_(),I_(),lS(),Tw();function Dw(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ow(e){return!Dw(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function kw(e){if(!Dw(e))return;let t=e.config;if(Dw(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`}pm({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:Fm}),pm({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:T_}),pm({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:qm}),ph({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`}]}),ph({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`}]}),ph({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:k_,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`}]}),ph({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)=>kw(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!Ow(e)}),ph({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`}]}),ph({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 Aw=(0,J.lazy)(()=>c(()=>import(`./SystemHubPage-B-apkIco.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),jw=(0,J.lazy)(()=>c(()=>import(`./AppManagementPage-CvdaGmZp.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Mw=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-wEhY3kyx.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),Nw=(0,J.lazy)(()=>c(()=>import(`./ApprovalsInboxPage-DDI1tDfy.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Pw=(0,J.lazy)(()=>c(()=>import(`./AiPendingActionsPage-lmvGLNua.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Fw=(0,J.lazy)(()=>c(()=>import(`./AuditLogPage-B_XhBMoJ.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Iw=(0,J.lazy)(()=>c(()=>import(`./SettingsHub-BLGHmF-y.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Lw=(0,J.lazy)(()=>c(()=>import(`./SettingsView-tuRcbYy6.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),Rw=(0,J.lazy)(()=>c(()=>import(`./DeveloperHubPage-CJ7NZxLQ.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),zw=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-2Hfplikq.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Bw=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-0KW8LdCn.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Vw=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BkfIcEml.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Hw(){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 Uw(){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 Ww=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{path:`system`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Aw,{})})}),(0,Y.jsx)(d,{path:`system/apps`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(jw,{})})}),(0,Y.jsx)(d,{path:`system/profile`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Mw,{})})}),(0,Y.jsx)(d,{path:`system/approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Nw,{})})}),(0,Y.jsx)(d,{path:`system/ai-approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Pw,{})})}),(0,Y.jsx)(d,{path:`system/audit-log`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Fw,{})})}),(0,Y.jsx)(d,{path:`system/settings`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Iw,{})})}),(0,Y.jsx)(d,{path:`system/settings/:namespace`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Lw,{})})}),(0,Y.jsx)(d,{path:`developer`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Rw,{})})}),(0,Y.jsx)(d,{path:`developer/api-console`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(zw,{})})}),(0,Y.jsx)(d,{path:`developer/flow-runs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Bw,{})})}),(0,Y.jsx)(d,{path:`developer/public-forms`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(Vw,{})})}),(0,Y.jsx)(d,{path:`system/objects`,element:(0,Y.jsx)(Hw,{})}),(0,Y.jsx)(d,{path:`system/objects/:objectName`,element:(0,Y.jsx)(Hw,{})}),(0,Y.jsx)(d,{path:`system/metadata`,element:(0,Y.jsx)(Uw,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType`,element:(0,Y.jsx)(Uw,{})}),(0,Y.jsx)(d,{path:`system/metadata/:metadataType/:itemName`,element:(0,Y.jsx)(Uw,{})})]});function Gw(){let e=(0,J.useMemo)(()=>ui({baseUrl:``}),[``]);return(0,Y.jsx)(j,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Y.jsx)(Ol,{}),children:(0,Y.jsx)(_i,{adapter:e,children:(0,Y.jsx)(Pf,{extraRoutes:Ww,extraRoutesNoApp:Ww})})})}var Kw=[`cloud_control`];function qw(){let{apps:e,loading:t}=ie();if(t)return(0,Y.jsx)(Qs,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Kw)if(n.has(e))return(0,Y.jsx)(_,{to:`/apps/${e}`,replace:!0});return(0,Y.jsx)(_,{to:`/home`,replace:!0})}var Jw=`/api/v1`;function Yw(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Xw(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 Zw(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Yw(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:Xw(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Qw(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 $w(e,t){return fetch(`${Jw}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function eT(e){let t=await $w(`/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 tT(e){let t=await $w(`/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 $w(`/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 nT(e,t){let n=await $w(`/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 rT(e,t){let n=await $w(`/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 iT=`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 aT({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:iT},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 oT({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`?eT(r):tT(r)).then(e=>{t||(u(e),p(Qw(Zw(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?Zw(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 nT(r,d):await rT(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(Qw(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)(aT,{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 sT({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 cT(){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 lT(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
32
|
|
|
33
|
-
`):``}function cT(){let{token:e}=f(),t=`${(0,J.useMemo)(()=>oT(),[])}/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)(Di,{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)(G,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Y.jsx)(W,{id:`share-pw`,type:`password`,value:u,onChange:e=>d(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Y.jsx)(K,{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)(Tn,{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)(di,{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=sT(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 lT(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function uT(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function dT(){return typeof window>`u`?null:window.location.host||null}function fT(){let e=ul();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 pT({children:e,formWidth:t=`sm`}){let{t:n}=z(),r=t===`md`?`max-w-md`:`max-w-sm`,i=dT(),a=!!i&&!lT(i)&&!uT(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:U(`flex w-full flex-col gap-5`,r),children:[(0,Y.jsx)(fT,{}),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 mT(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function hT(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function gT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function _T(){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(hT(mT(n)?n:`/`));return}window.location.assign(hT(`/organizations`));return}p||window.location.assign(hT(mT(n)?n:`/`))}},[r,s,a,o,p,n,c]),i&&!h||r)return(0,Y.jsx)(pT,{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)(pT,{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)(Ht,{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)(vT,{registerUrl:d?void 0:v,redirect:n})})]})})}function vT({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:gT,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 yT(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function bT(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function xT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function ST(){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(bT(yT(r)?r:`/`));return}window.location.assign(bT(`/organizations`));return}h||window.location.assign(bT(yT(r)?r:`/`))}},[i,u,o,c,h,r,d]),p===null||a&&!_||i)return(0,Y.jsx)(pT,{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)(pT,{formWidth:`md`,children:(0,Y.jsx)(Ht,{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:xT,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 CT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function wT(){let{t:e}=z();return(0,Y.jsx)(pT,{formWidth:`md`,children:(0,Y.jsx)(Ht,{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:CT,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 TT(){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)(pT,{children:(0,Y.jsxs)(Ht,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Y.jsx)(Rt,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Y.jsx)(ga,{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)(G,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(W,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:o,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(W,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsx)(K,{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 ET=`/api/v1/auth`;function DT(){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(`${ET}/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)(pT,{children:(0,Y.jsxs)(Ht,{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)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Y.jsx)(Rt,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Y.jsx)(ga,{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)(pr,{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)(vr,{className:`size-6`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Y.jsx)(Rt,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Y.jsx)(ga,{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)(pr,{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)(ir,{className:`size-6`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Y.jsx)(Rt,{children:o||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Y.jsx)(ga,{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 OT(){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)(pT,{children:(0,Y.jsxs)(Ht,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(pr,{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)(Xe,{className:`size-8 text-primary`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Y.jsx)(Rt,{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)(ga,{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)(K,{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)(Le,{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)(Le,{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)(K,{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 kT=`/api/v1/auth`;function AT(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function jT(){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(`${kT}/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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Y.jsx)(Rt,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Y.jsx)(ga,{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:AT(e)}),n=t.id):n=(await c({name:e,slug:AT(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)(G,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Y.jsx)(W,{id:`name`,autoComplete:`name`,required:!0,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Y.jsx)(W,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(W,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:f,onChange:e=>p(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Y.jsx)(W,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:m,onChange:e=>h(e.target.value)})]}),(0,Y.jsx)(K,{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 MT=`/api/v1/auth`;function NT(){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(`${MT}/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(`${MT}/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)(Ht,{className:`w-full max-w-md`,children:[(0,Y.jsxs)(pr,{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)(Ue,{className:`h-7 w-7 text-muted-foreground`})}),(0,Y.jsx)(cr,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,Y.jsx)(Rt,{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)(ga,{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)(Mr,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{children:PT(t,e)})]},t))})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>h(!1),disabled:i,children:[(0,Y.jsx)(ro,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Y.jsxs)(K,{onClick:()=>h(!0),disabled:i,children:[(0,Y.jsx)(Mr,{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 PT(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 FT=`/api/v1/auth`;function IT({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)(wi,{className:`size-4`})}),`ObjectStack`]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function LT(){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)(IT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsx)(pr,{className:`text-center`,children:(0,Y.jsx)(Rt,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?f?(0,Y.jsx)(IT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(vr,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Y.jsx)(cr,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):m?(0,Y.jsx)(IT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Y.jsx)(IT,{children:(0,Y.jsxs)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Y.jsxs)(ga,{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)(K,{onClick:async()=>{v(``),c(!0);try{let t=await fetch(`${FT}/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)(K,{onClick:async()=>{v(``),d(!0);try{await fetch(`${FT}/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)(IT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function RT(){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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Y.jsx)(Rt,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Y.jsxs)(ga,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(K,{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)(K,{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)(Ht,{className:`w-full max-w-sm`,children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Y.jsx)(Rt,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var zT=`/api/v1/auth`;function BT(){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 VT=BT();function HT(){let e=o(),t=e.pathname+e.search;return(0,Y.jsx)(_,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function UT({children:e,requireOrganization:t=!0}){return(0,Y.jsx)(te,{fallback:(0,Y.jsx)(HT,{}),loadingFallback:(0,Y.jsx)(Qs,{}),children:(0,Y.jsx)(ec,{children:t?(0,Y.jsx)(rc,{children:e}):e})})}function WT(){let{user:e}=w();return(0,Y.jsx)(Ep,{userId:e?.id,children:(0,Y.jsx)(zp,{})})}function GT(){return(0,Y.jsxs)(A,{authUrl:zT,children:[(0,Y.jsx)(kl,{position:`bottom-right`}),(0,Y.jsx)(aT,{}),(0,Y.jsx)(u,{basename:VT,children:(0,Y.jsx)($s,{children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/login`,element:(0,Y.jsx)(_T,{})}),(0,Y.jsx)(d,{path:`/register`,element:(0,Y.jsx)(ST,{})}),(0,Y.jsx)(d,{path:`/forgot-password`,element:(0,Y.jsx)(wT,{})}),(0,Y.jsx)(d,{path:`/reset-password`,element:(0,Y.jsx)(TT,{})}),(0,Y.jsx)(d,{path:`/verify-email`,element:(0,Y.jsx)(DT,{})}),(0,Y.jsx)(d,{path:`/verify-email-prompt`,element:(0,Y.jsx)(OT,{})}),(0,Y.jsx)(d,{path:`/setup`,element:(0,Y.jsx)(jT,{})}),(0,Y.jsx)(d,{path:`/oauth/consent`,element:(0,Y.jsx)(NT,{})}),(0,Y.jsx)(d,{path:`/auth/device`,element:(0,Y.jsx)(LT,{})}),(0,Y.jsx)(d,{path:`/accept-invitation/:invitationId`,element:(0,Y.jsx)(RT,{})}),(0,Y.jsx)(d,{path:`/f/:slug`,element:(0,Y.jsx)(iT,{mode:`public`})}),(0,Y.jsx)(d,{path:`/s/:token`,element:(0,Y.jsx)(cT,{})}),(0,Y.jsx)(d,{path:`/forms/:name`,element:(0,Y.jsx)(UT,{children:(0,Y.jsx)(iT,{mode:`internal`})})}),(0,Y.jsx)(d,{path:`/home`,element:(0,Y.jsx)(UT,{children:(0,Y.jsx)(WT,{})})}),(0,Y.jsx)(d,{path:`/organizations`,element:(0,Y.jsx)(UT,{requireOrganization:!1,children:(0,Y.jsx)(Bp,{children:(0,Y.jsx)(Gp,{})})})}),(0,Y.jsxs)(d,{path:`/organizations/:slug`,element:(0,Y.jsx)(UT,{requireOrganization:!1,children:(0,Y.jsx)(Kp,{})}),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)(Zp,{})}),(0,Y.jsx)(d,{path:`invitations`,element:(0,Y.jsx)(em,{})}),(0,Y.jsx)(d,{path:`settings`,element:(0,Y.jsx)(tm,{})})]}),(0,Y.jsx)(d,{path:`/system/*`,element:(0,Y.jsx)(ic,{})}),(0,Y.jsx)(d,{path:`/ai`,element:(0,Y.jsx)(UT,{children:(0,Y.jsx)(sm,{})})}),(0,Y.jsx)(d,{path:`/ai/:conversationId`,element:(0,Y.jsx)(UT,{children:(0,Y.jsx)(sm,{})})}),(0,Y.jsx)(d,{path:`/apps/:appName/*`,element:(0,Y.jsx)(UT,{children:(0,Y.jsx)(Uw,{})})}),(0,Y.jsx)(d,{path:`/`,element:(0,Y.jsx)(ec,{children:(0,Y.jsx)(Gw,{})})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(_,{to:`/`,replace:!0})})]})})})]})}async function KT(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 qT=`auth-session-token`,JT=`auth-active-organization-id`;async function YT(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(qT)}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(qT),localStorage.removeItem(JT)}catch{}}function XT(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 ZT(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 QT(e){let{objects:t}=ie(),n=(0,J.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,J.useMemo)(()=>n?XT(n,0):null,[n]),fields:(0,J.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(ZT):[],[n]),metadataObject:n}}function $T({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)(Dn,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,Y.jsx)(W,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,Y.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Mr,{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)(ro,{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)(vt,{className:`h-3 w-3`})})]})})]})}function eE({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=QT(t),{refresh:a}=ie(),o=Vd(),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)($T,{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)($T,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Y.jsx)($T,{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)($T,{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 tE=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function nE({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=QT(t),{refresh:i}=ie(),a=Vd(),[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)(K,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Y.jsx)(W,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Y.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:tE.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Y.jsx)(W,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Y.jsx)(W,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Y.jsxs)(K,{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:tE.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)(Xt,{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)(Di,{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)(K,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function rE({schema:e}){let t=e.objectName,{fields:n}=QT(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)(Ue,{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 iE(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)(fr,{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)(ln,{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)(ci,{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 aE({schema:e}){let t=e.objectName,{object:n}=QT(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)(zt,{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 oE(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function sE(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=oE(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 cE(){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 lE(){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 uE(){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 dE(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 fE(...e){return xo(bo(e))}function pE({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)(Tn,{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:fE(`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 mE(...e){return xo(bo(e))}function hE({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:mE(`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)(ea,{className:`h-3 w-3`}):(0,Y.jsx)(Ti,{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)(gE,{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 gE({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 _E(...e){return xo(bo(e))}function vE({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:_E(`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 yE=(0,J.createContext)(null);yE.displayName=`CollaborationContext`;function bE(){return(0,J.useContext)(yE)}function xE(...e){return xo(bo(e))}function SE({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=CE,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=sE(t),d=u.current,f=(0,J.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=dE({initialZoom:e.zoom??1}),{zoom:m}=p,h=lE(),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=uE(),y=cE(),b=bE(),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]),re=(0,J.useCallback)((e,t)=>{o||(O.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[o]),ie=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ae=(0,J.useCallback)(e=>{e.preventDefault();let t=O.current;if(!t||o)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;f(d.map(e=>e.id===t.id?{...e,position:{...e.position,x: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]),oe=(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`}]:[],[_]),P=(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:xE(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Y.jsx)(`div`,{className:xE(`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)(H,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:S?`Collapse palette`:`Expand palette`,"aria-label":S?`Collapse palette`:`Expand palette`,onClick:()=>C(e=>!e),children:(0,Y.jsx)(Qr,{className:xE(`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:xE(`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)(an,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:xE(`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)(tn,{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:xE(`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)(pt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:xE(`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)($n,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsx)(`button`,{className:xE(`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)(Xt,{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)(no,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:xE(`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)(Pr,{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)(la,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Y.jsx)(oo,{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)(kn,{className:xE(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:p.handleWheel,onMouseDown:p.startPan,onDragOver:ie,onDrop:ae,children:(0,Y.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*m,height:e.height*m,transform:`translate(${p.panOffset.x}px, ${p.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*m}px ${e.gridSize*m}px`:void 0},children:[d.map(e=>{let t=h.isSelected(e.id);return(0,Y.jsxs)(`div`,{draggable:!o,onDragStart:t=>re(t,e),className:xE(`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)(On,{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)(Xt,{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)(vE,{items:P,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Y.jsx)(`div`,{className:xE(`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)(At,{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:xE(`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)(hE,{title:`Properties – ${_.label??_.type}`,fields:oe,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)(pE,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var CE=[{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 wE(e,t={}){return sE(e,t)}function TE(...e){return xo(bo(e))}var EE=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function DE(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 OE({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=wE({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=cE(),m=lE(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=uE(),_=dE({minZoom:.25,maxZoom:3,zoomStep:.1}),v=bE(),[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:DE(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]),re=(0,J.useCallback)(()=>{if(i)return;let e=g.paste();if(!e||e.length===0)return;let t=l.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));f({entities:[...t.entities,...n],relationships:t.relationships}),m.selectMany(n.map(e=>e.id))},[i,g,l,f,m]),ie=(0,J.useCallback)(e=>{if(i)return;let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[i,l,f]),ae=(0,J.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),oe=(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]),P=(0,J.useCallback)(()=>{w(null)},[]),se=(0,J.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),ce=(0,J.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),F=(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(),re()):(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,re,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:TE(`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)(Ai,{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)(an,{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)(tn,{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)(Ka,{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)(Tr,{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)(Wn,{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)(pt,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:re,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)($n,{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)(Ae,{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)(rt,{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)(H,{className:`h-3 w-3`}),` Add Entity`]}),(0,Y.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,Y.jsx)(Di,{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:TE(`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)(Ai,{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:ce,onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&F()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,Y.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),se(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),te(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Y.jsx)(Xt,{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:oe,onKeyDown:e=>{e.key===`Enter`&&oe(),e.key===`Escape`&&P()},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:TE(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),ae(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Y.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Y.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),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:EE.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Y.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Y.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),ie(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Y.jsx)(vE,{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)(Ti,{className:`h-3 w-3`}):(0,Y.jsx)(ea,{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)(hE,{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)(Ti,{className:`h-3 w-3`}):(0,Y.jsx)(ea,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Y.jsx)(pE,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function kE(...e){return xo(bo(e))}var AE=120,jE=50;function ME(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 NE({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=sE({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=cE(),g=lE(),_=uE(),v=dE({initialZoom:1}),y=bE(),[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 re=(0,J.useCallback)((e,t)=>{if(s)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+f.length*160,y:200}};m([...f,n],p),x(n.id),g.selectOne(n.id),y?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:y.currentUserId??``})},[f,p,s,m,g,y]),ie=(0,J.useCallback)(async e=>{if(s)return;let t=f.find(t=>t.id===e);await h.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(m(f.filter(t=>t.id!==e),p.filter(t=>t.source!==e&&t.target!==e)),b===e&&x(null),g.clearSelection(),y?.sendOperation({type:`delete`,elementId:e,data:{},userId:y.currentUserId??``}))},[f,p,b,s,m,h,g,y]),ae=(0,J.useCallback)(async()=>{if(s||g.count===0||!await h.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${g.count} selected node(s) and their connected edges?`))return;let e=g.selectedIds;m(f.filter(t=>!e.has(t.id)),p.filter(t=>!e.has(t.source)&&!e.has(t.target))),x(null),g.clearSelection()},[f,p,s,m,h,g]),oe=(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,_]),P=(0,J.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),se=(0,J.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),ce=(0,J.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),F=(0,J.useCallback)(()=>{s||f.length===0||m(ME(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:AE,height:jE,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(),oe();return}if(n&&e.key===`v`){e.preventDefault(),P();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),ae()):b&&(e.preventDefault(),ie(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,oe,P,ie,ae]);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:kE(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsx)(pE,{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)($i,{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)(an,{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)(tn,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:oe,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)(pt,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:P,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)($n,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:se,className:kE(`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)(Ie,{className:`h-3 w-3`}),` Connect`]}),(0,Y.jsxs)(`button`,{onClick:F,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,Y.jsx)(Lt,{className:`h-3 w-3`}),` Layout`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:v.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,Y.jsx)(Tr,{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)(Ka,{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)(Wn,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(We,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ja,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ze,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ja,{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)(kn,{className:`h-3 w-3`}):(0,Y.jsx)(_r,{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+AE/2;let r=t.position.y+jE/2;n.position.x+AE/2;let i=n.position.y+jE/2,a=t.position.x+AE,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=>{ce(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Y.jsx)(`div`,{className:kE(`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:kE(`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:jE/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:jE/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?ce(e.id):(C(!0),T(e.id))}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:AE/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:AE/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}})]}),!s&&t&&!S&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ie(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,Y.jsx)(Xt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Y.jsx)(vE,{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)(hE,{title:fe?`Properties: ${fe.label}`:`Properties`,fields:pe,onChange:me})})]})]})}function PE(...e){return xo(bo(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`},FE={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}},IE=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function LE({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=sE(a.length>0?a:IE),f=d.current,p=(0,J.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=lE(),h=(0,J.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=uE(),_=cE(),v=bE(),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=FE[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`},[]),re=(0,J.useCallback)((e,t)=>{e.preventDefault();let n=S.current;if(!n||c)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)p(f.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=f.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&p(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}y({type:`move`,elementId:n.id,data:{}}),S.current=null},[c,f,p,y]),ie=(0,J.useMemo)(()=>{if(!O)return[];let e=[{name:`x`,label:$.propX,type:`number`,value:O.position.x,group:$.groupPosition},{name:`y`,label:$.propY,type:`number`,value:O.position.y,group:$.groupPosition},{name:`width`,label:$.propWidth,type:`number`,value:O.position.width,group:$.groupSize},{name:`height`,label:$.propHeight,type:`number`,value:O.position.height,group:$.groupSize}];return O.type===`text`&&e.push({name:`text`,label:$.propText,type:`text`,value:O.properties.text??``,group:$.groupContent}),O.type===`field`&&e.push({name:`field`,label:$.propField,type:`text`,value:O.properties.field??``,group:$.groupContent}),e},[O]);return(0,J.useEffect)(()=>{let e=C.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&m.count>0&&!t){e.preventDefault(),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:PE(`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)(da,{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:PE(`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)(an,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:PE(`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)(tn,{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:PE(`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)(pt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:PE(`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)($n,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsx)(`button`,{className:PE(`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)(Xt,{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)(kn,{className:PE(`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=>re(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)(fn,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,Y.jsx)(_t,{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)(ci,{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)(hr,{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:PE(`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)(Xt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Y.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:PE(`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)(hE,{title:`${$.properties} – ${O.type}`,fields:ie,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)(pE,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var RE={"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 zE(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 BE(){try{let e=z();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:zE(RE)}:{t:e.t}}catch{return{t:zE(RE)}}}function VE(...e){return xo(bo(e))}var HE={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function UE(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var WE=0;function GE(e){return WE+=1,`${e}_${Date.now()}_${WE}`}function KE({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:VE(`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:VE(`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:VE(`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)(Mr,{className:`h-4 w-4`}):r+1}),(0,Y.jsx)(`span`,{className:VE(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function qE({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:VE(`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:je},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:Lt},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:en}].map(({value:t,labelKey:a,Icon:o})=>(0,Y.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:VE(`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 JE({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)(Wa,{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:VE(`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:VE(`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)(Mr,{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 YE={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 XE({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)(Hr,{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)(Ie,{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)(la,{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:VE(`rounded-full px-2 py-0.5 text-[10px] font-medium`,YE[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)(Pa,{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)(Ti,{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)(Xt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function ZE({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)(_t,{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)(Qi,{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)(ei,{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 QE({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=BE(),l=cE(),[u,d]=(0,J.useState)(0),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(()=>({...HE,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:GE(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:UE(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:UE(e.objects)})),d(e))},[u,b]);return(0,Y.jsxs)(`div`,{className:VE(`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)(ro,{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)(KE,{steps:g,currentIndex:u,onStepClick:te})}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Y.jsx)(qE,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Y.jsx)(JE,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Y.jsx)(XE,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Y.jsx)(ZE,{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)(Sa,{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)(Mr,{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)(ea,{className:`h-4 w-4`})]})]})]})]})}function $E(...e){return xo(bo(e))}var eD=0;function tD(e){return eD+=1,`${e}_${Date.now()}_${eD}`}var nD={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Ai},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:dt},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:da},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:ci},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Ie},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:Hr},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:la},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:zr}},rD=[{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 iD({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=nD[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:$E(`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)(On,{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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(vt,{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:$E(`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:$E(`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)(Rn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(no,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":m(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,Y.jsx)(H,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:i||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveUp`),children:(0,Y.jsx)(Pa,{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)(Ti,{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)(Xt,{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)(iD,{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 aD({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)(oD,{item:e,depth:0},e.id))})]})}function oD({item:e,depth:t}){let n=nD[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)(oD,{item:e,depth:t+1},e.id))]})}function sD({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=BE(),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:tD(r),type:r,label:r===`separator`?``:`New ${s(nD[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:tD(n),type:n,label:n===`separator`?``:`New ${s(nD[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:$E(`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:[rD.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=nD[e];return(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:$E(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),s(t)]},e)}),(0,Y.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:y,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,Y.jsx)(nt,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Y.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:$E(`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)(ji,{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)(iD,{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)(aD,{items:e,t:s})]})}function cD(...e){return xo(bo(e))}var lD=[{type:`metric`,label:`KPI Metric`,Icon:mt},{type:`bar`,label:`Bar Chart`,Icon:ci},{type:`line`,label:`Line Chart`,Icon:Xr},{type:`pie`,label:`Pie Chart`,Icon:Wr},{type:`table`,label:`Table`,Icon:hr},{type:`grid`,label:`Grid`,Icon:Sn}],uD=0;function dD(){return uD+=1,`widget_${Date.now()}_${uD}`}function fD({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=lD.find(e=>e.type===l)||lD[0];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:cD(`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)(On,{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)(Pa,{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)(Ti,{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)(Xt,{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 pD({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=BE();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)(ro,{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:lD.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 mD({schema:e}){let{t}=BE(),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=lD.find(t=>t.type===(e.type||`metric`))||lD[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 hD({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=BE(),[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}=sE(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=dD(),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:cD(`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)(pD,{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`),`:`]}),lD.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)(an,{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)(tn,{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)(nt,{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)(ji,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:cD(`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)(Rn,{className:`h-4 w-4`}):(0,Y.jsx)(no,{className:`h-4 w-4`})})]})]}),d?(0,Y.jsx)(mD,{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)(fD,{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 gD(...e){return xo(bo(e))}var _D=[{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`}],vD=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function yD({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=BE(),[c,l]=(0,J.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=sE(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:gD(`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:gD(`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)(an,{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:gD(`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)(tn,{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)(nt,{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:gD(`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)(ji,{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)(_t,{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)(Qi,{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:_D.map(e=>(0,Y.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:gD(`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)(ei,{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)(fn,{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`)}),vD.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:gD(`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)(ur,{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:gD(`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)(Ia,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview`,className:gD(`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:gD(`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:gD(`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:gD(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Y.jsxs)(`div`,{className:gD(`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:gD(`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:gD(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:gD(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:gD(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function bD(...e){return xo(bo(e))}var xD=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],SD=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function CD({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=BE(),s=cE(),[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:SD.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:xD.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:bD(`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)(Ai,{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)(zo,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Y.jsx)(Bo,{schema:S}),(0,Y.jsx)(pE,{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 wD(...e){return xo(bo(e))}var TD={text:{label:`Text`,Icon:fn},textarea:{label:`Text Area`,Icon:da},number:{label:`Number`,Icon:dr},boolean:{label:`Checkbox`,Icon:qe},date:{label:`Date`,Icon:Xi},datetime:{label:`Date/Time`,Icon:Xi},time:{label:`Time`,Icon:Xi},select:{label:`Picklist`,Icon:hn},email:{label:`Email`,Icon:Ve},phone:{label:`Phone`,Icon:Yn},url:{label:`URL`,Icon:ei},password:{label:`Password`,Icon:Un},currency:{label:`Currency`,Icon:dr},percent:{label:`Percent`,Icon:dr},lookup:{label:`Lookup`,Icon:Di},formula:{label:`Formula`,Icon:Pn},autonumber:{label:`Auto Number`,Icon:dr},file:{label:`File`,Icon:da},image:{label:`Image`,Icon:_t},markdown:{label:`Markdown`,Icon:da},html:{label:`Rich Text`,Icon:da},color:{label:`Color`,Icon:Qi},code:{label:`Code`,Icon:Pn},location:{label:`Location`,Icon:eo},address:{label:`Address`,Icon:eo},rating:{label:`Rating`,Icon:Pe},slider:{label:`Slider`,Icon:Br}},ED={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`]},DD=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function OD({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=BE(),o=cE(),[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)(()=>DD.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:ED[e].map(e=>({label:TD[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:wD(`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)(Yt,{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)(zo,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Y.jsx)(Vo,{schema:w}),(0,Y.jsx)(pE,{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 kD=`objectui-app-wizard-draft`;function AD(){let e=v(),{appName:t}=p(),{objects:n,refresh:r}=ie(),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(kD);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(kD),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(kD,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)(QE,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function jD(){let e=v(),{appName:t,editAppName:n}=p(),{apps:r,objects:i,refresh:a}=ie(),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)(QE,{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 MD(){let e=v(),{dashboardName:t}=p(),n=le(),{dashboards:r,refresh:i}=ie(),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)(Zt,{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)(hD,{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 ND=t({AppCreationWizard:()=>QE,BrandingEditor:()=>yD,CreateAppPage:()=>AD,DashboardDesignPage:()=>MD,DashboardEditor:()=>hD,DataModelDesigner:()=>OE,EditAppPage:()=>jD,FieldDesigner:()=>OD,NavigationDesigner:()=>sD,ObjectManager:()=>CD,PageDesigner:()=>SE,ProcessDesigner:()=>NE,ReportDesigner:()=>LE});I.register(`page-designer`,SE,{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`,OE,{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`,NE,{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`,LE,{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`,QE,{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`,sD,{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`,hD,{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`,yD,{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`,CD,{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`,OD,{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 PD(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 FD(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 ID=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=PD(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(FD)};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 LD({schema:e}){let t=e.objectName,{objects:n,refresh:r}=ie(),i=Vd(),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(ZT):[],[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=ID.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)(Ne,{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)(OD,{objectName:t,fields:d,onFieldsChange:p})]})}function RD({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)(Fa,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Y.jsxs)(ta,{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)(fi,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Y.jsxs)(ta,{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)(Yt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Y.jsxs)(ta,{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)(Di,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Y.jsxs)(ta,{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)(zt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Y.jsx)(ri,{value:`details`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(F,{schema:i})})}),(0,Y.jsx)(ri,{value:`fields`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(F,{schema:a})})}),(0,Y.jsx)(ri,{value:`relationships`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(F,{schema:o}),(0,Y.jsx)(F,{schema:s})]})}),(0,Y.jsx)(ri,{value:`data`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(F,{schema:l}),(0,Y.jsx)(F,{schema:c})]})})]})})}var zD={namespace:`console`,category:`system`};I.register(`object-detail-tabs`,RD,{...zD,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),I.register(`object-properties`,eE,{...zD,label:`Object Properties`,icon:`Settings2`}),I.register(`object-relationships`,nE,{...zD,label:`Object Relationships`,icon:`Link2`}),I.register(`object-keys`,rE,{...zD,label:`Object Keys`,icon:`KeyRound`}),I.register(`object-data-experience`,iE,{...zD,label:`Data Experience`,icon:`LayoutList`}),I.register(`object-data-preview`,aE,{...zD,label:`Data Preview`,icon:`Table`}),I.register(`object-field-designer`,LD,{...zD,label:`Field Designer`,icon:`Columns`});var BD=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-ePJcxhf9.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),VD=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-C2ElJEUw.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),HD=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-CFO_htk4.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function UD({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pm({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(UD,{label:`API console`}),children:(0,Y.jsx)(BD,{...e})})}),pm({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(UD,{label:`flow runs`}),children:(0,Y.jsx)(VD,{...e})})}),pm({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(UD,{label:`public forms`}),children:(0,Y.jsx)(HD,{...e})})});var WD=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-DbEzcgM3.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function GD({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pm({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(GD,{label:`profile`}),children:(0,Y.jsx)(WD,{...e})})});var KD=`/api/v1/auth`;Pl(),I.registerLazy(`object-map`,()=>c(()=>import(`./plugin-map-Bl9-aL25.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),I.registerLazy(`map`,()=>c(()=>import(`./plugin-map-Bl9-aL25.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-Do4xOja1.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});I.registerLazy(`chart`,()=>c(()=>import(`./plugin-charts-BDWqi8DX.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-BDWqi8DX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});I.registerLazy(`object-gantt`,()=>c(()=>import(`./plugin-gantt-Bv3kYo78.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),I.registerLazy(`gantt`,()=>c(()=>import(`./plugin-gantt-Bv3kYo78.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`markdown`,()=>c(()=>import(`./plugin-markdown-DSLEFWrT.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),I.registerLazy(`object-timeline`,()=>c(()=>import(`./plugin-timeline-Bb7f-Qd7.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),I.registerLazy(`timeline`,()=>c(()=>import(`./plugin-timeline-Bb7f-Qd7.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`object-calendar`,()=>c(()=>import(`./plugin-calendar-CQDuOrA8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`calendar`,()=>c(()=>import(`./plugin-calendar-CQDuOrA8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`calendar-view`,()=>c(()=>import(`./plugin-calendar-CQDuOrA8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`object-kanban`,()=>c(()=>import(`./plugin-kanban-BhsP-1E9.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),I.registerLazy(`kanban`,()=>c(()=>import(`./plugin-kanban-BhsP-1E9.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-BhsP-1E9.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});I.registerLazy(`report`,()=>c(()=>import(`./plugin-report-DcNaFUN2.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-DcNaFUN2.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});Hn();var qD=``.replace(/\/+$/,``);Promise.all([cl(qD),YT(KD)]).finally(()=>{ds.createRoot(document.getElementById(`root`)).render((0,Y.jsx)(J.StrictMode,{children:(0,Y.jsx)(Ro,{pwa:{enabled:!0,name:ul(),shortName:dl()},children:(0,Y.jsx)(R,{loadLanguage:KT,children:(0,Y.jsx)(GT,{})})})}))});export{uf as n,mm as t};
|
|
33
|
+
`):``}function uT(){let{token:e}=f(),t=`${(0,J.useMemo)(()=>cT(),[])}/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)(Di,{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)(G,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Y.jsx)(W,{id:`share-pw`,type:`password`,value:u,onChange:e=>d(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Y.jsx)(K,{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)(Tn,{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)(di,{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=lT(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 dT(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function fT(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function pT(){return typeof window>`u`?null:window.location.host||null}function mT(){let e=ul();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 hT({children:e,formWidth:t=`sm`}){let{t:n}=z(),r=t===`md`?`max-w-md`:`max-w-sm`,i=pT(),a=!!i&&!dT(i)&&!fT(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:U(`flex w-full flex-col gap-5`,r),children:[(0,Y.jsx)(mT,{}),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 gT(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function _T(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function vT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function yT(){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(_T(gT(n)?n:`/`));return}window.location.assign(_T(`/organizations`));return}p||window.location.assign(_T(gT(n)?n:`/`))}},[r,s,a,o,p,n,c]),i&&!h||r)return(0,Y.jsx)(hT,{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)(hT,{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)(Ht,{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)(bT,{registerUrl:d?void 0:v,redirect:n})})]})})}function bT({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:vT,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 xT(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function ST(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function CT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function wT(){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(ST(xT(r)?r:`/`));return}window.location.assign(ST(`/organizations`));return}h||window.location.assign(ST(xT(r)?r:`/`))}},[i,u,o,c,h,r,d]),p===null||a&&!_||i)return(0,Y.jsx)(hT,{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)(hT,{formWidth:`md`,children:(0,Y.jsx)(Ht,{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:CT,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 TT(e){return(0,Y.jsx)(i,{to:e.href,className:e.className,children:e.children})}function ET(){let{t:e}=z();return(0,Y.jsx)(hT,{formWidth:`md`,children:(0,Y.jsx)(Ht,{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:TT,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 DT(){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)(hT,{children:(0,Y.jsxs)(Ht,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Y.jsx)(Rt,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Y.jsx)(ga,{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)(G,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(W,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:o,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(W,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsx)(K,{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 OT=`/api/v1/auth`;function kT(){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(`${OT}/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)(hT,{children:(0,Y.jsxs)(Ht,{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)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Y.jsx)(Rt,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Y.jsx)(ga,{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)(pr,{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)(vr,{className:`size-6`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Y.jsx)(Rt,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Y.jsx)(ga,{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)(pr,{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)(ir,{className:`size-6`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Y.jsx)(Rt,{children:o||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Y.jsx)(ga,{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 AT(){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)(hT,{children:(0,Y.jsxs)(Ht,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(pr,{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)(Xe,{className:`size-8 text-primary`})}),(0,Y.jsx)(cr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Y.jsx)(Rt,{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)(ga,{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)(K,{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)(Le,{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)(Le,{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)(K,{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 jT=`/api/v1/auth`;function MT(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function NT(){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(`${jT}/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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Y.jsx)(Rt,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Y.jsx)(ga,{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:MT(e)}),n=t.id):n=(await c({name:e,slug:MT(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)(G,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Y.jsx)(W,{id:`name`,autoComplete:`name`,required:!0,value:u,onChange:e=>d(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Y.jsx)(W,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(W,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:f,onChange:e=>p(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(G,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Y.jsx)(W,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:m,onChange:e=>h(e.target.value)})]}),(0,Y.jsx)(K,{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 PT=`/api/v1/auth`;function FT(){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(`${PT}/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(`${PT}/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)(Ht,{className:`w-full max-w-md`,children:[(0,Y.jsxs)(pr,{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)(Ue,{className:`h-7 w-7 text-muted-foreground`})}),(0,Y.jsx)(cr,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,Y.jsx)(Rt,{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)(ga,{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)(Mr,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{children:IT(t,e)})]},t))})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Y.jsxs)(K,{variant:`outline`,onClick:()=>h(!1),disabled:i,children:[(0,Y.jsx)(ro,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Y.jsxs)(K,{onClick:()=>h(!0),disabled:i,children:[(0,Y.jsx)(Mr,{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 IT(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 LT=`/api/v1/auth`;function RT({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)(wi,{className:`size-4`})}),`ObjectStack`]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function zT(){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)(RT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsx)(pr,{className:`text-center`,children:(0,Y.jsx)(Rt,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?f?(0,Y.jsx)(RT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(vr,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Y.jsx)(cr,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):m?(0,Y.jsx)(RT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Y.jsx)(RT,{children:(0,Y.jsxs)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Y.jsxs)(ga,{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)(K,{onClick:async()=>{v(``),c(!0);try{let t=await fetch(`${LT}/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)(K,{onClick:async()=>{v(``),d(!0);try{await fetch(`${LT}/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)(RT,{children:(0,Y.jsx)(Ht,{children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Y.jsx)(Rt,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function BT(){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)(Ht,{children:[(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Y.jsx)(Rt,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Y.jsxs)(ga,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(K,{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)(K,{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)(Ht,{className:`w-full max-w-sm`,children:(0,Y.jsxs)(pr,{className:`text-center`,children:[(0,Y.jsx)(cr,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Y.jsx)(Rt,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var VT=`/api/v1/auth`;function HT(){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 UT=HT();function WT(){let e=o(),t=e.pathname+e.search;return(0,Y.jsx)(_,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function GT({children:e,requireOrganization:t=!0}){return(0,Y.jsx)(te,{fallback:(0,Y.jsx)(WT,{}),loadingFallback:(0,Y.jsx)(Qs,{}),children:(0,Y.jsx)(ec,{children:t?(0,Y.jsx)(rc,{children:e}):e})})}function KT(){let{user:e}=w();return(0,Y.jsx)(Ep,{userId:e?.id,children:(0,Y.jsx)(zp,{})})}function qT(){return(0,Y.jsxs)(A,{authUrl:VT,children:[(0,Y.jsx)(kl,{position:`bottom-right`}),(0,Y.jsx)(sT,{}),(0,Y.jsx)(u,{basename:UT,children:(0,Y.jsx)($s,{children:(0,Y.jsxs)(y,{children:[(0,Y.jsx)(d,{path:`/login`,element:(0,Y.jsx)(yT,{})}),(0,Y.jsx)(d,{path:`/register`,element:(0,Y.jsx)(wT,{})}),(0,Y.jsx)(d,{path:`/forgot-password`,element:(0,Y.jsx)(ET,{})}),(0,Y.jsx)(d,{path:`/reset-password`,element:(0,Y.jsx)(DT,{})}),(0,Y.jsx)(d,{path:`/verify-email`,element:(0,Y.jsx)(kT,{})}),(0,Y.jsx)(d,{path:`/verify-email-prompt`,element:(0,Y.jsx)(AT,{})}),(0,Y.jsx)(d,{path:`/setup`,element:(0,Y.jsx)(NT,{})}),(0,Y.jsx)(d,{path:`/oauth/consent`,element:(0,Y.jsx)(FT,{})}),(0,Y.jsx)(d,{path:`/auth/device`,element:(0,Y.jsx)(zT,{})}),(0,Y.jsx)(d,{path:`/accept-invitation/:invitationId`,element:(0,Y.jsx)(BT,{})}),(0,Y.jsx)(d,{path:`/f/:slug`,element:(0,Y.jsx)(oT,{mode:`public`})}),(0,Y.jsx)(d,{path:`/s/:token`,element:(0,Y.jsx)(uT,{})}),(0,Y.jsx)(d,{path:`/forms/:name`,element:(0,Y.jsx)(GT,{children:(0,Y.jsx)(oT,{mode:`internal`})})}),(0,Y.jsx)(d,{path:`/home`,element:(0,Y.jsx)(GT,{children:(0,Y.jsx)(KT,{})})}),(0,Y.jsx)(d,{path:`/organizations`,element:(0,Y.jsx)(GT,{requireOrganization:!1,children:(0,Y.jsx)(Bp,{children:(0,Y.jsx)(Gp,{})})})}),(0,Y.jsxs)(d,{path:`/organizations/:slug`,element:(0,Y.jsx)(GT,{requireOrganization:!1,children:(0,Y.jsx)(Kp,{})}),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)(Zp,{})}),(0,Y.jsx)(d,{path:`invitations`,element:(0,Y.jsx)(em,{})}),(0,Y.jsx)(d,{path:`settings`,element:(0,Y.jsx)(tm,{})})]}),(0,Y.jsx)(d,{path:`/system/*`,element:(0,Y.jsx)(ic,{})}),(0,Y.jsx)(d,{path:`/ai`,element:(0,Y.jsx)(GT,{children:(0,Y.jsx)(sm,{})})}),(0,Y.jsx)(d,{path:`/ai/:conversationId`,element:(0,Y.jsx)(GT,{children:(0,Y.jsx)(sm,{})})}),(0,Y.jsx)(d,{path:`/apps/:appName/*`,element:(0,Y.jsx)(GT,{children:(0,Y.jsx)(Gw,{})})}),(0,Y.jsx)(d,{path:`/`,element:(0,Y.jsx)(ec,{children:(0,Y.jsx)(qw,{})})}),(0,Y.jsx)(d,{path:`*`,element:(0,Y.jsx)(_,{to:`/`,replace:!0})})]})})})]})}async function JT(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 YT=`auth-session-token`,XT=`auth-active-organization-id`;async function ZT(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(YT)}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(YT),localStorage.removeItem(XT)}catch{}}function QT(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 $T(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 eE(e){let{objects:t}=ie(),n=(0,J.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,J.useMemo)(()=>n?QT(n,0):null,[n]),fields:(0,J.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map($T):[],[n]),metadataObject:n}}function tE({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)(Dn,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,Y.jsx)(W,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,Y.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,Y.jsx)(B,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Mr,{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)(ro,{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)(vt,{className:`h-3 w-3`})})]})})]})}function nE({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=eE(t),{refresh:a}=ie(),o=Vd(),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)(tE,{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)(tE,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Y.jsx)(tE,{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)(tE,{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 rE=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function iE({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=eE(t),{refresh:i}=ie(),a=Vd(),[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)(K,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Y.jsx)(W,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Y.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:rE.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Y.jsx)(W,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Y.jsx)(W,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Y.jsxs)(K,{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:rE.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)(Xt,{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)(Di,{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)(K,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Y.jsx)(H,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function aE({schema:e}){let t=e.objectName,{fields:n}=eE(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)(Ue,{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 oE(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)(fr,{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)(ln,{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)(ci,{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 sE({schema:e}){let t=e.objectName,{object:n}=eE(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)(zt,{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 cE(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function lE(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=cE(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 uE(){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 dE(){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 fE(){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 pE(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 mE(...e){return xo(bo(e))}function hE({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)(Tn,{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:mE(`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 gE(...e){return xo(bo(e))}function _E({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:gE(`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)(ea,{className:`h-3 w-3`}):(0,Y.jsx)(Ti,{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)(vE,{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 vE({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 yE(...e){return xo(bo(e))}function bE({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:yE(`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 xE=(0,J.createContext)(null);xE.displayName=`CollaborationContext`;function SE(){return(0,J.useContext)(xE)}function CE(...e){return xo(bo(e))}function wE({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=TE,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=lE(t),d=u.current,f=(0,J.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=pE({initialZoom:e.zoom??1}),{zoom:m}=p,h=dE(),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=fE(),y=uE(),b=SE(),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]),re=(0,J.useCallback)((e,t)=>{o||(O.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[o]),ie=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ae=(0,J.useCallback)(e=>{e.preventDefault();let t=O.current;if(!t||o)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;f(d.map(e=>e.id===t.id?{...e,position:{...e.position,x: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]),oe=(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`}]:[],[_]),P=(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:CE(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Y.jsx)(`div`,{className:CE(`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)(H,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:S?`Collapse palette`:`Expand palette`,"aria-label":S?`Collapse palette`:`Expand palette`,onClick:()=>C(e=>!e),children:(0,Y.jsx)(Qr,{className:CE(`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:CE(`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)(an,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:CE(`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)(tn,{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:CE(`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)(pt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:CE(`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)($n,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsx)(`button`,{className:CE(`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)(Xt,{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)(no,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:CE(`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)(Pr,{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)(la,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Y.jsx)(oo,{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)(kn,{className:CE(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:p.handleWheel,onMouseDown:p.startPan,onDragOver:ie,onDrop:ae,children:(0,Y.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*m,height:e.height*m,transform:`translate(${p.panOffset.x}px, ${p.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*m}px ${e.gridSize*m}px`:void 0},children:[d.map(e=>{let t=h.isSelected(e.id);return(0,Y.jsxs)(`div`,{draggable:!o,onDragStart:t=>re(t,e),className:CE(`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)(On,{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)(Xt,{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)(bE,{items:P,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Y.jsx)(`div`,{className:CE(`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)(At,{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:CE(`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)(_E,{title:`Properties – ${_.label??_.type}`,fields:oe,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)(hE,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var TE=[{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 EE(e,t={}){return lE(e,t)}function DE(...e){return xo(bo(e))}var OE=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function kE(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 AE({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=EE({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=uE(),m=dE(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=fE(),_=pE({minZoom:.25,maxZoom:3,zoomStep:.1}),v=SE(),[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:kE(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]),re=(0,J.useCallback)(()=>{if(i)return;let e=g.paste();if(!e||e.length===0)return;let t=l.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));f({entities:[...t.entities,...n],relationships:t.relationships}),m.selectMany(n.map(e=>e.id))},[i,g,l,f,m]),ie=(0,J.useCallback)(e=>{if(i)return;let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[i,l,f]),ae=(0,J.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),oe=(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]),P=(0,J.useCallback)(()=>{w(null)},[]),se=(0,J.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),ce=(0,J.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),F=(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(),re()):(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,re,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:DE(`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)(Ai,{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)(an,{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)(tn,{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)(Ka,{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)(Tr,{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)(Wn,{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)(pt,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:re,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)($n,{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)(Ae,{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)(rt,{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)(H,{className:`h-3 w-3`}),` Add Entity`]}),(0,Y.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,Y.jsx)(Di,{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:DE(`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)(Ai,{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:ce,onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&F()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,Y.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),se(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),te(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Y.jsx)(Xt,{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:oe,onKeyDown:e=>{e.key===`Enter`&&oe(),e.key===`Escape`&&P()},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:DE(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),ae(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Y.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Y.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),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:OE.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Y.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Y.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),ie(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Y.jsx)(bE,{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)(Ti,{className:`h-3 w-3`}):(0,Y.jsx)(ea,{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)(_E,{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)(Ti,{className:`h-3 w-3`}):(0,Y.jsx)(ea,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Y.jsx)(hE,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function jE(...e){return xo(bo(e))}var ME=120,NE=50;function PE(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 FE({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=lE({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=uE(),g=dE(),_=fE(),v=pE({initialZoom:1}),y=SE(),[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 re=(0,J.useCallback)((e,t)=>{if(s)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+f.length*160,y:200}};m([...f,n],p),x(n.id),g.selectOne(n.id),y?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:y.currentUserId??``})},[f,p,s,m,g,y]),ie=(0,J.useCallback)(async e=>{if(s)return;let t=f.find(t=>t.id===e);await h.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(m(f.filter(t=>t.id!==e),p.filter(t=>t.source!==e&&t.target!==e)),b===e&&x(null),g.clearSelection(),y?.sendOperation({type:`delete`,elementId:e,data:{},userId:y.currentUserId??``}))},[f,p,b,s,m,h,g,y]),ae=(0,J.useCallback)(async()=>{if(s||g.count===0||!await h.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${g.count} selected node(s) and their connected edges?`))return;let e=g.selectedIds;m(f.filter(t=>!e.has(t.id)),p.filter(t=>!e.has(t.source)&&!e.has(t.target))),x(null),g.clearSelection()},[f,p,s,m,h,g]),oe=(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,_]),P=(0,J.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),se=(0,J.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),ce=(0,J.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),F=(0,J.useCallback)(()=>{s||f.length===0||m(PE(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:ME,height:NE,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(),oe();return}if(n&&e.key===`v`){e.preventDefault(),P();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),ae()):b&&(e.preventDefault(),ie(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,oe,P,ie,ae]);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:jE(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsx)(hE,{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)($i,{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)(an,{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)(tn,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:oe,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)(pt,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:P,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)($n,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:se,className:jE(`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)(Ie,{className:`h-3 w-3`}),` Connect`]}),(0,Y.jsxs)(`button`,{onClick:F,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,Y.jsx)(Lt,{className:`h-3 w-3`}),` Layout`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:v.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,Y.jsx)(Tr,{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)(Ka,{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)(Wn,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(We,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ja,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ze,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`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)(ja,{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)(kn,{className:`h-3 w-3`}):(0,Y.jsx)(_r,{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+ME/2;let r=t.position.y+NE/2;n.position.x+ME/2;let i=n.position.y+NE/2,a=t.position.x+ME,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=>{ce(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Y.jsx)(`div`,{className:jE(`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:jE(`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:NE/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:NE/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?ce(e.id):(C(!0),T(e.id))}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:ME/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:ME/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),ce(e.id)}})]}),!s&&t&&!S&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ie(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,Y.jsx)(Xt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Y.jsx)(bE,{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)(_E,{title:fe?`Properties: ${fe.label}`:`Properties`,fields:pe,onChange:me})})]})]})}function IE(...e){return xo(bo(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`},LE={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}},RE=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function zE({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=lE(a.length>0?a:RE),f=d.current,p=(0,J.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=dE(),h=(0,J.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=fE(),_=uE(),v=SE(),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=LE[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`},[]),re=(0,J.useCallback)((e,t)=>{e.preventDefault();let n=S.current;if(!n||c)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)p(f.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=f.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&p(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}y({type:`move`,elementId:n.id,data:{}}),S.current=null},[c,f,p,y]),ie=(0,J.useMemo)(()=>{if(!O)return[];let e=[{name:`x`,label:$.propX,type:`number`,value:O.position.x,group:$.groupPosition},{name:`y`,label:$.propY,type:`number`,value:O.position.y,group:$.groupPosition},{name:`width`,label:$.propWidth,type:`number`,value:O.position.width,group:$.groupSize},{name:`height`,label:$.propHeight,type:`number`,value:O.position.height,group:$.groupSize}];return O.type===`text`&&e.push({name:`text`,label:$.propText,type:`text`,value:O.properties.text??``,group:$.groupContent}),O.type===`field`&&e.push({name:`field`,label:$.propField,type:`text`,value:O.properties.field??``,group:$.groupContent}),e},[O]);return(0,J.useEffect)(()=>{let e=C.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&m.count>0&&!t){e.preventDefault(),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:IE(`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)(da,{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:IE(`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)(an,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:IE(`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)(tn,{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:IE(`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)(pt,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:IE(`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)($n,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsx)(`button`,{className:IE(`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)(Xt,{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)(kn,{className:IE(`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=>re(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)(fn,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,Y.jsx)(H,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,Y.jsx)(_t,{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)(ci,{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)(hr,{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:IE(`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)(Xt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Y.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:IE(`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)(_E,{title:`${$.properties} – ${O.type}`,fields:ie,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)(hE,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var BE={"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 VE(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 HE(){try{let e=z();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:VE(BE)}:{t:e.t}}catch{return{t:VE(BE)}}}function UE(...e){return xo(bo(e))}var WE={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function GE(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var KE=0;function qE(e){return KE+=1,`${e}_${Date.now()}_${KE}`}function JE({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:UE(`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:UE(`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:UE(`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)(Mr,{className:`h-4 w-4`}):r+1}),(0,Y.jsx)(`span`,{className:UE(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function YE({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:UE(`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:je},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:Lt},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:en}].map(({value:t,labelKey:a,Icon:o})=>(0,Y.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:UE(`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 XE({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)(Wa,{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:UE(`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:UE(`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)(Mr,{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 ZE={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 QE({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)(Hr,{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)(Ie,{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)(la,{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:UE(`rounded-full px-2 py-0.5 text-[10px] font-medium`,ZE[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)(Pa,{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)(Ti,{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)(Xt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function $E({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)(_t,{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)(Qi,{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)(ei,{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 eD({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=HE(),l=uE(),[u,d]=(0,J.useState)(0),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(()=>({...WE,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:qE(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:GE(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:GE(e.objects)})),d(e))},[u,b]);return(0,Y.jsxs)(`div`,{className:UE(`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)(ro,{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)(JE,{steps:g,currentIndex:u,onStepClick:te})}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Y.jsx)(YE,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Y.jsx)(XE,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Y.jsx)(QE,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Y.jsx)($E,{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)(Sa,{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)(Mr,{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)(ea,{className:`h-4 w-4`})]})]})]})]})}function tD(...e){return xo(bo(e))}var nD=0;function rD(e){return nD+=1,`${e}_${Date.now()}_${nD}`}var iD={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Ai},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:dt},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:da},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:ci},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Ie},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:Hr},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:la},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:zr}},aD=[{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 oD({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=iD[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:tD(`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)(On,{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)(Ti,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ea,{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)(vt,{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:tD(`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:tD(`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)(Rn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(no,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":m(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,Y.jsx)(H,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:i||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveUp`),children:(0,Y.jsx)(Pa,{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)(Ti,{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)(Xt,{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)(oD,{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 sD({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)(cD,{item:e,depth:0},e.id))})]})}function cD({item:e,depth:t}){let n=iD[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)(cD,{item:e,depth:t+1},e.id))]})}function lD({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=HE(),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:rD(r),type:r,label:r===`separator`?``:`New ${s(iD[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:rD(n),type:n,label:n===`separator`?``:`New ${s(iD[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:tD(`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:[aD.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=iD[e];return(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:tD(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),s(t)]},e)}),(0,Y.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:y,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,Y.jsx)(nt,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Y.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:tD(`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)(ji,{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)(oD,{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)(sD,{items:e,t:s})]})}function uD(...e){return xo(bo(e))}var dD=[{type:`metric`,label:`KPI Metric`,Icon:mt},{type:`bar`,label:`Bar Chart`,Icon:ci},{type:`line`,label:`Line Chart`,Icon:Xr},{type:`pie`,label:`Pie Chart`,Icon:Wr},{type:`table`,label:`Table`,Icon:hr},{type:`grid`,label:`Grid`,Icon:Sn}],fD=0;function pD(){return fD+=1,`widget_${Date.now()}_${fD}`}function mD({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=dD.find(e=>e.type===l)||dD[0];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:uD(`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)(On,{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)(Pa,{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)(Ti,{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)(Xt,{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 hD({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=HE();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)(ro,{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:dD.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 gD({schema:e}){let{t}=HE(),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=dD.find(t=>t.type===(e.type||`metric`))||dD[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 _D({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=HE(),[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}=lE(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=pD(),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:uD(`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)(hD,{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`),`:`]}),dD.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)(an,{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)(tn,{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)(nt,{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)(ji,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:uD(`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)(Rn,{className:`h-4 w-4`}):(0,Y.jsx)(no,{className:`h-4 w-4`})})]})]}),d?(0,Y.jsx)(gD,{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)(mD,{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 vD(...e){return xo(bo(e))}var yD=[{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`}],bD=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function xD({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=HE(),[c,l]=(0,J.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=lE(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:vD(`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:vD(`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)(an,{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:vD(`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)(tn,{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)(nt,{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:vD(`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)(ji,{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)(_t,{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)(Qi,{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:yD.map(e=>(0,Y.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:vD(`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)(ei,{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)(fn,{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`)}),bD.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:vD(`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)(ur,{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:vD(`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)(Ia,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview`,className:vD(`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:vD(`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:vD(`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:vD(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Y.jsxs)(`div`,{className:vD(`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:vD(`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:vD(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:vD(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:vD(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function SD(...e){return xo(bo(e))}var CD=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],wD=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function TD({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=HE(),s=uE(),[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:wD.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:CD.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:SD(`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)(Ai,{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)(zo,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Y.jsx)(Bo,{schema:S}),(0,Y.jsx)(hE,{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 ED(...e){return xo(bo(e))}var DD={text:{label:`Text`,Icon:fn},textarea:{label:`Text Area`,Icon:da},number:{label:`Number`,Icon:dr},boolean:{label:`Checkbox`,Icon:qe},date:{label:`Date`,Icon:Xi},datetime:{label:`Date/Time`,Icon:Xi},time:{label:`Time`,Icon:Xi},select:{label:`Picklist`,Icon:hn},email:{label:`Email`,Icon:Ve},phone:{label:`Phone`,Icon:Yn},url:{label:`URL`,Icon:ei},password:{label:`Password`,Icon:Un},currency:{label:`Currency`,Icon:dr},percent:{label:`Percent`,Icon:dr},lookup:{label:`Lookup`,Icon:Di},formula:{label:`Formula`,Icon:Pn},autonumber:{label:`Auto Number`,Icon:dr},file:{label:`File`,Icon:da},image:{label:`Image`,Icon:_t},markdown:{label:`Markdown`,Icon:da},html:{label:`Rich Text`,Icon:da},color:{label:`Color`,Icon:Qi},code:{label:`Code`,Icon:Pn},location:{label:`Location`,Icon:eo},address:{label:`Address`,Icon:eo},rating:{label:`Rating`,Icon:Pe},slider:{label:`Slider`,Icon:Br}},OD={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`]},kD=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function AD({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=HE(),o=uE(),[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)(()=>kD.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:OD[e].map(e=>({label:DD[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:ED(`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)(Yt,{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)(zo,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Y.jsx)(Vo,{schema:w}),(0,Y.jsx)(hE,{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 jD=`objectui-app-wizard-draft`;function MD(){let e=v(),{appName:t}=p(),{objects:n,refresh:r}=ie(),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(jD);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(jD),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(jD,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)(eD,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function ND(){let e=v(),{appName:t,editAppName:n}=p(),{apps:r,objects:i,refresh:a}=ie(),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)(eD,{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 PD(){let e=v(),{dashboardName:t}=p(),n=le(),{dashboards:r,refresh:i}=ie(),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)(Zt,{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)(_D,{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 FD=t({AppCreationWizard:()=>eD,BrandingEditor:()=>xD,CreateAppPage:()=>MD,DashboardDesignPage:()=>PD,DashboardEditor:()=>_D,DataModelDesigner:()=>AE,EditAppPage:()=>ND,FieldDesigner:()=>AD,NavigationDesigner:()=>lD,ObjectManager:()=>TD,PageDesigner:()=>wE,ProcessDesigner:()=>FE,ReportDesigner:()=>zE});I.register(`page-designer`,wE,{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`,AE,{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`,FE,{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`,zE,{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`,eD,{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`,lD,{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`,_D,{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`,xD,{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`,TD,{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`,AD,{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 ID(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 LD(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 RD=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=ID(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(LD)};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 zD({schema:e}){let t=e.objectName,{objects:n,refresh:r}=ie(),i=Vd(),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($T):[],[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=RD.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)(Ne,{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)(AD,{objectName:t,fields:d,onFieldsChange:p})]})}function BD({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)(Fa,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Y.jsxs)(ta,{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)(fi,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Y.jsxs)(ta,{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)(Yt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Y.jsxs)(ta,{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)(Di,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Y.jsxs)(ta,{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)(zt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Y.jsx)(ri,{value:`details`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(F,{schema:i})})}),(0,Y.jsx)(ri,{value:`fields`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(F,{schema:a})})}),(0,Y.jsx)(ri,{value:`relationships`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(F,{schema:o}),(0,Y.jsx)(F,{schema:s})]})}),(0,Y.jsx)(ri,{value:`data`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(F,{schema:l}),(0,Y.jsx)(F,{schema:c})]})})]})})}var VD={namespace:`console`,category:`system`};I.register(`object-detail-tabs`,BD,{...VD,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),I.register(`object-properties`,nE,{...VD,label:`Object Properties`,icon:`Settings2`}),I.register(`object-relationships`,iE,{...VD,label:`Object Relationships`,icon:`Link2`}),I.register(`object-keys`,aE,{...VD,label:`Object Keys`,icon:`KeyRound`}),I.register(`object-data-experience`,oE,{...VD,label:`Data Experience`,icon:`LayoutList`}),I.register(`object-data-preview`,sE,{...VD,label:`Data Preview`,icon:`Table`}),I.register(`object-field-designer`,zD,{...VD,label:`Field Designer`,icon:`Columns`});var HD=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-2Hfplikq.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),UD=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-0KW8LdCn.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),WD=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-BkfIcEml.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function GD({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pm({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(GD,{label:`API console`}),children:(0,Y.jsx)(HD,{...e})})}),pm({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(GD,{label:`flow runs`}),children:(0,Y.jsx)(UD,{...e})})}),pm({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(GD,{label:`public forms`}),children:(0,Y.jsx)(WD,{...e})})});var KD=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-wEhY3kyx.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function qD({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pm({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(qD,{label:`profile`}),children:(0,Y.jsx)(KD,{...e})})});var JD=`/api/v1/auth`;Pl(),I.registerLazy(`object-map`,()=>c(()=>import(`./plugin-map-dgG_mKQS.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),I.registerLazy(`map`,()=>c(()=>import(`./plugin-map-dgG_mKQS.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-CXLv53tc.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});I.registerLazy(`chart`,()=>c(()=>import(`./plugin-charts-BvH5iWMS.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-BvH5iWMS.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});I.registerLazy(`object-gantt`,()=>c(()=>import(`./plugin-gantt-DY4QgxI_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),I.registerLazy(`gantt`,()=>c(()=>import(`./plugin-gantt-DY4QgxI_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`markdown`,()=>c(()=>import(`./plugin-markdown-CWpRZuHu.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),I.registerLazy(`object-timeline`,()=>c(()=>import(`./plugin-timeline-Dk3Nk3zI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),I.registerLazy(`timeline`,()=>c(()=>import(`./plugin-timeline-Dk3Nk3zI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`object-calendar`,()=>c(()=>import(`./plugin-calendar-CHvFKG6D.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`calendar`,()=>c(()=>import(`./plugin-calendar-CHvFKG6D.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`calendar-view`,()=>c(()=>import(`./plugin-calendar-CHvFKG6D.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`object-kanban`,()=>c(()=>import(`./plugin-kanban-DSD6E3zx.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),I.registerLazy(`kanban`,()=>c(()=>import(`./plugin-kanban-DSD6E3zx.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-DSD6E3zx.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});I.registerLazy(`report`,()=>c(()=>import(`./plugin-report-BFZ-T3Th.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-BFZ-T3Th.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});Hn();var YD=``.replace(/\/+$/,``);Promise.all([cl(YD),ZT(JD)]).finally(()=>{ds.createRoot(document.getElementById(`root`)).render((0,Y.jsx)(J.StrictMode,{children:(0,Y.jsx)(Ro,{pwa:{enabled:!0,name:ul(),shortName:dl()},children:(0,Y.jsx)(R,{loadLanguage:JT,children:(0,Y.jsx)(qT,{})})})}))});export{uf as n,mm as t};
|