@objectstack/console 7.0.0 → 7.2.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 (87) hide show
  1. package/dist/assets/{AiPendingActionsPage-DLWrcsds.js → AiPendingActionsPage-B6prPdE6.js} +1 -1
  2. package/dist/assets/{ApiConsolePage-BIBykAYj.js → ApiConsolePage-KLlXE_J-.js} +1 -1
  3. package/dist/assets/{AppManagementPage-BKE0rv8B.js → AppManagementPage-CSGa-1u0.js} +1 -1
  4. package/dist/assets/ApprovalsInboxPage-BOY6Xpsn.js +1 -0
  5. package/dist/assets/{AuditLogPage-Bqlhi2ko.js → AuditLogPage-DzIHYkL6.js} +1 -1
  6. package/dist/assets/ComponentNavView-CZkyv2fY.js +1 -0
  7. package/dist/assets/{ConsoleFloatingChatbot-CBIXkoNS.js → ConsoleFloatingChatbot-Dfub90-W.js} +1 -1
  8. package/dist/assets/DeveloperHubPage-lLRr5-aY.js +1 -0
  9. package/dist/assets/FlowRunsPage-DV2m0d1l.js +1 -0
  10. package/dist/assets/MonacoImpl-DcAVOHcx.js +1 -0
  11. package/dist/assets/ProfilePage-B4ZMNend.js +1 -0
  12. package/dist/assets/PublicFormsPage-CHWj3DL5.js +1 -0
  13. package/dist/assets/RecentItemsProvider-Dt0K6V1V.js +1 -0
  14. package/dist/assets/{SettingsHub-BTNCNbjZ.js → SettingsHub-DrmQJKTl.js} +1 -1
  15. package/dist/assets/{SettingsView-BLXf7B7b.js → SettingsView-DQ4mtooC.js} +1 -1
  16. package/dist/assets/{SystemHubPage-CgN-8VKO.js → SystemHubPage-CjV_--P3.js} +1 -1
  17. package/dist/assets/data-adapter-CX0Tq3Q5.js +1 -0
  18. package/dist/assets/dist-Dal4BOHf.js +11 -0
  19. package/dist/assets/{framework-ClI3DbWX.js → framework-DpQcF_QW.js} +4 -4
  20. package/dist/assets/{highlighted-body-OFNGDK62-Dua_6VJ2.js → highlighted-body-OFNGDK62-BcbCsvGi.js} +1 -1
  21. package/dist/assets/index-DUV_YMtu.css +2 -0
  22. package/dist/assets/index-hBFJ6de4.js +33 -0
  23. package/dist/assets/infrastructure-IQKE4Vv8.js +3 -0
  24. package/dist/assets/mermaid-GHXKKRXX-DLb_WlhX.js +1 -0
  25. package/dist/assets/plugin-calendar-BGJsyv_O.js +1 -0
  26. package/dist/assets/{plugin-charts-C11LxM1X.js → plugin-charts-CRlZ01tc.js} +2 -2
  27. package/dist/assets/plugin-chatbot-BhnqfdW0.js +120 -0
  28. package/dist/assets/plugin-dashboard-CUH4Dbo1.js +3 -0
  29. package/dist/assets/{plugin-form-f39dp3V2.js → plugin-form-BzrcwmiI.js} +1 -1
  30. package/dist/assets/plugin-gantt-Dt2juPb1.js +1 -0
  31. package/dist/assets/plugin-grid-BHnAwQNY.js +6 -0
  32. package/dist/assets/plugin-kanban-lsYbj6Vr.js +1 -0
  33. package/dist/assets/plugin-map-BKE-4AVm.js +1 -0
  34. package/dist/assets/plugin-markdown-bkOWrh0-.js +7 -0
  35. package/dist/assets/plugin-report-CqzUFpeK.js +59 -0
  36. package/dist/assets/plugin-timeline-ZI65E7h4.js +1 -0
  37. package/dist/assets/plugin-view-CGR-rgKC.js +1 -0
  38. package/dist/assets/plugins-views-CzwBozRK.js +4 -0
  39. package/dist/assets/src-0fzF-kZX.js +2 -0
  40. package/dist/assets/{types-CuyLcCWX.js → types-C7d65SSU.js} +1 -1
  41. package/dist/assets/ui-components-CXy53m_o.js +41 -0
  42. package/dist/assets/ui-layout-BqvRQUkZ.js +1 -0
  43. package/dist/assets/{vendor-charts-vh1WJI0j.js → vendor-charts-Ba_-W-di.js} +3 -3
  44. package/dist/assets/{vendor-dndkit-0jp7h5ty.js → vendor-dndkit-CucFgdMa.js} +1 -1
  45. package/dist/assets/{vendor-i18n-CnFu8bdi.js → vendor-i18n-DPyFo2xM.js} +1 -1
  46. package/dist/assets/{vendor-icons-core-D5MicM14.js → vendor-icons-core-Cx2WYOuR.js} +1 -1
  47. package/dist/assets/{vendor-markdown-CvMSBmgq.js → vendor-markdown-B0mCB2Nu.js} +2 -2
  48. package/dist/assets/vendor-objectstack-DdIVmQL0.js +65 -0
  49. package/dist/assets/{vendor-radix-BNWIlSsV.js → vendor-radix-thTS_QfF.js} +1 -1
  50. package/dist/assets/vendor-react-CyVA1SE-.js +13 -0
  51. package/dist/assets/{vendor-sentry-D5yZpZ5X.js → vendor-sentry-DjMgMAaz.js} +1 -1
  52. package/dist/assets/{vendor-ui-utils-D3GsyZyi.js → vendor-ui-utils-BbOuugky.js} +1 -1
  53. package/dist/favicon.svg +11 -0
  54. package/dist/index.html +7 -7
  55. package/dist/logo.svg +15 -0
  56. package/dist/manifest.json +2 -2
  57. package/package.json +1 -1
  58. package/dist/assets/ApprovalsInboxPage-D7gF2CM8.js +0 -1
  59. package/dist/assets/ComponentNavView-DBMxrUvH.js +0 -1
  60. package/dist/assets/DeveloperHubPage-C3Ooh2Gg.js +0 -1
  61. package/dist/assets/FlowRunsPage-NjEPPv_e.js +0 -1
  62. package/dist/assets/MonacoImpl-CKoKq1tG.js +0 -11
  63. package/dist/assets/ObjectManagerListPage-DEPokJwV.js +0 -1
  64. package/dist/assets/ProfilePage-zYSeu2-d.js +0 -1
  65. package/dist/assets/PublicFormsPage-BrLPiHf1.js +0 -1
  66. package/dist/assets/data-adapter-Dn6-L_yI.js +0 -1
  67. package/dist/assets/index-Ca4KaljM.js +0 -23
  68. package/dist/assets/index-DsQwZDFr.css +0 -2
  69. package/dist/assets/infrastructure-ezj3FgNE.js +0 -3
  70. package/dist/assets/mermaid-GHXKKRXX-BvEKnLTo.js +0 -1
  71. package/dist/assets/plugin-calendar-Dnr7itgk.js +0 -1
  72. package/dist/assets/plugin-chatbot-COnH_NZC.js +0 -120
  73. package/dist/assets/plugin-dashboard-DvBectcr.js +0 -3
  74. package/dist/assets/plugin-gantt-7ui7uiVc.js +0 -1
  75. package/dist/assets/plugin-grid-DtceFt_J.js +0 -6
  76. package/dist/assets/plugin-kanban-q2UT5MlD.js +0 -1
  77. package/dist/assets/plugin-map-C6vgk2bJ.js +0 -1
  78. package/dist/assets/plugin-markdown-DPzm2nVd.js +0 -7
  79. package/dist/assets/plugin-report-BJM4LH87.js +0 -59
  80. package/dist/assets/plugin-timeline-lCaTr_4i.js +0 -1
  81. package/dist/assets/plugin-view-b7gS6gIn.js +0 -1
  82. package/dist/assets/plugins-views-Dvl7pQvR.js +0 -4
  83. package/dist/assets/src-Con14F4e.js +0 -2
  84. package/dist/assets/ui-components-ZN8XdmwJ.js +0 -41
  85. package/dist/assets/ui-layout-HiDSueut.js +0 -1
  86. package/dist/assets/vendor-objectstack-CwZ3saTl.js +0 -65
  87. package/dist/assets/vendor-react-CIpZOxG3.js +0 -13
@@ -1,23 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
2
- import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{a as r,c as i,d as a,f as o,g 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-CIpZOxG3.js";import{a as y,c as b,d as x,i as S,l as C,n as w,o as T,r as E,s as D,u as O}from"./infrastructure-ezj3FgNE.js";import{A as k,B as A,D as j,L as M,M as ee,N as te,O as ne,P as N,R as P,S as F,T as re,X as ie,Y as I,_ as ae,at as oe,b as se,c as ce,d as le,n as ue,nt as de,r as L,rt as fe,tt as pe,u as me,ut as R,v as he,x as ge,y as z}from"./framework-ClI3DbWX.js";import{n as B,r as V,t as _e}from"./data-adapter-Dn6-L_yI.js";import{$ as H,$a as ve,$i as U,$n as ye,$o as be,$t as xe,Aa as Se,Ai as W,An as Ce,Ao as we,Ar as Te,At as G,Bi as Ee,Bn as De,Br as Oe,Bt as ke,Ca as Ae,Ci as je,Co as Me,Cr as Ne,Dr as Pe,Dt as Fe,Ea as Ie,Ei as Le,Et as Re,F as ze,Fa as Be,Fi as Ve,Fn as He,Fr as Ue,Ft as We,Gi as Ge,Gn as Ke,Go as qe,Gr as Je,Ha as Ye,Hi as Xe,Hr as Ze,Ht as Qe,I as $e,Ia as et,Ii as tt,In as nt,Io as rt,Ir as it,It as at,Ja as ot,Ji as st,Jn as ct,Jo as lt,Ka as ut,Kn as dt,Ko as ft,Kr as pt,La as mt,Li as ht,Ln as gt,Lr as _t,M as vt,Ma as yt,Mi as bt,Mn as xt,Mo as St,Mr as Ct,Mt as wt,N as Tt,Na as Et,Ni as Dt,Nn as Ot,Nr as kt,Nt as At,Oa as jt,On as Mt,Or as Nt,Ot as Pt,P as Ft,Pa as It,Pi as Lt,Pn as Rt,Po as zt,Pt as Bt,Q as Vt,Qa as Ht,Qi as Ut,Qn as K,Qr as Wt,Qt as Gt,Ri as Kt,Rn as qt,Ro as Jt,Rt as Yt,Sa as Xt,So as Zt,Sr as Qt,St as $t,T as en,Ta as tn,Ti as nn,To as rn,Tr as an,Tt as on,Ua as sn,Ui as cn,Uo as ln,Ur as un,Ut as dn,V as fn,Va as pn,Vi as mn,Vo as hn,Vr as gn,Vt as _n,Wa as vn,Wi as yn,Wr as bn,X as xn,Xa as Sn,Xi as Cn,Xn as wn,Xo as Tn,Xr as En,Ya as Dn,Yi as On,Yn as kn,Yo as An,Yr as jn,Z as Mn,Zi as Nn,Zo as Pn,Zr as Fn,Zt as In,_i as Ln,_o as Rn,_r as zn,_t as Bn,aa as Vn,ai as Hn,an as Un,ao as Wn,ar as Gn,bi as Kn,bo as qn,br as Jn,bt as Yn,ca as Xn,cn as Zn,co as Qn,cr as $n,da as er,di as tr,do as nr,dr as rr,dt as ir,ea as ar,ei as or,en as sr,eo as cr,er as lr,et as ur,fa as dr,fi as fr,fo as pr,fr as mr,ft as hr,g as gr,ga as _r,gi as vr,go as yr,gt as br,h as xr,ho as Sr,ht as Cr,ia as wr,ii as Tr,in as Er,io as Dr,ja as Or,jn as kr,jo as Ar,jr,ka as Mr,ki as Nr,kn as Pr,ko as Fr,kr as Ir,kt as Lr,la as Rr,li as zr,ln as Br,lo as Vr,lr as Hr,lt as Ur,ma as Wr,mn as Gr,mr as q,mt as Kr,na as qr,ni as Jr,no as Yr,nt as Xr,oa as Zr,oi as Qr,on as $r,oo as ei,or as ti,pa as ni,po as ri,pt as ii,qa as ai,qi as oi,qn as si,qo as ci,qr as li,ri as ui,ro as di,sa as fi,si as pi,sn as mi,so as hi,sr as gi,ta as _i,ti as vi,to as yi,tr as bi,tt as xi,ua as Si,ui as Ci,un as wi,ur as Ti,v as Ei,va as Di,vi as Oi,vo as ki,vr as Ai,w as ji,wa as Mi,wi as Ni,wo as Pi,wr as Fi,wt as Ii,x as Li,xa as Ri,xo as zi,xr as Bi,xt as Vi,yi as Hi,yo as Ui,yr as Wi,yt as Gi,z as Ki,za as qi,zn as Ji,zo as Yi,zt as Xi}from"./ui-components-ZN8XdmwJ.js";import{a as Zi,i as Qi,o as J,r as $i}from"./vendor-ui-utils-D3GsyZyi.js";import{n as ea,r as ta,t as na}from"./ui-layout-HiDSueut.js";import{a as ra,n as ia,o as aa,s as oa,t as sa}from"./plugins-views-Dvl7pQvR.js";import{i as ca,r as la}from"./plugin-grid-DtceFt_J.js";import{n as ua,r as da,t as fa}from"./plugin-form-f39dp3V2.js";import{a as pa,c as ma,d as ha,f as ga,i as _a,l as va,m as ya,n as ba,o as xa,p as Sa,r as Ca,s as wa,t as Ta,u as Ea}from"./plugin-view-b7gS6gIn.js";import{i as Da,n as Oa,r as ka}from"./plugin-dashboard-DvBectcr.js";import{i as Aa,l as ja,t as Ma,u as Na}from"./plugin-chatbot-COnH_NZC.js";var Y=e(s(),1),Pa=e(d(),1),X=h();function Fa({children:e,adapter:t}){let[n,r]=(0,Y.useState)(t??null);return(0,Y.useEffect)(()=>{if(t){r(t);return}let e=!1;async function n(){try{let t=new _e({baseUrl:``,fetch:x(),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,X.jsx)(z.Provider,{value:n,children:e})}var Ia=300*1e3,La=[`app`,`view`],Ra={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},za=`objectui:metadata:`;function Ba(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var Va=Ba();function Ha(...e){Va&&console.debug(`[MetadataProvider]`,...e)}function Ua(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function Wa(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Ga(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Ka(e,t){if(!e.length||!t.length)return e;let n={};for(let e of t){let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t)continue;let r=n[t]||={listViews:{},formViews:{}};if(e.list){r.primary=e.list;let t=e.list.name||`list`;r.listViews[t]=e.list}if(e.form&&(r.form=e.form),e.listViews&&typeof e.listViews==`object`)for(let[t,n]of Object.entries(e.listViews))r.listViews[t]=n;if(e.formViews&&typeof e.formViews==`object`)for(let[t,n]of Object.entries(e.formViews))r.formViews[t]=n}return e.map(e=>{let t=n[e.name];if(!t)return e;let r=e.listViews||e.list_views||{},i=e.formViews||e.form_views||{},a={...e,listViews:{...t.listViews,...r}};return(Object.keys(t.formViews).length||Object.keys(i).length)&&(a.formViews={...t.formViews,...i}),t.primary&&!e.list&&(a.list=t.primary),t.form&&!e.form&&(a.form=t.form),a})}function qa(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Ja(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(za+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ya(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(za+e,JSON.stringify(t))}catch{}}function Xa({children:e,adapter:t,ttlMs:n=Ia}){let r=(0,Y.useRef)(new Map),i=(0,Y.useRef)(new Map),a=(0,Y.useRef)(t);a.current=t;let[o,s]=(0,Y.useState)(0),c=(0,Y.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>s(e=>e+1)):Promise.resolve().then(()=>s(e=>e+1))},[]),l=(0,Y.useCallback)(e=>{let t=r.current.get(e);return t||(t=qa(),r.current.set(e,t)),t},[]),u=(0,Y.useCallback)(e=>{let t=l(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return Ha(`cache hit (fresh) type=${e} items=${t.items.length}`),Promise.resolve(t.items);let r=Date.now();t.status=`loading`,t.error=null;let i=a.current.getClient().meta.getItems(e).then(n=>{let i=Ua(n);t.items=i,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of i)Ga(e)&&t.byName.set(e.name,e);return e===`app`&&Ya(e,i),Ha(`fetched type=${e} items=${i.length} in ${Date.now()-r}ms`),c(),i}).catch(n=>{let r=n instanceof Error?n:Error(String(n));return t.status=`error`,t.error=r,t.promise=null,Ha(`fetch failed type=${e}`,r),c(),[]});return t.promise=i,i},[c,l,n]),d=(0,Y.useCallback)((e,t)=>{let n=l(e);if(n.byName.has(t))return Ha(`item cache hit type=${e} name=${t}`),Promise.resolve(n.byName.get(t)??null);let r=i.current.get(e);r||(r=new Map,i.current.set(e,r));let o=r.get(t);if(o)return o;let s=Date.now(),c=a.current.getClient().meta.getItem(e,t).then(i=>{let a=Wa(i);return a&&n.byName.set(t,a),Ha(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Ha(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,c),c},[l]),f=(0,Y.useCallback)(async e=>{if(e){let t=l(e);t.fetchedAt=0,t.byName.clear(),await u(e);return}let t=Array.from(r.current.keys()).filter(e=>r.current.get(e).status!==`idle`);await Promise.all(t.map(e=>{let t=r.current.get(e);return t.fetchedAt=0,t.byName.clear(),u(e)}))},[u,l]),p=(0,Y.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),Ha(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Ha(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,Y.useState)(!0),[g,_]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1,t=Ja(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Ga(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of La)try{await u(t),e||_(null)}catch(t){e||_(t instanceof Error?t:Error(String(t)))}e||h(!1)})(),()=>{e=!0}},[t,u,l,c]);let v=(0,Y.useMemo)(()=>{let e=e=>{let t=l(e);return t.status===`idle`&&u(e),t.items};return{apps:l(`app`).items,get objects(){let t=e(Ra.objects),n=e(`view`);return n.length?Ka(t,n):t},get dashboards(){return e(Ra.dashboards)},get reports(){return e(Ra.reports)},get pages(){return e(Ra.pages)},loading:m,error:g??l(`app`).error,refresh:f,invalidate:p,ensureType:u,getItem:d,getItemsByType:t=>e(t)}},[o,m,g,u,d,l,f,p]);return(0,X.jsx)(se.Provider,{value:v,children:e})}var Za=(0,Y.createContext)(null);function Qa({children:e,user:t={},app:n={},data:r={},features:i={}}){let a=(0,Y.useMemo)(()=>({user:t,app:n,data:r,features:i,evaluator:new fe({user:t,app:n,data:r,features:i})}),[t,n,r,i]),o=(0,Y.useMemo)(()=>({user:t,app:n,data:r,features:i}),[t,n,r,i]);return(0,X.jsx)(Za.Provider,{value:a,children:(0,X.jsx)(N,{scope:o,children:e})})}function $a(){let e=(0,Y.useContext)(Za);if(!e){let e={user:{},app:{},data:{},features:{}};return{...e,evaluator:new fe(e)}}return e}function eo(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 to({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:o,onToast:s}){let c=v(),{appName:l}=a(),{t:u}=L(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=te({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:o,onToast:s});return(0,Y.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,Y.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,Y.useCallback)(async e=>f({type:`delete`,confirmText:u(`objectActions.deleteConfirm`),params:{recordId:e}}),[f,u]),navigateToView:(0,Y.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,Y.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:p,error:m}}var no=(0,Y.createContext)({favorites:null,recent:null}),ro=(0,Y.createContext)(null);function io({children:e}){let[t,n]=(0,Y.useState)({favorites:null,recent:null}),r=(0,Y.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,X.jsx)(ro.Provider,{value:r.current,children:(0,X.jsx)(no.Provider,{value:t,children:e})})}function ao(e){return(0,Y.useContext)(no)[e]}function oo(){let e=(0,Y.useContext)(ro);return(0,Y.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function so(e,t){return t?`${e}:u:${t}`:e}function co(e,t){let n=(0,Y.useRef)(t);n.current=t,(0,Y.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function lo(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var uo=`objectui-recent-items`,fo=8;function po(e){try{let t=localStorage.getItem(so(uo,e));return t?JSON.parse(t):[]}catch{return[]}}function mo(e,t){try{localStorage.setItem(so(uo,t),JSON.stringify(e))}catch{}}var ho=(0,Y.createContext)(null);function go({children:e}){let{user:t}=C(),n=t?.id??null,r=ao(`recent`),[i,a]=(0,Y.useState)(()=>po(n));(0,Y.useEffect)(()=>{a(po(n))},[n]),co(so(uo,n),e=>{a(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,fo):[])});let o=(0,Y.useRef)(0);(0,Y.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 s=(Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`).slice(0,fo);a(s),mo(s,n)}catch{}})(),()=>{t=!0}},[r,n]);let s=(0,Y.useMemo)(()=>lo(async e=>{r&&await r.save(e)},500),[r]);(0,Y.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,Y.useCallback)(e=>{mo(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,Y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,fo);return c(r),r})},[c]),u=(0,Y.useCallback)(()=>{a([]),c([])},[c]),d=(0,Y.useMemo)(()=>({recentItems:i,addRecentItem:l,clearRecentItems:u}),[i,l,u]);return(0,X.jsx)(ho.Provider,{value:d,children:e})}function _o(){return(0,Y.useContext)(ho)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}var vo=(0,Y.createContext)(void 0);function yo({children:e}){let[t,n]=(0,Y.useState)(`home`),[r,i]=(0,Y.useState)(),[a,o]=(0,Y.useState)(),s=(0,Y.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,X.jsx)(vo.Provider,{value:s,children:e})}function bo(){return(0,Y.useContext)(vo)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function xo(e){let{setRecordTitle:t}=bo();(0,Y.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}var So=`objectui-favorites`,Co=`objectui-nav-pins`,wo=20,To=20;function Eo(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>To&&(r=!0)):(t++,t>wo&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<To&&(i.push(t),o++):a<wo&&(i.push(t),a++);return i}function Do(e){try{let t=localStorage.getItem(so(So,e));return t?JSON.parse(t):[]}catch{return[]}}function Oo(e,t){try{localStorage.setItem(so(So,t),JSON.stringify(e))}catch{}}function ko(e){let t;try{t=localStorage.getItem(Co)}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(Co)}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 Ao=(0,Y.createContext)(null);function jo({children:e}){let{user:t}=C(),n=t?.id??null,r=ao(`favorites`),[i,a]=(0,Y.useState)(()=>Do(n));(0,Y.useEffect)(()=>{a(Do(n))},[n]),co(so(So,n),e=>{a(Array.isArray(e)?Eo(e.filter(e=>e&&typeof e.id==`string`)):[])});let o=(0,Y.useRef)(0);(0,Y.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=Eo((Array.isArray(i)?i:[]).filter(e=>e&&typeof e.id==`string`)),l=Do(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=Eo([...c,...d]),p=!0);let{migrated:m,didMigrate:h}=ko(f);h&&(f=Eo(m),p=!0),a(f),Oo(f,n),p&&s.schedule(f)}catch{}})(),()=>{t=!0}},[r,n]),(0,Y.useEffect)(()=>{r||a(e=>{let{migrated:t,didMigrate:r}=ko(e);if(!r)return e;let i=Eo(t);return Oo(i,n),i})},[r,n]);let s=(0,Y.useMemo)(()=>lo(async e=>{r&&await r.save(e)},500),[r]);(0,Y.useEffect)(()=>()=>{s.flush()},[s]);let c=(0,Y.useCallback)(e=>{Oo(e,n),r&&s.schedule(e)},[n,r,s]),l=(0,Y.useCallback)(e=>{a(t=>{if(t.some(t=>t.id===e.id))return t;let n=Eo([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),u=(0,Y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return c(n),n})},[c]),d=(0,Y.useCallback)(e=>{a(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):Eo([{...e,favoritedAt:new Date().toISOString()},...t]);return c(n),n})},[c]),f=(0,Y.useCallback)(()=>{a([]),c([])},[c]),p=(0,Y.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,Y.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,Y.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,X.jsx)(Ao.Provider,{value:h,children:e})}function Mo(){return(0,Y.useContext)(Ao)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}var No=(0,Y.createContext)({theme:`system`,setTheme:()=>null});function Po({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Y.useState)(()=>localStorage.getItem(n)||t);(0,Y.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,X.jsx)(No.Provider,{...r,value:o,children:e})}var Fo=()=>{let e=(0,Y.useContext)(No);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Io(){return(0,X.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Lo({children:e}){return(0,X.jsx)(Po,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,X.jsx)(yo,{children:(0,X.jsx)(io,{children:(0,X.jsx)(jo,{children:(0,X.jsx)(go,{children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(Io,{}),children:e})})})})})})}function Ro({children:e}){return(0,X.jsx)(Fa,{children:(0,X.jsx)(zo,{children:e})})}function zo({children:e}){let t=ge();return t?(0,X.jsx)(A,{dataSource:t,children:(0,X.jsxs)(Xa,{adapter:t,children:[(0,X.jsx)(Bo,{}),e]})}):(0,X.jsx)(Io,{})}function Bo(){let{user:e}=C(),t=ge(),n=oo();return(0,Y.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=V({dataSource:t,userId:e.id,key:`ui.favorites`}),i=V({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 Vo({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r}=C();return r?(0,X.jsx)(Io,{}):((n??[]).length>0||t)&&!t?(0,X.jsx)(p,{to:`/organizations`,replace:!0}):(0,X.jsx)(X.Fragment,{children:e})}function Ho(){let e=u(),t=e.pathname.replace(/^\/system/,``);return(0,X.jsx)(p,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var Uo=(0,Y.lazy)(()=>m(()=>import(`./ConsoleFloatingChatbot-CBIXkoNS.js`),__vite__mapDeps([0]),import.meta.url)),Wo=()=>{m(()=>import(`./ConsoleFloatingChatbot-CBIXkoNS.js`),__vite__mapDeps([0]),import.meta.url)};function Go(e){let[t,n]=(0,Y.useState)(!1);return t?(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Uo,{...e,defaultOpen:!0})}):(0,X.jsx)(`button`,{type:`button`,"aria-label":`Open ${e.appLabel} assistant`,onClick:()=>n(!0),onMouseEnter:Wo,onFocus:Wo,className:`fixed bottom-6 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2`,children:(0,X.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,X.jsx)(`path`,{d:`M12 3v3`}),(0,X.jsx)(`path`,{d:`M12 18v3`}),(0,X.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,X.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,X.jsx)(`path`,{d:`M3 12h3`}),(0,X.jsx)(`path`,{d:`M18 12h3`}),(0,X.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,X.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function Ko(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 qo=new Set(Mn),Jo=new Map;function Yo(e){if(!e)return Dn;let t=Jo.get(e);if(t)return t;let n=Ko(e);if(!qo.has(n))return Jo.set(e,Dn),Dn;let r=e=>Y.createElement(xn,{name:n,fallback:Dn,...e});return r.displayName=`LucideIcon(${e})`,Jo.set(e,r),r}var Xo=20;function Zo(e,t=``){let{href:n,external:r}=ea(e,t);return r?n:!n||n===`#`?``:n}function Qo(e){return`nav:${e}`}function $o(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Mo(),a=(0,Y.useCallback)((e,i,a,o)=>{let s=Qo(e);i?(a&&t({id:s,label:a.label,href:Zo(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,Y.useCallback)(e=>i.has(e),[i]),s=(0,Y.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<Xo;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,Y.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,Y.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}function es(e){let t=`objectui-nav-order-${e}`,[n,r]=Y.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=Y.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Y.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:Y.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function ts({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=on(),i=u(),{t:a}=L(),{objectLabel:o,dashboardLabel:s,navGroupLabel:c,viewLabel:l}=be(),{context:d,currentAppName:f}=bo(),{user:p}=C();Y.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}=_o(),{favorites:h,removeFavorite:g}=Mo(),{apps:_,objects:v}=F(),y=_||[],b=y.filter(e=>e.active!==!1&&e.hidden!==!0),x=y.find(t=>t.name===(e||f)&&t.active!==!1)||b[0],{applyOrder:S,handleReorder:T}=es(x?.name||`home`),{togglePin:E,applyPins:D}=$o(),O=x?.areas||[],[k,A]=Y.useState(()=>O.length>0?O[0].id:null);Y.useEffect(()=>{O.length>0?A(e=>O.some(t=>t.id===e)?e:O[0].id):A(null)},[x?.name,O.length]);let j=O.find(e=>e.id===k)?.navigation||x?.navigation||[],M=Y.useMemo(()=>[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[a]),ee=d===`home`?M:j,te=Y.useMemo(()=>D(S(ee)),[ee,S,D]),[ne,N]=Y.useState(!1),{evaluator:P}=$a(),re=Y.useCallback(e=>eo(e,P),[P]),{can:ie}=w(),I=Y.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return ie(n,r)}),[ie]),ae=Y.useMemo(()=>new Set((v||[]).map(e=>e?.name).filter(Boolean)),[v]),oe=Y.useCallback((e,t)=>e===`object`?ae.size===0?!0:ae.has(t):!0,[ae]),se=d===`app`&&x?`/apps/${x.name}`:``;return(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(ir,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,X.jsx)(Bn,{className:`border-b p-1.5`,children:(0,X.jsx)(Gi,{children:(0,X.jsx)($t,{children:(0,X.jsx)(Vi,{asChild:!0,className:`h-9 text-sm font-medium`,children:(0,X.jsxs)(r,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,X.jsx)(Ae,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,X.jsx)(hr,{className:`pt-2`,children:(0,X.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&x?(0,X.jsxs)(X.Fragment,{children:[O.length>1&&(0,X.jsxs)(Kr,{children:[(0,X.jsxs)(br,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(dr,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,X.jsx)(Cr,{children:(0,X.jsx)(Gi,{children:O.map(e=>{let t=Yo(e.icon);return(0,X.jsx)($t,{children:(0,X.jsxs)(Vi,{isActive:e.id===k,tooltip:e.label,onClick:()=>A(e.id),children:[(0,X.jsx)(t,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,X.jsx)(na,{items:te,basePath:se,evaluateVisibility:re,checkPermission:I,checkCapability:oe,enablePinning:!t,onPinToggle:E,enableReorder:!t,onReorder:T,resolveObjectLabel:(e,t)=>o({name:e,label:t}),resolveDashboardLabel:(e,t)=>s({name:e,label:t}),resolveGroupLabel:x?(e,t)=>c(x.name,e,t):void 0,resolveItemLabel:x?(e,t)=>c(x.name,e,t):void 0,resolveViewLabel:(e,t,n)=>l(e,t,n),t:a,templateContext:{currentUserId:p?.id??null}}),m.length>0&&(0,X.jsxs)(Kr,{children:[(0,X.jsxs)(br,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>N(e=>!e),children:[(0,X.jsx)(Rn,{className:`h-3 w-3 transition-transform duration-150 ${ne?`rotate-90`:``}`}),(0,X.jsx)(di,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),ne&&(0,X.jsx)(Cr,{children:(0,X.jsx)(Gi,{children:m.slice(0,5).map(e=>(0,X.jsx)($t,{children:(0,X.jsx)(Vi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),h.some(e=>e.type!==`nav`)&&(0,X.jsxs)(Kr,{children:[(0,X.jsxs)(br,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Je,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,X.jsx)(Cr,{children:(0,X.jsx)(Gi,{children:h.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,X.jsxs)($t,{children:[(0,X.jsx)(Vi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,X.jsx)(Yn,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,X.jsx)(pt,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Kr,{children:(0,X.jsx)(Cr,{children:(0,X.jsx)(Gi,{children:M.map(e=>{let t=Yo(e.icon),n=i.pathname===e.url;return(0,X.jsx)($t,{children:(0,X.jsx)(Vi,{asChild:!0,tooltip:e.label,isActive:n,children:(0,X.jsxs)(r,{to:e.url||`/home`,children:[(0,X.jsx)(t,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,X.jsxs)(Kr,{children:[(0,X.jsxs)(br,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Je,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,X.jsx)(Cr,{children:(0,X.jsx)(Gi,{children:h.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,X.jsxs)($t,{children:[(0,X.jsx)(Vi,{asChild:!0,tooltip:e.label,children:(0,X.jsxs)(r,{to:e.href,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,X.jsx)(Yn,{showOnHover:!0,onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,X.jsx)(pt,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,X.jsx)(ii,{className:`border-t p-1`,children:(0,X.jsx)(Ii,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function ns(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,Y.useState)(`disconnected`),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),g=(0,Y.useRef)(0),_=(0,Y.useRef)(null),v=(0,Y.useRef)(new Map),y=(0,Y.useRef)([]),b=(0,Y.useRef)(!0),x=(0,Y.useRef)(!1),S=(0,Y.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,Y.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,Y.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,Y.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,Y.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,Y.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,Y.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,Y.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 rs=0;function is(){return rs+=1,`conflict-${Date.now()}-${rs}`}var as=0;function os(){return as+=1,`ver-${Date.now()}-${as}`}function ss(e,t,n){let[r,i]=(0,Y.useState)([]),[a,o]=(0,Y.useState)([]);return{versions:r,currentVersion:(0,Y.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,Y.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:os(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,Y.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:os(),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,Y.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:os(),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,Y.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:os(),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,Y.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,Y.useCallback)(e=>{let t={...e,id:is()};o(e=>[...e,t])},[]),clearHistory:(0,Y.useCallback)(()=>{i([]),o([])},[])}}var cs={sm:24,md:32,lg:40},ls={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function us(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function ds({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=cs[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,Y.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,Y.useMemo)(()=>[...l].reverse(),[l]);return Y.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&Y.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>Y.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?Y.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):us(e.userName),r&&Y.createElement(`span`,{style:{...m,backgroundColor:ls[e.status]}}))))}var fs=Y.createContext({});function ps(){let e=Y.useContext(fs),[t,n]=Y.useState([]);return Y.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function ms(e,t){let n=Y.useContext(fs),[r,i]=Y.useState([]);return Y.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 hs(){let{theme:e,setTheme:t}=Fo(),{t:n}=L();return(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,X.jsx)(un,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,X.jsx)(cn,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,X.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,X.jsxs)($r,{align:`end`,children:[(0,X.jsxs)(Zn,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,X.jsx)(un,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,X.jsxs)(Zn,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,X.jsx)(cn,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,X.jsxs)(Zn,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,X.jsx)(yn,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var gs=[{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 _s(){let{t:e,language:t,changeLanguage:n}=L();return(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,X.jsx)(Se,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,X.jsx)($r,{align:`end`,className:`max-h-72 overflow-y-auto`,children:gs.map(e=>(0,X.jsxs)(Zn,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,X.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var vs={connected:{label:`Connected`,color:`text-green-500`,icon:ri},connecting:{label:`Connecting...`,color:`text-yellow-500`,icon:qr},reconnecting:{label:`Reconnecting...`,color:`text-yellow-500`,icon:qr},disconnected:{label:`Disconnected`,color:`text-muted-foreground`,icon:Ne},error:{label:`Connection Error`,color:`text-destructive`,icon:Ne}};function ys({state:e,className:t}){let n=vs[e],r=n.icon,[i,a]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(e===`connected`){a(!0);let e=setTimeout(()=>a(!1),2e3);return()=>clearTimeout(e)}a(!1)},[e]),e===`connected`&&!i?null:(0,X.jsxs)(`div`,{className:Pn(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:n.label,children:[(0,X.jsx)(r,{className:Pn(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}function bs(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 xs({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:o}){let{t:s}=L(),c=v(),l=a(),{currentAppName:u}=bo(),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(`notifications`),[h,g]=(0,Y.useState)(`unread`),_=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,Y.useRef)(null),[x,S]=(0,Y.useState)(!1);(0,Y.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,Y.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_notification?view=mine`)},T=()=>{f(!1),c(`/apps/setup/sys_activity`)},E=e=>{if(o(e.id),e.source_object&&e.source_id){f(!1);let t=u??l.appName;c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`)}};return(0,X.jsxs)(In,{open:d,onOpenChange:f,children:[(0,X.jsx)(xe,{asChild:!0,children:(0,X.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${x?`motion-safe:animate-bounce`:``}`,"aria-label":y,title:s(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,X.jsx)(rt,{className:`h-4 w-4`}),_>0&&(0,X.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,X.jsxs)(Gt,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:s(`sidebar.inbox`,{defaultValue:`Inbox`})}),p===`notifications`&&t>0&&(0,X.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:s(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,X.jsxs)(H,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,X.jsxs)(xi,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,X.jsxs)(Xr,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(rt,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,X.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,X.jsxs)(Xr,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(En,{className:`h-3.5 w-3.5`}),s(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,X.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,X.jsxs)(Xr,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(Tn,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,X.jsxs)(ur,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,X.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:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,X.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,X.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:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=h===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,X.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`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})}):(0,X.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.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,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:bs(e.created_at)})]})]})})},e.id))})})(),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,X.jsx)(ur,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,X.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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(En,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,X.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:s(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,X.jsx)(q,{size:`sm`,className:`mt-3`,onClick:C,children:s(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,X.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,X.jsxs)(ur,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,X.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:s(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,X.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,X.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,X.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[bs(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function Ss(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 Cs(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 ws(e){let{action:t,context:n={},defaultBaseUrl:r}=e,i=t.params?.objectName??t.objectName??n.objectName,a=t.params?.recordId??t.recordId,o=n.baseUrl??r;return!i||a==null||a===``?{success:!1,error:`navigate_edit: objectName and recordId are required`}:{success:!0,url:`${o}/${i}/record/${encodeURIComponent(String(a))}/edit`}}function Ts(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 Es(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}var Ds=`\0`,Os=`[-\\u2013\\u2014|/·,:]`;function ks(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===``?Ds:(r=!0,String(a))});if(!r)return``;let a=RegExp(`\\s*${Os}\\s*${Ds}`,`g`),o=RegExp(`${Ds}\\s*${Os}\\s*`,`g`);return i=i.replace(a,``).replace(o,``).replace(new RegExp(Ds,`g`),``).replace(/\s+/g,` `).trim(),i}function As(e,t){if(e?.titleFormat){let n=ks(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`}function js({activeAppName:e,onAppChange:t}){let{apps:n}=F(),{t:r}=L(),{appLabel:i}=be(),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,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.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,X.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:Ts(s.label,r)})}),(0,X.jsx)(Ui,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,X.jsxs)($r,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,X.jsx)(Br,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,X.jsx)(wi,{}),o.map(e=>{let n=Yo(e.icon),a=i({name:e.name,label:Ts(e.label,r)}),o=s.name===e.name;return(0,X.jsxs)(Zn,{onClick:()=>t(e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,X.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,X.jsx)(n,{className:`size-3`})}),(0,X.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,X.jsx)(qn,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Ms=(0,Y.createContext)(null);function Ns({children:e}){let[t,n]=(0,Y.useState)(null),r=(0,Y.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,X.jsx)(Ms.Provider,{value:r,children:e})}function Ps(){return(0,Y.useContext)(Ms)?.value??null}function Fs(e){let t=(0,Y.useContext)(Ms),n=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Is(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,Y.useRef)(r);o.current=r;let s=(0,Y.useCallback)(e=>o.current(e),[]);Fs((0,Y.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function Ls(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Rs(){return(0,X.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var zs=[];function Bs({variant:e,appName:t,objects:n,connectionState:i,presenceUsers:o,activities:s,activeAppName:c,onAppChange:l}){let d=e??(t?`app`:`home`),f=d===`app`,p=u(),m=a(),h=v(),{isOnline:g}=ne(),{user:_,signOut:y,isAuthEnabled:b,organizations:x,activeOrganization:S,isOrganizationsLoading:w}=C(),E=ge(),{t:D}=L(),{objectLabel:O,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:M,appLabel:ee}=be(),{apps:te,dashboards:N,pages:P,reports:re}=F(),{currentAppName:ie,recordTitle:I}=bo(),ae=Ps(),[oe,se]=(0,Y.useState)(null),[ce,le]=(0,Y.useState)([]),ue=(0,Y.useRef)(!1),de=(0,Y.useRef)(!1),[fe,pe]=(0,Y.useState)(0),me=(0,Y.useRef)(!1),R=(0,Y.useCallback)(async()=>{if(!E||!f)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!ue.current)try{let t=await E.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(ue.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&se(e)}}catch{}},[E,f]);(0,Y.useEffect)(()=>{R()},[R]),(0,Y.useEffect)(()=>{if(!E||!f||!_?.id||de.current)return;let e=!1,t=null,n=1e4,r=n,i=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`,a=async()=>{try{let t=await E.find(`sys_notification`,{$filter:{recipient_id:_.id},$orderby:{created_at:`desc`},$top:20});if(e)return;Array.isArray(t?.data)&&le(t.data),r=n}catch(e){if(i(e)){de.current=!0;return}r=Math.min(r*2,12e4)}},o=()=>{if(e||de.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await a(),o()},n)},s=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,a().finally(o))};return a().finally(o),typeof document<`u`&&document.addEventListener(`visibilitychange`,s),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,s)}},[E,f,_?.id]),(0,Y.useEffect)(()=>{if(!f||!_?.id||me.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()=>{try{let r=new Set;if(t.length===0)return;for(let n of t){let t=new URLSearchParams({status:`pending`,approverId:n}),i=await fetch(`${e}?${t}`,{credentials:`include`});if(i.status===404){me.current=!0;return}if(!i.ok)return;let a=await i.json().catch(()=>null);for(let e of a?.data||[])r.add(e.id)}n||pe(r.size)}catch{}},a=()=>{n||me.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[f,_?.id]);let he=ce.reduce((e,t)=>e+ +!t.is_read,0),z=(0,Y.useCallback)(async e=>{if(le(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),E)try{await E.update(`sys_notification`,e,{is_read:!0,read_at:new Date().toISOString()})}catch{}},[E]),B=(0,Y.useCallback)(async()=>{let e=ce.filter(e=>!e.is_read);if(!e.length||(le(e=>e.map(e=>({...e,is_read:!0}))),!E))return;let t=new Date().toISOString(),n=e.map(e=>e.id),r=E;if(typeof r.bulkUpdate==`function`)try{await r.bulkUpdate(`sys_notification`,n,{is_read:!0,read_at:t});return}catch{}await Promise.all(e.map(e=>E.update(`sys_notification`,e.id,{is_read:!0,read_at:t}).catch(()=>{})))},[E,ce]),V=ps(),_e=o??(V.length>0?V:zs),H=s??oe??[],ve=w||(x??[]).length>0||!!S,U=p.pathname.split(`/`).filter(Boolean),xe=m.appName||U[1],Se=U[2],W=`/apps/${xe}`,Ce=n??[],Te=c||ie||xe,G=(te||[]).find(e=>e.name===Te),Ee=new Set,De=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ee.add(t.objectName),t.children&&De(t.children)};De(G?.navigation||[]);for(let e of G?.areas||[])De(e.navigation||[]);let Oe=(Ee.size>0?Ce.filter(e=>Ee.has(e.name)):Ce.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:O(e),href:`${W}/${e.name}`})),ke=[];if(f){if(Se===`dashboard`){if(ke.push({label:D(`console.breadcrumb.dashboards`),href:W}),U[3]){let e=U[3],t=(N||[]).find(t=>t.name===e)?.label||Ls(e);ke.push({label:k({name:e,label:t})})}}else if(Se===`page`){if(ke.push({label:D(`console.breadcrumb.pages`),href:W}),U[3]){let e=U[3],t=(P||[]).find(t=>t.name===e)?.label||Ls(e);ke.push({label:A({name:e,label:t})})}}else if(Se===`report`){if(ke.push({label:D(`console.breadcrumb.reports`),href:W}),U[3]){let e=U[3],t=(re||[]).find(t=>t.name===e)?.label||Ls(e);ke.push({label:j({name:e,label:t})})}}else if(Se===`system`)ke.push({label:D(`console.breadcrumb.system`)}),U[3]&&ke.push({label:Ls(U[3])});else if(Se){let e=Ce.find(e=>e.name===Se);if(e){if(ke.push({label:O(e),href:`${W}/${Se}`,siblings:Oe}),U[3]===`record`&&U[4]){let e=U[4].length>12?`${U[4].slice(0,8)}…`:U[4],t=I?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;ke.push({label:n||`#${e}`})}else if(U[3]===`view`&&U[4]){let t=U[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Ls(t),i=M(e.name,t,r);ke.push({label:i})}}}}let Ae=ke[ke.length-1]?.label||t||``;return(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,X.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,X.jsx)(r,{to:`/home`,className:Pn(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,f&&`hidden sm:flex`),title:`ObjectStack`,children:(0,X.jsx)(we,{className:`h-4 w-4`})}),d===`home`&&(0,X.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:`ObjectStack`}),d===`orgs`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Rs,{}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:D(`organizations.title`,{defaultValue:`Organizations`})})]}),f&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Ii,{className:`md:hidden shrink-0 ml-1`,"aria-label":D(`common.toggleSidebar`)||`Toggle sidebar`}),c&&l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(Rs,{})}),(0,X.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(js,{activeAppName:c,onAppChange:l})})]}):t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,X.jsx)(Rs,{})}),(0,X.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,ke.map((e,t)=>{let n=t===ke.length-1;return(0,X.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,X.jsx)(Rs,{}),e.siblings&&e.siblings.length>1?(0,X.jsxs)(Un,{children:[(0,X.jsxs)(Gr,{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,X.jsx)(Ui,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,X.jsxs)($r,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,X.jsx)(Br,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,X.jsx)(wi,{}),e.siblings.map(e=>(0,X.jsx)(Zn,{asChild:!0,children:(0,X.jsx)(r,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,X.jsx)(r,{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,X.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)}),ae&&ae.views.length>0?ae.views.length>1?(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`sm:hidden flex items-center gap-0.5 min-w-0 ml-1 rounded-md px-1.5 py-1 text-sm font-medium hover:bg-accent active:bg-accent/80 transition-colors`,"aria-label":`Switch view`,children:[(0,X.jsx)(`span`,{className:`truncate max-w-[180px]`,children:ae.triggerLabel??ae.views.find(e=>e.id===ae.activeViewId)?.label??Ae}),(0,X.jsx)(Ui,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,X.jsx)($r,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:ae.views.map(e=>{let t=e.id===ae.activeViewId;return(0,X.jsxs)(Zn,{onSelect:()=>{t||ae.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,X.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,X.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,X.jsx)(_i,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,X.jsx)(qn,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,X.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:ae.triggerLabel??ae.views[0].label}):(0,X.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Ae})]})]}),(0,X.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,X.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,X.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),`Offline`]}),f&&i&&(0,X.jsx)(ys,{state:i}),f&&_e.length>0&&(0,X.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:`Users currently online`,children:(0,X.jsx)(ds,{users:_e,size:`sm`,maxVisible:3,showStatus:!0})}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,X.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,X.jsx)(zr,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:D(`console.search`,{defaultValue:`Search…`})}),(0,X.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,X.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,X.jsx)(q,{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":D(`console.search`,{defaultValue:`Search…`}),children:(0,X.jsx)(zr,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,X.jsx)(xs,{notifications:ce,unreadCount:he,pendingApprovalsCount:fe,activities:H,onMarkAllRead:B,onMarkRead:z}),(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":D(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,X.jsx)(r,{to:`/ai`,children:(0,X.jsx)(St,{className:`h-4 w-4`})})}),(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,asChild:!0,"aria-label":D(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,X.jsx)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:(0,X.jsx)(Vr,{className:`h-4 w-4`})})})]}),(0,X.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,X.jsxs)(ye,{className:`h-7 w-7 rounded-full`,children:[(0,X.jsx)(bi,{src:_?.image,alt:_?.name??`User`}),(0,X.jsx)(lr,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:T(_)})]})})}),(0,X.jsxs)($r,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,X.jsx)(Br,{className:`p-0 font-normal`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,X.jsxs)(ye,{className:`h-8 w-8 rounded-lg`,children:[(0,X.jsx)(bi,{src:_?.image,alt:_?.name??`User`}),(0,X.jsx)(lr,{className:`rounded-lg bg-primary text-primary-foreground`,children:T(_)})]}),(0,X.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,X.jsx)(`span`,{className:`truncate font-semibold`,children:_?.name??`User`}),(0,X.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:_?.email??``})]})]})}),(0,X.jsx)(wi,{}),(0,X.jsxs)(mi,{children:[ve&&(0,X.jsxs)(Zn,{onClick:()=>h(`/organizations`),className:`cursor-pointer`,children:[(0,X.jsx)(we,{className:`mr-2 h-4 w-4`}),D(`organizations.mine`,{defaultValue:`My Organizations`})]}),(te||[]).filter(e=>e.active!==!1&&e.hidden===!0).map(e=>{let t=Yo(e.icon),n=ee({name:e.name,label:Ts(e.label,D)});return(0,X.jsxs)(Zn,{onClick:()=>h(`/apps/${e.name}`),className:`cursor-pointer`,children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,X.jsx)(wi,{}),(0,X.jsx)(Br,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:D(`user.preferences`,{defaultValue:`Preferences`})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.theme`,{defaultValue:`Theme`})}),(0,X.jsx)(hs,{})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.language`,{defaultValue:`Language`})}),(0,X.jsx)(_s,{})]}),b&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(wi,{}),(0,X.jsxs)(Zn,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,X.jsx)(ar,{className:`mr-2 h-4 w-4`}),D(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Vs=768,Hs=1024;function Us(){let{setOpen:e,isMobile:t}=on();(0,Y.useEffect)(()=>{function t(){let t=window.innerWidth;t>=Vs&&t<Hs&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}var Ws={cloudUrl:``,singleEnvironment:!1,defaultOrgId:null,defaultEnvironmentId:null,features:{installLocal:!1,marketplace:!0},branding:{productName:`ObjectOS`,productShortName:`ObjectOS`}};function Gs(e){Ws={...Ws,...e,features:{...Ws.features,...e.features??{}},branding:{...Ws.branding,...e.branding??{}}}}async function Ks(e=``){let t=(e||``).replace(/\/+$/,``);try{let e=await fetch(`${t}/api/v1/runtime/config`,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let n=await e.json();if(!n||typeof n!=`object`)return;Gs({cloudUrl:typeof n.cloudUrl==`string`?n.cloudUrl.replace(/\/+$/,``):Ws.cloudUrl,singleEnvironment:!!n.singleEnvironment,defaultOrgId:n.defaultOrgId??Ws.defaultOrgId??null,defaultEnvironmentId:n.defaultEnvironmentId??Ws.defaultEnvironmentId??null,features:n.features?{installLocal:!!n.features.installLocal,marketplace:n.features.marketplace!==!1}:Ws.features,branding:n.branding?{productName:typeof n.branding.productName==`string`&&n.branding.productName.trim()?n.branding.productName.trim():Ws.branding.productName,productShortName:typeof n.branding.productShortName==`string`&&n.branding.productShortName.trim()?n.branding.productShortName.trim():Ws.branding.productShortName}:Ws.branding})}catch{}}function qs(){return Ws}function Js(){return Ws.branding?.productName||`ObjectOS`}function Ys(){return Ws.branding?.productShortName||Js()}function Xs(){return Ws.cloudUrl??``}function Zs({children:e}){return Us(),(0,X.jsx)(X.Fragment,{children:e})}function Qs({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Ts(n?.label)||t,{isAiEnabled:c}=k(),l=c||!1,{setContext:u,setCurrentAppName:d}=bo();return(0,Y.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,X.jsx)(Ns,{children:(0,X.jsxs)(ta,{sidebar:(0,X.jsx)(ts,{activeAppName:t,onAppChange:r}),navbar:(0,X.jsx)(Bs,{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?`${Ts(n.label)} — ${Js()}`:void 0}:void 0,children:[(0,X.jsx)(Zs,{children:e}),l&&(0,X.jsx)(Go,{appLabel:s,objects:i,userId:o})]})})}function $s({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,X.jsxs)(`div`,{style:{"--page-header-accent":i||`hsl(var(--primary))`},className:Pn(`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,X.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,X.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,X.jsx)(`div`,{className:Pn(`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,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,X.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,X.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function ec({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(``),u=v(),{appName:d}=a(),{setTheme:f}=Fo(),{evaluator:p}=$a(),{t:m}=L();(0,Y.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),s(e=>!e))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,Y.useEffect)(()=>{o||l(``)},[o]);let h=`/apps/${d||t?.name}`,{user:g}=C(),_=(0,Y.useMemo)(()=>({currentUserId:g?.id??null}),[g?.id]),y=(0,Y.useCallback)(e=>{s(!1),e()},[]),b=tc(t?.navigation||[]).filter(e=>eo(e.visible??e.visibleOn,p)),{results:x,isSearching:S}=ae({query:c,objects:n,dataSource:i,objectNames:(0,Y.useMemo)(()=>b.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,b.map(e=>e.objectName||``).join(`|`)]),enabled:o&&!!i,getDisplayName:As}),{recentItems:w}=_o(),T=(0,Y.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=o&&c.trim().length===0&&T.length>0;return(0,X.jsxs)(Mt,{open:o,onOpenChange:s,children:[(0,X.jsx)(kr,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,X.jsxs)(Ot,{children:[(0,X.jsx)(Pr,{children:S?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,X.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,X.jsx)(Ce,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,X.jsxs)(xt,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,X.jsx)(zr,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),x.length>0&&(0,X.jsx)(Ce,{heading:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[m(`console.commandPalette.records`,{defaultValue:`Records`}),S&&(0,X.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=Yo(e.icon);return(0,X.jsxs)(xt,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>y(()=>u(`${h}/${e.objectName}/record/${e.recordId}`)),children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.display}),(0,X.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,X.jsx)(Ce,{heading:m(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=Yo(e.icon);return(0,X.jsxs)(xt,{value:`object ${Ts(e.label,m)} ${e.objectName}`,onSelect:()=>y(()=>u(ea(e,h,_).href)),children:[(0,X.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Ts(e.label,m)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,X.jsx)(Ce,{heading:m(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,X.jsxs)(xt,{value:`dashboard ${Ts(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(ea(e,h,_).href)),children:[(0,X.jsx)(er,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Ts(e.label,m)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,X.jsx)(Ce,{heading:m(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,X.jsxs)(xt,{value:`page ${Ts(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(ea(e,h,_).href)),children:[(0,X.jsx)(mt,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Ts(e.label,m)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,X.jsx)(Ce,{heading:m(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,X.jsxs)(xt,{value:`report ${Ts(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(ea(e,h,_).href)),children:[(0,X.jsx)(Pi,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Ts(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Rt,{}),(0,X.jsx)(Ce,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Yo(e.icon);return(0,X.jsxs)(xt,{value:`app ${Ts(e.label,m)} ${e.name}`,onSelect:()=>y(()=>r(e.name)),children:[(0,X.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:Ts(e.label,m)}),e.name===t?.name&&(0,X.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:m(`console.commandPalette.current`)})]},e.name)})})]}),(0,X.jsx)(Rt,{}),(0,X.jsxs)(Ce,{heading:m(`console.commandPalette.preferences`),children:[(0,X.jsxs)(xt,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,X.jsx)(un,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,X.jsxs)(xt,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,X.jsx)(cn,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,X.jsxs)(xt,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,X.jsx)(yn,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,X.jsx)(Rt,{}),(0,X.jsxs)(Ce,{heading:m(`console.commandPalette.actions`),children:[(0,X.jsxs)(xt,{value:`create new app application`,onSelect:()=>y(()=>u(`${h}/create-app`)),children:[(0,X.jsx)(Ni,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.createApp`)})]}),(0,X.jsxs)(xt,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,X.jsx)(zr,{className:`mr-2 h-4 w-4`}),(0,X.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})]})]})]})}function tc(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...tc(n.children)):t.push(n);return t}function nc(){let{t:e}=L(),[t,n]=(0,Y.useState)(!1),r=(0,Y.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,Y.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,X.jsx)(He,{open:t,onOpenChange:n,children:(0,X.jsxs)(nt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:e(`console.shortcuts.title`)}),(0,X.jsx)(gt,{children:e(`console.shortcuts.description`)})]}),(0,X.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,X.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 rc(){return null}var ic={initializing:`Initializing…`,steps:{connecting:`Connecting to server`,loadingConfig:`Loading configuration`,preparingWorkspace:`Preparing workspace`},error:{connectionFailed:`Cannot connect to server`,checkServer:`Please check your network connection or that the backend is running.`},actions:{retry:`Retry`,retrying:`Retrying…`}};function ac({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Y.useState)(0),o=(0,Y.useMemo)(()=>[ic.steps.connecting,ic.steps.loadingConfig,ic.steps.preparingWorkspace],[]);return(0,Y.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,o.length-1))},1200);return()=>clearInterval(n)},[e,t,o.length]),(0,X.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,X.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,X.jsx)(Dn,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,X.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:Js()}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:ic.initializing})]}),t?(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,X.jsx)(Sr,{className:`h-5 w-5 shrink-0`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold`,children:ic.error.connectionFailed})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:ic.error.checkServer})]}),n&&(0,X.jsx)(q,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),ic.actions.retrying]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Oi,{className:`h-4 w-4`}),ic.actions.retry]})})]}):e?(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,X.jsx)(vt,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:o.map((e,t)=>(0,X.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,X.jsx)(ri,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,X.jsx)(qr,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,X.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}function oc(e){let{theme:t=`system`}=Fo();return(0,X.jsx)(Zi,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,icons:{success:(0,X.jsx)(ri,{className:`h-4 w-4`}),info:(0,X.jsx)(Di,{className:`h-4 w-4`}),warning:(0,X.jsx)(jr,{className:`h-4 w-4`}),error:(0,X.jsx)(mn,{className:`h-4 w-4`}),loading:(0,X.jsx)(qr,{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 sc=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function cc({children:e,className:t}){let n=u(),r=Y.useRef(null),i=Y.useRef(n.pathname);return Y.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...sc),e.offsetWidth,e.classList.add(...sc))},[n.pathname]),(0,X.jsx)(`div`,{ref:r,className:[...sc,t??``].filter(Boolean).join(` `),children:e})}var lc=null,uc=null;function dc(){return uc||(uc=(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 m(()=>import(`./vendor-sentry-D5yZpZ5X.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=pc(e.data.url)),e}}),lc=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),uc)}function fc(e,t){if(lc)try{lc.captureException(e,t?{extra:t}:void 0)}catch{}}function pc(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 mc({error:e,onReset:t}){let{t:n}=L();return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,X.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,X.jsx)(jr,{className:`h-6 w-6 text-destructive`})}),(0,X.jsx)(Ki,{children:n(`console.errors.somethingWentWrong`)}),(0,X.jsx)($e,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,X.jsx)(vr,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,X.jsx)(Ae,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var hc=class extends Y.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),fc(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,X.jsx)(mc,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function gc({sections:e,open:t}){if(!t)return null;let{t:n}=L(),[r,i]=(0,Y.useState)([`0`]),[a,o]=(0,Y.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,X.jsxs)(`div`,{className:`w-80 border-l bg-background p-0 overflow-hidden flex flex-col shrink-0 z-20 transition-all`,children:[(0,X.jsxs)(`div`,{className:`px-4 py-3 border-b bg-muted/5 flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:n(`layout.metadata.panelTitle`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60`,children:n(`layout.metadata.jsonBadge`)})]}),(0,X.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,X.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 hover:bg-muted/5 transition-colors`,children:[(0,X.jsxs)(`button`,{onClick:()=>c(i),className:`flex-1 flex items-center justify-between text-left`,children:[(0,X.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:e.title}),o?(0,X.jsx)(Ui,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,X.jsx)(Rn,{className:`h-3 w-3 text-muted-foreground ml-2`})]}),(0,X.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,X.jsx)(qn,{className:`h-3 w-3 text-green-600`}):(0,X.jsx)(Ht,{className:`h-3 w-3 text-muted-foreground`})})]}),o&&(0,X.jsx)(`div`,{className:`px-4 pb-4`,children:(0,X.jsx)(`div`,{className:`relative rounded-md border border-border/50 bg-muted/5 overflow-hidden`,children:(0,X.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 _c(){let[e,t]=(0,Y.useState)((0,Y.useMemo)(()=>{try{return typeof window<`u`?I(window.location.search).enabled:!1}catch{return!1}},[]));return{showDebug:e,toggleDebug:()=>t(e=>!e)}}function vc({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s}){let{t:c}=L(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{e||d(!1)},[e]);let f=(0,Y.useMemo)(()=>({id:`view_${Date.now()}`,label:c(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[],showSearch:!0,showFilters:!0,showSort:!0}),[]),p=(0,Y.useMemo)(()=>({...r}),[n===`create`?`create`:r.id]),{draft:m,isDirty:h,updateField:g,discard:_,undo:v,redo:y,canUndo:b,canRedo:x}=ji(n===`create`?f:p,{mode:n,onUpdate:a});(0,Y.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let S=(0,Y.useMemo)(()=>xa(i),[i.fields]),C=(0,Y.useMemo)(()=>Ea(m.filter),[m.filter]),w=(0,Y.useMemo)(()=>ha(m.sort),[m.sort]),T=(0,Y.useMemo)(()=>Ta({t:c,fieldOptions:S,objectDef:i,updateField:g,filterGroupValue:C,sortItemsValue:w,essentialOnly:!u}),[c,S,i,g,C,w,u]),E=m.type||`grid`,D=(0,Y.useMemo)(()=>({...T,breadcrumb:[c(`console.objectView.page`),pa[E]||E]}),[T,c,E]),O=(0,Y.useCallback)(()=>{n===`create`?s?.(m):o?.(m),_()},[m,o,s,n,_]),k=(0,Y.useCallback)(()=>{if(n===`create`){t();return}_()},[_,n,t]),A=c(n===`create`?`console.objectView.createView`:`console.objectView.configureView`),j=(0,X.jsx)(q,{size:`sm`,variant:u?`secondary`:`ghost`,onClick:()=>d(e=>!e),className:`h-7 w-7 p-0`,"data-testid":`view-config-advanced-toggle`,"aria-pressed":u,title:u?c(`console.objectView.showFewerSettings`,{defaultValue:`Show fewer settings`}):c(`console.objectView.showAdvancedSettings`,{defaultValue:`Show advanced settings`}),children:(0,X.jsx)(pi,{className:`h-3.5 w-3.5`})});return(0,X.jsx)(fn,{open:e,onClose:t,schema:D,draft:m,isDirty:h,onFieldChange:g,onSave:O,onDiscard:k,onUndo:v,onRedo:y,canUndo:b,canRedo:x,undoLabel:c(`designer.undo`),redoLabel:c(`designer.redo`),objectDef:i,saveLabel:c(`console.objectView.save`),discardLabel:c(`console.objectView.discard`),panelRef:l,role:`complementary`,ariaLabel:A,tabIndex:-1,testId:`view-config-panel`,closeTitle:c(`console.objectView.closePanel`),footerTestId:`view-config-footer`,saveTestId:`view-config-save`,discardTestId:`view-config-discard`,headerExtra:j,className:`transition-all overflow-hidden`})}function yc(e){return[{type:`grid`,icon:Si,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:jn,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:rn,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Ri,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:di,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Fn,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:Nn,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Pi,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function bc(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var xc={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:Ca}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:_a},{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:_a},{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:_a},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:ba},{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=>ma(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&wa(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&wa(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:Ca},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function Sc({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=L(),s=(0,Y.useMemo)(()=>yc(o),[o]),c=(0,Y.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,Y.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,Y.useMemo)(()=>a?xa(a):[],[a]),[d,f]=(0,Y.useState)(c[0]?.type??`grid`),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)({});(0,Y.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,Y.useEffect)(()=>{h||m(bc(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=xc[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,Y.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(xc[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,Y.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=va(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,X.jsx)(He,{open:e,onOpenChange:t,children:(0,X.jsxs)(nt,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:o(`console.objectView.createView`)}),(0,X.jsx)(gt,{children:o(`console.objectView.createViewDesc`)})]}),(0,X.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,X.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:Pn(`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,X.jsx)(r,{className:Pn(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,X.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,X.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,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,X.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,X.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:Pn(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,X.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,X.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,X.jsx)(Sr,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,X.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,X.jsx)(sr,{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,X.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,X.jsxs)(qt,{className:`mt-2`,children:[(0,X.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,X.jsx)(q,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var Cc={config:{icon:pi,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:_i,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:ci,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:Tr,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 wc({managedBy:e,label:t,className:n}){if(!e||e===`platform`)return null;let r=Cc[e];if(!r)return null;let i=r.icon,a=t??`better-auth`;return(0,X.jsx)(Pt,{delayDuration:200,children:(0,X.jsxs)(Re,{children:[(0,X.jsx)(Lr,{asChild:!0,children:(0,X.jsxs)(K,{variant:`outline`,"data-testid":`managed-by-badge`,"data-bucket":e,className:Pn(`gap-1 font-normal text-[11px] leading-none py-0.5 px-1.5 cursor-help`,r.tone,n),children:[(0,X.jsx)(i,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:r.short})]})}),(0,X.jsxs)(Fe,{side:`bottom`,align:`start`,className:`max-w-xs text-xs leading-relaxed`,children:[(0,X.jsx)(`p`,{className:`font-semibold mb-1`,children:r.title}),(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:r.body(a)})]})]})})}function Tc({cards:e=6}){return(0,X.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(G,{className:`h-7 w-56`}),(0,X.jsx)(G,{className:`h-4 w-80`})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:Array.from({length:4}).map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,X.jsx)(G,{className:`h-4 w-20`}),(0,X.jsx)(G,{className:`h-8 w-24`}),(0,X.jsx)(G,{className:`h-3 w-16`})]},`stat-${t}`))}),(0,X.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,X.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(G,{className:`h-5 w-32`}),(0,X.jsx)(G,{className:`h-5 w-5 rounded-full`})]}),(0,X.jsx)(G,{className:`h-40 w-full`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(G,{className:`h-3 w-16`}),(0,X.jsx)(G,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Ec({fields:e=8,columns:t=2}){return(0,X.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(G,{className:`h-8 w-8 rounded`}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(G,{className:`h-6 w-48`}),(0,X.jsx)(G,{className:`h-4 w-32`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(G,{className:`h-9 w-20`}),(0,X.jsx)(G,{className:`h-9 w-20`})]})]}),(0,X.jsx)(G,{className:`h-5 w-24`}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 ${t===2?`md:grid-cols-2`:``} gap-4`,children:Array.from({length:e}).map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(G,{className:`h-4 w-24`}),(0,X.jsx)(G,{className:`h-9 w-full`})]},`field-${t}`))}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,X.jsx)(G,{className:`h-5 w-32`}),(0,X.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:3}).map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-3 py-2`,children:[(0,X.jsx)(G,{className:`h-8 w-8 rounded-full`}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,X.jsx)(G,{className:`h-4 w-40`}),(0,X.jsx)(G,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}var Dc={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 Oc(e){let t=Dc[e?.managedBy??`platform`]??Dc.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 kc=new Set([`record:discussion`,`record:chatter`]);function Ac(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`&&kc.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 jc({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,X.jsx)(Gn,{open:e.open,onOpenChange:e=>{e||r()},children:(0,X.jsxs)($n,{children:[(0,X.jsxs)(rr,{children:[(0,X.jsx)(mr,{children:e.options?.title||`Confirm Action`}),(0,X.jsx)(Hr,{children:e.message})]}),(0,X.jsxs)(Ti,{children:[(0,X.jsx)(gi,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,X.jsx)(ti,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function Mc({state:e,onOpenChange:t}){let{t:n}=L(),[r,i]=(0,Y.useState)({}),[a,o]=(0,Y.useState)({});(0,Y.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,X.jsx)(He,{open:e.open,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(nt,{children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:n(`actionDialog.title`)}),(0,X.jsx)(gt,{children:n(`actionDialog.description`)})]}),(0,X.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,X.jsxs)(`div`,{className:`grid gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Ke,{id:e.name,checked:t,onCheckedChange:t=>u(e.name,t===!0),className:`mt-0.5`}),(0,X.jsxs)(Er,{htmlFor:e.name,className:`font-normal cursor-pointer`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]})]}),a[e.name]&&(0,X.jsx)(`p`,{className:`text-xs text-destructive ml-6`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,X.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,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsxs)(Er,{htmlFor:e.name,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,X.jsxs)(Yt,{value:r[e.name]??``,onValueChange:t=>u(e.name,t),children:[(0,X.jsx)(_n,{id:e.name,className:a[e.name]?`border-destructive`:``,children:(0,X.jsx)(Qe,{placeholder:e.placeholder||n(`actionDialog.selectPlaceholder`,{label:e.label})})}),(0,X.jsx)(Xi,{children:e.options.map(e=>(0,X.jsx)(ke,{value:e.value,children:e.label},e.value))})]}):t&&e.referenceTo?(0,X.jsx)(Ei,{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,X.jsx)(Vt,{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,X.jsx)(sr,{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,X.jsx)(sr,{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,X.jsx)(`p`,{className:`text-xs text-destructive`,children:n(`actionDialog.requiredError`,{label:e.label})}),e.helpText&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText}),t&&!e.helpText&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`actionDialog.lookupHelpText`)})]},e.name)})}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:l,children:n(`actionDialog.cancel`)}),(0,X.jsx)(q,{onClick:c,children:n(`actionDialog.confirm`)})]})]})})}var Nc=n(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Pc=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)}})),Fc=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}}})),Ic=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})),Lc=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})),Rc=n((e=>{var t=Pc().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}})),zc=n((e=>{var t=Pc().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Bc=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}})),Vc=n((e=>{var t=Fc(),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}}})),Hc=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]]}})),Uc=n((e=>{var t=Hc();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}})),Wc=n(((e,t)=>{var n=Uc();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})),Gc=n((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Kc=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)}})),qc=n((e=>{var t=Gc(),n=Kc();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}}})),Jc=n((e=>{var t=Pc(),n=Vc(),r=Fc(),i=qc(),a=Gc(),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}})),Yc=n((e=>{var t=Pc(),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}})),Xc=n(((e,t)=>{var n=qc();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})),Zc=n(((e,t)=>{var n=qc(),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})),Qc=n(((e,t)=>{var n=qc();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})),$c=n(((e,t)=>{var n=qc(),r=Pc();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})),el=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)})),tl=n((e=>{var t=qc(),n=Xc(),r=Zc(),i=Qc(),a=$c(),o=Kc(),s=Pc(),c=el();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()))}})),nl=n((e=>{var t=Pc(),n=Fc(),r=Ic(),i=Lc(),a=Rc(),o=zc(),s=Bc(),c=Vc(),l=Wc(),u=Jc(),d=Yc(),f=qc(),p=tl();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)}})),rl=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}}})),il=n((e=>{var t=rl();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)}})),al=n((e=>{var t=rl();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}})),ol=n((e=>{var t=Nc(),n=nl(),r=il(),i=al();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 sl(e,t){if(e!=null)return t.split(`.`).reduce((e,t)=>{if(e!=null)return e[t]},e)}function cl({state:e,onAcknowledge:t}){let{t:n}=L(),{spec:r,data:i}=e,a=(0,Y.useMemo)(()=>r?.fields&&r.fields.length>0?r.fields:[{path:``,label:void 0,format:r?.format??`json`}],[r]);return(0,X.jsx)(He,{open:e.open,onOpenChange:e=>{},children:(0,X.jsxs)(nt,{onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),className:`max-w-lg`,children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:r?.title||n(`actions.resultDialog.defaultTitle`)||`Save this value now`}),r?.description?(0,X.jsx)(gt,{children:r.description}):null]}),(0,X.jsx)(`div`,{className:`space-y-4 py-2`,children:a.map((e,t)=>(0,X.jsx)(ll,{field:e,value:e.path===``?i:sl(i,e.path),defaultFormat:r?.format},`${e.path}-${t}`))}),(0,X.jsx)(qt,{children:(0,X.jsx)(q,{onClick:t,children:r?.acknowledge||n(`actions.resultDialog.acknowledge`)||`I have saved this`})})]})})}function ll({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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[i?(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground/80`,children:i}):null,a===`qrcode`?(0,X.jsx)(fl,{value:t}):null,a===`code-list`?(0,X.jsx)(pl,{value:t}):null,a===`secret`?(0,X.jsx)(ml,{value:t}):null,a===`text`?(0,X.jsx)(hl,{value:t}):null,a===`json`?(0,X.jsx)(gl,{value:t}):null]})}function ul(e){let[t,n]=(0,Y.useState)(!1);return(0,Y.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 dl({value:e,label:t}){let{copy:n,copied:r}=ul(e);return(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:[r?(0,X.jsx)(qn,{className:`w-4 h-4`}):(0,X.jsx)(Ht,{className:`w-4 h-4`}),t?(0,X.jsx)(`span`,{className:`ml-2`,children:t}):null]})}function fl({value:e}){let[t,n]=(0,Y.useState)(null);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,X.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,X.jsx)(`canvas`,{ref:t=>{!t||!e||(0,ol.toCanvas)(t,e,{width:200,margin:1},e=>{e&&n(e.message)})}})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-2 py-1 text-xs font-mono`,children:e}),(0,X.jsx)(dl,{value:e})]})]})}function pl({value:e}){let t=e.join(`
10
- `);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`rounded-md border bg-muted/40 p-2`,children:(0,X.jsx)(`ul`,{className:`space-y-1`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 rounded bg-background px-2 py-1 text-sm font-mono`,children:e}),(0,X.jsx)(dl,{value:e})]},`${t}-${e}`))})}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(dl,{value:t,label:`Copy all`})})]})}function ml({value:e}){let[t,n]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.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,X.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e=>!e),children:t?(0,X.jsx)(Ye,{className:`w-4 h-4`}):(0,X.jsx)(pn,{className:`w-4 h-4`})}),(0,X.jsx)(dl,{value:e})]})}function hl({value:e}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`flex-1 rounded bg-muted px-2 py-1 text-sm font-mono break-all`,children:e}),(0,X.jsx)(dl,{value:e})]})}function gl({value:e}){let t=(0,Y.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-md border bg-muted/40 p-3 text-xs font-mono`,children:t}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsx)(dl,{value:t})})]})}function _l(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 vl(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??_l(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 yl(e,t){return Array.isArray(e)?e.map(e=>vl(e,t)):[]}function bl(){return`${``.replace(/\/$/,``)}/api/v1`}async function xl(e,t){let n=await fetch(`${bl()}${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 Sl(e,t,n){let[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(!0),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)([]),d=(0,Y.useRef)(!1),f=(0,Y.useCallback)(async()=>{if(!(!e||!t)&&!d.current){i(!0);try{let[n,r]=await Promise.all([xl(`/approvals/processes?object=${encodeURIComponent(e)}&activeOnly=true`),xl(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`)]);c(n?.data??[]),u(r?.data??[]),o(!0)}catch(e){e?.status===404&&(d.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,Y.useEffect)(()=>{if(!e||!t){c([]),u([]);return}f()},[e,t,f]);let p=(0,Y.useMemo)(()=>l.find(e=>e.status===`pending`)??null,[l]);return{loading:r,available:a,processes:s,pendingRequest:p,latestRequest:(0,Y.useMemo)(()=>l.length===0?null:[...l].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[l]),canSubmit:a&&s.length>0&&!p,canRecall:!!p&&!!n&&p.submitter_id===n,submit:(0,Y.useCallback)(async n=>{if(!e||!t)throw Error(`Missing object or record`);let r=n?.processName??(s.length===1?s[0].name:void 0),i=await xl(`/approvals/requests`,{method:`POST`,body:JSON.stringify({object:e,recordId:t,...r?{processName:r}:{},...n?.comment?{comment:n.comment}:{}})});return await f(),i},[e,t,s,f]),recall:(0,Y.useCallback)(async e=>{if(!p)throw Error(`No pending request`);let t=await xl(`/approvals/requests/${encodeURIComponent(p.id)}/recall`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...e?.comment?{comment:e.comment}:{}})});return await f(),t.request},[p,n,f]),refresh:f}}var Cl=t({RecordDetailView:()=>Al}),wl={id:`current-user`,name:`Demo User`},Tl=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),El=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),Dl=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],Ol=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function kl(e,t){if(Ol.has(t?.type))return!0;let n=e.toLowerCase();return Dl.some(e=>n===e||n.endsWith(`_${e}`))}function Al({dataSource:e,objects:t,onEdit:n,objectNameOverride:i,recordIdOverride:o,embedded:s}){let c=a(),l=c.appName,d=i??c.objectName,f=o??c.recordId,{showDebug:p}=_c(),{user:m}=C(),h=v(),g=u().state?.from,{t:_}=L(),{objectLabel:y,viewLabel:b,sectionLabel:S,actionLabel:w,actionConfirm:T,actionSuccess:E,fieldLabel:D,fieldOptionLabel:O}=be(),{isFavorite:k,toggleFavorite:A,refreshLabel:j}=Mo(),{addRecentItem:ee}=_o(),[te,ne]=(0,Y.useState)(!0),[N,P]=(0,Y.useState)([]),[F,ie]=(0,Y.useState)([]),[I,ae]=(0,Y.useState)(0),[se,ue]=(0,Y.useState)({}),[de,fe]=(0,Y.useState)(null),[pe,R]=(0,Y.useState)(!1),[ge,z]=(0,Y.useState)(),B=t.find(e=>e.name===d);xo(s?void 0:ge);let V=f,_e=ms(d,V),H=(0,Y.useMemo)(()=>!d||!V?null:{id:`record:${d}:${V}`,label:ge||V||``,href:`/apps/${l}/${d}/record/${V}`,type:`record`},[l,d,V,ge]),ve=H?k(H.id):!1,U=(0,Y.useCallback)(()=>{H&&A(H)},[H,A]),{page:ye,slots:xe}=he(d),Se=(0,Y.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 B?.detail?.renderViaSchema!==!1},[B]),W=(0,Y.useMemo)(()=>ye||!B||!Se&&!xe?null:sa(B,xe?{slots:xe}:void 0),[Se,ye,xe,B]),Ce=ye||W,[we,Te]=(0,Y.useState)(null),[G,Ee]=(0,Y.useState)(`idle`);(0,Y.useEffect)(()=>{let t=!1;if(!Ce||!V||!d||!e?.findOne){Te(null),Ee(`idle`);return}let n=oe(B?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{Ee(`loading`),(r?e.findOne(d,V,r):e.findOne(d,V)).then(e=>{t||(e&&typeof e==`object`?(Te(e),Ee(`loaded`)):(Te(null),Ee(`missing`)))}).catch(()=>{t||(Te(null),Ee(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==d||String(t.recordId)!==String(V)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[Ce,d,V,e,B]),(0,Y.useEffect)(()=>{if(!we||typeof we!=`object`||!B)return;let e=As(B,we);e&&e!==`Untitled`&&e!==ge&&z(e)},[we,B,ge]),(0,Y.useEffect)(()=>{if(!d||!V||!l||!ge)return;let e=`record:${d}:${V}`;ee({id:e,label:ge,href:`/apps/${l}/${d}/record/${V}`,type:`record`}),j(e,ge)},[l,d,V,ge,ee,j]);let[De,Oe]=(0,Y.useState)({open:!1,message:``}),[ke,Ae]=(0,Y.useState)({open:!1,params:[]}),[je,Me]=(0,Y.useState)({open:!1}),Ne=(0,Y.useCallback)((e,t)=>new Promise(n=>{Me({open:!0,spec:e,data:t,resolve:n})}),[]),Pe=(0,Y.useCallback)((e,t)=>new Promise(n=>{Oe({open:!0,message:e,options:t,resolve:n})}),[]),Fe=(0,Y.useCallback)(e=>new Promise(n=>{Ae({open:!0,params:yl(e,{objectName:d||B?.name||``,objects:t||[],fieldLabel:D,fieldOptionLabel:O}),resolve:n})}),[d,B,t,D,O]),Ie=(0,Y.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),Le=(0,Y.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):h(e)},[h]),Re=(0,Y.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(d,V,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(d,V,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(d,V,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(d,V,r);break}let i=t.refreshAfter===!0;return i&&ae(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,d,V]),Be=(0,Y.useMemo)(()=>x(),[]),Ve=(0,Y.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 Be(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:V,objectName:d,params:e.params??{}})}),r=await n.json().catch(()=>null);if(!n.ok||r&&r.success===!1)return{success:!1,error:r?.error||`Flow "${t}" failed (HTTP ${n.status})`};let i=e.refreshAfter!==!1;return i&&ae(e=>e+1),{success:!0,data:r?.data,reload:i}}catch(e){return{success:!1,error:e.message}}},[Be,V,d]),He=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{},r=null;if(e.opensInNewTab)try{r=window.open(`about:blank`,`_blank`,`noopener,noreferrer`)}catch{r=null}try{let i=e.objectName||d||`global`,a=await Be(`/api/v1/actions/${encodeURIComponent(i)}/${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(r)try{r.close()}catch{}return{success:!1,error:e}}let s=e.refreshAfter!==!1;s&&ae(e=>e+1);let c=o?.data;if(c&&typeof c==`object`&&typeof c.redirectUrl==`string`){let e=c.redirectUrl;if(r)try{r.location.href=e}catch{try{r.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`,`noopener,noreferrer`)}catch{t=null}t||(window.location.href=e)}}else if(r)try{r.close()}catch{}return{success:!0,data:c,reload:s}}catch(e){if(r)try{r.close()}catch{}return{success:!1,error:e.message}}},[Be,V,d]),Ue=Sl(d,V,m?.id),We=(0,Y.useRef)(Ue);We.current=Ue;let Ge=(0,Y.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`submit_approval`)await We.current.submit({processName:n.processName,comment:n.comment});else if(t===`recall_approval`)await We.current.recall({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return ae(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Ke=(0,Y.useMemo)(()=>{if(!B||!t)return[];let e=new Set([`created_by`,`updated_by`,`owner_id`]),n=[],r=new Set;for(let i of t)if(i.name!==B.name){for(let[t,a]of Object.entries(i.fields||{}))if(!e.has(t)&&a&&(a.type===`lookup`||a.type===`master_detail`)&&(a.reference_to||a.reference)===B.name){if(r.has(i.name))continue;r.add(i.name),n.push({childObject:i.name,childLabel:i.label||i.name,referenceField:t})}}return n},[B,t]);(0,Y.useEffect)(()=>{if(!e||!V||Ke.length===0)return;let t=!1;return Promise.all(Ke.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,Ke]);let qe=(0,Y.useMemo)(()=>!B||B.name===`sys_audit_log`||B.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[B,t]);(0,Y.useEffect)(()=>{if(!e||!V||!B||!qe){fe(null);return}let t=!1;return R(!0),e.find(`sys_audit_log`,{$filter:{record_id:V,object_name:B.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(B.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||R(!1)}),()=>{t=!0}},[e,V,B,qe]),(0,Y.useEffect)(()=>{if(!e)return;let t=!1,n=m?[{id:String(m.id),label:m.name||m.email||String(m.id),avatarUrl:m.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,m?.id,m?.name,m?.email]);let Je=(0,Y.useMemo)(()=>m?{id:m.id,name:m.name,avatar:m.image}:wl,[m?.id,m?.name,m?.image]);(0,Y.useEffect)(()=>{if(!e||!d||!V)return;let t=`${d}:${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(Je.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)}));P(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{});let r={created:`field_change`,updated:`field_change`,deleted:`field_change`,assigned:`field_change`,shared:`field_change`,system:`system`,completed:`task`,commented:void 0,mentioned:void 0,login:void 0,logout:void 0};e.find(`sys_activity`,{$filter:{object_name:d,record_id: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&&P(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{})},[e,d,V,Je]);let Ye=(0,Y.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Je.name,actorAvatarUrl:`avatar`in Je?Je.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(P(e=>[...e,n]),e){let r=`${d}:${V}`,i=ia(t,F);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Je.id,author_name:Je.name,author_avatar_url:`avatar`in Je?Je.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Je,e,d,V,F]),Xe=(0,Y.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Je.name,actorAvatarUrl:`avatar`in Je?Je.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(P(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${d}:${V}`,a=ia(n,F);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Je.id,author_name:Je.name,author_avatar_url:`avatar`in Je?Je.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Je,e,d,V,F]),Ze=(0,Y.useCallback)((t,n)=>{P(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=Je.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}))},[Je.id,e]);(0,Y.useEffect)(()=>{ne(!0),queueMicrotask(()=>ne(!1))},[d,f]);let Qe=(0,Y.useMemo)(()=>{if(!B)return{type:`detail-view`};let n=B.primaryField||Object.keys(B.fields||{}).find(e=>e===`name`||e===`title`),r=B.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?S(B.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!B.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=B.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${B.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(B.fields||{}).filter(e=>!Tl.has(e)&&!El.has(e)&&!B.fields[e]?.hidden),t=e=>{let t=B.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=>!kl(e,B.fields[e])),r=e.filter(e=>kl(e,B.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:e.map(t)}]:[{showBorder:!1,fields:n.map(t)},{name:`details`,title:S(B.name,`details`,_(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(B.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:w(B.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:T(B.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(B.name,e.name,e.successMessage)}}));return Ue.available&&Ue.processes.length>0&&(Ue.canSubmit&&t.push({name:`submit_approval`,type:`approval`,target:`submit_approval`,label:_(`approvals.submitForApproval`,{defaultValue:`Submit for Approval`}),icon:`send`,variant:`default`,locations:[`record_header`],refreshAfter:!0,successMessage:_(`approvals.submitSuccess`,{defaultValue:`Approval request submitted`}),...Ue.processes.length===1?{params:{processName:Ue.processes[0].name}}:{collectParams:[{name:`processName`,label:_(`approvals.process`,{defaultValue:`Process`}),type:`select`,required:!0,options:Ue.processes.map(e=>({value:e.name,label:e.label||e.name}))},{name:`comment`,label:_(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0}]}}),Ue.canRecall&&t.push({name:`recall_approval`,type:`approval`,target:`recall_approval`,label:_(`approvals.recall`,{defaultValue:`Recall`}),icon:`undo`,variant:`outline`,locations:[`record_header`],refreshAfter:!0,confirmText:_(`approvals.recallConfirm`,{defaultValue:`Recall this pending approval request?`}),successMessage:_(`approvals.recallSuccess`,{defaultValue:`Approval recalled`})})),t})(),o=B.views?.detail?.highlightFields??[],c=B.views?.detail?.sectionGroups??B.views?.form?.sectionGroups,u=l?`/apps/${l}`:``,d=Ke.map(({childObject:n,childLabel:r,referenceField:i})=>{let a=t.find(e=>e.name===n),o=V||``,s=a?y({name:a.name,label:a.label||r}):r,c=()=>{let e=new URLSearchParams({[i]:o}).toString();return`${u}/${n}/new${e?`?${e}`:``}`},l=()=>{let e=new URLSearchParams({[`filter[${i}]`]:o}).toString();return`${u}/${n}${e?`?${e}`:``}`},d=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},f=e=>{let t=e?.id||e?._id;return t?`${u}/${n}/record/${encodeURIComponent(String(t))}`:null},p=u?()=>h(c()):void 0,m=u?()=>h(l()):void 0,g=u?e=>{let t=f(e);t&&h(t)}:void 0,v=u?e=>{let t=d(e);t&&h(t)}:void 0,b=e&&o?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:s,type:`table`,api:n,data:se[n]||[],referenceField:i,icon:a?.icon,displayField:a?.displayNameField||(Array.isArray(a?.compactLayout)?a.compactLayout[0]:void 0),onNew:p,onViewAll:m,onRowClick:g,onRowEdit:v,onRowDelete:b}}),f=Oc(B);return{type:`detail-view`,objectName:B.name,resourceId:V,showBack:!s,onBack:`history`,showEdit:f.edit,title:B.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...qe&&{history:{entries:de??[],loading:pe&&de===null}},...d.length>0&&{related:d},...o.length>0&&{highlightFields:o},...c&&c.length>0&&{sectionGroups:c},...a.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:a}]}}},[B?.name,V,se,I,l,h,e,_,y,t,qe,de,pe,Ue.available,Ue.processes,Ue.canSubmit,Ue.canRecall,Ue.pendingRequest,Ue.latestRequest,s]);if(te)return(0,X.jsx)(Ec,{});if(!B)return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Dn,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:_(`empty.objectNotFound`)}),(0,X.jsx)($e,{children:_(`empty.objectNotFoundDescription`,{name:d})})]})});if(Ce&&G===`missing`)return(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Dn,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:_(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,X.jsx)($e,{children:_(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(Ce){let t=Ce?.disableDiscussion===!0,i=Ac(Ce),a=!t&&!i,o=(()=>{let e=Qe.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),c=(()=>{let t=Oc(B),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:d}}))}}),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(d,V),J.success(_(`detail.deleted`,{defaultValue:`Record deleted`})),h(`${l?`/apps/${l}`:``}/${d}`,{replace:!0})}catch(e){J.error(e?.message||`Delete failed`)}}}),r})(),u=o.length>0?o:void 0,f=Array.isArray(Qe.related)?Qe.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,m=Qe.history?{entries:Qe.history.entries??[],loading:!!Qe.history.loading,emptyText:Qe.history.emptyText}:void 0,v=ye?Ce:sa(B,{sections:Qe.sections,highlightFields:Array.isArray(Qe.highlightFields)?Qe.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:u,related:f,history:m,hideReferenceRail:B?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:B?.detail?.hideRelatedTab===!0||void 0,...xe?{slots:xe}:{}});return(0,X.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,X.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[_e.length>0&&(0,X.jsx)(ds,{users:_e,size:`sm`,maxVisible:3,showStatus:!0}),(0,X.jsx)(wc,{managedBy:B?.managedBy})]}),(0,X.jsx)(le,{objectName:d,recordId:V,data:we,objectSchema:B,dataSource:e,embedded:s,headerSystemActions:c,isFavorite:ve,onToggleFavorite:H?U:void 0,children:(0,X.jsx)(me,{children:(0,X.jsx)(ce,{items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze,mentionSuggestions:F,children:(0,X.jsx)(re,{context:{record:we||{},objectName:d,user:Je},onConfirm:Pe,onToast:Ie,onNavigate:Le,onParamCollection:Fe,onResultDialog:Ne,handlers:{api:Re,flow:Ve,script:He,modal:He,approval:Ge},children:(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[g?.pathname&&g?.label&&(0,X.jsxs)(r,{to:g.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,X.jsx)(ki,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{children:g.label})]}),(0,X.jsx)(M,{schema:v}),a&&(0,X.jsx)(`div`,{className:`mt-6`,children:(0,X.jsx)(ra,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze,mentionSuggestions:F})})]}),(0,X.jsx)(gc,{open:p,sections:[{title:`Page Schema`,data:v}]})]})})})})}),(0,X.jsx)(jc,{state:De,onOpenChange:e=>{e||Oe(e=>({...e,open:!1}))}}),(0,X.jsx)(Mc,{state:ke,onOpenChange:e=>{e||Ae(e=>({...e,open:!1}))}}),(0,X.jsx)(cl,{state:je,onAcknowledge:()=>{je.resolve?.(),Me({open:!1})}})]})}return(0,X.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,X.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[_e.length>0&&(0,X.jsx)(ds,{users:_e,size:`sm`,maxVisible:3,showStatus:!0}),(0,X.jsx)(wc,{managedBy:B?.managedBy})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,X.jsx)(re,{context:{record:{},objectName:d,user:Je},onConfirm:Pe,onToast:Ie,onNavigate:Le,onParamCollection:Fe,onResultDialog:Ne,handlers:{api:Re,flow:Ve,script:He,modal:He,approval:Ge},children:(0,X.jsx)(aa,{schema:Qe,dataSource:e,objectLabel:y({name:B.name,label:B.label}),isFavorite:ve,onToggleFavorite:H?U:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=As(B,e);t&&t!==ge&&t!==`Untitled`&&z(t)},onEdit:()=>{n({id:V})},discussionSlot:(0,X.jsx)(ra,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:N,onAddComment:Ye,onAddReply:Xe,onToggleReaction:Ze})},I)})}),(0,X.jsx)(gc,{open:p,sections:[{title:`View Schema`,data:Qe}]})]}),(0,X.jsx)(jc,{state:De,onOpenChange:e=>{e||Oe(e=>({...e,open:!1}))}}),(0,X.jsx)(Mc,{state:ke,onOpenChange:e=>{e||Ae(e=>({...e,open:!1}))}}),(0,X.jsx)(cl,{state:je,onAcknowledge:()=>{je.resolve?.(),Me({open:!1})}})]})}function jl(e){switch(e){case`system`:return{icon:`Lock`,title:`Nothing here yet`,message:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`};case`append-only`:return{icon:`Archive`,title:`No events recorded`,message:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`};case`better-auth`:return{icon:`ShieldAlert`,title:`No identity records`,message:`Identity rows are managed by the authentication provider. Use the dedicated identity workflows (Invite User, Reset Password, …) to create new entries.`};default:return}}var Ml=(0,Y.lazy)(()=>m(()=>import(`./plugin-charts-C11LxM1X.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),Nl=(0,Y.lazy)(()=>m(()=>import(`./plugin-grid-DtceFt_J.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Pl={grid:gn,kanban:jn,calendar:rn,gallery:Si,timeline:Tn,gantt:zi,map:Ut,chart:Pi},Fl={id:`current-user`,name:`Demo User`};function Il(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 Ll(e,t,n={}){let r=[`kanban`,`calendar`,`timeline`,`gantt`,`gallery`,`map`,`chart`,`grid`],i={};for(let t of r)e[t]&&typeof e[t]==`object`&&Object.assign(i,e[t]);for(let t of[`bulkActions`,`bulkActionDefs`,`rowActions`,`pagination`,`navigation`,`emptyState`,`exportOptions`,`rowHeight`,`isPinned`,`isDefault`,`visibility`,`sortOrder`,`showSort`])e[t]!==void 0&&(i[t]=e[t]);let a=Array.isArray(e.columns)&&e.columns.length>0?e.columns:n.defaultColumns??[],o=e.type||`grid`,s=e.label||e.name||`Untitled View`;return{name:`${s.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,60)||`view`}_${Date.now().toString(36)}`,label:s,object_name:t,view_type:o,columns_json:JSON.stringify(a),filters_json:e.filter?JSON.stringify(e.filter):null,sort_json:e.sort?JSON.stringify(e.sort):null,config_json:Object.keys(i).length>0?JSON.stringify(i):null,page_size:e.pageSize??25,show_search:e.showSearch!==!1,show_filters:e.showFilters!==!1,managed_by:`user`}}function Rl(e){let t=e=>{if(e!=null){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return}}},n=t(e.columns_json)??e.columns,r=t(e.filters_json)??e.filter,i=t(e.sort_json)??e.sort,a=t(e.config_json)??{};return{...e,...a,type:e.view_type??e.type??`grid`,objectName:e.object_name??e.objectName,columns:n,filter:r,sort:i,showSearch:e.show_search??e.showSearch,showFilters:e.show_filters??e.showFilters,pageSize:e.page_size??e.pageSize}}function zl({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=v(),{appName:s,objectName:c,viewId:l}=a(),[d,f]=o(),p=u(),{showDebug:m}=_c(),{t:h}=L(),{objectLabel:g,objectDescription:_,viewLabel:y,viewEmptyState:b,actionLabel:S,actionConfirm:T,actionSuccess:E,fieldLabel:D,fieldOptionLabel:O}=be(),{isFavorite:k,toggleFavorite:A}=Mo(),[j,te]=(0,Y.useState)(!1),[ne,N]=(0,Y.useState)(`edit`),[P,F]=(0,Y.useState)(!1),[ie,I]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(null),se=(0,Y.useRef)({}),ce=(0,Y.useRef)({}),le=(0,Y.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!c||!t)return;let i=ce.current[t]||{};ce.current[t]={...i,...r};let a=se.current[t];a&&clearTimeout(a),se.current[t]=setTimeout(()=>{let r=ce.current[t]||{};delete ce.current[t],delete se.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),ue=(0,Y.useCallback)(t=>{if(oe(t),V(e=>e+1),e?.updateViewConfig){let n=c,r=t.id;n&&r?e.updateViewConfig(n,r,t).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing objectName or viewId.`)}else console.warn(`[ViewConfigPanel] dataSource.updateViewConfig is not available. View config saved locally only.`)},[e,c]),de=(0,Y.useCallback)(async n=>{try{let r;if(e?.create){let i=t?.find?.(e=>e.name===c),a=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),o=[];Array.isArray(i?.compactLayout)&&i.compactLayout.length>0?o=i.compactLayout.filter(e=>i.fields?.[e]):i?.fields&&(o=Object.entries(i.fields).filter(([e,t])=>t&&!t.hidden&&!a.has(e)).map(([e])=>e).slice(0,5));let s=Array.isArray(n.columns)&&n.columns.length>0?n.columns:o,l={...n,columns:s};if(n.type===`kanban`)l.kanban={...l.kanban||{},columns:s};else if(n.type===`gallery`){let e=l.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(l.gallery={...e,visibleFields:s})}if(typeof e?.createView==`function`)r=(await e.createView(c,l))?.name||n?.name;else if(e?.create){let t=Ll(l,c,{defaultColumns:o}),n=await e.create(`sys_view`,t);r=n?.id??n?._id}}te(!1),N(`edit`),V(e=>e+1),r&&(l?i(`../${r}`,{relative:`path`}):i(`view/${r}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,c,t,i,l]),[fe,pe]=(0,Y.useState)(void 0),{user:me,activeOrganization:R}=C(),he=me?.role===`admin`,{can:ge}=w(),z=t.find(e=>e.name===c);if(!z)return(0,X.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(gn,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:h(`console.objectView.objectNotFound`)}),(0,X.jsxs)($e,{children:[h(`console.objectView.objectNotFoundDescription`,{objectName:c}),` `,h(`console.objectView.objectNotFoundHint`)]})]})});let[B,V]=(0,Y.useState)(0),_e=(0,Y.useMemo)(()=>Oc(z),[z]);(0,Y.useEffect)(()=>{r===void 0||r===0||V(e=>e+1)},[r]);let[H,ve]=(0,Y.useState)(!1),[U,ye]=(0,Y.useState)([]);(0,Y.useEffect)(()=>{let t=!1;if(!c){ye([]);return}if(typeof e?.listViews==`function`)return e.listViews(c).then(e=>{t||ye((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||c})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||ye([])}),()=>{t=!0};if(!e?.find){ye([]);return}return e.find(`sys_view`,{$filter:[`object_name`,`=`,c],$orderby:[{field:`created_at`,order:`asc`}],$top:200}).then(e=>{t||ye((Array.isArray(e)?e:Array.isArray(e?.data)?e.data:Array.isArray(e?.records)?e.records:Array.isArray(e?.value)?e.value:[]).filter(e=>e&&(e.object_name===c||e.objectName===c)).map(Rl))}).catch(e=>{console.error(`[ObjectView] Failed to load sys_view records:`,e),t||ye([])}),()=>{t=!0}},[e,c,B]);let[xe,Se]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let t=!1;if(!e||!c){Se({});return}let n=z.listViews||z.list_views||{},r=Object.keys(n),i=z.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){Se({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(c);if(t&&typeof t==`object`){let e={};for(let n of r)t[n]&&(e[n]=t[n]);return e}}catch{}if(typeof e.getView!=`function`)return{};let t=await Promise.all(r.map(async t=>{try{return[t,await e.getView(c,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||Se(e)}),()=>{t=!0}},[e,c,z.listViews,z.list_views,z.list,B]);let W=(0,Y.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(z.compactLayout)&&z.compactLayout.length>0?z.compactLayout.filter(e=>z.fields?.[e]):z.fields?Object.entries(z.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=z.listViews||z.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=xe[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=z.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=xe[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 U){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:${z.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=U.find(t=>(t.id||t._id)===e.id),a=U.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},[z,U,xe,h]),Ce=(0,Y.useMemo)(()=>W.find(e=>e.isDefault)?.id,[W]),we=l||d.get(`view`)||Ce||W[0]?.id,Te=W.find(e=>e.id===we)||W[0],G=ae&&ae.id===Te?.id?{...Te,...ae}:Te,Ee=(0,Y.useCallback)((e,t)=>{oe(n=>({...n||{},id:Te?.id,[e]:t}))},[Te?.id]),De=e=>{let t=W.find(t=>t.id===e);t&&(t.id!==we&&te(!1),l?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Oe=(0,Y.useMemo)(()=>(W||[]).map(e=>{let t=Pl[e.type];return{id:e.id,label:y(z.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,X.jsx)(t,{className:`h-4 w-4`}):void 0}}),[W,z.name,y]);Is({views:Oe,activeViewId:we??``,onChange:De,enabled:Oe.length>0&&!!we});let ke=(0,Y.useCallback)(()=>{F(!0)},[]),Ae=(0,Y.useCallback)((e,t)=>{if(e===`settings`){let e=W.find(e=>e.type===t);e&&De(e.id),N(`edit`),te(!0)}},[W,De]),je=(0,Y.useCallback)(e=>U.some(t=>(t.id||t._id)===e),[U]),Me=(0,Y.useCallback)(async(t,n)=>{if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`?await e.updateView(c,t,{label:n}):e?.update&&await e.update(`sys_view`,t,{label:n}),V(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),J.error(h(`objectViewActions.renameFailed`))}},[e,c,je,h]),[Ne,Pe]=(0,Y.useState)({open:!1,message:``}),[Fe,Ie]=(0,Y.useState)({open:!1,params:[]}),[Le,Re]=(0,Y.useState)({open:!1}),Be=(0,Y.useCallback)((e,t)=>new Promise(n=>{Re({open:!0,spec:e,data:t,resolve:n})}),[]),Ve=(0,Y.useCallback)((e,t)=>new Promise(n=>{Pe({open:!0,message:e,options:t,resolve:n})}),[]),He=(0,Y.useCallback)((e,n)=>new Promise(r=>{let i=n?.params&&!Array.isArray(n.params)?n.params._rowRecord:void 0;Ie({open:!0,params:yl(e,{objectName:c||z?.name||``,objects:t||[],fieldLabel:D,fieldOptionLabel:O,row:i}),resolve:r})}),[c,z,t,D,O]),Ue=(0,Y.useCallback)(async t=>{if(!e)return;if(!je(t)){J.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=W.find(e=>e.id===t)?.label||t;if(await Ve(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(c,t):e?.delete&&await e.delete(`sys_view`,t),t===we){let e=W.find(e=>e.id!==t);e&&i(l?`../${e.id}`:`view/${e.id}`,l?{relative:`path`}:void 0)}V(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),J.error(h(`objectViewActions.deleteFailed`))}},[e,je,we,W,l,i,h,Ve]),We=(0,Y.useCallback)(async t=>{if(!e)return;let n=W.find(e=>e.id===t);if(n)try{let r=`${String(n.name||t).toLowerCase().replace(/[^a-z0-9_]+/g,`_`).replace(/^_+|_+$/g,``)||`view`}_copy_${Date.now().toString(36)}`,{id:a,...o}=n,s={...o,name:r,label:`${n.label||t} (Copy)`,isDefault:!1,isPinned:!1,data:n.data||{provider:`object`,object:c},object:n.object||c},u;if(typeof e?.createView==`function`)u=(await e.createView(c,s))?.name||r;else if(e?.create){let t=Ll(s,c),n=await e.create(`sys_view`,t);u=n?.id??n?._id}V(e=>e+1),u&&(l?i(`../${u}`,{relative:`path`}):i(`view/${u}`))}catch(e){console.error(`[ViewTabBar] Failed to duplicate view:`,e),J.error(`Failed to duplicate view`)}},[e,W,c,i,l]),Ge=(0,Y.useCallback)(async(t,n)=>{if(e){if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`?await e.updateView(c,t,{isPinned:n}):e?.update&&await e.update(`sys_view`,t,{isPinned:n}),V(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,c,je,h]),Ke=(0,Y.useCallback)(async t=>{if(e){if(!je(t)){J.error(h(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to mark a default.`);return}try{let n=typeof e?.updateView==`function`,r=U.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(t=>{let r=t.id||t._id;return n?e.updateView(c,r,{isDefault:!1}):e.update(`sys_view`,r,{isDefault:!1})});r.push(n?e.updateView(c,t,{isDefault:!0}):e.update(`sys_view`,t,{isDefault:!0})),await Promise.all(r),V(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),J.error(`Failed to set default view`)}}},[e,c,U,je,h]),qe=(0,Y.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${c}`,JSON.stringify(t))}catch{}if(e){let n=typeof e?.updateView==`function`,r=new Set(U.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((t,r)=>n?e.updateView(c,t,{sortOrder:r}):e.update?.(`sys_view`,t,{sortOrder:r})).filter(Boolean);try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}V(e=>e+1)},[e,U,c]),Ye=(0,Y.useCallback)(e=>{if(!je(e)){J.error(h(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==we&&De(e),N(`edit`),te(!0)},[we,De,je,h]),Xe=(0,Y.useCallback)(()=>{F(!0)},[]),Ze=me?{id:me.id,name:me.name,avatar:me.image}:Fl,Qe=(0,Y.useCallback)((e,t)=>{t?.type===`error`?J.error(e):J.success(e)},[]),et=to({objectName:z.name,objectLabel:z.label,dataSource:e,onEdit:n,onRefresh:()=>V(e=>e+1),onConfirm:Ve,onToast:Qe}),tt=(0,Y.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):i(e)},[i]),nt=(0,Y.useMemo)(()=>x(),[]),rt=(0,Y.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{},i=typeof n==`string`?n:``;if(i.startsWith(`/`)||/^https?:\/\//i.test(i)){let e={...r},n=e._rowRecord;delete e._rowRecord;let a=i;n&&/\{[a-z_][a-z0-9_]*\}/i.test(a)&&(a=a.replace(/\{([a-z_][a-z0-9_]*)\}/gi,(e,t)=>{let r=n[t];return r==null?``:encodeURIComponent(String(r))}));let o=a.startsWith(`http`)?a:`${a}`,s=t.bodyShape&&typeof t.bodyShape==`object`&&t.bodyShape.wrap?t.bodyShape.wrap:void 0,c=s?{[s]:e}:{...e};if(n&&t.recordIdParam){let e=n[t.recordIdField||`id`];e!=null&&(c[t.recordIdParam]=e)}/\/api\/v1\/auth\//.test(a)&&!c.organizationId&&R?.id&&(c.organizationId=R.id),t.bodyExtra&&typeof t.bodyExtra==`object`&&Object.assign(c,t.bodyExtra);let l=(t.method||`POST`).toUpperCase(),u={method:l,headers:{"Content-Type":`application/json`},credentials:`include`};l!==`GET`&&l!==`DELETE`&&(u.body=JSON.stringify(c));let d=await nt(o,u);if(!d.ok){let e=`HTTP ${d.status}`;try{let t=await d.json();e=t?.error||t?.message||e}catch{}return{success:!1,error:e}}let f=await d.json().catch(()=>({}));return t.refreshAfter!==!1&&V(e=>e+1),{success:!0,data:f,reload:t.refreshAfter!==!1}}typeof e.execute==`function`?await e.execute(z.name,n,r):r.recordId&&Object.keys(r).length>1&&typeof e.update==`function`&&await e.update(z.name,r.recordId,r);let a=t.refreshAfter!==!1;return a&&V(e=>e+1),{success:!0,reload:a}}catch(e){return{success:!1,error:e.message}}},[e,z.name,nt,R]),it=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=e.params||{},r=await nt(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,objectName:z.name,params:n})}),i=await r.json().catch(()=>null);if(!r.ok||i&&i.success===!1)return{success:!1,error:i?.error||`Flow "${t}" failed (HTTP ${r.status})`};let a=e.refreshAfter!==!1;return a&&V(e=>e+1),{success:!0,data:i?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[nt,z.name]),at=(0,Y.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{};try{let r=e.objectName||z.name||`global`,i=await nt(`/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,params:n})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1)return{success:!1,error:a?.error||`Action "${t}" failed (HTTP ${i.status})`};let o=e.refreshAfter!==!1;return o&&V(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[nt,z.name]),{lastMessage:ot}=ns({channel:`object:${z.name}`}),{hasConflicts:st,resolveAllConflicts:ct}=ss(z.name?`user-${z.name}`:`current-user`);(0,Y.useEffect)(()=>{ot&&(st&&ct(`remote`),V(e=>e+1))},[ot,st,ct]),(0,Y.useEffect)(()=>{e?.find&&z.name&&e.find(z.name,{limit:0}).then(e=>{typeof e?.total==`number`?pe(e.total):Array.isArray(e?.data)?pe(e.data.length):Array.isArray(e)&&pe(e.length)}).catch(()=>{})},[e,z.name,B]);let lt=(0,Y.useMemo)(()=>G?.navigation??z.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[G?.navigation,z.navigation]),ut=d.get(`recordId`),dt=(0,Y.useMemo)(()=>{let e=[];return d.forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[d.toString()]),ft=(0,Y.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:p.pathname+(p.search||``),label:y(z.name,G?.name??``,G?.label??``)||g(z)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,l,p.pathname,p.search,z,G?.name,G?.label,y,g]),mt=ee({navigation:lt,objectName:z.name,onNavigate:ft}),ht=()=>{mt.close();let e=new URLSearchParams(d);e.delete(`recordId`),f(e)},gt=(0,Y.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){mt.handleClick(e,t);return}if(mt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),f(e);return}}mt.handleClick(e,t)},[mt,d,f]),_t=(0,Y.useCallback)(()=>{let e=mt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(ht(),ft(t))},[mt.selectedRecord,ft]);(0,Y.useEffect)(()=>{ut&&!mt.isOpen?mt.open({id:ut}):!ut&&mt.isOpen&&mt.close()},[ut]);let vt=(0,Y.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=B+(i||0),o=`${c}-${G.id}-${a}`,s=G;if(s.type===`chart`){let e=s.chart||{};return(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,X.jsx)(Ml,{dataSource:t,schema:{type:`object-chart`,objectName:z.name,chartType:e.chartType,xAxisField:e.xAxisField,yAxisFields:e.yAxisFields,aggregation:e.aggregation,series:e.series,config:e.config,filter:e.filter}})},o)}return(0,X.jsx)(oa,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=Il(s.filter??e.filter,Ze.id);return dt.length?[...Array.isArray(t)?t:[],...dt]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{le(s.id,s,{densityMode:e})},onSortChange:e=>{le(s.id,s,{sort:e})},onFilterChange:e=>{le(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{le(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{le(s.id,s,{columnState:e})},inlineEdit:s.inlineEdit??s.editRecordsInline??e.inlineEdit,appearance:s.showDescription==null?e.appearance:{showDescription:s.showDescription},showSearch:s.showSearch??e.showSearch,showSort:s.showSort??e.showSort,showFilters:s.showFilters??e.showFilters,showHideFields:s.showHideFields??e.showHideFields,showGroup:s.showGroup??e.showGroup,showColor:s.showColor??e.showColor,showDensity:s.showDensity??e.showDensity,allowExport:s.allowExport??e.allowExport,exportOptions:s.allowExport===!1?void 0:s.exportOptions??e.exportOptions,striped:s.striped??e.striped,bordered:s.bordered??e.bordered,color:s.color??e.color,wrapHeaders:s.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:s.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:s.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:s.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:s.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:s.fieldTextColor??e.fieldTextColor,prefixField:s.prefixField??e.prefixField,showDescription:s.showDescription??e.showDescription,navigation:s.navigation??e.navigation,selection:s.selection??e.selection,pagination:s.pagination??e.pagination,searchableFields:s.searchableFields??e.searchableFields,filterableFields:s.filterableFields??e.filterableFields,resizable:s.resizable??e.resizable,rowActions:s.rowActions??e.rowActions,rowActionDefs:Array.isArray(z?.actions)?z.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)):[],bulkActions:s.bulkActions??e.bulkActions,bulkActionDefs:s.bulkActionDefs??e.bulkActionDefs,sharing:s.sharing??e.sharing,addRecord:s.addRecord??e.addRecord,conditionalFormatting:s.conditionalFormatting??e.conditionalFormatting,quickFilters:s.quickFilters??e.quickFilters,userFilters:s.userFilters??e.userFilters,showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,virtualScroll:s.virtualScroll??e.virtualScroll,emptyState:b(z.name,s.name||s.id||``,s.emptyState??e.emptyState??jl(z?.managedBy)),aria:s.aria??e.aria,tabs:e.tabs,...(()=>{let e=Il([...Array.isArray(s.filter)?s.filter:[],...dt],Ze.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...s.sort?.length?{sort:s.sort}:{},options:{kanban:{groupBy:s.kanban?.groupByField||s.kanban?.groupField||`status`,groupField:s.kanban?.groupByField||s.kanban?.groupField||`status`,titleField:s.kanban?.titleField||z.titleField||`name`,cardFields:s.kanban?.columns},calendar:{startDateField:s.calendar?.startDateField||`due_date`,endDateField:s.calendar?.endDateField,titleField:s.calendar?.titleField||`name`,colorField:s.calendar?.colorField,allDayField:s.calendar?.allDayField,defaultView:s.calendar?.defaultView},timeline:{dateField:s.timeline?.dateField||`due_date`,titleField:s.timeline?.titleField||z.titleField||`name`,descriptionField:s.timeline?.descriptionField},map:{locationField:s.map?.locationField,titleField:s.map?.titleField||z.titleField||`name`,latitudeField:s.map?.latitudeField,longitudeField:s.map?.longitudeField,zoom:s.map?.zoom,center:s.map?.center},gallery:{...s.gallery||{},imageField:s.gallery?.imageField||s.gallery?.coverField||`image`,coverField:s.gallery?.coverField||s.gallery?.imageField,titleField:s.gallery?.titleField||z.titleField||`name`,subtitleField:s.gallery?.subtitleField},gantt:{startDateField:s.gantt?.startDateField||`start_date`,endDateField:s.gantt?.endDateField||`end_date`,titleField:s.gantt?.titleField||`name`,progressField:s.gantt?.progressField,dependenciesField:s.gantt?.dependenciesField,colorField:s.gantt?.colorField},chart:{chartType:s.chart?.chartType,xAxisField:s.chart?.xAxisField,yAxisFields:s.chart?.yAxisFields,aggregation:s.chart?.aggregation,series:s.chart?.series,config:s.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&et.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&et.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)=>{gt(e,t)},onSortChange:e=>{le(s.id,s,{sort:e})},onFilterChange:e=>{le(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{le(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{le(s.id,s,{columnState:e})},dataSource:t},o)},[G,z,c,B,mt,et,le,dt]),yt=(0,Y.useMemo)(()=>W.map(e=>e.id===we&&ae&&ae.id===e.id?{...e,...ae}:e),[W,we,ae]),bt=(0,Y.useMemo)(()=>({type:`object-view`,objectName:z.name,layout:`page`,showSearch:G?.showSearch!==!1,showFilters:G?.showFilters!==!1,showSort:G?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:he,viewActions:he?[{type:`settings`},{type:`share`},{type:`duplicate`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:p.pathname+(p.search||``),label:y(z.name,G?.name??``,G?.label??``)||g(z)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[z,n,G?.showSearch,G?.showFilters,G?.showSort,G?.name,G?.label,i,l,he,p.pathname,p.search,y,g]);return(0,X.jsxs)(re,{context:{objectName:z.name,user:Ze,apiBase:``,activeOrganization:R?{id:R.id,slug:R.slug,name:R.name}:null},onConfirm:Ve,onToast:Qe,onNavigate:tt,onParamCollection:He,onResultDialog:Be,handlers:{api:rt,flow:it,script:at,modal:at},children:[(0,X.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)($s,{title:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:g(z)}),(0,X.jsx)(wc,{managedBy:z?.managedBy})]}),description:z.description?_(z):void 0,icon:(0,X.jsx)(Yo(z?.icon),{className:`h-4 w-4`}),actions:(0,X.jsxs)(X.Fragment,{children:[c&&(0,X.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>A({id:`object:${c}`,label:g(z),href:`/apps/${s}/${c}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":k(`object:${c}`),"aria-label":k(`object:${c}`)?h(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):h(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${c}`,children:k(`object:${c}`)?(0,X.jsx)(Je,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,X.jsx)(pt,{className:`h-4 w-4`})}),_e.create&&ge(z.name,`create`)&&(0,X.jsxs)(q,{size:`sm`,onClick:et.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,X.jsx)(Ni,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),_e.import&&ge(z.name,`create`)&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>ve(!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,X.jsx)(Nt,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),z.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,X.jsx)(M,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(z.actions||[]).map(e=>({...e,label:S(z.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:T(z.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(z.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),_e.create&&ge(z.name,`create`)&&(0,X.jsx)(`button`,{type:`button`,onClick:et.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,X.jsx)(Ni,{className:`h-5 w-5`})}),H&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Nl,{open:H,onOpenChange:ve,objectName:z.name,objectLabel:g(z),fields:Object.entries(z.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{V(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}))}})}),W.length>=1&&(()=>{let e=W.map(e=>{let t=U.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(z.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 — duplicate to customize.`:void 0}});return(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,X.jsx)(Sa,{views:e,activeViewId:we,onViewChange:De,viewTypeIcons:Pl,config:{reorderable:!1,showAddButton:he,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:he?Xe:void 0,onRenameView:he?Me:void 0,onDeleteView:he?Ue:void 0,onDuplicateView:he?We:void 0,onPinView:he?Ge:void 0,onSetDefaultView:he?Ke:void 0,onConfigView:he?Ye:void 0,onManageViews:he?()=>I(!0):void 0}),he&&(0,X.jsx)(ga,{open:ie,onOpenChange:I,views:e,activeViewId:we,viewTypeIcons:Pl,onRename:Me,onDelete:Ue,onDuplicate:We,onSetDefault:Ke,onSetPinned:Ge,onReorder:qe,onAddView:Xe,onConfigView:Ye})]})})})(),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[mt.mode===`split`&&mt.isOpen?(0,X.jsx)(Tt,{...mt,setIsOpen:e=>{e||ht()},title:g(z),onExpand:_t,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${z.name}`,mainContent:(0,X.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,X.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,X.jsx)(ya,{schema:bt,dataSource:e,views:yt,activeViewId:we,onViewChange:De,onEdit:e=>n?.(e),onRowClick:(e,t)=>{gt(e,t)},renderListView:vt,onCreateView:ke,onViewAction:Ae})})}),typeof fe==`number`&&(0,X.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:fe})})]}),children:r=>{let i=r.id||r._id;return(0,X.jsx)(Al,{dataSource:e,objects:t,onEdit:n,objectNameOverride:z.name,recordIdOverride:i,embedded:!0})}}):(0,X.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,X.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,X.jsx)(ya,{schema:bt,dataSource:e,views:yt,activeViewId:we,onViewChange:De,onEdit:e=>n?.(e),onRowClick:(e,t)=>{gt(e,t)},renderListView:vt,onCreateView:ke,onViewAction:Ae})})})}),(0,X.jsx)(gc,{open:m&&he,sections:[{title:`View Configuration`,data:G},{title:`Object Definition`,data:z}]}),(0,X.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${j&&he?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,X.jsx)(vc,{open:j&&he,onClose:()=>{te(!1),N(`edit`)},mode:ne,activeView:G,objectDef:z,recordCount:fe,onSave:ue,onViewUpdate:Ee,onCreate:de})}),(0,X.jsx)(Sc,{open:P&&he,onOpenChange:F,existingLabels:W.map(e=>e.label).filter(Boolean),objectDef:z,onCreate:e=>de(e)})]}),mt.mode!==`split`&&(0,X.jsx)(Tt,{...mt,setIsOpen:e=>{e||ht()},title:g(z),onExpand:_t,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${z.name}`,children:r=>{let i=r.id||r._id;return(0,X.jsx)(Al,{dataSource:e,objects:t,onEdit:n,objectNameOverride:z.name,recordIdOverride:i,embedded:!0})}})]}),(0,X.jsx)(jc,{state:Ne,onOpenChange:e=>{e||Pe({open:!1,message:``})}}),(0,X.jsx)(Mc,{state:Fe,onOpenChange:e=>{e||Ie({open:!1,params:[]})}}),(0,X.jsx)(cl,{state:Le,onAcknowledge:()=>{Le.resolve?.(),Re({open:!1})}})]})}var Bl=t({RecordFormPage:()=>Vl});function Vl({mode:e}){let{appName:t,objectName:n,recordId:i}=a(),s=v(),[c]=o(),l=ge(),{objects:u,loading:d}=F(),{t:f}=L(),{objectLabel:p}=be(),{user:m,getAuthConfig:h}=C(),[g,_]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let e=!1;return h().then(t=>{e||_(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[h]);let y=(0,Y.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of c.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,c.toString()]),b=(0,Y.useMemo)(()=>u.find(e=>e.name===n),[u,n]),x=`/apps/${t}`,S=`${x}/${n}`,w=e===`edit`&&i?`${x}/${n}/record/${encodeURIComponent(i)}`:S,T=(0,Y.useCallback)(()=>{typeof window<`u`&&window.history.length>1?s(-1):s(w,{replace:!0})},[s,w]),E=b?p(b):n??``,D=e===`create`?f(`form.createTitle`,{object:E,defaultValue:`New ${E}`}):f(`form.editTitle`,{object:E,defaultValue:`Edit ${E}`}),O=(0,Y.useCallback)(()=>{J.success(e===`create`?f(`form.createSuccess`,{object:E,defaultValue:`${E} created successfully`}):f(`form.updateSuccess`,{object:E,defaultValue:`${E} updated successfully`})),T()},[e,f,E,T]),k=(0,Y.useCallback)(()=>{T()},[T]),A=(0,Y.useMemo)(()=>m?{name:m.name,email:m.email,role:m.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[m]),j=(0,Y.useMemo)(()=>new fe({user:A,app:{name:t},data:{}}),[A,t]),M=(0,Y.useMemo)(()=>b?.fields?Array.isArray(b.fields)?b.fields.filter(e=>typeof e==`string`?!0:eo(e.visible,j)).map(e=>typeof e==`string`?e:e.name):Object.entries(b.fields).filter(([,e])=>eo(e.visible,j)).map(([e])=>e):[],[b,j]);return d?(0,X.jsx)(Ec,{}):b?(0,X.jsx)(Qa,{user:A,app:{name:t},data:{},features:g,children:(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,X.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,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:T,"data-testid":`record-form-page-back`,"aria-label":f(`common.back`,{defaultValue:`Back`}),children:(0,X.jsx)(qe,{className:`h-4 w-4`})}),(0,X.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(r,{to:S,className:`hover:text-foreground transition-colors`,children:E}),(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:D}),(0,X.jsx)(wc,{managedBy:b?.managedBy,className:`ml-1`})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,X.jsx)(fa,{schema:{type:`object-form`,formType:`simple`,objectName:b.name,mode:e,recordId:e===`edit`?i:void 0,...y&&{initialValues:y},title:D,description:e===`create`?f(`form.createDescription`,{object:E,defaultValue:`Create a new ${E}.`}):f(`form.editDescription`,{object:E,defaultValue:`Edit this ${E}.`}),layout:`vertical`,fields:M,onSuccess:O,onCancel:k,showSubmit:!0,showCancel:!0,submitText:f(`form.saveRecord`,{defaultValue:`Save`}),cancelText:f(`common.cancel`,{defaultValue:`Cancel`})},dataSource:l??void 0},`${e}:${n}:${i??`new`}`)})})]})}):(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Dn,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:f(`empty.objectNotFound`)}),(0,X.jsx)($e,{children:f(`empty.objectNotFoundDescription`,{name:n})}),(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsxs)(q,{variant:`outline`,onClick:()=>s(x),children:[(0,X.jsx)(qe,{className:`mr-2 h-4 w-4`}),f(`empty.back`)]})})]})})}var Hl=t({DashboardView:()=>Ql}),Ul=[{type:`metric`,label:`KPI Metric`,Icon:Ct},{type:`bar`,label:`Bar Chart`,Icon:Pi},{type:`line`,label:`Line Chart`,Icon:Me},{type:`pie`,label:`Pie Chart`,Icon:Zt},{type:`table`,label:`Table`,Icon:Ze},{type:`pivot`,label:`Pivot`,Icon:Si}],Wl=0;function Gl(){return Wl+=1,`widget_${Date.now()}_${Wl}`}function Kl(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:Gl()})}}function ql(e){let t=Ul.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}var Jl=new Set([`title`,`description`,`type`,`object`,`categoryField`,`valueField`,`aggregate`,`colorVariant`,`actionUrl`,`layoutW`,`layoutH`,`id`,`searchable`,`pagination`,`drillDownEnabled`,`drillDownTarget`]);function Yl(e){let t=e.options??{},n=t.drillDown??{};return{...t,title:e.title??``,description:e.description??``,type:e.type??`metric`,object:e.object??``,categoryField:e.categoryField??t.categoryField??``,valueField:e.valueField??t.valueField??``,aggregate:e.aggregate??t.aggregate??`count`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1,colorVariant:e.colorVariant??t.colorVariant??`default`,actionUrl:e.actionUrl??t.actionUrl??``,searchable:e.searchable??t.searchable??!1,pagination:e.pagination??t.pagination??!1,drillDownEnabled:n.enabled??!1,drillDownTarget:n.target??`drawer`}}function Xl(e,t){let n=t.options??{},r={...n};for(let[t,n]of Object.entries(e))Jl.has(t)||n!==void 0&&(r[t]=n);let i=e.drillDownEnabled,a=e.drillDownTarget;return(i!==void 0||a!==void 0)&&(r.drillDown={...n.drillDown||{},...i===void 0?{}:{enabled:!!i},...a===void 0?{}:{target:a}}),{title:e.title,description:e.description,type:e.type,object:e.object,categoryField:e.categoryField,valueField:e.valueField,aggregate:e.aggregate,layout:{...t.layout||{},w:e.layoutW,h:e.layoutH},colorVariant:e.colorVariant,actionUrl:e.actionUrl,...e.searchable===void 0?{}:{searchable:!!e.searchable},...e.pagination===void 0?{}:{pagination:!!e.pagination},...Object.keys(r).length>0?{options:r}:{}}}function Zl(e){let t=e??{};return{columns:t.columns??3,gap:t.gap??4,rowHeight:String(t.rowHeight??`120`),refreshInterval:String(t.refreshInterval??`0`),title:t.title??``,description:t.description??``,showDescription:t.showDescription??!0,theme:t.theme??`auto`}}function Ql({dataSource:e}){let{dashboardName:t}=a(),{showDebug:n}=_c(),r=ge(),{t:i}=L(),{dashboardLabel:o,dashboardDescription:s}=be(),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(0),[g,_]=(0,Y.useState)(null),v=(0,Y.useCallback)(e=>{_(t=>(t&&t.resolve(e),null))},[]),y=(0,Y.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;_({schema:n,resolve:t})}),[]),b=(0,Y.useMemo)(()=>({export_dashboard_pdf:async()=>{J.info(i(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return J.error(i(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(J.info(i(`dashboardActions.forecastSoon`)),{success:!0})}),[i]);(0,Y.useEffect)(()=>{l(!0),E(null),d(!1),p(null),queueMicrotask(()=>l(!1))},[t]);let{dashboards:x,objects:S,refresh:C}=F(),w=x?.find(e=>e.name===t),[T,E]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{u||E(null)},[w]);let D=(0,Y.useCallback)(async e=>{try{r&&r.updateDashboard?await r.updateDashboard(t,e):r&&await r.update(`sys_dashboard`,t,e),C().catch(()=>{})}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`[DashboardView] Auto-save failed:`,e),J.error(`Failed to save dashboard: ${t}`)}},[r,t,C]),O=(0,Y.useCallback)(()=>{E(Kl(w)),d(!0),h(e=>e+1)},[w]),k=(0,Y.useCallback)(()=>{d(!1),p(null)},[]),A=(0,Y.useCallback)(e=>{if(!T)return;let t=Gl(),n={id:t,title:ql(e),type:e,layout:{x:0,y:T.widgets?.length??0,w:T.columns??2,h:1}},r={...T,widgets:[...T.widgets||[],n]};E(r),D(r),p(t),h(e=>e+1)},[T,D]),j=(0,Y.useCallback)(e=>{if(!T)return;let t={...T,widgets:T.widgets.filter(t=>t.id!==e)};E(t),D(t),f===e&&p(null)},[T,f,D]),M=(0,Y.useCallback)(e=>{let t=T||w;if(!t)return;let n={...t,widgets:e};E(n),D(n)},[T,w,D]),ee=(0,Y.useMemo)(()=>Zl(T||w),[m]),te=(0,Y.useCallback)(e=>{if(!T)return;let t=(e,t)=>{let n=Number(e);return Number.isFinite(n)?n:t},n={...T,columns:t(e.columns,T.columns),gap:t(e.gap,T.gap),rowHeight:t(e.rowHeight,T.rowHeight),refreshInterval:t(e.refreshInterval,0)??0,title:e.title,description:e.description,showDescription:e.showDescription,theme:e.theme};E(n),D(n),h(e=>e+1)},[T,D]),ne=(0,Y.useCallback)((e,t)=>{T&&E(n=>{if(!n)return n;if(new Set([`columns`,`gap`,`rowHeight`,`refreshInterval`]).has(e)){let r=Number(t);return{...n,[e]:Number.isFinite(r)?r:n[e]}}return{...n,[e]:t}})},[T]),N=T?.widgets?.find(e=>e.id===f),P=(0,Y.useMemo)(()=>N?Yl(N):{},[f,m]),re=(0,Y.useCallback)(e=>{if(!T||!f||!N)return;let t=Xl(e,N),n={...T,widgets:T.widgets.map(e=>e.id===f?{...e,...t}:e)};E(n),D(n),h(e=>e+1)},[T,f,N,D]),ie=(0,Y.useCallback)((e,t)=>{f&&E(n=>{if(!n)return n;let r=n.widgets?.find(e=>e.id===f);if(!r)return n;let i=Yl(r);i[e]=t;let a=Xl(i,r);return{...n,widgets:n.widgets.map(e=>e.id===f?{...e,...a}:e)}})},[f]),I=(0,Y.useMemo)(()=>{if(S?.length)return S.map(e=>({value:e.name,label:e.label||e.name}))},[S]),ae=(0,Y.useMemo)(()=>{let e=N?.object;if(!e||!S?.length)return;let t=S.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.filter(e=>e.name).map(e=>({value:e.name,label:e.label||e.name})):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e}))},[N?.object,S]),oe=(0,Y.useMemo)(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),se=T||w,ce=(0,Y.useMemo)(()=>{if(!se||oe.size===0)return se;let e=se.widgets;if(!Array.isArray(e)||e.length===0)return se;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?oe.has(t):!0});return t.length===e.length?se:{...se,widgets:t}},[se,oe]);return c?(0,X.jsx)(Tc,{}):w?(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,X.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,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=Ts((ce||w).title,i),t=Ts(w.label,i),n=o({name:w.name,label:t});return(0,X.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||w.name})})(),(()=>{let e=(ce||w).description??w.description,t=s({name:w.name,description:Ts(e,i)});return t?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,X.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[u&&(0,X.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:Ul.map(({type:e,label:t,Icon:n})=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>A(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,X.jsx)(Ni,{className:`h-3 w-3`}),(0,X.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,X.jsxs)(`button`,{type:`button`,onClick:O,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,X.jsx)(W,{className:`h-3.5 w-3.5`}),i(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,X.jsx)(Da,{schema:ce,dataSource:e,designMode:u,selectedWidgetId:f,onWidgetClick:p,onWidgetsReorder:M,modalHandler:y,scriptHandlers:b,hideHeaderText:!0})}),N?(0,X.jsx)(Oa,{open:u,onClose:k,config:P,onSave:re,onFieldChange:ie,availableObjects:I,availableFields:ae,headerExtra:(0,X.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>j(f),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"data-testid":`widget-delete-button`,title:`Delete widget`,children:(0,X.jsx)(kt,{className:`h-3.5 w-3.5`})})},f):(0,X.jsx)(ka,{open:u,onClose:k,config:ee,onSave:te,onFieldChange:ne}),(0,X.jsx)(gc,{open:n,sections:[{title:`Dashboard Configuration`,data:ce}]})]}),g&&g.schema?.objectName?(0,X.jsx)(ua,{schema:{type:`object-form`,formType:`modal`,objectName:g.schema.objectName,mode:g.schema.mode||`create`,recordId:g.schema.recordId,title:g.schema.title,description:g.schema.description,fields:g.schema.fields,open:!0,onOpenChange:e=>{e||v({success:!1})},onSuccess:e=>{v({success:!0,reload:!0,data:e})},onCancel:()=>{v({success:!1})},showSubmit:!0,showCancel:!0},dataSource:r}):g?(0,X.jsx)(He,{open:!0,onOpenChange:e=>{e||v({success:!1})},children:(0,X.jsxs)(nt,{children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:g.schema?.title||i(`actionDialog.defaultActionTitle`)}),g.schema?.description&&(0,X.jsx)(gt,{children:g.schema.description})]}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:()=>v({success:!1}),children:i(`actionDialog.cancel`)}),(0,X.jsx)(q,{onClick:()=>v({success:!0}),children:i(`actionDialog.ok`)})]})]})}):null]}):(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(er,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:i(`empty.dashboardNotFound`)}),(0,X.jsx)($e,{children:i(`empty.dashboardNotFoundDescription`,{name:t})})]})})}var $l=t({PageView:()=>eu});function eu(){let{t:e}=L(),{pageName:t}=a(),[n]=o(),{showDebug:r}=_c(),{pages:i}=F(),s=i?.find(e=>e.name===t);if(!s)return(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(mt,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:e(`empty.pageNotFound`)}),(0,X.jsx)($e,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let c=Object.fromEntries(n.entries());return(0,X.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:(0,X.jsx)(M,{schema:{...s,type:s.type||`page`,context:{...s.context,params:c}}})}),(0,X.jsx)(gc,{open:r,sections:[{title:`Page Configuration`,data:s}]})]})}var tu=t({ReportView:()=>ou}),nu=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),ru=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),iu=(0,Y.lazy)(()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0]),import.meta.url)),au=[{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 ou({dataSource:e}){let{t}=L(),{reportName:n}=a(),{showDebug:r}=_c(),i=ge(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(0),{reports:u,objects:d,loading:f,refresh:p}=F(),m=u?.find(e=>e.name===n),[h,g]=(0,Y.useState)(m),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),C=(0,Y.useCallback)(e=>{if(!e||!d?.length)return;let t=d.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`}))},[d]),w=(0,Y.useMemo)(()=>{let e=_||h;return C(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??au},[_,h,C]),T=(0,Y.useCallback)(async e=>{try{i&&(await i.update(`sys_report`,n,e),p().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,n,p]),E=(0,Y.useCallback)(()=>{v(h),s(!0),l(e=>e+1)},[h]),D=(0,Y.useCallback)(()=>{s(!1)},[]),O=(0,Y.useMemo)(()=>_||h,[c]),k=(0,Y.useCallback)(e=>{v(e),T(e),l(e=>e+1)},[T]),A=(0,Y.useCallback)((e,t)=>{v(n=>({...n,[e]:t}))},[]);(0,Y.useEffect)(()=>{g(m)},[m]),(0,Y.useEffect)(()=>{o||v(null)},[m]);let j=_||h,M=(0,Y.useMemo)(()=>JSON.stringify(j?.filters),[j?.filters]),ee=(0,Y.useMemo)(()=>JSON.stringify(j?.dataSource),[j?.dataSource]),te=(0,Y.useMemo)(()=>JSON.stringify(j?.data),[j?.data]);if((0,Y.useEffect)(()=>{if(!j||!e){b([]);return}if(j.data&&Array.isArray(j.data)){b(j.data);return}if(j.dataSource){(async()=>{S(!0);try{let t=j.dataSource.object||j.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),b([]);return}b((await e.find(t,{$filter:j.dataSource.filter,$orderby:j.dataSource.sort,$top:j.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),b([])}finally{S(!1)}})();return}if(j.objectName){(async()=>{S(!0);try{b((await e.find(j.objectName,{$filter:j.filters,$orderby:j.sort,$top:j.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),b([])}finally{S(!1)}})();return}b([])},[j?.objectName,j?.limit,M,ee,te,e]),f)return(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsx)(qr,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!m||!h)return!f&&!m?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,X.jsx)(Pi,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsx)(Ki,{children:t(`empty.reportNotFound`)}),(0,X.jsx)($e,{children:t(`empty.reportNotFoundDescription`,{name:n})})]})}):(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,X.jsx)(qr,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let ne=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?d?.find(e=>e.name===n):null,i=Array.isArray(r?.fields)?r.fields:r?.fields?Object.entries(r.fields).map(([e,t])=>({name:e,...t})):[],a={};for(let e of i)e&&e.name&&(a[e.name]=e);let o=e=>{let t=e.name||e.field,n=t?a[t]:void 0;if(!n)return e;let r={...e};if(r.type===void 0&&n.type!==void 0&&(r.type=n.type),r.options===void 0&&Array.isArray(n.options)&&(r.options=n.options),r.referenceTo===void 0){let e=n.referenceTo||n.reference?.to||n.target;e&&(r.referenceTo=e)}return r.label===void 0&&n.label&&(r.label=n.label),r};if(!t.fields&&Array.isArray(t.columns)?t.fields=t.columns.map(e=>{let t=o(e);return{name:t.field||t.name,label:t.label,type:t.type,options:t.options,referenceTo:t.referenceTo,format:t.format,renderAs:t.renderAs,colorMap:t.colorMap,...t.aggregate?{aggregation:t.aggregate,showInSummary:!0}:{}}}):Array.isArray(t.fields)&&(t.fields=t.fields.map(o)),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.type||t.reportType||`tabular`,i=[];(r===`summary`||n)&&i.push({type:`summary`,title:`Key Metrics`}),i.push({type:`table`,title:`Details`,columns:t.fields.map(e=>({name:e.name,label:e.label,type:e.type,options:e.options,referenceTo:e.referenceTo,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))});let a=t.chart||t.chartConfig,o=a?.type||a?.chartType;if(o){let e=a.xAxis||a.xAxisField,t=a.yAxis||a.yAxisFields?.[0];i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:o,xAxisField:e,yAxisFields:t?[t]:a.yAxisFields}})}if(Array.isArray(e.sections)){let t=e.sections.filter(e=>e.type===`chart`&&!o);i.push(...t)}t.sections=i}else t.sections||=[];return t},N=_||h,P=!!(N&&N.objectName&&(N.type===`matrix`||N.type===`joined`||N.type===`summary`||N.type===`tabular`||N.type===void 0||Array.isArray(N.groupingsAcross)&&N.groupingsAcross.length>0||Array.isArray(N.columns))),re={type:`report-viewer`,report:ne(N),data:y,showToolbar:!0,allowExport:!0,loading:x};return(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,X.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,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:N.title||N.label||`Report Viewer`}),N.description&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:N.description})]}),(0,X.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:E,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`report-edit-button`,children:[(0,X.jsx)(W,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,X.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,X.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:P?(0,X.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,X.jsx)(ru,{schema:N,dataSource:e})}):(0,X.jsx)(nu,{schema:re})})})}),(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(iu,{open:o,onClose:D,config:O,onSave:k,onFieldChange:A,availableFields:w,getFieldsForObject:C})}),(0,X.jsx)(gc,{open:r,sections:[{title:`Report Configuration`,data:N}]})]})]})}var su=t({SearchResultsPage:()=>du});function cu(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...cu(n.children)):t.push(n);return t}var lu={object:Dn,dashboard:er,page:mt,report:Pi},uu={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 du(){let{t:e}=L(),{appName:t}=a(),[n,i]=o(),[s,c]=(0,Y.useState)(n.get(`q`)||``),{apps:l}=F(),u=l||[],d=u.find(e=>e.name===t)||u[0],f=`/apps/${t}`,{user:p}=C(),m=(0,Y.useMemo)(()=>{if(!d)return[];let e=cu(d.navigation||[]),t={currentUserId:p?.id??null};return e.map(e=>{let{href:n}=ea(e,f,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!==`#`)},[d,f,p?.id]),h=(0,Y.useMemo)(()=>{if(!s.trim())return m;let e=s.toLowerCase();return m.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[m,s]),g=e=>{c(e),i(e?{q:e}:{})},_=(0,Y.useMemo)(()=>{let e={};for(let t of h)(e[t.type]||=[]).push(t);return e},[h]);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(r,{to:f,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,X.jsx)(qe,{className:`h-4 w-4`}),e(`search.back`)]}),(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`search.title`)})]}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:e(`search.placeholder`)}),(0,X.jsx)(zr,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsx)(sr,{id:`search-results-input`,value:s,onChange:e=>g(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s.trim()?e(h.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:h.length,query:s}):e(`search.itemsAvailable`,{count:m.length})}),h.length===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,X.jsx)(zr,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,X.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:e(`search.noResults`)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:e(`search.noResultsHint`)})]}):(0,X.jsx)(`div`,{className:`space-y-6`,children:Object.entries(_).map(([t,n])=>{let i=lu[t]||Dn,a=`search.type${t.charAt(0).toUpperCase()}${t.slice(1)}s`;return`${t.charAt(0).toUpperCase()}${t.slice(1)}`,(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,X.jsx)(i,{className:`h-4 w-4`}),e(a),(0,X.jsx)(K,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,X.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=lu[t.type]||Dn,i=`search.badge${t.type.charAt(0).toUpperCase()}${t.type.slice(1)}`;return(0,X.jsx)(r,{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,X.jsx)(dt,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,X.jsxs)(si,{className:`flex items-center gap-3 p-3`,children:[(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${uu[t.type]||``}`,children:(0,X.jsx)(n,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium truncate`,children:t.label}),t.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:t.description})]}),(0,X.jsx)(K,{variant:`outline`,className:`text-xs shrink-0`,children:e(i)})]})})},t.id)})})]},t)})})]})}function fu(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 pu(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 mu=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=fu(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(pu)};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 hu(){let e=ge();return(0,Y.useMemo)(()=>e?new mu(e):null,[e])}var gu=0;function _u(e=`nav`){return`${e}_${Date.now()}_${++gu}`}function vu(e,t){return[...e,t]}function yu(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:yu(e.children,t,n)}:e)}function bu(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:bu(i.children,t,n,r)}:i})}function xu(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Su(){let e=ge(),{apps:t,refresh:n}=F(),{t:r}=L(),i=(0,Y.useRef)(e);i.current=e;let a=(0,Y.useRef)(n);a.current=n;let o=(0,Y.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,Y.useCallback)(e=>t.find(t=>t.name===e),[t]),c=(0,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=vu(a,{id:_u(`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,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=vu(a,{id:_u(`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,Y.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=yu(i,`page`,t);if(xu(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,Y.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=yu(i,`dashboard`,t);if(xu(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,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=bu(a,`page`,t,n);if(xu(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,Y.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=bu(a,`dashboard`,t,n);if(xu(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,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Y.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Y.useCallback)(async e=>{for(let n of t){let t=m(n);t&&await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,Y.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&await p(t,e,n)}},[t,p])}}function Cu(){let{pages:e,dashboards:t,apps:n}=F(),r=ge(),i=(0,Y.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=Su(),l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),d=(0,Y.useRef)(0),f=(0,Y.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Y.useEffect)(()=>{if(f.current)return;let r=new Set((e??[]).map(e=>e.name).filter(Boolean)),i=new Set((t??[]).map(e=>e.name).filter(Boolean)),m=l.current,h=u.current;if(m===null||h===null){l.current=r,u.current=i;return}let g=[...r].filter(e=>!m.has(e)),_=[...m].filter(e=>!r.has(e)),v=[...i].filter(e=>!h.has(e)),y=[...h].filter(e=>!i.has(e));if(g.length===0&&_.length===0&&v.length===0&&y.length===0){l.current=r,u.current=i;return}let b=++d.current;f.current=!0;let x=!1;return(async()=>{try{for(let e of n){if(x||d.current!==b)break;let t=p(e);if(t){for(let e of g){if(x)break;await a(t,e)}for(let e of _){if(x)break;await s(t,e)}for(let e of v){if(x)break;await o(t,e)}for(let e of y){if(x)break;await c(t,e)}}}}finally{d.current===b&&(l.current=r,u.current=i,f.current=!1)}})(),()=>{x=!0}},[e,t,n,a,o,s,c]),null}var wu=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Tu(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Eu({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=_o(),o=(0,Y.useRef)(n);o.current=n,(0,Y.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&&!wu.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:Tu(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Tu(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Tu(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Du=`objectstack:ai-chat-conversation-id`;function Ou(e,t){return t?`${Du}:${e}:${t}`:`${Du}:${e}`}function ku(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Au(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function ju(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``):``}function Mu(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=ju(e.content);i&&t.push({id:e.id??`msg-${n}`,role:r,parts:[{type:`text`,text:i}]})}),t}async function Nu(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 Pu(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 Fu(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Iu(e){let{userId:t,scope:n,apiBase:r,activeId:i}=e,[a,o]=(0,Y.useState)(void 0),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(!!t),d=(0,Y.useRef)(!0),f=(0,Y.useRef)(void 0);return(0,Y.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]),(0,Y.useEffect)(()=>{if(!t){o(void 0),c([]),u(!1),f.current=void 0;return}if(!i&&f.current===t&&a)return;let e=!1,s=Ou(t,n);return u(!0),(async()=>{try{if(i){let n=await Nu(r,i);if(e)return;if(n){Au(s,n.id),o(n.id),c(Mu(n.messages)),f.current=t;return}Au(s,void 0)}else{let n=ku(s);if(n){let i=await Nu(r,n);if(e)return;if(i){o(i.id),c(Mu(i.messages)),f.current=t;return}Au(s,void 0)}}let n=await Pu(r);if(e)return;Au(s,n.id),o(n.id),c(Mu(n.messages)),f.current=t}catch{e||(o(void 0),c([]))}finally{e||u(!1)}})(),()=>{e=!0}},[t,n,r,i]),{conversationId:a,initialMessages:s,isLoading:l,reset:(0,Y.useCallback)(async()=>{if(!t)return;let e=Ou(t,n);u(!0);try{a&&await Fu(r,a),Au(e,void 0);let t=await Pu(r);if(Au(e,t.id),!d.current)return;o(t.id),c([])}catch{d.current&&(o(void 0),c([]))}finally{d.current&&u(!1)}},[a,t,n,r])}}function Lu(e){if(!e||e.length===0)return;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.role===`user`){let e=Ru(n.content);if(e)return e}}let t=e[e.length-1];return Ru(t?.content)}function Ru(e){if(typeof e==`string`)return e.slice(0,140);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function zu(e){return{id:e.id,title:e.title,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:Lu(e.messages)}}function Bu(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,Y.useState)([]),[s,c]=(0,Y.useState)(!!t),[l,u]=(0,Y.useState)(void 0),[d,f]=(0,Y.useState)(0),p=(0,Y.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,Y.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,Y.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,Y.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;o(a.map(zu).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``)))}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}var Vu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Cl).then(e=>({default:e.RecordDetailView})),void 0,import.meta.url)),Hu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Hl).then(e=>({default:e.DashboardView})),void 0,import.meta.url)),Uu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>$l).then(e=>({default:e.PageView})),void 0,import.meta.url)),Wu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>tu).then(e=>({default:e.ReportView})),void 0,import.meta.url)),Gu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>su).then(e=>({default:e.SearchResultsPage})),void 0,import.meta.url)),Ku=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Bl).then(e=>({default:e.RecordFormPage})),void 0,import.meta.url)),qu=(0,Y.lazy)(()=>m(()=>import(`./ComponentNavView-DBMxrUvH.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Ju=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>bg).then(e=>({default:e.MetadataDirectoryPage})),void 0,import.meta.url)),Yu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>bg).then(e=>({default:e.MetadataResourceListPage})),void 0,import.meta.url)),Xu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>bg).then(e=>({default:e.MetadataResourceEditPage})),void 0,import.meta.url)),Zu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>bg).then(e=>({default:e.MetadataResourceHistoryPage})),void 0,import.meta.url)),Qu=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>sy).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),$u=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>sy).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),ed=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>sy).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),td=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Bd).then(e=>({default:e.MarketplacePage})),void 0,import.meta.url)),nd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Kd).then(e=>({default:e.MarketplacePackagePage})),void 0,import.meta.url)),rd=(0,Y.lazy)(()=>m(()=>Promise.resolve().then(()=>Jd).then(e=>({default:e.MarketplaceInstalledPage})),void 0,import.meta.url));function id({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,Y.useState)(`disconnected`),{user:o,getAuthConfig:s}=C(),c=ge(),[l,d]=(0,Y.useState)({});(0,Y.useEffect)(()=>{let e=!1;return s().then(t=>{e||d(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[s]);let f=v(),m=u(),{appName:h}=a(),{apps:_,objects:y,loading:b,ensureType:x}=F(),{t:S}=L(),{objectLabel:w}=be(),[T,E]=(0,Y.useState)(!x);(0,Y.useEffect)(()=>{if(!x){E(!0);return}let e=!1;return Promise.all([x(`object`),x(`dashboard`),x(`report`),x(`page`)]).finally(()=>{e||E(!0)}),()=>{e=!0}},[x]);let D=_.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),O=_.find(e=>e.name===h)||D.find(e=>e.isDefault===!0)||D[0],[k,A]=(0,Y.useState)(!1),[M,ee]=(0,Y.useState)(null),[ne,N]=(0,Y.useState)(0),{execute:P,runner:re}=te();j({dataSource:c??void 0,onUndo:e=>{J.info(`Undo: ${e.description}`,{duration:4e3}),N(e=>e+1)},onRedo:e=>{J.info(`Redo: ${e.description}`,{duration:3e3}),N(e=>e+1)}}),(0,Y.useEffect)(()=>{re.registerHandler(`crud_success`,async e=>(A(!1),N(e=>e+1),J.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),re.registerHandler(`dialog_cancel`,async()=>(A(!1),{success:!0})),re.registerHandler(`navigate_create`,async e=>{let t=Cs({action:e,context:re.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(f(t.url),{success:!0}):t}),re.registerHandler(`navigate_edit`,async e=>{let t=ws({action:e,context:re.getContext?.()??{},defaultBaseUrl:`/apps/${h??``}`});return t.success?(f(t.url),{success:!0}):t})},[re,f,h]),(0,Y.useEffect)(()=>{if(!c)return;let e=c.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(c.getConnectionState()),e},[c]);let ie=m.pathname.split(`/`).filter(Boolean)[2];(ie===`view`||ie===`record`||ie===`page`||ie===`dashboard`||ie===`design`)&&(ie=``);let I=y.find(e=>e.name===ie),ae=(0,Y.useCallback)(()=>{let e=I?w(I):S(`common.record`,{defaultValue:`Record`});P({type:`crud_success`,params:{message:M?S(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):S(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[P,M,I,w,S]),oe=(0,Y.useCallback)(()=>{P({type:`dialog_cancel`})},[P]);Eu({pathname:m.pathname,appName:O?.name,objects:y});let se=e=>{let t=Ss({objectDef:I,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){f(t.url);return}ee(e),A(!0)},ce=e=>{f(`/apps/${e}`)},le=(0,Y.useMemo)(()=>new fe({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:O||{},data:M||{}}),[o,O,M]);if(!c||b||!T)return(0,X.jsx)(ac,{});let ue=m.pathname.endsWith(`/create-app`),de=m.pathname.includes(`/system`);return!O&&!ue&&!de?(0,X.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:S(`empty.noAppsConfigured`)}),(0,X.jsx)($e,{children:S(`empty.noAppsConfiguredDescription`)}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,X.jsx)(q,{onClick:()=>f(`/create-app`),"data-testid":`create-first-app-btn`,children:S(`empty.createFirstApp`)}),(0,X.jsx)(q,{variant:`outline`,onClick:()=>f(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:S(`empty.systemSettings`)})]})]})}):!O&&(ue||de)?(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`create-app`,element:(0,X.jsx)(Qu,{})}),(0,X.jsx)(g,{path:`system/marketplace`,element:(0,X.jsx)(td,{})}),(0,X.jsx)(g,{path:`system/marketplace/installed`,element:(0,X.jsx)(rd,{})}),(0,X.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,X.jsx)(nd,{})}),t]})}):(0,X.jsxs)(Qa,{user:o?{name:o.name,email:o.email,role:o.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:O,data:{},features:l,children:[(0,X.jsx)(Cu,{}),(0,X.jsxs)(Qs,{activeAppName:O.name,activeApp:O,onAppChange:ce,objects:y,connectionState:n,userId:o?.id,children:[(0,X.jsx)(ec,{apps:_,activeApp:O,objects:y,onAppChange:ce,dataSource:c}),(0,X.jsx)(nc,{}),(0,X.jsx)(rc,{}),(0,X.jsx)(hc,{children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(cc,{children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`/`,element:(0,X.jsx)(p,{to:cd(O,{currentUserId:o?.id??null}),replace:!0})}),(0,X.jsxs)(g,{path:`metadata`,children:[(0,X.jsx)(g,{index:!0,element:(0,X.jsx)(Ju,{})}),(0,X.jsx)(g,{path:`:type`,element:(0,X.jsx)(Yu,{})}),(0,X.jsx)(g,{path:`:type/new`,element:(0,X.jsx)(Xu,{createMode:!0})}),(0,X.jsx)(g,{path:`:type/:name`,element:(0,X.jsx)(Xu,{})}),(0,X.jsx)(g,{path:`:type/:name/history`,element:(0,X.jsx)(Zu,{})})]}),(0,X.jsx)(g,{path:`:objectName`,element:(0,X.jsx)(zl,{dataSource:c,objects:y,onEdit:se,externalRefreshKey:ne})}),(0,X.jsx)(g,{path:`:objectName/new`,element:(0,X.jsx)(Ku,{mode:`create`})}),(0,X.jsx)(g,{path:`:objectName/view/:viewId`,element:(0,X.jsx)(zl,{dataSource:c,objects:y,onEdit:se,externalRefreshKey:ne})}),(0,X.jsx)(g,{path:`:objectName/record/:recordId`,element:(0,X.jsx)(Vu,{dataSource:c,objects:y,onEdit:se},ne)}),(0,X.jsx)(g,{path:`:objectName/record/:recordId/edit`,element:(0,X.jsx)(Ku,{mode:`edit`})}),(0,X.jsx)(g,{path:`dashboard/:dashboardName`,element:(0,X.jsx)(Hu,{dataSource:c})}),(0,X.jsx)(g,{path:`report/:reportName`,element:(0,X.jsx)(Wu,{dataSource:c})}),(0,X.jsx)(g,{path:`page/:pageName`,element:(0,X.jsx)(Uu,{})}),(0,X.jsx)(g,{path:`component/:ns/:name/*`,element:(0,X.jsx)(qu,{})}),(0,X.jsx)(g,{path:`component/metadata/directory`,element:(0,X.jsx)(dd,{mode:`directory`})}),(0,X.jsx)(g,{path:`component/metadata/resource/*`,element:(0,X.jsx)(dd,{mode:`resource`})}),(0,X.jsx)(g,{path:`design/dashboard/:dashboardName`,element:(0,X.jsx)(ed,{})}),(0,X.jsx)(g,{path:`search`,element:(0,X.jsx)(Gu,{})}),(0,X.jsx)(g,{path:`create-app`,element:(0,X.jsx)(Qu,{})}),(0,X.jsx)(g,{path:`edit-app/:editAppName`,element:(0,X.jsx)($u,{})}),(0,X.jsx)(g,{path:`system/marketplace`,element:(0,X.jsx)(td,{})}),(0,X.jsx)(g,{path:`system/marketplace/installed`,element:(0,X.jsx)(rd,{})}),(0,X.jsx)(g,{path:`system/marketplace/:packageId`,element:(0,X.jsx)(nd,{})}),e,(0,X.jsx)(g,{path:`:objectName/:maybeRecordId`,element:(0,X.jsx)(fd,{})}),(0,X.jsx)(g,{path:`*`,element:(0,X.jsx)(pd,{})})]})})})}),I&&(0,X.jsx)(ua,{schema:{type:`object-form`,formType:`modal`,objectName:I.name,mode:M?`edit`:`create`,recordId:M?.id,title:S(M?`form.editTitle`:`form.createTitle`,{object:w(I)}),description:S(M?`form.editDescription`:`form.createDescription`,{object:w(I)}),open:k,onOpenChange:A,layout:`vertical`,fields:I.fields?Array.isArray(I.fields)?I.fields.filter(e=>typeof e==`string`?!0:eo(e.visible,le)).map(e=>typeof e==`string`?e:e.name):Object.entries(I.fields).filter(([e,t])=>eo(t.visible,le)).map(([e])=>e):[],onSuccess:ae,onCancel:oe,showSubmit:!0,showCancel:!0,submitText:M?S(`form.update`,{defaultValue:S(`common.save`,{defaultValue:`Save`})}):S(`form.create`,{defaultValue:S(`common.create`,{defaultValue:`Create`})}),cancelText:S(`common.cancel`)},dataSource:c},M?.id||`new`)]})]})}function ad(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=od(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=ad(n.children,t);if(e!==``)return e}}return``}function od(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=ea(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function sd(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=sd(n.children,t);if(e)return e}}}function cd(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=od(sd(r,n),t);if(e)return e}return ad(r,t)}var ld=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function ud(e){return!e||ld.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function dd({mode:e}){let t=u(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,X.jsx)(p,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,i=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,X.jsx)(p,{to:r?`${n}/metadata/${encodeURIComponent(r)}${i}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function fd(){let{objectName:e,maybeRecordId:t}=a(),n=u();return e&&ud(t)?(0,X.jsx)(p,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,X.jsx)(pd,{})}function pd(){let e=v(),{t}=L();return(0,X.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,X.jsx)($e,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(q,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function md({iconUrl:e,displayName:t,manifestId:n,className:r=`h-10 w-10`,initialClassName:i=`text-base font-semibold`}){let[a,o]=(0,Y.useState)(!1),s=((t??n??`?`).trim()[0]??`?`).toUpperCase(),c=!!e&&!a;return(0,X.jsx)(`div`,{className:`flex shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary overflow-hidden ${r}`,children:c?(0,X.jsx)(`img`,{src:e,alt:``,className:`${r} object-cover`,onError:()=>o(!0),loading:`lazy`}):(0,X.jsx)(`span`,{className:i,children:s})})}function hd(){let e=v(),{appName:t}=a(),{t:n}=L(),r=t?`/apps/${t}`:`/`;return(0,X.jsx)(`div`,{className:`container mx-auto max-w-2xl px-6 py-16`,children:(0,X.jsx)(dt,{children:(0,X.jsxs)(si,{className:`flex flex-col items-center gap-4 py-12 text-center`,children:[(0,X.jsx)(`div`,{className:`rounded-full bg-muted p-3`,children:(0,X.jsx)(_i,{className:`h-6 w-6 text-muted-foreground`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold`,children:n(`marketplace.accessDenied.title`)}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:n(`marketplace.accessDenied.description`)})]}),(0,X.jsx)(q,{variant:`outline`,onClick:()=>e(r),children:n(`marketplace.action.backHome`)})]})})})}var gd=`en`;function _d(e){let t=e.indexOf(`-`);return t===-1?e:e.slice(0,t)}function vd(e){let t=new Set,n=[];for(let r of e)!r||t.has(r)||(t.add(r),n.push(r));return n}function yd(e,t,n){if(!e)return;let r=_d(t),i=vd([t,r,...Object.keys(e).filter(e=>e===r||e.startsWith(`${r}-`)),gd]);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 bd(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 xd(e,t){let n=t||gd;return{displayName:yd(e.translations??void 0,n,`displayName`)??bd(e,`displayName`)??e.manifest_id,description:yd(e.translations??void 0,n,`description`)??bd(e,`description`),readme:yd(e.translations??void 0,n,`readme`)??bd(e,`readme`),tagline:yd(e.translations??void 0,n,`tagline`)??bd(e,`tagline`)}}var Sd=``.replace(/\/$/,``),Cd=`${Sd}/api/v1/marketplace`;async function wd(e,t){let n=await fetch(`${Cd}${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 Td(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 wd(`/packages${n?`?${n}`:``}`)}async function Ed(e){return wd(`/packages/${encodeURIComponent(e)}`)}async function Dd(e){let t=Xs()||Sd,n=await fetch(`${t}/api/v1/actions/sys_package/install_package`,{method:`POST`,credentials:`include`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({recordId:e.packageId,params:{environment_id:e.environmentId,seed_sample_data:!!e.seedSampleData}})}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??r?.error?.code??`HTTP_${n.status}`,t=r?.error??r?.message??n.statusText,i=Error(typeof t==`string`?t:`${e}`);throw i.code=e,i.status=n.status,i}return r?.data??r}async function Od(){let e=Xs()||Sd,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 kd(){let e=Xs()||Sd,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 Ad(e){return`${Xs()||`https://cloud.objectos.app`}/apps/cloud-control/sys_package/${encodeURIComponent(e)}`}async function jd(e,t){if(!e||!t)return null;let n=Xs()||Sd,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 Md(e){if(!e)return{ok:!1,error:`installation id required`};let t=Xs()||Sd;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 Nd(e){if(!e)return{ok:!1,error:`installation id required`};let t=Xs()||Sd;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 Pd(e){let t=await fetch(`${Cd}/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 Fd(){try{let e=await fetch(`${Cd}/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 Id(e){let t=await fetch(`${Cd}/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 Ld(e,t){let n=await fetch(`${Cd}/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 Rd(e){return Ld(e,`reseed`)}function zd(e){return Ld(e,`purge`)}var Bd=t({MarketplacePage:()=>Hd});function Vd(){let{language:e,t}=L();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 Hd(){let e=v(),{appName:t}=a(),n=b(),{t:r,language:i}=L(),o=Vd(),s=t?`/apps/${t}`:``,[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(!0),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(``),[y,x]=(0,Y.useState)([]),S=(0,Y.useMemo)(()=>{let e=new Map;for(let t of y)e.set(t.manifestId,t);return e},[y]),C=async()=>{d(!0),p(null);try{let[e,t]=await Promise.all([Td({limit:100}),Fd()]);l(e.items??[]),x(t)}catch(e){p(e?.message??String(e)),l([])}finally{d(!1)}};(0,Y.useEffect)(()=>{C()},[]);let w=(0,Y.useMemo)(()=>{let e=new Set;for(let t of c)t.category&&e.add(t.category);return Array.from(e).sort()},[c]),T=e=>{let t=`marketplace.category.${e}`,n=r(t,{defaultValue:e});return n===t?e:n},E=(0,Y.useMemo)(()=>{let e=m.trim().toLowerCase();return c.filter(t=>{if(g&&t.category!==g)return!1;if(!e)return!0;let n=xd(t,i);return`${n.displayName} ${t.manifest_id} ${n.description??``}`.toLowerCase().includes(e)})},[c,m,g,i]);return n?(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(bn,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,X.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.title`)})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:r(`marketplace.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>e(`${s}/system/marketplace/installed`),children:[(0,X.jsx)(Qr,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),y.length>0?r(`marketplace.installedCount`,{count:y.length}):r(`marketplace.installed`)]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void C(),disabled:u,children:[(0,X.jsx)(Hi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(zr,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsx)(sr,{value:m,onChange:e=>h(e.target.value),placeholder:r(`marketplace.searchPlaceholder`),className:`pl-9`,"aria-label":r(`marketplace.searchAria`)})]}),w.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,X.jsx)(q,{size:`sm`,variant:g===``?`default`:`outline`,onClick:()=>_(``),children:r(`marketplace.all`)}),w.map(e=>(0,X.jsx)(q,{size:`sm`,variant:g===e?`default`:`outline`,onClick:()=>_(e),children:T(e)},e))]})]}),f&&(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-destructive`,children:r(`marketplace.load.failed`)}),(0,X.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:f}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2`,dangerouslySetInnerHTML:{__html:r(`marketplace.load.failedHint`)}})]})]}),u&&c.length===0?(0,X.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,X.jsxs)(dt,{children:[(0,X.jsxs)(kn,{className:`pb-2`,children:[(0,X.jsx)(G,{className:`h-10 w-10 rounded-lg mb-2`}),(0,X.jsx)(G,{className:`h-5 w-3/4`}),(0,X.jsx)(G,{className:`h-4 w-1/2 mt-1`})]}),(0,X.jsx)(si,{children:(0,X.jsx)(G,{className:`h-12 w-full`})})]},t))}):E.length===0?(0,X.jsx)(`div`,{className:`text-center py-12 text-sm text-muted-foreground`,children:c.length===0?r(`marketplace.noApprovedYet`):r(`marketplace.noMatchFilters`)}):(0,X.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:E.map(t=>{let n=S.get(t.manifest_id),a=xd(t,i);return(0,X.jsxs)(dt,{className:`cursor-pointer transition-colors hover:bg-accent/50 flex flex-col`,onClick:()=>e(`${s}/system/marketplace/${t.id}`),role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(`${s}/system/marketplace/${t.id}`))},"data-testid":`marketplace-card-${t.manifest_id}`,children:[(0,X.jsxs)(kn,{className:`flex flex-row items-start gap-3 pb-2`,children:[(0,X.jsx)(md,{iconUrl:t.icon_url,displayName:a.displayName,manifestId:t.manifest_id}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(wn,{className:`text-base truncate`,children:a.displayName}),(0,X.jsx)(ct,{className:`text-xs truncate`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:t.manifest_id})})]}),t.publisher&&t.publisher!==`private`&&(0,X.jsx)(K,{variant:t.publisher===`objectstack`?`default`:`secondary`,className:`shrink-0`,children:t.publisher})]}),(0,X.jsxs)(si,{className:`flex-1 flex flex-col gap-2`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:a.description||r(`marketplace.noDescription`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-auto pt-2 flex-wrap`,children:[n&&(0,X.jsxs)(K,{variant:`default`,className:`text-xs bg-green-600 hover:bg-green-600`,children:[(0,X.jsx)(ri,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.installedBadge`,{version:n.version})]}),t.latest_version?.version&&(0,X.jsxs)(K,{variant:`outline`,className:`text-xs`,children:[(0,X.jsx)(Ee,{className:`h-3 w-3 mr-1`,"aria-hidden":`true`}),r(`marketplace.versionBadge`,{version:t.latest_version.version})]}),t.category&&(0,X.jsx)(K,{variant:`outline`,className:`text-xs`,children:T(t.category)}),t.latest_version?.published_at&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:o(t.latest_version.published_at)})]})]})]},t.id)})})]}):(0,X.jsx)(hd,{})}function Ud(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 Wd(e){let t=[],n=e,r=0,i=[{re:/`([^`]+)`/,render:e=>(0,X.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,X.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e[1]},`k${r++}`)},{re:/\*([^*]+)\*/,render:e=>(0,X.jsx)(`em`,{children:e[1]},`k${r++}`)},{re:/\[([^\]]+)\]\(([^)]+)\)/,render:e=>(0,X.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,X.jsx)(X.Fragment,{children:t.map((e,t)=>(0,X.jsx)(Y.Fragment,{children:e},t))})}function Gd({source:e,className:t}){let n=Ud(e);return(0,X.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,X.jsx)(`h2`,{className:`mt-2 text-xl font-bold tracking-tight`,children:Wd(e.text??``)},t);case`h2`:return(0,X.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:Wd(e.text??``)},t);case`h3`:return(0,X.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:Wd(e.text??``)},t);case`p`:return(0,X.jsx)(`p`,{children:Wd(e.text??``)},t);case`ul`:return(0,X.jsx)(`ul`,{className:`ml-1 flex list-none flex-col gap-1.5`,children:(e.items??[]).map((e,t)=>(0,X.jsxs)(`li`,{className:`flex gap-2`,children:[(0,X.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,X.jsx)(`span`,{children:Wd(e)})]},t))},t);case`ol`:return(0,X.jsx)(`ol`,{className:`ml-5 flex list-decimal flex-col gap-1.5 marker:text-muted-foreground`,children:(e.items??[]).map((e,t)=>(0,X.jsx)(`li`,{className:`pl-1`,children:Wd(e)},t))},t);case`code`:return(0,X.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border bg-muted/40 p-3 text-xs leading-relaxed`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:e.text})},t)}return null})})}var Kd=t({MarketplacePackagePage:()=>qd});function qd(){let e=v(),{packageId:t,appName:n}=a(),r=b(),{t:i,language:o}=L(),s=n?`/apps/${n}`:``,{refresh:c}=F(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!0),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(!1),[_,y]=(0,Y.useState)([]),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(null),[ee,te]=(0,Y.useState)(null),[ne,N]=(0,Y.useState)(null),[P,re]=(0,Y.useState)(null),[ie,I]=(0,Y.useState)(null),[ae,oe]=(0,Y.useState)([]),[se,ce]=(0,Y.useState)(!1),[le,ue]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!qs().features.installLocal)return;let e=!1;return(async()=>{let t=await Fd();e||oe(t)})(),()=>{e=!0}},[t,le]),(0,Y.useEffect)(()=>{if(!t)return;let e=qs().defaultEnvironmentId;if(!e)return;let n=!1;return(async()=>{let r=await jd(t,e);n||!r||(N(r),te(r.version))})(),()=>{n=!0}},[t]),(0,Y.useEffect)(()=>{let e=!1;return(async()=>{if(t){f(!0),m(null);try{let n=await Ed(t);e||u(n)}catch(t){e||m(t?.message??String(t))}finally{e||f(!1)}}})(),()=>{e=!0}},[t]);let de=async()=>{g(!0),M(null),w(null);let e=qs().defaultEnvironmentId;if(e){S(!1),E(e),y([]);return}S(!0);try{let[e,t]=await Promise.all([Od(),kd()]),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)}},fe=async()=>{if(!(!t||!T)){A(!0),M(null);try{te(((await Dd({packageId:t,environmentId:T,seedSampleData:D}))?.installation?.version??l?.package?.latest_version?.version??l?.versions?.[0]?.version??``)||`installed`);try{let e=qs().defaultEnvironmentId||T;if(e){let n=await jd(t,e);n&&N(n)}}catch{}let e=qs().defaultEnvironmentId;if(!e||e===T)try{if(typeof sessionStorage<`u`)for(let e of Object.keys(sessionStorage))e.startsWith(`objectui:metadata:`)&&sessionStorage.removeItem(e);await c()}catch{}M({ok:!0,message:i(`marketplace.install.success`)})}catch(e){M({ok:!1,message:e?.message??String(e)})}finally{A(!1)}}},pe=async()=>{if(t){ce(!0),ue(null);try{let e=await Pd({packageId:t});try{await c(`app`)}catch{}ue({ok:!0,message:i(`marketplace.install.localSuccess`,{version:e.version,name:l?.package?xd(l.package,o).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`)),ue({ok:!1,message:n})}finally{ce(!1)}}},me=async()=>{if(H&&confirm(i(`marketplace.uninstall.confirm`,{manifestId:H.manifestId,version:H.version}))){ce(!0),ue(null);try{await Id(H.manifestId);try{await c(`app`)}catch{}ue({ok:!0,message:i(`marketplace.uninstall.successInDetail`,{manifestId:H.manifestId})})}catch(e){ue({ok:!1,message:e?.message??String(e)})}finally{ce(!1)}}},R=async()=>{if(ne){re(`reseed`),I(null);try{let e=await Md(ne.installationId);e.ok?(N({...ne,withSampleData:!0}),I({ok:!0,text:i(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):I({ok:!1,text:e.error||`Re-seed failed`})}finally{re(null)}}},he=async()=>{if(ne&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){re(`purge`),I(null);try{let e=await Nd(ne.installationId);if(e.ok){N({...ne,withSampleData:!1});let t=e.deleted??0;I({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 I({ok:!1,text:e.error||`Purge failed`})}finally{re(null)}}},ge=async()=>{if(H){re(`reseed`),I(null);try{let e=await Rd(H.manifestId);oe(e=>e.map(e=>e.manifestId===H.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0;I({ok:!0,text:i(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`})}catch(e){I({ok:!1,text:e?.message||`Re-seed failed`})}finally{re(null)}}},z=async()=>{if(H&&confirm(i(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){re(`purge`),I(null);try{let e=await zd(H.manifestId);oe(e=>e.map(e=>e.manifestId===H.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;I({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){I({ok:!1,text:e?.message||`Purge failed`})}finally{re(null)}}};if(d)return(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsx)(G,{className:`h-8 w-32`}),(0,X.jsx)(G,{className:`h-16 w-full`}),(0,X.jsx)(G,{className:`h-64 w-full`})]});if(p||!l)return(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,X.jsx)(qe,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-destructive`,children:i(`marketplace.load.packageFailed`)}),(0,X.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:p??i(`marketplace.load.notFound`)})]})]})]});let B=l.package,V=xd(B,o),_e=B.latest_version?.version??l.versions[0]?.version??null,H=ae.find(e=>e.manifestId===B.manifest_id)??null,ve=qs().features.installLocal,U=!_e||se||k||!ve&&!!ee,ye=ve?{label:i(se?`marketplace.action.working`:H?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:pe}:{label:k?i(`marketplace.action.installing`):ee?i(`marketplace.action.installed`,{defaultValue:`Installed`}):i(`marketplace.action.installToCloud`),onClick:de},be=B.category?i(`marketplace.category.${B.category}`,{defaultValue:B.category}):null;return r?(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,X.jsx)(qe,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.back`)]}),(0,X.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,X.jsx)(md,{iconUrl:B.icon_url,displayName:V.displayName,manifestId:B.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:V.displayName||B.manifest_id}),B.homepage_url&&(0,X.jsxs)(`a`,{href:B.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,X.jsx)(sn,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`hidden sm:inline`,children:i(`marketplace.detail.homepage`)})]})]}),(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`code`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:B.manifest_id}),_e&&(0,X.jsx)(K,{variant:`outline`,children:i(`marketplace.versionBadge`,{version:_e})}),B.publisher&&B.publisher!==`private`&&(0,X.jsx)(K,{variant:B.publisher===`objectstack`?`default`:`secondary`,children:B.publisher}),be&&(0,X.jsx)(K,{variant:`outline`,children:be}),B.license&&(0,X.jsx)(K,{variant:`outline`,className:`font-normal`,children:B.license}),H&&(0,X.jsxs)(K,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,X.jsx)(ri,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:H.version})]}),!H&&ee&&(0,X.jsxs)(K,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,X.jsx)(ri,{className:`h-3 w-3`,"aria-hidden":`true`}),i(`marketplace.detail.installedV`,{version:ee})]})]}),V.description&&(0,X.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:V.description})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,X.jsxs)(q,{onClick:ye.onClick,disabled:U,size:`lg`,className:`min-w-[8rem]`,children:[(0,X.jsx)(ai,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),ye.label]}),H&&(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsx)(q,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`),children:(0,X.jsx)(vn,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,X.jsxs)($r,{align:`end`,className:`w-56`,children:[(0,X.jsxs)(Zn,{onSelect:ge,disabled:P!==null,children:[P===`reseed`?(0,X.jsx)(qr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(Dn,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),H.withSampleData?i(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:i(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,X.jsxs)(Zn,{onSelect:z,disabled:P!==null||!H.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,X.jsx)(qr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(kt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,X.jsxs)(Zn,{onSelect:me,disabled:se,className:`text-destructive focus:text-destructive`,children:[(0,X.jsx)(kt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!H&&ne&&(0,X.jsxs)(Un,{children:[(0,X.jsx)(Gr,{asChild:!0,children:(0,X.jsx)(q,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":i(`marketplace.detail.moreOptions`)||`More options`,children:(0,X.jsx)(vn,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,X.jsxs)($r,{align:`end`,className:`w-56`,children:[(0,X.jsxs)(Zn,{onSelect:R,disabled:P!==null,children:[P===`reseed`?(0,X.jsx)(qr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(Dn,{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,X.jsxs)(Zn,{onSelect:he,disabled:P!==null||!ne.withSampleData,className:`text-destructive focus:text-destructive`,children:[P===`purge`?(0,X.jsx)(qr,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(kt,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),i(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),ie&&(0,X.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${ie.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:[ie.ok?(0,X.jsx)(ri,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:ie.text}),(0,X.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>I(null),children:i(`marketplace.action.dismiss`)})]}),le&&(0,X.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${le.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:[le.ok?(0,X.jsx)(ri,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:le.message}),(0,X.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>ue(null),children:i(`marketplace.action.dismiss`)})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,children:[(0,X.jsx)(`div`,{className:`lg:col-span-2 space-y-4`,children:(0,X.jsxs)(dt,{children:[(0,X.jsx)(kn,{children:(0,X.jsx)(wn,{className:`text-base`,children:i(`marketplace.detail.about`)})}),(0,X.jsx)(si,{children:V.readme?(0,X.jsx)(Gd,{source:V.readme}):(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noReadme`)})})]})}),(0,X.jsx)(`div`,{className:`space-y-4`,children:(0,X.jsxs)(dt,{children:[(0,X.jsx)(kn,{children:(0,X.jsx)(wn,{className:`text-base`,children:i(`marketplace.detail.versions`)})}),(0,X.jsx)(si,{children:l.versions.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.detail.noApprovedVersions`)}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:l.versions.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Ee,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsxs)(`code`,{className:`font-mono`,children:[`v`,e.version]}),e.is_prerelease&&(0,X.jsx)(K,{variant:`outline`,className:`text-xs`,children:i(`marketplace.detail.prerelease`)})]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.published_at?new Date(e.published_at).toLocaleDateString():`—`})]},e.id))})})]})})]}),(0,X.jsx)(He,{open:h,onOpenChange:e=>{g(e),e||M(null)},children:(0,X.jsxs)(nt,{children:[(0,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:i(`marketplace.install.dialogTitle`,{name:V.displayName||B.manifest_id})}),(0,X.jsx)(gt,{children:qs().defaultEnvironmentId?i(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):i(`marketplace.install.dialogDescPicker`)})]}),x?(0,X.jsx)(G,{className:`h-10 w-full`}):C?(0,X.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 text-sm space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 text-amber-600`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`flex-1`,children:C})]}),(0,X.jsx)(`a`,{href:Ad(B.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,X.jsxs)(q,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,X.jsx)(sn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),i(`marketplace.action.openOnCloud`)]})})]}):qs().defaultEnvironmentId?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ke,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,X.jsx)(Er,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]}):_.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`marketplace.install.noEnvs`)}):(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(Er,{htmlFor:`env-select`,children:i(`marketplace.install.environment`)}),(0,X.jsxs)(Yt,{value:T,onValueChange:E,children:[(0,X.jsx)(_n,{id:`env-select`,children:(0,X.jsx)(Qe,{placeholder:i(`marketplace.install.environmentPlaceholder`)})}),(0,X.jsx)(Xi,{children:_.map(e=>(0,X.jsxs)(ke,{value:e.id,children:[e.display_name||e.hostname||e.id,e.plan&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.plan]})]},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ke,{id:`seed`,checked:D,onCheckedChange:e=>O(e===!0)}),(0,X.jsx)(Er,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:i(`marketplace.install.includeSampleData`)})]})]}),j&&(0,X.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${j.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:j.message}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{variant:`outline`,onClick:()=>g(!1),children:i(`marketplace.action.close`)}),!C&&(0,X.jsx)(q,{onClick:fe,disabled:!T||k||j?.ok===!0,children:i(k?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,X.jsx)(hd,{})}var Jd=t({MarketplaceInstalledPage:()=>Yd});function Yd(){let e=v(),{appName:t}=a(),n=b(),{t:r,language:i}=L(),o=t?`/apps/${t}`:``,[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),h=async()=>{u(!0);try{c(await Fd())}finally{u(!1)}};(0,Y.useEffect)(()=>{h()},[]);let g=async e=>{if(confirm(r(`marketplace.uninstall.confirm`,{manifestId:e.manifestId,version:e.version}))){f(e.manifestId),m(null);try{await Id(e.manifestId),m({ok:!0,message:r(`marketplace.uninstall.successInList`,{manifestId:e.manifestId})}),await h()}catch(e){m({ok:!1,message:e?.message??String(e)})}finally{f(null)}}};return n?(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-5xl`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,className:`self-start`,onClick:()=>e(`${o}/system/marketplace`),children:[(0,X.jsx)(qe,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.back`)]}),(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(bn,{className:`h-6 w-6 text-primary`,"aria-hidden":`true`}),(0,X.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:r(`marketplace.installedTitle`)})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedSubtitle`)}})]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void h(),disabled:l,children:[(0,X.jsx)(Hi,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.refresh`)]})]}),p&&(0,X.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${p.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,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{children:p.message})]})}),l&&s.length===0?(0,X.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:3}).map((e,t)=>(0,X.jsx)(G,{className:`h-20 w-full`},t))}):s.length===0?(0,X.jsxs)(`div`,{className:`text-center py-12 text-sm text-muted-foreground border rounded-md`,children:[(0,X.jsx)(`p`,{children:r(`marketplace.installedEmpty`)}),(0,X.jsx)(q,{variant:`link`,className:`mt-2`,onClick:()=>e(`${o}/system/marketplace`),children:r(`marketplace.browseLink`)})]}):(0,X.jsx)(`div`,{className:`grid gap-3`,children:s.map(t=>(0,X.jsxs)(dt,{children:[(0,X.jsxs)(kn,{className:`flex flex-row items-start justify-between gap-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(wn,{className:`text-base truncate flex items-center gap-2`,children:[t.manifestId,(0,X.jsx)(K,{variant:`outline`,children:r(`marketplace.versionBadge`,{version:t.version})})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap gap-x-3 gap-y-1`,children:[(0,X.jsx)(`span`,{children:r(`marketplace.installedAt`,{when:new Date(t.installedAt).toLocaleString(i||void 0)})}),t.installedBy&&(0,X.jsx)(`span`,{children:r(`marketplace.installedBy`,{user:t.installedBy})}),(0,X.jsxs)(`span`,{children:[r(`marketplace.installedPackageId`),` `,(0,X.jsx)(`code`,{className:`font-mono`,children:t.packageId})]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>e(`${o}/system/marketplace/${t.packageId}`),children:[(0,X.jsx)(sn,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),r(`marketplace.action.details`)]}),(0,X.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>void g(t),disabled:d===t.manifestId,children:[(0,X.jsx)(kt,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),d===t.manifestId?r(`marketplace.action.uninstalling`):r(`marketplace.action.uninstall`)]})]})]}),(0,X.jsx)(si,{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,X.jsx)(`p`,{className:`text-xs text-muted-foreground border-t pt-4`,dangerouslySetInnerHTML:{__html:r(`marketplace.installedAdditiveNote`)}})]}):(0,X.jsx)(hd,{})}function Xd({children:e,userId:t}){let{setContext:n}=bo(),{isAiEnabled:r}=k(),i=r||!1;return(0,Y.useEffect)(()=>{n(`home`)},[n]),(0,X.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,X.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,X.jsx)(Bs,{variant:`home`})}),(0,X.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,X.jsx)(Go,{appLabel:`Workspace`,objects:[],userId:t})]})}var Zd=[{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 Qd(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function $d({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=L(),{appLabel:a,appDescription:o}=be(),{toggleFavorite:s}=Mo(),c=Yo(e.icon),l=a({name:e.name,label:Ts(e.label,i)}),u=o({name:e.name,description:Ts(e.description,i)}),d=e.branding?.primaryColor,f=Zd[(Qd(e.name)+r)%Zd.length];return(0,X.jsxs)(dt,{role:`button`,tabIndex:0,"aria-label":l,className:Pn(`group relative cursor-pointer overflow-hidden border border-border/70 bg-card/80 backdrop-blur-sm`,`transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-lg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`motion-reduce:transition-none motion-reduce:hover:transform-none`,!d&&f.ring),onClick:t,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())},"data-testid":`app-card-${e.name}`,style:d?{borderColor:void 0}:void 0,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:Pn(`absolute inset-x-0 top-0 h-1`,d?``:f.solid),style:d?{backgroundColor:d}:void 0}),!d&&(0,X.jsx)(`div`,{"aria-hidden":!0,className:Pn(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,f.from,f.to)}),(0,X.jsxs)(si,{className:`relative p-5`,children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,className:`absolute top-2 right-2 h-8 w-8 p-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,onClick:t=>{t.stopPropagation(),s({id:`app:${e.name}`,label:l,href:`/apps/${e.name}`,type:`object`})},"aria-label":n?i(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`})+` — ${l}`:i(`common.addToFavorites`,{defaultValue:`Add to favorites`})+` — ${l}`,"aria-pressed":n,"data-testid":`favorite-btn-${e.name}`,children:n?(0,X.jsx)(Je,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,X.jsx)(pt,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:Pn(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,d?``:Pn(`bg-gradient-to-br`,f.from,f.to,`ring-border/40`)),style:d?{backgroundColor:`${d}1f`,boxShadow:`inset 0 0 0 1px ${d}33`}:void 0,children:(0,X.jsx)(c,{className:Pn(`h-7 w-7`,d?``:f.text),style:d?{color:d}:void 0})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`h3`,{className:`font-semibold text-base sm:text-lg leading-tight truncate`,children:l}),e.isDefault&&(0,X.jsx)(K,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,X.jsx)(`p`,{className:Pn(`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,X.jsx)(`div`,{className:`mt-4 flex items-center justify-between text-xs font-medium`,children:(0,X.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,X.jsx)(hn,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var ef={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`},tf={object:Dn,record:mt,dashboard:er,page:et};function nf({items:e}){let t=v(),{t:n}=L();return e.length===0?null:(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,X.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,X.jsx)(di,{className:`h-4 w-4`})}),(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,X.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=tf[e.type]||Dn,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Es(e.type)}),a=ef[e.type]||ef.object;return(0,X.jsx)(dt,{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,X.jsx)(si,{className:`p-3.5`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:Pn(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,a),children:(0,X.jsx)(r,{className:`h-5 w-5`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,X.jsx)(hn,{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 rf={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`},af={object:Dn,record:mt,dashboard:er,page:et};function of({items:e}){let t=v(),{t:n}=L();return e.length===0?null:(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,X.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,X.jsx)(Je,{className:`h-4 w-4 fill-current`})}),(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,X.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=af[e.type]||Dn,i=rf[e.type]||rf.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Es(e.type)});return(0,X.jsx)(dt,{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,X.jsx)(si,{className:`p-3.5`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:Pn(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,i),children:(0,X.jsx)(r,{className:`h-5 w-5`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]}),(0,X.jsx)(hn,{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 sf(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function cf({t:e}){return(0,X.jsxs)(`section`,{"data-testid":`home-getting-started`,className:`relative overflow-hidden rounded-2xl border border-border/60 bg-card/70 backdrop-blur-sm p-6 sm:p-8`,children:[(0,X.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-fuchsia-500/5`}),(0,X.jsxs)(`div`,{className:`relative flex flex-col sm:flex-row sm:items-center gap-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,X.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,X.jsx)(Je,{className:`h-5 w-5`})}),(0,X.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,X.jsx)(di,{className:`h-5 w-5`})})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:e(`home.gettingStarted.title`,{defaultValue:`Make this home yours`})}),(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:e(`home.gettingStarted.cta`,{defaultValue:`Browse all applications`})}),(0,X.jsx)(ft,{className:`h-3.5 w-3.5`})]})]})]})}function lf(){let e=v(),{t}=L(),{apps:n,loading:r}=F(),{recentItems:i}=_o(),{favorites:a}=Mo(),{user:o}=C(),s=b(),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,Y.useMemo)(()=>t(sf(new Date().getHours()),{defaultValue:`Welcome`}),[t]),f=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,X.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):c.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,X.jsx)($e,{children:t(`home.welcomeDescription`,{defaultValue:`Get started by creating your first application or configure your system settings.`})}),(0,X.jsxs)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:[(0,X.jsxs)(q,{onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,X.jsx)(Ni,{className:`mr-2 h-4 w-4`}),t(`home.createFirstApp`,{defaultValue:`Create Your First App`})]}),s&&(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-empty-btn`,children:[(0,X.jsx)(bn,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]}),(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,X.jsx)(Qr,{className:`mr-2 h-4 w-4`}),t(`home.systemSettings`,{defaultValue:`System Settings`})]})]})]})}):(0,X.jsxs)(`div`,{className:`relative isolate min-h-full bg-gradient-to-b from-background via-background to-muted/40`,children:[(0,X.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 top-0 -z-10 h-[28rem] overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`absolute -top-32 -left-24 h-[28rem] w-[28rem] rounded-full bg-primary/30 blur-3xl opacity-70 dark:opacity-40`}),(0,X.jsx)(`div`,{className:`absolute -top-20 right-[-6rem] h-[26rem] w-[36rem] rounded-full bg-sky-400/30 blur-3xl opacity-70 dark:opacity-35`}),(0,X.jsx)(`div`,{className:`absolute top-32 left-1/3 h-[18rem] w-[24rem] rounded-full bg-fuchsia-400/25 blur-3xl opacity-60 dark:opacity-25`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-b from-transparent via-background/40 to-background`})]}),(0,X.jsx)(`section`,{className:`px-4 sm:px-6 lg:px-8 pt-10 pb-6`,children:(0,X.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-3`,children:[(0,X.jsx)(Wt,{className:`h-3.5 w-3.5 text-primary`}),(0,X.jsx)(`span`,{className:`uppercase tracking-wider`,children:t(`home.title`,{defaultValue:`Home`})})]}),(0,X.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-pretty`,children:[(0,X.jsxs)(`span`,{className:`bg-gradient-to-r from-foreground via-foreground to-foreground/70 bg-clip-text text-transparent`,children:[d,f?`, ${f}`:``]}),(0,X.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,X.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,X.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pb-16`,children:(0,X.jsxs)(`div`,{className:`max-w-7xl mx-auto space-y-10`,children:[u.length===0&&l.length===0&&(0,X.jsx)(cf,{t}),u.length>0&&(0,X.jsx)(of,{items:u}),l.length>0&&(0,X.jsx)(nf,{items:l}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-end justify-between mb-5`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[c.length,` · `,t(`home.stats.apps`,{defaultValue:`Applications`})]})]}),s&&(0,X.jsxs)(q,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,X.jsx)(bn,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,X.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,X.jsx)($d,{app:t,index:n,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function uf({children:e}){let{setContext:t}=bo();return(0,Y.useEffect)(()=>{t(`home`)},[t]),(0,X.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,X.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,X.jsx)(Bs,{variant:`orgs`})}),(0,X.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function df(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function ff({open:e,onOpenChange:t,onCreated:n}){let{t:r}=L(),{createOrganization:i,getAuthConfig:a}=C(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,Y.useEffect)(()=>{u||l(df(o))},[o,u]),(0,Y.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,X.jsx)(He,{open:e,onOpenChange:t,children:(0,X.jsx)(nt,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,X.jsxs)(`form`,{onSubmit:(0,Y.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,X.jsxs)(Ji,{children:[(0,X.jsx)(De,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,X.jsx)(gt,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(Er,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,X.jsx)(sr,{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,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(Er,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,X.jsx)(sr,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,X.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,X.jsxs)(q,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,X.jsx)(qr,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function pf(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 mf(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function hf(){let{t:e}=L(),t=v(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a,getAuthConfig:o}=C(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{let e=!1;return o().then(t=>{e||t?.features?.multiOrgEnabled===!1&&m(!1)}).catch(()=>{}),()=>{e=!0}},[o]);let h=n??[],g=(0,Y.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=pf()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),f(null)}},y=e=>{u(!1),_(e)},b=(0,Y.useRef)(!1);(0,Y.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,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,X.jsx)(qr,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,X.jsxs)(`div`,{className:`mb-8`,children:[(0,X.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,X.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,X.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,X.jsx)(zr,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(sr,{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,X.jsxs)(q,{onClick:()=>u(!0),"data-testid":`organizations-new`,children:[(0,X.jsx)(Ni,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,X.jsx)($e,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),p&&(0,X.jsxs)(q,{className:`mt-6`,onClick:()=>u(!0),children:[(0,X.jsx)(Ni,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):g.length===0?(0,X.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,X.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,X.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,X.jsxs)(ye,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,X.jsx)(bi,{src:n.logo,alt:n.name}),(0,X.jsx)(lr,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:mf(n.name)})]}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,X.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,X.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,X.jsx)(qr,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,X.jsx)(ff,{open:l,onOpenChange:u,onCreated:y})]})}function gf(e){if(!e)return``;let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=Date.now()-t.getTime(),r=60*1e3,i=60*r,a=24*i;return n<r?`just now`:n<i?`${Math.floor(n/r)}m ago`:n<a?`${Math.floor(n/i)}h ago`:n<7*a?`${Math.floor(n/a)}d ago`:t.toLocaleDateString()}function _f({userId:e,apiBase:t,className:n,refreshKey:r}){let i=v(),{conversationId:o}=a(),{conversations:s,isLoading:c,error:l,remove:u,rename:d}=Bu({userId:e,apiBase:t,refreshKey:r}),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(void 0),g=(0,Y.useMemo)(()=>{let e=f.trim().toLowerCase();return e?s.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):s},[s,f]),_=(0,Y.useCallback)(()=>i(`/ai`),[i]),y=(0,Y.useCallback)(async(e,t)=>{e.stopPropagation(),await u(t),t===o&&i(`/ai`,{replace:!0})},[u,o,i]),b=(0,Y.useCallback)(async(e,t)=>{h(void 0);try{await d(e,t)}catch{}},[d]);return(0,X.jsxs)(`aside`,{className:Pn(`flex h-full min-h-0 flex-col bg-muted/30`,n),"data-testid":`ai-conversations-sidebar`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`Chats`}),(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:_,"data-testid":`ai-new-chat`,children:[(0,X.jsx)(Ni,{className:`h-3.5 w-3.5`}),`New`]})]}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(zr,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(sr,{value:f,onChange:e=>p(e.target.value),placeholder:`Search chats...`,className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,X.jsx)(dn,{className:`flex-1 min-h-0`,children:c&&s.length===0?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`Loading…`}):l?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:l.message}):s.length===0?(0,X.jsxs)(ze,{className:`px-3 py-8`,children:[(0,X.jsx)(st,{className:`h-8 w-8 text-muted-foreground`}),(0,X.jsx)(Ki,{children:`No chats yet`}),(0,X.jsx)($e,{children:`Start a new conversation to see it here.`})]}):g.length===0?(0,X.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:`No matching chats.`}):(0,X.jsx)(`ul`,{className:`flex flex-col py-1`,children:g.map(e=>(0,X.jsx)(vf,{conversation:e,active:e.id===o,renaming:e.id===m,onSelect:()=>i(`/ai/${e.id}`),onDelete:t=>y(t,e.id),onStartRename:()=>h(e.id),onCancelRename:()=>h(void 0),onSubmitRename:t=>b(e.id,t)},e.id))})})]})}function vf({conversation:e,active:t,renaming:n,onSelect:r,onDelete:i,onStartRename:a,onCancelRename:o,onSubmitRename:s}){let c=e.title?.trim()||e.preview?.trim()||`New conversation`,[l,u]=(0,Y.useState)(c),d=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{n&&(u(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>d.current?.select(),0))},[n,e.title,e.preview]),n?(0,X.jsx)(`li`,{children:(0,X.jsxs)(`div`,{className:Pn(`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,X.jsx)(sr,{ref:d,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s(l)):e.key===`Escape`&&(e.preventDefault(),o())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":`Rename conversation`}),(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>s(l),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":`Save rename`,children:(0,X.jsx)(qn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:o,"aria-label":`Cancel rename`,children:(0,X.jsx)(Jn,{className:`h-3.5 w-3.5`})})]})}):(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,onClick:r,className:Pn(`group flex w-full flex-col gap-0.5 border-l-2 border-transparent px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50`,t&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`line-clamp-1 flex-1 font-medium`,children:c}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),a()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),a())},className:`hover:text-primary`,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":`Rename conversation`,children:(0,X.jsx)(W,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),i(e)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),i(e))},className:`hover:text-destructive`,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":`Delete conversation`,children:(0,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]})]}),e.preview&&e.preview!==c?(0,X.jsx)(`span`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:e.preview}):null,(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:gf(e.updatedAt??e.createdAt)})]})})}var yf=`/api/v1/ai`;function bf(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(/\/$/,``)}${yf}`}function xf({apiBase:e,defaultAgent:t}={}){let{user:n}=C(),r=n?.id,{conversationId:i}=a(),o=v(),{setContext:s}=bo();(0,Y.useEffect)(()=>{s(`home`)},[s]);let c=(0,Y.useMemo)(()=>bf(e),[e]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:u,isLoading:d,error:f}=ja({apiBase:c}),[p,m]=(0,Y.useState)(void 0);(0,Y.useEffect)(()=>{if(!p&&u.length>0){let e=t??l;m(((e?u.find(t=>t.name===e):void 0)??u[0]).name)}},[u,p,t,l]);let h=p?`${c}/agents/${encodeURIComponent(p)}/chat`:void 0,{conversationId:g,initialMessages:_,isLoading:y}=Iu({userId:r,scope:p,apiBase:c,activeId:i}),[b,x]=(0,Y.useState)(0),[S,w]=(0,Y.useState)(!1),T=(0,Y.useMemo)(()=>c.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[c]);(0,Y.useEffect)(()=>{!i&&g&&o(`/ai/${g}`,{replace:!0})},[i,g,o]);let E=(0,Y.useRef)(new Set);(0,Y.useEffect)(()=>{g&&_.length>0&&E.current.add(g)},[g,_.length]);let D=(0,Y.useCallback)(e=>{if(x(e=>e+1),!e||!g||E.current.has(g))return;E.current.add(g);let t=()=>x(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[g]);return(0,X.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,X.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:[(0,X.jsx)(Bs,{variant:`home`}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,X.jsxs)(q,{variant:`outline`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>w(!0),disabled:!g,"data-testid":`ai-chat-share-button`,title:g?`Share this conversation`:`Start chatting to enable sharing`,children:[(0,X.jsx)(Hn,{className:`h-3.5 w-3.5`}),`Share`]})})]}),g&&(0,X.jsx)(Li,{open:S,onOpenChange:w,objectName:`ai_conversations`,recordId:g,recordLabel:`this conversation`,apiBase:T}),(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0 w-full`,children:[(0,X.jsx)(_f,{userId:r,apiBase:c,refreshKey:b,className:`hidden w-72 shrink-0 border-r md:flex`}),(0,X.jsx)(`main`,{className:`flex flex-1 min-w-0 flex-col`,children:(0,X.jsx)(Sf,{agents:u,agentsLoading:d,agentsError:f,activeAgent:p,onAgentChange:m,chatApi:h,apiBase:c,conversationId:g,initialMessages:_,hydrating:y,onSent:D},`${h??`local`}:${g??`pending`}`)})]})]})}function Sf({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,onAgentChange:i,chatApi:a,apiBase:o,conversationId:s,initialMessages:c,hydrating:l,onSent:u}){let d=(0,Y.useMemo)(()=>e.find(e=>e.name===r)?.label??r??`Assistant`,[e,r]),f=(0,Y.useMemo)(()=>c.map(e=>({id:e.id,role:e.role,content:e.parts.map(e=>e.text).join(``)})),[c]),p=(0,Y.useMemo)(()=>{if(!(f.length>0))return Tf(r,d)},[f.length,r,d]),{messages:m,isLoading:h,error:g,sendMessage:_,stop:v,reload:y,clear:b}=Na({api:a,conversationId:s,body:{context:{activeApp:`AI`,agentName:r}},initialMessages:f,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600}),x=Ma({messages:m,apiBase:o,continueConversation:e=>{_(e)}}),S=(0,Y.useCallback)((e,t)=>{_(e,t),u(e)},[_,u]);return(0,X.jsx)(Aa,{className:`flex-1 min-h-0 rounded-none border-0`,maxHeight:`100%`,headerSlot:e.length>0?(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Agent:`}),(0,X.jsxs)(Yt,{value:r,onValueChange:i,disabled:t,children:[(0,X.jsx)(_n,{className:`h-7 w-[220px] text-xs`,"data-testid":`ai-chat-agent-picker`,children:(0,X.jsx)(Qe,{placeholder:`Choose agent...`})}),(0,X.jsx)(Xi,{align:`start`,children:e.map(e=>(0,X.jsxs)(ke,{value:e.name,className:`text-xs`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,X.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}),l?(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Loading history…`}):null,n?(0,X.jsx)(`span`,{className:`text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:`⚠ Offline demo mode — agent list unavailable`}):null]}):null,messages:m,placeholder:r?`Ask ${d}… (try “${p?.[0]??`How can you help?`}”)`:t?`Loading agents…`:`Ask anything…`,suggestions:p,onSendMessage:S,onClear:b,onStop:h?v:void 0,onReload:y,isLoading:h,error:g,enableMarkdown:!0,onToolApprove:x.decide,toolDecisions:x.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,"data-testid":`ai-chat-panel`})}var Cf={data_chat:[`系统里有多少个用户?列出他们的邮箱。`,`帮我列出最近创建的 5 条记录。`,`统计每个对象的记录数。`],metadata_assistant:[`系统里注册了哪些对象类型?`,`sys_user 对象有哪些字段?`,`描述一下用户相关的对象关系。`]},wf=[`What can you help me with?`,`List the available data objects.`,`Summarize my recent activity.`];function Tf(e,t){if(e&&Cf[e])return Cf[e];let n=(e??t).toLowerCase();return n.includes(`data`)?Cf.data_chat:n.includes(`metadata`)?Cf.metadata_assistant:wf}var Ef=new Map;function Df(e){Ef.set(e.ref,e)}function Of(e){return Ef.get(e)}function kf(e){return(0,Y.useMemo)(()=>{let t=new B({baseUrl:``});return e?t.withEnvironment(e):t},[e])}function Af(e){let[t,n]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)([]);return(0,Y.useEffect)(()=>{let t=!1;return n(!0),i(null),(async()=>{try{let r=await e.listTypes(),i;if(Array.isArray(r))i=r.map(e=>typeof e==`string`?{type:e}:e);else{let e=r?.entries;i=Array.isArray(e)&&e.length>0?e:(r?.types??[]).map(e=>({type:e}))}t||(o(i),n(!1))}catch(e){t||(i(e?.message??String(e)),n(!1))}})(),()=>{t=!0}},[e]),{loading:t,error:r,entries:a}}function jf(e,t,n=[`name`,`label`,`description`]){if(!t)return!0;let r=t.toLowerCase();for(let t of n){let n=e[t];if(typeof n==`string`&&n.toLowerCase().includes(r))return!0}return!1}var Mf={object:`Object`,field:`Field`,trigger:`Trigger`,validation:`Validation Rule`,hook:`Hook`,view:`View`,page:`Page`,dashboard:`Dashboard`,app:`Application`,action:`Action`,report:`Report`,flow:`Flow`,workflow:`Workflow`,approval:`Approval Process`,datasource:`Datasource`,translation:`Translation`,router:`Router`,function:`Function`,service:`Service`,email_template:`Email Template`,permission:`Permission Set`,profile:`Profile`,role:`Role`,agent:`AI Agent`,tool:`AI Tool`,skill:`AI Skill`,package:`Package`,data:`Dataset`,job:`Background Job`},Nf={object:`对象`,field:`字段`,trigger:`触发器`,validation:`校验规则`,hook:`钩子`,view:`视图`,page:`页面`,dashboard:`仪表板`,app:`应用`,action:`操作`,report:`报表`,flow:`流程`,workflow:`工作流`,approval:`审批流程`,datasource:`数据源`,translation:`翻译`,router:`路由`,function:`函数`,service:`服务`,email_template:`邮件模板`,permission:`权限集`,profile:`配置文件`,role:`角色`,agent:`AI 智能体`,tool:`AI 工具`,skill:`AI 技能`,package:`包`,data:`数据集`,job:`后台任务`},Pf={data:`Data`,ui:`UI`,automation:`Automation`,ai:`AI`,system:`System`,platform:`Platform`,identity:`Identity`,security:`Security`,other:`Other`},Ff={data:`数据`,ui:`界面`,automation:`自动化`,ai:`AI`,system:`系统`,platform:`平台`,identity:`身份`,security:`安全`,other:`其他`},If={"engine.directory.title":`All Metadata Types`,"engine.directory.description":`The platform protocol exposes {count} metadata types ({writable} writable at runtime). Click any tile to browse, override, or create instances.`,"engine.directory.search":`Search metadata types…`,"engine.directory.writableOnly":`Writable only`,"engine.directory.quickFind":`Quick Find`,"engine.directory.noMatches":`No matches`,"engine.directory.noMatchesHint":`Adjust your search or filters to see more metadata types.`,"engine.directory.loading":`Loading metadata types…`,"engine.directory.loadFailed":`Failed to load metadata types`,"engine.directory.all":`All`,"engine.list.create":`New`,"engine.list.refresh":`Refresh`,"engine.list.search":`Search name, label, description…`,"engine.list.empty":`No items yet.`,"engine.list.items":`Items`,"engine.list.filtered":`Filtered`,"engine.list.allSources":`All sources`,"engine.list.col.name":`Name`,"engine.list.col.label":`Label`,"engine.list.col.source":`Source`,"engine.list.col.object":`Object`,"engine.list.col.type":`Type`,"engine.list.col.description":`Description`,"engine.list.emptyType":`No {type} items registered`,"engine.list.emptyQuery":`No matches for "{query}"`,"engine.list.createHint":`Click "New" above to create the first {type}.`,"engine.list.readOnlyHint":`This type is read-only — instances are defined by code artifacts in packages.`,"engine.edit.save":`Save`,"engine.edit.reset":`Reset overlay`,"engine.edit.resetConfirm":`Reset overlay for {type}/{name}?`,"engine.edit.history":`History`,"engine.edit.layers":`Layers`,"engine.edit.references":`References`,"engine.edit.form":`Form`,"engine.edit.edit":`Edit`,"engine.edit.editOverlay":`Edit overlay`,"engine.edit.createNew":`Create new`,"engine.edit.detail":`Detail`,"engine.edit.preview":`Preview`,"engine.edit.designer":`Designer`,"engine.edit.related":`Related`,"engine.edit.overlay":`overlay`,"engine.edit.readOnlyBanner":`Viewing in read-only mode. Click {edit} to make changes.`,"engine.edit.readOnlyTypeBanner":`This type is read-only. To enable runtime editing, set {flag} to include {type}, or flip {override} in the registry.`,"engine.repeater.empty":`No items. Click + to add.`,"engine.badge.writable":`writable`,"engine.badge.readOnly":`read-only`,"engine.edit.readOnly":`Read-only (runtime overrides disabled).`,"engine.edit.loading":`Loading`,"engine.edit.bespokeDesigner":`Designer`,"engine.edit.readOnlyHint":`Read-only — this metadata type does not allow runtime overrides. Edit the source in the package and redeploy.`,"engine.edit.unsaved":`Unsaved`,"engine.edit.unsavedHint":`You have unsaved changes.`,"engine.edit.destructive":`Destructive change`,"engine.edit.destructiveHint":`The change would break existing references. Review the issues and confirm to force-save.`,"engine.edit.forceSave":`Force save`,"engine.cancel":`Cancel`,"engine.quickfind.placeholder":`Find metadata types or items… (try 'view', 'account')`,"engine.quickfind.empty":`Type to search across all metadata types.`,"engine.quickfind.title":`Quick Find`,"engine.quickfind.indexing":`Indexing items across`,"engine.quickfind.noMatches":`No matches.`,"engine.breadcrumb.allTypes":`All Metadata Types`,"perm.action.create":`Create`,"perm.action.read":`Read`,"perm.action.edit":`Edit`,"perm.action.delete":`Delete`,"perm.action.transfer":`Transfer ownership`,"perm.action.restore":`Restore from trash`,"perm.action.purge":`Hard delete (purge)`,"perm.action.viewAll":`View All Records (bypass sharing)`,"perm.action.modifyAll":`Modify All Records (bypass sharing)`,"perm.col.object":`Object`,"perm.col.bulk":`Bulk`,"perm.bulk.read":`R`,"perm.bulk.crud":`CRUD`,"perm.bulk.all":`All`,"perm.bulk.none":`None`,"perm.filter.placeholder":`Filter objects…`,"perm.filter.onlyGranted":`Only granted`,"perm.filter.empty":`No objects match the filter.`,"perm.field.name":`Name`,"perm.field.label":`Label`,"perm.field.isProfile":`Is profile`,"perm.field.loading":`Loading fields…`,"perm.field.empty":`No fields registered for this object.`,"perm.field.col.name":`Field`,"perm.field.read":`Read`,"perm.field.edit":`Edit`,"perm.stat.objects":`Objects granted`,"perm.stat.fields":`Fields granted`,"perm.stat.objectsGranted":`Objects granted`,"perm.stat.fieldOverrides":`Field overrides`,"perm.stat.objectsSuffix":`objects`,"perm.subtitle.profile":`Profile`,"perm.subtitle.set":`Permission set`,"perm.loading":`Loading permission set {name}…`,"perm.readOnly":`Read-only (OS_METADATA_WRITABLE not enabled)`,"designer.unsavedChanges":`Unsaved changes`,"designer.editingOverlay":`Editing overlay`,"designer.codeBaseline":`Code baseline`},Lf={"engine.directory.title":`元数据`,"engine.directory.description":`平台协议共暴露 {count} 个元数据类型(其中 {writable} 个支持运行时覆盖)。点击任意卡片即可浏览、覆盖或创建实例。`,"engine.directory.search":`搜索元数据类型…`,"engine.directory.writableOnly":`仅显示可写`,"engine.directory.quickFind":`快速查找`,"engine.directory.noMatches":`没有匹配项`,"engine.directory.noMatchesHint":`调整搜索或筛选条件以查看更多元数据类型。`,"engine.directory.loading":`正在加载元数据类型…`,"engine.directory.loadFailed":`加载元数据类型失败`,"engine.directory.all":`全部`,"engine.list.create":`新建`,"engine.list.refresh":`刷新`,"engine.list.search":`搜索名称、标签或描述…`,"engine.list.empty":`暂无数据。`,"engine.list.items":`条目`,"engine.list.filtered":`已筛选`,"engine.list.allSources":`全部来源`,"engine.list.col.name":`名称`,"engine.list.col.label":`标签`,"engine.list.col.source":`来源`,"engine.list.col.object":`对象`,"engine.list.col.type":`类型`,"engine.list.col.description":`描述`,"engine.list.emptyType":`暂无 {type} 条目`,"engine.list.emptyQuery":`没有匹配 "{query}" 的结果`,"engine.list.createHint":`点击上方"新建"创建第一个 {type}。`,"engine.list.readOnlyHint":`此类型为只读 — 实例由包内的代码工件定义。`,"engine.edit.save":`保存`,"engine.edit.reset":`重置覆盖`,"engine.edit.resetConfirm":`重置 {type}/{name} 的覆盖层?`,"engine.edit.history":`历史`,"engine.edit.layers":`层次`,"engine.edit.references":`引用关系`,"engine.edit.form":`表单`,"engine.edit.edit":`编辑`,"engine.edit.editOverlay":`编辑覆盖层`,"engine.edit.createNew":`新建`,"engine.edit.detail":`详情`,"engine.edit.preview":`预览`,"engine.edit.designer":`可视化编辑器`,"engine.edit.related":`关联`,"engine.edit.overlay":`覆盖`,"engine.edit.readOnlyBanner":`当前为只读模式。点击 {edit} 进行修改。`,"engine.edit.readOnlyTypeBanner":`此类型为只读。如需启用运行时编辑,请将 {flag} 设置为包含 {type},或在注册表中开启 {override}。`,"engine.repeater.empty":`暂无条目。点击 + 添加。`,"engine.badge.writable":`可写`,"engine.badge.readOnly":`只读`,"engine.edit.readOnly":`只读(运行时覆盖未启用)。`,"engine.edit.loading":`加载中`,"engine.edit.bespokeDesigner":`可视化编辑器`,"engine.edit.readOnlyHint":`只读 — 该元数据类型不支持运行时覆盖。请修改包内源代码并重新部署。`,"engine.edit.unsaved":`未保存`,"engine.edit.unsavedHint":`当前存在未保存的修改。`,"engine.edit.destructive":`破坏性变更`,"engine.edit.destructiveHint":`该修改会破坏现有引用关系。请检查问题清单后确认强制保存。`,"engine.edit.forceSave":`强制保存`,"engine.cancel":`取消`,"engine.quickfind.placeholder":`搜索元数据类型或条目…(如:view、account)`,"engine.quickfind.empty":`输入关键字以搜索所有元数据类型。`,"engine.quickfind.title":`快速查找`,"engine.quickfind.indexing":`正在索引所有类型,共`,"engine.quickfind.noMatches":`没有匹配项。`,"engine.breadcrumb.allTypes":`元数据`,"perm.action.create":`创建`,"perm.action.read":`读取`,"perm.action.edit":`编辑`,"perm.action.delete":`删除`,"perm.action.transfer":`转移所有者`,"perm.action.restore":`从回收站恢复`,"perm.action.purge":`彻底删除`,"perm.action.viewAll":`查看所有记录(绕过共享规则)`,"perm.action.modifyAll":`修改所有记录(绕过共享规则)`,"perm.col.object":`对象`,"perm.col.bulk":`批量`,"perm.bulk.read":`读`,"perm.bulk.crud":`增改删`,"perm.bulk.all":`全选`,"perm.bulk.none":`清空`,"perm.filter.placeholder":`筛选对象…`,"perm.filter.onlyGranted":`只看已授权`,"perm.filter.empty":`没有匹配的对象。`,"perm.field.name":`名称`,"perm.field.label":`标签`,"perm.field.isProfile":`作为 Profile`,"perm.field.loading":`加载字段中…`,"perm.field.empty":`该对象未注册字段。`,"perm.field.col.name":`字段`,"perm.field.read":`读`,"perm.field.edit":`改`,"perm.stat.objects":`已授权对象`,"perm.stat.fields":`已授权字段`,"perm.stat.objectsGranted":`已授权对象`,"perm.stat.fieldOverrides":`字段覆盖`,"perm.stat.objectsSuffix":`个对象`,"perm.subtitle.profile":`Profile`,"perm.subtitle.set":`权限集`,"perm.loading":`加载权限集 {name}…`,"perm.readOnly":`只读(OS_METADATA_WRITABLE 未启用)`,"designer.unsavedChanges":`未保存的修改`,"designer.editingOverlay":`编辑覆盖层`,"designer.codeBaseline":`代码基线`};function Rf(e){return(e??``).toLowerCase().startsWith(`zh`)?{types:Nf,domains:Ff,strings:Lf}:{types:Mf,domains:Pf,strings:If}}function zf(e,t,n){return Rf(t).types[e]||(n??e)}function Bf(e,t){return Rf(t).domains[e]??e}function Z(e,t){return Rf(t).strings[e]??e}function Vf(e,t,n){return Z(e,t).replace(/\{(\w+)\}/g,(e,t)=>t in n?String(n[t]):`{${t}}`)}function Hf(){return typeof navigator<`u`&&/^zh/i.test(navigator.language)?`zh-CN`:`en-US`}function Uf({appSlug:e}={}){let t=v(),n=kf(),{entries:r}=Af(n),[i,a]=Y.useState(!1),[o,s]=Y.useState(``),[c,l]=Y.useState(null),[u,d]=Y.useState(!1),[f,p]=Y.useState(0),m=Y.useMemo(()=>Hf(),[]);Y.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)},[]),Y.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})}}catch{}})),e||l(t)}finally{e||d(!1)}})(),()=>{e=!0}},[i,c,u,r,n]);let h=Y.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)||(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]);Y.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,X.jsx)(He,{open:i,onOpenChange:a,children:(0,X.jsxs)(nt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,X.jsx)(Ji,{className:`sr-only`,children:(0,X.jsx)(De,{children:Z(`engine.quickfind.title`,m)})}),(0,X.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,X.jsx)(zr,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(sr,{autoFocus:!0,placeholder:Z(`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,X.jsx)(Ft,{children:`esc`})]}),(0,X.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[u&&(0,X.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-3.5 w-3.5 animate-spin`}),Z(`engine.quickfind.indexing`,m),` `,r.length,`…`]}),!u&&h.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:Z(`engine.quickfind.noMatches`,m)}),(0,X.jsx)(`ul`,{role:`listbox`,children:h.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.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,X.jsx)(K,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e.entry.label??e.entry.type}),e.entry.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-sm font-mono truncate`,children:[e.name,e.label&&(0,X.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,X.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,X.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(Ft,{children:`↑`}),` `,(0,X.jsx)(Ft,{children:`↓`}),` navigate`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(Ft,{children:`↵`}),` open`]}),(0,X.jsxs)(`span`,{className:`ml-auto`,children:[(0,X.jsx)(Ft,{children:`⌘`}),(0,X.jsx)(Ft,{children:`⇧`}),(0,X.jsx)(Ft,{children:`M`}),` toggle`]})]})]})})}var Wf={data:Dn,ui:dr,automation:Qt,ai:Wt,system:Qr,platform:Qr,identity:ui,security:ui},Gf=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Kf=new Set([`field`]);function qf(){let{loading:e,error:t,entries:n}=Af(kf()),r=Y.useMemo(()=>Hf(),[]),[i,a]=Y.useState(``),[o,s]=Y.useState(`all`),[c,l]=Y.useState(!1),u=Y.useMemo(()=>{let e=n.filter(e=>!Kf.has(e.type)),t={all:e.length};for(let n of e){let e=n.domain??`other`;t[e]=(t[e]??0)+1}return t},[n]),d=n.filter(e=>!Kf.has(e.type)&&e.allowOrgOverride).length,f=n.filter(e=>{if(Kf.has(e.type)||c&&!e.allowOrgOverride||o!==`all`&&(e.domain??`other`)!==o)return!1;if(i){let t=i.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),p=Y.useMemo(()=>{let e={};for(let t of f)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=Gf.indexOf(e),r=Gf.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[f]);return e?(0,X.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:Z(`engine.directory.loading`,r)}):t?(0,X.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[Z(`engine.directory.loadFailed`,r),`: `,t]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:Z(`engine.directory.title`,r)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:Vf(`engine.directory.description`,r,{count:`<strong class="text-foreground">${n.filter(e=>!Kf.has(e.type)).length}</strong>`,writable:d})}}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,X.jsx)(zr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(sr,{className:`pl-8`,placeholder:Z(`engine.directory.search`,r),value:i,onChange:e=>a(e.target.value)})]}),(0,X.jsxs)(q,{variant:c?`default`:`outline`,size:`sm`,onClick:()=>l(e=>!e),children:[Z(`engine.directory.writableOnly`,r),` (`,d,`)`]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[Z(`engine.directory.quickFind`,r),` `,(0,X.jsx)(Ft,{children:`⌘`}),(0,X.jsx)(Ft,{children:`⇧`}),(0,X.jsx)(Ft,{children:`M`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,X.jsx)(Jf,{domain:`all`,label:Z(`engine.directory.all`,r),active:o===`all`,count:u.all??0,onClick:()=>s(`all`)}),Gf.filter(e=>u[e]).map(e=>(0,X.jsx)(Jf,{domain:e,label:Bf(e,r),active:o===e,count:u[e]??0,onClick:()=>s(e)},e))]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[f.length===0&&(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:Z(`engine.directory.noMatches`,r)}),(0,X.jsx)($e,{children:Z(`engine.directory.noMatchesHint`,r)})]}),p.map(([e,t])=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,X.jsx)(Wf[e]??Ar,{className:`h-3.5 w-3.5`}),Bf(e,r),` (`,t.length,`)`]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>(0,X.jsx)(Yf,{entry:e,locale:r},e.type))})]},e))]}),(0,X.jsx)(Uf,{})]})}function Jf({domain:e,label:t,active:n,count:r,onClick:i}){return(0,X.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,X.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Yf({entry:e,locale:t}){let n=zf(e.type,t,e.label);return(0,X.jsxs)(r,{to:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:border-primary hover:bg-accent transition-colors`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium truncate`,children:n}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),e.allowOrgOverride?(0,X.jsx)(K,{className:`text-[10px] shrink-0 `+(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:Z(`engine.badge.writable`,t)}):(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] shrink-0 text-muted-foreground`,children:Z(`engine.badge.readOnly`,t)})]}),e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}function Xf({entry:e,itemName:t,subtitle:n,stats:i,actions:a,children:o}){let s=e?.type??``,c=Y.useMemo(()=>Hf(),[]),l=zf(s,c,e?.label),{pathname:d}=u(),f=Y.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,X.jsx)(r,{to:f,className:`hover:text-foreground`,children:Z(`engine.breadcrumb.allTypes`,c)}),(0,X.jsx)(Rn,{className:`h-3 w-3`}),(0,X.jsx)(r,{to:`${f}/${encodeURIComponent(s)}`,className:`hover:text-foreground`,children:l}),t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Rn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium font-mono`,children:t})]})]}),(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:l}),(0,X.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:s}),e?.domain&&(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Bf(e.domain,c)}),e?.allowOrgOverride?(0,X.jsx)(K,{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:Z(`engine.badge.writable`,c)}):(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:Z(`engine.badge.readOnly`,c)})]}),n&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:n}),!n&&e?.description&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,X.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),a]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:o})]})}function Zf(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 Qf=new Map;function $f(e){let t=Qf.get(e.type);if(!t){Qf.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Qf.set(e.type,n)}function ep(e){return Qf.get(e)}function tp(e){let t=[];for(let n of Qf.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 np(e,t){let n=Qf.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 rp({type:e}){let t=a(),n=e??t.type??``,r=ep(n);if(r?.ListPage){let e=r.ListPage;return(0,X.jsx)(e,{type:n})}return(0,X.jsx)(ip,{type:n})}function ip({type:e}){let t=v(),n=kf(),{entries:i}=Af(n),a=i.find(t=>t.type===e),o=np(e,a),[s,c]=Y.useState([]),[l,u]=Y.useState(!0),[d,f]=Y.useState(null),[p,m]=Y.useState(``),[h,g]=Y.useState(`all`),[_,y]=Y.useState(0);Y.useEffect(()=>{let t=!1;return u(!0),f(null),(async()=>{try{let r=await n.list(e);if(t)return;c((r??[]).map(e=>({raw:e,item:(e&&typeof e==`object`&&`item`in e?e.item:e)??{},source:e?.source}))),u(!1)}catch(e){t||(f(e?.message??String(e)),u(!1))}})(),()=>{t=!0}},[n,e,_]);let b=o.searchableFields??[`name`,`label`,`description`],x=s.filter(e=>!(!jf(e.item,p,b)||h!==`all`&&e.source&&e.source!==h)),S=Y.useMemo(()=>{let e={all:s.length,code:0,overlay:0,effective:0};for(let t of s)t.source&&e[t.source]!==void 0&&e[t.source]++;return e},[s]),C=o.listColumns??ap(o.primaryKey??`name`),w=Hf(),T=zf(e,w,a?.label??e),E=e=>{let t=`engine.list.col.${e.key}`,n=Z(t,w);return n===t?e.label:n};return(0,X.jsx)(Xf,{entry:a??{type:e,label:e},stats:[{label:Z(`engine.list.items`,w),value:s.length},{label:Z(`engine.list.filtered`,w),value:x.length}],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>y(e=>e+1),title:Z(`engine.list.refresh`,w),children:(0,X.jsx)(Oi,{className:`h-4 w-4`})}),a?.allowOrgOverride&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>t(`./new`),children:[(0,X.jsx)(Ni,{className:`h-4 w-4 mr-1`}),Z(`engine.list.create`,w)]})]}),children:(0,X.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,X.jsx)(zr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(sr,{className:`pl-8`,placeholder:Z(`engine.list.search`,w),value:p,onChange:e=>m(e.target.value)})]}),(0,X.jsxs)(Yt,{value:h,onValueChange:g,children:[(0,X.jsx)(_n,{className:`w-[180px]`,children:(0,X.jsx)(Qe,{})}),(0,X.jsxs)(Xi,{children:[(0,X.jsxs)(ke,{value:`all`,children:[Z(`engine.list.allSources`,w),` (`,S.all,`)`]}),(0,X.jsxs)(ke,{value:`code`,children:[`Code (`,S.code,`)`]}),(0,X.jsxs)(ke,{value:`overlay`,children:[`Overlay (`,S.overlay,`)`]}),(0,X.jsxs)(ke,{value:`effective`,children:[`Effective (`,S.effective,`)`]})]})]})]}),l&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[Z(`engine.edit.loading`,w),` `,e,`…`]}),d&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:d}),!l&&!d&&x.length===0&&(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:s.length===0?Vf(`engine.list.emptyType`,w,{type:T}):Vf(`engine.list.emptyQuery`,w,{query:p})}),(0,X.jsx)($e,{children:o.emptyStateHint??(a?.allowOrgOverride?Vf(`engine.list.createHint`,w,{type:T}):Z(`engine.list.readOnlyHint`,w))})]}),!l&&x.length>0&&(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[C.map(e=>(0,X.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:E(e)},e.key)),(0,X.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:Z(`engine.list.col.source`,w)})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:x.map((e,t)=>{let n=o.primaryKey??`name`,i=String(e.item[n]??`(unnamed-${t})`);return(0,X.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[C.map((t,n)=>{let a=e.item[t.key],o=t.render?t.render(a,e.item):op(a);return(0,X.jsx)(`td`,{className:`px-3 py-2 align-top`,children:n===0?(0,X.jsx)(r,{to:`./${encodeURIComponent(i)}`,className:`text-primary hover:underline font-mono`,children:o}):o},t.key)}),(0,X.jsx)(`td`,{className:`px-3 py-2 text-right align-top`,children:e.source?(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] `+(e.source===`overlay`?`border-emerald-500 text-emerald-700`:``),children:e.source}):(0,X.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`—`})})]},i+t)})})]})})]})})}function ap(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function op(e){if(e==null||e===``)return(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,X.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}function sp({layered:e,loading:t}){if(t)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading layers…`});if(!e)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Layered view unavailable for this item.`});let n=e.overlay!=null;return(0,X.jsxs)(H,{defaultValue:`effective`,className:`w-full`,children:[(0,X.jsxs)(xi,{className:`grid grid-cols-3 w-fit`,children:[(0,X.jsxs)(Xr,{value:`code`,children:[`Code`,(0,X.jsx)(K,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,X.jsxs)(Xr,{value:`overlay`,children:[`Overlay`,n?(0,X.jsx)(K,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,X.jsx)(K,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,X.jsxs)(Xr,{value:`effective`,children:[`Effective`,(0,X.jsx)(K,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,X.jsx)(ur,{value:`code`,className:`mt-3`,children:(0,X.jsx)(cp,{payload:e.code,emptyHint:`No code-level artifact for this item. It may have been created at runtime as a pure overlay.`})}),(0,X.jsx)(ur,{value:`overlay`,className:`mt-3`,children:(0,X.jsx)(cp,{payload:e.overlay,emptyHint:`No overlay set. The runtime is using the code-level value as-is.`})}),(0,X.jsx)(ur,{value:`effective`,className:`mt-3`,children:(0,X.jsx)(cp,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function cp({payload:e,emptyHint:t}){if(e==null)return(0,X.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,X.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}function lp(e,t){if(e==null)return!0;let n=typeof e==`string`?e:e.source;if(!n)return!0;try{return up(n.trim(),t)}catch{return!0}}function up(e,t){let n=dp(e,`||`);if(n.length>1)return n.some(e=>up(e.trim(),t));let r=dp(e,`&&`);if(r.length>1)return r.every(e=>up(e.trim(),t));if(e.startsWith(`!`))return!up(e.slice(1).trim(),t);let i=e.match(/^(.+?)\s+in\s+(\[.*\])$/);if(i){let e=fp(i[1].trim(),t),n=pp(i[2]);return Array.isArray(n)&&n.includes(e)}let a=e.match(/^(.+?)\s*(==|!=)\s*(.+)$/);if(a){let e=fp(a[1].trim(),t),n=pp(a[3].trim()),r=e=>e==null,i=r(e)&&r(n)?!0:e===n;return a[2]===`==`?i:!i}return!!fp(e,t)}function dp(e,t){let n=[],r=0,i=null,a=``;for(let o=0;o<e.length;o++){let s=e[o];if(i){a+=s,s===i&&e[o-1]!==`\\`&&(i=null);continue}if(s===`'`||s===`"`){i=s,a+=s;continue}if(s===`(`||s===`[`?r++:(s===`)`||s===`]`)&&r--,r===0&&e.slice(o,o+t.length)===t&&e[o+t.length]!==`=`){n.push(a),a=``,o+=t.length-1;continue}a+=s}return a&&n.push(a),n}function fp(e,t){if(/^['"]/.test(e)||/^-?\d/.test(e)||e===`true`||e===`false`||e===`null`)return pp(e);let n=e.split(`.`),r=t;for(let e of n){if(r==null)return;r=r[e]}return r}function pp(e){let t=e.trim();if(t===`true`)return!0;if(t===`false`)return!1;if(t===`null`)return null;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`'`)&&t.endsWith(`'`)||t.startsWith(`"`)&&t.endsWith(`"`))return t.slice(1,-1);if(t.startsWith(`[`)&&t.endsWith(`]`))try{let e=t.replace(/'([^']*)'/g,(e,t)=>JSON.stringify(t));return JSON.parse(e)}catch{return[]}return t}function mp({id:e,value:t,onChange:n,readOnly:r,context:i}){let a=i?.objectNames??[],o=t==null?``:String(t);return i?.objectsLoading?(0,X.jsx)(sr,{id:e,value:o,disabled:!0,placeholder:`Loading objects…`}):a.length===0?(0,X.jsx)(sr,{id:e,value:o,disabled:r,onChange:e=>n(e.target.value||void 0),placeholder:`object_name (no objects detected)`}):(0,X.jsxs)(Yt,{value:o,onValueChange:e=>n(e||void 0),disabled:r,children:[(0,X.jsx)(_n,{id:e,children:(0,X.jsx)(Qe,{placeholder:`Select object…`})}),(0,X.jsx)(Xi,{children:a.map(e=>(0,X.jsx)(ke,{value:e,children:e},e))})]})}function hp({id:e,value:t,onChange:n,readOnly:r,context:i,fieldSpec:a}){let o=i?.objectNames??[],s=a?.multiple??!1,c=Y.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),l=e=>{if(!r){if(!s){n(e);return}n(c.includes(e)?c.filter(t=>t!==e):[...c,e])}},u=e=>{if(r)return;let t=c.filter(t=>t!==e);n(s?t:``)};return i?.objectsLoading?(0,X.jsx)(sr,{id:e,value:`Loading objects...`,readOnly:!0,disabled:!0}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[c.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,X.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,X.jsx)(`span`,{children:e}),!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e))}),(0,X.jsxs)(Yt,{value:``,onValueChange:l,disabled:r||o.length===0,children:[(0,X.jsx)(_n,{id:e,children:(0,X.jsx)(Qe,{placeholder:s?`Add objects...`:`Select object...`})}),(0,X.jsx)(Xi,{children:o.map(e=>(0,X.jsxs)(ke,{value:e,disabled:!s&&c.includes(e),children:[e,c.includes(e)&&` ✓`]},e))})]})]})}function gp({id:e,value:t,onChange:n,readOnly:r,fieldSpec:i,formData:a}){let[o,s]=Y.useState([]),[c,l]=Y.useState(!1),u=i?.dependsOn||i?.reference||`objectName`,d=Array.isArray(u)?u[0]:u,f=a?.[d];Y.useEffect(()=>{if(!f){s([]);return}l(!0),fetch(`/api/v1/objects/${f}/fields`).then(e=>e.json()).then(e=>{s(e.fields||[]),l(!1)}).catch(e=>{console.error(`Failed to load fields:`,e),s([]),l(!1)})},[f]);let p=i?.multiple??!1,m=Y.useMemo(()=>t?Array.isArray(t)?t.map(String):String(t).split(`,`).map(e=>e.trim()).filter(Boolean):[],[t]),h=e=>{if(!r){if(!p){n(e);return}n(m.includes(e)?m.filter(t=>t!==e):[...m,e])}},g=e=>{if(r)return;let t=m.filter(t=>t!==e);n(p?t:``)};return f?c?(0,X.jsx)(sr,{id:e,value:`Loading fields...`,readOnly:!0,disabled:!0}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[m.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>{let t=o.find(t=>t.name===e);return(0,X.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-1 text-sm`,children:[(0,X.jsx)(`span`,{children:t?.label||e}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:t?.type}),!r&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-foreground`,children:`×`})]},e)})}),(0,X.jsxs)(Yt,{value:``,onValueChange:h,disabled:r||o.length===0,children:[(0,X.jsx)(_n,{id:e,children:(0,X.jsx)(Qe,{placeholder:p?`Add fields...`:`Select field...`})}),(0,X.jsx)(Xi,{children:o.map(e=>(0,X.jsx)(ke,{value:e.name,disabled:!p&&m.includes(e.name),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e.label||e.name}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.type}),m.includes(e.name)&&` ✓`]})},e.name))})]})]}):(0,X.jsx)(sr,{id:e,value:`(Select an object first)`,readOnly:!0,disabled:!0})}function _p({schema:e,value:t,onChange:n,readOnly:r,context:i}){let a=e;if(a?.anyOf||a?.oneOf){let e=(a.anyOf??a.oneOf).find(e=>e?.type===`array`&&e?.items?.type===`object`);e&&(a={...a,...e})}let o=a?.items??{},s=o.properties??{},c=new Set(Array.isArray(o.required)?o.required:[]),l=Array.isArray(t)?t:[],u=Object.keys(s);if(u.length===0)return(0,X.jsxs)(`div`,{className:`rounded border border-dashed border-amber-500/40 bg-amber-500/5 p-2 text-xs text-amber-700 dark:text-amber-300`,children:[`master-detail widget requires `,(0,X.jsx)(`code`,{children:`items.properties`}),` on the JSON schema (or an `,(0,X.jsx)(`code`,{children:`anyOf`}),` branch that has them).`]});function d(e,t){let r=l.slice();r[e]={...r[e]??{},...t},n(r)}function f(){n([...l,{}])}function p(e){let t=l.slice();t.splice(e,1),n(t)}return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`overflow-x-auto rounded border border-border/40`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40`,children:(0,X.jsxs)(`tr`,{children:[u.map(e=>(0,X.jsxs)(`th`,{className:`px-2 py-1.5 text-left text-xs font-medium text-muted-foreground`,children:[s[e]?.title??e,c.has(e)&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e)),(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsxs)(`tbody`,{children:[l.length===0&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:u.length+1,className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:`No rows. Click + to add.`})}),l.map((e,t)=>(0,X.jsxs)(`tr`,{className:`border-t border-border/30`,children:[u.map(n=>(0,X.jsx)(`td`,{className:`p-1`,children:(0,X.jsx)(vp,{schema:s[n],value:(e??{})[n],readOnly:r,context:i,onChange:e=>d(t,{[n]:e})})},n)),(0,X.jsx)(`td`,{className:`p-1 text-right`,children:(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),disabled:r,className:`h-7 w-7 p-0`,"aria-label":`Remove row`,children:(0,X.jsx)(kt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:r,children:[(0,X.jsx)(Ni,{className:`h-3.5 w-3.5 mr-1`}),` Add row`]})]})}function vp({schema:e,value:t,readOnly:n,context:r,onChange:i}){if(e?.widget===`ref:object`)return(0,X.jsx)(mp,{schema:e,value:t,onChange:i,readOnly:n,context:r});let a=e?.enum;return Array.isArray(a)&&a.length>0?(0,X.jsxs)(Yt,{value:t==null?``:String(t),onValueChange:e=>i(e||void 0),disabled:n,children:[(0,X.jsx)(_n,{className:`h-8 text-xs`,children:(0,X.jsx)(Qe,{placeholder:`—`})}),(0,X.jsx)(Xi,{children:a.map(e=>(0,X.jsx)(ke,{value:String(e),children:String(e)},String(e)))})]}):e?.type===`boolean`?(0,X.jsx)(`input`,{type:`checkbox`,checked:!!t,disabled:n,onChange:e=>i(e.target.checked),className:`h-4 w-4`}):e?.type===`number`||e?.type===`integer`?(0,X.jsx)(sr,{type:`number`,value:t==null?``:String(t),disabled:n,onChange:e=>{let t=e.target.valueAsNumber;i(Number.isFinite(t)?t:void 0)},className:`h-8 text-xs`}):(0,X.jsx)(sr,{value:t==null?``:String(t),disabled:n,onChange:e=>i(e.target.value||void 0),className:`h-8 text-xs`})}function yp({id:e,value:t,onChange:n,readOnly:r}){let i=Array.isArray(t)?t:[],[a,o]=Y.useState(``);function s(e){let t=e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean);if(t.length===0)return;let r=[...i];for(let e of t)r.includes(e)||r.push(e);n(r),o(``)}function c(e){let t=i.slice();t.splice(e,1),n(t)}return(0,X.jsx)(`div`,{className:`rounded border border-input bg-background p-1.5`,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-xs`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),!r&&(0,X.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e}`,onClick:()=>c(t),className:`text-muted-foreground hover:text-destructive`,children:`×`})]},t)),(0,X.jsx)(`input`,{id:e,type:`text`,value:a,disabled:r,placeholder:i.length===0?`Type and press Enter…`:``,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),s(a)):e.key===`Backspace`&&!a&&i.length>0&&c(i.length-1)},onBlur:()=>a&&s(a),className:`min-w-[8rem] flex-1 bg-transparent text-sm outline-none`})]})})}var bp={"ref:object":mp,"object-selector":hp,"field-selector":gp,"master-detail":_p,"string-tags":yp,code:Cp,"filter-builder":_p};function xp(e,t){if(e?.language)return e.language;if(typeof t?.format==`string`){let e=t.format.toLowerCase();if(e===`sql`||e===`javascript`||e===`typescript`||e===`json`||e===`yaml`||e===`html`||e===`css`||e===`python`)return e}let n=e?.field?.toLowerCase()??``;return n.includes(`sql`)||n===`query`?`sql`:`javascript`}var Sp=Y.lazy(()=>m(()=>import(`./src-Con14F4e.js`).then(e=>({default:e.CodeEditorRenderer})),__vite__mapDeps([0]),import.meta.url));function Cp({schema:e,value:t,onChange:n,readOnly:r,fieldSpec:i}){let a=xp(i,e),o=typeof t==`string`?t:t==null?``:String(t);return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/50 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 bg-muted/40 border-b border-border/30 text-[10px] font-mono text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:a}),r&&(0,X.jsx)(`span`,{children:`read-only`})]}),(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`h-[280px] flex items-center justify-center text-xs text-muted-foreground`,children:`Loading editor…`}),children:(0,X.jsx)(Sp,{schema:{type:`code`,language:a,theme:`vs-dark`,height:`280px`,readOnly:r},value:o,onChange:e=>n(e??``)})})]})}var wp=new Set([`text`,`textarea`,`number`,`switch`,`select`,`json`]);function Tp(e,t){if(e?.widget)return e.widget;if(e?.type){let t=e.type;if(t===`text`||t===`email`||t===`url`||t===`phone`||t===`password`)return`text`;if(t===`textarea`||t===`markdown`||t===`html`||t===`richtext`)return`textarea`;if(t===`number`||t===`currency`||t===`percent`)return`number`;if(t===`date`||t===`datetime`||t===`time`)return`date-picker`;if(t===`boolean`||t===`toggle`)return`switch`;if(t===`select`||t===`radio`)return e.multiple?`multiselect`:`select`;if(t===`multiselect`||t===`checkboxes`||t===`tags`)return`string-tags`;if(t===`composite`)return`composite`;if(t===`repeater`)return`repeater`;if(t===`lookup`||t===`master_detail`||t===`tree`)return`ref-object`;if(t===`image`||t===`file`||t===`avatar`||t===`video`||t===`audio`)return`file-upload`;if(t===`code`)return`code`;if(t===`json`||t===`location`||t===`address`)return`json`;if(t===`color`)return`color-picker`;if(t===`rating`)return`number`;if(t===`slider`)return`slider`;if(t===`signature`)return`signature`;if(t===`qrcode`)return`qrcode`;if(t===`progress`)return`number`;if(t===`formula`||t===`summary`||t===`autonumber`)return`text`;if(t===`vector`)return`json`}if(t){let e=t.type;if(e===`array`&&t.items?.type===`string`)return`string-tags`;if(e===`array`&&t.items?.type===`object`)return`master-detail`;if(e===`object`)return`object-fields`;if(e===`boolean`)return`switch`;if(e===`number`||e===`integer`)return`number`;if(Array.isArray(t.enum))return`select`;if(e===`string`){if(t.format===`date`||t.format===`date-time`)return`date-picker`;if(t.format===`email`||t.format===`uri`||t.format===`uri-reference`)return`text`;if(t.format===`multiline`)return`textarea`}}}function Ep({schema:e,form:t,value:n,onChange:r,issues:i=[],hiddenFields:a=[],fieldOrder:o=[],readOnly:s=!1,createMode:c=!1,widgetContext:l}){let u=e;if(!u||typeof u!=`object`)if(n&&typeof n==`object`)u=Fp(n);else return(0,X.jsx)(Pp,{value:n,onChange:r,readOnly:s});let d=u.properties??{},f=Array.isArray(u.required)?u.required:[],p=Rp(Object.keys(d),o).filter(e=>!a.includes(e)),m=Y.useMemo(()=>{let e={};for(let t of i)(e[t.path]??=[]).push(t.message);return e},[i]),h=n??{};function g(e,t){let n={...h,[e]:t};(t===void 0||t===``)&&delete n[e],r(n)}return t?.sections?.length?(0,X.jsx)(Op,{form:t,props:d,required:f,hiddenFields:a,issuesByPath:m,value:h,readOnly:s,createMode:c,widgetContext:l,onChange:g}):(0,X.jsx)(`div`,{className:`space-y-4`,children:p.map(e=>(0,X.jsx)(kp,{name:e,schema:d[e],value:h[e],required:f.includes(e),issues:m[e],readOnly:s,widgetContext:l,formData:h,onChange:t=>g(e,t)},e))})}function Dp(e){return typeof e==`string`?{field:e}:e}function Op({form:e,props:t,required:n,hiddenFields:r,issuesByPath:i,value:a,readOnly:o,createMode:s,widgetContext:c,onChange:l}){let u=(e.sections??[]).filter(e=>!e.visibleOn||lp(e.visibleOn,{data:a})),d=e.type===`tabbed`&&u.length>1,f=(e,u)=>{let d=e.fields.map(Dp).filter(e=>!(e.hidden||r.includes(e.field)||e.visibleOn&&!lp(e.visibleOn,{data:a})));if(d.length===0)return null;let f=e.columns??1;return(0,X.jsxs)(`section`,{className:`space-y-3 rounded-md border border-border/40 bg-card/30 p-4`,children:[e.label&&(0,X.jsxs)(`header`,{children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold text-foreground/90`,children:e.label}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),(0,X.jsx)(`div`,{className:`grid gap-4`,style:{gridTemplateColumns:`repeat(${f}, minmax(0, 1fr))`},children:d.map(e=>{let r=t[e.field];return r?(0,X.jsx)(`div`,{style:{gridColumn:`span ${e.colSpan??1}`},children:(0,X.jsx)(kp,{name:e.field,schema:{...r,...e.label?{title:e.label}:{},...e.helpText?{description:e.helpText}:{},...e.placeholder?{placeholder:e.placeholder}:{}},value:a[e.field],required:e.required??n.includes(e.field),issues:i[e.field],readOnly:o||e.readonly||e.immutable&&!s,fieldSpec:e,widgetContext:c,formData:a,onChange:t=>l(e.field,t)})},e.field):(0,X.jsxs)(`div`,{className:`rounded border border-dashed border-amber-500/40 bg-amber-500/5 p-2 text-xs text-amber-700 dark:text-amber-300`,style:{gridColumn:`span ${e.colSpan??1}`},children:[`⚠️ Field `,(0,X.jsx)(`code`,{children:e.field}),` declared in form layout but missing from schema. Skipping.`]},e.field)})})]},u)};if(d){let e=u.filter(e=>e.fields.map(Dp).some(e=>!e.hidden&&!r.includes(e.field)&&(!e.visibleOn||lp(e.visibleOn,{data:a}))));return e.length===0?null:(0,X.jsxs)(H,{defaultValue:(e[0].label??`section-0`).toLowerCase(),className:`w-full`,children:[(0,X.jsx)(xi,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>(0,X.jsx)(Xr,{value:(e.label??`section-${t}`).toLowerCase(),children:e.label??`Section ${t+1}`},t))}),e.map((e,t)=>(0,X.jsx)(ur,{value:(e.label??`section-${t}`).toLowerCase(),className:`mt-4`,children:f(e,t)},t))]})}return(0,X.jsx)(`div`,{className:`space-y-4`,children:u.map(f)})}function kp({name:e,schema:t,value:n,required:r,issues:i,readOnly:a,fieldSpec:o,widgetContext:s,formData:c,onChange:l}){let u=o?.label||t?.title||Lp(e),d=o?.helpText||t?.description,f=`mdf-${e}`,p=Tp(o,t),m=t?.type===`boolean`||p===`switch`,h=t?.default!==void 0,g=r&&!(m&&h),_=Lp(e).toLowerCase()===u.toLowerCase();return m?(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(Er,{htmlFor:f,className:`text-sm font-medium cursor-pointer`,children:[u,g&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),d&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:d}),i?.map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs text-destructive mt-0.5`,children:e},t))]}),(0,X.jsx)(Ap,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c})]}):(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between gap-2`,children:(0,X.jsxs)(Er,{htmlFor:f,className:`text-sm font-medium`,children:[u,g&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`}),!_&&(0,X.jsx)(`code`,{className:`ml-2 text-[10px] font-mono text-muted-foreground/70`,title:`Machine name`,children:e})]})}),(0,X.jsx)(Ap,{id:f,schema:t,value:n,onChange:l,readOnly:a,widget:p,fieldSpec:o,widgetContext:s,formData:c}),d&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:d}),i?.map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:e},t))]})}function Ap({id:e,schema:t,value:n,onChange:r,readOnly:i,widget:a,fieldSpec:o,widgetContext:s,formData:c}){if(o?.type===`composite`)return(0,X.jsx)(Mp,{value:n,fields:o.fields?.length?o.fields:zp(t),schema:t,readOnly:i,widgetContext:s,onChange:r});if(o?.type===`repeater`){let e=t?.items??{};return(0,X.jsx)(Np,{value:n,fields:o.fields?.length?o.fields:zp(e),schema:t,readOnly:i,widgetContext:s,widget:o.widget,onChange:r})}if(a){let l=bp[a];if(l)return(0,X.jsx)(l,{id:e,schema:t,value:n,onChange:r,readOnly:i,context:s,fieldSpec:o,formData:c});if(!wp.has(a))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Pp,{value:n,onChange:e=>r(e),readOnly:i}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`widget `,(0,X.jsx)(`code`,{className:`font-mono`,children:a}),` — falling back to JSON until a custom renderer is registered.`]})]})}let l=o?.options,u=t?.enum??void 0;if(Array.isArray(l)&&l.length>0)return(0,X.jsxs)(Yt,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,X.jsx)(_n,{id:e,children:(0,X.jsx)(Qe,{placeholder:`Select…`})}),(0,X.jsx)(Xi,{children:l.map(e=>(0,X.jsxs)(ke,{value:e.value,children:[e.label,e.color&&(0,X.jsx)(`span`,{className:`ml-2 inline-block h-3 w-3 rounded`,style:{backgroundColor:e.color}})]},e.value))})]});if(Array.isArray(u)&&u.length>0)return(0,X.jsxs)(Yt,{value:n==null?``:String(n),onValueChange:e=>r(e),disabled:i,children:[(0,X.jsx)(_n,{id:e,children:(0,X.jsx)(Qe,{placeholder:`Select…`})}),(0,X.jsx)(Xi,{children:u.map(e=>(0,X.jsx)(ke,{value:String(e),children:String(e)},String(e)))})]});if(t?.type===`boolean`||a===`switch`||o?.type===`boolean`||o?.type===`toggle`)return(0,X.jsx)(Ur,{id:e,checked:!!n,onCheckedChange:e=>r(e),disabled:i});if(t?.type===`number`||t?.type===`integer`){let a=o?.min,s=o?.max;return(0,X.jsx)(sr,{id:e,type:`number`,value:n==null?``:String(n),min:a,max:s,onChange:e=>{let n=e.target.value;if(n===``)return r(void 0);let i=t.type===`integer`?parseInt(n,10):Number(n);r(Number.isFinite(i)?i:void 0)},readOnly:i})}if(t?.type===`string`){let a=o?.maxLength;return t?.format===`multiline`||t?.contentMediaType===`text/markdown`||typeof n==`string`&&n.length>80?(0,X.jsx)(Vt,{id:e,rows:4,value:n??``,maxLength:a,onChange:e=>r(e.target.value||void 0),readOnly:i}):(0,X.jsx)(sr,{id:e,value:n??``,maxLength:a,onChange:e=>r(e.target.value||void 0),readOnly:i})}if(t?.type===`array`){let a=t?.items??{};if(a.type===`string`||a.type===`number`||a.type===`integer`)return(0,X.jsx)(sr,{id:e,value:(Array.isArray(n)?n:[]).map(String).join(`, `),placeholder:`comma, separated, values`,onChange:e=>{let t=e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean);a.type===`number`||a.type===`integer`?r(t.map(e=>Number(e)).filter(e=>Number.isFinite(e))):r(t)},readOnly:i})}return(0,X.jsx)(Pp,{value:n,onChange:r,readOnly:i,small:!0})}function jp(e,t,n){return e?(t===`composite`?e.properties:e.items?.properties)?.[n]??{}:{}}function Mp({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,onChange:a}){let o=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return(0,X.jsx)(`div`,{className:`rounded-md border border-border/50 bg-muted/20 p-3 space-y-3`,children:t.map(Dp).map(e=>{let t=jp(n,`composite`,e.field);return(0,X.jsx)(kp,{name:e.field,schema:t,value:o[e.field],required:!!e.required,readOnly:r||e.readonly,fieldSpec:e,widgetContext:i,formData:o,onChange:t=>a({...o,[e.field]:t})},e.field)})})}function Np({value:e,fields:t,schema:n,readOnly:r,widgetContext:i,widget:a,onChange:o}){let s=Array.isArray(e)?e:[],c=t.map(Dp),[l,u]=Y.useState(null),d=a===`grid`||a===`table`,f=(e,t)=>{o(s.map((n,r)=>r===e?{...n,...t}:n))},p=e=>o(s.filter((t,n)=>n!==e)),m=()=>{let e={};c.forEach(t=>{e[t.field]=void 0}),o([...s,e]),u(s.length)};return d?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border/50`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40`,children:(0,X.jsxs)(`tr`,{children:[c.map(e=>(0,X.jsxs)(`th`,{className:`px-2 py-1.5 text-left text-xs font-medium`,children:[e.label||Lp(e.field),e.required&&(0,X.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]},e.field)),!r&&(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsxs)(`tbody`,{children:[s.length===0&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:c.length+1,className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:Z(`engine.repeater.empty`,Hf())})}),s.map((e,t)=>(0,X.jsxs)(`tr`,{className:`border-t border-border/30 align-top`,children:[c.map(a=>{let o=jp(n,`repeater`,a.field);return(0,X.jsx)(`td`,{className:`p-1.5`,children:(0,X.jsx)(Ap,{id:`rep-${t}-${a.field}`,schema:o,value:e?.[a.field],readOnly:r||a.readonly,widget:Tp(a,o),fieldSpec:a,widgetContext:i,formData:e,onChange:e=>f(t,{[a.field]:e})})},a.field)}),!r&&(0,X.jsx)(`td`,{className:`p-1.5 text-right`,children:(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,X.jsx)(kt,{className:`h-3.5 w-3.5`})})})]},t))]})]})}),!r&&(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,X.jsx)(Ni,{className:`h-3.5 w-3.5 mr-1`}),` Add`]})]}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,X.jsx)(`div`,{className:`rounded-md border border-dashed border-border/50 px-3 py-4 text-center text-xs text-muted-foreground`,children:Z(`engine.list.empty`,Hf())}),s.map((e,t)=>{let a=l===t,o=c.map(t=>e?.[t.field]).find(e=>e!=null&&e!==``);return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-muted/10`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5 border-b border-border/30`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(a?null:t),className:`flex items-center gap-1.5 text-sm font-medium text-left flex-1 min-w-0`,children:[a?(0,X.jsx)(Ui,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Rn,{className:`h-3.5 w-3.5`}),(0,X.jsxs)(`span`,{className:`truncate`,children:[`#`,t+1,o==null?``:` — ${String(o)}`]})]}),!r&&(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`h-7 w-7 p-0`,"aria-label":`Remove`,children:(0,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]}),a&&(0,X.jsx)(`div`,{className:`p-3 space-y-3`,children:c.map(a=>{let o=jp(n,`repeater`,a.field);return(0,X.jsx)(kp,{name:a.field,schema:o,value:e?.[a.field],required:!!a.required,readOnly:r||a.readonly,fieldSpec:a,widgetContext:i,formData:e,onChange:e=>f(t,{[a.field]:e})},a.field)})})]},t)}),!r&&(0,X.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,X.jsx)(Ni,{className:`h-3.5 w-3.5 mr-1`}),` Add item`]})]})}function Pp({value:e,onChange:t,readOnly:n,small:r}){let[i,a]=Y.useState(()=>Ip(e)),[o,s]=Y.useState(null);return Y.useEffect(()=>{a(Ip(e)),s(null)},[JSON.stringify(e)]),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Vt,{rows:r?4:12,className:`font-mono text-xs`,value:i,readOnly:n,onChange:e=>{let n=e.target.value;if(a(n),!n.trim()){s(null),t(void 0);return}try{let e=JSON.parse(n);s(null),t(e)}catch(e){s(e?.message??`Invalid JSON`)}}}),o&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:o})]})}function Fp(e){let t={};for(let[n,r]of Object.entries(e))if(!n.startsWith(`_`))if(r==null)t[n]={type:`string`};else if(typeof r==`string`)t[n]=r.length>80||r.includes(`
14
- `)?{type:`string`,format:`multiline`}:{type:`string`};else if(typeof r==`number`)t[n]={type:Number.isInteger(r)?`integer`:`number`};else if(typeof r==`boolean`)t[n]={type:`boolean`};else if(Array.isArray(r))if(r.length>0&&typeof r[0]==`string`)t[n]={type:`array`,items:{type:`string`}};else if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let e=r[0],i={};for(let t of Object.keys(e))i[t]={type:`string`};t[n]={type:`array`,items:{type:`object`,properties:i}}}else t[n]={type:`array`,items:{type:`string`}};else typeof r==`object`?t[n]={type:`object`,additionalProperties:!0}:t[n]={type:`string`};return{type:`object`,properties:t,additionalProperties:!0}}function Ip(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Lp(e){return e.replace(/[_-]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function Rp(e,t){if(!t.length)return e;let n=new Set(e),r=t.filter(e=>n.has(e)),i=e.filter(e=>!t.includes(e));return[...r,...i]}function zp(e){let t=e?.properties??{};return Object.keys(t)}function Bp({type:e,name:t,parentItem:n,onOpen:r}){let i=kf(),a=v(),o=Y.useMemo(()=>tp(e),[e]),[s,c]=Y.useState([]),[l,u]=Y.useState(``),[d,f]=Y.useState({});if(Y.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(Vp)}}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=>Vp(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,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:`No related metadata`}),(0,X.jsxs)($e,{children:[`No metadata types are configured to anchor at `,(0,X.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,X.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,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,X.jsx)(zr,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,X.jsx)(sr,{placeholder:`Search related…`,value:l,onChange:e=>u(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,X.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,X.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,X.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,X.jsx)(Rn,{className:Pn(`h-4 w-4 text-muted-foreground transition-transform`,!o&&`rotate-90`)}),(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,X.jsx)(K,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,X.jsx)(q,{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,X.jsx)(Ni,{className:`h-3.5 w-3.5`})})]}),!o&&(0,X.jsxs)(`div`,{className:`divide-y`,children:[n.loading&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:h?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.map((i,a)=>(0,X.jsxs)(`button`,{type:`button`,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}),className:`w-full text-left px-3 py-2 hover:bg-accent/50 flex items-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-mono text-xs truncate`,children:i.name}),i.label&&i.label!==i.name&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:i.label})]}),(0,X.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground`})]},`${i.name}-${a}`))]})]},n.childType)})]})}function Vp(e){return{name:Hp(e,[`name`,`id`,`key`])??`(unnamed)`,label:Hp(e,[`label`,`title`,`displayName`]),description:Hp(e,[`description`,`summary`]),raw:e}}function Hp(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function Up({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=kf(),{entries:c}=Af(s),l=i?c.find(e=>e.type===i):void 0,u=!l?.schema&&i?Gp[i]:void 0,d=l?.schema??u?.schema,f=l?.form??u?.form,[p,m]=Y.useState(a),[h,g]=Y.useState(!1),[_,v]=Y.useState(null),[y,b]=Y.useState([]),[x,S]=Y.useState(null);Y.useEffect(()=>{m(a),v(null),b([]),S(null)},[a,r,e,t]);let C=l!=null&&!l.allowOrgOverride;async function w(){if(!n){v(`Cannot save: this item has no embeddedPath registered.`);return}g(!0),v(null),b([]);try{let i=await s.layered(e,t),a=Wp(i.effective??i.code??{},n,r,p);await s.save(e,t,a),S(Date.now()),o?.(p)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:String(e.message??`Invalid`)}});b(i),v(`Validation failed (${i.length} issue${i.length===1?``:`s`}).`)}else v(e?.message??String(e))}finally{g(!1)}}return d?(0,X.jsxs)(`div`,{className:`p-4 space-y-4`,children:[_&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:_}),x!=null&&!_&&(0,X.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:`Saved.`}),C&&(0,X.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:`The parent type is read-only — saving will still attempt a PUT and may be refused by the server.`}),(0,X.jsx)(Ep,{schema:d,form:f,value:p,onChange:m,issues:y}),(0,X.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,X.jsxs)(q,{onClick:w,disabled:h||!n,children:[h?(0,X.jsx)(qr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(fr,{className:`h-4 w-4 mr-1`}),`Save into `,e]})}),!n&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Read-only`}),(0,X.jsx)(`div`,{children:`No embedded path registered — cannot determine where to write this item back.`})]})]}):(0,X.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`No form schema is registered for`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:i??`this item`}),`. Edit the raw JSON below; saving will splice it back into`,` `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[e,`/`,t,`.`,n,`.`,r]}),`.`]}),(0,X.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(p,null,2),onChange:e=>{try{m(JSON.parse(e.target.value)),v(null)}catch(e){v(`Invalid JSON: ${e.message}`)}}}),_&&(0,X.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 inline mr-1`}),` `,_]}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)(q,{onClick:w,disabled:h||!n,children:[h?(0,X.jsx)(qr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(fr,{className:`h-4 w-4 mr-1`}),`Save into parent`]})})]})}function Wp(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 Gp={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 Kp({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,X.jsx)(wt,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,X.jsxs)(At,{side:`right`,className:Pn(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,X.jsxs)(We,{className:`px-4 py-3 border-b space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(K,{variant:`outline`,className:`font-mono text-[10px]`,children:o}),(0,X.jsx)(at,{className:`font-mono text-base truncate`,children:s}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:i&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,X.jsx)(sn,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,X.jsxs)(Bt,{className:`text-xs`,children:[a?`Embedded in `:`Related to `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[i&&(0,X.jsx)(Xp,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),a&&(0,X.jsx)(Up,{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}`)]})]})})}var qp=new Map;function Jp(e,t){qp.set(e,t)}function Yp(e){return qp.get(e)}function Xp({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=a(),o=e??i.type??``,s=t??i.name??``,c=v(),l=kf(),{entries:u}=Af(l),d=u.find(e=>e.type===o),f=np(o,d),p=Y.useMemo(()=>Hf(),[]),m=ep(o);if(m?.EditPage&&!n){let e=m.EditPage;return(0,X.jsx)(e,{type:o,name:s})}if(m?.CreatePage&&n){let e=m.CreatePage;return(0,X.jsx)(e,{type:o})}let[h,g]=Y.useState(null),[_,y]=Y.useState(n?{name:``}:{}),[b,x]=Y.useState(null),[S,C]=Y.useState(!n),[w,T]=Y.useState(!1),[E,D]=Y.useState(null),[O,k]=Y.useState([]),[A,j]=Y.useState(null),[M,ee]=Y.useState(null),[te,ne]=Y.useState(!!n),N=Y.useRef(null),[P,F]=Y.useState([]),[re,ie]=Y.useState(!0);Y.useEffect(()=>{let e=!1;return(async()=>{try{let t=await l.list(`object`);if(e)return;F(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||F([])}finally{e||ie(!1)}})(),()=>{e=!0}},[l]);let I=Y.useMemo(()=>({objectNames:P,objectsLoading:re}),[P,re]);Y.useEffect(()=>{if(n){C(!1);return}let e=!1;return C(!0),D(null),(async()=>{try{let t=await l.layered(o,s);if(e)return;g(t);let n=t.effective??t.code??{};y(n),N.current=n,C(!1)}catch(t){e||(D(t?.message??String(t)),C(!1))}})(),()=>{e=!0}},[l,o,s,n]);let[ae,oe]=Y.useState(!1);async function se(){if(!(b!=null||ae)){oe(!0);try{x(await l.references(o,s))}catch(e){x([]),console.error(`references() failed`,e)}finally{oe(!1)}}}let[ce,le]=Y.useState(null),ue=Y.useMemo(()=>!n&&!r&&tp(o).length>0,[o,n,r]),de=Y.useRef(null);Y.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);t&&(de.current=t);let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&le({kind:`metadata`,type:e,name:t})}},[]),Y.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]);async function L(e){T(!0),D(null),k([]);try{let t=n?{..._,name:String(_.name??s)}:_,r=String(t.name??s);if(!r){D(`A name is required.`),T(!1);return}await l.save(o,r,t,{force:e});let i=await l.layered(o,r);g(i);let a=i.effective??t;y(a),N.current=a,j(null),ee(null),n||ne(!1),n&&c(`../${encodeURIComponent(r)}`)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];j(Array.isArray(t)?t:[]),ee(_)}else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:String(e.message??`Invalid`)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:e[2].trim()}]:[{path:``,message:r}]}k(n),n.length===1&&!n[0].path?D(n[0].message):n.length===1?D(`${n[0].path}: ${n[0].message}`):D(`Validation failed (${n.length} issues).`)}else D(e?.message??String(e))}finally{T(!1)}}async function fe(){if(confirm(`Reset overlay for ${o}/${s}? Code-level value will be restored.`)){T(!0),D(null);try{await l.reset(o,s);let e=await l.layered(o,s);g(e);let t=e.effective??e.code??{};y(t),N.current=t,ne(!1)}catch(e){D(e?.message??String(e))}finally{T(!1)}}}if(S)return(0,X.jsx)(Xf,{entry:d,itemName:s,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` Loading `,o,`/`,s,`…`]})});let pe=d?.schema??f.defaultSchema,me=!d?.allowOrgOverride&&!n,R=!n&&!r?Yp(o):void 0;function he(){N.current&&y(N.current),k([]),D(null),ne(!1)}let ge=me||!te&&!n,z=de.current??(R?`preview`:`form`);return(0,X.jsxs)(Xf,{entry:d??{type:o,label:o},itemName:n?`(new)`:s,subtitle:Z(n?`engine.edit.createNew`:`engine.edit.editOverlay`,p),actions:(0,X.jsxs)(X.Fragment,{children:[!n&&d?.allowOrgOverride&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:fe,disabled:w,children:[(0,X.jsx)(vr,{className:`h-4 w-4 mr-1`}),Z(`engine.edit.reset`,p)]}),!n&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>c(`./history`),children:[(0,X.jsx)(Mi,{className:`h-4 w-4 mr-1`}),Z(`engine.edit.history`,p)]}),d?.allowOrgOverride&&!n&&!te&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>ne(!0),children:[(0,X.jsx)(W,{className:`h-4 w-4 mr-1`}),Z(`engine.edit.edit`,p)]}),d?.allowOrgOverride&&!n&&te&&(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:he,disabled:w,children:[(0,X.jsx)(Jn,{className:`h-4 w-4 mr-1`}),Z(`engine.cancel`,p)]}),d?.allowOrgOverride&&(te||n)&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>L(!1),disabled:w,children:[w?(0,X.jsx)(qr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(fr,{className:`h-4 w-4 mr-1`}),Z(`engine.edit.save`,p)]})]}),children:[(0,X.jsxs)(`div`,{className:`p-6 space-y-6 max-w-7xl`,children:[E&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:E}),me&&(0,X.jsxs)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-3`,children:[`This type is read-only. To enable runtime editing, set`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`}),` to include `,(0,X.jsx)(`code`,{className:`font-mono`,children:o}),`, or flip`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`}),` in the registry.`]}),(0,X.jsxs)(H,{defaultValue:z,className:`w-full`,onValueChange:e=>{if(typeof window>`u`||r)return;let t=new URL(window.location.href);t.searchParams.set(`tab`,e),window.history.replaceState({},``,t.toString())},children:[(0,X.jsxs)(xi,{children:[R&&(0,X.jsxs)(Xr,{value:`preview`,children:[(0,X.jsx)(pn,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.preview`,p)]}),(0,X.jsx)(Xr,{value:`form`,children:Z(`engine.edit.detail`,p)}),!n&&(0,X.jsxs)(Xr,{value:`layers`,children:[Z(`engine.edit.layers`,p),h?.overlay&&(0,X.jsx)(K,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:Z(`engine.edit.overlay`,p)})]}),!n&&(0,X.jsxs)(Xr,{value:`references`,onClick:se,children:[(0,X.jsx)(fi,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.references`,p),b&&(0,X.jsx)(K,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:b.length})]}),ue&&(0,X.jsxs)(Xr,{value:`related`,children:[(0,X.jsx)(dr,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.related`,p)]})]}),(0,X.jsxs)(ur,{value:`form`,className:`mt-4 space-y-3`,children:[ge&&!me&&d?.allowOrgOverride&&!n&&(0,X.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,X.jsx)(`span`,{children:Z(`engine.edit.readOnlyBanner`,p).split(/\{edit\}/).map((e,t,n)=>(0,X.jsxs)(Y.Fragment,{children:[e,t<n.length-1&&(0,X.jsx)(`strong`,{children:Z(`engine.edit.edit`,p)})]},t))}),(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>ne(!0),children:[(0,X.jsx)(W,{className:`h-3.5 w-3.5 mr-1`}),Z(`engine.edit.edit`,p)]})]}),(0,X.jsx)(Ep,{schema:pe,form:d?.form,value:_,onChange:y,issues:O,hiddenFields:f.hiddenFields,fieldOrder:f.fieldOrder,readOnly:ge,createMode:n,widgetContext:I})]}),R&&(0,X.jsx)(ur,{value:`preview`,className:`mt-4`,children:(0,X.jsx)(R,{type:o,name:s,draft:_})}),!n&&(0,X.jsx)(ur,{value:`layers`,className:`mt-4`,children:(0,X.jsx)(sp,{layered:h})}),!n&&(0,X.jsx)(ur,{value:`references`,className:`mt-4`,children:(0,X.jsx)(Zp,{refs:b,loading:ae})}),ue&&(0,X.jsx)(ur,{value:`related`,className:`mt-4`,children:(0,X.jsx)(Bp,{type:o,name:s,parentItem:_,onOpen:e=>le(e)})})]})]}),(0,X.jsx)(Kp,{target:ce,onClose:()=>le(null),parentContext:{type:o,name:s}}),(0,X.jsx)(He,{open:A!=null,onOpenChange:e=>{e||(j(null),ee(null))},children:(0,X.jsxs)(nt,{children:[(0,X.jsxs)(Ji,{children:[(0,X.jsxs)(De,{className:`flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,X.jsx)(gt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,X.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:A?.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,X.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,X.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,X.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{variant:`ghost`,onClick:()=>j(null),children:`Cancel`}),(0,X.jsx)(q,{variant:`destructive`,onClick:()=>L(!0),disabled:w,children:w?`Forcing…`:`Force save`})]})]})})]})}function Zp({refs:e,loading:t}){return t||e==null?(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:`No references found`}),(0,X.jsx)($e,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,X.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,X.jsx)(`td`,{className:`px-3 py-2`,children:(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function Qp({type:e,name:t}){let n=a(),r=e??n.type??``,i=t??n.name??``,o=v(),s=kf(),{entries:c}=Af(s),l=c.find(e=>e.type===r),[u,d]=Y.useState([]),[f,p]=Y.useState(!0),[m,h]=Y.useState(null),[g,_]=Y.useState(0),[y,b]=Y.useState(null);return Y.useEffect(()=>{let e=!1;return p(!0),h(null),(async()=>{try{let t=await s.history(r,i,{limit:100});if(e)return;d([...Array.isArray(t)?t:Array.isArray(t?.events)?t.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0))),p(!1)}catch(t){e||(h(t?.message??String(t)),p(!1))}})(),()=>{e=!0}},[s,r,i,g]),(0,X.jsx)(Xf,{entry:l??{type:r,label:r},itemName:i,subtitle:`Version history`,stats:[{label:`Events`,value:u.length}],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(i)}`),children:[(0,X.jsx)(qe,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,X.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>_(e=>e+1),children:(0,X.jsx)(Oi,{className:`h-4 w-4`})})]}),children:(0,X.jsxs)(`div`,{className:`p-6 max-w-4xl`,children:[f&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),m&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:m}),!f&&!m&&u.length===0&&(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:`No history yet`}),(0,X.jsx)($e,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!f&&u.length>0&&(0,X.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:u.map((e,t)=>{let n=y===t;return(0,X.jsxs)(`li`,{className:`relative`,children:[(0,X.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,X.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>b(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&b(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsxs)(K,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),e.kind&&(0,X.jsx)(K,{className:`text-[10px] `+(e.kind===`delete`||e.kind===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:e.kind===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(e.kind)}),e.actor&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),e.at&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:$p(e.at)})]}),n&&(0,X.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:em(e)})]})]},`${e.seq??t}-${t}`)})})]})})}function $p(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function em(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function tm({type:e}){let t=u(),[n]=o(),r=e??n.get(`type`)??``;if(!r)return(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:`Missing metadata type`}),(0,X.jsxs)($e,{children:[`This page expects a `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,X.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let i=nm(t.pathname),a=i.split(`/`).filter(Boolean);return a.length===0?(0,X.jsx)(rp,{type:r}):a[0]===`new`&&a.length===1?(0,X.jsx)(Xp,{type:r,name:``,createMode:!0},`${r}:__new__`):a.length===2&&a[1]===`history`?(0,X.jsx)(Qp,{type:r,name:decodeURIComponent(a[0])}):a.length===1?(0,X.jsx)(Xp,{type:r,name:decodeURIComponent(a[0])},`${r}:${a[0]}`):(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(ze,{children:[(0,X.jsx)(Ki,{children:`Unknown sub-path`}),(0,X.jsxs)($e,{children:[`The path `,(0,X.jsx)(`code`,{className:`font-mono`,children:i}),` isn't recognized. Valid forms are `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function nm(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function rm(e){return[{key:`allowCreate`,short:`C`,tip:Z(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:Z(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:Z(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:Z(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:Z(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:Z(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:Z(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:Z(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:Z(`perm.action.modifyAll`,e)}]}function im({type:e,name:t}){let n=v(),r=kf(),{entries:i}=Af(r),a=i.find(t=>t.type===e),o=!!np(e,a).allowOrgOverride,s=Y.useMemo(()=>Hf(),[]),c=Y.useCallback(e=>Z(e,s),[s]),l=Y.useMemo(()=>rm(s),[s]),[u,d]=Y.useState({name:t,objects:{},fields:{}}),[f,p]=Y.useState([]),[m,h]=Y.useState({}),[g,_]=Y.useState(new Set),[y,b]=Y.useState(!0),[x,S]=Y.useState(!1),[C,w]=Y.useState(null),[T,E]=Y.useState(null),[D,O]=Y.useState(``),[k,A]=Y.useState(!1);Y.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 te(e,t){d(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(l.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function ne(e,t,n,r){let i=`${e}.${t}`;d(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}async function N(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 P=Y.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,X.jsx)(Xf,{entry:a,itemName:t,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` `,c(`perm.loading`).replace(`{name}`,t)]})}):(0,X.jsxs)(Xf,{entry:a??{type:e,label:e},itemName:t,subtitle:u.isProfile?c(`perm.subtitle.profile`):c(`perm.subtitle.set`),stats:F,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>n(`./history?type=${encodeURIComponent(e)}`),children:[(0,X.jsx)(Mi,{className:`h-4 w-4 mr-1`}),` `,c(`engine.edit.history`)]}),o&&(0,X.jsxs)(q,{size:`sm`,onClick:()=>N(!1),disabled:x,children:[x?(0,X.jsx)(qr,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(fr,{className:`h-4 w-4 mr-1`}),c(`engine.edit.save`)]})]}),children:[(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[C&&(0,X.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,X.jsx)(jr,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{children:C})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Er,{htmlFor:`perm-name`,className:`text-xs`,children:c(`perm.field.name`)}),(0,X.jsx)(sr,{id:`perm-name`,value:u.name,disabled:!o,onChange:e=>d(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(Er,{htmlFor:`perm-label`,className:`text-xs`,children:c(`perm.field.label`)}),(0,X.jsx)(sr,{id:`perm-label`,value:u.label??``,disabled:!o,onChange:e=>d(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,X.jsx)(Ur,{id:`perm-is-profile`,checked:!!u.isProfile,disabled:!o,onCheckedChange:e=>d(t=>({...t,isProfile:!!e}))}),(0,X.jsx)(Er,{htmlFor:`perm-is-profile`,className:`text-xs`,children:c(`perm.field.isProfile`)})]}),!o&&(0,X.jsx)(K,{variant:`secondary`,className:`ml-auto`,children:c(`perm.readOnly`)})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,X.jsx)(sr,{placeholder:c(`perm.filter.placeholder`),value:D,onChange:e=>O(e.target.value),className:`h-8 w-72`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Ur,{id:`only-enabled`,checked:k,onCheckedChange:e=>A(!!e)}),(0,X.jsx)(Er,{htmlFor:`only-enabled`,className:`text-xs`,children:c(`perm.filter.onlyGranted`)})]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[P.length,` / `,f.length,` `,c(`perm.stat.objectsSuffix`)]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,X.jsx)(am,{objects:P,draft:u,expanded:g,fieldsByObject:m,writable:o,objectActions:l,t:c,onToggleExpand:M,onObjectPerm:ee,onFieldPerm:ne,onBulkSet:te})})]}),(0,X.jsx)(He,{open:!!T,onOpenChange:e=>!e&&E(null),children:(0,X.jsxs)(nt,{children:[(0,X.jsxs)(Ji,{children:[(0,X.jsxs)(De,{className:`flex items-center gap-2`,children:[(0,X.jsx)(jr,{className:`h-4 w-4 text-amber-500`}),` `,c(`engine.edit.destructive`)]}),(0,X.jsx)(gt,{children:c(`engine.edit.destructiveHint`)})]}),(0,X.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:T?.issues.map((e,t)=>(0,X.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,X.jsx)(K,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,X.jsxs)(qt,{children:[(0,X.jsx)(q,{variant:`ghost`,onClick:()=>E(null),children:c(`engine.cancel`)}),(0,X.jsxs)(q,{variant:`destructive`,onClick:()=>T&&N(!0,T.pending),disabled:x,children:[x&&(0,X.jsx)(qr,{className:`h-4 w-4 mr-1 animate-spin`}),c(`engine.edit.forceSave`)]})]})]})})]})}function am({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,X.jsxs)(`tbody`,{children:[e.length===0&&(0,X.jsx)(`tr`,{children:(0,X.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,X.jsxs)(Y.Fragment,{children:[(0,X.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,X.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,X.jsx)(Ui,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Rn,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,X.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,X.jsx)(Ke,{checked:!!d[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,X.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,X.jsx)(q,{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,X.jsx)(q,{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,X.jsx)(q,{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,X.jsx)(q,{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,X.jsx)(`tr`,{className:`bg-muted/10`,children:(0,X.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,X.jsx)(om,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function om({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,X.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,X.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,X.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,X.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(Ke,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(Ke,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function sm(){$f({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>cm(e.fields),groupLabel:`Fields`,order:5}]}),$f({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}]}),$f({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>cm(e.validations),groupLabel:`Embedded Validations`,order:15}]}),$f({type:`hook`,anchors:[{anchorType:`object`,match:Zf(`object`),groupLabel:`Hooks`,order:20}]}),$f({type:`approval`,anchors:[{anchorType:`object`,match:Zf(`object`),groupLabel:`Approval Processes`,order:70}]}),$f({type:`page`,anchors:[{anchorType:`object`,match:Zf(`object`),groupLabel:`Pages`,order:40}]}),$f({type:`view`,anchors:[{anchorType:`object`,match:Zf([`data.object`,`list.data.object`,`form.data.object`,`object`]),groupLabel:`Views`,order:30}]}),$f({type:`flow`,anchors:[{anchorType:`object`,match:Zf([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}]}),$f({type:`workflow`,anchors:[{anchorType:`object`,match:Zf([`object`,`on.object`]),groupLabel:`Workflow Rules`,order:51}]}),$f({type:`trigger`,anchors:[{anchorType:`object`,match:Zf([`object`,`on.object`]),groupLabel:`Triggers`,order:52}]}),$f({type:`validation`,anchors:[{anchorType:`object`,match:Zf(`object`),groupLabel:`Validations`,order:25}]}),$f({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}]}),$f({type:`action`,anchors:[{anchorType:`object`,match:Zf([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}]}),$f({type:`dashboard`,anchors:[{anchorType:`object`,match:Zf([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}]}),$f({type:`report`,anchors:[{anchorType:`object`,match:Zf([`object`,`data.object`]),groupLabel:`Reports`,order:81}]})}function cm(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var lm={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`}},um={role:{type:`object`,title:`Role`,required:[`name`],properties:{...lm,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:{...lm,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 Set`,required:[`name`],properties:{...lm,isProfile:{type:`boolean`,title:`Is profile`},objects:{type:`object`,title:`Object Permissions`},fields:{type:`object`,title:`Field Permissions`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...lm.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:lm.label,description:lm.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:{...lm,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:{...lm,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...lm,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...lm,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...lm,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:{...lm,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...lm,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`],properties:{...lm,subject:{type:`string`,title:`Subject`},body:{type:`string`,title:`Body (HTML / text)`,format:`multiline`},from:{type:`string`,title:`From address`}}}};function dm(){for(let[e,t]of Object.entries(um))$f({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Q({hint:e,title:t=`Preview`,toolbar:n,children:r}){return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b bg-muted/30 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(pn,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:t}),e!=null&&(0,X.jsx)(`span`,{className:`ml-1 text-[10px] uppercase tracking-wider opacity-70`,children:e})]}),n]}),(0,X.jsx)(`div`,{className:`bg-background`,children:r})]})}function fm({tone:e=`info`,children:t}){return(0,X.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,X.jsx)(Sr,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`div`,{className:`flex-1`,children:t})]})}var pm=class extends Y.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,X.jsxs)(fm,{tone:`error`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,X.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,X.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function mm({draft:e}){let t=Y.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]);return!t||Object.keys(t).length<=1?(0,X.jsx)(Q,{hint:`page`,children:(0,X.jsx)(fm,{children:`Add components to the page to see a preview.`})}):(0,X.jsx)(Q,{hint:`page`,children:(0,X.jsx)(pm,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:(0,X.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,X.jsx)(M,{schema:t})})})})}var hm=[`list`,`form`,`kanban`,`calendar`,`gantt`,`map`,`gallery`,`timeline`,`feed`,`detail`];function gm(e){let t=[];for(let n of hm){let r=e[n];r&&typeof r==`object`&&!Array.isArray(r)&&t.push({key:n,schema:r})}return t}function _m(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object,e.list?.data?.object,e.list?.object];for(let e of n)if(typeof e==`string`&&e)return e}function vm({name:e,draft:t}){let n=Y.useMemo(()=>gm(t),[t]),r=Y.useMemo(()=>_m(t,n[0]?.schema),[t,n]),{listViews:i,defaultViewId:a}=Y.useMemo(()=>{let r={},i=n.find(e=>e.key===`list`)??n[0],a=String(e)||i?.key||`default`;i&&(r[a]={...i.schema,label:i.schema.label??t.label??e});let o=t.listViews;if(o&&typeof o==`object`&&!Array.isArray(o))for(let[e,t]of Object.entries(o))t&&typeof t==`object`&&e!==a&&(r[e]=t);return{listViews:r,defaultViewId:i?a:void 0}},[t,n,e]);if(!n.length&&t.type){let e={...t};return(0,X.jsx)(Q,{hint:`view · ${e.type}`,children:(0,X.jsx)(pm,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(M,{schema:e})})})})}if(!r)return(0,X.jsx)(Q,{hint:`view`,children:(0,X.jsxs)(fm,{tone:`warn`,children:[`This view has no object binding yet. Set `,(0,X.jsx)(`code`,{children:`list.data.object`}),` in the Form tab to fetch live data.`]})});let o=n[0]?.schema?.type??`grid`,s=Y.useMemo(()=>({type:`object-view`,objectName:r,defaultViewType:o,defaultListView:a,listViews:i,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[r,o,a,i]);return(0,X.jsx)(Q,{hint:`view · ${n.map(e=>e.key).slice(0,3).join(` · `)||`list`}`,children:(0,X.jsx)(pm,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(M,{schema:s})})})})}var ym=Y.lazy(()=>m(()=>import(`./plugin-dashboard-DvBectcr.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function bm({draft:e}){let t=ge(),n=Array.isArray(e.widgets)?e.widgets:[];return n.length===0?(0,X.jsx)(Q,{hint:`dashboard`,children:(0,X.jsx)(fm,{children:`Add at least one widget to see a preview.`})}):(0,X.jsx)(Q,{hint:`dashboard · ${n.length} widget${n.length===1?``:`s`}`,children:(0,X.jsx)(pm,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,X.jsx)(ym,{schema:e,dataSource:t,designMode:!1,hideHeaderText:!0})})})})})}var xm=Y.lazy(()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Sm({draft:e}){let t=ge(),n=e.object??e.objectName??e.data?.object,r=e.visualization?.type??e.type;return n?(0,X.jsx)(Q,{hint:`report · ${r??`table`}`,children:(0,X.jsx)(pm,{fallbackHint:`The Report references an object/field that doesn't resolve, or its visualization config is incomplete.`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 min-h-[300px] max-h-[70vh] overflow-auto`,children:(0,X.jsx)(xm,{schema:e,dataSource:t})})})})}):(0,X.jsx)(Q,{hint:`report`,children:(0,X.jsx)(fm,{tone:`warn`,children:`Pick an Object in the Form tab — Reports need a source object before they can render.`})})}function Cm(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)?Cm(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function wm(e){switch(e){case`object`:return Dn;case`page`:return mt;case`dashboard`:return er;case`report`:return Pi;default:return ve}}function Tm({name:e,draft:t}){let n=String(t.name??e??``),r=t.label??n,i=t.landingRoute??t.landing??t.defaultRoute??`/`,a=Y.useMemo(()=>{let e=[t.nav,t.navigation,t.tabs,t.items,t.menu];for(let t of e)if(Array.isArray(t)&&t.length)return Cm(t);return[]},[t]),o=n?`/apps/${encodeURIComponent(n)}/`:null;return(0,X.jsx)(Q,{hint:`app`,toolbar:o&&(0,X.jsxs)(`a`,{href:o,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,X.jsx)(sn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(r)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:n}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,X.jsx)(`code`,{className:`font-mono`,children:String(i)})]})]}),a.length===0?(0,X.jsxs)(fm,{children:[`No top-level nav items. Add `,(0,X.jsx)(`code`,{children:`nav`}),` / `,(0,X.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,X.jsx)(`div`,{className:`border rounded divide-y`,children:a.map((e,t)=>(0,X.jsx)(Em,{item:e,appName:n,depth:0},t))})]})})})}function Em({item:e,appName:t,depth:n}){let r=wm(e.kind),i=Dm(t,e.path);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40`,style:{paddingLeft:`${12+n*16}px`},children:[(0,X.jsx)(r,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),i&&(0,X.jsxs)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,X.jsx)(sn,{className:`h-3 w-3`})]})]}),e.children?.map((e,r)=>(0,X.jsx)(Em,{item:e,appName:t,depth:n+1},r))]})}function Dm(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 Om({name:e,draft:t}){let n=String(t.name??e??``);return n?(0,X.jsx)(Q,{hint:`object · live data`,children:(0,X.jsx)(pm,{fallbackHint:`The object metadata couldn't be rendered. Save the draft and reload to retry.`,children:(0,X.jsx)(`div`,{className:`max-h-[75vh] overflow-auto`,children:(0,X.jsx)(M,{schema:Y.useMemo(()=>({type:`object-view`,objectName:n,defaultViewType:`grid`,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[n])})})})}):(0,X.jsx)(Q,{hint:`object`,children:(0,X.jsx)(fm,{children:`Give the object a name to enable preview.`})})}function km(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 Am(e,t){return t[e]??``}function jm(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Am(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Am(n,t))}function Mm({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=Y.useMemo(()=>{let e=new Set;for(let n of km(t))e.add(n);for(let t of km(i))e.add(t);for(let t of km(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=Y.useState({}),l=jm(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
15
- html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
16
- a{color:#2563eb;}
17
- </style></head><body>${(i?jm(i,s):jm(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(fm,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,X.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,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,X.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,X.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,X.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,X.jsxs)(`label`,{className:`block`,children:[(0,X.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,X.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 Nm(e){switch(e){case`start`:return Le;case`end`:return Qn;case`decision`:case`branch`:case`gateway`:return ot;case`wait`:case`timer`:return _t;case`boundary_event`:case`signal`:return Wi;case`subflow`:case`flow`:return Qt;default:return pr}}function Pm(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Fm(e,t){if(e.length===0)return[];let n=new Map(e.map(e=>[e.id,e])),r=new Map;for(let e of t)!n.has(e.source)||!n.has(e.target)||(r.has(e.source)||r.set(e.source,[]),r.get(e.source).push(e.target));let i=e.find(e=>e.type===`start`)??e[0],a=new Set,o=[],s=[i.id];for(;s.length;){let e=s.shift();if(a.has(e))continue;a.add(e);let t=n.get(e);t&&o.push(t);for(let t of r.get(e)??[])a.has(t)||s.push(t)}for(let t of e)a.has(t.id)||o.push(t);return o}function Im({draft:e}){let t=e,n=Array.isArray(t.nodes)?t.nodes:[],r=Array.isArray(t.edges)?t.edges:[],i=Array.isArray(t.variables)?t.variables:[],a=Y.useMemo(()=>Fm(n,r),[n,r]),o=Y.useMemo(()=>{let e=new Map;for(let t of r)e.has(t.source)||e.set(t.source,[]),e.get(t.source).push(t);return e},[r]),s=Y.useMemo(()=>new Map(n.map(e=>[e.id,e])),[n]),c=String(t.type??`autolaunched`),l=String(t.status??(t.active?`active`:`draft`)),u=String(t.runAs??`user`),d=t.version==null?void 0:String(t.version),f=t.errorHandling?.strategy;return n.length===0?(0,X.jsx)(Q,{hint:`flow`,children:(0,X.jsx)(fm,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,X.jsx)(Q,{hint:`flow · ${n.length} node${n.length===1?``:`s`}`,children:(0,X.jsx)(pm,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,X.jsx)(Rm,{icon:Wi,label:`Trigger`,value:c}),(0,X.jsx)(Rm,{icon:pr,label:`Status`,value:l,tone:l===`active`?`green`:l===`draft`?`gray`:`amber`}),(0,X.jsx)(Rm,{icon:pi,label:`Run as`,value:u}),d&&(0,X.jsx)(Rm,{label:`v`,value:d}),f&&(0,X.jsx)(Rm,{icon:Or,label:`On error`,value:f})]}),(0,X.jsx)(`ol`,{className:`space-y-2`,children:a.map((e,t)=>{let n=Nm(e.type),r=o.get(e.id)??[],i=e.type===`decision`||e.type===`branch`||e.type===`gateway`;return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-mono`,children:t+1}),(0,X.jsx)(n,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.id}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.type})]}),Lm(e)&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5 truncate`,children:Lm(e)})]})]}),r.length>0&&(0,X.jsx)(`div`,{className:`border-t bg-muted/20 px-3 py-1.5 text-[11px] space-y-0.5`,children:r.map((e,t)=>{let n=Pm(e.condition),r=s.get(e.target),a=i?e.isDefault?`else`:n?`if ${n}`:e.label??`branch`:e.label??(n?`when ${n}`:`next`);return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(ft,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:a}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:r?.label||e.target}),!r&&(0,X.jsx)(`span`,{className:`ml-1 text-amber-600`,children:`(unresolved)`})]},e.id||t)})})]},e.id||t)})})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(Fi,{className:`h-3 w-3`}),` Variables`]}),i.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((e,t)=>(0,X.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-1`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type})]}),e.defaultValue!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]})]})})})}function Lm(e){let t=e.config;if(!t)return;if(typeof t.objectName==`string`)return`object: ${t.objectName}`;if(typeof t.flowName==`string`)return`flow: ${t.flowName}`;if(typeof t.actionName==`string`)return`action: ${t.actionName}`;if(typeof t.eventType==`string`)return`event: ${t.eventType}`;if(typeof t.expression==`string`)return`expr: ${t.expression}`;let n=Object.keys(t).slice(0,3);return n.length?n.map(e=>`${e}`).join(`, `):void 0}function Rm({icon:e,label:t,value:n,tone:r=`gray`}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,X.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function zm(e){switch(e){case`field_update`:return W;case`email_alert`:return U;case`http_call`:case`webhook`:return Se;case`task_creation`:return Vn;case`push_notification`:return rt;case`custom_script`:return Yr;case`connector_action`:return nn;default:return St}}function Bm(e){switch(e.type){case`field_update`:return`${e.objectName??`?`}.${e.fieldName??`?`} = ${Vm(e.value)}`;case`email_alert`:return`template: ${e.templateName??`?`} → ${Hm(e)}`;case`http_call`:case`webhook`:return`${String(e.method??`POST`).toUpperCase()} ${e.url??e.endpoint??`?`}`;case`task_creation`:return`assign to ${e.assigneeRef??e.assignee??`?`} — ${e.subject??``}`;case`push_notification`:return`${e.title??``}`;case`custom_script`:return`${e.scriptName??e.functionName??`?`}`;case`connector_action`:return`${e.connectorId??`?`}.${e.actionId??`?`}`;default:return}}function Vm(e){return e==null?`∅`:typeof e==`string`?`"${e}"`:typeof e==`object`?JSON.stringify(e):String(e)}function Hm(e){let t=e.recipients??e.to;return Array.isArray(t)?t.slice(0,3).join(`, `)+(t.length>3?`, …`:``):typeof t==`string`?t:`—`}function Um({draft:e}){let t=e,n=String(t.objectName??t.object??``),r=String(t.triggerType??t.trigger??`—`),i=t.criteria,a=typeof i==`string`?i:i&&typeof i==`object`&&typeof i.source==`string`?i.source:void 0,o=Array.isArray(t.actions)?t.actions:[],s=Array.isArray(t.timeTriggers)?t.timeTriggers:[],c=t.active!==!1,l=t.executionOrder;return!n&&o.length===0&&s.length===0?(0,X.jsx)(Q,{hint:`workflow`,children:(0,X.jsx)(fm,{children:`Set the target object and at least one action to see the workflow preview.`})}):(0,X.jsx)(Q,{hint:`workflow · ${o.length+s.reduce((e,t)=>e+(t.actions?.length??0),0)} action(s)`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 text-xs space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,X.jsx)(Jm,{icon:Qt,label:`Object`,value:n||`—`,mono:!0}),(0,X.jsx)(Jm,{icon:nr,label:`When`,value:r}),(0,X.jsx)(Jm,{icon:je,label:`Active`,value:c?`yes`:`no`,tone:c?`green`:`amber`}),l!=null&&(0,X.jsx)(Jm,{label:`Order`,value:String(l)})]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(Et,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Criteria:`}),(0,X.jsx)(`code`,{className:`font-mono text-foreground break-all`,children:a||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`always`})})]})]}),(0,X.jsx)(Km,{title:`Immediate Actions`,count:o.length,children:o.length===0?(0,X.jsx)(qm,{children:`No immediate actions.`}):(0,X.jsx)(`ul`,{className:`divide-y rounded border bg-background`,children:o.map((e,t)=>(0,X.jsx)(Wm,{action:e},t))})}),s.length>0&&(0,X.jsx)(Km,{title:`Time-Dependent Actions`,count:s.length,children:(0,X.jsx)(`ul`,{className:`space-y-2`,children:s.map((e,t)=>{let n=e.offset??0,r=e.unit??`hours`,i=e.baseField??e.baseEvent??`trigger`;return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs border-b bg-muted/20`,children:[(0,X.jsx)(An,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[n>=0?`+`:``,n,` `,r]}),(0,X.jsx)(ln,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`after`}),(0,X.jsx)(`code`,{className:`font-mono`,children:i})]}),Array.isArray(e.actions)&&e.actions.length>0?(0,X.jsx)(`ul`,{className:`divide-y`,children:e.actions.map((e,t)=>(0,X.jsx)(Wm,{action:e},t))}):(0,X.jsx)(qm,{children:`No actions scheduled at this offset.`})]},t)})})})]})})})}function Wm({action:e}){let t=zm(e.type),n=Bm(e);return(0,X.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2 text-xs`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:Gm(e.type)}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.type})]}),n&&(0,X.jsx)(`div`,{className:`text-muted-foreground font-mono break-all`,children:n})]})]})}function Gm(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Km({title:e,count:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function qm({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-2 py-1.5`,children:e})}function Jm({icon:e,label:t,value:n,tone:r=`gray`,mono:i=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,X.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`} ${i?`font-mono`:``}`,children:n})]})}function Ym({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,X.jsx)(Q,{hint:`agent`,children:(0,X.jsx)(fm,{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,X.jsx)(Q,{hint:`agent`,toolbar:v&&(0,X.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,X.jsx)(sn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,X.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,X.jsx)(St,{className:`h-5 w-5 text-muted-foreground`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(rh,{icon:c?pn:Ye,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,X.jsx)(rh,{icon:_i,label:l}),u.provider&&(0,X.jsx)(rh,{icon:Wt,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,X.jsx)(rh,{icon:yt,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,X.jsx)(rh,{label:`max ${u.maxTokens}t`})]})]})]}),(0,X.jsx)(Zm,{title:`Instructions`,icon:Ci,children:s?(0,X.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,X.jsx)(Qm,{children:`No system prompt set yet.`})}),(0,X.jsx)(Zm,{title:`Capabilities`,icon:Bi,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)($m,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),mono:!0}),(0,X.jsx)($m,{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})),mono:!0})]})}),p&&Object.keys(p).length>0&&(0,X.jsx)(Zm,{title:`Knowledge (RAG)`,icon:Dn,children:(0,X.jsx)(Xm,{knowledge:p})})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,X.jsx)(eh,{icon:Fr,title:`Planning`,children:(0,X.jsx)(th,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,X.jsx)(eh,{icon:Tn,title:`Memory`,children:(0,X.jsx)(th,{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,X.jsx)(eh,{icon:Jr,title:`Guardrails`,children:(0,X.jsx)(th,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,X.jsx)(eh,{icon:_i,title:`Permissions`,children:(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,X.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function Xm({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,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,X.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,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(Dn,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Zm({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Qm({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function $m({label:e,emptyHint:t,items:n,mono:r=!1}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] ${r?`font-mono`:``}`,children:[e.label,e.hint&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.hint})]},e.key))})]})}function eh({icon:e,title:t,children:n}){return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,X.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function th({data:e,keys:t}){let n=t.map(t=>[t,nh(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,X.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function nh(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function rh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function ih(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function ah(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${ah(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function oh(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 sh({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=ih(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=Y.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=oh(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=oh(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,X.jsx)(Q,{hint:`tool`,children:(0,X.jsx)(fm,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,X.jsx)(Q,{hint:`tool`,toolbar:r&&(0,X.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,X.jsx)(sn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Bi,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,X.jsx)(dh,{icon:Oe,label:o}),s&&(0,X.jsx)(dh,{icon:Dn,label:s,mono:!0}),(0,X.jsx)(dh,{icon:je,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,X.jsx)(dh,{icon:jr,label:`Requires confirmation`,tone:`amber`}),u&&(0,X.jsx)(dh,{label:`built-in`})]})]})]}),a&&(0,X.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,X.jsx)(lh,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,X.jsx)(uh,{children:`This tool takes no input parameters.`}):(0,X.jsx)(ch,{props:p,required:m})}),Object.keys(p).length>0&&(0,X.jsx)(lh,{title:`Example LLM Call`,icon:qi,children:(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
18
- "tool": "${r}",
19
- "arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
20
- `)}
21
- }`})}),ih(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,X.jsx)(lh,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Ar,children:(0,X.jsx)(ch,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function ch({props:e,required:t}){return(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:Object.keys(e).map(n=>{let r=e[n],i=t.has(n);return(0,X.jsxs)(`tr`,{className:`align-top`,children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,X.jsx)(ri,{className:`h-3 w-3 text-emerald-600`}):(0,X.jsx)(Rn,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:ah(r)}),(0,X.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,X.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,X.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function lh({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function uh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function dh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var fh=[{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 ph(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 mh({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=Y.useMemo(()=>Object.keys(o).sort(),[o]),f=Y.useMemo(()=>ph(o),[o]),p=Y.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,X.jsx)(Q,{hint:`permission`,children:(0,X.jsx)(fm,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,X.jsx)(Q,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,X.jsx)(Je,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,X.jsx)(ui,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(vh,{icon:dr,label:`${d.length} objects`}),(0,X.jsx)(vh,{icon:Oe,label:`${c.length} system perms`}),(0,X.jsx)(vh,{icon:pn,label:`${Object.keys(l).length} tabs`}),(0,X.jsx)(vh,{icon:_i,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,X.jsxs)(_h,{title:`Object Permissions`,count:d.length,children:[(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),fh.map(e=>(0,X.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),fh.map(e=>(0,X.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,X.jsx)(hh,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,X.jsx)(gh,{})]}),p.size>0&&(0,X.jsx)(_h,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,X.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,X.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,X.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,X.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,X.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,X.jsx)(_h,{title:`System Permissions`,count:c.length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,X.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,X.jsx)(_h,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),(0,X.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,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,X.jsx)(jr,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,X.jsxs)(`li`,{className:`text-amber-900`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function hh({granted:e,danger:t}){return e?(0,X.jsx)(ri,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,X.jsx)(ei,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function gh(){return(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(ri,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(ri,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(ei,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,X.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 _h({title:e,count:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function vh({icon:e,label:t}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{children:t})]})}function yh(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 bh(e){switch(e){case`url`:return fi;case`modal`:return Si;case`flow`:return Qt;case`api`:return Se;case`form`:return W;default:return Yr}}function xh(e){switch(e){case`primary`:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function Sh(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 Ch({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=yh(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=yh(n.confirmText),g=yh(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=bh(o),w=l===`action:icon`;return!r&&!i?(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(fm,{children:`Set name and label to see the action preview.`})}):(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,X.jsx)(wh,{label:i,icon:a,variant:c,iconOnly:w,disabled:!!S&&typeof S==`boolean`})}),(0,X.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(jh,{icon:C,label:`type: ${o}`}),b&&(0,X.jsx)(jh,{icon:li,label:`object: ${b}`,mono:!0}),c&&(0,X.jsx)(jh,{label:`variant: ${c}`}),l&&(0,X.jsx)(jh,{icon:vn,label:l}),d&&(0,X.jsx)(jh,{icon:Wr,label:d,mono:!0}),f&&(0,X.jsx)(jh,{icon:tr,label:`bulk`,tone:`green`}),p&&(0,X.jsx)(jh,{icon:Oi,label:`refresh after`}),m===!1&&(0,X.jsx)(jh,{icon:St,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,X.jsx)(jh,{icon:Wt,label:`AI: exposed`})]}),u.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,X.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,X.jsx)(kh,{label:`Visible when`,value:x,icon:pn}),S!=null&&typeof S!=`boolean`&&(0,X.jsx)(kh,{label:`Disabled when`,value:S,icon:_i})]}),(0,X.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,X.jsx)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,X.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:Sh(o,s,!!y?.source)}),h&&(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,X.jsx)(jr,{className:`h-3 w-3 mt-0.5`}),(0,X.jsxs)(`span`,{children:[`First asks: `,(0,X.jsx)(`em`,{children:h})]})]}),g&&(0,X.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,X.jsx)(`em`,{children:g})]})]}),_.length>0&&(0,X.jsx)(Ah,{title:`Input Dialog`,count:_.length,children:(0,X.jsx)(Eh,{title:i,params:_,variant:c})}),v&&(0,X.jsx)(Ah,{title:`Result Dialog`,icon:pn,children:(0,X.jsx)(Oh,{dialog:v})}),y?.source&&(0,X.jsx)(Ah,{title:`Script Body (${y.language??`expression`})`,icon:Yr,children:(0,X.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 wh({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,X.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 ${xh(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,X.jsx)(Th,{name:t}),!r&&(0,X.jsx)(`span`,{children:e})]})}function Th({name:e}){return(0,X.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 Eh({title:e,params:t,variant:n}){return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,X.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[yh(e.label)||n,e.required&&(0,X.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,X.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),Dh(e),e.helpText&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${xh(n||`primary`)}`,children:`OK`})]})]})}function Dh(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,X.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,X.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,X.jsx)(`option`,{value:e.value,children:yh(e.label)},t))]}):e.type===`boolean`?(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,X.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,X.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,X.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 Oh({dialog:e}){let t=yh(e.title)||`Result`,n=yh(e.description),r=yh(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,X.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,X.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,X.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:yh(t.label)||t.path}),(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,X.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,X.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,X.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 kh({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,X.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function Ah({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function jh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Mh(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Nh({draft:e}){let t=e,n=String(t.object??``),r=!!t.active,i=t.lockRecord!==!1,a=t.approvalStatusField||void 0,o=Mh(t.entryCriteria),s=Array.isArray(t.steps)?t.steps:[],c=t.escalation,l={onSubmit:Array.isArray(t.onSubmit)?t.onSubmit:[],onFinalApprove:Array.isArray(t.onFinalApprove)?t.onFinalApprove:[],onFinalReject:Array.isArray(t.onFinalReject)?t.onFinalReject:[],onRecall:Array.isArray(t.onRecall)?t.onRecall:[]};return s.length===0&&!n?(0,X.jsx)(Q,{hint:`approval`,children:(0,X.jsx)(fm,{children:`Set the target object and at least one step to see the approval chain.`})}):(0,X.jsx)(Q,{hint:`approval · ${s.length} step${s.length===1?``:`s`}`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsx)(Lh,{icon:je,label:r?`Active`:`Inactive`,tone:r?`green`:`gray`}),(0,X.jsx)(Lh,{icon:Tr,label:`object: ${n||`—`}`,mono:!0}),(0,X.jsx)(Lh,{icon:_i,label:i?`lock during approval`:`unlocked`,tone:i?`amber`:`gray`}),a&&(0,X.jsx)(Lh,{label:`status field: ${a}`,mono:!0})]}),o&&(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(Et,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Entry:`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:o})]})]}),c?.enabled&&(0,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-900`,children:[(0,X.jsx)(An,{className:`h-3.5 w-3.5`}),` SLA escalation enabled`]}),(0,X.jsxs)(`div`,{className:`mt-1 text-amber-900`,children:[`After `,(0,X.jsxs)(`code`,{className:`font-mono`,children:[c.timeoutHours,`h`]}),` on a pending step →`,` `,(0,X.jsx)(`span`,{className:`font-medium`,children:c.action??`notify`}),c.escalateTo&&(0,X.jsxs)(X.Fragment,{children:[` → `,(0,X.jsx)(`code`,{className:`font-mono`,children:c.escalateTo})]}),c.notifySubmitter&&(0,X.jsx)(`span`,{className:`ml-1 opacity-80`,children:`(notify submitter)`})]})]}),s.length===0?(0,X.jsx)(fm,{children:`No steps defined yet.`}):(0,X.jsx)(`ol`,{className:`space-y-2`,children:s.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[(0,X.jsx)(Ph,{step:e,index:t}),t<s.length-1&&(0,X.jsx)(`li`,{className:`flex justify-center`,"aria-hidden":!0,children:(0,X.jsx)(ft,{className:`h-3.5 w-3.5 text-muted-foreground`})})]},e.name||t))}),(0,X.jsxs)(`div`,{className:`rounded border bg-muted/20 p-2.5 text-xs`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground uppercase tracking-wider text-[10px] mb-1`,children:`Global Hooks`}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[(0,X.jsx)(Ih,{icon:nr,label:`onSubmit`,actions:l.onSubmit}),(0,X.jsx)(Ih,{icon:ri,label:`onFinalApprove`,actions:l.onFinalApprove,tone:`green`}),(0,X.jsx)(Ih,{icon:hi,label:`onFinalReject`,actions:l.onFinalReject,tone:`red`}),(0,X.jsx)(Ih,{icon:Ir,label:`onRecall`,actions:l.onRecall})]})]})]})})})}function Ph({step:e,index:t}){let n=e.approvers??[],r=Mh(e.entryCriteria);return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-mono`,children:t+1}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.label||e.name||`Step ${t+1}`}),e.name&&(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name}),e.behavior&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.behavior===`unanimous`?`all must approve`:`first response wins`})]}),e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.description}),r&&(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,X.jsx)(Et,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`When:`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:r})]}),(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-xs`,children:[(0,X.jsx)(an,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Approvers:`}),n.length===0?(0,X.jsx)(`span`,{className:`text-amber-700`,children:`none`}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px]`,children:[(0,X.jsx)(Pe,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.value||`?`}),e.type&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type})]},t))})]})]})]}),((e.onApprove?.length??0)>0||(e.onReject?.length??0)>0||e.rejectionBehavior)&&(0,X.jsxs)(`div`,{className:`border-t bg-muted/20 px-3 py-1.5 text-[11px] space-y-0.5`,children:[e.onApprove&&e.onApprove.length>0&&(0,X.jsx)(Fh,{icon:ri,tone:`green`,label:`on approve`,actions:e.onApprove}),e.onReject&&e.onReject.length>0&&(0,X.jsx)(Fh,{icon:hi,tone:`red`,label:`on reject`,actions:e.onReject}),e.rejectionBehavior&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[e.rejectionBehavior===`back_to_previous`?(0,X.jsx)(vr,{className:`h-3 w-3`}):(0,X.jsx)(Sr,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[`Rejection: `,(0,X.jsx)(`code`,{className:`font-mono text-foreground`,children:e.rejectionBehavior})]})]})]})]})}function Fh({icon:e,tone:t,label:n,actions:r}){return(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(e,{className:`h-3 w-3 mt-0.5 ${t===`green`?`text-emerald-700`:`text-red-700`}`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[n,`:`]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted/40 px-1.5 py-0.5 font-mono text-[10px]`,children:[e.type??`action`,e.name&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`· `,e.name]})]},t))})]})}function Ih({icon:e,label:t,actions:n,tone:r=`gray`}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${r===`green`?`text-emerald-700`:r===`red`?`text-red-700`:`text-muted-foreground`}`,children:[(0,X.jsx)(e,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`font-mono`,children:t}),(0,X.jsx)(`span`,{className:`rounded bg-muted px-1 text-[10px]`,children:n.length})]})}function Lh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Rh={"@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 zh(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 Bh(e){let t=(Rh[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=zh(n,0,59),c=zh(r,0,23),l=zh(i,1,31),u=zh(a,1,12),d=zh(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function Vh(e,t,n){let r=Bh(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 Hh(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 Uh(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function Wh(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Gh({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.cron??n.schedule,s=n.every??n.interval,c=n.at??n.runAt,l=n.timezone??n.tz,u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.maxRetries??n.retries,p=n.timeoutMs??n.timeout,m=n.concurrency,h=s?Hh(s):null,{nextFires:g,deltas:_}=Y.useMemo(()=>{let e=new Date,t=[];if(o)t=Vh(o,e,5);else if(h)t=Uh(h,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Kh(t.getTime()-e.getTime()))}},[o,h,c]),v=o&&g.length===0||s&&!h;return!r&&!o&&!s&&!c&&!u?(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(fm,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(An,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Yh,{icon:je,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,X.jsx)(Yh,{icon:ut,label:l,mono:!0}),f!=null&&(0,X.jsx)(Yh,{icon:vr,label:`retries: ${f}`}),p!=null&&(0,X.jsx)(Yh,{icon:Ue,label:`timeout: ${p}ms`}),m!=null&&(0,X.jsx)(Yh,{label:`concurrency: ${m}`})]})]})]})}),(0,X.jsx)(Jh,{title:`Schedule`,icon:rn,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,X.jsx)(qh,{label:`Cron`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,X.jsxs)(qh,{label:`Every`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:s}),!h&&(0,X.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,X.jsx)(qh,{label:`At`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||h||c)&&(0,X.jsx)(Jh,{title:`Next ${Math.max(g.length,1)} run${g.length===1?``:`s`}`,icon:di,children:g.length===0?(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:v?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:g.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,X.jsx)(di,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:Wh(e)}),(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,_[t]]})]},t))})}),(0,X.jsx)(Jh,{title:`Handler`,icon:Yr,children:u?(0,X.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,X.jsx)(nr,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Kh(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 qh({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:`break-all`,children:t})]})}function Jh({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Yh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Xh=[{key:`objects`,label:`Objects`,icon:Vn,flat:!1},{key:`apps`,label:`Apps`,icon:lt,flat:!1},{key:`messages`,label:`Messages`,icon:On,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Tr,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Wn,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:er,flat:!1},{key:`settings`,label:`Settings`,icon:pi,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:mt,flat:!1}];function Zh({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=Xh.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/Xh.length*100);return c===0?(0,X.jsx)(Q,{hint:`translation · ${r}`,children:(0,X.jsx)(fm,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,X.jsx)(Q,{hint:`translation · ${r} · ${c} keys`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(ni,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.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,X.jsx)(ut,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,X.jsx)(yt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,X.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,Xh.length,` (`,u,`%)`]}),(0,X.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,X.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,X.jsx)(Qh,{cat:e},e.key))})]})})})}function Qh({cat:e}){let t=e.icon;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,X.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,X.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,X.jsx)(`span`,{className:`truncate text-foreground/80`,children:$h(n,e.flat)})]},t)),e.count>e.sample.length&&(0,X.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function $h(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function eg({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,X.jsx)(Q,{hint:`role`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(an,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,X.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Xt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,X.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,X.jsx)(Sn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.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,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.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,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,X.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(ui,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,X.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,X.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,X.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,X.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,X.jsx)(Q,{hint:`role`,children:(0,X.jsx)(fm,{children:`Give the role a name to see the preview.`})})}function tg({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,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Wt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(rg,{icon:je,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,X.jsx)(rg,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,X.jsx)(rg,{icon:ui,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,X.jsx)(ng,{title:`Instructions`,icon:zt,children:o?(0,X.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,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,X.jsxs)(ng,{title:`Tools (${s.length})`,icon:Bi,children:[s.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,X.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,X.jsx)(Yi,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,X.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,X.jsx)(ng,{title:`Trigger Phrases (${c.length})`,icon:oi,children:(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,X.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,X.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,X.jsx)(ng,{title:`Trigger Conditions (${l.length})`,icon:Et,children:(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,X.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,X.jsx)(ng,{title:`Required Permissions`,icon:ui,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,X.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,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(fm,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function ng({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function rg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var ig=/pass|secret|key|token|credential|auth/i;function ag(e){return ig.test(e)}function og(e){return e==null||e===``?`∅`:`••••••`}function sg(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 cg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=Object.entries(l);return!r&&g.length===0?(0,X.jsx)(Q,{hint:`datasource`,children:(0,X.jsx)(fm,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,X.jsx)(Q,{hint:`datasource · ${o}`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Dn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,X.jsx)(Ie,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,X.jsx)(dg,{icon:je,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,X.jsx)(dg,{icon:Je,label:`default`,tone:`amber`}),m.length>0&&(0,X.jsx)(dg,{icon:Ht,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),(0,X.jsx)(ug,{title:`Connection`,icon:_i,children:g.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:g.map(([e,t])=>{let n=ag(e);return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:og(t)}),(0,X.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`})]}):sg(t)})]},e)})})})})}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(lg,{title:`Pool`,icon:Tn,value:u}),(0,X.jsx)(lg,{title:`SSL`,icon:ui,value:typeof d==`boolean`?{enabled:d}:d}),(0,X.jsx)(lg,{title:`Retry Policy`,icon:vr,value:f}),(0,X.jsx)(lg,{title:`Health Check`,icon:Tn,value:p})]}),h.length>0&&(0,X.jsx)(ug,{title:`Capabilities`,icon:ui,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,X.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 lg({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,X.jsx)(`dd`,{className:`font-mono truncate`,children:ag(e)?og(t):sg(t)})]},e))}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function ug({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function dg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function fg(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function pg(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50`,text:`text-red-700`,icon:mn};case`warning`:return{ring:`border-amber-200 bg-amber-50`,text:`text-amber-800`,icon:jr};default:return{ring:`border-blue-200 bg-blue-50`,text:`text-blue-800`,icon:Di}}}function mg({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=pg(l);return r?(0,X.jsx)(Q,{hint:`validation · ${o}`,children:(0,X.jsx)(pm,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Tr,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(vg,{icon:je,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,X.jsx)(vg,{label:`object: ${s}`,mono:!0}),f!=null&&(0,X.jsx)(vg,{label:`priority ${f}`}),d.length>0&&(0,X.jsx)(vg,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,X.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,X.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,X.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,X.jsx)(hg,{type:o,d:n}),p.length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,X.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,X.jsx)(Q,{hint:`validation`,children:(0,X.jsx)(fm,{children:`Give the validation a name to see the preview.`})})}function hg({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,X.jsx)(_g,{title:`Condition`,icon:Yr,children:(0,X.jsx)(gg,{value:fg(t.condition)??fg(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=fg(t.scope)??fg(t.where);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_g,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Be,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,X.jsx)(`span`,{className:`text-xs text-amber-700`,children:`no fields set`}):e.map(e=>(0,X.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,X.jsx)(_g,{title:`Scope`,icon:vi,children:(0,X.jsx)(gg,{value:n})})]})}case`state_machine`:{let e=Array.isArray(t.transitions)?t.transitions:[],n=t.field;return(0,X.jsx)(_g,{title:`Transitions${n?` on ${n}`:``}`,icon:Qt,children:e.length===0?(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No transitions declared.`}):(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:Array.isArray(e.from)?e.from.join(` | `):e.from??`*`}),(0,X.jsx)(ln,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono text-emerald-700`,children:e.to??`?`})]},t))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,X.jsx)(_g,{title:`Format`,icon:Ln,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,X.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,X.jsx)(`span`,{className:`text-amber-700`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=fg(t.condition);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_g,{title:`Fields involved`,icon:vi,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,X.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,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,X.jsx)(_g,{title:`Cross-field condition`,icon:Yr,children:(0,X.jsx)(gg,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,X.jsx)(_g,{title:`Async endpoint`,icon:ut,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,X.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,X.jsx)(_g,{title:`Custom handler`,icon:Yr,children:(0,X.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,X.jsx)(`span`,{className:`text-amber-700`,children:`No handler set.`})})})}default:return(0,X.jsx)(_g,{title:`Rule`,icon:Tr,children:(0,X.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 gg({value:e}){return e?(0,X.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No expression set.`})}function _g({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function vg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function yg(){Jp(`page`,mm),Jp(`view`,vm),Jp(`dashboard`,bm),Jp(`report`,Sm),Jp(`app`,Tm),Jp(`action`,Ch),Jp(`object`,Om),Jp(`datasource`,cg),Jp(`validation`,mg),Jp(`email_template`,Mm),Jp(`translation`,Zh),Jp(`flow`,Im),Jp(`workflow`,Um),Jp(`approval`,Nh),Jp(`job`,Gh),Jp(`agent`,Ym),Jp(`tool`,sh),Jp(`skill`,tg),Jp(`permission`,mh),Jp(`profile`,mh),Jp(`role`,eg)}var bg=t({MetadataDirectoryPage:()=>qf,MetadataResourceEditPage:()=>Xp,MetadataResourceHistoryPage:()=>Qp,MetadataResourceListPage:()=>rp});sm(),dm(),yg(),Df({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:qf}),Df({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:tm}),$f({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`}]}),$f({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`}]}),$f({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:im,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`}]}),$f({type:`view`,label:`Views`,description:`Saved list / kanban / calendar / gantt configurations on top of an object.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`},{key:`label`,label:`Label`}]}),$f({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`}]}),$f({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 xg=(0,Y.lazy)(()=>m(()=>import(`./SystemHubPage-CgN-8VKO.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),Sg=(0,Y.lazy)(()=>m(()=>import(`./AppManagementPage-BKE0rv8B.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Cg=(0,Y.lazy)(()=>m(()=>import(`./ProfilePage-zYSeu2-d.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),wg=(0,Y.lazy)(()=>m(()=>import(`./ApprovalsInboxPage-D7gF2CM8.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Tg=(0,Y.lazy)(()=>m(()=>import(`./AiPendingActionsPage-DLWrcsds.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Eg=(0,Y.lazy)(()=>m(()=>import(`./AuditLogPage-Bqlhi2ko.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Dg=(0,Y.lazy)(()=>m(()=>import(`./SettingsHub-BTNCNbjZ.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Og=(0,Y.lazy)(()=>m(()=>import(`./SettingsView-BLXf7B7b.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),kg=(0,Y.lazy)(()=>m(()=>import(`./DeveloperHubPage-C3Ooh2Gg.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),Ag=(0,Y.lazy)(()=>m(()=>import(`./ApiConsolePage-BIBykAYj.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),jg=(0,Y.lazy)(()=>m(()=>import(`./FlowRunsPage-NjEPPv_e.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Mg=(0,Y.lazy)(()=>m(()=>import(`./PublicFormsPage-BrLPiHf1.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Ng(){let{objectName:e}=a(),t=u().pathname.replace(/\/objects(\/.*)?$/,``);return(0,X.jsx)(p,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function Pg(){let{metadataType:e,itemName:t}=a(),n=u().pathname.replace(/\/metadata(\/.*)?$/,``),r=`${n}/component/metadata/resource`;return(0,X.jsx)(p,{to:e?t?`${r}/${t}?type=${e}`:`${r}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var Fg=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(g,{path:`system`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(xg,{})})}),(0,X.jsx)(g,{path:`system/apps`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Sg,{})})}),(0,X.jsx)(g,{path:`system/profile`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Cg,{})})}),(0,X.jsx)(g,{path:`system/approvals`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(wg,{})})}),(0,X.jsx)(g,{path:`system/ai-approvals`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Tg,{})})}),(0,X.jsx)(g,{path:`system/audit-log`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Eg,{})})}),(0,X.jsx)(g,{path:`system/settings`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Dg,{})})}),(0,X.jsx)(g,{path:`system/settings/:namespace`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Og,{})})}),(0,X.jsx)(g,{path:`developer`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(kg,{})})}),(0,X.jsx)(g,{path:`developer/api-console`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Ag,{})})}),(0,X.jsx)(g,{path:`developer/flow-runs`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(jg,{})})}),(0,X.jsx)(g,{path:`developer/public-forms`,element:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(Mg,{})})}),(0,X.jsx)(g,{path:`system/objects`,element:(0,X.jsx)(Ng,{})}),(0,X.jsx)(g,{path:`system/objects/:objectName`,element:(0,X.jsx)(Ng,{})}),(0,X.jsx)(g,{path:`system/metadata`,element:(0,X.jsx)(Pg,{})}),(0,X.jsx)(g,{path:`system/metadata/:metadataType`,element:(0,X.jsx)(Pg,{})}),(0,X.jsx)(g,{path:`system/metadata/:metadataType/:itemName`,element:(0,X.jsx)(Pg,{})})]});function Ig(){let e=(0,Y.useMemo)(()=>gr({baseUrl:``}),[``]);return(0,X.jsx)(E,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,X.jsx)(ac,{}),children:(0,X.jsx)(xr,{adapter:e,children:(0,X.jsx)(id,{extraRoutes:Fg,extraRoutesNoApp:Fg})})})}var Lg=`/_account`;function Rg(){return typeof window>`u`?`/`:window.location.pathname+window.location.search}function zg(e){let t=e??Rg(),n=`${Lg}/login?redirect=${encodeURIComponent(t)}`;window.location.assign(n)}function Bg(e){let t=e??Rg(),n=`${Lg}/register?redirect=${encodeURIComponent(t)}`;window.location.assign(n)}function Vg(){window.location.assign(`${Lg}/forgot-password`)}function Hg({redirect:e}={}){return(0,Y.useEffect)(()=>{zg(e)},[e]),(0,X.jsx)(`div`,{className:`flex min-h-screen w-full items-center justify-center bg-background`,children:(0,X.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-primary`})})}var Ug=[`cloud_control`];function Wg(){let{apps:e,loading:t}=F();if(t)return(0,X.jsx)(Io,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Ug)if(n.has(e))return(0,X.jsx)(p,{to:`/apps/${e}`,replace:!0});return(0,X.jsx)(p,{to:`/home`,replace:!0})}var Gg=`/api/v1`;function Kg(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function qg(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 Jg(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Kg(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:qg(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Yg(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 Xg(e,t){return fetch(`${Gg}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function Zg(e){let t=await Xg(`/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 Qg(e){let t=await Xg(`/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 Xg(`/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 $g(e,t){let n=await Xg(`/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 e_(e,t){let n=await Xg(`/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 t_=`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 n_({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:t_},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,X.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,X.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,X.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,X.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,X.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,X.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,X.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,X.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,X.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,X.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,X.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,X.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,X.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,X.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,X.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function r_({mode:e}){let t=a(),[n]=o(),r=(e===`public`?t.slug:t.name)??``,[i,s]=(0,Y.useState)(!0),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)({}),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let t=!1;return s(!0),l(null),(e===`public`?Zg(r):Qg(r)).then(e=>{t||(d(e),p(Yg(Jg(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||l(e?.message??String(e))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,Y.useMemo)(()=>u?Jg(u.form,u.objectSchema):[],[u]),y=u?.form?.submitBehavior??{kind:`thank-you`};return i?(0,X.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):c&&!u?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,X.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:c})}):u?g&&y.kind===`thank-you`?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,X.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,X.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,X.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,X.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,X.jsxs)(`header`,{className:`mb-6`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:u.label}),u.form?.label&&u.form.label!==u.label&&(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:u.form.label})]}),(0,X.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),u){h(!0),l(null);try{switch(e===`public`?await $g(r,f):await e_(u.object,f),J.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:p(Yg(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);l(t),J.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,X.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,X.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,X.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,X.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,X.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,X.jsx)(n_,{field:e,value:f[e.name],onChange:t=>p(n=>({...n,[e.name]:t}))}),e.helpText&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),c&&(0,X.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:c}),(0,X.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,X.jsx)(`button`,{type:`submit`,disabled:m,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:m?`Submitting…`:`Submit`})})]})]}):null}function i_({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,Y.useRef)(null);return(0,Y.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}var a_=e(c(),1);function o_({message:e}){return typeof document>`u`?null:(0,a_.createPortal)((0,X.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`fixed inset-0 z-[9999] flex items-center justify-center`,style:{background:`rgba(255,255,255,0.85)`,backdropFilter:`blur(4px)`},children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,style:{color:`#525252`,fontSize:14},children:[(0,X.jsx)(`div`,{style:{width:32,height:32,border:`2px solid #d4d4d4`,borderTopColor:`transparent`,borderRadius:`50%`,animation:`so-spin 0.8s linear infinite`}}),(0,X.jsx)(`span`,{children:e}),(0,X.jsx)(`style`,{children:`@keyframes so-spin { to { transform: rotate(360deg); } }`})]})}),document.body)}function s_(){let{user:e,isAuthenticated:t}=C(),n=(0,Y.useRef)(!1),[r,i]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(t||e){n.current=!0;return}if(n.current&&!r){i(!0);let e=window.setTimeout(()=>i(!1),8e3);return()=>window.clearTimeout(e)}},[t,e,r]),r?(0,X.jsx)(o_,{message:`Signing you out…`}):null}function c_(){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 l_(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(`
22
-
23
- `):``}function u_(){let{token:e}=a(),t=`${(0,Y.useMemo)(()=>c_(),[])}/api/v1`,[n,r]=(0,Y.useState)(null),[i,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!0),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(null),h=(0,Y.useCallback)(async n=>{if(e){c(!0),o(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let a=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(a.status===401){u(!0),o(n?`Wrong password.`:null),c(!1);return}if(a.status===404){o(`This link is invalid or no longer available.`),c(!1);return}if(a.status===410){o(`This link has expired or was revoked.`),c(!1);return}if(!a.ok){o((await a.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${a.status}).`),c(!1);return}let s=await a.json();r(`data`in s?s.data:{record:s.record,link:s.link,redactedFields:s.redactFields}),u(!1)}catch(e){o(e?.message??`Failed to load shared content.`)}finally{c(!1)}}},[t,e]);if((0,Y.useEffect)(()=>{h()},[h]),(0,Y.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]),s)return(0,X.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,X.jsx)(qr,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,X.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,X.jsx)(fi,{className:`h-8 w-8 text-muted-foreground`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,X.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,X.jsx)(Er,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,X.jsx)(sr,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,X.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,X.jsx)(q,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,X.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,X.jsx)(jr,{className:`h-8 w-8 text-amber-500`}),(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,X.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,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,X.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,X.jsx)(st,{className:`h-5 w-5 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,X.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,X.jsx)(K,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,X.jsx)(qr,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,X.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,X.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=l_(e);if(!t)return null;let n=e.role===`user`;return(0,X.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,X.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,X.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,X.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,X.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,X.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,X.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,X.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,X.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}var d_=`/api/v1/auth`;function f_(){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 p_=f_();function m_({children:e,requireOrganization:t=!0}){return(0,X.jsx)(D,{fallback:(0,X.jsx)(Hg,{}),loadingFallback:(0,X.jsx)(Io,{}),children:(0,X.jsx)(Ro,{children:t?(0,X.jsx)(Vo,{children:e}):e})})}function h_(){return(0,Y.useEffect)(()=>{zg(new URLSearchParams(window.location.search).get(`redirect`)??void 0)},[]),(0,X.jsx)(Io,{})}function g_(){return(0,Y.useEffect)(()=>{Bg(new URLSearchParams(window.location.search).get(`redirect`)??void 0)},[]),(0,X.jsx)(Io,{})}function __(){return(0,Y.useEffect)(()=>{Vg()},[]),(0,X.jsx)(Io,{})}function v_(){let{user:e}=C();return(0,X.jsx)(Xd,{userId:e?.id,children:(0,X.jsx)(lf,{})})}function y_(){return(0,X.jsxs)(O,{authUrl:d_,children:[(0,X.jsx)(oc,{position:`bottom-right`}),(0,X.jsx)(i_,{}),(0,X.jsx)(s_,{}),(0,X.jsx)(l,{basename:p_,children:(0,X.jsx)(Lo,{children:(0,X.jsxs)(i,{children:[(0,X.jsx)(g,{path:`/login`,element:(0,X.jsx)(h_,{})}),(0,X.jsx)(g,{path:`/register`,element:(0,X.jsx)(g_,{})}),(0,X.jsx)(g,{path:`/forgot-password`,element:(0,X.jsx)(__,{})}),(0,X.jsx)(g,{path:`/f/:slug`,element:(0,X.jsx)(r_,{mode:`public`})}),(0,X.jsx)(g,{path:`/s/:token`,element:(0,X.jsx)(u_,{})}),(0,X.jsx)(g,{path:`/forms/:name`,element:(0,X.jsx)(m_,{children:(0,X.jsx)(r_,{mode:`internal`})})}),(0,X.jsx)(g,{path:`/home`,element:(0,X.jsx)(m_,{children:(0,X.jsx)(v_,{})})}),(0,X.jsx)(g,{path:`/organizations`,element:(0,X.jsx)(m_,{requireOrganization:!1,children:(0,X.jsx)(uf,{children:(0,X.jsx)(hf,{})})})}),(0,X.jsx)(g,{path:`/system/*`,element:(0,X.jsx)(Ho,{})}),(0,X.jsx)(g,{path:`/ai`,element:(0,X.jsx)(m_,{children:(0,X.jsx)(xf,{})})}),(0,X.jsx)(g,{path:`/ai/:conversationId`,element:(0,X.jsx)(m_,{children:(0,X.jsx)(xf,{})})}),(0,X.jsx)(g,{path:`/apps/:appName/*`,element:(0,X.jsx)(m_,{children:(0,X.jsx)(Ig,{})})}),(0,X.jsx)(g,{path:`/`,element:(0,X.jsx)(Ro,{children:(0,X.jsx)(Wg,{})})}),(0,X.jsx)(g,{path:`*`,element:(0,X.jsx)(p,{to:`/`,replace:!0})})]})})})]})}async function b_(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,S(r)?y(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var x_=`auth-session-token`,S_=`auth-active-organization-id`;async function C_(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(x_)}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(x_),localStorage.removeItem(S_)}catch{}}function w_(e,t){let n=Array.isArray(e.fields)?e.fields:Object.values(e.fields||{});return{id:e.name||`obj_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,pluralLabel:e.pluralLabel||e.plural_label||void 0,description:typeof e.description==`object`?e.description.defaultValue:e.description||void 0,icon:e.icon||void 0,group:e.name?.startsWith(`sys_`)?`System Objects`:`Custom Objects`,sortOrder:t,isSystem:e.name?.startsWith(`sys_`)||!1,enabled:e.enabled!==!1,fieldCount:n.length,relationships:Array.isArray(e.relationships)?e.relationships.map(e=>({relatedObject:e.object||e.relatedObject||``,type:e.type||`one-to-many`,label:e.label||e.name||void 0,foreignKey:e.foreign_key||e.foreignKey||void 0})):void 0}}function T_(e,t){return{id:e.name||`fld_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,type:e.type||`text`,group:e.group||void 0,sortOrder:t,description:e.description||e.help||void 0,required:e.required||!1,unique:e.unique||!1,readonly:e.readonly||!1,hidden:e.hidden||!1,defaultValue:e.defaultValue||e.default_value||void 0,placeholder:e.placeholder||void 0,options:Array.isArray(e.options)?e.options.map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label||e.value,value:e.value,color:e.color}):void 0,isSystem:e.readonly===!0&&(e.name===`id`||e.name===`createdAt`||e.name===`updatedAt`),externalId:e.externalId||!1,trackHistory:e.trackHistory||e.track_history||!1,indexed:e.indexed||!1,referenceTo:e.reference_to||e.referenceTo||void 0,formula:e.formula||void 0}}function E_(e){let{objects:t}=F(),n=(0,Y.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,Y.useMemo)(()=>n?w_(n,0):null,[n]),fields:(0,Y.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(T_):[],[n]),metadataObject:n}}function D_({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(t),[u,d]=(0,Y.useState)(!1),f=(0,Y.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,Y.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,X.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,X.jsx)(`dd`,{children:o?(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,X.jsx)(Vt,{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,X.jsx)(sr,{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,X.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,X.jsx)(qr,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(qn,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(Jn,{className:`h-3.5 w-3.5`})})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,X.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,X.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,X.jsx)(W,{className:`h-3 w-3`})})]})})]})}function O_({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=E_(t),{refresh:a}=F(),o=hu(),s=(0,Y.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,X.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,X.jsx)(D_,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,X.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,X.jsx)(D_,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,X.jsx)(D_,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,X.jsx)(`div`,{className:`sm:col-span-2`,children:(0,X.jsx)(D_,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(K,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,X.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(K,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var k_=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function A_({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=E_(t),{refresh:i}=F(),a=hu(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,Y.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,Y.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,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,X.jsx)(Ni,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,X.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,X.jsx)(sr,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,X.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:k_.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,X.jsx)(sr,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,X.jsx)(sr,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,X.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,X.jsxs)(q,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,X.jsx)(qr,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,X.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,X.jsx)(K,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:k_.find(t=>t.value===e.type)?.label||e.type}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,X.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,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,X.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,X.jsx)(fi,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,X.jsxs)(q,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,X.jsx)(Ni,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function j_({schema:e}){let t=e.objectName,{fields:n}=E_(t),r=(0,Y.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,X.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,X.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,X.jsx)(K,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,X.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,X.jsx)(_r,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function M_(e){return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.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,X.jsx)(Dt,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,X.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,X.jsx)(Rr,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,X.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,X.jsx)(Pi,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function N_({schema:e}){let t=e.objectName,{object:n}=E_(t);return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,X.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,X.jsx)(gn,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,X.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function P_(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function F_(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=P_(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,Y.useState)(o?.current??e),l=(0,Y.useRef)(o?.past??[]),u=(0,Y.useRef)(o?.future??[]),[,d]=(0,Y.useState)(0),f=(0,Y.useCallback)(()=>d(e=>e+1),[]);(0,Y.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,Y.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,Y.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,Y.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,Y.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,Y.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,Y.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 I_(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),o=(0,Y.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,Y.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,Y.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,Y.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function L_(){let[e,t]=(0,Y.useState)(new Set);return{selectedIds:e,toggle:(0,Y.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,Y.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,Y.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,Y.useCallback)(()=>{t(new Set)},[]),isSelected:(0,Y.useCallback)(t=>e.has(t),[e]),count:e.size}}function R_(){let[e,t]=(0,Y.useState)(null);return{clipboard:e,copy:(0,Y.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,Y.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function z_(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,Y.useState)(i),[s,c]=(0,Y.useState)({x:0,y:0}),l=(0,Y.useRef)(!1),u=(0,Y.useRef)({x:0,y:0}),d=(0,Y.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,Y.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,Y.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,Y.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,Y.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,Y.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,Y.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 B_(...e){return $i(Qi(e))}function V_({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,X.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,X.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,X.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,X.jsx)(jr,{className:`h-5 w-5 text-destructive`})}),(0,X.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,X.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,X.jsx)(`button`,{onClick:o,className:B_(`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 H_(...e){return $i(Qi(e))}function U_({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,Y.useState)(new Set),o=(0,Y.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,X.jsxs)(`div`,{className:H_(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,X.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,X.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,X.jsx)(Rn,{className:`h-3 w-3`}):(0,X.jsx)(Ui,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,X.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,X.jsx)(W_,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,X.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function W_({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,X.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,X.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,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,X.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,X.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,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.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,X.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,X.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,X.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function G_(...e){return $i(Qi(e))}function K_({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,X.jsx)(`div`,{className:G_(`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,X.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,X.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,X.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 q_=(0,Y.createContext)(null);q_.displayName=`CollaborationContext`;function J_(){return(0,Y.useContext)(q_)}function Y_(...e){return $i(Qi(e))}function X_({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=Z_,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=F_(t),d=u.current,f=(0,Y.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=z_({initialZoom:e.zoom??1}),{zoom:m}=p,h=L_(),g=(0,Y.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,Y.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=R_(),y=I_(),b=J_(),x=(0,Y.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,Y.useState)(!0),[w,T]=(0,Y.useState)(!0),[E,D]=(0,Y.useState)(s),O=(0,Y.useRef)(null),k=(0,Y.useRef)(null),A=(0,Y.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(0,Y.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,Y.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,Y.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]),te=(0,Y.useCallback)((e,t)=>{o||!g||(f(d.map(n=>n.id===g?e===`label`?{...n,label:String(t)}:e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,props:{...n.props,[e]:t}}:n)),x({type:`update`,elementId:g,data:{[e]:t}}))},[o,g,d,f,x]),ne=(0,Y.useCallback)(()=>{let e=h.selectedIds;if(e.size===0)return;let t=d.filter(t=>e.has(t.id));v.copy(t)},[h,d,v]),N=(0,Y.useCallback)(()=>{if(o)return;let e=v.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));f([...d,...n]),h.selectMany(n.map(e=>e.id)),n.forEach(e=>{x({type:`insert`,elementId:e.id,data:{component:e}})})},[o,v,d,f,h,x]),P=(0,Y.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,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),re=(0,Y.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,Y.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`}]:[],[_]),I=(0,Y.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,Y.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(),ne();return}if(n&&e.key===`v`&&!o){e.preventDefault(),N();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,ee,i,o,u,ne,N,d]),(0,X.jsxs)(`div`,{ref:k,tabIndex:0,className:Y_(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,X.jsx)(`div`,{className:Y_(`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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,X.jsxs)(`div`,{className:`mb-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,X.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,X.jsx)(Ni,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,X.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,X.jsx)(ht,{className:Y_(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,X.jsx)(`button`,{className:Y_(`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,X.jsx)(Ir,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:Y_(`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,X.jsx)(Kn,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{className:Y_(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:h.count===0,onClick:ne,children:(0,X.jsx)(Ht,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:Y_(`p-1.5 rounded hover:bg-accent`,!v.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!v.hasContent,onClick:N,children:(0,X.jsx)(Dr,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,X.jsx)(`button`,{className:Y_(`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,X.jsx)(kt,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,X.jsx)(pn,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:Y_(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,X.jsx)(Nn,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,X.jsx)(Ge,{className:`h-3 w-3`})}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,X.jsx)(Ni,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,X.jsx)(Cn,{className:`h-3 w-3`})})]}),r&&(0,X.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,X.jsx)(Ve,{className:Y_(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,X.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,X.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,X.jsxs)(`div`,{draggable:!o,onDragStart:t=>P(t,e),className:Y_(`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,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,X.jsx)(jt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,X.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,X.jsx)(kt,{className:`h-3 w-3 text-destructive`})})]}),(0,X.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,X.jsx)(K_,{items:I,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,X.jsx)(`div`,{className:Y_(`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,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,X.jsx)(dr,{className:`h-4 w-4`}),`Component Tree`]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,X.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,X.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:Y_(`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,X.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,X.jsx)(`div`,{className:`border-t`,children:(0,X.jsx)(U_,{title:`Properties – ${_.label??_.type}`,fields:ie,onChange:te})}):_&&(0,X.jsxs)(`div`,{className:`border-t p-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,X.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,X.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,X.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,X.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,X.jsx)(V_,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var Z_=[{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 Q_(e,t={}){return F_(e,t)}function $_(...e){return $i(Qi(e))}var ev=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function tv(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 nv({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,Y.useRef)(null),l=Q_({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,Y.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=I_(),m=L_(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=R_(),_=z_({minZoom:.25,maxZoom:3,zoomStep:.1}),v=J_(),[y,b]=(0,Y.useState)(!0),[x,S]=(0,Y.useState)(!0),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(``),j=(0,Y.useRef)(null),M=(0,Y.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,Y.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]),te=(0,Y.useCallback)(async()=>{if(i||m.count===0)return;let e=Array.from(m.selectedIds);if(!await p.confirm(`Delete Entities`,`Are you sure you want to delete ${e.length} selected entity(s)? This action cannot be undone.`))return;let t=l.current,n=new Set(e);f({entities:t.entities.filter(e=>!n.has(e.id)),relationships:t.relationships.filter(e=>!n.has(e.sourceEntity)&&!n.has(e.targetEntity))}),m.clearSelection()},[i,m,p,l,f]),ne=(0,Y.useCallback)(()=>{if(i)return;let e=l.current;f({entities:tv(e.entities),relationships:e.relationships})},[i,l,f]),N=(0,Y.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),P=(0,Y.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,Y.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,Y.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),ie=(0,Y.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]),I=(0,Y.useCallback)(()=>{w(null)},[]),ae=(0,Y.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),oe=(0,Y.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,Y.useCallback)(()=>{O(null)},[]),ce=(0,Y.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,Y.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,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),de=(0,Y.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]),L=h?u.find(e=>e.id===h):null,fe=L?[{name:`name`,label:`Name`,type:`text`,value:L.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:L.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:L.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:L.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:L.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:L.position.y,group:`Position`}]:[],pe=(0,Y.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,Y.useEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{let t=e.target.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;n&&e.key===`z`?(e.preventDefault(),l.undo()):n&&(e.key===`y`||e.shiftKey&&e.key===`Z`)?(e.preventDefault(),l.redo()):n&&e.key===`c`?(e.preventDefault(),N()):n&&e.key===`v`?(e.preventDefault(),P()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),te()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,N,P,te,m]);let me=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,X.jsxs)(`div`,{ref:c,tabIndex:0,className:$_(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,X.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,X.jsx)(Dn,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,X.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,X.jsx)(Ir,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(Kn,{className:`h-3.5 w-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,X.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(Ai,{className:`h-3.5 w-3.5`})}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,X.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(zn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,X.jsx)(vr,{className:`h-3 w-3`})})]}),!i&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,X.jsx)(`button`,{onClick:N,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(Ht,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{onClick:P,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,X.jsx)(Dr,{className:`h-3.5 w-3.5`})})]}),!i&&(0,X.jsxs)(`button`,{onClick:ne,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,X.jsx)(Mr,{className:`h-3 w-3`}),` Auto Layout`]}),(0,X.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,X.jsx)(an,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(Ni,{className:`h-3 w-3`}),` Add Entity`]}),(0,X.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,X.jsx)(fi,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,X.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,X.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,X.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,X.jsxs)(`g`,{children:[(0,X.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,X.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,X.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,X.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>le(t,e.id),className:$_(`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,X.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,X.jsx)(Dn,{className:`h-3.5 w-3.5`}),D===e.id?(0,X.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:oe,onKeyDown:e=>{e.key===`Enter`&&oe(),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,X.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),ae(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,X.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,X.jsx)(kt,{className:`h-3 w-3 text-destructive`})})]}),(0,X.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,X.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:ie,onKeyDown:e=>{e.key===`Enter`&&ie(),e.key===`Escape`&&I()},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,X.jsxs)(`span`,{className:$_(`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,X.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,X.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,X.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:ev.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,X.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,X.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,X.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,X.jsx)(Ni,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,X.jsx)(K_,{items:me,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,X.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,X.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,X.jsx)(Ui,{className:`h-3 w-3`}):(0,X.jsx)(Rn,{className:`h-3 w-3`}),`Properties`]}),y&&(0,X.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,X.jsx)(U_,{title:L?L.label:`Properties`,fields:fe,onChange:pe})})]}),(0,X.jsx)(`div`,{className:`border-t`,children:(0,X.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,X.jsx)(Ui,{className:`h-3 w-3`}):(0,X.jsx)(Rn,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,X.jsx)(V_,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function rv(...e){return $i(Qi(e))}var iv=120,av=50;function ov(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 sv({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=F_({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,Y.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=I_(),g=L_(),_=R_(),v=z_({initialZoom:1}),y=J_(),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(null),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!0),[A,j]=(0,Y.useState)(null),[M,ee]=(0,Y.useState)({x:0,y:0}),te=(0,Y.useRef)(null),ne=(0,Y.useRef)(c),N=(0,Y.useRef)(l);ne.current=c,N.current=l,(0,Y.useEffect)(()=>{ne.current?.(f),N.current?.(p)},[d.current]);let P=(0,Y.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,Y.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,Y.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,Y.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,_]),I=(0,Y.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]),ae=(0,Y.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),oe=(0,Y.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,Y.useCallback)(()=>{s||f.length===0||m(ov(f,p),p)},[f,p,s,m]),ce=(0,Y.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,Y.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,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),de=(0,Y.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),L=(0,Y.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]),fe=(0,Y.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),pe=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`}},me=(0,Y.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:iv,height:av,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,Y.useEffect)(()=>{let e=te.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(),I();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,I,F,re]);let R=(0,Y.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,X.jsxs)(`div`,{ref:te,tabIndex:0,className:rv(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,X.jsx)(V_,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,X.jsx)(Or,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,X.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,X.jsx)(`div`,{className:`flex-1`}),!s&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.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,X.jsx)(Ir,{className:`h-3 w-3`})}),(0,X.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,X.jsx)(Kn,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.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,X.jsx)(Ht,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:I,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,X.jsx)(Dr,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsxs)(`button`,{onClick:ae,className:rv(`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,X.jsx)(Zr,{className:`h-3 w-3`}),` Connect`]}),(0,X.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,X.jsx)(bt,{className:`h-3 w-3`}),` Layout`]}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.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,X.jsx)(zn,{className:`h-3 w-3`})}),(0,X.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,X.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,X.jsx)(Ai,{className:`h-3 w-3`})}),(0,X.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,X.jsx)(vr,{className:`h-3 w-3`})}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.jsxs)(`button`,{onClick:()=>P(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,X.jsx)(Le,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,X.jsx)(li,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,X.jsx)(ot,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,X.jsxs)(`button`,{onClick:()=>P(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,X.jsx)(li,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,X.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,X.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,X.jsx)(Ve,{className:`h-3 w-3`}):(0,X.jsx)(Lt,{className:`h-3 w-3`})})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,X.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,X.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:R,onDrop:le,onDragOver:ue,children:[(0,X.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,X.jsx)(`defs`,{children:(0,X.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,X.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+iv/2;let r=t.position.y+av/2;n.position.x+iv/2;let i=n.position.y+av/2,a=t.position.x+iv,o=r,s=n.position.x,c=i;return(0,X.jsxs)(`g`,{children:[(0,X.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,X.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,X.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,X.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=>{oe(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,X.jsx)(`div`,{className:rv(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,pe(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,X.jsx)(`span`,{className:rv(`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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:av/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),oe(e.id)}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:av/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?oe(e.id):(C(!0),T(e.id))}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:iv/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),oe(e.id)}}),(0,X.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:iv/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),oe(e.id)}})]}),!s&&t&&!S&&(0,X.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,X.jsx)(kt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,X.jsx)(K_,{items:me,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,X.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,X.jsx)(U_,{title:de?`Properties: ${de.label}`:`Properties`,fields:L,onChange:fe})})]})]})}function cv(...e){return $i(Qi(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`},lv={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}},uv=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function dv({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=F_(a.length>0?a:uv),f=d.current,p=(0,Y.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=L_(),h=(0,Y.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=R_(),_=I_(),v=J_(),y=(0,Y.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,Y.useState)(!0),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=lv[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,Y.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,Y.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,Y.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,Y.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,Y.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,Y.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]),te=(0,Y.useCallback)(()=>{if(c)return;let e=g.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`elem-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}})),r=f.findIndex(e=>e.type===`detail`),i=r>=0?r:0;p(f.map((e,t)=>t===i?{...e,elements:[...e.elements,...n]}:e)),m.selectMany(n.map(e=>e.id)),n.forEach(e=>{y({type:`insert`,elementId:e.id,data:{element:e}})})},[c,g,f,p,m,y]),ne=(0,Y.useCallback)((e,t,n)=>{c||(S.current={id:t.id,sectionIndex:n,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[c]),N=(0,Y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),P=(0,Y.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,Y.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,Y.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(),te();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,te,f]),(0,X.jsxs)(`div`,{ref:C,tabIndex:0,className:cv(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,X.jsxs)(`div`,{role:`toolbar`,"aria-label":$.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,X.jsx)(mt,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,X.jsx)(`button`,{className:cv(`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,X.jsx)(Ir,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:cv(`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,X.jsx)(Kn,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{className:cv(`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,X.jsx)(Ht,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{className:cv(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:te,children:(0,X.jsx)(Dr,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,X.jsx)(`button`,{className:cv(`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,X.jsx)(kt,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),$.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,X.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,X.jsx)(Ve,{className:cv(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,X.jsx)(`div`,{role:`region`,"aria-label":$.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,X.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:N,onDrop:e=>P(e,t),children:[(0,X.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,X.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,X.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:$.addText,"aria-label":$.addText,children:(0,X.jsx)(Te,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,X.jsx)(Ni,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,X.jsx)(Ri,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:$.addChart,"aria-label":$.addChart,children:(0,X.jsx)(Pi,{className:`h-3 w-3`})}),(0,X.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:$.addTable,"aria-label":$.addTable,children:(0,X.jsx)(Ze,{className:`h-3 w-3`})})]}),(0,X.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,X.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,X.jsxs)(`div`,{draggable:!c,onDragStart:n=>ne(n,e,t),className:cv(`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,X.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,X.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,X.jsx)(kt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,X.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:cv(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,X.jsx)(U_,{title:`${$.properties} – ${O.type}`,fields:F,onChange:M}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:$.properties}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:$.selectElementPrompt})})]}))}),(0,X.jsx)(V_,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var fv={"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 pv(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 mv(){try{let e=L();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:pv(fv)}:{t:e.t}}catch{return{t:pv(fv)}}}function hv(...e){return $i(Qi(e))}var gv={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function _v(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var vv=0;function yv(e){return vv+=1,`${e}_${Date.now()}_${vv}`}function bv({steps:e,currentIndex:t,onStepClick:n}){return(0,X.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,X.jsxs)(Y.Fragment,{children:[r>0&&(0,X.jsx)(`div`,{className:hv(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,X.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:hv(`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,X.jsx)(`div`,{className:hv(`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,X.jsx)(qn,{className:`h-4 w-4`}):r+1}),(0,X.jsx)(`span`,{className:hv(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function xv({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!pe(e.name);return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,X.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,X.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:hv(`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,X.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,X.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,X.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,X.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,X.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,X.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:tt},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:bt},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:Xn}].map(({value:t,labelKey:a,Icon:o})=>(0,X.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:hv(`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,X.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,X.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function Sv({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,Y.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,X.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(zr,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.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,X.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:hv(`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,X.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,X.jsx)(`div`,{className:hv(`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,X.jsx)(qn,{className:`h-3 w-3`})})]}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,X.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var Cv={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 wv({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.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,X.jsx)(It,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,X.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,X.jsx)(Zr,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,X.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,X.jsx)(Ge,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,X.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,X.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,X.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,X.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):P(n.label)}),(0,X.jsx)(`span`,{className:hv(`rounded-full px-2 py-0.5 text-[10px] font-medium`,Cv[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,X.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,X.jsx)(yr,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(Ui,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function Tv({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,X.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Ri,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Kt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Se,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,X.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,X.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,X.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function Ev({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=mv(),l=I_(),[u,d]=(0,Y.useState)(0),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(()=>({...gv,objects:e.map(e=>({...e})),...n})),g=(0,Y.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,Y.useMemo)(()=>m.name.length>0&&pe(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,Y.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,Y.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,Y.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,Y.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,Y.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,Y.useCallback)(e=>{let t={id:yv(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,Y.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,Y.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,Y.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:_v(e.objects)})),d(e=>e+1))},[u,v]),k=(0,Y.useCallback)(()=>{_||d(e=>e-1)},[_]),A=(0,Y.useCallback)(()=>{r?.(m)},[m,r]),j=(0,Y.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,Y.useCallback)(()=>{a?.(m)},[m,a]),ee=(0,Y.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:_v(e.objects)})),d(e))},[u,b]);return(0,X.jsxs)(`div`,{className:hv(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,X.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,X.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,X.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,X.jsx)(Jn,{className:`h-4 w-4`})})]}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,X.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,X.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,X.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,X.jsx)(bv,{steps:g,currentIndex:u,onStepClick:ee})}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,X.jsx)(xv,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,X.jsx)(Sv,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,X.jsx)(wv,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,X.jsx)(Tv,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,X.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,X.jsx)(ki,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,X.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,X.jsx)(qn,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,X.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,X.jsx)(Rn,{className:`h-4 w-4`})]})]})]})]})}function Dv(...e){return $i(Qi(e))}var Ov=0;function kv(e){return Ov+=1,`${e}_${Date.now()}_${Ov}`}var Av={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Dn},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:er},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:mt},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:Pi},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Zr},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:It},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:Ge},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:Xe}},jv=[{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 Mv({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,Y.useState)(!1),[_,v]=(0,Y.useState)(P(e.label)??``),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(e.icon||``),C=Av[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(P(e.label)??``),g(!1)},D=()=>{u(e.id,x.trim()),b(!1)};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:Dv(`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,X.jsx)(jt,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,X.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,X.jsx)(Ui,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Rn,{className:`h-3.5 w-3.5`})}):(0,X.jsx)(`span`,{className:`w-5`}),y&&!i?(0,X.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,X.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,X.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,X.jsx)(W,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,X.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,X.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(P(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,X.jsx)(`span`,{className:Dv(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(P(e.label)??``),g(!0))},children:P(e.label)}),(0,X.jsx)(`span`,{className:Dv(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,X.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,X.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,X.jsx)(Ye,{className:`h-3.5 w-3.5`}):(0,X.jsx)(pn,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,X.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,X.jsx)(Ni,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(yr,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(Ui,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,X.jsx)(X.Fragment,{children:e.children.map((n,r)=>(0,X.jsx)(Mv,{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 Nv({items:e,t}){return(0,X.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,X.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,X.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,X.jsx)(Pv,{item:e,depth:0},e.id))})]})}function Pv({item:e,depth:t}){let n=Av[e.type];return e.type===`separator`?(0,X.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,X.jsx)(`span`,{className:`truncate`,children:P(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,X.jsx)(Pv,{item:e,depth:t+1},e.id))]})}function Fv({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=mv(),c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,Y.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,Y.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,Y.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,Y.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,Y.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,Y.useCallback)((n,r)=>{let i={id:kv(r),type:r,label:r===`separator`?``:`New ${s(Av[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,Y.useCallback)(n=>{let r={id:kv(n),type:n,label:n===`separator`?``:`New ${s(Av[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,Y.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,Y.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,Y.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,X.jsxs)(`div`,{"data-testid":`navigation-designer`,className:Dv(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,X.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[jv.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=Av[e];return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:Dv(`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,X.jsx)(Ni,{className:`h-3 w-3`}),s(t)]},e)}),(0,X.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,X.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,X.jsx)(ai,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,X.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:Dv(`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,X.jsx)(Nt,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,X.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,X.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,X.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,X.jsx)(Mv,{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,X.jsx)(Nv,{items:e,t:s})]})}function Iv(...e){return $i(Qi(e))}var Lv=[{type:`metric`,label:`KPI Metric`,Icon:Ct},{type:`bar`,label:`Bar Chart`,Icon:Pi},{type:`line`,label:`Line Chart`,Icon:Me},{type:`pie`,label:`Pie Chart`,Icon:Zt},{type:`table`,label:`Table`,Icon:Ze},{type:`grid`,label:`Grid`,Icon:Si}],Rv=0;function zv(){return Rv+=1,`widget_${Date.now()}_${Rv}`}function Bv({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=Lv.find(e=>e.type===l)||Lv[0];return(0,X.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:Iv(`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,X.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(jt,{className:`h-4 w-4 text-gray-300`}),(0,X.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,X.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,X.jsx)(yr,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(Ui,{className:`h-3.5 w-3.5`})}),(0,X.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,X.jsx)(kt,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,X.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,X.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function Vv({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=mv();return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,X.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,X.jsx)(Jn,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,X.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:Lv.map(e=>(0,X.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,X.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,X.jsx)(`option`,{value:`count`,children:`Count`}),(0,X.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,X.jsx)(`option`,{value:`avg`,children:`Average`}),(0,X.jsx)(`option`,{value:`min`,children:`Min`}),(0,X.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,X.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,X.jsx)(`option`,{value:`default`,children:`Default`}),(0,X.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,X.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,X.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,X.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,X.jsx)(`option`,{value:`success`,children:`Success`}),(0,X.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,X.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,X.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,X.jsxs)(`div`,{className:`flex-1`,children:[(0,X.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,X.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 Hv({schema:e}){let{t}=mv(),n=e.widgets||[];return(0,X.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,X.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,X.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=Lv.find(t=>t.type===(e.type||`metric`))||Lv[0];return(0,X.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,X.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function Uv({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=mv(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null),m=(0,Y.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,Y.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=F_(e),w=(0,Y.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,Y.useCallback)(e=>{let t=zv(),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,Y.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,Y.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,Y.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,Y.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,Y.useCallback)(()=>{i&&i(v)},[v,i]),M=(0,Y.useCallback)(()=>{m.current?.click()},[]),ee=(0,Y.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,X.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:Iv(`flex flex-col gap-4 outline-none`,r),children:[(0,X.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:ee}),E&&!d&&(0,X.jsx)(Vv,{widget:E,readOnly:n,onChange:A,onClose:()=>_(null)}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),Lv.map(({type:e,label:t,Icon:r})=>(0,X.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,X.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(Ir,{className:`h-4 w-4`})}),(0,X.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,X.jsx)(Kn,{className:`h-4 w-4`})})]}),(0,X.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,X.jsx)(ai,{className:`h-4 w-4`})}),!n&&(0,X.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,X.jsx)(Nt,{className:`h-4 w-4`})}),(0,X.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:Iv(`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,X.jsx)(Ye,{className:`h-4 w-4`}):(0,X.jsx)(pn,{className:`h-4 w-4`})})]})]}),d?(0,X.jsx)(Hv,{schema:v}):T.length===0?(0,X.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,X.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,X.jsx)(Bv,{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 Wv(...e){return $i(Qi(e))}var Gv=[{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`}],Kv=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function qv({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=mv(),[c,l]=(0,Y.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=F_(e),g=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,Y.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,Y.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,Y.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,Y.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,X.jsxs)(`div`,{"data-testid":`branding-editor`,className:Wv(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,X.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,X.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:Wv(`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,X.jsx)(Ir,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:Wv(`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,X.jsx)(Kn,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,X.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,X.jsx)(ai,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:Wv(`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,X.jsx)(Nt,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,X.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Ri,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(Kt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,X.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:Gv.map(e=>(0,X.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:Wv(`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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Se,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Te,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,X.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,X.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),Kv.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,X.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,X.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:Wv(`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,X.jsx)(un,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,X.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:Wv(`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,X.jsx)(cn,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,X.jsxs)(`div`,{"data-testid":`branding-preview`,className:Wv(`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,X.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,X.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,X.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,X.jsx)(`span`,{className:Wv(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,X.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,X.jsx)(`p`,{className:Wv(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,X.jsx)(`span`,{className:Wv(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,X.jsxs)(`div`,{className:Wv(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,X.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:Wv(`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,X.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,X.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,X.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,X.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,X.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,X.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,X.jsx)(`div`,{className:Wv(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,X.jsx)(`div`,{className:Wv(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,X.jsx)(`div`,{className:Wv(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function Jv(...e){return $i(Qi(e))}var Yv=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],Xv=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function Zv({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=mv(),s=I_(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),f=(0,Y.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,Y.useMemo)(()=>new ie({items:f}),[f]),m=(0,Y.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,Y.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,Y.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,Y.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,Y.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,Y.useCallback)(()=>{d(null),l(!0)},[]),b=(0,Y.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,Y.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,Y.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:Xv.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:Yv.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,X.jsxs)(`div`,{"data-testid":`object-manager`,className:Jv(`w-full space-y-3`,a),children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Dn,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,X.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,X.jsx)(la,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,X.jsx)(ua,{schema:S}),(0,X.jsx)(V_,{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 Qv(...e){return $i(Qi(e))}var $v={text:{label:`Text`,Icon:Te},textarea:{label:`Text Area`,Icon:mt},number:{label:`Number`,Icon:tn},boolean:{label:`Checkbox`,Icon:it},date:{label:`Date`,Icon:rn},datetime:{label:`Date/Time`,Icon:rn},time:{label:`Time`,Icon:rn},select:{label:`Picklist`,Icon:wr},email:{label:`Email`,Icon:Jt},phone:{label:`Phone`,Icon:Nr},url:{label:`URL`,Icon:Se},password:{label:`Password`,Icon:_i},currency:{label:`Currency`,Icon:tn},percent:{label:`Percent`,Icon:tn},lookup:{label:`Lookup`,Icon:fi},formula:{label:`Formula`,Icon:yi},autonumber:{label:`Auto Number`,Icon:tn},file:{label:`File`,Icon:mt},image:{label:`Image`,Icon:Ri},markdown:{label:`Markdown`,Icon:mt},html:{label:`Rich Text`,Icon:mt},color:{label:`Color`,Icon:Kt},code:{label:`Code`,Icon:yi},location:{label:`Location`,Icon:Ut},address:{label:`Address`,Icon:Ut},rating:{label:`Rating`,Icon:Je},slider:{label:`Slider`,Icon:or}},ey={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`]},ty=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function ny({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=mv(),o=I_(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(``),p=(0,Y.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,Y.useMemo)(()=>new ie({items:p}),[p]),h=(0,Y.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,Y.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,Y.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,Y.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,Y.useCallback)(()=>{u(null),c(!0)},[]),b=(0,Y.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,Y.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,Y.useMemo)(()=>ty.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:ey[e].map(e=>({label:$v[e].label,value:e}))})),[a]),C=(0,Y.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,Y.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,X.jsxs)(`div`,{"data-testid":`field-designer`,className:Qv(`w-full space-y-3`,i),children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(cr,{className:`h-4 w-4 text-primary`}),(0,X.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,X.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,X.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,X.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,X.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,X.jsx)(la,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,X.jsx)(da,{schema:w}),(0,X.jsx)(V_,{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 ry=`objectui-app-wizard-draft`;function iy(){let e=_(),{appName:t}=f(),{objects:n,refresh:r}=F(),i=ge(),a=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),o=(0,Y.useCallback)(()=>{try{let e=localStorage.getItem(ry);if(e)return JSON.parse(e)}catch{}},[]),s=(0,Y.useCallback)(async t=>{try{let n=de(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(ry),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]),c=(0,Y.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),l=(0,Y.useCallback)(e=>{try{localStorage.setItem(ry,JSON.stringify(e)),J.info(`Draft saved`)}catch{}},[]);return(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,X.jsx)(Ev,{availableObjects:a,initialDraft:o(),onComplete:s,onCancel:c,onSaveDraft:l})})}function ay(){let e=_(),{appName:t,editAppName:n}=f(),{apps:r,objects:i,refresh:a}=F(),o=ge(),s=n||t,c=r.find(e=>e.name===s),l=(i||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:c?.navigation?.some(t=>t.type===`object`&&t.objectName===e.name)??!1})),u=(0,Y.useMemo)(()=>{if(c)return{name:c.name,title:c.title||c.label||``,description:c.description||``,icon:c.icon||``,layout:c.layout||`sidebar`,navigation:c.navigation||[],branding:{logo:c.branding?.logo||c.logo||``,primaryColor:c.branding?.primaryColor||`#3b82f6`,favicon:c.branding?.favicon||c.favicon||``}}},[c]),d=(0,Y.useCallback)(async t=>{try{let n=de(t),r={...c,...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,c]),p=(0,Y.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,Y.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${s}`,JSON.stringify(e)),J.info(`Draft saved`)}catch{}},[s]);return c?(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,X.jsx)(Ev,{availableObjects:l,initialDraft:u,onComplete:d,onCancel:p,onSaveDraft:m})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,X.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,s,`" not found.`]})})}function oy(){let e=_(),{dashboardName:t}=f(),n=ge(),{dashboards:r,refresh:i}=F(),a=r?.find(e=>e.name===t),[o,s]=(0,Y.useState)(()=>a||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),c=(0,Y.useRef)(o);c.current=o;let l=(0,Y.useCallback)(async e=>{try{if(n)return await n.update(`sys_dashboard`,t,e),i().catch(()=>{}),!0}catch{}return!1},[n,t,i]),u=(0,Y.useCallback)(async e=>{s(e),await l(e)},[l]);(0,Y.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),l(c.current).then(e=>{e&&J.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]);let d=(0,Y.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,Y.useCallback)(e=>{J.success(`Dashboard schema imported`),u(e)},[u]);return a?(0,X.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,X.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,X.jsx)(qe,{className:`h-4 w-4`})}),(0,X.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,a.label||a.title||t]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,X.jsx)(Uv,{schema:o,onChange:u,onExport:d,onImport:p})})]}):(0,X.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var sy=t({AppCreationWizard:()=>Ev,BrandingEditor:()=>qv,CreateAppPage:()=>iy,DashboardDesignPage:()=>oy,DashboardEditor:()=>Uv,DataModelDesigner:()=>nv,EditAppPage:()=>ay,FieldDesigner:()=>ny,NavigationDesigner:()=>Fv,ObjectManager:()=>Zv,PageDesigner:()=>X_,ProcessDesigner:()=>sv,ReportDesigner:()=>dv});R.register(`page-designer`,X_,{namespace:`plugin-designer`,label:`Page Designer`,category:`Designer`,inputs:[{name:`canvas`,type:`code`,label:`Canvas Configuration`},{name:`components`,type:`code`,label:`Components`},{name:`showComponentTree`,type:`boolean`,label:`Show Component Tree`,defaultValue:!0},{name:`undoRedo`,type:`boolean`,label:`Undo/Redo`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`data-model-designer`,nv,{namespace:`plugin-designer`,label:`Data Model Designer`,category:`Designer`,inputs:[{name:`entities`,type:`code`,label:`Entities`},{name:`relationships`,type:`code`,label:`Relationships`},{name:`autoLayout`,type:`boolean`,label:`Auto Layout`,defaultValue:!1},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`process-designer`,sv,{namespace:`plugin-designer`,label:`Process Designer (BPMN)`,category:`Designer`,inputs:[{name:`processName`,type:`string`,label:`Process Name`},{name:`nodes`,type:`code`,label:`Nodes`},{name:`edges`,type:`code`,label:`Edges`},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`report-designer`,dv,{namespace:`plugin-designer`,label:`Report Designer`,category:`Designer`,inputs:[{name:`reportName`,type:`string`,label:`Report Name`},{name:`objectName`,type:`string`,label:`Data Source Object`},{name:`sections`,type:`code`,label:`Sections`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showPropertyPanel`,type:`boolean`,label:`Show Property Panel`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`app-creation-wizard`,Ev,{namespace:`plugin-designer`,label:`App Creation Wizard`,category:`Designer`,inputs:[{name:`availableObjects`,type:`code`,label:`Available Objects`},{name:`templates`,type:`code`,label:`Templates`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`navigation-designer`,Fv,{namespace:`plugin-designer`,label:`Navigation Designer`,category:`Designer`,inputs:[{name:`items`,type:`code`,label:`Navigation Items`},{name:`showPreview`,type:`boolean`,label:`Show Preview`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`dashboard-editor`,Uv,{namespace:`plugin-designer`,label:`Dashboard Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Dashboard Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`branding-editor`,qv,{namespace:`plugin-designer`,label:`Branding Editor`,category:`Designer`,inputs:[{name:`branding`,type:`code`,label:`Branding Config`},{name:`appTitle`,type:`string`,label:`App Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`object-manager`,Zv,{namespace:`plugin-designer`,label:`Object Manager`,category:`Designer`,inputs:[{name:`objects`,type:`code`,label:`Object Definitions`},{name:`showSystemObjects`,type:`boolean`,label:`Show System Objects`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),R.register(`field-designer`,ny,{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 cy(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 ly(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 uy=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=cy(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(ly)};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 dy({schema:e}){let t=e.objectName,{objects:n,refresh:r}=F(),i=hu(),a=(0,Y.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,Y.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(T_):[],[a]),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),d=s??o,f=(0,Y.useRef)(d),p=(0,Y.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=uy.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,X.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,X.jsx)(qr,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,X.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,X.jsx)(Sr,{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,X.jsx)(ny,{objectName:t,fields:d,onFieldsChange:p})]})}function fy({schema:e}){let t=e.objectName,[n,r]=(0,Y.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,X.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,X.jsxs)(H,{value:n,onValueChange:r,className:`w-full`,children:[(0,X.jsxs)(xi,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,X.jsxs)(Xr,{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,X.jsx)(pi,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,X.jsxs)(Xr,{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,X.jsx)(cr,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,X.jsxs)(Xr,{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,X.jsx)(fi,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,X.jsxs)(Xr,{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,X.jsx)(gn,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,X.jsx)(ur,{value:`details`,className:`mt-6`,children:(0,X.jsx)(`div`,{className:`space-y-6`,children:(0,X.jsx)(M,{schema:i})})}),(0,X.jsx)(ur,{value:`fields`,className:`mt-6`,children:(0,X.jsx)(`div`,{className:`space-y-6`,children:(0,X.jsx)(M,{schema:a})})}),(0,X.jsx)(ur,{value:`relationships`,className:`mt-6`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(M,{schema:o}),(0,X.jsx)(M,{schema:s})]})}),(0,X.jsx)(ur,{value:`data`,className:`mt-6`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(M,{schema:l}),(0,X.jsx)(M,{schema:c})]})})]})})}var py={namespace:`console`,category:`system`};R.register(`object-detail-tabs`,fy,{...py,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),R.register(`object-properties`,O_,{...py,label:`Object Properties`,icon:`Settings2`}),R.register(`object-relationships`,A_,{...py,label:`Object Relationships`,icon:`Link2`}),R.register(`object-keys`,j_,{...py,label:`Object Keys`,icon:`KeyRound`}),R.register(`object-data-experience`,M_,{...py,label:`Data Experience`,icon:`LayoutList`}),R.register(`object-data-preview`,N_,{...py,label:`Data Preview`,icon:`Table`}),R.register(`object-field-designer`,dy,{...py,label:`Field Designer`,icon:`Columns`});var my=(0,Y.lazy)(()=>m(()=>import(`./ApiConsolePage-BIBykAYj.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),hy=(0,Y.lazy)(()=>m(()=>import(`./FlowRunsPage-NjEPPv_e.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),gy=(0,Y.lazy)(()=>m(()=>import(`./PublicFormsPage-BrLPiHf1.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function _y({label:e}){return(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Df({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(_y,{label:`API console`}),children:(0,X.jsx)(my,{...e})})}),Df({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(_y,{label:`flow runs`}),children:(0,X.jsx)(hy,{...e})})}),Df({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(_y,{label:`public forms`}),children:(0,X.jsx)(gy,{...e})})});var vy=(0,Y.lazy)(()=>m(()=>import(`./ObjectManagerListPage-DEPokJwV.js`).then(e=>({default:e.ObjectManagerListPage})),__vite__mapDeps([0]),import.meta.url));$f({type:`object`,ListPage:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading Object Manager…`}),children:(0,X.jsx)(vy,{...e})})});var yy=`/api/v1/auth`;dc(),R.registerLazy(`object-map`,()=>m(()=>import(`./plugin-map-C6vgk2bJ.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),R.registerLazy(`map`,()=>m(()=>import(`./plugin-map-C6vgk2bJ.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`dashboard`,`metric`,`metric-card`,`object-metric`,`pivot`,`object-pivot`,`dashboard-grid`,`object-data-table`])R.registerLazy(e,()=>m(()=>import(`./plugin-dashboard-DvBectcr.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});R.registerLazy(`chart`,()=>m(()=>import(`./plugin-charts-C11LxM1X.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])R.registerLazy(e,()=>m(()=>import(`./plugin-charts-C11LxM1X.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});R.registerLazy(`object-gantt`,()=>m(()=>import(`./plugin-gantt-7ui7uiVc.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),R.registerLazy(`gantt`,()=>m(()=>import(`./plugin-gantt-7ui7uiVc.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`markdown`,()=>m(()=>import(`./plugin-markdown-DPzm2nVd.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),R.registerLazy(`object-timeline`,()=>m(()=>import(`./plugin-timeline-lCaTr_4i.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),R.registerLazy(`timeline`,()=>m(()=>import(`./plugin-timeline-lCaTr_4i.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`object-calendar`,()=>m(()=>import(`./plugin-calendar-Dnr7itgk.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),R.registerLazy(`calendar`,()=>m(()=>import(`./plugin-calendar-Dnr7itgk.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),R.registerLazy(`calendar-view`,()=>m(()=>import(`./plugin-calendar-Dnr7itgk.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),R.registerLazy(`object-kanban`,()=>m(()=>import(`./plugin-kanban-q2UT5MlD.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),R.registerLazy(`kanban`,()=>m(()=>import(`./plugin-kanban-q2UT5MlD.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])R.registerLazy(e,()=>m(()=>import(`./plugin-kanban-q2UT5MlD.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});R.registerLazy(`report`,()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`report-builder`,`spec-report`])R.registerLazy(e,()=>m(()=>import(`./plugin-report-BJM4LH87.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});en();var by=``.replace(/\/+$/,``);Promise.all([Ks(by),C_(yy)]).finally(()=>{Pa.createRoot(document.getElementById(`root`)).render((0,X.jsx)(Y.StrictMode,{children:(0,X.jsx)(ca,{pwa:{enabled:!0,name:Js(),shortName:Ys()},children:(0,X.jsx)(ue,{loadLanguage:b_,children:(0,X.jsx)(y_,{})})})}))});export{Iu as a,Of as i,Zv as n,hu as o,w_ as r,uy as t};