@objectstack/console 9.2.0 → 9.3.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.
Files changed (62) hide show
  1. package/dist/assets/{AiPendingActionsPage-B-n-gqzM.js → AiPendingActionsPage-Y9r83gqj.js} +1 -1
  2. package/dist/assets/{ApiConsolePage-uPTuvhXX.js → ApiConsolePage-Dwbms0Zh.js} +1 -1
  3. package/dist/assets/{AppManagementPage-CNpBOuFm.js → AppManagementPage-0JEALVYK.js} +1 -1
  4. package/dist/assets/ApprovalsInboxPage-B-drSsxQ.js +1 -0
  5. package/dist/assets/{AuditLogPage-_9ECzJM8.js → AuditLogPage-CXhNSVOU.js} +1 -1
  6. package/dist/assets/{ComponentNavView-CDdExuCL.js → ComponentNavView-BI4O_zkC.js} +1 -1
  7. package/dist/assets/ConsoleFloatingChatbot-CiODZIcp.js +1 -0
  8. package/dist/assets/{DeveloperHubPage-mdknfgGp.js → DeveloperHubPage-D-UigRUA.js} +1 -1
  9. package/dist/assets/FlowRunsPage-_UeeNdBc.js +1 -0
  10. package/dist/assets/{IntegrationsPage-7SUsLOvq.js → IntegrationsPage-DsWyxKR6.js} +2 -2
  11. package/dist/assets/{ProfilePage-D4yjFTMG.js → ProfilePage-T27zVrMO.js} +1 -1
  12. package/dist/assets/PublicFormsPage-Pd453sW6.js +1 -0
  13. package/dist/assets/{SettingsHub-7kLSZWnI.js → SettingsHub-B4oSx4ed.js} +1 -1
  14. package/dist/assets/{SettingsView-DqnY47y1.js → SettingsView-CkQEI5DW.js} +1 -1
  15. package/dist/assets/{SystemHubPage-DeiksJan.js → SystemHubPage-Di6eqozE.js} +1 -1
  16. package/dist/assets/assistantBus-B-xBT6j1.js +1 -0
  17. package/dist/assets/{data-adapter-D1EJuDUI.js → data-adapter-3AJO7A2o.js} +1 -1
  18. package/dist/assets/framework-crD8qZlm.js +34 -0
  19. package/dist/assets/{highlighted-body-OFNGDK62-Du4wVUV7.js → highlighted-body-OFNGDK62-B3OlR_Nx.js} +1 -1
  20. package/dist/assets/index-Cf7NsvAk.css +2 -0
  21. package/dist/assets/index-CiI7zDDo.js +32 -0
  22. package/dist/assets/{mergeServerFields-CNavewPY.js → mergeServerFields-DUkbynPg.js} +3 -3
  23. package/dist/assets/mermaid-GHXKKRXX-CBocchJ2.js +1 -0
  24. package/dist/assets/{plugin-calendar-u9Aa9OAR.js → plugin-calendar-ed7RoEFF.js} +1 -1
  25. package/dist/assets/{plugin-charts-DSBNwB9E.js → plugin-charts-QabQJ_NJ.js} +2 -2
  26. package/dist/assets/plugin-chatbot-Cy3tiXkg.js +120 -0
  27. package/dist/assets/plugin-dashboard-PA0xf59v.js +5 -0
  28. package/dist/assets/plugin-form-BABEMaum.js +1 -0
  29. package/dist/assets/plugin-gantt-BNjfLkTR.js +1 -0
  30. package/dist/assets/plugin-grid-BxyuFeJP.js +6 -0
  31. package/dist/assets/plugin-kanban-D4yCkUn_.js +1 -0
  32. package/dist/assets/plugin-map-C8Jxhxs1.js +1 -0
  33. package/dist/assets/{plugin-markdown-6MvgfANj.js → plugin-markdown-CR5TpghH.js} +1 -1
  34. package/dist/assets/plugin-report-rz8HUIsi.js +59 -0
  35. package/dist/assets/{plugin-timeline-DrUpbBdn.js → plugin-timeline-DQHQwtdw.js} +1 -1
  36. package/dist/assets/plugin-view-BykLknWa.js +1 -0
  37. package/dist/assets/plugins-views-CBO5qxO-.js +4 -0
  38. package/dist/assets/{src-s-NNbVef.js → src-Tw2eleSi.js} +1 -1
  39. package/dist/assets/{types-Decs33Tv.js → types-BkFEpiv3.js} +1 -1
  40. package/dist/assets/{ui-components-BbPoD3rS.js → ui-components-BrY5joKQ.js} +8 -8
  41. package/dist/assets/{ui-layout-CWeej0a8.js → ui-layout-KICrO2Oe.js} +1 -1
  42. package/dist/index.html +4 -4
  43. package/package.json +1 -1
  44. package/dist/assets/ApprovalsInboxPage-BFNNZBXy.js +0 -1
  45. package/dist/assets/ConsoleFloatingChatbot-DThmuzxB.js +0 -1
  46. package/dist/assets/FlowRunsPage-yleJQxJv.js +0 -1
  47. package/dist/assets/PublicFormsPage-DWj4wR8t.js +0 -1
  48. package/dist/assets/assistantBus-Bppk-Y9t.js +0 -1
  49. package/dist/assets/framework-CHiz03zG.js +0 -34
  50. package/dist/assets/index-B_NAVTba.js +0 -32
  51. package/dist/assets/index-DwG7_t-6.css +0 -2
  52. package/dist/assets/mermaid-GHXKKRXX-D0s_nNwO.js +0 -1
  53. package/dist/assets/plugin-chatbot-BzJE6C-F.js +0 -120
  54. package/dist/assets/plugin-dashboard-C5nSNZfG.js +0 -5
  55. package/dist/assets/plugin-form-DrL6xDfP.js +0 -1
  56. package/dist/assets/plugin-gantt-aDdnMW0u.js +0 -1
  57. package/dist/assets/plugin-grid-CSHgWd0O.js +0 -6
  58. package/dist/assets/plugin-kanban-D45w069C.js +0 -1
  59. package/dist/assets/plugin-map-ue6Mjnhb.js +0 -1
  60. package/dist/assets/plugin-report-QmyiWpfC.js +0 -59
  61. package/dist/assets/plugin-view-DS-dSLs-.js +0 -1
  62. package/dist/assets/plugins-views-DH1gGZh6.js +0 -4
@@ -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 M}from"./infrastructure-CxityHZF.js";import{$ as ee,A as N,B as P,C as te,F as ne,I as F,L as re,N as ie,O as ae,Q as oe,S as I,T as se,U as ce,V as le,a as ue,at as de,b as fe,d as pe,it as me,j as he,lt as ge,m as _e,mt as L,n as R,o as z,p as ve,r as B,st as V,w as ye,x as be}from"./framework-crD8qZlm.js";import{R as xe,_ as Se,d as Ce,f as we,h as Te,l as Ee,m as De,p as Oe}from"./vendor-objectstack-RB3xvhcR.js";import{$ as ke,$a as Ae,$i as je,$n as Me,$o as Ne,$r as Pe,$s as Fe,$t as Ie,Aa as Le,Ai as Re,An as ze,Ao as Be,Ar 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 H,Di as tt,Do as nt,Dr as rt,Ds as it,Dt as at,E as ot,Ea as st,Ei as ct,Er as lt,Es as ut,Et as dt,F as ft,Fa as pt,Fi as mt,Fn as ht,Fo as gt,Fr as _t,Fs as vt,Ft as yt,Gi as bt,Gn as xt,Go as St,Gs as Ct,Gt as wt,Ho as Tt,Hr as Et,Ht as Dt,I as Ot,Ia as kt,In as At,Io as jt,Ir as Mt,Is as Nt,It as Pt,Ja as Ft,Ji as It,Jn as Lt,Jo as Rt,Jr as zt,Ka as Bt,Ki as Vt,Kn as Ht,Ko as Ut,Kr as Wt,Ks as Gt,Kt,L as qt,La as Jt,Li as Yt,Ln as Xt,Lo as Zt,Lr as Qt,Lt as $t,Ma as en,Mi as tn,Mn as nn,Mo as rn,Mr as an,Mt as on,N as sn,Na as cn,Ni as ln,Nn as un,No as dn,Nr as fn,Ns as pn,Nt as mn,Oa as hn,Oi as gn,On as _n,Oo as vn,Or as yn,Ot as bn,P as xn,Pa as Sn,Pn as Cn,Po as wn,Pr as Tn,Ps as En,Pt as Dn,Q as On,Qi as kn,Qn as An,Qo as jn,Qr as Mn,Qs as Nn,Qt as Pn,Ra as Fn,Ri as In,Rn as Ln,Ro as Rn,Rr as zn,Rs as Bn,Rt as Vn,S as Hn,Sa as Un,Si as Wn,So as Gn,Sr as Kn,Ss as qn,St as Jn,Ta as Yn,To as Xn,Tr as Zn,Ts as Qn,Tt as $n,Ua as er,Uo as tr,Ur as nr,Us as rr,Ut as ir,Va as ar,Vi as or,Vr as sr,Vt as cr,Wa as lr,Wi as ur,Wn as dr,Wo as fr,Ws as pr,Xa as mr,Xi as hr,Xo as gr,Xr as _r,Ya as vr,Yi as yr,Yn as br,Yo as xr,Yr as Sr,Ys as Cr,Z as wr,Za as Tr,Zi as Er,Zn as U,Zr as Dr,Zs as Or,Zt as kr,_ as Ar,_a as jr,_i as Mr,_n as Nr,_o as Pr,_r as Fr,_s as Ir,_t as Lr,aa as Rr,ac as zr,ai as Br,an as Vr,ao as Hr,ar as Ur,at as Wr,ba as Gr,bi as Kr,bo as qr,br as Jr,bs as Yr,bt as Xr,ca as Zr,ci as Qr,cn as $r,co as ei,cr as ti,cs as ni,ct as ri,da as ii,di as ai,do as oi,dr as si,ds as ci,ea as li,ec as ui,ei as di,en as W,eo as fi,er as pi,es as mi,et as hi,fa as gi,fi as _i,fo 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,hr as Pi,hs as Fi,ht as Ii,ii as Li,in as G,io as Ri,ir as zi,is as Bi,it as Vi,ja as Hi,ji as Ui,jn as Wi,jr as Gi,js as Ki,ka as qi,ki as Ji,kn as Yi,ko as Xi,kr as Zi,ks as Qi,kt as $i,la as ea,li as ta,ln as na,lo as ra,lr as ia,ls as aa,lt as oa,ma as sa,mi as ca,mn as la,mo as ua,ms as da,mt as fa,na as pa,nc as ma,no as ha,ns as ga,nt as _a,oa as va,oi as ya,on as ba,oo as xa,or as Sa,os as Ca,ot as wa,pa as Ta,pi as Ea,po as Da,pr as K,ps as Oa,pt as ka,qa as Aa,qi as ja,qn as Ma,qo as Na,qr as Pa,qs as Fa,qt as Ia,ra as La,rc as q,ri as Ra,ro as za,rs as Ba,rt as Va,sa as Ha,sn as Ua,so as Wa,sr as Ga,ss as Ka,st as qa,ta as Ja,tc as Ya,ti as Xa,to as Za,ts as Qa,tt as $a,ua as eo,ui as to,un as no,uo as ro,ur as io,ut as ao,v as oo,va as so,vi as co,vn as lo,vo as uo,vr as fo,vs as po,vt as mo,wa as ho,wi as go,wo as _o,wr as vo,ws as yo,xa as bo,xi as xo,xo as So,xr as Co,xs as wo,xt as To,y as Eo,ya as Do,yi as Oo,yn as ko,yr as Ao,ys as jo,za as Mo,zi as No,zn as Po,zt as Fo}from"./ui-components-BrY5joKQ.js";import{a as Io,n as Lo,o as Ro,r as J}from"./vendor-ui-utils-rQOI1gAo.js";import{n as zo,r as Bo,t as Vo}from"./data-adapter-3AJO7A2o.js";import{i as Ho,n as Uo,r as Wo,t as Go}from"./plugin-form-BABEMaum.js";import{a as Ko,c as qo,i as Jo,l as Yo,n as Xo,o as Zo,s as Qo,u as $o}from"./assistantBus-B-xBT6j1.js";import{a as es,c as ts,i as ns,n as rs,o as is,r as as,s as os,t as ss}from"./RecentItemsProvider-DiJIrHwK.js";import{n as cs,r as ls,t as us}from"./ui-layout-KICrO2Oe.js";import{a as ds,d as fs,f as ps,i as ms,t as hs,u as gs}from"./plugin-chatbot-Cy3tiXkg.js";import{C as _s,S as vs,_ as ys,a as bs,b as xs,c as Ss,d as Cs,f as ws,g as Ts,h as Es,i as Y,l as Ds,m as Os,n as ks,o as As,p as js,r as Ms,s as Ns,t as Ps,u as Fs,v as Is,w as Ls,x as Rs,y as zs}from"./mergeServerFields-DUkbynPg.js";import{a as Bs,i as Vs,n as Hs,r as Us,t as Ws}from"./runtime-config-ir5bt3TX.js";import{c as Gs,n as Ks,o as qs,r as Js,s as Ys}from"./plugins-views-CBO5qxO-.js";import{i as Xs,r as Zs}from"./plugin-grid-BxyuFeJP.js";import{a as Qs,c as $s,i as ec,l as tc,n as nc,o as rc,r as ic,s as ac,t as oc,u as sc}from"./plugin-view-BykLknWa.js";import{n as cc}from"./plugin-dashboard-PA0xf59v.js";var X=e(r(),1),lc=e(c(),1),Z=_(),uc={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`}]}]},dc=()=>(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)(P,{schema:uc})]}),fc={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`}]}},pc={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},mc=()=>(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)(P,{schema:fc})})]}),(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)(P,{schema:pc})})]})]});function hc({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 Vo({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)(I.Provider,{value:n,children:e})}var gc=300*1e3,_c=[`app`,`view`],vc={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},yc=`objectui:metadata:`;function bc(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var xc=bc();function Sc(...e){xc&&console.debug(`[MetadataProvider]`,...e)}function Cc(e){return Array.isArray(e)?e:e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function wc(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Tc(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Ec(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function Dc(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)Ec(e)&&r.add(e.object);for(let e of t){if(Ec(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 Oc(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:Ho(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 kc(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Ac(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(yc+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function jc(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(yc+e,JSON.stringify(t))}catch{}}function Mc({children:e,adapter:t,ttlMs:n=gc}){let r=(0,X.useRef)(new Map),i=(0,X.useRef)(new Map),a=(0,X.useRef)(t);a.current=t;let o=$o(),s=(0,X.useMemo)(()=>o?new zo({baseUrl:``,previewDrafts:!0}):null,[o]),c=(0,X.useRef)(s);c.current=s;let[l,u]=(0,X.useState)(0),d=(0,X.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>u(e=>e+1)):Promise.resolve().then(()=>u(e=>e+1))},[]);(0,X.useEffect)(()=>{r.current.clear(),i.current.clear(),d()},[o,d]);let f=(0,X.useCallback)(e=>{let t=r.current.get(e);return t||(t=kc(),r.current.set(e,t)),t},[]),p=(0,X.useCallback)(e=>{let t=f(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=c.current,o=(i?i.list(e):a.current.getClient().meta.getItems(e)).then(n=>{let a=Cc(n);t.items=a,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of a)Tc(e)&&t.byName.set(e.name,e);return e===`app`&&!i&&jc(e,a),Sc(`fetched type=${e} items=${a.length} in ${Date.now()-r}ms`),d(),a}).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),d(),[]});return t.promise=o,o},[d,f,n]),m=(0,X.useCallback)((e,t)=>{let n=f(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(),l=c.current,u=(l?l.get(e,t):a.current.getClient().meta.getItem(e,t)).then(i=>{let a=wc(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,u),u},[f]),h=(0,X.useCallback)(async e=>{if(e){let t=f(e);t.fetchedAt=0,t.byName.clear(),await p(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(),p(e)}))},[p,f]),g=(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}`)),d())},[d]);(0,X.useEffect)(()=>{if(o)return Jo(({type:e})=>{g(e)})},[o,g]);let[_,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!1,t=o?null:Ac(`app`);if(t){let e=f(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Tc(n)&&e.byName.set(n.name,n);d(),v(!1)}return(async()=>{for(let t of _c)try{await p(t),e||b(null)}catch(t){e||b(t instanceof Error?t:Error(String(t)))}e||v(!1)})(),()=>{e=!0}},[t,p,f,d,o]);let x=(0,X.useMemo)(()=>{let e=e=>{let t=f(e);return t.status===`idle`&&p(e),t.items};return{apps:f(`app`).items,get objects(){let t=e(vc.objects),n=e(`view`);return Oc(n.length?Dc(t,n):t)},get dashboards(){return e(vc.dashboards)},get reports(){return e(vc.reports)},get pages(){return e(vc.pages)},loading:_,error:y??f(`app`).error,refresh:h,invalidate:g,ensureType:p,getItem:m,getItemsByType:t=>e(t),getTypeStatus:e=>f(e).status}},[l,_,y,p,m,f,h,g]);return(0,Z.jsx)(te.Provider,{value:x,children:e})}var Nc=(0,X.createContext)(null);function Pc({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 V({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)(Nc.Provider,{value:a,children:(0,Z.jsx)(re,{scope:o,children:e})})}function Fc(){let e=(0,X.useContext)(Nc);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new V(e)}}return e}function Ic(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 Lc({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let c=v(),{appName:l}=s(),{t:u}=B(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=F({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?(J.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0}):(J.error(u(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1,error:`${o} failed`})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:u(`objectActions.noRecordId`)};try{return await n.delete(e,o),i?.(),J.success(u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return J.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),h.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),h.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[h,e,n,r,i,c,d,u,t]),{execute:f,create:(0,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 Rc=(0,X.createContext)(void 0);function zc({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)(Rc.Provider,{value:s,children:e})}function Bc(){return(0,X.useContext)(Rc)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function Vc(e){let{setRecordTitle:t}=Bc();(0,X.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var Hc=`objectui-favorites`,Uc=`objectui-nav-pins`,Wc=20,Gc=20;function Kc(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>Gc&&(r=!0)):(t++,t>Wc&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<Gc&&(i.push(t),o++):a<Wc&&(i.push(t),a++);return i}function qc(e){try{let t=localStorage.getItem(es(Hc,e));return t?JSON.parse(t):[]}catch{return[]}}function Jc(e,t){try{localStorage.setItem(es(Hc,t),JSON.stringify(e))}catch{}}function Yc(e){let t;try{t=localStorage.getItem(Uc)}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(Uc)}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 Xc=(0,X.createContext)(null);function Zc({children:e}){let{user:t}=S(),n=t?.id??null,r=ts(`favorites`),[i,a]=(0,X.useState)(()=>qc(n));(0,X.useEffect)(()=>{a(qc(n))},[n]),os(es(Hc,n),e=>{a(Array.isArray(e)?Kc(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=Kc((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=qc(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=Kc([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=Yc(f);h&&(f=Kc(m),p=!0),a(f),Jc(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,X.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=Yc(e);if(!r)return e;let i=Kc(t);return Jc(i,n),i})},[r,n]);let s=(0,X.useMemo)(()=>ns(async e=>{r&&await r.save(e)},500),[r]);(0,X.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,X.useCallback)(e=>{Jc(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=Kc([{...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):Kc([{...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)(Xc.Provider,{value:h,children:e})}function Qc(){return(0,X.useContext)(Xc)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var $c=(0,X.createContext)({theme:`system`,setTheme:()=>null});function el({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)($c.Provider,{...r,value:o,children:e})}var tl=()=>{let e=(0,X.useContext)($c);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function nl(){return(0,Z.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function rl({children:e}){return(0,Z.jsx)(el,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Z.jsx)(zc,{children:(0,Z.jsx)(as,{children:(0,Z.jsx)(Zc,{children:(0,Z.jsx)(ss,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(nl,{}),children:e})})})})})})}function il({children:e}){return(0,Z.jsx)(hc,{children:(0,Z.jsx)(qo,{children:(0,Z.jsx)(al,{children:e})})})}function al({children:e}){let t=ye(),{language:n}=B(),r=(0,X.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Z.jsx)(ce,{dataSource:t,children:(0,Z.jsxs)(Mc,{adapter:t,children:[(0,Z.jsx)(ol,{}),e]},n)}):(0,Z.jsx)(nl,{})}function ol(){let{user:e}=S(),t=ye(),n=is();return(0,X.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=Bo({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Bo({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 sl({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=S();return r?(0,Z.jsx)(nl,{}):((n??[]).length>0||t)&&!t?(0,Z.jsx)(i,{to:`/organizations`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function cl(){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 ll=(0,X.lazy)(()=>d(()=>import(`./ConsoleFloatingChatbot-CiODZIcp.js`),__vite__mapDeps([0]),import.meta.url)),ul=()=>{d(()=>import(`./ConsoleFloatingChatbot-CiODZIcp.js`),__vite__mapDeps([0]),import.meta.url)};function dl(e){let[t,n]=(0,X.useState)(!1),{t:r}=B(),{openSeq:i}=Ko(),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)(ll,{...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:ul,onFocus:ul,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 fl(e){let t=_s(),[n,r]=(0,X.useState)(!1);return{publishAll:(0,X.useCallback)(async()=>{r(!0);try{let n=(await t.listDrafts?.({})||[]).filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}));if(n.length===0)return J.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],i=n.filter(e=>e.packageId===null),a=[],o=[],s=0,c=e=>{if(e){e.seedError&&a.push(e.seedError),typeof e.seededRows==`number`&&(s+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&o.push(t.message)}};for(let e of r){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}`);c(ds(n))}let l=[...i.filter(e=>e.type!==`seed`),...i.filter(e=>e.type===`seed`)];for(let e of l){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&a.push(n.error??`${e.name}: sample data failed to load`)}return o.length>0?J.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:o[0]}):a.length>0?J.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:a[0]}):J.success(s>0?e(`home.pendingDrafts.publishedVerified`,{count:s,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),{ok:!0,attempted:n.length}}catch(t){return J.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function pl(){let e=await fetch(`/api/v1/meta/_drafts`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`_drafts HTTP ${e.status}`);let t=await e.json();return(Array.isArray(t)?t:t?.drafts??[]).filter(e=>typeof e?.type==`string`&&typeof e?.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}))}async function ml(e){let t=await fetch(`/api/v1/meta/${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`published list HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.items??[];return new Set(r.map(e=>typeof e?.name==`string`?e.name:null).filter(e=>e!==null))}function hl({open:e,onOpenChange:t}){let{t:n}=B(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),s=(0,X.useCallback)(async()=>{i(null),o(null);try{let e=await pl();i(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await ml(e)}catch{return}i(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){o(e.message)}},[]);(0,X.useEffect)(()=>{e&&s()},[e,s]);let c=new Map;for(let e of r??[]){let t=c.get(e.type)??[];t.push(e),c.set(e.type,t)}return(0,Z.jsx)(on,{open:e,onOpenChange:t,children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Z.jsxs)(yt,{children:[(0,Z.jsx)(Pt,{children:n(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Z.jsx)(Dn,{children:n(`preview.changes.description`,{defaultValue:`What publishing will change. New items are added; updates overwrite the live version.`})})]}),(0,Z.jsx)(`div`,{className:`mt-4 flex flex-col gap-4 overflow-y-auto px-4 pb-6`,children:a?(0,Z.jsxs)(`p`,{className:`text-sm text-destructive`,children:[n(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,a]}):r===null?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(H,{className:`h-4 w-4 animate-spin`}),n(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):r.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...c.entries()].map(([e,t])=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:[e,` · `,t.length]}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-sm`,children:[e.kind===`new`?(0,Z.jsx)(Gn,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Z.jsx)(Ze,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Z.jsx)(H,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),e.kind?(0,Z.jsx)(U,{variant:`outline`,className:e.kind===`new`?`border-emerald-200 bg-emerald-50 text-emerald-700`:`border-amber-200 bg-amber-50 text-amber-700`,children:e.kind===`new`?n(`preview.changes.kindNew`,{defaultValue:`New`}):n(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]},`${e.type}:${e.name}`))})]},e))})]})})}function gl(){let e=$o(),t=u(),n=v(),{t:r}=B(),{publishAll:i,publishing:a}=fl(r),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);if((0,X.useEffect)(()=>{if(!e)return;let t=!1;return fetch(`/api/v1/meta/_drafts`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`}).then(e=>e.ok?e.json():null).then(e=>{if(t||!e)return;let n=Array.isArray(e)?e:e?.drafts??[];l(Array.isArray(n)?n.length:null)}).catch(()=>{}),()=>{t=!0}},[e,t.pathname]),!e)return null;let d=()=>{Yo();let e=new URLSearchParams(t.search);e.delete(Qo);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})};return(0,Z.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`draft-preview-bar`,children:[(0,Z.jsx)(nt,{className:`h-4 w-4 shrink-0`}),(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:r(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>s(!0),"data-testid":`draft-preview-changes`,children:[(0,Z.jsx)(za,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof c==`number`?` (${c})`:``]}),(0,Z.jsxs)(K,{size:`sm`,onClick:async()=>{(await i()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},disabled:a,"data-testid":`draft-preview-publish`,children:[(0,Z.jsx)(tt,{className:`mr-1 h-3.5 w-3.5`}),a?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publish`,{defaultValue:`Publish`})]}),(0,Z.jsx)(hl,{open:o,onOpenChange:s}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,Z.jsx)(Jr,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]})}function _l(){let e=$o(),{appName:t}=s(),n=u(),{apps:r,refresh:i}=se(),{t:a}=B(),[o,c]=(0,X.useState)(!1);if(e)return null;let l=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!l)return null;let d=(r??[]).find(e=>e?.name===l);return!d||d.hidden!==!0?null:(0,Z.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`unpublished-app-bar`,children:[(0,Z.jsx)(vn,{className:`h-4 w-4 shrink-0`}),(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:a(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),(0,Z.jsxs)(K,{size:`sm`,onClick:async()=>{c(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(l)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...d,hidden:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}J.success(a(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){J.error(`${a(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{c(!1)}},disabled:o,"data-testid":`unpublished-app-publish`,children:[(0,Z.jsx)(tt,{className:`mr-1 h-3.5 w-3.5`}),o?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]})}function vl(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 yl=new Set(On),bl=new Map;function xl(e){if(!e)return Zt;let t=bl.get(e);if(t)return t;let n=vl(e);if(!yl.has(n))return bl.set(e,Zt),Zt;let r=e=>X.createElement(wr,{name:n,fallback:Zt,...e});return r.displayName=`LucideIcon(${e})`,bl.set(e,r),r}var Sl=20;function Cl(e,t=``){let{href:n,external:r}=cs(e,t);return r?n:!n||n===`#`?``:n}function wl(e){return`nav:${e}`}function Tl(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Qc(),a=(0,X.useCallback)((e,i,a,o)=>{let s=wl(e);i?(a&&t({id:s,label:a.label,href:Cl(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<Sl;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 El(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 Dl(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 Ol(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 kl=new Set([`created_by`,`updated_by`,`owner_id`]);function Al(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function jl(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 Al(e.fields)){if(!o)continue;let s=o.type;if(s!==`lookup`&&s!==`master_detail`||(o.reference_to||o.reference)!==n||kl.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 Ml(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 Nl(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var Pl=`\0`,Fl=`[-\\u2013\\u2014|/·,:]`;function Il(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===``?Pl:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Fl}\\s*${Pl}`,`g`),o=RegExp(`${Pl}\\s*${Fl}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(Pl,`g`),``).replace(/\s+/g,` `).trim(),i}function Ll(e,t){if(e?.titleFormat){let n=Il(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 Rl=`__all__`;function zl(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Bl(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 Vl(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=zl(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 Hl(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=Bl(s),l=[],u=new Set;for(let e of c){if(!Vl(e,o))continue;let t=zl(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=zl(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 Ul(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===Rl?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)(Wl,{def:e,value:c[e.id],onChange:t=>s(e,t),t:n},e.id))})}}function Wl({def:e,value:t,onChange:n,t:r}){let i=Hl(e),a=xl(e.icon),o=Ml(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)(Vn,{value:l?t:``,onValueChange:n,children:[(0,Z.jsx)(cr,{"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)(Dt,{placeholder:c,className:`truncate`})]})}),(0,Z.jsx)(Fo,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]})}var Gl=X.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=$n(),{t:s}=B(),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:q(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Z.jsx)(je,{}),(0,Z.jsx)(`span`,{className:`sr-only`,children:c})]})});Gl.displayName=`LocalizedSidebarTrigger`;function Kl(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 ql(e){return e.componentRef===`metadata:directory`}function Jl(e){return e.componentRef===`developer:packages`}function Yl(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 Xl({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=$n(),r=u(),{t:i}=B(),{objectLabel:a,dashboardLabel:o,navGroupLabel:s,viewLabel:c}=zr(),{context:l,currentAppName:d}=Bc(),{user:f}=S(),p=x();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:m}=rs(),{favorites:g,removeFavorite:_}=Qc(),{apps:v,objects:y}=se(),b=v||[],C=b.filter(e=>e.active!==!1&&e.hidden!==!0),w=b.find(t=>t.name===(e||d)&&t.active!==!1)||C[0],{applyOrder:T,handleReorder:E}=Kl(w?.name||`home`),{togglePin:O,applyPins:k}=Tl(),A=w?.areas||[],[j,M]=X.useState(()=>A.length>0?A[0].id:null);X.useEffect(()=>{A.length>0?M(e=>A.some(t=>t.id===e)?e:A[0].id):M(null)},[w?.name,A.length]);let ee=A.find(e=>e.id===j)?.navigation||w?.navigation||[],{contextValues:N,element:P}=Ul(w?.name||`home`,w?.contextSelectors,i),te=X.useMemo(()=>{let e=[{id:`home-dashboard`,label:i(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}];if(p){let t=[{id:`sys-settings`,label:i(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup`,icon:`settings`},{id:`sys-apps`,label:i(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:i(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:i(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/system/metadata/object`,icon:`database`},{id:`sys-users`,label:i(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:i(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:i(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:i(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:i(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,children:t})}return e},[i,p]),ne=l===`home`?te:ee,F=l===`app`&&w?`/apps/${w.name}`:``,re=l===`app`&&w?.name===`studio`,ie=X.useMemo(()=>{if(!re)return``;let e=new URLSearchParams(r.search).get(`package`)||N.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[N.active_package,re,r.search]),ae=X.useMemo(()=>{if(l!==`app`||w?.name!==`studio`)return ne;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(ql(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:Jl(n)?[{...n,type:`url`,label:e,url:`${F}/component/developer/packages${ie}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(ne).flatMap(e=>Yl(e)?e.children??[]:[e])},[w?.name,F,l,ne,ie,i]),oe=X.useMemo(()=>k(T(ae)),[ae,T,k]),[I,ce]=X.useState(!1),{evaluator:le}=Fc(),ue=X.useCallback(e=>Ic(e,le),[le]),{can:de}=D(),fe=X.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return de(n,r)}),[de]),pe=X.useMemo(()=>new Set((y||[]).map(e=>e?.name).filter(Boolean)),[y]),me=X.useCallback((e,t)=>e===`object`?pe.size===0?!0:pe.has(t):!0,[pe]),he=re&&r.pathname.replace(/\/+$/,``)===F;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)(mo,{className:`border-b p-1.5`,children:(0,Z.jsx)(Xr,{children:(0,Z.jsx)(et,{children:(0,Z.jsx)(Jn,{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)(Ft,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Z.jsx)(ka,{className:`pt-2`,children:(0,Z.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:l===`app`&&w?(0,Z.jsxs)(Z.Fragment,{children:[P&&(0,Z.jsx)(Ii,{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:P})})}),re&&(0,Z.jsx)(Ii,{children:(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:(0,Z.jsx)(et,{children:(0,Z.jsx)(Jn,{asChild:!0,isActive:he,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,Z.jsxs)(h,{to:{pathname:F,search:ie},children:[(0,Z.jsx)(Ft,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),A.length>1&&(0,Z.jsxs)(Ii,{children:[(0,Z.jsxs)(Lr,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Jt,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:A.map(e=>{let t=xl(e.icon);return(0,Z.jsx)(et,{children:(0,Z.jsxs)(Jn,{isActive:e.id===j,tooltip:e.label,onClick:()=>M(e.id),children:[(0,Z.jsx)(t,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Z.jsx)(us,{items:oe,basePath:F,evaluateVisibility:ue,checkPermission:fe,checkCapability:me,enablePinning:!t,onPinToggle:O,enableReorder:!t,onReorder:E,resolveObjectLabel:(e,t)=>a({name:e,label:t}),resolveDashboardLabel:(e,t)=>o({name:e,label:t}),resolveGroupLabel:w?(e,t)=>s(w.name,e,t):void 0,resolveItemLabel:w?(e,t)=>w.name===`studio`&&t===i(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:s(w.name,e,t):void 0,resolveViewLabel:(e,t,n)=>c(e,t,n),t:i,templateContext:{currentUserId:f?.id??null,contextValues:N}}),m.length>0&&(0,Z.jsxs)(Ii,{children:[(0,Z.jsxs)(Lr,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ce(e=>!e),children:[(0,Z.jsx)(Fi,{className:`h-3 w-3 transition-transform duration-150 ${I?`rotate-90`:``}`}),(0,Z.jsx)(gr,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),I&&(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:m.slice(0,5).map(e=>(0,Z.jsx)(et,{children:(0,Z.jsx)(Jn,{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))})})]}),g.some(e=>e.type!==`nav`)&&(0,Z.jsxs)(Ii,{children:[(0,Z.jsxs)(Lr,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Pe,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:g.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Z.jsxs)(et,{children:[(0,Z.jsx)(Jn,{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)(To,{showOnHover:!0,onClick:t=>{t.stopPropagation(),_(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Z.jsx)(di,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ii,{children:(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:te.map(e=>{let t=xl(e.icon),n=r.pathname===e.url;return(0,Z.jsx)(et,{children:(0,Z.jsx)(Jn,{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)})})})}),g.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Z.jsxs)(Ii,{children:[(0,Z.jsxs)(Lr,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(Pe,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Z.jsx)(Oi,{children:(0,Z.jsx)(Xr,{children:g.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Z.jsxs)(et,{children:[(0,Z.jsx)(Jn,{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)(To,{showOnHover:!0,onClick:t=>{t.stopPropagation(),_(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Z.jsx)(di,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Z.jsx)(fa,{className:`border-t p-1`,children:(0,Z.jsx)(Gl,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Zl(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 Ql=0;function $l(){return Ql+=1,`conflict-${Date.now()}-${Ql}`}var eu=0;function tu(){return eu+=1,`ver-${Date.now()}-${eu}`}function nu(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:tu(),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:tu(),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:tu(),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:tu(),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:$l()};o(e=>[...e,t])},[]),clearHistory:(0,X.useCallback)(()=>{i([]),o([])},[])}}var ru={sm:24,md:32,lg:40},iu={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function au(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function ou({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=ru[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`}}):au(e.userName),r&&X.createElement(`span`,{style:{...m,backgroundColor:iu[e.status]}}))))}var su=X.createContext({});function cu(){let e=X.useContext(su),[t,n]=X.useState([]);return X.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function lu(e,t){let n=X.useContext(su),[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 uu(){let{theme:e,setTheme:t}=tl(),{t:n}=B();return(0,Z.jsxs)(Vr,{children:[(0,Z.jsx)(la,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Z.jsx)(_r,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Z.jsx)(ii,{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)(ba,{align:`end`,children:[(0,Z.jsxs)($r,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Z.jsx)(_r,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Z.jsxs)($r,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Z.jsx)(ii,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Z.jsxs)($r,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Z.jsx)(gi,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Z.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var du=[{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 fu(){let{t:e,language:t,changeLanguage:n}=B();return(0,Z.jsxs)(Vr,{children:[(0,Z.jsx)(la,{asChild:!0,children:(0,Z.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Z.jsx)(Za,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Z.jsx)(ba,{align:`end`,className:`max-h-72 overflow-y-auto`,children:du.map(e=>(0,Z.jsxs)($r,{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 pu={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:aa},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:H},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:H},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:Qe},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:Qe}};function mu({state:e,className:t}){let n=pu[e],{t:r}=B(),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:q(`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:q(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function hu(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 gu({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:o}=B(),c=v(),l=s(),{currentAppName:u}=Bc(),[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)(kr,{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)(Je,{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)(Pn,{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)(hi,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,Z.jsxs)(_a,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Z.jsxs)(Va,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(Je,{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)(Va,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(Li,{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)(Va,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Z.jsx)(ma,{className:`h-3.5 w-3.5`}),o(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Z.jsxs)($a,{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:hu(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)($a,{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)(Li,{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)($a,{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:[hu(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 _u({activeAppName:e,onAppChange:t}){let{apps:n}=se(),{t:r}=B(),{appLabel:i}=zr(),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)(Vr,{children:[(0,Z.jsx)(la,{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:Ml(s.label,r)})}),(0,Z.jsx)(Ir,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Z.jsxs)(ba,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Z.jsx)(na,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Z.jsx)(no,{}),o.map(e=>{let n=xl(e.icon),a=i({name:e.name,label:Ml(e.label,r)}),o=s.name===e.name;return(0,Z.jsxs)($r,{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)(po,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var vu=(0,X.createContext)(null);function yu({children:e}){let[t,n]=(0,X.useState)(null),r=(0,X.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Z.jsx)(vu.Provider,{value:r,children:e})}function bu(){return(0,X.useContext)(vu)?.value??null}function xu(e){let t=(0,X.useContext)(vu),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 Su(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),[]);xu((0,X.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function Cu(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function wu(){return(0,Z.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Tu=[];function Eu({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}=he(),{user:_,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:C,isOrganizationsLoading:w}=S(),T=ye(),{t:E}=B(),{objectLabel:D,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:M,appLabel:ee}=zr(),{apps:N,dashboards:P,pages:te,reports:ne}=se(),{currentAppName:F,recordTitle:re}=Bc(),ie=bu(),[ae,oe]=(0,X.useState)(null),[I,ce]=(0,X.useState)([]),le=(0,X.useRef)(!1),ue=(0,X.useRef)(!1),de=(0,X.useRef)(!0);(0,X.useEffect)(()=>(de.current=!0,()=>{de.current=!1}),[]);let fe=(0,X.useRef)(!1),pe=(0,X.useRef)(!1),me=(0,X.useRef)(!1),[ge,_e]=(0,X.useState)(0),L=(0,X.useRef)(!1),R=(0,X.useCallback)(async()=>{if(!T||!d)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!le.current&&!me.current){me.current=!0;try{let t=await T.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(le.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&oe(e)}}catch{}finally{me.current=!1}}},[T,d]);(0,X.useEffect)(()=>{R()},[R]),(0,X.useEffect)(()=>{if(!T||!d||!_?.id||ue.current)return;let e=!1,t=null,n=1e4,r=n,i=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`,a=new Set([`read`,`clicked`,`dismissed`]),o=async()=>{if(!fe.current){fe.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(!de.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)})}ce(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)){ue.current=!0;return}r=Math.min(r*2,12e4)}finally{fe.current=!1}}},s=()=>{if(e||ue.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||L.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&&!pe.current){pe.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){L.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);de.current&&_e(a.size)}catch{}finally{pe.current=!1}}},a=()=>{n||L.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[d,_?.id]);let z=I.reduce((e,t)=>e+ +!t.is_read,0),ve=(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]),V=(0,X.useCallback)(async e=>{let t=I.find(t=>t.id===e);if(ce(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await ve(t,new Date().toISOString())}catch{}},[I,ve]),be=(0,X.useCallback)(async()=>{let e=I.filter(e=>!e.is_read);if(!e.length)return;ce(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>ve(e,t).catch(()=>{})))},[I,ve]),xe=cu(),Se=i??(xe.length>0?xe:Tu),Ce=a??ae??[],we=w||(x??[]).length>0||!!C,Te=f.pathname.split(`/`).filter(Boolean),Ee=p.appName||Te[1],De=Te[2],Oe=`/apps/${Ee}`,ke=n??[],Ae=o||F||Ee,je=(N||[]).find(e=>e.name===Ae),Ne=new Set,Pe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ne.add(t.objectName),t.children&&Pe(t.children)};Pe(je?.navigation||[]);for(let e of je?.areas||[])Pe(e.navigation||[]);let Fe=(Ne.size>0?ke.filter(e=>Ne.has(e.name)):ke.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:D(e),href:`${Oe}/${e.name}`})),Ie=[];if(d){if(De===`dashboard`){if(Ie.push({label:E(`console.breadcrumb.dashboards`),href:Oe}),Te[3]){let e=Te[3],t=(P||[]).find(t=>t.name===e)?.label||Cu(e);Ie.push({label:k({name:e,label:t})})}}else if(De===`page`){if(Ie.push({label:E(`console.breadcrumb.pages`),href:Oe}),Te[3]){let e=Te[3],t=(te||[]).find(t=>t.name===e)?.label||Cu(e);Ie.push({label:A({name:e,label:t})})}}else if(De===`report`){if(Ie.push({label:E(`console.breadcrumb.reports`),href:Oe}),Te[3]){let e=Te[3],t=(ne||[]).find(t=>t.name===e)?.label||Cu(e);Ie.push({label:j({name:e,label:t})})}}else if(De===`system`)Ie.push({label:E(`console.breadcrumb.system`)}),Te[3]&&Ie.push({label:Cu(Te[3])});else if(De){let e=ke.find(e=>e.name===De);if(e){if(Ie.push({label:D(e),href:`${Oe}/${De}`,siblings:Fe}),Te[3]===`record`&&Te[4]){let e=Te[4].length>12?`${Te[4].slice(0,8)}…`:Te[4],t=re?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Ie.push({label:n||`#${e}`})}else if(Te[3]===`view`&&Te[4]){let t=Te[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Cu(t),i=M(e.name,t,r);Ie.push({label:i})}}}}let Le=Ie[Ie.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:q(`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:Hs(),children:(0,Z.jsx)(Jt,{className:`h-4 w-4`})}),l===`home`&&(0,Z.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:Hs()}),l===`orgs`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(wu,{}),(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)(Gl,{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)(wu,{})}),(0,Z.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Z.jsx)(_u,{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)(wu,{})}),(0,Z.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Ie.map((e,t)=>{let n=t===Ie.length-1;return(0,Z.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Z.jsx)(wu,{}),e.siblings&&e.siblings.length>1?(0,Z.jsxs)(Vr,{children:[(0,Z.jsxs)(la,{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)(Ir,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Z.jsxs)(ba,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Z.jsx)(na,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Z.jsx)(no,{}),e.siblings.map(e=>(0,Z.jsx)($r,{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)}),ie&&ie.views.length>0?ie.views.length>1?(0,Z.jsxs)(Vr,{children:[(0,Z.jsx)(la,{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:ie.triggerLabel??ie.views.find(e=>e.id===ie.activeViewId)?.label??Le}),(0,Z.jsx)(Ir,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Z.jsx)(ba,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:ie.views.map(e=>{let t=e.id===ie.activeViewId;return(0,Z.jsxs)($r,{onSelect:()=>{t||ie.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)(st,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Z.jsx)(po,{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:ie.triggerLabel??ie.views[0].label}):(0,Z.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Le})]})]}),(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)(mu,{state:r}),d&&Se.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)(ou,{users:Se,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)(Oo,{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)(Oo,{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)(gu,{notifications:I,unreadCount:z,pendingApprovalsCount:ge,activities:Ce,onMarkAllRead:be,onMarkRead:V}),(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)(Nt,{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)(Bi,{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)(Vr,{children:[(0,Z.jsx)(la,{asChild:!0,children:(0,Z.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Z.jsxs)(An,{className:`h-7 w-7 rounded-full`,children:[(0,Z.jsx)(pi,{src:_?.image,alt:_?.name??`User`}),(0,Z.jsx)(Me,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:O(_)})]})})}),(0,Z.jsxs)(ba,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Z.jsx)(na,{className:`p-0 font-normal`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Z.jsxs)(An,{className:`h-8 w-8 rounded-lg`,children:[(0,Z.jsx)(pi,{src:_?.image,alt:_?.name??`User`}),(0,Z.jsx)(Me,{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)(no,{}),(0,Z.jsxs)(Ua,{children:[(0,Z.jsxs)($r,{onClick:()=>m(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Z.jsx)(yn,{className:`mr-2 h-4 w-4`}),E(`user.profile`,{defaultValue:`Profile`})]}),we&&(0,Z.jsxs)($r,{onClick:()=>m(`/organizations`),className:`cursor-pointer`,children:[(0,Z.jsx)(En,{className:`mr-2 h-4 w-4`}),E(`organizations.mine`,{defaultValue:`My Organizations`})]}),(N||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=xl(e.icon),n=ee({name:e.name,label:Ml(e.label,E)});return(0,Z.jsxs)($r,{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)(no,{}),(0,Z.jsx)(na,{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)(uu,{})]}),(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)(fu,{})]}),b&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(no,{}),(0,Z.jsxs)($r,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Z.jsx)(Yn,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Du=768,Ou=1024;function ku(){let{setOpen:e,isMobile:t}=$n(),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>=Du&&t<Ou;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function Au({children:e}){return ku(),(0,Z.jsx)(Z.Fragment,{children:e})}function ju({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Ml(n?.label)||t,{isAiEnabled:c}=ie(),l=c||!1,u=Vs().features.aiStudio===!1&&n?.defaultAgent===`metadata_assistant`?void 0:n?.defaultAgent,{setContext:d,setCurrentAppName:f}=Bc();return(0,X.useEffect)(()=>{d(`app`),f(t)},[d,f,t]),(0,Z.jsx)(yu,{children:(0,Z.jsxs)(ls,{sidebar:(0,Z.jsx)(Xl,{activeAppName:t,onAppChange:r}),navbar:(0,Z.jsx)(Eu,{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?`${Ml(n.label)} — ${Hs()}`:void 0}:void 0,children:[(0,Z.jsxs)(Au,{children:[(0,Z.jsx)(gl,{}),(0,Z.jsx)(_l,{}),e]}),l&&(0,Z.jsx)(dl,{appLabel:s,appName:t,defaultAgent:u,objects:i,userId:o})]})})}function Mu({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:q(`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:q(`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 Nu({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}=tl(),{evaluator:p}=Fc(),{t:m}=B();(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=Pu(t?.navigation||[]).filter(e=>Ic(e.visible??e.visibleOn,p)),{results:x,isSearching:C}=fe({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:Ll}),{recentItems:w}=rs(),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)(_n,{open:a,onOpenChange:o,children:[(0,Z.jsx)(Wi,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Z.jsxs)(un,{children:[(0,Z.jsx)(Yi,{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)(nn,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Z.jsx)(Oo,{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=xl(e.icon);return(0,Z.jsxs)(nn,{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=xl(e.icon);return(0,Z.jsxs)(nn,{value:`object ${Ml(e.label,m)} ${e.objectName}`,onSelect:()=>y(()=>u(cs(e,h,_).href)),children:[(0,Z.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:Ml(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)(nn,{value:`dashboard ${Ml(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(cs(e,h,_).href)),children:[(0,Z.jsx)(kt,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:Ml(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)(nn,{value:`page ${Ml(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(cs(e,h,_).href)),children:[(0,Z.jsx)(uo,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:Ml(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)(nn,{value:`report ${Ml(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(cs(e,h,_).href)),children:[(0,Z.jsx)(Qn,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:Ml(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Cn,{}),(0,Z.jsx)(ze,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=xl(e.icon);return(0,Z.jsxs)(nn,{value:`app ${Ml(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:Ml(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)(Cn,{}),(0,Z.jsxs)(ze,{heading:m(`console.commandPalette.preferences`),children:[(0,Z.jsxs)(nn,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,Z.jsx)(_r,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,Z.jsxs)(nn,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,Z.jsx)(ii,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,Z.jsxs)(nn,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,Z.jsx)(gi,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,Z.jsx)(Cn,{}),(0,Z.jsx)(ze,{heading:m(`console.commandPalette.actions`),children:(0,Z.jsxs)(nn,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,Z.jsx)(Oo,{className:`mr-2 h-4 w-4`}),(0,Z.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})})]})]})}function Pu(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Pu(n.children)):t.push(n);return t}function Fu(){let{t:e}=B(),[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)(ht,{open:t,onOpenChange:n,children:(0,Z.jsxs)(At,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:e(`console.shortcuts.title`)}),(0,Z.jsx)(Xt,{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 Iu(){return null}function Lu(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?ue.console:z.console}function Ru({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,X.useState)(0),o=Lu(),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)(Zt,{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:Hs()}),(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)(ci,{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)(H,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ui,{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)(aa,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Z.jsx)(H,{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 zu(e){let{theme:t=`system`}=tl(),{t:n}=B();return(0,Z.jsx)(Lo,{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)(aa,{className:`h-4 w-4`}),info:(0,Z.jsx)(er,{className:`h-4 w-4`}),warning:(0,Z.jsx)(_t,{className:`h-4 w-4`}),error:(0,Z.jsx)(va,{className:`h-4 w-4`}),loading:(0,Z.jsx)(H,{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 Bu=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Vu({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(...Bu),e.offsetWidth,e.classList.add(...Bu))},[n.pathname]),(0,Z.jsx)(`div`,{ref:r,className:[...Bu,t??``].filter(Boolean).join(` `),children:e})}var Hu=null,Uu=null;function Wu(){return Uu||(Uu=(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=Ku(e.data.url)),e}}),Hu=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Uu)}function Gu(e,t){if(Hu)try{Hu.captureException(e,t?{extra:t}:void 0)}catch{}}function Ku(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 qu({error:e,onReset:t}){let{t:n}=B();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)(Ot,{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)(_t,{className:`h-6 w-6 text-destructive`})}),(0,Z.jsx)(Ue,{children:n(`console.errors.somethingWentWrong`)}),(0,Z.jsx)(qt,{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)(ct,{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)(Ft,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Ju=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),Gu(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)(qu,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function Yu({sections:e,open:t}){if(!t)return null;let{t:n}=B(),[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)(Ir,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,Z.jsx)(Fi,{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)(po,{className:`h-3 w-3 text-green-600`}):(0,Z.jsx)(Tt,{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 Xu(){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 Zu(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 Qu(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 $u(e,t){return e.entries.findIndex(e=>e.name===t)}function ed(e,t,n){let r={type:t,label:n??td(e)};return(t===`select`||t===`multiselect`||t===`radio`||t===`checkboxes`)&&(r.options=[{value:``,label:``}]),{name:e,def:r}}function td(e){return e?e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):``}function nd(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 rd(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 id(e,t){let n=/[a-z0-9]/i.test(e)?nd(e):`group`;if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}_${r}`);)r+=1;return`${n}_${r}`}function ad(e,t){let n=t.trim()||`New section`,r=id(n,e.map(e=>e.key));return[...e,{key:r,label:n}]}function od(e,t,n){let r=n.trim();return r?e.map(e=>e.key===t?{...e,label:r}:e):e}function sd(e,t){return e.filter(e=>e.key!==t)}function cd(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:ud(e,r,i)}function ld(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 ud(e,t,n){let r=e.slice(),[i]=r.splice(t,1);return r.splice(n,0,i),r}function dd(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 fd(e,t){return e===t?!0:JSON.stringify(e??null)===JSON.stringify(t??null)}function pd(e,t){let n=new Set([...Object.keys(e),...Object.keys(t)]),r=[];for(let i of n)fd(e[i],t[i])||r.push(i);return r.sort()}function md(e,t){let n=Zu(e),r=Zu(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=pd(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 hd(e,t){let n=_s(),[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:Zu(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 gd=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),_d={text:gd(`text`,`Text`,`单行文本`,`text`,Tn),textarea:gd(`textarea`,`Text Area`,`多行文本`,`text`,nr),email:gd(`email`,`Email`,`邮箱`,`text`,pr),url:gd(`url`,`URL`,`网址`,`text`,Za),phone:gd(`phone`,`Phone`,`电话`,`text`,ur),password:gd(`password`,`Password`,`密码`,`text`,st),markdown:gd(`markdown`,`Markdown`,`Markdown`,`text`,uo),html:gd(`html`,`HTML`,`HTML`,`text`,St),richtext:gd(`richtext`,`Rich Text`,`富文本`,`text`,ya),number:gd(`number`,`Number`,`数字`,`number`,mr),currency:gd(`currency`,`Currency`,`货币`,`number`,gt),percent:gd(`percent`,`Percent`,`百分比`,`number`,bt),date:gd(`date`,`Date`,`日期`,`date`,it),datetime:gd(`datetime`,`Date/Time`,`日期时间`,`date`,it),time:gd(`time`,`Time`,`时间`,`date`,gr),boolean:gd(`boolean`,`Checkbox`,`复选框`,`logic`,Li),toggle:gd(`toggle`,`Toggle`,`开关`,`logic`,qe),select:gd(`select`,`Picklist`,`下拉选择`,`selection`,qi),multiselect:gd(`multiselect`,`Multi-Select`,`多选`,`selection`,Hi),radio:gd(`radio`,`Radio`,`单选`,`selection`,ni),checkboxes:gd(`checkboxes`,`Checkboxes`,`复选组`,`selection`,Hi),lookup:gd(`lookup`,`Lookup`,`查找关系`,`relation`,en),master_detail:gd(`master_detail`,`Master-Detail`,`主从关系`,`relation`,Kn),tree:gd(`tree`,`Tree`,`树形关系`,`relation`,Ha),image:gd(`image`,`Image`,`图片`,`media`,Bt),file:gd(`file`,`File`,`文件`,`media`,It),avatar:gd(`avatar`,`Avatar`,`头像`,`media`,ga),video:gd(`video`,`Video`,`视频`,`media`,Zn),audio:gd(`audio`,`Audio`,`音频`,`media`,Zr),formula:gd(`formula`,`Formula`,`公式`,`calculated`,Qi),summary:gd(`summary`,`Rollup`,`汇总`,`calculated`,to),autonumber:gd(`autonumber`,`Auto Number`,`自动编号`,`calculated`,mr),composite:gd(`composite`,`Composite`,`复合字段`,`advanced`,En),repeater:gd(`repeater`,`Repeater`,`重复字段`,`advanced`,Ji),location:gd(`location`,`Location`,`地理坐标`,`advanced`,Un),address:gd(`address`,`Address`,`地址`,`advanced`,bo),code:gd(`code`,`Code`,`代码`,`advanced`,St),json:gd(`json`,`JSON`,`JSON`,`advanced`,Xn),color:gd(`color`,`Color`,`颜色`,`advanced`,La),rating:gd(`rating`,`Rating`,`评分`,`advanced`,Pe),slider:gd(`slider`,`Slider`,`滑块`,`advanced`,Qr),signature:gd(`signature`,`Signature`,`签名`,`advanced`,ja),qrcode:gd(`qrcode`,`QR Code`,`二维码`,`advanced`,mt),progress:gd(`progress`,`Progress`,`进度条`,`advanced`,Qn),tags:gd(`tags`,`Tags`,`标签`,`advanced`,Wt),vector:gd(`vector`,`Vector`,`向量`,`advanced`,rr)},vd=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],yd={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},bd={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 xd(e){return bd[wd(e).category]}var Sd={text:`文本`,number:`数值`,date:`日期/时间`,logic:`逻辑`,selection:`选择`,relation:`关系`,media:`媒体`,calculated:`计算`,advanced:`高级`},Cd=vd.map(e=>({category:e,types:Object.keys(_d).filter(t=>_d[t].category===e)}));function wd(e){return typeof e==`string`&&e in _d?_d[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:Tn}}var Td=`text/x-objectui-viewcol`;function Ed({type:e}){let t=wd(e),n=xd(e),r=t.Icon;return(0,Z.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function Dd({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(Td,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(Td)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(Td)&&(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)(Ae,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,Z.jsx)(Ed,{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)(Jr,{className:`h-3 w-3`})})]})]})}function Od({fields:e,usedNames:t,loading:n,error:r,onAdd:i}){let a=X.useMemo(()=>Ms(),[]),[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)(kr,{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)(No,{className:`h-3.5 w-3.5`}),` `,Y(`engine.form.addFieldPlain`,a)]})}),(0,Z.jsxs)(Pn,{align:`start`,className:`w-72 p-0`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,Z.jsx)(Oo,{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:Y(`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)(kd,{children:Y(`engine.form.loadingFields`,a)}):r?(0,Z.jsx)(kd,{tone:`warn`,children:bs(`engine.form.noObjectFields`,a,{error:r})}):u.length===0?(0,Z.jsx)(kd,{children:Y(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)(Ed,{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)(U,{variant:`secondary`,className:`px-1 py-0 text-[9px]`,children:Y(`engine.form.added`,a)})]},e.name)})})]})]})}function kd({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 Ad(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 jd(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 Md(e){let t=new Set;for(let n of e){let e=jd(n);e&&t.add(e)}return t}function Nd(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Pd(e,t){return e===t?null:e>t?e-1:e}function Fd(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Id({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}=hd(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=ys(n,Nd(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=zs(n,t,null);if(y(r),o!=null){let n=Pd(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Ad(r[n],n)})}},[n,y,o,e,l]),S=X.useCallback((t,r)=>{if(t===r)return;let i=Is(n,t,r);if(y(i),o!=null){let n=Fd(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Ad(i[n],n)})}},[n,y,o,e,l]),C=X.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Ad(n[t],t)})},[n,e,l]),w=Md(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)(U,{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)(Dd,{index:t,label:Ad(e,t),fieldName:jd(e),fieldType:m.get(jd(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)(Od,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var Ld={io:`input`,unrepresentable:`any`},Rd=new Set([`columns`,`data`,`name`]),zd,Bd=!1;function Vd(){if(zd||Bd)return zd;try{zd=xe(Oe,Ld)}catch(e){Bd=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return zd}function Hd(){return Vd()?.properties?.list}function Ud(){return Vd()?.properties?.form}var Wd,Gd=!1;function Kd(){if(Wd||Gd)return Wd;try{Wd=xe(Ce,Ld)}catch(e){Gd=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Wd}var qd;function Jd(){if(qd)return qd;if(!(!Se||typeof Se!=`object`)){try{let e=JSON.parse(JSON.stringify(Se));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Rd.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),qd=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return qd}}var Yd=new Set([`form`,`detail`]);function Xd(e){return Yd.has(e)}function Zd(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Qd(e,t){return typeof e==`string`&&Yd.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Yd.has(t)?`form`:`list`}function $d(e){let t=e.config;return Zd(t)?[{storeKey:`config`,familyKey:Qd(e.viewKind,t.type),schema:t}]:[]}function ef(e){return $d(e)[0]}function tf(e,t){return ef(e)}var nf=new Set([`type`,`object`,`label`,`columns`]),rf={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function af(e,t){let n=`engine.inspector.view.type.${e}`,r=Y(n,t);return r===n?rf[e]??e:r}var of=[`columns`,`data`,`name`];function sf(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 cf(e,t){return X.useMemo(()=>{let n=Hd()?.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:af(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:af(e,t)}),r},[e,t])}function lf({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=Xd(n??t),p=typeof d.type==`string`?d.type:`grid`,m=cf(p,l),h=sf(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}=hd(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(()=>Ps({bundledSchema:f?Ud():Hd(),bundledForm:f?void 0:Jd(),serverSchema:x,excludeFields:nf,sectionTitle:Y(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:Y(`engine.inspector.view.close`,l),hideClose:r,children:[(0,Z.jsx)(Ts,{label:Y(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:Y(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,Z.jsx)(Os,{label:Y(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,Z.jsx)(Ts,{label:Y(`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:Y(`engine.inspector.view.objectPlaceholder`,l),disabled:a,mono:!0}),!f&&(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:(0,Z.jsx)(Id,{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)(ks,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of of)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Y(`engine.inspector.view.noSchema`,l)})})]})}function uf(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 df(e,t,n,r){await r.metadataClient.save(e,t,n,{mode:`draft`})}async function ff(e,t,n,r){return await r.metadataClient.save(e,t,n,{mode:`draft`}),t}async function pf(e,t,n){return uf(await n.metadataClient.get(e,t,{state:`draft`}))}async function mf(e,t,n){await n.metadataClient.reset(e,t,{state:`draft`})}async function hf(e,t,n){await n.metadataClient.publish(e,t)}function gf({type:e,name:t,metadataClient:n,dirty:r,onResume:i,onAfterChange:a,savedSignal:o}){let s=Ms(),[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 pf(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 hf(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(bs(`engine.edit.discardDraftConfirm`,s,{type:e,name:t})))){d(!0);try{await mf(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:Y(`engine.edit.draftPending`,s),"data-testid":`runtime-draft-indicator`,children:[`● `,Y(`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:Y(`engine.edit.discardDraft`,s),"aria-label":Y(`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:Y(r?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,s),"data-testid":`runtime-draft-publish`,children:u?(0,Z.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(co,{className:`h-3.5 w-3.5 mr-1`}),Y(`engine.edit.publish`,s)]})})]}):null}var _f=new Set([`form`,`detail`]);function vf(e){return typeof e==`string`&&_f.has(e)}function yf(e,t){let n=e.type||`grid`,r=vf(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 bf(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function xf(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 Sf({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=B(),d=(0,X.useRef)(null),f=(0,X.useMemo)(()=>Ms(),[]),[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)(()=>yf(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)(()=>xf(i),[i.fields]),T=Xd(g.viewKind)?`form`:`list`,E=(0,X.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=bf(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,X.useCallback)(()=>{let e=bf(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=yf(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)(lf,{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)(gf,{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 Cf(e){return[{type:`grid`,icon:pt,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Ra,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:it,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Bt,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:gr,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Br,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:bo,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Qn,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function wf(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Tf={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:nc}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:ic},{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:ic},{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:ic},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:oc},{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=>rc(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&Qs(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&Qs(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:nc},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function Ef({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=B(),s=(0,X.useMemo)(()=>Cf(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?ec(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(wf(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Tf[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=(Tf[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=ac(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)(ht,{open:e,onOpenChange:t,children:(0,Z.jsxs)(At,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:o(`console.objectView.createView`)}),(0,Z.jsx)(Xt,{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:q(`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:q(`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:q(`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)(ci,{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)(Ln,{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 Df={config:{icon:Mr,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:st,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:Fe,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:ca,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 Of({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=Df[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,Z.jsx)(bn,{delayDuration:200,children:(0,Z.jsxs)(dt,{children:[(0,Z.jsx)($i,{asChild:!0,children:(0,Z.jsxs)(U,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:q(`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)(at,{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 kf({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 Af({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 jf={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 Mf(e){let t=jf[e?.managedBy??`platform`]??jf.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 Nf=new Set([`record:discussion`,`record:chatter`]);function Pf(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`&&Nf.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 Ff({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,Z.jsx)(zi,{open:e.open,onOpenChange:e=>{e||r()},children:(0,Z.jsxs)(Ga,{children:[(0,Z.jsxs)(io,{children:[(0,Z.jsx)(si,{children:e.options?.title||`Confirm Action`}),(0,Z.jsx)(ti,{children:e.message})]}),(0,Z.jsxs)(ia,{children:[(0,Z.jsx)(Sa,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,Z.jsx)(Ur,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function If({state:e,onOpenChange:t}){let{t:n}=B(),[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)(ht,{open:e.open,onOpenChange:e=>{e||l()},children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:e.title||n(`actionDialog.title`)}),(0,Z.jsx)(Xt,{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)(dr,{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)(Vn,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,Z.jsx)(cr,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,Z.jsx)(Dt,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,Z.jsx)(Fo,{children:e.options.map(e=>(0,Z.jsx)(Ye,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,Z.jsx)(Eo,{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)(ke,{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)(Ln,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,Z.jsx)(K,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var Lf=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Rf=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)}})),zf=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}}})),Bf=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})),Vf=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})),Hf=n((e=>{var t=Rf().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}})),Uf=n((e=>{var t=Rf().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Wf=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}})),Gf=n((e=>{var t=zf(),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}}})),Kf=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]]}})),qf=n((e=>{var t=Kf();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}})),Jf=n(((e,t)=>{var n=qf();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})),Yf=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Xf=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)}})),Zf=n((e=>{var t=Yf(),n=Xf();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}}})),Qf=n((e=>{var t=Rf(),n=Gf(),r=zf(),i=Zf(),a=Yf(),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}})),$f=n((e=>{var t=Rf(),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}})),ep=n(((e,t)=>{var n=Zf();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})),tp=n(((e,t)=>{var n=Zf(),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})),np=n(((e,t)=>{var n=Zf();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})),rp=n(((e,t)=>{var n=Zf(),r=Rf();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})),ip=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)})),ap=n((e=>{var t=Zf(),n=ep(),r=tp(),i=np(),a=rp(),o=Xf(),s=Rf(),c=ip();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()))}})),op=n((e=>{var t=Rf(),n=zf(),r=Bf(),i=Vf(),a=Hf(),o=Uf(),s=Wf(),c=Gf(),l=Jf(),u=Qf(),d=$f(),f=Zf(),p=ap();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)}})),sp=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}}})),cp=n((e=>{var t=sp();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)}})),lp=n((e=>{var t=sp();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}})),up=n((e=>{var t=Lf(),n=op(),r=cp(),i=lp();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 dp(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function fp({state:e,onAcknowledge:t}){let{t:n}=B(),{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)(ht,{open:e.open,onOpenChange:e=>{},children:(0,Z.jsxs)(At,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,Z.jsx)(Xt,{children:r.description}):null]}),(0,Z.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,Z.jsx)(pp,{field:e,value:e.path===``?i:dp(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,Z.jsx)(Ln,{children:(0,Z.jsx)(K,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function pp({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)(gp,{value:t}):null,a===`code-list`?(0,Z.jsx)(_p,{value:t}):null,a===`secret`?(0,Z.jsx)(vp,{value:t}):null,a===`text`?(0,Z.jsx)(yp,{value:t}):null,a===`json`?(0,Z.jsx)(bp,{value:t}):null]})}function mp(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 hp({value:e,label:t}){let{copy:n,copied:r}=mp(e);return(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,Z.jsx)(po,{className:`w-4 h-4`}):(0,Z.jsx)(Tt,{className:`w-4 h-4`}),t?(0,Z.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function gp({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,up.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)(hp,{value:e})]})]})}function _p({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)(hp,{value:e})]},`${t}-${e}`))})}),(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsx)(hp,{value:t,label:`Copy all`})})]})}function vp({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)(vn,{className:`w-4 h-4`}):(0,Z.jsx)(nt,{className:`w-4 h-4`})}),(0,Z.jsx)(hp,{value:e})]})}function yp({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)(hp,{value:e})]})}function bp({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)(hp,{value:t})})]})}function xp(e){let t={};for(let n of e.fields)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function Sp({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(xp(e.screen)))},[e]),!e||!a)return null;let h=(e,t)=>f(n=>({...n,[e]:t}));return(0,Z.jsx)(ht,{open:!0,onOpenChange:e=>{!e&&!p&&r()},children:(0,Z.jsxs)(At,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:a.title||`Input`}),a.description&&(0,Z.jsx)(Xt,{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)(Cp,{field:e,value:d[e.name],onChange:t=>h(e.name,t)})]},e.name))}),(0,Z.jsxs)(Ln,{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){J.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){J.error(a?.error||`Resume failed (HTTP ${e.status})`);return}let u=a?.data??{};if(u.success===!1||u.status===`failed`){J.error(u.error||`The flow failed to complete.`),r();return}u.status===`paused`&&u.screen?(o(u.screen),c(u.runId||s),f(xp(u.screen)),J.success(`Saved — next step`)):(J.success(`Done`),i())}catch(e){J.error(e.message)}finally{m(!1)}},disabled:p,children:p?`Submitting…`:`Submit`})]})]})})}function Cp({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)(Vn,{value:t==null?void 0:String(t),onValueChange:e=>n(e),children:[(0,Z.jsx)(cr,{id:r,children:(0,Z.jsx)(Dt,{placeholder:e.placeholder||`Select…`})}),(0,Z.jsx)(Fo,{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)(dr,{id:r,checked:t===!0,onCheckedChange:e=>n(e===!0)});if(i===`textarea`||i===`markdown`)return(0,Z.jsx)(ke,{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 wp(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 Tp(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??wp(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 Ep(e,t){return Array.isArray(e)?e.map(e=>Tp(e,t)):[]}function Dp(){return`${``.replace(/\/$/,``)}/api/v1`}async function Op(e,t){let n=await fetch(`${Dp()}${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 kp(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 Op(`/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 Op(`/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 Ap={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`},jp={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function Mp(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 Np(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:Mp(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)(Uo,{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)(P,{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)(mn,{side:n.side||`right`,className:q(`w-full overflow-y-auto`,jp[n.size||`default`]),children:[n.title&&(0,Z.jsxs)(yt,{children:[(0,Z.jsx)(Pt,{children:n.title}),n.description&&(0,Z.jsx)(Dn,{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)(lo,{children:[(0,Z.jsx)(ko,{children:n.title}),n.description&&(0,Z.jsx)(Nr,{children:n.description})]}),(0,Z.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,Z.jsx)(ht,{open:!0,onOpenChange:i,children:(0,Z.jsxs)(At,{className:q(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:Ap[n.size||`default`]),children:[n.title&&(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:n.title}),n.description&&(0,Z.jsx)(Xt,{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 Pp=t({RecordDetailView:()=>Vp}),Fp={id:`current-user`,name:`Demo User`},Ip=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Lp=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),Rp=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],zp=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function Bp(e,t){if(zp.has(t?.type))return!0;let n=e.toLowerCase();return Rp.some(e=>n===e||n.endsWith(`_${e}`))}function Vp({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}=Xu(),{user:p}=S(),m=v(),g=u().state?.from,{t:_}=B(),{objectLabel:y,viewLabel:b,sectionLabel:x,actionLabel:C,actionConfirm:w,actionSuccess:T,actionParamText:D,fieldLabel:O,fieldOptionLabel:k}=zr(),{isFavorite:A,toggleFavorite:j,refreshLabel:M}=Qc(),{addRecentItem:ee}=rs(),[N,te]=(0,X.useState)(!0),[ne,F]=(0,X.useState)([]),[re,ie]=(0,X.useState)([]),[oe,I]=(0,X.useState)(0),[se,ce]=(0,X.useState)(null),[le,ue]=(0,X.useState)({}),[de,fe]=(0,X.useState)(null),[me,he]=(0,X.useState)(!1),[L,R]=(0,X.useState)(),z=t.find(e=>e.name===l);Vc(a?void 0:L);let V=d,ye=lu(l,V),xe=(0,X.useMemo)(()=>!l||!V?null:{id:`record:${l}:${V}`,label:L||V||``,href:`/apps/${c}/${l}/record/${V}`,type:`record`},[c,l,V,L]),Se=xe?A(xe.id):!1,Ce=(0,X.useCallback)(()=>{xe&&j(xe)},[xe,j]),{page:we,slots:Te}=be(l),Ee=(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 z?.detail?.renderViaSchema!==!1},[z]),De=(0,X.useMemo)(()=>we||!z||!Ee&&!Te?null:Ks(z,Te?{slots:Te}:void 0),[Ee,we,Te,z]),Oe=we||De,[ke,Ae]=(0,X.useState)(null),[je,Me]=(0,X.useState)(`idle`);(0,X.useEffect)(()=>{let t=!1;if(!Oe||!V||!l||!e?.findOne){Ae(null),Me(`idle`);return}let n=ge(z?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{Me(`loading`),(r?e.findOne(l,V,r):e.findOne(l,V)).then(e=>{t||(e&&typeof e==`object`?(Ae(e),Me(`loaded`)):(Ae(null),Me(`missing`)))}).catch(()=>{t||(Ae(null),Me(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==l||String(t.recordId)!==String(V)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[Oe,l,V,e,z]),(0,X.useEffect)(()=>{if(!ke||typeof ke!=`object`||!z)return;let e=Ll(z,ke);e&&e!==`Untitled`&&e!==L&&R(e)},[ke,z,L]),(0,X.useEffect)(()=>{if(!l||!V||!c||!L)return;let e=`record:${l}:${V}`;ee({id:e,label:L,href:`/apps/${c}/${l}/record/${V}`,type:`record`}),M(e,L)},[c,l,V,L,ee,M]);let[Ne,Pe]=(0,X.useState)({open:!1,message:``}),[Fe,Ie]=(0,X.useState)({open:!1,params:[]}),[Le,Re]=(0,X.useState)({open:!1}),ze=(0,X.useCallback)((e,t)=>new Promise(n=>{Re({open:!0,spec:e,data:t,resolve:n})}),[]),Be=(0,X.useCallback)((e,t)=>new Promise(n=>{Pe({open:!0,message:e,options:t,resolve:n})}),[]),Ve=(0,X.useCallback)((e,n)=>new Promise(r=>{let i=Ep(e,{objectName:l||z?.name||``,objects:t||[],fieldLabel:O,fieldOptionLabel:k}),a=l||z?.name;Ie({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,z,t,O,k,D]),He=(0,X.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),We=(0,X.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):m(e)},[m]),Ge=(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,V,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(l,V,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(l,V,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(l,V,r);break}let i=t.refreshAfter===!0;return i&&I(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,l,V]),{modalHandler:Ke,modalElement:qe}=Np(e),Je=(0,X.useMemo)(()=>E(),[]),Ye=(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 Je(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:V,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 ce({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&I(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Je,V,l]),Xe=(0,X.useRef)(new Set),Ze=(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}:${V??``}`;if(Xe.current.has(r))return{success:!1,error:`Action already in progress`};Xe.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 Je(`/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:V,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 J.error(e),{success:!1,error:e}}let s=e.refreshAfter!==!1;s&&I(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||J(`浏览器拦截了弹窗 / 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 J.error(t),{success:!1,error:t}}finally{Xe.current.delete(r)}},[Je,V,l]),Qe=kp(l,V,p?.id),$e=(0,X.useRef)(Qe);$e.current=Qe;let et=(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 $e.current.approve({comment:n.comment});else if(t===`reject_request`)await $e.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return I(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),H=(0,X.useMemo)(()=>jl(z,t),[z,t]);(0,X.useEffect)(()=>{if(Oe||!e||!V||H.length===0)return;let t=!1;return Promise.all(H.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:V}}).then(e=>({childObject:t,items:Array.isArray(e)?e:e?.data||[]})).catch(e=>(console.warn(`[RecordDetailView] Failed to fetch related ${t}:`,e),{childObject:t,items:[]})))).then(e=>{if(t)return;let n={};for(let{childObject:t,items:r}of e)n[t]=r;ue(n)}),()=>{t=!0}},[e,V,H,z,Oe]);let tt=(0,X.useMemo)(()=>!z||z.name===`sys_audit_log`||z.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[z,t]);(0,X.useEffect)(()=>{if(!e||!V||!z||!tt){fe(null);return}let t=!1;return he(!0),e.find(`sys_audit_log`,{$filter:{record_id:V,object_name:z.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(z.fields||{}))t?.label&&(o[e]=t.label);let s=e=>{if(!e)return null;if(typeof e==`object`)return e;if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return null};fe(r.map(e=>{let t=e?.user_id?a.get(e.user_id):void 0,n=s(e?.old_value)||{},r=s(e?.new_value)||{},i=new Set([...Object.keys(n),...Object.keys(r)]),c=Array.from(i).filter(e=>JSON.stringify(n[e])!==JSON.stringify(r[e])).map(e=>({field:e,label:o[e]||e,from:n[e],to:r[e]}));return{...e,user_name:t?.name??null,user_avatar:t?.image??null,changes:c.length>0?c:void 0}}))}).catch(e=>{t||(console.warn(`[RecordDetailView] Failed to fetch sys_audit_log:`,e),fe([]))}).finally(()=>{t||he(!1)}),()=>{t=!0}},[e,V,z,tt]),(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))];ie(o.length>0?o:n)}catch{if(t)return;ie(n)}})(),()=>{t=!0}},[e,p?.id,p?.name,p?.email]);let nt=(0,X.useMemo)(()=>p?{id:p.id,name:p.name,avatar:p.image}:Fp,[p?.id,p?.name,p?.image]);(0,X.useEffect)(()=>{if(!e||!l||!V)return;let t=`${l}:${V}`,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(nt.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)}));F(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:V},$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&&F(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,V,nt]);let rt=(0,X.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:nt.name,actorAvatarUrl:`avatar`in nt?nt.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(F(e=>[...e,n]),e){let r=`${l}:${V}`,i=Js(t,re);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:nt.id,author_name:nt.name,author_avatar_url:`avatar`in nt?nt.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[nt,e,l,V,re]),it=(0,X.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:nt.name,actorAvatarUrl:`avatar`in nt?nt.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(F(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${l}:${V}`,a=Js(n,re);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:nt.id,author_name:nt.name,author_avatar_url:`avatar`in nt?nt.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[nt,e,l,V,re]),at=(0,X.useCallback)((t,n)=>{F(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=nt.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}))},[nt.id,e]);(0,X.useEffect)(()=>{te(!0),queueMicrotask(()=>te(!1))},[l,d]);let ot=(0,X.useMemo)(()=>{if(!z)return{type:`detail-view`};let n=z.primaryField||Object.keys(z.fields||{}).find(e=>e===`name`||e===`title`),r=z.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?x(z.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!z.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=z.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${z.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(z.fields||{}).filter(e=>!Ip.has(e)&&!Lp.has(e)&&!z.fields[e]?.hidden),t=e=>{let t=z.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=>!Bp(e,z.fields[e])),r=e.filter(e=>Bp(e,z.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(z.name,`details`,_(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),o=(()=>{let e=new Set,t=(z.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(z.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:w(z.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(z.name,e.name,e.successMessage)}}));if(Qe.available&&Qe.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=z.views?.detail?.highlightFields??[],l=z.views?.detail?.sectionGroups??z.views?.form?.sectionGroups,u=c?`/apps/${c}`:``,d=H.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let s=t.find(e=>e.name===n),c=V||``,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),J.success(_(`detail.deleteSuccess`,{defaultValue:`Deleted`})),ue(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){J.error(e?.message||_(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:l,type:`table`,api:n,data:le[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=Mf(z);return{type:`detail-view`,objectName:z.name,resourceId:V,showBack:!a,onBack:`history`,showEdit:f.edit,title:z.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...tt&&{history:{entries:de??[],loading:me&&de===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}]}}},[z?.name,V,le,oe,c,m,e,_,y,t,tt,de,me,Qe.available,Qe.canDecide,Qe.pendingRequest,Qe.latestRequest,a]);if(N)return(0,Z.jsx)(Af,{});if(!z)return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Z.jsxs)(Ot,{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)(Zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:_(`empty.objectNotFound`)}),(0,Z.jsx)(qt,{children:_(`empty.objectNotFoundDescription`,{name:l})})]})});if(Oe&&je===`missing`)return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,Z.jsxs)(Ot,{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)(Zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:_(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,Z.jsx)(qt,{children:_(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(Oe){let t=Oe?.disableDiscussion===!0,r=Pf(Oe),i=!t&&!r,o=(()=>{let e=ot.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=Mf(z),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:V,objectName:l}}))}}),r.push({name:`sys_edit`,label:_(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:V})})),r.push({name:`sys_share`,label:_(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:async()=>{try{if(navigator.share){await navigator.share({title:document.title,url:window.location.href});return}}catch{return}try{await navigator.clipboard.writeText(window.location.href),J.success(_(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){J.error(_(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:_(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=_(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(l,V),J.success(_(`detail.deleted`,{defaultValue:`Record deleted`})),m(`${c?`/apps/${c}`:``}/${l}`,{replace:!0})}catch(e){J.error(e?.message||`Delete failed`)}}}),r})(),u=o.length>0?o:void 0,d=Array.isArray(ot.related)?ot.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=ot.history?{entries:ot.history.entries??[],loading:!!ot.history.loading,emptyText:ot.history.emptyText}:void 0,v=we?Oe:Ks(z,{sections:ot.sections,highlightFields:Array.isArray(ot.highlightFields)?ot.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:u,related:d,history:p,showReferenceRail:z?.detail?.showReferenceRail===!0||void 0,hideReferenceRail:z?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:z?.detail?.hideRelatedTab===!0||void 0,...Te?{slots:Te}:{}});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:[ye.length>0&&(0,Z.jsx)(ou,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Z.jsx)(Of,{managedBy:z?.managedBy})]}),(0,Z.jsx)(_e,{objectName:l,recordId:V,data:ke,objectSchema:z,dataSource:e,embedded:a,headerSystemActions:s,isFavorite:Se,onToggleFavorite:xe?Ce:void 0,children:(0,Z.jsx)(ve,{children:(0,Z.jsx)(pe,{items:ne,onAddComment:rt,onAddReply:it,onToggleReaction:at,mentionSuggestions:re,children:(0,Z.jsxs)(ae,{context:{record:ke||{},objectName:l,user:nt},onConfirm:Be,onToast:He,onNavigate:We,onParamCollection:Ve,onResultDialog:ze,onModal:Ke,handlers:{api:Ge,flow:Ye,script:Ze,approval:et},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)(Di,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:g.label})]}),(0,Z.jsx)(P,{schema:v}),i&&(0,Z.jsx)(`div`,{className:`mt-6`,children:(0,Z.jsx)(qs,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:rt,onAddReply:it,onToggleReaction:at,mentionSuggestions:re})})]}),(0,Z.jsx)(Yu,{open:f,sections:[{title:`Page Schema`,data:v}]})]}),qe]})})})}),(0,Z.jsx)(Ff,{state:Ne,onOpenChange:e=>{e||Pe(e=>({...e,open:!1}))}}),(0,Z.jsx)(If,{state:Fe,onOpenChange:e=>{e||Ie(e=>({...e,open:!1}))}}),(0,Z.jsx)(fp,{state:Le,onAcknowledge:()=>{Le.resolve?.(),Re({open:!1})}}),(0,Z.jsx)(Sp,{state:se,authFetch:Je,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),I(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:[ye.length>0&&(0,Z.jsx)(ou,{users:ye,size:`sm`,maxVisible:3,showStatus:!0}),(0,Z.jsx)(Of,{managedBy:z?.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:nt},onConfirm:Be,onToast:He,onNavigate:We,onParamCollection:Ve,onResultDialog:ze,onModal:Ke,handlers:{api:Ge,flow:Ye,script:Ze,approval:et},children:[(0,Z.jsx)(Ys,{schema:ot,dataSource:e,objectLabel:y({name:z.name,label:z.label}),isFavorite:Se,onToggleFavorite:xe?Ce:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=Ll(z,e);t&&t!==L&&t!==`Untitled`&&R(t)},onEdit:()=>{n({id:V})},discussionSlot:(0,Z.jsx)(qs,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:ne,onAddComment:rt,onAddReply:it,onToggleReaction:at})},oe),qe]})}),(0,Z.jsx)(Yu,{open:f,sections:[{title:`View Schema`,data:ot}]})]}),(0,Z.jsx)(Ff,{state:Ne,onOpenChange:e=>{e||Pe(e=>({...e,open:!1}))}}),(0,Z.jsx)(If,{state:Fe,onOpenChange:e=>{e||Ie(e=>({...e,open:!1}))}}),(0,Z.jsx)(fp,{state:Le,onAcknowledge:()=>{Le.resolve?.(),Re({open:!1})}}),(0,Z.jsx)(Sp,{state:se,authFetch:Je,baseUrl:``,onClose:()=>ce(null),onComplete:()=>{ce(null),I(e=>e+1)}})]})}function Hp(e,t){switch(e){case`system`:return{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`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:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`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:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`Identity rows are managed by the authentication provider. Use the dedicated identity workflows (Invite User, Reset Password, …) to create new entries.`})};default:return}}var Up={id:`current-user`,name:`Demo User`};function Wp(e){let{dataSource:t,objects:n,objectName:r,onRefresh:i}=e,a=v(),{user:o,activeOrganization:s}=S(),{fieldLabel:c,fieldOptionLabel:l,actionParamText:u}=zr(),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=Ep(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}:Up,A=(0,X.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),j=(0,X.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):a(e)},[a]),M=(0,X.useMemo)(()=>E(),[]),ee=(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 M(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,M,s,p]),N=(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 M(`/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}}},[M,f,p]),P=(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 M(`/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 J.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||J(`浏览器拦截了弹窗 / 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 J.error(t),{success:!1,error:t}}finally{w.current.delete(s)}},[M,f,p]);return{confirmHandler:D,toastHandler:A,navigateHandler:j,paramCollectionHandler:O,resultDialogHandler:T,apiHandler:ee,flowHandler:N,serverActionHandler:P,authFetch:M,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:ee,flow:N,script:P,modal:P}}),[r,k,s,D,A,j,O,T,ee,N,P]),dialogs:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ff,{state:m,onOpenChange:e=>{e||h({open:!1,message:``})}}),(0,Z.jsx)(If,{state:g,onOpenChange:e=>{e||_({open:!1,params:[]})}}),(0,Z.jsx)(fp,{state:y,onAcknowledge:()=>{y.resolve?.(),b({open:!1})}}),(0,Z.jsx)(Sp,{state:x,authFetch:M,baseUrl:``,onClose:()=>C(null),onComplete:()=>{C(null),p()}})]})}}function Gp({children:e,...t}){let n=Wp(t);return(0,Z.jsxs)(ae,{...n.actionProviderProps,children:[e,n.dialogs]})}var Kp=(0,X.lazy)(()=>d(()=>import(`./plugin-charts-QabQJ_NJ.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),qp=(0,X.lazy)(()=>d(()=>import(`./plugin-grid-BxyuFeJP.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Jp={grid:zt,kanban:Ra,calendar:it,gallery:pt,timeline:ma,gantt:wo,map:Un,chart:Qn},Yp={id:`current-user`,name:`Demo User`};function Xp(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 Zp({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=s(),{t:a}=B();return t.find(e=>e.name===i)?(0,Z.jsx)(Qp,{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)(Ot,{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)(zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:a(`console.objectView.objectNotFound`)}),(0,Z.jsxs)(qt,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Qp({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}=Xu(),{t:h}=B(),{objectLabel:g,objectDescription:_,viewLabel:y,viewEmptyState:b,actionLabel:x,actionConfirm:C,actionSuccess:w,actionParamText:T,fieldLabel:E,fieldOptionLabel:O}=zr(),{isFavorite:k,toggleFavorite:A}=Qc(),j=_s(),[M,ee]=(0,X.useState)(!1),[N,te]=(0,X.useState)(`edit`),[F,re]=(0,X.useState)(!1),[ie,oe]=(0,X.useState)(!1),[I,se]=(0,X.useState)(null),ce=(0,X.useRef)({}),le=(0,X.useRef)({}),ue=(0,X.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!o||!t)return;let i=le.current[t]||{};le.current[t]={...i,...r};let a=ce.current[t];a&&clearTimeout(a),ce.current[t]=setTimeout(()=>{let r=le.current[t]||{};delete le.current[t],delete ce.current[t],Promise.resolve(e.updateViewConfig(o,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,o]),de=(0,X.useCallback)(e=>{se(e),ve(e=>e+1);let t=e.id;j&&t?df(`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]),fe=(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 ff(`view`,String(e?.name??e?.id??c?.id??``),c,{metadataClient:j})}ee(!1),te(`edit`),ve(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]),[pe,me]=(0,X.useState)(void 0),{user:he,activeOrganization:ge}=S(),_e=he?.role===`admin`,{can:L}=D(),R=t.find(e=>e.name===o),[z,ve]=(0,X.useState)(0),V=Wp({dataSource:e,objects:t,objectName:R.name,onRefresh:()=>ve(e=>e+1)}),{confirmHandler:ye,toastHandler:be}=V,xe=(0,X.useMemo)(()=>Mf(R),[R]);(0,X.useEffect)(()=>{r===void 0||r===0||ve(e=>e+1)},[r]);let[Se,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)([]);(0,X.useEffect)(()=>{let t=!1;if(!o){Te([]);return}return typeof e?.listViews==`function`?(e.listViews(o).then(e=>{t||Te((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||Te([])}),()=>{t=!0}):(Te([]),()=>{t=!0})},[e,o,z]);let[Ee,De]=(0,X.useState)({});(0,X.useEffect)(()=>{let t=!1;if(!e||!o){De({});return}let n=R.listViews||R.list_views||{},r=Object.keys(n),i=R.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){De({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(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||De(e)}),()=>{t=!0}},[e,o,R.listViews,R.list_views,R.list,z]);let Oe=(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(R.compactLayout)&&R.compactLayout.length>0?R.compactLayout.filter(e=>R.fields?.[e]):R.fields?Object.entries(R.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=R.listViews||R.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=Ee[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=R.list;if(i&&typeof i==`object`){let e=i.name||`list`,t=r.findIndex(t=>t.id===e);if(t>=0){let[e]=r.splice(t,1);r.unshift({...e,isDefault:!0})}else{let t=Ee[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:h(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of we){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},i={};for(let[e,t]of Object.entries(n))t!==void 0&&(i[e]=t);if(a.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...i}}else r.push(i)}let o=new Set([`grid`,`list`,`table`]);for(let e of r)o.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let s=new Map(r.map((e,t)=>[e.id,t])),c=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${R.name}`):null;e&&(c=JSON.parse(e))}catch{}let l=new Map(c.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=l.get(e.id),r=l.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=we.find(t=>(t.id||t._id)===e.id),a=we.find(e=>(e.id||e._id)===t.id),o=i&&typeof i.sortOrder==`number`,c=a&&typeof a.sortOrder==`number`;return o&&c?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:o?-1:c?1:(s.get(e.id)??0)-(s.get(t.id)??0)}),r},[R,we,Ee,h]),ke=(0,X.useMemo)(()=>Oe.find(e=>e.isDefault)?.id,[Oe]),Ae=c||l.get(`view`)||ke||Oe[0]?.id,je=Oe.find(e=>e.id===Ae)||Oe[0],Me=I&&I.id===je?.id?{...je,...I}:je,Ne=(0,X.useCallback)((e,t)=>{se(n=>({...n||{},id:je?.id,[e]:t}))},[je?.id]),Fe=e=>{let t=Oe.find(t=>t.id===e);t&&(t.id!==Ae&&ee(!1),c?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Ie=(0,X.useMemo)(()=>(Oe||[]).map(e=>{let t=Jp[e.type];return{id:e.id,label:y(R.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Z.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Oe,R.name,y]);Su({views:Ie,activeViewId:Ae??``,onChange:Fe,enabled:Ie.length>0&&!!Ae});let Le=(0,X.useCallback)(()=>{re(!0)},[]),Re=(0,X.useCallback)((e,t)=>{if(e===`settings`){let e=Oe.find(e=>e.type===t);e&&Fe(e.id),te(`edit`),ee(!0)}},[Oe,Fe]),ze=(0,X.useCallback)(e=>we.some(t=>(t.id||t._id)===e),[we]),Be=(0,X.useCallback)(async(t,n)=>{if(!ze(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{label:n}),ve(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),J.error(h(`objectViewActions.renameFailed`))}},[e,o,ze,h]),Ve=(0,X.useCallback)(async t=>{if(!e)return;if(!ze(t)){J.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Oe.find(e=>e.id===t)?.label||t;if(await ye(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===Ae){let e=Oe.find(e=>e.id!==t);e&&i(c?`../${e.id}`:`view/${e.id}`,c?{relative:`path`}:void 0)}ve(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),J.error(h(`objectViewActions.deleteFailed`))}},[e,ze,Ae,Oe,c,i,h,ye]),He=(0,X.useCallback)(async(t,n)=>{if(e){if(!ze(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{isPinned:n}),ve(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,o,ze,h]),Ue=(0,X.useCallback)(async t=>{if(e){if(!ze(t)){J.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=we.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),ve(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),J.error(`Failed to set default view`)}}},[e,o,we,ze,h]),We=(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(we.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)}}ve(e=>e+1)},[e,we,o]),Ge=(0,X.useCallback)(e=>{if(!ze(e)){J.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Ae&&Fe(e),te(`edit`),ee(!0)},[Ae,Fe,ze,h]),Ke=(0,X.useCallback)(()=>{re(!0)},[]),qe=he?{id:he.id,name:he.name,avatar:he.image}:Yp,Je=Lc({objectName:R.name,objectLabel:R.label,dataSource:e,onEdit:n,onRefresh:()=>ve(e=>e+1),onConfirm:ye,onToast:be}),{lastMessage:Ye}=Zl({channel:`object:${R.name}`}),{hasConflicts:Xe,resolveAllConflicts:Ze}=nu(R.name?`user-${R.name}`:`current-user`);(0,X.useEffect)(()=>{Ye&&(Xe&&Ze(`remote`),ve(e=>e+1))},[Ye,Xe,Ze]),(0,X.useEffect)(()=>{e?.find&&R.name&&e.find(R.name,{limit:0}).then(e=>{typeof e?.total==`number`?me(e.total):Array.isArray(e?.data)?me(e.data.length):Array.isArray(e)&&me(e.length)}).catch(()=>{})},[e,R.name,z]);let Qe=(0,X.useMemo)(()=>Me?.navigation??R.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[Me?.navigation,R.navigation]),$e=l.get(`recordId`),et=(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()]),H=(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(R.name,Me?.name??``,Me?.label??``)||g(R)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,c,f.pathname,f.search,R,Me?.name,Me?.label,y,g]),tt=ne({navigation:Qe,objectName:R.name,onNavigate:H}),nt=()=>{tt.close();let e=new URLSearchParams(l);e.delete(`recordId`),d(e)},rt=(0,X.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){tt.handleClick(e,t);return}if(tt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(l);e.set(`recordId`,String(t)),d(e);return}}tt.handleClick(e,t)},[tt,l,d]),it=(0,X.useCallback)(()=>{let e=tt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(nt(),H(t))},[tt.selectedRecord,H]);(0,X.useEffect)(()=>{$e&&!tt.isOpen?tt.open({id:$e}):!$e&&tt.isOpen&&tt.close()},[$e]);let at=(0,X.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=z+(i||0),s=`${o}-${Me.id}-${a}`,c=Me;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)(Kp,{dataSource:t,schema:{type:`object-chart`,objectName:R.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)(Gs,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=Xp(c.filter??e.filter,qe.id);return et.length?[...Array.isArray(t)?t:[],...et]:t})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{ue(c.id,c,{densityMode:e})},onSortChange:e=>{ue(c.id,c,{sort:e})},onFilterChange:e=>{ue(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{ue(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{ue(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(R?.actions)?R.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:x(R.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(R.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:w(R.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(R.name,c.name||c.id||``,c.emptyState??e.emptyState??Hp(R?.managedBy,h)),aria:c.aria??e.aria,tabs:e.tabs,...(()=>{let e=Xp([...Array.isArray(c.filter)?c.filter:[],...et],qe.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||R.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||R.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||R.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||R.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&&Je.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Je.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)=>{rt(e,t)},onSortChange:e=>{ue(c.id,c,{sort:e})},onFilterChange:e=>{ue(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{ue(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{ue(c.id,c,{columnState:e})},dataSource:t},s)},[Me,R,o,z,tt,Je,ue,et]),ot=(0,X.useMemo)(()=>Oe.map(e=>e.id===Ae&&I&&I.id===e.id?{...e,...I}:e),[Oe,Ae,I]),st=(0,X.useMemo)(()=>({type:`object-view`,objectName:R.name,layout:`page`,showSearch:Me?.showSearch!==!1,showFilters:Me?.showFilters!==!1,showSort:Me?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:_e,viewActions:_e?[{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(R.name,Me?.name??``,Me?.label??``)||g(R)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[R,n,Me?.showSearch,Me?.showFilters,Me?.showSort,Me?.name,Me?.label,i,c,_e,f.pathname,f.search,y,g]);return(0,Z.jsxs)(ae,{...V.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)(Mu,{title:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:g(R)}),(0,Z.jsx)(Of,{managedBy:R?.managedBy})]}),description:R.description?_(R):void 0,icon:(0,Z.jsx)(xl(R?.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(R),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)(Pe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Z.jsx)(di,{className:`h-4 w-4`})}),xe.create&&L(R.name,`create`)&&(0,Z.jsxs)(K,{size:`sm`,onClick:Je.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Z.jsx)(No,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),xe.import&&L(R.name,`create`)&&(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>Ce(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:h(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Z.jsx)(Gi,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),R.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,Z.jsx)(P,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(R.actions||[]).map(e=>({...e,label:x(R.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(R.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:w(R.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),xe.create&&L(R.name,`create`)&&(0,Z.jsx)(`button`,{type:`button`,onClick:Je.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)(No,{className:`h-5 w-5`})}),Se&&(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(qp,{open:Se,onOpenChange:Ce,objectName:R.name,objectLabel:g(R),fields:Object.entries(R.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{ve(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?J.warning(h(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&J.success(h(`console.objectView.importedToast`,{count:t}))}})}),Oe.length>=1&&(()=>{let e=Oe.map(e=>{let t=we.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(R.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)(tc,{views:e,activeViewId:Ae,onViewChange:Fe,viewTypeIcons:Jp,config:{reorderable:!1,showAddButton:_e,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:_e?Ke:void 0,onRenameView:_e?Be:void 0,onDeleteView:_e?Ve:void 0,onPinView:_e?He:void 0,onSetDefaultView:_e?Ue:void 0,onConfigView:_e?Ge:void 0,onManageViews:_e?()=>oe(!0):void 0}),_e&&(0,Z.jsx)($s,{open:ie,onOpenChange:oe,views:e,activeViewId:Ae,viewTypeIcons:Jp,onRename:Be,onDelete:Ve,onSetDefault:Ue,onSetPinned:He,onReorder:We,onAddView:Ke,onConfigView:Ge})]})})})(),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[tt.mode===`split`&&tt.isOpen?(0,Z.jsx)(xn,{...tt,setIsOpen:e=>{e||nt()},title:g(R),onExpand:it,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${R.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)(sc,{schema:st,dataSource:e,views:ot,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{rt(e,t)},renderListView:at,onCreateView:Le,onViewAction:Re})})}),typeof pe==`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:pe})})]}),children:r=>{let i=r.id||r._id;return(0,Z.jsx)(Vp,{dataSource:e,objects:t,onEdit:n,objectNameOverride:R.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)(sc,{schema:st,dataSource:e,views:ot,activeViewId:Ae,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{rt(e,t)},renderListView:at,onCreateView:Le,onViewAction:Re})})})}),(0,Z.jsx)(Yu,{open:p&&_e,sections:[{title:`View Configuration`,data:Me},{title:`Object Definition`,data:R}]}),(0,Z.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${M&&_e?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Z.jsx)(Sf,{open:M&&_e,onClose:()=>{ee(!1),te(`edit`)},mode:N,activeView:Me,objectDef:R,recordCount:pe,onSave:de,onViewUpdate:Ne,onCreate:fe,metadataClient:j,onAfterChange:()=>ve(e=>e+1)})}),(0,Z.jsx)(Ef,{open:F&&_e,onOpenChange:re,existingLabels:Oe.map(e=>e.label).filter(Boolean),objectDef:R,onCreate:e=>fe(e)})]}),tt.mode!==`split`&&(0,Z.jsx)(xn,{...tt,setIsOpen:e=>{e||nt()},title:g(R),onExpand:it,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${R.name}`,children:r=>{let i=r.id||r._id;return(0,Z.jsx)(Vp,{dataSource:e,objects:t,onEdit:n,objectNameOverride:R.name,recordIdOverride:i,embedded:!0})}})]}),V.dialogs]})}var $p=t({RecordFormPage:()=>em});function em({mode:e}){let{appName:t,objectName:n,recordId:r}=s(),i=v(),[a]=m(),o=ye(),{objects:c,loading:l}=se(),{t:u}=B(),{objectLabel:d}=zr(),{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)(()=>{J.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 V({user:A,app:{name:t},data:{}}),[A,t]),M=(0,X.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:Ic(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>Ic(e.visible,j)).map(([e])=>e):[],[b,j]);return l?(0,Z.jsx)(Af,{}):b?(0,Z.jsx)(Pc,{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)(Or,{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)(Of,{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)(Go,{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:M,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)(Ot,{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)(Zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:u(`empty.objectNotFound`)}),(0,Z.jsx)(qt,{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)(Or,{className:`mr-2 h-4 w-4`}),u(`empty.back`)]})})]})})}var tm={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:mr},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:$e},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:qn},line:{id:`line`,label:`Line chart`,category:`chart`,icon:yo},area:{id:`area`,label:`Area chart`,category:`chart`,icon:ut},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:Yr},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:wn},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:jo},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Qt},table:{id:`table`,label:`Data table`,category:`data`,icon:Sr},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:Zt},list:{id:`list`,label:`Record list`,category:`data`,icon:hn},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:Ut}},nm={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},rm=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(tm).filter(t=>t.category===e)})),im=ma;function am({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?rm.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):rm},[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)(No,{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)(Oo,{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:nm[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)(tm[t.id]?.icon??im,{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 om={io:`input`,unrepresentable:`any`},sm=new Set([`widgets`,`label`,`description`,`name`]),cm,lm=!1;function um(){if(cm||lm)return cm;try{cm=xe(Ee,om)}catch(e){lm=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return cm}var dm;function fm(){if(dm)return dm;if(!(!De||typeof De!=`object`)){try{let e=JSON.parse(JSON.stringify(De));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!sm.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),dm=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return dm}}var pm=new Set([`name`,`label`,`description`,`widgets`]);function mm({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=X.useCallback(e=>Y(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=xs(`widget`,l.map(e=>e?.id).filter(Boolean)),r=tm[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;t({widgets:ys(l,{id:n,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:zs(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:Is(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(()=>Ps({bundledSchema:um(),bundledForm:fm(),serverSchema:a,excludeFields:pm,sectionTitle:Y(`engine.inspector.moreFields`,r)}),[a,r]);return(0,Z.jsxs)(Es,{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)(Ts,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,Z.jsx)(Ts,{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)(U,{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=tm[e?.type]?.icon??im;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)(Ae,{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)(Jr,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,Z.jsx)(am,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,Z.jsx)(ks,{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 hm=[{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`}],gm=[`count`,`sum`,`avg`,`min`,`max`],_m=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function vm(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 ym({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){if(t.kind!==`widget`)return(0,Z.jsx)(xm,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});let s=vm(e,t.id);if(!s)return(0,Z.jsx)(xm,{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:Is(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:Y(`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)(js,{index:l,total:u.length,onMove:_,upLabel:Y(`engine.inspector.reorder.up`,o),downLabel:Y(`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:Y(`engine.inspector.widget.close`,o),"aria-label":Y(`engine.inspector.widget.close`,o),children:(0,Z.jsx)(Jr,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsx)(bm,{id:`widget-title`,label:Y(`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)(bm,{id:`widget-type`,label:Y(`engine.inspector.widget.type`,o),children:(0,Z.jsxs)(Vn,{value:c.type??`metric`,onValueChange:e=>d({type:e}),disabled:a,children:[(0,Z.jsx)(cr,{id:`widget-type`,children:(0,Z.jsx)(Dt,{})}),(0,Z.jsx)(Fo,{children:hm.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:Y(`engine.inspector.widget.datasetSection`,o)}),(0,Z.jsxs)(bm,{id:`widget-dataset`,label:Y(`engine.inspector.widget.dataset`,o),children:[(0,Z.jsx)(W,{id:`widget-dataset`,value:p,placeholder:Y(`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:Y(`engine.inspector.widget.datasetHint`,o)})]}),p&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(bm,{id:`widget-dimensions`,label:Y(`engine.inspector.widget.dimensions`,o),children:[(0,Z.jsx)(W,{id:`widget-dimensions`,value:m,placeholder:Y(`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:Y(`engine.inspector.widget.dimensionsHint`,o)})]}),(0,Z.jsxs)(bm,{id:`widget-values`,label:Y(`engine.inspector.widget.values`,o),children:[(0,Z.jsx)(W,{id:`widget-values`,value:h,placeholder:Y(`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:Y(`engine.inspector.widget.valuesHint`,o)})]})]})]}),(0,Z.jsx)(bm,{id:`widget-object`,label:Y(`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)(bm,{id:`widget-value-field`,label:Y(`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)(bm,{id:`widget-category-field`,label:Y(`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)(bm,{id:`widget-aggregate`,label:Y(`engine.inspector.widget.aggregate`,o),children:(0,Z.jsxs)(Vn,{value:c.aggregate??`count`,onValueChange:e=>d({aggregate:e}),disabled:a,children:[(0,Z.jsx)(cr,{id:`widget-aggregate`,children:(0,Z.jsx)(Dt,{})}),(0,Z.jsx)(Fo,{children:gm.map(e=>(0,Z.jsx)(Ye,{value:e,children:e},e))})]})}),(0,Z.jsx)(bm,{id:`widget-color`,label:Y(`engine.inspector.widget.color`,o),children:(0,Z.jsxs)(Vn,{value:c.colorVariant??`default`,onValueChange:e=>d({colorVariant:e}),disabled:a,children:[(0,Z.jsx)(cr,{id:`widget-color`,children:(0,Z.jsx)(Dt,{})}),(0,Z.jsx)(Fo,{children:_m.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)(bm,{id:`widget-w`,label:Y(`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)(bm,{id:`widget-h`,label:Y(`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:Y(`engine.inspector.widget.remove`,o)})})]})}function bm({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 xm({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:Y(`engine.inspector.widget.close`,n)})]})}function Sm({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}=B(),f=(0,X.useMemo)(()=>Ms(),[]),[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)(Or,{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)(zn,{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)(Jr,{className:`h-4 w-4`})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:x?(0,Z.jsx)(ym,{type:`dashboard`,name:S,draft:n??{},selection:{kind:`widget`,id:r},onPatch:_,onClearSelection:()=>i(null),onSelectionChange:y,readOnly:!1,locale:f}):(0,Z.jsx)(mm,{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)(gf,{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 Cm=t({DashboardView:()=>km}),wm=[{type:`metric`,label:`KPI Metric`,Icon:Mt},{type:`bar`,label:`Bar Chart`,Icon:Qn},{type:`line`,label:`Line Chart`,Icon:yo},{type:`pie`,label:`Pie Chart`,Icon:Yr},{type:`table`,label:`Table`,Icon:Sr},{type:`pivot`,label:`Pivot`,Icon:pt}],Tm=0;function Em(){return Tm+=1,`widget_${Date.now()}_${Tm}`}function Dm(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:Em()})}}function Om(e){let t=wm.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function km({dataSource:e}){let{dashboardName:t}=s(),{showDebug:n}=Xu(),r=ye(),i=_s(),{t:a}=B(),{dashboardLabel:o,dashboardDescription:c}=zr(),{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()=>{J.info(a(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return J.error(a(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(J.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}=se(),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 df(`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),J.error(`Failed to save dashboard: ${t}`)}},[i,t,T]),A=(0,X.useCallback)(()=>{O(Dm(E)),m(!0)},[E]),j=(0,X.useCallback)(()=>{m(!1),g(null)},[]),M=(0,X.useCallback)(e=>{if(!D)return;let t=Em(),n={id:t,title:Om(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]),ee=(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]),N=(0,X.useCallback)(e=>{let t=D||E;if(!t)return;let n={...t,widgets:e};O(n),k(n)},[D,E,k]),P=(D||E)??null,te=(0,X.useMemo)(()=>new Set((w||[]).map(e=>e?.name).filter(Boolean)),[w]),ne=D||E,F=(0,X.useMemo)(()=>{if(!ne||te.size===0)return ne;let e=ne.widgets;if(!Array.isArray(e)||e.length===0)return ne;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?te.has(t):!0});return t.length===e.length?ne:{...ne,widgets:t}},[ne,te]);return d?(0,Z.jsx)(kf,{}):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=Ml((F||E).title,a),t=Ml(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=(F||E).description??E.description,t=c({name:E.name,description:Ml(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:wm.map(({type:e,label:t,Icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>M(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)(No,{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)(Vt,{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)(cc,{schema:F,dataSource:e,designMode:p,selectedWidgetId:h,onWidgetClick:g,onWidgetsReorder:N,modalHandler:b,scriptHandlers:x,hideHeaderText:!0})}),(0,Z.jsx)(Sm,{open:p&&u,onClose:j,schema:P,selectedWidgetId:h,onSelectWidget:g,onSave:k,onChange:O,onRemoveWidget:ee,name:t,metadataClient:i,onAfterChange:()=>T().catch(()=>{})}),(0,Z.jsx)(Yu,{open:n,sections:[{title:`Dashboard Configuration`,data:F}]})]}),_&&_.schema?.objectName?(0,Z.jsx)(Uo,{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)(ht,{open:!0,onOpenChange:e=>{e||y({success:!1})},children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:_.schema?.title||a(`actionDialog.defaultActionTitle`)}),_.schema?.description&&(0,Z.jsx)(Xt,{children:_.schema.description})]}),(0,Z.jsxs)(Ln,{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)(Ot,{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:a(`empty.dashboardNotFound`)}),(0,Z.jsx)(qt,{children:a(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var Am=t({PageView:()=>jm});function jm(){let{t:e}=B(),{pageName:t}=s(),[n]=m(),{showDebug:r}=Xu(),i=v(),a=u(),{user:o}=S(),c=o?.role===`admin`,{pages:l,objects:d}=se(),f=ye(),[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)(Ot,{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)(uo,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:e(`empty.pageNotFound`)}),(0,Z.jsx)(qt,{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)(Gp,{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)(Vt,{className:`h-3.5 w-3.5`}),e(`common.editInStudio`,{defaultValue:`Edit in studio`})]}),(0,Z.jsx)(P,{schema:{...g,type:g.type||`page`,context:{...g.context,params:_,refreshKey:p}}},p)]}),(0,Z.jsx)(Yu,{open:r,sections:[{title:`Page Configuration`,data:g}]})]})})}function Mm(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function Nm(e){let t=typeof e.name==`string`?e.name:``;if(!t)return null;let n=Array.isArray(e.dimensions)?e.dimensions.filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({name:e.name,type:typeof e.type==`string`?e.type:void 0})):[],r=Array.isArray(e.measures)?e.measures.filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({name:e.name,aggregate:typeof e.aggregate==`string`?e.aggregate:void 0,certified:e.certified===!0})):[];return{name:t,label:Mm(e.label,t),dimensions:n,measures:r}}function Pm(e){let t=_s(),[n,r]=X.useState({datasets:e??[],loading:!e,error:null});return X.useEffect(()=>{if(e){r({datasets:e,loading:!1,error:null});return}let n=!1;return r(e=>({...e,loading:!0,error:null})),t.list(`dataset`).then(e=>{n||r({datasets:(Array.isArray(e)?e:[]).map(Nm).filter(e=>e!==null),loading:!1,error:null})}).catch(e=>{n||r({datasets:[],loading:!1,error:e?.message??String(e)})}),()=>{n=!0}},[t,e]),n}function Fm(e,t){let n=_s(),r=e?t.datasets.find(t=>t.name===e):void 0,i=!!e&&!t.loading&&(!r||r.dimensions.length===0&&r.measures.length===0),[a,o]=X.useState(null);X.useEffect(()=>{if(!i||!e||a?.name===e)return;let t=!1;return n.get(`dataset`,e).then(n=>{t||o({name:e,entry:n?Nm(n):null,error:n?null:`Dataset not found`})}).catch(n=>{t||o({name:e,entry:null,error:n?.message??String(n)})}),()=>{t=!0}},[n,e,i,a]);let s=i&&a?.name===e?a.entry:r;return{dimensions:s?.dimensions??[],measures:s?.measures??[],loading:t.loading||i&&a?.name!==e,error:(i&&a?.name===e?a.error:null)??t.error}}var Im={io:`input`,unrepresentable:`any`},Lm=new Set([`dataset`,`values`,`rows`,`columns`,`name`]),Rm,zm=!1;function Bm(){if(Rm||zm)return Rm;try{Rm=xe(we,Im)}catch(e){zm=!0,typeof console<`u`&&console.warn(`[report-schema] failed to derive Report JSONSchema from spec`,e)}return Rm}var Vm;function Hm(){if(Vm)return Vm;if(!(!Te||typeof Te!=`object`)){try{let e=JSON.parse(JSON.stringify(Te)),t=Bm()?.properties;for(let n of e.sections??[])n.fields=(n.fields??[]).filter(e=>{let n=typeof e==`string`?e:e?.field;return!(Lm.has(n)||t&&!(n in t))});if(t&&`runtimeFilter`in t){let t=new Set;for(let n of e.sections??[])for(let e of n.fields??[])t.add(typeof e==`string`?e:e?.field);t.has(`runtimeFilter`)||(e.sections=[...e.sections??[],{label:`Filter`,description:`Render-time scope filter, ANDed at query time.`,collapsible:!0,collapsed:!0,fields:[{field:`runtimeFilter`,widget:`json`}]}])}e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Vm=e}catch(e){typeof console<`u`&&console.warn(`[report-schema] failed to prepare reportForm from spec`,e);return}return Vm}}var Um=new Set([`type`,`label`,`name`,`dataset`,`values`,`rows`,`columns`]),Wm={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 Gm(e,t){return X.useMemo(()=>{let n=Bm()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`tabular`,`summary`,`matrix`,`joined`]).map(e=>{let n=Wm[e],r=n?Y(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 Km(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function qm({label:e,emptyText:t,names:n,options:r,loading:i,error:a,readOnly:o,onCommit:s}){let[c,l]=X.useState(null),[u,d]=X.useState(null),f=X.useMemo(()=>new Set(n),[n]),p=X.useMemo(()=>{let e=new Map;for(let t of r)e.set(t.name,t.type);return e},[r]);return(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:e}),(0,Z.jsx)(U,{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:t}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Z.jsx)(Dd,{index:t,label:e,fieldName:e,fieldType:p.get(e)??`number`,selected:!1,canEdit:!o,dragging:c!==null,dropBefore:u===t&&c!==null&&c!==t,onSelect:()=>{},onRemove:()=>s(zs(n,t,null)),onDragStart:()=>l(t),onDragEnd:()=>{l(null),d(null)},onDragOverRow:()=>d(t),onDropRow:()=>{c!=null&&c!==t&&s(Is(n,c,t)),l(null),d(null)}},`${e}-${t}`))}),!o&&(0,Z.jsx)(Od,{fields:r,usedNames:f,loading:i,error:a,onAdd:e=>s(ys(n,e.name))})]})}function Jm({draft:e,onPatch:t,readOnly:n,locale:r,datasetCatalogOverride:i,serverSchema:a}){let o=X.useCallback(e=>Y(e,r),[r]),s=typeof e.type==`string`?e.type:`tabular`,c=Gm(s,r),l=typeof e.label==`string`?e.label:``,u=typeof e.dataset==`string`?e.dataset:``,d=X.useMemo(()=>Km(e.values),[e.values]),f=X.useMemo(()=>Km(e.rows),[e.rows]),p=X.useMemo(()=>Km(e.columns),[e.columns]),m=Pm(i),h=Fm(u||void 0,m),g=X.useMemo(()=>{let e=m.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return u&&!e.some(e=>e.value===u)&&e.push({value:u,label:u}),e},[m.datasets,u]),_=X.useMemo(()=>h.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[h.measures]),v=X.useMemo(()=>h.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[h.dimensions]),y=s!==`joined`,{schema:b,form:x}=X.useMemo(()=>Ps({bundledSchema:Bm(),bundledForm:Hm(),serverSchema:a,excludeFields:Um,sectionTitle:Y(`engine.inspector.moreFields`,r)}),[a,r]);return(0,Z.jsxs)(Es,{kindLabel:o(`engine.inspector.report.kind`),title:String(l||e.name||o(`engine.inspector.report.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.report.close`),hideClose:!0,children:[(0,Z.jsx)(Ts,{label:o(`engine.inspector.report.label`),value:l,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.report.labelPlaceholder`),disabled:n}),(0,Z.jsx)(Os,{label:o(`engine.inspector.report.type`),value:s,options:c,onCommit:e=>t({type:e}),disabled:n}),y&&(0,Z.jsxs)(Z.Fragment,{children:[m.datasets.length>0||u?(0,Z.jsx)(Os,{label:o(`engine.inspector.report.dataset`),value:u,options:g,onCommit:e=>t({dataset:e}),disabled:n}):(0,Z.jsx)(Ts,{label:o(`engine.inspector.report.dataset`),value:u,onCommit:e=>t({dataset:e}),placeholder:o(`engine.inspector.report.datasetPlaceholder`),disabled:n,mono:!0}),(0,Z.jsx)(qm,{label:o(`engine.inspector.report.values`),emptyText:o(`engine.inspector.report.valuesEmpty`),names:d,options:_,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({values:e})}),(0,Z.jsx)(qm,{label:o(`engine.inspector.report.rows`),emptyText:o(`engine.inspector.report.rowsEmpty`),names:f,options:v,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({rows:e})}),s===`matrix`&&(0,Z.jsx)(qm,{label:o(`engine.inspector.report.columnsAcross`),emptyText:o(`engine.inspector.report.columnsAcrossEmpty`),names:p,options:v,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({columns:e})})]}),(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:b?(0,Z.jsx)(ks,{schema:b,form:x,value:e,hiddenFields:[`type`,`label`,`name`,`dataset`,`values`,`rows`,`columns`],readOnly:n,onChange:e=>t(e)}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.report.noSchema`)})})]})}function Ym({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,name:a,metadataClient:o,onAfterChange:s}){let{t:c}=B(),l=(0,X.useMemo)(()=>Ms(),[]),[u,d]=(0,X.useState)(!1),f=(0,X.useMemo)(()=>({...n??{}}),[n]),[p,m]=(0,X.useState)(f),h=(0,X.useRef)(p),g=(0,X.useRef)(f);g.current!==f&&(g.current=f,h.current=f,m(f),d(!1));let _=(0,X.useCallback)(e=>{let t={...h.current,...e};if(h.current=t,m(t),d(!0),i)for(let[n,r]of Object.entries(e))i(n,r,t)},[i]),v=(0,X.useCallback)(()=>{r(h.current),d(!1),t()},[r,t]),y=(0,X.useCallback)(e=>{let t={...e};h.current=t,m(t),d(!1)},[]),b=(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":c(`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:c(`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":c(`common.close`,{defaultValue:`Close`}),"data-testid":`report-config-close`,children:(0,Z.jsx)(Jr,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,Z.jsx)(Jm,{type:`report`,name:typeof p.name==`string`?p.name:``,draft:p,readOnly:!1,locale:l,onPatch:_})}),(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)(gf,{type:`report`,name:a,metadataClient:o,dirty:u,onResume:y,onAfterChange:s}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:b,"data-testid":`report-config-discard`,children:c(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(K,{size:`sm`,onClick:v,"data-testid":`report-config-save`,children:c(`common.save`,{defaultValue:`Save`})})]})]}):null}var Xm=t({ReportView:()=>eh}),Zm=(0,X.lazy)(()=>d(()=>import(`./plugin-report-rz8HUIsi.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),Qm=(0,X.lazy)(()=>d(()=>import(`./plugin-report-rz8HUIsi.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),$m=[{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 eh({dataSource:e}){let{t}=B(),{appName:n,reportName:r}=s(),i=v(),{showDebug:a}=Xu();ye();let o=_s(),{user:c}=S(),l=c?.role===`admin`,[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(0),{reports:m,objects:h,loading:g,refresh:_}=se(),y=m?.find(e=>e.name===r),[b,x]=(0,X.useState)(y),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)([]),[D,O]=(0,X.useState)(!1),k=(0,X.useCallback)(e=>{if(!e||!h?.length)return;let t=h.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`}))},[h]),A=(0,X.useCallback)(async({dataset:e,groupKey:t})=>{try{let r=await o.get(`dataset`,e),a=typeof r?.object==`string`?r.object:void 0;if(!a)return;let s=Array.isArray(r?.dimensions)?r.dimensions:[],c=new Map(s.filter(e=>e?.name).map(e=>[e.name,e])),l=h?.find(e=>e.name===a)?.fields,u=e=>{if(Array.isArray(l))return l.find(t=>t?.name===e);if(l&&typeof l==`object`)return l[e]},d=new URLSearchParams;for(let[e,n]of Object.entries(t)){if(n==null)continue;let t=c.get(e);if(t?.dateGranularity)continue;let r=t?.field||e,i=u(r);if(i?.type===`lookup`||i?.type===`master_detail`)continue;let a=n;if(Array.isArray(i?.options)){let e=i.options.find(e=>e?.label===n||e?.value===n);e&&e.value!=null&&(a=e.value)}d.set(`filter[${r}]`,String(a))}let f=d.toString();i(`${n?`/apps/${n}`:``}/${a}${f?`?${f}`:``}`)}catch(e){console.warn(`ReportView: drill navigation failed`,e)}},[o,i,n,h]),j=(0,X.useMemo)(()=>{let e=C||b;return k(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??$m},[C,b,k]),M=(0,X.useCallback)(async e=>{try{o&&(await df(`report`,r,e,{metadataClient:o}),_().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[o,r,_]),ee=(0,X.useCallback)(()=>{w(b),d(!0),p(e=>e+1)},[b]),N=(0,X.useCallback)(()=>{d(!1)},[]),P=(0,X.useMemo)(()=>C||b,[f]),te=(0,X.useCallback)(e=>{w(e),M(e),p(e=>e+1)},[M]),ne=(0,X.useCallback)((e,t)=>{w(n=>({...n,[e]:t}))},[]);(0,X.useEffect)(()=>{x(y)},[y]),(0,X.useEffect)(()=>{u||w(null)},[y]);let F=C||b,re=(0,X.useMemo)(()=>JSON.stringify(F?.filters),[F?.filters]),ie=(0,X.useMemo)(()=>JSON.stringify(F?.dataSource),[F?.dataSource]),ae=(0,X.useMemo)(()=>JSON.stringify(F?.data),[F?.data]);if((0,X.useEffect)(()=>{if(!F||!e){E([]);return}if(F.data&&Array.isArray(F.data)){E(F.data);return}if(F.dataSource){(async()=>{O(!0);try{let t=F.dataSource.object||F.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),E([]);return}E((await e.find(t,{$filter:F.dataSource.filter,$orderby:F.dataSource.sort,$top:F.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),E([])}finally{O(!1)}})();return}if(F.objectName){(async()=>{O(!0);try{E((await e.find(F.objectName,{$filter:F.filters,$orderby:F.sort,$top:F.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),E([])}finally{O(!1)}})();return}E([])},[F?.objectName,F?.limit,re,ie,ae,e]),g)return(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsx)(H,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!y||!b)return!g&&!y?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsxs)(Ot,{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)(Qn,{className:`h-6 w-6 text-muted-foreground`})}),(0,Z.jsx)(Ue,{children:t(`empty.reportNotFound`)}),(0,Z.jsx)(qt,{children:t(`empty.reportNotFoundDescription`,{name:r})})]})}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,Z.jsx)(H,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let oe=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?h?.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},I=C||b,ce=!!(I&&(typeof I.dataset==`string`||I.type===`joined`&&Array.isArray(I.blocks)&&I.blocks.some(e=>typeof e?.dataset==`string`)))||!!(I&&I.objectName&&(I.type===`matrix`||I.type===`joined`||I.type===`summary`||I.type===`tabular`||I.type===void 0||Array.isArray(I.groupingsAcross)&&I.groupingsAcross.length>0||Array.isArray(I.columns))),le={type:`report-viewer`,report:oe(I),data:T,showToolbar:!0,allowExport:!0,loading:D};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:I.title||I.label||`Report Viewer`}),I.description&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:I.description})]}),(0,Z.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:l&&(0,Z.jsxs)(`button`,{type:`button`,onClick:ee,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)(Vt,{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:ce?(0,Z.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,Z.jsx)(Qm,{schema:I,dataSource:e,rows:T,onDrill:A})}):(0,Z.jsx)(Zm,{schema:le})})})}),(0,Z.jsx)(Ym,{open:u&&l,onClose:N,config:P,onSave:te,onFieldChange:ne,availableFields:j,getFieldsForObject:k,name:r,metadataClient:o,onAfterChange:()=>_().catch(()=>{})}),(0,Z.jsx)(Yu,{open:a,sections:[{title:`Report Configuration`,data:I}]})]})]})}var th=t({SearchResultsPage:()=>ah});function nh(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...nh(n.children)):t.push(n);return t}var rh={object:Zt,dashboard:kt,page:uo,report:Qn},ih={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 ah(){let{t:e}=B(),{appName:t}=s(),[n,r]=m(),[i,a]=(0,X.useState)(n.get(`q`)||``),{apps:o}=se(),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=nh(l.navigation||[]),t={currentUserId:d?.id??null};return e.map(e=>{let{href:n}=cs(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)(Or,{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)(Oo,{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)(Oo,{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=rh[t]||Zt,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)(U,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,Z.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=rh[t.type]||Zt,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)(xt,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,Z.jsxs)(Ht,{className:`flex items-center gap-3 p-3`,children:[(0,Z.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${ih[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)(U,{variant:`outline`,className:`text-xs shrink-0`,children:e(r)})]})})},t.id)})})]},t)})})]})}function oh(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 sh(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 ch=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=oh(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(sh)};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 lh(){let e=ye();return(0,X.useMemo)(()=>e?new ch(e):null,[e])}var uh=0;function dh(e=`nav`){return`${e}_${Date.now()}_${++uh}`}function fh(e,t){return[...e,t]}function ph(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:ph(e.children,t,n)}:e)}function mh(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:mh(i.children,t,n,r)}:i})}function hh(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function gh(e){return typeof e==`string`&&e.startsWith(`sys_`)}function _h(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`?!0:gh(t.name)}function vh(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function yh(){let e=ye(),{apps:t,refresh:n}=se(),{t:r}=B(),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=fh(a,{id:dh(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=fh(a,{id:dh(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,X.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=ph(i,`page`,t);if(hh(a,i))return;let c={...n,navigation:a};try{await o(e,c),J.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,X.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=ph(i,`dashboard`,t);if(hh(a,i))return;let c={...n,navigation:a};try{await o(e,c),J.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=mh(a,`page`,t,n);if(hh(c,a))return;let l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,X.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=mh(a,`dashboard`,t,n);if(hh(c,a))return;let l={...i,navigation:c};try{await o(e,l),J.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),J.info(r(`navigationSync.undone`))}catch{J.error(r(`navigationSync.undoFailed`))}}}})}catch{J.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!vh(r)||await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!vh(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,X.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!vh(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,X.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!vh(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!vh(r)||await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,X.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!vh(r)||await p(t,e,n)}},[t,p])}}function bh(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=se(),i=ye(),a=(0,X.useRef)(i);a.current=i;let o=$o(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=yh(),d=(0,X.useRef)(null),f=(0,X.useRef)(null),p=(0,X.useRef)(0),m=(0,X.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,X.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!_h(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(!(!t||!vh(e))){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var xh=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Sh(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ch(e){try{return decodeURIComponent(e)}catch{return e}}function wh({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=rs(),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}:${Ch(t)}`,label:Ch(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!xh.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:Sh(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Sh(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Sh(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Th=`objectstack:ai-chat-conversation-id`,Eh=`objectstack:ai-chat-messages`;function Dh(e,t){return t?`${Th}:${e}:${t}`:`${Th}:${e}`}function Oh(e){try{return localStorage.getItem(e)??void 0}catch{return}}function kh(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function Ah(e){return`${Eh}:${e}`}function jh(e){try{let t=localStorage.getItem(Ah(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 Mh(e,t){if(e)try{if(t.length===0){localStorage.removeItem(Ah(e));return}localStorage.setItem(Ah(e),JSON.stringify(t))}catch{}}function Nh(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 Ph(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)?Ph(e.parts):[]}function Fh(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=Ph(e.content);i.length!==0&&t.push({id:e.id??`msg-${n}`,role:r,parts:i})}),t}async function Ih(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 Lh(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 Rh(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function zh(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a}=e,[o,s]=(0,X.useState)(void 0),[c,l]=(0,X.useState)([]),[u,d]=(0,X.useState)(!!t),f=(0,X.useRef)(!0),p=(0,X.useRef)(void 0);return(0,X.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,X.useEffect)(()=>{if(!t){s(void 0),l([]),d(!1),p.current=void 0;return}if(!i&&!a&&p.current===t&&o)return;let e=!1,c=Dh(t,n);return!i&&a&&(s(void 0),l([])),d(!0),(async()=>{try{if(i){let n=await Ih(r,i);if(e)return;if(n){kh(c,n.id),s(n.id);let e=Fh(n.messages);l(e.length>0?e:jh(n.id)),p.current=t;return}kh(c,void 0),Mh(i,[])}else if(!a){let n=Oh(c);if(n){let i=await Ih(r,n);if(e)return;if(i){s(i.id);let e=Fh(i.messages);l(e.length>0?e:jh(i.id)),p.current=t;return}kh(c,void 0),Mh(n,[])}}let n=await Lh(r);if(e)return;kh(c,n.id),s(n.id),l(Fh(n.messages)),p.current=t}catch{e||(s(void 0),l([]))}finally{e||d(!1)}})(),()=>{e=!0}},[t,n,r,i,a]),{conversationId:o,initialMessages:c,isLoading:u,reset:(0,X.useCallback)(async()=>{if(!t)return;let e=Dh(t,n);d(!0);try{o&&await Rh(r,o),Mh(o,[]),kh(e,void 0);let t=await Lh(r);if(kh(e,t.id),Mh(t.id,[]),!f.current)return;s(t.id),l([])}catch{f.current&&(s(void 0),l([]))}finally{f.current&&d(!1)}},[o,t,n,r])}}var Bh=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function Vh(e){let t=e?.trim().toLowerCase();return!t||Bh.has(t)}function Hh(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=Uh(n.content);if(e)return e}}let n=t[t.length-1];return Uh(n?.content)}function Uh(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 Uh(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 Wh(e){let t=e.title?.trim(),n=Hh(e)??Uh(e.preview);return{id:e.id,title:Vh(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function Gh(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return Wh(`conversation`in r&&r.conversation?r.conversation:r)}function Kh(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(Wh).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=>Gh(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}}function qh({appName:e,error:t,onRetry:n}){let{t:r}=B(),i=!!t;return(0,Z.jsx)(`div`,{className:`flex h-screen items-center justify-center`,"data-testid":`preview-draft-empty-state`,children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Z.jsx)(_t,{className:`h-8 w-8`}):(0,Z.jsx)(nt,{className:`h-8 w-8`})}),(0,Z.jsx)(Ue,{children:i?r(`preview.empty.loadFailedTitle`,{defaultValue:`Draft preview failed to load`}):e?r(`preview.empty.notReadyTitle`,{app:e,defaultValue:`“{{app}}” isn’t in the draft yet`}):r(`preview.empty.nothingTitle`,{defaultValue:`Nothing to preview yet`})}),(0,Z.jsx)(qt,{children:i?r(`preview.empty.loadFailedDescription`,{defaultValue:`The draft overlay could not be read. Retry, or check your connection.`}):r(`preview.empty.notReadyDescription`,{defaultValue:`The build may still be running, or it may have failed before this app was staged. Check the conversation for the build status — this pane refreshes as drafts land.`})}),(0,Z.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,Z.jsxs)(K,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Z.jsx)(Ui,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var Jh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Pp).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Yh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Cm).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),Xh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Am).then(e=>({default:e.PageView})),void 0,import.meta.url)),Zh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>Xm).then(e=>({default:e.ReportView})),void 0,import.meta.url)),Qh=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>th).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),$h=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>$p).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),eg=(0,X.lazy)(()=>d(()=>import(`./ComponentNavView-BI4O_zkC.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),tg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),ng=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.StudioHomePage})),void 0,import.meta.url)),rg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),ig=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),ag=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),og=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>rD).then(e=>({default:e.MetadataDiagnosticsPage})),void 0,import.meta.url)),sg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>xA).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),cg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>xA).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),lg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>xA).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),ug=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>$g).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),dg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>c_).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),fg=(0,X.lazy)(()=>d(()=>Promise.resolve().then(()=>d_).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function pg({appName:e}){let{reviewSeq:t,reviewTarget:n}=Ko(),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 mg({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,X.useState)(`disconnected`),{user:o,getAuthConfig:c}=S(),l=ye(),[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,error:C,refresh:w}=se(),T=$o(),{t:E}=B(),{objectLabel:D}=zr(),[O,k]=(0,X.useState)(!x);(0,X.useEffect)(()=>{if(!x){k(!0);return}let e=!1;return Promise.all([x(`object`),x(`dashboard`),x(`report`),x(`page`)]).finally(()=>{e||k(!0)}),()=>{e=!0}},[x]);let A=_.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),j=_.find(e=>e.name===h)||A.find(e=>e.isDefault===!0)||A[0],M=T&&!!h&&!_.some(e=>e.name===h);(0,X.useEffect)(()=>{if(!j?.name)return;let e=`/apps/${j.name}/metadata/package`;(m.pathname===e||m.pathname.startsWith(`${e}/`))&&p(`/apps/${j.name}/component/developer/packages`,{replace:!0})},[j?.name,m.pathname,p]);let[ee,P]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[re,ie]=(0,X.useState)(0),{execute:ae,runner:oe}=F();N({dataSource:l??void 0,onUndo:e=>{J.info(`Undo: ${e.description}`,{duration:4e3}),ie(e=>e+1)},onRedo:e=>{J.info(`Redo: ${e.description}`,{duration:3e3}),ie(e=>e+1)}}),(0,X.useEffect)(()=>{oe.registerHandler(`crud_success`,async e=>(P(!1),ie(e=>e+1),J.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),oe.registerHandler(`dialog_cancel`,async()=>(P(!1),{success:!0})),oe.registerHandler(`navigate_create`,async e=>{let t=Dl({action:e,context:oe.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(p(t.url),{success:!0}):t}),oe.registerHandler(`navigate_edit`,async e=>{let t=Ol({action:e,context:oe.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(p(t.url),{success:!0}):t})},[oe,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 I=m.pathname.split(`/`).filter(Boolean)[2];(I===`view`||I===`record`||I===`page`||I===`dashboard`||I===`design`)&&(I=``);let ce=y.find(e=>e.name===I),le=(0,X.useCallback)(()=>{let e=ce?D(ce):E(`common.record`,{defaultValue:`Record`});ae({type:`crud_success`,params:{message:te?E(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):E(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[ae,te,ce,D,E]),ue=(0,X.useCallback)(()=>{ae({type:`dialog_cancel`})},[ae]);wh({pathname:m.pathname,appName:j?.name,objects:y});let de=e=>{let t=El({objectDef:ce,baseUrl:j?.name?`/apps/${j.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}ne(e),P(!0)},fe=e=>{p(`/apps/${e}`)},pe=(0,X.useMemo)(()=>new V({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:j||{},data:te||{}}),[o,j,te]);if(!l||b||!O)return(0,Z.jsx)(Ru,{});if(T&&(M||!j))return(0,Z.jsx)(qh,{appName:h,error:C,onRetry:()=>void w()});let me=m.pathname.endsWith(`/create-app`),he=m.pathname.includes(`/system`),ge=m.pathname.includes(`/metadata`);return!j&&!me&&!he&&!ge?(0,Z.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:E(`empty.noAppsConfigured`)}),(0,Z.jsx)(qt,{children:E(`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:E(`empty.createFirstApp`)}),(0,Z.jsx)(K,{variant:`outline`,onClick:()=>p(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:E(`empty.systemSettings`)})]})]})}):!j&&(me||he||ge)?(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`create-app`,element:(0,Z.jsx)(sg,{})}),(0,Z.jsx)(g,{path:`system/marketplace`,element:(0,Z.jsx)(ug,{})}),(0,Z.jsx)(g,{path:`system/marketplace/installed`,element:(0,Z.jsx)(fg,{})}),(0,Z.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,Z.jsx)(dg,{})}),(0,Z.jsx)(g,{path:`metadata`,element:(0,Z.jsx)(tg,{})}),(0,Z.jsx)(g,{path:`metadata/_diagnostics`,element:(0,Z.jsx)(og,{})}),(0,Z.jsx)(g,{path:`metadata/:type`,element:(0,Z.jsx)(rg,{})}),(0,Z.jsx)(g,{path:`metadata/:type/new`,element:(0,Z.jsx)(ig,{createMode:!0})}),(0,Z.jsx)(g,{path:`metadata/:type/:name`,element:(0,Z.jsx)(ig,{})}),(0,Z.jsx)(g,{path:`metadata/:type/:name/history`,element:(0,Z.jsx)(ag,{})}),t]})}):(0,Z.jsxs)(Pc,{user:o?{name:o.name,email:o.email,role:o.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:j,data:{},features:d,children:[(0,Z.jsx)(bh,{}),(0,Z.jsxs)(ju,{activeAppName:j.name,activeApp:j,onAppChange:fe,objects:y,connectionState:n,userId:o?.id,children:[(0,Z.jsx)(Nu,{apps:_,activeApp:j,objects:y,onAppChange:fe,dataSource:l}),(0,Z.jsx)(Fu,{}),(0,Z.jsx)(Iu,{}),(0,Z.jsx)(pg,{appName:h}),(0,Z.jsx)(Ju,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(Vu,{className:`h-full`,children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`/`,element:(()=>{let e=vg(j,{currentUserId:o?.id??null});return e?(0,Z.jsx)(i,{to:e,replace:!0}):(0,Z.jsx)(ng,{})})()}),(0,Z.jsx)(g,{path:`metadata/package/*`,element:(0,Z.jsx)(i,{to:`/apps/${j.name}/component/developer/packages`,replace:!0})}),(0,Z.jsxs)(g,{path:`metadata`,children:[(0,Z.jsx)(g,{index:!0,element:(0,Z.jsx)(tg,{})}),(0,Z.jsx)(g,{path:`_diagnostics`,element:(0,Z.jsx)(og,{})}),(0,Z.jsx)(g,{path:`:type`,element:(0,Z.jsx)(rg,{})}),(0,Z.jsx)(g,{path:`:type/new`,element:(0,Z.jsx)(ig,{createMode:!0})}),(0,Z.jsx)(g,{path:`:type/:name`,element:(0,Z.jsx)(ig,{})}),(0,Z.jsx)(g,{path:`:type/:name/history`,element:(0,Z.jsx)(ag,{})})]}),(0,Z.jsx)(g,{path:`:objectName`,element:(0,Z.jsx)(Zp,{dataSource:l,objects:y,onEdit:de,externalRefreshKey:re})}),(0,Z.jsx)(g,{path:`:objectName/new`,element:(0,Z.jsx)($h,{mode:`create`})}),(0,Z.jsx)(g,{path:`:objectName/view/:viewId`,element:(0,Z.jsx)(Zp,{dataSource:l,objects:y,onEdit:de,externalRefreshKey:re})}),(0,Z.jsx)(g,{path:`:objectName/record/:recordId`,element:(0,Z.jsx)(Jh,{dataSource:l,objects:y,onEdit:de},re)}),(0,Z.jsx)(g,{path:`:objectName/record/:recordId/edit`,element:(0,Z.jsx)($h,{mode:`edit`})}),(0,Z.jsx)(g,{path:`dashboard/:dashboardName`,element:(0,Z.jsx)(Yh,{dataSource:l})}),(0,Z.jsx)(g,{path:`report/:reportName`,element:(0,Z.jsx)(Zh,{dataSource:l})}),(0,Z.jsx)(g,{path:`page/:pageName`,element:(0,Z.jsx)(Xh,{})}),(0,Z.jsx)(g,{path:`component/:ns/:name/*`,element:(0,Z.jsx)(eg,{})}),(0,Z.jsx)(g,{path:`component/metadata/directory`,element:(0,Z.jsx)(xg,{mode:`directory`})}),(0,Z.jsx)(g,{path:`component/metadata/resource/*`,element:(0,Z.jsx)(xg,{mode:`resource`})}),(0,Z.jsx)(g,{path:`design/dashboard/:dashboardName`,element:(0,Z.jsx)(lg,{})}),(0,Z.jsx)(g,{path:`search`,element:(0,Z.jsx)(Qh,{})}),(0,Z.jsx)(g,{path:`create-app`,element:(0,Z.jsx)(sg,{})}),(0,Z.jsx)(g,{path:`edit-app/:editAppName`,element:(0,Z.jsx)(cg,{})}),(0,Z.jsx)(g,{path:`system/marketplace`,element:(0,Z.jsx)(ug,{})}),(0,Z.jsx)(g,{path:`system/marketplace/installed`,element:(0,Z.jsx)(fg,{})}),(0,Z.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,Z.jsx)(dg,{})}),e,(0,Z.jsx)(g,{path:`:objectName/:maybeRecordId`,element:(0,Z.jsx)(Sg,{})}),(0,Z.jsx)(g,{path:`*`,element:(0,Z.jsx)(Cg,{})})]})})})}),ce&&(0,Z.jsx)(Uo,{schema:{type:`object-form`,formType:`modal`,objectName:ce.name,mode:te?`edit`:`create`,recordId:te?.id,subforms:ce.form?.subforms??ce.formViews?.default?.subforms,title:E(te?`form.editTitle`:`form.createTitle`,{object:D(ce)}),description:E(te?`form.editDescription`:`form.createDescription`,{object:D(ce)}),open:ee,onOpenChange:P,layout:`vertical`,fields:ce.fields?Array.isArray(ce.fields)?ce.fields.filter(e=>typeof e==`string`?!0:Ic(e.visible,pe)).map(e=>typeof e==`string`?e:e.name):Object.entries(ce.fields).filter(([e,t])=>Ic(t.visible,pe)).map(([e])=>e):[],onSuccess:le,onCancel:ue,showSubmit:!0,showCancel:!0,submitText:te?E(`form.update`,{defaultValue:E(`common.save`,{defaultValue:`Save`})}):E(`form.create`,{defaultValue:E(`common.create`,{defaultValue:`Create`})}),cancelText:E(`common.cancel`)},dataSource:l},te?.id||`new`)]})]})}function hg(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=gg(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=hg(n.children,t);if(e!==``)return e}}return``}function gg(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=cs(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function _g(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=_g(n.children,t);if(e)return e}}}function vg(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=gg(_g(r,n),t);if(e)return e}return hg(r,t)}var yg=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function bg(e){return!e||yg.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function xg({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 Sg(){let{objectName:e,maybeRecordId:t}=s(),n=u();return e&&bg(t)?(0,Z.jsx)(i,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Z.jsx)(Cg,{})}function Cg(){let e=v(),{t}=B();return(0,Z.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Z.jsx)(qt,{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 wg({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 Tg(){let e=v(),{appName:t}=s(),{t:n}=B(),r=t?`/apps/${t}`:`/`;return(0,Z.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,Z.jsx)(xt,{children:(0,Z.jsxs)(Ht,{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)(st,{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 Eg=`en`;function Dg(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function Og(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function kg(e,t,n){if(!e)return;let r=Dg(t),i=Og([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),Eg]);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 Ag(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 jg(e,t){let n=t||Eg;return{displayName:kg(e.translations??void 0,n,`displayName`)??Ag(e,`displayName`)??e.manifest_id,description:kg(e.translations??void 0,n,`description`)??Ag(e,`description`),readme:kg(e.translations??void 0,n,`readme`)??Ag(e,`readme`),tagline:kg(e.translations??void 0,n,`tagline`)??Ag(e,`tagline`)}}var Mg=``.replace(/\/$/,``),Ng=`${Mg}/api/v1/marketplace`;function Pg(e){let t=C.get();return t?{...e,Authorization:`Bearer ${t}`}:e}async function Fg(e,t){let n=await fetch(`${Ng}${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 Ig(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 Fg(`/packages${n?`?${n}`:``}`)}async function Lg(e){return Fg(`/packages/${encodeURIComponent(e)}`)}async function Rg(e){if(Ws()){let t=await fetch(`/api/v1/cloud-connection/install`,{method:`POST`,credentials:`include`,headers:Pg({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(`${Mg}/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 zg(){let e=Ws()||Mg,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 Bg(){let e=Ws()||Mg,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 Vg(e){return`${Ws()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function Hg(e,t){if(!e)return null;if(Ws())try{let t=await fetch(`/api/v1/cloud-connection/installation?package_id=${encodeURIComponent(e)}`,{credentials:`include`,headers:Pg({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=Mg,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 Ug(e){if(!e)return{ok:!1,error:`installation id required`};let t=Ws()||Mg;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 Wg(e){if(!e)return{ok:!1,error:`installation id required`};let t=Ws()||Mg;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 Gg(){try{let e=await fetch(`${Mg}/api/v1/cloud-connection/org-packages`,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return{connected:!1,items:[]};let t=(await e.json().catch(()=>({})))?.data??{},n=Array.isArray(t.items)?t.items:[];return{connected:t.connected===!0,items:n}}catch{return{connected:!1,items:[]}}}async function Kg(e){let t=await fetch(`${Ng}/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 qg(){try{let e=await fetch(`${Ng}/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 Jg(){try{let e=await fetch(`${Mg}/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 Yg(e){let t=await fetch(`${Ng}/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 Xg(e,t){let n=await fetch(`${Ng}/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 Zg(e){return Xg(e,`reseed`)}function Qg(e){return Xg(e,`purge`)}var $g=t({MarketplacePage:()=>t_});function e_(){let{language:e,t}=B();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 t_(){let e=v(),{appName:t}=s(),n=x(),{t:r,language:i}=B(),a=e_(),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,C]=(0,X.useState)([]),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(new Set),A=(0,X.useMemo)(()=>{let e=new Map;for(let t of y)e.set(t.manifestId,t);return e},[y]),j=async()=>{d(!0),p(null);try{let[e,t,n,r]=await Promise.all([Ig({limit:100}),qg(),Gg(),Jg()]);l(e.items??[]),b(t),C(n.items??[]);let i=new Set;for(let e of t)i.add(e.manifestId);for(let e of r.items)i.add(e.manifestId);k(i)}catch(e){p(e?.message??String(e)),l([])}finally{d(!1)}};(0,X.useEffect)(()=>{j()},[]);let M=async e=>{T(e.id),D(null);try{Vs().features.installLocal?await Kg({packageId:e.manifest_id||e.id,versionId:`latest`}):await Rg({packageId:e.id,environmentId:``,seedSampleData:!0}),D({ok:!0,text:r(`marketplace.org.installed`,{defaultValue:`Installed ${e.display_name}`,name:e.display_name})}),await j()}catch(e){D({ok:!1,text:e?.message??String(e)})}finally{T(null)}},ee=(0,X.useMemo)(()=>{let e=new Set;for(let t of c)t.category&&e.add(t.category);return Array.from(e).sort()},[c]),N=e=>{let t=`marketplace.category.${e}`,n=r(t,{defaultValue:e});return n===t?e:n},P=(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=jg(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)(Dr,{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 j(),disabled:u,children:[(0,Z.jsx)(tn,{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)(Oo,{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`)})]}),ee.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`)}),ee.map(e=>(0,Z.jsx)(K,{size:`sm`,variant:g===e?`default`:`outline`,onClick:()=>_(e),children:N(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)(ci,{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`)}})]})]}),S.length>0&&(0,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Dr,{className:`h-5 w-5 text-primary`,"aria-hidden":`true`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:r(`marketplace.org.heading`,{defaultValue:`Your organization`})}),(0,Z.jsx)(U,{variant:`secondary`,className:`text-xs`,children:S.length})]}),E&&(0,Z.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${E.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:E.text}),(0,Z.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:S.map(e=>{let t=O.has(e.manifest_id);return(0,Z.jsxs)(xt,{className:`flex flex-col`,"data-testid":`org-card-${e.manifest_id}`,children:[(0,Z.jsxs)(Lt,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Z.jsx)(wg,{iconUrl:e.icon_url,displayName:e.display_name,manifestId:e.manifest_id}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(br,{className:`text-base truncate`,children:e.display_name}),(0,Z.jsx)(Ma,{className:`text-xs truncate`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:e.manifest_id})})]}),e.visibility&&(0,Z.jsx)(U,{variant:`outline`,className:`shrink-0 text-xs`,children:e.visibility})]}),(0,Z.jsxs)(Ht,{className:`flex-1 flex flex-col gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:e.description||r(`marketplace.noDescription`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-auto pt-2 flex-wrap`,children:[e.latest_version&&(0,Z.jsxs)(U,{variant:`outline`,className:`text-xs`,children:[(0,Z.jsx)(Rr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:e.latest_version})]}),(0,Z.jsx)(`div`,{className:`ml-auto`,children:t?(0,Z.jsxs)(U,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,Z.jsx)(aa,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.org.installedBadge`,{defaultValue:`Installed`})]}):(0,Z.jsx)(K,{size:`sm`,onClick:()=>void M(e),disabled:w===e.id,children:w===e.id?r(`marketplace.org.installing`,{defaultValue:`Installing…`}):r(`marketplace.org.install`,{defaultValue:`Install`})})})]})]})]},e.id)})}),(0,Z.jsx)(`div`,{className:`border-b pt-2`})]}),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)(xt,{children:[(0,Z.jsxs)(Lt,{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)(Ht,{children:(0,Z.jsx)(He,{className:`h-12 w-full`})})]},t))}):P.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:P.map(t=>{let n=A.get(t.manifest_id),s=jg(t,i);return(0,Z.jsxs)(xt,{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)(Lt,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,Z.jsx)(wg,{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)(br,{className:`text-base truncate`,children:s.displayName}),(0,Z.jsx)(Ma,{className:`text-xs truncate`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,Z.jsx)(U,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,Z.jsxs)(Ht,{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)(U,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,Z.jsx)(aa,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,Z.jsxs)(U,{variant:`outline`,className:`text-xs`,children:[(0,Z.jsx)(Rr,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,Z.jsx)(U,{variant:`outline`,className:`text-xs`,children:N(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)(Tg,{})}function n_(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 r_(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 i_({source:e,className:t}){let n=n_(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:r_(e.text??``)},t);case`h2`:return(0,Z.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:r_(e.text??``)},t);case`h3`:return(0,Z.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:r_(e.text??``)},t);case`p`:return(0,Z.jsx)(`p`,{children:r_(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:r_(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:r_(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 a_={node:`In-process · full trust`,sandbox:`Sandboxed`,worker:`Out-of-process`};function o_({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 s_({version:e}){let{t}=B();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)(Ut,{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)(U,{variant:`outline`,children:t(`marketplace.disclosure.runtime.${e.runtime}`,{defaultValue:a_[e.runtime]??e.runtime})}),e.platform_verified?(0,Z.jsxs)(U,{variant:`outline`,className:`gap-1 border-green-500/40 text-green-700 dark:text-green-400`,children:[(0,Z.jsx)(Ea,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.reviewed`,{defaultValue:`Reviewed & approved`})]}):(0,Z.jsxs)(U,{variant:`outline`,className:`gap-1 border-amber-500/40 text-amber-700 dark:text-amber-400`,children:[(0,Z.jsx)(ca,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.unreviewed`,{defaultValue:`Not yet reviewed`})]}),e.signed&&(0,Z.jsxs)(U,{variant:`outline`,className:`gap-1`,children:[(0,Z.jsx)(aa,{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)(o_,{icon:En,label:t(`marketplace.disclosure.services`,{defaultValue:`Platform services`}),items:n.services??void 0}),(0,Z.jsx)(o_,{icon:vo,label:t(`marketplace.disclosure.hooks`,{defaultValue:`Lifecycle hooks`}),items:n.hooks??void 0}),(0,Z.jsx)(o_,{icon:Ha,label:t(`marketplace.disclosure.network`,{defaultValue:`Network access`}),items:n.network??void 0}),(0,Z.jsx)(o_,{icon:ro,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 c_=t({MarketplacePackagePage:()=>l_});function l_(){let e=v(),{packageId:t,appName:n}=s(),r=x(),{t:i,language:a}=B(),o=n?`/apps/${n}`:``,{refresh:c}=se(),[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,M]=(0,X.useState)(!1),[ee,N]=(0,X.useState)(null),[P,te]=(0,X.useState)(null),[ne,F]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(null),[I,ce]=(0,X.useState)([]),[le,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!Vs().features.installLocal)return;let e=!1;return(async()=>{let t=await qg();e||ce(t)})(),()=>{e=!0}},[t,de]),(0,X.useEffect)(()=>{if(!t)return;let e=Vs().defaultEnvironmentId??``,n=!1;return(async()=>{let r=await Hg(t,e);n||!r||(F(r),te(r.version))})(),()=>{n=!0}},[t]),(0,X.useEffect)(()=>{let e=!1;return(async()=>{if(t){f(!0),m(null);try{let n=await Lg(t);e||u(n)}catch(t){e||m(t?.message??String(t))}finally{e||f(!1)}}})(),()=>{e=!0}},[t]);let pe=async()=>{g(!0),N(null),w(null);let e=Vs().defaultEnvironmentId;if(e){S(!1),E(e),y([]);return}S(!0);try{let[e,t]=await Promise.all([zg(),Bg()]),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)}},me=async()=>{if(!(!t||!T)){M(!0),N(null);try{te(((await Rg({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=Vs().defaultEnvironmentId||T;if(e){let n=await Hg(t,e);n&&F(n)}}catch{}let e=Vs().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{}N({ok:!0,message:i(`marketplace.install.success`)})}catch(e){N({ok:!1,message:e?.message??String(e)})}finally{M(!1)}}},he=async()=>{if(t){ue(!0),fe(null);try{let e=await Kg({packageId:t});try{await c(`app`)}catch{}fe({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?jg(l.package,a).displayName:e.manifestId})})}catch(e){let t=e?.code,n=e?.message??String(e);t===`manifest_conflict`?n=i(`marketplace.install.localManifestConflict`,{message:n}):t===`unauthorized`?n=i(`marketplace.install.localUnauthorized`):t===`marketplace_unavailable`&&(n=i(`marketplace.install.localMarketplaceUnavailable`)),fe({ok:!1,message:n})}finally{ue(!1)}}},ge=async()=>{if(be&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:be.manifestId,version:be.version}))){ue(!0),fe(null);try{await Yg(be.manifestId);try{await c(`app`)}catch{}fe({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:be.manifestId})})}catch(e){fe({ok:!1,message:e?.message??String(e)})}finally{ue(!1)}}},_e=async()=>{if(ne){ie(`reseed`),oe(null);try{let e=await Ug(ne.installationId);e.ok?(F({...ne,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{ie(null)}}},L=async()=>{if(ne&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ie(`purge`),oe(null);try{let e=await Wg(ne.installationId);if(e.ok){F({...ne,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{ie(null)}}},R=async()=>{if(be){ie(`reseed`),oe(null);try{let e=await Zg(be.manifestId);ce(e=>e.map(e=>e.manifestId===be.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{ie(null)}}},z=async()=>{if(be&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){ie(`purge`),oe(null);try{let e=await Qg(be.manifestId);ce(e=>e.map(e=>e.manifestId===be.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{ie(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)(Or,{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)(ci,{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 ve=l.package,V=jg(ve,a),ye=ve.latest_version?.version??l.versions[0]?.version??null,be=I.find(e=>e.manifestId===ve.manifest_id)??null,xe=!!ve.latest_version?.contains_code,Se=Vs().features.installLocal,Ce=!ye||le||j||!Se&&!!P,we=Se?{label:i(le?`marketplace.action.working`:be?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:he}:{label:j?i(`marketplace.action.installing`):P?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:pe},Te=ve.category?i(`marketplace.category.${ve.category}`,{defaultValue:ve.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)(Or,{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)(wg,{iconUrl:ve.icon_url,displayName:V.displayName,manifestId:ve.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,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:V.displayName||ve.manifest_id}),ve.homepage_url&&(0,Z.jsxs)(`a`,{href:ve.homepage_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,title:i(`marketplace.detail.homepage`),children:[(0,Z.jsx)(Xi,{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:ve.manifest_id}),ye&&(0,Z.jsx)(U,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:ye})}),ve.publisher&&ve.publisher!==`private`&&(0,Z.jsx)(U,{variant:ve.publisher===`objectstack`?`default`:`secondary`,children:ve.publisher}),Te&&(0,Z.jsx)(U,{variant:`outline`,children:Te}),ve.license&&(0,Z.jsx)(U,{variant:`outline`,className:`font-normal`,children:ve.license}),be&&(0,Z.jsxs)(U,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Z.jsx)(aa,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:be.version})]}),!be&&P&&(0,Z.jsxs)(U,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,Z.jsx)(aa,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:P})]})]}),V.description&&(0,Z.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:V.description})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,Z.jsxs)(K,{onClick:we.onClick,disabled:Ce,size:`lg`,className:`min-w-[8rem]`,children:[(0,Z.jsx)(dn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),we.label]}),be&&(0,Z.jsxs)(Vr,{children:[(0,Z.jsx)(la,{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)(Be,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Z.jsxs)(ba,{align:`end`,className:`w-56`,children:[(0,Z.jsxs)($r,{onSelect:R,disabled:re!==null,children:[re===`reseed`?(0,Z.jsx)(H,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(Zt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),be.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Z.jsxs)($r,{onSelect:z,disabled:re!==null||!be.withSampleData,className:`text-destructive focus:text-destructive`,children:[re===`purge`?(0,Z.jsx)(H,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(zn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,Z.jsxs)($r,{onSelect:ge,disabled:le,className:`text-destructive focus:text-destructive`,children:[(0,Z.jsx)(zn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!be&&ne&&!Vs().cloudUrl&&(0,Z.jsxs)(Vr,{children:[(0,Z.jsx)(la,{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)(Be,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Z.jsxs)(ba,{align:`end`,className:`w-56`,children:[(0,Z.jsxs)($r,{onSelect:_e,disabled:re!==null,children:[re===`reseed`?(0,Z.jsx)(H,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(Zt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),ne.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,Z.jsxs)($r,{onSelect:L,disabled:re!==null||!ne.withSampleData,className:`text-destructive focus:text-destructive`,children:[re===`purge`?(0,Z.jsx)(H,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(zn,{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)(aa,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Z.jsx)(ci,{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`)})]}),de&&(0,Z.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${de.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[de.ok?(0,Z.jsx)(aa,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,Z.jsx)(ci,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:de.message}),(0,Z.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>fe(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)(xt,{children:[(0,Z.jsx)(Lt,{children:(0,Z.jsx)(br,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,Z.jsx)(Ht,{children:V.readme?(0,Z.jsx)(i_,{source:V.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)(xt,{children:[(0,Z.jsx)(Lt,{children:(0,Z.jsx)(br,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,Z.jsx)(Ht,{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)(Rr,{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)(U,{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)(ht,{open:h,onOpenChange:e=>{g(e),e||(N(null),A(!1))},children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:i(`marketplace.install.dialogTitle`,{name:V.displayName||ve.manifest_id})}),(0,Z.jsx)(Xt,{children:Vs().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)(ci,{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:Vg(ve.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,Z.jsx)(Xi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):Vs().defaultEnvironmentId?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(dr,{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)(Vn,{value:T,onValueChange:E,children:[(0,Z.jsx)(cr,{id:`env-select`,children:(0,Z.jsx)(Dt,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,Z.jsx)(Fo,{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)(dr,{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`)})]})]}),xe&&!C&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(s_,{version:ve.latest_version}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(dr,{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.`})})]})]}),ee&&(0,Z.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${ee.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:ee.message}),(0,Z.jsxs)(Ln,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:()=>g(!1),children:i(`marketplace.action.close`)}),!C&&(0,Z.jsx)(K,{onClick:me,disabled:!T||j||ee?.ok===!0||xe&&!k,children:i(j?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,Z.jsx)(Tg,{})}function u_(){let e=v(),{appName:t}=s(),n=x(),{t:r,language:i}=B(),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 Jg();e.connected?(u(`cloud`),c(e.items)):(u(`local`),c(await qg()))}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 Yg(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-4`,children:[(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void _(),disabled:d,children:[(0,Z.jsx)(tn,{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)(ci,{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)(xt,{children:[(0,Z.jsxs)(Lt,{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)(br,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,Z.jsx)(U,{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)(Xi,{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)(zn,{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)(Ht,{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)(Tg,{})}L.register(`marketplace:installed-list`,()=>(0,Z.jsx)(u_,{}),{namespace:`app-shell`,label:`Installed Marketplace Packages`,category:`plugin`,inputs:[]});var d_=t({MarketplaceInstalledPage:()=>f_});function f_(){let e=v(),{appName:t}=s(),{t:n}=B(),r=t?`/apps/${t}`:``;return(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(`${r}/system/marketplace`),children:[(0,Z.jsx)(Or,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),n(`marketplace.back`)]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Dr,{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:n(`marketplace.installedTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,dangerouslySetInnerHTML:{__html:n(`marketplace.installedSubtitle`)}})]}),(0,Z.jsx)(u_,{})]})}function p_({children:e,userId:t}){let{setContext:n}=Bc(),{isAiEnabled:r}=ie(),{t:i}=B(),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)(Eu,{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)(dl,{appLabel:i(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var m_=[{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 h_(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function g_({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=B(),{appLabel:a,appDescription:o}=zr(),{toggleFavorite:s}=Qc(),c=xl(e.icon),l=a({name:e.name,label:Ml(e.label,i)}),u=o({name:e.name,description:Ml(e.description,i)}),d=m_[(h_(e.name)+r)%m_.length];return(0,Z.jsxs)(xt,{className:q(`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:q(`absolute inset-x-0 top-0 h-1`,d.solid)}),(0,Z.jsx)(`div`,{"aria-hidden":!0,className:q(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,d.from,d.to)}),(0,Z.jsxs)(Ht,{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)(Pe,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Z.jsx)(di,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:q(`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:q(`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)(U,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,Z.jsx)(`p`,{className:q(`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)(Fa,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var __={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`},v_={object:Zt,record:uo,dashboard:kt,page:Ni};function y_({items:e}){let t=v(),{t:n}=B();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)(gr,{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=v_[e.type]||Zt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Nl(e.type)}),a=__[e.type]||__.object;return(0,Z.jsx)(xt,{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)(Ht,{className:`p-3.5`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:q(`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)(Fa,{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 b_={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`},x_={object:Zt,record:uo,dashboard:kt,page:Ni};function S_({items:e}){let t=v(),{t:n}=B();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)(Pe,{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=x_[e.type]||Zt,i=b_[e.type]||b_.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Nl(e.type)});return(0,Z.jsx)(xt,{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)(Ht,{className:`p-3.5`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:q(`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)(Fa,{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 C_(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function w_({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)(Pe,{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)(gr,{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)(Nn,{className:`h-3.5 w-3.5`})]})]})})}function T_({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 E_({t:e}){let t=_s(),[n,r]=(0,X.useState)([]),{publishAll:i,publishing:a}=fl(e),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)(Rt,{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()=>{(await i()).ok&&(r([]),setTimeout(()=>{try{window.location.reload()}catch{}},700))},disabled:a,"data-testid":`pending-drafts-publish`,children:a?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function D_({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)(ca,{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)(Jr,{className:`h-4 w-4`})})]})})}):null}function O_(){let e=v(),{t}=B(),{apps:n,loading:r}=se(),{recentItems:i}=rs(),{favorites:a}=Qc(),{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(C_(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)(E_,{t}),(0,Z.jsx)(D_,{t}),(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s?(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Z.jsx)(qt,{children:t(`home.welcomeAdminDescription`,{defaultValue:`Describe your business in one sentence — AI generates the objects, screens, APIs and agent tools. Or set things up yourself from the Administration menu on the left.`})}),(0,Z.jsx)(`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)(ya,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]})})]}):(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Z.jsx)(qt,{children:t(`home.noAppsDescription`,{defaultValue:`There are no applications available to you yet. Please contact your workspace administrator.`})})]})})]}):(0,Z.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Z.jsx)(E_,{t}),(0,Z.jsx)(D_,{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)(ya,{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)(ya,{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)(T_,{icon:pt,tone:`text-indigo-600 dark:text-indigo-400`,value:c.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Z.jsx)(T_,{icon:gr,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)(T_,{icon:Pe,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)(w_,{t}),u.length>0&&(0,Z.jsx)(S_,{items:u}),l.length>0&&(0,Z.jsx)(y_,{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)(pt,{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)(Dr,{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)(g_,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function k_({children:e}){let{setContext:t}=Bc();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)(Eu,{variant:`orgs`})}),(0,Z.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function A_(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function j_({open:e,onOpenChange:t,onCreated:n}){let{t:r}=B(),{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(A_(o))},[o,u]),(0,X.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Z.jsx)(ht,{open:e,onOpenChange:t,children:(0,Z.jsx)(At,{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)(Po,{children:[(0,Z.jsx)(Ge,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Z.jsx)(Xt,{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)(Ln,{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)(H,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function M_(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 N_(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function P_(){let{t:e}=B(),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=M_()}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)(H,{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)(Oo,{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)(No,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Z.jsx)(qt,{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)(No,{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)(An,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Z.jsx)(pi,{src:n.logo,alt:n.name}),(0,Z.jsx)(Me,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:N_(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)(H,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Z.jsx)(j_,{open:l,onOpenChange:u,onCreated:y})]})}function F_(){let{t:e}=B(),t=v(),{slug:n}=s(),{organizations:r,activeOrganization:i,isOrganizationsLoading:a,switchOrganization:o}=S(),{setContext:c}=Bc();(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)(H,{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)(Eu,{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)(Or,{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 I_(){return o()}function L_(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function R_({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=B(),{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=L_(m.id);try{await navigator.clipboard.writeText(e),_(!0),J.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>_(!1),2e3)}catch{J.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Z.jsx)(ht,{open:t,onOpenChange:n,children:(0,Z.jsx)(At,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Z.jsx)(Xt,{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:L_(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)(po,{className:`h-4 w-4`}):(0,Z.jsx)(Tt,{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)(Ln,{children:(0,Z.jsx)(K,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Z.jsxs)(`form`,{onSubmit:v,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Z.jsx)(Xt,{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)(Vn,{value:c,onValueChange:e=>l(e),children:[(0,Z.jsx)(cr,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Z.jsx)(Dt,{})}),(0,Z.jsxs)(Fo,{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)(Ln,{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)(H,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function z_(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function B_(){let{t:e}=B(),{org:t}=I_(),{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}),J.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){J.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)(H,{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)($t,{}),(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)(An,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Z.jsx)(pi,{src:t.user.image,alt:t.user.name}),(0,Z.jsx)(Me,{className:`text-xs font-medium`,children:z_(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)(U,{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)(Vr,{children:[(0,Z.jsx)(la,{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)(Be,{className:`h-4 w-4`})})}),(0,Z.jsxs)(ba,{align:`end`,children:[(0,Z.jsxs)($r,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Z.jsx)(Ea,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Z.jsxs)($r,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Z.jsx)(Ea,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Z.jsxs)($r,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Z.jsx)(Ea,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Z.jsxs)($r,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Z.jsx)(Zi,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Z.jsx)(zi,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Z.jsxs)(Ga,{children:[(0,Z.jsxs)(io,{children:[(0,Z.jsx)(si,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Z.jsx)(ti,{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)(ia,{children:[(0,Z.jsx)(Sa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(Ur,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),J.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){J.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)(R_,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function V_(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function H_(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function U_(){let{t:e}=B(),{org:t}=I_(),{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=V_(t.id);try{await navigator.clipboard.writeText(n),h(t.id),J.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{J.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},v=async()=>{if(f)try{await r(f.id),J.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){J.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)(H,{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)($t,{}),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)(An,{className:`h-9 w-9 shrink-0`,children:(0,Z.jsx)(Me,{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)(U,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Z.jsx)(U,{variant:H_(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)(po,{className:`h-4 w-4 text-green-600`}):(0,Z.jsx)(Tt,{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)(Jr,{className:`h-4 w-4`})})]})]},t.id))}),(0,Z.jsx)(zi,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Z.jsxs)(Ga,{children:[(0,Z.jsxs)(io,{children:[(0,Z.jsx)(si,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Z.jsx)(ti,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Z.jsxs)(ia,{children:[(0,Z.jsx)(Sa,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsx)(Ur,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function W_(){let{t:e}=B(),{org:t}=I_(),{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}=oo(),[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)(``),[M,ee]=(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 N=(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}),J.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){J.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)(H,{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)($t,{className:`my-4`}),x?(0,Z.jsxs)(`form`,{onSubmit:N,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)(An,{className:`size-16 rounded-md`,children:[f?(0,Z.jsx)(pi,{src:f,alt:c,className:`object-cover`}):null,(0,Z.jsx)(Me,{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),J.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){J.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)(H,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Z.jsx)(Gi,{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)(Jr,{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)(H,{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)($t,{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)($t,{}),(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)(zi,{open:E,onOpenChange:D,children:(0,Z.jsxs)(Ga,{children:[(0,Z.jsxs)(io,{children:[(0,Z.jsx)(si,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Z.jsx)(ti,{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)(ia,{children:[(0,Z.jsx)(Sa,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(Ur,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await o(t.id),J.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){J.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{ee(!1)}},disabled:M,children:[M&&(0,Z.jsx)(H,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Z.jsx)(zi,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Z.jsxs)(Ga,{children:[(0,Z.jsxs)(io,{children:[(0,Z.jsx)(si,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Z.jsx)(ti,{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)(ia,{children:[(0,Z.jsx)(Sa,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Z.jsxs)(Ur,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await a(t.id),J.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){J.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{ee(!1)}},disabled:M||A!==t.slug,children:[M&&(0,Z.jsx)(H,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}async function G_(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function K_(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 q_({userId:e,apiBase:t,className:n,refreshKey:r,titleHints:i,onNavigate:a}){let{t:o}=B(),c=v(),{conversationId:l}=s(),{conversations:u,isLoading:d,error:f,remove:p,rename:m}=Kh({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?new=1`),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:q(`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)(No,{className:`h-3.5 w-3.5`}),o(`console.ai.newChat`)]})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Oo,{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)(ir,{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)(Ot,{className:`px-3 py-8`,children:[(0,Z.jsx)(jr,{className:`h-8 w-8 text-muted-foreground`}),(0,Z.jsx)(Ue,{children:o(`console.ai.noChatsYet`)}),(0,Z.jsx)(qt,{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)(J_,{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 J_({conversation:e,active:t,renaming:n,onSelect:r,onDelete:i,onStartRename:a,onCancelRename:o,onSubmitRename:s}){let{t:c}=B(),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:q(`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)(po,{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)(Jr,{className:`h-3.5 w-3.5`})})]})}):(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`div`,{className:q(`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:K_(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)(Vt,{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)(zn,{className:`h-3.5 w-3.5`})})]})]})})}function Y_(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function X_(e,t){let n=`${Y_()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function Z_({appName:e,materialized:t=!1,refreshKey:n,onClose:r}){let{t:i}=B(),a=(0,X.useRef)(null);return(0,X.useEffect)(()=>{if(!a.current)return;let n=X_(e,t);try{a.current.getAttribute(`src`)!==n&&a.current.setAttribute(`src`,n)}catch{}},[e,t]),(0,X.useEffect)(()=>{if(n>0)try{a.current?.contentWindow?.location.reload()}catch{}},[n]),(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b bg-muted/30 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(nt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t?i(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):i(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,onClick:r,"data-testid":`live-canvas-close`,children:(0,Z.jsx)(Jr,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsx)(`iframe`,{ref:a,title:`Draft preview: ${e}`,src:X_(e,t),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}var Q_=`/api/v1/ai`;function $_(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function ev(e){let t=$_(e,`state`);switch(t){case`input-streaming`:case`input-available`:return`output-available`;case`approval-requested`:case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return t;default:return`output-available`}}function tv(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=$_(n,`toolName`)??n.type.slice(5),i=$_(n,`toolCallId`)??`${e.id}-${r}`,a=ev(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 nv(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var rv={data_chat:{key:`console.ai.agentLabels.dataChat`,defaultValue:`Assistant`},metadata_assistant:{key:`console.ai.agentLabels.metadataAssistant`,defaultValue:`Metadata Assistant`}};function iv(e,t,n){let r=t?rv[t]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function av(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(/\/$/,``)}${Q_}`}function ov({apiBase:e,defaultAgent:t}={}){let{user:n}=S(),{t:r}=B(),i=n?.id,{conversationId:a}=s(),[o]=m(),[c]=(0,X.useState)(()=>o.get(`agent`)??void 0),l=o.get(`new`)!==null,u=v(),{setContext:d}=Bc();(0,X.useEffect)(()=>{d(`home`)},[d]);let f=(0,X.useMemo)(()=>av(e),[e]),p={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:h,isLoading:g,error:_}=fs({apiBase:f}),[y,b]=(0,X.useState)(void 0);(0,X.useEffect)(()=>{if(!y&&h.length>0){let e=gs(h,c??t??p);e&&b(e)}},[h,y,c,t,p]);let x=y?`${f}/agents/${encodeURIComponent(y)}/chat`:void 0,{conversationId:C,initialMessages:w}=zh({userId:i,scope:y,apiBase:f,activeId:a,forceNew:l}),[T,E]=(0,X.useState)(0),[D,O]=(0,X.useState)({}),[k,A]=(0,X.useState)(!1),[j,M]=(0,X.useState)(!1),ee=(0,X.useMemo)(()=>f.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[f]),N=(0,X.useRef)(null);l?N.current===null&&(N.current={id:C}):N.current=null,(0,X.useEffect)(()=>{if(!a&&C){if(N.current&&N.current.id===C)return;u(`/ai/${C}`,{replace:!0})}},[a,C,u]);let P=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{C&&w.length>0&&P.current.add(C)},[C,w.length]),(0,X.useEffect)(()=>{if(!C)return;let e=nv(w);e&&O(t=>t[C]===e?t:{...t,[C]:e})},[C,w]);let te=(0,X.useCallback)(e=>{if(E(e=>e+1),e&&C&&O(t=>({...t,[C]:e})),!e||!C||P.current.has(C))return;P.current.add(C);let t=()=>E(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[C]);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:()=>M(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Z.jsx)(je,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(Eu,{variant:`home`})})]}),(0,Z.jsx)(on,{open:j,onOpenChange:M,children:(0,Z.jsxs)(mn,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Z.jsxs)(yt,{className:`sr-only`,children:[(0,Z.jsx)(Pt,{children:r(`console.ai.chats`)}),(0,Z.jsx)(Dn,{children:r(`console.ai.chatsDescription`)})]}),(0,Z.jsx)(q_,{userId:i,apiBase:f,refreshKey:T,titleHints:D,className:`h-full border-r-0`,onNavigate:()=>M(!1)})]})}),C&&(0,Z.jsx)(Hn,{open:k,onOpenChange:A,objectName:`ai_conversations`,recordId:C,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)(q_,{userId:i,apiBase:f,refreshKey:T,titleHints:D,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)(sv,{agents:h,agentsLoading:g,agentsError:_,activeAgent:y,onAgentChange:b,showAgentPicker:!!c,chatApi:x,apiBase:f,conversationId:C,initialMessages:w,onSent:te,onShare:()=>A(!0)},`${x??`local`}:${C??`pending`}`)})]})]})}function sv({agents:e,agentsLoading:t,showAgentPicker:n,agentsError:r,activeAgent:i,onAgentChange:a,chatApi:o,apiBase:s,conversationId:c,initialMessages:l,onSent:u,onShare:d}){let{t:f}=B(),p=v(),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(0),y=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{y.current&&window.clearTimeout(y.current)},[]);let b=(0,X.useCallback)(e=>{let t=e.find(e=>e.type===`app`);t&&h(e=>e??{name:t.name,materialized:!1}),y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>_(e=>e+1),800)},[]),x=(0,X.useCallback)(e=>{h(t=>t&&t.name===e&&!t.materialized?{name:e,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,X.useEffect)(()=>{h(null)},[c]);let S=(0,X.useMemo)(()=>iv(f,i,e.find(e=>e.name===i)?.label??i??f(`console.ai.assistant`)),[e,i,f]),C=(0,X.useMemo)(()=>tv(l),[l]),w=(0,X.useMemo)(()=>{if(!(C.length>0))return dv(i,S,f)},[C.length,i,S,f]),{messages:T,isLoading:E,error:D,sendMessage:O,stop:k,reload:A,clear:j}=ps({api:o,conversationId:c,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:Vs().features.autoPublishAiBuilds}},initialMessages:C,autoResponse:!o,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,X.useEffect)(()=>{Mh(c,Nh(T))},[c,T]);let M=hs({messages:T,apiBase:s,continueConversation:e=>{O(e)}}),ee=(0,X.useCallback)((e,t)=>{O(e,t),u(e)},[O,u]),N=(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:n&&e.length>0?(0,Z.jsxs)(Vn,{value:i,onValueChange:a,disabled:t,children:[(0,Z.jsx)(cr,{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)(Dt,{placeholder:`Choose agent...`})}),(0,Z.jsx)(Fo,{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:iv(f,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:S})}),(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:d,disabled:!c,"aria-label":f(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:f(c?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Z.jsx)(ji,{className:`h-3.5 w-3.5`})})}),r?(0,Z.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:r.message,children:f(`console.ai.offlineDemoMode`)}):null]});return(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 px-0`,children:[(0,Z.jsx)(`div`,{className:m?`flex min-h-0 w-[42%] min-w-[380px] max-w-[640px] shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,children:(0,Z.jsx)(ms,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,surface:`plain`,maxHeight:`100%`,headerSlot:N,messages:T,placeholder:i?f(`console.ai.askAgent`,{agent:S}):f(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:f(`console.ai.emptyTitle`),emptyDescription:f(`console.ai.emptyDescription`),clear:f(`console.ai.clearConversation`),sendHint:f(`console.ai.sendHint`),agentActivity:f(`console.ai.agentActivity`),toolCompleted:f(`console.ai.toolCompleted`),toolRunning:f(`console.ai.toolRunning`),toolAwaitingApproval:f(`console.ai.toolAwaitingApproval`),toolFailed:f(`console.ai.toolFailed`),toolDetailsHidden:f(`console.ai.toolDetailsHidden`),copy:f(`console.ai.copy`),copied:f(`console.ai.copied`),regenerate:f(`console.ai.regenerate`),model:f(`console.ai.model`),submit:f(`console.ai.submit`),uploadFiles:f(`console.ai.uploadFiles`),stopResponse:f(`console.ai.stopResponse`),trace:f(`console.ai.trace`),viewTrace:f(`console.ai.viewTrace`)},suggestions:w,onSendMessage:ee,onClear:j,hideClearBar:!0,onStop:E?k:void 0,onReload:A,isLoading:E,error:D,enableMarkdown:!0,onToolApprove:M.decide,toolDecisions:M.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:e=>p(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:f(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),fetchPendingDraftCount:G_,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?J.warning(f(`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)}):J.success(f(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),{ok:!0,health:ds(n)}}catch(e){return J.error(f(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:f(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:f(`console.ai.published`,{defaultValue:`Published`}),autoPublishDrafts:Vs().features.autoPublishAiBuilds,onDraftArtifacts:b,onPreviewDraftApp:(e,t)=>h({name:e,materialized:t?.materialized===!0}),onBuildMaterialized:x,previewDraftLabel:f(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),m?(0,Z.jsx)(Z_,{appName:m.name,materialized:m.materialized,refreshKey:g,onClose:()=>h(null)}):null]})}function cv(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 lv(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 uv(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 dv(e,t,n){if(e===`data_chat`)return cv(n);if(e===`metadata_assistant`)return lv(n);let r=(e??t).toLowerCase();return r.includes(`data`)?cv(n):r.includes(`metadata`)?lv(n):uv(n)}var fv=new Map;function pv(e){fv.set(e.ref,e)}function mv(e){return fv.get(e)}function hv({appSlug:e}={}){let t=v(),n=_s(),{entries:r}=Ls(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(()=>Ms(),[]);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)||Ns(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)(ht,{open:i,onOpenChange:a,children:(0,Z.jsxs)(At,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Z.jsx)(Po,{className:`sr-only`,children:(0,Z.jsx)(Ge,{children:Y(`engine.quickfind.title`,m)})}),(0,Z.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Z.jsx)(Oo,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(W,{autoFocus:!0,placeholder:Y(`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)(ft,{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)(H,{className:`h-3.5 w-3.5 animate-spin`}),Y(`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:Y(`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)(U,{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:Ns(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)(st,{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)(ft,{children:`↑`}),` `,(0,Z.jsx)(ft,{children:`↓`}),` navigate`]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(ft,{children:`↵`}),` open`]}),(0,Z.jsxs)(`span`,{className:`ml-auto`,children:[(0,Z.jsx)(ft,{children:`⌘`}),(0,Z.jsx)(ft,{children:`⇧`}),(0,Z.jsx)(ft,{children:`M`}),` toggle`]})]})]})})}var gv={data:Zt,ui:Jt,automation:Kn,ai:ya,system:Ci,platform:Ci,identity:Ea,security:Ea},_v=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],vv=new Set([`field`,`package`]);function yv(){let e=_s(),{loading:t,error:n,entries:r}=Ls(e),i=X.useMemo(()=>Ms(),[]),[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}=vs(e,`warning`,v??void 0),E=X.useMemo(()=>r.filter(e=>vv.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)||Ns(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=_v.indexOf(e),r=_v.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:Y(`engine.directory.loading`,i)}):n?(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[Y(`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:Y(`engine.directory.title`,i)}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:bs(`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)(Oo,{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:Y(`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:[Y(`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)(_t,{className:`h-3.5 w-3.5 mr-1`}),bs(`engine.directory.diagnosticsLink`,i,{count:x.total})]})}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[Y(`engine.directory.quickFind`,i),` `,(0,Z.jsx)(ft,{children:`⌘`}),(0,Z.jsx)(ft,{children:`⇧`}),(0,Z.jsx)(ft,{children:`M`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Z.jsx)(bv,{domain:`all`,label:Y(`engine.directory.all`,i),active:s===`all`,count:D.all??0,onClick:()=>c(`all`)}),_v.filter(e=>D[e]).map(e=>(0,Z.jsx)(bv,{domain:e,label:As(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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`No project packages installed`}),(0,Z.jsx)(qt,{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)(Ot,{children:[(0,Z.jsx)(Ue,{children:Y(`engine.directory.noMatches`,i)}),(0,Z.jsx)(qt,{children:Y(`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)(gv[e]??vt,{className:`h-3.5 w-3.5`}),As(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)(xv,{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)(hv,{})]})}function bv({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 xv({entry:e,locale:t,invalidCount:n=0,warnCount:r=0,itemCount:i=0,lockedCount:a=0,packageFilter:o}){let s=Ns(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:bs(`engine.directory.invalidTooltip`,t??`en`,{count:n}),"aria-label":bs(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:(0,Z.jsx)(_t,{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)(U,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:bs(`engine.directory.itemCountTooltip`,t??`en`,{count:i}),children:i}),n>0&&(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:bs(`engine.directory.invalidTooltip`,t??`en`,{count:n}),children:n}),r>0&&(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:bs(`engine.directory.warnTooltip`,t??`en`,{count:r}),children:r}),a>0&&(0,Z.jsxs)(U,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${a} locked item${a===1?``:`s`} — see ADR-0010`,"aria-label":`${a} locked items`,children:[(0,Z.jsx)(st,{className:`h-2.5 w-2.5`}),a]}),e.allowOrgOverride?(0,Z.jsx)(U,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:Y(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Z.jsx)(U,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:Y(`engine.badge.createOnly`,t)}):(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:Y(`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 Sv=`/api/v1/packages`;async function Cv(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 wv({scope:e}){let t=X.useMemo(()=>Ms(),[]),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)(U,{variant:r,children:i?Y(i,t):n})}function Tv({pkg:e}){let t=X.useMemo(()=>Ms(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,Z.jsx)(U,{variant:n?`default`:`outline`,children:Y(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var Ev=/^[a-z0-9][a-z0-9._-]{1,254}$/i,Dv=/^\d+\.\d+\.\d+$/;function Ov({open:e,onOpenChange:t,onCreated:n}){let r=X.useMemo(()=>Ms(),[]),[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=Ev.test(i),h=Dv.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await Cv(Sv,{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??Y(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,Z.jsx)(ht,{open:e,onOpenChange:t,children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsx)(Ge,{children:Y(`engine.packages.create.title`,r)}),(0,Z.jsx)(Xt,{children:bs(`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:Y(`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:Y(`engine.packages.create.idInvalid`,r)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(G,{htmlFor:`pkg-name`,children:Y(`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:Y(`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:Y(`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)(_t,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{children:f})]})]}),(0,Z.jsxs)(Ln,{children:[(0,Z.jsx)(K,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:Y(`engine.cancel`,r)}),(0,Z.jsx)(K,{onClick:_,disabled:!g,children:Y(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function kv({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 Av({pkg:e,appBase:t,open:n,onOpenChange:r,onChanged:i}){let a=X.useMemo(()=>Ms(),[]),[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 Cv(`/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??Y(`engine.packages.detail.actionFailed`,a)})}finally{s(null)}}return(0,Z.jsx)(on,{open:n,onOpenChange:r,children:(0,Z.jsxs)(mn,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Z.jsxs)(yt,{children:[(0,Z.jsxs)(Pt,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Rr,{className:`h-4 w-4`}),e.manifest.name||f]}),(0,Z.jsx)(Dn,{className:`font-mono text-xs`,children:f})]}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(kv,{label:Y(`engine.packages.col.version`,a),children:e.manifest.version||`—`}),(0,Z.jsx)(kv,{label:Y(`engine.packages.detail.type`,a),children:e.manifest.type||`—`}),(0,Z.jsx)(kv,{label:Y(`engine.packages.col.scope`,a),children:(0,Z.jsx)(wv,{scope:e.manifest.scope})}),(0,Z.jsx)(kv,{label:Y(`engine.packages.col.status`,a),children:(0,Z.jsx)(Tv,{pkg:e})}),e.manifest.description&&(0,Z.jsx)(kv,{label:Y(`engine.packages.detail.description`,a),children:e.manifest.description})]}),(0,Z.jsx)($t,{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)(Xi,{className:`h-3.5 w-3.5`}),Y(`engine.packages.detail.browseMetadata`,a)]}),u&&u.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($t,{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:[Y(`engine.packages.detail.pendingChanges`,a),(0,Z.jsx)(U,{variant:`secondary`,children:u.length})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Y(`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`,()=>Cv(`${Sv}/${encodeURIComponent(f)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{d((await Cv(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(f)}`))?.drafts??[])}catch{d([])}if(e?.failedCount)throw Error(bs(`engine.packages.detail.publishDraftsPartial`,a,{published:e.publishedCount??0,failed:e.failedCount}));return e}),Y(`engine.packages.detail.publishDraftsOk`,a)),disabled:!!o,children:[(0,Z.jsx)(Gi,{className:`mr-1.5 h-3.5 w-3.5`}),o===`publish-drafts`?Y(`engine.packages.detail.publishing`,a):bs(`engine.packages.detail.publishApp`,a,{count:u.length})]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`discard-drafts`,()=>Cv(`${Sv}/${encodeURIComponent(f)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{d((await Cv(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(f)}`))?.drafts??[])}catch{d([])}if(e?.failedCount)throw Error(bs(`engine.packages.detail.discardDraftsPartial`,a,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),Y(`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`?Y(`engine.packages.detail.discarding`,a):bs(`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)(Pr,{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)($t,{className:`my-4`}),m?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Y(`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:Y(`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`,()=>Cv(`${Sv}/${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?bs(`engine.packages.detail.publishBlocked`,a,{count:t}):e.validationErrors?.[0]?.message||Y(`engine.packages.detail.nothingToPublish`,a))}return e}),Y(`engine.packages.detail.published`,a)),disabled:!!o,children:[(0,Z.jsx)(Gi,{className:`mr-1.5 h-3.5 w-3.5`}),Y(o===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`revert`,()=>Cv(`${Sv}/${encodeURIComponent(f)}/revert`,{method:`POST`}),Y(`engine.packages.detail.reverted`,a)),disabled:!!o,children:[(0,Z.jsx)(fn,{className:`mr-1.5 h-3.5 w-3.5`}),Y(`engine.packages.detail.revert`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>g(`toggle`,()=>Cv(`${Sv}/${encodeURIComponent(f)}/${p?`disable`:`enable`}`,{method:`PATCH`}),Y(p?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,a)),disabled:!!o,children:[p?(0,Z.jsx)(In,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Z.jsx)(Yt,{className:`mr-1.5 h-3.5 w-3.5`}),Y(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 Cv(`${Sv}/${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)},Y(`engine.packages.detail.exported`,a)),disabled:!!o,children:[(0,Z.jsx)(dn,{className:`mr-1.5 h-3.5 w-3.5`}),Y(o===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,a)]}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(bs(`engine.packages.detail.deleteConfirm`,a,{name:e?.manifest.name||f}))){s(`delete`),l(null);try{await Cv(`${Sv}/${encodeURIComponent(f)}`,{method:`DELETE`}),i(),r(!1)}catch(e){l({kind:`err`,text:e?.message??Y(`engine.packages.detail.deleteFailed`,a)})}finally{s(null)}}},disabled:!!o,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,Z.jsx)(zn,{className:`mr-1.5 h-3.5 w-3.5`}),Y(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 jv(){let e=X.useMemo(()=>Ms(),[]),{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 Cv(Sv),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??Y(`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(Y(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(Y(`engine.packages.import.invalidPackage`,e));w({kind:`ok`,text:bs(`engine.packages.import.success`,e,{id:(await Cv(`/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??Y(`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)(Rr,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:Y(`engine.packages.title`,e)}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Y(`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)(Ui,{className:`mr-1.5 h-3.5 w-3.5 ${a?`animate-spin`:``}`}),Y(`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)(Pr,{className:`mr-1.5 h-3.5 w-3.5`}),Y(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,Z.jsxs)(K,{size:`sm`,onClick:()=>h(!0),children:[(0,Z.jsx)(No,{className:`mr-1.5 h-3.5 w-3.5`}),Y(`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)(Oo,{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:Y(`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)(ao,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,Z.jsx)(G,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:bs(`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)(_t,{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)(Ot,{children:[(0,Z.jsx)(Ue,{children:Y(`engine.packages.empty`,e)}),(0,Z.jsx)(qt,{children:r.length===0?Y(`engine.packages.emptyCreate`,e):Y(`engine.packages.emptyFiltered`,e)})]})}):(0,Z.jsxs)(Vi,{children:[(0,Z.jsx)(ri,{children:(0,Z.jsxs)(oa,{children:[(0,Z.jsx)(qa,{children:Y(`engine.packages.col.name`,e)}),(0,Z.jsx)(qa,{children:`ID`}),(0,Z.jsx)(qa,{className:`w-24`,children:Y(`engine.packages.col.version`,e)}),(0,Z.jsx)(qa,{className:`w-24`,children:Y(`engine.packages.col.scope`,e)}),(0,Z.jsx)(qa,{className:`w-24`,children:Y(`engine.packages.col.status`,e)})]})}),(0,Z.jsx)(Wr,{children:E.map(e=>(0,Z.jsxs)(oa,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,Z.jsx)(wa,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Z.jsx)(wa,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Z.jsx)(wa,{children:e.manifest.version||`—`}),(0,Z.jsx)(wa,{children:(0,Z.jsx)(wv,{scope:e.manifest.scope})}),(0,Z.jsx)(wa,{children:(0,Z.jsx)(Tv,{pkg:e})})]},e.manifest.id))})]})}),(0,Z.jsx)(Ov,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,Z.jsx)(Av,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var Mv=new Set([`field`,`package`]),Nv={data:Zt,ui:Jt,automation:Kn,ai:ya,system:Ci,platform:Ci,identity:Ea,security:Ea},Pv={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`],Iv=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],Lv={object:Sr,dashboard:kt,page:uo,report:Qn,record:vt,metadata:Jt};function Rv(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function zv(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 Bv(){let e=_s(),{loading:t,entries:n}=Ls(e),{recentItems:r}=rs(),i=X.useMemo(()=>Ms(),[]),[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}=vs(e,`warning`,u??void 0),b=X.useMemo(()=>n.filter(e=>Mv.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 Iv.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:Y(`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)(ya,{className:`h-4 w-4`}),Y(Rv(),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:Y(`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)(Jt,{className:`mr-1.5 h-4 w-4`}),Y(`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)(Oo,{className:`h-3.5 w-3.5`}),Y(`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:Y(`engine.home.statTypes`,i)}),(0,Z.jsx)(Vv,{value:x.length,label:Y(`engine.home.statWritable`,i)}),(0,Z.jsx)(Vv,{value:s.length,label:Y(`engine.home.statPackages`,i)})]})]})]}),(0,Z.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Z.jsx)(Hv,{icon:Jt,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:Y(`engine.home.statTypes`,i),to_link:f}),(0,Z.jsx)(Hv,{icon:aa,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:Y(`engine.home.statWritable`,i),to_link:f}),(0,Z.jsx)(Hv,{icon:Rr,from:`from-emerald-500`,to:`to-teal-600`,value:s.length,label:Y(`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)(aa,{className:`h-5 w-5`}):(0,Z.jsx)(_t,{className:`h-5 w-5`})}),(0,Z.jsx)(Cr,{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?Y(`engine.home.allHealthy`,i):w}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Y(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,i)})]})]})]}),C.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(Uv,{icon:No,title:Y(`engine.home.quickActions`,i),hint:Y(`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)(No,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),bs(`engine.home.newItem`,i,{label:Ns(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)(Uv,{icon:Jt,title:Y(`engine.home.explore`,i),hint:Y(`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)(Wv,{domain:e,group:t,countsByType:_,locale:i,packageSuffix:d},e))})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(Uv,{icon:gr,title:Y(`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:Y(`engine.home.recentEmpty`,i)}):(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:r.slice(0,8).map(e=>{let t=Lv[e.type]??vt;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:zv(e.visitedAt,i)})]}),(0,Z.jsx)(Cr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Z.jsx)(hv,{})]})}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 Hv({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)(Cr,{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 Uv({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 Wv({domain:e,group:t,countsByType:n,locale:r,packageSuffix:i}){let a=Nv[e]??vt,o=Pv[e]??Pv.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:As(e,r)}),(0,Z.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,Y(`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:Ns(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 Gv({entry:e,itemName:t,subtitle:n,stats:r,actions:i,children:a}){let o=e?.type??``,s=X.useMemo(()=>Ms(),[]),c=Ns(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:Y(`engine.breadcrumb.allTypes`,s)}),(0,Z.jsx)(Fi,{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)(Fi,{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)(U,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:As(e.domain,s)}),e?.allowOrgOverride?(0,Z.jsx)(U,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:Y(`engine.badge.writable`,s)}):e?.allowRuntimeCreate?(0,Z.jsx)(U,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:Y(`engine.badge.createOnly`,s)}):(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:Y(`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:Y(`engine.breadcrumb.allTypes`,s)}),(0,Z.jsx)(Fi,{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)(U,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:As(e.domain,s)}),e?.allowOrgOverride?(0,Z.jsx)(U,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:Y(`engine.badge.writable`,s)}):e?.allowRuntimeCreate?(0,Z.jsx)(U,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:Y(`engine.badge.createOnly`,s)}):(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:Y(`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 Kv={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function qv(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 Jv({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`){J.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=qv(e.target??``,s,i);if(!c){J.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();J.error(`${t}: ${e}`);return}let c=typeof s?.message==`string`?s.message:`${t} ✓`;J.success(c),e.refreshAfter&&r?.()}catch(e){J.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,Z.jsx)(Z.Fragment,{children:s.map(e=>{let t=e.icon?xl(e.icon):null,n=i===e.name;return(0,Z.jsxs)(K,{size:`sm`,variant:Kv[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>c(e),title:e.label??e.name,children:[n?(0,Z.jsx)(H,{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 Yv(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 Xv=new Map;function Zv(e){let t=Xv.get(e.type);if(!t){Xv.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Xv.set(e.type,n)}function Qv(e){return Xv.get(e)}function $v(e){let t=[];for(let n of Xv.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 ey(e,t){let n=Xv.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 ty(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 ny({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=Qv(n);if(r?.ListPage){let e=r.ListPage;return(0,Z.jsx)(e,{type:n})}return(0,Z.jsx)(ry,{type:n})}function ry({type:e}){let t=v(),n=_s(),{entries:r}=Ls(n),i=r.find(t=>t.type===e),a=ey(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:ty(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)||!Rs(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]),M=X.useMemo(()=>o.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[o]),ee=a.listColumns??iy(a.primaryKey??`name`),N=Ms(),P=Ns(e,N,i?.label??e),te=e=>{let t=`engine.list.col.${e.key}`,n=Y(t,N);return n===t?e.label:n};return(0,Z.jsx)(Gv,{entry:i??{type:e,label:e},stats:[{label:Y(`engine.list.items`,N),value:o.length},{label:Y(`engine.list.filtered`,N),value:k.length},...j>0?[{label:Y(`engine.list.invalid`,N),value:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Z.jsx)(_t,{className:`w-3.5 h-3.5`}),j]})}]:[],...M>0?[{label:Y(`engine.list.warnings`,N),value:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Z.jsx)(_t,{className:`w-3.5 h-3.5`}),M]})}]:[]],actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Jv,{entry:i,location:`list_toolbar`,onAfter:()=>S(e=>e+1)}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>S(e=>e+1),title:Y(`engine.list.refresh`,N),children:(0,Z.jsx)(Ui,{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?bs(`engine.list.createHint`,N,{type:P}):void 0,children:[(0,Z.jsx)(No,{className:`h-4 w-4 mr-1`}),Y(`engine.list.create`,N)]})]}),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)(Oo,{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:Y(`engine.list.search`,N),value:f,onChange:e=>p(e.target.value)})]}),(0,Z.jsxs)(Vn,{value:g,onValueChange:_,children:[(0,Z.jsx)(cr,{className:`w-[180px]`,children:(0,Z.jsx)(Dt,{})}),(0,Z.jsxs)(Fo,{children:[(0,Z.jsxs)(Ye,{value:`all`,children:[Y(`engine.list.allSources`,N),` (`,A.all,`)`]}),(0,Z.jsxs)(Ye,{value:`artifact`,children:[Y(`engine.list.source.artifact`,N),` (`,A.artifact,`)`]}),(0,Z.jsxs)(Ye,{value:`runtime`,children:[Y(`engine.list.source.runtime`,N),` (`,A.runtime,`)`]})]})]})]}),(c||C===null)&&(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[Y(`engine.edit.loading`,N),` `,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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`No project packages installed`}),(0,Z.jsx)(qt,{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)(Ot,{children:[(0,Z.jsx)(Ue,{children:o.length===0?bs(`engine.list.emptyType`,N,{type:P}):bs(`engine.list.emptyQuery`,N,{query:f})}),(0,Z.jsx)(qt,{children:a.emptyStateHint??(i?.allowOrgOverride||i?.allowRuntimeCreate?bs(`engine.list.createHint`,N,{type:P}):Y(`engine.list.readOnlyHint`,N))}),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)(No,{className:`h-4 w-4 mr-1`}),Y(`engine.list.create`,N)]})})]}),!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:[ee.map(e=>(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:te(e)},e.key)),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:Y(`engine.list.col.source`,N)})]})}),(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:[ee.map((t,n)=>{let a=e.item[t.key],u=t.render?t.render(a,e.item):ay(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":Y(`engine.list.invalidTitle`,N),title:`${bs(`engine.list.invalidCount`,N,{count:o.length})}\n${l}`,children:(0,Z.jsx)(_t,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),c&&(0,Z.jsx)(`span`,{className:`inline-flex`,"aria-label":Y(`engine.list.warnTitle`,N),title:`${bs(`engine.list.warnCount`,N,{count:s.length})}\n${l}`,children:(0,Z.jsx)(_t,{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)(st,{className:`h-3 w-3`})}),(0,Z.jsx)(U,{variant:`outline`,className:`text-[10px] `+(e.source===`artifact`?`border-sky-500/50 text-sky-700 dark:text-sky-300`:`border-emerald-500/50 text-emerald-700 dark:text-emerald-300`),title:e.source===`artifact`?`${Y(`engine.list.source.artifactDesc`,N)}${e.item._packageId?` (${e.item._packageId})`:``}`:Y(`engine.list.source.runtimeDesc`,N),children:Y(`engine.list.source.${e.source}`,N)})]})]},r+t)})})]})})]})})}function iy(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function ay(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 oy={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 sy(e,t){let n=cy(e)?e:{},r=cy(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`:ly(o)===ly(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 cy(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ly(e){try{return JSON.stringify(e,(e,t)=>cy(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function uy(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 dy(e,t){if(e==null)return 0;let n=0;for(let r of sy(e,t))r.status!==`unchanged`&&(n+=1);return n}function fy({layered:e,loading:t,locale:n}){if(t)return(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:Y(`engine.edit.loading`,n)});if(!e)return(0,Z.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:Y(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,Z.jsxs)(hi,{defaultValue:`diff`,className:`w-full`,children:[(0,Z.jsxs)(_a,{className:`grid grid-cols-4 w-fit`,children:[(0,Z.jsx)(Va,{value:`diff`,children:Y(`engine.layers.diff`,n)}),(0,Z.jsxs)(Va,{value:`code`,children:[Y(`engine.layers.code`,n),(0,Z.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Z.jsxs)(Va,{value:`overlay`,children:[Y(`engine.layers.overlay`,n),r?(0,Z.jsx)(U,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Z.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Z.jsxs)(Va,{value:`effective`,children:[Y(`engine.layers.effective`,n),(0,Z.jsx)(U,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Z.jsx)($a,{value:`diff`,className:`mt-3`,children:(0,Z.jsx)(py,{code:e.code,effective:e.effective,locale:n})}),(0,Z.jsx)($a,{value:`code`,className:`mt-3`,children:(0,Z.jsx)(hy,{payload:e.code,emptyHint:Y(`engine.layers.diff.noBaseline`,n)})}),(0,Z.jsx)($a,{value:`overlay`,className:`mt-3`,children:(0,Z.jsx)(hy,{payload:e.overlay,emptyHint:Y(`engine.layers.diff.noChanges`,n)})}),(0,Z.jsx)($a,{value:`effective`,className:`mt-3`,children:(0,Z.jsx)(hy,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function py({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:Y(`engine.layers.diff.noBaseline`,n)});let a=X.useMemo(()=>sy(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:bs(`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)(ao,{checked:r,onCheckedChange:i,"aria-label":Y(`engine.layers.diff.showUnchanged`,n)}),Y(`engine.layers.diff.showUnchanged`,n),(0,Z.jsx)(U,{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:Y(`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:Y(`engine.layers.diff.field`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:Y(`engine.layers.diff.code`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:Y(`engine.layers.diff.effective`,n)}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:Y(`engine.layers.diff.status`,n)})]}),(0,Z.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=oy[e.status];return(0,Z.jsxs)(`div`,{className:q(`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)(my,{value:e.codeValue,muted:e.status===`added`}),(0,Z.jsx)(my,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Z.jsx)(`div`,{className:`px-3 py-2`,children:(0,Z.jsx)(`span`,{className:q(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:Y(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function my({value:e,muted:t}){let n=uy(e);return(0,Z.jsx)(`div`,{className:q(`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 hy({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 gy={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`},_y={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 vy(e,t){return Y(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function yy(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 by(e,t){let n=0;for(let r of sy(e,t))r.status!==`unchanged`&&(n+=1);return n}function xy({published:e,draft:t,locale:n,className:r}){let i=X.useMemo(()=>sy(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:Y(`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 ${_y[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 ${gy[t]}`,children:vy(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:yy(e.effectiveValue)}):t===`removed`?(0,Z.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:yy(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:yy(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:yy(e.effectiveValue)})]})]},e.key)})})}function Sy(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 Cy(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 wy(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function Ty(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function Ey(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return Sy(n);case`plural-en`:return Cy(n);case`titlecase`:return wy(n);case`first-token`:return Ty(n);default:return n}}function Dy(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=Ey(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 Oy(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 ky({type:e,name:t,parentItem:n,onOpen:r}){let i=_s(),a=v(),o=X.useMemo(()=>$v(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(Ay)}}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=>Ay(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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`No related metadata`}),(0,Z.jsxs)(qt,{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)(Oo,{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)(Fi,{className:q(`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)(U,{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)(No,{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)(H,{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)(Xi,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function Ay(e){return{name:jy(e,[`name`,`id`,`key`])??`(unnamed)`,label:jy(e,[`label`,`title`,`displayName`]),description:jy(e,[`description`,`summary`]),raw:e}}function jy(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function My({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=X.useMemo(()=>Ms(),[]),c=_s(),{entries:l}=Ls(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?Py[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(Y(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=Ny(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:Ss(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?Y(`engine.validation.failedOne`,s):bs(`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:Y(`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:Y(`engine.embedded.readOnlyParent`,s)}),(0,Z.jsx)(ks,{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)(H,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Wn,{className:`h-4 w-4 mr-1`}),bs(`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:Y(`engine.embedded.readOnly`,s)}),(0,Z.jsx)(`div`,{children:Y(`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:bs(`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(`${Y(`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)(_t,{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)(H,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Wn,{className:`h-4 w-4 mr-1`}),bs(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function Ny(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 Py={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)(mn,{side:`right`,className:q(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Z.jsxs)(yt,{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)(U,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,Z.jsx)(Pt,{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)(Xi,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Z.jsxs)(Dn,{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)(Ab,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,Z.jsx)(My,{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 Iy({type:e,name:t}){let n=s(),r=e??n.type??``,i=t??n.name??``,a=v(),o=_s(),{entries:c}=Ls(o),l=c.find(e=>e.type===r),[u,d]=X.useState(0),[f,p]=X.useState(0);return(0,Z.jsx)(Gv,{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)(Or,{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)(Ui,{className:`h-4 w-4`})})]}),children:(0,Z.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Z.jsx)(Ly,{type:r,name:i,refreshKey:u,onCount:p,client:o,onRollback:()=>d(e=>e+1)})})})}function Ly({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)(H,{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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`No history yet`}),(0,Z.jsx)(qt,{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)(U,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Z.jsxs)(U,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Z.jsx)(U,{className:`text-[10px] `+(r===`delete`||r===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:r===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:r===`publish`?`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`:r===`revert`?`bg-amber-100 text-amber-900 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(r)}),e.actor&&(0,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:Ry(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)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(ct,{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:zy(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Ry(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function zy(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function By(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:Ea},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:ai},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:ca}},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 Hy({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,` `,Y(`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:Y(`engine.edit.refresh`,r),children:[i?(0,Z.jsx)(H,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Ui,{className:`h-3 w-3`}),Y(`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)(H,{className:`mr-2 h-3 w-3 animate-spin`}),Y(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Z.jsxs)(Ot,{className:`py-10`,children:[(0,Z.jsx)(Ue,{children:Y(`engine.edit.auditEmptyTitle`,r)}),(0,Z.jsx)(qt,{children:Y(`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:Y(`engine.edit.auditColTime`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Y(`engine.edit.auditColActor`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Y(`engine.edit.auditColOperation`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Y(`engine.edit.auditColOutcome`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Y(`engine.edit.auditColLock`,r)}),(0,Z.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Y(`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:By(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)(U,{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 Uy=new Map;function Wy(e,t){Uy.set(e,t)}function Gy(e){return Uy.get(e)}var Ky=new Map;function qy(e,t){Ky.set(e,t)}function Jy(e){return Ky.get(e)}var Yy=new Map;function Xy(e,t){Yy.set(e,t)}function Zy(e){return Yy.get(e)}function Qy(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&&tb(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&tb(e.charCodeAt(r)))for(r++;r<e.length&&tb(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&&tb(e.charCodeAt(r))){for(r++;r<e.length&&tb(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(eb(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($y(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while($y(t));return o=15}if(eb(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&&!eb(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++,eb(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||!tb(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($y(e)||eb(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 $y(e){return e===32||e===9}function eb(e){return e===10||e===13}function tb(e){return e>=48&&e<=57}var nb;(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`})(nb||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var rb=200;Array(rb).fill(0).map((e,t)=>`
18
+ `+` `.repeat(t)),Array(rb).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(rb).fill(0).map((e,t)=>`\r
19
+ `+` `.repeat(t)),Array(rb).fill(0).map((e,t)=>`
20
+ `+` `.repeat(t)),Array(rb).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(rb).fill(0).map((e,t)=>`\r
21
+ `+` `.repeat(t));var ib;(function(e){e.DEFAULT={allowTrailingComma:!1}})(ib||={});function ab(e,t=[],n=ib.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}sb(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:cb(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 ob(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 sb(e,t,n=ib.DEFAULT){let r=Qy(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 cb(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 lb;(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`})(lb||={});var ub;(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`})(ub||={});var db=ab,fb=ob,pb;(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`})(pb||={});var mb=X.lazy(async()=>({default:(await d(()=>import(`./dist-DYcwLEm6.js`),[],import.meta.url)).default}));function hb(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function gb(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function _b({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`}){let a=X.useMemo(()=>Ms(),[]),[o,s]=X.useState(()=>hb(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=db(o)}catch{i=void 0}let a=r.map(e=>{let r=gb(e.path),a=1,o=1,s=1,c=2,l=i?fb(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=hb(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)(mb,{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(Y(`engine.form.rootJsonObject`,a))}catch(e){l(e?.message??Y(`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 vb={object:async()=>(await d(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.i);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await d(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.i);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await d(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.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-RB3xvhcR.js`).then(e=>e.i);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await d(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await d(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await d(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await d(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await d(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await d(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await d(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.g);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await d(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.a);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await d(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.a);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await d(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.s);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await d(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.s);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await d(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.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-RB3xvhcR.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await d(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await d(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await d(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,policy:async()=>(await d(async()=>{let{PolicySchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.n);return{PolicySchema:e}},[],import.meta.url)).PolicySchema,role:async()=>(await d(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await d(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-RB3xvhcR.js`).then(e=>e.o);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},yb=new Set([`approval`,`connector_action`]),bb=/^nodes\.(\d+)\.type$/;function xb(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 Sb=new Map;async function Cb(e){if(Sb.has(e))return Sb.get(e)??null;let t=vb[e];if(!t)return Sb.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return Sb.set(e,r),r}catch{return Sb.set(e,null),null}}function wb(e){return e in vb}async function Tb(e,t,n){let r=await Cb(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=bb.exec(n);if(!r)return!0;let i=xb(t,Number(r[1]));return!(i&&yb.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 Eb=Ia,Db=new Set([`object`]),Ob={object:[`fields`,`fieldGroups`]};function kb(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 Ab({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=s(),a=e??i.type??``,o=t??i.name??``,c=Qv(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)(jb,{type:a,name:o,createMode:n,embedded:r})}function jb({type:e,name:t,createMode:n,embedded:r}){let i=v(),[a,o]=m(),s=_s(),{entries:c}=Ls(s),l=c.find(t=>t.type===e),u=ey(e,l),d=(n&&u.createSchema?u.createSchema:l?.schema)??u.defaultSchema,f=X.useMemo(()=>Ms(),[]),[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,M]=X.useState(null),[ee,N]=X.useState(null),P=X.useCallback(e=>{A(t=>({...t,...e}))},[A]),{markTouched:te}=Dy({rules:u.createDerive,draft:_,onPatch:P,enabled:!!n}),ne=X.useMemo(()=>{if(n)return u.createFields&&u.createFields.length>0?u.createFields:Oy(d?.properties??void 0,d?.required??void 0)},[n,u.createFields,d]),F=X.useMemo(()=>{let t=Ob[e]??[];if(!n||!ne)return t.length===0?u.hiddenFields:Array.from(new Set([...u.hiddenFields??[],...t]));let r=d?.properties??{},i=new Set(ne),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,ne,d,u.hiddenFields,e]),re=X.useMemo(()=>n&&ne?ne:u.fieldOrder,[n,ne,u.fieldOrder]),ie=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])||te(e)}A(e)},[n,_,A,te]);X.useEffect(()=>{if(!wb(e))return;let t=!1,n=window.setTimeout(()=>{Tb(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),[I,se]=X.useState(!1),[ce,le]=X.useState(0),[ue,de]=X.useState(!!n),[fe,pe]=X.useState(null);X.useEffect(()=>{pe(null)},[e,t]),X.useEffect(()=>{ue||pe(null)},[ue]);let me=X.useRef(null),[he,ge]=X.useState(null),[_e,L]=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`,_e?`1`:`0`)}catch{}},[_e]);let R=X.useRef(null),[z,ve]=X.useState([]),[B,V]=X.useState(!0);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await s.list(`object`);if(e)return;ve(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||ve([])}finally{e||V(!1)}})(),()=>{e=!0}},[s]);let ye=X.useMemo(()=>({objectNames:z,objectsLoading:B}),[z,B]);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=kb(i),c=o??n.effective??n.code??{},l=u.toDraft?u.toDraft(c):c;y(l),me.current=l,oe(!!o),C(!1)}catch(e){r||(D(e?.message??String(e)),C(!1))}})(),()=>{r=!0}},[s,e,t,n,ce]);let[be,xe]=X.useState(!1);async function Se(){if(!(b!=null||be)){xe(!0);try{x(await s.references(e,t))}catch(e){x([]),console.error(`references() failed`,e)}finally{xe(!1)}}}let[Ce,we]=X.useState(null),Te=X.useMemo(()=>!n&&!r&&$v(e).length>0,[e,n,r]),Ee=X.useRef(null),[De,Oe]=X.useState(null),ke=a.get(`review`),Ae=X.useRef(!1);X.useEffect(()=>{if(!(ke!==`1`||n)){if(!Ae.current){Ae.current=!0,le(e=>e+1);return}if(!S){ae&&Oe(`review`);let e=new URLSearchParams(a);e.delete(`review`),o(e,{replace:!0}),Ae.current=!1}}},[ke,n,S,ae]);let[je,Me]=X.useState(`properties`);X.useEffect(()=>{if(De===`references`&&Se(),typeof window<`u`&&!r){let e=new URL(window.location.href);De?e.searchParams.set(`tab`,De):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[De,r]);let Ne=`metadata-edit:inspector-collapsed`,Pe=`metadata-edit:inspector-size`,[Fe,Ie]=X.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Ne)===`1`),Le=X.useRef(38);X.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(Pe));Number.isFinite(e)&&e>=22&&e<=80&&(Le.current=e)},[]);let Re=X.useRef(null),ze=X.useCallback(()=>{Ie(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Ne,t?`1`:`0`),t})},[]);X.useEffect(()=>{let e=Re.current;if(e)if(Fe)e.resize?.(`0%`);else{let t=Le.current||38;e.resize?.(`${t}%`)}},[Fe]);let[Be,Ve]=X.useState(!1),[He,Ue]=X.useState(!1);X.useEffect(()=>{if(typeof document>`u`||!He)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[He]),X.useEffect(()=>{if(typeof window>`u`||!He)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Ue(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[He]);let We=X.useRef(null);X.useEffect(()=>{We.current=null},[e,t]),X.useEffect(()=>{if(n||r||S)return;let i=`${e}/${t??``}`;We.current!==i&&Gy(e)&&(p?.code==null?l?.allowOrgOverride||l?.allowRuntimeCreate:l?.allowOrgOverride)&&(We.current=i,de(!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(),ze())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,ze]),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`)&&Oe(t),Ee.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&we({kind:`metadata`,type:e,name:t})}},[]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);Ce?.kind===`metadata`?e.searchParams.set(`open`,`${Ce.type}:${Ce.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[Ce,r]);function Ke(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 qe(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(Y(`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=kb(p);oe(!!m);let v=m??d.effective??c,b=u.toDraft?u.toDraft(v):v;y(b),me.current=b,ge(new Date),R.current=JSON.stringify(b),M(null),N(null);let x=!n&&!!Gy(e);!n&&!x&&de(!1),n&&i(`../${encodeURIComponent(o)}`,{relative:`path`})}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];M(Array.isArray(t)?t:[]),N(_)}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:Ss(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:Ss(e[2].trim(),f)}]:[{path:``,message:Ss(r,f)}]}k(n),n.length===1&&!n[0].path?D(n[0].message):n.length===1?D(`${Ke(n[0].path)}: ${n[0].message}`):D(bs(`engine.validation.failed`,f,{count:n.length}))}else D(e?.message??String(e))}finally{T(!1)}}async function Je(){let r=!n&&p?.code!=null;if(confirm(bs(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),me.current=r,Gy(e)?We.current=null:de(!1)}else i(`../`,{relative:`path`})}catch(e){D(e?.message??String(e))}finally{T(!1)}}}async function Ye(){se(!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=kb(r);oe(!!i);let a=i??n.effective??_;y(a),me.current=a}catch(e){D(e?.message??String(e))}finally{se(!1)}}async function Xe(){if(confirm(bs(`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),me.current=r,oe(!1)}catch(e){D(e?.message??String(e))}finally{T(!1)}}}let Ze=X.useMemo(()=>{if(n)return Object.keys(_).length>0;let e=me.current;if(!e)return!1;try{return JSON.stringify(_)!==JSON.stringify(e)}catch{return!1}},[_,n]),Qe=!n&&p?.code!=null,$e=p?.editable!==!1,et=p?.deletable!==!1,tt=p?.resettable!==!1,rt=p?.lockReason,it=p?.lock&&p.lock!==`none`,at=(n?!!(l?.allowOrgOverride||l?.allowRuntimeCreate):Qe?!!l?.allowOrgOverride:!!(l?.allowOrgOverride||l?.allowRuntimeCreate))&&(n||$e),ot=!at&&!n,lt=X.useRef(qe);if(X.useEffect(()=>{lt.current=qe}),X.useEffect(()=>{if(!_e||n||ot||!ue||!Ze||w)return;let e;try{e=JSON.stringify(_)}catch{return}if(e===R.current)return;let t=window.setTimeout(()=>{R.current=e,lt.current(!1)},1500);return()=>window.clearTimeout(t)},[_,Ze,ue,w,n,ot,_e]),X.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!at||ot||!ue&&!n)return;e.preventDefault(),!w&&(n||Ze)&&lt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[at,ot,ue,n,w,Ze]),X.useEffect(()=>{if(!Ze)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ze]),X.useEffect(()=>{if(!Ze)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(Y(`engine.edit.unsavedLeaveConfirm`,f))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[Ze,f]),Zo(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=Zu(_.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)(Gv,{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)(H,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let ut=ot&&Qe&&!!l?.allowRuntimeCreate,dt=Db.has(e),ft=!r&&(!n||dt)?Gy(e):void 0,pt=Jy(e),mt=Zy(e);function gt(){me.current&&y(me.current),k([]),D(null),de(!1)}let vt=ot||!ue&&!n,bt=(0,Z.jsxs)(Z.Fragment,{children:[!n&&(0,Z.jsx)(Jv,{entry:l,location:`record_header`,recordId:t,onAfter:()=>le(e=>e+1)}),(!n||Te)&&(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:()=>Oe(`layers`),title:Y(`engine.edit.layers`,f),className:`h-7 w-7 p-0 relative`,children:[(0,Z.jsx)(Jt,{className:`h-3.5 w-3.5`}),p?.overlay&&(()=>{let e=dy(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:Y(`engine.layers.diff`,f),children:e}):null})()]}),!n&&ae&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>Oe(`review`),title:Y(`designer.draftReview.title`,f),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,Z.jsx)(za,{className:`h-3.5 w-3.5`}),(()=>{let e=by(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:bs(`designer.draftReview.badge`,f,{n:e}),children:e}):null})()]}),!n&&(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>Oe(`references`),title:Y(`engine.edit.references`,f),className:`h-7 w-7 p-0 relative`,children:[(0,Z.jsx)(en,{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})]}),Te&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Oe(`related`),title:Y(`engine.edit.related`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(En,{className:`h-3.5 w-3.5`})}),!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Oe(`history`),title:Y(`engine.edit.history`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(vr,{className:`h-3.5 w-3.5`})}),!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Oe(`audit`),title:Y(`engine.edit.auditTab`,f),className:`h-7 w-7 p-0`,children:(0,Z.jsx)(Ea,{className:`h-3.5 w-3.5`})})]}),!n&&at&&p?.overlay&&(Qe?tt:et)&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Je,disabled:w,title:Y(Qe?`engine.edit.reset`:`engine.edit.delete`,f),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Qe?(0,Z.jsx)(ct,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(zn,{className:`h-3.5 w-3.5`})}),at&&!n&&!ue&&!ft&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>de(!0),className:`h-7`,children:[(0,Z.jsx)(Vt,{className:`h-3.5 w-3.5 mr-1`}),Y(`engine.edit.edit`,f)]}),at&&(ue||n)&&(0,Z.jsx)(Nb,{saving:w,isDirty:Ze,autoSaveEnabled:_e,lastSavedAt:he,createMode:!!n,locale:f}),at&&(ue||n)&&!n&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>L(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:Y(_e?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,f),children:_e?(0,Z.jsx)(fo,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Z.jsx)(Ao,{className:`h-3.5 w-3.5`})}),at&&!n&&ue&&!ft&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:gt,disabled:w,className:`h-7 w-7 p-0`,title:Y(`engine.cancel`,f),children:(0,Z.jsx)(Jr,{className:`h-3.5 w-3.5`})}),at&&(ue||n)&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>qe(!1),disabled:w||!n&&!Ze,className:`h-7 w-7 p-0 relative`,title:w?Y(`engine.edit.saving`,f):!n&&!Ze?Y(`engine.edit.noChanges`,f):`${Y(`engine.edit.save`,f)} (⌘S)`,children:[w?(0,Z.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Wn,{className:`h-3.5 w-3.5`}),Ze&&!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`})]}),at&&!n&&ae&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:Xe,disabled:w||I,className:`h-7 w-7 p-0 text-muted-foreground`,title:Y(`engine.edit.discardDraft`,f),children:(0,Z.jsx)(fn,{className:`h-3.5 w-3.5`})}),at&&!n&&ae&&(0,Z.jsx)(K,{size:`sm`,onClick:Ye,disabled:w||I||Ze,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:Y(Ze?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,f),children:I?(0,Z.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(co,{className:`h-3.5 w-3.5 mr-1`}),(0,Z.jsx)(`span`,{className:`text-xs`,children:Y(`engine.edit.publish`,f)})]})})]});return(0,Z.jsxs)(Gv,{entry:l??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?Y(`engine.edit.createNew`,f):void 0,actions:ft?null:bt,children:[(0,Z.jsxs)(`div`,{className:ft?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(E||ot||ae||it)&&(0,Z.jsxs)(`div`,{className:ft?`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}),it&&(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)(st,{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`&&Y(`engine.edit.lockFull`,f),p?.lock===`no-overlay`&&Y(`engine.edit.lockNoOverlay`,f),p?.lock===`no-delete`&&Y(`engine.edit.lockNoDelete`,f)]}),rt&&(0,Z.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:rt}),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}`:``]})})]}),ut&&(0,Z.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>i(`../new`,{relative:`path`}),children:Y(`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)(co,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:Y(`engine.edit.draftPending`,f)}),at&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(K,{size:`sm`,variant:`ghost`,onClick:Xe,disabled:w||I,className:`h-7`,children:Y(`engine.edit.discardDraft`,f)}),(0,Z.jsx)(K,{size:`sm`,onClick:Ye,disabled:w||I||Ze,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:I?(0,Z.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):Y(`engine.edit.publish`,f)})]})]}),ot&&!it&&(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:ut?Y(`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)):Y(`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))}),ut&&(0,Z.jsx)(K,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>i(`../new`,{relative:`path`}),children:Y(`engine.list.create`,f)})]})]}),(0,Z.jsx)(`div`,{className:ft?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Z.jsxs)(`div`,{className:ft?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!ft&&vt&&!ot&&at&&!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:Y(`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:Y(`engine.edit.edit`,f)})]},t))}),(0,Z.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>de(!0),children:[(0,Z.jsx)(Vt,{className:`h-3.5 w-3.5 mr-1`}),Y(`engine.edit.edit`,f)]})]}),(()=>{let t=p?._diagnostics,n=wb(e)?O.map(e=>({path:e.path,message:Ss(e.message,f)})):(t?.errors??[]).map(e=>({...e,message:Ss(e.message,f)})),r=wb(e)?n.length===0:t?.valid!==!1;if(!t&&!wb(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)(_t,{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:bs(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?Ke(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,Z.jsx)(`li`,{className:`opacity-70`,children:bs(`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)]})})(),ft?(0,Z.jsx)(`div`,{className:He?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Z.jsxs)(Eb,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Z.jsx)(Kt,{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:at&&(0,Z.jsxs)(`div`,{role:`tablist`,"aria-label":Y(`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":!Be,onClick:()=>Ve(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Be?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:Y(`engine.edit.designMode`,f),children:[(0,Z.jsx)(eo,{className:`h-3.5 w-3.5`}),Y(`engine.edit.designMode`,f)]}),(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Be,onClick:()=>Ve(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Be?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Y(`engine.edit.previewMode`,f),children:[(0,Z.jsx)(nt,{className:`h-3.5 w-3.5`}),Y(`engine.edit.previewMode`,f)]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[bt,(0,Z.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),ft&&(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:ze,className:`h-7 w-7 p-0`,title:Y(Fe?`engine.edit.showInspector`:`engine.edit.hideInspector`,f)+` (⌘\\)`,children:Fe?(0,Z.jsx)(kn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(li,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>Ue(e=>!e),className:`h-7 w-7 p-0`,title:Y(He?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,f),children:He?(0,Z.jsx)(Ai,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Gr,{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)(ft,{type:e,name:t,draft:_,baseline:n?void 0:p?.effective??void 0,editing:ue&&!Be,selection:Be?null:fe,onSelectionChange:pe,locale:f,onPatch:e=>A(t=>({...t,...e}))})})]})}),(0,Z.jsx)(wt,{withHandle:!0,className:Fe?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Z.jsx)(Kt,{panelRef:Re,defaultSize:Le.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Le.current=t,typeof window<`u`&&window.localStorage.setItem(Pe,String(Math.round(t)))),Ie(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Ne,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":je===`properties`,onClick:()=>Me(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(je===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Y(`engine.edit.inspector.properties`,f),children:[(0,Z.jsx)(Qr,{className:`h-3.5 w-3.5`}),Y(`engine.edit.inspector.properties`,f)]}),(0,Z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":je===`source`,onClick:()=>Me(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(je===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:Y(`engine.edit.inspector.source`,f),children:[(0,Z.jsx)(_o,{className:`h-3.5 w-3.5`}),Y(`engine.edit.inspector.source`,f)]})]}),Ze&&(0,Z.jsxs)(U,{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`}),Y(`engine.edit.unsaved`,f)]})]}),(0,Z.jsx)(`div`,{className:`p-4`,children:je===`source`?(0,Z.jsx)(_b,{value:_,onChange:A,readOnly:vt,issues:O.map(e=>({path:e.path??``,message:e.message}))}):fe&&pt?(0,Z.jsx)(pt,{type:e,name:t,draft:_,selection:fe,onPatch:e=>A(t=>({...t,...e})),onClearSelection:()=>pe(null),onSelectionChange:pe,readOnly:vt,locale:f}):!fe&&mt?(0,Z.jsx)(mt,{type:e,name:t,draft:_,onPatch:e=>A(t=>({...t,...e})),onSelectionChange:pe,readOnly:vt,locale:f,serverSchema:l?.schema}):(0,Z.jsx)(ks,{schema:d,form:n&&u.createSchema?void 0:l?.form,value:_,onChange:ie,issues:O,hiddenFields:F,fieldOrder:re,readOnly:vt,createMode:n,widgetContext:ye})})]})})]})}):(0,Z.jsx)(ks,{schema:d,form:n&&u.createSchema?void 0:l?.form,value:_,onChange:ie,issues:O,hiddenFields:F,fieldOrder:re,readOnly:vt,createMode:n,widgetContext:ye})]})})]}),(0,Z.jsx)(on,{open:De===`layers`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Pt,{className:`text-base`,children:Y(`engine.edit.layers`,f)}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(fy,{layered:p,locale:f})})]})}),(0,Z.jsx)(on,{open:De===`review`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Pt,{className:`text-base`,children:Y(`designer.draftReview.title`,f)}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t,` · `,Y(`designer.canvas.reviewVsPublished`,f)]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(xy,{published:p?.effective??null,draft:_,locale:f})})]})}),(0,Z.jsx)(on,{open:De===`references`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsxs)(Pt,{className:`text-base`,children:[Y(`engine.edit.references`,f),b&&(0,Z.jsx)(U,{variant:`outline`,className:`ml-2 text-[10px]`,children:b.length})]}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(Mb,{refs:b,loading:be})})]})}),Te&&(0,Z.jsx)(on,{open:De===`related`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Pt,{className:`text-base`,children:Y(`engine.edit.related`,f)}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(ky,{type:e,name:t,parentItem:_,onOpen:e=>we(e)})})]})}),!n&&(0,Z.jsx)(on,{open:De===`history`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Pt,{className:`text-base`,children:Y(`engine.edit.history`,f)}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Z.jsx)(Ly,{type:e,name:t,client:s,onRollback:()=>le(e=>e+1),rollbackLabel:Y(`engine.edit.rollback`,f),rollbackConfirm:e=>Y(`engine.edit.rollbackConfirm`,f).replace(`{version}`,String(e))})})]})}),!n&&(0,Z.jsx)(on,{open:De===`audit`,onOpenChange:e=>!e&&Oe(null),children:(0,Z.jsxs)(mn,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Z.jsxs)(yt,{className:`px-4 py-3 border-b`,children:[(0,Z.jsx)(Pt,{className:`text-base`,children:Y(`engine.edit.auditTab`,f)}),(0,Z.jsxs)(Dn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Z.jsx)(Hy,{type:e,name:t,client:s,locale:f})})]})}),(0,Z.jsx)(Fy,{target:Ce,onClose:()=>we(null),parentContext:{type:e,name:t}}),(0,Z.jsx)(ht,{open:j!=null,onOpenChange:e=>{e||(M(null),N(null))},children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(_t,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Z.jsx)(Xt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,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)(Ln,{children:[(0,Z.jsx)(K,{variant:`ghost`,onClick:()=>M(null),children:`Cancel`}),(0,Z.jsx)(K,{variant:`destructive`,onClick:()=>qe(!0),disabled:w,children:w?`Forcing…`:`Force save`})]})]})})]})}function Mb({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)(H,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:`No references found`}),(0,Z.jsx)(qt,{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)(U,{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 Nb({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)(H,{className:`h-3 w-3 animate-spin`}),Y(`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`}),Y(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:bs(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function Pb({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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`Missing metadata type`}),(0,Z.jsxs)(qt,{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)(ny,{type:r}):a[0]===`new`&&a.length===1?(0,Z.jsx)(Ab,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,Z.jsx)(Iy,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,Z.jsx)(Ab,{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)(Ot,{children:[(0,Z.jsx)(Ue,{children:`Unknown sub-path`}),(0,Z.jsxs)(qt,{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 Ib(){let e=_s(),t=X.useMemo(()=>Ms(),[]),[n,r]=X.useState(`error`),{loading:i,error:a,summary:o,reload:s}=vs(e,n),{entries:c}=Ls(e),l=X.useMemo(()=>{let e={};for(let n of c)e[n.type]=Ns(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)(Or,{className:`h-3 w-3`}),Y(`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)(_t,{className:`h-5 w-5 text-destructive`}),Y(`engine.diagnostics.title`,t)]}),(0,Z.jsx)(U,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:bs(`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:Y(`engine.diagnostics.severity.${e}`,t)},e))}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:s,children:[(0,Z.jsx)(Ui,{className:`h-3.5 w-3.5 mr-1`}),Y(`engine.diagnostics.refresh`,t)]})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:Y(`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:Y(`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:bs(`engine.diagnostics.loadFailed`,t,{error:a})}),!i&&!a&&u.length===0&&(0,Z.jsxs)(Ot,{children:[(0,Z.jsx)(Ue,{children:Y(`engine.diagnostics.cleanTitle`,t)}),(0,Z.jsx)(qt,{children:bs(`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)(U,{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:Y(`engine.diagnostics.col.name`,t)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:Y(`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)(U,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:bs(`engine.diagnostics.errorN`,t,{count:i.length})}),a.length>0&&(0,Z.jsx)(U,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:bs(`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:bs(`engine.diagnostics.more`,t,{count:s})})]})})]},r.name)})})]})})]},e))]})]})}function Lb(e){return[{key:`allowCreate`,short:`C`,tip:Y(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:Y(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:Y(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:Y(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:Y(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:Y(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:Y(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:Y(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:Y(`perm.action.modifyAll`,e)}]}function Rb({type:e,name:t}){let n=v(),r=_s(),{entries:i}=Ls(r),a=i.find(t=>t.type===e),o=!!ey(e,a).allowOrgOverride,s=X.useMemo(()=>Ms(),[]),c=X.useCallback(e=>Y(e,s),[s]),l=X.useMemo(()=>Lb(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 M(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),j(e)),n})}function ee(e,t,n){d(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function N(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 P(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 te(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 ne=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]),F=[{label:c(`perm.stat.objectsGranted`),value:Object.values(u.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:c(`perm.stat.fieldOverrides`),value:Object.keys(u.fields??{}).length}];return y?(0,Z.jsx)(Gv,{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)(H,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,Z.jsxs)(Gv,{entry:a??{type:e,label:e},itemName:t,subtitle:u.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:F,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)(vr,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,Z.jsxs)(K,{size:`sm`,onClick:()=>te(!1),disabled:x,children:[x?(0,Z.jsx)(H,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Z.jsx)(Wn,{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)(_t,{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)(ao,{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)(U,{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)(ao,{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:[ne.length,` / `,f.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Z.jsx)(zb,{objects:ne,draft:u,expanded:g,fieldsByObject:m,writable:o,objectActions:l,t:c,onToggleExpand:M,onObjectPerm:ee,onFieldPerm:P,onBulkSet:N})})]}),(0,Z.jsx)(ht,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,Z.jsxs)(At,{children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(_t,{className:`h-4 w-4 text-amber-500`}),` `,c(`engine.edit.destructive`)]}),(0,Z.jsx)(Xt,{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)(U,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Z.jsxs)(Ln,{children:[(0,Z.jsx)(K,{variant:`ghost`,onClick:()=>E(null),children:c(`engine.cancel`)}),(0,Z.jsxs)(K,{variant:`destructive`,onClick:()=>T&&te(!0,T.pending),disabled:x,children:[x&&(0,Z.jsx)(H,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function zb({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)(Ir,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Fi,{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)(dr,{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)(Bb,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function Bb({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)(dr,{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)(dr,{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)(H,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function Vb(){Zv({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Hb(e.fields),groupLabel:`Fields`,order:5}]}),Zv({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}]}),Zv({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Hb(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Zv({type:`hook`,anchors:[{anchorType:`object`,match:Yv(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Zv({type:`page`,anchors:[{anchorType:`object`,match:Yv(`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-CBO5qxO-.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{}}}}),Zv({type:`view`,anchors:[{anchorType:`object`,match:Yv([`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}}}}}),Zv({type:`flow`,anchors:[{anchorType:`object`,match:Yv([`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:[]}}),Zv({type:`trigger`,anchors:[{anchorType:`object`,match:Yv([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Zv({type:`validation`,anchors:[{anchorType:`object`,match:Yv(`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`}}),Zv({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:{}}}),Zv({type:`action`,anchors:[{anchorType:`object`,match:Yv([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Zv({type:`dashboard`,anchors:[{anchorType:`object`,match:Yv([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Zv({type:`report`,anchors:[{anchorType:`object`,match:Yv([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`objectName`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{columns:[]}}),Zv({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 Hb(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Ub={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`}},Wb={role:{type:`object`,title:`Role`,required:[`name`],properties:{...Ub,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:{...Ub,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:{...Ub.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Ub.label,description:Ub.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:{...Ub,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:{...Ub,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Ub,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Ub,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Ub,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:{...Ub,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Ub,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:{...Ub,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 Gb(){for(let[e,t]of Object.entries(Wb))Zv({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Kb({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 qb({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)(ci,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Z.jsx)(`div`,{className:`flex-1`,children:t})]})}function Jb({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)(lr,{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 Yb=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)(qb,{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 Xb({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:q(`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)(No,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:a??`Add`})]})]})]})}var Zb={"page:header":{label:`Header`,category:`layout`,Icon:hr},"page:footer":{label:`Footer`,category:`layout`,Icon:pa},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:je},"page:tabs":{label:`Tabs`,category:`layout`,Icon:ei},"page:accordion":{label:`Accordion`,category:`layout`,Icon:yi},"page:card":{label:`Card`,category:`layout`,Icon:Xa},"page:section":{label:`Section`,category:`layout`,Icon:Jt},"record:details":{label:`Record details`,category:`record`,Icon:uo},"record:highlights":{label:`Highlights`,category:`record`,Icon:Pa},"record:related_list":{label:`Related list`,category:`record`,Icon:Hi},"record:activity":{label:`Activity timeline`,category:`record`,Icon:ma},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:jr},"record:path":{label:`Stage path`,category:`record`,Icon:tr},"record:alert":{label:`Alert banner`,category:`record`,Icon:_t},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:fo},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Bn},"record:history":{label:`History`,category:`record`,Icon:vr},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Do},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:tr},"global:search":{label:`Global search`,category:`navigation`,Icon:Oo},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:Nt},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:ya},"element:text":{label:`Text`,category:`element`,Icon:Tn},"element:number":{label:`Number`,category:`element`,Icon:mr},"element:image":{label:`Image`,category:`element`,Icon:Bt},"element:divider":{label:`Divider`,category:`element`,Icon:sa},"element:button":{label:`Button`,category:`element`,Icon:ea},"element:definition-list":{label:`Definition list`,category:`element`,Icon:hn},"element:repeater":{label:`Repeater`,category:`element`,Icon:go}},Qb={layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},$b=(()=>{let e={layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Zb))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)})(),ex=vt,tx={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 nx(e){return tx[Zb[e]?.category??`misc`]}var rx={"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 ix(e){return!!e&&Array.isArray(rx[e])&&rx[e].length>0}function ax(){let e=_s(),[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 ox(e){let{fields:t}=hd(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 sx({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=ax();return i.length===0?(0,Z.jsx)(Ts,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Z.jsx)(Os,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function cx({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=ox(t);return!t||a.length===0?(0,Z.jsx)(Ts,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Z.jsx)(Os,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function lx({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=ox(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)(Vn,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,Z.jsx)(cr,{className:`h-8`,children:(0,Z.jsx)(Dt,{placeholder:`—`})}),(0,Z.jsx)(Fo,{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)(Jr,{className:`h-4 w-4`})})]},t)),!i&&(0,Z.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,Z.jsx)(No,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}var ux=Symbol(`remove`);function dx(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 fx(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function px(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function mx(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===ux?t.splice(r,1):t[r]=n:t[r]=mx(t[r],i,n),t}let a={...e||{}};return i.length===0?n===ux?delete a[r]:a[r]=n:a[r]=mx(a[r],i,n),a}function hx(e,t){return px(e,fx(t))}function gx(e,t,n){let r=fx(t),i=mx(e,r,n===null?ux:n),a=r[0];return{[a]:i[a]}}function _x(e,t){let n=fx(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=px(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function vx(e,t,n){let r=fx(t),i=mx(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function yx({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:dx(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?dx(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?hx(h||{},f):h:c?hx(t,c):null,y=s?f?_x(h||{},f):{siblings:m,index:u}:c?_x(t,c):null;if(!s&&!c||!v)return(0,Z.jsx)(Es,{kindLabel:Y(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Y(`engine.inspector.pageBlock.close`,a),children:(0,Z.jsx)(Fs,{message:e.id})});let b=e=>s?_(f?{...h,...gx(h||{},f,{...v,...e})}:{...v,...e}):n(gx(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)(Cs,{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)(Ds,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`select`:return(0,Z.jsx)(Os,{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)(Jr,{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)(No,{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)(zn,{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)(No,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,Z.jsx)(sx,{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)(cx,{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)(lx,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,Z.jsx)(Ts,{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,...gx(h||{},f,null)}:null):n(gx(t,c,null)),r()},O=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:Y(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,Z.jsx)(js,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=Is(y.siblings,y.index,e);_({...h,...vx(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(Is(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}n(vx(t,c,Is(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:Y(`engine.inspector.reorder.up`,a),downLabel:Y(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Z.jsx)(ws,{label:Y(`engine.inspector.pageBlock.remove`,a),onClick:D,disabled:o}),children:[(0,Z.jsx)(Ts,{label:Y(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e}),disabled:o,mono:!0}),ix(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:Y(`engine.inspector.pageBlock.properties`,a)}),rx[v.type].map(e=>E(e,w,T))]})]})}function bx(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 xx=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function Sx(e){let t=e||{};return xx.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function Cx(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 wx(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:Sx(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 Tx(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function Ex(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 Dx=`text/x-objectui-pageblock`;function Ox({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=X.useMemo(()=>wx(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:Cx(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=Tx(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:Ex(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:Tx(o,e,l,i[e]?.name),label:Ex(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=dx(i);if(!s)return;let c=fx(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=px(p,c)||[];f[l]=mx(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=dx(`${n}.${i}`);if(!o)return;let s=fx(o),c=px(e,s)||[],l=mx(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)(No,{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)(kx,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:Tx(o,t,n,e.name),label:Ex(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>Tx(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)(No,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function kx({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:q(`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(Dx)||(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(Dx);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=Tx(n,t,d,e.name);return(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(Ax,{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)(jx,{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)(Mx,{onPick:e=>s(t,e)})})]})]})}function Ax({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Zb[c]?.Icon??ex,u=nx(c),d=Ex(e),f=!i,[p,m]=X.useState(null),h=e=>{e.dataTransfer.setData(Dx,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(Dx))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(Dx);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:q(`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:q(`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)(Ae,{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:q(`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:q(`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)(U,{variant:`outline`,className:q(`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 jx({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=bx(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=Zb[s]?.Icon??ex;return(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,Ex(r))},className:q(`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:Ex(r)}),(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground/60`,children:s})]},a)}),!r&&(0,Z.jsx)(Mx,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function Mx({onPick:e}){let[t,n]=X.useState(!1),[r,i]=X.useState(``),a=r.trim().toLowerCase(),o=X.useMemo(()=>a?$b.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Zb[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):$b,[a]);return(0,Z.jsxs)(kr,{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)(No,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Z.jsxs)(Pn,{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:Qb[t.category]}),t.types.map(t=>{let r=Zb[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:q(`h-3.5 w-3.5 shrink-0`,nx(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 Nx({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)(Kb,{hint:`page${s?` · design`:``}`,children:[s&&u===`regions`?(0,Z.jsx)(Ox,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Z.jsx)(Xb,{title:Y(`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:Y(`engine.inspector.add.block`,a)}):null,!s&&(0,Z.jsx)(qb,{children:`Add components to the page to see a preview.`})]}):s&&u===`regions`?(0,Z.jsx)(Kb,{hint:`page · design`,children:(0,Z.jsx)(Ox,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r})}):(0,Z.jsx)(Kb,{hint:`page${s?` · design`:``}`,children:(0,Z.jsxs)(Yb,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Z.jsx)(Xb,{title:Y(`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:Y(`engine.inspector.add.block`,a)}),(0,Z.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Z.jsx)(P,{schema:o})})]})})}function Px(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 Ix(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 Lx(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(Ix):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function Rx({name:e,draft:t,editing:n}){let r=X.useMemo(()=>ef(t)?.schema,[t]),i=X.useMemo(()=>Px(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)(Kb,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Z.jsx)(Yb,{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)(P,{schema:e})})})})}if(!i)return(0,Z.jsx)(Kb,{hint:`view${a?` · design`:``}`,children:(0,Z.jsxs)(qb,{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=Lx(i,r);return(0,Z.jsx)(Kb,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Z.jsx)(Yb,{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)(P,{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)(Kb,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Z.jsx)(Yb,{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)(P,{schema:l})})})})}var zx=X.lazy(()=>d(()=>import(`./plugin-dashboard-PA0xf59v.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Bx({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=ye(),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=xs(`widget`,s.map(e=>e?.id).filter(Boolean)),r=tm[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;n({widgets:ys(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)(am,{onAdd:p,label:Y(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Z.jsx)(Kb,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Z.jsx)(qb,{children:`Add at least one widget to see a preview.`})}):(0,Z.jsx)(Kb,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Z.jsxs)(Yb,{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)(H,{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)(zx,{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=tm[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)(po,{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)(Vt,{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)(Jr,{className:`h-3.5 w-3.5`})})]})}var Hx=X.lazy(()=>d(()=>import(`./plugin-report-rz8HUIsi.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Ux({draft:e}){let t=ye();if(typeof e.dataset==`string`&&e.dataset){let n=Array.isArray(e.rows)?e.rows.filter(Boolean):[];return(0,Z.jsx)(Kb,{hint:`report · dataset "${e.dataset}"${n.length?` · by `+n.join(`, `):``}`,children:(0,Z.jsx)(Yb,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Z.jsx)(H,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Z.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,Z.jsx)(Hx,{schema:e,dataSource:t})})})})})}return(0,Z.jsx)(Kb,{children:(0,Z.jsx)(Jb,{icon:(0,Z.jsx)(Zt,{className:`h-8 w-8`}),title:`Bind a dataset to preview this report`,description:`Since the 9.0 single-form cutover a report renders its dataset's measures (values) grouped by dimensions (rows). Choose a Dataset in the right panel to start designing.`})})}var Wx=`text/x-objectui-nav`;function Gx(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 Kx(e){switch(e){case`object`:return Zt;case`page`:return uo;case`dashboard`:return kt;case`report`:return Qn;case`link`:return Le;case`group`:return ra;default:return tr}}var qx={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 Jx(e){return qx[e]??qx.item}function Yx(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Xx(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Zx({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=ys(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(zs(a,e,null)),o===`${t}[${e}]`&&i?.(null))},[n,a,l,t,o,i]),f=X.useCallback((e,r)=>{n&&(l(zs(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=Is(a,e,o);l(s),i?.({kind:`nav`,id:`${t}[${o}]`,label:Yx(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)(U,{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)(No,{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(Wx)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Wx)&&(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)(Qx,{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 Qx({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)($x,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,Yx(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)(Qx,{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 $x({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=Gx(e),p=Kx(f),m=Jx(f),h=Xx(e),[g,_]=X.useState(!1),[v,y]=X.useState(Yx(e,t)),[b,x]=X.useState(!1),[S,C]=X.useState(null);return X.useEffect(()=>{g||y(Yx(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(Wx,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Wx)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,C(`before`))},onDragLeave:()=>C(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Wx)&&(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)(Ae,{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:q(`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!==Yx(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),y(Yx(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:Yx(e,t)}),(0,Z.jsx)(U,{variant:`outline`,className:q(`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)(zn,{className:`h-3 w-3`})})]})]})}function eS(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)?eS(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function tS(e){switch(e){case`object`:return Zt;case`page`:return uo;case`dashboard`:return kt;case`report`:return Qn;default:return tr}}function nS({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:eS(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)(Kb,{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)(Xi,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Yb,{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)(Zx,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Z.jsxs)(qb,{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)(rS,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function rS({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=tS(e.kind),s=iS(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)(Xi,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Z.jsx)(rS,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function iS(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 aS(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Z.jsx)(oS,{...e,icon:t===`password`?(0,Z.jsx)(st,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(pr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(Za,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(ur,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(mr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(it,{className:`h-3.5 w-3.5`}),placeholder:Y(`designer.stub.pickDate`,n)});case`time`:return(0,Z.jsx)(oS,{...e,icon:(0,Z.jsx)(gr,{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)(sS,{...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)(ao,{disabled:!0}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??Y(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Z.jsx)(cS,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Z.jsx)(cS,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Z.jsx)(lS,{...e});case`image`:case`avatar`:return(0,Z.jsx)(uS,{icon:(0,Z.jsx)(Bt,{className:`h-4 w-4`}),label:Y(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Z.jsx)(uS,{icon:(0,Z.jsx)(It,{className:`h-4 w-4`}),label:bs(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Z.jsx)(uS,{icon:(0,Z.jsx)(It,{className:`h-4 w-4`}),label:Y(`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)(La,{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)(Pe,{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)(oS,{...e,icon:(0,Z.jsx)(Un,{className:`h-3.5 w-3.5`}),placeholder:Y(`designer.stub.latLng`,n)});case`address`:return(0,Z.jsx)(sS,{...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}`:`ƒ ${Y(`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:Y(`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:Y(`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)(U,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function oS({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 sS({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 cS({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||Y(`designer.stub.select`,r)}),(0,Z.jsx)(Ir,{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||Y(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,Z.jsx)(U,{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 lS({referenceTo:e,placeholder:t,locale:n}){let r=e?_d.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)(en,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?bs(`designer.stub.searchRef`,n,{ref:e}):Y(`designer.stub.chooseRelated`,n))}),e&&(0,Z.jsxs)(U,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Z.jsx)(Oo,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function uS({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 dS=e=>(e??``).toLowerCase().startsWith(`zh`),fS=(e,t)=>e?dS(t)?e.labelZh:e.label:void 0,pS=(e,t)=>(dS(t)?Sd:yd)[e];function mS({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,c=X.useMemo(()=>Zu(t.fields),[t]),l=X.useMemo(()=>n?md(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(()=>rd(t.fieldGroups),[t]),_=g.length>0,v=X.useMemo(()=>dd(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 M=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]),ee=X.useCallback(()=>k(new Set),[]),N=X.useCallback(()=>{if(!r||O.size===0)return;let e=c.entries.filter(e=>!O.has(e.name));r({fields:Qu({shape:c.shape,entries:e})}),T&&O.has(T)&&a?.(null),k(new Set)},[r,O,c,T,a]),P=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:Qu({shape:c.shape,entries:t})})},[r,O,c]),te=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=ed(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:Qu({shape:c.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(l.def.label??s)})},[r,a,c]),ne=X.useCallback(()=>{if(!r)return;let e=ad(g,bs(`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]),F=X.useCallback((e,t)=>{r&&r({fieldGroups:od(g,e,t)})},[r,g]),re=X.useCallback(e=>{if(!r)return;let t=ld(c,e);r({fieldGroups:sd(g,e),fields:Qu(t)})},[r,g,c]),ie=X.useCallback((e,t)=>{r&&r({fieldGroups:cd(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:Qu({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:Qu({shape:c.shape,entries:n})})},[r,c]),I=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:Qu({shape:c.shape,entries:n})})},[r,c]),se=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:Qu({shape:c.shape,entries:n})})},[r,c]),ce=X.useCallback(e=>{e.target===e.currentTarget&&T&&a?.(null)},[a,T]),le=c.entries.length===0,ue=_||v.length>1;return(0,Z.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:ce,"data-object-name":e,children:[!s&&O.size>0&&(0,Z.jsx)(gS,{count:O.size,groups:g,onMoveToGroup:P,onDelete:N,onClear:ee,locale:o}),(0,Z.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:ce,children:[!le&&(0,Z.jsx)(hS,{fieldCount:c.entries.length,requiredCount:E,sectionCount:g.length,allCollapsed:C,onToggleAll:ue?()=>w(!C):void 0,reviewAvailable:u>0,reviewing:p,diffCounts:l?.counts,onToggleReview:()=>f(e=>!e),locale:o}),le?(0,Z.jsx)(xS,{onAdd:s?void 0:te,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)(_S,{groupKey:e.key,label:e.key===null?Y(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:ue,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=>F(e.key,t):void 0,onRemove:e.key?()=>re(e.key):void 0,onMove:e.key?t=>ie(e.key,t):void 0,onAddField:s?void 0:t=>te(t,e.key),onDropField:s?void 0:I,children:[e.entries.map(e=>(0,Z.jsx)(bS,{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=>M(e,t),onReorder:s?void 0:ae,onRenameLabel:s?void 0:se,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:Y(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:Y(`designer.canvas.diffRemoved`,o)}),l.removed.map(e=>(0,Z.jsx)(yS,{entry:e,locale:o},e.name))]}),!le&&!s&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Z.jsx)(SS,{onPick:e=>te(e),locale:o}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:ne,children:[(0,Z.jsx)(oi,{className:`h-3.5 w-3.5`}),Y(`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:()=>Xo(),children:[(0,Z.jsx)(ya,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.askAi`,o)]})]})]})]})}function hS({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}),` `,Y(`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}),` `,Y(`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}),` `,Y(`designer.canvas.diffRemoved`,l),(0,Z.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:Y(`designer.canvas.reviewVsPublished`,l)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,Y(`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}),` `,Y(`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}),` `,Y(`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:q(`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)(za,{className:`h-3 w-3`}),Y(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)(yi,{className:`h-3 w-3`}):(0,Z.jsx)(Oa,{className:`h-3 w-3`}),Y(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function gS({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:bs(`designer.canvas.bulkSelected`,a,{n:e})}),(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:Y(`designer.canvas.bulkHint`,a)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,Z.jsxs)(kr,{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)(Da,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.bulkMoveTo`,a),(0,Z.jsx)(Ir,{className:`h-3 w-3`})]})}),(0,Z.jsxs)(Pn,{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:Y(`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)(zn,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.bulkDelete`,a)]}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,Z.jsx)(Jr,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.bulkClear`,a)]})]})]})}function _S({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:q(`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)(vS,{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 vS({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?Fi:Ir;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":Y(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:q(`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?Y(`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:Y(`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)(SS,{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":Y(`designer.canvas.moveSectionUp`,a),children:(0,Z.jsx)(Gt,{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":Y(`designer.canvas.moveSectionDown`,a),children:(0,Z.jsx)(Nn,{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":Y(`designer.canvas.removeSection`,a),title:Y(`designer.canvas.removeSectionHint`,a),children:(0,Z.jsx)(zn,{className:`h-3 w-3`})})]})]})}function yS({entry:e,locale:t}){let n=e.def,r=_d[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)(U,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:Y(`designer.canvas.diffRemoved`,t)})]})})}function bS({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=_d[f],m=p?.Icon,h=bd[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)},M=()=>{k(g),D(!1)};return(0,Z.jsxs)(`div`,{className:q(`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:q(`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)(Li,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),T&&!n&&(0,Z.jsx)(Ae,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,Z.jsx)(m,{className:q(`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(),M())},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:q(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:A,title:l?Y(`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)(U,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:Y(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,Z.jsx)(U,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?bs(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:Y(`designer.canvas.diffChanged`,o)}),(0,Z.jsx)(U,{variant:`outline`,className:q(`text-[10px] font-medium`,h.badge),children:fS(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)(aS,{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 xS({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:Y(`designer.canvas.noFields`,t)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Y(`designer.canvas.noFieldsHint`,t)}),e&&(0,Z.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(SS,{onPick:e,locale:t}),(0,Z.jsxs)(K,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>Xo(),children:[(0,Z.jsx)(ya,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.askAiGenerate`,t)]})]})]})}function SS({onPick:e,compact:t,locale:n}){let[r,i]=X.useState(!1),[a,o]=X.useState(``),s=a.trim().toLowerCase(),c=X.useMemo(()=>s?Cd.map(e=>({category:e.category,types:e.types.filter(e=>{let t=_d[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):Cd,[s,a]);return(0,Z.jsxs)(kr,{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":Y(`designer.canvas.addFieldToSection`,n),title:Y(`designer.canvas.addFieldToSection`,n),children:(0,Z.jsx)(No,{className:`h-3 w-3`})}):(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Z.jsx)(No,{className:`h-3.5 w-3.5`}),Y(`designer.canvas.addField`,n)]})}),(0,Z.jsxs)(Pn,{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:Y(`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:Y(`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:pS(t.category,n)}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=_d[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:q(`h-3.5 w-3.5 shrink-0`,bd[r.category].icon)}),(0,Z.jsx)(`span`,{className:`truncate`,children:fS(r,n)})]},t)})})]},t.category))})]})]})}function CS({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)(Kb,{hint:`object · designer`,children:(0,Z.jsx)(Yb,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Z.jsx)(mS,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,Z.jsx)(Kb,{hint:`object`,children:(0,Z.jsx)(qb,{children:Y(`designer.canvas.nameToStart`,o)})})}function wS(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 TS(e,t){return t[e]??``}function ES(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>TS(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>TS(n,t))}function DS({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 wS(t))e.add(n);for(let t of wS(i))e.add(t);for(let t of wS(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=X.useState({}),l=ES(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?ES(i,s):ES(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Z.jsx)(Kb,{hint:`email_template`,children:(0,Z.jsx)(qb,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Z.jsx)(Kb,{hint:`email_template`,children:(0,Z.jsx)(Yb,{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 kS(e){return OS(e.ui?.x)&&OS(e.ui?.y)}function AS(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)kS(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function jS(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 MS(e){return{x:e.x+240/2,y:e.y+66}}function NS(e){return{x:e.x+240/2,y:e.y}}function PS(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 FS(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function IS(e,t){return e.id||`${e.source}->${e.target}#${t}`}function LS(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function RS(e){switch(e){case`start`:return or;case`end`:return Ba;case`decision`:case`branch`:case`gateway`:return jt;case`wait`:case`timer`:case`delay`:return Et;case`boundary_event`:case`signal`:return fo;case`subflow`:case`flow`:return Kn;case`create_record`:return So;case`update_record`:return Ze;case`delete_record`:return Ti;case`get_record`:return qr;case`http_request`:case`webhook`:return Za;case`script`:case`script_task`:return St;case`screen`:case`user_task`:return Ta;case`approval`:return Ve;case`connector_action`:case`service_task`:return We;case`assignment`:return lt;case`loop`:case`for_each`:return gn;case`map`:return Hi;case`parallel_gateway`:case`join_gateway`:case`parallel`:return ha;case`try_catch`:return ca;default:return ni}}var zS={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 BS(e){switch(e){case`start`:return zS.start;case`end`:return zS.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return zS.decision;case`wait`:case`timer`:case`delay`:return zS.wait;case`boundary_event`:case`signal`:case`try_catch`:return zS.signal;case`subflow`:case`flow`:return zS.subflow;case`approval`:return zS.approval;case`loop`:case`for_each`:case`map`:return zS.loop;case`screen`:case`user_task`:return zS.screen;case`assignment`:return zS.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return zS.record;case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return zS.integration;default:return zS.task}}function VS({type:e,className:t}){return X.createElement(RS(e),{className:t,"aria-hidden":!0})}var HS=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function US(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`map`: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 WS=[{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 GS(e){let t=WS.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function KS(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 qS({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,onPointerDown:c,onSelect:l,onAppend:u}){let d=BS(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:q(`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:q(`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)(VS,{type:e,className:q(`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:q(`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:q(`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)(No,{className:`h-3.5 w-3.5`})})]})}function JS({items:e=WS,onPick:t,onClose:n}){let r=X.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??US(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return HS.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),i=e=>{let n=BS(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:q(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,Z.jsx)(VS,{type:e.type,className:q(`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:q(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 YS(){return`${``.replace(/\/$/,``)}/api/v1`}function XS(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??US(e.type)})}return[...n.values()]}function ZS(){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(`${YS()}/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 QS(){let e=ZS();return(0,X.useMemo)(()=>e.length?XS(WS,e):WS,[e])}function $S(){let e=ZS();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 eC=.4,tC=1.6,nC=4;function rC({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=QS(),[x,S]=X.useState(null),C=X.useRef(null),w=X.useRef(null),T=X.useMemo(()=>AS(e,t),[e,t]),E=X.useMemo(()=>jS(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:zs(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,f]),M=X.useCallback((n,r)=>{if(!f)return;let i=xs(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:GS(n),o=r?.at,s={id:i,type:n,label:a,...KS(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:ys(e,s)};r?.from&&(c.edges=ys(t,{id:xs(`edge`,t.map(e=>e.id).filter(Boolean)),source:r.from,target:i})),f(c),u(s),y(!1)},[t,e,f,u,A]),ee=X.useCallback((n,r=`create_record`)=>{if(!f)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=xs(`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:GS(r),...KS(r),ui:{x:c.x,y:c.y}},d={...n,target:a},p={id:xs(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},m=zs(t,i,d);f({nodes:ys(e,l),edges:ys(m,p)}),u(l)},[t,e,f,u,A]),N=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]),P=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]),te=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)<nC||(t.moved=!0,S({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[m]),ne=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]),F=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]),re=X.useCallback(e=>{let t=w.current;t&&_({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),ie=X.useCallback(e=>{w.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),w.current=null},[]),ae=e=>Math.min(tC,Math.max(eC,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]),I=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(),N(i)}},[N,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)(No,{className:`h-3.5 w-3.5`}),Y(`engine.inspector.add.node`,o)]}),v&&(0,Z.jsx)(JS,{locale:o,items:b,onClose:()=>y(!1),onPick:e=>M(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)(Ei,{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)(Fr,{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)(Gr,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsx)(`div`,{ref:p,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:I,onPointerDown:F,onPointerMove:e=>{re(e),te(e)},onPointerUp:e=>{ie(e),ne(e)},className:q(`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=MS(x?.id===e.source?A(e.source):i),c=NS(x?.id===e.target?A(e.target):o),l=FS(s,c),u=LS(e.condition),f=e.isDefault?`else`:u?`if ${u}`:e.label,p=IS(e,t),m=O.has(p),h=a===p,g=PS(s,c),_=r&&!!d;return(0,Z.jsxs)(`g`,{children:[(0,Z.jsx)(`path`,{d:g,strokeLinecap:`round`,className:q(`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:q(_&&`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:q(`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(),ee(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)(No,{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)(qS,{id:e.id,type:e.type,label:e.label||e.id,summary:iC(e),position:A(e.id),selected:i===e.id,editable:n,runState:t,dimmed:k&&!t,onPointerDown:P(e.id),onSelect:()=>r&&u(e),onAppend:()=>M(`create_record`,{from:e.id})},e.id)})]})})]})}function iC(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 aC=e=>typeof e==`string`?e:void 0;function oC(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new V({...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 sC(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=>aC(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 cC=500,lC=new Set([`start`,`assignment`]),uC=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),dC=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),fC=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,pC=e=>typeof e==`string`?e:void 0,mC=e=>typeof e==`string`&&e?e:void 0,hC=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=sC([...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>=cC)return e.status=`error`,e.error=`Step limit (${cC}) 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(dC.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(uC.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:lC.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=pC(e.condition);if(!t){n.push({edgeId:fC(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=oC(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:fC(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:fC(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=mC(e.config?.collection),n=mC(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=mC(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=mC(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=fC(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 gC(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 _C=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function vC(e){let t=[];for(let n of e){if(!_C.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 yC={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 bC({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(()=>vC(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:gC(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=gC(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]=gC(n));return e},[h]),b=X.useCallback(()=>{let n=new hC(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)(or,{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)(Mn,{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)(Fi,{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)(ct,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Z.jsx)(`span`,{className:q(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,yC[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)(ci,{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)(_t,{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)(No,{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)(zn,{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:q(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,yC[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:q(`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:q(`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 xC(e,t){try{let n=await fetch(`${YS()}/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 SC={completed:{icon:aa,cls:`text-emerald-600 dark:text-emerald-400`,label:`Completed`},failed:{icon:ci,cls:`text-rose-600 dark:text-rose-400`,label:`Failed`},paused:{icon:Ka,cls:`text-amber-600 dark:text-amber-400`,label:`Paused`},running:{icon:H,cls:`text-sky-600 dark:text-sky-400`,label:`Running`},cancelled:{icon:ta,cls:`text-muted-foreground`,label:`Cancelled`}};function CC(e){return SC[e]??{icon:gr,cls:`text-muted-foreground`,label:e}}function wC(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function TC(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function EC({step:e}){return(0,Z.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,children:[(0,Z.jsx)(`span`,{className:q(`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}),TC(e.durationMs)&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:TC(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 DC({run:e}){let[t,n]=X.useState(!1),r=CC(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)(Ir,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Z.jsx)(Fi,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Z.jsx)(i,{className:q(`h-3.5 w-3.5 shrink-0`,r.cls,e.status===`running`&&`animate-spin`)}),(0,Z.jsx)(`span`,{className:q(`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:wC(e.startedAt)}),TC(e.durationMs)&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:TC(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)(EC,{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 xC(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)(gr,{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)(Ui,{className:q(`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)(DC,{run:e},e.id))})]})}function kC({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:xs(`node`,s.map(e=>e.id).filter(Boolean)),type:`start`,label:`Start`};i({nodes:ys(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)(Kb,{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)(No,{className:`h-3 w-3`}),Y(`engine.inspector.add.node`,a)]})}):(0,Z.jsx)(qb,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Z.jsx)(Kb,{hint:`flow · ${s.length} node${s.length===1?``:`s`}`,children:(0,Z.jsx)(Yb,{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)(AC,{icon:fo,label:`Trigger`,value:w}),(0,Z.jsx)(AC,{icon:ni,label:`Status`,value:T,tone:T===`active`?`green`:T===`draft`?`gray`:`amber`}),(0,Z.jsx)(AC,{icon:Mr,label:`Run as`,value:E}),D&&(0,Z.jsx)(AC,{label:`v`,value:D}),O&&(0,Z.jsx)(AC,{icon:Ri,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)(Er,{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)(vr,{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)(Ki,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Z.jsx)(rC,{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)(bC,{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)(lt,{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 AC({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 jC({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)(Kb,{hint:`agent`,children:(0,Z.jsx)(qb,{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)(Kb,{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)(Xi,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Yb,{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)(Nt,{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)(BC,{icon:c?nt:vn,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Z.jsx)(BC,{icon:st,label:l}),u.provider&&(0,Z.jsx)(BC,{icon:ya,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Z.jsx)(BC,{icon:Hr,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Z.jsx)(BC,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Z.jsx)(NC,{title:`Instructions`,icon:Kr,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)(PC,{children:`No system prompt set yet.`})}),(0,Z.jsx)(NC,{title:`Capabilities`,icon:Co,children:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(IC,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:ya,tone:`violet`,mono:!0}),(0,Z.jsx)(IC,{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:Co,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Z.jsx)(NC,{title:`Knowledge (RAG)`,icon:Zt,children:(0,Z.jsx)(MC,{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)(LC,{icon:pn,title:`Planning`,children:(0,Z.jsx)(RC,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Z.jsx)(LC,{icon:ma,title:`Memory`,children:(0,Z.jsx)(RC,{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)(LC,{icon:_i,title:`Guardrails`,children:(0,Z.jsx)(RC,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Z.jsx)(LC,{icon:st,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 MC({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)(Zt,{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 NC({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 PC({children:e}){return(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var FC={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 IC({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?FC[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:q(`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:q(`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 LC({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 RC({data:e,keys:t}){let n=t.map(t=>[t,zC(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 zC(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function BC({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 VC(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function HC(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${HC(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function UC(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 WC({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=VC(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]=UC(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=UC(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Z.jsx)(Kb,{hint:`tool`,children:(0,Z.jsx)(qb,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Z.jsx)(Kb,{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)(Xi,{className:`h-3 w-3`})]}),children:(0,Z.jsx)(Yb,{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)(Co,{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)(JC,{icon:Pa,label:o}),s&&(0,Z.jsx)(JC,{icon:Zt,label:s,mono:!0}),(0,Z.jsx)(JC,{icon:Yt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Z.jsx)(JC,{icon:_t,label:`Requires confirmation`,tone:`amber`}),u&&(0,Z.jsx)(JC,{label:`built-in`})]})]})]}),a&&(0,Z.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Z.jsx)(KC,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Z.jsx)(qC,{children:`This tool takes no input parameters.`}):(0,Z.jsx)(GC,{props:p,required:m})}),Object.keys(p).length>0&&(0,Z.jsx)(KC,{title:`Example LLM Call`,icon:Xn,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
+ }`})}),VC(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Z.jsx)(KC,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:vt,children:(0,Z.jsx)(GC,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function GC({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)(aa,{className:`h-3 w-3 text-emerald-600`}):(0,Z.jsx)(Fi,{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:HC(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 KC({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 qC({children:e}){return(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function JC({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 YC=[{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 XC(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 ZC({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(()=>XC(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)(Kb,{hint:`permission`,children:(0,Z.jsx)(qb,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Z.jsx)(Kb,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Z.jsx)(Yb,{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)(Pe,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Z.jsx)(Ea,{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)(tw,{icon:Jt,label:`${d.length} objects`}),(0,Z.jsx)(tw,{icon:Pa,label:`${c.length} system perms`}),(0,Z.jsx)(tw,{icon:nt,label:`${Object.keys(l).length} tabs`}),(0,Z.jsx)(tw,{icon:st,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Z.jsxs)(ew,{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`}),YC.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}),YC.map(e=>(0,Z.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Z.jsx)(QC,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Z.jsx)($C,{})]}),p.size>0&&(0,Z.jsx)(ew,{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)(ew,{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)(ew,{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)(_t,{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 QC({granted:e,danger:t}){return e?(0,Z.jsx)(aa,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Z.jsx)(mi,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function $C(){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)(aa,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(aa,{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)(mi,{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 ew({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 tw({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 nw(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 rw(e){switch(e){case`url`:return en;case`modal`:return pt;case`flow`:return Kn;case`api`:return Za;case`form`:return Vt;default:return Ut}}function iw(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 aw(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 ow({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=nw(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=nw(n.confirmText),g=nw(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=rw(o),w=l===`action:icon`;return!r&&!i?(0,Z.jsx)(Kb,{hint:`action`,children:(0,Z.jsx)(qb,{children:`Set name and label to see the action preview.`})}):(0,Z.jsx)(Kb,{hint:`action`,children:(0,Z.jsx)(Yb,{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)(sw,{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)(mw,{icon:C,label:`type: ${o}`}),b&&(0,Z.jsx)(mw,{icon:Xa,label:`object: ${b}`,mono:!0}),c&&(0,Z.jsx)(mw,{label:`variant: ${c}`}),l&&(0,Z.jsx)(mw,{icon:Be,label:l}),d&&(0,Z.jsx)(mw,{icon:Mo,label:d,mono:!0}),f&&(0,Z.jsx)(mw,{icon:xo,label:`bulk`,tone:`green`}),p&&(0,Z.jsx)(mw,{icon:Ui,label:`refresh after`}),m===!1&&(0,Z.jsx)(mw,{icon:Nt,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Z.jsx)(mw,{icon:ya,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)(fw,{label:`Visible when`,value:x,icon:nt}),S!=null&&typeof S!=`boolean`&&(0,Z.jsx)(fw,{label:`Disabled when`,value:S,icon:st})]}),(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:aw(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)(_t,{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)(pw,{title:`Input Dialog`,count:_.length,children:(0,Z.jsx)(lw,{title:i,params:_,variant:c})}),v&&(0,Z.jsx)(pw,{title:`Result Dialog`,icon:nt,children:(0,Z.jsx)(dw,{dialog:v})}),y?.source&&(0,Z.jsx)(pw,{title:`Script Body (${y.language??`expression`})`,icon:Ut,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 sw({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 ${iw(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Z.jsx)(cw,{name:t}),!r&&(0,Z.jsx)(`span`,{children:e})]})}function cw({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=Pi[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 lw({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:[nw(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})]}),uw(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 ${iw(n||`primary`)}`,children:`OK`})]})]})}function uw(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:nw(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 dw({dialog:e}){let t=nw(e.title)||`Result`,n=nw(e.description),r=nw(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:nw(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 fw({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 pw({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 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`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var hw={"@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 gw(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 _w(e){let t=(hw[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=gw(n,0,59),c=gw(r,0,23),l=gw(i,1,31),u=gw(a,1,12),d=gw(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function vw(e,t,n){let r=_w(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 yw(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 bw(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function xw(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Sw(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?Cw(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`?Cw(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function Cw(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 ww({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}=Sw(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?yw(s):null,{nextFires:v,deltas:y}=X.useMemo(()=>{let e=new Date,t=[];if(o)t=vw(o,e,5);else if(_)t=bw(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Tw(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Z.jsx)(Kb,{hint:`job`,children:(0,Z.jsx)(qb,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Z.jsx)(Kb,{hint:`job`,children:(0,Z.jsx)(Yb,{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)(Ya,{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:Yt,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Z.jsx)(Ow,{icon:rn,label:l,mono:!0}),p!=null&&(0,Z.jsx)(Ow,{icon:ct,label:`retries: ${p}${m?` (${Cw(m)} backoff)`:``}`}),h!=null&&(0,Z.jsx)(Ow,{icon:sr,label:`timeout: ${Cw(h)}`}),g!=null&&(0,Z.jsx)(Ow,{label:`concurrency: ${g}`})]})]})]})}),(0,Z.jsx)(Dw,{title:`Schedule`,icon:it,children:(0,Z.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Z.jsx)(Ew,{label:`Cron`,children:(0,Z.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Z.jsxs)(Ew,{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)(Ew,{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)(Dw,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:gr,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)(gr,{className:`h-3 w-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:xw(e)}),(0,Z.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Z.jsx)(Dw,{title:`Handler`,icon:Ut,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)(Ca,{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 Tw(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 Ew({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 Dw({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 kw=[{key:`objects`,label:`Objects`,icon:Hi,flat:!1},{key:`apps`,label:`Apps`,icon:ui,flat:!1},{key:`messages`,label:`Messages`,icon:so,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:ca,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Ne,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:kt,flat:!1},{key:`settings`,label:`Settings`,icon:Mr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:uo,flat:!1}];function Aw({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=kw.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/kw.length*100);return c===0?(0,Z.jsx)(Kb,{hint:`translation · ${r}`,children:(0,Z.jsx)(qb,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Z.jsx)(Kb,{hint:`translation · ${r} · ${c} keys`,children:(0,Z.jsx)(Yb,{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)(Fn,{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)(rn,{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)(Hr,{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,`/`,kw.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)(jw,{cat:e},e.key))})]})})})}function jw({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:Mw(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 Mw(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Nw({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)(Kb,{hint:`role`,children:(0,Z.jsx)(Yb,{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)(rt,{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)(Aa,{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)(Ke,{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)(Ea,{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)(Kb,{hint:`role`,children:(0,Z.jsx)(qb,{children:`Give the role a name to see the preview.`})})}function Pw({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)(Kb,{hint:`skill`,children:(0,Z.jsx)(Yb,{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)(ya,{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)(Iw,{icon:Yt,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Z.jsx)(Iw,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Z.jsx)(Iw,{icon:Ea,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Z.jsx)(Fw,{title:`Instructions`,icon:Bn,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)(Fw,{title:`Tools (${s.length})`,icon:Co,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)(Ct,{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)(Fw,{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)(Fw,{title:`Trigger Conditions (${l.length})`,icon:Wa,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)(Fw,{title:`Required Permissions`,icon:Ea,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)(Kb,{hint:`skill`,children:(0,Z.jsx)(qb,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Fw({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 Iw({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 Lw=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Rw=E();function zw(){return``.replace(/\/+$/,``)}function Bw(e){return`${zw()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function Vw(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 Lw}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 Hw(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await Vw(await Rw(`${Bw(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Uw(e,t,n={}){return(await Vw(await Rw(`${Bw(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Ww(e){return(await Vw(await Rw(`${Bw(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Gw(e){return Vw(await Rw(`${Bw(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Kw(e){await Vw(await Rw(`${zw()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function qw({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 Uw(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof Lw?`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 Kw(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)(ht,{open:n,onOpenChange:r,children:(0,Z.jsxs)(At,{className:`max-w-2xl`,children:[(0,Z.jsxs)(Po,{children:[(0,Z.jsxs)(Ge,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Zt,{className:`h-4 w-4`}),`Import as Object`]}),(0,Z.jsxs)(Xt,{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)(H,{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)(aa,{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)(_t,{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)(_o,{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)(Ln,{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)(H,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Jw({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 Hw(e)),n(`loaded`)}catch(e){e instanceof Lw?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)(Yw,{}):(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)(Oo,{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)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Ui,{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)(H,{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)(Sr,{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)(fr,{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)(dn,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Z.jsx)(qw,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Yw(){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 Xw={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 Zw({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 Gw(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof Lw?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)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Ca,{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)(aa,{className:`h-4 w-4`}):(0,Z.jsx)(ca,{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)(Qw,{result:e},e.object))})]})}function Qw({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)(Ea,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Z.jsx)(ca,{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)($w,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function $w({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:Xw[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 eT({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 Ww(e))}catch(e){c(e instanceof Lw?`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)(Rn,{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)(gr,{className:`h-3 w-3`}),`snapshot `,tT(r.snapshotAt)]}),(0,Z.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Z.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Ui,{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)(hi,{defaultValue:`tables`,className:`p-3`,children:[(0,Z.jsxs)(_a,{children:[(0,Z.jsx)(Va,{value:`tables`,children:`Tables`}),(0,Z.jsx)(Va,{value:`validation`,children:`Validation`})]}),(0,Z.jsx)($a,{value:`tables`,className:`mt-3`,children:(0,Z.jsx)(Jw,{datasource:e})}),(0,Z.jsx)($a,{value:`validation`,className:`mt-3`,children:(0,Z.jsx)(Zw,{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 tT(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var nT=/pass|secret|key|token|credential|auth/i;function rT(e){return nT.test(e)}function iT(e){return e==null||e===``?`∅`:`••••••`}function aT(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 oT({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)(Kb,{hint:`datasource`,children:(0,Z.jsx)(qb,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Z.jsx)(Kb,{hint:`datasource · ${o}`,children:(0,Z.jsx)(Yb,{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)(Zt,{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)(Tr,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Z.jsx)(lT,{icon:Yt,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Z.jsx)(lT,{icon:Pe,label:`default`,tone:`amber`}),m.length>0&&(0,Z.jsx)(lT,{icon:Tt,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Z.jsx)(eT,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Z.jsx)(cT,{title:`Connection`,icon:st,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=rT(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:iT(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`})]}):aT(t)})]},e)})})})})}),(0,Z.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Z.jsx)(sT,{title:`Pool`,icon:ma,value:u}),(0,Z.jsx)(sT,{title:`SSL`,icon:Ea,value:typeof d==`boolean`?{enabled:d}:d}),(0,Z.jsx)(sT,{title:`Retry Policy`,icon:ct,value:f}),(0,Z.jsx)(sT,{title:`Health Check`,icon:ma,value:p})]}),h.length>0&&(0,Z.jsx)(cT,{title:`Capabilities`,icon:Ea,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 sT({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:rT(e)?iT(t):aT(t)})]},e))}):(0,Z.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function cT({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 lT({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 uT(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function dT(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:va};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:_t};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:er}}}function fT({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=dT(l);return r?(0,Z.jsx)(Kb,{hint:`validation · ${o}`,children:(0,Z.jsx)(Yb,{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)(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:`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)(gT,{icon:Yt,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Z.jsx)(gT,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Z.jsx)(gT,{label:`priority ${f}`}),d.length>0&&(0,Z.jsx)(gT,{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)(pT,{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)(Kb,{hint:`validation`,children:(0,Z.jsx)(qb,{children:`Give the validation a name to see the preview.`})})}function pT({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Z.jsx)(hT,{title:`Condition`,icon:Ut,children:(0,Z.jsx)(mT,{value:uT(t.condition)??uT(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=uT(t.scope)??uT(t.where);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(hT,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:ua,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)(hT,{title:`Scope`,icon:to,children:(0,Z.jsx)(mT,{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)(hT,{title:`Transitions${r?` on ${r}`:``}`,icon:Kn,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)(Cr,{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)(hT,{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=uT(t.condition);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(hT,{title:`Fields involved`,icon:to,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)(hT,{title:`Cross-field condition`,icon:Ut,children:(0,Z.jsx)(mT,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Z.jsx)(hT,{title:`Async endpoint`,icon:rn,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)(hT,{title:`Custom handler`,icon:Ut,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)(hT,{title:`Rule`,icon:ca,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 mT({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 hT({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 gT({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 _T=X.lazy(()=>d(()=>import(`./plugin-charts-QabQJ_NJ.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function vT(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 yT({draft:e}){let t=ye(),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)(Kb,{children:(0,Z.jsx)(Jb,{icon:(0,Z.jsx)(Qn,{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)(Kb,{children:(0,Z.jsx)(Jb,{icon:(0,Z.jsx)(Qn,{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)(Kb,{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)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Qn,{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)(_t,{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)(Jb,{icon:(0,Z.jsx)(Qn,{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)(Yb,{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)(H,{className:`h-4 w-4 animate-spin`})}),children:(0,Z.jsx)(`div`,{className:`rounded-md border p-2`,children:(0,Z.jsx)(_T,{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:vT(e[t])},t))},t))})]})})]})})}function bT(){Wy(`page`,Nx),Wy(`view`,Rx),Wy(`dashboard`,Bx),Wy(`report`,Ux),Wy(`app`,nS),Wy(`action`,ow),Wy(`object`,CS),Wy(`datasource`,oT),Wy(`validation`,fT),Wy(`dataset`,yT),Wy(`email_template`,DS),Wy(`translation`,Aw),Wy(`flow`,kC),Wy(`job`,ww),Wy(`agent`,jC),Wy(`tool`,WC),Wy(`skill`,Pw),Wy(`permission`,ZC),Wy(`profile`,ZC),Wy(`role`,Nw)}function Q(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function xT(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var ST=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),CT={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`})],map:[Q(`collection`,`Collection`,`expression`,{placeholder:`{items}`,help:`Expression resolving to the array to process, one item at a time.`}),Q(`flowName`,`Per-item flow`,`reference`,{ref:{kind:`flow`},placeholder:`one_task_signoff`,help:`Subflow run for each item — it may pause (e.g. an approval).`}),Q(`iteratorVariable`,`Item variable`,`text`,{placeholder:`item`}),Q(`itemObject`,`Item object`,`reference`,{ref:{kind:`object`},placeholder:`showcase_task`,help:`When items are records, the object they belong to (exposes each item as the child’s record).`}),Q(`outputVariable`,`Output variable`,`text`,{placeholder:`results`,help:`Each item’s subflow output, collected in order.`})],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:ST,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:[xT(`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`}),xT(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]}}),xT(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]}}),xT(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`}),xT(`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:[xT(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),xT(`connectorConfig`,`actionId`,`Action`,`text`,{placeholder:`sendMessage · send`}),xT(`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:[xT(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),xT(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),xT(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),xT(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),xT(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),xT(`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`})]},wT={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 TT(e){return e?CT[wT[e]??e]??[]:[]}function ET(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 DT(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=ET(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=ET(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 kT=[`start`,`create_record`,`update_record`,`delete_record`,`get_record`,`decision`,`assignment`,`loop`,`http_request`,`script`,`screen`,`approval`,`wait`,`subflow`,`map`,`connector_action`,`parallel`,`try_catch`,`end`],AT=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function jT(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`&&AT.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&AT.has(t.kind))return{kind:t.kind,...n}}function MT(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 NT(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function PT(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 FT(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:MT(e)}))}function IT(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 LT(e){if(Array.isArray(e.enum))return`select`;let t=PT(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function RT(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!NT(r))continue;let t=PT(r),i,a,o=jT(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=FT(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||MT(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function zT(e,t){return{label:e.title||MT(t),...e.description?{help:e.description}:{},...IT(e)?{defaultValue:IT(e)}:{}}}function BT(e){if(!NT(e)||PT(e)!==`object`||!NT(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!NT(r))continue;let e=PT(r);if(e===`array`){let e=NT(r.items)?r.items:void 0,i=e?PT(e):void 0;e&&i===`object`&&NT(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:RT(e),...zT(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...zT(r,n)});continue}if(e===`object`&&NT(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>NT(e)),i=e.some(([e,t])=>e===`enabled`&&PT(t)===`boolean`);for(let[a,o]of e){let e=o,s=jT(e),c=s?`reference`:LT(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||MT(n),...r.description?{help:r.description}:{},...IT(e)?{defaultValue:IT(e)}:{}}:zT(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:FT(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=jT(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...zT(r,n)});continue}let a=LT(r);a&&t.push({id:n,path:[`config`,n],kind:a,...zT(r,n),...a===`select`&&Array.isArray(r.enum)?{options:FT(r.enum)}:{}})}return t}function VT(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function HT(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function UT(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 WT(e,t){let n=[...t];return Object.entries(e).map(([e,t])=>{let r=xs(`kv`,n);return n.push(r),{id:r,key:e,raw:HT(t)}})}function GT(e){let t={};for(let n of e){let e=n.key.trim();!e||e in t||(t[e]=UT(n.raw))}return t}function KT(e){let t=Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{});return JSON.stringify(t)}function qT({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l}){let u=VT(t)?t:{},[d,f]=X.useState(()=>WT(u,[])),p=X.useRef(KT(u));X.useEffect(()=>{let e=KT(u);e!==p.current&&(f(WT(u,[])),p.current=e)},[u]);let m=e=>{let t=GT(e);p.current=KT(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:xs(`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)(Jr,{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)(No,{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 JT(e,t){let n=[...t];return e.map(e=>{let t=xs(`sl`,n);return n.push(t),{id:t,value:e}})}function YT(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function XT({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(()=>JT(c,[])),d=X.useRef(JSON.stringify(c));X.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(JT(c,[])),d.current=e)},[c]);let f=e=>{let t=YT(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:xs(`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)(Jr,{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)(No,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var ZT={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function QT(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 $T(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 eE(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?$T((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):$T(n.node,r)}function tE(e){let t=_s(),[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 nE({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?eE(e.kind,e.objectSource,l):void 0,{fields:f}=hd(u===`object-field`?d:void 0),p=u&&u!==`object-field`&&u!==`node`?ZT[u]:void 0,{options:m}=tE(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 rE({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=QT(e.ref,e=>$T(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)(nE,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function iE(e,t){let n=[];return e.map(e=>{let r=xs(`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 aE(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 oE({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(()=>iE(l,t)),f=X.useRef(JSON.stringify(l));X.useEffect(()=>{let e=JSON.stringify(l);e!==f.current&&(d(iE(l,t)),f.current=e)},[l,t]);let p=e=>{let n=aE(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:xs(`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)(Jr,{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)(dr,{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)(nE,{resolved:QT(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)(No,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var sE=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function cE(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 lE(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.`};cE(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=sE.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=sE.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\`).`}:cE(n,`(`,`)`)?cE(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function uE({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a}){let o=(()=>{switch(e.kind){case`reference`:return(0,Z.jsx)(rE,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Z.jsx)(qT,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:Y(`engine.inspector.flowNode.kv.add`,i),keyLabel:Y(`engine.inspector.flowNode.kv.key`,i),valueLabel:Y(`engine.inspector.flowNode.kv.value`,i),removeLabel:Y(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:Y(`engine.inspector.flowNode.kv.empty`,i)});case`stringList`:return(0,Z.jsx)(XT,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:Y(`engine.inspector.flowNode.list.add`,i),itemLabel:Y(`engine.inspector.flowNode.list.item`,i),removeLabel:Y(`engine.inspector.flowNode.list.remove`,i),emptyLabel:Y(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Z.jsx)(oE,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:Y(`engine.inspector.flowNode.list.add`,i),removeLabel:Y(`engine.inspector.flowNode.list.remove`,i),emptyLabel:Y(`engine.inspector.flowNode.list.empty`,i),context:a});case`number`:return(0,Z.jsx)(Cs,{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)(Ds,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Z.jsx)(Os,{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)(Ts,{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`?lE(`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 dE(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function fE(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=fE(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function pE({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=$S(),u=X.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:BT(e))??TT(c?.type)},[l,c?.type]),d=dE(c),f=u.filter(e=>OT(e,c,u)),p=X.useMemo(()=>{let e=new Set;for(let t of u){let n=DT(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)(Es,{kindLabel:Y(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:Y(`engine.inspector.flowNode.close`,i),children:(0,Z.jsx)(Fs,{message:e.id})});let C=e=>{n({nodes:zs(o,s,{...c,...e})})},w=m.trim()!==``,T=(e,t)=>{n({nodes:zs(o,s,fE(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:zs(o,s,a)})}catch(e){v(String(e.message))}},D=()=>{n({nodes:zs(o,s,null)}),r()},O=kT.includes(c.type)?[...kT]:[...kT,c.type??``].filter(Boolean);return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:Y(`engine.inspector.flowNode.close`,i),footer:(0,Z.jsx)(ws,{label:Y(`engine.inspector.flowNode.remove`,i),onClick:D,disabled:a}),children:[(0,Z.jsx)(Ts,{label:Y(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>C({id:e}),disabled:a,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>C({label:e}),disabled:a}),(0,Z.jsx)(Os,{label:Y(`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)(Ts,{label:Y(`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:Y(`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:Y(`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)(uE,{field:e,value:ET(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:Y(`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:Y(`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)(No,{className:`h-3 w-3`}),Y(`engine.inspector.flowNode.advanced`,i)]})]})}function mE({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 hE({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)=>IS(t,n)===e.id),c=s>=0?o[s]:null;if(!c)return(0,Z.jsx)(Es,{kindLabel:Y(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:Y(`engine.inspector.flowEdge.close`,i),children:(0,Z.jsx)(Fs,{message:Y(`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:zs(o,s,t)})},u=c.isDefault===!0;return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:Y(`engine.inspector.flowEdge.close`,i),footer:(0,Z.jsx)(ws,{label:Y(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:zs(o,s,null)}),r()},disabled:a}),children:[(0,Z.jsx)(mE,{label:Y(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Z.jsx)(mE,{label:Y(`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:Y(`engine.inspector.flowEdge.routing`,i)}),(0,Z.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>l({label:e}),placeholder:Y(`engine.inspector.flowEdge.labelHint`,i),disabled:a||u}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.flowEdge.condition`,i),value:LS(c.condition)??``,onCommit:e=>l({condition:e||void 0}),placeholder:Y(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||u,mono:!0}),(()=>{let e=u?null:lE(`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)(Ds,{label:Y(`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:Y(`engine.inspector.flowEdge.hint`,i)})]})}function gE(e){return e.selection.kind===`edge`?(0,Z.jsx)(hE,{...e}):(0,Z.jsx)(pE,{...e})}var _E=[`object`,`page`,`dashboard`,`report`,`link`,`group`];function vE(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 yE(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 bE(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:zs(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=zs(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function xE(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 SE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=vE(e.id),{node:c,parent:l,index:u}=s?yE(t,s):{node:null,parent:[],index:-1};if(!s||!c)return(0,Z.jsx)(Es,{kindLabel:Y(`engine.inspector.appNav.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Y(`engine.inspector.appNav.close`,a),children:(0,Z.jsx)(Fs,{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(bE(t,s,{...c,...e}))};return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.appNav.kind`,a),title:String(d),onClose:r,closeLabel:Y(`engine.inspector.appNav.close`,a),headerActions:(0,Z.jsx)(js,{index:u,total:l.length,onMove:e=>{n(xE(t,s,Is(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:Y(`engine.inspector.reorder.up`,a),downLabel:Y(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Z.jsx)(ws,{label:Y(`engine.inspector.appNav.remove`,a),onClick:()=>{n(bE(t,s,null)),r()},disabled:o}),children:[(0,Z.jsx)(Ts,{label:Y(`engine.inspector.appNav.label`,a),value:String(c.label??c.title??c.name??``),onCommit:e=>p({label:e}),disabled:o}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.appNav.path`,a),value:String(f),onCommit:e=>p({path:e}),disabled:o,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.appNav.icon`,a),value:String(c.icon??``),onCommit:e=>p({icon:e}),disabled:o}),(0,Z.jsx)(Os,{label:Y(`engine.inspector.appNav.kindField`,a),value:c.kind,options:_E.map(e=>({value:e,label:e})),onCommit:e=>p({kind:e}),disabled:o})]})}var CE=[`field`,`label`,`accessorKey`,`header`];function wE(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function TE(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function EE(e){return e.field??e.accessorKey??``}function DE(e){return e.label??e.header??EE(e)}function OE(e){return Object.keys(e).some(e=>!CE.includes(e))}function kE(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function AE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=wE(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(TE),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=X.useMemo(()=>Kd(),[]),m=kE(c),{fields:h}=hd(m||void 0),g=d?EE(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)(Es,{kindLabel:Y(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:Y(`engine.inspector.viewColumn.close`,a),children:(0,Z.jsx)(Fs,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=EE(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(zs(u,s.index,{...d,...r}))};return(0,Z.jsxs)(Es,{kindLabel:Y(`engine.inspector.viewColumn.kind`,a),title:DE(d)||e.id,onClose:r,closeLabel:Y(`engine.inspector.viewColumn.close`,a),headerActions:(0,Z.jsx)(js,{index:s.index,total:u.length,onMove:e=>{v(Is(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:DE(d)||`columns[${e}]`})},upLabel:Y(`engine.inspector.reorder.up`,a),downLabel:Y(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Z.jsx)(ws,{label:Y(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(zs(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Z.jsx)(`div`,{className:`pb-1`,children:(0,Z.jsx)(Id,{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)(Os,{label:Y(`engine.inspector.viewColumn.accessorKey`,a),value:EE(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Z.jsx)(Ts,{label:Y(`engine.inspector.viewColumn.accessorKey`,a),value:EE(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Z.jsx)(Ts,{label:Y(`engine.inspector.viewColumn.header`,a),value:DE(d)===EE(d)?``:DE(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Z.jsx)(`div`,{className:`border-t pt-3`,children:(0,Z.jsx)(ks,{schema:p,value:d,hiddenFields:CE,readOnly:o,onChange:e=>{v(zs(u,s.index,e))}})}):null]})]})}function jE(e){let{selection:t}=e;if(t.kind===`column`)return(0,Z.jsx)(AE,{...e});let n=tf(e.draft,t.id||void 0)??ef(e.draft);return(0,Z.jsx)(lf,{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 ME(e){let t=ef(e.draft);return(0,Z.jsx)(lf,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var NE=e=>(e??``).toLowerCase().startsWith(`zh`);function PE(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 FE(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function IE(e){return e===`lookup`||e===`master_detail`||e===`tree`}function LE(e){return e===`formula`||e===`summary`}function RE(e){return e===`number`||e===`currency`||e===`percent`}function zE(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function BE(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 VE(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?Sd:yd;return Cd.flatMap(e=>e.types.map(r=>{let i=_d[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function HE({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=X.useCallback(e=>Y(e,o),[o]),c=X.useMemo(()=>VE(o),[o]),l=X.useMemo(()=>Zu(t.fields),[t]),u=String(e.id),d=$u(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=JE();if(!f)return(0,Z.jsx)(Es,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Z.jsx)(Fs,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=_d[g],v=e=>{n({fields:Qu(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=nd(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:Is(l.entries,d,e)})},w=PE(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)(Tt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(js,{index:d,total:l.entries.length,onMove:C,disabled:a})]}),D=(0,Z.jsx)(ws,{label:bs(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:x,disabled:a}),O=NE(o)?_?.labelZh:_?.label;return(0,Z.jsxs)(Es,{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)(UE,{title:s(`designer.field.section.basic`),children:[(0,Z.jsx)(Ts,{label:s(`designer.field.apiName`),value:f.name,onCommit:b,disabled:a,mono:!0}),(0,Z.jsx)(Ts,{label:s(`designer.field.label`),value:typeof h.label==`string`?h.label:``,onCommit:e=>y({label:e}),disabled:a}),(0,Z.jsx)(Os,{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)(Ds,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,Z.jsx)(Ds,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,Z.jsx)(GE,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),BE(g)&&(0,Z.jsx)(WE,{kind:BE(g),value:h.defaultValue,options:w,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,Z.jsx)(GE,{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`)})]}),(FE(g)||IE(g)||LE(g)||RE(g)||zE(g))&&(0,Z.jsxs)(UE,{title:bs(`designer.field.section.options`,o,{type:O??g}),children:[FE(g)&&(0,Z.jsx)(qE,{options:w,onChange:T,disabled:a,locale:o}),IE(g)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(KE,{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)(Ts,{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`)})]}),LE(g)&&(0,Z.jsx)(GE,{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`}),RE(g)&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Cs,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,Z.jsx)(Cs,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,Z.jsx)(Cs,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,Z.jsx)(Cs,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),zE(g)&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Cs,{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)(Cs,{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)(UE,{title:s(`designer.field.section.advanced`),children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(Ds,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,Z.jsx)(Ds,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,Z.jsx)(Ds,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,Z.jsx)(Ds,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,Z.jsx)(Ds,{label:s(`designer.field.trackHistory`),value:!!h.trackHistory,onCommit:e=>y({trackHistory:e||void 0}),disabled:a})]}),(0,Z.jsx)(Ts,{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)(Ts,{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)(Os,{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 UE({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 WE({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=Y(`designer.field.defaultValue`,a),s=Y(`designer.field.defaultNone`,a);return e===`bool`?(0,Z.jsx)(Os,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:Y(`designer.field.true`,a)},{value:`false`,label:Y(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Z.jsx)(Cs,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Z.jsx)(Os,{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)(Ts,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function GE({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 KE({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 qE({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(Is(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:Y(`designer.field.picklistValues`,r)}),(0,Z.jsx)(U,{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:Y(`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:Y(`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:Y(`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:Y(`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":Y(`designer.field.moveUp`,r),children:(0,Z.jsx)(Gt,{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":Y(`designer.field.moveDown`,r),children:(0,Z.jsx)(Nn,{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":Y(`designer.field.removeValue`,r),children:(0,Z.jsx)(Jr,{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)(No,{className:`h-3 w-3`}),Y(`designer.field.addValue`,r)]})]})}function JE(){let e=_s(),[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 YE({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=X.useCallback(e=>Y(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=nd(e)),n(t)},u=e=>{c.current=!0,n({name:nd(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Z.jsx)(Es,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,Z.jsxs)(XE,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Z.jsx)(ZE,{hint:a(`designer.object.nameHint`),children:(0,Z.jsx)(Ts,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Z.jsx)(Ts,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Z.jsx)(Ts,{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)(ZE,{hint:a(`designer.object.iconHint`),children:(0,Z.jsx)(Ts,{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 XE({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 ZE({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 QE=[{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`}],$E=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}];function eD({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)(U,{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)(No,{className:`h-3 w-3`}),` `,r]})]})}function tD({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)(Es,{kindLabel:`Dataset`,title:String(r||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[(0,Z.jsx)(Ts,{label:`Label`,value:r,onCommit:e=>t({label:e}),disabled:n}),(0,Z.jsx)(Ts,{label:`Description`,value:i,onCommit:e=>t({description:e}),disabled:n}),(0,Z.jsx)(Ts,{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)(eD,{title:`Included relationships`,count:o.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:ys(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:zs(o,r,null)}),"aria-label":`Remove relationship`,children:(0,Z.jsx)(Jr,{className:`h-3.5 w-3.5`})})]},r))]}),(0,Z.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Z.jsx)(eD,{title:`Dimensions`,count:s.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:ys(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)(ws,{label:`Remove`,onClick:()=>t({dimensions:zs(s,r,null)})})]}),(0,Z.jsx)(Ts,{label:`Name`,value:e.name??``,onCommit:e=>l(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,Z.jsx)(Ts,{label:`Field`,value:e.field??``,onCommit:e=>l(r,{field:e}),placeholder:`field or relationship.field`,disabled:n,mono:!0}),(0,Z.jsx)(Os,{label:`Type`,value:e.type,options:$E,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)(eD,{title:`Measures`,count:c.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:ys(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)(ws,{label:`Remove`,onClick:()=>t({measures:zs(c,r,null)})})]}),(0,Z.jsx)(Ts,{label:`Name`,value:e.name??``,onCommit:e=>u(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,Z.jsx)(Os,{label:`Aggregate`,value:e.aggregate,options:QE,onCommit:e=>u(r,{aggregate:e}),disabled:n}),(0,Z.jsx)(Ts,{label:`Field`,value:e.field??``,onCommit:e=>u(r,{field:e}),placeholder:`field (optional for count)`,disabled:n,mono:!0}),(0,Z.jsx)(Ds,{label:`Certified`,value:!!e.certified,onCommit:e=>u(r,{certified:e}),disabled:n})]},r))]})]})}function nD(){qy(`dashboard`,ym),Xy(`dashboard`,mm),qy(`flow`,gE),qy(`app`,SE),qy(`view`,jE),Xy(`view`,ME),qy(`page`,yx),Xy(`report`,Jm),qy(`object`,HE),Xy(`object`,YE),Xy(`dataset`,tD)}var rD=t({MetadataDiagnosticsPage:()=>Ib,MetadataDirectoryPage:()=>yv,MetadataResourceEditPage:()=>Ab,MetadataResourceHistoryPage:()=>Iy,MetadataResourceListPage:()=>ny,StudioHomePage:()=>Bv});Vb(),Gb(),bT(),nD();function iD(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function aD(e){return!iD(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function oD(e){if(!iD(e))return;let t=e.config;if(iD(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`}pv({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:yv}),pv({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Pb}),pv({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:jv}),Zv({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`}]}),Zv({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`}]}),Zv({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:Rb,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`}]}),Zv({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)=>oD(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!aD(e)}),Zv({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`}]}),Zv({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 sD=`/api/v1/cloud-connection`;async function cD(e,t){let n=await fetch(e,{credentials:`same-origin`,headers:{"Content-Type":`application/json`},...t}),r=await n.json().catch(()=>({}));if(!n.ok&&r?.success!==!0){let e=r?.error?.message??r?.error?.code??r?.error??`HTTP ${n.status}`;throw Error(typeof e==`string`?e:JSON.stringify(e))}return r}function lD(){let[e,t]=(0,X.useState)({kind:`loading`}),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(!1),c=(0,X.useRef)(null),l=(0,X.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null)},[]),u=(0,X.useCallback)(async()=>{try{let e=(await cD(`${sD}/status`))?.data??{environmentId:null,bound:!1,connection:null};t(e.bound?{kind:`bound`,status:e}:{kind:`unbound`,environmentId:e.environmentId}),e.environmentId&&r(e.environmentId)}catch(e){t({kind:`error`,message:e?.message??String(e)})}},[]);(0,X.useEffect)(()=>(u(),l),[u,l]);let d=(0,X.useCallback)((e,n,r)=>{let i=Math.max(e.interval,2)*1e3,a=async()=>{if(Date.now()-r>e.expires_in*1e3){t({kind:`error`,message:`The code expired before it was approved. Start again.`});return}try{let r=await cD(`${sD}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:e.device_code,environment_id:n})});if(r?.data?.pending){c.current=setTimeout(a,i);return}if(r?.data?.bound||r?.success){await u();return}t({kind:`error`,message:r?.error?.code??`Binding failed.`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}};c.current=setTimeout(a,i)},[u]),f=(0,X.useCallback)(async e=>{a(!0);try{let n=(await cD(`${sD}/bind/start`,{method:`POST`,body:JSON.stringify(e?{environment_id:e}:{})}))?.data;if(!n?.device_code||!n?.user_code)throw Error(`Device code request failed.`);t({kind:`waiting`,code:n,environmentId:e}),d(n,e,Date.now())}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[d]),p=(0,X.useCallback)(async()=>{a(!0);try{await cD(`${sD}/unbind`,{method:`POST`,body:`{}`}),await u()}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[u]),m=(0,X.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}},[]);if(e.kind===`loading`)return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border p-6 text-sm text-muted-foreground`,children:[(0,Z.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` Checking connection…`]});if(e.kind===`error`)return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-destructive`,children:[(0,Z.jsx)(ci,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,e.message]}),(0,Z.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:`Try again`})]});if(e.kind===`waiting`){let t=e.code.verification_uri_complete??e.code.verification_uri;return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Waiting for approval in the cloud console…`]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`code`,{className:`rounded-md bg-muted px-4 py-2 text-2xl font-semibold tracking-[0.25em]`,children:e.code.user_code}),(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>void m(e.code.user_code),children:[(0,Z.jsx)(Tt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,o?`Copied`:`Copy`]})]}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Enter this code in the cloud console to approve the connection`,t?(0,Z.jsxs)(Z.Fragment,{children:[` `,`— or`,` `,(0,Z.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline`,href:t,target:`_blank`,rel:`noreferrer`,children:[`open the approval page `,(0,Z.jsx)(Xi,{className:`h-3 w-3`,"aria-hidden":`true`})]}),`.`]}):`.`]}),(0,Z.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:`Cancel`})]})}if(e.kind===`bound`){let t=e.status.connection??{};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(aa,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:`Connected to ObjectStack Cloud`})]}),(0,Z.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[t.organization_id?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Organization`}),(0,Z.jsx)(`dd`,{className:`font-mono`,children:t.organization_id})]}):null,t.account_email?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Approved by`}),(0,Z.jsx)(`dd`,{children:t.account_email})]}):null,e.status.environmentId?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Environment`}),(0,Z.jsx)(`dd`,{className:`font-mono`,children:e.status.environmentId})]}):null,t.bound_at?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Since`}),(0,Z.jsx)(`dd`,{children:new Date(t.bound_at).toLocaleString()})]}):null]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your organization's private packages now appear in the Marketplace under “Your organization”.`}),(0,Z.jsxs)(`button`,{type:`button`,disabled:i,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void p(),children:[(0,Z.jsx)(an,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` Disconnect`]})]})}let h=!e.environmentId;return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(xr,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:`Not connected`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connect this runtime to an ObjectStack control plane to browse your organization's private packages and install them here. Approval happens in the cloud console — no credentials are typed into this page.`}),h?(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Environment ID (create an environment in the cloud console and paste its id)`}),(0,Z.jsx)(`input`,{className:`w-full max-w-md rounded-md border bg-background px-3 py-2 font-mono text-sm`,placeholder:`e.g. 1764f947-6d1a-4b3e-82e4-9ca733f50a56`,value:n,onChange:e=>r(e.target.value)})]}):null,(0,Z.jsxs)(`button`,{type:`button`,disabled:i||h&&!n.trim(),className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void f((e.environmentId??n).trim()),children:[i?(0,Z.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Z.jsx)(Na,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}L.register(`cloud-connection:panel`,()=>(0,Z.jsx)(lD,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var uD={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`}]}},dD=()=>{let{modalHandler:e,modalElement:t}=Np();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:uD}),children:`Center`}),(0,Z.jsx)(K,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:uD}),children:`Side drawer`}),(0,Z.jsx)(K,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:uD}),children:`Bottom sheet`}),(0,Z.jsx)(K,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:uD}),children:`Fullscreen`})]}),t]})},fD=()=>{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)})]})},pD=(0,X.lazy)(()=>d(()=>import(`./SystemHubPage-Di6eqozE.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),mD=(0,X.lazy)(()=>d(()=>import(`./AppManagementPage-0JEALVYK.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),hD=(0,X.lazy)(()=>d(()=>import(`./ProfilePage-T27zVrMO.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),gD=(0,X.lazy)(()=>d(()=>import(`./ApprovalsInboxPage-B-drSsxQ.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),_D=(0,X.lazy)(()=>d(()=>import(`./AiPendingActionsPage-Y9r83gqj.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),vD=(0,X.lazy)(()=>d(()=>import(`./AuditLogPage-CXhNSVOU.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),yD=(0,X.lazy)(()=>d(()=>import(`./SettingsHub-B4oSx4ed.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),bD=(0,X.lazy)(()=>d(()=>import(`./SettingsView-CkQEI5DW.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),xD=(0,X.lazy)(()=>d(()=>import(`./DeveloperHubPage-D-UigRUA.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),SD=(0,X.lazy)(()=>d(()=>import(`./ApiConsolePage-Dwbms0Zh.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),CD=(0,X.lazy)(()=>d(()=>import(`./FlowRunsPage-_UeeNdBc.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),wD=(0,X.lazy)(()=>d(()=>import(`./PublicFormsPage-Pd453sW6.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),TD=(0,X.lazy)(()=>d(()=>import(`./IntegrationsPage-DsWyxKR6.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url));function ED(){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 DD(){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 OD=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(g,{path:`system`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(pD,{})})}),(0,Z.jsx)(g,{path:`system/apps`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(mD,{})})}),(0,Z.jsx)(g,{path:`system/profile`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(hD,{})})}),(0,Z.jsx)(g,{path:`system/approvals`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(gD,{})})}),(0,Z.jsx)(g,{path:`system/ai-approvals`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(_D,{})})}),(0,Z.jsx)(g,{path:`system/audit-log`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(vD,{})})}),(0,Z.jsx)(g,{path:`system/settings`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(yD,{})})}),(0,Z.jsx)(g,{path:`system/settings/:namespace`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(bD,{})})}),(0,Z.jsx)(g,{path:`developer`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(xD,{})})}),(0,Z.jsx)(g,{path:`developer/api-console`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(SD,{})})}),(0,Z.jsx)(g,{path:`developer/flow-runs`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(CD,{})})}),(0,Z.jsx)(g,{path:`developer/public-forms`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(wD,{})})}),(0,Z.jsx)(g,{path:`developer/integrations`,element:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(TD,{})})}),(0,Z.jsx)(g,{path:`system/objects`,element:(0,Z.jsx)(ED,{})}),(0,Z.jsx)(g,{path:`system/objects/:objectName`,element:(0,Z.jsx)(ED,{})}),(0,Z.jsx)(g,{path:`system/metadata`,element:(0,Z.jsx)(DD,{})}),(0,Z.jsx)(g,{path:`system/metadata/:metadataType`,element:(0,Z.jsx)(DD,{})}),(0,Z.jsx)(g,{path:`system/metadata/:metadataType/:itemName`,element:(0,Z.jsx)(DD,{})})]});function kD(){let e=(0,X.useMemo)(()=>Ar({baseUrl:``}),[``]);return(0,Z.jsx)(A,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Z.jsx)(Ru,{}),children:(0,Z.jsx)(xi,{adapter:e,children:(0,Z.jsx)(mg,{extraRoutes:OD,extraRoutesNoApp:OD})})})}var AD=[`cloud_control`];function jD(){let{apps:e,loading:t}=se();if(t)return(0,Z.jsx)(nl,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of AD)if(n.has(e))return(0,Z.jsx)(i,{to:`/apps/${e}`,replace:!0});return(0,Z.jsx)(i,{to:`/home`,replace:!0})}var MD=`/api/v1`;function ND(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 FD(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=ND(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 ID(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 LD(e,t){return fetch(`${MD}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function RD(e){let t=await LD(`/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 zD(e){let t=await LD(`/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 LD(`/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 BD(e,t){let n=await LD(`/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 VD(e,t){let n=await LD(`/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 HD=`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 UD({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:HD},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 WD({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`?RD(r):zD(r)).then(e=>{t||(u(e),f(ID(FD(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?FD(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 BD(r,d):await VD(l.object,d),J.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:f(ID(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);c(t),J.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)(UD,{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 GD({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{J.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},l=e=>{try{let t=JSON.parse(e.data);c(t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`)}catch{c(`change`)}},u=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}c(t)},d=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`metadata-change`,l),a.addEventListener(`reload`,u),a.addEventListener(`error`,()=>{s||a?.readyState===EventSource.CLOSED&&(a=null,o=setTimeout(d,r))})}catch{o=setTimeout(d,r)}};return d(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}function KD(){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 qD(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 JD(){let{token:e}=s(),t=`${(0,X.useMemo)(()=>KD(),[])}/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)(H,{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)(en,{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)(_t,{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)(jr,{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)(U,{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)(H,{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=qD(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 YD(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function XD(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function ZD(){return typeof window>`u`?null:window.location.host||null}function QD(){let e=Hs();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 $D({children:e,formWidth:t=`sm`}){let{t:n}=B(),r=t===`md`?`max-w-md`:`max-w-sm`,i=ZD(),a=!!i&&!YD(i)&&!XD(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:q(`flex w-full flex-col gap-5`,r),children:[(0,Z.jsx)(QD,{}),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 eO(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function tO(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function nO(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function rO(){let{t:e}=B(),[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(tO(eO(n)?n:`/`));return}window.location.assign(tO(`/organizations`));return}f||window.location.assign(tO(eO(n)?n:`/`))}},[r,s,a,o,f,n,c]),i&&!h||r)return(0,Z.jsx)($D,{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)($D,{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)(xt,{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)(iO,{registerUrl:u?void 0:v,redirect:n})})]})})}function iO({registerUrl:e,redirect:t}){let{t:n}=B(),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:nO,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 aO(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function oO(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function sO(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function cO(){let{t:e}=B(),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(oO(aO(r)?r:`/`));return}window.location.assign(oO(`/organizations`));return}p||window.location.assign(oO(aO(r)?r:`/`))}},[i,c,o,s,p,r,l]),d===null||a&&!g||i)return(0,Z.jsx)($D,{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)($D,{formWidth:`md`,children:(0,Z.jsx)(xt,{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:sO,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 lO(e){return(0,Z.jsx)(h,{to:e.href,className:e.className,children:e.children})}function uO(){let{t:e}=B();return(0,Z.jsx)($D,{formWidth:`md`,children:(0,Z.jsx)(xt,{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:lO,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 dO(){let{t:e}=B(),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)($D,{children:(0,Z.jsxs)(xt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Z.jsx)(Ma,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Z.jsx)(Ht,{children:r?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a!==s){J.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!r){J.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}u(!0);try{await i(r,a),J.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){J.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 fO(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function pO(){let{t:e}=B(),t=v(),[n]=m(),r=fO(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)($D,{children:(0,Z.jsxs)(xt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`,{defaultValue:`Set a recovery password`})}),(0,Z.jsx)(Ma,{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)(Ht,{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){J.error(e(`auth.setPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}f(!0);try{await o(s),J.success(e(`auth.setPassword.success`,{defaultValue:`Local password set`})),t(r)}catch(t){J.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 mO=`/api/v1/auth`;function hO(){let{t:e}=B(),[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(`${mO}/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)($D,{children:(0,Z.jsxs)(xt,{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)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Z.jsx)(Ma,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Z.jsx)(Ht,{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)(Lt,{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)(aa,{className:`size-6`})}),(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Z.jsx)(Ma,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Z.jsx)(Ht,{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)(Lt,{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)(Qa,{className:`size-6`})}),(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Z.jsx)(Ma,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Z.jsx)(Ht,{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 gO(){let{t:e}=B(),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)($D,{children:(0,Z.jsxs)(xt,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Z.jsxs)(Lt,{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)(ho,{className:`size-8 text-primary`})}),(0,Z.jsx)(br,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Z.jsx)(Ma,{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)(Ht,{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){J.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),J.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){J.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)(Ui,{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)(Ui,{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 _O=`/api/v1/auth`;function vO(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function yO(){let{t:e}=B(),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(`${_O}/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)(xt,{children:[(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Z.jsx)(Ma,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Z.jsx)(Ht,{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:vO(e)}),n=t.id):n=(await s({name:e,slug:vO(e)}))?.id,n&&await c(n).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(`/`)}catch(t){J.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 bO=`/api/v1/auth`;function xO(){let{t:e}=B(),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(`${bO}/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(`${bO}/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}J(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){J.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)(xt,{className:`w-full max-w-md`,children:[(0,Z.jsxs)(Lt,{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)(ar,{className:`h-7 w-7 text-muted-foreground`})}),(0,Z.jsx)(br,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:h,defaultValue:`${h} wants to access your account`})}),(0,Z.jsx)(Ma,{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)(Ht,{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)(po,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Z.jsx)(`span`,{children:SO(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)(Jr,{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)(po,{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 SO(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 CO=`/api/v1/auth`;function wO({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)(xa,{className:`size-4`})}),`ObjectStack`]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function TO(){let{t:e}=B(),[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)(wO,{children:(0,Z.jsx)(xt,{children:(0,Z.jsx)(Lt,{className:`text-center`,children:(0,Z.jsx)(Ma,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})}):r?d?(0,Z.jsx)(wO,{children:(0,Z.jsx)(xt,{children:(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(aa,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Z.jsx)(br,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Z.jsx)(Ma,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})}):p?(0,Z.jsx)(wO,{children:(0,Z.jsx)(xt,{children:(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Z.jsx)(Ma,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})}):(0,Z.jsx)(wO,{children:(0,Z.jsxs)(xt,{children:[(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Z.jsx)(Ma,{children:e(`auth.device.subtitle`,{email:r.email,defaultValue:`Approve this device to sign in as ${r.email}.`})})]}),(0,Z.jsxs)(Ht,{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(`${CO}/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),J.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(`${CO}/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)(wO,{children:(0,Z.jsx)(xt,{children:(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Z.jsx)(Ma,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})})}function EO(){let{t:e}=B(),{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)(xt,{children:[(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Z.jsx)(Ma,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Z.jsxs)(Ht,{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),J.success(e(`acceptInvitation.accepted`,{defaultValue:`Invitation accepted`})),n(`/organizations`)}catch(t){J.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),J.success(e(`acceptInvitation.declined`,{defaultValue:`Invitation declined`})),n(`/organizations`)}catch(t){J.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)(xt,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(Lt,{className:`text-center`,children:[(0,Z.jsx)(br,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Z.jsx)(Ma,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var DO=`/api/v1/auth`;function OO(){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 kO=OO();function AO(){let e=u(),t=e.pathname+e.search;return(0,Z.jsx)(i,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function jO({children:e,requireOrganization:t=!0}){return(0,Z.jsx)(M,{fallback:(0,Z.jsx)(AO,{}),loadingFallback:(0,Z.jsx)(nl,{}),children:(0,Z.jsx)(il,{children:t?(0,Z.jsx)(sl,{children:e}):e})})}function MO(){let{user:e}=S();return(0,Z.jsx)(p_,{userId:e?.id,children:(0,Z.jsx)(O_,{})})}function NO(){return(0,Z.jsxs)(k,{authUrl:DO,children:[(0,Z.jsx)(zu,{position:`bottom-right`}),(0,Z.jsx)(GD,{}),(0,Z.jsx)(f,{basename:kO,children:(0,Z.jsx)(rl,{children:(0,Z.jsxs)(a,{children:[(0,Z.jsx)(g,{path:`/login`,element:(0,Z.jsx)(rO,{})}),(0,Z.jsx)(g,{path:`/register`,element:(0,Z.jsx)(cO,{})}),(0,Z.jsx)(g,{path:`/forgot-password`,element:(0,Z.jsx)(uO,{})}),(0,Z.jsx)(g,{path:`/reset-password`,element:(0,Z.jsx)(dO,{})}),(0,Z.jsx)(g,{path:`/set-password`,element:(0,Z.jsx)(pO,{})}),(0,Z.jsx)(g,{path:`/verify-email`,element:(0,Z.jsx)(hO,{})}),(0,Z.jsx)(g,{path:`/verify-email-prompt`,element:(0,Z.jsx)(gO,{})}),(0,Z.jsx)(g,{path:`/setup`,element:(0,Z.jsx)(yO,{})}),(0,Z.jsx)(g,{path:`/oauth/consent`,element:(0,Z.jsx)(xO,{})}),(0,Z.jsx)(g,{path:`/auth/device`,element:(0,Z.jsx)(TO,{})}),(0,Z.jsx)(g,{path:`/accept-invitation/:invitationId`,element:(0,Z.jsx)(EO,{})}),(0,Z.jsx)(g,{path:`/f/:slug`,element:(0,Z.jsx)(WD,{mode:`public`})}),(0,Z.jsx)(g,{path:`/s/:token`,element:(0,Z.jsx)(JD,{})}),(0,Z.jsx)(g,{path:`/forms/:name`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(WD,{mode:`internal`})})}),(0,Z.jsx)(g,{path:`/home`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(MO,{})})}),(0,Z.jsx)(g,{path:`/dev/master-detail`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(dc,{})})}),(0,Z.jsx)(g,{path:`/dev/lists`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(mc,{})})}),(0,Z.jsx)(g,{path:`/dev/modal`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(dD,{})})}),(0,Z.jsx)(g,{path:`/dev/lookup`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(fD,{})})}),(0,Z.jsx)(g,{path:`/organizations`,element:(0,Z.jsx)(jO,{requireOrganization:!1,children:(0,Z.jsx)(k_,{children:(0,Z.jsx)(P_,{})})})}),(0,Z.jsxs)(g,{path:`/organizations/:slug`,element:(0,Z.jsx)(jO,{requireOrganization:!1,children:(0,Z.jsx)(F_,{})}),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)(B_,{})}),(0,Z.jsx)(g,{path:`invitations`,element:(0,Z.jsx)(U_,{})}),(0,Z.jsx)(g,{path:`settings`,element:(0,Z.jsx)(W_,{})})]}),(0,Z.jsx)(g,{path:`/system/*`,element:(0,Z.jsx)(cl,{})}),(0,Z.jsx)(g,{path:`/ai`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(ov,{})})}),(0,Z.jsx)(g,{path:`/ai/:conversationId`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(ov,{})})}),(0,Z.jsx)(g,{path:`/apps/:appName/*`,element:(0,Z.jsx)(jO,{children:(0,Z.jsx)(kD,{})})}),(0,Z.jsx)(g,{path:`/`,element:(0,Z.jsx)(il,{children:(0,Z.jsx)(jD,{})})}),(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 FO=`auth-session-token`,IO=`auth-active-organization-id`;async function LO(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(FO)}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(FO),localStorage.removeItem(IO)}catch{}}function RO(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 zO(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 BO(e){let{objects:t}=se(),n=(0,X.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,X.useMemo)(()=>n?RO(n,0):null,[n]),fields:(0,X.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(zO):[],[n]),metadataObject:n}}function VO({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)(ke,{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)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(po,{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)(Jr,{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)(Vt,{className:`h-3 w-3`})})]})})]})}function HO({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=BO(t),{refresh:a}=se(),o=lh(),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(),J.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw J.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,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)(VO,{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)(VO,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Z.jsx)(VO,{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)(VO,{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)(U,{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)(U,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var UO=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function WO({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=BO(t),{refresh:i}=se(),a=lh(),[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(),J.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){J.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,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(),J.success(`关联关系已删除`)}catch(e){J.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,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)(No,{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:UO.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)(H,{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)(U,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:UO.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)(zn,{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)(en,{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)(No,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function GO({schema:e}){let t=e.objectName,{fields:n}=BO(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)(U,{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)(ar,{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 KO(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)(hr,{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)(Sn,{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)(Qn,{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 qO({schema:e}){let t=e.objectName,{object:n}=BO(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)(zt,{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 JO(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function YO(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=JO(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 XO(){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 ZO(){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 QO(){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 $O(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 ek(...e){return Io(Ro(e))}function tk({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)(_t,{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:ek(`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 nk(...e){return Io(Ro(e))}function rk({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:nk(`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)(Fi,{className:`h-3 w-3`}):(0,Z.jsx)(Ir,{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)(ik,{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 ik({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 ak(...e){return Io(Ro(e))}function ok({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:ak(`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 sk=(0,X.createContext)(null);sk.displayName=`CollaborationContext`;function ck(){return(0,X.useContext)(sk)}function lk(...e){return Io(Ro(e))}function uk({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=dk,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=YO(t),d=u.current,f=(0,X.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=$O({initialZoom:e.zoom??1}),{zoom:m}=p,h=ZO(),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=QO(),y=XO(),b=ck(),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]),M=(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]),ee=(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]),N=(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]),P=(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]),te=(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]),ne=(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]),F=(0,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),re=(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]),ie=(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(),ee();return}if(e.key===`Escape`){h.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&i&&!o){e.preventDefault(),u.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&i&&!o){e.preventDefault(),u.redo();return}if(n&&e.key===`c`){e.preventDefault(),P();return}if(n&&e.key===`v`&&!o){e.preventDefault(),te();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,ee,i,o,u,P,te,d]),(0,Z.jsxs)(`div`,{ref:k,tabIndex:0,className:lk(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Z.jsx)(`div`,{className:lk(`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)(No,{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)(Ja,{className:lk(`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:lk(`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:lk(`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:lk(`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:P,children:(0,Z.jsx)(Tt,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:lk(`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:te,children:(0,Z.jsx)(jn,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Z.jsx)(`button`,{className:lk(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Delete selected`,"aria-label":`Delete selected`,disabled:h.count===0,onClick:ee,children:(0,Z.jsx)(zn,{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)(nt,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:lk(`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)(bo,{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)(sa,{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)(No,{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)(Gr,{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)(li,{className:lk(`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:F,onDrop:re,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=>ne(t,e),className:lk(`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)(Ae,{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(),M(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,Z.jsx)(zn,{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)(ok,{items:ae,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Z.jsx)(`div`,{className:lk(`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)(Jt,{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:lk(`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)(rk,{title:`Properties – ${_.label??_.type}`,fields:ie,onChange:N})}):_&&(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)(tk,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var dk=[{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 fk(e,t={}){return YO(e,t)}function pk(...e){return Io(Ro(e))}var mk=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function hk(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 gk({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=fk({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=XO(),m=ZO(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=QO(),_=$O({minZoom:.25,maxZoom:3,zoomStep:.1}),v=ck(),[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),M=(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]),ee=(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]),N=(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]),P=(0,X.useCallback)(()=>{if(i)return;let e=l.current;f({entities:hk(e.entities),relationships:e.relationships})},[i,l,f]),te=(0,X.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),ne=(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]),F=(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]),re=(0,X.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),ie=(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]),I=(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]),se=(0,X.useCallback)(()=>{O(null)},[]),ce=(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]),le=(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]),ue=(0,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),de=(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]),fe=h?u.find(e=>e.id===h):null,pe=fe?[{name:`name`,label:`Name`,type:`text`,value:fe.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:fe.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:fe.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:fe.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:fe.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:fe.position.y,group:`Position`}]:[],me=(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(),te()):n&&e.key===`v`?(e.preventDefault(),ne()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),N()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,te,ne,N,m]);let he=u.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:240,height:40+e.fields.length*24,color:e.color,selected:m.isSelected(e.id)}));return(0,Z.jsxs)(`div`,{ref:c,tabIndex:0,className:pk(`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)(Zt,{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)(Ei,{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)(Fr,{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)(ct,{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:te,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)(Tt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{onClick:ne,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Z.jsx)(jn,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Z.jsxs)(`button`,{onClick:P,"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)(fi,{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)(rt,{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:M,"aria-label":`Add Entity`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,Z.jsx)(No,{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)(en,{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:ue,onDrop:de,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=>le(t,e.id),className:pk(`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)(Zt,{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:I,onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&se()},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(),ee(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Z.jsx)(zn,{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:ie,onKeyDown:e=>{e.key===`Enter`&&ie(),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:pk(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),re(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,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(),ce(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:mk.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(),F(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,Z.jsx)(No,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Z.jsx)(ok,{items:he,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)(Ir,{className:`h-3 w-3`}):(0,Z.jsx)(Fi,{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)(rk,{title:fe?fe.label:`Properties`,fields:pe,onChange:me})})]}),(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)(Ir,{className:`h-3 w-3`}):(0,Z.jsx)(Fi,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Z.jsx)(tk,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function _k(...e){return Io(Ro(e))}var vk=120,yk=50;function bk(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 xk({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=YO({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=XO(),g=ZO(),_=QO(),v=$O({initialZoom:1}),y=ck(),[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),[M,ee]=(0,X.useState)({x:0,y:0}),N=(0,X.useRef)(null),P=(0,X.useRef)(c),te=(0,X.useRef)(l);P.current=c,te.current=l,(0,X.useEffect)(()=>{P.current?.(f),te.current?.(p)},[d.current]);let ne=(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]),F=(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]),re=(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]),ie=(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)},[]),I=(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]),se=(0,X.useCallback)(()=>{s||f.length===0||m(bk(f,p),p)},[f,p,s,m]),ce=(0,X.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;j(t);let n=e.target.getBoundingClientRect();ee({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[s,f]),le=(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-M.x,i=(e.clientY-t.top-v.panOffset.y)/n-M.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);m(f.map(e=>e.id===A?{...e,position:{x:a,y:o}}:e),p),j(null)},[s,A,M,f,p,v.zoom,v.panOffset,m]),ue=(0,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),de=(0,X.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),fe=(0,X.useMemo)(()=>de?[{name:`label`,label:`Name`,type:`text`,value:de.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:de.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:de.description??``,group:`General`}]:[],[de]),pe=(0,X.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),me=e=>{switch(e){case`start-event`:return`rounded-full bg-green-100 border-green-500 text-green-700`;case`end-event`:return`rounded-full bg-red-100 border-red-500 text-red-700`;case`exclusive-gateway`:case`parallel-gateway`:case`inclusive-gateway`:case`event-based-gateway`:return`rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700`;case`user-task`:return`rounded bg-blue-100 border-blue-500 text-blue-700`;case`service-task`:case`script-task`:return`rounded bg-purple-100 border-purple-500 text-purple-700`;default:return`rounded bg-gray-100 border-gray-500 text-gray-700`}},he=(0,X.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:vk,height:yk,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,X.useEffect)(()=>{let e=N.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(),ie();return}if(n&&e.key===`v`){e.preventDefault(),ae();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),re()):b&&(e.preventDefault(),F(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,ie,ae,F,re]);let ge=(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:N,tabIndex:0,className:_k(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Z.jsx)(tk,{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)(Ri,{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:ie,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)(Tt,{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)(jn,{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:_k(`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:se,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)(yr,{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)(Fr,{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)(Ei,{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)(ct,{className:`h-3 w-3`})}),(0,Z.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Z.jsxs)(`button`,{onClick:()=>ne(`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)(or,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Z.jsxs)(`button`,{onClick:()=>ne(`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)(Xa,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Z.jsxs)(`button`,{onClick:()=>ne(`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)(jt,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Z.jsxs)(`button`,{onClick:()=>ne(`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)(Xa,{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)(li,{className:`h-3 w-3`}):(0,Z.jsx)(kn,{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:ge,onDrop:le,onDragOver:ue,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+vk/2;let r=t.position.y+yk/2;n.position.x+vk/2;let i=n.position.y+yk/2,a=t.position.x+vk,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=>ce(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{I(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Z.jsx)(`div`,{className:_k(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,me(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:_k(`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:yk/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),I(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:yk/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?I(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:vk/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),I(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:vk/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),I(e.id)}})]}),!s&&t&&!S&&(0,Z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),F(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,Z.jsx)(zn,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Z.jsx)(ok,{items:he,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)(rk,{title:de?`Properties: ${de.label}`:`Properties`,fields:fe,onChange:pe})})]})]})}function Sk(...e){return Io(Ro(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`},Ck={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}},wk=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function Tk({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=YO(a.length>0?a:wk),f=d.current,p=(0,X.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=ZO(),h=(0,X.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=QO(),_=XO(),v=ck(),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=Ck[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]),M=(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]),ee=(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]),N=(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]),P=(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]),te=(0,X.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ne=(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]),F=(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(),ee();return}if(n&&e.key===`v`&&!c){e.preventDefault(),N();return}if(n&&e.key===`a`){e.preventDefault();let t=f.flatMap(e=>e.elements).map(e=>e.id);m.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[m,j,c,d,ee,N,f]),(0,Z.jsxs)(`div`,{ref:C,tabIndex:0,className:Sk(`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)(uo,{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:Sk(`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:Sk(`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:Sk(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.copyShortcut,"aria-label":$.copy,disabled:m.count===0,onClick:ee,children:(0,Z.jsx)(Tt,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{className:Sk(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:N,children:(0,Z.jsx)(jn,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Z.jsx)(`button`,{className:Sk(`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)(zn,{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)(li,{className:Sk(`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:te,onDrop:e=>ne(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)(Tn,{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)(No,{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)(Bt,{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)(Qn,{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)(Sr,{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=>P(n,e,t),className:Sk(`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)(zn,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Z.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:Sk(`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)(rk,{title:`${$.properties} – ${O.type}`,fields:F,onChange:M}):(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)(tk,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var Ek={"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 Dk(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 Ok(){try{let e=B();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:Dk(Ek)}:{t:e.t}}catch{return{t:Dk(Ek)}}}function kk(...e){return Io(Ro(e))}var Ak={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function jk(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var Mk=0;function Nk(e){return Mk+=1,`${e}_${Date.now()}_${Mk}`}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:kk(`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:kk(`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:kk(`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)(po,{className:`h-4 w-4`}):r+1}),(0,Z.jsx)(`span`,{className:kk(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function Fk({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!me(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:kk(`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:je},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:yr},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:cn}].map(({value:t,labelKey:a,Icon:o})=>(0,Z.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:kk(`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 Ik({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)(Oo,{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:kk(`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:kk(`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)(po,{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 Lk={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 Rk({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)(vi,{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)(sa,{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`):le(n.label)}),(0,Z.jsx)(`span`,{className:kk(`rounded-full px-2 py-0.5 text-[10px] font-medium`,Lk[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)(da,{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)(Ir,{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)(zn,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function zk({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)(Bt,{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)(La,{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)(Za,{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 Bk({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=Ok(),l=XO(),[u,d]=(0,X.useState)(0),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(()=>({...Ak,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&&me(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:Nk(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:jk(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]),M=(0,X.useCallback)(()=>{a?.(m)},[m,a]),ee=(0,X.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:jk(e.objects)})),d(e))},[u,b]);return(0,Z.jsxs)(`div`,{className:kk(`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)(Jr,{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:ee})}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Z.jsx)(Fk,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Z.jsx)(Ik,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Z.jsx)(Rk,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Z.jsx)(zk,{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:M,disabled:o,className:`rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`appDesigner.saveDraft`)})]}),(0,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)(Di,{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)(po,{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)(Fi,{className:`h-4 w-4`})]})]})]})]})}function Vk(...e){return Io(Ro(e))}var Hk=0;function Uk(e){return Hk+=1,`${e}_${Date.now()}_${Hk}`}var Wk={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Zt},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:kt},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:uo},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:Qn},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:vi},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:sa},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:ea}},Gk=[{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 Kk({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)(le(e.label)??``),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(e.icon||``),C=Wk[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(le(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:Vk(`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)(Ae,{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)(Ir,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Fi,{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)(Vt,{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(le(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:Vk(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(le(e.label)??``),g(!0))},children:le(e.label)}),(0,Z.jsx)(`span`,{className:Vk(`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)(vn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(nt,{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)(No,{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)(da,{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)(Ir,{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)(zn,{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)(Kk,{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 qk({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)(Jk,{item:e,depth:0},e.id))})]})}function Jk({item:e,depth:t}){let n=Wk[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:le(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Z.jsx)(Jk,{item:e,depth:t+1},e.id))]})}function Yk({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=Ok(),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:Uk(r),type:r,label:r===`separator`?``:`New ${s(Wk[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:Uk(n),type:n,label:n===`separator`?``:`New ${s(Wk[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:Vk(`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:[Gk.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=Wk[e];return(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:Vk(`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)(No,{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)(dn,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Z.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:Vk(`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)(Gi,{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)(Kk,{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)(qk,{items:e,t:s})]})}function Xk(...e){return Io(Ro(e))}var Zk=[{type:`metric`,label:`KPI Metric`,Icon:Mt},{type:`bar`,label:`Bar Chart`,Icon:Qn},{type:`line`,label:`Line Chart`,Icon:yo},{type:`pie`,label:`Pie Chart`,Icon:Yr},{type:`table`,label:`Table`,Icon:Sr},{type:`grid`,label:`Grid`,Icon:pt}],Qk=0;function $k(){return Qk+=1,`widget_${Date.now()}_${Qk}`}function eA({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=Zk.find(e=>e.type===l)||Zk[0];return(0,Z.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:Xk(`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)(Ae,{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)(da,{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)(Ir,{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)(zn,{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 tA({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=Ok();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)(Jr,{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:Zk.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 nA({schema:e}){let{t}=Ok(),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=Zk.find(t=>t.type===(e.type||`metric`))||Zk[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 rA({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=Ok(),[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}=YO(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=$k(),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]),M=(0,X.useCallback)(()=>{m.current?.click()},[]),ee=(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:Xk(`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:ee}),E&&!d&&(0,Z.jsx)(tA,{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`),`:`]}),Zk.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)(dn,{className:`h-4 w-4`})}),!n&&(0,Z.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:M,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,Z.jsx)(Gi,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:Xk(`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)(vn,{className:`h-4 w-4`}):(0,Z.jsx)(nt,{className:`h-4 w-4`})})]})]}),d?(0,Z.jsx)(nA,{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)(eA,{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 iA(...e){return Io(Ro(e))}var aA=[{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`}],oA=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function sA({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=Ok(),[c,l]=(0,X.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=YO(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:iA(`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:iA(`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:iA(`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)(dn,{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:iA(`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)(Gi,{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)(Bt,{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)(La,{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:aA.map(e=>(0,Z.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:iA(`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)(Za,{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)(Tn,{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`)}),oA.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:iA(`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)(_r,{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:iA(`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)(ii,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Z.jsxs)(`div`,{"data-testid":`branding-preview`,className:iA(`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:iA(`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:iA(`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:iA(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Z.jsxs)(`div`,{className:iA(`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:iA(`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:iA(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Z.jsx)(`div`,{className:iA(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Z.jsx)(`div`,{className:iA(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function cA(...e){return Io(Ro(e))}var lA=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],uA=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function dA({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=Ok(),s=XO(),[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 ee({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:uA.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:lA.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:cA(`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)(Zt,{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)(Zs,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Z.jsx)(Uo,{schema:S}),(0,Z.jsx)(tk,{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 fA(...e){return Io(Ro(e))}var pA={text:{label:`Text`,Icon:Tn},textarea:{label:`Text Area`,Icon:uo},number:{label:`Number`,Icon:mr},boolean:{label:`Checkbox`,Icon:qe},date:{label:`Date`,Icon:it},datetime:{label:`Date/Time`,Icon:it},time:{label:`Time`,Icon:it},select:{label:`Picklist`,Icon:qi},email:{label:`Email`,Icon:pr},phone:{label:`Phone`,Icon:ur},url:{label:`URL`,Icon:Za},password:{label:`Password`,Icon:st},currency:{label:`Currency`,Icon:mr},percent:{label:`Percent`,Icon:mr},lookup:{label:`Lookup`,Icon:en},formula:{label:`Formula`,Icon:St},autonumber:{label:`Auto Number`,Icon:mr},file:{label:`File`,Icon:uo},image:{label:`Image`,Icon:Bt},markdown:{label:`Markdown`,Icon:uo},html:{label:`Rich Text`,Icon:uo},color:{label:`Color`,Icon:La},code:{label:`Code`,Icon:St},location:{label:`Location`,Icon:Un},address:{label:`Address`,Icon:Un},rating:{label:`Rating`,Icon:Pe},slider:{label:`Slider`,Icon:Qr}},mA={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`]},hA=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function gA({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=Ok(),o=XO(),[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 ee({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)(()=>hA.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:mA[e].map(e=>({label:pA[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:fA(`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)(fr,{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)(Zs,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Z.jsx)(Wo,{schema:w}),(0,Z.jsx)(tk,{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 _A=`objectui-app-wizard-draft`;function vA(){let e=v(),{appName:t}=s(),{objects:n,refresh:r}=se(),i=ye(),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(_A);if(e)return JSON.parse(e)}catch{}},[]),c=(0,X.useCallback)(async t=>{try{let n=de(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(_A),J.success(`Application "${t.title}" created successfully`),await r?.(),e(`/apps/${t.name}`)}catch(e){J.error(e?.message||`Failed to create application`)}},[e,r,i]),l=(0,X.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),u=(0,X.useCallback)(e=>{try{localStorage.setItem(_A,JSON.stringify(e)),J.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)(Bk,{availableObjects:a,initialDraft:o(),onComplete:c,onCancel:l,onSaveDraft:u})})}function yA(){let e=v(),{appName:t,editAppName:n}=s(),{apps:r,objects:i,refresh:a}=se(),o=ye(),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=de(t),r={...l,...n},i=o?.getClient();i&&await i.meta.saveItem(`app`,t.name,r),J.success(`Application "${t.title}" updated successfully`),await a?.(),e(`/apps/${t.name}`)}catch(e){J.error(e?.message||`Failed to update application`)}},[e,a,o,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)),J.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)(Bk,{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 bA(){let e=v(),{dashboardName:t}=s(),n=ye(),{dashboards:r,refresh:i}=se(),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&&J.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),J.success(`Dashboard schema exported`)},[t]),p=(0,X.useCallback)(e=>{J.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)(Or,{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)(rA,{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 xA=t({AppCreationWizard:()=>Bk,BrandingEditor:()=>sA,CreateAppPage:()=>vA,DashboardDesignPage:()=>bA,DashboardEditor:()=>rA,DataModelDesigner:()=>gk,EditAppPage:()=>yA,FieldDesigner:()=>gA,NavigationDesigner:()=>Yk,ObjectManager:()=>dA,PageDesigner:()=>uk,ProcessDesigner:()=>xk,ReportDesigner:()=>Tk});L.register(`page-designer`,uk,{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}]}),L.register(`data-model-designer`,gk,{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}]}),L.register(`process-designer`,xk,{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}]}),L.register(`report-designer`,Tk,{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}]}),L.register(`app-creation-wizard`,Bk,{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}]}),L.register(`navigation-designer`,Yk,{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}]}),L.register(`dashboard-editor`,rA,{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}]}),L.register(`branding-editor`,sA,{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}]}),L.register(`object-manager`,dA,{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}]}),L.register(`field-designer`,gA,{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 SA(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 CA(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 wA=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=SA(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(CA)};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 TA({schema:e}){let t=e.objectName,{objects:n,refresh:r}=se(),i=lh(),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(zO):[],[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){J.error(`Service unavailable — changes saved locally only`);return}let a=wA.diffFields(n,e),o=a?a.type===`create`?`Field "${a.field.label||a.field.name}" created`:a.type===`update`?`Field "${a.field.label||a.field.name}" updated`:`Field "${a.field.label||a.field.name}" deleted`:`Field configuration updated`;u(!0);try{await i.saveFields(t,e),await r(),J.success(o)}catch(e){c(n),f.current=n,J.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,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)(H,{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)(ci,{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)(gA,{objectName:t,fields:d,onFieldsChange:p})]})}function EA({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)(hi,{value:n,onValueChange:r,className:`w-full`,children:[(0,Z.jsxs)(_a,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Z.jsxs)(Va,{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)(Mr,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Z.jsxs)(Va,{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)(fr,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Z.jsxs)(Va,{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)(en,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Z.jsxs)(Va,{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)(zt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Z.jsx)($a,{value:`details`,className:`mt-6`,children:(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsx)(P,{schema:i})})}),(0,Z.jsx)($a,{value:`fields`,className:`mt-6`,children:(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsx)(P,{schema:a})})}),(0,Z.jsx)($a,{value:`relationships`,className:`mt-6`,children:(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsx)(P,{schema:o}),(0,Z.jsx)(P,{schema:s})]})}),(0,Z.jsx)($a,{value:`data`,className:`mt-6`,children:(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsx)(P,{schema:l}),(0,Z.jsx)(P,{schema:c})]})})]})})}var DA={namespace:`console`,category:`system`};L.register(`object-detail-tabs`,EA,{...DA,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),L.register(`object-properties`,HO,{...DA,label:`Object Properties`,icon:`Settings2`}),L.register(`object-relationships`,WO,{...DA,label:`Object Relationships`,icon:`Link2`}),L.register(`object-keys`,GO,{...DA,label:`Object Keys`,icon:`KeyRound`}),L.register(`object-data-experience`,KO,{...DA,label:`Data Experience`,icon:`LayoutList`}),L.register(`object-data-preview`,qO,{...DA,label:`Data Preview`,icon:`Table`}),L.register(`object-field-designer`,TA,{...DA,label:`Field Designer`,icon:`Columns`});var OA=(0,X.lazy)(()=>d(()=>import(`./ApiConsolePage-Dwbms0Zh.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),kA=(0,X.lazy)(()=>d(()=>import(`./FlowRunsPage-_UeeNdBc.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),AA=(0,X.lazy)(()=>d(()=>import(`./PublicFormsPage-Pd453sW6.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function jA({label:e}){return(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pv({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(jA,{label:`API console`}),children:(0,Z.jsx)(OA,{...e})})}),pv({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(jA,{label:`flow runs`}),children:(0,Z.jsx)(kA,{...e})})}),pv({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(jA,{label:`public forms`}),children:(0,Z.jsx)(AA,{...e})})});var MA=(0,X.lazy)(()=>d(()=>import(`./ProfilePage-T27zVrMO.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function NA({label:e}){return(0,Z.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}pv({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(NA,{label:`profile`}),children:(0,Z.jsx)(MA,{...e})})});var PA=`/api/v1/auth`;Wu(),L.registerLazy(`object-map`,()=>d(()=>import(`./plugin-map-C8Jxhxs1.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),L.registerLazy(`map`,()=>d(()=>import(`./plugin-map-C8Jxhxs1.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`])L.registerLazy(e,()=>d(()=>import(`./plugin-dashboard-PA0xf59v.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});L.registerLazy(`chart`,()=>d(()=>import(`./plugin-charts-QabQJ_NJ.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`])L.registerLazy(e,()=>d(()=>import(`./plugin-charts-QabQJ_NJ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});L.registerLazy(`object-gantt`,()=>d(()=>import(`./plugin-gantt-BNjfLkTR.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),L.registerLazy(`gantt`,()=>d(()=>import(`./plugin-gantt-BNjfLkTR.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),L.registerLazy(`markdown`,()=>d(()=>import(`./plugin-markdown-CR5TpghH.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),L.registerLazy(`object-timeline`,()=>d(()=>import(`./plugin-timeline-DQHQwtdw.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),L.registerLazy(`timeline`,()=>d(()=>import(`./plugin-timeline-DQHQwtdw.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),L.registerLazy(`object-calendar`,()=>d(()=>import(`./plugin-calendar-ed7RoEFF.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),L.registerLazy(`calendar`,()=>d(()=>import(`./plugin-calendar-ed7RoEFF.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),L.registerLazy(`calendar-view`,()=>d(()=>import(`./plugin-calendar-ed7RoEFF.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),L.registerLazy(`object-kanban`,()=>d(()=>import(`./plugin-kanban-D4yCkUn_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),L.registerLazy(`kanban`,()=>d(()=>import(`./plugin-kanban-D4yCkUn_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])L.registerLazy(e,()=>d(()=>import(`./plugin-kanban-D4yCkUn_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});L.registerLazy(`report`,()=>d(()=>import(`./plugin-report-rz8HUIsi.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`spec-report`])L.registerLazy(e,()=>d(()=>import(`./plugin-report-rz8HUIsi.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});ot();var FA=``.replace(/\/+$/,``);Promise.all([Bs(FA),LO(PA)]).finally(()=>{lc.createRoot(document.getElementById(`root`)).render((0,Z.jsx)(X.StrictMode,{children:(0,Z.jsx)(Xs,{pwa:{enabled:!0,name:Hs(),shortName:Us()},children:(0,Z.jsx)(R,{loadLanguage:PO,children:(0,Z.jsx)(NO,{})})})}))});export{Mh as a,zh as i,G_ as n,Nh as r,mv as t};