@objectstack/console 8.0.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AiPendingActionsPage-GMbp_gU6.js → AiPendingActionsPage-B9iWZUDQ.js} +1 -1
- package/dist/assets/{ApiConsolePage-fx31NUJu.js → ApiConsolePage-DJYUA73f.js} +1 -1
- package/dist/assets/AppManagementPage-DPljSpdo.js +1 -0
- package/dist/assets/{ApprovalsInboxPage-Nx8dWGIh.js → ApprovalsInboxPage-Be6DrS7X.js} +1 -1
- package/dist/assets/{AuditLogPage-BbJVvOwP.js → AuditLogPage-DWQl9my4.js} +1 -1
- package/dist/assets/{ComponentNavView-BDbQBPDu.js → ComponentNavView-BlNdGi6O.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-DWHDGm6C.js +1 -0
- package/dist/assets/DeveloperHubPage-D7pt27Ji.js +1 -0
- package/dist/assets/FlowRunsPage-sdTkbx5s.js +1 -0
- package/dist/assets/{IntegrationsPage-ByxF20mz.js → IntegrationsPage-CHg7ApBe.js} +2 -2
- package/dist/assets/{MonacoImpl-D8XcOOYC.js → MonacoImpl-BsJjT9SV.js} +1 -1
- package/dist/assets/{ProfilePage-Cg44IVsv.js → ProfilePage-D7kxyCKj.js} +1 -1
- package/dist/assets/PublicFormsPage-DbMqDQiv.js +1 -0
- package/dist/assets/{RecentItemsProvider-PPHUem2M.js → RecentItemsProvider-DiJIrHwK.js} +1 -1
- package/dist/assets/{SettingsHub-BSUyG7Hf.js → SettingsHub-DerOpof3.js} +1 -1
- package/dist/assets/SettingsView-BNq6smI8.js +1 -0
- package/dist/assets/SystemHubPage-D-J4FeqY.js +1 -0
- package/dist/assets/data-adapter-DlR5JXpU.js +1 -0
- package/dist/assets/{dist-BG5mNWi0.js → dist-DYcwLEm6.js} +1 -1
- package/dist/assets/{framework-CzhT5JRV.js → framework-DoGxClbR.js} +6 -6
- package/dist/assets/{highlighted-body-OFNGDK62-BhGyBfwq.js → highlighted-body-OFNGDK62-Bu5WidAv.js} +1 -1
- package/dist/assets/index-CJppnf0b.css +2 -0
- package/dist/assets/index-DMV3FQgO.js +32 -0
- package/dist/assets/infrastructure-CxityHZF.js +3 -0
- package/dist/assets/mergeServerFields-DL5isEen.js +7 -0
- package/dist/assets/mermaid-GHXKKRXX-BAcku4Xs.js +1 -0
- package/dist/assets/plugin-calendar-DSFbexMB.js +1 -0
- package/dist/assets/plugin-charts-BjUzf65B.js +7 -0
- package/dist/assets/plugin-chatbot-DUla2_T9.js +120 -0
- package/dist/assets/plugin-dashboard-DbPGiGy-.js +5 -0
- package/dist/assets/plugin-form-CcC4fdyJ.js +1 -0
- package/dist/assets/plugin-gantt-CEW8O7uB.js +1 -0
- package/dist/assets/plugin-grid-BiWgglXK.js +6 -0
- package/dist/assets/plugin-kanban-C_GfAMzI.js +1 -0
- package/dist/assets/plugin-map-Bt30Mxn6.js +1 -0
- package/dist/assets/plugin-markdown-tayYSGF3.js +7 -0
- package/dist/assets/plugin-report-qca5M0OZ.js +59 -0
- package/dist/assets/{plugin-timeline-Cj7Vdr5S.js → plugin-timeline-DZoFKL82.js} +1 -1
- package/dist/assets/plugin-view-Ei4BPIYk.js +1 -0
- package/dist/assets/plugins-views-BtLnemvB.js +4 -0
- package/dist/assets/runtime-config-ir5bt3TX.js +1 -0
- package/dist/assets/{src-DkkPzDZy.js → src-DOKKicsm.js} +1 -1
- package/dist/assets/{types-CUTB6-yK.js → types-TLjbGkho.js} +1 -1
- package/dist/assets/ui-components-DeXgqLMc.js +42 -0
- package/dist/assets/{ui-layout-BiOdr9x-.js → ui-layout-CvIgXgRF.js} +1 -1
- package/dist/assets/vendor-charts-DAigH0Ti.js +39 -0
- package/dist/assets/{vendor-dndkit-Ds4hJT77.js → vendor-dndkit-DMFEUxSy.js} +1 -1
- package/dist/assets/{vendor-i18n-D22Ua8-0.js → vendor-i18n-CdF5ccW5.js} +1 -1
- package/dist/assets/{vendor-icons-core-XrvLM9sL.js → vendor-icons-core-C_yMA5lO.js} +1 -1
- package/dist/assets/{vendor-markdown-CW3B88C8.js → vendor-markdown-C9mPywRm.js} +2 -2
- package/dist/assets/vendor-objectstack-B2q1QmZh.js +102 -0
- package/dist/assets/vendor-radix-CSVEhP0L.js +56 -0
- package/dist/assets/vendor-react-DR370ovB.js +11 -0
- package/dist/assets/vendor-sentry-Cv_7Tgs6.js +501 -0
- package/dist/assets/{vendor-ui-utils-CjuGfYLJ.js → vendor-ui-utils-rQOI1gAo.js} +1 -1
- package/dist/index.html +6 -6
- package/package.json +1 -1
- package/dist/assets/AppManagementPage-D8RAo63V.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-ez78SjMT.js +0 -1
- package/dist/assets/DeveloperHubPage-DcJoR8P3.js +0 -1
- package/dist/assets/FlowRunsPage-lx4QRpzF.js +0 -1
- package/dist/assets/PublicFormsPage-Cy_6D1eO.js +0 -1
- package/dist/assets/SettingsView-DPBCFHk1.js +0 -1
- package/dist/assets/SystemHubPage-CJGBoDcK.js +0 -1
- package/dist/assets/data-adapter-_AZenlJe.js +0 -1
- package/dist/assets/index-BN0WVFAv.js +0 -32
- package/dist/assets/index-TbUZx7_1.css +0 -2
- package/dist/assets/infrastructure-ai8_U_pI.js +0 -3
- package/dist/assets/mergeServerFields-B5HoGDzy.js +0 -7
- package/dist/assets/mermaid-GHXKKRXX-DjL587yX.js +0 -1
- package/dist/assets/plugin-calendar-CJzupXd5.js +0 -1
- package/dist/assets/plugin-charts-BEUWAwv7.js +0 -7
- package/dist/assets/plugin-chatbot-Bu4iH5QF.js +0 -120
- package/dist/assets/plugin-dashboard-Cp10Wl4m.js +0 -3
- package/dist/assets/plugin-form-C0Ec8keG.js +0 -1
- package/dist/assets/plugin-gantt-BCNazePX.js +0 -1
- package/dist/assets/plugin-grid-b1qcltrl.js +0 -6
- package/dist/assets/plugin-kanban-DH3H0Wva.js +0 -1
- package/dist/assets/plugin-map-Bq_z3o3E.js +0 -1
- package/dist/assets/plugin-markdown-MGi27oiL.js +0 -7
- package/dist/assets/plugin-report-DSe9lGEO.js +0 -59
- package/dist/assets/plugin-view-DcCK17lP.js +0 -1
- package/dist/assets/plugins-views-BCJT2gzM.js +0 -4
- package/dist/assets/ui-components-BHdgV-R1.js +0 -42
- package/dist/assets/vendor-charts-4buVt82U.js +0 -39
- package/dist/assets/vendor-objectstack-DRFh8zSo.js +0 -96
- package/dist/assets/vendor-radix-Bzf7fki-.js +0 -56
- package/dist/assets/vendor-react-BMpe6Iqg.js +0 -13
- package/dist/assets/vendor-sentry-BreXt3n4.js +0 -501
|
@@ -0,0 +1,32 @@
|
|
|
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,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _,u as v}from"./vendor-react-DR370ovB.js";import{a as y,c as b,d as x,f as S,h as C,i as w,l as T,m as E,n as D,o as O,p as k,r as A,s as j,u as ee}from"./infrastructure-CxityHZF.js";import{$ as te,A as M,B as ne,C as re,F as N,I as ie,L as P,N as F,O as ae,Q as oe,S as se,T as ce,U as le,V as ue,a as de,at as fe,b as pe,d as me,it as he,j as ge,lt as _e,m as ve,mt as I,n as L,o as R,p as ye,r as z,st as B,w as be,x as xe}from"./framework-DoGxClbR.js";import{R as Se,_ as Ce,d as we,f as Te,h as Ee,l as De,m as Oe,p as ke}from"./vendor-objectstack-B2q1QmZh.js";import{$ as Ae,$a as je,$i as Me,$n as Ne,$o as Pe,$r as Fe,$t as Ie,Aa as Le,Ai as Re,An as ze,Ar as Be,As as Ve,At as He,B 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,Ct as et,Da as V,Do as tt,Dr as nt,Ds as rt,Dt as it,E as at,Ea as ot,Ei as st,Eo as ct,Er as lt,Et as ut,F as dt,Fa as ft,Fi as pt,Fn as mt,Fo as ht,Fr as gt,Ft as _t,Gi as vt,Gn as yt,Go as bt,Gt as xt,Ho as St,Hr as Ct,Hs as wt,Ht as Tt,I as Et,Ia as Dt,In as Ot,Io as kt,Ir as At,Is as jt,It as Mt,Ja as Nt,Ji as Pt,Jn as Ft,Jo as It,Jr as Lt,Js as Rt,Ka as zt,Ki as Bt,Kn as Vt,Ko as Ht,Kr as Ut,Ks as Wt,Kt as Gt,L as Kt,La as qt,Li as Jt,Ln as Yt,Lo as Xt,Lr as Zt,Lt as Qt,Ma as $t,Mi as en,Mn as tn,Mo as nn,Mr as rn,Ms as an,Mt as on,N as sn,Na as cn,Ni as ln,Nn as un,No as dn,Nr as fn,Nt as pn,Oa as mn,Oi as hn,On as gn,Oo as _n,Or as vn,Ot as yn,P as bn,Pa as xn,Pn as Sn,Po as Cn,Pr as wn,Ps as Tn,Pt as En,Q as Dn,Qi as On,Qn as H,Qo as kn,Qr as An,Qs as U,Qt as jn,Ra as Mn,Ri as Nn,Rn as Pn,Ro as Fn,Rr as In,Rs as Ln,Rt as Rn,S as zn,Sa as Bn,Si as Vn,So as Hn,Sr as Un,Ss as Wn,St as Gn,Ta as Kn,Tr as qn,Ts as Jn,Tt as Yn,Ua as Xn,Uo as Zn,Ur as Qn,Ut as $n,Va as er,Vi as tr,Vo as nr,Vr as rr,Vs as ir,Vt as ar,Wa as or,Wi as sr,Wo as cr,Ws as lr,Xa as ur,Xi as dr,Xn as fr,Xo as pr,Xr as mr,Xs as hr,Ya as gr,Yi as _r,Yn as vr,Yo as yr,Yr as br,Ys as xr,Z as Sr,Za as Cr,Zi as wr,Zo as Tr,Zr as Er,Zs as Dr,Zt as Or,_ as kr,_a as Ar,_i as jr,_n as Mr,_o as Nr,_r as Pr,_s as Fr,_t as Ir,aa as Lr,ai as Rr,an as zr,ao as Br,ar as Vr,as as Hr,at as Ur,ba as Wr,bi as Gr,bo as Kr,br as qr,bs as Jr,bt as Yr,ca as Xr,ci as Zr,cn as Qr,co as $r,cr as ei,cs as ti,ct as ni,da as ri,di as ii,do as ai,dr as oi,ds as si,ea as ci,ec as li,ei as ui,en as W,eo as di,er as fi,es as pi,et as mi,fa as hi,fi as gi,fo as _i,fr as vi,fs as yi,ft as bi,g as xi,ga as Si,gi as Ci,gn as wi,go as Ti,gr as Ei,gs as Di,gt as Oi,h as ki,ha as Ai,hi as ji,hn as Mi,ho as Ni,hs as Pi,ht as Fi,ii as Ii,in as G,io as Li,is as Ri,it as zi,ja as Bi,ji as Vi,jn as Hi,jo as Ui,jr as Wi,js as Gi,ka as Ki,ki as qi,kn as Ji,ko as Yi,kr as Xi,ks as Zi,kt as Qi,la as $i,li as ea,ln as ta,lo as na,lr as ra,ls as ia,lt as aa,ma as oa,mi as sa,mn as ca,mo as la,mr as K,ms as ua,mt as da,na as fa,no as pa,ns as ma,nt as ha,oa as ga,oi as _a,on as va,oo as ya,or as ba,ot as xa,pa as Sa,pi as Ca,po as wa,ps as Ta,pt as Ea,qa as Da,qi as Oa,qn as ka,qr as Aa,qs as ja,qt as Ma,ra as Na,ri as Pa,ro as Fa,rs as Ia,rt as La,sa as Ra,sn as za,so as Ba,sr as Va,ss as Ha,st as Ua,ta as Wa,ti as Ga,to as Ka,tr as qa,tt as Ja,ua as Ya,ui as Xa,un as Za,uo as Qa,ur as $a,us as eo,ut as to,v as no,va as ro,vi as io,vn as ao,vo as oo,vr as so,vs as co,vt as lo,wa as uo,wi as fo,wo as po,wr as mo,xa as ho,xi as go,xo as _o,xr as vo,xs as yo,xt as bo,y as xo,ya as So,yi as Co,yn as wo,yr as To,ys as Eo,za as Do,zi as Oo,zn as ko,zs as Ao,zt as jo}from"./ui-components-DeXgqLMc.js";import{a as Mo,n as No,o as Po,r as q}from"./vendor-ui-utils-rQOI1gAo.js";import{r as Fo,t as Io}from"./data-adapter-DlR5JXpU.js";import{i as Lo,n as Ro,r as zo,t as Bo}from"./plugin-form-CcC4fdyJ.js";import{a as Vo,c as Ho,i as Uo,n as Wo,o as Go,r as Ko,s as qo,t as Jo}from"./RecentItemsProvider-DiJIrHwK.js";import{n as Yo,r as Xo,t as Zo}from"./ui-layout-CvIgXgRF.js";import{a as Qo,i as $o,n as es,r as ts,t as ns}from"./runtime-config-ir5bt3TX.js";import{c as rs,n as is,o as as,r as os,s as ss}from"./plugins-views-BtLnemvB.js";import{i as cs,r as ls}from"./plugin-grid-BiWgglXK.js";import{a as us,c as ds,i as fs,l as ps,n as ms,o as hs,r as gs,s as _s,t as vs,u as ys}from"./plugin-view-Ei4BPIYk.js";import{C as bs,S as xs,_ as Ss,a as Cs,b as ws,c as J,d as Ts,f as Es,g as Ds,h as Os,i as ks,l as Y,m as As,n as js,o as Ms,p as Ns,r as Ps,s as Fs,t as Is,u as Ls,v as Rs,w as zs,x as Bs,y as Vs}from"./mergeServerFields-DL5isEen.js";import{n as Hs}from"./plugin-dashboard-DbPGiGy-.js";import{d as Us,i as Ws,l as Gs,t as Ks,u as qs}from"./plugin-chatbot-DUla2_T9.js";var X=e(r(),1),Js=e(c(),1),Z=_(),Ys={type:`object-master-detail-form`,objectName:`expense_claim`,mode:`create`,formType:`simple`,title:`New Expense Claim`,submitText:`Create Claim`,fields:[`title`,`applicant`,`department`,`reason`,`currency`,`claim_status`,`payment_status`,`remarks`],details:[{title:`Expense Lines`,childObject:`expense_line`,relationshipField:`expense_claim`,amountField:`amount`,totalField:`total_amount`,columns:[{field:`expense_date`,label:`Date`,type:`date`},{field:`category`,label:`Category`,type:`select`,options:[{label:`Travel & Transport`,value:`travel_transport`},{label:`Lodging`,value:`lodging`},{label:`Meals & Entertainment`,value:`meals_entertainment`},{label:`Office Supplies`,value:`office_supplies`},{label:`Communications`,value:`communications`},{label:`Training & Conference`,value:`training_conference`},{label:`Client / Project`,value:`client_project`},{label:`Other`,value:`other`}]},{field:`description`,label:`Description`,type:`text`},{field:`merchant_vendor`,label:`Merchant`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}]}]},Xs=()=>(0,Z.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,Z.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Dev · Master-Detail Form (ADR-0001)`}),(0,Z.jsx)(ne,{schema:Ys})]}),Zs={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Qs={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},$s=()=>(0,Z.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-8 p-6`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:definition-list`}),(0,Z.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Z.jsx)(ne,{schema:Zs})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:repeater (showcase_category)`}),(0,Z.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Z.jsx)(ne,{schema:Qs})})]})]});function ec({children:e,adapter:t}){let[n,r]=(0,X.useState)(t??null);return(0,X.useEffect)(()=>{if(t){r(t);return}let e=!1;async function n(){try{let t=new Io({baseUrl:``,fetch:E(),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,Z.jsx)(se.Provider,{value:n,children:e})}var tc=300*1e3,nc=[`app`,`view`],rc={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},ic=`objectui:metadata:`;function ac(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var oc=ac();function sc(...e){oc&&console.debug(`[MetadataProvider]`,...e)}function cc(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function lc(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function uc(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function dc(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function fc(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)dc(e)&&r.add(e.object);for(let e of t){if(dc(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 pc(e){if(!e?.length)return e;let t={};for(let n of e){let e=n?.fields;if(!e)continue;let r=Array.isArray(e)?e.map(e=>[e?.name,e]):Object.entries(e);for(let[e,i]of r){let r=i;if(!e||!r?.inlineEdit||r.type!==`master_detail`&&r.type!==`lookup`)continue;let a=r.reference;a&&(t[a]||=[]).push({childObject:n.name,relationshipField:e,inlineMode:Lo(n,r.inlineEdit,{relationshipField:e}),...r.inlineTitle?{title:r.inlineTitle}:{},...Array.isArray(r.inlineColumns)?{columns:r.inlineColumns}:{},...typeof r.inlineAmountField==`string`?{amountField:r.inlineAmountField}:{}})}}return Object.keys(t).length?e.map(e=>{let n=t[e.name];if(!n?.length)return e;let r={...e.form||{type:`simple`}},i=Array.isArray(r.subforms)?r.subforms:[],a=new Set(i.map(e=>e.childObject));r.subforms=[...n.filter(e=>!a.has(e.childObject)),...i];let o={...e,form:r};return e.formViews?.default&&(o.formViews={...e.formViews,default:{...e.formViews.default,subforms:r.subforms}}),o}):e}function mc(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function hc(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(ic+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function gc(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(ic+e,JSON.stringify(t))}catch{}}function _c({children:e,adapter:t,ttlMs:n=tc}){let r=(0,X.useRef)(new Map),i=(0,X.useRef)(new Map),a=(0,X.useRef)(t);a.current=t;let[o,s]=(0,X.useState)(0),c=(0,X.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>s(e=>e+1)):Promise.resolve().then(()=>s(e=>e+1))},[]),l=(0,X.useCallback)(e=>{let t=r.current.get(e);return t||(t=mc(),r.current.set(e,t)),t},[]),u=(0,X.useCallback)(e=>{let t=l(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return sc(`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=cc(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)uc(e)&&t.byName.set(e.name,e);return e===`app`&&gc(e,i),sc(`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,sc(`fetch failed type=${e}`,r),c(),[]});return t.promise=i,i},[c,l,n]),d=(0,X.useCallback)((e,t)=>{let n=l(e);if(n.byName.has(t))return sc(`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=lc(i);return a&&n.byName.set(t,a),sc(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),sc(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,c),c},[l]),f=(0,X.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,X.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),sc(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,sc(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,X.useState)(!0),[g,_]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!1,t=hc(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)uc(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of nc)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,X.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(rc.objects),n=e(`view`);return pc(n.length?fc(t,n):t)},get dashboards(){return e(rc.dashboards)},get reports(){return e(rc.reports)},get pages(){return e(rc.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,Z.jsx)(re.Provider,{value:v,children:e})}var vc=(0,X.createContext)(null);function yc({children:e,user:t={},app:n={},data:r={},features:i={}}){let a=(0,X.useMemo)(()=>({user:t,app:n,data:r,features:i,evaluator:new B({user:t,app:n,data:r,features:i})}),[t,n,r,i]),o=(0,X.useMemo)(()=>({user:t,app:n,data:r,features:i}),[t,n,r,i]);return(0,Z.jsx)(vc.Provider,{value:a,children:(0,Z.jsx)(P,{scope:o,children:e})})}function bc(){let e=(0,X.useContext)(vc);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new B(e)}}return e}function xc(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 Sc({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let c=v(),{appName:l}=s(),{t:u}=z(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=ie({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:a,onToast:o});return(0,X.useEffect)(()=>{h.registerHandler(`create`,async()=>(r?.(null),{success:!0})),h.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(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}}}),h.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),h.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[h,e,n,r,i,c,d,u,t]),{execute:f,create:(0,X.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,X.useCallback)(async e=>f({type:`delete`,confirmText:u(`objectActions.deleteConfirm`),params:{recordId:e}}),[f,u]),navigateToView:(0,X.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,X.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:p,error:m}}var Cc=(0,X.createContext)(void 0);function wc({children:e}){let[t,n]=(0,X.useState)(`home`),[r,i]=(0,X.useState)(),[a,o]=(0,X.useState)(),s=(0,X.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,Z.jsx)(Cc.Provider,{value:s,children:e})}function Tc(){return(0,X.useContext)(Cc)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Ec(e){let{setRecordTitle:t}=Tc();(0,X.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Dc=`objectui-favorites`,Oc=`objectui-nav-pins`,kc=20,Ac=20;function jc(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Ac&&(r=!0)):(t++,t>kc&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Ac&&(i.push(t),o++):a<kc&&(i.push(t),a++);return i}function Mc(e){try{let t=localStorage.getItem(Vo(Dc,e));return t?JSON.parse(t):[]}catch{return[]}}function Nc(e,t){try{localStorage.setItem(Vo(Dc,t),JSON.stringify(e))}catch{}}function Pc(e){let t;try{t=localStorage.getItem(Oc)}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(Oc)}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 Fc=(0,X.createContext)(null);function Ic({children:e}){let{user:t}=S(),n=t?.id??null,r=Ho(`favorites`),[i,a]=(0,X.useState)(()=>Mc(n));(0,X.useEffect)(()=>{a(Mc(n))},[n]),qo(Vo(Dc,n),e=>{a(Array.isArray(e)?jc(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,X.useRef)(0);(0,X.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=jc((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Mc(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=jc([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Pc(f);h&&(f=jc(m),p=!0),a(f),Nc(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,X.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Pc(e);if(!r)return e;let i=jc(t);return Nc(i,n),i})},[r,n]);let s=(0,X.useMemo)(()=>Uo(async e=>{r&&await r.save(e)},500),[r]);(0,X.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,X.useCallback)(e=>{Nc(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,X.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=jc([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),u=(0,X.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),d=(0,X.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):jc([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),f=(0,X.useCallback)(()=>{a([]),c([])},[c]),p=(0,X.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,X.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,X.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,Z.jsx)(Fc.Provider,{value:h,children:e})}function Lc(){return(0,X.useContext)(Fc)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var Rc=(0,X.createContext)({theme:`system`,setTheme:()=>null});function zc({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,X.useState)(()=>localStorage.getItem(n)||t);(0,X.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,Z.jsx)(Rc.Provider,{...r,value:o,children:e})}var Bc=()=>{let e=(0,X.useContext)(Rc);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Vc(){return(0,Z.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Hc({children:e}){return(0,Z.jsx)(zc,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Z.jsx)(wc,{children:(0,Z.jsx)(Ko,{children:(0,Z.jsx)(Ic,{children:(0,Z.jsx)(Jo,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Vc,{}),children:e})})})})})})}function Uc({children:e}){return(0,Z.jsx)(ec,{children:(0,Z.jsx)(Wc,{children:e})})}function Wc({children:e}){let t=be(),{language:n}=z(),r=(0,X.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Z.jsx)(le,{dataSource:t,children:(0,Z.jsxs)(_c,{adapter:t,children:[(0,Z.jsx)(Gc,{}),e]},n)}):(0,Z.jsx)(Vc,{})}function Gc(){let{user:e}=S(),t=be(),n=Go();return(0,X.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=Fo({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Fo({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 Kc({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=S();return r?(0,Z.jsx)(Vc,{}):((n??[]).length>0||t)&&!t?(0,Z.jsx)(i,{to:`/organizations`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function qc(){let e=u(),t=e.pathname.replace(/^\/system/,``);return(0,Z.jsx)(i,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var Jc=null,Yc=0,Xc=0,Zc=null,Qc={editor:Jc,openSeq:Yc,reviewSeq:Xc,reviewTarget:Zc},$c=new Set;function el(){Qc={editor:Jc,openSeq:Yc,reviewSeq:Xc,reviewTarget:Zc};for(let e of $c)e()}function tl(e,t){return e===t?!0:JSON.stringify(e)===JSON.stringify(t)}var nl={subscribe(e){return $c.add(e),()=>{$c.delete(e)}},getSnapshot(){return Qc},setEditor(e){tl(Jc,e)||(Jc=e,el())},requestOpen(){Yc+=1,el()},requestReview(e){Xc+=1,Zc=e,el()}};function rl(){return(0,X.useSyncExternalStore)(nl.subscribe,nl.getSnapshot,nl.getSnapshot)}function il(e){(0,X.useEffect)(()=>(nl.setEditor(e),()=>nl.setEditor(null)),[e?JSON.stringify(e):``])}function al(){nl.requestOpen()}function ol(e){nl.requestReview(e)}var sl=(0,X.lazy)(()=>d(()=>import(`./ConsoleFloatingChatbot-DWHDGm6C.js`),__vite__mapDeps([0]),import.meta.url)),cl=()=>{d(()=>import(`./ConsoleFloatingChatbot-DWHDGm6C.js`),__vite__mapDeps([0]),import.meta.url)};function ll(e){let[t,n]=(0,X.useState)(!1),{t:r}=z(),{openSeq:i}=rl(),a=(0,X.useRef)(i);return(0,X.useEffect)(()=>{i!==a.current&&(a.current=i,n(!0))},[i]),t?(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(sl,{...e,defaultOpen:!0})}):(0,Z.jsx)(`button`,{type:`button`,"aria-label":r(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e.appLabel}),onClick:()=>n(!0),onMouseEnter:cl,onFocus:cl,className:`fixed bottom-20 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 sm:bottom-6`,"data-testid":`console-chatbot-fab`,children:(0,Z.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,Z.jsx)(`path`,{d:`M12 3v3`}),(0,Z.jsx)(`path`,{d:`M12 18v3`}),(0,Z.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,Z.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,Z.jsx)(`path`,{d:`M3 12h3`}),(0,Z.jsx)(`path`,{d:`M18 12h3`}),(0,Z.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,Z.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function ul(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 dl=new Set(Dn),fl=new Map;function pl(e){if(!e)return kt;let t=fl.get(e);if(t)return t;let n=ul(e);if(!dl.has(n))return fl.set(e,kt),kt;let r=e=>X.createElement(Sr,{name:n,fallback:kt,...e});return r.displayName=`LucideIcon(${e})`,fl.set(e,r),r}var ml=20;function hl(e,t=``){let{href:n,external:r}=Yo(e,t);return r?n:!n||n===`#`?``:n}function gl(e){return`nav:${e}`}function _l(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Lc(),a=(0,X.useCallback)((e,i,a,o)=>{let s=gl(e);i?(a&&t({id:s,label:a.label,href:hl(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,X.useCallback)(e=>i.has(e),[i]),s=(0,X.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<ml;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,X.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,X.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}function vl(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 yl(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 bl(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`}}var xl=new Set([`created_by`,`updated_by`,`owner_id`]);function Sl(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function Cl(e,t){if(!e?.name||!Array.isArray(t)||t.length===0)return[];let n=e.name,r=[],i=[],a=new Set;for(let e of t)if(!(!e?.name||e.name===n))for(let[t,o]of Sl(e.fields)){if(!o)continue;let s=o.type;if(s!==`lookup`&&s!==`master_detail`||(o.reference_to||o.reference)!==n||xl.has(t)||o.relatedList===!1||a.has(e.name))continue;a.add(e.name);let c={childObject:e.name,childLabel:e.label||e.name,referenceField:t,isOwned:s===`master_detail`,...typeof o.relatedListTitle==`string`&&o.relatedListTitle?{title:o.relatedListTitle}:{},...Array.isArray(o.relatedListColumns)&&o.relatedListColumns.length>0?{columns:o.relatedListColumns}:{}};(c.isOwned?r:i).push(c);break}return[...r,...i]}function wl(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 Tl(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var El=`\0`,Dl=`[-\\u2013\\u2014|/·,:]`;function Ol(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===``?El:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Dl}\\s*${El}`,`g`),o=RegExp(`${El}\\s*${Dl}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(El,`g`),``).replace(/\s+/g,` `).trim(),i}function kl(e,t){if(e?.titleFormat){let n=Ol(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 Al=`__all__`;function jl(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Ml(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 Nl(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=jl(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 Pl(e){let[t,n]=X.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]);return X.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=Ml(s),l=[],u=new Set;for(let e of c){if(!Nl(e,o))continue;let t=jl(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=jl(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 Fl(e,t,n){let r=Array.isArray(t)?t:[],i=v(),a=u(),o=new URLSearchParams(a.search);X.useEffect(()=>{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})},[e,r,a.pathname,a.search,i]);let s=X.useCallback((t,n)=>{let r=n===Al?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]),c={};for(let t of r){let n=``;try{n=sessionStorage.getItem(`objectui-ctx-${e}-${t.id}`)??``}catch{}c[t.id]=(o.get(`package`)??n)||(t.allValue??``)}return{contextValues:c,element:r.length===0?null:(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Z.jsx)(Il,{def:e,value:c[e.id],onChange:t=>s(e,t),t:n},e.id))})}}function Il({def:e,value:t,onChange:n,t:r}){let i=Pl(e),a=pl(e.icon),o=wl(e.label,r)||e.id,s=o===`Package`?r?.(`common.package`,{defaultValue:o})??o:o,c=r?.(`actionDialog.selectPlaceholder`,{label:s,defaultValue:`Select ${s}…`})??`Select ${s}…`,l=!!t&&t!==(e.allValue??``);return X.useEffect(()=>{l||i.length>0&&n(i[0].value)},[l,n,i]),(0,Z.jsxs)(Rn,{value:l?t:``,onValueChange:n,children:[(0,Z.jsx)(ar,{"aria-label":s,className:`h-9 w-full gap-2 rounded-md border-sidebar-border/70 bg-sidebar/80 px-2 text-xs font-medium text-sidebar-foreground shadow-none transition-colors hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:shrink-0`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,Z.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border border-sidebar-border/70 bg-sidebar-accent text-sidebar-foreground/70`,children:(0,Z.jsx)(a,{className:`h-3 w-3`})}),(0,Z.jsx)(Tt,{placeholder:c,className:`truncate`})]})}),(0,Z.jsx)(jo,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}var Ll=X.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=Yn(),{t:s}=z(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Z.jsxs)(K,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:U(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Z.jsx)(Me,{}),(0,Z.jsx)(`span`,{className:`sr-only`,children:c})]})});Ll.displayName=`LocalizedSidebarTrigger`;function Rl(e){let t=`objectui-nav-order-${e}`,[n,r]=X.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=X.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:X.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:X.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function zl(e){return e.componentRef===`metadata:directory`}function Bl(e){return e.componentRef===`developer:packages`}function Vl(e){if(e.type!==`group`)return!1;let t=String(e.id??``).toLowerCase(),n=typeof e.label==`string`?e.label.toLowerCase():``;return t===`overview`||n===`overview`}function Hl({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=Yn(),r=u(),{t:i}=z(),{objectLabel:a,dashboardLabel:o,navGroupLabel:s,viewLabel:c}=li(),{context:l,currentAppName:d}=Tc(),{user:f}=S();X.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:p}=Wo(),{favorites:m,removeFavorite:g}=Lc(),{apps:_,objects:v}=ce(),y=_||[],b=y.filter(e=>e.active!==!1&&e.hidden!==!0),x=y.find(t=>t.name===(e||d)&&t.active!==!1)||b[0],{applyOrder:C,handleReorder:w}=Rl(x?.name||`home`),{togglePin:T,applyPins:E}=_l(),O=x?.areas||[],[k,A]=X.useState(()=>O.length>0?O[0].id:null);X.useEffect(()=>{O.length>0?A(e=>O.some(t=>t.id===e)?e:O[0].id):A(null)},[x?.name,O.length]);let j=O.find(e=>e.id===k)?.navigation||x?.navigation||[],{contextValues:ee,element:te}=Fl(x?.name||`home`,x?.contextSelectors,i),M=X.useMemo(()=>[{id:`home-dashboard`,label:i(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[i]),ne=l===`home`?M:j,re=l===`app`&&x?`/apps/${x.name}`:``,N=l===`app`&&x?.name===`studio`,ie=X.useMemo(()=>{if(!N)return``;let e=new URLSearchParams(r.search).get(`package`)||ee.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[ee.active_package,N,r.search]),P=X.useMemo(()=>{if(l!==`app`||x?.name!==`studio`)return ne;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(zl(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:Bl(n)?[{...n,type:`url`,label:e,url:`${re}/component/developer/packages${ie}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(ne).flatMap(e=>Vl(e)?e.children??[]:[e])},[x?.name,re,l,ne,ie,i]),F=X.useMemo(()=>E(C(P)),[P,C,E]),[ae,oe]=X.useState(!1),{evaluator:se}=bc(),le=X.useCallback(e=>xc(e,se),[se]),{can:ue}=D(),de=X.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return ue(n,r)}),[ue]),fe=X.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),pe=X.useCallback((e,t)=>e===`object`?fe.size===0?!0:fe.has(t):!0,[fe]),me=N&&r.pathname.replace(/\/+$/,``)===re;return(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(bi,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&l===`app`&&(0,Z.jsx)(lo,{className:`border-b p-1.5`,children:(0,Z.jsx)(Yr,{children:(0,Z.jsx)(et,{children:(0,Z.jsx)(Gn,{asChild:!0,className:`h-9 text-sm font-medium`,children:(0,Z.jsxs)(h,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Z.jsx)(Nt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Z.jsx)(Ea,{className:`pt-2`,children:(0,Z.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:l===`app`&&x?(0,Z.jsxs)(Z.Fragment,{children:[te&&(0,Z.jsx)(Fi,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,Z.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,Z.jsx)(Oi,{children:te})})}),N&&(0,Z.jsx)(Fi,{children:(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:(0,Z.jsx)(et,{children:(0,Z.jsx)(Gn,{asChild:!0,isActive:me,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,Z.jsxs)(h,{to:{pathname:re,search:ie},children:[(0,Z.jsx)(Nt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),O.length>1&&(0,Z.jsxs)(Fi,{children:[(0,Z.jsxs)(Ir,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(qt,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:O.map(e=>{let t=pl(e.icon);return(0,Z.jsx)(et,{children:(0,Z.jsxs)(Gn,{isActive:e.id===k,tooltip:e.label,onClick:()=>A(e.id),children:[(0,Z.jsx)(t,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Z.jsx)(Zo,{items:F,basePath:re,evaluateVisibility:le,checkPermission:de,checkCapability:pe,enablePinning:!t,onPinToggle:T,enableReorder:!t,onReorder:w,resolveObjectLabel:(e,t)=>a({name:e,label:t}),resolveDashboardLabel:(e,t)=>o({name:e,label:t}),resolveGroupLabel:x?(e,t)=>s(x.name,e,t):void 0,resolveItemLabel:x?(e,t)=>x.name===`studio`&&t===i(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:s(x.name,e,t):void 0,resolveViewLabel:(e,t,n)=>c(e,t,n),t:i,templateContext:{currentUserId:f?.id??null,contextValues:ee}}),p.length>0&&(0,Z.jsxs)(Fi,{children:[(0,Z.jsxs)(Ir,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>oe(e=>!e),children:[(0,Z.jsx)(si,{className:`h-3 w-3 transition-transform duration-150 ${ae?`rotate-90`:``}`}),(0,Z.jsx)(Ht,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),ae&&(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:p.slice(0,5).map(e=>(0,Z.jsx)(et,{children:(0,Z.jsx)(Gn,{asChild:!0,tooltip:e.label,children:(0,Z.jsxs)(h,{to:e.href,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),m.some(e=>e.type!==`nav`)&&(0,Z.jsxs)(Fi,{children:[(0,Z.jsxs)(Ir,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Fe,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:m.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Z.jsxs)(et,{children:[(0,Z.jsx)(Gn,{asChild:!0,tooltip:e.label,children:(0,Z.jsxs)(h,{to:e.href,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Z.jsx)(bo,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Z.jsx)(ui,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Fi,{children:(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:M.map(e=>{let t=pl(e.icon),n=r.pathname===e.url;return(0,Z.jsx)(et,{children:(0,Z.jsx)(Gn,{asChild:!0,tooltip:e.label,isActive:n,children:(0,Z.jsxs)(h,{to:e.url||`/home`,children:[(0,Z.jsx)(t,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),m.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Z.jsxs)(Fi,{children:[(0,Z.jsxs)(Ir,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Fe,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Yr,{children:m.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Z.jsxs)(et,{children:[(0,Z.jsx)(Gn,{asChild:!0,tooltip:e.label,children:(0,Z.jsxs)(h,{to:e.href,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Z.jsx)(bo,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Z.jsx)(ui,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Z.jsx)(da,{className:`border-t p-1`,children:(0,Z.jsx)(Ll,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Ul(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,X.useState)(`disconnected`),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)([]),[p,m]=(0,X.useState)(null),h=(0,X.useRef)(null),g=(0,X.useRef)(0),_=(0,X.useRef)(null),v=(0,X.useRef)(new Map),y=(0,X.useRef)([]),b=(0,X.useRef)(!0),x=(0,X.useRef)(!1),S=(0,X.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,X.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,X.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,X.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,X.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,X.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,X.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,X.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 Wl=0;function Gl(){return Wl+=1,`conflict-${Date.now()}-${Wl}`}var Kl=0;function ql(){return Kl+=1,`ver-${Date.now()}-${Kl}`}function Jl(e,t,n){let[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)([]);return{versions:r,currentVersion:(0,X.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,X.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:ql(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,X.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:ql(),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,X.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:ql(),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,X.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:ql(),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,X.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,X.useCallback)(e=>{let t={...e,id:Gl()};o(e=>[...e,t])},[]),clearHistory:(0,X.useCallback)(()=>{i([]),o([])},[])}}var Yl={sm:24,md:32,lg:40},Xl={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Zl(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Ql({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=Yl[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,X.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,X.useMemo)(()=>[...l].reverse(),[l]);return X.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&X.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>X.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?X.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Zl(e.userName),r&&X.createElement(`span`,{style:{...m,backgroundColor:Xl[e.status]}}))))}var $l=X.createContext({});function eu(){let e=X.useContext($l),[t,n]=X.useState([]);return X.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function tu(e,t){let n=X.useContext($l),[r,i]=X.useState([]);return X.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 nu(){let{theme:e,setTheme:t}=Bc(),{t:n}=z();return(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Z.jsx)(mr,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Z.jsx)(ri,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,Z.jsxs)(va,{align:`end`,children:[(0,Z.jsxs)(Qr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Z.jsx)(mr,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Z.jsxs)(Qr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Z.jsx)(ri,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Z.jsxs)(Qr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Z.jsx)(hi,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var ru=[{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 iu(){let{t:e,language:t,changeLanguage:n}=z();return(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Z.jsx)(Ka,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Z.jsx)(va,{align:`end`,className:`max-h-72 overflow-y-auto`,children:ru.map(e=>(0,Z.jsxs)(Qr,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var au={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Hr},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:V},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:V},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:mo},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:mo}};function ou({state:e,className:t}){let n=au[e],{t:r}=z(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(e===`connected`){s(!0);let e=setTimeout(()=>s(!1),2e3);return()=>clearTimeout(e)}s(!1)},[e]),e===`connected`&&!o?null:(0,Z.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:i,children:[(0,Z.jsx)(a,{className:U(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function su(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 cu({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=z(),c=v(),l=s(),{currentAppName:u}=Tc(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(`notifications`),[h,g]=(0,X.useState)(`unread`),_=t+n,y=o(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,X.useRef)(null),[x,S]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=b.current;if(e!==null&&_>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=_},[_]),(0,X.useEffect)(()=>{x||(b.current=_)},[x,_]);let C=()=>{f(!1);let e=u??l.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{f(!1),c(`/apps/setup/sys_inbox_message?view=mine`)},T=()=>{f(!1),c(`/apps/setup/sys_activity`)},E=e=>{a(e.id);let t=u??l.appName;if(e.action_url){f(!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&&(f(!1),c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`))};return(0,Z.jsxs)(Or,{open:d,onOpenChange:f,children:[(0,Z.jsx)(Ie,{asChild:!0,children:(0,Z.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,Z.jsx)(jt,{className:`h-4 w-4`}),_>0&&(0,Z.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:_>9?`9+`:_},_)]})}),(0,Z.jsxs)(jn,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold`,children:o(`sidebar.inbox`,{defaultValue:`Inbox`})}),p===`notifications`&&t>0&&(0,Z.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:o(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Z.jsxs)(mi,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,Z.jsxs)(ha,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Z.jsxs)(La,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(jt,{className:`h-3.5 w-3.5`}),o(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,Z.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,Z.jsxs)(La,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`}),o(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,Z.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,Z.jsxs)(La,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(Dr,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Z.jsxs)(Ja,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[o(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,Z.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:o(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=h===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:h===`unread`?o(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):o(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Z.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:su(e.created_at)})]})]})})},e.id))})})(),(0,Z.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:o(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Z.jsx)(Ja,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,Z.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ii,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,Z.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:o(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Z.jsx)(K,{size:`sm`,className:`mt-3`,onClick:C,children:o(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:o(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Z.jsxs)(Ja,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,Z.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,Z.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,Z.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,Z.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[su(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Z.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:o(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function lu({activeAppName:e,onAppChange:t}){let{apps:n}=ce(),{t:r}=z(),{appLabel:i}=li(),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,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.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,Z.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:wl(s.label,r)})}),(0,Z.jsx)(Ta,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Z.jsxs)(va,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Z.jsx)(ta,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Z.jsx)(Za,{}),o.map(e=>{let n=pl(e.icon),a=i({name:e.name,label:wl(e.label,r)}),o=s.name===e.name;return(0,Z.jsxs)(Qr,{onClick:()=>t(e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,Z.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,Z.jsx)(n,{className:`size-3`})}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,Z.jsx)(ua,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var uu=(0,X.createContext)(null);function du({children:e}){let[t,n]=(0,X.useState)(null),r=(0,X.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Z.jsx)(uu.Provider,{value:r,children:e})}function fu(){return(0,X.useContext)(uu)?.value??null}function pu(e){let t=(0,X.useContext)(uu),n=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function mu(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,X.useRef)(r);o.current=r;let s=(0,X.useCallback)(e=>o.current(e),[]);pu((0,X.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function hu(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function gu(){return(0,Z.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var _u=[];function vu({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:i,activities:a,activeAppName:o,onAppChange:c}){let l=e??(t?`app`:`home`),d=l===`app`,f=u(),p=s(),m=v(),{isOnline:g}=ge(),{user:_,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:C,isOrganizationsLoading:w}=S(),T=be(),{t:E}=z(),{objectLabel:D,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:ee,appLabel:te}=li(),{apps:M,dashboards:ne,pages:re,reports:N}=ce(),{currentAppName:ie,recordTitle:P}=Tc(),F=fu(),[ae,oe]=(0,X.useState)(null),[se,le]=(0,X.useState)([]),ue=(0,X.useRef)(!1),de=(0,X.useRef)(!1),fe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(fe.current=!0,()=>{fe.current=!1}),[]);let pe=(0,X.useRef)(!1),me=(0,X.useRef)(!1),he=(0,X.useRef)(!1),[_e,ve]=(0,X.useState)(0),I=(0,X.useRef)(!1),L=(0,X.useCallback)(async()=>{if(!T||!d)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!ue.current&&!he.current){he.current=!0;try{let t=await T.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(ue.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&oe(e)}}catch{}finally{he.current=!1}}},[T,d]);(0,X.useEffect)(()=>{L()},[L]),(0,X.useEffect)(()=>{if(!T||!d||!_?.id||de.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()=>{if(!pe.current){pe.current=!0;try{let[e,t]=await Promise.all([T.find(`sys_inbox_message`,{$filter:{user_id:_.id},$orderby:{created_at:`desc`},$top:20}),T.find(`sys_notification_receipt`,{$filter:{user_id:_.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!fe.current)return;let i=Array.isArray(e?.data)?e.data:[],o=Array.isArray(t?.data)?t.data:[],s=new Map;for(let e of o){let t=e?.notification_id==null?``:String(e.notification_id);if(!t)continue;let n=s.get(t);(!n||!a.has(n.state)&&a.has(e.state))&&s.set(t,{id:String(e.id),state:String(e.state)})}le(i.map(e=>{let t=e?.notification_id==null?null:String(e.notification_id),n=t?s.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)){de.current=!0;return}r=Math.min(r*2,12e4)}finally{pe.current=!1}}},s=()=>{if(e||de.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,d,_?.id]),(0,X.useEffect)(()=>{if(!d||!_?.id||I.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];_.id&&t.push(_.id),_.email&&t.push(_.email);for(let e of _.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!me.current){me.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){I.current=!0;return}if(!r.ok)return;let i=await r.json().catch(()=>null),a=new Set;for(let e of i?.data||[])a.add(e.id);fe.current&&ve(a.size)}catch{}finally{me.current=!1}}},a=()=>{n||I.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[d,_?.id]);let R=se.reduce((e,t)=>e+ +!t.is_read,0),ye=(0,X.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:_?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[T,_?.id]),B=(0,X.useCallback)(async e=>{let t=se.find(t=>t.id===e);if(le(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await ye(t,new Date().toISOString())}catch{}},[se,ye]),xe=(0,X.useCallback)(async()=>{let e=se.filter(e=>!e.is_read);if(!e.length)return;le(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>ye(e,t).catch(()=>{})))},[se,ye]),Se=eu(),Ce=i??(Se.length>0?Se:_u),we=a??ae??[],Te=w||(x??[]).length>0||!!C,Ee=f.pathname.split(`/`).filter(Boolean),De=p.appName||Ee[1],Oe=Ee[2],ke=`/apps/${De}`,Ae=n??[],je=o||ie||De,Me=(M||[]).find(e=>e.name===je),Pe=new Set,Fe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Pe.add(t.objectName),t.children&&Fe(t.children)};Fe(Me?.navigation||[]);for(let e of Me?.areas||[])Fe(e.navigation||[]);let Ie=(Pe.size>0?Ae.filter(e=>Pe.has(e.name)):Ae.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:D(e),href:`${ke}/${e.name}`})),Le=[];if(d){if(Oe===`dashboard`){if(Le.push({label:E(`console.breadcrumb.dashboards`),href:ke}),Ee[3]){let e=Ee[3],t=(ne||[]).find(t=>t.name===e)?.label||hu(e);Le.push({label:k({name:e,label:t})})}}else if(Oe===`page`){if(Le.push({label:E(`console.breadcrumb.pages`),href:ke}),Ee[3]){let e=Ee[3],t=(re||[]).find(t=>t.name===e)?.label||hu(e);Le.push({label:A({name:e,label:t})})}}else if(Oe===`report`){if(Le.push({label:E(`console.breadcrumb.reports`),href:ke}),Ee[3]){let e=Ee[3],t=(N||[]).find(t=>t.name===e)?.label||hu(e);Le.push({label:j({name:e,label:t})})}}else if(Oe===`system`)Le.push({label:E(`console.breadcrumb.system`)}),Ee[3]&&Le.push({label:hu(Ee[3])});else if(Oe){let e=Ae.find(e=>e.name===Oe);if(e){if(Le.push({label:D(e),href:`${ke}/${Oe}`,siblings:Ie}),Ee[3]===`record`&&Ee[4]){let e=Ee[4].length>12?`${Ee[4].slice(0,8)}…`:Ee[4],t=P?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Le.push({label:n||`#${e}`})}else if(Ee[3]===`view`&&Ee[4]){let t=Ee[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||hu(t),i=ee(e.name,t,r);Le.push({label:i})}}}}let Re=Le[Le.length-1]?.label||t||``;return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,Z.jsx)(h,{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`,d&&`hidden sm:flex`),title:es(),children:(0,Z.jsx)(qt,{className:`h-4 w-4`})}),l===`home`&&(0,Z.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:es()}),l===`orgs`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(gu,{}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:E(`organizations.title`,{defaultValue:`Organizations`})})]}),d&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ll,{className:`lg:hidden shrink-0 ml-1`,"aria-label":E(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),o&&c?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Z.jsx)(gu,{})}),(0,Z.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Z.jsx)(lu,{activeAppName:o,onAppChange:c})})]}):t?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Z.jsx)(gu,{})}),(0,Z.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Le.map((e,t)=>{let n=t===Le.length-1;return(0,Z.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Z.jsx)(gu,{}),e.siblings&&e.siblings.length>1?(0,Z.jsxs)(zr,{children:[(0,Z.jsxs)(ca,{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,Z.jsx)(Ta,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Z.jsxs)(va,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Z.jsx)(ta,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Z.jsx)(Za,{}),e.siblings.map(e=>(0,Z.jsx)(Qr,{asChild:!0,children:(0,Z.jsx)(h,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Z.jsx)(h,{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,Z.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),F&&F.views.length>0?F.views.length>1?(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.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":E(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Z.jsx)(`span`,{className:`truncate max-w-[180px]`,children:F.triggerLabel??F.views.find(e=>e.id===F.activeViewId)?.label??Re}),(0,Z.jsx)(Ta,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Z.jsx)(va,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:F.views.map(e=>{let t=e.id===F.activeViewId;return(0,Z.jsxs)(Qr,{onSelect:()=>{t||F.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,Z.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,Z.jsx)(ot,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Z.jsx)(ua,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,Z.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:F.triggerLabel??F.views[0].label}):(0,Z.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Re})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!g&&(0,Z.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,Z.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),E(`topbar.offline`,{defaultValue:`Offline`})]}),d&&r&&(0,Z.jsx)(ou,{state:r}),d&&Ce.length>0&&(0,Z.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:E(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Z.jsx)(Ql,{users:Ce,size:`sm`,maxVisible:3,showStatus:!0})}),(0,Z.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,Z.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,Z.jsx)(Co,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:E(`console.search`,{defaultValue:`Search…`})}),(0,Z.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,Z.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,Z.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,Z.jsx)(Co,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,Z.jsx)(cu,{notifications:se,unreadCount:R,pendingApprovalsCount:_e,activities:we,onMarkAllRead:xe,onMarkRead:B}),(0,Z.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,Z.jsx)(h,{to:`/ai`,children:(0,Z.jsx)(an,{className:`h-4 w-4`})})}),(0,Z.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,Z.jsx)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsx)(pi,{className:`h-4 w-4`})})})]}),(0,Z.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Z.jsxs)(Ne,{className:`h-7 w-7 rounded-full`,children:[(0,Z.jsx)(qa,{src:_?.image,alt:_?.name??`User`}),(0,Z.jsx)(fi,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:O(_)})]})})}),(0,Z.jsxs)(va,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Z.jsx)(ta,{className:`p-0 font-normal`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Z.jsxs)(Ne,{className:`h-8 w-8 rounded-lg`,children:[(0,Z.jsx)(qa,{src:_?.image,alt:_?.name??`User`}),(0,Z.jsx)(fi,{className:`rounded-lg bg-primary text-primary-foreground`,children:O(_)})]}),(0,Z.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Z.jsx)(`span`,{className:`truncate font-semibold`,children:_?.name??`User`}),(0,Z.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:_?.email??``})]})]})}),(0,Z.jsx)(Za,{}),(0,Z.jsxs)(za,{children:[(0,Z.jsxs)(Qr,{onClick:()=>m(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Z.jsx)(Xi,{className:`mr-2 h-4 w-4`}),E(`user.profile`,{defaultValue:`Profile`})]}),Te&&(0,Z.jsxs)(Qr,{onClick:()=>m(`/organizations`),className:`cursor-pointer`,children:[(0,Z.jsx)(Ve,{className:`mr-2 h-4 w-4`}),E(`organizations.mine`,{defaultValue:`My Organizations`})]}),(M||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=pl(e.icon),n=te({name:e.name,label:wl(e.label,E)});return(0,Z.jsxs)(Qr,{onClick:()=>m(`/apps/${e.name}`),className:`cursor-pointer`,children:[(0,Z.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,Z.jsx)(Za,{}),(0,Z.jsx)(ta,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:E(`user.preferences`,{defaultValue:`Preferences`})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-foreground/80`,children:E(`user.theme`,{defaultValue:`Theme`})}),(0,Z.jsx)(nu,{})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-foreground/80`,children:E(`user.language`,{defaultValue:`Language`})}),(0,Z.jsx)(iu,{})]}),b&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Za,{}),(0,Z.jsxs)(Qr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Z.jsx)(Kn,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var yu=768,bu=1024;function xu(){let{setOpen:e,isMobile:t}=Yn(),n=(0,X.useRef)(e);(0,X.useEffect)(()=>{n.current=e},[e]),(0,X.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=yu&&t<bu;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function Su({children:e}){return xu(),(0,Z.jsx)(Z.Fragment,{children:e})}function Cu({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=wl(n?.label)||t,{isAiEnabled:c}=F(),l=c||!1,u=$o().features.aiStudio===!1&&n?.defaultAgent===`metadata_assistant`?void 0:n?.defaultAgent,{setContext:d,setCurrentAppName:f}=Tc();return(0,X.useEffect)(()=>{d(`app`),f(t)},[d,f,t]),(0,Z.jsx)(du,{children:(0,Z.jsxs)(Xo,{sidebar:(0,Z.jsx)(Hl,{activeAppName:t,onAppChange:r}),navbar:(0,Z.jsx)(vu,{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?`${wl(n.label)} — ${es()}`:void 0}:void 0,children:[(0,Z.jsx)(Su,{children:e}),l&&(0,Z.jsx)(ll,{appLabel:s,appName:t,defaultAgent:u,objects:i,userId:o})]})})}function wu({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,Z.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,Z.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function Tu({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let[a,o]=(0,X.useState)(!1),[c,l]=(0,X.useState)(``),u=v(),{appName:d}=s(),{setTheme:f}=Bc(),{evaluator:p}=bc(),{t:m}=z();(0,X.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,X.useEffect)(()=>{a||l(``)},[a]);let h=`/apps/${d||t?.name}`,{user:g}=S(),_=(0,X.useMemo)(()=>({currentUserId:g?.id??null}),[g?.id]),y=(0,X.useCallback)(e=>{o(!1),e()},[]),b=Eu(t?.navigation||[]).filter(e=>xc(e.visible??e.visibleOn,p)),{results:x,isSearching:C}=pe({query:c,objects:n,dataSource:i,objectNames:(0,X.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:kl}),{recentItems:w}=Wo(),T=(0,X.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=a&&c.trim().length===0&&T.length>0;return(0,Z.jsxs)(gn,{open:a,onOpenChange:o,children:[(0,Z.jsx)(Hi,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Z.jsxs)(un,{children:[(0,Z.jsx)(Ji,{children:C?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`}),m(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):m(`console.commandPalette.noResults`)}),E&&(0,Z.jsx)(ze,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Z.jsxs)(tn,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Z.jsx)(Co,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),x.length>0&&(0,Z.jsx)(ze,{heading:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[m(`console.commandPalette.records`,{defaultValue:`Records`}),C&&(0,Z.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=pl(e.icon);return(0,Z.jsxs)(tn,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>y(()=>u(`${h}/${e.objectName}/record/${e.recordId}`)),children:[(0,Z.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.display}),(0,Z.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,Z.jsx)(ze,{heading:m(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=pl(e.icon);return(0,Z.jsxs)(tn,{value:`object ${wl(e.label,m)} ${e.objectName}`,onSelect:()=>y(()=>u(Yo(e,h,_).href)),children:[(0,Z.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:wl(e.label,m)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Z.jsx)(ze,{heading:m(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Z.jsxs)(tn,{value:`dashboard ${wl(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Yo(e,h,_).href)),children:[(0,Z.jsx)(Dt,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:wl(e.label,m)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Z.jsx)(ze,{heading:m(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Z.jsxs)(tn,{value:`page ${wl(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(Yo(e,h,_).href)),children:[(0,Z.jsx)(oo,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:wl(e.label,m)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Z.jsx)(ze,{heading:m(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Z.jsxs)(tn,{value:`report ${wl(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(Yo(e,h,_).href)),children:[(0,Z.jsx)(yo,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:wl(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Sn,{}),(0,Z.jsx)(ze,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=pl(e.icon);return(0,Z.jsxs)(tn,{value:`app ${wl(e.label,m)} ${e.name}`,onSelect:()=>y(()=>r(e.name)),children:[(0,Z.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:wl(e.label,m)}),e.name===t?.name&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:m(`console.commandPalette.current`)})]},e.name)})})]}),(0,Z.jsx)(Sn,{}),(0,Z.jsxs)(ze,{heading:m(`console.commandPalette.preferences`),children:[(0,Z.jsxs)(tn,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,Z.jsx)(mr,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,Z.jsxs)(tn,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,Z.jsx)(ri,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,Z.jsxs)(tn,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,Z.jsx)(hi,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,Z.jsx)(Sn,{}),(0,Z.jsxs)(ze,{heading:m(`console.commandPalette.actions`),children:[(0,Z.jsxs)(tn,{value:`create new app application`,onSelect:()=>y(()=>u(`${h}/create-app`)),children:[(0,Z.jsx)(Oo,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.createApp`)})]}),(0,Z.jsxs)(tn,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,Z.jsx)(Co,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})]})]})]})}function Eu(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Eu(n.children)):t.push(n);return t}function Du(){let{t:e}=z(),[t,n]=(0,X.useState)(!1),r=(0,X.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,X.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,Z.jsx)(mt,{open:t,onOpenChange:n,children:(0,Z.jsxs)(Ot,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:e(`console.shortcuts.title`)}),(0,Z.jsx)(Yt,{children:e(`console.shortcuts.description`)})]}),(0,Z.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Z.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 Ou(){return null}function ku(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?de.console:R.console}function Au({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,X.useState)(0),o=ku(),s=(0,X.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,X.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,s.length-1))},1200);return()=>clearInterval(n)},[e,t,s.length]),(0,Z.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,Z.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,Z.jsx)(kt,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,Z.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:es()}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.initializing})]}),t?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,Z.jsx)(Ha,{className:`h-5 w-5 shrink-0`}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,Z.jsx)(K,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Vi,{className:`h-4 w-4`}),o.actions.retry]})})]}):e?(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,Z.jsx)(sn,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:s.map((e,t)=>(0,Z.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,Z.jsx)(Hr,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Z.jsx)(V,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,Z.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,Z.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}function ju(e){let{theme:t=`system`}=Bc(),{t:n}=z();return(0,Z.jsx)(No,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,containerAriaLabel:n(`notifications.regionLabel`,{defaultValue:`Notifications`}),icons:{success:(0,Z.jsx)(Hr,{className:`h-4 w-4`}),info:(0,Z.jsx)(Xn,{className:`h-4 w-4`}),warning:(0,Z.jsx)(gt,{className:`h-4 w-4`}),error:(0,Z.jsx)(ga,{className:`h-4 w-4`}),loading:(0,Z.jsx)(V,{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 Mu=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Nu({children:e,className:t}){let n=u(),r=X.useRef(null),i=X.useRef(n.pathname);return X.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...Mu),e.offsetWidth,e.classList.add(...Mu))},[n.pathname]),(0,Z.jsx)(`div`,{ref:r,className:[...Mu,t??``].filter(Boolean).join(` `),children:e})}var Pu=null,Fu=null;function Iu(){return Fu||(Fu=(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 d(()=>import(`./vendor-sentry-Cv_7Tgs6.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=Ru(e.data.url)),e}}),Pu=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Fu)}function Lu(e,t){if(Pu)try{Pu.captureException(e,t?{extra:t}:void 0)}catch{}}function Ru(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 zu({error:e,onReset:t}){let{t:n}=z();return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,Z.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,Z.jsx)(gt,{className:`h-6 w-6 text-destructive`})}),(0,Z.jsx)(Ue,{children:n(`console.errors.somethingWentWrong`)}),(0,Z.jsx)(Kt,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Z.jsx)(st,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Z.jsx)(Nt,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Bu=class extends X.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),Lu(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,Z.jsx)(zu,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function Vu({sections:e,open:t}){if(!t)return null;let{t:n}=z(),[r,i]=(0,X.useState)([`0`]),[a,o]=(0,X.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,Z.jsxs)(`div`,{className:`w-80 border-l bg-background p-0 overflow-hidden flex flex-col shrink-0 z-20 transition-all`,children:[(0,Z.jsxs)(`div`,{className:`px-4 py-3 border-b bg-muted/5 flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:n(`layout.metadata.panelTitle`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60`,children:n(`layout.metadata.jsonBadge`)})]}),(0,Z.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,Z.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 hover:bg-muted/5 transition-colors`,children:[(0,Z.jsxs)(`button`,{onClick:()=>c(i),className:`flex-1 flex items-center justify-between text-left`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:e.title}),o?(0,Z.jsx)(Ta,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Z.jsx)(si,{className:`h-3 w-3 text-muted-foreground ml-2`})]}),(0,Z.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,Z.jsx)(ua,{className:`h-3 w-3 text-green-600`}):(0,Z.jsx)(Ke,{className:`h-3 w-3 text-muted-foreground`})})]}),o&&(0,Z.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Z.jsx)(`div`,{className:`relative rounded-md border border-border/50 bg-muted/5 overflow-hidden`,children:(0,Z.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 Hu(){let[e,t]=(0,X.useState)((0,X.useMemo)(()=>{try{return typeof window<`u`?oe(window.location.search).enabled:!1}catch{return!1}},[]));return{showDebug:e,toggleDebug:()=>t(e=>!e)}}function Uu(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 Wu(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 Gu(e,t){return e.entries.findIndex(e=>e.name===t)}function Ku(e,t,n){let r={type:t,label:n??qu(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function qu(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function Ju(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 Yu(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:``})).filter(e=>e.key):[]}function Xu(e,t){let n=/[a-z0-9]/i.test(e)?Ju(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function Zu(e,t){let n=t.trim()||`New section`,r=Xu(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function Qu(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function $u(e,t){return e.filter(e=>e.key!==t)}function ed(e,t,n){let r=e.findIndex(e=>e.key===t);if(r<0)return e;let i=r+n;return i<0||i>=e.length?e:nd(e,r,i)}function td(e,t){return{shape:e.shape,entries:e.entries.map(e=>e.def.group===t?{name:e.name,def:{...e.def,group:void 0}}:e)}}function nd(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function rd(e,t,n){let r=Array.isArray(t)?t.filter(e=>typeof e?.key==`string`):[],i=new Map;for(let e of r)i.set(e.key,{key:e.key,label:String(e.label??e.key),entries:[]});let a=new Set(r.map(e=>e.key));for(let t of e.entries){let e=typeof t.def.group==`string`?t.def.group:null;e&&a.has(e)?i.get(e).entries.push(t):(i.has(null)||i.set(null,{key:null,label:`Ungrouped`,entries:[]}),i.get(null).entries.push(t))}let o=!!n?.includeEmptyDeclared;return Array.from(i.values()).filter(e=>e.entries.length>0||o&&e.key!==null)}function id(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function ad(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)id(e[i],t[i])||r.push(i);return r.sort()}function od(e,t){let n=Uu(e),r=Uu(t),i=new Map(n.entries.map(e=>[e.name,e])),a=new Set(r.entries.map(e=>e.name)),o={},s=0,c=0;for(let e of r.entries){let t=i.get(e.name);if(!t){o[e.name]={name:e.name,status:`added`,changedKeys:[]},s+=1;continue}let n=ad(t.def,e.def);n.length?(o[e.name]={name:e.name,status:`changed`,changedKeys:n},c+=1):o[e.name]={name:e.name,status:`unchanged`,changedKeys:[]}}let l=n.entries.filter(e=>!a.has(e.name));return{byName:o,removed:l,counts:{added:s,changed:c,removed:l.length}}}function sd(e,t){let n=ks(),[r,i]=X.useState({fields:[],loading:!t&&!!e,error:null});return X.useEffect(()=>{if(t){i({fields:t,loading:!1,error:null});return}if(!e){i({fields:[],loading:!1,error:null});return}let r=!1;return i(e=>({...e,loading:!0,error:null})),n.get(`object`,e).then(e=>{if(!r){if(!e){i({fields:[],loading:!1,error:`Object not found`});return}i({fields:Uu(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`&&e.def.label?e.def.label:e.name,type:typeof e.def.type==`string`?e.def.type:`text`,hidden:e.def.hidden===!0})),loading:!1,error:null})}}).catch(e=>{r||i({fields:[],loading:!1,error:e?.message??String(e)})}),()=>{r=!0}},[n,e,t]),r}var cd=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),ld={text:cd(`text`,`Text`,`单行文本`,`text`,wn),textarea:cd(`textarea`,`Text Area`,`多行文本`,`text`,Qn),email:cd(`email`,`Email`,`邮箱`,`text`,Ao),url:cd(`url`,`URL`,`网址`,`text`,Ka),phone:cd(`phone`,`Phone`,`电话`,`text`,sr),password:cd(`password`,`Password`,`密码`,`text`,ot),markdown:cd(`markdown`,`Markdown`,`Markdown`,`text`,oo),html:cd(`html`,`HTML`,`HTML`,`text`,Zn),richtext:cd(`richtext`,`Rich Text`,`富文本`,`text`,_a),number:cd(`number`,`Number`,`数字`,`number`,ur),currency:cd(`currency`,`Currency`,`货币`,`number`,Cn),percent:cd(`percent`,`Percent`,`百分比`,`number`,vt),date:cd(`date`,`Date`,`日期`,`date`,$e),datetime:cd(`datetime`,`Date/Time`,`日期时间`,`date`,$e),time:cd(`time`,`Time`,`时间`,`date`,Ht),boolean:cd(`boolean`,`Checkbox`,`复选框`,`logic`,Ii),toggle:cd(`toggle`,`Toggle`,`开关`,`logic`,qe),select:cd(`select`,`Picklist`,`下拉选择`,`selection`,Ki),multiselect:cd(`multiselect`,`Multi-Select`,`多选`,`selection`,Bi),radio:cd(`radio`,`Radio`,`单选`,`selection`,Ri),checkboxes:cd(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Bi),lookup:cd(`lookup`,`Lookup`,`查找关系`,`relation`,$t),master_detail:cd(`master_detail`,`Master-Detail`,`主从关系`,`relation`,Qe),tree:cd(`tree`,`Tree`,`树形关系`,`relation`,Ra),image:cd(`image`,`Image`,`图片`,`media`,zt),file:cd(`file`,`File`,`文件`,`media`,Pt),avatar:cd(`avatar`,`Avatar`,`头像`,`media`,kn),video:cd(`video`,`Video`,`视频`,`media`,lt),audio:cd(`audio`,`Audio`,`音频`,`media`,Xr),formula:cd(`formula`,`Formula`,`公式`,`calculated`,Jn),summary:cd(`summary`,`Rollup`,`汇总`,`calculated`,Xa),autonumber:cd(`autonumber`,`Auto Number`,`自动编号`,`calculated`,ur),composite:cd(`composite`,`Composite`,`复合字段`,`advanced`,Ve),repeater:cd(`repeater`,`Repeater`,`重复字段`,`advanced`,qi),location:cd(`location`,`Location`,`地理坐标`,`advanced`,Bn),address:cd(`address`,`Address`,`地址`,`advanced`,ho),code:cd(`code`,`Code`,`代码`,`advanced`,Zn),json:cd(`json`,`JSON`,`JSON`,`advanced`,po),color:cd(`color`,`Color`,`颜色`,`advanced`,Na),rating:cd(`rating`,`Rating`,`评分`,`advanced`,Fe),slider:cd(`slider`,`Slider`,`滑块`,`advanced`,Zr),signature:cd(`signature`,`Signature`,`签名`,`advanced`,Oa),qrcode:cd(`qrcode`,`QR Code`,`二维码`,`advanced`,pt),progress:cd(`progress`,`Progress`,`进度条`,`advanced`,yo),tags:cd(`tags`,`Tags`,`标签`,`advanced`,Ut),vector:cd(`vector`,`Vector`,`向量`,`advanced`,Ln)},ud=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],dd={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},fd={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 pd(e){return fd[gd(e).category]}var md={text:`文本`,number:`数值`,date:`日期/时间`,logic:`逻辑`,selection:`选择`,relation:`关系`,media:`媒体`,calculated:`计算`,advanced:`高级`},hd=ud.map(e=>({category:e,types:Object.keys(ld).filter(t=>ld[t].category===e)}));function gd(e){return typeof e==`string`&&e in ld?ld[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:wn}}var _d=`text/x-objectui-viewcol`;function vd({type:e}){let t=gd(e),n=pd(e),r=t.Icon;return(0,Z.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function yd({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,Z.jsxs)(`div`,{className:`relative`,children:[s&&(0,Z.jsx)(`span`,{className:`pointer-events-none absolute -top-0.5 left-0 right-0 h-0.5 rounded bg-primary`}),(0,Z.jsxs)(`div`,{role:`button`,tabIndex:0,draggable:a,"aria-pressed":i,onDragStart:t=>{a&&(t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(_d,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(_d)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(_d)&&(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,Z.jsx)(je,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,Z.jsx)(vd,{type:r}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:t}),n&&n!==t&&(0,Z.jsx)(`code`,{className:`max-w-[7rem] shrink-0 truncate text-[10px] text-muted-foreground`,children:n}),a&&(0,Z.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,Z.jsx)(vo,{className:`h-3 w-3`})})]})]})}function bd({fields:e,usedNames:t,loading:n,error:r,onAdd:i}){let a=X.useMemo(()=>Fs(),[]),[o,s]=X.useState(!1),[c,l]=X.useState(``),u=X.useMemo(()=>{let t=c.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)):e},[e,c]);return(0,Z.jsxs)(Or,{open:o,onOpenChange:s,children:[(0,Z.jsx)(Ie,{asChild:!0,children:(0,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),` `,J(`engine.form.addFieldPlain`,a)]})}),(0,Z.jsxs)(jn,{align:`start`,className:`w-72 p-0`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,Z.jsx)(Co,{className:`pointer-events-none absolute left-4 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),placeholder:J(`engine.form.searchFields`,a),className:`h-8 w-full rounded border border-input bg-background pl-7 pr-2 text-xs outline-none focus:border-primary`})]}),(0,Z.jsx)(`div`,{className:`max-h-72 overflow-auto p-1`,children:n?(0,Z.jsx)(xd,{children:J(`engine.form.loadingFields`,a)}):r?(0,Z.jsx)(xd,{tone:`warn`,children:Y(`engine.form.noObjectFields`,a,{error:r})}):u.length===0?(0,Z.jsx)(xd,{children:J(c?`engine.form.noMatchingFields`:`engine.form.noFieldsOnObject`,a)}):u.map(e=>{let n=t.has(e.name);return(0,Z.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,Z.jsx)(vd,{type:e.type}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label}),e.name!==e.label&&(0,Z.jsx)(`code`,{className:`max-w-[6rem] truncate text-[10px] text-muted-foreground`,children:e.name}),n&&(0,Z.jsx)(H,{variant:`secondary`,className:`px-1 py-0 text-[9px]`,children:J(`engine.form.added`,a)})]},e.name)})})]})]})}function xd({children:e,tone:t}){return(0,Z.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 Sd(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 Cd(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 wd(e){let t=new Set;for(let n of e){let e=Cd(n);e&&t.add(e)}return t}function Td(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Ed(e,t){return e===t?null:e>t?e-1:e}function Dd(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Od({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=sd(i||void 0,a),m=X.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=X.useState(null),[_,v]=X.useState(null),y=X.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=X.useCallback(t=>{let i=Bs(n,Td(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),x=X.useCallback(t=>{let r=bs(n,t,null);if(y(r),o!=null){let n=Ed(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Sd(r[n],n)})}},[n,y,o,e,l]),S=X.useCallback((t,r)=>{if(t===r)return;let i=xs(n,t,r);if(y(i),o!=null){let n=Dd(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Sd(i[n],n)})}},[n,y,o,e,l]),C=X.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Sd(n[t],t)})},[n,e,l]),w=wd(n);return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,Z.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,Z.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Z.jsx)(yd,{index:t,label:Sd(e,t),fieldName:Cd(e),fieldType:m.get(Cd(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>C(t),onRemove:()=>x(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&S(h,t),g(null),v(null)}},t))}),u&&(0,Z.jsx)(bd,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var kd={io:`input`,unrepresentable:`any`},Ad=new Set([`columns`,`data`,`name`]),jd,Md=!1;function Nd(){if(jd||Md)return jd;try{jd=Se(ke,kd)}catch(e){Md=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return jd}function Pd(){return Nd()?.properties?.list}function Fd(){return Nd()?.properties?.form}var Id,Ld=!1;function Rd(){if(Id||Ld)return Id;try{Id=Se(we,kd)}catch(e){Ld=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Id}var zd;function Bd(){if(zd)return zd;if(!(!Ce||typeof Ce!=`object`)){try{let e=JSON.parse(JSON.stringify(Ce));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Ad.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),zd=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return zd}}var Vd=new Set([`form`,`detail`]);function Hd(e){return Vd.has(e)}function Ud(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Wd(e,t){return typeof e==`string`&&Vd.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Vd.has(t)?`form`:`list`}function Gd(e){let t=e.config;return Ud(t)?[{storeKey:`config`,familyKey:Wd(e.viewKind,t.type),schema:t}]:[]}function Kd(e){return Gd(e)[0]}function qd(e,t){return Kd(e)}var Jd=new Set([`type`,`object`,`label`,`columns`]),Yd={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function Xd(e,t){let n=`engine.inspector.view.type.${e}`,r=J(n,t);return r===n?Yd[e]??e:r}var Zd=[`columns`,`data`,`name`];function Qd(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 $d(e,t){return X.useMemo(()=>{let n=Pd()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:Xd(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:Xd(e,t)}),r},[e,t])}function ef({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=Hd(n??t),p=typeof d.type==`string`?d.type:`grid`,m=$d(p,l),h=Qd(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=sd(h.value||void 0,c),b=X.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),x=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:S,form:C}=X.useMemo(()=>Is({bundledSchema:f?Fd():Pd(),bundledForm:f?void 0:Bd(),serverSchema:x,excludeFields:Jd,sectionTitle:J(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:J(`engine.inspector.view.close`,l),hideClose:r,children:[(0,Z.jsx)(ws,{label:J(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:J(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,Z.jsx)(Rs,{label:J(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,Z.jsx)(ws,{label:J(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:J(`engine.inspector.view.objectPlaceholder`,l),disabled:a,mono:!0}),!f&&(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:(0,Z.jsx)(Od,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:S?(0,Z.jsx)(Ms,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of Zd)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.view.noSchema`,l)})})]})}function tf(e){if(!e||typeof e!=`object`)return null;let t=e;if(`item`in t){let e=t.item;return!e||typeof e!=`object`?null:Object.keys(e).length>0?e:null}return Object.keys(t).length>0?t:null}async function nf(e,t,n,r){await r.metadataClient.save(e,t,n,{mode:`draft`})}async function rf(e,t,n,r){return await r.metadataClient.save(e,t,n,{mode:`draft`}),t}async function af(e,t,n){return tf(await n.metadataClient.get(e,t,{state:`draft`}))}async function of(e,t,n){await n.metadataClient.reset(e,t,{state:`draft`})}async function sf(e,t,n){await n.metadataClient.publish(e,t)}function cf({type:e,name:t,metadataClient:n,dirty:r,onResume:i,onAfterChange:a,savedSignal:o}){let s=Fs(),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),f=(0,X.useRef)(null),p=(0,X.useCallback)(async()=>{if(!t||!n){l(!1);return}let r;try{r=await af(e,t,{metadataClient:n})}catch{l(!1);return}if(l(!!r),r&&i&&f.current!==t){f.current=t;try{i(r)}catch(e){console.error(`[RuntimeDraftBar] Resume draft failed:`,e)}}},[e,t,n,i]);(0,X.useEffect)(()=>{p()},[p]);let m=(0,X.useRef)(o);(0,X.useEffect)(()=>{o!==m.current&&(m.current=o,o&&l(!0))},[o]);let h=(0,X.useCallback)(async()=>{if(t){d(!0);try{await sf(e,t,{metadataClient:n}),l(!1),a?.()}catch(e){console.error(`[RuntimeDraftBar] Publish failed:`,e)}finally{d(!1)}}},[e,t,n,a]),g=(0,X.useCallback)(async()=>{if(t&&!(typeof confirm==`function`&&!confirm(Y(`engine.edit.discardDraftConfirm`,s,{type:e,name:t})))){d(!0);try{await of(e,t,{metadataClient:n}),l(!1),a?.()}catch(e){console.error(`[RuntimeDraftBar] Discard draft failed:`,e)}finally{d(!1)}}},[e,t,n,a,s]);return c?(0,Z.jsxs)(`div`,{className:`mr-auto flex items-center gap-2`,"data-testid":`runtime-draft-bar`,children:[(0,Z.jsxs)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,title:J(`engine.edit.draftPending`,s),"data-testid":`runtime-draft-indicator`,children:[`● `,J(`engine.edit.draftPending`,s)]}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:g,disabled:u,className:`h-7 w-7 p-0 text-muted-foreground`,title:J(`engine.edit.discardDraft`,s),"aria-label":J(`engine.edit.discardDraft`,s),"data-testid":`runtime-draft-discard`,children:(0,Z.jsx)(fn,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{size:`sm`,onClick:h,disabled:u||r,className:`h-7 px-2 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:J(r?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,s),"data-testid":`runtime-draft-publish`,children:u?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(io,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.edit.publish`,s)]})})]}):null}var lf=new Set([`form`,`detail`]);function uf(e){return typeof e==`string`&&lf.has(e)}function df(e,t){let n=e.type||`grid`,r=uf(n)?`form`:`list`,i=e.label,a=e.data&&typeof e.data==`object`?e.data:void 0;return{name:e.id,object:t,viewKind:r,label:i,config:{...e,type:n,label:i,columns:Array.isArray(e.columns)?e.columns:[],data:{...a,object:t}}}}function ff(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function pf(e){let t=e.fields;return!t||typeof t!=`object`?[]:Object.entries(t).map(([e,t])=>{let n=t??{};return{name:e,label:typeof n.label==`string`&&n.label?n.label:e,type:typeof n.type==`string`?n.type:`text`,hidden:n.hidden===!0}})}function mf({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=z(),d=(0,X.useRef)(null),f=(0,X.useMemo)(()=>Fs(),[]),[p]=(0,X.useState)(()=>`view_${Date.now()}`),m=(0,X.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,X.useMemo)(()=>df(n===`create`?m:r,i.name),[n===`create`?`create`:r.id,i.name]),[g,_]=(0,X.useState)(h),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(0),S=(0,X.useRef)(g),C=(0,X.useRef)(h);C.current!==h&&(C.current=h,S.current=h,_(h),y(!1)),(0,X.useEffect)(()=>{S.current=g},[g]),(0,X.useEffect)(()=>{e&&d.current&&d.current.focus()},[e]);let w=(0,X.useMemo)(()=>pf(i),[i.fields]),T=Hd(g.viewKind)?`form`:`list`,E=(0,X.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=ff(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,X.useCallback)(()=>{let e=ff(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),O=(0,X.useCallback)(()=>{if(n===`create`){t();return}_(h),y(!1)},[h,n,t]),k=(0,X.useCallback)(e=>{let t=df(e,i.name);S.current=t,_(t),y(!1)},[i.name]),A=u(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,Z.jsxs)(`div`,{ref:d,tabIndex:-1,role:`complementary`,"aria-label":A,"data-testid":`view-config-panel`,className:`flex h-full flex-col`,children:[(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,Z.jsx)(ef,{type:`view`,name:g.name,draft:g,variantKey:`config`,familyKey:T,isHome:!0,readOnly:!1,locale:f,objectFieldsOverride:w,onPatch:E})}),(0,Z.jsxs)(`div`,{"data-testid":`view-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5`,children:[n===`edit`&&(0,Z.jsx)(cf,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Z.jsx)(K,{size:`sm`,onClick:D,disabled:n===`edit`&&!v,"data-testid":`view-config-save`,children:u(`console.objectView.save`)})]})]}):(0,Z.jsx)(`div`,{ref:d,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}function hf(e){return[{type:`grid`,icon:ft,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Pa,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:$e,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:zt,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:Ht,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Rr,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:ho,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:yo,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function gf(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var _f={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:ms}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:gs},{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:gs},{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:gs},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:vs},{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=>hs(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&us(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&us(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:ms},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function vf({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=z(),s=(0,X.useMemo)(()=>hf(o),[o]),c=(0,X.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,X.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,X.useMemo)(()=>a?fs(a):[],[a]),[d,f]=(0,X.useState)(c[0]?.type??`grid`),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)({});(0,X.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,X.useEffect)(()=>{h||m(gf(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=_f[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,X.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(_f[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,X.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=_s(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,Z.jsx)(mt,{open:e,onOpenChange:t,children:(0,Z.jsxs)(Ot,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:o(`console.objectView.createView`)}),(0,Z.jsx)(Yt,{children:o(`console.objectView.createViewDesc`)})]}),(0,Z.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,Z.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,Z.jsx)(r,{className:U(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,Z.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,Z.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Z.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,Z.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,Z.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,Z.jsx)(Ha,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Z.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Z.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,Z.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Z.jsxs)(Pn,{className:`mt-2`,children:[(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Z.jsx)(K,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var yf={config:{icon:jr,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:ot,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:Rt,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:sa,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 bf({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=yf[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Z.jsx)(yn,{delayDuration:200,children:(0,Z.jsxs)(ut,{children:[(0,Z.jsx)(Qi,{asChild:!0,children:(0,Z.jsxs)(H,{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,Z.jsx)(i,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:r.short})]})}),(0,Z.jsxs)(it,{side:`bottom`,align:`start`,className:`max-w-xs text-xs leading-relaxed`,children:[(0,Z.jsx)(`p`,{className:`font-semibold mb-1`,children:r.title}),(0,Z.jsx)(`p`,{className:`text-muted-foreground`,children:r.body(a)})]})]})})}function xf({cards:e=6}){return(0,Z.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(He,{className:`h-7 w-56`}),(0,Z.jsx)(He,{className:`h-4 w-80`})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:Array.from({length:4}).map((e,t)=>(0,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,Z.jsx)(He,{className:`h-4 w-20`}),(0,Z.jsx)(He,{className:`h-8 w-24`}),(0,Z.jsx)(He,{className:`h-3 w-16`})]},`stat-${t}`))}),(0,Z.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,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(He,{className:`h-5 w-32`}),(0,Z.jsx)(He,{className:`h-5 w-5 rounded-full`})]}),(0,Z.jsx)(He,{className:`h-40 w-full`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(He,{className:`h-3 w-16`}),(0,Z.jsx)(He,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Sf({fields:e=8,columns:t=2}){return(0,Z.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(He,{className:`h-8 w-8 rounded`}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(He,{className:`h-6 w-48`}),(0,Z.jsx)(He,{className:`h-4 w-32`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(He,{className:`h-9 w-20`}),(0,Z.jsx)(He,{className:`h-9 w-20`})]})]}),(0,Z.jsx)(He,{className:`h-5 w-24`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 ${t===2?`md:grid-cols-2`:``} gap-4`,children:Array.from({length:e}).map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(He,{className:`h-4 w-24`}),(0,Z.jsx)(He,{className:`h-9 w-full`})]},`field-${t}`))}),(0,Z.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,Z.jsx)(He,{className:`h-5 w-32`}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:3}).map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 py-2`,children:[(0,Z.jsx)(He,{className:`h-8 w-8 rounded-full`}),(0,Z.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Z.jsx)(He,{className:`h-4 w-40`}),(0,Z.jsx)(He,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var Cf={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 wf(e){let t=Cf[e?.managedBy??`platform`]??Cf.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 Tf=new Set([`record:discussion`,`record:chatter`]);function Ef(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`&&Tf.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 Df({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Z.jsx)(Vr,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Z.jsxs)(ei,{children:[(0,Z.jsxs)(oi,{children:[(0,Z.jsx)(vi,{children:e.options?.title||`Confirm Action`}),(0,Z.jsx)(ra,{children:e.message})]}),(0,Z.jsxs)($a,{children:[(0,Z.jsx)(Va,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Z.jsx)(ba,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function Of({state:e,onOpenChange:t}){let{t:n}=z(),[r,i]=(0,X.useState)({}),[a,o]=(0,X.useState)({});(0,X.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,Z.jsx)(mt,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:e.title||n(`actionDialog.title`)}),(0,Z.jsx)(Yt,{children:e.description||n(`actionDialog.description`)})]}),(0,Z.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,Z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(yt,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,Z.jsxs)(G,{htmlFor:e.name,className:`font-normal cursor-pointer`,children:[e.label,e.required&&(0,Z.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),a[e.name]&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Z.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,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsxs)(G,{htmlFor:e.name,children:[e.label,e.required&&(0,Z.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,Z.jsxs)(Rn,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,Z.jsx)(ar,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,Z.jsx)(Tt,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Z.jsx)(jo,{children:e.options.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Z.jsx)(xo,{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,Z.jsx)(Ae,{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,Z.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,Z.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,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Z.jsx)(K,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var kf=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Af=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)}})),jf=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}}})),Mf=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})),Nf=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})),Pf=n((e=>{var t=Af().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}})),Ff=n((e=>{var t=Af().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),If=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}})),Lf=n((e=>{var t=jf(),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}}})),Rf=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]]}})),zf=n((e=>{var t=Rf();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}})),Bf=n(((e,t)=>{var n=zf();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})),Vf=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Hf=n((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
|
|
3
|
+
]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),Uf=n((e=>{var t=Vf(),n=Hf();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}}})),Wf=n((e=>{var t=Af(),n=Lf(),r=jf(),i=Uf(),a=Vf(),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}})),Gf=n((e=>{var t=Af(),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}})),Kf=n(((e,t)=>{var n=Uf();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})),qf=n(((e,t)=>{var n=Uf(),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})),Jf=n(((e,t)=>{var n=Uf();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})),Yf=n(((e,t)=>{var n=Uf(),r=Af();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
|
|
4
|
+
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),Xf=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)})),Zf=n((e=>{var t=Uf(),n=Kf(),r=qf(),i=Jf(),a=Yf(),o=Hf(),s=Af(),c=Xf();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
|
|
5
|
+
Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),Qf=n((e=>{var t=Af(),n=jf(),r=Mf(),i=Nf(),a=Pf(),o=Ff(),s=If(),c=Lf(),l=Bf(),u=Wf(),d=Gf(),f=Uf(),p=Zf();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
|
|
6
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
7
|
+
Minimum version required to store current data is: `+c+`.
|
|
8
|
+
`);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),$f=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}}})),ep=n((e=>{var t=$f();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)}})),tp=n((e=>{var t=$f();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
|
|
9
|
+
`;return typeof a==`function`&&a(null,p),p}})),np=n((e=>{var t=kf(),n=Qf(),r=ep(),i=tp();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 rp(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function ip({state:e,onAcknowledge:t}){let{t:n}=z(),{spec:r,data:i}=e,a=(0,X.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,Z.jsx)(mt,{open:e.open,onOpenChange:e=>{},children:(0,Z.jsxs)(Ot,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,Z.jsx)(Yt,{children:r.description}):null]}),(0,Z.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,Z.jsx)(ap,{field:e,value:e.path===``?i:rp(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,Z.jsx)(Pn,{children:(0,Z.jsx)(K,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function ap({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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,Z.jsx)(cp,{value:t}):null,a===`code-list`?(0,Z.jsx)(lp,{value:t}):null,a===`secret`?(0,Z.jsx)(up,{value:t}):null,a===`text`?(0,Z.jsx)(dp,{value:t}):null,a===`json`?(0,Z.jsx)(fp,{value:t}):null]})}function op(e){let[t,n]=(0,X.useState)(!1);return(0,X.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 sp({value:e,label:t}){let{copy:n,copied:r}=op(e);return(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,Z.jsx)(ua,{className:`w-4 h-4`}):(0,Z.jsx)(Ke,{className:`w-4 h-4`}),t?(0,Z.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function cp({value:e}){let[t,n]=(0,X.useState)(null);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,Z.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,Z.jsx)(`canvas`,{ref:t=>{!t||!e||(0,np.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,Z.jsx)(sp,{value:e})]})]})}function lp({value:e}){let t=e.join(`
|
|
10
|
+
`);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,Z.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,Z.jsx)(sp,{value:e})]},`${t}-${e}`))})}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(sp,{value:t,label:`Copy all`})})]})}function up({value:e}){let[t,n]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.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,Z.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,Z.jsx)(tt,{className:`w-4 h-4`}):(0,Z.jsx)(ct,{className:`w-4 h-4`})}),(0,Z.jsx)(sp,{value:e})]})}function dp({value:e}){return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,Z.jsx)(sp,{value:e})]})}function fp({value:e}){let t=(0,X.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(sp,{value:t})})]})}function pp(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function mp({state:e,authFetch:t,baseUrl:n,onClose:r,onComplete:i}){let[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)({}),[p,m]=(0,X.useState)(!1);if((0,X.useEffect)(()=>{e&&(o(e.screen),c(e.runId),u(e.flowName),f(pp(e.screen)))},[e]),!e||!a)return null;let h=(e,t)=>f(n=>({...n,[e]:t}));return(0,Z.jsx)(mt,{open:!0,onOpenChange:e=>{!e&&!p&&r()},children:(0,Z.jsxs)(Ot,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:a.title||`Input`}),a.description&&(0,Z.jsx)(Yt,{children:a.description})]}),(0,Z.jsx)(`div`,{className:`space-y-4 py-2`,children:a.fields.map(e=>(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(G,{htmlFor:`ff-${e.name}`,className:`text-sm`,children:[e.label||e.name,e.required&&(0,Z.jsx)(`span`,{className:`text-destructive`,children:` *`})]}),(0,Z.jsx)(hp,{field:e,value:d[e.name],onChange:t=>h(e.name,t)})]},e.name))}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:r,disabled:p,children:`Cancel`}),(0,Z.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})}),a=await e.json().catch(()=>null);if(!e.ok||a?.success===!1){q.error(a?.error||`Resume failed (HTTP ${e.status})`);return}let u=a?.data??{};if(u.success===!1||u.status===`failed`){q.error(u.error||`The flow failed to complete.`),r();return}u.status===`paused`&&u.screen?(o(u.screen),c(u.runId||s),f(pp(u.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 hp({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,Z.jsxs)(Rn,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,Z.jsx)(ar,{id:r,children:(0,Z.jsx)(Tt,{placeholder:e.placeholder||`Select…`})}),(0,Z.jsx)(jo,{children:e.options.map((e,t)=>(0,Z.jsx)(Ye,{value:String(e.value),children:e.label},t))})]});if(i===`boolean`||i===`checkbox`)return(0,Z.jsx)(yt,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,Z.jsx)(Ae,{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,Z.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 gp(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 _p(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??gp(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 vp(e,t){return Array.isArray(e)?e.map(e=>_p(e,t)):[]}function yp(){return`${``.replace(/\/$/,``)}/api/v1`}async function bp(e,t){let n=await fetch(`${yp()}${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 xp(e,t,n){let[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!0),[s,c]=(0,X.useState)([]),l=(0,X.useRef)(!1),u=(0,X.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{c((await bp(`/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,X.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,X.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,X.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,X.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await bp(`/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,X.useCallback)(e=>m(`approve`,e),[m]),reject:(0,X.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}var Sp={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},Cp={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function wp(e){if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);return t?{objectName:t[2],mode:t[1]===`edit`||t[1]===`update`?`edit`:`create`}:{objectName:e,mode:`create`}}return e&&typeof e==`object`?e.type&&!e.content&&!e.objectName&&!e.placement?{content:e}:e:{}}function Tp(e){let[t,n]=(0,X.useState)(null),r=(0,X.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),i=(0,X.useCallback)(e=>new Promise(t=>{n({d:wp(e),resolve:t})}),[]),a=null;if(t){let n=t.d,i=e=>{e||r({success:!1})};if(n.objectName&&!n.content)a=(0,Z.jsx)(Ro,{schema:{type:`object-form`,formType:`modal`,objectName:n.objectName,mode:n.mode||`create`,recordId:n.recordId,title:n.title,description:n.description,fields:n.fields,modalSize:n.size,open:!0,onOpenChange:i,onSuccess:e=>r({success:!0,reload:!0,data:e}),onCancel:()=>r({success:!1}),showSubmit:!0,showCancel:!0},dataSource:e});else{let e=n.placement||`center`,t=n.content?(0,Z.jsx)(ne,{schema:n.content}):n.description?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;a=e===`side`?(0,Z.jsx)(on,{open:!0,onOpenChange:i,children:(0,Z.jsxs)(pn,{side:n.side||`right`,className:U(`w-full overflow-y-auto`,Cp[n.size||`default`]),children:[n.title&&(0,Z.jsxs)(_t,{children:[(0,Z.jsx)(Mt,{children:n.title}),n.description&&(0,Z.jsx)(En,{children:n.description})]}),(0,Z.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,Z.jsx)(Mi,{open:!0,onOpenChange:i,children:(0,Z.jsxs)(wi,{children:[n.title&&(0,Z.jsxs)(ao,{children:[(0,Z.jsx)(wo,{children:n.title}),n.description&&(0,Z.jsx)(Mr,{children:n.description})]}),(0,Z.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,Z.jsx)(mt,{open:!0,onOpenChange:i,children:(0,Z.jsxs)(Ot,{className:U(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:Sp[n.size||`default`]),children:[n.title&&(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:n.title}),n.description&&(0,Z.jsx)(Yt,{children:n.description})]}),(0,Z.jsx)(`div`,{children:t}),!n.content&&(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(K,{onClick:()=>r({success:!0}),children:`OK`})})]})})}}return{modalHandler:i,modalElement:a,closeModal:r}}var Ep=t({RecordDetailView:()=>Np}),Dp={id:`current-user`,name:`Demo User`},Op=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),kp=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),Ap=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],jp=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function Mp(e,t){if(jp.has(t?.type))return!0;let n=e.toLowerCase();return Ap.some(e=>n===e||n.endsWith(`_${e}`))}function Np({dataSource:e,objects:t,onEdit:n,objectNameOverride:r,recordIdOverride:i,embedded:a}){let o=s(),c=o.appName,l=r??o.objectName,d=i??o.recordId,{showDebug:f}=Hu(),{user:p}=S(),m=v(),g=u().state?.from,{t:_}=z(),{objectLabel:y,viewLabel:b,sectionLabel:x,actionLabel:C,actionConfirm:w,actionSuccess:T,actionParamText:D,fieldLabel:O,fieldOptionLabel:k}=li(),{isFavorite:A,toggleFavorite:j,refreshLabel:ee}=Lc(),{addRecentItem:te}=Wo(),[M,re]=(0,X.useState)(!0),[N,ie]=(0,X.useState)([]),[P,F]=(0,X.useState)([]),[oe,se]=(0,X.useState)(0),[ce,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)({}),[fe,pe]=(0,X.useState)(null),[he,ge]=(0,X.useState)(!1),[I,L]=(0,X.useState)(),R=t.find(e=>e.name===l);Ec(a?void 0:I);let B=d,be=tu(l,B),Se=(0,X.useMemo)(()=>!l||!B?null:{id:`record:${l}:${B}`,label:I||B||``,href:`/apps/${c}/${l}/record/${B}`,type:`record`},[c,l,B,I]),Ce=Se?A(Se.id):!1,we=(0,X.useCallback)(()=>{Se&&j(Se)},[Se,j]),{page:Te,slots:Ee}=xe(l),De=(0,X.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 R?.detail?.renderViaSchema!==!1},[R]),Oe=(0,X.useMemo)(()=>Te||!R||!De&&!Ee?null:is(R,Ee?{slots:Ee}:void 0),[De,Te,Ee,R]),ke=Te||Oe,[Ae,je]=(0,X.useState)(null),[Me,Ne]=(0,X.useState)(`idle`);(0,X.useEffect)(()=>{let t=!1;if(!ke||!B||!l||!e?.findOne){je(null),Ne(`idle`);return}let n=_e(R?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{Ne(`loading`),(r?e.findOne(l,B,r):e.findOne(l,B)).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!==l||String(t.recordId)!==String(B)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[ke,l,B,e,R]),(0,X.useEffect)(()=>{if(!Ae||typeof Ae!=`object`||!R)return;let e=kl(R,Ae);e&&e!==`Untitled`&&e!==I&&L(e)},[Ae,R,I]),(0,X.useEffect)(()=>{if(!l||!B||!c||!I)return;let e=`record:${l}:${B}`;te({id:e,label:I,href:`/apps/${c}/${l}/record/${B}`,type:`record`}),ee(e,I)},[c,l,B,I,te,ee]);let[Pe,Fe]=(0,X.useState)({open:!1,message:``}),[Ie,Le]=(0,X.useState)({open:!1,params:[]}),[Re,ze]=(0,X.useState)({open:!1}),Be=(0,X.useCallback)((e,t)=>new Promise(n=>{ze({open:!0,spec:e,data:t,resolve:n})}),[]),Ve=(0,X.useCallback)((e,t)=>new Promise(n=>{Fe({open:!0,message:e,options:t,resolve:n})}),[]),He=(0,X.useCallback)((e,n)=>new Promise(r=>{let i=vp(e,{objectName:l||R?.name||``,objects:t||[],fieldLabel:O,fieldOptionLabel:k}),a=l||R?.name;Le({open:!0,params:i.map(e=>({...e,label:D(a,n?.name,e.name,`label`,e.label)??e.label,placeholder:D(a,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:D(a,n?.name,e.name,`helpText`,e.helpText)??e.helpText})),title:n?.label||n?.title,description:n?.description,resolve:r})}),[l,R,t,O,k,D]),We=(0,X.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),Ge=(0,X.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):m(e)},[m]),Ke=(0,X.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(l,B,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(l,B,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(l,B,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(l,B,r);break}let i=t.refreshAfter===!0;return i&&se(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,l,B]),{modalHandler:qe,modalElement:Je}=Tp(e),Ye=(0,X.useMemo)(()=>E(),[]),Xe=(0,X.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 Ye(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:B,objectName:l,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 le({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&se(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Ye,B,l]),Ze=(0,X.useRef)(new Set),Qe=(0,X.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=`${t}:${B??``}`;if(Ze.current.has(r))return{success:!1,error:`Action already in progress`};Ze.current.add(r);let i=null;if(e.opensInNewTab)try{i=window.open(`about:blank`,`_blank`),i&&(i.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),i.document.close())}catch{i=null}try{let r=e.objectName||l||`global`,a=await Ye(`/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:B,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(i)try{i.close()}catch{}return q.error(e),{success:!1,error:e}}let s=e.refreshAfter!==!1;s&&se(e=>e+1);let c=o?.data;if(c&&typeof c==`object`&&typeof c.redirectUrl==`string`){let e=c.redirectUrl;if(i)try{i.location.href=e}catch{try{i.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`)}catch{t=null}t||q(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(e,`_blank`)}catch{window.location.href=e}}},duration:1e4})}}else if(i)try{i.close()}catch{}return{success:!0,data:c,reload:s}}catch(e){if(i)try{i.close()}catch{}let t=e.message;return q.error(t),{success:!1,error:t}}finally{Ze.current.delete(r)}},[Ye,B,l]),$e=xp(l,B,p?.id),et=(0,X.useRef)($e);et.current=$e;let V=(0,X.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await et.current.approve({comment:n.comment});else if(t===`reject_request`)await et.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return se(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),tt=(0,X.useMemo)(()=>Cl(R,t),[R,t]);(0,X.useEffect)(()=>{if(ke||!e||!B||tt.length===0)return;let t=!1;return Promise.all(tt.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:B}}).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;de(n)}),()=>{t=!0}},[e,B,tt,R,ke]);let nt=(0,X.useMemo)(()=>!R||R.name===`sys_audit_log`||R.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[R,t]);(0,X.useEffect)(()=>{if(!e||!B||!R||!nt){pe(null);return}let t=!1;return ge(!0),e.find(`sys_audit_log`,{$filter:{record_id:B,object_name:R.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(R.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};pe(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),pe([]))}).finally(()=>{t||ge(!1)}),()=>{t=!0}},[e,B,R,nt]),(0,X.useEffect)(()=>{if(!e)return;let t=!1,n=p?[{id:String(p.id),label:p.name||p.email||String(p.id),avatarUrl:p.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))];F(o.length>0?o:n)}catch{if(t)return;F(n)}})(),()=>{t=!0}},[e,p?.id,p?.name,p?.email]);let rt=(0,X.useMemo)(()=>p?{id:p.id,name:p.name,avatar:p.image}:Dp,[p?.id,p?.name,p?.image]);(0,X.useEffect)(()=>{if(!e||!l||!B)return;let t=`${l}:${B}`,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(rt.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)}));ie(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:l,record_id:B},$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&&ie(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,l,B,rt]);let it=(0,X.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:rt.name,actorAvatarUrl:`avatar`in rt?rt.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(ie(e=>[...e,n]),e){let r=`${l}:${B}`,i=os(t,P);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:rt.id,author_name:rt.name,author_avatar_url:`avatar`in rt?rt.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[rt,e,l,B,P]),at=(0,X.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:rt.name,actorAvatarUrl:`avatar`in rt?rt.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(ie(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${l}:${B}`,a=os(n,P);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:rt.id,author_name:rt.name,author_avatar_url:`avatar`in rt?rt.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[rt,e,l,B,P]),ot=(0,X.useCallback)((t,n)=>{ie(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=rt.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}))},[rt.id,e]);(0,X.useEffect)(()=>{re(!0),queueMicrotask(()=>re(!1))},[l,d]);let st=(0,X.useMemo)(()=>{if(!R)return{type:`detail-view`};let n=R.primaryField||Object.keys(R.fields||{}).find(e=>e===`name`||e===`title`),r=R.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?x(R.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!R.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=R.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${R.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(R.fields||{}).filter(e=>!Op.has(e)&&!kp.has(e)&&!R.fields[e]?.hidden),t=e=>{let t=R.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=>!Mp(e,R.fields[e])),r=e.filter(e=>Mp(e,R.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(R.name,`details`,_(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),o=(()=>{let e=new Set,t=(R.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:C(R.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:w(R.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(R.name,e.name,e.successMessage)}}));if($e.available&&$e.canDecide){let e={name:`comment`,label:_(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:_(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`default`,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:_(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:_(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,locations:[`record_header`],refreshAfter:!0,confirmText:_(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:_(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),s=R.views?.detail?.highlightFields??[],l=R.views?.detail?.sectionGroups??R.views?.form?.sectionGroups,u=c?`/apps/${c}`:``,d=tt.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let s=t.find(e=>e.name===n),c=B||``,l=a||(s?y({name:s.name,label:s.label||r}):r),d=()=>{let e=new URLSearchParams({[i]:c}).toString();return`${u}/${n}/new${e?`?${e}`:``}`},f=()=>{let e=new URLSearchParams({[`filter[${i}]`]:c}).toString();return`${u}/${n}${e?`?${e}`:``}`},p=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},h=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}`:null},g=u?()=>m(d()):void 0,v=u?()=>m(f()):void 0,b=u?e=>{let t=h(e);t&&m(t)}:void 0,x=u?e=>{let t=p(e);t&&m(t)}:void 0,S=e&&c?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),q.success(_(`detail.deleteSuccess`,{defaultValue:`Deleted`})),de(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){q.error(e?.message||_(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:l,type:`table`,api:n,data:ue[n]||[],referenceField:i,...Array.isArray(o)&&o.length>0?{columns:o}:{},icon:s?.icon,displayField:s?.displayNameField||(Array.isArray(s?.compactLayout)?s.compactLayout[0]:void 0),onNew:g,onViewAll:v,onRowClick:b,onRowEdit:x,onRowDelete:S}}),f=wf(R);return{type:`detail-view`,objectName:R.name,resourceId:B,showBack:!a,onBack:`history`,showEdit:f.edit,title:R.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...nt&&{history:{entries:fe??[],loading:he&&fe===null}},...d.length>0&&{related:d},...s.length>0&&{highlightFields:s},...l&&l.length>0&&{sectionGroups:l},...o.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:o}]}}},[R?.name,B,ue,oe,c,m,e,_,y,t,nt,fe,he,$e.available,$e.canDecide,$e.pendingRequest,$e.latestRequest,a]);if(M)return(0,Z.jsx)(Sf,{});if(!R)return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(kt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:_(`empty.objectNotFound`)}),(0,Z.jsx)(Kt,{children:_(`empty.objectNotFoundDescription`,{name:l})})]})});if(ke&&Me===`missing`)return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(kt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:_(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Z.jsx)(Kt,{children:_(`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=Ef(ke),i=!t&&!r,o=(()=>{let e=st.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=wf(R),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:_(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:B,objectName:l}}))}}),r.push({name:`sys_edit`,label:_(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:B})})),r.push({name:`sys_share`,label:_(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:async()=>{try{if(navigator.share){await navigator.share({title:document.title,url:window.location.href});return}}catch{return}try{await navigator.clipboard.writeText(window.location.href),q.success(_(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){q.error(_(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:_(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=_(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(l,B),q.success(_(`detail.deleted`,{defaultValue:`Record deleted`})),m(`${c?`/apps/${c}`:``}/${l}`,{replace:!0})}catch(e){q.error(e?.message||`Delete failed`)}}}),r})(),u=o.length>0?o:void 0,d=Array.isArray(st.related)?st.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=st.history?{entries:st.history.entries??[],loading:!!st.history.loading,emptyText:st.history.emptyText}:void 0,v=Te?ke:is(R,{sections:st.sections,highlightFields:Array.isArray(st.highlightFields)?st.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:u,related:d,history:p,showReferenceRail:R?.detail?.showReferenceRail===!0||void 0,hideReferenceRail:R?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:R?.detail?.hideRelatedTab===!0||void 0,...Ee?{slots:Ee}:{}});return(0,Z.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,Z.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[be.length>0&&(0,Z.jsx)(Ql,{users:be,size:`sm`,maxVisible:3,showStatus:!0}),(0,Z.jsx)(bf,{managedBy:R?.managedBy})]}),(0,Z.jsx)(ve,{objectName:l,recordId:B,data:Ae,objectSchema:R,dataSource:e,embedded:a,headerSystemActions:s,isFavorite:Ce,onToggleFavorite:Se?we:void 0,children:(0,Z.jsx)(ye,{children:(0,Z.jsx)(me,{items:N,onAddComment:it,onAddReply:at,onToggleReaction:ot,mentionSuggestions:P,children:(0,Z.jsxs)(ae,{context:{record:Ae||{},objectName:l,user:rt},onConfirm:Ve,onToast:We,onNavigate:Ge,onParamCollection:He,onResultDialog:Be,onModal:qe,handlers:{api:Ke,flow:Xe,script:Qe,approval:V},children:[(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[g?.pathname&&g?.label&&(0,Z.jsxs)(h,{to:g.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Z.jsx)(yi,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:g.label})]}),(0,Z.jsx)(ne,{schema:v}),i&&(0,Z.jsx)(`div`,{className:`mt-6`,children:(0,Z.jsx)(as,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:it,onAddReply:at,onToggleReaction:ot,mentionSuggestions:P})})]}),(0,Z.jsx)(Vu,{open:f,sections:[{title:`Page Schema`,data:v}]})]}),Je]})})})}),(0,Z.jsx)(Df,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Z.jsx)(Of,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Z.jsx)(ip,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Z.jsx)(mp,{state:ce,authFetch:Ye,baseUrl:``,onClose:()=>le(null),onComplete:()=>{le(null),se(e=>e+1)}})]})}return(0,Z.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,Z.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[be.length>0&&(0,Z.jsx)(Ql,{users:be,size:`sm`,maxVisible:3,showStatus:!0}),(0,Z.jsx)(bf,{managedBy:R?.managedBy})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,Z.jsxs)(ae,{context:{record:{},objectName:l,user:rt},onConfirm:Ve,onToast:We,onNavigate:Ge,onParamCollection:He,onResultDialog:Be,onModal:qe,handlers:{api:Ke,flow:Xe,script:Qe,approval:V},children:[(0,Z.jsx)(ss,{schema:st,dataSource:e,objectLabel:y({name:R.name,label:R.label}),isFavorite:Ce,onToggleFavorite:Se?we:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=kl(R,e);t&&t!==I&&t!==`Untitled`&&L(t)},onEdit:()=>{n({id:B})},discussionSlot:(0,Z.jsx)(as,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:it,onAddReply:at,onToggleReaction:ot})},oe),Je]})}),(0,Z.jsx)(Vu,{open:f,sections:[{title:`View Schema`,data:st}]})]}),(0,Z.jsx)(Df,{state:Pe,onOpenChange:e=>{e||Fe(e=>({...e,open:!1}))}}),(0,Z.jsx)(Of,{state:Ie,onOpenChange:e=>{e||Le(e=>({...e,open:!1}))}}),(0,Z.jsx)(ip,{state:Re,onAcknowledge:()=>{Re.resolve?.(),ze({open:!1})}}),(0,Z.jsx)(mp,{state:ce,authFetch:Ye,baseUrl:``,onClose:()=>le(null),onComplete:()=>{le(null),se(e=>e+1)}})]})}function Pp(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 Fp={id:`current-user`,name:`Demo User`};function Ip(e){let{dataSource:t,objects:n,objectName:r,onRefresh:i}=e,a=v(),{user:o,activeOrganization:s}=S(),{fieldLabel:c,fieldOptionLabel:l,actionParamText:u}=li(),d=(0,X.useMemo)(()=>r?n?.find(e=>e.name===r):void 0,[n,r]),f=r||d?.name,p=(0,X.useCallback)(()=>{i?.()},[i]),[m,h]=(0,X.useState)({open:!1,message:``}),[g,_]=(0,X.useState)({open:!1,params:[]}),[y,b]=(0,X.useState)({open:!1}),[x,C]=(0,X.useState)(null),w=(0,X.useRef)(new Set),T=(0,X.useCallback)((e,t)=>new Promise(n=>{b({open:!0,spec:e,data:t,resolve:n})}),[]),D=(0,X.useCallback)((e,t)=>new Promise(n=>{h({open:!0,message:e,options:t,resolve:n})}),[]),O=(0,X.useCallback)((e,t)=>new Promise(i=>{let a=t?.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,o=vp(e,{objectName:r||d?.name||``,objects:n||[],fieldLabel:c,fieldOptionLabel:l,row:a}),s=r||d?.name;_({open:!0,params:o.map(e=>({...e,label:u(s,t?.name,e.name,`label`,e.label)??e.label,placeholder:u(s,t?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:u(s,t?.name,e.name,`helpText`,e.helpText)??e.helpText})),title:t?.label||t?.title,description:t?.description,resolve:i})}),[r,d,n,c,l,u]),k=o?{id:o.id,name:o.name,avatar:o.image}:Fp,A=(0,X.useCallback)((e,t)=>{t?.type===`error`?q.error(e):q.success(e)},[]),j=(0,X.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):a(e)},[a]),ee=(0,X.useMemo)(()=>E(),[]),te=(0,X.useCallback)(async e=>{try{let n=e.target||e.name,r=e.params||{},i=typeof n==`string`?n:``;if(i.startsWith(`/`)||/^https?:\/\//i.test(i)){let t={...r},n=t._rowRecord;delete t._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}`,c=e.bodyShape&&typeof e.bodyShape==`object`&&e.bodyShape.wrap?e.bodyShape.wrap:void 0,l=c?{[c]:t}:{...t};if(n&&e.recordIdParam){let t=n[e.recordIdField||`id`];t!=null&&(l[e.recordIdParam]=t)}/\/api\/v1\/auth\//.test(a)&&!l.organizationId&&s?.id&&(l.organizationId=s.id),e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(l,e.bodyExtra);let u=(e.method||`POST`).toUpperCase(),d={method:u,headers:{"Content-Type":`application/json`},credentials:`include`};u!==`GET`&&u!==`DELETE`&&(d.body=JSON.stringify(l));let f=await ee(o,d);if(!f.ok){let e=`HTTP ${f.status}`;try{let t=await f.json();e=t?.error||t?.message||e}catch{}return{success:!1,error:e}}let m=await f.json().catch(()=>({}));return e.refreshAfter!==!1&&p(),{success:!0,data:m,reload:e.refreshAfter!==!1}}let a=e.objectName||f;a&&typeof t?.execute==`function`?await t.execute(a,n,r):a&&r.recordId&&Object.keys(r).length>1&&typeof t?.update==`function`&&await t.update(a,r.recordId,r);let o=e.refreshAfter!==!1;return o&&p(),{success:!0,reload:o}}catch(e){return{success:!1,error:e.message}}},[t,f,ee,s,p]),M=(0,X.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No flow target provided for flow action`};try{let r={...e.params||{}},i=r._rowRecord;delete r._rowRecord;let a=r.recordId??i?.id;if(a==null){let e=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(e.length===1)a=e[0]?.id;else if(e.length>1)return{success:!1,error:`This flow runs on a single record — select exactly one row.`}}a!=null&&r.recordId==null&&(r.recordId=a);let o=await ee(`/api/v1/automation/${encodeURIComponent(n)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,objectName:e.objectName||f,params:r})}),s=await o.json().catch(()=>null);if(!o.ok||s&&s.success===!1)return{success:!1,error:s?.error||`Flow "${n}" failed (HTTP ${o.status})`};let c=s?.data??{};if(c.status===`paused`&&c.screen)return C({flowName:n,runId:c.runId,screen:c.screen}),{success:!0};let l=e.refreshAfter!==!1;return l&&p(),{success:!0,data:s?.data,reload:l}}catch(e){return{success:!1,error:e.message}}},[ee,f,p]),ne=(0,X.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No action target provided`};let r=e.params&&!Array.isArray(e.params)?{...e.params}:{},i=r._rowRecord;delete r._rowRecord;let a=e.recordIdField||`id`,o=r.recordId??i?.[a];if(o==null){let e=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(e.length===1)o=e[0]?.[a];else if(e.length>1)return{success:!1,error:`This action runs on a single record — select exactly one row.`}}let s=`${n}:${o??``}`;if(w.current.has(s))return{success:!1,error:`Action already in progress`};w.current.add(s);let c=null;if(e.opensInNewTab)try{c=window.open(`about:blank`,`_blank`),c&&(c.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),c.document.close())}catch{c=null}try{let t=e.objectName||f||`global`,i=await ee(`/api/v1/actions/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:o,params:r})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1){let e=a?.error||`Action "${n}" failed (HTTP ${i.status})`;if(c)try{c.close()}catch{}return q.error(e),{success:!1,error:e}}let s=e.refreshAfter!==!1;s&&p();let l=a?.data,u=l&&typeof l==`object`&&typeof l.redirectUrl==`string`?l.redirectUrl:null;if(u)if(c)try{c.location.href=u}catch{try{c.close()}catch{}window.location.href=u}else{let e=null;try{e=window.open(u,`_blank`)}catch{e=null}e||q(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(u,`_blank`)}catch{window.location.href=u}}},duration:1e4})}else if(c)try{c.close()}catch{}return{success:!0,data:l,reload:s}}catch(e){if(c)try{c.close()}catch{}let t=e.message;return q.error(t),{success:!1,error:t}}finally{w.current.delete(s)}},[ee,f,p]);return{confirmHandler:D,toastHandler:A,navigateHandler:j,paramCollectionHandler:O,resultDialogHandler:T,apiHandler:te,flowHandler:M,serverActionHandler:ne,authFetch:ee,actionProviderProps:(0,X.useMemo)(()=>({context:{...r?{objectName:r}:{},user:k,apiBase:``,activeOrganization:s?{id:s.id,slug:s.slug,name:s.name}:null},onConfirm:D,onToast:A,onNavigate:j,onParamCollection:O,onResultDialog:T,handlers:{api:te,flow:M,script:ne,modal:ne}}),[r,k,s,D,A,j,O,T,te,M,ne]),dialogs:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Df,{state:m,onOpenChange:e=>{e||h({open:!1,message:``})}}),(0,Z.jsx)(Of,{state:g,onOpenChange:e=>{e||_({open:!1,params:[]})}}),(0,Z.jsx)(ip,{state:y,onAcknowledge:()=>{y.resolve?.(),b({open:!1})}}),(0,Z.jsx)(mp,{state:x,authFetch:ee,baseUrl:``,onClose:()=>C(null),onComplete:()=>{C(null),p()}})]})}}function Lp({children:e,...t}){let n=Ip(t);return(0,Z.jsxs)(ae,{...n.actionProviderProps,children:[e,n.dialogs]})}var Rp=(0,X.lazy)(()=>d(()=>import(`./plugin-charts-BjUzf65B.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),zp=(0,X.lazy)(()=>d(()=>import(`./plugin-grid-BiWgglXK.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Bp={grid:Lt,kanban:Pa,calendar:$e,gallery:ft,timeline:Dr,gantt:Fr,map:Bn,chart:yo},Vp={id:`current-user`,name:`Demo User`};function Hp(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 Up({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=s(),{t:a}=z();return t.find(e=>e.name===i)?(0,Z.jsx)(Wp,{dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}):(0,Z.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(Lt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:a(`console.objectView.objectNotFound`)}),(0,Z.jsxs)(Kt,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Wp({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=v(),{appName:a,objectName:o,viewId:c}=s(),[l,d]=m(),f=u(),{showDebug:p}=Hu(),{t:h}=z(),{objectLabel:g,objectDescription:_,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:C,actionSuccess:w,actionParamText:T,fieldLabel:E,fieldOptionLabel:O}=li(),{isFavorite:k,toggleFavorite:A}=Lc(),j=ks(),[ee,te]=(0,X.useState)(!1),[M,re]=(0,X.useState)(`edit`),[ie,P]=(0,X.useState)(!1),[F,oe]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(null),le=(0,X.useRef)({}),ue=(0,X.useRef)({}),de=(0,X.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!o||!t)return;let i=ue.current[t]||{};ue.current[t]={...i,...r};let a=le.current[t];a&&clearTimeout(a),le.current[t]=setTimeout(()=>{let r=ue.current[t]||{};delete ue.current[t],delete le.current[t],Promise.resolve(e.updateViewConfig(o,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,o]),fe=(0,X.useCallback)(e=>{ce(e),ye(e=>e+1);let t=e.id;j&&t?nf(`view`,t,e,{metadataClient:j}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[j]),pe=(0,X.useCallback)(async e=>{try{let n;if(j){let r=t?.find?.(e=>e.name===o),i=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),a=[];Array.isArray(r?.compactLayout)&&r.compactLayout.length>0?a=r.compactLayout.filter(e=>r.fields?.[e]):r?.fields&&(a=Object.entries(r.fields).filter(([e,t])=>t&&!t.hidden&&!i.has(e)).map(([e])=>e).slice(0,5));let s=Array.isArray(e.columns)&&e.columns.length>0?e.columns:a,c={...e,columns:s};if(e.type===`kanban`)c.kanban={...c.kanban||{},columns:s};else if(e.type===`gallery`){let e=c.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(c.gallery={...e,visibleFields:s})}n=await rf(`view`,String(e?.name??e?.id??c?.id??``),c,{metadataClient:j})}te(!1),re(`edit`),ye(e=>e+1),n&&(c?i(`../${n}`,{relative:`path`}):i(`view/${n}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,o,t,i,c,j]),[me,he]=(0,X.useState)(void 0),{user:ge,activeOrganization:_e}=S(),ve=ge?.role===`admin`,{can:I}=D(),L=t.find(e=>e.name===o),[R,ye]=(0,X.useState)(0),B=Ip({dataSource:e,objects:t,objectName:L.name,onRefresh:()=>ye(e=>e+1)}),{confirmHandler:be,toastHandler:xe}=B,Se=(0,X.useMemo)(()=>wf(L),[L]);(0,X.useEffect)(()=>{r===void 0||r===0||ye(e=>e+1)},[r]);let[Ce,we]=(0,X.useState)(!1),[Te,Ee]=(0,X.useState)([]);(0,X.useEffect)(()=>{let t=!1;if(!o){Ee([]);return}return typeof e?.listViews==`function`?(e.listViews(o).then(e=>{t||Ee((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||o})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Ee([])}),()=>{t=!0}):(Ee([]),()=>{t=!0})},[e,o,R]);let[De,Oe]=(0,X.useState)({});(0,X.useEffect)(()=>{let t=!1;if(!e||!o){Oe({});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){Oe({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(o);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(o,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||Oe(e)}),()=>{t=!0}},[e,o,L.listViews,L.list_views,L.list,R]);let ke=(0,X.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=De[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=De[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:h(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of Te){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=Te.find(t=>(t.id||t._id)===e.id),a=Te.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,Te,De,h]),Ae=(0,X.useMemo)(()=>ke.find(e=>e.isDefault)?.id,[ke]),je=c||l.get(`view`)||Ae||ke[0]?.id,Me=ke.find(e=>e.id===je)||ke[0],Ne=se&&se.id===Me?.id?{...Me,...se}:Me,Pe=(0,X.useCallback)((e,t)=>{ce(n=>({...n||{},id:Me?.id,[e]:t}))},[Me?.id]),Ie=e=>{let t=ke.find(t=>t.id===e);t&&(t.id!==je&&te(!1),c?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Le=(0,X.useMemo)(()=>(ke||[]).map(e=>{let t=Bp[e.type];return{id:e.id,label:y(L.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Z.jsx)(t,{className:`h-4 w-4`}):void 0}}),[ke,L.name,y]);mu({views:Le,activeViewId:je??``,onChange:Ie,enabled:Le.length>0&&!!je});let Re=(0,X.useCallback)(()=>{P(!0)},[]),ze=(0,X.useCallback)((e,t)=>{if(e===`settings`){let e=ke.find(e=>e.type===t);e&&Ie(e.id),re(`edit`),te(!0)}},[ke,Ie]),Be=(0,X.useCallback)(e=>Te.some(t=>(t.id||t._id)===e),[Te]),Ve=(0,X.useCallback)(async(t,n)=>{if(!Be(t)){q.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{label:n}),ye(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),q.error(h(`objectViewActions.renameFailed`))}},[e,o,Be,h]),He=(0,X.useCallback)(async t=>{if(!e)return;if(!Be(t)){q.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=ke.find(e=>e.id===t)?.label||t;if(await be(h(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:h(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:h(`console.objectView.delete`)||`Delete`,cancelText:h(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(o,t),t===je){let e=ke.find(e=>e.id!==t);e&&i(c?`../${e.id}`:`view/${e.id}`,c?{relative:`path`}:void 0)}ye(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),q.error(h(`objectViewActions.deleteFailed`))}},[e,Be,je,ke,c,i,h,be]),Ue=(0,X.useCallback)(async(t,n)=>{if(e){if(!Be(t)){q.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{isPinned:n}),ye(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,o,Be,h]),We=(0,X.useCallback)(async t=>{if(e){if(!Be(t)){q.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be set as a default.`);return}try{if(typeof e?.updateView!=`function`)return;let n=e.updateView,r=Te.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(e=>n(o,e.id||e._id,{isDefault:!1}));r.push(n(o,t,{isDefault:!0})),await Promise.all(r),ye(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),q.error(`Failed to set default view`)}}},[e,o,Te,Be,h]),Ge=(0,X.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${o}`,JSON.stringify(t))}catch{}if(typeof e?.updateView==`function`){let n=e.updateView,r=new Set(Te.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((e,t)=>n(o,e,{sortOrder:t}));try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}ye(e=>e+1)},[e,Te,o]),Ke=(0,X.useCallback)(e=>{if(!Be(e)){q.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==je&&Ie(e),re(`edit`),te(!0)},[je,Ie,Be,h]),qe=(0,X.useCallback)(()=>{P(!0)},[]),Je=ge?{id:ge.id,name:ge.name,avatar:ge.image}:Vp,Ye=Sc({objectName:L.name,objectLabel:L.label,dataSource:e,onEdit:n,onRefresh:()=>ye(e=>e+1),onConfirm:be,onToast:xe}),{lastMessage:Xe}=Ul({channel:`object:${L.name}`}),{hasConflicts:Ze,resolveAllConflicts:Qe}=Jl(L.name?`user-${L.name}`:`current-user`);(0,X.useEffect)(()=>{Xe&&(Ze&&Qe(`remote`),ye(e=>e+1))},[Xe,Ze,Qe]),(0,X.useEffect)(()=>{e?.find&&L.name&&e.find(L.name,{limit:0}).then(e=>{typeof e?.total==`number`?he(e.total):Array.isArray(e?.data)?he(e.data.length):Array.isArray(e)&&he(e.length)}).catch(()=>{})},[e,L.name,R]);let $e=(0,X.useMemo)(()=>Ne?.navigation??L.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Ne?.navigation,L.navigation]),et=l.get(`recordId`),V=(0,X.useMemo)(()=>{let e=[];return l.forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[l.toString()]),tt=(0,X.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:f.pathname+(f.search||``),label:y(L.name,Ne?.name??``,Ne?.label??``)||g(L)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,c,f.pathname,f.search,L,Ne?.name,Ne?.label,y,g]),nt=N({navigation:$e,objectName:L.name,onNavigate:tt}),rt=()=>{nt.close();let e=new URLSearchParams(l);e.delete(`recordId`),d(e)},it=(0,X.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){nt.handleClick(e,t);return}if(nt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(l);e.set(`recordId`,String(t)),d(e);return}}nt.handleClick(e,t)},[nt,l,d]),at=(0,X.useCallback)(()=>{let e=nt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(rt(),tt(t))},[nt.selectedRecord,tt]);(0,X.useEffect)(()=>{et&&!nt.isOpen?nt.open({id:et}):!et&&nt.isOpen&&nt.close()},[et]);let ot=(0,X.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=R+(i||0),s=`${o}-${Ne.id}-${a}`,c=Ne;if(c.type===`chart`){let e=c.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,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Z.jsx)(Rp,{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`}})},s)}return(0,Z.jsx)(rs,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=Hp(c.filter??e.filter,Je.id);return V.length?[...Array.isArray(t)?t:[],...V]:t})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{de(c.id,c,{densityMode:e})},onSortChange:e=>{de(c.id,c,{sort:e})},onFilterChange:e=>{de(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{de(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{de(c.id,c,{columnState:e})},inlineEdit:c.inlineEdit??c.editRecordsInline??e.inlineEdit,appearance:c.showDescription==null?e.appearance:{showDescription:c.showDescription},showSearch:c.showSearch??e.showSearch,showSort:c.showSort??e.showSort,showFilters:c.showFilters??e.showFilters,showHideFields:c.showHideFields??e.showHideFields,showGroup:c.showGroup??e.showGroup,showColor:c.showColor??e.showColor,showDensity:c.showDensity??e.showDensity,allowExport:c.allowExport??e.allowExport,exportOptions:c.allowExport===!1?void 0:c.exportOptions??e.exportOptions,striped:c.striped??e.striped,bordered:c.bordered??e.bordered,color:c.color??e.color,wrapHeaders:c.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:c.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:c.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:c.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:c.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:c.fieldTextColor??e.fieldTextColor,prefixField:c.prefixField??e.prefixField,showDescription:c.showDescription??e.showDescription,navigation:c.navigation??e.navigation,selection:c.selection??e.selection,pagination:c.pagination??e.pagination,searchableFields:c.searchableFields??e.searchableFields,filterableFields:c.filterableFields??e.filterableFields,resizable:c.resizable??e.resizable,rowActions:c.rowActions??e.rowActions,rowActionDefs:Array.isArray(L?.actions)?L.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:x(L.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(L.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:w(L.name,e.name,e.successMessage)}})):[],bulkActions:c.bulkActions??e.bulkActions,bulkActionDefs:c.bulkActionDefs??e.bulkActionDefs,sharing:c.sharing??e.sharing,addRecord:c.addRecord??e.addRecord,conditionalFormatting:c.conditionalFormatting??e.conditionalFormatting,quickFilters:c.quickFilters??e.quickFilters,userFilters:c.userFilters??e.userFilters,showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,virtualScroll:c.virtualScroll??e.virtualScroll,emptyState:b(L.name,c.name||c.id||``,c.emptyState??e.emptyState??Pp(L?.managedBy)),aria:c.aria??e.aria,tabs:e.tabs,...(()=>{let e=Hp([...Array.isArray(c.filter)?c.filter:[],...V],Je.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...c.sort?.length?{sort:c.sort}:{},options:{kanban:{groupBy:c.kanban?.groupByField||c.kanban?.groupField||`status`,groupField:c.kanban?.groupByField||c.kanban?.groupField||`status`,titleField:c.kanban?.titleField||L.titleField||`name`,cardFields:c.kanban?.columns},calendar:{startDateField:c.calendar?.startDateField||`due_date`,endDateField:c.calendar?.endDateField,titleField:c.calendar?.titleField||`name`,colorField:c.calendar?.colorField,allDayField:c.calendar?.allDayField,defaultView:c.calendar?.defaultView},timeline:{dateField:c.timeline?.dateField||`due_date`,titleField:c.timeline?.titleField||L.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||L.titleField||`name`,latitudeField:c.map?.latitudeField,longitudeField:c.map?.longitudeField,zoom:c.map?.zoom,center:c.map?.center},gallery:{...c.gallery||{},imageField:c.gallery?.imageField||c.gallery?.coverField||`image`,coverField:c.gallery?.coverField||c.gallery?.imageField,titleField:c.gallery?.titleField||L.titleField||`name`,subtitleField:c.gallery?.subtitleField},gantt:{startDateField:c.gantt?.startDateField||`start_date`,endDateField:c.gantt?.endDateField||`end_date`,titleField:c.gantt?.titleField||`name`,progressField:c.gantt?.progressField,dependenciesField:c.gantt?.dependenciesField,colorField:c.gantt?.colorField},chart:{chartType:c.chart?.chartType,xAxisField:c.chart?.xAxisField,yAxisFields:c.chart?.yAxisFields,aggregation:c.chart?.aggregation,series:c.chart?.series,config:c.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&Ye.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Ye.execute({type:`delete`,confirmText:h(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{it(e,t)},onSortChange:e=>{de(c.id,c,{sort:e})},onFilterChange:e=>{de(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{de(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{de(c.id,c,{columnState:e})},dataSource:t},s)},[Ne,L,o,R,nt,Ye,de,V]),st=(0,X.useMemo)(()=>ke.map(e=>e.id===je&&se&&se.id===e.id?{...e,...se}:e),[ke,je,se]),ct=(0,X.useMemo)(()=>({type:`object-view`,objectName:L.name,layout:`page`,showSearch:Ne?.showSearch!==!1,showFilters:Ne?.showFilters!==!1,showSort:Ne?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:ve,viewActions:ve?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:f.pathname+(f.search||``),label:y(L.name,Ne?.name??``,Ne?.label??``)||g(L)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[L,n,Ne?.showSearch,Ne?.showFilters,Ne?.showSort,Ne?.name,Ne?.label,i,c,ve,f.pathname,f.search,y,g]);return(0,Z.jsxs)(ae,{...B.actionProviderProps,children:[(0,Z.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`hidden sm:block`,children:(0,Z.jsx)(wu,{title:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:g(L)}),(0,Z.jsx)(bf,{managedBy:L?.managedBy})]}),description:L.description?_(L):void 0,icon:(0,Z.jsx)(pl(L?.icon),{className:`h-4 w-4`}),actions:(0,Z.jsxs)(Z.Fragment,{children:[o&&(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>A({id:`object:${o}`,label:g(L),href:`/apps/${a}/${o}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":k(`object:${o}`),"aria-label":k(`object:${o}`)?h(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):h(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${o}`,children:k(`object:${o}`)?(0,Z.jsx)(Fe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Z.jsx)(ui,{className:`h-4 w-4`})}),Se.create&&I(L.name,`create`)&&(0,Z.jsxs)(K,{size:`sm`,onClick:Ye.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Z.jsx)(Oo,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),Se.import&&I(L.name,`create`)&&(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>we(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:h(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Z.jsx)(rn,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),L.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,Z.jsx)(ne,{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:C(L.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:w(L.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),Se.create&&I(L.name,`create`)&&(0,Z.jsx)(`button`,{type:`button`,onClick:Ye.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":h(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Z.jsx)(Oo,{className:`h-5 w-5`})}),Ce&&(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(zp,{open:Ce,onOpenChange:we,objectName:L.name,objectLabel:g(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=>{ye(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?q.warning(h(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&q.success(h(`console.objectView.importedToast`,{count:t}))}})}),ke.length>=1&&(()=>{let e=ke.map(e=>{let t=Te.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?h(`console.objectView.systemViewReadonly`)||`System view defined in code — read-only.`:void 0}});return(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,Z.jsx)(ps,{views:e,activeViewId:je,onViewChange:Ie,viewTypeIcons:Bp,config:{reorderable:!1,showAddButton:ve,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:ve?qe:void 0,onRenameView:ve?Ve:void 0,onDeleteView:ve?He:void 0,onPinView:ve?Ue:void 0,onSetDefaultView:ve?We:void 0,onConfigView:ve?Ke:void 0,onManageViews:ve?()=>oe(!0):void 0}),ve&&(0,Z.jsx)(ds,{open:F,onOpenChange:oe,views:e,activeViewId:je,viewTypeIcons:Bp,onRename:Ve,onDelete:He,onSetDefault:We,onSetPinned:Ue,onReorder:Ge,onAddView:qe,onConfigView:Ke})]})})})(),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[nt.mode===`split`&&nt.isOpen?(0,Z.jsx)(bn,{...nt,setIsOpen:e=>{e||rt()},title:g(L),onExpand:at,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${L.name}`,mainContent:(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,Z.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Z.jsx)(ys,{schema:ct,dataSource:e,views:st,activeViewId:je,onViewChange:Ie,onEdit:e=>n?.(e),onRowClick:(e,t)=>{it(e,t)},renderListView:ot,onCreateView:Re,onViewAction:ze})})}),typeof me==`number`&&(0,Z.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:h(`console.objectView.recordCount`,{count:me})})]}),children:r=>{let i=r.id||r._id;return(0,Z.jsx)(Np,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}}):(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,Z.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Z.jsx)(ys,{schema:ct,dataSource:e,views:st,activeViewId:je,onViewChange:Ie,onEdit:e=>n?.(e),onRowClick:(e,t)=>{it(e,t)},renderListView:ot,onCreateView:Re,onViewAction:ze})})})}),(0,Z.jsx)(Vu,{open:p&&ve,sections:[{title:`View Configuration`,data:Ne},{title:`Object Definition`,data:L}]}),(0,Z.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${ee&&ve?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Z.jsx)(mf,{open:ee&&ve,onClose:()=>{te(!1),re(`edit`)},mode:M,activeView:Ne,objectDef:L,recordCount:me,onSave:fe,onViewUpdate:Pe,onCreate:pe,metadataClient:j,onAfterChange:()=>ye(e=>e+1)})}),(0,Z.jsx)(vf,{open:ie&&ve,onOpenChange:P,existingLabels:ke.map(e=>e.label).filter(Boolean),objectDef:L,onCreate:e=>pe(e)})]}),nt.mode!==`split`&&(0,Z.jsx)(bn,{...nt,setIsOpen:e=>{e||rt()},title:g(L),onExpand:at,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${L.name}`,children:r=>{let i=r.id||r._id;return(0,Z.jsx)(Np,{dataSource:e,objects:t,onEdit:n,objectNameOverride:L.name,recordIdOverride:i,embedded:!0})}})]}),B.dialogs]})}var Gp=t({RecordFormPage:()=>Kp});function Kp({mode:e}){let{appName:t,objectName:n,recordId:r}=s(),i=v(),[a]=m(),o=be(),{objects:c,loading:l}=ce(),{t:u}=z(),{objectLabel:d}=li(),{user:f,getAuthConfig:p}=S(),[g,_]=(0,X.useState)({});(0,X.useEffect)(()=>{let e=!1;return p().then(t=>{e||_(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[p]);let y=(0,X.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of a.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,a.toString()]),b=(0,X.useMemo)(()=>c.find(e=>e.name===n),[c,n]),x=`/apps/${t}`,C=`${x}/${n}`,w=e===`edit`&&r?`${x}/${n}/record/${encodeURIComponent(r)}`:C,T=(0,X.useCallback)(()=>{typeof window<`u`&&window.history.length>1?i(-1):i(w,{replace:!0})},[i,w]),E=b?d(b):n??``,D=e===`create`?u(`form.createTitle`,{object:E,defaultValue:`New ${E}`}):u(`form.editTitle`,{object:E,defaultValue:`Edit ${E}`}),O=(0,X.useCallback)(()=>{q.success(e===`create`?u(`form.createSuccess`,{object:E,defaultValue:`${E} created successfully`}):u(`form.updateSuccess`,{object:E,defaultValue:`${E} updated successfully`})),T()},[e,u,E,T]),k=(0,X.useCallback)(()=>{T()},[T]),A=(0,X.useMemo)(()=>f?{name:f.name,email:f.email,role:f.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[f]),j=(0,X.useMemo)(()=>new B({user:A,app:{name:t},data:{}}),[A,t]),ee=(0,X.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:xc(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>xc(e.visible,j)).map(([e])=>e):[],[b,j]);return l?(0,Z.jsx)(Sf,{}):b?(0,Z.jsx)(yc,{user:A,app:{name:t},data:{},features:g,children:(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,Z.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,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":u(`common.back`,{defaultValue:`Back`}),children:(0,Z.jsx)(Wt,{className:`h-4 w-4`})}),(0,Z.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(h,{to:C,className:`hover:text-foreground transition-colors`,children:E}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,Z.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:D}),(0,Z.jsx)(bf,{managedBy:b?.managedBy,className:`ml-1`})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,Z.jsx)(Bo,{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`?u(`form.createDescription`,{object:E,defaultValue:`Create a new ${E}.`}):u(`form.editDescription`,{object:E,defaultValue:`Edit this ${E}.`}),layout:`vertical`,fields:ee,subforms:b.form?.subforms??b.formViews?.default?.subforms,onSuccess:O,onCancel:k,showSubmit:!0,showCancel:!0,submitText:u(`form.saveRecord`,{defaultValue:`Save`}),cancelText:u(`common.cancel`,{defaultValue:`Cancel`})},dataSource:o??void 0},`${e}:${n}:${r??`new`}`)})})]})}):(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(kt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:u(`empty.objectNotFound`)}),(0,Z.jsx)(Kt,{children:u(`empty.objectNotFoundDescription`,{name:n})}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsxs)(K,{variant:`outline`,onClick:()=>i(x),children:[(0,Z.jsx)(Wt,{className:`mr-2 h-4 w-4`}),u(`empty.back`)]})})]})})}var qp={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:ur},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:Eo},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:co},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Jr},area:{id:`area`,label:`Area chart`,category:`chart`,icon:Wn},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:Di},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:dn},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Pi},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Zt},table:{id:`table`,label:`Data table`,category:`data`,icon:br},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:kt},list:{id:`list`,label:`Record list`,category:`data`,icon:mn},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:cr}},Jp={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},Yp=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(qp).filter(t=>t.category===e)})),Xp=Dr;function Zp({onAdd:e,label:t=`Add widget`}){let[n,r]=X.useState(!1),[i,a]=X.useState(``),o=X.useRef(null),s=X.useRef(null);X.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=X.useMemo(()=>{let e=i.trim().toLowerCase();return e?Yp.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):Yp},[i]);return(0,Z.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),t]}),n&&(0,Z.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-md border bg-popover shadow-md`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Z.jsx)(Co,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.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,Z.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:c.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):c.map(t=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:Jp[t.category]}),t.types.map(t=>(0,Z.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,Z.jsx)(qp[t.id]?.icon??Xp,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Z.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,Z.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var Qp={io:`input`,unrepresentable:`any`},$p=new Set([`widgets`,`label`,`description`,`name`]),em,tm=!1;function nm(){if(em||tm)return em;try{em=Se(De,Qp)}catch(e){tm=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return em}var rm;function im(){if(rm)return rm;if(!(!Oe||typeof Oe!=`object`)){try{let e=JSON.parse(JSON.stringify(Oe));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!$p.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),rm=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return rm}}var am=new Set([`name`,`label`,`description`,`widgets`]);function om({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=X.useCallback(e=>J(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=X.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=zs(`widget`,l.map(e=>e?.id).filter(Boolean)),r=qp[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;t({widgets:Bs(l,{id:n,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:bs(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:xs(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=X.useState(null),[g,_]=X.useState(null),{schema:v,form:y}=X.useMemo(()=>Is({bundledSchema:nm(),bundledForm:im(),serverSchema:a,excludeFields:am,sectionTitle:J(`engine.inspector.moreFields`,r)}),[a,r]);return(0,Z.jsxs)(Vs,{kindLabel:o(`engine.inspector.dashboard.kind`),title:String(s||e.name||o(`engine.inspector.dashboard.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.dashboard.close`),hideClose:!0,children:[(0,Z.jsx)(ws,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,Z.jsx)(ws,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,Z.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.widgetsEmpty`)}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=qp[e?.type]?.icon??Xp;return(0,Z.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,Z.jsx)(je,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,Z.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,Z.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,Z.jsx)(Zp,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,Z.jsx)(Ms,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.noSchema`)})})]})}var sm=[{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`}],cm=[`count`,`sum`,`avg`,`min`,`max`],lm=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function um(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 dm({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Z.jsx)(pm,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=um(e,t.id);if(!s)return(0,Z.jsx)(pm,{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})}let f=c,p=typeof f.dataset==`string`?f.dataset:``,m=Array.isArray(f.dimensions)?f.dimensions.join(`, `):``,h=Array.isArray(f.values)?f.values.join(`, `):``,g=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean);function _(e){n({widgets:xs(u,l,e)}),c.id&&i?.({kind:`widget`,id:c.id,label:c.title??void 0})}return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:J(`engine.inspector.widget.kind`,o)}),(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:c.title||t.label||`Widget ${l+1}`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Z.jsx)(Ss,{index:l,total:u.length,onMove:_,upLabel:J(`engine.inspector.reorder.up`,o),downLabel:J(`engine.inspector.reorder.down`,o),disabled:a}),(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:J(`engine.inspector.widget.close`,o),"aria-label":J(`engine.inspector.widget.close`,o),children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsx)(fm,{id:`widget-title`,label:J(`engine.inspector.widget.title`,o),children:(0,Z.jsx)(W,{id:`widget-title`,value:c.title??``,onChange:e=>d({title:e.target.value}),disabled:a})}),(0,Z.jsx)(fm,{id:`widget-type`,label:J(`engine.inspector.widget.type`,o),children:(0,Z.jsxs)(Rn,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Z.jsx)(ar,{id:`widget-type`,children:(0,Z.jsx)(Tt,{})}),(0,Z.jsx)(jo,{children:sm.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}),(0,Z.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed border-primary/40 bg-primary/5 p-3`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-primary/80`,children:J(`engine.inspector.widget.datasetSection`,o)}),(0,Z.jsxs)(fm,{id:`widget-dataset`,label:J(`engine.inspector.widget.dataset`,o),children:[(0,Z.jsx)(W,{id:`widget-dataset`,value:p,placeholder:J(`engine.inspector.widget.datasetPlaceholder`,o),onChange:e=>d({dataset:e.target.value||void 0}),disabled:a}),(0,Z.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:J(`engine.inspector.widget.datasetHint`,o)})]}),p&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(fm,{id:`widget-dimensions`,label:J(`engine.inspector.widget.dimensions`,o),children:[(0,Z.jsx)(W,{id:`widget-dimensions`,value:m,placeholder:J(`engine.inspector.widget.dimensionsPlaceholder`,o),onChange:e=>d({dimensions:g(e.target.value)}),disabled:a}),(0,Z.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:J(`engine.inspector.widget.dimensionsHint`,o)})]}),(0,Z.jsxs)(fm,{id:`widget-values`,label:J(`engine.inspector.widget.values`,o),children:[(0,Z.jsx)(W,{id:`widget-values`,value:h,placeholder:J(`engine.inspector.widget.valuesPlaceholder`,o),onChange:e=>d({values:g(e.target.value)}),disabled:a}),(0,Z.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:J(`engine.inspector.widget.valuesHint`,o)})]})]})]}),(0,Z.jsx)(fm,{id:`widget-object`,label:J(`engine.inspector.widget.object`,o),children:(0,Z.jsx)(W,{id:`widget-object`,value:c.object??``,placeholder:`e.g. order`,onChange:e=>d({object:e.target.value}),disabled:a})}),(0,Z.jsx)(fm,{id:`widget-value-field`,label:J(`engine.inspector.widget.valueField`,o),children:(0,Z.jsx)(W,{id:`widget-value-field`,value:c.valueField??``,placeholder:`e.g. amount`,onChange:e=>d({valueField:e.target.value}),disabled:a})}),(0,Z.jsx)(fm,{id:`widget-category-field`,label:J(`engine.inspector.widget.categoryField`,o),children:(0,Z.jsx)(W,{id:`widget-category-field`,value:c.categoryField??``,placeholder:`e.g. status`,onChange:e=>d({categoryField:e.target.value}),disabled:a})}),(0,Z.jsx)(fm,{id:`widget-aggregate`,label:J(`engine.inspector.widget.aggregate`,o),children:(0,Z.jsxs)(Rn,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Z.jsx)(ar,{id:`widget-aggregate`,children:(0,Z.jsx)(Tt,{})}),(0,Z.jsx)(jo,{children:cm.map(e=>(0,Z.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Z.jsx)(fm,{id:`widget-color`,label:J(`engine.inspector.widget.color`,o),children:(0,Z.jsxs)(Rn,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Z.jsx)(ar,{id:`widget-color`,children:(0,Z.jsx)(Tt,{})}),(0,Z.jsx)(jo,{children:lm.map(e=>(0,Z.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Z.jsx)(fm,{id:`widget-w`,label:J(`engine.inspector.widget.width`,o),children:(0,Z.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,Z.jsx)(fm,{id:`widget-h`,label:J(`engine.inspector.widget.height`,o),children:(0,Z.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,Z.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Z.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:J(`engine.inspector.widget.remove`,o)})})]})}function fm({id:e,label:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function pm({message:e,onClose:t,locale:n}){return(0,Z.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,Z.jsx)(`p`,{children:e}),(0,Z.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:J(`engine.inspector.widget.close`,n)})]})}function mm({open:e,onClose:t,schema:n,selectedWidgetId:r,onSelectWidget:i,onSave:a,onChange:o,onRemoveWidget:s,name:c,metadataClient:l,onAfterChange:u}){let{t:d}=z(),f=(0,X.useMemo)(()=>Fs(),[]),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(0),_=(0,X.useCallback)(e=>{m(!0),o({...n??{},...e})},[n,o]),v=(0,X.useCallback)(e=>{o(e),m(!1)},[o]),y=(0,X.useCallback)(e=>{i(e&&e.kind===`widget`?e.id:null)},[i]),b=Array.isArray(n?.widgets)?n.widgets:[],x=r?b.find(e=>e?.id===r):null;if(!e)return null;let S=typeof n?.name==`string`?n.name:``,C=x?d(`widget.editor.title`,{defaultValue:`Edit widget`}):d(`dashboard.editor.title`,{defaultValue:`Edit dashboard`});return(0,Z.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`dashboard-config-panel`,role:`complementary`,"aria-label":C,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[x&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>i(null),className:`h-7 w-7 p-0`,"aria-label":d(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),title:d(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),"data-testid":`dashboard-config-back`,children:(0,Z.jsx)(Wt,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:C})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[x&&s&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>s(r),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"aria-label":d(`widget.editor.delete`,{defaultValue:`Delete widget`}),title:d(`widget.editor.delete`,{defaultValue:`Delete widget`}),"data-testid":`widget-delete-button`,children:(0,Z.jsx)(In,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":d(`common.close`,{defaultValue:`Close`}),"data-testid":`dashboard-config-close`,children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:x?(0,Z.jsx)(dm,{type:`dashboard`,name:S,draft:n??{},selection:{kind:`widget`,id:r},onPatch:_,onClearSelection:()=>i(null),onSelectionChange:y,readOnly:!1,locale:f}):(0,Z.jsx)(om,{type:`dashboard`,name:S,draft:n??{},onPatch:_,onSelectionChange:y,readOnly:!1,locale:f})}),(0,Z.jsxs)(`div`,{"data-testid":`dashboard-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,Z.jsx)(cf,{type:`dashboard`,name:c||S||void 0,metadataClient:l,dirty:p,onResume:v,savedSignal:h,onAfterChange:u}),(0,Z.jsx)(K,{size:`sm`,onClick:()=>{a(n??{}),m(!1),g(e=>e+1)},"data-testid":`dashboard-config-save`,children:d(`common.save`,{defaultValue:`Save`})})]})]})}var hm=t({DashboardView:()=>xm}),gm=[{type:`metric`,label:`KPI Metric`,Icon:At},{type:`bar`,label:`Bar Chart`,Icon:yo},{type:`line`,label:`Line Chart`,Icon:Jr},{type:`pie`,label:`Pie Chart`,Icon:Di},{type:`table`,label:`Table`,Icon:br},{type:`pivot`,label:`Pivot`,Icon:ft}],_m=0;function vm(){return _m+=1,`widget_${Date.now()}_${_m}`}function ym(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:vm()})}}function bm(e){let t=gm.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function xm({dataSource:e}){let{dashboardName:t}=s(),{showDebug:n}=Hu(),r=be(),i=ks(),{t:a}=z(),{dashboardLabel:o,dashboardDescription:c}=li(),{user:l}=S(),u=l?.role===`admin`,[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),y=(0,X.useCallback)(e=>{v(t=>(t&&t.resolve(e),null))},[]),b=(0,X.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;v({schema:n,resolve:t})}),[]),x=(0,X.useMemo)(()=>({export_dashboard_pdf:async()=>{q.info(a(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return q.error(a(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(q.info(a(`dashboardActions.forecastSoon`)),{success:!0})}),[a]);(0,X.useEffect)(()=>{f(!0),O(null),m(!1),g(null),queueMicrotask(()=>f(!1))},[t]);let{dashboards:C,objects:w,refresh:T}=ce(),E=C?.find(e=>e.name===t),[D,O]=(0,X.useState)(null);(0,X.useEffect)(()=>{p||O(null)},[E]);let k=(0,X.useCallback)(async e=>{try{i&&await nf(`dashboard`,t,e,{metadataClient:i}),T().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}`)}},[i,t,T]),A=(0,X.useCallback)(()=>{O(ym(E)),m(!0)},[E]),j=(0,X.useCallback)(()=>{m(!1),g(null)},[]),ee=(0,X.useCallback)(e=>{if(!D)return;let t=vm(),n={id:t,title:bm(e),type:e,layout:{x:0,y:D.widgets?.length??0,w:D.columns??2,h:1}},r={...D,widgets:[...D.widgets||[],n]};O(r),k(r),g(t)},[D,k]),te=(0,X.useCallback)(e=>{if(!D)return;let t={...D,widgets:D.widgets.filter(t=>t.id!==e)};O(t),k(t),h===e&&g(null)},[D,h,k]),M=(0,X.useCallback)(e=>{let t=D||E;if(!t)return;let n={...t,widgets:e};O(n),k(n)},[D,E,k]),ne=(D||E)??null,re=(0,X.useMemo)(()=>new Set((w||[]).map(e=>e?.name).filter(Boolean)),[w]),N=D||E,ie=(0,X.useMemo)(()=>{if(!N||re.size===0)return N;let e=N.widgets;if(!Array.isArray(e)||e.length===0)return N;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?re.has(t):!0});return t.length===e.length?N:{...N,widgets:t}},[N,re]);return d?(0,Z.jsx)(xf,{}):E?(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=wl((ie||E).title,a),t=wl(E.label,a),n=o({name:E.name,label:t});return(0,Z.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||E.name})})(),(()=>{let e=(ie||E).description??E.description,t=c({name:E.name,description:wl(e,a)});return t?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,Z.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[p&&(0,Z.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:gm.map(({type:e,label:t,Icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>ee(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,Z.jsx)(Oo,{className:`h-3 w-3`}),(0,Z.jsx)(n,{className:`h-3 w-3`})]},e))}),u&&(0,Z.jsxs)(`button`,{type:`button`,onClick:A,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,Z.jsx)(Bt,{className:`h-3.5 w-3.5`}),a(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,Z.jsx)(Hs,{schema:ie,dataSource:e,designMode:p,selectedWidgetId:h,onWidgetClick:g,onWidgetsReorder:M,modalHandler:b,scriptHandlers:x,hideHeaderText:!0})}),(0,Z.jsx)(mm,{open:p&&u,onClose:j,schema:ne,selectedWidgetId:h,onSelectWidget:g,onSave:k,onChange:O,onRemoveWidget:te,name:t,metadataClient:i,onAfterChange:()=>T().catch(()=>{})}),(0,Z.jsx)(Vu,{open:n,sections:[{title:`Dashboard Configuration`,data:ie}]})]}),_&&_.schema?.objectName?(0,Z.jsx)(Ro,{schema:{type:`object-form`,formType:`modal`,objectName:_.schema.objectName,mode:_.schema.mode||`create`,recordId:_.schema.recordId,title:_.schema.title,description:_.schema.description,fields:_.schema.fields,open:!0,onOpenChange:e=>{e||y({success:!1})},onSuccess:e=>{y({success:!0,reload:!0,data:e})},onCancel:()=>{y({success:!1})},showSubmit:!0,showCancel:!0},dataSource:r}):_?(0,Z.jsx)(mt,{open:!0,onOpenChange:e=>{e||y({success:!1})},children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:_.schema?.title||a(`actionDialog.defaultActionTitle`)}),_.schema?.description&&(0,Z.jsx)(Yt,{children:_.schema.description})]}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:()=>y({success:!1}),children:a(`actionDialog.cancel`)}),(0,Z.jsx)(K,{onClick:()=>y({success:!0}),children:a(`actionDialog.ok`)})]})]})}):null]}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(Dt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:a(`empty.dashboardNotFound`)}),(0,Z.jsx)(Kt,{children:a(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Sm=t({PageView:()=>Cm});function Cm(){let{t:e}=z(),{pageName:t}=s(),[n]=m(),{showDebug:r}=Hu(),i=v(),a=u(),{user:o}=S(),c=o?.role===`admin`,{pages:l,objects:d}=ce(),f=be(),[p,h]=(0,X.useState)(0),g=l?.find(e=>e.name===t);if(!g)return(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(oo,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:e(`empty.pageNotFound`)}),(0,Z.jsx)(Kt,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let _=Object.fromEntries(n.entries()),y=a.pathname.match(/\/apps\/([^/]+)/)?.[1],b=c&&!!y&&!!t;return(0,Z.jsx)(Lp,{dataSource:f,objects:d,onRefresh:()=>h(e=>e+1),children:(0,Z.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:[b&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{b&&i(`/apps/${y}/metadata/page/${encodeURIComponent(t)}`)},className:`absolute right-3 top-3 z-30 inline-flex items-center gap-1.5 rounded-md border border-input bg-background/90 px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm backdrop-blur hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-in-studio-button`,title:e(`common.editInStudio`,{defaultValue:`Edit in studio`}),children:[(0,Z.jsx)(Bt,{className:`h-3.5 w-3.5`}),e(`common.editInStudio`,{defaultValue:`Edit in studio`})]}),(0,Z.jsx)(ne,{schema:{...g,type:g.type||`page`,context:{...g.context,params:_,refreshKey:p}}},p)]}),(0,Z.jsx)(Vu,{open:r,sections:[{title:`Page Configuration`,data:g}]})]})})}var wm={io:`input`,unrepresentable:`any`},Tm=new Set([`columns`,`objectName`,`name`]),Em,Dm=!1;function Om(){if(Em||Dm)return Em;try{Em=Se(Te,wm)}catch(e){Dm=!0,typeof console<`u`&&console.warn(`[report-schema] failed to derive Report JSONSchema from spec`,e)}return Em}var km;function Am(){if(km)return km;if(!(!Ee||typeof Ee!=`object`)){try{let e=JSON.parse(JSON.stringify(Ee));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Tm.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),km=e}catch(e){typeof console<`u`&&console.warn(`[report-schema] failed to prepare reportForm from spec`,e);return}return km}}var jm=new Set([`type`,`objectName`,`label`,`name`,`columns`]),Mm={tabular:`engine.inspector.report.type.tabular`,summary:`engine.inspector.report.type.summary`,matrix:`engine.inspector.report.type.matrix`,joined:`engine.inspector.report.type.joined`};function Nm(e,t){return X.useMemo(()=>{let n=Om()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`tabular`,`summary`,`matrix`,`joined`]).map(e=>{let n=Mm[e],r=n?J(n,t):e;return{value:e,label:r===n?e:r}});return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:e}),r},[e,t])}function Pm({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,objectFieldsOverride:a,serverSchema:o}){let s=X.useCallback(e=>J(e,r),[r]),c=typeof e.type==`string`?e.type:`tabular`,l=Nm(c,r),u=typeof e.label==`string`?e.label:``,d=typeof e.objectName==`string`?e.objectName:``,f=X.useMemo(()=>Array.isArray(e.columns)?e.columns:[],[e.columns]),{fields:p,loading:m,error:h}=sd(d||void 0,a),g=X.useMemo(()=>{let e=new Map;for(let t of p)e.set(t.name,t.type);return e},[p]),_=X.useMemo(()=>({objectFields:p.map(e=>({name:e.name,label:e.label,type:e.type}))}),[p]),v=X.useMemo(()=>{let e=new Set;for(let t of f)t?.field&&e.add(t.field);return e},[f]),y=e=>{let n={field:e.name};e.label&&e.label!==e.name&&(n.label=e.label);let r=Bs(f,n);t({columns:r}),i?.({kind:`column`,id:`columns[${r.length-1}]`,label:e.label})},b=e=>{t({columns:bs(f,e,null)})},x=(e,n)=>{e!==n&&t({columns:xs(f,e,n)})},S=e=>{let t=f[e];i?.({kind:`column`,id:`columns[${e}]`,label:t?.label||t?.field||`columns[${e}]`})},[C,w]=X.useState(null),[T,E]=X.useState(null),{schema:D,form:O}=X.useMemo(()=>Is({bundledSchema:Om(),bundledForm:Am(),serverSchema:o,excludeFields:jm,sectionTitle:J(`engine.inspector.moreFields`,r)}),[o,r]);return(0,Z.jsxs)(Vs,{kindLabel:s(`engine.inspector.report.kind`),title:String(u||e.name||s(`engine.inspector.report.kind`)),onClose:()=>{},closeLabel:s(`engine.inspector.report.close`),hideClose:!0,children:[(0,Z.jsx)(ws,{label:s(`engine.inspector.report.label`),value:u,onCommit:e=>t({label:e}),placeholder:s(`engine.inspector.report.labelPlaceholder`),disabled:n}),(0,Z.jsx)(Rs,{label:s(`engine.inspector.report.type`),value:c,options:l,onCommit:e=>t({type:e}),disabled:n}),(0,Z.jsx)(ws,{label:s(`engine.inspector.report.object`),value:d,onCommit:e=>t({objectName:e}),placeholder:s(`engine.inspector.report.objectPlaceholder`),disabled:n,mono:!0}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:s(`engine.inspector.report.columns`)}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:f.length})]}),f.length===0?(0,Z.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:s(`engine.inspector.report.columnsEmpty`)}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:f.map((e,t)=>(0,Z.jsx)(yd,{index:t,label:e.label||e.field||`col ${t+1}`,fieldName:e.field,fieldType:g.get(e.field??``)??`text`,selected:!1,canEdit:!n,dragging:C!==null,dropBefore:T===t&&C!==null&&C!==t,onSelect:()=>S(t),onRemove:()=>b(t),onDragStart:()=>w(t),onDragEnd:()=>{w(null),E(null)},onDragOverRow:()=>E(t),onDropRow:()=>{C!=null&&C!==t&&x(C,t),w(null),E(null)}},t))}),!n&&(0,Z.jsx)(bd,{fields:p,usedNames:v,loading:m,error:h,onAdd:y})]}),(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:D?(0,Z.jsx)(Ms,{schema:D,form:O,value:e,hiddenFields:[`type`,`objectName`,`label`,`name`,`columns`],readOnly:n,widgetContext:_,onChange:e=>t(e)}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:s(`engine.inspector.report.noSchema`)})})]})}function Fm(e){return Array.isArray(e)?e.map(e=>({name:e.value,label:e.label||e.value,type:e.type||`text`,hidden:!1})):[]}function Im({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,availableFields:a,name:o,metadataClient:s,onAfterChange:c}){let{t:l}=z(),u=(0,X.useMemo)(()=>Fs(),[]),d=(0,X.useMemo)(()=>Fm(a),[a]),[f,p]=(0,X.useState)(!1),m=(0,X.useMemo)(()=>({...n??{}}),[n]),[h,g]=(0,X.useState)(m),_=(0,X.useRef)(h),v=(0,X.useRef)(m);v.current!==m&&(v.current=m,_.current=m,g(m),p(!1));let y=(0,X.useCallback)(e=>{let t={..._.current,...e};if(_.current=t,g(t),p(!0),i)for(let[n,r]of Object.entries(e))i(n,r,t)},[i]),b=(0,X.useCallback)(()=>{r(_.current),p(!1),t()},[r,t]),x=(0,X.useCallback)(e=>{let t={...e};_.current=t,g(t),p(!1)},[]),S=(0,X.useCallback)(()=>{t()},[t]);return e?(0,Z.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`report-config-panel`,role:`complementary`,"aria-label":l(`report.editor.title`,{defaultValue:`Edit report`}),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:l(`report.editor.title`,{defaultValue:`Edit report`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":l(`common.close`,{defaultValue:`Close`}),"data-testid":`report-config-close`,children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,Z.jsx)(Pm,{type:`report`,name:typeof h.name==`string`?h.name:``,draft:h,readOnly:!1,locale:u,objectFieldsOverride:d,onPatch:y})}),(0,Z.jsxs)(`div`,{"data-testid":`report-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,Z.jsx)(cf,{type:`report`,name:o,metadataClient:s,dirty:f,onResume:x,onAfterChange:c}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:S,"data-testid":`report-config-discard`,children:l(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(K,{size:`sm`,onClick:b,"data-testid":`report-config-save`,children:l(`common.save`,{defaultValue:`Save`})})]})]}):null}var Lm=t({ReportView:()=>Vm}),Rm=(0,X.lazy)(()=>d(()=>import(`./plugin-report-qca5M0OZ.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),zm=(0,X.lazy)(()=>d(()=>import(`./plugin-report-qca5M0OZ.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),Bm=[{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 Vm({dataSource:e}){let{t}=z(),{reportName:n}=s(),{showDebug:r}=Hu();be();let i=ks(),{user:a}=S(),o=a?.role===`admin`,[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(0),{reports:f,objects:p,loading:m,refresh:h}=ce(),g=f?.find(e=>e.name===n),[_,v]=(0,X.useState)(g),[y,b]=(0,X.useState)(null),[x,C]=(0,X.useState)([]),[w,T]=(0,X.useState)(!1),E=(0,X.useCallback)(e=>{if(!e||!p?.length)return;let t=p.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`}))},[p]),D=(0,X.useMemo)(()=>{let e=y||_;return E(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??Bm},[y,_,E]),O=(0,X.useCallback)(async e=>{try{i&&(await nf(`report`,n,e,{metadataClient:i}),h().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,n,h]),k=(0,X.useCallback)(()=>{b(_),l(!0),d(e=>e+1)},[_]),A=(0,X.useCallback)(()=>{l(!1)},[]),j=(0,X.useMemo)(()=>y||_,[u]),ee=(0,X.useCallback)(e=>{b(e),O(e),d(e=>e+1)},[O]),te=(0,X.useCallback)((e,t)=>{b(n=>({...n,[e]:t}))},[]);(0,X.useEffect)(()=>{v(g)},[g]),(0,X.useEffect)(()=>{c||b(null)},[g]);let M=y||_,ne=(0,X.useMemo)(()=>JSON.stringify(M?.filters),[M?.filters]),re=(0,X.useMemo)(()=>JSON.stringify(M?.dataSource),[M?.dataSource]),N=(0,X.useMemo)(()=>JSON.stringify(M?.data),[M?.data]);if((0,X.useEffect)(()=>{if(!M||!e){C([]);return}if(M.data&&Array.isArray(M.data)){C(M.data);return}if(M.dataSource){(async()=>{T(!0);try{let t=M.dataSource.object||M.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),C([]);return}C((await e.find(t,{$filter:M.dataSource.filter,$orderby:M.dataSource.sort,$top:M.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),C([])}finally{T(!1)}})();return}if(M.objectName){(async()=>{T(!0);try{C((await e.find(M.objectName,{$filter:M.filters,$orderby:M.sort,$top:M.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),C([])}finally{T(!1)}})();return}C([])},[M?.objectName,M?.limit,ne,re,N,e]),m)return(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsx)(V,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!g||!_)return!m&&!g?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Z.jsx)(yo,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:t(`empty.reportNotFound`)}),(0,Z.jsx)(Kt,{children:t(`empty.reportNotFoundDescription`,{name:n})})]})}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsx)(V,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let ie=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?p?.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},P=y||_,F=!!(P&&(typeof P.dataset==`string`||P.type===`joined`&&Array.isArray(P.blocks)&&P.blocks.some(e=>typeof e?.dataset==`string`)))||!!(P&&P.objectName&&(P.type===`matrix`||P.type===`joined`||P.type===`summary`||P.type===`tabular`||P.type===void 0||Array.isArray(P.groupingsAcross)&&P.groupingsAcross.length>0||Array.isArray(P.columns))),ae={type:`report-viewer`,report:ie(P),data:x,showToolbar:!0,allowExport:!0,loading:w};return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:P.title||P.label||`Report Viewer`}),P.description&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:P.description})]}),(0,Z.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:o&&(0,Z.jsxs)(`button`,{type:`button`,onClick:k,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,Z.jsx)(Bt,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,Z.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:F?(0,Z.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Z.jsx)(zm,{schema:P,dataSource:e})}):(0,Z.jsx)(Rm,{schema:ae})})})}),(0,Z.jsx)(Im,{open:c&&o,onClose:A,config:j,onSave:ee,onFieldChange:te,availableFields:D,getFieldsForObject:E,name:n,metadataClient:i,onAfterChange:()=>h().catch(()=>{})}),(0,Z.jsx)(Vu,{open:r,sections:[{title:`Report Configuration`,data:P}]})]})]})}var Hm=t({SearchResultsPage:()=>Km});function Um(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Um(n.children)):t.push(n);return t}var Wm={object:kt,dashboard:Dt,page:oo,report:yo},Gm={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 Km(){let{t:e}=z(),{appName:t}=s(),[n,r]=m(),[i,a]=(0,X.useState)(n.get(`q`)||``),{apps:o}=ce(),c=o||[],l=c.find(e=>e.name===t)||c[0],u=`/apps/${t}`,{user:d}=S(),f=(0,X.useMemo)(()=>{if(!l)return[];let e=Um(l.navigation||[]),t={currentUserId:d?.id??null};return e.map(e=>{let{href:n}=Yo(e,u,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!==`#`)},[l,u,d?.id]),p=(0,X.useMemo)(()=>{if(!i.trim())return f;let e=i.toLowerCase();return f.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[f,i]),g=e=>{a(e),r(e?{q:e}:{})},_=(0,X.useMemo)(()=>{let e={};for(let t of p)(e[t.type]||=[]).push(t);return e},[p]);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(h,{to:u,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Z.jsx)(Wt,{className:`h-4 w-4`}),e(`search.back`)]}),(0,Z.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`search.title`)})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:e(`search.placeholder`)}),(0,Z.jsx)(Co,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Z.jsx)(W,{id:`search-results-input`,value:i,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:i.trim()?e(p.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:p.length,query:i}):e(`search.itemsAvailable`,{count:f.length})}),p.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,Z.jsx)(Co,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,Z.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:e(`search.noResults`)}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:e(`search.noResultsHint`)})]}):(0,Z.jsx)(`div`,{className:`space-y-6`,children:Object.entries(_).map(([t,n])=>{let r=Wm[t]||kt,i=`search.type${t.charAt(0).toUpperCase()}${t.slice(1)}s`;return`${t.charAt(0).toUpperCase()}${t.slice(1)}`,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,Z.jsx)(r,{className:`h-4 w-4`}),e(i),(0,Z.jsx)(H,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,Z.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=Wm[t.type]||kt,r=`search.badge${t.type.charAt(0).toUpperCase()}${t.type.slice(1)}`;return(0,Z.jsx)(h,{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,Z.jsx)(Vt,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Z.jsxs)(ka,{className:`flex items-center gap-3 p-3`,children:[(0,Z.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${Gm[t.type]||``}`,children:(0,Z.jsx)(n,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium truncate`,children:t.label}),t.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:t.description})]}),(0,Z.jsx)(H,{variant:`outline`,className:`text-xs shrink-0`,children:e(r)})]})})},t.id)})})]},t)})})]})}function qm(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 Jm(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 Ym=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=qm(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(Jm)};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 Xm(){let e=be();return(0,X.useMemo)(()=>e?new Ym(e):null,[e])}var Zm=0;function Qm(e=`nav`){return`${e}_${Date.now()}_${++Zm}`}function $m(e,t){return[...e,t]}function eh(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:eh(e.children,t,n)}:e)}function th(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:th(i.children,t,n,r)}:i})}function nh(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function rh(){let e=be(),{apps:t,refresh:n}=ce(),{t:r}=z(),i=(0,X.useRef)(e);i.current=e;let a=(0,X.useRef)(n);a.current=n;let o=(0,X.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,X.useCallback)(e=>t.find(t=>t.name===e),[t]),c=(0,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=$m(a,{id:Qm(`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,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=$m(a,{id:Qm(`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,X.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=eh(i,`page`,t);if(nh(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,X.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=eh(i,`dashboard`,t);if(nh(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,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=th(a,`page`,t,n);if(nh(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,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=th(a,`dashboard`,t,n);if(nh(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,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,X.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,X.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await p(t,e,n)}},[t,p])}}function ih(){let{pages:e,dashboards:t,apps:n}=ce(),r=be(),i=(0,X.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=rh(),l=(0,X.useRef)(null),u=(0,X.useRef)(null),d=(0,X.useRef)(0),f=(0,X.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,X.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 ah=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function oh(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function sh(e){try{return decodeURIComponent(e)}catch{return e}}function ch({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=Wo(),o=(0,X.useRef)(n);o.current=n,(0,X.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}:${sh(t)}`,label:sh(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!ah.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:oh(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:oh(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:oh(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var lh=`objectstack:ai-chat-conversation-id`,uh=`objectstack:ai-chat-messages`;function dh(e,t){return t?`${lh}:${e}:${t}`:`${lh}:${e}`}function fh(e){try{return localStorage.getItem(e)??void 0}catch{return}}function ph(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function mh(e){return`${uh}:${e}`}function hh(e){try{let t=localStorage.getItem(mh(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function gh(e,t){if(e)try{if(t.length===0){localStorage.removeItem(mh(e));return}localStorage.setItem(mh(e),JSON.stringify(t))}catch{}}function _h(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[])t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{}});if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function vh(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?vh(e.parts):[]}function yh(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=vh(e.content);i.length!==0&&t.push({id:e.id??`msg-${n}`,role:r,parts:i})}),t}async function bh(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 xh(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 Sh(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Ch(e){let{userId:t,scope:n,apiBase:r,activeId:i}=e,[a,o]=(0,X.useState)(void 0),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!!t),d=(0,X.useRef)(!0),f=(0,X.useRef)(void 0);return(0,X.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]),(0,X.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=dh(t,n);return u(!0),(async()=>{try{if(i){let n=await bh(r,i);if(e)return;if(n){ph(s,n.id),o(n.id);let e=yh(n.messages);c(e.length>0?e:hh(n.id)),f.current=t;return}ph(s,void 0),gh(i,[])}else{let n=fh(s);if(n){let i=await bh(r,n);if(e)return;if(i){o(i.id);let e=yh(i.messages);c(e.length>0?e:hh(i.id)),f.current=t;return}ph(s,void 0),gh(n,[])}}let n=await xh(r);if(e)return;ph(s,n.id),o(n.id),c(yh(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,X.useCallback)(async()=>{if(!t)return;let e=dh(t,n);u(!0);try{a&&await Sh(r,a),gh(a,[]),ph(e,void 0);let t=await xh(r);if(ph(e,t.id),gh(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])}}var wh=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function Th(e){let t=e?.trim().toLowerCase();return!t||wh.has(t)}function Eh(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=Dh(n.content);if(e)return e}}let n=t[t.length-1];return Dh(n?.content)}function Dh(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return Dh(e.parts);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 Oh(e){let t=e.title?.trim(),n=Eh(e)??Dh(e.preview);return{id:e.id,title:Th(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function kh(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return Oh(`conversation`in r&&r.conversation?r.conversation:r)}function Ah(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(!!t),[l,u]=(0,X.useState)(void 0),[d,f]=(0,X.useState)(0),p=(0,X.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,X.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,X.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,X.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;let s=a.map(Oh).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>kh(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}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 jh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Ep).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Mh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>hm).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),Nh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Sm).then(e=>({default:e.PageView})),void 0,import.meta.url)),Ph=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Lm).then(e=>({default:e.ReportView})),void 0,import.meta.url)),Fh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Hm).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),Ih=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Gp).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),Lh=(0,X.lazy)(()=>d(()=>import(`./ComponentNavView-BlNdGi6O.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Rh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),zh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),Bh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Vh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Hh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Uh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>zE).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),Wh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>eA).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),Gh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>eA).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),Kh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>eA).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),qh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Fg).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),Jh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Wg).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),Yh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Kg).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function Xh({appName:e}){let{reviewSeq:t,reviewTarget:n}=rl(),r=v(),i=(0,X.useRef)(t);return(0,X.useEffect)(()=>{if(t===i.current||!n||!e)return;i.current=t;let{type:a,name:o}=n;r(`/apps/${e}/metadata/${encodeURIComponent(a)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,r]),null}function Zh({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,X.useState)(`disconnected`),{user:o,getAuthConfig:c}=S(),l=be(),[d,f]=(0,X.useState)({});(0,X.useEffect)(()=>{let e=!1;return c().then(t=>{e||f(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[c]);let p=v(),m=u(),{appName:h}=s(),{apps:_,objects:y,loading:b,ensureType:x}=ce(),{t:C}=z(),{objectLabel:w}=li(),[T,E]=(0,X.useState)(!x);(0,X.useEffect)(()=>{if(!x){E(!0);return}let e=!1;return Promise.all([x(`object`),x(`dashboard`),x(`report`),x(`page`)]).finally(()=>{e||E(!0)}),()=>{e=!0}},[x]);let D=_.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),O=_.find(e=>e.name===h)||D.find(e=>e.isDefault===!0)||D[0];(0,X.useEffect)(()=>{if(!O?.name)return;let e=`/apps/${O.name}/metadata/package`;(m.pathname===e||m.pathname.startsWith(`${e}/`))&&p(`/apps/${O.name}/component/developer/packages`,{replace:!0})},[O?.name,m.pathname,p]);let[k,A]=(0,X.useState)(!1),[j,ee]=(0,X.useState)(null),[te,ne]=(0,X.useState)(0),{execute:re,runner:N}=ie();M({dataSource:l??void 0,onUndo:e=>{q.info(`Undo: ${e.description}`,{duration:4e3}),ne(e=>e+1)},onRedo:e=>{q.info(`Redo: ${e.description}`,{duration:3e3}),ne(e=>e+1)}}),(0,X.useEffect)(()=>{N.registerHandler(`crud_success`,async e=>(A(!1),ne(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=yl({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=bl({action:e,context:N.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(p(t.url),{success:!0}):t})},[N,p,h]),(0,X.useEffect)(()=>{if(!l)return;let e=l.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(l.getConnectionState()),e},[l]);let P=m.pathname.split(`/`).filter(Boolean)[2];(P===`view`||P===`record`||P===`page`||P===`dashboard`||P===`design`)&&(P=``);let F=y.find(e=>e.name===P),ae=(0,X.useCallback)(()=>{let e=F?w(F):C(`common.record`,{defaultValue:`Record`});re({type:`crud_success`,params:{message:j?C(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):C(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[re,j,F,w,C]),oe=(0,X.useCallback)(()=>{re({type:`dialog_cancel`})},[re]);ch({pathname:m.pathname,appName:O?.name,objects:y});let se=e=>{let t=vl({objectDef:F,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}ee(e),A(!0)},le=e=>{p(`/apps/${e}`)},ue=(0,X.useMemo)(()=>new B({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:O||{},data:j||{}}),[o,O,j]);if(!l||b||!T)return(0,Z.jsx)(Au,{});let de=m.pathname.endsWith(`/create-app`),fe=m.pathname.includes(`/system`),pe=m.pathname.includes(`/metadata`);return!O&&!de&&!fe&&!pe?(0,Z.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:C(`empty.noAppsConfigured`)}),(0,Z.jsx)(Kt,{children:C(`empty.noAppsConfiguredDescription`)}),(0,Z.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Z.jsx)(K,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:C(`empty.createFirstApp`)}),(0,Z.jsx)(K,{variant:`outline`,onClick:()=>p(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:C(`empty.systemSettings`)})]})]})}):!O&&(de||fe||pe)?(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`create-app`,element:(0,Z.jsx)(Wh,{})}),(0,Z.jsx)(g,{path:`system/marketplace`,element:(0,Z.jsx)(qh,{})}),(0,Z.jsx)(g,{path:`system/marketplace/installed`,element:(0,Z.jsx)(Yh,{})}),(0,Z.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,Z.jsx)(Jh,{})}),(0,Z.jsx)(g,{path:`metadata`,element:(0,Z.jsx)(Rh,{})}),(0,Z.jsx)(g,{path:`metadata/_diagnostics`,element:(0,Z.jsx)(Uh,{})}),(0,Z.jsx)(g,{path:`metadata/:type`,element:(0,Z.jsx)(Bh,{})}),(0,Z.jsx)(g,{path:`metadata/:type/new`,element:(0,Z.jsx)(Vh,{createMode:!0})}),(0,Z.jsx)(g,{path:`metadata/:type/:name`,element:(0,Z.jsx)(Vh,{})}),(0,Z.jsx)(g,{path:`metadata/:type/:name/history`,element:(0,Z.jsx)(Hh,{})}),t]})}):(0,Z.jsxs)(yc,{user:o?{name:o.name,email:o.email,role:o.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:O,data:{},features:d,children:[(0,Z.jsx)(ih,{}),(0,Z.jsxs)(Cu,{activeAppName:O.name,activeApp:O,onAppChange:le,objects:y,connectionState:n,userId:o?.id,children:[(0,Z.jsx)(Tu,{apps:_,activeApp:O,objects:y,onAppChange:le,dataSource:l}),(0,Z.jsx)(Du,{}),(0,Z.jsx)(Ou,{}),(0,Z.jsx)(Xh,{appName:h}),(0,Z.jsx)(Bu,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(Nu,{className:`h-full`,children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`/`,element:(()=>{let e=tg(O,{currentUserId:o?.id??null});return e?(0,Z.jsx)(i,{to:e,replace:!0}):(0,Z.jsx)(zh,{})})()}),(0,Z.jsx)(g,{path:`metadata/package/*`,element:(0,Z.jsx)(i,{to:`/apps/${O.name}/component/developer/packages`,replace:!0})}),(0,Z.jsxs)(g,{path:`metadata`,children:[(0,Z.jsx)(g,{index:!0,element:(0,Z.jsx)(Rh,{})}),(0,Z.jsx)(g,{path:`_diagnostics`,element:(0,Z.jsx)(Uh,{})}),(0,Z.jsx)(g,{path:`:type`,element:(0,Z.jsx)(Bh,{})}),(0,Z.jsx)(g,{path:`:type/new`,element:(0,Z.jsx)(Vh,{createMode:!0})}),(0,Z.jsx)(g,{path:`:type/:name`,element:(0,Z.jsx)(Vh,{})}),(0,Z.jsx)(g,{path:`:type/:name/history`,element:(0,Z.jsx)(Hh,{})})]}),(0,Z.jsx)(g,{path:`:objectName`,element:(0,Z.jsx)(Up,{dataSource:l,objects:y,onEdit:se,externalRefreshKey:te})}),(0,Z.jsx)(g,{path:`:objectName/new`,element:(0,Z.jsx)(Ih,{mode:`create`})}),(0,Z.jsx)(g,{path:`:objectName/view/:viewId`,element:(0,Z.jsx)(Up,{dataSource:l,objects:y,onEdit:se,externalRefreshKey:te})}),(0,Z.jsx)(g,{path:`:objectName/record/:recordId`,element:(0,Z.jsx)(jh,{dataSource:l,objects:y,onEdit:se},te)}),(0,Z.jsx)(g,{path:`:objectName/record/:recordId/edit`,element:(0,Z.jsx)(Ih,{mode:`edit`})}),(0,Z.jsx)(g,{path:`dashboard/:dashboardName`,element:(0,Z.jsx)(Mh,{dataSource:l})}),(0,Z.jsx)(g,{path:`report/:reportName`,element:(0,Z.jsx)(Ph,{dataSource:l})}),(0,Z.jsx)(g,{path:`page/:pageName`,element:(0,Z.jsx)(Nh,{})}),(0,Z.jsx)(g,{path:`component/:ns/:name/*`,element:(0,Z.jsx)(Lh,{})}),(0,Z.jsx)(g,{path:`component/metadata/directory`,element:(0,Z.jsx)(ig,{mode:`directory`})}),(0,Z.jsx)(g,{path:`component/metadata/resource/*`,element:(0,Z.jsx)(ig,{mode:`resource`})}),(0,Z.jsx)(g,{path:`design/dashboard/:dashboardName`,element:(0,Z.jsx)(Kh,{})}),(0,Z.jsx)(g,{path:`search`,element:(0,Z.jsx)(Fh,{})}),(0,Z.jsx)(g,{path:`create-app`,element:(0,Z.jsx)(Wh,{})}),(0,Z.jsx)(g,{path:`edit-app/:editAppName`,element:(0,Z.jsx)(Gh,{})}),(0,Z.jsx)(g,{path:`system/marketplace`,element:(0,Z.jsx)(qh,{})}),(0,Z.jsx)(g,{path:`system/marketplace/installed`,element:(0,Z.jsx)(Yh,{})}),(0,Z.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,Z.jsx)(Jh,{})}),e,(0,Z.jsx)(g,{path:`:objectName/:maybeRecordId`,element:(0,Z.jsx)(ag,{})}),(0,Z.jsx)(g,{path:`*`,element:(0,Z.jsx)(og,{})})]})})})}),F&&(0,Z.jsx)(Ro,{schema:{type:`object-form`,formType:`modal`,objectName:F.name,mode:j?`edit`:`create`,recordId:j?.id,subforms:F.form?.subforms??F.formViews?.default?.subforms,title:C(j?`form.editTitle`:`form.createTitle`,{object:w(F)}),description:C(j?`form.editDescription`:`form.createDescription`,{object:w(F)}),open:k,onOpenChange:A,layout:`vertical`,fields:F.fields?Array.isArray(F.fields)?F.fields.filter(e=>typeof e==`string`?!0:xc(e.visible,ue)).map(e=>typeof e==`string`?e:e.name):Object.entries(F.fields).filter(([e,t])=>xc(t.visible,ue)).map(([e])=>e):[],onSuccess:ae,onCancel:oe,showSubmit:!0,showCancel:!0,submitText:j?C(`form.update`,{defaultValue:C(`common.save`,{defaultValue:`Save`})}):C(`form.create`,{defaultValue:C(`common.create`,{defaultValue:`Create`})}),cancelText:C(`common.cancel`)},dataSource:l},j?.id||`new`)]})]})}function Qh(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=$h(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Qh(n.children,t);if(e!==``)return e}}return``}function $h(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Yo(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function eg(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=eg(n.children,t);if(e)return e}}}function tg(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=$h(eg(r,n),t);if(e)return e}return Qh(r,t)}var ng=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function rg(e){return!e||ng.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function ig({mode:e}){let t=u(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Z.jsx)(i,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,a=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,Z.jsx)(i,{to:r?`${n}/metadata/${encodeURIComponent(r)}${a}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function ag(){let{objectName:e,maybeRecordId:t}=s(),n=u();return e&&rg(t)?(0,Z.jsx)(i,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Z.jsx)(og,{})}function og(){let e=v(),{t}=z();return(0,Z.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Z.jsx)(Kt,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(K,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function sg({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,X.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,Z.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,Z.jsx)(`span`,{className:i,children:s})})}function cg(){let e=v(),{appName:t}=s(),{t:n}=z(),r=t?`/apps/${t}`:`/`;return(0,Z.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,Z.jsx)(Vt,{children:(0,Z.jsxs)(ka,{className:`flex flex-col items-center gap-4 py-12 text-center`,children:[(0,Z.jsx)(`div`,{className:`rounded-full bg-muted p-3`,children:(0,Z.jsx)(ot,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:n(`marketplace.accessDenied.title`)}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:n(`marketplace.accessDenied.description`)})]}),(0,Z.jsx)(K,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var lg=`en`;function ug(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function dg(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function fg(e,t,n){if(!e)return;let r=ug(t),i=dg([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),lg]);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 pg(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 mg(e,t){let n=t||lg;return{displayName:fg(e.translations??void 0,n,`displayName`)??pg(e,`displayName`)??e.manifest_id,description:fg(e.translations??void 0,n,`description`)??pg(e,`description`),readme:fg(e.translations??void 0,n,`readme`)??pg(e,`readme`),tagline:fg(e.translations??void 0,n,`tagline`)??pg(e,`tagline`)}}var hg=``.replace(/\/$/,``),gg=`${hg}/api/v1/marketplace`;function _g(e){let t=C.get();return t?{...e,Authorization:`Bearer ${t}`}:e}async function vg(e,t){let n=await fetch(`${gg}${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 yg(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 vg(`/packages${n?`?${n}`:``}`)}async function bg(e){return vg(`/packages/${encodeURIComponent(e)}`)}async function xg(e){if(ns()){let t=await fetch(`/api/v1/cloud-connection/install`,{method:`POST`,credentials:`include`,headers:_g({Accept:`application/json`,"Content-Type":`application/json`}),body:JSON.stringify({package_id:e.packageId,seed_sample_data:!!e.seedSampleData})}),n=null;try{n=await t.json()}catch{}if(!t.ok||n?.success===!1){let e=n?.error?.code??n?.code??`HTTP_${t.status}`,r=n?.error?.message??n?.error??n?.message??t.statusText,i=Error(typeof r==`string`?r:`${e}`);throw i.code=e,i.status=t.status,i}return n?.data??n}let t=await fetch(`${hg}/api/v1/actions/sys_package/install_package`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({recordId:e.packageId,params:{environment_id:e.environmentId,seed_sample_data:!!e.seedSampleData}})}),n=null;try{n=await t.json()}catch{}if(!t.ok){let e=n?.code??n?.error?.code??`HTTP_${t.status}`,r=n?.error??n?.message??t.statusText,i=Error(typeof r==`string`?r:`${e}`);throw i.code=e,i.status=t.status,i}return n?.data??n}async function Sg(){let e=ns()||hg,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 Cg(){let e=ns()||hg,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 wg(e){return`${ns()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function Tg(e,t){if(!e)return null;if(ns())try{let t=await fetch(`/api/v1/cloud-connection/installation?package_id=${encodeURIComponent(e)}`,{credentials:`include`,headers:_g({Accept:`application/json`})});if(!t.ok)return null;let n=await t.json().catch(()=>({})),r=n?.data??n??{};return r.installed?{installationId:String(r.installationId??``),version:String(r.version??`installed`),withSampleData:r.withSampleData===!0}:null}catch{return null}if(!t)return null;let n=hg,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 Eg(e){if(!e)return{ok:!1,error:`installation id required`};let t=ns()||hg;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 Dg(e){if(!e)return{ok:!1,error:`installation id required`};let t=ns()||hg;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 Og(e){let t=await fetch(`${gg}/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 kg(){try{let e=await fetch(`${gg}/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 Ag(){try{let e=await fetch(`${hg}/api/v1/cloud-connection/installed`,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return{connected:!1,items:[]};let t=(await e.json().catch(()=>({})))?.data??{},n=(Array.isArray(t.packages)?t.packages:[]).map(e=>{let t=String(e.packageId??e.package_id??``);return{packageId:t,versionId:String(e.package_version_id??``),manifestId:t,version:String(e.version??`installed`),installedAt:String(e.installed_at??e.installedAt??``),installedBy:e.installed_by??e.installedBy??null,withSampleData:e.with_sample_data===!0||e.withSampleData===!0}});return{connected:t.connected===!0,items:n}}catch{return{connected:!1,items:[]}}}async function jg(e){let t=await fetch(`${gg}/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 Mg(e,t){let n=await fetch(`${gg}/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 Ng(e){return Mg(e,`reseed`)}function Pg(e){return Mg(e,`purge`)}var Fg=t({MarketplacePage:()=>Lg});function Ig(){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 Lg(){let e=v(),{appName:t}=s(),n=x(),{t:r,language:i}=z(),a=Ig(),o=t?`/apps/${t}`:``,[c,l]=(0,X.useState)([]),[u,d]=(0,X.useState)(!0),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(``),[y,b]=(0,X.useState)([]),S=(0,X.useMemo)(()=>{let e=new Map;for(let t of y)e.set(t.manifestId,t);return e},[y]),C=async()=>{d(!0),p(null);try{let[e,t]=await Promise.all([yg({limit:100}),kg()]);l(e.items??[]),b(t)}catch(e){p(e?.message??String(e)),l([])}finally{d(!1)}};(0,X.useEffect)(()=>{C()},[]);let w=(0,X.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,X.useMemo)(()=>{let e=m.trim().toLowerCase();return c.filter(t=>{if(g&&t.category!==g)return!1;if(!e)return!0;let n=mg(t,i);return`${n.displayName} ${t.manifest_id} ${n.description??``}`.toLowerCase().includes(e)})},[c,m,g,i]);return n?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Er,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,Z.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.title`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:r(`marketplace.subtitle`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/installed`),children:[(0,Z.jsx)(Ci,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),y.length>0?r(`marketplace.installedCount`,{count:y.length}):r(`marketplace.installed`)]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void C(),disabled:u,children:[(0,Z.jsx)(en,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(Co,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,Z.jsx)(W,{value:m,onChange:e=>h(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,Z.jsx)(K,{size:`sm`,variant:g===``?`default`:`outline`,onClick:()=>_(``),children:r(`marketplace.all`)}),w.map(e=>(0,Z.jsx)(K,{size:`sm`,variant:g===e?`default`:`outline`,onClick:()=>_(e),children:T(e)},e))]})]}),f&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-medium text-destructive`,children:r(`marketplace.load.failed`)}),(0,Z.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:f}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2`,dangerouslySetInnerHTML:{__html:r(`marketplace.load.failedHint`)}})]})]}),u&&c.length===0?(0,Z.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(vr,{className:`pb-2`,children:[(0,Z.jsx)(He,{className:`h-10 w-10 rounded-lg mb-2`}),(0,Z.jsx)(He,{className:`h-5 w-3/4`}),(0,Z.jsx)(He,{className:`h-4 w-1/2 mt-1`})]}),(0,Z.jsx)(ka,{children:(0,Z.jsx)(He,{className:`h-12 w-full`})})]},t))}):E.length===0?(0,Z.jsx)(`div`,{className:`text-center py-12 text-sm text-muted-foreground`,children:c.length===0?r(`marketplace.noApprovedYet`):r(`marketplace.noMatchFilters`)}):(0,Z.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:E.map(t=>{let n=S.get(t.manifest_id),s=mg(t,i);return(0,Z.jsxs)(Vt,{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,Z.jsxs)(vr,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Z.jsx)(sg,{iconUrl:t.icon_url,displayName:s.displayName,manifestId:t.manifest_id}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(fr,{className:`text-base truncate`,children:s.displayName}),(0,Z.jsx)(Ft,{className:`text-xs truncate`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,Z.jsx)(H,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,Z.jsxs)(ka,{className:`flex-1 flex flex-col gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:s.description||r(`marketplace.noDescription`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-auto pt-2 flex-wrap`,children:[n&&(0,Z.jsxs)(H,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,Z.jsxs)(H,{variant:`outline`,className:`text-xs`,children:[(0,Z.jsx)(Lr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,Z.jsx)(H,{variant:`outline`,className:`text-xs`,children:T(t.category)}),t.latest_version?.published_at&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:a(t.latest_version.published_at)})]})]})]},t.id)})})]}):(0,Z.jsx)(cg,{})}function Rg(e){let t=e.replace(/\r\n/g,`
|
|
11
|
+
`).split(`
|
|
12
|
+
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(e.startsWith("```")){let i=e.slice(3).trim();r++;let a=[];for(;r<t.length&&!t[r].startsWith("```");)a.push(t[r]),r++;r++,n.push({type:`code`,text:a.join(`
|
|
13
|
+
`),lang:i});continue}let i=/^(#{1,3})\s+(.*)$/.exec(e);if(i){let e=i[1].length;n.push({type:`h${e}`,text:i[2].trim()}),r++;continue}if(/^[-*]\s+/.test(e)){let e=[];for(;r<t.length&&/^[-*]\s+/.test(t[r]);)e.push(t[r].replace(/^[-*]\s+/,``)),r++;n.push({type:`ul`,items:e});continue}if(/^\d+\.\s+/.test(e)){let e=[];for(;r<t.length&&/^\d+\.\s+/.test(t[r]);)e.push(t[r].replace(/^\d+\.\s+/,``)),r++;n.push({type:`ol`,items:e});continue}if(!e.trim()){r++;continue}let a=[];for(;r<t.length&&t[r].trim()&&!/^#{1,3}\s+/.test(t[r])&&!/^[-*]\s+/.test(t[r])&&!/^\d+\.\s+/.test(t[r])&&!t[r].startsWith("```");)a.push(t[r]),r++;n.push({type:`p`,text:a.join(` `)})}return n}function zg(e){let t=[],n=e,r=0,i=[{re:/`([^`]+)`/,render:e=>(0,Z.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,Z.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e[1]},`k${r++}`)},{re:/\*([^*]+)\*/,render:e=>(0,Z.jsx)(`em`,{children:e[1]},`k${r++}`)},{re:/\[([^\]]+)\]\(([^)]+)\)/,render:e=>(0,Z.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,Z.jsx)(Z.Fragment,{children:t.map((e,t)=>(0,Z.jsx)(X.Fragment,{children:e},t))})}function Bg({source:e,className:t}){let n=Rg(e);return(0,Z.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,Z.jsx)(`h2`,{className:`mt-2 text-xl font-bold tracking-tight`,children:zg(e.text??``)},t);case`h2`:return(0,Z.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:zg(e.text??``)},t);case`h3`:return(0,Z.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:zg(e.text??``)},t);case`p`:return(0,Z.jsx)(`p`,{children:zg(e.text??``)},t);case`ul`:return(0,Z.jsx)(`ul`,{className:`ml-1 flex list-none flex-col gap-1.5`,children:(e.items??[]).map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Z.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,Z.jsx)(`span`,{children:zg(e)})]},t))},t);case`ol`:return(0,Z.jsx)(`ol`,{className:`ml-5 flex list-decimal flex-col gap-1.5 marker:text-muted-foreground`,children:(e.items??[]).map((e,t)=>(0,Z.jsx)(`li`,{className:`pl-1`,children:zg(e)},t))},t);case`code`:return(0,Z.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border bg-muted/40 p-3 text-xs leading-relaxed`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:e.text})},t)}return null})})}var Vg={node:`In-process · full trust`,sandbox:`Sandboxed`,worker:`Out-of-process`};function Hg({icon:e,label:t,items:n}){return!n||n.length===0?null:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(e,{className:`h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium`,children:t}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:n.map(e=>(0,Z.jsx)(`code`,{className:`font-mono text-[11px] px-1 py-0.5 rounded bg-muted break-all`,children:e},e))})]})]})}function Ug({version:e}){let{t}=z();if(!e?.contains_code)return null;let n=e.permissions??{},r=(n.services?.length??0)+(n.hooks?.length??0)+(n.network?.length??0)+(n.fs?.length??0)>0;return(0,Z.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 space-y-3 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,Z.jsx)(cr,{className:`h-4 w-4 text-amber-600 shrink-0`,"aria-hidden":`true`}),t(`marketplace.disclosure.containsCode`,{defaultValue:`This package contains code`})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[e.runtime&&(0,Z.jsx)(H,{variant:`outline`,children:t(`marketplace.disclosure.runtime.${e.runtime}`,{defaultValue:Vg[e.runtime]??e.runtime})}),e.platform_verified?(0,Z.jsxs)(H,{variant:`outline`,className:`gap-1 border-green-500/40 text-green-700 dark:text-green-400`,children:[(0,Z.jsx)(Ca,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.reviewed`,{defaultValue:`Reviewed & approved`})]}):(0,Z.jsxs)(H,{variant:`outline`,className:`gap-1 border-amber-500/40 text-amber-700 dark:text-amber-400`,children:[(0,Z.jsx)(sa,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.unreviewed`,{defaultValue:`Not yet reviewed`})]}),e.signed&&(0,Z.jsxs)(H,{variant:`outline`,className:`gap-1`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.signed`,{defaultValue:`Signed`})]})]}),r?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.grantsIntro`,{defaultValue:`On install, this package will be granted:`})}),(0,Z.jsx)(Hg,{icon:Ve,label:t(`marketplace.disclosure.services`,{defaultValue:`Platform services`}),items:n.services??void 0}),(0,Z.jsx)(Hg,{icon:qn,label:t(`marketplace.disclosure.hooks`,{defaultValue:`Lifecycle hooks`}),items:n.hooks??void 0}),(0,Z.jsx)(Hg,{icon:Ra,label:t(`marketplace.disclosure.network`,{defaultValue:`Network access`}),items:n.network??void 0}),(0,Z.jsx)(Hg,{icon:Qa,label:t(`marketplace.disclosure.fs`,{defaultValue:`Filesystem access`}),items:n.fs??void 0})]}):(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.noPermissions`,{defaultValue:`Requests no special permissions.`})})]})}var Wg=t({MarketplacePackagePage:()=>Gg});function Gg(){let e=v(),{packageId:t,appName:n}=s(),r=x(),{t:i,language:a}=z(),o=n?`/apps/${n}`:``,{refresh:c}=ce(),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)([]),[b,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(!1),[j,ee]=(0,X.useState)(!1),[te,M]=(0,X.useState)(null),[ne,re]=(0,X.useState)(null),[N,ie]=(0,X.useState)(null),[P,F]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(null),[se,le]=(0,X.useState)([]),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!$o().features.installLocal)return;let e=!1;return(async()=>{let t=await kg();e||le(t)})(),()=>{e=!0}},[t,fe]),(0,X.useEffect)(()=>{if(!t)return;let e=$o().defaultEnvironmentId??``,n=!1;return(async()=>{let r=await Tg(t,e);n||!r||(ie(r),re(r.version))})(),()=>{n=!0}},[t]),(0,X.useEffect)(()=>{let e=!1;return(async()=>{if(t){f(!0),m(null);try{let n=await bg(t);e||u(n)}catch(t){e||m(t?.message??String(t))}finally{e||f(!1)}}})(),()=>{e=!0}},[t]);let me=async()=>{g(!0),M(null),w(null);let e=$o().defaultEnvironmentId;if(e){S(!1),E(e),y([]);return}S(!0);try{let[e,t]=await Promise.all([Sg(),Cg()]),n=e.filter(e=>{let n=e.organization_id;return n?t.has(String(n)):!1});y(n),e.length>0&&n.length===0?w(i(`marketplace.install.noPermission`)):n.length===1&&E(n[0].id)}catch(e){let t=e?.status;w(t===401||t===403?i(`marketplace.install.signInFirst`):e?.message??String(e))}finally{S(!1)}},he=async()=>{if(!(!t||!T)){ee(!0),M(null);try{re(((await xg({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=$o().defaultEnvironmentId||T;if(e){let n=await Tg(t,e);n&&ie(n)}}catch{}let e=$o().defaultEnvironmentId;if(!e||e===T)try{if(typeof sessionStorage<`u`)for(let e of Object.keys(sessionStorage))e.startsWith(`objectui:metadata:`)&&sessionStorage.removeItem(e);await c()}catch{}M({ok:!0,message:i(`marketplace.install.success`)})}catch(e){M({ok:!1,message:e?.message??String(e)})}finally{ee(!1)}}},ge=async()=>{if(t){de(!0),pe(null);try{let e=await Og({packageId:t});try{await c(`app`)}catch{}pe({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?mg(l.package,a).displayName:e.manifestId})})}catch(e){let t=e?.code,n=e?.message??String(e);t===`manifest_conflict`?n=i(`marketplace.install.localManifestConflict`,{message:n}):t===`unauthorized`?n=i(`marketplace.install.localUnauthorized`):t===`marketplace_unavailable`&&(n=i(`marketplace.install.localMarketplaceUnavailable`)),pe({ok:!1,message:n})}finally{de(!1)}}},_e=async()=>{if(xe&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:xe.manifestId,version:xe.version}))){de(!0),pe(null);try{await jg(xe.manifestId);try{await c(`app`)}catch{}pe({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:xe.manifestId})})}catch(e){pe({ok:!1,message:e?.message??String(e)})}finally{de(!1)}}},ve=async()=>{if(N){F(`reseed`),oe(null);try{let e=await Eg(N.installationId);e.ok?(ie({...N,withSampleData:!0}),oe({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):oe({ok:!1,text:e.error||`Re-seed failed`})}finally{F(null)}}},I=async()=>{if(N&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){F(`purge`),oe(null);try{let e=await Dg(N.installationId);if(e.ok){ie({...N,withSampleData:!1});let t=e.deleted??0;oe({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 oe({ok:!1,text:e.error||`Purge failed`})}finally{F(null)}}},L=async()=>{if(xe){F(`reseed`),oe(null);try{let e=await Ng(xe.manifestId);le(e=>e.map(e=>e.manifestId===xe.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;oe({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){oe({ok:!1,text:e?.message||`Re-seed failed`})}finally{F(null)}}},R=async()=>{if(xe&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){F(`purge`),oe(null);try{let e=await Pg(xe.manifestId);le(e=>e.map(e=>e.manifestId===xe.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;oe({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){oe({ok:!1,text:e?.message||`Purge failed`})}finally{F(null)}}};if(d)return(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Z.jsx)(He,{className:`h-8 w-32`}),(0,Z.jsx)(He,{className:`h-16 w-full`}),(0,Z.jsx)(He,{className:`h-64 w-full`})]});if(p||!l)return(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Z.jsx)(Wt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-medium text-destructive`,children:i(`marketplace.load.packageFailed`)}),(0,Z.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:p??i(`marketplace.load.notFound`)})]})]})]});let ye=l.package,B=mg(ye,a),be=ye.latest_version?.version??l.versions[0]?.version??null,xe=se.find(e=>e.manifestId===ye.manifest_id)??null,Se=!!ye.latest_version?.contains_code,Ce=$o().features.installLocal,we=!be||ue||j||!Ce&&!!ne,Te=Ce?{label:i(ue?`marketplace.action.working`:xe?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:ge}:{label:j?i(`marketplace.action.installing`):ne?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:me},Ee=ye.category?i(`marketplace.category.${ye.category}`,{defaultValue:ye.category}):null;return r?(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,Z.jsx)(Wt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,Z.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,Z.jsx)(sg,{iconUrl:ye.icon_url,displayName:B.displayName,manifestId:ye.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:B.displayName||ye.manifest_id}),ye.homepage_url&&(0,Z.jsxs)(`a`,{href:ye.homepage_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,title:i(`marketplace.detail.homepage`),children:[(0,Z.jsx)(_n,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:i(`marketplace.detail.homepage`)})]})]}),(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsx)(`code`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:ye.manifest_id}),be&&(0,Z.jsx)(H,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:be})}),ye.publisher&&ye.publisher!==`private`&&(0,Z.jsx)(H,{variant:ye.publisher===`objectstack`?`default`:`secondary`,children:ye.publisher}),Ee&&(0,Z.jsx)(H,{variant:`outline`,children:Ee}),ye.license&&(0,Z.jsx)(H,{variant:`outline`,className:`font-normal`,children:ye.license}),xe&&(0,Z.jsxs)(H,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:xe.version})]}),!xe&&ne&&(0,Z.jsxs)(H,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:ne})]})]}),B.description&&(0,Z.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:B.description})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,Z.jsxs)(K,{onClick:Te.onClick,disabled:we,size:`lg`,className:`min-w-[8rem]`,children:[(0,Z.jsx)(nn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),Te.label]}),xe&&(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsx)(K,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`),children:(0,Z.jsx)(Yi,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Z.jsxs)(va,{align:`end`,className:`w-56`,children:[(0,Z.jsxs)(Qr,{onSelect:L,disabled:P!==null,children:[P===`reseed`?(0,Z.jsx)(V,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(kt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),xe.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Z.jsxs)(Qr,{onSelect:R,disabled:P!==null||!xe.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,Z.jsx)(V,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(In,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,Z.jsxs)(Qr,{onSelect:_e,disabled:ue,className:`text-destructive focus:text-destructive`,children:[(0,Z.jsx)(In,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!xe&&N&&!$o().cloudUrl&&(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsx)(K,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`)||`More options`,children:(0,Z.jsx)(Yi,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Z.jsxs)(va,{align:`end`,className:`w-56`,children:[(0,Z.jsxs)(Qr,{onSelect:ve,disabled:P!==null,children:[P===`reseed`?(0,Z.jsx)(V,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(kt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),N.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Z.jsxs)(Qr,{onSelect:I,disabled:P!==null||!N.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,Z.jsx)(V,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(In,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),ae&&(0,Z.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${ae.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[ae.ok?(0,Z.jsx)(Hr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:ae.text}),(0,Z.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>oe(null),children:i(`marketplace.action.dismiss`)})]}),fe&&(0,Z.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${fe.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[fe.ok?(0,Z.jsx)(Hr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:fe.message}),(0,Z.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>pe(null),children:i(`marketplace.action.dismiss`)})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,children:[(0,Z.jsx)(`div`,{className:`lg:col-span-2 space-y-4`,children:(0,Z.jsxs)(Vt,{children:[(0,Z.jsx)(vr,{children:(0,Z.jsx)(fr,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,Z.jsx)(ka,{children:B.readme?(0,Z.jsx)(Bg,{source:B.readme}):(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noReadme`)})})]})}),(0,Z.jsx)(`div`,{className:`space-y-4`,children:(0,Z.jsxs)(Vt,{children:[(0,Z.jsx)(vr,{children:(0,Z.jsx)(fr,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,Z.jsx)(ka,{children:l.versions.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noApprovedVersions`)}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:l.versions.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Lr,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,Z.jsxs)(`code`,{className:`font-mono`,children:[`v`,e.version]}),e.is_prerelease&&(0,Z.jsx)(H,{variant:`outline`,className:`text-xs`,children:i(`marketplace.detail.prerelease`)})]}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.published_at?new Date(e.published_at).toLocaleDateString():`—`})]},e.id))})})]})})]}),(0,Z.jsx)(mt,{open:h,onOpenChange:e=>{g(e),e||(M(null),A(!1))},children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:i(`marketplace.install.dialogTitle`,{name:B.displayName||ye.manifest_id})}),(0,Z.jsx)(Yt,{children:$o().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),b?(0,Z.jsx)(He,{className:`h-10 w-full`}):C?(0,Z.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 text-sm space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 text-amber-600`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:C})]}),(0,Z.jsx)(`a`,{href:wg(ye.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,Z.jsx)(_n,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):$o().defaultEnvironmentId?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(yt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Z.jsx)(G,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]}):_.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.install.noEnvs`)}):(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,Z.jsxs)(Rn,{value:T,onValueChange:E,children:[(0,Z.jsx)(ar,{id:`env-select`,children:(0,Z.jsx)(Tt,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,Z.jsx)(jo,{children:_.map(e=>(0,Z.jsxs)(Ye,{value:e.id,children:[e.display_name||e.hostname||e.id,e.plan&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.plan]})]},e.id))})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(yt,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,Z.jsx)(G,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),Se&&!C&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(Ug,{version:ye.latest_version}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(yt,{id:`ack-perms`,checked:k,onCheckedChange:e=>A(e===!0)}),(0,Z.jsx)(G,{htmlFor:`ack-perms`,className:`text-sm font-normal cursor-pointer leading-snug`,children:i(`marketplace.disclosure.acknowledge`,{defaultValue:`I understand this package runs code and grants the permissions above.`})})]})]}),te&&(0,Z.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${te.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:te.message}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:()=>g(!1),children:i(`marketplace.action.close`)}),!C&&(0,Z.jsx)(K,{onClick:he,disabled:!T||j||te?.ok===!0||Se&&!k,children:i(j?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,Z.jsx)(cg,{})}var Kg=t({MarketplaceInstalledPage:()=>qg});function qg(){let e=v(),{appName:t}=s(),n=x(),{t:r,language:i}=z(),a=t?`/apps/${t}`:``,[o,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(`local`),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),_=async()=>{f(!0);try{let e=await Ag();e.connected?(u(`cloud`),c(e.items)):(u(`local`),c(await kg()))}finally{f(!1)}};(0,X.useEffect)(()=>{_()},[]);let y=async e=>{if(confirm(r(`marketplace.uninstall.confirm`,{manifestId:e.manifestId,version:e.version}))){m(e.manifestId),g(null);try{await jg(e.manifestId),g({ok:!0,message:r(`marketplace.uninstall.successInList`,{manifestId:e.manifestId})}),await _()}catch(e){g({ok:!1,message:e?.message??String(e)})}finally{m(null)}}};return n?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-5xl`,children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`self-start`,onClick:()=>e(`${a}/system/marketplace`),children:[(0,Z.jsx)(Wt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.back`)]}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Er,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,Z.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.installedTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedSubtitle`)}})]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void _(),disabled:d,children:[(0,Z.jsx)(en,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]}),h&&(0,Z.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${h.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,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{children:h.message})]})}),d&&o.length===0?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:3}).map((e,t)=>(0,Z.jsx)(He,{className:`h-20 w-full`},t))}):o.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-12 text-sm text-muted-foreground border rounded-md`,children:[(0,Z.jsx)(`p`,{children:r(`marketplace.installedEmpty`)}),(0,Z.jsx)(K,{variant:`link`,className:`mt-2`,onClick:()=>e(`${a}/system/marketplace`),children:r(`marketplace.browseLink`)})]}):(0,Z.jsx)(`div`,{className:`grid gap-3`,children:o.map(t=>(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(vr,{className:`flex flex-row items-start justify-between gap-3 pb-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(fr,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,Z.jsx)(H,{variant:`outline`,children:r(`marketplace.versionBadge`,{version:t.version})})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap gap-x-3 gap-y-1`,children:[(0,Z.jsx)(`span`,{children:r(`marketplace.installedAt`,{when:new Date(t.installedAt).toLocaleString(i||void 0)})}),t.installedBy&&(0,Z.jsx)(`span`,{children:r(`marketplace.installedBy`,{user:t.installedBy})}),(0,Z.jsxs)(`span`,{children:[r(`marketplace.installedPackageId`),` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:t.packageId})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>e(`${a}/system/marketplace/${t.packageId}`),children:[(0,Z.jsx)(_n,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.action.details`)]}),l===`local`&&(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void y(t),disabled:p===t.manifestId,children:[(0,Z.jsx)(In,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),p===t.manifestId?r(`marketplace.action.uninstalling`):r(`marketplace.action.uninstall`)]})]})]}),l===`local`&&(0,Z.jsx)(ka,{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,Z.jsx)(`p`,{className:`text-xs text-muted-foreground border-t pt-4`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedAdditiveNote`)}})]}):(0,Z.jsx)(cg,{})}function Jg({children:e,userId:t}){let{setContext:n}=Tc(),{isAiEnabled:r}=F(),{t:i}=z(),a=r||!1;return(0,X.useEffect)(()=>{n(`home`)},[n]),(0,Z.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,Z.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,Z.jsx)(vu,{variant:`home`})}),(0,Z.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),a&&(0,Z.jsx)(ll,{appLabel:i(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var Yg=[{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 Xg(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function Zg({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=z(),{appLabel:a,appDescription:o}=li(),{toggleFavorite:s}=Lc(),c=pl(e.icon),l=a({name:e.name,label:wl(e.label,i)}),u=o({name:e.name,description:wl(e.description,i)}),d=Yg[(Xg(e.name)+r)%Yg.length];return(0,Z.jsxs)(Vt,{className:U(`group relative 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`,`motion-reduce:transition-none motion-reduce:hover:transform-none`,d.ring),"data-testid":`app-card-${e.name}`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":l,className:`absolute inset-0 z-10 rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,onClick:t,"data-testid":`app-card-open-${e.name}`}),(0,Z.jsx)(`div`,{"aria-hidden":!0,className:U(`absolute inset-x-0 top-0 h-1`,d.solid)}),(0,Z.jsx)(`div`,{"aria-hidden":!0,className:U(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,d.from,d.to)}),(0,Z.jsxs)(ka,{className:`relative p-5`,children:[(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,className:`absolute top-2 right-2 z-20 h-8 w-8 p-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`,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,Z.jsx)(Fe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Z.jsx)(ui,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:U(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,`bg-gradient-to-br ring-border/40`,d.from,d.to),children:(0,Z.jsx)(c,{className:U(`h-7 w-7`,d.text)})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold text-base sm:text-lg leading-tight truncate`,children:l}),e.isDefault&&(0,Z.jsx)(H,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,Z.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,Z.jsx)(`div`,{className:`mt-4 flex items-center justify-between text-xs font-medium`,children:(0,Z.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,Z.jsx)(wt,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var Qg={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`},$g={object:kt,record:oo,dashboard:Dt,page:Ni};function e_({items:e}){let t=v(),{t:n}=z();return e.length===0?null:(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Z.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,Z.jsx)(Ht,{className:`h-4 w-4`})}),(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,Z.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=$g[e.type]||kt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Tl(e.type)}),a=Qg[e.type]||Qg.object;return(0,Z.jsx)(Vt,{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,Z.jsx)(ka,{className:`p-3.5`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:U(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,a),children:(0,Z.jsx)(r,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,Z.jsx)(wt,{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 t_={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`},n_={object:kt,record:oo,dashboard:Dt,page:Ni};function r_({items:e}){let t=v(),{t:n}=z();return e.length===0?null:(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Z.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,Z.jsx)(Fe,{className:`h-4 w-4 fill-current`})}),(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,Z.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=n_[e.type]||kt,i=t_[e.type]||t_.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Tl(e.type)});return(0,Z.jsx)(Vt,{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,Z.jsx)(ka,{className:`p-3.5`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:U(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,i),children:(0,Z.jsx)(r,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]}),(0,Z.jsx)(wt,{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 i_(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function a_({t:e}){return(0,Z.jsx)(`section`,{"data-testid":`home-getting-started`,className:`rounded-2xl border border-border bg-card p-6 sm:p-8 shadow-sm`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Z.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,Z.jsx)(Fe,{className:`h-5 w-5`})}),(0,Z.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,Z.jsx)(Ht,{className:`h-5 w-5`})})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:e(`home.gettingStarted.title`,{defaultValue:`Make this home yours`})}),(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,Z.jsx)(`span`,{children:e(`home.gettingStarted.cta`,{defaultValue:`Browse all applications`})}),(0,Z.jsx)(ja,{className:`h-3.5 w-3.5`})]})]})})}function o_({icon:e,value:t,label:n,tone:r}){return(0,Z.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,Z.jsx)(e,{className:`h-4 w-4 ${r}`}),(0,Z.jsx)(`span`,{className:`font-semibold tabular-nums`,children:t}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n})]})}function s_({t:e}){let t=ks(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),o=n.length;return(0,X.useEffect)(()=>{let e=!1;return Promise.resolve(t.listDrafts?.({})).then(t=>{e||!Array.isArray(t)||r(t.filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name})))}).catch(()=>{}),()=>{e=!0}},[t]),o<=0?null:(0,Z.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Z.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-indigo-300/60 dark:border-indigo-700/50 bg-indigo-50 dark:bg-indigo-950/30 px-4 py-3`,children:[(0,Z.jsx)(bt,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,Z.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:o,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,Z.jsx)(K,{size:`sm`,onClick:async()=>{a(!0);try{let i=n.length?n:(await t.listDrafts?.({})||[]).filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name}));if(i.length===0)throw Error(`nothing to publish`);let a=[...i.filter(e=>e.type!==`seed`),...i.filter(e=>e.type===`seed`)],o=[];for(let e of a){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&o.push(n.error??`${e.name}: sample data failed to load`)}o.length>0?q.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:o[0]}):q.success(e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),r([]),setTimeout(()=>{try{window.location.reload()}catch{}},700)}catch(t){q.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),a(!1)}},disabled:i,"data-testid":`pending-drafts-publish`,children:i?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function c_({t:e}){let t=v(),{hasLocalPassword:n}=S(),[r,i]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-dismissed`)===`1`)return;let e=!1;return Promise.resolve(n?.()).then(t=>{!e&&t===!1&&i(!0)}).catch(()=>{}),()=>{e=!0}},[n]),r?(0,Z.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Z.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-amber-300/60 dark:border-amber-700/50 bg-amber-50 dark:bg-amber-950/30 px-4 py-3`,children:[(0,Z.jsx)(sa,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,Z.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-amber-900 dark:text-amber-200`,children:e(`home.recoveryReminder.message`,{defaultValue:`Set a recovery password so you can still sign in if single sign-on is ever unavailable.`})}),(0,Z.jsx)(K,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{try{localStorage.setItem(`os:recovery-pw-dismissed`,`1`)}catch{}i(!1)},"aria-label":e(`home.recoveryReminder.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded-md p-1 text-amber-700/70 hover:text-amber-900 dark:text-amber-300/70 dark:hover:text-amber-100`,children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]})})}):null}function l_(){let e=v(),{t}=z(),{apps:n,loading:r}=ce(),{recentItems:i}=Wo(),{favorites:a}=Lc(),{user:o}=S(),s=x(),c=n.filter(e=>e.active!==!1&&e.hidden!==!0),l=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),u=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,8),d=(0,X.useMemo)(()=>t(i_(new Date().getHours()),{defaultValue:`Welcome`}),[t]),f=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):c.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Z.jsx)(s_,{t}),(0,Z.jsx)(c_,{t}),(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Z.jsx)(Kt,{children:t(`home.welcomeDescription`,{defaultValue:`Get started by creating your first application or configure your system settings.`})}),(0,Z.jsxs)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Z.jsxs)(K,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`build-with-ai-btn`,children:[(0,Z.jsx)(_a,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),(0,Z.jsxs)(K,{variant:`outline`,onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,Z.jsx)(Oo,{className:`mr-2 h-4 w-4`}),t(`home.createFirstApp`,{defaultValue:`Create Your First App`})]}),(0,Z.jsxs)(K,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,Z.jsx)(Ci,{className:`mr-2 h-4 w-4`}),t(`home.systemSettings`,{defaultValue:`System Settings`})]})]})]})})]}):(0,Z.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Z.jsx)(s_,{t}),(0,Z.jsx)(c_,{t}),(0,Z.jsx)(`section`,{className:`px-4 sm:px-6 lg:px-8 pt-10 pb-6`,children:(0,Z.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-3`,children:[(0,Z.jsx)(_a,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`uppercase tracking-wider`,children:t(`home.title`,{defaultValue:`Home`})})]}),(0,Z.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-pretty`,children:[(0,Z.jsxs)(`span`,{className:`text-foreground`,children:[d,f?`, `:``]}),f&&(0,Z.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:f}),(0,Z.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Z.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,Z.jsx)(`div`,{className:`mt-5`,children:(0,Z.jsxs)(K,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`home-build-with-ai`,children:[(0,Z.jsx)(_a,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]})}),(0,Z.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Z.jsx)(o_,{icon:ft,tone:`text-indigo-600 dark:text-indigo-400`,value:c.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Z.jsx)(o_,{icon:Ht,tone:`text-sky-600 dark:text-sky-400`,value:i.length,label:t(`home.recentApps.title`,{defaultValue:`Recently Accessed`})}),a.length>0&&(0,Z.jsx)(o_,{icon:Fe,tone:`text-amber-500 dark:text-amber-400`,value:a.length,label:t(`home.starredApps.title`,{defaultValue:`Starred`})})]})]})}),(0,Z.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pb-16`,children:(0,Z.jsxs)(`div`,{className:`max-w-7xl mx-auto space-y-10`,children:[u.length===0&&l.length===0&&(0,Z.jsx)(a_,{t}),u.length>0&&(0,Z.jsx)(r_,{items:u}),l.length>0&&(0,Z.jsx)(e_,{items:l}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-end justify-between mb-5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Z.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,Z.jsx)(ft,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[c.length,` · `,t(`home.stats.apps`,{defaultValue:`Applications`})]})]})]}),s&&(0,Z.jsxs)(K,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,Z.jsx)(Er,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:c.map((t,n)=>(0,Z.jsx)(Zg,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function u_({children:e}){let{setContext:t}=Tc();return(0,X.useEffect)(()=>{t(`home`)},[t]),(0,Z.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,Z.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,Z.jsx)(vu,{variant:`orgs`})}),(0,Z.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function d_(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function f_({open:e,onOpenChange:t,onCreated:n}){let{t:r}=z(),{createOrganization:i,getAuthConfig:a}=S(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,X.useEffect)(()=>{u||l(d_(o))},[o,u]),(0,X.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Z.jsx)(mt,{open:e,onOpenChange:t,children:(0,Z.jsx)(Ot,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Z.jsxs)(`form`,{onSubmit:(0,X.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,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Z.jsx)(Yt,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Z.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,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Z.jsx)(W,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(K,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function p_(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 m_(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function h_(){let{t:e}=z(),t=v(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a,getAuthConfig:o}=S(),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!0);(0,X.useEffect)(()=>{let e=!1;return o().then(t=>{e||t?.features?.multiOrgEnabled===!1&&m(!1)}).catch(()=>{}),()=>{e=!0}},[o]);let h=n??[],g=(0,X.useMemo)(()=>{let e=s.trim().toLowerCase();return e?h.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):h},[h,s]),_=async e=>{f(e.id);try{e.id!==r?.id&&await a(e.id),window.location.href=p_()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),f(null)}},y=e=>{u(!1),_(e)},b=(0,X.useRef)(!1);(0,X.useEffect)(()=>{b.current||i||h.length===1&&(b.current=!0,_(h[0]))},[i,h.length]);let x=!i&&h.length===1;return i||x?(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Z.jsx)(V,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,Z.jsxs)(`div`,{className:`mb-8`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,Z.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,Z.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,Z.jsx)(Co,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(W,{value:s,onChange:e=>c(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),p&&(0,Z.jsxs)(K,{onClick:()=>u(!0),"data-testid":`organizations-new`,children:[(0,Z.jsx)(Oo,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Z.jsx)(Kt,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),p&&(0,Z.jsxs)(K,{className:`mt-6`,onClick:()=>u(!0),children:[(0,Z.jsx)(Oo,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):g.length===0?(0,Z.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,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:g.map(n=>{let i=n.id===r?.id,a=d===n.id;return(0,Z.jsxs)(`button`,{onClick:()=>_(n),disabled:a,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,Z.jsxs)(Ne,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Z.jsx)(qa,{src:n.logo,alt:n.name}),(0,Z.jsx)(fi,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:m_(n.name)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,Z.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,Z.jsx)(V,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Z.jsx)(f_,{open:l,onOpenChange:u,onCreated:y})]})}function g_(){let{t:e}=z(),t=v(),{slug:n}=s(),{organizations:r,activeOrganization:i,isOrganizationsLoading:a,switchOrganization:o}=S(),{setContext:c}=Tc();(0,X.useEffect)(()=>{c(`home`)},[c]);let u=(0,X.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,X.useEffect)(()=>{u&&i?.id!==u.id&&o(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,i,o]),a)return(0,Z.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Z.jsx)(V,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,Z.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,Z.jsx)(vu,{variant:`orgs`})}),(0,Z.jsx)(`div`,{className:`border-b`,children:(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(0,Z.jsxs)(`button`,{onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,Z.jsx)(Wt,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,Z.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,Z.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:d.map(e=>(0,Z.jsx)(l,{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,Z.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,Z.jsx)(p,{context:{org:u}})})})]})}function __(){return o()}function v_(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function y_({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=z(),{inviteMember:a}=S(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(`member`),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1);(0,X.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),_(!1))},[t]);let v=(0,X.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,X.useCallback)(async()=>{if(!m)return;let e=v_(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,Z.jsx)(mt,{open:t,onOpenChange:n,children:(0,Z.jsx)(Ot,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Z.jsx)(Yt,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,Z.jsx)(G,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(W,{readOnly:!0,value:v_(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Z.jsx)(K,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,Z.jsx)(ua,{className:`h-4 w-4`}):(0,Z.jsx)(Ke,{className:`h-4 w-4`})})]}),(0,Z.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,Z.jsx)(Pn,{children:(0,Z.jsx)(K,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Z.jsxs)(`form`,{onSubmit:v,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Z.jsx)(Yt,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Z.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,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Z.jsxs)(Rn,{value:c,onValueChange:e=>l(e),children:[(0,Z.jsx)(ar,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Z.jsx)(Tt,{})}),(0,Z.jsxs)(jo,{children:[(0,Z.jsx)(Ye,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Z.jsx)(Ye,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Z.jsx)(Ye,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(K,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function b_(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function x_(){let{t:e}=z(),{org:t}=__(),{getMembers:n,removeMember:r,updateMemberRole:i}=S(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(!0),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),h=(0,X.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,X.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,Z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Z.jsx)(V,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,Z.jsx)(K,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,Z.jsx)(K,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Z.jsx)(Qt,{}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,Z.jsxs)(Ne,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Z.jsx)(qa,{src:t.user.image,alt:t.user.name}),(0,Z.jsx)(fi,{className:`text-xs font-medium`,children:b_(t.user?.name)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,Z.jsx)(H,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),t.createdAt&&(0,Z.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),(0,Z.jsxs)(zr,{children:[(0,Z.jsx)(ca,{asChild:!0,children:(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Z.jsx)(Yi,{className:`h-4 w-4`})})}),(0,Z.jsxs)(va,{align:`end`,children:[(0,Z.jsxs)(Qr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Z.jsx)(Ca,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Z.jsxs)(Qr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Z.jsx)(Ca,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Z.jsxs)(Qr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Z.jsx)(Ca,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Z.jsxs)(Qr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Z.jsx)(Be,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Z.jsx)(Vr,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Z.jsxs)(ei,{children:[(0,Z.jsxs)(oi,{children:[(0,Z.jsx)(vi,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Z.jsx)(ra,{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,Z.jsxs)($a,{children:[(0,Z.jsx)(Va,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(ba,{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,Z.jsx)(y_,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function S_(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function C_(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function w_(){let{t:e}=z(),{org:t}=__(),{listInvitations:n,cancelInvitation:r}=S(),[i,a]=(0,X.useState)([]),[o,s]=(0,X.useState)(!0),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(`all`),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),g=(0,X.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,X.useEffect)(()=>{g()},[g]);let _=async t=>{let n=S_(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,Z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Z.jsx)(V,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,Z.jsx)(K,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,Z.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,Z.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,Z.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:b[t]})]},t))}),(0,Z.jsx)(Qt,{}),y.length===0?(0,Z.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,Z.jsx)(`div`,{className:`space-y-2`,children:y.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Z.jsx)(Ne,{className:`h-9 w-9 shrink-0`,children:(0,Z.jsx)(fi,{className:`text-xs`,children:(0,Z.jsx)(Xe,{className:`h-4 w-4`})})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,Z.jsx)(H,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Z.jsx)(H,{variant:C_(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Z.jsx)(ua,{className:`h-4 w-4 text-green-600`}):(0,Z.jsx)(Ke,{className:`h-4 w-4`})}),(0,Z.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,Z.jsx)(vo,{className:`h-4 w-4`})})]})]},t.id))}),(0,Z.jsx)(Vr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Z.jsxs)(ei,{children:[(0,Z.jsxs)(oi,{children:[(0,Z.jsx)(vi,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Z.jsx)(ra,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Z.jsxs)($a,{children:[(0,Z.jsx)(Va,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(ba,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function T_(){let{t:e}=z(),{org:t}=__(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=S(),s=v(),[c,l]=(0,X.useState)(t.name),[u,d]=(0,X.useState)(t.slug??``),[f,p]=(0,X.useState)(t.logo??``),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),y=(0,X.useRef)(null),{upload:b}=no(),[x,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!0),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(``),[ee,te]=(0,X.useState)(!1);(0,X.useEffect)(()=>{l(t.name),d(t.slug??``),p(t.logo??``)},[t]),(0,X.useEffect)(()=>{let e=!1;return T(!0),r(t.id).then(t=>{e||C(t.find(e=>e.userId===n?.id)?.role===`owner`)}).catch(()=>{e||C(!1)}).finally(()=>{e||T(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let M=(0,X.useCallback)(async n=>{n.preventDefault(),h(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.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{h(!1)}},[t.id,c,u,f,i,e]);return w?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Z.jsx)(V,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Z.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,Z.jsx)(Qt,{className:`my-4`}),x?(0,Z.jsxs)(`form`,{onSubmit:M,className:`space-y-4 max-w-md`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Z.jsx)(W,{id:`org-name`,value:c,onChange:e=>l(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Z.jsx)(W,{id:`org-slug`,value:u,onChange:e=>d(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(G,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(Ne,{className:`size-16 rounded-md`,children:[f?(0,Z.jsx)(qa,{src:f,alt:c,className:`object-cover`}):null,(0,Z.jsx)(fi,{className:`rounded-md text-base`,children:(c||`O`).slice(0,2).toUpperCase()})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.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){_(!0);try{p((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{_(!1)}}},"data-testid":`settings-logo-file`}),(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,disabled:g,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[g?(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Z.jsx)(rn,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Z.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Z.jsx)(vo,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Z.jsx)(W,{id:`org-logo`,type:`url`,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Z.jsxs)(K,{type:`submit`,disabled:m,"data-testid":`settings-save-btn`,children:[m&&(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,Z.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,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,Z.jsx)(Qt,{className:`my-4`}),(0,Z.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,Z.jsx)(K,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Z.jsx)(Qt,{}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Z.jsx)(K,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Z.jsx)(Vr,{open:E,onOpenChange:D,children:(0,Z.jsxs)(ei,{children:[(0,Z.jsxs)(oi,{children:[(0,Z.jsx)(vi,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Z.jsx)(ra,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,Z.jsxs)($a,{children:[(0,Z.jsx)(Va,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(ba,{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`})),s(`/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,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Z.jsx)(Vr,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Z.jsxs)(ei,{children:[(0,Z.jsxs)(oi,{children:[(0,Z.jsx)(vi,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Z.jsx)(ra,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,Z.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,Z.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,Z.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,Z.jsxs)($a,{children:[(0,Z.jsx)(Va,{disabled:ee,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(ba,{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`})),s(`/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,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function E_(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Date.now()-n.getTime(),i=60*1e3,a=60*i,o=24*a;return r<i?t(`console.ai.justNow`):r<a?t(`console.ai.minutesAgo`,{count:Math.floor(r/i)}):r<o?t(`console.ai.hoursAgo`,{count:Math.floor(r/a)}):r<7*o?t(`console.ai.daysAgo`,{count:Math.floor(r/o)}):n.toLocaleDateString()}function D_({userId:e,apiBase:t,className:n,refreshKey:r,titleHints:i,onNavigate:a}){let{t:o}=z(),c=v(),{conversationId:l}=s(),{conversations:u,isLoading:d,error:f,remove:p,rename:m}=Ah({userId:e,apiBase:t,refreshKey:r}),[h,g]=(0,X.useState)(``),[_,y]=(0,X.useState)(void 0),b=(0,X.useMemo)(()=>u.map(e=>{let t=i?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[u,i]),x=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase();return e?b.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):b},[b,h]),S=(0,X.useCallback)(()=>{c(`/ai`),a?.()},[c,a]),C=(0,X.useCallback)(async(e,t)=>{e.stopPropagation(),await p(t),t===l&&(c(`/ai`,{replace:!0}),a?.())},[p,l,c,a]),w=(0,X.useCallback)(async(e,t)=>{y(void 0);try{await m(e,t)}catch{}},[m]);return(0,Z.jsxs)(`aside`,{className:U(`flex h-full min-h-0 flex-col bg-muted/30`,n),"data-testid":`ai-conversations-sidebar`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:o(`console.ai.chats`)}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:S,"data-testid":`ai-new-chat`,children:[(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),o(`console.ai.newChat`)]})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Co,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(W,{value:h,onChange:e=>g(e.target.value),placeholder:o(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Z.jsx)($n,{className:`flex-1 min-h-0`,children:d&&u.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:o(`common.loading`)}):f?(0,Z.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:f.message}):u.length===0?(0,Z.jsxs)(Et,{className:`px-3 py-8`,children:[(0,Z.jsx)(Ar,{className:`h-8 w-8 text-muted-foreground`}),(0,Z.jsx)(Ue,{children:o(`console.ai.noChatsYet`)}),(0,Z.jsx)(Kt,{children:o(`console.ai.noChatsDescription`)})]}):x.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:o(`console.ai.noMatchingChats`)}):(0,Z.jsx)(`ul`,{className:`flex flex-col py-1`,children:x.map(e=>(0,Z.jsx)(O_,{conversation:e,active:e.id===l,renaming:e.id===_,onSelect:()=>{c(`/ai/${e.id}`),a?.()},onDelete:t=>C(t,e.id),onStartRename:()=>y(e.id),onCancelRename:()=>y(void 0),onSubmitRename:t=>w(e.id,t)},e.id))})})]})}function O_({conversation:e,active:t,renaming:n,onSelect:r,onDelete:i,onStartRename:a,onCancelRename:o,onSubmitRename:s}){let{t:c}=z(),l=e.title?.trim()||e.preview?.trim()||c(`console.ai.newConversation`),[u,d]=(0,X.useState)(l),f=(0,X.useRef)(null);return(0,X.useEffect)(()=>{n&&(d(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>f.current?.select(),0))},[n,e.title,e.preview]),n?(0,Z.jsx)(`li`,{children:(0,Z.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,Z.jsx)(W,{ref:f,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s(u)):e.key===`Escape`&&(e.preventDefault(),o())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":c(`console.ai.renameConversation`)}),(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>s(u),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":c(`console.ai.saveRename`),children:(0,Z.jsx)(ua,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:o,"aria-label":c(`console.ai.cancelRename`),children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]})}):(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`div`,{className:U(`group flex w-full items-start gap-2 border-l-2 border-transparent px-3 py-2 text-sm transition-colors hover:bg-accent/50`,t&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,Z.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:l}),e.preview&&e.preview!==l?(0,Z.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:e.preview}):null,(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,children:E_(e.updatedAt??e.createdAt,c)})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[(0,Z.jsx)(K,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-primary`,onClick:a,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":c(`console.ai.renameConversation`),children:(0,Z.jsx)(Bt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-destructive`,onClick:i,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":c(`console.ai.deleteConversation`),children:(0,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]})]})})}var k_=`/api/v1/ai`;function A_(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function j_(e){let t=A_(e,`state`);switch(t){case`input-streaming`:case`input-available`:case`approval-requested`:case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return t;default:return}}function M_(e){return e.map(e=>{let t=[],n=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let n of e.parts){if(!n.type.startsWith(`tool-`))continue;let r=A_(n,`toolName`)??n.type.slice(5),i=A_(n,`toolCallId`)??`${e.id}-${r}`,a=j_(n);t.push({toolCallId:i,toolName:r,...a?{state:a}:{},...n.errorText?{errorText:String(n.errorText)}:{}})}return{id:e.id,role:e.role,content:n,...t.length>0?{toolInvocations:t}:{}}})}function N_(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var P_={data_chat:{key:`console.ai.agentLabels.dataChat`,defaultValue:`Data Assistant`},metadata_assistant:{key:`console.ai.agentLabels.metadataAssistant`,defaultValue:`Metadata Assistant`}};function F_(e,t,n){let r=t?P_[t]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function I_(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(/\/$/,``)}${k_}`}function L_({apiBase:e,defaultAgent:t}={}){let{user:n}=S(),{t:r}=z(),i=n?.id,{conversationId:a}=s(),[o]=m(),[c]=(0,X.useState)(()=>o.get(`agent`)??void 0),l=v(),{setContext:u}=Tc();(0,X.useEffect)(()=>{u(`home`)},[u]);let d=(0,X.useMemo)(()=>I_(e),[e]),f={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:p,isLoading:h,error:g}=qs({apiBase:d}),[_,y]=(0,X.useState)(void 0);(0,X.useEffect)(()=>{if(!_&&p.length>0){let e=Gs(p,c??t??f);e&&y(e)}},[p,_,c,t,f]);let b=_?`${d}/agents/${encodeURIComponent(_)}/chat`:void 0,{conversationId:x,initialMessages:C}=Ch({userId:i,scope:_,apiBase:d,activeId:a}),[w,T]=(0,X.useState)(0),[E,D]=(0,X.useState)({}),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(!1),ee=(0,X.useMemo)(()=>d.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[d]);(0,X.useEffect)(()=>{!a&&x&&l(`/ai/${x}`,{replace:!0})},[a,x,l]);let te=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{x&&C.length>0&&te.current.add(x)},[x,C.length]),(0,X.useEffect)(()=>{if(!x)return;let e=N_(C);e&&D(t=>t[x]===e?t:{...t,[x]:e})},[x,C]);let M=(0,X.useCallback)(e=>{if(T(e=>e+1),e&&x&&D(t=>({...t,[x]:e})),!e||!x||te.current.has(x))return;te.current.add(x);let t=()=>T(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[x]);return(0,Z.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,Z.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>j(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Z.jsx)(Me,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(vu,{variant:`home`})})]}),(0,Z.jsx)(on,{open:A,onOpenChange:j,children:(0,Z.jsxs)(pn,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Z.jsxs)(_t,{className:`sr-only`,children:[(0,Z.jsx)(Mt,{children:r(`console.ai.chats`)}),(0,Z.jsx)(En,{children:r(`console.ai.chatsDescription`)})]}),(0,Z.jsx)(D_,{userId:i,apiBase:d,refreshKey:w,titleHints:E,className:`h-full border-r-0`,onNavigate:()=>j(!1)})]})}),x&&(0,Z.jsx)(zn,{open:O,onOpenChange:k,objectName:`ai_conversations`,recordId:x,recordLabel:`this conversation`,apiBase:ee}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-muted/20`,children:[(0,Z.jsx)(D_,{userId:i,apiBase:d,refreshKey:w,titleHints:E,className:`hidden w-72 shrink-0 border-r md:flex`}),(0,Z.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Z.jsx)(R_,{agents:p,agentsLoading:h,agentsError:g,activeAgent:_,onAgentChange:y,chatApi:b,apiBase:d,conversationId:x,initialMessages:C,onSent:M,onShare:()=>k(!0)},`${b??`local`}:${x??`pending`}`)})]})]})}function R_({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,onAgentChange:i,chatApi:a,apiBase:o,conversationId:s,initialMessages:c,onSent:l,onShare:u}){let{t:d}=z(),f=v(),p=(0,X.useMemo)(()=>F_(d,r,e.find(e=>e.name===r)?.label??r??d(`console.ai.assistant`)),[e,r,d]),m=(0,X.useMemo)(()=>M_(c),[c]),h=(0,X.useMemo)(()=>{if(!(m.length>0))return H_(r,p,d)},[m.length,r,p,d]),{messages:g,isLoading:_,error:y,sendMessage:b,stop:x,reload:S,clear:C}=Us({api:a,conversationId:s,body:{context:{activeApp:`AI`,agentName:r,autoPublishAiBuilds:$o().features.autoPublishAiBuilds}},initialMessages:m,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,X.useEffect)(()=>{gh(s,_h(g))},[s,g]);let w=Ks({messages:g,apiBase:o,continueConversation:e=>{b(e)}}),T=(0,X.useCallback)((e,t)=>{b(e,t),l(e)},[b,l]);return(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 justify-center px-0`,children:(0,Z.jsx)(Ws,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,surface:`plain`,maxHeight:`100%`,headerSlot:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6`,children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:e.length>0?(0,Z.jsxs)(Rn,{value:r,onValueChange:i,disabled:t,children:[(0,Z.jsx)(ar,{className:`h-7 w-auto min-w-0 border-0 bg-transparent px-1.5 text-xs shadow-none hover:bg-accent focus:ring-0 focus:ring-offset-0 focus-visible:ring-1 focus-visible:ring-border/80 focus-visible:ring-offset-0 sm:min-w-[160px]`,"data-testid":`ai-chat-agent-picker`,children:(0,Z.jsx)(Tt,{placeholder:`Choose agent...`})}),(0,Z.jsx)(jo,{align:`start`,children:e.map(e=>(0,Z.jsxs)(Ye,{value:e.name,className:`text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:F_(d,e.name,e.label)}),e.description?(0,Z.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}):(0,Z.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground/85`,children:p})}),(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:u,disabled:!s,"aria-label":d(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:d(s?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Z.jsx)(ji,{className:`h-3.5 w-3.5`})})}),n?(0,Z.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:d(`console.ai.offlineDemoMode`)}):null]}),messages:g,placeholder:r?d(`console.ai.askAgent`,{agent:p}):d(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:d(`console.ai.emptyTitle`),emptyDescription:d(`console.ai.emptyDescription`),clear:d(`console.ai.clearConversation`),sendHint:d(`console.ai.sendHint`),agentActivity:d(`console.ai.agentActivity`),toolCompleted:d(`console.ai.toolCompleted`),toolRunning:d(`console.ai.toolRunning`),toolAwaitingApproval:d(`console.ai.toolAwaitingApproval`),toolFailed:d(`console.ai.toolFailed`),toolDetailsHidden:d(`console.ai.toolDetailsHidden`),copy:d(`console.ai.copy`),copied:d(`console.ai.copied`),regenerate:d(`console.ai.regenerate`),model:d(`console.ai.model`),submit:d(`console.ai.submit`),uploadFiles:d(`console.ai.uploadFiles`),stopResponse:d(`console.ai.stopResponse`),trace:d(`console.ai.trace`),viewTrace:d(`console.ai.viewTrace`)},suggestions:h,onSendMessage:T,onClear:C,hideClearBar:!0,onStop:_?x:void 0,onReload:S,isLoading:_,error:y,enableMarkdown:!0,onToolApprove:w.decide,toolDecisions:w.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:e=>f(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:d(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?q.warning(d(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):q.success(d(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),!0}catch(e){return q.error(d(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:d(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:d(`console.ai.published`,{defaultValue:`Published`}),autoPublishDrafts:$o().features.autoPublishAiBuilds,"data-testid":`ai-chat-panel`})})}function z_(e){return[e(`console.ai.suggestions.dataChat.userCount`,{defaultValue:`How many users are in the system? List their emails.`}),e(`console.ai.suggestions.dataChat.recentRecords`,{defaultValue:`List the 5 most recently created records.`}),e(`console.ai.suggestions.dataChat.recordCounts`,{defaultValue:`Count records for each object.`})]}function B_(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a CRM: customers, contacts and opportunities, with relationships.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project management app: projects, tasks and members.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a ticketing system: tickets, priority and a status flow.`})]}function V_(e){return[e(`console.ai.suggestions.generic.help`,{defaultValue:`What can you help me with?`}),e(`console.ai.suggestions.generic.availableObjects`,{defaultValue:`List the available data objects.`}),e(`console.ai.suggestions.generic.recentActivity`,{defaultValue:`Summarize my recent activity.`})]}function H_(e,t,n){if(e===`data_chat`)return z_(n);if(e===`metadata_assistant`)return B_(n);let r=(e??t).toLowerCase();return r.includes(`data`)?z_(n):r.includes(`metadata`)?B_(n):V_(n)}var U_=new Map;function W_(e){U_.set(e.ref,e)}function G_(e){return U_.get(e)}function K_({appSlug:e}={}){let t=v(),n=ks(),{entries:r}=Cs(n),[i,a]=X.useState(!1),[o,s]=X.useState(``),[c,l]=X.useState(null),[u,d]=X.useState(!1),[f,p]=X.useState(0),m=X.useMemo(()=>Fs(),[]);X.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)},[]),X.useEffect(()=>{if(!i||c!=null||u||r.length===0)return;d(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||l(t)}finally{e||d(!1)}})(),()=>{e=!0}},[i,c,u,r,n]);let h=X.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)||Ts(t.type,m,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(c??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[o,r,c]);X.useEffect(()=>{p(0)},[o,i]);function g(n){a(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function _(e){e.key===`ArrowDown`?(e.preventDefault(),p(e=>Math.min(e+1,h.length-1))):e.key===`ArrowUp`?(e.preventDefault(),p(e=>Math.max(e-1,0))):e.key===`Enter`&&h[f]&&(e.preventDefault(),g(h[f]))}return(0,Z.jsx)(mt,{open:i,onOpenChange:a,children:(0,Z.jsxs)(Ot,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Z.jsx)(ko,{className:`sr-only`,children:(0,Z.jsx)(Ge,{children:J(`engine.quickfind.title`,m)})}),(0,Z.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Z.jsx)(Co,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(W,{autoFocus:!0,placeholder:J(`engine.quickfind.placeholder`,m),value:o,onChange:e=>s(e.target.value),onKeyDown:_,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Z.jsx)(dt,{children:`esc`})]}),(0,Z.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[u&&(0,Z.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),J(`engine.quickfind.indexing`,m),` `,r.length,`…`]}),!u&&h.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:J(`engine.quickfind.noMatches`,m)}),(0,Z.jsx)(`ul`,{role:`listbox`,children:h.map((e,t)=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(e),onMouseEnter:()=>p(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===f?`bg-accent`:``),children:[(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:Ts(e.entry.type,m,e.entry.label)}),e.entry.description&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,Z.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,Z.jsx)(ot,{className:`h-3 w-3`})}),e.name,e.label&&(0,Z.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,Z.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,Z.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(dt,{children:`↑`}),` `,(0,Z.jsx)(dt,{children:`↓`}),` navigate`]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(dt,{children:`↵`}),` open`]}),(0,Z.jsxs)(`span`,{className:`ml-auto`,children:[(0,Z.jsx)(dt,{children:`⌘`}),(0,Z.jsx)(dt,{children:`⇧`}),(0,Z.jsx)(dt,{children:`M`}),` toggle`]})]})]})})}var q_={data:kt,ui:qt,automation:Qe,ai:_a,system:Ci,platform:Ci,identity:Ca,security:Ca},J_=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Y_=new Set([`field`,`package`]);function X_(){let e=ks(),{loading:t,error:n,entries:r}=Cs(e),i=X.useMemo(()=>Fs(),[]),[a,o]=X.useState(``),[s,c]=X.useState(`all`),[l,u]=X.useState(!1),[d,f]=m(),[p,g]=X.useState(null);X.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 _=d.get(`package`),v=X.useMemo(()=>p?_&&p.some(e=>e.id===_)?_:p[0]?.id??null:null,[p,_]);X.useEffect(()=>{if(!p||p.length===0||_&&p.some(e=>e.id===_))return;let e=new URLSearchParams(d);e.set(`package`,p[0].id),f(e,{replace:!0})},[p,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Ps(e,`warning`,v??void 0),E=X.useMemo(()=>r.filter(e=>Y_.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[r,v,w]),D=X.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(l&&!(e.allowOrgOverride||e.allowRuntimeCreate)||s!==`all`&&(e.domain??`other`)!==s)return!1;if(a){let t=a.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||Ts(e.type,i,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=X.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=J_.indexOf(e),r=J_.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||p===null||v&&T?(0,Z.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:J(`engine.directory.loading`,i)}):n?(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[J(`engine.directory.loadFailed`,i),`: `,n]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold`,children:J(`engine.directory.title`,i)}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:Y(`engine.directory.description`,i,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,Z.jsx)(Co,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(W,{className:`pl-8`,placeholder:J(`engine.directory.search`,i),value:a,onChange:e=>o(e.target.value)})]}),(0,Z.jsxs)(K,{variant:l?`default`:`outline`,size:`sm`,onClick:()=>u(e=>!e),children:[J(`engine.directory.writableOnly`,i),` (`,O,`)`]}),x.total>0&&(0,Z.jsx)(K,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,Z.jsxs)(h,{to:`./_diagnostics`,children:[(0,Z.jsx)(gt,{className:`h-3.5 w-3.5 mr-1`}),Y(`engine.directory.diagnosticsLink`,i,{count:x.total})]})}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[J(`engine.directory.quickFind`,i),` `,(0,Z.jsx)(dt,{children:`⌘`}),(0,Z.jsx)(dt,{children:`⇧`}),(0,Z.jsx)(dt,{children:`M`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Z.jsx)(Z_,{domain:`all`,label:J(`engine.directory.all`,i),active:s===`all`,count:D.all??0,onClick:()=>c(`all`)}),J_.filter(e=>D[e]).map(e=>(0,Z.jsx)(Z_,{domain:e,label:Ls(e,i),active:s===e,count:D[e]??0,onClick:()=>c(e)},e))]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[p.length===0&&(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`No project packages installed`}),(0,Z.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.`})]}),p.length>0&&k.length===0&&(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:J(`engine.directory.noMatches`,i)}),(0,Z.jsx)(Kt,{children:J(`engine.directory.noMatchesHint`,i)})]}),A.map(([e,t])=>(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,Z.jsx)(q_[e]??Gi,{className:`h-3.5 w-3.5`}),Ls(e,i),` (`,t.length,`)`]}),(0,Z.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,Z.jsx)(Q_,{entry:e,locale:i,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,Z.jsx)(K_,{})]})}function Z_({domain:e,label:t,active:n,count:r,onClick:i}){return(0,Z.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,Z.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Q_({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=Ts(e.type,t,e.label);return(0,Z.jsxs)(h,{to:o?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(o)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(n>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[n>0&&(0,Z.jsx)(`span`,{title:Y(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":Y(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,Z.jsx)(gt,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),s]}),(0,Z.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Z.jsx)(H,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:Y(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:Y(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:Y(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),a>0&&(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${a} locked item${a===1?``:`s`} — see ADR-0010`,"aria-label":`${a} locked items`,children:[(0,Z.jsx)(ot,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,Z.jsx)(H,{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:J(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Z.jsx)(H,{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:J(`engine.badge.createOnly`,t)}):(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:J(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var $_=`/api/v1/packages`;async function ev(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 tv({scope:e}){let t=X.useMemo(()=>Fs(),[]),n=e??`project`,r=n===`project`?`default`:n===`system`?`secondary`:`outline`,i=n===`project`?`engine.packages.scope.project`:n===`system`?`engine.packages.scope.system`:n===`cloud`?`engine.packages.scope.cloud`:``;return(0,Z.jsx)(H,{variant:r,children:i?J(i,t):n})}function nv({pkg:e}){let t=X.useMemo(()=>Fs(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,Z.jsx)(H,{variant:n?`default`:`outline`,children:J(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var rv=/^[a-z0-9][a-z0-9._-]{1,254}$/i,iv=/^\d+\.\d+\.\d+$/;function av({open:e,onOpenChange:t,onCreated:n}){let r=X.useMemo(()=>Fs(),[]),[i,a]=X.useState(``),[o,s]=X.useState(``),[c,l]=X.useState(`0.1.0`),[u,d]=X.useState(!1),[f,p]=X.useState(null);X.useEffect(()=>{e&&(a(``),s(``),l(`0.1.0`),p(null),d(!1))},[e]);let m=rv.test(i),h=iv.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await ev($_,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:i.trim(),name:o.trim(),version:c.trim(),type:`app`,scope:`project`}})}),n(i.trim()),t(!1)}catch(e){p(e?.message??J(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,Z.jsx)(mt,{open:e,onOpenChange:t,children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsx)(Ge,{children:J(`engine.packages.create.title`,r)}),(0,Z.jsx)(Yt,{children:Y(`engine.packages.create.description`,r,{example:`com.acme.crm`})})]}),(0,Z.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:`pkg-id`,children:J(`engine.packages.create.id`,r)}),(0,Z.jsx)(W,{id:`pkg-id`,placeholder:`com.acme.crm`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!!i&&!m}),!!i&&!m&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:J(`engine.packages.create.idInvalid`,r)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:`pkg-name`,children:J(`engine.packages.create.name`,r)}),(0,Z.jsx)(W,{id:`pkg-name`,placeholder:`Acme CRM`,value:o,onChange:e=>s(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:`pkg-version`,children:J(`engine.packages.create.version`,r)}),(0,Z.jsx)(W,{id:`pkg-version`,placeholder:`0.1.0`,value:c,onChange:e=>l(e.target.value),"aria-invalid":!!c&&!h}),!!c&&!h&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:J(`engine.packages.create.versionInvalid`,r)})]}),f&&(0,Z.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,Z.jsx)(gt,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{children:f})]})]}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:J(`engine.cancel`,r)}),(0,Z.jsx)(K,{onClick:_,disabled:!g,children:J(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function ov({label:e,children:t}){return(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function sv({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=X.useMemo(()=>Fs(),[]),[o,s]=X.useState(null),[c,l]=X.useState(null),[u,d]=X.useState(null);if(X.useEffect(()=>{l(null),s(null)},[e?.manifest.id]),X.useEffect(()=>{let t=e?.manifest.id;if(!n||!t){d(null);return}let r=!1;return ev(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{r||d(e?.drafts??[])}).catch(()=>{r||d([])}),()=>{r=!0}},[n,e?.manifest.id]),!e)return null;let f=e.manifest.id,p=e.enabled!==!1&&e.status!==`disabled`,m=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function g(e,t,n){s(e),l(null);try{await t(),l({kind:`ok`,text:n}),i()}catch(e){l({kind:`err`,text:e?.message??J(`engine.packages.detail.actionFailed`,a)})}finally{s(null)}}return(0,Z.jsx)(on,{open:n,onOpenChange:r,children:(0,Z.jsxs)(pn,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Z.jsxs)(_t,{children:[(0,Z.jsxs)(Mt,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Lr,{className:`h-4 w-4`}),e.manifest.name||f]}),(0,Z.jsx)(En,{className:`font-mono text-xs`,children:f})]}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(ov,{label:J(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,Z.jsx)(ov,{label:J(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,Z.jsx)(ov,{label:J(`engine.packages.col.scope`,a),children:(0,Z.jsx)(tv,{scope:e.manifest.scope})}),(0,Z.jsx)(ov,{label:J(`engine.packages.col.status`,a),children:(0,Z.jsx)(nv,{pkg:e})}),e.manifest.description&&(0,Z.jsx)(ov,{label:J(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,Z.jsx)(Qt,{className:`my-4`}),(0,Z.jsxs)(h,{to:`${t}/metadata/object?package=${encodeURIComponent(f)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,Z.jsx)(_n,{className:`h-3.5 w-3.5`}),J(`engine.packages.detail.browseMetadata`,a)]}),u&&u.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Qt,{className:`my-4`}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[J(`engine.packages.detail.pendingChanges`,a),(0,Z.jsx)(H,{variant:`secondary`,children:u.length})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J(`engine.packages.detail.pendingHint`,a)}),!m&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(K,{size:`sm`,onClick:()=>g(`publish-drafts`,()=>ev(`${$_}/${encodeURIComponent(f)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{d((await ev(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(f)}`))?.drafts??[])}catch{d([])}if(e?.failedCount)throw Error(Y(`engine.packages.detail.publishDraftsPartial`,a,{published:e.publishedCount??0,failed:e.failedCount}));return e}),J(`engine.packages.detail.publishDraftsOk`,a)),disabled:!!o,children:[(0,Z.jsx)(rn,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?J(`engine.packages.detail.publishing`,a):Y(`engine.packages.detail.publishApp`,a,{count:u.length})]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>ev(`${$_}/${encodeURIComponent(f)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{d((await ev(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(f)}`))?.drafts??[])}catch{d([])}if(e?.failedCount)throw Error(Y(`engine.packages.detail.discardDraftsPartial`,a,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),J(`engine.packages.detail.discardDraftsOk`,a)),disabled:!!o,children:[(0,Z.jsx)(fn,{className:`mr-1.5 h-3.5 w-3.5`}),o===`discard-drafts`?J(`engine.packages.detail.discarding`,a):Y(`engine.packages.detail.discardChanges`,a,{count:u.length})]})]}),(0,Z.jsx)(`ul`,{className:`space-y-1`,children:u.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(h,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>r(!1),children:[(0,Z.jsx)(Nr,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`))})]})]}),(0,Z.jsx)(Qt,{className:`my-4`}),m?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:J(`engine.packages.detail.kernelReadOnly`,a)}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.packages.detail.actions`,a)}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(K,{size:`sm`,onClick:()=>g(`publish`,()=>ev(`${$_}/${encodeURIComponent(f)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?Y(`engine.packages.detail.publishBlocked`,a,{count:t}):e.validationErrors?.[0]?.message||J(`engine.packages.detail.nothingToPublish`,a))}return e}),J(`engine.packages.detail.published`,a)),disabled:!!o,children:[(0,Z.jsx)(rn,{className:`mr-1.5 h-3.5 w-3.5`}),J(o===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>ev(`${$_}/${encodeURIComponent(f)}/revert`,{method:`POST`}),J(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,Z.jsx)(fn,{className:`mr-1.5 h-3.5 w-3.5`}),J(`engine.packages.detail.revert`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>ev(`${$_}/${encodeURIComponent(f)}/${p?`disable`:`enable`}`,{method:`PATCH`}),J(p?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,a)),disabled:!!o,children:[p?(0,Z.jsx)(Nn,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Z.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),J(p?`engine.packages.detail.disable`:`engine.packages.detail.enable`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`export`,async()=>{let e=await ev(`${$_}/${encodeURIComponent(f)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${f}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},J(`engine.packages.detail.exported`,a)),disabled:!!o,children:[(0,Z.jsx)(nn,{className:`mr-1.5 h-3.5 w-3.5`}),J(o===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(Y(`engine.packages.detail.deleteConfirm`,a,{name:e?.manifest.name||f}))){s(`delete`),l(null);try{await ev(`${$_}/${encodeURIComponent(f)}`,{method:`DELETE`}),i(),r(!1)}catch(e){l({kind:`err`,text:e?.message??J(`engine.packages.detail.deleteFailed`,a)})}finally{s(null)}}},disabled:!!o,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,Z.jsx)(In,{className:`mr-1.5 h-3.5 w-3.5`}),J(o===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,a)]})]})]}),c&&(0,Z.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 cv(){let e=X.useMemo(()=>Fs(),[]),{pathname:t}=u(),n=X.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[r,i]=X.useState([]),[a,o]=X.useState(!0),[s,c]=X.useState(null),[l,d]=X.useState(``),[f,p]=X.useState(!1),[m,h]=X.useState(!1),[g,_]=X.useState(null),[v,y]=X.useState(!1),b=X.useRef(null),[x,S]=X.useState(!1),[C,w]=X.useState(null),T=X.useCallback(async()=>{o(!0),c(null);try{let e=await ev($_),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),i(t)}catch(t){c(t?.message??J(`engine.packages.loadFailed`,e))}finally{o(!1)}},[e]);X.useEffect(()=>{T()},[T]),X.useEffect(()=>{if(!g)return;let e=r.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[r,g]);let E=X.useMemo(()=>{let e=l.trim().toLowerCase();return r.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[r,l,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(J(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(J(`engine.packages.import.invalidPackage`,e));w({kind:`ok`,text:Y(`engine.packages.import.success`,e,{id:(await ev(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})}))?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??J(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=r.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,Z.jsx)(Lr,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:J(`engine.packages.title`,e)}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:J(`engine.packages.description`,e)})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:a,children:[(0,Z.jsx)(Vi,{className:`mr-1.5 h-3.5 w-3.5 ${a?`animate-spin`:``}`}),J(`engine.packages.refresh`,e)]}),(0,Z.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,Z.jsx)(Nr,{className:`mr-1.5 h-3.5 w-3.5`}),J(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,Z.jsxs)(K,{size:`sm`,onClick:()=>h(!0),children:[(0,Z.jsx)(Oo,{className:`mr-1.5 h-3.5 w-3.5`}),J(`engine.packages.new`,e)]})]})]}),C&&(0,Z.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${C.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:C.text}),(0,Z.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Z.jsx)(Co,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(W,{className:`pl-8`,placeholder:J(`engine.packages.search`,e),value:l,onChange:e=>d(e.target.value)})]}),k>0&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(to,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,Z.jsx)(G,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:Y(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,Z.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:a?(0,Z.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,Z.jsx)(He,{className:`h-10 w-full`},e))}):s?(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,Z.jsx)(gt,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{children:s})]}):E.length===0?(0,Z.jsx)(`div`,{className:`p-8`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:J(`engine.packages.empty`,e)}),(0,Z.jsx)(Kt,{children:r.length===0?J(`engine.packages.emptyCreate`,e):J(`engine.packages.emptyFiltered`,e)})]})}):(0,Z.jsxs)(zi,{children:[(0,Z.jsx)(ni,{children:(0,Z.jsxs)(aa,{children:[(0,Z.jsx)(Ua,{children:J(`engine.packages.col.name`,e)}),(0,Z.jsx)(Ua,{children:`ID`}),(0,Z.jsx)(Ua,{className:`w-24`,children:J(`engine.packages.col.version`,e)}),(0,Z.jsx)(Ua,{className:`w-24`,children:J(`engine.packages.col.scope`,e)}),(0,Z.jsx)(Ua,{className:`w-24`,children:J(`engine.packages.col.status`,e)})]})}),(0,Z.jsx)(Ur,{children:E.map(e=>(0,Z.jsxs)(aa,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,Z.jsx)(xa,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Z.jsx)(xa,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Z.jsx)(xa,{children:e.manifest.version||`—`}),(0,Z.jsx)(xa,{children:(0,Z.jsx)(tv,{scope:e.manifest.scope})}),(0,Z.jsx)(xa,{children:(0,Z.jsx)(nv,{pkg:e})})]},e.manifest.id))})]})}),(0,Z.jsx)(av,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,Z.jsx)(sv,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var lv=new Set([`field`,`package`]),uv={data:kt,ui:qt,automation:Qe,ai:_a,system:Ci,platform:Ci,identity:Ca,security:Ca},dv={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`}},fv=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],pv=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],mv={object:br,dashboard:Dt,page:oo,report:yo,record:Gi,metadata:qt};function hv(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function gv(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 _v(){let e=ks(),{loading:t,entries:n}=Cs(e),{recentItems:r}=Wo(),i=X.useMemo(()=>Fs(),[]),[a,o]=m(),[s,c]=X.useState(null);X.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)),c(i.map(e=>({id:e.id,name:e.name})))}catch{t||c([])}})(),()=>{t=!0}},[e]);let l=a.get(`package`),u=X.useMemo(()=>s?l&&s.some(e=>e.id===l)?l:s[0]?.id??null:null,[s,l]);X.useEffect(()=>{if(!s||s.length===0||l&&s.some(e=>e.id===l))return;let e=new URLSearchParams(a);e.set(`package`,s[0].id),o(e,{replace:!0})},[s,l]);let d=u?`?package=${encodeURIComponent(u)}`:``,f=`metadata${d}`,p=`component/developer/packages${d}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Ps(e,`warning`,u??void 0),b=X.useMemo(()=>n.filter(e=>lv.has(e.type)||!u?!1:(v[e.type]??[]).includes(u)),[u,n,v]),x=X.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=X.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(fv.indexOf(e)===-1?99:fv.indexOf(e))-(fv.indexOf(t)===-1?99:fv.indexOf(t)))},[b,_]),C=X.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return pv.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||s===null||u&&y?(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:J(`engine.home.loading`,i)}):(0,Z.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,Z.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,Z.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,Z.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,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,Z.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`max-w-xl`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,Z.jsx)(_a,{className:`h-4 w-4`}),J(hv(),i)]}),(0,Z.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:J(`engine.home.subtitle`,i)}),(0,Z.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Z.jsx)(K,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,Z.jsxs)(h,{to:f,children:[(0,Z.jsx)(qt,{className:`mr-1.5 h-4 w-4`}),J(`engine.home.browseAll`,i)]})}),(0,Z.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,Z.jsx)(Co,{className:`h-3.5 w-3.5`}),J(`engine.directory.quickFind`,i),` ⌘⇧M`]})]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Z.jsx)(vv,{value:b.length,label:J(`engine.home.statTypes`,i)}),(0,Z.jsx)(vv,{value:x.length,label:J(`engine.home.statWritable`,i)}),(0,Z.jsx)(vv,{value:s.length,label:J(`engine.home.statPackages`,i)})]})]})]}),(0,Z.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Z.jsx)(yv,{icon:qt,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:J(`engine.home.statTypes`,i),to_link:f}),(0,Z.jsx)(yv,{icon:Hr,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:J(`engine.home.statWritable`,i),to_link:f}),(0,Z.jsx)(yv,{icon:Lr,from:`from-emerald-500`,to:`to-teal-600`,value:s.length,label:J(`engine.home.statPackages`,i),to_link:p}),(0,Z.jsxs)(h,{to:T?f:`metadata/_diagnostics${d}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,Z.jsx)(Hr,{className:`h-5 w-5`}):(0,Z.jsx)(gt,{className:`h-5 w-5`})}),(0,Z.jsx)(lr,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?J(`engine.home.allHealthy`,i):w}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:J(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,i)})]})]})]}),C.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(bv,{icon:Oo,title:J(`engine.home.quickActions`,i),hint:J(`engine.home.quickActionsHint`,i)}),(0,Z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,Z.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,Z.jsxs)(h,{to:`metadata/${encodeURIComponent(e.type)}/new${d}`,children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),Y(`engine.home.newItem`,i,{label:Ts(e.type,i,e.label)})]})},e.type))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,Z.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,Z.jsx)(bv,{icon:qt,title:J(`engine.home.explore`,i),hint:J(`engine.home.exploreHint`,i)}),(0,Z.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,Z.jsx)(xv,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:d},e))})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(bv,{icon:Ht,title:J(`engine.home.recent`,i)}),(0,Z.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:r.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:J(`engine.home.recentEmpty`,i)}):(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:r.slice(0,8).map(e=>{let t=mv[e.type]??Gi;return(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(h,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,Z.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,Z.jsx)(t,{className:`h-4 w-4`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:gv(e.visitedAt,i)})]}),(0,Z.jsx)(lr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Z.jsx)(K_,{})]})}function vv({value:e,label:t}){return(0,Z.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function yv({icon:e,from:t,to:n,value:r,label:i,to_link:a}){return(0,Z.jsxs)(h,{to:a,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.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,Z.jsx)(e,{className:`h-5 w-5`})}),(0,Z.jsx)(lr,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:r}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i})]})]})}function bv({icon:e,title:t,hint:n}){return(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,Z.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,Z.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function xv({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=uv[e]??Gi,o=dv[e]??dv.other,s=t.slice(0,6),c=t.length-s.length;return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.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,Z.jsx)(a,{className:`h-[18px] w-[18px]`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ls(e,r)}),(0,Z.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,J(`engine.home.typesLower`,r)]})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[s.map(e=>(0,Z.jsxs)(h,{to:`metadata/${encodeURIComponent(e.type)}${i}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,Z.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:Ts(e.type,r,e.label)}),(0,Z.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:n[e.type]??0})]},e.type)),c>0&&(0,Z.jsxs)(h,{to:`metadata${i}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${o.text} hover:underline`,children:[`+`,c]})]})]})}function Sv({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:a}){let o=e?.type??``,s=X.useMemo(()=>Fs(),[]),c=Ts(o,s,e?.label),{pathname:l}=u(),d=X.useMemo(()=>{let e=l.indexOf(`/metadata`);return e>=0?l.slice(0,e+9):`/metadata`},[l]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,Z.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,Z.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,Z.jsx)(h,{to:d,className:`hover:text-foreground shrink-0`,children:J(`engine.breadcrumb.allTypes`,s)}),(0,Z.jsx)(si,{className:`h-3 w-3 shrink-0`}),(0,Z.jsx)(h,{to:`${d}/${encodeURIComponent(o)}`,className:`hover:text-foreground shrink-0`,children:c}),(0,Z.jsx)(si,{className:`h-3 w-3 shrink-0`}),(0,Z.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ls(e.domain,s)}),e?.allowOrgOverride?(0,Z.jsx)(H,{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:J(`engine.badge.writable`,s)}):e?.allowRuntimeCreate?(0,Z.jsx)(H,{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:J(`engine.badge.createOnly`,s)}):(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:J(`engine.badge.readOnly`,s)})]}),n&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[r?.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),i]})]}):(0,Z.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Z.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,Z.jsx)(h,{to:d,className:`hover:text-foreground`,children:J(`engine.breadcrumb.allTypes`,s)}),(0,Z.jsx)(si,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{className:`text-foreground font-medium`,children:c})]}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:c}),(0,Z.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:o}),e?.domain&&(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ls(e.domain,s)}),e?.allowOrgOverride?(0,Z.jsx)(H,{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:J(`engine.badge.writable`,s)}):e?.allowRuntimeCreate?(0,Z.jsx)(H,{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:J(`engine.badge.createOnly`,s)}):(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:J(`engine.badge.readOnly`,s)})]}),n&&(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r?.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),i]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto`,children:a})]})}var Cv={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function wv(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 Tv({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=X.useState(null),o=X.useMemo(()=>E(),[]),s=X.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=wv(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,Z.jsx)(Z.Fragment,{children:s.map(e=>{let t=e.icon?pl(e.icon):null,n=i===e.name;return(0,Z.jsxs)(K,{size:`sm`,variant:Cv[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,Z.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,Z.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)})})}function Ev(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 Dv=new Map;function Ov(e){let t=Dv.get(e.type);if(!t){Dv.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Dv.set(e.type,n)}function kv(e){return Dv.get(e)}function Av(e){let t=[];for(let n of Dv.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 jv(e,t){let n=Dv.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 Mv(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 Nv({type:e}){let t=s(),n=e??t.type??``;if(n===`package`)return(0,Z.jsx)(i,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let r=kv(n);if(r?.ListPage){let e=r.ListPage;return(0,Z.jsx)(e,{type:n})}return(0,Z.jsx)(Pv,{type:n})}function Pv({type:e}){let t=v(),n=ks(),{entries:r}=Cs(n),i=r.find(t=>t.type===e),a=jv(e,i),[o,s]=X.useState([]),[c,l]=X.useState(!0),[u,d]=X.useState(null),[f,p]=X.useState(``),[g,_]=X.useState(`all`),[y,b]=m(),[x,S]=X.useState(0),[C,w]=X.useState(null);X.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=X.useMemo(()=>C?T&&C.some(e=>e.id===T)?T:C[0]?.id??null:null,[C,T]);X.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)}`:``;X.useEffect(()=>{let t=!1;return l(!0),d(null),(async()=>{try{let r=await n.list(e);if(t)return;s((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:Mv(t,e?.source),diagnostics:n}})),l(!1)}catch(e){t||(d(e?.message??String(e)),l(!1))}})(),()=>{t=!0}},[n,e,x]);let O=a.searchableFields??[`name`,`label`,`description`],k=o.filter(e=>{if(a.listFilter&&!a.listFilter(e.item)||!js(e.item,f,O)||g!==`all`&&e.source!==g||!E)return!1;let t=e.item?._packageId;return(!t||t===`sys_metadata`?null:t)===E}),A=X.useMemo(()=>{let e={all:o.length,artifact:0,runtime:0};for(let t of o)e[t.source]++;return e},[o]),j=X.useMemo(()=>o.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[o]),ee=X.useMemo(()=>o.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[o]),te=a.listColumns??Fv(a.primaryKey??`name`),M=Fs(),ne=Ts(e,M,i?.label??e),re=e=>{let t=`engine.list.col.${e.key}`,n=J(t,M);return n===t?e.label:n};return(0,Z.jsx)(Sv,{entry:i??{type:e,label:e},stats:[{label:J(`engine.list.items`,M),value:o.length},{label:J(`engine.list.filtered`,M),value:k.length},...j>0?[{label:J(`engine.list.invalid`,M),value:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Z.jsx)(gt,{className:`w-3.5 h-3.5`}),j]})}]:[],...ee>0?[{label:J(`engine.list.warnings`,M),value:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Z.jsx)(gt,{className:`w-3.5 h-3.5`}),ee]})}]:[]],actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Tv,{entry:i,location:`list_toolbar`,onAfter:()=>S(e=>e+1)}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>S(e=>e+1),title:J(`engine.list.refresh`,M),children:(0,Z.jsx)(Vi,{className:`h-4 w-4`})}),(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,Z.jsxs)(K,{size:`sm`,variant:a.createFields?`default`:`outline`,onClick:()=>t(`./new${D}`),title:a.createFields?Y(`engine.list.createHint`,M,{type:ne}):void 0,children:[(0,Z.jsx)(Oo,{className:`h-4 w-4 mr-1`}),J(`engine.list.create`,M)]})]}),children:(0,Z.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,Z.jsx)(Co,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(W,{className:`pl-8`,placeholder:J(`engine.list.search`,M),value:f,onChange:e=>p(e.target.value)})]}),(0,Z.jsxs)(Rn,{value:g,onValueChange:_,children:[(0,Z.jsx)(ar,{className:`w-[180px]`,children:(0,Z.jsx)(Tt,{})}),(0,Z.jsxs)(jo,{children:[(0,Z.jsxs)(Ye,{value:`all`,children:[J(`engine.list.allSources`,M),` (`,A.all,`)`]}),(0,Z.jsxs)(Ye,{value:`artifact`,children:[J(`engine.list.source.artifact`,M),` (`,A.artifact,`)`]}),(0,Z.jsxs)(Ye,{value:`runtime`,children:[J(`engine.list.source.runtime`,M),` (`,A.runtime,`)`]})]})]})]}),(c||C===null)&&(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[J(`engine.edit.loading`,M),` `,e,`…`]}),u&&(0,Z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:u}),!c&&!u&&C!==null&&C.length===0&&(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`No project packages installed`}),(0,Z.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.`})]}),!c&&!u&&C!==null&&C.length>0&&k.length===0&&(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:o.length===0?Y(`engine.list.emptyType`,M,{type:ne}):Y(`engine.list.emptyQuery`,M,{query:f})}),(0,Z.jsx)(Kt,{children:a.emptyStateHint??(i?.allowOrgOverride||i?.allowRuntimeCreate?Y(`engine.list.createHint`,M,{type:ne}):J(`engine.list.readOnlyHint`,M))}),o.length===0&&(i?.allowOrgOverride||i?.allowRuntimeCreate)&&(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsxs)(K,{onClick:()=>t(`./new${D}`),children:[(0,Z.jsx)(Oo,{className:`h-4 w-4 mr-1`}),J(`engine.list.create`,M)]})})]}),!c&&k.length>0&&(0,Z.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Z.jsxs)(`tr`,{children:[te.map(e=>(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:re(e)},e.key)),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:J(`engine.list.col.source`,M)})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:k.map((e,t)=>{let n=a.primaryKey??`name`,r=String(e.item[n]??`(unnamed-${t})`),i=e.diagnostics?.valid===!1,o=e.diagnostics?.errors??[],s=e.diagnostics?.warnings??[],c=!i&&s.length>0,l=i?o.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
14
|
+
`)+(o.length>3?`\n+${o.length-3} more`:``):c?s.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
|
|
15
|
+
`)+(s.length>3?`\n+${s.length-3} more`:``):``;return(0,Z.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(i?`bg-destructive/[0.04]`:c?`bg-amber-500/[0.05]`:``),children:[te.map((t,n)=>{let a=e.item[t.key],u=t.render?t.render(a,e.item):Iv(a);return(0,Z.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[i&&(0,Z.jsx)(`span`,{className:`inline-flex`,"aria-label":J(`engine.list.invalidTitle`,M),title:`${Y(`engine.list.invalidCount`,M,{count:o.length})}\n${l}`,children:(0,Z.jsx)(gt,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),c&&(0,Z.jsx)(`span`,{className:`inline-flex`,"aria-label":J(`engine.list.warnTitle`,M),title:`${Y(`engine.list.warnCount`,M,{count:s.length})}\n${l}`,children:(0,Z.jsx)(gt,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,Z.jsx)(h,{to:`./${encodeURIComponent(r)}${D}`,className:`text-primary hover:underline font-mono`,children:u})]}):u},t.key)}),(0,Z.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,Z.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,Z.jsx)(ot,{className:`h-3 w-3`})}),(0,Z.jsx)(H,{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`?`${J(`engine.list.source.artifactDesc`,M)}${e.item._packageId?` (${e.item._packageId})`:``}`:J(`engine.list.source.runtimeDesc`,M),children:J(`engine.list.source.${e.source}`,M)})]})]},r+t)})})]})})]})})}function Fv(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Iv(e){if(e==null||e===``)return(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,Z.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Lv={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 Rv(e,t){let n=zv(e)?e:{},r=zv(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`:Bv(o)===Bv(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 zv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Bv(e){try{return JSON.stringify(e,(e,t)=>zv(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Vv(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 Hv(e,t){if(e==null)return 0;let n=0;for(let r of Rv(e,t))r.status!==`unchanged`&&(n+=1);return n}function Uv({layered:e,loading:t,locale:n}){if(t)return(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:J(`engine.edit.loading`,n)});if(!e)return(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:J(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,Z.jsxs)(mi,{defaultValue:`diff`,className:`w-full`,children:[(0,Z.jsxs)(ha,{className:`grid grid-cols-4 w-fit`,children:[(0,Z.jsx)(La,{value:`diff`,children:J(`engine.layers.diff`,n)}),(0,Z.jsxs)(La,{value:`code`,children:[J(`engine.layers.code`,n),(0,Z.jsx)(H,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Z.jsxs)(La,{value:`overlay`,children:[J(`engine.layers.overlay`,n),r?(0,Z.jsx)(H,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Z.jsx)(H,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Z.jsxs)(La,{value:`effective`,children:[J(`engine.layers.effective`,n),(0,Z.jsx)(H,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Z.jsx)(Ja,{value:`diff`,className:`mt-3`,children:(0,Z.jsx)(Wv,{code:e.code,effective:e.effective,locale:n})}),(0,Z.jsx)(Ja,{value:`code`,className:`mt-3`,children:(0,Z.jsx)(Kv,{payload:e.code,emptyHint:J(`engine.layers.diff.noBaseline`,n)})}),(0,Z.jsx)(Ja,{value:`overlay`,className:`mt-3`,children:(0,Z.jsx)(Kv,{payload:e.overlay,emptyHint:J(`engine.layers.diff.noChanges`,n)})}),(0,Z.jsx)(Ja,{value:`effective`,className:`mt-3`,children:(0,Z.jsx)(Kv,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Wv({code:e,effective:t,locale:n}){let[r,i]=X.useState(!1);if(e==null)return(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:J(`engine.layers.diff.noBaseline`,n)});let a=X.useMemo(()=>Rv(e,t),[e,t]),o=X.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,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Y(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,Z.jsx)(to,{checked:r,onCheckedChange:i,"aria-label":J(`engine.layers.diff.showUnchanged`,n)}),J(`engine.layers.diff.showUnchanged`,n),(0,Z.jsx)(H,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:J(`engine.layers.diff.noChanges`,n)}):(0,Z.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,Z.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,Z.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.field`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.code`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.effective`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.status`,n)})]}),(0,Z.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Lv[e.status];return(0,Z.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,Z.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,Z.jsx)(Gv,{value:e.codeValue,muted:e.status===`added`}),(0,Z.jsx)(Gv,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:(0,Z.jsx)(`span`,{className:U(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:J(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function Gv({value:e,muted:t}){let n=Vv(e);return(0,Z.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 Kv({payload:e,emptyHint:t}){if(e==null)return(0,Z.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,Z.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var qv={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},Jv={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function Yv(e,t){return J(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function Xv(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function Zv(e,t){let n=0;for(let r of Rv(e,t))r.status!==`unchanged`&&(n+=1);return n}function Qv({published:e,draft:t,locale:n,className:r}){let i=X.useMemo(()=>Rv(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:J(`designer.draftReview.empty`,n)}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${Jv[t]}`,children:[(0,Z.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${qv[t]}`,children:Yv(t,n)}),(0,Z.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,Z.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Xv(e.effectiveValue)}):t===`removed`?(0,Z.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Xv(e.codeValue)}):(0,Z.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,Z.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Xv(e.codeValue)}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,Z.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Xv(e.effectiveValue)})]})]},e.key)})})}function $v(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 ey(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 ty(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function ny(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function ry(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return $v(n);case`plural-en`:return ey(n);case`titlecase`:return ty(n);case`first-token`:return ny(n);default:return n}}function iy(e){let{rules:t,draft:n,onPatch:r,enabled:i=!0}=e,a=(0,X.useRef)(new Set),o=(0,X.useRef)({}),s=(0,X.useCallback)(e=>{a.current.add(e)},[]);return(0,X.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=ry(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 ay(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 oy({type:e,name:t,parentItem:n,onOpen:r}){let i=ks(),a=v(),o=X.useMemo(()=>Av(e),[e]),[s,c]=X.useState([]),[l,u]=X.useState(``),[d,f]=X.useState({});if(X.useEffect(()=>{if(o.length===0){c([]);return}let e=!1,r=[...o].sort((e,t)=>(e.anchor.order??999)-(t.anchor.order??999)).map(e=>{if(e.anchor.source===`embedded`){let t=e.anchor.extract&&n?e.anchor.extract(n):[];return{childType:e.type,anchor:e.anchor,loading:!1,error:null,items:t.map(sy)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return c(r),Promise.all(r.map(async n=>{if(n.anchor.source===`embedded`)return n;try{let r=await i.list(n.childType);if(e)return n;let a=n.anchor.match??(()=>!1),o=r.filter(e=>a(e,t)).map(e=>sy(e));return{...n,loading:!1,items:o}}catch(t){return e?n:{...n,loading:!1,error:t instanceof Error?t.message:String(t)}}})).then(t=>{e||c(t)}),()=>{e=!0}},[i,e,t,o,n]),o.length===0)return(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`No related metadata`}),(0,Z.jsxs)(Kt,{children:[`No metadata types are configured to anchor at `,(0,Z.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let p=s.reduce((e,t)=>e+t.items.length,0),m=s.some(e=>e.loading),h=l.trim().toLowerCase();return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,Z.jsx)(Co,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(W,{placeholder:`Search related…`,value:l,onChange:e=>u(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:m?`Scanning…`:`${p} item${p===1?``:`s`}`})]}),s.map(n=>{let i=h?n.items.filter(e=>e.name.toLowerCase().includes(h)||(e.label??``).toLowerCase().includes(h)):n.items,o=d[n.childType]??!1;return!(!h||i.length>0)&&!n.loading?null:(0,Z.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>f(e=>({...e,[n.childType]:!o})),children:[(0,Z.jsx)(si,{className:U(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`})})]}),!o&&(0,Z.jsxs)(`div`,{children:[n.loading&&(0,Z.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,Z.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:h?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,Z.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,Z.jsx)(`th`,{className:`w-8`})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,Z.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,Z.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,Z.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,Z.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,Z.jsx)(_n,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function sy(e){return{name:cy(e,[`name`,`id`,`key`])??`(unnamed)`,label:cy(e,[`label`,`title`,`displayName`]),description:cy(e,[`description`,`summary`]),raw:e}}function cy(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function ly({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=X.useMemo(()=>Fs(),[]),c=ks(),{entries:l}=Cs(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?dy[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=X.useState(a),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState([]),[S,C]=X.useState(null);X.useEffect(()=>{h(a),y(null),x([]),C(null)},[a,r,e,t]);let w=u!=null&&!u.allowOrgOverride&&!u.allowRuntimeCreate;async function T(){if(!n){y(J(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=uy(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:Es(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?J(`engine.validation.failedOne`,s):Y(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,Z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,Z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,Z.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:J(`engine.embedded.saved`,s)}),w&&(0,Z.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:J(`engine.embedded.readOnlyParent`,s)}),(0,Z.jsx)(Ms,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,Z.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,Z.jsxs)(K,{onClick:T,disabled:g||!n,children:[g?(0,Z.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-4 w-4 mr-1`}),Y(`engine.embedded.saveIntoParent`,s,{parentType:e})]})}),!n&&(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:J(`engine.embedded.readOnly`,s)}),(0,Z.jsx)(`div`,{children:J(`engine.embedded.noPathHint`,s)})]})]}):(0,Z.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Y(`engine.embedded.noSchema`,s,{type:i??`this item`,target:`${e}/${t}.${n}.${r}`})}),(0,Z.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(m,null,2),onChange:e=>{try{h(JSON.parse(e.target.value)),y(null)}catch(e){y(`${J(`engine.form.invalidJson`,s)}: ${e.message}`)}}}),v&&(0,Z.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,Z.jsx)(gt,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsxs)(K,{onClick:T,disabled:g||!n,children:[g?(0,Z.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-4 w-4 mr-1`}),Y(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function uy(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 dy={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 fy({target:e,onClose:t,parentContext:n}){let r=v(),i=e?.kind===`metadata`,a=e?.kind===`embedded`,o=i?e.type:a?e.groupLabel:``,s=i?e.name:a?e.itemName:``;return(0,Z.jsx)(on,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Z.jsxs)(pn,{side:`right`,className:U(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(H,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,Z.jsx)(Mt,{className:`font-mono text-base truncate`,children:s}),(0,Z.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,Z.jsx)(_n,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Z.jsxs)(En,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,Z.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,Z.jsx)(sb,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,Z.jsx)(ly,{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 py({type:e,name:t}){let n=s(),r=e??n.type??``,i=t??n.name??``,a=v(),o=ks(),{entries:c}=Cs(o),l=c.find(e=>e.type===r),[u,d]=X.useState(0),[f,p]=X.useState(0);return(0,Z.jsx)(Sv,{entry:l??{type:r,label:r},itemName:i,subtitle:`Version history`,stats:[{label:`Events`,value:f}],actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>a(`../${encodeURIComponent(i)}`),children:[(0,Z.jsx)(Wt,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>d(e=>e+1),children:(0,Z.jsx)(Vi,{className:`h-4 w-4`})})]}),children:(0,Z.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Z.jsx)(my,{type:r,name:i,refreshKey:u,onCount:p,client:o,onRollback:()=>d(e=>e+1)})})})}function my({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=X.useState([]),[u,d]=X.useState(!0),[f,p]=X.useState(null),[m,h]=X.useState(null),[g,_]=X.useState(null),[v,y]=X.useState(0);X.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,Z.jsxs)(Z.Fragment,{children:[u&&(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,Z.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,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`No history yet`}),(0,Z.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,Z.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,Z.jsxs)(`li`,{className:`relative`,children:[(0,Z.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Z.jsx)(H,{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,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:hy(i)}),o&&(0,Z.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,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(st,{className:`h-3.5 w-3.5`})})]}),n&&(0,Z.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:gy(e)})]})]},`${e.seq??t}-${t}`)})})]})}function hy(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function gy(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function _y(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function vy(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:Ca},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:ii},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:sa}},n=t[e]??t.allowed;return(0,Z.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,Z.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function yy({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=X.useState(!1),[o,s]=X.useState(null),[c,l]=X.useState(null),u=X.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 X.useEffect(()=>{u()},[u]),(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,J(`engine.edit.auditCount`,r)]}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:J(`engine.edit.refresh`,r),children:[i?(0,Z.jsx)(V,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Vi,{className:`h-3 w-3`}),J(`engine.edit.refresh`,r)]})]}),o&&(0,Z.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,Z.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`mr-2 h-3 w-3 animate-spin`}),J(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Z.jsxs)(Et,{className:`py-10`,children:[(0,Z.jsx)(Ue,{children:J(`engine.edit.auditEmptyTitle`,r)}),(0,Z.jsx)(Kt,{children:J(`engine.edit.auditEmptyDescription`,r)})]}):(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColTime`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColActor`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColOperation`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColOutcome`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColLock`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColNote`,r)})]})}),(0,Z.jsx)(`tbody`,{children:c.map(e=>(0,Z.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:_y(e.occurredAt)}),(0,Z.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,Z.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,Z.jsx)(`td`,{className:`px-2 py-1.5`,children:vy(e.outcome)}),(0,Z.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,Z.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,Z.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 by=new Map;function xy(e,t){by.set(e,t)}function Sy(e){return by.get(e)}var Cy=new Map;function wy(e,t){Cy.set(e,t)}function Ty(e){return Cy.get(e)}var Ey=new Map;function Dy(e,t){Ey.set(e,t)}function Oy(e){return Ey.get(e)}function ky(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&&My(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&My(e.charCodeAt(r)))for(r++;r<e.length&&My(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&&My(e.charCodeAt(r))){for(r++;r<e.length&&My(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+=`
|
|
16
|
+
`;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(jy(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(Ay(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Ay(t));return o=15}if(jy(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
17
|
+
`),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&&!jy(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++,jy(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||!My(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(Ay(e)||jy(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 Ay(e){return e===32||e===9}function jy(e){return e===10||e===13}function My(e){return e>=48&&e<=57}var Ny;(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`})(Ny||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var Py=200;Array(Py).fill(0).map((e,t)=>`
|
|
18
|
+
`+` `.repeat(t)),Array(Py).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Py).fill(0).map((e,t)=>`\r
|
|
19
|
+
`+` `.repeat(t)),Array(Py).fill(0).map((e,t)=>`
|
|
20
|
+
`+` `.repeat(t)),Array(Py).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Py).fill(0).map((e,t)=>`\r
|
|
21
|
+
`+` `.repeat(t));var Fy;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Fy||={});function Iy(e,t=[],n=Fy.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}Ry(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:zy(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 Ly(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 Ry(e,t,n=Fy.DEFAULT){let r=ky(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 zy(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 By;(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`})(By||={});var Vy;(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`})(Vy||={});var Hy=Iy,Uy=Ly,Wy;(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`})(Wy||={});var Gy=X.lazy(async()=>({default:(await d(()=>import(`./dist-DYcwLEm6.js`),[],import.meta.url)).default}));function Ky(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function qy(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function Jy({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let a=X.useMemo(()=>Fs(),[]),[o,s]=X.useState(()=>Ky(e)),[c,l]=X.useState(null),u=X.useRef(o),d=X.useRef(null),f=X.useRef(null),[p,m]=X.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>m(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let h=X.useCallback(()=>{let e=d.current,t=f.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=Hy(o)}catch{i=void 0}let a=r.map(e=>{let r=qy(e.path),a=1,o=1,s=1,c=2,l=i?Uy(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`,a)},[r,o]);return X.useEffect(()=>{h()},[h]),X.useEffect(()=>{let t=Ky(e);t!==u.current&&(s(t),u.current=t,l(null))},[e]),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(`div`,{className:`border rounded overflow-hidden bg-background`,style:{height:typeof i==`number`?`${i}px`:i},children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(He,{className:`w-full h-full`}),children:(0,Z.jsx)(Gy,{value:o,language:`json`,theme:p,onChange:e=>{let n=e??``;s(n);try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)?(l(null),u.current=n,t(e)):l(J(`engine.form.rootJsonObject`,a))}catch(e){l(e?.message??J(`engine.form.invalidJson`,a))}},onMount:(e,t)=>{d.current=e,f.current=t,setTimeout(h,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}}})})}),c&&(0,Z.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,Z.jsx)(`span`,{children:c})]})]})}var Yy={object:async()=>(await d(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.i);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await d(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.i);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await d(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.i);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await d(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.i);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await d(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await d(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await d(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await d(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await d(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await d(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await d(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.g);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await d(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.a);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await d(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.a);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await d(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.s);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await d(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.s);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await d(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.s);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await d(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await d(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await d(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await d(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await d(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await d(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await d(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-B2q1QmZh.js`).then(e=>e.o);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},Xy=new Set([`approval`,`connector_action`]),Zy=/^nodes\.(\d+)\.type$/;function Qy(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 $y=new Map;async function eb(e){if($y.has(e))return $y.get(e)??null;let t=Yy[e];if(!t)return $y.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return $y.set(e,r),r}catch{return $y.set(e,null),null}}function tb(e){return e in Yy}async function nb(e,t,n){let r=await eb(e);if(!r)return{ok:!0,issues:[]};let i=r.safeParse(t);if(i.success)return{ok:!0,issues:[]};let a=i.error?.issues??[],o=Array.isArray(n?.required)?new Set(n.required.map(e=>String(e))):void 0;if(o&&t&&typeof t==`object`&&!Array.isArray(t)){let e=t;a=a.filter(t=>{let n=t.path??[];if(n.length!==1)return!0;let r=String(n[0]);return!((e[r]===void 0||e[r]===null)&&!o.has(r))})}return e===`flow`&&(a=a.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=Zy.exec(n);if(!r)return!0;let i=Qy(t,Number(r[1]));return!(i&&Xy.has(i))})),a.length===0?{ok:!0,issues:[]}:{ok:!1,issues:a.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message}))}}var rb=Ma,ib=new Set([`object`]),ab={object:[`fields`,`fieldGroups`]};function ob(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 sb({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=s(),a=e??i.type??``,o=t??i.name??``,c=kv(a);if(c?.EditPage&&!n){let e=c.EditPage;return(0,Z.jsx)(e,{type:a,name:o})}if(c?.CreatePage&&n){let e=c.CreatePage;return(0,Z.jsx)(e,{type:a})}return(0,Z.jsx)(cb,{type:a,name:o,createMode:n,embedded:r})}function cb({type:e,name:t,createMode:n,embedded:r}){let i=v(),[a,o]=m(),s=ks(),{entries:c}=Cs(s),l=c.find(t=>t.type===e),u=jv(e,l),d=(n&&u.createSchema?u.createSchema:l?.schema)??u.defaultSchema,f=X.useMemo(()=>Fs(),[]),[p,h]=X.useState(null),g=u.identityField??`name`,[_,y]=X.useState(()=>n?{...u.createDefaults??{},[g]:``}:{}),[b,x]=X.useState(null),[S,C]=X.useState(!n),[w,T]=X.useState(!1),[E,D]=X.useState(null),[O,k]=X.useState([]),A=X.useCallback(e=>{y(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&k(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)})),n})},[]),[j,ee]=X.useState(null),[te,M]=X.useState(null),ne=X.useCallback(e=>{A(t=>({...t,...e}))},[A]),{markTouched:re}=iy({rules:u.createDerive,draft:_,onPatch:ne,enabled:!!n}),N=X.useMemo(()=>{if(n)return u.createFields&&u.createFields.length>0?u.createFields:ay(d?.properties??void 0,d?.required??void 0)},[n,u.createFields,d]),ie=X.useMemo(()=>{let t=ab[e]??[];if(!n||!N)return t.length===0?u.hiddenFields:Array.from(new Set([...u.hiddenFields??[],...t]));let r=d?.properties??{},i=new Set(N),a=Object.keys(r).filter(e=>!i.has(e));if(u.hiddenFields)for(let e of u.hiddenFields)a.includes(e)||a.push(e);for(let e of t)a.includes(e)||a.push(e);return a},[n,N,d,u.hiddenFields,e]),P=X.useMemo(()=>n&&N?N:u.fieldOrder,[n,N,u.fieldOrder]),F=X.useCallback(e=>{if(n){let t=_,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])||re(e)}A(e)},[n,_,A,re]);X.useEffect(()=>{if(!tb(e))return;let t=!1,n=window.setTimeout(()=>{nb(e,_,l?.schema).then(e=>{t||k(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,_,l?.schema]);let[ae,oe]=X.useState(!1),[se,ce]=X.useState(!1),[le,ue]=X.useState(0),[de,fe]=X.useState(!!n),[pe,me]=X.useState(null);X.useEffect(()=>{me(null)},[e,t]),X.useEffect(()=>{de||me(null)},[de]);let he=X.useRef(null),[ge,_e]=X.useState(null),[ve,I]=X.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}});X.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,ve?`1`:`0`)}catch{}},[ve]);let L=X.useRef(null),[R,ye]=X.useState([]),[z,B]=X.useState(!0);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await s.list(`object`);if(e)return;ye(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||ye([])}finally{e||B(!1)}})(),()=>{e=!0}},[s]);let be=X.useMemo(()=>({objectNames:R,objectsLoading:z}),[R,z]);X.useEffect(()=>{if(n){C(!1);return}let r=!1;return C(!0),D(null),(async()=>{try{let[n,i]=await Promise.all([s.layered(e,t),s.getDraft(e,t).catch(()=>null)]);if(r)return;h(n);let a=n?._diagnostics;a&&a.valid===!1&&Array.isArray(a.errors)?k(a.errors.map(e=>({path:e.path||``,message:e.message}))):k([]);let o=ob(i),c=o??n.effective??n.code??{},l=u.toDraft?u.toDraft(c):c;y(l),he.current=l,oe(!!o),C(!1)}catch(e){r||(D(e?.message??String(e)),C(!1))}})(),()=>{r=!0}},[s,e,t,n,le]);let[xe,Se]=X.useState(!1);async function Ce(){if(!(b!=null||xe)){Se(!0);try{x(await s.references(e,t))}catch(e){x([]),console.error(`references() failed`,e)}finally{Se(!1)}}}let[we,Te]=X.useState(null),Ee=X.useMemo(()=>!n&&!r&&Av(e).length>0,[e,n,r]),De=X.useRef(null),[Oe,ke]=X.useState(null),Ae=a.get(`review`),je=X.useRef(!1);X.useEffect(()=>{if(!(Ae!==`1`||n)){if(!je.current){je.current=!0,ue(e=>e+1);return}if(!S){ae&&ke(`review`);let e=new URLSearchParams(a);e.delete(`review`),o(e,{replace:!0}),je.current=!1}}},[Ae,n,S,ae]);let[Me,Ne]=X.useState(`properties`);X.useEffect(()=>{if(Oe===`references`&&Ce(),typeof window<`u`&&!r){let e=new URL(window.location.href);Oe?e.searchParams.set(`tab`,Oe):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[Oe,r]);let Pe=`metadata-edit:inspector-collapsed`,Fe=`metadata-edit:inspector-size`,[Ie,Le]=X.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Pe)===`1`),Re=X.useRef(38);X.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(Fe));Number.isFinite(e)&&e>=22&&e<=80&&(Re.current=e)},[]);let ze=X.useRef(null),Be=X.useCallback(()=>{Le(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Pe,t?`1`:`0`),t})},[]);X.useEffect(()=>{let e=ze.current;if(e)if(Ie)e.resize?.(`0%`);else{let t=Re.current||38;e.resize?.(`${t}%`)}},[Ie]);let[He,Ue]=X.useState(!1),[We,Ke]=X.useState(!1);X.useEffect(()=>{if(typeof document>`u`||!We)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[We]),X.useEffect(()=>{if(typeof window>`u`||!We)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Ke(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[We]);let qe=X.useRef(null);X.useEffect(()=>{qe.current=null},[e,t]),X.useEffect(()=>{if(n||r||S)return;let i=`${e}/${t??``}`;qe.current!==i&&Sy(e)&&(p?.code==null?l?.allowOrgOverride||l?.allowRuntimeCreate:l?.allowOrgOverride)&&(qe.current=i,fe(!0))},[e,t,n,r,S,l,p]),X.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(),Be())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Be]),X.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`)&&ke(t),De.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&Te({kind:`metadata`,type:e,name:t})}},[]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);we?.kind===`metadata`?e.searchParams.set(`open`,`${we.type}:${we.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[we,r]);function Je(e){let t=e.split(`.`)[0];if(!t)return e;let r=n&&u.createSchema?void 0:l?.form,i=Array.isArray(r?.sections)?r.sections:[];for(let e of i){let n=Array.isArray(e?.fields)?e.fields:[];for(let e of n)if(typeof e==`string`){if(e===t)return e}else if(e?.field===t)return String(e.label??t)}let a=d?.properties??{};return String(a[t]?.title??t)}async function Ye(r){T(!0),D(null),k([]);try{let a=n?u.createBuildBody?u.createBuildBody(_):{...u.createDefaults??{},..._}:u.fromDraft?u.fromDraft(_):_;if(n&&u.createSeed)try{let e=await u.createSeed(_,{client:s});e&&typeof e==`object`&&(a={...a,...e})}catch{}let o=String(a[g]??_[g]??t),c=n?{...a,[g]:o}:a;if(!o){D(J(`engine.validation.nameRequired`,f)),T(!1);return}let l=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await s.save(e,o,c,{force:r,mode:`draft`,...l?{packageId:l}:{}});let[d,p]=await Promise.all([s.layered(e,o),s.getDraft(e,o).catch(()=>null)]);h(d);let m=ob(p);oe(!!m);let v=m??d.effective??c,b=u.toDraft?u.toDraft(v):v;y(b),he.current=b,_e(new Date),L.current=JSON.stringify(b),ee(null),M(null);let x=!n&&!!Sy(e);!n&&!x&&fe(!1),n&&i(`../${encodeURIComponent(o)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];ee(Array.isArray(t)?t:[]),M(_)}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:Es(String(e.message??`Invalid`),f)})),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:Es(e[2].trim(),f)}]:[{path:``,message:Es(r,f)}]}k(n),n.length===1&&!n[0].path?D(n[0].message):n.length===1?D(`${Je(n[0].path)}: ${n[0].message}`):D(Y(`engine.validation.failed`,f,{count:n.length}))}else D(e?.message??String(e))}finally{T(!1)}}async function Xe(){let r=!n&&p?.code!=null;if(confirm(Y(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,f,{type:e,name:t??``}))){T(!0),D(null);try{if(await s.reset(e,t),r){let n=await s.layered(e,t);h(n);let r=n.effective??n.code??{};y(r),he.current=r,Sy(e)?qe.current=null:fe(!1)}else i(`../`,{relative:`path`})}catch(e){D(e?.message??String(e))}finally{T(!1)}}}async function Qe(){ce(!0),D(null);try{await s.publish(e,t);let[n,r]=await Promise.all([s.layered(e,t),s.getDraft(e,t).catch(()=>null)]);h(n);let i=ob(r);oe(!!i);let a=i??n.effective??_;y(a),he.current=a}catch(e){D(e?.message??String(e))}finally{ce(!1)}}async function $e(){if(confirm(Y(`engine.edit.discardDraftConfirm`,f,{type:e,name:t??``}))){T(!0),D(null);try{await s.reset(e,t,{state:`draft`});let n=await s.layered(e,t);h(n);let r=n.effective??n.code??{};y(r),he.current=r,oe(!1)}catch(e){D(e?.message??String(e))}finally{T(!1)}}}let et=X.useMemo(()=>{if(n)return Object.keys(_).length>0;let e=he.current;if(!e)return!1;try{return JSON.stringify(_)!==JSON.stringify(e)}catch{return!1}},[_,n]),tt=!n&&p?.code!=null,nt=p?.editable!==!1,rt=p?.deletable!==!1,it=p?.resettable!==!1,at=p?.lockReason,lt=p?.lock&&p.lock!==`none`,ut=(n?!!(l?.allowOrgOverride||l?.allowRuntimeCreate):tt?!!l?.allowOrgOverride:!!(l?.allowOrgOverride||l?.allowRuntimeCreate))&&(n||nt),dt=!ut&&!n,ft=X.useRef(Ye);if(X.useEffect(()=>{ft.current=Ye}),X.useEffect(()=>{if(!ve||n||dt||!de||!et||w)return;let e;try{e=JSON.stringify(_)}catch{return}if(e===L.current)return;let t=window.setTimeout(()=>{L.current=e,ft.current(!1)},1500);return()=>window.clearTimeout(t)},[_,et,de,w,n,dt,ve]),X.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!ut||dt||!de&&!n)return;e.preventDefault(),!w&&(n||et)&&ft.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ut,dt,de,n,w,et]),X.useEffect(()=>{if(!et)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[et]),X.useEffect(()=>{if(!et)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(J(`engine.edit.unsavedLeaveConfirm`,f))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[et,f]),il(X.useMemo(()=>{if(r)return null;let n=String(_.name??t??``);if(!n)return null;let i={type:e,name:n,label:typeof _.label==`string`?_.label:void 0};return e===`object`&&(i.fields=Uu(_.fields).entries.slice(0,60).map(e=>({name:e.name,type:typeof e.def.type==`string`?e.def.type:void 0,label:typeof e.def.label==`string`?e.def.label:void 0,required:!!e.def.required||void 0}))),i},[r,e,t,_])),S)return(0,Z.jsx)(Sv,{entry:l,itemName:t,children:(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let pt=dt&&tt&&!!l?.allowRuntimeCreate,ht=ib.has(e),vt=!r&&(!n||ht)?Sy(e):void 0,yt=Ty(e),bt=Oy(e);function St(){he.current&&y(he.current),k([]),D(null),fe(!1)}let Ct=dt||!de&&!n,wt=(0,Z.jsxs)(Z.Fragment,{children:[!n&&(0,Z.jsx)(Tv,{entry:l,location:`record_header`,recordId:t,onAfter:()=>ue(e=>e+1)}),(!n||Ee)&&(0,Z.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`layers`),title:J(`engine.edit.layers`,f),className:`h-7 w-7 p-0 relative`,children:[(0,Z.jsx)(qt,{className:`h-3.5 w-3.5`}),p?.overlay&&(()=>{let e=Hv(p.code,p.effective);return e>0?(0,Z.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:J(`engine.layers.diff`,f),children:e}):null})()]}),!n&&ae&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`review`),title:J(`designer.draftReview.title`,f),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,Z.jsx)(Fa,{className:`h-3.5 w-3.5`}),(()=>{let e=Zv(p?.effective??null,_);return e>0?(0,Z.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-amber-500 text-amber-50 text-[9px] leading-[14px] text-center font-medium`,title:Y(`designer.draftReview.badge`,f,{n:e}),children:e}):null})()]}),!n&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`references`),title:J(`engine.edit.references`,f),className:`h-7 w-7 p-0 relative`,children:[(0,Z.jsx)($t,{className:`h-3.5 w-3.5`}),b&&b.length>0&&(0,Z.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:b.length})]}),Ee&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`related`),title:J(`engine.edit.related`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(Ve,{className:`h-3.5 w-3.5`})}),!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`history`),title:J(`engine.edit.history`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(gr,{className:`h-3.5 w-3.5`})}),!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>ke(`audit`),title:J(`engine.edit.auditTab`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(Ca,{className:`h-3.5 w-3.5`})})]}),!n&&ut&&p?.overlay&&(tt?it:rt)&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Xe,disabled:w,title:J(tt?`engine.edit.reset`:`engine.edit.delete`,f),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:tt?(0,Z.jsx)(st,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(In,{className:`h-3.5 w-3.5`})}),ut&&!n&&!de&&!vt&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>fe(!0),className:`h-7`,children:[(0,Z.jsx)(Bt,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.edit.edit`,f)]}),ut&&(de||n)&&(0,Z.jsx)(ub,{saving:w,isDirty:et,autoSaveEnabled:ve,lastSavedAt:ge,createMode:!!n,locale:f}),ut&&(de||n)&&!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>I(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:J(ve?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,f),children:ve?(0,Z.jsx)(To,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Z.jsx)(qr,{className:`h-3.5 w-3.5`})}),ut&&!n&&de&&!vt&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:St,disabled:w,className:`h-7 w-7 p-0`,title:J(`engine.cancel`,f),children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})}),ut&&(de||n)&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>Ye(!1),disabled:w||!n&&!et,className:`h-7 w-7 p-0 relative`,title:w?J(`engine.edit.saving`,f):!n&&!et?J(`engine.edit.noChanges`,f):`${J(`engine.edit.save`,f)} (⌘S)`,children:[w?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-3.5 w-3.5`}),et&&!w&&(0,Z.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`})]}),ut&&!n&&ae&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:$e,disabled:w||se,className:`h-7 w-7 p-0 text-muted-foreground`,title:J(`engine.edit.discardDraft`,f),children:(0,Z.jsx)(fn,{className:`h-3.5 w-3.5`})}),ut&&!n&&ae&&(0,Z.jsx)(K,{size:`sm`,onClick:Qe,disabled:w||se||et,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:J(et?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,f),children:se?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(io,{className:`h-3.5 w-3.5 mr-1`}),(0,Z.jsx)(`span`,{className:`text-xs`,children:J(`engine.edit.publish`,f)})]})})]});return(0,Z.jsxs)(Sv,{entry:l??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?J(`engine.edit.createNew`,f):void 0,actions:vt?null:wt,children:[(0,Z.jsxs)(`div`,{className:vt?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(E||dt||ae||lt)&&(0,Z.jsxs)(`div`,{className:vt?`px-6 pt-4 space-y-3`:`space-y-3`,children:[E&&(0,Z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:E}),lt&&(0,Z.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,Z.jsx)(ot,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`font-medium`,children:[p?.lock===`full`&&J(`engine.edit.lockFull`,f),p?.lock===`no-overlay`&&J(`engine.edit.lockNoOverlay`,f),p?.lock===`no-delete`&&J(`engine.edit.lockNoDelete`,f)]}),at&&(0,Z.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:at}),p?.lockDocsUrl&&(0,Z.jsxs)(`a`,{href:p.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:[f===`zh-CN`?`查看文档`:`View docs`,` →`]}),p?.packageId&&(0,Z.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Z.jsxs)(`code`,{className:`font-mono`,children:[p.packageId,p.packageVersion?`@${p.packageVersion}`:``]})})]}),pt&&(0,Z.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:J(`engine.list.create`,f)})]}),ae&&!n&&(0,Z.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,Z.jsx)(io,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:J(`engine.edit.draftPending`,f)}),ut&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,onClick:$e,disabled:w||se,className:`h-7`,children:J(`engine.edit.discardDraft`,f)}),(0,Z.jsx)(K,{size:`sm`,onClick:Qe,disabled:w||se||et,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:se?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):J(`engine.edit.publish`,f)})]})]}),dt&&!lt&&(0,Z.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,Z.jsx)(`div`,{className:`flex-1`,children:pt?J(`engine.edit.artifactLockedBanner`,f).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Z.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Z.jsx)(X.Fragment,{children:t},n)):J(`engine.edit.readOnlyTypeBanner`,f).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Z.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Z.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Z.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Z.jsx)(X.Fragment,{children:t},n))}),pt&&(0,Z.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:J(`engine.list.create`,f)})]})]}),(0,Z.jsx)(`div`,{className:vt?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Z.jsxs)(`div`,{className:vt?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!vt&&Ct&&!dt&&ut&&!n&&(0,Z.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,Z.jsx)(`span`,{children:J(`engine.edit.readOnlyBanner`,f).split(/\{edit\}/).map((e,t,n)=>(0,Z.jsxs)(X.Fragment,{children:[e,t<n.length-1&&(0,Z.jsx)(`strong`,{children:J(`engine.edit.edit`,f)})]},t))}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>fe(!0),children:[(0,Z.jsx)(Bt,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.edit.edit`,f)]})]}),(()=>{let t=p?._diagnostics,n=tb(e)?O.map(e=>({path:e.path,message:Es(e.message,f)})):(t?.errors??[]).map(e=>({...e,message:Es(e.message,f)})),r=tb(e)?n.length===0:t?.valid!==!1;if(!t&&!tb(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,Z.jsxs)(`div`,{className:`flex items-start gap-2 text-xs border rounded p-2.5 ${i}`,children:[(0,Z.jsx)(gt,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:Y(a,f,{count:t.length})}),(0,Z.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Z.jsxs)(`li`,{className:`truncate`,children:[(0,Z.jsx)(`span`,{className:`opacity-70`,children:e.path?Je(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,Z.jsx)(`li`,{className:`opacity-70`,children:Y(`engine.edit.diagnostics.more`,f,{count:r})})]})]})]},e)};return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[o&&c(`error`,i),s&&c(`warning`,a)]})})(),vt?(0,Z.jsx)(`div`,{className:We?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Z.jsxs)(rb,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Z.jsx)(Gt,{defaultSize:62,minSize:30,children:(0,Z.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,Z.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,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:ut&&(0,Z.jsxs)(`div`,{role:`tablist`,"aria-label":J(`engine.edit.designer`,f),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!He,onClick:()=>Ue(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(He?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:J(`engine.edit.designMode`,f),children:[(0,Z.jsx)(Ya,{className:`h-3.5 w-3.5`}),J(`engine.edit.designMode`,f)]}),(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":He,onClick:()=>Ue(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(He?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.previewMode`,f),children:[(0,Z.jsx)(ct,{className:`h-3.5 w-3.5`}),J(`engine.edit.previewMode`,f)]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[wt,(0,Z.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),vt&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Be,className:`h-7 w-7 p-0`,title:J(Ie?`engine.edit.showInspector`:`engine.edit.hideInspector`,f)+` (⌘\\)`,children:Ie?(0,Z.jsx)(On,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(ci,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Ke(e=>!e),className:`h-7 w-7 p-0`,title:J(We?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,f),children:We?(0,Z.jsx)(Ai,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Wr,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.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,Z.jsx)(vt,{type:e,name:t,draft:_,baseline:n?void 0:p?.effective??void 0,editing:de&&!He,selection:He?null:pe,onSelectionChange:me,locale:f,onPatch:e=>A(t=>({...t,...e}))})})]})}),(0,Z.jsx)(xt,{withHandle:!0,className:Ie?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Z.jsx)(Gt,{panelRef:ze,defaultSize:Re.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Re.current=t,typeof window<`u`&&window.localStorage.setItem(Fe,String(Math.round(t)))),Le(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Pe,n?`1`:`0`),n))},children:(0,Z.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Z.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,Z.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Me===`properties`,onClick:()=>Ne(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Me===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.inspector.properties`,f),children:[(0,Z.jsx)(Zr,{className:`h-3.5 w-3.5`}),J(`engine.edit.inspector.properties`,f)]}),(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Me===`source`,onClick:()=>Ne(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Me===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.inspector.source`,f),children:[(0,Z.jsx)(Ze,{className:`h-3.5 w-3.5`}),J(`engine.edit.inspector.source`,f)]})]}),et&&(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,Z.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),J(`engine.edit.unsaved`,f)]})]}),(0,Z.jsx)(`div`,{className:`p-4`,children:Me===`source`?(0,Z.jsx)(Jy,{value:_,onChange:A,readOnly:Ct,issues:O.map(e=>({path:e.path??``,message:e.message}))}):pe&&yt?(0,Z.jsx)(yt,{type:e,name:t,draft:_,selection:pe,onPatch:e=>A(t=>({...t,...e})),onClearSelection:()=>me(null),onSelectionChange:me,readOnly:Ct,locale:f}):!pe&&bt?(0,Z.jsx)(bt,{type:e,name:t,draft:_,onPatch:e=>A(t=>({...t,...e})),onSelectionChange:me,readOnly:Ct,locale:f,serverSchema:l?.schema}):(0,Z.jsx)(Ms,{schema:d,form:n&&u.createSchema?void 0:l?.form,value:_,onChange:F,issues:O,hiddenFields:ie,fieldOrder:P,readOnly:Ct,createMode:n,widgetContext:be})})]})})]})}):(0,Z.jsx)(Ms,{schema:d,form:n&&u.createSchema?void 0:l?.form,value:_,onChange:F,issues:O,hiddenFields:ie,fieldOrder:P,readOnly:Ct,createMode:n,widgetContext:be})]})})]}),(0,Z.jsx)(on,{open:Oe===`layers`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Mt,{className:`text-base`,children:J(`engine.edit.layers`,f)}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(Uv,{layered:p,locale:f})})]})}),(0,Z.jsx)(on,{open:Oe===`review`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Mt,{className:`text-base`,children:J(`designer.draftReview.title`,f)}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t,` · `,J(`designer.canvas.reviewVsPublished`,f)]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(Qv,{published:p?.effective??null,draft:_,locale:f})})]})}),(0,Z.jsx)(on,{open:Oe===`references`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsxs)(Mt,{className:`text-base`,children:[J(`engine.edit.references`,f),b&&(0,Z.jsx)(H,{variant:`outline`,className:`ml-2 text-[10px]`,children:b.length})]}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(lb,{refs:b,loading:xe})})]})}),Ee&&(0,Z.jsx)(on,{open:Oe===`related`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Mt,{className:`text-base`,children:J(`engine.edit.related`,f)}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(oy,{type:e,name:t,parentItem:_,onOpen:e=>Te(e)})})]})}),!n&&(0,Z.jsx)(on,{open:Oe===`history`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Mt,{className:`text-base`,children:J(`engine.edit.history`,f)}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(my,{type:e,name:t,client:s,onRollback:()=>ue(e=>e+1),rollbackLabel:J(`engine.edit.rollback`,f),rollbackConfirm:e=>J(`engine.edit.rollbackConfirm`,f).replace(`{version}`,String(e))})})]})}),!n&&(0,Z.jsx)(on,{open:Oe===`audit`,onOpenChange:e=>!e&&ke(null),children:(0,Z.jsxs)(pn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(_t,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Mt,{className:`text-base`,children:J(`engine.edit.auditTab`,f)}),(0,Z.jsxs)(En,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Z.jsx)(yy,{type:e,name:t,client:s,locale:f})})]})}),(0,Z.jsx)(fy,{target:we,onClose:()=>Te(null),parentContext:{type:e,name:t}}),(0,Z.jsx)(mt,{open:j!=null,onOpenChange:e=>{e||(ee(null),M(null))},children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(gt,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Z.jsx)(Yt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Z.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:j?.map((e,t)=>(0,Z.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Z.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Z.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`ghost`,onClick:()=>ee(null),children:`Cancel`}),(0,Z.jsx)(K,{variant:`destructive`,onClick:()=>Ye(!0),disabled:w,children:w?`Forcing…`:`Force save`})]})]})})]})}function lb({refs:e,loading:t}){return t||e==null?(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`No references found`}),(0,Z.jsx)(Kt,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,Z.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,Z.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,Z.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function ub({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=X.useReducer(e=>e+1,0);return X.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,Z.jsx)(V,{className:`h-3 w-3 animate-spin`}),J(`engine.edit.saving`,a)]}):t?i?null:(0,Z.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),J(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:Y(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function db({type:e}){let t=u(),[n]=m(),r=e??n.get(`type`)??``;if(!r)return(0,Z.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`Missing metadata type`}),(0,Z.jsxs)(Kt,{children:[`This page expects a `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,Z.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let i=fb(t.pathname),a=i.split(`/`).filter(Boolean);return a.length===0?(0,Z.jsx)(Nv,{type:r}):a[0]===`new`&&a.length===1?(0,Z.jsx)(sb,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Z.jsx)(py,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Z.jsx)(sb,{type:r,name:decodeURIComponent(a[0])},`${r}:${a[0]}`):(0,Z.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:`Unknown sub-path`}),(0,Z.jsxs)(Kt,{children:[`The path `,(0,Z.jsx)(`code`,{className:`font-mono`,children:i}),` isn't recognized. Valid forms are `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function fb(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function pb(){let e=ks(),t=X.useMemo(()=>Fs(),[]),[n,r]=X.useState(`error`),{loading:i,error:a,summary:o,reload:s}=Ps(e,n),{entries:c}=Cs(e),l=X.useMemo(()=>{let e={};for(let n of c)e[n.type]=Ts(n.type,t,n.label);return e},[c,t]),u=X.useMemo(()=>{let e={};for(let t of o.entries)(e[t.type]??=[]).push(t);return Object.entries(e).sort(([,e],[,t])=>t.length-e.length)},[o]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Z.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,Z.jsxs)(h,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,Z.jsx)(Wt,{className:`h-3 w-3`}),J(`engine.diagnostics.back`,t)]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Z.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,Z.jsx)(gt,{className:`h-5 w-5 text-destructive`}),J(`engine.diagnostics.title`,t)]}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:Y(`engine.diagnostics.summary`,t,{count:o.total,items:o.scannedItems,types:o.scannedTypes})}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.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,Z.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:J(`engine.diagnostics.severity.${e}`,t)},e))}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:s,children:[(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.diagnostics.refresh`,t)]})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:J(`engine.diagnostics.description`,t)})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[i&&(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:J(`engine.diagnostics.loading`,t)}),!i&&a&&(0,Z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:Y(`engine.diagnostics.loadFailed`,t,{error:a})}),!i&&!a&&u.length===0&&(0,Z.jsxs)(Et,{children:[(0,Z.jsx)(Ue,{children:J(`engine.diagnostics.cleanTitle`,t)}),(0,Z.jsx)(Kt,{children:Y(`engine.diagnostics.cleanHint`,t,{items:o.scannedItems,types:o.scannedTypes})})]}),u.map(([e,r])=>(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(h,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:l[e]??e}),(0,Z.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:r.length})]}),(0,Z.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:J(`engine.diagnostics.col.name`,t)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:J(`engine.diagnostics.col.issues`,t)})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:r.map(r=>{let i=r.diagnostics.errors??[],a=r.diagnostics.warnings??[],o=(n===`warning`&&i.length===0?a:i).slice(0,3),s=Math.max(0,(i.length||a.length)-o.length);return(0,Z.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,Z.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,Z.jsx)(h,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(r.name)}`,className:`text-primary hover:underline font-mono`,children:r.name}),i.length>0&&(0,Z.jsx)(H,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:Y(`engine.diagnostics.errorN`,t,{count:i.length})}),a.length>0&&(0,Z.jsx)(H,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:Y(`engine.diagnostics.warnN`,t,{count:a.length})})]}),(0,Z.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,Z.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[o.map((e,t)=>(0,Z.jsxs)(`li`,{className:`truncate`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),s>0&&(0,Z.jsx)(`li`,{className:`text-muted-foreground`,children:Y(`engine.diagnostics.more`,t,{count:s})})]})})]},r.name)})})]})})]},e))]})]})}function mb(e){return[{key:`allowCreate`,short:`C`,tip:J(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:J(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:J(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:J(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:J(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:J(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:J(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:J(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:J(`perm.action.modifyAll`,e)}]}function hb({type:e,name:t}){let n=v(),r=ks(),{entries:i}=Cs(r),a=i.find(t=>t.type===e),o=!!jv(e,a).allowOrgOverride,s=X.useMemo(()=>Fs(),[]),c=X.useCallback(e=>J(e,s),[s]),l=X.useMemo(()=>mb(s),[s]),[u,d]=X.useState({name:t,objects:{},fields:{}}),[f,p]=X.useState([]),[m,h]=X.useState({}),[g,_]=X.useState(new Set),[y,b]=X.useState(!0),[x,S]=X.useState(!1),[C,w]=X.useState(null),[T,E]=X.useState(null),[D,O]=X.useState(``),[k,A]=X.useState(!1);X.useEffect(()=>{let n=!1;return b(!0),(async()=>{try{let[i,a]=await Promise.all([r.layered(e,t).catch(()=>null),r.list(`object`).catch(()=>[])]);if(n)return;let o=i?.effective??i?.code??{name:t,objects:{}};d({...o,name:String(o?.name??t),objects:o?.objects??{},fields:o?.fields??{}}),p((a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name)))}catch(e){w(e?.message??String(e))}finally{n||b(!1)}})(),()=>{n=!0}},[r,e,t]);async function j(e){if(!m[e])try{let t=(await r.list(`field`)??[]).map(e=>e?.item??e).filter(t=>String(t?.object??``)===e).map(e=>({name:String(e?.name??``),label:e?.label})).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));h(n=>({...n,[e]:t}))}catch{h(t=>({...t,[e]:[]}))}}function ee(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),j(e)),n})}function te(e,t,n){d(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function M(e,t){d(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(l.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function ne(e,t,n,r){let i=`${e}.${t}`;d(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function re(t,n){let i=n??u;S(!0),w(null);try{await r.save(e,i.name,i,{force:t}),d((await r.layered(e,i.name)).effective??i),E(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];E({issues:Array.isArray(t)?t:[],pending:i})}else w(e?.message??String(e))}finally{S(!1)}}let N=X.useMemo(()=>{let e=D.trim().toLowerCase();return f.filter(t=>{if(k){let e=u.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[f,D,k,u.objects]),ie=[{label:c(`perm.stat.objectsGranted`),value:Object.values(u.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:c(`perm.stat.fieldOverrides`),value:Object.keys(u.fields??{}).length}];return y?(0,Z.jsx)(Sv,{entry:a,itemName:t,children:(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,Z.jsxs)(Sv,{entry:a??{type:e,label:e},itemName:t,subtitle:u.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:ie,actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,Z.jsx)(gr,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>re(!1),disabled:x,children:[x?(0,Z.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-4 w-4 mr-1`}),c(`engine.edit.save`)]})]}),children:[(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[C&&(0,Z.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,Z.jsx)(gt,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{children:C})]}),(0,Z.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{htmlFor:`perm-name`,className:`text-xs`,children:c(`perm.field.name`)}),(0,Z.jsx)(W,{id:`perm-name`,value:u.name,disabled:!o,onChange:e=>d(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{htmlFor:`perm-label`,className:`text-xs`,children:c(`perm.field.label`)}),(0,Z.jsx)(W,{id:`perm-label`,value:u.label??``,disabled:!o,onChange:e=>d(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,Z.jsx)(to,{id:`perm-is-profile`,checked:!!u.isProfile,disabled:!o,onCheckedChange:e=>d(t=>({...t,isProfile:!!e}))}),(0,Z.jsx)(G,{htmlFor:`perm-is-profile`,className:`text-xs`,children:c(`perm.field.isProfile`)})]}),!o&&(0,Z.jsx)(H,{variant:`secondary`,className:`ml-auto`,children:c(`perm.readOnly`)})]}),(0,Z.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,Z.jsx)(W,{placeholder:c(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(to,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,Z.jsx)(G,{htmlFor:`only-enabled`,className:`text-xs`,children:c(`perm.filter.onlyGranted`)})]}),(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[N.length,` / `,f.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Z.jsx)(gb,{objects:N,draft:u,expanded:g,fieldsByObject:m,writable:o,objectActions:l,t:c,onToggleExpand:ee,onObjectPerm:te,onFieldPerm:ne,onBulkSet:M})})]}),(0,Z.jsx)(mt,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(gt,{className:`h-4 w-4 text-amber-500`}),` `,c(`engine.edit.destructive`)]}),(0,Z.jsx)(Yt,{children:c(`engine.edit.destructiveHint`)})]}),(0,Z.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:T?.issues.map((e,t)=>(0,Z.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,Z.jsx)(H,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(K,{variant:`ghost`,onClick:()=>E(null),children:c(`engine.cancel`)}),(0,Z.jsxs)(K,{variant:`destructive`,onClick:()=>T&&re(!0,T.pending),disabled:x,children:[x&&(0,Z.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function gb({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,Z.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,Z.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,Z.jsxs)(`tbody`,{children:[e.length===0&&(0,Z.jsx)(`tr`,{children:(0,Z.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,Z.jsxs)(X.Fragment,{children:[(0,Z.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,Z.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,Z.jsx)(Ta,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(si,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,Z.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,Z.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,Z.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,Z.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,Z.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,Z.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,Z.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,Z.jsx)(`tr`,{className:`bg-muted/10`,children:(0,Z.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,Z.jsx)(_b,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function _b({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,Z.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,Z.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,Z.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,Z.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,Z.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,Z.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,Z.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Z.jsx)(yt,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,Z.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Z.jsx)(yt,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function vb(){Ov({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>yb(e.fields),groupLabel:`Fields`,order:5}]}),Ov({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}]}),Ov({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>yb(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Ov({type:`hook`,anchors:[{anchorType:`object`,match:Ev(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Ov({type:`page`,anchors:[{anchorType:`object`,match:Ev(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`object`,`type`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`type`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable page title.`},name:{type:`string`,title:`Name`,description:`Page key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},type:{type:`string`,title:`Page type`,enum:[`record`,`app`,`home`,`dashboard`,`utility`],default:`record`,description:"A `record` page renders for an object’s records; pick the object below."},object:{type:`string`,title:`Object`,description:`For a record page — the object whose records this page renders.`},kind:{type:`string`,title:`Kind`,enum:[`full`,`slotted`],default:`full`,description:`full = the whole page; slotted = override only named slots of the default.`}}},createDefaults:{type:`record`,kind:`full`,regions:[]},createSeed:async(e,{client:t})=>{if(e?.type!==`record`||!e?.object)return{};try{let n=await t.get(`object`,String(e.object));if(!n||typeof n!=`object`)return{};let{buildDefaultPageSchema:r}=await d(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-BtLnemvB.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),i=r(n),a={};return Array.isArray(i?.regions)&&i.regions.length&&(a.regions=i.regions),i?.template&&(a.template=i.template),a}catch{return{}}}}),Ov({type:`view`,anchors:[{anchorType:`object`,match:Ev([`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}}}}}),Ov({type:`flow`,anchors:[{anchorType:`object`,match:Ev([`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:[]}}),Ov({type:`trigger`,anchors:[{anchorType:`object`,match:Ev([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ov({type:`validation`,anchors:[{anchorType:`object`,match:Ev(`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`}}),Ov({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:{}}}),Ov({type:`action`,anchors:[{anchorType:`object`,match:Ev([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Ov({type:`dashboard`,anchors:[{anchorType:`object`,match:Ev([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Ov({type:`report`,anchors:[{anchorType:`object`,match:Ev([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Ov({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 yb(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var bb={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`}},xb={role:{type:`object`,title:`Role`,required:[`name`],properties:{...bb,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:{...bb,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:{...bb.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:bb.label,description:bb.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:{...bb,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:{...bb,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...bb,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...bb,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...bb,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:{...bb,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...bb,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:{...bb,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 Sb(){for(let[e,t]of Object.entries(xb))Ov({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Cb({toolbar:e,children:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,Z.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,Z.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function wb({tone:e=`info`,children:t}){return(0,Z.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,Z.jsx)(Ha,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:t})]})}function Tb({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,Z.jsx)(or,{className:`h-8 w-8 opacity-50`});return(0,Z.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,Z.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,Z.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,Z.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,Z.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Eb=class extends X.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,Z.jsxs)(wb,{tone:`error`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,Z.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,Z.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function Db({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,Z.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,Z.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,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:a??`Add`})]})]})]})}var Ob={"page:header":{label:`Header`,category:`layout`,Icon:dr},"page:footer":{label:`Footer`,category:`layout`,Icon:fa},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Me},"page:tabs":{label:`Tabs`,category:`layout`,Icon:$r},"page:accordion":{label:`Accordion`,category:`layout`,Icon:ti},"page:card":{label:`Card`,category:`layout`,Icon:Ga},"page:section":{label:`Section`,category:`layout`,Icon:qt},"record:details":{label:`Record details`,category:`record`,Icon:oo},"record:highlights":{label:`Highlights`,category:`record`,Icon:Aa},"record:related_list":{label:`Related list`,category:`record`,Icon:Bi},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Dr},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Ar},"record:path":{label:`Stage path`,category:`record`,Icon:nr},"record:alert":{label:`Alert banner`,category:`record`,Icon:gt},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:To},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Tn},"record:history":{label:`History`,category:`record`,Icon:gr},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:So},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:nr},"global:search":{label:`Global search`,category:`navigation`,Icon:Co},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:an},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:_a},"element:text":{label:`Text`,category:`element`,Icon:wn},"element:number":{label:`Number`,category:`element`,Icon:ur},"element:image":{label:`Image`,category:`element`,Icon:zt},"element:divider":{label:`Divider`,category:`element`,Icon:oa},"element:button":{label:`Button`,category:`element`,Icon:$i},"element:definition-list":{label:`Definition list`,category:`element`,Icon:mn},"element:repeater":{label:`Repeater`,category:`element`,Icon:fo}},kb={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Ab=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Ob))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)})(),jb=Gi,Mb={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 Nb(e){return Mb[Ob[e]?.category??`misc`]}var Pb={"element:text":[{name:`content`,label:`Content`,kind:`text`,placeholder:`Text…`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`heading`,label:`Heading`},{value:`subheading`,label:`Subheading`},{value:`body`,label:`Body`},{value:`caption`,label:`Caption`}]},{name:`align`,label:`Align`,kind:`select`,options:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}],"element:image":[{name:`src`,label:`Source URL`,kind:`text`,placeholder:`https://…`},{name:`alt`,label:`Alt text`,kind:`text`},{name:`fit`,label:`Fit`,kind:`select`,options:[{value:`cover`,label:`Cover`},{value:`contain`,label:`Contain`},{value:`fill`,label:`Fill`}]}],"element:definition-list":[{name:`items`,label:`Items`,kind:`array`,addLabel:`Add item`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`value`,label:`Value`,kind:`text`}]},{name:`columns`,label:`Columns (1 or 2)`,kind:`number`,placeholder:`1`},{name:`inline`,label:`Inline (label · value)`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`},{name:`emptyText`,label:`Empty text`,kind:`text`},{name:`divided`,label:`Dividers between rows`,kind:`boolean`}],"element:number":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`field`,label:`Field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`Aggregate`,kind:`select`,options:[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"element:button":[{name:`label`,label:`Label`,kind:`text`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}]},{name:`size`,label:`Size`,kind:`select`,options:[{value:`small`,label:`Small`},{value:`medium`,label:`Medium`},{value:`large`,label:`Large`}]},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`}],"page:header":[{name:`title`,label:`Title`,kind:`text`},{name:`subtitle`,label:`Subtitle`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`breadcrumb`,label:`Show breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`Title`,kind:`text`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`Tabs`,kind:`array`,addLabel:`Add tab`,itemFields:[{name:`key`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"page:accordion":[{name:`title`,label:`Title`,kind:`text`},{name:`items`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`value`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`relationshipField`,label:`Relationship field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`}],"record:highlights":[{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`columns`,label:`Columns`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`Severity`,kind:`select`,options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`error`,label:`Error`},{value:`success`,label:`Success`}]},{name:`title`,label:`Title`,kind:`text`},{name:`body`,label:`Body`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`dismissible`,label:`Dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`Status field`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`Stages`,kind:`array`,addLabel:`Add stage`,itemFields:[{name:`value`,label:`Value`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`Action names`,kind:`string-list`,placeholder:`action name`},{name:`location`,label:`Location`,kind:`select`,options:[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record more menu`},{value:`record_section`,label:`Record section`},{value:`record_related`,label:`Record related`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List item`},{value:`global_nav`,label:`Global nav`}]}],"ai:chat_window":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}],"ai:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function Fb(e){return!!e&&Array.isArray(Pb[e])&&Pb[e].length>0}function Ib(){let e=ks(),[t,n]=X.useState([]),[r,i]=X.useState(!0);return X.useEffect(()=>{let t=!1;return i(!0),e.list(`object`).then(e=>{t||(n((e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item: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))),i(!1))}).catch(()=>{t||(n([]),i(!1))}),()=>{t=!0}},[e]),{options:t,loading:r}}function Lb(e){let{fields:t}=sd(e);return X.useMemo(()=>t.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[t])}function Rb({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=Ib();return i.length===0?(0,Z.jsx)(ws,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Z.jsx)(Rs,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function zb({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=Lb(t);return!t||a.length===0?(0,Z.jsx)(ws,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Z.jsx)(Rs,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function Bb({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=Lb(t),o=Array.isArray(n)?n:[];return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,Z.jsx)(`div`,{className:`flex-1`,children:(0,Z.jsxs)(Rn,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,Z.jsx)(ar,{className:`h-8`,children:(0,Z.jsx)(Tt,{placeholder:`—`})}),(0,Z.jsx)(jo,{children:a.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}):(0,Z.jsx)(W,{className:`h-8 text-sm`,value:String(e??``),placeholder:`field name`,disabled:i,onChange:e=>{let n=[...o];n[t]=e.target.value,r(n)}}),(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":`Remove`,onClick:()=>r(o.filter((e,n)=>n!==t)),children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]},t)),!i&&(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}var Vb=Symbol(`remove`);function Hb(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:t[2]==null?-1:Number(t[2])})}return n.length>0?n:null}function Ub(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function Wb(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function Gb(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return i.length===0?n===Vb?t.splice(r,1):t[r]=n:t[r]=Gb(t[r],i,n),t}let a={...e||{}};return i.length===0?n===Vb?delete a[r]:a[r]=n:a[r]=Gb(a[r],i,n),a}function Kb(e,t){return Wb(e,Ub(t))}function qb(e,t,n){let r=Ub(t),i=Gb(e,r,n===null?Vb:n),a=r[0];return{[a]:i[a]}}function Jb(e,t){let n=Ub(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=Wb(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function Yb(e,t,n){let r=Ub(t),i=Gb(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function Xb({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),c=s?null:Hb(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?Hb(d):null,p=t.slots&&typeof t.slots==`object`?t.slots:{},m=s?Array.isArray(p[l])?p[l]:p[l]==null?[]:[p[l]]:[],h=s?m[u]??null:null,g=e=>n({slots:{...p,[l]:e}}),_=e=>g(e===null?m.filter((e,t)=>t!==u):m.map((t,n)=>n===u?e:t)),v=s?f?Kb(h||{},f):h:c?Kb(t,c):null,y=s?f?Jb(h||{},f):{siblings:m,index:u}:c?Jb(t,c):null;if(!s&&!c||!v)return(0,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,a),children:(0,Z.jsx)(As,{message:e.id})});let b=e=>s?_(f?{...h,...qb(h||{},f,{...v,...e})}:{...v,...e}):n(qb(t,c,{...v,...e})),x=v.properties||{},S=typeof t?.object==`string`?t.object:void 0,C=e=>e.objectFrom===`page`?S:e.objectProp!=null&&x[e.objectProp]!=null?String(x[e.objectProp]):void 0,w=e=>x[e]??v[e],T=(e,t)=>b({properties:{...x,[e]:t}}),E=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,Z.jsx)(Os,{label:e.label,value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`boolean`:return(0,Z.jsx)(Ns,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`select`:return(0,Z.jsx)(Rs,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),options:e.options,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(W,{className:`h-8 text-sm`,value:String(t??``),placeholder:e.placeholder,disabled:o,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:o,"aria-label":`Remove`,onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]},i)),!o&&(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]},i)}case`array`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:o,"aria-label":`Remove item`,onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>E(t,e=>s[e],(t,i)=>{let o=[...r];o[a]={...s,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!o&&(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,Z.jsx)(Rb,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-picker`:return(0,Z.jsx)(zb,{label:e.label,objectName:C(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-list`:return(0,Z.jsx)(Bb,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,Z.jsx)(ws,{label:e.label,value:t(e.name)==null?``:String(t(e.name)),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i)}},D=()=>{s?_(f?{...h,...qb(h||{},f,null)}:null):n(qb(t,c,null)),r()},O=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,Z.jsx)(Ss,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=xs(y.siblings,y.index,e);_({...h,...Yb(h||{},f,t)});let n=O([...f.slice(0,-1),{key:f[f.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${l}:${u}.${n}`,label:String(v.id||v.type||e)})}else g(xs(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}n(Yb(t,c,xs(y.siblings,y.index,e)));let r=O([...c.slice(0,-1),{key:c[c.length-1].key,index:e}]);i?.({kind:`block`,id:r,label:String(v.id||v.type||r)})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.pageBlock.remove`,a),onClick:D,disabled:o}),children:[(0,Z.jsx)(ws,{label:J(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e}),disabled:o,mono:!0}),Fb(v.type)&&(0,Z.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.pageBlock.properties`,a)}),Pb[v.type].map(e=>E(e,w,T))]})]})}function Zb(e){let t=e?.properties||{};switch(e?.type){case`page:tabs`:case`page:accordion`:return(Array.isArray(t.items)?t.items:[]).map((e,t)=>({label:e?.label||e?.key||`Item ${t+1}`,pathSuffix:`properties.items[${t}].children`,children:Array.isArray(e?.children)?e.children:[]}));case`page:card`:return[{label:`Body`,pathSuffix:`properties.body`,children:Array.isArray(t.body)?t.body:[]}];case`page:section`:return[{label:`Content`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];default:return[]}}var Qb=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function $b(e){let t=e||{};return Qb.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function ex(e){let t={};for(let n of e){let e=Array.isArray(n.components)?n.components:[];e.length===0||!n.name||(t[n.name]=e)}return t}function tx(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:$b(t),shape:`slots`};let n=e.regions;if(Array.isArray(n))return{regions:n,shape:`regions`};let r=e.children;return Array.isArray(r)?{regions:[{name:`children`,components:r}],shape:`children`}:{regions:[],shape:`regions`}}function nx(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function rx(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 ix=`text/x-objectui-pageblock`;function ax({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=X.useMemo(()=>tx(e),[e]),s=n?.kind===`block`?String(n.id):null,c=X.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:ex(e)}):t?.({regions:e})},[t,o]),l=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),s=i[e.region]?.components;if(!s)return;let[l]=s.splice(e.comp,1);if(!l)return;let u=i[n.region]?.components;if(!u)return;let d=u.length;if(`appendEnd`in n)d=u.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,d=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,d=t}u.splice(d,0,l),c(i);let f=nx(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:rx(l)})},[t,r,a,c,o]),u=X.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 s={type:n};i[e].components.push(s),c(i);let l=i[e].components.length-1;r?.({kind:`block`,id:nx(o,e,l,i[e]?.name),label:rx(s)})},[t,r,a,c,o]),d=X.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=X.useCallback(()=>{t&&c([...a,{name:`region_${a.length+1}`,components:[]}])},[t,a,c]),p=X.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=Hb(i);if(!s)return;let c=Ub(s);if(o){let s=o[1],l=Number(o[2]),u=e.slots||{},d=u[s],f=Array.isArray(d)?[...d]:d==null?[]:[d],p=f[l];if(!p)return;let m=Wb(p,c)||[];f[l]=Gb(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=Hb(`${n}.${i}`);if(!o)return;let s=Ub(o),c=Wb(e,s)||[],l=Gb(e,s,[...c,{type:a}]);t({[s[0]]:l[s[0]]}),r?.({kind:`block`,id:`${n}.${i}[${c.length}]`,label:a})}},[t,e,r]),m=X.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,Z.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,Z.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,Z.jsx)(`div`,{className:`pt-2`,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Z.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,Z.jsx)(ox,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:nx(o,t,n,e.name),label:rx(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>nx(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,Z.jsx)(`div`,{className:`pt-1`,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function ox({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c,onSelectId:l,onAddNested:u}){let d=Array.isArray(e.components)?e.components:[],[f,p]=X.useState(!1);return(0,Z.jsxs)(`section`,{className:U(`rounded-md transition-colors`,f&&`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(ix)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(!0))},onDragLeave:e=>{e.currentTarget===e.target&&p(!1)},onDrop:e=>{if(i||(p(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(ix);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,Z.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,Z.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,Z.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,Z.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:n===`slots`?`Inherited from the default page — add a block to override this slot.`:`Empty region — drop a block here or use the add button below.`}):d.map((s,d)=>{let f=nx(n,t,d,e.name);return(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(sx,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,Z.jsx)(cx,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,Z.jsx)(`div`,{className:`pt-1`,children:(0,Z.jsx)(lx,{onPick:e=>s(t,e)})})]})]})}function sx({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Ob[c]?.Icon??jb,u=Nb(c),d=rx(e),f=!i,[p,m]=X.useState(null),h=e=>{e.dataTransfer.setData(ix,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(ix))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(ix);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]=X.useState(!1),[x,S]=X.useState(d);X.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,Z.jsxs)(`div`,{className:U(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,Z.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,Z.jsx)(je,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,Z.jsx)(l,{className:U(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,Z.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,Z.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,Z.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,Z.jsx)(H,{variant:`outline`,className:U(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]})}),p===`after`&&(0,Z.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function cx({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=Zb(e);return o.length===0?null:(0,Z.jsx)(`div`,{className:`ml-5 mt-1.5 space-y-2.5 border-l border-dashed border-border pl-3`,children:o.map((e,o)=>(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,Z.jsx)(`div`,{className:`rounded border border-dashed bg-background/40 py-2 px-3 text-[11px] text-muted-foreground`,children:`Empty — add a block.`}):e.children.map((r,a)=>{let o=`${t}.${e.pathSuffix}[${a}]`,s=String(r?.type??``),c=Ob[s]?.Icon??jb;return(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,rx(r))},className:U(`flex w-full items-center gap-2 rounded border px-2.5 py-1.5 text-left text-xs transition-colors`,o===n?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-border bg-background hover:bg-muted/40`),children:[(0,Z.jsx)(c,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:rx(r)}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:s})]},a)}),!r&&(0,Z.jsx)(lx,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function lx({onPick:e}){let[t,n]=X.useState(!1),[r,i]=X.useState(``),a=r.trim().toLowerCase(),o=X.useMemo(()=>a?Ab.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Ob[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Ab,[a]);return(0,Z.jsxs)(Or,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Z.jsx)(Ie,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Z.jsxs)(jn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Z.jsx)(`div`,{className:`p-2 border-b`,children:(0,Z.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,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Z.jsxs)(`div`,{className:`mb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:kb[t.category]}),t.types.map(t=>{let r=Ob[t],a=r.Icon;return(0,Z.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,Z.jsx)(a,{className:U(`h-3.5 w-3.5 shrink-0`,Nb(t).icon)}),(0,Z.jsx)(`span`,{className:`truncate`,children:r.label}),(0,Z.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function ux({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=X.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=X.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),d=X.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=X.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,Z.jsxs)(Cb,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Z.jsx)(ax,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Z.jsx)(Db,{title:J(`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:J(`engine.inspector.add.block`,a)}):null,!s&&(0,Z.jsx)(wb,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Z.jsx)(Cb,{hint:`page · design`,children:(0,Z.jsx)(ax,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Z.jsx)(Cb,{hint:`page${s?` · design`:``}`,children:(0,Z.jsxs)(Eb,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Z.jsx)(Db,{title:J(`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:J(`engine.inspector.add.block`,a)}),(0,Z.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Z.jsx)(ne,{schema:o})})]})})}function dx(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 fx=new Set([`simple`,`tabbed`,`wizard`,`split`]);function px(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 mx(e,t){let n=typeof t.type==`string`?t.type:`simple`;return{type:`object-form`,objectName:e,mode:`create`,formType:fx.has(n)?n:`simple`,sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(px):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function hx({name:e,draft:t,editing:n}){let r=X.useMemo(()=>Kd(t)?.schema,[t]),i=X.useMemo(()=>dx(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=X.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,Z.jsx)(Cb,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Z.jsx)(Eb,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,Z.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Z.jsx)(ne,{schema:e})})})})}if(!i)return(0,Z.jsx)(Cb,{hint:`view${a?` · design`:``}`,children:(0,Z.jsxs)(wb,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,Z.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=mx(i,r);return(0,Z.jsx)(Cb,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Z.jsx)(Eb,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,Z.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Z.jsx)(ne,{schema:t})})})})}let l=X.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,Z.jsx)(Cb,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Z.jsx)(Eb,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,Z.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Z.jsx)(ne,{schema:l})})})})}var gx=X.lazy(()=>d(()=>import(`./plugin-dashboard-DbPGiGy-.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function _x({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=be(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=X.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=X.useCallback(e=>{n&&n({widgets:e})},[n]),p=X.useCallback(e=>{if(!l)return;let t=zs(`widget`,s.map(e=>e?.id).filter(Boolean)),r=qp[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:Bs(s,{id:t,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),m=X.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,Z.jsx)(Zp,{onAdd:p,label:J(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Z.jsx)(Cb,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Z.jsx)(wb,{children:`Add at least one widget to see a preview.`})}):(0,Z.jsx)(Cb,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Z.jsxs)(Eb,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Z.jsx)(vx,{widget:h,onRename:e=>m(h.id,e),onClose:()=>i?.(null)}):null,(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,Z.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,Z.jsx)(gx,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})]})})}function vx({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=X.useState(!1),[o,s]=X.useState(r),c=X.useRef(null);X.useEffect(()=>{s(r),a(!1)},[e.id,r]),X.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=qp[e.type]?.icon??null;return(0,Z.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,Z.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,Z.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,Z.jsx)(ua,{className:`h-3.5 w-3.5`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,Z.jsx)(Bt,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]})}var yx=X.lazy(()=>d(()=>import(`./plugin-report-qca5M0OZ.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function bx({draft:e}){let t=be(),n=String(e.dataset),r=X.useMemo(()=>Array.isArray(e.rows)?e.rows.filter(Boolean):[],[e]),i=X.useMemo(()=>Array.isArray(e.values)?e.values.filter(Boolean):[],[e]),a=e.runtimeFilter,[o,s]=X.useState({status:`idle`,rows:[]}),c=`${n}|${r.join(`,`)}|${i.join(`,`)}`;if(X.useEffect(()=>{if(i.length===0){s({status:`idle`,rows:[]});return}let e=!1;return s({status:`loading`,rows:[]}),t.queryDataset(n,{dimensions:r,measures:i,runtimeFilter:a}).then(t=>{e||s({status:`ok`,rows:Array.isArray(t?.rows)?t.rows:[]})}).catch(t=>{e||s({status:`error`,rows:[],error:String(t?.message??t)})}),()=>{e=!0}},[c]),i.length===0)return(0,Z.jsx)(Cb,{children:(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(br,{className:`h-8 w-8`}),title:`Pick measures to show`,description:`This report binds the "${n}" dataset — choose at least one measure (values) to render.`})});let l=[...r,...i];return(0,Z.jsx)(Cb,{hint:`report · dataset "${n}"${r.length?` · by `+r.join(`, `):``}`,children:(0,Z.jsxs)(`div`,{className:`p-3`,children:[o.status===`loading`&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Running report…`]}),o.status===`error`&&(0,Z.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,Z.jsx)(gt,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`break-words`,children:o.error})]}),o.status===`ok`&&o.rows.length===0&&(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(br,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for this report's scope.`}),o.rows.length>0&&(0,Z.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Z.jsx)(`tr`,{children:l.map(e=>(0,Z.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:e},e))})}),(0,Z.jsx)(`tbody`,{children:o.rows.map((e,t)=>(0,Z.jsx)(`tr`,{className:`border-t`,children:l.map(t=>{let n=e[t];return(0,Z.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:n==null?`—`:typeof n==`number`?Number.isInteger(n)?String(n):n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n)},t)})},t))})]})})]})})}function xx({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=be();if(typeof e.dataset==`string`&&e.dataset)return(0,Z.jsx)(bx,{draft:e});let 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=X.useMemo(()=>(Array.isArray(e.columns)?e.columns:[]).map((e,t)=>({id:`columns[${t}]`,label:String(e.label??e.field??`col ${t+1}`)})),[e]),p=X.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=X.useMemo(()=>({columns:[],...e}),[e]);return s?Array.isArray(e.columns)&&e.columns.length>0?(0,Z.jsx)(Cb,{hint:`report · ${c??`table`}${l?` · design`:``}`,children:(0,Z.jsxs)(Eb,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:[l&&(0,Z.jsx)(Db,{title:J(`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:J(`engine.inspector.add.column`,a)}),(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Z.jsx)(`div`,{className:`p-3 min-h-[300px] max-h-[70vh] overflow-auto`,children:(0,Z.jsx)(yx,{schema:m,dataSource:o})})})]})}):(0,Z.jsxs)(Cb,{children:[l&&(0,Z.jsx)(Db,{title:J(`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:J(`engine.inspector.add.column`,a)}),(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(St,{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,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),` Add first column`]}):void 0})]}):(0,Z.jsx)(Cb,{children:(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(kt,{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 Sx=`text/x-objectui-nav`;function Cx(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 wx(e){switch(e){case`object`:return kt;case`page`:return oo;case`dashboard`:return Dt;case`report`:return yo;case`link`:return Le;case`group`:return na;default:return nr}}var Tx={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 Ex(e){return Tx[e]??Tx.item}function Dx(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Ox(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function kx({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=X.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),o=r&&r.kind===`nav`?r.id:null,[s,c]=X.useState(null),l=X.useCallback(e=>{n&&n({[t]:e})},[n,t]),u=X.useCallback(()=>{if(!n)return;let e=Bs(a,{label:`New item`,path:``});l(e),i?.({kind:`nav`,id:`${t}[${e.length-1}]`,label:`New item`})},[n,a,l,t,i]),d=X.useCallback(e=>{n&&(l(bs(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=X.useCallback((e,r)=>{n&&(l(bs(a,e,{...a[e]??{},label:r})),o===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r}))},[n,a,l,t,o,i]),p=X.useCallback((e,r)=>{if(!n)return;let o=r;if(e<r&&(o=r-1),o===e)return;let s=xs(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Dx(s[o]??{},o)})},[n,a,l,t,i]);return(0,Z.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-mono uppercase tracking-wide text-muted-foreground`,children:t}),(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px]`,children:[a.length,` `,a.length===1?`item`:`items`]})]}),n&&(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),` Add nav item`]})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Sx)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Sx)&&(e.preventDefault(),s!=null&&(p(s,a.length),c(null)))},children:a.length===0?(0,Z.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,Z.jsx)(Ax,{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 Ax({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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(jx,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Dx(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,Z.jsx)(Ax,{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 jx({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=Cx(e),p=wx(f),m=Ex(f),h=Ox(e),[g,_]=X.useState(!1),[v,y]=X.useState(Dx(e,t)),[b,x]=X.useState(!1),[S,C]=X.useState(null);return X.useEffect(()=>{g||y(Dx(e,t))},[e,t,g]),(0,Z.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[S===`before`&&(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Z.jsxs)(`button`,{type:`button`,draggable:a&&!g,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(Sx,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Sx)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Sx)&&(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,Z.jsx)(je,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,Z.jsx)(`span`,{className:`w-3.5`}),(0,Z.jsx)(p,{className:U(`h-3.5 w-3.5 shrink-0`,m.icon)}),g?(0,Z.jsx)(`input`,{autoFocus:!0,value:v,onChange:e=>y(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{_(!1);let n=v.trim();n&&n!==Dx(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Dx(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,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),_(!0))},children:Dx(e,t)}),(0,Z.jsx)(H,{variant:`outline`,className:U(`text-[10px] font-medium`,m.badge),children:f}),h&&(0,Z.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:h}),a&&b&&!g&&(0,Z.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,Z.jsx)(In,{className:`h-3 w-3`})})]})]})}function Mx(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)?Mx(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Nx(e){switch(e){case`object`:return kt;case`page`:return oo;case`dashboard`:return Dt;case`report`:return yo;default:return nr}}function Px({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}=X.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:Mx(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,Z.jsx)(Cb,{hint:`app`,toolbar:g&&(0,Z.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,Z.jsx)(_n,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,Z.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,Z.jsx)(kx,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Z.jsxs)(wb,{children:[`No top-level nav items. Add `,(0,Z.jsx)(`code`,{children:`nav`}),` / `,(0,Z.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,Z.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,Z.jsx)(Fx,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Fx({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Nx(e.kind),s=Ix(t,e.path);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Z.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,Z.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,Z.jsx)(_n,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Z.jsx)(Fx,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function Ix(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 Lx(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Z.jsx)(Rx,{...e,icon:t===`password`?(0,Z.jsx)(ot,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(Ao,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(Ka,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(sr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(ur,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)($e,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.pickDate`,n)});case`time`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(Ht,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,Z.jsx)(zx,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Z.jsx)(to,{disabled:!0}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??J(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Z.jsx)(Bx,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Z.jsx)(Bx,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Z.jsx)(Vx,{...e});case`image`:case`avatar`:return(0,Z.jsx)(Hx,{icon:(0,Z.jsx)(zt,{className:`h-4 w-4`}),label:J(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Z.jsx)(Hx,{icon:(0,Z.jsx)(Pt,{className:`h-4 w-4`}),label:Y(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Z.jsx)(Hx,{icon:(0,Z.jsx)(Pt,{className:`h-4 w-4`}),label:J(`designer.stub.qrcode`,n)});case`color`:return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Z.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Z.jsx)(Na,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,Z.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,Z.jsx)(Fe,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,Z.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Z.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,Z.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,Z.jsx)(Rx,{...e,icon:(0,Z.jsx)(Bn,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.latLng`,n)});case`address`:return(0,Z.jsx)(zx,{...e,placeholder:e.placeholder??`Street
|
|
22
|
+
City, State ZIP
|
|
23
|
+
Country`});case`formula`:case`summary`:return(0,Z.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}`:`ƒ ${J(`designer.stub.computed`,n)}`});case`composite`:return(0,Z.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:J(`designer.stub.composite`,n)});case`repeater`:return(0,Z.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:J(`designer.stub.repeater`,n)});case`vector`:return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(W,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function Rx({placeholder:e,icon:t}){return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(W,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,Z.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function zx({placeholder:e,mono:t}){return(0,Z.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 Bx({options:e,placeholder:t,single:n,locale:r}){let i=e??[],a=i.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,Z.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:a[0]?.label||a[0]?.value||t||J(`designer.stub.select`,r)}),(0,Z.jsx)(Ta,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,Z.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[a.length===0?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||J(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,Z.jsx)(H,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function Vx({referenceTo:e,placeholder:t,locale:n}){let r=e?ld.lookup:null;return(0,Z.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,Z.jsx)($t,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?Y(`designer.stub.searchRef`,n,{ref:e}):J(`designer.stub.chooseRelated`,n))}),e&&(0,Z.jsxs)(H,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Z.jsx)(Co,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function Hx({icon:e,label:t}){return(0,Z.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,Z.jsx)(`span`,{className:`text-[11px]`,children:t})]})}var Ux=e=>(e??``).toLowerCase().startsWith(`zh`),Wx=(e,t)=>e?Ux(t)?e.labelZh:e.label:void 0,Gx=(e,t)=>(Ux(t)?md:dd)[e];function Kx({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,c=X.useMemo(()=>Uu(t.fields),[t]),l=X.useMemo(()=>n?od(n.fields,t.fields):null,[n,t]),u=l?l.counts.added+l.counts.changed+l.counts.removed:0,[d,f]=X.useState(!1);X.useEffect(()=>{d&&u===0&&f(!1)},[d,u]);let p=d&&u>0,m=e=>p?l?.byName[e]?.status:void 0,h=e=>p?l?.byName[e]?.changedKeys??[]:[],g=X.useMemo(()=>Yu(t.fieldGroups),[t]),_=g.length>0,v=X.useMemo(()=>rd(c,g,{includeEmptyDeclared:!s}),[c,g,s]),[y,b]=X.useState({}),x=e=>e??`__ungrouped__`,S=X.useCallback(e=>{let t=e??`__ungrouped__`;b(e=>({...e,[t]:!e[t]}))},[]),C=v.length>0&&v.every(e=>y[x(e.key)]),w=X.useCallback(e=>{b(()=>{let t={};for(let n of v)t[x(n.key)]=e;return t})},[v]),T=i?.kind===`field`?String(i.id):null,E=c.entries.filter(e=>!!e.def.required).length,D=X.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[O,k]=X.useState(()=>new Set),A=X.useRef(null),j=X.useMemo(()=>v.flatMap(e=>e.entries.map(e=>e.name)),[v]);X.useEffect(()=>{k(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>c.entries.some(t=>t.name===e)));return t.size===e.size?e:t})},[c]);let ee=X.useCallback((e,t)=>{let n=e.name;if(!s&&t&&(t.metaKey||t.ctrlKey)){k(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),A.current=n;return}if(!s&&t&&t.shiftKey&&A.current&&A.current!==n){let e=j.indexOf(A.current),t=j.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];k(new Set(j.slice(n,r+1)));return}}O.size&&k(new Set),A.current=n,D(e)},[s,j,O,D]),te=X.useCallback(()=>k(new Set),[]),M=X.useCallback(()=>{if(!r||O.size===0)return;let e=c.entries.filter(e=>!O.has(e.name));r({fields:Wu({shape:c.shape,entries:e})}),T&&O.has(T)&&a?.(null),k(new Set)},[r,O,c,T,a]),ne=X.useCallback(e=>{if(!r||O.size===0)return;let t=c.entries.map(t=>O.has(t.name)?{name:t.name,def:{...t.def,group:e??void 0}}:t);r({fields:Wu({shape:c.shape,entries:t})})},[r,O,c]),re=X.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(e=>e.name),i=e===`select`?`status`:e,o=1,s=i;for(;n.includes(s);)o+=1,s=`${i}_${o}`;let l=Ku(s,e);t&&(l.def={...l.def,group:t});let u=c.entries.length;if(t){for(let e=c.entries.length-1;e>=0;--e)if(c.entries[e].def.group===t){u=e+1;break}}let d=c.entries.slice();d.splice(u,0,l),r({fields:Wu({shape:c.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(l.def.label??s)})},[r,a,c]),N=X.useCallback(()=>{if(!r)return;let e=Zu(g,Y(`designer.canvas.sectionN`,o,{n:g.length+1})),t=e[e.length-1];r({fieldGroups:e}),b(e=>({...e,[t.key]:!1}))},[r,g,o]),ie=X.useCallback((e,t)=>{r&&r({fieldGroups:Qu(g,e,t)})},[r,g]),P=X.useCallback(e=>{if(!r)return;let t=td(c,e);r({fieldGroups:$u(g,e),fields:Wu(t)})},[r,g,c]),F=X.useCallback((e,t)=>{r&&r({fieldGroups:ed(g,e,t)})},[r,g]),ae=X.useCallback((e,t,n)=>{if(!r||e===t)return;let i=c.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[o]=i.splice(a,1),s=i.findIndex(e=>e.name===t),l=s>=0?i[s]:void 0;if(l){let e=typeof l.def.group==`string`?l.def.group:void 0;e!==(typeof o.def.group==`string`?o.def.group:void 0)&&(o.def={...o.def,group:e})}s<0?i.push(o):i.splice(n===`before`?s:s+1,0,o),r({fields:Wu({shape:c.shape,entries:i})})},[r,c]),oe=X.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let a=typeof n[i].def.group==`string`?n[i].def.group:null,o=i+t;for(;o>=0&&o<n.length&&(typeof n[o].def.group==`string`?n[o].def.group:null)!==a;)o+=t;if(o<0||o>=n.length)return;let s=n[i];n[i]=n[o],n[o]=s,r({fields:Wu({shape:c.shape,entries:n})})},[r,c]),se=X.useCallback((e,t)=>{if(!r)return;let n=c.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let[a]=n.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){n.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let o=n.length;for(let e=n.length-1;e>=0;--e)if((typeof n[e].def.group==`string`?n[e].def.group:null)===t){o=e+1;break}n.splice(o,0,a),r({fields:Wu({shape:c.shape,entries:n})})},[r,c]),ce=X.useCallback((e,t)=>{if(!r)return;let n=c.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);r({fields:Wu({shape:c.shape,entries:n})})},[r,c]),le=X.useCallback(e=>{e.target===e.currentTarget&&T&&a?.(null)},[a,T]),ue=c.entries.length===0,de=_||v.length>1;return(0,Z.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:le,"data-object-name":e,children:[!s&&O.size>0&&(0,Z.jsx)(Jx,{count:O.size,groups:g,onMoveToGroup:ne,onDelete:M,onClear:te,locale:o}),(0,Z.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:le,children:[!ue&&(0,Z.jsx)(qx,{fieldCount:c.entries.length,requiredCount:E,sectionCount:g.length,allCollapsed:C,onToggleAll:de?()=>w(!C):void 0,reviewAvailable:u>0,reviewing:p,diffCounts:l?.counts,onToggleReview:()=>f(e=>!e),locale:o}),ue?(0,Z.jsx)($x,{onAdd:s?void 0:re,locale:o}):(0,Z.jsx)(`div`,{className:`space-y-5`,children:v.map(e=>{let t=e.key?g.findIndex(t=>t.key===e.key):-1;return(0,Z.jsxs)(Yx,{groupKey:e.key,label:e.key===null?J(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:de,collapsed:!!y[x(e.key)],onToggleCollapse:()=>S(e.key),readOnly:s,locale:o,canMoveUp:t>0,canMoveDown:t>=0&&t<g.length-1,onRename:e.key?t=>ie(e.key,t):void 0,onRemove:e.key?()=>P(e.key):void 0,onMove:e.key?t=>F(e.key,t):void 0,onAddField:s?void 0:t=>re(t,e.key),onDropField:s?void 0:se,children:[e.entries.map(e=>(0,Z.jsx)(Qx,{entry:e,selected:e.name===T,multiSelected:O.has(e.name),diffStatus:m(e.name),changedKeys:h(e.name),readOnly:s,locale:o,onClick:t=>ee(e,t),onReorder:s?void 0:ae,onRenameLabel:s?void 0:ce,onMoveOffset:s?void 0:t=>oe(e.name,t)},e.name)),e.entries.length===0&&(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:J(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),p&&l&&l.removed.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:J(`designer.canvas.diffRemoved`,o)}),l.removed.map(e=>(0,Z.jsx)(Zx,{entry:e,locale:o},e.name))]}),!ue&&!s&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Z.jsx)(eS,{onPick:e=>re(e),locale:o}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:N,children:[(0,Z.jsx)(ai,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addSection`,o)]}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>al(),children:[(0,Z.jsx)(_a,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAi`,o)]})]})]})]})}function qx({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,J(`designer.canvas.diffAdded`,l),(0,Z.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,J(`designer.canvas.diffChanged`,l),(0,Z.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,J(`designer.canvas.diffRemoved`,l),(0,Z.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:J(`designer.canvas.reviewVsPublished`,l)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,J(`designer.canvas.fields`,l),(0,Z.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,J(`designer.canvas.required`,l),n>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,J(`designer.canvas.sections`,l)]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,Z.jsxs)(`button`,{type:`button`,onClick:c,className:U(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 transition-colors`,o?`bg-primary/10 text-primary hover:bg-primary/15`:`hover:bg-accent hover:text-foreground`),children:[(0,Z.jsx)(Fa,{className:`h-3 w-3`}),J(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,Z.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:[r?(0,Z.jsx)(ti,{className:`h-3 w-3`}):(0,Z.jsx)(ia,{className:`h-3 w-3`}),J(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function Jx({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=X.useState(!1);return(0,Z.jsxs)(`div`,{className:`sticky top-0 z-20 flex items-center gap-2 border-b border-primary/20 bg-primary/10 backdrop-blur px-6 py-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:Y(`designer.canvas.bulkSelected`,a,{n:e})}),(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:J(`designer.canvas.bulkHint`,a)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,Z.jsxs)(Or,{open:o,onOpenChange:s,children:[(0,Z.jsx)(Ie,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,Z.jsx)(wa,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkMoveTo`,a),(0,Z.jsx)(Ta,{className:`h-3 w-3`})]})}),(0,Z.jsxs)(jn,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(null),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent`,children:J(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(e.key),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent truncate`,children:e.label||e.key},e.key))]})]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,Z.jsx)(In,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkDelete`,a)]}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkClear`,a)]})]})]})}function Yx({groupKey:e,label:t,count:n,showHeader:r,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,onRename:u,onRemove:d,onMove:f,onAddField:p,onDropField:m,children:h}){let[g,_]=X.useState(!1);return(0,Z.jsxs)(`section`,{className:U(`space-y-2.5 rounded-md transition-colors`,g&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!m)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(!0))},onDragLeave:e=>{e.currentTarget===e.target&&_(!1)},onDrop:t=>{if(!m)return;if(t.defaultPrevented){_(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);_(!1),n&&m(n,e)},children:[r&&(0,Z.jsx)(Xx,{label:t,count:n,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,dropActive:g,onRename:u,onRemove:d,onMove:f,onAddField:p}),!i&&(0,Z.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function Xx({label:e,count:t,collapsed:n,onToggleCollapse:r,readOnly:i,locale:a,canMoveUp:o,canMoveDown:s,dropActive:c,onRename:l,onRemove:u,onMove:d,onAddField:f}){let[p,m]=X.useState(!1),[h,g]=X.useState(e);X.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?si:Ta;return(0,Z.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-accent hover:text-foreground transition-colors shrink-0`,"aria-label":J(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,Z.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,Z.jsx)(`input`,{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`?(t.preventDefault(),_()):t.key===`Escape`&&(t.preventDefault(),g(e),m(!1))},onBlur:_,className:`text-[11px] font-medium uppercase tracking-wider px-1 py-0.5 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1 max-w-[220px]`}):(0,Z.jsx)(`span`,{className:U(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?J(`designer.canvas.renameHint`,a):void 0,children:e}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,Z.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:J(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 opacity-0 group-hover/sec:opacity-100 focus-within:opacity-100 transition-opacity`,children:[f&&(0,Z.jsx)(eS,{onPick:f,compact:!0,locale:a}),d&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>d(-1),disabled:!o,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":J(`designer.canvas.moveSectionUp`,a),children:(0,Z.jsx)(ir,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>d(1),disabled:!s,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":J(`designer.canvas.moveSectionDown`,a),children:(0,Z.jsx)(ja,{className:`h-3 w-3`})})]}),u&&(0,Z.jsx)(`button`,{type:`button`,onClick:u,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":J(`designer.canvas.removeSection`,a),title:J(`designer.canvas.removeSectionHint`,a),children:(0,Z.jsx)(In,{className:`h-3 w-3`})})]})]})}function Zx({entry:e,locale:t}){let n=e.def,r=ld[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed border-destructive/30 bg-destructive/[0.03] px-3.5 py-2.5 opacity-80`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[r&&(0,Z.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,Z.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,Z.jsx)(H,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:J(`designer.canvas.diffRemoved`,t)})]})})}function Qx({entry:e,selected:t,multiSelected:n,diffStatus:r,changedKeys:i,readOnly:a,locale:o,onClick:s,onReorder:c,onRenameLabel:l,onMoveOffset:u}){let d=e.def,f=typeof d.type==`string`?d.type:`text`,p=ld[f],m=p?.Icon,h=fd[p?.category??`advanced`],g=typeof d.label==`string`?d.label:e.name,_=!!d.required,v=typeof d.description==`string`?d.description:null,y=Array.isArray(d.options)?d.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,b=typeof d.reference==`string`?d.reference:void 0,x=typeof d.formula==`string`?d.formula:void 0,S=typeof d.placeholder==`string`?d.placeholder:void 0,[C,w]=X.useState(null),T=!!c,[E,D]=X.useState(!1),[O,k]=X.useState(g);X.useEffect(()=>{k(g)},[g]);let A=e=>{l&&(e.preventDefault(),e.stopPropagation(),k(g),D(!0))},j=()=>{if(!l){D(!1);return}let t=O.trim();t&&t!==g&&l(e.name,t),D(!1)},ee=()=>{k(g),D(!1)};return(0,Z.jsxs)(`div`,{className:U(`relative`,C===`before`&&`pt-1.5`),onDragOver:e=>{if(!T)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();w(e.clientY-n.top<n.height/2?`before`:`after`)},onDragLeave:()=>w(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);w(null),n&&n!==e.name&&c(n,e.name,C??`before`)},children:[C===`before`&&(0,Z.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Z.jsxs)(`div`,{role:`button`,tabIndex:a?-1:0,onClick:s,onKeyDown:e=>{if(e.target===e.currentTarget){if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u&&(e.preventDefault(),u(e.key===`ArrowUp`?-1:1));return}(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s?.())}},draggable:T,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className: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&&`border-primary/60 ring-2 ring-primary/40 bg-primary/[0.04]`,r===`added`&&`border-l-[3px] border-l-emerald-500`,r===`changed`&&`border-l-[3px] border-l-amber-500`,a&&`cursor-default`,T&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[n&&(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),T&&!n&&(0,Z.jsx)(je,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,Z.jsx)(m,{className:U(`h-3.5 w-3.5 shrink-0`,h.icon)}),E?(0,Z.jsx)(`input`,{autoFocus:!0,value:O,onChange:e=>k(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),j()):e.key===`Escape`&&(e.preventDefault(),ee())},onBlur:j,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Z.jsx)(`span`,{className:U(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:A,title:l?J(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(0,Z.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,Z.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,Z.jsx)(H,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:J(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,Z.jsx)(H,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?Y(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:J(`designer.canvas.diffChanged`,o)}),(0,Z.jsx)(H,{variant:`outline`,className:U(`text-[10px] font-medium`,h.badge),children:Wx(p,o)??f})]})]}),v&&(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,Z.jsx)(Lx,{type:f,label:g,placeholder:S,options:y,referenceTo:b,formula:x,locale:o})]}),C===`after`&&(0,Z.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function $x({onAdd:e,locale:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:J(`designer.canvas.noFields`,t)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:J(`designer.canvas.noFieldsHint`,t)}),e&&(0,Z.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(eS,{onPick:e,locale:t}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>al(),children:[(0,Z.jsx)(_a,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAiGenerate`,t)]})]})]})}function eS({onPick:e,compact:t,locale:n}){let[r,i]=X.useState(!1),[a,o]=X.useState(``),s=a.trim().toLowerCase(),c=X.useMemo(()=>s?hd.map(e=>({category:e.category,types:e.types.filter(e=>{let t=ld[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):hd,[s,a]);return(0,Z.jsxs)(Or,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,Z.jsx)(Ie,{asChild:!0,children:t?(0,Z.jsx)(`button`,{type:`button`,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":J(`designer.canvas.addFieldToSection`,n),title:J(`designer.canvas.addFieldToSection`,n),children:(0,Z.jsx)(Oo,{className:`h-3 w-3`})}):(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addField`,n)]})}),(0,Z.jsxs)(jn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Z.jsx)(`div`,{className:`p-2 border-b`,children:(0,Z.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:J(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:J(`designer.canvas.noMatchingTypes`,n)}):c.map(t=>(0,Z.jsxs)(`div`,{className:`mb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:Gx(t.category,n)}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=ld[t],a=r.Icon;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),i(!1),o(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Z.jsx)(a,{className:U(`h-3.5 w-3.5 shrink-0`,fd[r.category].icon)}),(0,Z.jsx)(`span`,{className:`truncate`,children:Wx(r,n)})]},t)})})]},t.category))})]})]})}function tS({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,Z.jsx)(Cb,{hint:`object · designer`,children:(0,Z.jsx)(Eb,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Z.jsx)(Kx,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,Z.jsx)(Cb,{hint:`object`,children:(0,Z.jsx)(wb,{children:J(`designer.canvas.nameToStart`,o)})})}function nS(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 rS(e,t){return t[e]??``}function iS(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>rS(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>rS(n,t))}function aS({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=X.useMemo(()=>{let e=new Set;for(let n of nS(t))e.add(n);for(let t of nS(i))e.add(t);for(let t of nS(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=X.useState({}),l=iS(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
24
|
+
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
25
|
+
a{color:#2563eb;}
|
|
26
|
+
</style></head><body>${(i?iS(i,s):iS(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Z.jsx)(Cb,{hint:`email_template`,children:(0,Z.jsx)(wb,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Z.jsx)(Cb,{hint:`email_template`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,Z.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,Z.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,Z.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Z.jsx)(Xe,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,Z.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,Z.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,Z.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,Z.jsxs)(`label`,{className:`block`,children:[(0,Z.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,Z.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 oS(e){return typeof e==`number`&&Number.isFinite(e)}function sS(e){return oS(e.ui?.x)&&oS(e.ui?.y)}function cS(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)sS(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function lS(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 uS(e){return{x:e.x+240/2,y:e.y+66}}function dS(e){return{x:e.x+240/2,y:e.y}}function fS(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 pS(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function mS(e,t){return e.id||`${e.source}->${e.target}#${t}`}function hS(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function gS(e){switch(e){case`start`:return tr;case`end`:return Pe;case`decision`:case`branch`:case`gateway`:return ht;case`wait`:case`timer`:case`delay`:return Ct;case`boundary_event`:case`signal`:return To;case`subflow`:case`flow`:return Qe;case`create_record`:return _o;case`update_record`:return Hn;case`delete_record`:return Ti;case`get_record`:return Kr;case`http_request`:case`webhook`:return Ka;case`script`:case`script_task`:return Zn;case`screen`:case`user_task`:return Sa;case`approval`:return Wi;case`connector_action`:case`service_task`:return We;case`assignment`:return nt;case`loop`:case`for_each`:return hn;case`parallel_gateway`:case`join_gateway`:case`parallel`:return pa;case`try_catch`:return sa;default:return Ri}}var _S={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 vS(e){switch(e){case`start`:return _S.start;case`end`:return _S.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return _S.decision;case`wait`:case`timer`:case`delay`:return _S.wait;case`boundary_event`:case`signal`:case`try_catch`:return _S.signal;case`subflow`:case`flow`:return _S.subflow;case`approval`:return _S.approval;case`loop`:case`for_each`:return _S.loop;case`screen`:case`user_task`:return _S.screen;case`assignment`:return _S.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return _S.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return _S.integration;default:return _S.task}}function yS({type:e,className:t}){return X.createElement(gS(e),{className:t,"aria-hidden":!0})}var bS=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function xS(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`:case`try_catch`: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 SS=[{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`,label:`Parallel`,hint:`Run branches concurrently, join at end`,category:`Logic`},{type:`try_catch`,label:`Try / Catch`,hint:`Protect steps with error handling and retry`,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 CS(e){let t=SS.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function wS(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 TS({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=vS(e);return(0,Z.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,Z.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,Z.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,Z.jsx)(yS,{type:e,className:U(`h-[18px] w-[18px]`,d.icon)})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{title:t,className:`truncate text-[13px] font-semibold leading-tight text-foreground`,children:t}),(0,Z.jsxs)(`div`,{className:`mt-1 flex items-baseline gap-1.5 leading-tight`,children:[(0,Z.jsx)(`span`,{className:U(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.08em]`,d.label),children:e}),n&&(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,title:n,children:n})]})]})]}),a&&e!==`end`&&(0,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`})})]})}function ES({items:e=SS,onPick:t,onClose:n}){let r=X.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??xS(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return bS.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=vS(e.type);return(0,Z.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,Z.jsx)(`span`,{className:U(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,Z.jsx)(yS,{type:e.type,className:U(`h-[15px] w-[15px]`,n.icon)})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[13px] font-medium`,children:e.label}),e.hint&&(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.hint})]})]},e.type)};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-20`,onClick:n,"aria-hidden":!0}),(0,Z.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,Z.jsxs)(`div`,{className:U(n>0&&`mt-1 border-t border-border/60 pt-1`),children:[(0,Z.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 DS(){return`${``.replace(/\/$/,``)}/api/v1`}function OS(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??xS(e.type)})}return[...n.values()]}function kS(){let[e,t]=(0,X.useState)([]),n=(0,X.useRef)(!0);return(0,X.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${DS()}/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 AS(){let e=kS();return(0,X.useMemo)(()=>e.length?OS(SS,e):SS,[e])}function jS(){let e=kS();return(0,X.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 MS=.4,NS=1.6,PS=4;function FS({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=X.useRef(null),[m,h]=X.useState(1),[g,_]=X.useState({x:0,y:0}),[v,y]=X.useState(!1),b=AS(),[x,S]=X.useState(null),C=X.useRef(null),w=X.useRef(null),T=X.useMemo(()=>cS(e,t),[e,t]),E=X.useMemo(()=>lS(T),[T]),D=X.useMemo(()=>new Set(c??[]),[c]),O=X.useMemo(()=>new Set(l??[]),[l]),k=(c?.length??0)>0||!!s,A=X.useCallback(e=>x&&x.id===e?{x:x.x,y:x.y}:T.get(e)??{x:0,y:0},[x,T]),j=X.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:bs(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),ee=X.useCallback((n,r)=>{if(!f)return;let i=zs(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:CS(n),o=r?.at,s={id:i,type:n,label:a,...wS(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:Bs(e,s)};r?.from&&(c.edges=Bs(t,{id:zs(`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=X.useCallback((n,r=`create_record`)=>{if(!f)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=zs(`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:CS(r),...wS(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:zs(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=bs(t,i,d);f({nodes:Bs(e,l),edges:Bs(m,p)}),u(l)},[t,e,f,u,A]),M=X.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=X.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]),re=X.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)<PS||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),N=X.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=X.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]),P=X.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),F=X.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),ae=e=>Math.min(NS,Math.max(MS,e)),oe=X.useCallback(()=>{let e=p.current;if(!e)return;let t=(e.clientWidth-32)/E.width,n=(e.clientHeight-32)/E.height,r=ae(Math.min(t,n,1));h(r),_({x:(e.clientWidth-E.width*r)/2,y:Math.max(16,(e.clientHeight-E.height*r)/2)})},[E.height,E.width]),se=X.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,Z.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`absolute right-2 top-2 z-30 flex items-center gap-1.5`,children:[n&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`}),J(`engine.inspector.add.node`,o)]}),v&&(0,Z.jsx)(ES,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>ee(e,{from:i??void 0})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-background/90 shadow-sm backdrop-blur-sm`,children:[(0,Z.jsx)(`button`,{type:`button`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>h(e=>ae(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(Pr,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`span`,{className:`w-10 text-center text-[11px] tabular-nums text-muted-foreground`,children:[Math.round(m*100),`%`]}),(0,Z.jsx)(`button`,{type:`button`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>h(e=>ae(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(so,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:oe,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(Wr,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:se,onPointerDown:ie,onPointerMove:e=>{P(e),re(e)},onPointerUp:e=>{F(e),N(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,Z.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,Z.jsxs)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:E.width,height:E.height,children:[(0,Z.jsx)(`defs`,{children:(0,Z.jsx)(`marker`,{id:`flow-arrow`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Z.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=uS(x?.id===e.source?A(e.source):i),c=dS(x?.id===e.target?A(e.target):o),l=pS(s,c),u=hS(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=mS(e,t),m=O.has(p),h=a===p,g=fS(s,c),_=r&&!!d;return(0,Z.jsxs)(`g`,{children:[(0,Z.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,Z.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,Z.jsx)(`title`,{children:`${e.source} → ${e.target}`})}),f&&(0,Z.jsx)(`foreignObject`,{x:l.x-60,y:l.y-11,width:120,height:22,className:U(_&&`pointer-events-auto`),children:(0,Z.jsx)(`div`,{className:`flex justify-center`,children:(0,Z.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,Z.jsx)(`foreignObject`,{x:f?l.x+66:l.x-11,y:l.y-11,width:22,height:22,className:`pointer-events-auto`,children:(0,Z.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,Z.jsx)(Oo,{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,Z.jsx)(TS,{id:e.id,type:e.type,label:e.label||e.id,summary:IS(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 IS(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 LS=e=>typeof e==`string`?e:void 0;function RS(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new B({...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 zS(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=>LS(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 BS=500,VS=new Set([`start`,`assignment`]),HS=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),US=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),WS=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,GS=e=>typeof e==`string`?e:void 0,KS=e=>typeof e==`string`&&e?e:void 0,qS=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=zS([...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>=BS)return e.status=`error`,e.error=`Step limit (${BS}) 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(US.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(HS.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:VS.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=GS(e.condition);if(!t){n.push({edgeId:WS(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=RS(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:WS(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:WS(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=KS(e.config?.collection),n=KS(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=KS(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=KS(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=WS(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 JS(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 YS=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function XS(e){let t=[];for(let n of e){if(!YS.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 ZS={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 QS({nodes:e,edges:t,variables:n,onRunStateChange:r}){let i=X.useRef(null),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useMemo(()=>n.filter(e=>e.isInput),[n]),u=X.useMemo(()=>XS(e),[e]),[d,f]=X.useState({}),[p,m]=X.useState([]),[h,g]=X.useState({}),_=X.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=X.useCallback(()=>{let e={};for(let t of l){let n=d[t.name],r=n==null?void 0:JS(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=JS(t.v))}return e},[l,d,p]),y=X.useCallback(()=>{let e={};for(let[t,n]of Object.entries(h))n!=null&&n.trim()!==``&&(e[t]=JS(n));return e},[h]),b=X.useCallback(()=>{let n=new qS(e,t);i.current=n,c(n.reset(v(),y())),_()},[e,t,v,y,_]),x=X.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,Z.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Z.jsxs)(K,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:D,children:[(0,Z.jsx)(tr,{className:`h-3.5 w-3.5`}),` Run`]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:D||E===`done`||E===`error`,children:[(0,Z.jsx)(An,{className:`h-3.5 w-3.5`}),` Step`]}),E===`paused`&&(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,Z.jsx)(si,{className:`h-3.5 w-3.5`}),` Continue`]}),(0,Z.jsxs)(K,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:T,children:[(0,Z.jsx)(st,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Z.jsx)(`span`,{className:U(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,ZS[E===`idle`||E===`running`?`ok`:E]??`bg-muted`),children:E})]}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[s.errors.map((e,t)=>(0,Z.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,Z.jsx)(Ha,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Z.jsx)(`span`,{children:e.message})]},`e${t}`)),s.warnings.map((e,t)=>(0,Z.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,Z.jsx)(gt,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Z.jsx)(`span`,{children:e.message})]},`w${t}`))]}),l.length>0&&(0,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Inputs`}),l.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(G,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,Z.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,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Z.jsx)(`span`,{children:`Set variables`}),(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),` Add`]})]}),p.length===0?(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.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,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,Z.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,Z.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,Z.jsx)(In,{className:`h-3 w-3`})})]},t))]}),u.length>0&&(0,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Mock outputs`}),u.map(e=>(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(G,{className:`flex items-baseline gap-1.5 text-[11px]`,title:e.id,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type.replace(/_/g,` `)}),e.outputs.length>0&&(0,Z.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-violet-600`,children:[`→ `,e.outputs.join(`, `)]})]}),(0,Z.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,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Variables`}),Object.keys(a.variables).length===0?(0,Z.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No variables set.`}):(0,Z.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(a.variables).map(([e,t])=>(0,Z.jsxs)(`li`,{className:`flex items-baseline gap-1.5 rounded border bg-background px-1.5 py-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-[11px]`,children:e}),(0,Z.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,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Timeline`}),(0,Z.jsx)(`ol`,{className:`space-y-1`,children:a.steps.map(e=>(0,Z.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.seq+1}),(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),(0,Z.jsx)(`span`,{className:U(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,ZS[e.status]),children:e.status})]}),e.note&&(0,Z.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e.note}),e.error&&(0,Z.jsx)(`div`,{className:`mt-0.5 text-[10px] text-rose-600`,children:e.error}),e.wrote&&(0,Z.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,Z.jsx)(`ul`,{className:`mt-0.5 space-y-0.5`,children:e.edges.map(e=>(0,Z.jsxs)(`li`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`div`,{className:U(`flex items-center gap-1 font-mono text-[10px]`,e.selected?`text-sky-700`:`text-muted-foreground`),children:[(0,Z.jsx)(`span`,{children:e.selected?`▶`:`·`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.isDefault?`else`:e.condition}),(0,Z.jsx)(`span`,{className:U(`ml-auto`,e.error&&`text-rose-600`),children:e.error?`error`:e.result?`true`:`false`})]}),e.error&&(0,Z.jsx)(`div`,{className:`pl-3 text-[10px] text-rose-600`,children:e.error})]},e.edgeId))})]},e.seq))})]}),!a&&!D&&(0,Z.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.`})]})]})}async function $S(e,t){try{let n=await fetch(`${DS()}/automation/${encodeURIComponent(e)}/runs?limit=25`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:t});if(!n.ok)return null;let r=await n.json(),i=r?.data?.runs??r?.runs;return Array.isArray(i)?i:null}catch{return null}}var eC={completed:{icon:Hr,cls:`text-emerald-600 dark:text-emerald-400`,label:`Completed`},failed:{icon:Ha,cls:`text-rose-600 dark:text-rose-400`,label:`Failed`},paused:{icon:Ia,cls:`text-amber-600 dark:text-amber-400`,label:`Paused`},running:{icon:V,cls:`text-sky-600 dark:text-sky-400`,label:`Running`},cancelled:{icon:ea,cls:`text-muted-foreground`,label:`Cancelled`}};function tC(e){return eC[e]??{icon:Ht,cls:`text-muted-foreground`,label:e}}function nC(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function rC(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function iC({step:e}){return(0,Z.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,children:[(0,Z.jsx)(`span`,{className:U(`shrink-0 text-[9px] font-semibold uppercase`,e.status===`success`?`text-emerald-600 dark:text-emerald-400`:e.status===`failure`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`),children:e.status}),(0,Z.jsx)(`span`,{className:`truncate font-mono text-[10px]`,title:e.nodeId,children:e.nodeId}),e.nodeType&&(0,Z.jsx)(`span`,{className:`shrink-0 text-[9px] uppercase text-muted-foreground`,children:e.nodeType}),rC(e.durationMs)&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:rC(e.durationMs)}),e.error?.message&&(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[9px] text-rose-600`,title:e.error.message,children:e.error.message})]})}function aC({run:e}){let[t,n]=X.useState(!1),r=tC(e.status),i=r.icon,a=Array.isArray(e.steps)?e.steps:[];return(0,Z.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-1.5 p-1.5 text-left`,"aria-expanded":t,children:[t?(0,Z.jsx)(Ta,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Z.jsx)(si,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Z.jsx)(i,{className:U(`h-3.5 w-3.5 shrink-0`,r.cls,e.status===`running`&&`animate-spin`)}),(0,Z.jsx)(`span`,{className:U(`shrink-0 text-[10px] font-semibold`,r.cls),children:r.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground`,title:e.id,children:nC(e.startedAt)}),rC(e.durationMs)&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:rC(e.durationMs)})]}),t&&(0,Z.jsxs)(`div`,{className:`border-t px-2 py-1.5`,children:[(0,Z.jsxs)(`div`,{className:`pb-1 font-mono text-[9px] text-muted-foreground`,title:e.id,children:[`run `,e.id,e.trigger?.type&&` · trigger ${e.trigger.type}`]}),e.error?.message&&(0,Z.jsx)(`div`,{className:`pb-1 text-[10px] text-rose-600`,children:e.error.message}),a.length===0?(0,Z.jsx)(`div`,{className:`text-[10px] italic text-muted-foreground`,children:`No step log recorded.`}):(0,Z.jsx)(`ul`,{className:`divide-y divide-border/50`,children:a.map((e,t)=>(0,Z.jsx)(iC,{step:e},`${e.nodeId}#${t}`))})]})]})}function oC({flowName:e}){let[t,n]=X.useState([]),[r,i]=X.useState(`loading`),[a,o]=X.useState(0);return X.useEffect(()=>{let t=new AbortController,r=!0;return i(`loading`),(async()=>{let a=await $S(e,t.signal);r&&(a===null?i(`unavailable`):(n(a),i(`ready`)))})(),()=>{r=!1,t.abort()}},[e,a]),(0,Z.jsxs)(`div`,{className:`flex h-full flex-col p-3 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 font-medium text-muted-foreground`,children:[(0,Z.jsx)(Ht,{className:`h-3 w-3`}),` Runs`,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>o(e=>e+1),title:`Refresh run history`,"aria-label":`Refresh run history`,className:`ml-auto rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:(0,Z.jsx)(Vi,{className:U(`h-3 w-3`,r===`loading`&&`animate-spin`)})})]}),r===`unavailable`?(0,Z.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Run history unavailable — the automation engine is offline or this flow hasn’t been published.`}):r===`ready`&&t.length===0?(0,Z.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No runs yet.`}):(0,Z.jsx)(`ul`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto`,children:t.map(e=>(0,Z.jsx)(aC,{run:e},e.id))})]})}function sC({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]=X.useState(!1),[g,_]=X.useState(!0),[v,y]=X.useState(!1),[b,x]=X.useState(null),S=X.useCallback(()=>{if(!d)return;let e={id:zs(`node`,s.map(e=>e.id).filter(Boolean)),type:`start`,label:`Start`};i({nodes:Bs(s,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[d,s,i,r]),C=typeof o.name==`string`&&o.name?o.name:``,w=String(o.type??`autolaunched`),T=String(o.status??(o.active?`active`:`draft`)),E=String(o.runAs??`user`),D=o.version==null?void 0:String(o.version),O=o.errorHandling?.strategy;return s.length===0?(0,Z.jsx)(Cb,{hint:`flow${u?` · design`:``}`,children:d?(0,Z.jsx)(`div`,{className:`p-3`,children:(0,Z.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:S,children:[(0,Z.jsx)(Oo,{className:`h-3 w-3`}),J(`engine.inspector.add.node`,a)]})}):(0,Z.jsx)(wb,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Z.jsx)(Cb,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Z.jsx)(Eb,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,Z.jsxs)(`div`,{className:`grid gap-0 h-full min-h-[440px] `+(m||g||v?`lg:grid-cols-[1fr_240px]`:`grid-cols-1`),children:[(0,Z.jsxs)(`div`,{className:`flex flex-col min-w-0 min-h-0`,children:[(0,Z.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,Z.jsx)(cC,{icon:To,label:`Trigger`,value:w}),(0,Z.jsx)(cC,{icon:Ri,label:`Status`,value:T,tone:T===`active`?`green`:T===`draft`?`gray`:`amber`}),(0,Z.jsx)(cC,{icon:jr,label:`Run as`,value:E}),D&&(0,Z.jsx)(cC,{label:`v`,value:D}),O&&(0,Z.jsx)(cC,{icon:Li,label:`On error`,value:O}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!m&&!v&&(0,Z.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,Z.jsx)(wr,{className:`h-3 w-3`}),` Variables`]}),C&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{y(e=>!e),h(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(v?`border-emerald-500 bg-emerald-50 text-emerald-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:`Run history from the automation engine`,children:[(0,Z.jsx)(gr,{className:`h-3 w-3`}),` Runs`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{h(e=>!e),y(!1)},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,Z.jsx)(rt,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Z.jsx)(FS,{nodes:s,edges:c,editable:d,designMode:u,selectedId:f,selectedEdgeId:p,locale:a,activeNodeId:b?.activeNodeId??null,visitedNodeIds:b?.visitedNodeIds,traversedEdgeIds:b?.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,Z.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Z.jsx)(QS,{nodes:s,edges:c,variables:l,onRunStateChange:x})}):v&&C?(0,Z.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Z.jsx)(oC,{flowName:C})}):g?(0,Z.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Z.jsx)(nt,{className:`h-3 w-3`}),` Variables`]}),l.length===0?(0,Z.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,Z.jsx)(`ul`,{className:`space-y-1.5`,children:l.map((e,t)=>(0,Z.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,Z.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,Z.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,Z.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]}):null]})})})}function cC({icon:e,label:t,value:n,tone:r=`gray`}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,Z.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function lC({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,Z.jsx)(Cb,{hint:`agent`,children:(0,Z.jsx)(wb,{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,Z.jsx)(Cb,{hint:`agent`,toolbar:v&&(0,Z.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,Z.jsx)(_n,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,Z.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,Z.jsx)(an,{className:`h-5 w-5 text-muted-foreground`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(vC,{icon:c?ct:tt,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Z.jsx)(vC,{icon:ot,label:l}),u.provider&&(0,Z.jsx)(vC,{icon:_a,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Z.jsx)(vC,{icon:Br,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Z.jsx)(vC,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Z.jsx)(dC,{title:`Instructions`,icon:Gr,children:s?(0,Z.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,Z.jsx)(fC,{children:`No system prompt set yet.`})}),(0,Z.jsx)(dC,{title:`Capabilities`,icon:Un,children:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(mC,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:_a,tone:`violet`,mono:!0}),(0,Z.jsx)(mC,{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:Un,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Z.jsx)(dC,{title:`Knowledge (RAG)`,icon:kt,children:(0,Z.jsx)(uC,{knowledge:p})})]}),(0,Z.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,Z.jsx)(hC,{icon:Zi,title:`Planning`,children:(0,Z.jsx)(gC,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Z.jsx)(hC,{icon:Dr,title:`Memory`,children:(0,Z.jsx)(gC,{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,Z.jsx)(hC,{icon:gi,title:`Guardrails`,children:(0,Z.jsx)(gC,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Z.jsx)(hC,{icon:ot,title:`Permissions`,children:(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,Z.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,Z.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function uC({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,Z.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,Z.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,Z.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Z.jsx)(kt,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,Z.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function dC({title:e,icon:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Z.jsx)(t,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e})]}),n]})}function fC({children:e}){return(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var pC={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 mC({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?pC[i]:null;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,Z.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,Z.jsx)(r,{className:U(`h-3 w-3 shrink-0`,o?.icon)}),e.label,e.hint&&(0,Z.jsx)(`span`,{className:`text-[9px] uppercase opacity-70`,children:e.hint})]},e.key))})]})}function hC({icon:e,title:t,children:n}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,Z.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function gC({data:e,keys:t}){let n=t.map(t=>[t,_C(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,Z.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,Z.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,Z.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function _C(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function vC({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function yC(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function bC(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${bC(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function xC(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 SC({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=yC(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=X.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=xC(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=xC(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Z.jsx)(Cb,{hint:`tool`,children:(0,Z.jsx)(wb,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Z.jsx)(Cb,{hint:`tool`,toolbar:r&&(0,Z.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,Z.jsx)(_n,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(Un,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,Z.jsx)(EC,{icon:Aa,label:o}),s&&(0,Z.jsx)(EC,{icon:kt,label:s,mono:!0}),(0,Z.jsx)(EC,{icon:Jt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Z.jsx)(EC,{icon:gt,label:`Requires confirmation`,tone:`amber`}),u&&(0,Z.jsx)(EC,{label:`built-in`})]})]})]}),a&&(0,Z.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Z.jsx)(wC,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Z.jsx)(TC,{children:`This tool takes no input parameters.`}):(0,Z.jsx)(CC,{props:p,required:m})}),Object.keys(p).length>0&&(0,Z.jsx)(wC,{title:`Example LLM Call`,icon:po,children:(0,Z.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
|
|
27
|
+
"tool": "${r}",
|
|
28
|
+
"arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
|
|
29
|
+
`)}
|
|
30
|
+
}`})}),yC(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Z.jsx)(wC,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Gi,children:(0,Z.jsx)(CC,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function CC({props:e,required:t}){return(0,Z.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:Object.keys(e).map(n=>{let r=e[n],i=t.has(n);return(0,Z.jsxs)(`tr`,{className:`align-top`,children:[(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,Z.jsx)(Hr,{className:`h-3 w-3 text-emerald-600`}):(0,Z.jsx)(si,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,Z.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:bC(r)}),(0,Z.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,Z.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,Z.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function wC({title:e,count:t,icon:n,children:r}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Z.jsx)(n,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e}),t!=null&&(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function TC({children:e}){return(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function EC({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var DC=[{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 OC(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 kC({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=X.useMemo(()=>Object.keys(o).sort(),[o]),f=X.useMemo(()=>OC(o),[o]),p=X.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,Z.jsx)(Cb,{hint:`permission`,children:(0,Z.jsx)(wb,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Z.jsx)(Cb,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,Z.jsx)(Fe,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Z.jsx)(Ca,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(NC,{icon:qt,label:`${d.length} objects`}),(0,Z.jsx)(NC,{icon:Aa,label:`${c.length} system perms`}),(0,Z.jsx)(NC,{icon:ct,label:`${Object.keys(l).length} tabs`}),(0,Z.jsx)(NC,{icon:ot,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Z.jsxs)(MC,{title:`Object Permissions`,count:d.length,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),DC.map(e=>(0,Z.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),DC.map(e=>(0,Z.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Z.jsx)(AC,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Z.jsx)(jC,{})]}),p.size>0&&(0,Z.jsx)(MC,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,Z.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,Z.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,Z.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,Z.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,Z.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,Z.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,Z.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,Z.jsx)(MC,{title:`System Permissions`,count:c.length,children:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,Z.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,Z.jsx)(MC,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e}),(0,Z.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,Z.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,Z.jsx)(gt,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,Z.jsxs)(`li`,{className:`text-amber-900`,children:[(0,Z.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function AC({granted:e,danger:t}){return e?(0,Z.jsx)(Hr,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Z.jsx)(pr,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function jC(){return(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(Hr,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(pr,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,Z.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 MC({title:e,count:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Z.jsx)(`span`,{children:e}),t!=null&&(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function NC({icon:e,label:t}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{children:t})]})}function PC(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 FC(e){switch(e){case`url`:return $t;case`modal`:return ft;case`flow`:return Qe;case`api`:return Ka;case`form`:return Bt;default:return cr}}function IC(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 LC(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 RC({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=PC(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=PC(n.confirmText),g=PC(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=FC(o),w=l===`action:icon`;return!r&&!i?(0,Z.jsx)(Cb,{hint:`action`,children:(0,Z.jsx)(wb,{children:`Set name and label to see the action preview.`})}):(0,Z.jsx)(Cb,{hint:`action`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,Z.jsx)(zC,{label:i,icon:a,variant:c,iconOnly:w,disabled:!!S&&typeof S==`boolean`})}),(0,Z.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(KC,{icon:C,label:`type: ${o}`}),b&&(0,Z.jsx)(KC,{icon:Ga,label:`object: ${b}`,mono:!0}),c&&(0,Z.jsx)(KC,{label:`variant: ${c}`}),l&&(0,Z.jsx)(KC,{icon:Yi,label:l}),d&&(0,Z.jsx)(KC,{icon:Do,label:d,mono:!0}),f&&(0,Z.jsx)(KC,{icon:go,label:`bulk`,tone:`green`}),p&&(0,Z.jsx)(KC,{icon:Vi,label:`refresh after`}),m===!1&&(0,Z.jsx)(KC,{icon:an,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Z.jsx)(KC,{icon:_a,label:`AI: exposed`})]}),u.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,Z.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,Z.jsx)(WC,{label:`Visible when`,value:x,icon:ct}),S!=null&&typeof S!=`boolean`&&(0,Z.jsx)(WC,{label:`Disabled when`,value:S,icon:ot})]}),(0,Z.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,Z.jsx)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,Z.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:LC(o,s,!!y?.source)}),h&&(0,Z.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,Z.jsx)(gt,{className:`h-3 w-3 mt-0.5`}),(0,Z.jsxs)(`span`,{children:[`First asks: `,(0,Z.jsx)(`em`,{children:h})]})]}),g&&(0,Z.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,Z.jsx)(`em`,{children:g})]})]}),_.length>0&&(0,Z.jsx)(GC,{title:`Input Dialog`,count:_.length,children:(0,Z.jsx)(VC,{title:i,params:_,variant:c})}),v&&(0,Z.jsx)(GC,{title:`Result Dialog`,icon:ct,children:(0,Z.jsx)(UC,{dialog:v})}),y?.source&&(0,Z.jsx)(GC,{title:`Script Body (${y.language??`expression`})`,icon:cr,children:(0,Z.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 zC({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,Z.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 ${IC(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Z.jsx)(BC,{name:t}),!r&&(0,Z.jsx)(`span`,{children:e})]})}function BC({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=Ei[t===`Home`?`House`:t];return n?(0,Z.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,Z.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 VC({title:e,params:t,variant:n}){return(0,Z.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Z.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,Z.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[PC(e.label)||n,e.required&&(0,Z.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,Z.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,Z.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),HC(e),e.helpText&&(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${IC(n||`primary`)}`,children:`OK`})]})]})}function HC(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,Z.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,Z.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,Z.jsx)(`option`,{value:e.value,children:PC(e.label)},t))]}):e.type===`boolean`?(0,Z.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,Z.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,Z.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 UC({dialog:e}){let t=PC(e.title)||`Result`,n=PC(e.description),r=PC(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,Z.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Z.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,Z.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,Z.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,Z.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,Z.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:PC(t.label)||t.path}),(0,Z.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,Z.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,Z.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,Z.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 WC({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,Z.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Z.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function GC({title:e,count:t,icon:n,children:r}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Z.jsx)(n,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e}),t!=null&&(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function KC({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var qC={"@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 JC(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 YC(e){let t=(qC[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=JC(n,0,59),c=JC(r,0,23),l=JC(i,1,31),u=JC(a,1,12),d=JC(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function XC(e,t,n){let r=YC(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 ZC(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 QC(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function $C(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function ew(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?tw(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`?tw(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function tw(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 nw({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}=ew(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?ZC(s):null,{nextFires:v,deltas:y}=X.useMemo(()=>{let e=new Date,t=[];if(o)t=XC(o,e,5);else if(_)t=QC(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>rw(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Z.jsx)(Cb,{hint:`job`,children:(0,Z.jsx)(wb,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Z.jsx)(Cb,{hint:`job`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(hr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(ow,{icon:Jt,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Z.jsx)(ow,{icon:Ui,label:l,mono:!0}),p!=null&&(0,Z.jsx)(ow,{icon:st,label:`retries: ${p}${m?` (${tw(m)} backoff)`:``}`}),h!=null&&(0,Z.jsx)(ow,{icon:rr,label:`timeout: ${tw(h)}`}),g!=null&&(0,Z.jsx)(ow,{label:`concurrency: ${g}`})]})]})]})}),(0,Z.jsx)(aw,{title:`Schedule`,icon:$e,children:(0,Z.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Z.jsx)(iw,{label:`Cron`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Z.jsxs)(iw,{label:`Every`,children:[(0,Z.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,Z.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,Z.jsx)(iw,{label:`At`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,Z.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,Z.jsx)(aw,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:Ht,children:v.length===0?(0,Z.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,Z.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,Z.jsx)(Ht,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:$C(e)}),(0,Z.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Z.jsx)(aw,{title:`Handler`,icon:cr,children:u?(0,Z.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,Z.jsx)(ma,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,Z.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function rw(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 iw({label:e,children:t}){return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,Z.jsx)(`span`,{className:`break-all`,children:t})]})}function aw({title:e,icon:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Z.jsx)(t,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e})]}),n]})}function ow({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var sw=[{key:`objects`,label:`Objects`,icon:Bi,flat:!1},{key:`apps`,label:`Apps`,icon:xr,flat:!1},{key:`messages`,label:`Messages`,icon:ro,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:sa,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:yr,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Dt,flat:!1},{key:`settings`,label:`Settings`,icon:jr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:oo,flat:!1}];function cw({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=sw.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/sw.length*100);return c===0?(0,Z.jsx)(Cb,{hint:`translation · ${r}`,children:(0,Z.jsx)(wb,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Z.jsx)(Cb,{hint:`translation · ${r} · ${c} keys`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(Mn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.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,Z.jsx)(Ui,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,Z.jsx)(Br,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,Z.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,Z.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,sw.length,` (`,u,`%)`]}),(0,Z.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,Z.jsx)(lw,{cat:e},e.key))})]})})})}function lw({cat:e}){let t=e.icon;return(0,Z.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,Z.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,Z.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,Z.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Z.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,Z.jsx)(`span`,{className:`truncate text-foreground/80`,children:uw(n,e.flat)})]},t)),e.count>e.sample.length&&(0,Z.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function uw(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function dw({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,Z.jsx)(Cb,{hint:`role`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(vn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,Z.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Da,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,Z.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,Z.jsx)(Fn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.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,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.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,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,Z.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Z.jsx)(Ca,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,Z.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,Z.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,Z.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,Z.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,Z.jsx)(Cb,{hint:`role`,children:(0,Z.jsx)(wb,{children:`Give the role a name to see the preview.`})})}function fw({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,Z.jsx)(Cb,{hint:`skill`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(_a,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(mw,{icon:Jt,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Z.jsx)(mw,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Z.jsx)(mw,{icon:Ca,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Z.jsx)(pw,{title:`Instructions`,icon:Tn,children:o?(0,Z.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,Z.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,Z.jsxs)(pw,{title:`Tools (${s.length})`,icon:Un,children:[s.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,Z.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,Z.jsx)(Je,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,Z.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,Z.jsx)(pw,{title:`Trigger Phrases (${c.length})`,icon:Si,children:(0,Z.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,Z.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,Z.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,Z.jsx)(pw,{title:`Trigger Conditions (${l.length})`,icon:Ba,children:(0,Z.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Z.jsx)(`table`,{className:`w-full text-xs`,children:(0,Z.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,Z.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,Z.jsx)(pw,{title:`Required Permissions`,icon:Ca,children:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,Z.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,Z.jsx)(Cb,{hint:`skill`,children:(0,Z.jsx)(wb,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function pw({title:e,icon:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Z.jsx)(t,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e})]}),n]})}function mw({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var hw=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},gw=E();function _w(){return``.replace(/\/+$/,``)}function vw(e){return`${_w()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function yw(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 hw}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 bw(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await yw(await gw(`${vw(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function xw(e,t,n={}){return(await yw(await gw(`${vw(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Sw(e){return(await yw(await gw(`${vw(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Cw(e){return yw(await gw(`${vw(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function ww(e){await yw(await gw(`${_w()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Tw({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=X.useState(`loading`),[s,c]=X.useState(null),[l,u]=X.useState(null);X.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await xw(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof hw?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=X.useCallback(async()=>{if(s){o(`importing`),u(null);try{await ww(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,Z.jsx)(mt,{open:n,onOpenChange:r,children:(0,Z.jsxs)(Ot,{className:`max-w-2xl`,children:[(0,Z.jsxs)(ko,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(kt,{className:`h-4 w-4`}),`Import as Object`]}),(0,Z.jsxs)(Yt,{children:[`Map remote table `,(0,Z.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,Z.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Z.jsx)(Hr,{className:`h-8 w-8 text-emerald-500`}),(0,Z.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,Z.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,Z.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,Z.jsx)(gt,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,Z.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,Z.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,Z.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,Z.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Z.jsx)(Ze,{className:`h-3 w-3`}),` Generated source`]}),(0,Z.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,Z.jsx)(Pn,{children:a===`done`?(0,Z.jsx)(K,{onClick:()=>r(!1),children:`Close`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(K,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Z.jsx)(K,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Ew({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),p=X.useCallback(async()=>{n(`loading`),o(null);try{i(await bw(e)),n(`loaded`)}catch(e){e instanceof hw?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);X.useEffect(()=>{p()},[p]);let m=X.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,Z.jsx)(Dw,{}):(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(Co,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Z.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,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,Z.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,Z.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,Z.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,Z.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,Z.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,Z.jsx)(br,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,Z.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Z.jsx)(St,{className:`h-3 w-3`}),e.columnCount]})}),(0,Z.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,Z.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Z.jsx)(nn,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Z.jsx)(Tw,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Dw(){return(0,Z.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,Z.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var Ow={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 kw({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useCallback(async()=>{n(`running`),c(null);try{let t=await Cw(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof hw?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,Z.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,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(ma,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,Z.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,Z.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,Z.jsx)(Hr,{className:`h-4 w-4`}):(0,Z.jsx)(sa,{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,Z.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,Z.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,Z.jsx)(Aw,{result:e},e.object))})]})}function Aw({result:e}){return(0,Z.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,Z.jsx)(Ca,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Z.jsx)(sa,{className:`h-3.5 w-3.5 text-destructive`}),(0,Z.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,Z.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,Z.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,Z.jsx)(jw,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function jw({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,Z.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,Z.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:Ow[e.kind]??e.kind}),t&&(0,Z.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,Z.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function Mw({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=X.useState(null),[a,o]=X.useState(!1),[s,c]=X.useState(null),l=X.useCallback(async()=>{if(e){o(!0),c(null);try{i(await Sw(e))}catch(e){c(e instanceof hw?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,Z.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Z.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,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,Z.jsx)(Xt,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Z.jsx)(Ht,{className:`h-3 w-3`}),`snapshot `,Nw(r.snapshotAt)]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,Z.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,Z.jsxs)(mi,{defaultValue:`tables`,className:`p-3`,children:[(0,Z.jsxs)(ha,{children:[(0,Z.jsx)(La,{value:`tables`,children:`Tables`}),(0,Z.jsx)(La,{value:`validation`,children:`Validation`})]}),(0,Z.jsx)(Ja,{value:`tables`,className:`mt-3`,children:(0,Z.jsx)(Ew,{datasource:e})}),(0,Z.jsx)(Ja,{value:`validation`,className:`mt-3`,children:(0,Z.jsx)(kw,{datasource:e})})]})]}):(0,Z.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 Nw(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Pw=/pass|secret|key|token|credential|auth/i;function Fw(e){return Pw.test(e)}function Iw(e){return e==null||e===``?`∅`:`••••••`}function Lw(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 Rw({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,Z.jsx)(Cb,{hint:`datasource`,children:(0,Z.jsx)(wb,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Z.jsx)(Cb,{hint:`datasource · ${o}`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(kt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,Z.jsx)(Cr,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Z.jsx)(Vw,{icon:Jt,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Z.jsx)(Vw,{icon:Fe,label:`default`,tone:`amber`}),m.length>0&&(0,Z.jsx)(Vw,{icon:Ke,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Z.jsx)(Mw,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Z.jsx)(Bw,{title:`Connection`,icon:ot,children:y.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,Z.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Z.jsx)(`table`,{className:`w-full text-xs`,children:(0,Z.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=Fw(e);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,Z.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{children:Iw(t)}),(0,Z.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`})]}):Lw(t)})]},e)})})})})}),(0,Z.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Z.jsx)(zw,{title:`Pool`,icon:Dr,value:u}),(0,Z.jsx)(zw,{title:`SSL`,icon:Ca,value:typeof d==`boolean`?{enabled:d}:d}),(0,Z.jsx)(zw,{title:`Retry Policy`,icon:st,value:f}),(0,Z.jsx)(zw,{title:`Health Check`,icon:Dr,value:p})]}),h.length>0&&(0,Z.jsx)(Bw,{title:`Capabilities`,icon:Ca,children:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,Z.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 zw({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,Z.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,Z.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,Z.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,Z.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Z.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,Z.jsx)(`dd`,{className:`font-mono truncate`,children:Fw(e)?Iw(t):Lw(t)})]},e))}):(0,Z.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function Bw({title:e,icon:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Z.jsx)(t,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e})]}),n]})}function Vw({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Hw(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Uw(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:ga};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:gt};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:Xn}}}function Ww({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=Uw(l);return r?(0,Z.jsx)(Cb,{hint:`validation · ${o}`,children:(0,Z.jsx)(Eb,{children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(sa,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Z.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Z.jsx)(Jw,{icon:Jt,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Z.jsx)(Jw,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Z.jsx)(Jw,{label:`priority ${f}`}),d.length>0&&(0,Z.jsx)(Jw,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,Z.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,Z.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,Z.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,Z.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,Z.jsx)(Gw,{type:o,d:n}),p.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,Z.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,Z.jsx)(Cb,{hint:`validation`,children:(0,Z.jsx)(wb,{children:`Give the validation a name to see the preview.`})})}function Gw({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Z.jsx)(qw,{title:`Condition`,icon:cr,children:(0,Z.jsx)(Kw,{value:Hw(t.condition)??Hw(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=Hw(t.scope)??Hw(t.where);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(qw,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:la,children:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,Z.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,Z.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,Z.jsx)(qw,{title:`Scope`,icon:Xa,children:(0,Z.jsx)(Kw,{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,Z.jsx)(qw,{title:`Transitions${r?` on ${r}`:``}`,icon:Qe,children:n.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,Z.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e}),(0,Z.jsx)(lr,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.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,Z.jsx)(qw,{title:`Format`,icon:Re,children:(0,Z.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,Z.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,Z.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,Z.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=Hw(t.condition);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(qw,{title:`Fields involved`,icon:Xa,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,Z.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,Z.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,Z.jsx)(qw,{title:`Cross-field condition`,icon:cr,children:(0,Z.jsx)(Kw,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Z.jsx)(qw,{title:`Async endpoint`,icon:Ui,children:(0,Z.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,Z.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,Z.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,Z.jsx)(qw,{title:`Custom handler`,icon:cr,children:(0,Z.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,Z.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,Z.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,Z.jsx)(qw,{title:`Rule`,icon:sa,children:(0,Z.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 Kw({value:e}){return e?(0,Z.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,Z.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function qw({title:e,icon:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Z.jsx)(t,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e})]}),n]})}function Jw({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Z.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Yw=X.lazy(()=>d(()=>import(`./plugin-charts-BjUzf65B.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function Xw(e){return e==null?`—`:typeof e==`number`?Number.isInteger(e)?String(e):e.toLocaleString(void 0,{maximumFractionDigits:2}):typeof e==`boolean`?e?`true`:`false`:String(e)}function Zw({draft:e}){let t=be(),n=e.object,r=X.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),i=X.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=!!n&&r.length>0,[o,s]=X.useState({status:`idle`,rows:[]}),c=X.useCallback(async()=>{if(a){s({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:i,measures:r});s({status:`ok`,rows:Array.isArray(n?.rows)?n.rows:[]})}catch(e){s({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,i,r,a]),l=`${n??``}|${i.join(`,`)}|${r.join(`,`)}`;if(X.useEffect(()=>{a&&c()},[l]),!n)return(0,Z.jsx)(Cb,{children:(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(yo,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(r.length===0)return(0,Z.jsx)(Cb,{children:(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(yo,{className:`h-8 w-8`}),title:`Add a measure`,description:`A dataset needs at least one measure (e.g. revenue = sum(amount)) to preview.`})});let u=[...i,...r];return(0,Z.jsx)(Cb,{hint:`dataset · ${n}${i.length?` · by `+i.join(`, `):``}`,children:(0,Z.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void c(),disabled:o.status===`loading`,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 disabled:opacity-50`,children:[o.status===`loading`?(0,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(yo,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,Z.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[r.length,` measure`,r.length===1?``:`s`,` · `,i.length,` dimension`,i.length===1?``:`s`]})]}),o.status===`error`&&(0,Z.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,Z.jsx)(gt,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`break-words`,children:o.error})]}),o.status===`ok`&&o.rows.length===0&&(0,Z.jsx)(Tb,{icon:(0,Z.jsx)(yo,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),o.rows.length>0&&i.length>=1&&(0,Z.jsx)(Eb,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`})}),children:(0,Z.jsx)(`div`,{className:`rounded-md border p-2`,children:(0,Z.jsx)(Yw,{schema:{data:o.rows,xAxisKey:i[0],series:r.map(e=>({dataKey:e,label:e,chartType:`bar`}))}})})})}),o.rows.length>0&&(0,Z.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Z.jsx)(`tr`,{children:u.map(e=>(0,Z.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:e},e))})}),(0,Z.jsx)(`tbody`,{children:o.rows.map((e,t)=>(0,Z.jsx)(`tr`,{className:`border-t`,children:u.map(t=>(0,Z.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:Xw(e[t])},t))},t))})]})})]})})}function Qw(){xy(`page`,ux),xy(`view`,hx),xy(`dashboard`,_x),xy(`report`,xx),xy(`app`,Px),xy(`action`,RC),xy(`object`,tS),xy(`datasource`,Rw),xy(`validation`,Ww),xy(`dataset`,Zw),xy(`email_template`,aS),xy(`translation`,cw),xy(`flow`,sC),xy(`job`,nw),xy(`agent`,lC),xy(`tool`,SC),xy(`skill`,fw),xy(`permission`,kC),xy(`profile`,kC),xy(`role`,dw)}function Q(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function $w(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var eT=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),tT={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:eT,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:[$w(`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`}),$w(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),$w(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),$w(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),$w(`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:[$w(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),$w(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),$w(`connectorConfig`,`input`,`Input`,`keyValue`,{help:`Mapped inputs for the connector action.`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],parallel:[],try_catch:[Q(`errorVariable`,`Error variable`,`text`,{placeholder:`$error`,help:`Variable the caught error is bound to inside the catch region.`})],parallel_gateway:[],join_gateway:[],boundary_event:[$w(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),$w(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),$w(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),$w(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),$w(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),$w(`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`})]},nT={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`};function rT(e){return e?tT[nT[e]??e]??[]:[]}function iT(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 aT(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function oT(e,t,n){if(!e.showWhen)return!0;let r=iT(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=iT(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 sT=[`start`,`create_record`,`update_record`,`delete_record`,`get_record`,`decision`,`assignment`,`loop`,`http_request`,`script`,`screen`,`approval`,`wait`,`subflow`,`connector_action`,`parallel`,`try_catch`,`end`],cT=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function lT(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`&&cT.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&cT.has(t.kind))return{kind:t.kind,...n}}function uT(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 dT(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function fT(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 pT(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:uT(e)}))}function mT(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 hT(e){if(Array.isArray(e.enum))return`select`;let t=fT(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function gT(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!dT(r))continue;let t=fT(r),i,a,o=lT(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=pT(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||uT(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function _T(e,t){return{label:e.title||uT(t),...e.description?{help:e.description}:{},...mT(e)?{defaultValue:mT(e)}:{}}}function vT(e){if(!dT(e)||fT(e)!==`object`||!dT(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!dT(r))continue;let e=fT(r);if(e===`array`){let e=dT(r.items)?r.items:void 0,i=e?fT(e):void 0;e&&i===`object`&&dT(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:gT(e),..._T(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,..._T(r,n)});continue}if(e===`object`&&dT(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>dT(e)),i=e.some(([e,t])=>e===`enabled`&&fT(t)===`boolean`);for(let[a,o]of e){let e=o,s=lT(e),c=s?`reference`:hT(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||uT(n),...r.description?{help:r.description}:{},...mT(e)?{defaultValue:mT(e)}:{}}:_T(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:pT(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=lT(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,..._T(r,n)});continue}let a=hT(r);a&&t.push({id:n,path:[`config`,n],kind:a,..._T(r,n),...a===`select`&&Array.isArray(r.enum)?{options:pT(r.enum)}:{}})}return t}function yT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function bT(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function xT(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 ST(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=zs(`kv`,n);return n.push(r),{id:r,key:e,raw:bT(t)}})}function CT(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=xT(n.raw))}return t}function wT(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function TT({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=yT(t)?t:{},[d,f]=X.useState(()=>ST(u,[])),p=X.useRef(wT(u));X.useEffect(()=>{let e=wT(u);e!==p.current&&(f(ST(u,[])),p.current=e)},[u]);let m=e=>{let t=CT(e);p.current=wT(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:zs(`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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[d.length===0&&(0,Z.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),d.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.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,Z.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,Z.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,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:r,children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function ET(e,t){let n=[...t];return e.map(e=>{let t=zs(`sl`,n);return n.push(t),{id:t,value:e}})}function DT(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function OT({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=X.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=X.useState(()=>ET(c,[])),d=X.useRef(JSON.stringify(c));X.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(ET(c,[])),d.current=e)},[c]);let f=e=>{let t=DT(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:zs(`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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,Z.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.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,Z.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,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var kT={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function AT(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 jT(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 MT(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?jT((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):jT(n.node,r)}function NT(e){let t=ks(),[n,r]=X.useState({options:[],loading:!!e});return X.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 PT({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=X.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?MT(e.kind,e.objectSource,l):void 0,{fields:f}=sd(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?kT[u]:void 0,{options:m}=NT(p),h=X.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,Z.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,Z.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,Z.jsx)(`datalist`,{id:c,children:h.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,Z.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&g&&(0,Z.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 FT({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=AT(e.ref,e=>jT(a,e));return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Z.jsx)(PT,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function IT(e,t){let n=[];return e.map(e=>{let r=zs(`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 LT(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 RT({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,context:c}){let l=X.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[u,d]=X.useState(()=>IT(l,t)),f=X.useRef(JSON.stringify(l));X.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(IT(l,t)),f.current=e)},[l,t]);let p=e=>{let n=LT(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:zs(`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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[u.length===0&&(0,Z.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),u.map(e=>(0,Z.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,Z.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,Z.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,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(G,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Z.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,Z.jsx)(`div`,{className:`flex-1`,children:(0,Z.jsx)(PT,{resolved:AT(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,Z.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,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:h,disabled:i,children:[(0,Z.jsx)(Oo,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var zT=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function BT(e,t,n){let r=0;for(let i of e)if(i===t)r++;else if(i===n&&(r--,r<0))return!1;return r===0}function VT(e,t){let n=``,r;if(typeof t==`string`)n=t;else if(t&&typeof t==`object`){let e=t;r=e.dialect,n=e.source??``}if(!n.trim())return null;if(e===`template`){if(r&&r!==`template`)return{message:`Expected a text template but got a \`${r}\` expression.`};BT(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=zT.exec(n);return e?{message:`Single-brace \`{${e[1]}}\` is not a valid template hole — use double braces: \`{{ ${e[1]} }}\`.`}:null}if(r&&r!==`cel`)return{message:`Expected a CEL expression but got a \`${r}\` dialect.`};let i=zT.exec(n);return i?{message:`It looks like a \`{${i[1]}}\` template brace was used inside a condition — \`{…}\` parses as a CEL map literal and fails. Write the bare reference instead, e.g. \`${i[1]}\`. Conditions are bare CEL (e.g. \`record.rating >= 4\`).`}:BT(n,`(`,`)`)?BT(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function HT({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){let o=(()=>{switch(e.kind){case`reference`:return(0,Z.jsx)(FT,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Z.jsx)(TT,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.kv.add`,i),keyLabel:J(`engine.inspector.flowNode.kv.key`,i),valueLabel:J(`engine.inspector.flowNode.kv.value`,i),removeLabel:J(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:J(`engine.inspector.flowNode.kv.empty`,i)});case`stringList`:return(0,Z.jsx)(OT,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),itemLabel:J(`engine.inspector.flowNode.list.item`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Z.jsx)(RT,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i),context:a});case`number`:return(0,Z.jsx)(Os,{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,Z.jsx)(Ns,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Z.jsx)(Rs,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Z.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,Z.jsx)(ws,{label:e.label,value:t==null?``:String(t),placeholder:e.placeholder,onCommit:e=>n(e),disabled:r,mono:e.kind===`expression`})}})(),s=e.kind===`expression`?VT(`predicate`,t):null;return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[o,s&&(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:s.message}),e.help&&!s&&(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}function UT(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function WT(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=WT(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function GT({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=jS(),u=X.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:vT(e))??rT(c?.type)},[l,c?.type]),d=UT(c),f=u.filter(e=>oT(e,c,u)),p=X.useMemo(()=>{let e=new Set;for(let t of u){let n=aT(t);n&&e.add(n)}return e},[u]),m=X.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]=X.useState(m),[_,v]=X.useState(null),[y,b]=X.useState(m.trim()!==``),[x,S]=X.useState(!1);if(X.useEffect(()=>{g(m),v(null),b(m.trim()!==``),S(!1)},[m]),!c)return(0,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),children:(0,Z.jsx)(As,{message:e.id})});let C=e=>{n({nodes:bs(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:bs(o,s,WT(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:bs(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:bs(o,s,null)}),r()},O=sT.includes(c.type)?[...sT]:[...sT,c.type??``].filter(Boolean);return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,Z.jsx)(ws,{label:J(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,Z.jsx)(Rs,{label:J(`engine.inspector.flowNode.type`,i),value:c.type,options:O.map(e=>({value:e,label:e})),onCommit:e=>C({type:e}),disabled:a}),(0,Z.jsx)(ws,{label:J(`engine.inspector.flowNode.description`,i),value:c.description??``,onCommit:e=>C({description:e||void 0}),disabled:a}),u.length===0?(0,Z.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:J(`engine.inspector.flowNode.noConfig`,i)}):f.length>0&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.flowNode.configuration`,i)}),(0,Z.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),f.map(e=>(0,Z.jsx)(HT,{field:e,value:iT(c,e),onCommit:t=>T(e.path,t),disabled:a,locale:i,context:{draft:t,node:c}},e.id)),w||x?(0,Z.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:y,onToggle:e=>b(e.target.open),children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:J(`engine.inspector.flowNode.advanced`,i)}),(0,Z.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:J(`engine.inspector.flowNode.advancedHint`,i)}),(0,Z.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,Z.jsx)(`div`,{className:`text-xs text-destructive`,children:_})]})]}):!a&&(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),J(`engine.inspector.flowNode.advanced`,i)]})]})}function KT({label:e,value:t}){return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.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 qT({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)=>mS(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),children:(0,Z.jsx)(As,{message:J(`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:bs(o,s,t)})},u=c.isDefault===!0;return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:bs(o,s,null)}),r()},disabled:a}),children:[(0,Z.jsx)(KT,{label:J(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Z.jsx)(KT,{label:J(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.flowEdge.routing`,i)}),(0,Z.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Z.jsx)(ws,{label:J(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>l({label:e}),placeholder:J(`engine.inspector.flowEdge.labelHint`,i),disabled:a||u}),(0,Z.jsx)(ws,{label:J(`engine.inspector.flowEdge.condition`,i),value:hS(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:J(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(()=>{let e=u?null:VT(`predicate`,c.condition);return e?(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message}):null})(),(0,Z.jsx)(Ns,{label:J(`engine.inspector.flowEdge.isDefault`,i),value:u,onCommit:e=>l(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,Z.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:J(`engine.inspector.flowEdge.hint`,i)})]})}function JT(e){return e.selection.kind===`edge`?(0,Z.jsx)(qT,{...e}):(0,Z.jsx)(GT,{...e})}var YT=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function XT(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 ZT(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 QT(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:bs(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=bs(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function $T(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 eE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=XT(e.id),{node:c,parent:l,index:u}=s?ZT(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.appNav.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.appNav.close`,a),children:(0,Z.jsx)(As,{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(QT(t,s,{...c,...e}))};return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:J(`engine.inspector.appNav.close`,a),headerActions:(0,Z.jsx)(Ss,{index:u,total:l.length,onMove:e=>{n($T(t,s,xs(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:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.appNav.remove`,a),onClick:()=>{n(QT(t,s,null)),r()},disabled:o}),children:[(0,Z.jsx)(ws,{label:J(`engine.inspector.appNav.label`,a),value:String(c.label??c.title??c.name??``),onCommit:e=>p({label:e}),disabled:o}),(0,Z.jsx)(ws,{label:J(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Z.jsx)(Rs,{label:J(`engine.inspector.appNav.kindField`,a),value:c.kind,options:YT.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var tE=[`field`,`label`,`accessorKey`,`header`];function nE(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function rE(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function iE(e){return e.field??e.accessorKey??``}function aE(e){return e.label??e.header??iE(e)}function oE(e){return Object.keys(e).some(e=>!tE.includes(e))}function sE(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function cE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=nE(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(rE),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=X.useMemo(()=>Rd(),[]),m=sE(c),{fields:h}=sd(m||void 0),g=d?iE(d):``,_=X.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,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),children:(0,Z.jsx)(As,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=iE(e);return n&&!oE(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(bs(u,s.index,{...d,...r}))};return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:aE(d)||e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),headerActions:(0,Z.jsx)(Ss,{index:s.index,total:u.length,onMove:e=>{v(xs(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:aE(d)||`columns[${e}]`})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(bs(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Z.jsx)(`div`,{className:`pb-1`,children:(0,Z.jsx)(Od,{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,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,Z.jsx)(Rs,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:iE(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Z.jsx)(ws,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:iE(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.viewColumn.header`,a),value:aE(d)===iE(d)?``:aE(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:(0,Z.jsx)(Ms,{schema:p,value:d,hiddenFields:tE,readOnly:o,onChange:e=>{v(bs(u,s.index,e))}})}):null]})]})}function lE(e){let{selection:t}=e;if(t.kind===`column`)return(0,Z.jsx)(cE,{...e});let n=qd(e.draft,t.id||void 0)??Kd(e.draft);return(0,Z.jsx)(ef,{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 uE(e){let t=Kd(e.draft);return(0,Z.jsx)(ef,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var dE=`__none__`,fE=[{value:dE,label:`(none)`},{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`}];function pE(e){let t=/^columns\[(\d+)\]$/.exec(e);return t?Number(t[1]):null}function mE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=pE(e.id),c=Array.isArray(t.columns)?t.columns:[],l=s==null?null:c[s]??null;if(s==null||!l)return(0,Z.jsx)(Vs,{kindLabel:J(`engine.inspector.reportColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.reportColumn.close`,a),children:(0,Z.jsx)(As,{message:e.id})});let u=e=>n({columns:bs(c,s,{...l,...e})});return(0,Z.jsxs)(Vs,{kindLabel:J(`engine.inspector.reportColumn.kind`,a),title:l.label||l.field||e.id,onClose:r,closeLabel:J(`engine.inspector.reportColumn.close`,a),headerActions:(0,Z.jsx)(Ss,{index:s,total:c.length,onMove:e=>{n({columns:xs(c,s,e)}),i?.({kind:`column`,id:`columns[${e}]`,label:l.label||l.field||`columns[${e}]`})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Z.jsx)(Ds,{label:J(`engine.inspector.reportColumn.remove`,a),onClick:()=>{n({columns:bs(c,s,null)}),r()},disabled:o}),children:[(0,Z.jsx)(ws,{label:J(`engine.inspector.reportColumn.field`,a),value:l.field??``,onCommit:e=>u({field:e}),disabled:o,mono:!0}),(0,Z.jsx)(ws,{label:J(`engine.inspector.reportColumn.label`,a),value:l.label??``,onCommit:e=>u({label:e}),disabled:o}),(0,Z.jsx)(Rs,{label:J(`engine.inspector.reportColumn.aggregate`,a),value:l.aggregate??dE,options:fE,onCommit:e=>u({aggregate:e===dE?void 0:e}),disabled:o})]})}var hE=e=>(e??``).toLowerCase().startsWith(`zh`);function gE(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 _E(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function vE(e){return e===`lookup`||e===`master_detail`||e===`tree`}function yE(e){return e===`formula`||e===`summary`}function bE(e){return e===`number`||e===`currency`||e===`percent`}function xE(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function SE(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}function CE(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?md:dd;return hd.flatMap(e=>e.types.map(r=>{let i=ld[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function wE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=X.useCallback(e=>J(e,o),[o]),c=X.useMemo(()=>CE(o),[o]),l=X.useMemo(()=>Uu(t.fields),[t]),u=String(e.id),d=Gu(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=AE();if(!f)return(0,Z.jsx)(Vs,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Z.jsx)(As,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=ld[g],v=e=>{n({fields:Wu(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=Ju(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},v({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(h.label??t)})},x=()=>{let e=l.entries.filter((e,t)=>t!==d);v({shape:l.shape,entries:e}),r()},S=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof h.label==`string`&&h.label?h.label:``,o={name:n,def:{...h,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),v({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},C=e=>{v({shape:l.shape,entries:xs(l.entries,d,e)})},w=gE(h),T=e=>{y({options:e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t})})},E=(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:S,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,Z.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(Ss,{index:d,total:l.entries.length,onMove:C,disabled:a})]}),D=(0,Z.jsx)(Ds,{label:Y(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:x,disabled:a}),O=hE(o)?_?.labelZh:_?.label;return(0,Z.jsxs)(Vs,{kindLabel:s(`designer.field.kind`),title:typeof h.label==`string`&&h.label?h.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:E,footer:D,children:[(0,Z.jsxs)(TE,{title:s(`designer.field.section.basic`),children:[(0,Z.jsx)(ws,{label:s(`designer.field.apiName`),value:f.name,onCommit:b,disabled:a,mono:!0}),(0,Z.jsx)(ws,{label:s(`designer.field.label`),value:typeof h.label==`string`?h.label:``,onCommit:e=>y({label:e}),disabled:a}),(0,Z.jsx)(Rs,{label:s(`designer.field.type`),value:g,options:c,onCommit:e=>y({type:e}),disabled:a}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Z.jsx)(Ns,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,Z.jsx)(Ns,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,Z.jsx)(DE,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),SE(g)&&(0,Z.jsx)(EE,{kind:SE(g),value:h.defaultValue,options:w,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,Z.jsx)(DE,{label:s(`designer.field.helpText`),value:typeof h.inlineHelpText==`string`?h.inlineHelpText:``,onCommit:e=>y({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(_E(g)||vE(g)||yE(g)||bE(g)||xE(g))&&(0,Z.jsxs)(TE,{title:Y(`designer.field.section.options`,o,{type:O??g}),children:[_E(g)&&(0,Z.jsx)(kE,{options:w,onChange:T,disabled:a,locale:o}),vE(g)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(OE,{label:s(`designer.field.relatedObject`),value:typeof h.reference==`string`?h.reference:``,options:m,onCommit:e=>y({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,Z.jsx)(ws,{label:s(`designer.field.relationshipName`),value:typeof h.relationshipName==`string`?h.relationshipName:``,onCommit:e=>y({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)})]}),yE(g)&&(0,Z.jsx)(DE,{label:s(`designer.field.formula`),value:typeof h.formula==`string`?h.formula:``,onCommit:e=>y({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),bE(g)&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Os,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,Z.jsx)(Os,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,Z.jsx)(Os,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,Z.jsx)(Os,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),xE(g)&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Os,{label:s(`designer.field.minLength`),value:typeof h.minLength==`number`?h.minLength:void 0,onCommit:e=>y({minLength:e}),disabled:a,placeholder:`0`}),(0,Z.jsx)(Os,{label:s(`designer.field.maxLength`),value:typeof h.maxLength==`number`?h.maxLength:void 0,onCommit:e=>y({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,Z.jsxs)(TE,{title:s(`designer.field.section.advanced`),children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Ns,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,Z.jsx)(Ns,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,Z.jsx)(Ns,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,Z.jsx)(Ns,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,Z.jsx)(Ns,{label:s(`designer.field.trackHistory`),value:!!h.trackHistory,onCommit:e=>y({trackHistory:e||void 0}),disabled:a})]}),(0,Z.jsx)(ws,{label:s(`designer.field.placeholder`),value:typeof h.placeholder==`string`?h.placeholder:``,onCommit:e=>y({placeholder:e||void 0}),disabled:a}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(ws,{label:s(`designer.field.conditionalRequired`),value:typeof h.conditionalRequired==`string`?h.conditionalRequired:``,onCommit:e=>y({conditionalRequired:e||void 0}),disabled:a,mono:!0,placeholder:`record.status == 'closed'`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRequiredHint`)})]}),p.length>0&&(0,Z.jsx)(Rs,{label:s(`designer.field.group`),value:typeof h.group==`string`?h.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>y({group:e||void 0}),disabled:a})]})]})}function TE({title:e,children:t}){return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:t})]})}function EE({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=J(`designer.field.defaultValue`,a),s=J(`designer.field.defaultNone`,a);return e===`bool`?(0,Z.jsx)(Rs,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:J(`designer.field.true`,a)},{value:`false`,label:J(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Z.jsx)(Os,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Z.jsx)(Rs,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,Z.jsx)(ws,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function DE({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.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 OE({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=X.useId();return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.jsx)(W,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,Z.jsx)(`datalist`,{id:o,children:n.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function kE({options:e,onChange:t,disabled:n,locale:r}){let i=(n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},a=n=>t(e.filter((e,t)=>t!==n)),o=(n,r)=>t(xs(e,n,r));return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:J(`designer.field.picklistValues`,r)}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:e.length})]}),e.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:J(`designer.field.noValues`,r)}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:e.map((t,s)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(W,{value:t.value,onChange:e=>i(s,{value:e.target.value}),placeholder:J(`designer.field.optValue`,r),disabled:n,className:`h-7 text-xs font-mono flex-1`}),(0,Z.jsx)(W,{value:t.label??``,onChange:e=>i(s,{label:e.target.value}),placeholder:J(`designer.field.optLabel`,r),disabled:n,className:`h-7 text-xs flex-1`}),(0,Z.jsx)(`input`,{type:`color`,value:t.color??`#cccccc`,onChange:e=>i(s,{color:e.target.value}),disabled:n,className:`h-7 w-7 rounded border bg-background cursor-pointer p-0.5`,title:J(`designer.field.optColor`,r)}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o(s,s-1),disabled:n||s===0,"aria-label":J(`designer.field.moveUp`,r),children:(0,Z.jsx)(ir,{className:`h-3 w-3`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>o(s,s+1),disabled:n||s===e.length-1,"aria-label":J(`designer.field.moveDown`,r),children:(0,Z.jsx)(ja,{className:`h-3 w-3`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0 text-destructive`,onClick:()=>a(s),disabled:n,"aria-label":J(`designer.field.removeValue`,r),children:(0,Z.jsx)(vo,{className:`h-3 w-3`})})]},s))}),!n&&(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>t([...e,{value:``,label:``}]),children:[(0,Z.jsx)(Oo,{className:`h-3 w-3`}),J(`designer.field.addValue`,r)]})]})}function AE(){let e=ks(),[t,n]=X.useState([]);return X.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 jE({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=X.useCallback(e=>J(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=X.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=Ju(e)),n(t)},u=e=>{c.current=!0,n({name:Ju(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Z.jsx)(Vs,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,Z.jsxs)(ME,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Z.jsx)(NE,{hint:a(`designer.object.nameHint`),children:(0,Z.jsx)(ws,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Z.jsx)(ws,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Z.jsx)(ws,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,Z.jsx)(NE,{hint:a(`designer.object.iconHint`),children:(0,Z.jsx)(ws,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,Z.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]})})}function ME({title:e,hint:t,children:n}){return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,Z.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:n})]})}function NE({hint:e,children:t}){return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var PE=[{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`},{value:`count_distinct`,label:`count distinct`}],FE=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}];function IE({title:e,count:t,onAdd:n,addLabel:r}){return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(G,{className:`text-xs text-muted-foreground`,children:e}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,Z.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,Z.jsx)(Oo,{className:`h-3 w-3`}),` `,r]})]})}function LE({draft:e,onPatch:t,readOnly:n}){let r=typeof e.label==`string`?e.label:``,i=typeof e.description==`string`?e.description:``,a=typeof e.object==`string`?e.object:``,o=Array.isArray(e.include)?e.include:[],s=Array.isArray(e.dimensions)?e.dimensions:[],c=Array.isArray(e.measures)?e.measures:[],l=(e,n)=>t({dimensions:s.map((t,r)=>r===e?{...t,...n}:t)}),u=(e,n)=>t({measures:c.map((t,r)=>r===e?{...t,...n}:t)});return(0,Z.jsxs)(Vs,{kindLabel:`Dataset`,title:String(r||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[(0,Z.jsx)(ws,{label:`Label`,value:r,onCommit:e=>t({label:e}),disabled:n}),(0,Z.jsx)(ws,{label:`Description`,value:i,onCommit:e=>t({description:e}),disabled:n}),(0,Z.jsx)(ws,{label:`Base object`,value:a,onCommit:e=>t({object:e}),placeholder:`e.g. opportunity`,disabled:n,mono:!0}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Z.jsx)(IE,{title:`Included relationships`,count:o.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:Bs(o,``)})}),o.length===0?(0,Z.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:[`No joins. Add a relationship name (e.g. `,(0,Z.jsx)(`code`,{children:`account`}),`) to use `,(0,Z.jsx)(`code`,{children:`account.field`}),` dimensions/measures.`]}):o.map((e,r)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(W,{value:e,onChange:e=>t({include:o.map((t,n)=>n===r?e.target.value:t)}),placeholder:`relationship name (lookup field)`,disabled:n,className:`h-8 text-sm font-mono`}),!n&&(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:bs(o,r,null)}),"aria-label":`Remove relationship`,children:(0,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]},r))]}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Z.jsx)(IE,{title:`Dimensions`,count:s.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:Bs(s,{name:``,field:``,type:`string`})})}),s.map((e,r)=>(0,Z.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,Z.jsx)(Ds,{label:`Remove`,onClick:()=>t({dimensions:bs(s,r,null)})})]}),(0,Z.jsx)(ws,{label:`Name`,value:e.name??``,onCommit:e=>l(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,Z.jsx)(ws,{label:`Field`,value:e.field??``,onCommit:e=>l(r,{field:e}),placeholder:`field or relationship.field`,disabled:n,mono:!0}),(0,Z.jsx)(Rs,{label:`Type`,value:e.type,options:FE,onCommit:e=>l(r,{type:e}),disabled:n})]},r))]}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Z.jsx)(IE,{title:`Measures`,count:c.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:Bs(c,{name:``,aggregate:`sum`,field:``,certified:!1})})}),c.map((e,r)=>(0,Z.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,Z.jsx)(Ds,{label:`Remove`,onClick:()=>t({measures:bs(c,r,null)})})]}),(0,Z.jsx)(ws,{label:`Name`,value:e.name??``,onCommit:e=>u(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,Z.jsx)(Rs,{label:`Aggregate`,value:e.aggregate,options:PE,onCommit:e=>u(r,{aggregate:e}),disabled:n}),(0,Z.jsx)(ws,{label:`Field`,value:e.field??``,onCommit:e=>u(r,{field:e}),placeholder:`field (optional for count)`,disabled:n,mono:!0}),(0,Z.jsx)(Ns,{label:`Certified`,value:!!e.certified,onCommit:e=>u(r,{certified:e}),disabled:n})]},r))]})]})}function RE(){wy(`dashboard`,dm),Dy(`dashboard`,om),wy(`flow`,JT),wy(`app`,eE),wy(`view`,lE),Dy(`view`,uE),wy(`page`,Xb),wy(`report`,mE),Dy(`report`,Pm),wy(`object`,wE),Dy(`object`,jE),Dy(`dataset`,LE)}var zE=t({MetadataDiagnosticsPage:()=>pb,MetadataDirectoryPage:()=>X_,MetadataResourceEditPage:()=>sb,MetadataResourceHistoryPage:()=>py,MetadataResourceListPage:()=>Nv,StudioHomePage:()=>_v});vb(),Sb(),Qw(),RE();function BE(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function VE(e){return!BE(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function HE(e){if(!BE(e))return;let t=e.config;if(BE(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`}W_({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:X_}),W_({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:db}),W_({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:cv}),Ov({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`}]}),Ov({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`}]}),Ov({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:hb,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`}]}),Ov({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)=>HE(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!VE(e)}),Ov({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`}]}),Ov({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 UE={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},WE=()=>{let{modalHandler:e,modalElement:t}=Tp();return(0,Z.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Action modal transport`}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`One `,(0,Z.jsx)(`code`,{children:`onModal`}),` handler, four placements, arbitrary SchemaNode content.`]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(K,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:UE}),children:`Center`}),(0,Z.jsx)(K,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:UE}),children:`Side drawer`}),(0,Z.jsx)(K,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:UE}),children:`Bottom sheet`}),(0,Z.jsx)(K,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:UE}),children:`Fullscreen`})]}),t]})},GE=()=>{let[e,t]=X.useState([{},{}]);return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4 p-6`,children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Line-item grid with a lookup cell`}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The `,(0,Z.jsx)(`code`,{children:`Account`}),` column is a real lookup picker bound to live `,(0,Z.jsx)(`code`,{children:`showcase_account`}),`.`]}),(0,Z.jsx)(ki,{value:e,onChange:t,field:{columns:[{field:`account`,label:`Account`,type:`lookup`,reference:`showcase_account`,displayField:`name`},{field:`note`,label:`Note`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}],total_field:`amount`}}),(0,Z.jsx)(`pre`,{className:`rounded bg-muted p-3 text-xs`,"data-testid":`rows-json`,children:JSON.stringify(e)})]})},KE=(0,X.lazy)(()=>d(()=>import(`./SystemHubPage-D-J4FeqY.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),qE=(0,X.lazy)(()=>d(()=>import(`./AppManagementPage-DPljSpdo.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),JE=(0,X.lazy)(()=>d(()=>import(`./ProfilePage-D7kxyCKj.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),YE=(0,X.lazy)(()=>d(()=>import(`./ApprovalsInboxPage-Be6DrS7X.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),XE=(0,X.lazy)(()=>d(()=>import(`./AiPendingActionsPage-B9iWZUDQ.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),ZE=(0,X.lazy)(()=>d(()=>import(`./AuditLogPage-DWQl9my4.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),QE=(0,X.lazy)(()=>d(()=>import(`./SettingsHub-DerOpof3.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),$E=(0,X.lazy)(()=>d(()=>import(`./SettingsView-BNq6smI8.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),eD=(0,X.lazy)(()=>d(()=>import(`./DeveloperHubPage-D7pt27Ji.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),tD=(0,X.lazy)(()=>d(()=>import(`./ApiConsolePage-DJYUA73f.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),nD=(0,X.lazy)(()=>d(()=>import(`./FlowRunsPage-sdTkbx5s.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),rD=(0,X.lazy)(()=>d(()=>import(`./PublicFormsPage-DbMqDQiv.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),iD=(0,X.lazy)(()=>d(()=>import(`./IntegrationsPage-CHg7ApBe.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url));function aD(){let{objectName:e}=s(),t=u().pathname.replace(/\/objects(\/.*)?$/,``);return(0,Z.jsx)(i,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function oD(){let{metadataType:e,itemName:t}=s(),n=u().pathname.replace(/\/metadata(\/.*)?$/,``),r=`${n}/component/metadata/resource`;return(0,Z.jsx)(i,{to:e?t?`${r}/${t}?type=${e}`:`${r}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var sD=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(g,{path:`system`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(KE,{})})}),(0,Z.jsx)(g,{path:`system/apps`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(qE,{})})}),(0,Z.jsx)(g,{path:`system/profile`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(JE,{})})}),(0,Z.jsx)(g,{path:`system/approvals`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(YE,{})})}),(0,Z.jsx)(g,{path:`system/ai-approvals`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(XE,{})})}),(0,Z.jsx)(g,{path:`system/audit-log`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(ZE,{})})}),(0,Z.jsx)(g,{path:`system/settings`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(QE,{})})}),(0,Z.jsx)(g,{path:`system/settings/:namespace`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)($E,{})})}),(0,Z.jsx)(g,{path:`developer`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(eD,{})})}),(0,Z.jsx)(g,{path:`developer/api-console`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(tD,{})})}),(0,Z.jsx)(g,{path:`developer/flow-runs`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(nD,{})})}),(0,Z.jsx)(g,{path:`developer/public-forms`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(rD,{})})}),(0,Z.jsx)(g,{path:`developer/integrations`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(iD,{})})}),(0,Z.jsx)(g,{path:`system/objects`,element:(0,Z.jsx)(aD,{})}),(0,Z.jsx)(g,{path:`system/objects/:objectName`,element:(0,Z.jsx)(aD,{})}),(0,Z.jsx)(g,{path:`system/metadata`,element:(0,Z.jsx)(oD,{})}),(0,Z.jsx)(g,{path:`system/metadata/:metadataType`,element:(0,Z.jsx)(oD,{})}),(0,Z.jsx)(g,{path:`system/metadata/:metadataType/:itemName`,element:(0,Z.jsx)(oD,{})})]});function cD(){let e=(0,X.useMemo)(()=>kr({baseUrl:``}),[``]);return(0,Z.jsx)(A,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Z.jsx)(Au,{}),children:(0,Z.jsx)(xi,{adapter:e,children:(0,Z.jsx)(Zh,{extraRoutes:sD,extraRoutesNoApp:sD})})})}var lD=[`cloud_control`];function uD(){let{apps:e,loading:t}=ce();if(t)return(0,Z.jsx)(Vc,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of lD)if(n.has(e))return(0,Z.jsx)(i,{to:`/apps/${e}`,replace:!0});return(0,Z.jsx)(i,{to:`/home`,replace:!0})}var dD=`/api/v1`;function fD(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function pD(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 mD(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=fD(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:pD(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function hD(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 gD(e,t){return fetch(`${dD}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function _D(e){let t=await gD(`/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 vD(e){let t=await gD(`/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 gD(`/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 yD(e,t){let n=await gD(`/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 bD(e,t){let n=await gD(`/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 xD=`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 SD({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:xD},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,Z.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,Z.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,Z.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,Z.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,Z.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,Z.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,Z.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,Z.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,Z.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,Z.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,Z.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,Z.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,Z.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Z.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,Z.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,Z.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function CD({mode:e}){let t=s(),[n]=m(),r=(e===`public`?t.slug:t.name)??``,[i,a]=(0,X.useState)(!0),[o,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)({}),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let t=!1;return a(!0),c(null),(e===`public`?_D(r):vD(r)).then(e=>{t||(u(e),f(hD(mD(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||c(e?.message??String(e))}).finally(()=>{t||a(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,X.useMemo)(()=>l?mD(l.form,l.objectSchema):[],[l]),y=l?.form?.submitBehavior??{kind:`thank-you`};return i?(0,Z.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):o&&!l?(0,Z.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:o})}):l?g&&y.kind===`thank-you`?(0,Z.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Z.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,Z.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,Z.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,Z.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,Z.jsxs)(`header`,{className:`mb-6`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold`,children:l.label}),l.form?.label&&l.form.label!==l.label&&(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:l.form.label})]}),(0,Z.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),l){h(!0),c(null);try{switch(e===`public`?await yD(r,d):await bD(l.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`:f(hD(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);c(t),q.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,Z.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,Z.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,Z.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,Z.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,Z.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,Z.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,Z.jsx)(SD,{field:e,value:d[e.name],onChange:t=>f(n=>({...n,[e.name]:t}))}),e.helpText&&(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),o&&(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:o}),(0,Z.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,Z.jsx)(`button`,{type:`submit`,disabled:p,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:p?`Submitting…`:`Submit`})})]})]}):null}function wD({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,X.useRef)(null);return(0,X.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 TD(){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 ED(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
|
+
|
|
32
|
+
`):``}function DD(){let{token:e}=s(),t=`${(0,X.useMemo)(()=>TD(),[])}/api/v1`,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,c]=(0,X.useState)(!0),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(null),h=(0,X.useCallback)(async n=>{if(e){c(!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){u(!0),a(n?`Wrong password.`:null),c(!1);return}if(o.status===404){a(`This link is invalid or no longer available.`),c(!1);return}if(o.status===410){a(`This link has expired or was revoked.`),c(!1);return}if(!o.ok){a((await o.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${o.status}).`),c(!1);return}let s=await o.json();r(`data`in s?s.data:{record:s.record,link:s.link,redactedFields:s.redactFields}),u(!1)}catch(e){a(e?.message??`Failed to load shared content.`)}finally{c(!1)}}},[t,e]);if((0,X.useEffect)(()=>{h()},[h]),(0,X.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,Z.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,Z.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,Z.jsx)($t,{className:`h-8 w-8 text-muted-foreground`}),(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,Z.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,Z.jsx)(G,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Z.jsx)(W,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Z.jsx)(K,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,Z.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,Z.jsx)(gt,{className:`h-8 w-8 text-amber-500`}),(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,Z.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,Z.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Z.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,Z.jsx)(Ar,{className:`h-5 w-5 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,Z.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,Z.jsx)(H,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,Z.jsx)(V,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,Z.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,Z.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=ED(e);if(!t)return null;let n=e.role===`user`;return(0,Z.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,Z.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,Z.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,Z.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,Z.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,Z.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Z.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,Z.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,Z.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,Z.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}function OD(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function kD(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function AD(){return typeof window>`u`?null:window.location.host||null}function jD(){let e=es();return(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,Z.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,Z.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,Z.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,Z.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,Z.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,Z.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function MD({children:e,formWidth:t=`sm`}){let{t:n}=z(),r=t===`md`?`max-w-md`:`max-w-sm`,i=AD(),a=!!i&&!OD(i)&&!kD(i);return(0,X.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,Z.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,Z.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,Z.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,Z.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,Z.jsxs)(`div`,{className:U(`flex w-full flex-col gap-5`,r),children:[(0,Z.jsx)(jD,{}),a?(0,Z.jsx)(`div`,{className:`flex justify-center`,children:(0,Z.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 ND(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function PD(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function FD(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function ID(){let{t:e}=z(),[t]=m(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:s,switchOrganization:c,getAuthConfig:l}=S(),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1);(0,X.useLayoutEffect)(()=>{i||g(!0)},[i]);let _=(0,X.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,X.useEffect)(()=>{let e=!1;return l().then(t=>{e||d(t?.emailPassword?.disableSignUp===!0)}).catch(()=>{}),()=>{e=!0}},[l]),(0,X.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||f)return;if(a.length===1){p(!0),c(a[0].id).catch(()=>void 0).finally(()=>p(!1));return}if(a.length===0){window.location.assign(PD(ND(n)?n:`/`));return}window.location.assign(PD(`/organizations`));return}f||window.location.assign(PD(ND(n)?n:`/`))}},[r,s,a,o,f,n,c]),i&&!h||r)return(0,Z.jsx)(MD,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,Z.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,Z.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let v=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,Z.jsx)(MD,{formWidth:`md`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[_?(0,Z.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,Z.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,Z.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:_,defaultValue:`Continue to ${_}`})})]}):null,(0,Z.jsx)(Vt,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Z.jsx)(LD,{registerUrl:u?void 0:v,redirect:n})})]})})}function LD({registerUrl:e,redirect:t}){let{t:n}=z(),r=v(),i=(0,X.useRef)(``);return(0,X.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,Z.jsx)(T,{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:FD,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 RD(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function zD(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function BD(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function VD(){let{t:e}=z(),t=v(),[n]=m(),r=n.get(`redirect`),{user:i,isLoading:a,organizations:o,isOrganizationsLoading:s,activeOrganization:c,switchOrganization:l,getAuthConfig:u}=S(),[d,f]=(0,X.useState)(null),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1);if((0,X.useLayoutEffect)(()=>{a||_(!0)},[a]),(0,X.useEffect)(()=>{let e=!1;return u().then(n=>{if(e)return;let i=n?.emailPassword?.disableSignUp===!0;f(i),i&&t(`/login${r?`?redirect=${encodeURIComponent(r)}`:``}`,{replace:!0})}).catch(()=>{e||f(!1)}),()=>{e=!0}},[u,t,r]),(0,X.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(!c){if(s||p)return;if(o.length===1){h(!0),l(o[0].id).catch(()=>void 0).finally(()=>h(!1));return}if(o.length===0){window.location.assign(zD(RD(r)?r:`/`));return}window.location.assign(zD(`/organizations`));return}p||window.location.assign(zD(RD(r)?r:`/`))}},[i,c,o,s,p,r,l]),d===null||a&&!g||i)return(0,Z.jsx)(MD,{children:(0,Z.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,Z.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,Z.jsx)(MD,{formWidth:`md`,children:(0,Z.jsx)(Vt,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Z.jsx)(b,{title:e(`auth.register.title`,{defaultValue:`Create your account`}),description:e(`auth.register.description`,{defaultValue:`Sign up to get started`}),loginUrl:y,linkComponent:BD,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 HD(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function UD(){let{t:e}=z();return(0,Z.jsx)(MD,{formWidth:`md`,children:(0,Z.jsx)(Vt,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Z.jsx)(j,{loginUrl:`/login`,linkComponent:HD,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 WD(){let{t:e}=z(),t=v(),[n]=m(),r=n.get(`token`),{resetPassword:i}=S(),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1);return(0,Z.jsx)(MD,{children:(0,Z.jsxs)(Vt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Z.jsx)(Ft,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Z.jsx)(ka,{children:r?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a!==s){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}u(!0);try{await i(r,a),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{u(!1)}},className:`flex flex-col gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Z.jsx)(W,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:a,onChange:e=>o(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Z.jsx)(W,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Z.jsx)(K,{type:`submit`,className:`w-full`,disabled:l,children:l?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,Z.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,Z.jsx)(h,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}function GD(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function KD(){let{t:e}=z(),t=v(),[n]=m(),r=GD(n.get(`next`)),{user:i,isLoading:a,setInitialPassword:o}=S(),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(!1);return(0,Z.jsx)(MD,{children:(0,Z.jsxs)(Vt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`,{defaultValue:`Set a recovery password`})}),(0,Z.jsx)(Ft,{children:e(`auth.setPassword.description`,{defaultValue:`You signed in via single sign-on. Set a local password so you can still sign in to this environment directly if SSO ever becomes unavailable.`})})]}),(0,Z.jsx)(ka,{children:!a&&!i?(0,Z.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.setPassword.noSession`,{defaultValue:`Your session has expired.`}),` `,(0,Z.jsx)(h,{to:`/login`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.setPassword.backToSignIn`,{defaultValue:`Sign in again`})})]}):(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),s!==l){q.error(e(`auth.setPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}f(!0);try{await o(s),q.success(e(`auth.setPassword.success`,{defaultValue:`Local password set`})),t(r)}catch(t){q.error(e(`auth.setPassword.failed`,{defaultValue:`Could not set password`}),{description:t.message})}finally{f(!1)}},className:`flex flex-col gap-4`,children:[i?.email?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`set-password-email`,children:e(`auth.setPassword.email`,{defaultValue:`Email`})}),(0,Z.jsx)(W,{id:`set-password-email`,type:`email`,autoComplete:`username`,value:i.email,disabled:!0,className:`bg-muted text-muted-foreground`})]}):null,(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`new-password`,children:e(`auth.setPassword.newPassword`,{defaultValue:`New password`})}),(0,Z.jsx)(W,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`confirm-password`,children:e(`auth.setPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Z.jsx)(W,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:l,onChange:e=>u(e.target.value)})]}),(0,Z.jsx)(K,{type:`submit`,className:`w-full`,disabled:d,children:d?e(`auth.setPassword.submitting`,{defaultValue:`Saving…`}):e(`auth.setPassword.submit`,{defaultValue:`Set password`})})]})})]})})}var qD=`/api/v1/auth`;function JD(){let{t:e}=z(),[t]=m(),n=t.get(`token`),[r,i]=(0,X.useState)(`loading`),[a,o]=(0,X.useState)(``);return(0,X.useEffect)(()=>{if(!n){i(`error`),o(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${qD}/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||i(`success`)}catch(n){t||(i(`error`),o(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[n,e]),(0,Z.jsx)(MD,{children:(0,Z.jsxs)(Vt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[r===`loading`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Z.jsx)(Ft,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Z.jsx)(ka,{className:`flex justify-center py-6`,children:(0,Z.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),r===`success`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.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,Z.jsx)(Hr,{className:`size-6`})}),(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Z.jsx)(Ft,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Z.jsx)(ka,{className:`text-center`,children:(0,Z.jsx)(h,{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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.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,Z.jsx)(Tr,{className:`size-6`})}),(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Z.jsx)(Ft,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Z.jsx)(ka,{className:`text-center`,children:(0,Z.jsx)(h,{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 YD(){let{t:e}=z(),t=v(),[n]=m(),r=n.get(`email`)??``,i=n.get(`redirect`)??``,{sendVerificationEmail:a}=S(),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1);return(0,Z.jsx)(MD,{children:(0,Z.jsxs)(Vt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,Z.jsx)(uo,{className:`size-8 text-primary`})}),(0,Z.jsx)(fr,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Z.jsx)(Ft,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,Z.jsx)(ka,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r?(0,Z.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:r})]}):null,(0,Z.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}s(!0);try{await a(r,i||`/`),l(!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{s(!1)}},disabled:o||c,className:`w-full`,variant:c?`outline`:`default`,children:o?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Vi,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):c?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Vi,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,Z.jsx)(`span`,{className:`w-full border-t`})}),(0,Z.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,Z.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,Z.jsx)(K,{onClick:()=>{t(`/login${i?`?redirect=${encodeURIComponent(i)}`:``}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,Z.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 XD=`/api/v1/auth`;function ZD(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function QD(){let{t:e}=z(),t=v(),{user:n,signUp:r,organizations:i,refreshOrganizations:a,updateOrganization:o,createOrganization:s,switchOrganization:c}=S(),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(``),[_,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${XD}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||x(n.hasOwner===!0)}catch{e||x(!1)}})(),()=>{e=!0}},[]),(0,X.useEffect)(()=>{b===!0&&!n&&t(`/login`,{replace:!0})},[b,n,t]),(0,X.useEffect)(()=>{n&&window.location.assign(`/`)},[n]),b===null?(0,Z.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,Z.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,Z.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,Z.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Z.jsx)(Ft,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Z.jsx)(ka,{children:(0,Z.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),y(!0);try{await r(l,d,p);let e=h.trim();if(e)try{await a();let t=i[0],n;t?.id?(await o(t.id,{name:e,slug:ZD(e)}),n=t.id):n=(await s({name:e,slug:ZD(e)}))?.id,n&&await c(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,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Z.jsx)(W,{id:`name`,autoComplete:`name`,required:!0,value:l,onChange:e=>u(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Z.jsx)(W,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:h,onChange:e=>g(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Z.jsx)(W,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:d,onChange:e=>f(e.target.value)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(G,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Z.jsx)(W,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:p,onChange:e=>m(e.target.value)})]}),(0,Z.jsx)(K,{type:`submit`,className:`mt-2 w-full`,disabled:_,children:_?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}var $D=`/api/v1/auth`;function eO(){let{t:e}=z(),t=v(),{user:n,isLoading:r}=S(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=typeof window<`u`?window.location.search:``,l=c.startsWith(`?`)?c.slice(1):c,u=new URLSearchParams(l),d=u.get(`client_id`)??void 0,f=u.get(`scope`)??``;(0,X.useEffect)(()=>{if(!r&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,r,t]),(0,X.useEffect)(()=>{if(!d)return;let e=!1;return fetch(`${$D}/oauth2/applications/${encodeURIComponent(d)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));e||s(n?.data??n)}).catch(()=>{}),()=>{e=!0}},[d]);let p=f.split(/\s+/).filter(Boolean),m=async t=>{a(!0);try{let n=await fetch(`${$D}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:l})}),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)}},h=o?.name??o?.client_name??d??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,Z.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,Z.jsxs)(Vt,{className:`w-full max-w-md`,children:[(0,Z.jsxs)(vr,{className:`items-center text-center`,children:[(0,Z.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:o?.icon||o?.logo_uri?(0,Z.jsx)(`img`,{src:o.icon||o.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,Z.jsx)(er,{className:`h-7 w-7 text-muted-foreground`})}),(0,Z.jsx)(fr,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:h,defaultValue:`${h} wants to access your account`})}),(0,Z.jsx)(Ft,{children:e(`oauth.consent.request`,{appName:h,suffix:n?.email?` (${n.email})`:``,defaultValue:`${h} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,Z.jsxs)(ka,{className:`space-y-4`,children:[p.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,Z.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:p.map(t=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(ua,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Z.jsx)(`span`,{children:tO(t,e)})]},t))})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Z.jsxs)(K,{variant:`outline`,onClick:()=>m(!1),disabled:i,children:[(0,Z.jsx)(vo,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Z.jsxs)(K,{onClick:()=>m(!0),disabled:i,children:[(0,Z.jsx)(ua,{className:`mr-2 h-4 w-4`}),i?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,Z.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 tO(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 nO=`/api/v1/auth`;function rO({children:e}){return(0,Z.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,Z.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,Z.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,Z.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground`,children:(0,Z.jsx)(ya,{className:`size-4`})}),`ObjectStack`]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function iO(){let{t:e}=z(),[t]=m(),n=t.get(`user_code`)??t.get(`code`)??``,{user:r,isLoading:a}=S(),o=v(),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(``);return n?a?(0,Z.jsx)(rO,{children:(0,Z.jsx)(Vt,{children:(0,Z.jsx)(vr,{className:`text-center`,children:(0,Z.jsx)(Ft,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?d?(0,Z.jsx)(rO,{children:(0,Z.jsx)(Vt,{children:(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(Hr,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Z.jsx)(fr,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Z.jsx)(Ft,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):p?(0,Z.jsx)(rO,{children:(0,Z.jsx)(Vt,{children:(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Z.jsx)(Ft,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Z.jsx)(rO,{children:(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Z.jsx)(Ft,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Z.jsxs)(ka,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Z.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,Z.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:n})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.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,Z.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:g}),(0,Z.jsx)(K,{onClick:async()=>{_(``),c(!0);try{let t=await fetch(`${nO}/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`}))}f(!0),q.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){_(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{c(!1)}},className:`w-full`,disabled:s||l,children:s?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,Z.jsx)(K,{onClick:async()=>{_(``),u(!0);try{await fetch(`${nO}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:n})}),h(!0)}catch(t){_(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{u(!1)}},variant:`outline`,className:`w-full`,disabled:s||l,children:l?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,Z.jsx)(`div`,{className:`text-center`,children:(0,Z.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>o(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})}):(0,Z.jsx)(i,{to:`/login?redirect=${encodeURIComponent(`/auth/device?user_code=${encodeURIComponent(n)}`)}`,replace:!0}):(0,Z.jsx)(rO,{children:(0,Z.jsx)(Vt,{children:(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Z.jsx)(Ft,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function aO(){let{t:e}=z(),{invitationId:t}=s(),n=v(),{user:r,isLoading:i,acceptInvitation:a,rejectInvitation:o,refreshOrganizations:c}=S(),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(!i&&!r&&t){let e=`/accept-invitation/${t}`;n(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[i,r,t,n]),t?(0,Z.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,Z.jsx)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Z.jsx)(Ft,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Z.jsxs)(ka,{className:`flex flex-col gap-3`,children:[(0,Z.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,Z.jsx)(K,{variant:`outline`,className:`w-full`,onClick:async()=>{f(!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{f(!1)}},disabled:l||d,children:d?e(`acceptInvitation.declining`,{defaultValue:`Declining…`}):e(`acceptInvitation.decline`,{defaultValue:`Decline`})})]})]})})}):(0,Z.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center bg-muted p-6`,children:(0,Z.jsx)(Vt,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(vr,{className:`text-center`,children:[(0,Z.jsx)(fr,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Z.jsx)(Ft,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var oO=`/api/v1/auth`;function sO(){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 cO=sO();function lO(){let e=u(),t=e.pathname+e.search;return(0,Z.jsx)(i,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function uO({children:e,requireOrganization:t=!0}){return(0,Z.jsx)(ee,{fallback:(0,Z.jsx)(lO,{}),loadingFallback:(0,Z.jsx)(Vc,{}),children:(0,Z.jsx)(Uc,{children:t?(0,Z.jsx)(Kc,{children:e}):e})})}function dO(){let{user:e}=S();return(0,Z.jsx)(Jg,{userId:e?.id,children:(0,Z.jsx)(l_,{})})}function fO(){return(0,Z.jsxs)(k,{authUrl:oO,children:[(0,Z.jsx)(ju,{position:`bottom-right`}),(0,Z.jsx)(wD,{}),(0,Z.jsx)(f,{basename:cO,children:(0,Z.jsx)(Hc,{children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`/login`,element:(0,Z.jsx)(ID,{})}),(0,Z.jsx)(g,{path:`/register`,element:(0,Z.jsx)(VD,{})}),(0,Z.jsx)(g,{path:`/forgot-password`,element:(0,Z.jsx)(UD,{})}),(0,Z.jsx)(g,{path:`/reset-password`,element:(0,Z.jsx)(WD,{})}),(0,Z.jsx)(g,{path:`/set-password`,element:(0,Z.jsx)(KD,{})}),(0,Z.jsx)(g,{path:`/verify-email`,element:(0,Z.jsx)(JD,{})}),(0,Z.jsx)(g,{path:`/verify-email-prompt`,element:(0,Z.jsx)(YD,{})}),(0,Z.jsx)(g,{path:`/setup`,element:(0,Z.jsx)(QD,{})}),(0,Z.jsx)(g,{path:`/oauth/consent`,element:(0,Z.jsx)(eO,{})}),(0,Z.jsx)(g,{path:`/auth/device`,element:(0,Z.jsx)(iO,{})}),(0,Z.jsx)(g,{path:`/accept-invitation/:invitationId`,element:(0,Z.jsx)(aO,{})}),(0,Z.jsx)(g,{path:`/f/:slug`,element:(0,Z.jsx)(CD,{mode:`public`})}),(0,Z.jsx)(g,{path:`/s/:token`,element:(0,Z.jsx)(DD,{})}),(0,Z.jsx)(g,{path:`/forms/:name`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(CD,{mode:`internal`})})}),(0,Z.jsx)(g,{path:`/home`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(dO,{})})}),(0,Z.jsx)(g,{path:`/dev/master-detail`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(Xs,{})})}),(0,Z.jsx)(g,{path:`/dev/lists`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)($s,{})})}),(0,Z.jsx)(g,{path:`/dev/modal`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(WE,{})})}),(0,Z.jsx)(g,{path:`/dev/lookup`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(GE,{})})}),(0,Z.jsx)(g,{path:`/organizations`,element:(0,Z.jsx)(uO,{requireOrganization:!1,children:(0,Z.jsx)(u_,{children:(0,Z.jsx)(h_,{})})})}),(0,Z.jsxs)(g,{path:`/organizations/:slug`,element:(0,Z.jsx)(uO,{requireOrganization:!1,children:(0,Z.jsx)(g_,{})}),children:[(0,Z.jsx)(g,{index:!0,element:(0,Z.jsx)(i,{to:`members`,replace:!0})}),(0,Z.jsx)(g,{path:`members`,element:(0,Z.jsx)(x_,{})}),(0,Z.jsx)(g,{path:`invitations`,element:(0,Z.jsx)(w_,{})}),(0,Z.jsx)(g,{path:`settings`,element:(0,Z.jsx)(T_,{})})]}),(0,Z.jsx)(g,{path:`/system/*`,element:(0,Z.jsx)(qc,{})}),(0,Z.jsx)(g,{path:`/ai`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(L_,{})})}),(0,Z.jsx)(g,{path:`/ai/:conversationId`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(L_,{})})}),(0,Z.jsx)(g,{path:`/apps/:appName/*`,element:(0,Z.jsx)(uO,{children:(0,Z.jsx)(cD,{})})}),(0,Z.jsx)(g,{path:`/`,element:(0,Z.jsx)(Uc,{children:(0,Z.jsx)(uD,{})})}),(0,Z.jsx)(g,{path:`*`,element:(0,Z.jsx)(i,{to:`/`,replace:!0})})]})})})]})}async function pO(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,w(r)?y(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var mO=`auth-session-token`,hO=`auth-active-organization-id`;async function gO(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(mO)}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(mO),localStorage.removeItem(hO)}catch{}}function _O(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 vO(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 yO(e){let{objects:t}=ce(),n=(0,X.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,X.useMemo)(()=>n?_O(n,0):null,[n]),fields:(0,X.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(vO):[],[n]),metadataObject:n}}function bO({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(t),[u,d]=(0,X.useState)(!1),f=(0,X.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,X.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,Z.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,Z.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Z.jsx)(`dd`,{children:o?(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,Z.jsx)(Ae,{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,Z.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,Z.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,Z.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(ua,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(vo,{className:`h-3.5 w-3.5`})})]}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,Z.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,Z.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,Z.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,Z.jsx)(Bt,{className:`h-3 w-3`})})]})})]})}function xO({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=yO(t),{refresh:a}=ce(),o=Xm(),s=(0,X.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,Z.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,Z.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,Z.jsx)(bO,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,Z.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,Z.jsx)(bO,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Z.jsx)(bO,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,Z.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Z.jsx)(bO,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,Z.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(H,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,Z.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,Z.jsx)(`dd`,{children:(0,Z.jsx)(H,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var SO=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function CO({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=yO(t),{refresh:i}=ce(),a=Xm(),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,X.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,X.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,Z.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Z.jsx)(Oo,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Z.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Z.jsx)(W,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Z.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:SO.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Z.jsx)(W,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Z.jsx)(W,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Z.jsxs)(K,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,Z.jsx)(V,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,Z.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,Z.jsx)(H,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:SO.find(t=>t.value===e.type)?.label||e.type}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,Z.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,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,Z.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Z.jsx)($t,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Z.jsx)(Oo,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function wO({schema:e}){let t=e.objectName,{fields:n}=yO(t),r=(0,X.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,Z.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,Z.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,Z.jsx)(H,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,Z.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Z.jsx)(er,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function TO(e){return(0,Z.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Z.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,Z.jsx)(dr,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,Z.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,Z.jsx)(xn,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,Z.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,Z.jsx)(yo,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function EO({schema:e}){let t=e.objectName,{object:n}=yO(t);return(0,Z.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,Z.jsx)(Lt,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function DO(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function OO(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=DO(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,X.useState)(o?.current??e),l=(0,X.useRef)(o?.past??[]),u=(0,X.useRef)(o?.future??[]),[,d]=(0,X.useState)(0),f=(0,X.useCallback)(()=>d(e=>e+1),[]);(0,X.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,X.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,X.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,X.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,X.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,X.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,X.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 kO(){let[e,t]=(0,X.useState)(!1),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),o=(0,X.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,X.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,X.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,X.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function AO(){let[e,t]=(0,X.useState)(new Set);return{selectedIds:e,toggle:(0,X.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,X.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,X.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,X.useCallback)(()=>{t(new Set)},[]),isSelected:(0,X.useCallback)(t=>e.has(t),[e]),count:e.size}}function jO(){let[e,t]=(0,X.useState)(null);return{clipboard:e,copy:(0,X.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,X.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function MO(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,X.useState)(i),[s,c]=(0,X.useState)({x:0,y:0}),l=(0,X.useRef)(!1),u=(0,X.useRef)({x:0,y:0}),d=(0,X.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,X.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,X.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,X.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,X.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,X.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,X.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 NO(...e){return Mo(Po(e))}function PO({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,X.useRef)(null);return(0,X.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,Z.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,Z.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,Z.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,Z.jsx)(gt,{className:`h-5 w-5 text-destructive`})}),(0,Z.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,Z.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,Z.jsx)(`button`,{onClick:o,className:NO(`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 FO(...e){return Mo(Po(e))}function IO({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,X.useState)(new Set),o=(0,X.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,Z.jsxs)(`div`,{className:FO(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,Z.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Z.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,Z.jsx)(si,{className:`h-3 w-3`}):(0,Z.jsx)(Ta,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,Z.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,Z.jsx)(LO,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,Z.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function LO({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,Z.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,Z.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,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,Z.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,Z.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,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.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,Z.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,Z.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,Z.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function RO(...e){return Mo(Po(e))}function zO({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,Z.jsx)(`div`,{className:RO(`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,Z.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,Z.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,Z.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 BO=(0,X.createContext)(null);BO.displayName=`CollaborationContext`;function VO(){return(0,X.useContext)(BO)}function HO(...e){return Mo(Po(e))}function UO({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=WO,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=OO(t),d=u.current,f=(0,X.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=MO({initialZoom:e.zoom??1}),{zoom:m}=p,h=AO(),g=(0,X.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,X.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=jO(),y=kO(),b=VO(),x=(0,X.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,X.useState)(!0),[w,T]=(0,X.useState)(!0),[E,D]=(0,X.useState)(s),O=(0,X.useRef)(null),k=(0,X.useRef)(null),A=(0,X.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(0,X.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,X.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,X.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,X.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,X.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]),re=(0,X.useCallback)(()=>{if(o)return;let e=v.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));f([...d,...n]),h.selectMany(n.map(e=>e.id)),n.forEach(e=>{x({type:`insert`,elementId:e.id,data:{component:e}})})},[o,v,d,f,h,x]),N=(0,X.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,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),P=(0,X.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]),F=(0,X.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`}]:[],[_]),ae=(0,X.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,X.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(),re();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,re,d]),(0,Z.jsxs)(`div`,{ref:k,tabIndex:0,className:HO(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Z.jsx)(`div`,{className:HO(`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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,Z.jsxs)(`div`,{className:`mb-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Z.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,Z.jsx)(Wa,{className:HO(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Z.jsx)(`button`,{className:HO(`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,Z.jsx)(fn,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:HO(`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,Z.jsx)(ln,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{className:HO(`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,Z.jsx)(Ke,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:HO(`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:re,children:(0,Z.jsx)(It,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Z.jsx)(`button`,{className:HO(`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,Z.jsx)(In,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,Z.jsx)(ct,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:HO(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,Z.jsx)(ho,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,Z.jsx)(oa,{className:`h-3 w-3`})}),(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Z.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Z.jsx)(Oo,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Z.jsx)(Wr,{className:`h-3 w-3`})})]}),r&&(0,Z.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,Z.jsx)(ci,{className:HO(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Z.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:P,children:(0,Z.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,Z.jsxs)(`div`,{draggable:!o,onDragStart:t=>N(t,e),className:HO(`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,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,Z.jsx)(je,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,Z.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,Z.jsx)(In,{className:`h-3 w-3 text-destructive`})})]}),(0,Z.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,Z.jsx)(zO,{items:ae,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Z.jsx)(`div`,{className:HO(`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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,Z.jsx)(qt,{className:`h-4 w-4`}),`Component Tree`]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,Z.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,Z.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:HO(`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,Z.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,Z.jsx)(`div`,{className:`border-t`,children:(0,Z.jsx)(IO,{title:`Properties – ${_.label??_.type}`,fields:F,onChange:M})}):_&&(0,Z.jsxs)(`div`,{className:`border-t p-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,Z.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,Z.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,Z.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,Z.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,Z.jsx)(PO,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var WO=[{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 GO(e,t={}){return OO(e,t)}function KO(...e){return Mo(Po(e))}var qO=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function JO(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 YO({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,X.useRef)(null),l=GO({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,X.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=kO(),m=AO(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=jO(),_=MO({minZoom:.25,maxZoom:3,zoomStep:.1}),v=VO(),[y,b]=(0,X.useState)(!0),[x,S]=(0,X.useState)(!0),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(``),j=(0,X.useRef)(null),ee=(0,X.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,X.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,X.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,X.useCallback)(()=>{if(i)return;let e=l.current;f({entities:JO(e.entities),relationships:e.relationships})},[i,l,f]),re=(0,X.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),N=(0,X.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,X.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]),P=(0,X.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),F=(0,X.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]),ae=(0,X.useCallback)(()=>{w(null)},[]),oe=(0,X.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),se=(0,X.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),ce=(0,X.useCallback)(()=>{O(null)},[]),le=(0,X.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,X.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,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),fe=(0,X.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`}]:[],he=(0,X.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,X.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(),re()):n&&e.key===`v`?(e.preventDefault(),N()):(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,re,N,M,m]);let ge=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,Z.jsxs)(`div`,{ref:c,tabIndex:0,className:KO(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,Z.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,Z.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,Z.jsx)(kt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,Z.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,Z.jsx)(fn,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(ln,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Z.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,Z.jsx)(Pr,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,Z.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,Z.jsx)(so,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,Z.jsx)(st,{className:`h-3 w-3`})})]}),!i&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Z.jsx)(`button`,{onClick:re,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Z.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{onClick:N,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Z.jsx)(It,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Z.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,Z.jsx)(di,{className:`h-3 w-3`}),` Auto Layout`]}),(0,Z.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Z.jsx)(vn,{className:`h-3 w-3`}),(0,Z.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),` Add Entity`]}),(0,Z.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,Z.jsx)($t,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,Z.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,Z.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,Z.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,Z.jsxs)(`g`,{children:[(0,Z.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,Z.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,Z.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,Z.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>ue(t,e.id),className:KO(`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,Z.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,Z.jsx)(kt,{className:`h-3.5 w-3.5`}),D===e.id?(0,Z.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:se,onKeyDown:e=>{e.key===`Enter`&&se(),e.key===`Escape`&&ce()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,Z.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),oe(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Z.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,Z.jsx)(In,{className:`h-3 w-3 text-destructive`})})]}),(0,Z.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,Z.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:F,onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&ae()},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,Z.jsxs)(`span`,{className:KO(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),P(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Z.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Z.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Z.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:qO.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Z.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Z.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Z.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,Z.jsx)(Oo,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Z.jsx)(zO,{items:ge,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,Z.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Z.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,Z.jsx)(Ta,{className:`h-3 w-3`}):(0,Z.jsx)(si,{className:`h-3 w-3`}),`Properties`]}),y&&(0,Z.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,Z.jsx)(IO,{title:pe?pe.label:`Properties`,fields:me,onChange:he})})]}),(0,Z.jsx)(`div`,{className:`border-t`,children:(0,Z.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,Z.jsx)(Ta,{className:`h-3 w-3`}):(0,Z.jsx)(si,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Z.jsx)(PO,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function XO(...e){return Mo(Po(e))}var ZO=120,QO=50;function $O(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 ek({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=OO({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,X.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=kO(),g=AO(),_=jO(),v=MO({initialZoom:1}),y=VO(),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!0),[A,j]=(0,X.useState)(null),[ee,te]=(0,X.useState)({x:0,y:0}),M=(0,X.useRef)(null),ne=(0,X.useRef)(c),re=(0,X.useRef)(l);ne.current=c,re.current=l,(0,X.useEffect)(()=>{ne.current?.(f),re.current?.(p)},[d.current]);let N=(0,X.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,X.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]),P=(0,X.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]),F=(0,X.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,_]),ae=(0,X.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),oe=(0,X.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),se=(0,X.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),ce=(0,X.useCallback)(()=>{s||f.length===0||m($O(f,p),p)},[f,p,s,m]),le=(0,X.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,X.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,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),fe=(0,X.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),pe=(0,X.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,X.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),he=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`}},ge=(0,X.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:ZO,height:QO,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,X.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(),F();return}if(n&&e.key===`v`){e.preventDefault(),ae();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),P()):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,F,ae,ie,P]);let _e=(0,X.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,Z.jsxs)(`div`,{ref:M,tabIndex:0,className:XO(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Z.jsx)(PO,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,Z.jsx)(Li,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Z.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,Z.jsx)(`div`,{className:`flex-1`}),!s&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.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,Z.jsx)(fn,{className:`h-3 w-3`})}),(0,Z.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,Z.jsx)(ln,{className:`h-3 w-3`})}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.jsx)(`button`,{onClick:F,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,Z.jsx)(Ke,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{onClick:ae,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,Z.jsx)(It,{className:`h-3 w-3`})}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.jsxs)(`button`,{onClick:oe,className:XO(`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,Z.jsx)(Le,{className:`h-3 w-3`}),` Connect`]}),(0,Z.jsxs)(`button`,{onClick:ce,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,Z.jsx)(_r,{className:`h-3 w-3`}),` Layout`]}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.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,Z.jsx)(so,{className:`h-3 w-3`})}),(0,Z.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,Z.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,Z.jsx)(Pr,{className:`h-3 w-3`})}),(0,Z.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,Z.jsx)(st,{className:`h-3 w-3`})}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.jsxs)(`button`,{onClick:()=>N(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,Z.jsx)(tr,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Z.jsxs)(`button`,{onClick:()=>N(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,Z.jsx)(Ga,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Z.jsxs)(`button`,{onClick:()=>N(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,Z.jsx)(ht,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Z.jsxs)(`button`,{onClick:()=>N(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,Z.jsx)(Ga,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.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,Z.jsx)(ci,{className:`h-3 w-3`}):(0,Z.jsx)(On,{className:`h-3 w-3`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,Z.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,Z.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:_e,onDrop:ue,onDragOver:de,children:[(0,Z.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,Z.jsx)(`defs`,{children:(0,Z.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,Z.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+ZO/2;let r=t.position.y+QO/2;n.position.x+ZO/2;let i=n.position.y+QO/2,a=t.position.x+ZO,o=r,s=n.position.x,c=i;return(0,Z.jsxs)(`g`,{children:[(0,Z.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,Z.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,Z.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,Z.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},role:`group`,"aria-label":e.label,draggable:!s&&!S,onDragStart:t=>le(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{se(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Z.jsx)(`div`,{className:XO(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,he(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,Z.jsx)(`span`,{className:XO(`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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:QO/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),se(e.id)}}),(0,Z.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:QO/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?se(e.id):(C(!0),T(e.id))}}),(0,Z.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:ZO/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),se(e.id)}}),(0,Z.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:ZO/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),se(e.id)}})]}),!s&&t&&!S&&(0,Z.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,Z.jsx)(In,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Z.jsx)(zO,{items:ge,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,Z.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,Z.jsx)(IO,{title:fe?`Properties: ${fe.label}`:`Properties`,fields:pe,onChange:me})})]})]})}function tk(...e){return Mo(Po(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`},nk={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}},rk=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function ik({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=OO(a.length>0?a:rk),f=d.current,p=(0,X.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=AO(),h=(0,X.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=jO(),_=kO(),v=VO(),y=(0,X.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,X.useState)(!0),S=(0,X.useRef)(null),C=(0,X.useRef)(null),w=nk[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,X.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,X.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,X.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,X.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,X.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,X.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,X.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,X.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]),re=(0,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),N=(0,X.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,X.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,X.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,Z.jsxs)(`div`,{ref:C,tabIndex:0,className:tk(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,Z.jsxs)(`div`,{role:`toolbar`,"aria-label":$.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,Z.jsx)(oo,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Z.jsx)(`button`,{className:tk(`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,Z.jsx)(fn,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:tk(`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,Z.jsx)(ln,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{className:tk(`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,Z.jsx)(Ke,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:tk(`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,Z.jsx)(It,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Z.jsx)(`button`,{className:tk(`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,Z.jsx)(In,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),$.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,Z.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,Z.jsx)(ci,{className:tk(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,Z.jsx)(`div`,{role:`region`,"aria-label":$.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,Z.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,Z.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:re,onDrop:e=>N(e,t),children:[(0,Z.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,Z.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,Z.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:$.addText,"aria-label":$.addText,children:(0,Z.jsx)(wn,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,Z.jsx)(Oo,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,Z.jsx)(zt,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:$.addChart,"aria-label":$.addChart,children:(0,Z.jsx)(yo,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:$.addTable,"aria-label":$.addTable,children:(0,Z.jsx)(br,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,Z.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,Z.jsxs)(`div`,{draggable:!c,onDragStart:n=>ne(n,e,t),className:tk(`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,Z.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,Z.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,Z.jsx)(In,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Z.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:tk(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,Z.jsx)(IO,{title:`${$.properties} – ${O.type}`,fields:ie,onChange:ee}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:$.properties}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:$.selectElementPrompt})})]}))}),(0,Z.jsx)(PO,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var ak={"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 ok(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 sk(){try{let e=z();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:ok(ak)}:{t:e.t}}catch{return{t:ok(ak)}}}function ck(...e){return Mo(Po(e))}var lk={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function uk(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var dk=0;function fk(e){return dk+=1,`${e}_${Date.now()}_${dk}`}function pk({steps:e,currentIndex:t,onStepClick:n}){return(0,Z.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,Z.jsxs)(X.Fragment,{children:[r>0&&(0,Z.jsx)(`div`,{className:ck(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:ck(`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,Z.jsx)(`div`,{className:ck(`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,Z.jsx)(ua,{className:`h-4 w-4`}):r+1}),(0,Z.jsx)(`span`,{className:ck(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function mk({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!he(e.name);return(0,Z.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,Z.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Z.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:ck(`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,Z.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,Z.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,Z.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,Z.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,Z.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:Me},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:_r},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:cn}].map(({value:t,labelKey:a,Icon:o})=>(0,Z.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:ck(`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,Z.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,Z.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function hk({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,X.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,Z.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(Co,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.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,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:ck(`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,Z.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,Z.jsx)(`div`,{className:ck(`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,Z.jsx)(ua,{className:`h-3 w-3`})})]}),(0,Z.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,Z.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var gk={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 _k({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,Z.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.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,Z.jsx)(_i,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,Z.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,Z.jsx)(Le,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,Z.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,Z.jsx)(oa,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,Z.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,Z.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,Z.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,Z.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):ue(n.label)}),(0,Z.jsx)(`span`,{className:ck(`rounded-full px-2 py-0.5 text-[10px] font-medium`,gk[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Z.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,Z.jsx)(eo,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(Ta,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function vk({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,Z.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(zt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Na,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Ka,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,Z.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,Z.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,Z.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,Z.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,Z.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Z.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Z.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function yk({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=sk(),l=kO(),[u,d]=(0,X.useState)(0),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(()=>({...lk,objects:e.map(e=>({...e})),...n})),g=(0,X.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,X.useMemo)(()=>m.name.length>0&&he(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,X.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,X.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,X.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,X.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,X.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,X.useCallback)(e=>{let t={id:fk(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,X.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,X.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,X.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:uk(e.objects)})),d(e=>e+1))},[u,v]),k=(0,X.useCallback)(()=>{_||d(e=>e-1)},[_]),A=(0,X.useCallback)(()=>{r?.(m)},[m,r]),j=(0,X.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,X.useCallback)(()=>{a?.(m)},[m,a]),te=(0,X.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:uk(e.objects)})),d(e))},[u,b]);return(0,Z.jsxs)(`div`,{className:ck(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,Z.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,Z.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,Z.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,Z.jsx)(vo,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,Z.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Z.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,Z.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,Z.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,Z.jsx)(pk,{steps:g,currentIndex:u,onStepClick:te})}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Z.jsx)(mk,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Z.jsx)(hk,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Z.jsx)(_k,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Z.jsx)(vk,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,Z.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,Z.jsx)(yi,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,Z.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,Z.jsx)(ua,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,Z.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,Z.jsx)(si,{className:`h-4 w-4`})]})]})]})]})}function bk(...e){return Mo(Po(e))}var xk=0;function Sk(e){return xk+=1,`${e}_${Date.now()}_${xk}`}var Ck={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:kt},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:oo},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:yo},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Le},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:_i},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:oa},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:$i}},wk=[{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 Tk({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,X.useState)(!1),[_,v]=(0,X.useState)(ue(e.label)??``),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(e.icon||``),C=Ck[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(ue(e.label)??``),g(!1)},D=()=>{u(e.id,x.trim()),b(!1)};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:bk(`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,Z.jsx)(je,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,Z.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,Z.jsx)(Ta,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(si,{className:`h-3.5 w-3.5`})}):(0,Z.jsx)(`span`,{className:`w-5`}),y&&!i?(0,Z.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,Z.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Z.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,Z.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,Z.jsx)(Bt,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,Z.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,Z.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(ue(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,Z.jsx)(`span`,{className:bk(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(ue(e.label)??``),g(!0))},children:ue(e.label)}),(0,Z.jsx)(`span`,{className:bk(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,Z.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,Z.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,Z.jsx)(tt,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(ct,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Z.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,Z.jsx)(Oo,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(eo,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(Ta,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,Z.jsx)(Z.Fragment,{children:e.children.map((n,r)=>(0,Z.jsx)(Tk,{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 Ek({items:e,t}){return(0,Z.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,Z.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,Z.jsx)(Dk,{item:e,depth:0},e.id))})]})}function Dk({item:e,depth:t}){let n=Ck[e.type];return e.type===`separator`?(0,Z.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Z.jsx)(`span`,{className:`truncate`,children:ue(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Z.jsx)(Dk,{item:e,depth:t+1},e.id))]})}function Ok({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=sk(),c=(0,X.useRef)(null),[l,u]=(0,X.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,X.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,X.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,X.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,X.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,X.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,X.useCallback)((n,r)=>{let i={id:Sk(r),type:r,label:r===`separator`?``:`New ${s(Ck[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,X.useCallback)(n=>{let r={id:Sk(n),type:n,label:n===`separator`?``:`New ${s(Ck[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,X.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,X.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,X.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,Z.jsxs)(`div`,{"data-testid":`navigation-designer`,className:bk(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,Z.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[wk.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=Ck[e];return(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:bk(`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,Z.jsx)(Oo,{className:`h-3 w-3`}),s(t)]},e)}),(0,Z.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Z.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,Z.jsx)(nn,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Z.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:bk(`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,Z.jsx)(rn,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,Z.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,Z.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,Z.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,Z.jsx)(Tk,{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,Z.jsx)(Ek,{items:e,t:s})]})}function kk(...e){return Mo(Po(e))}var Ak=[{type:`metric`,label:`KPI Metric`,Icon:At},{type:`bar`,label:`Bar Chart`,Icon:yo},{type:`line`,label:`Line Chart`,Icon:Jr},{type:`pie`,label:`Pie Chart`,Icon:Di},{type:`table`,label:`Table`,Icon:br},{type:`grid`,label:`Grid`,Icon:ft}],jk=0;function Mk(){return jk+=1,`widget_${Date.now()}_${jk}`}function Nk({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=Ak.find(e=>e.type===l)||Ak[0];return(0,Z.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:kk(`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,Z.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(je,{className:`h-4 w-4 text-gray-300`}),(0,Z.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Z.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,Z.jsx)(eo,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(Ta,{className:`h-3.5 w-3.5`})}),(0,Z.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,Z.jsx)(In,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,Z.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,Z.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function Pk({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=sk();return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,Z.jsx)(vo,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,Z.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:Ak.map(e=>(0,Z.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,Z.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,Z.jsx)(`option`,{value:`count`,children:`Count`}),(0,Z.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,Z.jsx)(`option`,{value:`avg`,children:`Average`}),(0,Z.jsx)(`option`,{value:`min`,children:`Min`}),(0,Z.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,Z.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,Z.jsx)(`option`,{value:`default`,children:`Default`}),(0,Z.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,Z.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,Z.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,Z.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,Z.jsx)(`option`,{value:`success`,children:`Success`}),(0,Z.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,Z.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,Z.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,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,Z.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 Fk({schema:e}){let{t}=sk(),n=e.widgets||[];return(0,Z.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,Z.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,Z.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,Z.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=Ak.find(t=>t.type===(e.type||`metric`))||Ak[0];return(0,Z.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,Z.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function Ik({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=sk(),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(null),m=(0,X.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,X.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=OO(e),w=(0,X.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,X.useCallback)(e=>{let t=Mk(),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,X.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,X.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,X.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,X.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,X.useCallback)(()=>{i&&i(v)},[v,i]),ee=(0,X.useCallback)(()=>{m.current?.click()},[]),te=(0,X.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,Z.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:kk(`flex flex-col gap-4 outline-none`,r),children:[(0,Z.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:te}),E&&!d&&(0,Z.jsx)(Pk,{widget:E,readOnly:n,onChange:A,onClose:()=>_(null)}),(0,Z.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),Ak.map(({type:e,label:t,Icon:r})=>(0,Z.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,Z.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(fn,{className:`h-4 w-4`})}),(0,Z.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,Z.jsx)(ln,{className:`h-4 w-4`})})]}),(0,Z.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,Z.jsx)(nn,{className:`h-4 w-4`})}),!n&&(0,Z.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,Z.jsx)(rn,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:kk(`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,Z.jsx)(tt,{className:`h-4 w-4`}):(0,Z.jsx)(ct,{className:`h-4 w-4`})})]})]}),d?(0,Z.jsx)(Fk,{schema:v}):T.length===0?(0,Z.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,Z.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,Z.jsx)(Nk,{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 Lk(...e){return Mo(Po(e))}var Rk=[{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`}],zk=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function Bk({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=sk(),[c,l]=(0,X.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=OO(e),g=(0,X.useRef)(!0);(0,X.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,X.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,X.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,X.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,X.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,Z.jsxs)(`div`,{"data-testid":`branding-editor`,className:Lk(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,Z.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,Z.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:Lk(`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,Z.jsx)(fn,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,Z.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:Lk(`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,Z.jsx)(ln,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,Z.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,Z.jsx)(nn,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,Z.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:Lk(`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,Z.jsx)(rn,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(zt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(Na,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,Z.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:Rk.map(e=>(0,Z.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:Lk(`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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Ka,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(wn,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Z.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,Z.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),zk.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,Z.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,Z.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:Lk(`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,Z.jsx)(mr,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,Z.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:Lk(`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,Z.jsx)(ri,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Z.jsxs)(`div`,{"data-testid":`branding-preview`,className:Lk(`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,Z.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,Z.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,Z.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,Z.jsx)(`span`,{className:Lk(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,Z.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,Z.jsx)(`p`,{className:Lk(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Z.jsx)(`span`,{className:Lk(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Z.jsxs)(`div`,{className:Lk(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,Z.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:Lk(`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,Z.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,Z.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,Z.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,Z.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,Z.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,Z.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,Z.jsx)(`div`,{className:Lk(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Z.jsx)(`div`,{className:Lk(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Z.jsx)(`div`,{className:Lk(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function Vk(...e){return Mo(Po(e))}var Hk=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],Uk=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function Wk({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=sk(),s=kO(),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(null),f=(0,X.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,X.useMemo)(()=>new te({items:f}),[f]),m=(0,X.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,X.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,X.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,X.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,X.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,X.useCallback)(()=>{d(null),l(!0)},[]),b=(0,X.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,X.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,X.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:Uk.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:Hk.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,Z.jsxs)(`div`,{"data-testid":`object-manager`,className:Vk(`w-full space-y-3`,a),children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(kt,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,Z.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,Z.jsx)(ls,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Z.jsx)(Ro,{schema:S}),(0,Z.jsx)(PO,{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 Gk(...e){return Mo(Po(e))}var Kk={text:{label:`Text`,Icon:wn},textarea:{label:`Text Area`,Icon:oo},number:{label:`Number`,Icon:ur},boolean:{label:`Checkbox`,Icon:qe},date:{label:`Date`,Icon:$e},datetime:{label:`Date/Time`,Icon:$e},time:{label:`Time`,Icon:$e},select:{label:`Picklist`,Icon:Ki},email:{label:`Email`,Icon:Ao},phone:{label:`Phone`,Icon:sr},url:{label:`URL`,Icon:Ka},password:{label:`Password`,Icon:ot},currency:{label:`Currency`,Icon:ur},percent:{label:`Percent`,Icon:ur},lookup:{label:`Lookup`,Icon:$t},formula:{label:`Formula`,Icon:Zn},autonumber:{label:`Auto Number`,Icon:ur},file:{label:`File`,Icon:oo},image:{label:`Image`,Icon:zt},markdown:{label:`Markdown`,Icon:oo},html:{label:`Rich Text`,Icon:oo},color:{label:`Color`,Icon:Na},code:{label:`Code`,Icon:Zn},location:{label:`Location`,Icon:Bn},address:{label:`Address`,Icon:Bn},rating:{label:`Rating`,Icon:Fe},slider:{label:`Slider`,Icon:Zr}},qk={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`]},Jk=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function Yk({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=sk(),o=kO(),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),p=(0,X.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,X.useMemo)(()=>new te({items:p}),[p]),h=(0,X.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,X.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,X.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,X.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,X.useCallback)(()=>{u(null),c(!0)},[]),b=(0,X.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,X.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,X.useMemo)(()=>Jk.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:qk[e].map(e=>({label:Kk[e].label,value:e}))})),[a]),C=(0,X.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,X.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,Z.jsxs)(`div`,{"data-testid":`field-designer`,className:Gk(`w-full space-y-3`,i),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(St,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,Z.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,Z.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,Z.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,Z.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,Z.jsx)(ls,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Z.jsx)(zo,{schema:w}),(0,Z.jsx)(PO,{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 Xk=`objectui-app-wizard-draft`;function Zk(){let e=v(),{appName:t}=s(),{objects:n,refresh:r}=ce(),i=be(),a=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),o=(0,X.useCallback)(()=>{try{let e=localStorage.getItem(Xk);if(e)return JSON.parse(e)}catch{}},[]),c=(0,X.useCallback)(async t=>{try{let n=fe(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(Xk),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]),l=(0,X.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),u=(0,X.useCallback)(e=>{try{localStorage.setItem(Xk,JSON.stringify(e)),q.info(`Draft saved`)}catch{}},[]);return(0,Z.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,Z.jsx)(yk,{availableObjects:a,initialDraft:o(),onComplete:c,onCancel:l,onSaveDraft:u})})}function Qk(){let e=v(),{appName:t,editAppName:n}=s(),{apps:r,objects:i,refresh:a}=ce(),o=be(),c=n||t,l=r.find(e=>e.name===c),u=(i||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:l?.navigation?.some(t=>t.type===`object`&&t.objectName===e.name)??!1})),d=(0,X.useMemo)(()=>{if(l)return{name:l.name,title:l.title||l.label||``,description:l.description||``,icon:l.icon||``,layout:l.layout||`sidebar`,navigation:l.navigation||[],branding:{logo:l.branding?.logo||l.logo||``,primaryColor:l.branding?.primaryColor||`#3b82f6`,favicon:l.branding?.favicon||l.favicon||``}}},[l]),f=(0,X.useCallback)(async t=>{try{let n=fe(t),r={...l,...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,l]),p=(0,X.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,X.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${c}`,JSON.stringify(e)),q.info(`Draft saved`)}catch{}},[c]);return l?(0,Z.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,Z.jsx)(yk,{availableObjects:u,initialDraft:d,onComplete:f,onCancel:p,onSaveDraft:m})}):(0,Z.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,Z.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,c,`" not found.`]})})}function $k(){let e=v(),{dashboardName:t}=s(),n=be(),{dashboards:r,refresh:i}=ce(),a=r?.find(e=>e.name===t),[o,c]=(0,X.useState)(()=>a||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),l=(0,X.useRef)(o);l.current=o;let u=(0,X.useCallback)(async e=>{try{if(n)return await n.update(`sys_dashboard`,t,e),i().catch(()=>{}),!0}catch{}return!1},[n,t,i]),d=(0,X.useCallback)(async e=>{c(e),await u(e)},[u]);(0,X.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),u(l.current).then(e=>{e&&q.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u]);let f=(0,X.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]),p=(0,X.useCallback)(e=>{q.success(`Dashboard schema imported`),d(e)},[d]);return a?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,Z.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,Z.jsx)(Wt,{className:`h-4 w-4`})}),(0,Z.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,a.label||a.title||t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Z.jsx)(Ik,{schema:o,onChange:d,onExport:f,onImport:p})})]}):(0,Z.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var eA=t({AppCreationWizard:()=>yk,BrandingEditor:()=>Bk,CreateAppPage:()=>Zk,DashboardDesignPage:()=>$k,DashboardEditor:()=>Ik,DataModelDesigner:()=>YO,EditAppPage:()=>Qk,FieldDesigner:()=>Yk,NavigationDesigner:()=>Ok,ObjectManager:()=>Wk,PageDesigner:()=>UO,ProcessDesigner:()=>ek,ReportDesigner:()=>ik});I.register(`page-designer`,UO,{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`,YO,{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`,ek,{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`,ik,{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`,yk,{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`,Ok,{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`,Ik,{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`,Bk,{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`,Wk,{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`,Yk,{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 tA(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 nA(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 rA=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=tA(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(nA)};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 iA({schema:e}){let t=e.objectName,{objects:n,refresh:r}=ce(),i=Xm(),a=(0,X.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,X.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(vO):[],[a]),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),d=s??o,f=(0,X.useRef)(d),p=(0,X.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=rA.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,Z.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,Z.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,Z.jsx)(Ha,{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,Z.jsx)(Yk,{objectName:t,fields:d,onFieldsChange:p})]})}function aA({schema:e}){let t=e.objectName,[n,r]=(0,X.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,Z.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,Z.jsxs)(mi,{value:n,onValueChange:r,className:`w-full`,children:[(0,Z.jsxs)(ha,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Z.jsxs)(La,{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,Z.jsx)(jr,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Z.jsxs)(La,{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,Z.jsx)(St,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Z.jsxs)(La,{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,Z.jsx)($t,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Z.jsxs)(La,{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,Z.jsx)(Lt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Z.jsx)(Ja,{value:`details`,className:`mt-6`,children:(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsx)(ne,{schema:i})})}),(0,Z.jsx)(Ja,{value:`fields`,className:`mt-6`,children:(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsx)(ne,{schema:a})})}),(0,Z.jsx)(Ja,{value:`relationships`,className:`mt-6`,children:(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsx)(ne,{schema:o}),(0,Z.jsx)(ne,{schema:s})]})}),(0,Z.jsx)(Ja,{value:`data`,className:`mt-6`,children:(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsx)(ne,{schema:l}),(0,Z.jsx)(ne,{schema:c})]})})]})})}var oA={namespace:`console`,category:`system`};I.register(`object-detail-tabs`,aA,{...oA,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),I.register(`object-properties`,xO,{...oA,label:`Object Properties`,icon:`Settings2`}),I.register(`object-relationships`,CO,{...oA,label:`Object Relationships`,icon:`Link2`}),I.register(`object-keys`,wO,{...oA,label:`Object Keys`,icon:`KeyRound`}),I.register(`object-data-experience`,TO,{...oA,label:`Data Experience`,icon:`LayoutList`}),I.register(`object-data-preview`,EO,{...oA,label:`Data Preview`,icon:`Table`}),I.register(`object-field-designer`,iA,{...oA,label:`Field Designer`,icon:`Columns`});var sA=(0,X.lazy)(()=>d(()=>import(`./ApiConsolePage-DJYUA73f.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),cA=(0,X.lazy)(()=>d(()=>import(`./FlowRunsPage-sdTkbx5s.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),lA=(0,X.lazy)(()=>d(()=>import(`./PublicFormsPage-DbMqDQiv.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function uA({label:e}){return(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}W_({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(uA,{label:`API console`}),children:(0,Z.jsx)(sA,{...e})})}),W_({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(uA,{label:`flow runs`}),children:(0,Z.jsx)(cA,{...e})})}),W_({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(uA,{label:`public forms`}),children:(0,Z.jsx)(lA,{...e})})});var dA=(0,X.lazy)(()=>d(()=>import(`./ProfilePage-D7kxyCKj.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function fA({label:e}){return(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}W_({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(fA,{label:`profile`}),children:(0,Z.jsx)(dA,{...e})})});var pA=`/api/v1/auth`;Iu(),I.registerLazy(`object-map`,()=>d(()=>import(`./plugin-map-Bt30Mxn6.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),I.registerLazy(`map`,()=>d(()=>import(`./plugin-map-Bt30Mxn6.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,()=>d(()=>import(`./plugin-dashboard-DbPGiGy-.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});I.registerLazy(`chart`,()=>d(()=>import(`./plugin-charts-BjUzf65B.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,()=>d(()=>import(`./plugin-charts-BjUzf65B.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});I.registerLazy(`object-gantt`,()=>d(()=>import(`./plugin-gantt-CEW8O7uB.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),I.registerLazy(`gantt`,()=>d(()=>import(`./plugin-gantt-CEW8O7uB.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`markdown`,()=>d(()=>import(`./plugin-markdown-tayYSGF3.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),I.registerLazy(`object-timeline`,()=>d(()=>import(`./plugin-timeline-DZoFKL82.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),I.registerLazy(`timeline`,()=>d(()=>import(`./plugin-timeline-DZoFKL82.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`object-calendar`,()=>d(()=>import(`./plugin-calendar-DSFbexMB.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`calendar`,()=>d(()=>import(`./plugin-calendar-DSFbexMB.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),I.registerLazy(`calendar-view`,()=>d(()=>import(`./plugin-calendar-DSFbexMB.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),I.registerLazy(`object-kanban`,()=>d(()=>import(`./plugin-kanban-C_GfAMzI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),I.registerLazy(`kanban`,()=>d(()=>import(`./plugin-kanban-C_GfAMzI.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,()=>d(()=>import(`./plugin-kanban-C_GfAMzI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});I.registerLazy(`report`,()=>d(()=>import(`./plugin-report-qca5M0OZ.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,()=>d(()=>import(`./plugin-report-qca5M0OZ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});at();var mA=``.replace(/\/+$/,``);Promise.all([Qo(mA),gO(pA)]).finally(()=>{Js.createRoot(document.getElementById(`root`)).render((0,Z.jsx)(X.StrictMode,{children:(0,Z.jsx)(cs,{pwa:{enabled:!0,name:es(),shortName:ts()},children:(0,Z.jsx)(L,{loadLanguage:pO,children:(0,Z.jsx)(fO,{})})})}))});export{ol as a,gh as i,_h as n,rl as o,Ch as r,G_ as t};
|