@objectstack/console 12.1.0 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.objectui-sha +1 -1
- package/dist/assets/{AdapterProvider-BcaDLM8t.js → AdapterProvider-_4c7hk3d.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-kXdn272E.js → AiPendingActionsPage-Gc2Wh8Kh.js} +1 -1
- package/dist/assets/{ApiConsolePage-BUAZ2Y01.js → ApiConsolePage-CmiLmtuU.js} +1 -1
- package/dist/assets/{AppDocsIndex-BfFCj_wz.js → AppDocsIndex-CG7e4V2y.js} +1 -1
- package/dist/assets/{AppManagementPage-lZl1h0_x.js → AppManagementPage-C7T-9Exg.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-BllA35Q9.js → ApprovalsInboxPage-D9PFFxKD.js} +1 -1
- package/dist/assets/{AuditLogPage-Du_n63Ua.js → AuditLogPage-C-rDSpPt.js} +1 -1
- package/dist/assets/{ComponentNavView-BNkTx_gd.js → ComponentNavView-DX23dzZd.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-CmLazUxX.js +1 -0
- package/dist/assets/CreateViewDialog-6JmiAMxS.js +1 -0
- package/dist/assets/DashboardView-Al7ce4gm.js +1 -0
- package/dist/assets/DashboardWidgetInspector-BmIMgSGO.js +1 -0
- package/dist/assets/{DeveloperHubPage-BJDkM5bW.js → DeveloperHubPage-D8eYekI9.js} +1 -1
- package/dist/assets/{ExpressionProvider-CD5Qq5aY.js → ExpressionProvider-w-HoWEV1.js} +1 -1
- package/dist/assets/{FlowRunsPage-C8usAiCs.js → FlowRunsPage-Hs5i7s3C.js} +1 -1
- package/dist/assets/{IntegrationsPage-DHi5SpvX.js → IntegrationsPage-COvUlRq2.js} +1 -1
- package/dist/assets/InterfaceListPage-JNxR3qlQ.js +1 -0
- package/dist/assets/{ManagedByBadge-CQOEWdSz.js → ManagedByBadge-BZofhfqM.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-BUAjFq6w.js → MarketplaceAccessDenied-Cur1UQ0U.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-CK-HsgOu.js → MarketplaceInstalledPage-D9ow2tlx.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-DHsi6uiN.js → MarketplacePackagePage-0AKyKbMD.js} +1 -1
- package/dist/assets/{MarketplacePage-DIFzpvbl.js → MarketplacePage-DUzZZa8D.js} +1 -1
- package/dist/assets/{MetadataInspector-Bayj0F4e.js → MetadataInspector-CpceGXDL.js} +1 -1
- package/dist/assets/{MetadataProvider-DboJnyDA.js → MetadataProvider-MNkZn-bR.js} +1 -1
- package/dist/assets/{MonacoImpl-DFmzedsv.js → MonacoImpl-DoDns4Vj.js} +1 -1
- package/dist/assets/ObjectDataPage-CUJksP8e.js +1 -0
- package/dist/assets/{PageView-BfC2HLWA.js → PageView-AS6xg5z-.js} +1 -1
- package/dist/assets/{ProfilePage-YhSTeHYm.js → ProfilePage-iJeMD7FK.js} +1 -1
- package/dist/assets/{PublicFormsPage-B3Wg58sq.js → PublicFormsPage-C-wbtEXG.js} +1 -1
- package/dist/assets/RecordDetailView-Ba0xool8.js +9 -0
- package/dist/assets/{RecordFormPage-BqNRd1-N.js → RecordFormPage-CbvOD5UT.js} +1 -1
- package/dist/assets/ReportDefaultInspector-OSqdhKEL.js +11 -0
- package/dist/assets/ReportView-Df7cdlQo.js +2 -0
- package/dist/assets/SearchResultsPage-D0nbmFox.js +1 -0
- package/dist/assets/{SettingsHub-B8_T5GH3.js → SettingsHub-BsZee-2C.js} +1 -1
- package/dist/assets/SettingsView-CSBwd4YP.js +1 -0
- package/dist/assets/{SystemHubPage-CgvK6Oyz.js → SystemHubPage-n41ly_cC.js} +1 -1
- package/dist/assets/data-adapter-W6WwA2ln.js +7 -0
- package/dist/assets/dist-CfcbLQde.js +11 -0
- package/dist/assets/framework-B9PMswdm.js +36 -0
- package/dist/assets/getIcon-DkcFniPV.js +1 -0
- package/dist/assets/{highlighted-body-OFNGDK62-DRL1o2sE.js → highlighted-body-OFNGDK62-CLUabCIi.js} +1 -1
- package/dist/assets/index-Oki50z-M.js +2 -0
- package/dist/assets/index-rbBh03NP.css +2 -0
- package/dist/assets/{infrastructure-BySW-NB0.js → infrastructure-BnbfcrX8.js} +1 -1
- package/dist/assets/{marketplaceApi-2fWjbQI7.js → marketplaceApi-BLyDDfGk.js} +1 -1
- package/dist/assets/mermaid-GHXKKRXX-Df_DEhBm.js +1 -0
- package/dist/assets/metadata-admin-DiOg8Tx8.js +22 -0
- package/dist/assets/{plugin-calendar-jq5LS38z.js → plugin-calendar-CVeG5Hhb.js} +1 -1
- package/dist/assets/plugin-charts-BTfOaZVx.js +7 -0
- package/dist/assets/{plugin-chatbot-BTDg_ecv.js → plugin-chatbot-COpsZSy4.js} +45 -45
- package/dist/assets/plugin-dashboard-Bi5WrqPG.js +6 -0
- package/dist/assets/plugin-form-CzotVFc-.js +1 -0
- package/dist/assets/{plugin-gantt-D51p6Rw0.js → plugin-gantt-BUcqVYxX.js} +2 -2
- package/dist/assets/plugin-grid-BXfwTczT.js +8 -0
- package/dist/assets/{plugin-kanban-D2Et0gJr.js → plugin-kanban-Dw_QTU-e.js} +1 -1
- package/dist/assets/plugin-map-D89OX2_H.js +1 -0
- package/dist/assets/{plugin-markdown-BAdYqOQi.js → plugin-markdown-CWbusz5W.js} +1 -1
- package/dist/assets/plugin-report-Cy6FwNfk.js +59 -0
- package/dist/assets/{plugin-timeline-DFNoZxR2.js → plugin-timeline-BAImk_4t.js} +1 -1
- package/dist/assets/{plugin-tree-B5L8YkYP.js → plugin-tree-CtakCCIf.js} +1 -1
- package/dist/assets/plugin-view-DZC_ZJtv.js +1 -0
- package/dist/assets/plugins-views-CxFTNQJ7.js +4 -0
- package/dist/assets/recordFormNavigation-8nEYNxNo.js +1 -0
- package/dist/assets/runtime-metadata-persistence-D1KKivGr.js +1 -0
- package/dist/assets/{skeletons-9VTXs8YD.js → skeletons-BK6x7CYd.js} +1 -1
- package/dist/assets/{src-4pltlsqa.js → src-BPEDMjfw.js} +1 -1
- package/dist/assets/src-CCztNT-4.js +15 -0
- package/dist/assets/{types-B9qOi1b_.js → types-X8W-qTHJ.js} +1 -1
- package/dist/assets/ui-components-DsYvPIox.js +42 -0
- package/dist/assets/ui-layout-BdFgfR9C.js +1 -0
- package/dist/assets/useMetadata-DAEfn7ks.js +1 -0
- package/dist/assets/useOpenRecordList-DL3H_OJi.js +1 -0
- package/dist/assets/useReconcileOnError-CtvIPgmD.js +1 -0
- package/dist/assets/{useRecordApprovals-PhUYX_dd.js → useRecordApprovals-BHkgfYJW.js} +1 -1
- package/dist/assets/vendor-objectstack-sPlD8LgO.js +95 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ConsoleFloatingChatbot-BTKK_vEs.js +0 -1
- package/dist/assets/DashboardView-DwORDYTI.js +0 -1
- package/dist/assets/DashboardWidgetInspector-DnxXy8MD.js +0 -1
- package/dist/assets/InterfaceListPage-BqCFOLqM.js +0 -1
- package/dist/assets/RecordDetailView-BXq0yKAC.js +0 -9
- package/dist/assets/ReportDefaultInspector-BpiqbNpa.js +0 -11
- package/dist/assets/ReportView-C44qsTBA.js +0 -2
- package/dist/assets/SearchResultsPage-CcZIaPuL.js +0 -1
- package/dist/assets/SettingsView-DU5GHJoJ.js +0 -1
- package/dist/assets/data-adapter-B0hWGLbx.js +0 -7
- package/dist/assets/dist-BrXdcuve.js +0 -11
- package/dist/assets/framework-CUm99d5f.js +0 -36
- package/dist/assets/index-BT5Kcjbb.css +0 -2
- package/dist/assets/index-gh_wl34E.js +0 -2
- package/dist/assets/mermaid-GHXKKRXX-CnhpyTzH.js +0 -1
- package/dist/assets/metadata-admin-B0y5-vc3.js +0 -22
- package/dist/assets/plugin-charts-CN_USFkK.js +0 -7
- package/dist/assets/plugin-dashboard-DVmEJF7R.js +0 -6
- package/dist/assets/plugin-form-G3dyuFOt.js +0 -1
- package/dist/assets/plugin-grid-Dk1ZUbuk.js +0 -8
- package/dist/assets/plugin-map-C_5T2eDy.js +0 -1
- package/dist/assets/plugin-report-6nU1jd3t.js +0 -59
- package/dist/assets/plugin-view-BSG5MvLZ.js +0 -1
- package/dist/assets/plugins-views-Cxvy9qpT.js +0 -4
- package/dist/assets/recordFormNavigation-CXt3jCB4.js +0 -1
- package/dist/assets/src-DdEhFXgM.js +0 -15
- package/dist/assets/ui-components-DvVVxGRS.js +0 -42
- package/dist/assets/ui-layout-DmrJIZR6.js +0 -1
- package/dist/assets/useOpenRecordList-WXseLM45.js +0 -1
- package/dist/assets/useReconcileOnError-DzkPdzFt.js +0 -1
- package/dist/assets/vendor-objectstack-BGWJwgbT.js +0 -95
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./index-BT5Kcjbb.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{_ as n,a as r,c as i,d as a,f as o,i as s,l as c,m as l,o as u,p as d,r as f,s as p,t as m,u as h}from"./vendor-react-slxo-5GC.js";import{d as g,f as _,m as v,n as y,o as b}from"./infrastructure-BySW-NB0.js";import{G as x,N as S,Nt as C,P as w,R as T,Rt as E,U as D,W as O,_ as k,a as A,c as j,et as M,g as N,it as P,p as ee,s as F}from"./framework-CUm99d5f.js";import{Aa as I,Ac as L,At as R,B as te,Ba as z,Bn as ne,Bs as B,Bt as re,Ca as ie,Ci as ae,Cs as oe,Ct as se,Di as V,Do as ce,Ds as le,Es as H,Et as ue,Fa as U,Fi as de,Fs as W,G as fe,Gn as G,Gr as pe,Gs as me,Gt as he,Ha as ge,Hi as _e,Hn as ve,Ho as ye,Hr as be,Ht as xe,Ia as Se,Ic as Ce,Io as we,J as Te,Ja as Ee,Jn as De,Jo as Oe,Jr as K,Js as ke,Jt as Ae,Kn as je,Kt as Me,Li as Ne,Ln as q,Lr as Pe,Ls as Fe,Mi as Ie,Mr as Le,Ms as Re,N as ze,No as Be,Nt as Ve,Ot as He,Pa as Ue,Qa as We,Qs as Ge,Ra as Ke,Ri as qe,Rn as Je,Rr as Ye,Rt as Xe,Sa as Ze,Sc as Qe,Sn as $e,So as et,Sr as J,St as tt,Ti as nt,Tt as rt,Un as it,Ur as at,Us as ot,Ut as st,V as ct,Vn as lt,Vo as ut,Vr as dt,Vs as ft,Vt as pt,W as mt,Wn as ht,Ws as gt,Wt as _t,Xa as vt,Xi as Y,Xo as yt,Xt as bt,Yn as xt,Yo as St,Yt as Ct,Za as wt,Zt as Tt,_n as Et,_o as Dt,_r as Ot,_s as kt,ai as At,an as jt,ao as Mt,br as Nt,bt as Pt,cn as Ft,co as It,cr as Lt,ct as Rt,dc as zt,dt as Bt,ec as Vt,eo as Ht,fa as Ut,fn as Wt,fo as Gt,gi as Kt,gn as qt,gr as Jt,gs as Yt,hi as Xt,hn as Zt,ho as Qt,hr as $t,hs as en,ii as tn,jr as nn,jt as rn,k as an,ka as on,kc as sn,ki as cn,kr as ln,kt as un,lc as dn,li as fn,lr as pn,ls as mn,lt as hn,mi as gn,mn as _n,mr as vn,ms as yn,oi as bn,on as xn,or as Sn,pa as Cn,pc as wn,pi as Tn,pn as En,pr as Dn,qn as On,qo as kn,qt as An,ra as jn,rc as Mn,rs as Nn,sc as Pn,si as Fn,sn as In,sr as Ln,ua as Rn,ui as zn,uo as Bn,us as Vn,ut as Hn,va as Un,vi as Wn,vn as Gn,vr as Kn,w as qn,wa as Jn,wc as Yn,wi as Xn,wt as Zn,xi as Qn,xo as $n,xt as er,yo as tr,yr as nr,za as rr,zn as ir,zr as ar}from"./ui-components-DvVVxGRS.js";import{n as or,r as X}from"./vendor-ui-utils-C1OpMExs.js";import{r as sr}from"./data-adapter-B0hWGLbx.js";import{t as cr}from"./AdapterProvider-BcaDLM8t.js";import{n as lr,t as ur}from"./plugin-form-G3dyuFOt.js";import{a as dr,i as fr,n as pr,r as mr,t as hr}from"./MetadataProvider-DboJnyDA.js";import{n as gr,s as _r}from"./assistantBus-DosfPCbN.js";import{n as vr,r as yr,t as br}from"./ExpressionProvider-CD5Qq5aY.js";import{a as xr,c as Sr,d as Cr,g as wr,h as Tr,l as Er,m as Dr,n as Or,o as kr,p as Ar,r as jr,t as Mr,u as Nr}from"./useReconcileOnError-DzkPdzFt.js";import{a as Pr,c as Fr,i as Ir,n as Lr,o as Rr,r as zr,s as Br}from"./useRecordApprovals-PhUYX_dd.js";import{i as Vr,n as Hr,r as Ur,t as Wr}from"./recordFormNavigation-CXt3jCB4.js";import{S as Gr,_ as Kr,a as qr,b as Jr,d as Yr,f as Xr,g as Zr,h as Qr,i as $r,m as ei,p as ti,t as ni,u as ri,v as ii,x as ai,y as oi}from"./plugin-chatbot-BTDg_ecv.js";import{a as si,c as ci,d as li,f as ui,h as di,i as fi,l as pi,m as mi,n as hi,o as gi,p as _i,r as vi,s as yi,u as bi}from"./metadata-admin-B0y5-vc3.js";import{_ as xi,d as Si,f as Ci,g as wi,h as Ti,m as Ei,p as Di,t as Oi,v as ki}from"./RecordDetailView-BXq0yKAC.js";import{n as Ai,r as ji,t as Mi}from"./ui-layout-DmrJIZR6.js";import{_ as Ni,a as Pi,c as Fi,d as Ii,g as Li,h as Ri,l as zi,n as Bi,o as Vi,s as Hi,t as Ui,u as Wi,v as Gi,y as Ki}from"./vendor-dndkit-0M_nRjzm.js";import{$ as qi,A as Ji,E as Yi,F as Xi,I as Zi,L as Qi,M as $i,N as ea,P as ta,R as na,T as ra,b as ia,h as aa,j as oa,v as sa,w as ca,y as Z}from"./ReportDefaultInspector-BpiqbNpa.js";import{n as la,r as ua,t as da}from"./appRoute-CbCiASix.js";import{t as fa}from"./utils-Bixzg6Bz.js";import{n as pa,r as ma,t as ha}from"./MetadataInspector-Bayj0F4e.js";import{n as ga,v as _a,x as va,y as ya}from"./marketplaceApi-2fWjbQI7.js";import{n as ba,r as xa}from"./InterfaceListPage-BqCFOLqM.js";import{l as Sa}from"./plugins-views-Cxvy9qpT.js";import{a as Ca,c as wa,d as Ta,f as Ea,i as Da,l as Oa,n as ka,o as Aa,r as ja,s as Ma,t as Na,u as Pa}from"./plugin-view-BSG5MvLZ.js";import{i as Fa,n as Ia,r as La}from"./useOpenRecordList-WXseLM45.js";import{t as Ra}from"./ManagedByBadge-CQOEWdSz.js";import{a as za,i as Ba,n as Va,r as Ha}from"./PageView-BfC2HLWA.js";import"./RecordFormPage-BqNRd1-N.js";import"./DashboardView-DwORDYTI.js";import"./ReportView-C44qsTBA.js";import"./SearchResultsPage-CcZIaPuL.js";import"./MarketplacePage-DIFzpvbl.js";import"./MarketplacePackagePage-DHsi6uiN.js";import"./MarketplaceInstalledPage-CK-HsgOu.js";import{n as Ua}from"./componentRegistry-ByxoJqMW.js";var Q=m(),$=e(n(),1),Wa=(0,$.createContext)({theme:`system`,setTheme:()=>null});function Ga({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,$.useState)(()=>localStorage.getItem(n)||t);(0,$.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,Q.jsx)(Wa.Provider,{...r,value:o,children:e})}var Ka=()=>{let e=(0,$.useContext)(Wa);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e},qa=wi();function Ja(){let{remediationRequired:e}=_();return e?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[200] flex items-center justify-center bg-background/95 p-4 backdrop-blur-sm`,children:(0,Q.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-6 shadow-xl`,children:e.code===`PASSWORD_EXPIRED`?(0,Q.jsx)(Xa,{message:e.message}):(0,Q.jsx)(Qa,{message:e.message})})}):null}function Ya(){let{signOut:e}=_();return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{e()},className:`mt-4 w-full text-center text-xs text-muted-foreground hover:text-foreground hover:underline`,children:`Sign out instead`})}function Xa({message:e}){let{changePassword:t,setRemediationRequired:n}=_(),[r,i]=(0,$.useState)(``),[a,o]=(0,$.useState)(``),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null);return(0,Q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),f(null),a!==s){f(`New passwords do not match.`);return}u(!0);try{await t(r,a),n(null),window.location.reload()}catch(e){f(e instanceof Error?e.message:`Could not change password.`),u(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Your password has expired`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Please set a new password to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`rem-cur`,children:`Current password`}),(0,Q.jsx)(Ft,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`rem-new`,children:`New password`}),(0,Q.jsx)(Ft,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:a,onChange:e=>o(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`rem-conf`,children:`Confirm new password`}),(0,Q.jsx)(Ft,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),d?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:d}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:l,children:l?`Updating…`:`Change password & continue`}),(0,Q.jsx)(Ya,{})]})}function Za({uri:e}){let[t,n]=(0,$.useState)(null);return(0,Q.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,Q.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,Q.jsx)(`canvas`,{ref:t=>{!t||!e||(0,qa.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function Qa({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=_(),[i,a]=(0,$.useState)(`password`),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(``),[f,p]=(0,$.useState)([]),[m,h]=(0,$.useState)(!1),[g,v]=(0,$.useState)(null);return i===`password`?(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{let{totpURI:e,backupCodes:n}=await t(o);d(e),p(n??[]),a(`verify`)}catch(e){v(e instanceof Error?e.message:`Could not start enrollment.`)}finally{h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Set up two-factor authentication`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Your organization requires an authenticator app to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`rem-pw`,children:`Confirm your password`}),(0,Q.jsx)(Ft,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),g?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:g}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:m,children:m?`Preparing…`:`Continue`}),(0,Q.jsx)(Ya,{})]}):(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{await n(c.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:`Invalid code. Try again.`),h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Scan with your authenticator`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Scan this QR code with Google Authenticator, 1Password, Authy, etc., then enter the 6-digit code.`})]}),u?(0,Q.jsx)(Za,{uri:u}):null,f.length>0?(0,Q.jsxs)(`details`,{className:`rounded-md border bg-muted/40 p-3 text-xs`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:`Save your backup codes`}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Store these somewhere safe — each can be used once if you lose your device.`}),(0,Q.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:f.map(e=>(0,Q.jsx)(`span`,{children:e},e))})]}):null,(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`rem-code`,children:`6-digit code`}),(0,Q.jsx)(Ft,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:c,onChange:e=>l(e.target.value),required:!0})]}),g?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:g}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:m,children:m?`Verifying…`:`Verify & continue`}),(0,Q.jsx)(Ya,{})]})}function $a(){return(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function eo({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=Ir(e);return(0,Q.jsxs)(T,{onModal:n,children:[t,r]})}function to({children:e}){return(0,Q.jsx)(Ga,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(xi,{children:(0,Q.jsx)(Br,{children:(0,Q.jsx)(Lr,{children:(0,Q.jsxs)(Pr,{children:[(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)($a,{}),children:e}),(0,Q.jsx)(Ja,{})]})})})})})}function no({children:e}){return(0,Q.jsx)(cr,{children:(0,Q.jsx)(mr,{children:(0,Q.jsx)(ro,{children:e})})})}function ro({children:e}){let t=S(),{language:n}=A(),r=(0,$.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Q.jsx)(M,{dataSource:t,children:(0,Q.jsxs)(hr,{adapter:t,children:[(0,Q.jsx)(io,{}),(0,Q.jsx)(eo,{dataSource:t,children:e})]},n)}):(0,Q.jsx)($a,{})}function io(){let{user:e}=_(),t=S(),n=Fr();return(0,$.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=sr({dataSource:t,userId:e.id,key:`ui.favorites`}),i=sr({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 ao({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:i,getAuthConfig:a}=_(),[o,s]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let e=!1;return a().then(t=>{e||s(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||s(!1)}),()=>{e=!0}},[a]),i)return(0,Q.jsx)($a,{});let c=n??[];if((c.length>0||t)&&!t)return(0,Q.jsx)(r,{to:`/organizations`,replace:!0});if(c.length===0&&!t){if(o===null)return(0,Q.jsx)($a,{});if(o)return(0,Q.jsx)(r,{to:`/organizations`,replace:!0})}return(0,Q.jsx)(Q.Fragment,{children:e})}function oo({children:e,redirectTo:t=`/home`}){let{enabled:n,isLoading:i}=di();return i?(0,Q.jsx)($a,{}):n?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(r,{to:t,replace:!0})}function so(){let e=c(),t=e.pathname.replace(/^\/system/,``);return(0,Q.jsx)(r,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var co=(0,$.lazy)(()=>l(()=>import(`./ConsoleFloatingChatbot-BTKK_vEs.js`),__vite__mapDeps([0]),import.meta.url)),lo=()=>{l(()=>import(`./ConsoleFloatingChatbot-BTKK_vEs.js`),__vite__mapDeps([0]),import.meta.url)};function uo(e){let[t,n]=(0,$.useState)(!1),{t:r}=A(),{openSeq:i}=_r(),a=(0,$.useRef)(i);return(0,$.useEffect)(()=>{i!==a.current&&(a.current=i,n(!0))},[i]),t?(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(co,{...e,defaultOpen:!0})}):(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e.appLabel}),onClick:()=>n(!0),onMouseEnter:lo,onFocus:lo,className:`fixed bottom-20 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 sm:bottom-6`,"data-testid":`console-chatbot-fab`,children:(0,Q.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,Q.jsx)(`path`,{d:`M12 3v3`}),(0,Q.jsx)(`path`,{d:`M12 18v3`}),(0,Q.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,Q.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,Q.jsx)(`path`,{d:`M3 12h3`}),(0,Q.jsx)(`path`,{d:`M18 12h3`}),(0,Q.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,Q.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function fo(e){let t=qi(),[n,r]=(0,$.useState)(!1);return{publishAll:(0,$.useCallback)(async()=>{r(!0);try{let n=(await t.listDrafts?.({})||[]).filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}));if(n.length===0)return X.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],i=n.filter(e=>e.packageId===null),a=[],o=[],s=0,c=e=>{if(e){e.seedError&&a.push(e.seedError),typeof e.seededRows==`number`&&(s+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&o.push(t.message)}};for(let e of r){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);c(qr(n))}let l=[...i.filter(e=>e.type!==`seed`),...i.filter(e=>e.type===`seed`)];for(let e of l){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&a.push(n.error??`${e.name}: sample data failed to load`)}return o.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:o[0]}):a.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:a[0]}):X.success(s>0?e(`home.pendingDrafts.publishedVerified`,{count:s,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),{ok:!0,attempted:n.length}}catch(t){return X.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function po(e){let t=e?`?packageId=${encodeURIComponent(e)}`:``,n=await fetch(`/api/v1/meta/_drafts${t}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!n.ok)throw Error(`_drafts HTTP ${n.status}`);let r=await n.json();return(Array.isArray(r)?r:r?.drafts??[]).filter(e=>typeof e?.type==`string`&&typeof e?.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}))}async function mo(e){let t=await fetch(`/api/v1/meta/${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`published list HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.items??[];return new Set(r.map(e=>typeof e?.name==`string`?e.name:null).filter(e=>e!==null))}function ho({open:e,onOpenChange:t,packageId:n}){let{t:r}=A(),[i,a]=(0,$.useState)(null),[o,s]=(0,$.useState)(null),c=(0,$.useCallback)(async()=>{a(null),s(null);try{let e=await po(n);a(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await mo(e)}catch{return}a(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){s(e.message)}},[n]);(0,$.useEffect)(()=>{e&&c()},[e,c]);let l=new Map;for(let e of i??[]){let t=l.get(e.type)??[];t.push(e),l.set(e.type,t)}return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(pt,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(st,{children:[(0,Q.jsx)(_t,{children:r(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(xe,{children:r(`preview.changes.description`,{defaultValue:`What publishing will change. New items are added; updates overwrite the live version.`})})]}),(0,Q.jsx)(`div`,{className:`mt-4 flex flex-col gap-4 overflow-y-auto px-4 pb-6`,children:o?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[r(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,o]}):i===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),r(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):i.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...l.entries()].map(([e,t])=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`h4`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:[e,` · `,t.length]}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-sm`,children:[e.kind===`new`?(0,Q.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(ye,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Q.jsx)(z,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),e.kind?(0,Q.jsx)(Sn,{variant:`outline`,className:e.kind===`new`?`border-emerald-200 bg-emerald-50 text-emerald-700`:`border-amber-200 bg-amber-50 text-amber-700`,children:e.kind===`new`?r(`preview.changes.kindNew`,{defaultValue:`New`}):r(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]},`${e.type}:${e.name}`))})]},e))})]})})}function go(){let e=dr(),t=c(),n=h(),{t:r}=A(),{publishAll:i,publishing:a}=fo(r),[o,s]=(0,$.useState)(!1),[l,u]=(0,$.useState)(null);if((0,$.useEffect)(()=>{if(!e)return;let t=!1;return fetch(`/api/v1/meta/_drafts`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`}).then(e=>e.ok?e.json():null).then(e=>{if(t||!e)return;let n=Array.isArray(e)?e:e?.drafts??[];u(Array.isArray(n)?n.length:null)}).catch(()=>{}),()=>{t=!0}},[e,t.pathname]),!e)return null;let d=()=>{fr();let e=new URLSearchParams(t.search);e.delete(pr);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})},f=async()=>{(await i()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},p=l===0;return(0,Q.jsxs)(`div`,{className:L(`sticky top-0 z-40 border-b`,p?`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-700/60 dark:bg-slate-900/40 dark:text-slate-300`:`border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`),"data-testid":`draft-preview-bar`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 text-sm`,children:[(0,Q.jsx)(kn,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:p?r(`preview.draftBar.messageClean`,{defaultValue:`Draft preview — no unpublished changes; everything here is already live.`}):r(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),!p&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>s(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)($n,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof l==`number`?` (${l})`:``]}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,Q.jsx)(ln,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!p&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-t border-amber-300/50 px-4 py-2.5 dark:border-amber-700/40`,"data-testid":`draft-preview-sample-hint`,children:[(0,Q.jsx)(Kt,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300`,"aria-hidden":`true`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold leading-tight`,children:r(`preview.draftBar.sampleDataTitle`,{defaultValue:`Sample data appears once you publish`})}),(0,Q.jsx)(`p`,{className:`text-xs leading-snug text-amber-800/80 dark:text-amber-200/70`,children:r(`preview.draftBar.sampleDataBody`,{defaultValue:`You’re previewing your app’s structure. Publish to load example records and make it live.`})})]}),(0,Q.jsxs)(J,{onClick:f,disabled:a,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,Q.jsx)(qe,{className:`mr-1.5 h-4 w-4`}),a?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publishCta`,{defaultValue:`Publish to see it live`})]})]}),(0,Q.jsx)(ho,{open:o,onOpenChange:s})]})]})}async function _o(e){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`commits HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.commits??n?.data?.commits??[];return(Array.isArray(r)?r:[]).map(e=>{let t=e;return{id:String(t.id),operation:t.operation===`revert`?`revert`:`apply`,message:typeof t.message==`string`?t.message:void 0,actor:typeof t.actor==`string`?t.actor:void 0,aiModel:typeof t.aiModel==`string`?t.aiModel:void 0,itemCount:typeof t.itemCount==`number`?t.itemCount:0,createdAt:typeof t.createdAt==`string`?t.createdAt:void 0}})}async function vo(e,t){let n=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits/${encodeURIComponent(t)}/revert`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),r=await n.json().catch(()=>null),i=r?.data??r??void 0;if(!n.ok||i?.success===!1){let e=r?.error;throw Error((typeof e==`object`?e?.message:e)??`HTTP ${n.status}`)}}function yo(e){if(!e)return``;let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`${n}s`;let r=Math.round(n/60);if(r<60)return`${r}m`;let i=Math.round(r/60);return i<24?`${i}h`:`${Math.round(i/24)}d`}function bo({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=A(),[a,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(null),d=(0,$.useCallback)(async()=>{o(null),c(null);try{o(await _o(n))}catch(e){c(e.message)}},[n]);(0,$.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await vo(n,e),X.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){X.error(`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,Q.jsx)(re,{open:e,onOpenChange:t,children:(0,Q.jsxs)(pt,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,Q.jsxs)(st,{children:[(0,Q.jsx)(_t,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,Q.jsx)(xe,{children:i(`preview.history.description`,{defaultValue:`Every change to this app, newest first. Revert any step to undo it — no publish confirmation needed.`})})]}),(0,Q.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 overflow-y-auto px-4 pb-6`,children:s?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[i(`preview.history.loadFailed`,{defaultValue:`Could not load history:`}),` `,s]}):a===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),i(`preview.history.loading`,{defaultValue:`Loading history…`})]}):a.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`preview.history.empty`,{defaultValue:`No history yet for this app.`})}):a.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded-md border px-2.5 py-2 text-sm`,"data-testid":`commit-row`,children:[(0,Q.jsx)(et,{className:`mt-0.5 h-4 w-4 shrink-0 ${e.operation===`revert`?`text-muted-foreground`:`text-primary`}`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`truncate font-medium`,children:e.message??(e.operation===`revert`?i(`preview.history.revertLabel`,{defaultValue:`Reverted a change`}):i(`preview.history.applyLabel`,{defaultValue:`Build change`}))}),(0,Q.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[e.operation===`revert`?(0,Q.jsx)(Sn,{variant:`outline`,className:`border-muted-foreground/30`,children:i(`preview.history.revert`,{defaultValue:`revert`})}):null,(0,Q.jsxs)(`span`,{children:[e.itemCount,` `,i(`preview.history.items`,{defaultValue:`item(s)`})]}),e.actor?(0,Q.jsxs)(`span`,{children:[`· `,e.actor]}):null,e.createdAt?(0,Q.jsxs)(`span`,{children:[`· `,yo(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`shrink-0`,disabled:l!==null,onClick:()=>f(e.id),"data-testid":`commit-revert`,children:l===e.id?(0,Q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(at,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function xo(){let e=dr(),{appName:t}=o(),n=c(),{apps:r,refresh:i}=w(),{t:a}=A(),[s,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(!1);if(e)return null;let f=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!f)return null;let p=ua(r??[],f);if(!p||p.hidden!==!0)return null;let m=p?.packageId??p?._packageId??null;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`unpublished-app-bar`,children:[(0,Q.jsx)(Oe,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:a(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),m?(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>d(!0),"data-testid":`unpublished-app-history`,children:[(0,Q.jsx)(Gt,{className:`mr-1 h-3.5 w-3.5`}),a(`preview.history.button`,{defaultValue:`History`})]}):null,(0,Q.jsxs)(J,{size:`sm`,onClick:async()=>{l(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(f)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...p,hidden:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}X.success(a(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){X.error(`${a(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{l(!1)}},disabled:s,"data-testid":`unpublished-app-publish`,children:[(0,Q.jsx)(qe,{className:`mr-1 h-3.5 w-3.5`}),s?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),m?(0,Q.jsx)(bo,{open:u,onOpenChange:d,packageId:m,onReverted:i}):null]})}var So=`__all__`;function Co(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function wo(e){if(Array.isArray(e))return e;let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.packages)?t.packages:Array.isArray(t?.items)?t.items:Array.isArray(e?.items)?e.items:[]}function To(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Co(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1;break}}return!0}function Eo(e){let[t,n]=$.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]),c=$.useCallback(async()=>{try{let e=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let t=wo(await e.json()),s=[],c=new Set;for(let e of t){if(!To(e,o))continue;let t=Co(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=Co(e,a);s.push({value:t,label:typeof n==`string`&&n?n:t})}s.sort((e,t)=>e.label.localeCompare(t.label)),n(s)}catch{}},[r,i,a,s]);return $.useEffect(()=>{c();let e=()=>{c()};return window.addEventListener(`objectui:packages-changed`,e),()=>window.removeEventListener(`objectui:packages-changed`,e)},[c]),{options:t,refetch:c}}function Do(e,t,n){let r=Array.isArray(t)?t:[],i=h(),a=c(),o=new URLSearchParams(a.search);$.useEffect(()=>{let t=new URLSearchParams(a.search),n=!1;for(let i of r)if(i.persist!==`none`&&!t.get(`package`))try{let r=sessionStorage.getItem(`objectui-ctx-${e}-${i.id}`);r&&(t.set(`package`,r),n=!0)}catch{}n&&i({pathname:a.pathname,search:t.toString()},{replace:!0})},[e,r,a.pathname,a.search,i]);let s=$.useCallback((t,n)=>{let r=n===So?t.allValue??``:n;try{let n=`objectui-ctx-${e}-${t.id}`;r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}let o=new URLSearchParams(a.search);r?o.set(`package`,r):o.delete(`package`),i({pathname:a.pathname,search:o.toString()},{replace:!0})},[e,a.pathname,a.search,i]),l={};for(let t of r){let n=``;try{n=sessionStorage.getItem(`objectui-ctx-${e}-${t.id}`)??``}catch{}l[t.id]=(o.get(`package`)??n)||(t.allValue??``)}return{contextValues:l,element:r.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Q.jsx)(Oo,{def:e,value:l[e.id],onChange:t=>s(e,t),t:n},e.id))})}}function Oo({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=Eo(e),o=_i(e.icon),s=fa(e.label,r)||e.id,c=s===`Package`?r?.(`common.package`,{defaultValue:s})??s:s,l=r?.(`actionDialog.selectPlaceholder`,{label:c,defaultValue:`Select ${c}…`})??`Select ${c}…`,u=!!t&&t!==(e.allValue??``);return $.useEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,Q.jsxs)(Me,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,Q.jsx)(Ct,{"aria-label":c,"data-testid":`package-switcher`,className:`h-9 w-full gap-2 rounded-md border-sidebar-border/70 bg-sidebar/80 px-2 text-xs font-medium text-sidebar-foreground shadow-none transition-colors hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:shrink-0`,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,Q.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border border-sidebar-border/70 bg-sidebar-accent text-sidebar-foreground/70`,children:(0,Q.jsx)(o,{className:`h-3 w-3`})}),(0,Q.jsx)(bt,{placeholder:l,className:`truncate`})]})}),(0,Q.jsx)(An,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(Ae,{value:e.value,children:e.label},e.value))})]})}var ko=$.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=Ve(),{t:s}=A(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(J,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:L(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(Rn,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});ko.displayName=`LocalizedSidebarTrigger`;function Ao(e){let t=`objectui-nav-order-${e}`,[n,r]=$.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=$.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:$.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:$.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function jo(e){return e.componentRef===`metadata:directory`}function Mo(e){return e.componentRef===`developer:packages`}function No(e){if(e.type!==`group`)return!1;let t=String(e.id??``).toLowerCase(),n=typeof e.label==`string`?e.label.toLowerCase():``;return t===`overview`||n===`overview`}function Po({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=Ve(),r=c(),{t:i}=A(),{objectLabel:a,dashboardLabel:o,navGroupLabel:s,viewLabel:l}=Ce(),{context:u,currentAppName:d}=ki(),{user:p}=_(),m=g();$.useEffect(()=>{let e=0,r=t=>{e=t.touches[0].clientX},i=r=>{let i=r.changedTouches[0].clientX-e;e<30&&i>50&&t&&n(!0)};return document.addEventListener(`touchstart`,r,{passive:!0}),document.addEventListener(`touchend`,i,{passive:!0}),()=>{document.removeEventListener(`touchstart`,r),document.removeEventListener(`touchend`,i)}},[t,n]);let{recentItems:h}=Rr(),{favorites:v,removeFavorite:b}=zr(),{apps:x,objects:S}=w(),C=x||[],T=C.filter(e=>e.active!==!1&&e.hidden!==!0),E=ua(C.filter(e=>e.active!==!1),e||d)||T[0],{applyOrder:D,handleReorder:O}=Ao(E?.name||`home`),{togglePin:k,applyPins:j}=Dr(),M=E?.areas||[],[N,P]=$.useState(()=>M.length>0?M[0].id:null);$.useEffect(()=>{M.length>0?P(e=>M.some(t=>t.id===e)?e:M[0].id):P(null)},[E?.name,M.length]);let ee=M.find(e=>e.id===N)?.navigation||E?.navigation||[],{contextValues:F,element:I}=Do(E?.name||`home`,E?.contextSelectors,i),L=$.useMemo(()=>{let e=[{id:`home-dashboard`,label:i(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`},{id:`docs`,label:i(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(m){let t=[{id:`sys-settings`,label:i(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup`,icon:`settings`},{id:`sys-apps`,label:i(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:i(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:i(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/system/metadata/object`,icon:`database`},{id:`sys-datasources`,label:i(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/component/metadata/resource?type=datasource`,icon:`database`},{id:`sys-users`,label:i(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:i(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:i(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:i(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:i(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,children:t})}return e},[i,m]),te=u===`home`?L:ee,z=u===`app`&&E?`/apps/${da(E)}`:``,ne=u===`app`&&E?.name===`studio`,B=$.useMemo(()=>{if(!ne)return``;let e=new URLSearchParams(r.search).get(`package`)||F.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[F.active_package,ne,r.search]),re=$.useMemo(()=>{if(u!==`app`||E?.name!==`studio`)return te;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(jo(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:Mo(n)?[{...n,type:`url`,label:e,url:`${z}/component/developer/packages${B}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(te).flatMap(e=>No(e)?e.children??[]:[e])},[E?.name,z,u,te,B,i]),ie=$.useMemo(()=>j(D(re)),[re,D,j]),[ae,oe]=$.useState(!1),{evaluator:V}=yr(),ce=$.useCallback(e=>vr(e,V),[V]),{can:le}=y(),H=$.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return le(n,r)}),[le]),U=$.useMemo(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),de=$.useCallback((e,t)=>e===`object`?U.size===0?!0:U.has(t):!0,[U]),W=ne&&r.pathname.replace(/\/+$/,``)===z;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(Pt,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&u===`app`&&(0,Q.jsx)(ue,{className:`border-b p-1.5`,children:(0,Q.jsx)(He,{children:(0,Q.jsx)(rn,{children:(0,Q.jsx)(R,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,Q.jsxs)(f,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Q.jsx)(Bn,{className:`h-5 w-5`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(er,{className:`pt-2`,children:(0,Q.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:u===`app`&&E?(0,Q.jsxs)(Q.Fragment,{children:[I&&(0,Q.jsx)(se,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,Q.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,Q.jsx)(Zn,{children:I})})}),ne&&(0,Q.jsx)(se,{children:(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:(0,Q.jsx)(rn,{children:(0,Q.jsx)(R,{asChild:!0,isActive:W,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(f,{to:{pathname:z,search:B},children:[(0,Q.jsx)(Bn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),M.length>1&&(0,Q.jsxs)(se,{children:[(0,Q.jsxs)(rt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(We,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:M.map(e=>{let t=_i(e.icon);return(0,Q.jsx)(rn,{children:(0,Q.jsxs)(R,{isActive:e.id===N,tooltip:e.label,onClick:()=>P(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Q.jsx)(Mi,{items:ie,basePath:z,evaluateVisibility:ce,checkPermission:H,checkCapability:de,enablePinning:!t,onPinToggle:k,enableReorder:!t,onReorder:O,resolveObjectLabel:(e,t)=>a({name:e,label:t}),resolveDashboardLabel:(e,t)=>o({name:e,label:t}),resolveGroupLabel:E?(e,t)=>s(E.name,e,t):void 0,resolveItemLabel:E?(e,t)=>E.name===`studio`&&t===i(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:s(E.name,e,t):void 0,resolveViewLabel:(e,t,n)=>l(e,t,n),t:i,templateContext:{currentUserId:p?.id??null,contextValues:F}}),h.length>0&&(0,Q.jsxs)(se,{children:[(0,Q.jsxs)(rt,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>oe(e=>!e),children:[(0,Q.jsx)(ft,{className:`h-3 w-3 transition-transform duration-150 ${ae?`rotate-90`:``}`}),(0,Q.jsx)(kt,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),ae&&(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:h.slice(0,5).map(e=>(0,Q.jsx)(rn,{children:(0,Q.jsx)(R,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(f,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),v.some(e=>e.type!==`nav`)&&(0,Q.jsxs)(se,{children:[(0,Q.jsxs)(rt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(fn,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:v.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(R,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(f,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Q.jsx)(un,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(zn,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(se,{children:(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:L.map(e=>{let t=_i(e.icon),n=r.pathname===e.url;return(0,Q.jsx)(rn,{children:(0,Q.jsx)(R,{asChild:!0,tooltip:e.label,isActive:n,children:(0,Q.jsxs)(f,{to:e.url||`/home`,children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Q.jsxs)(se,{children:[(0,Q.jsxs)(rt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(fn,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(Zn,{children:(0,Q.jsx)(He,{children:v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(R,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(f,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Q.jsx)(un,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(zn,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(tt,{className:`border-t p-1`,children:(0,Q.jsx)(ko,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Fo(){let{theme:e,setTheme:t}=Ka(),{t:n}=A();return(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(bn,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(ie,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,Q.jsxs)(_n,{align:`end`,children:[(0,Q.jsxs)(qt,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(bn,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(qt,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(ie,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(qt,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(Jn,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function Io(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function Lo(e){return e===void 0?Io().toString():new URL(`.`,e).toString()}function Ro(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function zo({name:e}){return(0,Q.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded bg-muted text-[10px] font-semibold text-muted-foreground`,children:Ro(e)})}function Bo(){let{t:e}=A(),t=h(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:a}=_(),[o,s]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return a?.().then(t=>{e||s(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[a]);let c=n??[],l=r??c[0]??null;if(!l||c.length<=1)return null;let u=async e=>{if(e.id!==l.id)try{await i(e.id),window.location.href=Lo()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,Q.jsxs)(En,{children:[(0,Q.jsxs)($e,{className:`ml-2 inline-flex max-w-[14rem] items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 transition-colors hover:bg-accent hover:text-foreground`,"data-testid":`workspace-switcher`,children:[(0,Q.jsx)(zo,{name:l.name}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:l.name}),(0,Q.jsx)(Fe,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,Q.jsxs)(_n,{align:`start`,className:`w-60`,children:[(0,Q.jsx)(Et,{className:`text-xs text-muted-foreground`,children:e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),c.map(e=>(0,Q.jsxs)(qt,{onClick:()=>u(e),className:`cursor-pointer gap-2`,children:[(0,Q.jsx)(zo,{name:e.name}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===l.id&&(0,Q.jsx)(gt,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,Q.jsx)(Gn,{}),(0,Q.jsxs)(qt,{onClick:()=>t(`/organizations/${l.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,Q.jsx)(Pe,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!o&&(0,Q.jsxs)(qt,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}var Vo=[{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 Ho(){let{t:e,language:t,changeLanguage:n}=A();return(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(tr,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(_n,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Vo.map(e=>(0,Q.jsxs)(qt,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var Uo={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Re},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:z},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:z},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:Le},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:Le}};function Wo({state:e,className:t}){let n=Uo[e],{t:r}=A(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(e===`connected`){s(!0);let e=setTimeout(()=>s(!1),2e3);return()=>clearTimeout(e)}s(!1)},[e]),e===`connected`&&!o?null:(0,Q.jsxs)(`div`,{className:L(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:i,children:[(0,Q.jsx)(a,{className:L(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Go(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 Ko({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:s}=A(),c=h(),l=o(),{currentAppName:u}=ki(),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(`notifications`),[g,_]=(0,$.useState)(`unread`),v=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,$.useRef)(null),[x,S]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=b.current;if(e!==null&&v>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=v},[v]),(0,$.useEffect)(()=>{x||(b.current=v)},[x,v]);let C=()=>{f(!1);let e=u??l.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{f(!1),c(`/apps/setup/sys_inbox_message?view=mine`)},T=()=>{f(!1),c(`/apps/setup/sys_activity`)},E=e=>{a(e.id);let t=u??l.appName;if(e.action_url){f(!1);let n=e.action_url;if(/^https?:\/\//i.test(n)){window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`/apps/`)){c(n);return}let r=n.startsWith(`/`)?n:`/${n}`;c(t?`/apps/${t}${r}`:r);return}e.source_object&&e.source_id&&(f(!1),c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`))};return(0,Q.jsxs)(jt,{open:d,onOpenChange:f,children:[(0,Q.jsx)(In,{asChild:!0,children:(0,Q.jsxs)(J,{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,Q.jsx)(wn,{className:`h-4 w-4`}),v>0&&(0,Q.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:v>9?`9+`:v},v)]})}),(0,Q.jsxs)(xn,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-semibold`,children:s(`sidebar.inbox`,{defaultValue:`Inbox`})}),p===`notifications`&&t>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:s(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Q.jsxs)(Rt,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,Q.jsxs)(Hn,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(Bt,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(wn,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,Q.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,Q.jsxs)(Bt,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(gn,{className:`h-3.5 w-3.5`}),s(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,Q.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,Q.jsxs)(Bt,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(sn,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(hn,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>_(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,Q.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>_(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=g===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:g===`unread`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,Q.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,Q.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,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.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,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,Q.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:Go(e.created_at)})]})]})})},e.id))})})(),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Q.jsx)(hn,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,Q.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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(gn,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,Q.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:s(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Q.jsx)(J,{size:`sm`,className:`mt-3`,onClick:C,children:s(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Q.jsxs)(hn,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,Q.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,Q.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,Q.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,Q.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[Go(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function qo({activeAppName:e,onAppChange:t}){let{apps:n}=w(),{t:r}=A(),{appLabel:i}=Ce(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=ua(o,e)||ua(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.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,Q.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:fa(s.label,r)})}),(0,Q.jsx)(ot,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(_n,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(Et,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(Gn,{}),o.map(e=>{let n=_i(e.icon),a=i({name:e.name,label:fa(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(qt,{onClick:()=>t(da(e)??e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,Q.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,Q.jsx)(n,{className:`size-3`})}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,Q.jsx)(gt,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Jo=(0,$.createContext)(null);function Yo({children:e}){let[t,n]=(0,$.useState)(null),r=(0,$.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(Jo.Provider,{value:r,children:e})}function Xo(){return(0,$.useContext)(Jo)?.value??null}function Zo(e){let t=(0,$.useContext)(Jo),n=(0,$.useRef)(null);(0,$.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Qo(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,$.useRef)(r);o.current=r;let s=(0,$.useCallback)(e=>o.current(e),[]);Zo((0,$.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var $o=(0,$.createContext)(null);function es({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=Tr(`palette`,{alias:`cmdk`});(0,$.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),a())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]);let o=(0,$.useMemo)(()=>({open:t,openCommandPalette:r,closeCommandPalette:i,toggleCommandPalette:a,setOpen:n}),[t,r,i,a,n]);return(0,Q.jsx)($o.Provider,{value:o,children:e})}function ts(){return(0,$.useContext)($o)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}function ns(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function rs(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var is=[];function as({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:i,activities:a,activeAppName:s,onAppChange:l}){let u=e??(t?`app`:`home`),d=u===`app`,p=c(),m=o(),v=h(),{isOnline:y}=k(),{openCommandPalette:x}=ts(),{openOverlay:C}=Tr(`shortcuts`),{user:T,signOut:E,isAuthEnabled:D,organizations:O,activeOrganization:j,isOrganizationsLoading:M,getAuthConfig:N}=_(),P=S(),{enabled:ee}=di(),F=g(),{t:I}=A(),{objectLabel:R,dashboardLabel:te,pageLabel:z,reportLabel:ne,viewLabel:B,appLabel:re}=Ce(),{apps:ie,dashboards:ae,pages:oe,reports:se}=w(),{currentAppName:V,recordTitle:ce}=ki(),H=Xo(),[ue,U]=(0,$.useState)(null),de=(0,$.useCallback)(async()=>{if(ue===null)try{let e=P?.getClient?.();if(!e?.meta?.getItems){U([]);return}let t=await e.meta.getItems(`doc`);U((Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[]).map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{U([])}},[ue,P]),[W,fe]=(0,$.useState)(null),[G,pe]=(0,$.useState)([]),me=(0,$.useRef)(!1),he=(0,$.useRef)(!1),ge=(0,$.useRef)(!0);(0,$.useEffect)(()=>(ge.current=!0,()=>{ge.current=!1}),[]);let _e=(0,$.useRef)(!1),ve=(0,$.useRef)(!1),ye=(0,$.useRef)(!1),[be,xe]=(0,$.useState)(0),Se=(0,$.useRef)(!1),we=(0,$.useCallback)(async()=>{if(!P||!d)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!me.current&&!ye.current){ye.current=!0;try{let t=await P.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(me.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&fe(e)}}catch{}finally{ye.current=!1}}},[P,d]);(0,$.useEffect)(()=>{we()},[we]),(0,$.useEffect)(()=>{if(!P||!d||!T?.id||he.current)return;let e=!1,t=null,n=1e4,r=n,i=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`,a=new Set([`read`,`clicked`,`dismissed`]),o=async()=>{if(!_e.current){_e.current=!0;try{let[e,t]=await Promise.all([P.find(`sys_inbox_message`,{$filter:{user_id:T.id},$orderby:{created_at:`desc`},$top:20}),P.find(`sys_notification_receipt`,{$filter:{user_id:T.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!ge.current)return;let i=Array.isArray(e?.data)?e.data:[],o=Array.isArray(t?.data)?t.data:[],s=new Map;for(let e of o){let t=e?.notification_id==null?``:String(e.notification_id);if(!t)continue;let n=s.get(t);(!n||!a.has(n.state)&&a.has(e.state))&&s.set(t,{id:String(e.id),state:String(e.state)})}pe(i.map(e=>{let t=e?.notification_id==null?null:String(e.notification_id),n=t?s.get(t):void 0;return{id:String(e.id),notification_id:t,receipt_id:n?.id??null,type:e.topic??`notification`,title:e.title??``,body:e.body_md??null,action_url:e.action_url??null,is_read:n?a.has(n.state):!1,created_at:e.created_at}})),r=n}catch(e){if(i(e)){he.current=!0;return}r=Math.min(r*2,12e4)}finally{_e.current=!1}}},s=()=>{if(e||he.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await o(),s()},n)},c=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,o().finally(s))};return o().finally(s),typeof document<`u`&&document.addEventListener(`visibilitychange`,c),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,c)}},[P,d,T?.id]),(0,$.useEffect)(()=>{if(!d||!T?.id||Se.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];T.id&&t.push(T.id),T.email&&t.push(T.email);for(let e of T.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!ve.current){ve.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){Se.current=!0;return}if(!r.ok)return;let i=await r.json().catch(()=>null),a=new Set;for(let e of i?.data||[])a.add(e.id);ge.current&&xe(a.size)}catch{}finally{ve.current=!1}}},a=()=>{n||Se.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[d,T?.id]);let Te=G.reduce((e,t)=>e+ +!t.is_read,0),Ee=(0,$.useCallback)(async(e,t)=>{!P||!e.notification_id||(e.receipt_id?await P.update(`sys_notification_receipt`,e.receipt_id,{state:`read`,at:t}):await P.create(`sys_notification_receipt`,{notification_id:e.notification_id,user_id:T?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[P,T?.id]),De=(0,$.useCallback)(async e=>{let t=G.find(t=>t.id===e);if(pe(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await Ee(t,new Date().toISOString())}catch{}},[G,Ee]),Oe=(0,$.useCallback)(async()=>{let e=G.filter(e=>!e.is_read);if(!e.length)return;pe(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>Ee(e,t).catch(()=>{})))},[G,Ee]),K=Ci(),ke=i??(K.length>0?K:is),Ae=a??W??[],je=M||(O??[]).length>0||!!j,[Me,Ne]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return N?.().then(t=>{e||Ne(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[N]);let q=p.pathname.split(`/`).filter(Boolean),Pe=m.appName||q[1],Fe=q[2],Ie=`/apps/${Pe}`,Le=n??[],Re=ua(ie||[],s||V||Pe),ze=new Set,Be=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&ze.add(t.objectName),t.children&&Be(t.children)};Be(Re?.navigation||[]);for(let e of Re?.areas||[])Be(e.navigation||[]);let Ve=ze.size>0?Le.filter(e=>ze.has(e.name)):Le.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),He=Re?._packageId,Ue=He?(ue??[]).filter(e=>e._packageId===He):[],Ge=d?la(Re,F):null,qe=Ve.map(e=>({label:R(e),href:`${Ie}/${e.name}`})),Je=[];if(d){if(Fe===`dashboard`){if(Je.push({label:I(`console.breadcrumb.dashboards`),href:Ie}),q[3]){let e=q[3],t=ma(ae,e,Re?._packageId)?.label||ns(e);Je.push({label:te({name:e,label:t})})}}else if(Fe===`page`){if(Je.push({label:I(`console.breadcrumb.pages`),href:Ie}),q[3]){let e=q[3],t=ma(oe,e,Re?._packageId)?.label||ns(e);Je.push({label:z({name:e,label:t})})}}else if(Fe===`report`){if(Je.push({label:I(`console.breadcrumb.reports`),href:Ie}),q[3]){let e=q[3],t=ma(se,e,Re?._packageId)?.label||ns(e);Je.push({label:ne({name:e,label:t})})}}else if(Fe===`system`)Je.push({label:I(`console.breadcrumb.system`)}),q[3]&&Je.push({label:ns(q[3])});else if(Fe){let e=Le.find(e=>e.name===Fe);if(e){if(Je.push({label:R(e),href:`${Ie}/${Fe}`,siblings:qe}),q[3]===`record`&&q[4]){let e=q[4].length>12?`${q[4].slice(0,8)}…`:q[4],t=ce?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Je.push({label:n||`#${e}`})}else if(q[3]===`view`&&q[4]){let t=q[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||ns(t),i=B(e.name,t,r);Je.push({label:i})}}}}let Xe=Je[Je.length-1]?.label||t||``;return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,Q.jsx)(f,{to:`/home`,className:L(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,d&&`hidden sm:flex`),title:ya(),children:(0,Q.jsx)(We,{className:`h-4 w-4`})}),u===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:ya()}),(0,Q.jsx)(Bo,{}),u===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(rs,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:I(`organizations.title`,{defaultValue:`Organizations`})})]}),d&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ko,{className:`lg:hidden shrink-0 ml-1`,"aria-label":I(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),s&&l?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(rs,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(qo,{activeAppName:s,onAppChange:l})})]}):t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(rs,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Je.map((e,t)=>{let n=t===Je.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(rs,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(En,{children:[(0,Q.jsxs)($e,{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,Q.jsx)(ot,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(_n,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(Et,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Q.jsx)(Gn,{}),e.siblings.map(e=>(0,Q.jsx)(qt,{asChild:!0,children:(0,Q.jsx)(f,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Q.jsx)(f,{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,Q.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)}),H&&H.views.length>0?H.views.length>1?(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.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":I(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Q.jsx)(`span`,{className:`truncate max-w-[180px]`,children:H.triggerLabel??H.views.find(e=>e.id===H.activeViewId)?.label??Xe}),(0,Q.jsx)(ot,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(_n,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:H.views.map(e=>{let t=e.id===H.activeViewId;return(0,Q.jsxs)(qt,{onSelect:()=>{t||H.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,Q.jsx)(rr,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(gt,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:H.triggerLabel??H.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Xe})]})]}),(0,Q.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:[!y&&(0,Q.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,Q.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),I(`topbar.offline`,{defaultValue:`Offline`})]}),d&&r&&(0,Q.jsx)(Wo,{state:r}),d&&ke.length>0&&(0,Q.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:I(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Q.jsx)(Di,{users:ke,size:`sm`,maxVisible:3,showStatus:!0})}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`action:command-palette:open`,"aria-label":I(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:x,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,Q.jsx)(cn,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:I(`console.search`,{defaultValue:`Search…`})}),(0,Q.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,Q.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:x,"aria-label":I(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(cn,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,Q.jsx)(Ko,{notifications:G,unreadCount:Te,pendingApprovalsCount:be,activities:Ae,onMarkAllRead:Oe,onMarkRead:De}),Ge&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"data-testid":`app-design-in-studio-button`,"aria-label":I(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:I(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,Q.jsx)(f,{to:Ge,children:(0,Q.jsx)(Qt,{className:`h-4 w-4`})})}),ee&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":I(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Q.jsx)(f,{to:`/ai`,children:(0,Q.jsx)(dn,{className:`h-4 w-4`})})}),(0,Q.jsxs)(En,{onOpenChange:e=>{e&&de()},children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":I(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Q.jsx)(le,{className:`h-4 w-4`})})}),(0,Q.jsxs)(_n,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Ue.length>0&&He?(0,Q.jsxs)(qt,{className:`cursor-pointer`,onClick:()=>v(Ue.length===1?`/apps/${He}/docs/${Ue[0].name}`:`/apps/${He}/docs`),children:[(0,Q.jsx)(zt,{className:`mr-2 h-4 w-4`}),I(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(qt,{className:`cursor-pointer`,onClick:()=>v(`/docs`),children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),I(`help.allDocs`,{defaultValue:`All documentation`})]}),d?(0,Q.jsxs)(qt,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:C,children:[(0,Q.jsx)(Ht,{className:`mr-2 h-4 w-4`}),I(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,Q.jsx)(Gn,{}),(0,Q.jsx)(qt,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(St,{className:`mr-2 h-4 w-4`}),I(`help.onlineDocs`,{defaultValue:`Online documentation`})]})})]})]})]}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(Ln,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(pn,{src:T?.image,alt:T?.name??`User`}),(0,Q.jsx)(Lt,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:b(T)})]})})}),(0,Q.jsxs)(_n,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(Et,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(Ln,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(pn,{src:T?.image,alt:T?.name??`User`}),(0,Q.jsx)(Lt,{className:`rounded-lg bg-primary text-primary-foreground`,children:b(T)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:T?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:T?.email??``})]})]})}),(0,Q.jsx)(Gn,{}),(0,Q.jsxs)(Zt,{children:[(0,Q.jsxs)(qt,{onClick:()=>v(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(Ye,{className:`mr-2 h-4 w-4`}),I(`user.profile`,{defaultValue:`Profile`})]}),je&&!Me&&(0,Q.jsxs)(qt,{onClick:()=>v(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4`}),I(`organizations.create`,{defaultValue:`Create workspace`})]}),(ie||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=_i(e.icon),n=re({name:e.name,label:fa(e.label,I)});return(0,Q.jsxs)(qt,{onClick:()=>v(`/apps/${da(e)??e.name}`),className:`cursor-pointer`,children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,Q.jsx)(Gn,{}),(0,Q.jsx)(Et,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:I(`user.preferences`,{defaultValue:`Preferences`})}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-foreground/80`,children:I(`user.theme`,{defaultValue:`Theme`})}),(0,Q.jsx)(Fo,{})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-foreground/80`,children:I(`user.language`,{defaultValue:`Language`})}),(0,Q.jsx)(Ho,{})]}),D&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Gn,{}),(0,Q.jsxs)(qt,{className:`text-destructive focus:text-destructive`,onClick:()=>E(),children:[(0,Q.jsx)(Ke,{className:`mr-2 h-4 w-4`}),I(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}function os({children:e}){return Ar(),(0,Q.jsx)(Q.Fragment,{children:e})}function ss({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=fa(n?.label)||t,{enabled:c}=di(),l=va().features.aiStudio===!1&&Zr(n?.defaultAgent)?void 0:n?.defaultAgent,{setContext:u,setCurrentAppName:d}=ki();return(0,$.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Q.jsx)(es,{children:(0,Q.jsx)(Yo,{children:(0,Q.jsxs)(ji,{sidebar:(0,Q.jsx)(Po,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(as,{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?`${fa(n.label)} — ${ya()}`:void 0}:void 0,children:[(0,Q.jsxs)(os,{children:[(0,Q.jsx)(go,{}),(0,Q.jsx)(xo,{}),e]}),c&&(0,Q.jsx)(uo,{appLabel:s,appName:t,defaultAgent:l,objects:i,userId:o})]})})})}function cs({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,Q.jsxs)(`div`,{style:{"--page-header-accent":i||`hsl(var(--primary))`},className:L(`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,Q.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,Q.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,Q.jsx)(`div`,{className:L(`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,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,Q.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,Q.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function ls({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:a,setOpen:s}=ts(),[c,l]=(0,$.useState)(``),u=h(),{appName:d}=o(),{setTheme:f}=Ka(),{evaluator:p}=yr(),{t:m}=A();(0,$.useEffect)(()=>{a||l(``)},[a]);let g=`/apps/${d||da(t)}`,{user:v}=_(),y=(0,$.useMemo)(()=>({currentUserId:v?.id??null}),[v?.id]),b=(0,$.useCallback)(e=>{s(!1),e()},[]),x=us(t?.navigation||[]).filter(e=>vr(e.visible??e.visibleOn,p)),{results:S,isSearching:C}=ee({query:c,objects:n,dataSource:i,objectNames:(0,$.useMemo)(()=>x.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,x.map(e=>e.objectName||``).join(`|`)]),enabled:a&&!!i,getDisplayName:P}),{recentItems:w}=Rr(),T=(0,$.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=a&&c.trim().length===0&&T.length>0;return(0,Q.jsxs)(q,{open:a,onOpenChange:s,title:m(`console.commandPalette.title`,{defaultValue:`Command palette`}),description:m(`console.commandPalette.placeholder`),contentProps:{"data-testid":`overlay:command-palette`},children:[(0,Q.jsx)(ne,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Q.jsxs)(ve,{children:[(0,Q.jsx)(Je,{children:C?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,Q.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,Q.jsx)(ir,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Q.jsxs)(lt,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>u(e.href)),children:[(0,Q.jsx)(cn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),S.length>0&&(0,Q.jsx)(ir,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[m(`console.commandPalette.records`,{defaultValue:`Records`}),C&&(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:S.map(e=>{let t=_i(e.icon);return(0,Q.jsxs)(lt,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>u(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.display}),(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:e.objectLabel})]},`${e.objectName}:${e.recordId}`)})}),x.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(ir,{heading:m(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=_i(e.icon);return(0,Q.jsxs)(lt,{value:`object ${fa(e.label,m)} ${e.objectName}`,onSelect:()=>b(()=>u(Ai(e,g,y).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:fa(e.label,m)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(ir,{heading:m(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(lt,{value:`dashboard ${fa(e.label,m)} ${e.dashboardName}`,onSelect:()=>b(()=>u(Ai(e,g,y).href)),children:[(0,Q.jsx)(wt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:fa(e.label,m)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(ir,{heading:m(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(lt,{value:`page ${fa(e.label,m)} ${e.pageName}`,onSelect:()=>b(()=>u(Ai(e,g,y).href)),children:[(0,Q.jsx)(we,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:fa(e.label,m)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(ir,{heading:m(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(lt,{value:`report ${fa(e.label,m)} ${e.reportName}`,onSelect:()=>b(()=>u(Ai(e,g,y).href)),children:[(0,Q.jsx)(Ge,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:fa(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(it,{}),(0,Q.jsx)(ir,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=_i(e.icon);return(0,Q.jsxs)(lt,{value:`app ${fa(e.label,m)} ${e.name}`,onSelect:()=>b(()=>r(da(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:fa(e.label,m)}),e.name===t?.name&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:m(`console.commandPalette.current`)})]},e.name)})})]}),(0,Q.jsx)(it,{}),(0,Q.jsxs)(ir,{heading:m(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(lt,{value:`theme light`,onSelect:()=>b(()=>f(`light`)),children:[(0,Q.jsx)(bn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(lt,{value:`theme dark`,onSelect:()=>b(()=>f(`dark`)),children:[(0,Q.jsx)(ie,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(lt,{value:`theme system`,onSelect:()=>b(()=>f(`system`)),children:[(0,Q.jsx)(Jn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(it,{}),(0,Q.jsx)(ir,{heading:m(`console.commandPalette.actions`),children:(0,Q.jsxs)(lt,{value:`search all results full page`,onSelect:()=>b(()=>u(`${g}/search`)),children:[(0,Q.jsx)(cn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})})]})]})}function us(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...us(n.children)):t.push(n);return t}function ds(){let{t:e}=A(),{open:t,setOpen:n,toggleOverlay:r}=Tr(`shortcuts`),i=(0,$.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.aiChat`,{defaultValue:`AI assistant`}),shortcuts:[{keys:[`⌘`,`⇧`,`O`],description:e(`console.shortcuts.newChat`,{defaultValue:`New chat`})},{keys:[`⌘`,`⇧`,`S`],description:e(`console.shortcuts.toggleChatsList`,{defaultValue:`Toggle conversations list`})}]},{title:e(`console.shortcuts.groups.preferences`),shortcuts:[{keys:[`⌘`,`D`],description:e(`console.shortcuts.toggleDarkMode`)}]}],[e]);return(0,$.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(),r())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r]),(0,Q.jsx)(ht,{open:t,onOpenChange:n,children:(0,Q.jsxs)(G,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(xt,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(je,{children:e(`console.shortcuts.description`)})]}),(0,Q.jsx)(`div`,{className:`space-y-6 pt-2`,children:i.map(e=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Q.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 fs(){return null}function ps(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?F.console:j.console}function ms({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,$.useState)(0),o=ps(),s=(0,$.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,$.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,s.length-1))},1200);return()=>clearInterval(n)},[e,t,s.length]),(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,Q.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,Q.jsx)(Nn,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,Q.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:ya()}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.initializing})]}),t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,Q.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,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,Q.jsx)(W,{className:`h-5 w-5 shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,Q.jsx)(J,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_e,{className:`h-4 w-4`}),o.actions.retry]})})]}):e?(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,Q.jsx)(te,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 w-64`,children:[s.map((e,t)=>(0,Q.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,Q.jsx)(Re,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Q.jsx)(z,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,Q.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,Q.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e)),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.loadingHint})]})]})})}function hs(e){let{theme:t=`system`}=Ka(),{t:n}=A();return(0,Q.jsx)(or,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,containerAriaLabel:n(`notifications.regionLabel`,{defaultValue:`Notifications`}),icons:{success:(0,Q.jsx)(Re,{className:`h-4 w-4`}),info:(0,Q.jsx)(Mt,{className:`h-4 w-4`}),warning:(0,Q.jsx)(pe,{className:`h-4 w-4`}),error:(0,Q.jsx)(Un,{className:`h-4 w-4`}),loading:(0,Q.jsx)(z,{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 gs=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function _s({children:e,className:t}){let n=c(),r=$.useRef(null),i=$.useRef(n.pathname);return $.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...gs),e.offsetWidth,e.classList.add(...gs))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...gs,t??``].filter(Boolean).join(` `),children:e})}var vs=null,ys=null;function bs(){return ys||(ys=(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 l(()=>import(`./vendor-sentry-BnfuR4xu.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=Ss(e.data.url)),e}}),vs=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),ys)}function xs(e,t){if(vs)try{vs.captureException(e,t?{extra:t}:void 0)}catch{}}function Ss(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 Cs({error:e,onReset:t}){let{t:n}=A();return(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,Q.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,Q.jsx)(pe,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(Te,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(fe,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)(Ne,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)(Bn,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var ws=class extends $.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),xs(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,Q.jsx)(Cs,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},Ts=new Set([`form`,`detail`]);function Es(e){return typeof e==`string`&&Ts.has(e)}function Ds(e,t){let n=e.type||`grid`,r=Es(n)?`form`:`list`,i=e.label,a=e.data&&typeof e.data==`object`?e.data:void 0;return{name:e.id,object:t,viewKind:r,label:i,config:{...e,type:n,label:i,columns:Array.isArray(e.columns)?e.columns:[],data:{...a,object:t}}}}function Os(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function ks(e){let t=e.fields;return!t||typeof t!=`object`?[]:Object.entries(t).map(([e,t])=>{let n=t??{};return{name:e,label:typeof n.label==`string`&&n.label?n.label:e,type:typeof n.type==`string`?n.type:`text`,hidden:n.hidden===!0}})}function As({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=A(),d=(0,$.useRef)(null),f=(0,$.useMemo)(()=>sa(),[]),[p]=(0,$.useState)(()=>`view_${Date.now()}`),m=(0,$.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,$.useMemo)(()=>Ds(n===`create`?m:r,i.name),[n===`create`?`create`:r.id,i.name]),[g,_]=(0,$.useState)(h),[v,y]=(0,$.useState)(!1),[b,x]=(0,$.useState)(0),S=(0,$.useRef)(g),C=(0,$.useRef)(h);C.current!==h&&(C.current=h,S.current=h,_(h),y(!1)),(0,$.useEffect)(()=>{S.current=g},[g]),(0,$.useEffect)(()=>{e&&d.current&&d.current.focus()},[e]);let w=(0,$.useMemo)(()=>ks(i),[i.fields]),T=ui(g.viewKind)?`form`:`list`,E=(0,$.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=Os(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,$.useCallback)(()=>{let e=Os(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),O=(0,$.useCallback)(()=>{if(n===`create`){t();return}_(h),y(!1)},[h,n,t]),k=(0,$.useCallback)(e=>{let t=Ds(e,i.name);S.current=t,_(t),y(!1)},[i.name]),j=u(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,Q.jsxs)(`div`,{ref:d,tabIndex:-1,role:`complementary`,"aria-label":j,"data-testid":`view-config-panel`,className:`flex h-full flex-col`,children:[(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,Q.jsx)(li,{type:`view`,name:g.name,draft:g,variantKey:`config`,familyKey:T,isHome:!0,readOnly:!1,locale:f,objectFieldsOverride:w,onPatch:E})}),(0,Q.jsxs)(`div`,{"data-testid":`view-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5`,children:[n===`edit`&&(0,Q.jsx)(Ia,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(J,{size:`sm`,onClick:D,disabled:n===`edit`&&!v,"data-testid":`view-config-save`,children:u(`console.objectView.save`)})]})]}):(0,Q.jsx)(`div`,{ref:d,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}function js(e){return[{type:`grid`,icon:vt,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:Tn,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Vt,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:It,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:kt,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Xt,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:Ue,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Ge,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)},{type:`tree`,icon:ge,label:e(`console.objectView.viewTypeTree`),description:e(`console.objectView.viewTypeTreeDesc`)}]}function Ms(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Ns={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:ka}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:ja},{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:ja},{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:ja},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Na},{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=>Aa(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&Ca(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&Ca(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:ka},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}],tree:[{key:`parentField`,i18nKey:`console.objectView.parentField`,helpI18nKey:`console.objectView.parentFieldHelp`,filter:e=>e.rawType===`tree`||e.rawType===`lookup`||e.rawType===`master_detail`}]};function Ps({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=A(),s=(0,$.useMemo)(()=>js(o),[o]),c=(0,$.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,$.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,$.useMemo)(()=>a?Da(a):[],[a]),[d,f]=(0,$.useState)(c[0]?.type??`grid`),[p,m]=(0,$.useState)(``),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)({});(0,$.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,$.useEffect)(()=>{h||m(Ms(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Ns[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,$.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(Ns[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,$.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=Ma(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,Q.jsx)(ht,{open:e,onOpenChange:t,children:(0,Q.jsxs)(G,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(xt,{children:o(`console.objectView.createView`)}),(0,Q.jsx)(je,{children:o(`console.objectView.createViewDesc`)})]}),(0,Q.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,Q.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:L(`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,Q.jsx)(r,{className:L(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,Q.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,Q.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,Q.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,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,Q.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Q.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:L(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,Q.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,Q.jsx)(W,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Q.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Q.jsx)(Ft,{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,Q.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Q.jsxs)(On,{className:`mt-2`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Q.jsx)(J,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}function Fs(e,t,n){switch(e){case`system`:return{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`})};case`append-only`:return{icon:`Archive`,title:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`})};case`better-auth`:return n===`sys_user`?{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuthUser.title`,{defaultValue:`No users yet`}),message:t(`list.managedBy.betterAuthUser.message`,{defaultValue:`User accounts are provisioned by the authentication provider, not created here. Invite teammates to your organization and they appear automatically on first sign-in (SSO just-in-time provisioning). App end-users arrive when they sign up through your app.`})}:{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`These records are created by the authentication provider — through sign-in, provisioning, and security flows — not added by hand here.`})};default:return}}function Is(e,t,n){if(!e)return;let r=e=>t.includes(e);if(r(e))return e;let i=`${n}.`;if(!e.includes(`.`)&&r(i+e))return i+e;if(e.startsWith(i)&&r(e.slice(i.length)))return e.slice(i.length)}var Ls=new Set;function Rs(e,t,n,r){let i=[`userFilters`,`quickFilters`].filter(e=>(n?.[e]??r?.[e])!=null);if(i.length===0)return!1;let a=`${e}.${t}`;return Ls.has(a)||(Ls.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0053 "views" mode — the view switcher is the only nav control here). Move them to a page list (InterfaceListPage "filters" mode).`)),!0}var zs=new Set([`archived`,`failed`]);function Bs(e){let t=String(e?.environment_type??``).trim().toLowerCase();return t===`production`||t===`prod`?`production`:t?`development`:e?.is_default===!0||e?.is_default===1?`production`:`development`}function Vs(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=_(),s=o?.id,[c,l]=(0,$.useState)(null);return(0,$.useEffect)(()=>{if(!t){l(null);return}let e=!1,a=async()=>{try{let e=await r(`${(i||``).replace(/\/+$/,``)}/api/v1/cloud/environment-entitlements${s?`?organizationId=${encodeURIComponent(s)}`:``}`,{method:`GET`,credentials:`include`});if(!e.ok)return null;let t=await e.json().catch(()=>null),n=t?.data??t;return!n||typeof n!=`object`?null:{ready:!0,hasProductionEnv:n.hasProductionEnv===!0,canCreateDevelopmentEnv:n.development?.canCreate,plan:n.plan,upgradeUrl:n.upgradeUrl||`/settings/billing`,contactSalesUrl:n.contactSalesUrl,source:`summary`}}catch{return null}},o=async()=>{try{let e={$top:200};s&&(e.$filter={organization_id:s});let t=await n.find(`sys_environment`,e);return{ready:!0,hasProductionEnv:(Array.isArray(t)?t:t?.data??[]).filter(e=>!zs.has(String(e?.status??``))).some(e=>Bs(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:Ha,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:Ha,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var Hs=`create_environment`;function Us({actions:e,entitlements:t,onUpgrade:n}){let r=(e||[]).filter(e=>e?.locations?.includes(`list_toolbar`));if(r.length===0)return null;let i=t?.ready?Ba(t):null;if(i===`upgrade_for_development`){let e=r.filter(e=>e?.name!==Hs);return(0,Q.jsxs)(Q.Fragment,{children:[e.length>0&&(0,Q.jsx)(x,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}}),(0,Q.jsxs)(J,{size:`sm`,onClick:()=>n(za(t)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:`Add environment`})]})]})}return(0,Q.jsx)(x,{schema:{type:`action:bar`,location:`list_toolbar`,actions:r.map(e=>e?.name!==Hs||i==null?e:i===`setup_production`?{...e,label:`Set up your production environment`,variant:`primary`}:{...e,label:`Add development environment`}),size:`sm`,variant:`outline`}})}var Ws=(0,$.lazy)(()=>l(()=>import(`./plugin-charts-CN_USFkK.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),Gs=(0,$.lazy)(()=>l(()=>import(`./plugin-grid-Dk1ZUbuk.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Ks={grid:tn,kanban:Tn,calendar:Vt,gallery:vt,timeline:sn,gantt:ke,map:U,chart:Ge},qs={id:`current-user`,name:`Demo User`};function Js(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 Ys({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=o(),{t:a}=A();return t.find(e=>e.name===i)?(0,Q.jsx)(Xs,{dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}):(0,Q.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Q.jsx)(tn,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(Te,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(fe,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Xs({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=h(),{appName:a,objectName:s,viewId:l}=o(),[u,f]=d(),p=c(),{showDebug:m}=pa(),{t:v}=A(),{objectLabel:b,objectDescription:S,viewLabel:C,viewEmptyState:w,actionLabel:E,actionConfirm:O,actionSuccess:k,actionParamText:j,fieldLabel:M,fieldOptionLabel:N}=Ce(),{isFavorite:P,toggleFavorite:ee}=zr(),F=qi(),[I,L]=(0,$.useState)(!1),[R,te]=(0,$.useState)(`edit`),[z,ne]=(0,$.useState)(!1),[B,re]=(0,$.useState)(!1),[ie,ae]=(0,$.useState)(null),oe=(0,$.useRef)({}),se=(0,$.useRef)({}),V=(0,$.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!s||!t)return;let i=se.current[t]||{};se.current[t]={...i,...r};let a=oe.current[t];a&&clearTimeout(a),oe.current[t]=setTimeout(()=>{let r=se.current[t]||{};delete se.current[t],delete oe.current[t],Promise.resolve(e.updateViewConfig(s,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,s]),ce=(0,$.useCallback)(e=>{ae(e),me(e=>e+1);let t=e.id;F&&t?Fa(`view`,t,e,{metadataClient:F}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[F]),le=(0,$.useCallback)(async e=>{try{let n;if(F){let r=t?.find?.(e=>e.name===s),i=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),a=[],o=r?.highlightFields;Array.isArray(o)&&o.length>0?a=o.filter(e=>r.fields?.[e]):r?.fields&&(a=Object.entries(r.fields).filter(([e,t])=>t&&!t.hidden&&!i.has(e)).map(([e])=>e).slice(0,5));let c=Array.isArray(e.columns)&&e.columns.length>0?e.columns:a,l={...e,columns:c};if(e.type===`kanban`)l.kanban={...l.kanban||{},columns:c};else if(e.type===`gallery`){let e=l.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(l.gallery={...e,visibleFields:c})}n=await La(`view`,String(e?.name??e?.id??l?.id??``),l,{metadataClient:F})}L(!1),te(`edit`),me(e=>e+1),n&&(l?i(`../${n}`,{relative:`path`}):i(`view/${n}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,s,t,i,l,F]),[H,ue]=(0,$.useState)(void 0),{user:U,activeOrganization:de}=_(),W=g(),{can:fe}=y(),G=t.find(e=>e.name===s),[pe,me]=(0,$.useState)(0),he=Va({dataSource:e,objects:t,objectName:G.name,onRefresh:()=>me(e=>e+1)}),{confirmHandler:ge,toastHandler:_e}=he,ve=G.name===`sys_environment`,ye=Vs({enabled:ve,dataSource:e,authFetch:he.authFetch,apiBase:``,refreshKey:pe}),be=(0,$.useMemo)(()=>(G.actions||[]).map(e=>({...e,label:E(G.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:O(G.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:k(G.name,e.name,e.successMessage)}})),[G,E,O,k]),xe=(0,$.useMemo)(()=>Si(G),[G]);(0,$.useEffect)(()=>{r===void 0||r===0||me(e=>e+1)},[r]);let[Se,we]=(0,$.useState)(!1),[Te,Ee]=(0,$.useState)([]);(0,$.useEffect)(()=>{let t=!1;if(!s){Ee([]);return}return typeof e?.listViews==`function`?(e.listViews(s).then(e=>{t||Ee((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||s})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Ee([])}),()=>{t=!0}):(Ee([]),()=>{t=!0})},[e,s,pe]);let[De,Oe]=(0,$.useState)({});(0,$.useEffect)(()=>{let t=!1;if(!e||!s){Oe({});return}let n=G.listViews||G.list_views||{},r=Object.keys(n),i=G.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){Oe({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(s);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(s,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||Oe(e)}),()=>{t=!0}},[e,s,G.listViews,G.list_views,G.list,pe]);let K=(0,$.useMemo)(()=>{let e=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),t=()=>{let t=G.highlightFields;return Array.isArray(t)&&t.length>0?t.filter(e=>G.fields?.[e]):G.fields?Object.entries(G.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[]},n=G.listViews||G.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=De[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=G.list;if(i&&typeof i==`object`){let e=i.name||`list`,t=r.findIndex(t=>t.id===e);if(t>=0){let[e]=r.splice(t,1);r.unshift({...e,isDefault:!0})}else{let t=De[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:v(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of Te){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},i={};for(let[e,t]of Object.entries(n))t!==void 0&&(i[e]=t);if(a.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...i}}else r.push(i)}let o=new Set([`grid`,`list`,`table`]);for(let e of r)o.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let s=new Map(r.map((e,t)=>[e.id,t])),c=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${G.name}`):null;e&&(c=JSON.parse(e))}catch{}let l=new Map(c.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=l.get(e.id),r=l.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=Te.find(t=>(t.id||t._id)===e.id),a=Te.find(e=>(e.id||e._id)===t.id),o=i&&typeof i.sortOrder==`number`,c=a&&typeof a.sortOrder==`number`;return o&&c?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:o?-1:c?1:(s.get(e.id)??0)-(s.get(t.id)??0)}),r},[G,Te,De,v]),ke=(0,$.useMemo)(()=>K.find(e=>e.isDefault)?.id,[K]),Ae=l||u.get(`view`)||void 0,je=(0,$.useMemo)(()=>Is(Ae,K.map(e=>e.id),G.name),[Ae,K,G.name]);(0,$.useEffect)(()=>{Ae&&!je&&console.warn(`[ObjectView] Requested view "${Ae}" not found on object "${G.name}"; falling back to the default view. Known views: ${K.map(e=>e.id).join(`, `)}`)},[Ae,je,G.name,K]);let Me=je||ke||K[0]?.id,Ne=K.find(e=>e.id===Me)||K[0],q=ie&&ie.id===Ne?.id?{...Ne,...ie}:Ne,Pe=(0,$.useCallback)((e,t)=>{ae(n=>({...n||{},id:Ne?.id,[e]:t}))},[Ne?.id]),Fe=e=>{let t=K.find(t=>t.id===e);t&&(t.id!==Me&&L(!1),l?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Ie=(0,$.useMemo)(()=>(K||[]).map(e=>{let t=Ks[e.type];return{id:e.id,label:C(G.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Q.jsx)(t,{className:`h-4 w-4`}):void 0}}),[K,G.name,C]);Qo({views:Ie,activeViewId:Me??``,onChange:Fe,enabled:Ie.length>0&&!!Me});let Le=(0,$.useCallback)(()=>{ne(!0)},[]),Re=(0,$.useCallback)((e,t)=>{if(e===`settings`){let e=K.find(e=>e.type===t);e&&Fe(e.id),te(`edit`),L(!0)}},[K,Fe]),ze=(0,$.useCallback)(e=>Te.some(t=>(t.id||t._id)===e),[Te]),Be=(0,$.useCallback)(async(t,n)=>{if(!ze(t)){X.error(v(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{label:n}),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(v(`objectViewActions.renameFailed`))}},[e,s,ze,v]),Ve=(0,$.useCallback)(async t=>{if(!e)return;if(!ze(t)){X.error(v(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=K.find(e=>e.id===t)?.label||t;if(await ge(v(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:v(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:v(`console.objectView.delete`)||`Delete`,cancelText:v(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(s,t),t===Me){let e=K.find(e=>e.id!==t);e&&i(l?`../${e.id}`:`view/${e.id}`,l?{relative:`path`}:void 0)}me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(v(`objectViewActions.deleteFailed`))}},[e,ze,Me,K,l,i,v,ge]),He=(0,$.useCallback)(async(t,n)=>{if(e){if(!ze(t)){X.error(v(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{isPinned:n}),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,s,ze,v]),Ue=(0,$.useCallback)(async t=>{if(e){if(!ze(t)){X.error(v(`console.objectView.cannotEditMetaView`)||`System view — it cannot be set as a default.`);return}try{if(typeof e?.updateView!=`function`)return;let n=e.updateView,r=Te.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(e=>n(s,e.id||e._id,{isDefault:!1}));r.push(n(s,t,{isDefault:!0})),await Promise.all(r),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,s,Te,ze,v]),We=(0,$.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${s}`,JSON.stringify(t))}catch{}if(typeof e?.updateView==`function`){let n=e.updateView,r=new Set(Te.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((e,t)=>n(s,e,{sortOrder:t}));try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}me(e=>e+1)},[e,Te,s]),Ge=(0,$.useCallback)(e=>{if(!ze(e)){X.error(v(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Me&&Fe(e),te(`edit`),L(!0)},[Me,Fe,ze,v]),Ke=(0,$.useCallback)(()=>{ne(!0)},[]),qe=U?{id:U.id,name:U.name,avatar:U.image}:qs,Je=wr({objectName:G.name,objectLabel:G.label,dataSource:e,onEdit:n,onRefresh:()=>me(e=>e+1),onConfirm:ge,onToast:_e}),{lastMessage:Ye}=Ti({channel:`object:${G.name}`}),{hasConflicts:Xe,resolveAllConflicts:Ze}=Ei(G.name?`user-${G.name}`:`current-user`);(0,$.useEffect)(()=>{Ye&&(Xe&&Ze(`remote`),me(e=>e+1))},[Ye,Xe,Ze]),(0,$.useEffect)(()=>{e?.find&&G.name&&e.find(G.name,{limit:0}).then(e=>{typeof e?.total==`number`?ue(e.total):Array.isArray(e?.data)?ue(e.data.length):Array.isArray(e)&&ue(e.length)}).catch(()=>{})},[e,G.name,pe]);let Qe=(0,$.useMemo)(()=>{let e=q?.navigation??G.navigation;return e?e.mode===`page`?e:{...e,width:e.width??Ea(e.size,G)}:Ta(G)===`page`?{mode:`page`}:{mode:`drawer`,width:Ea(`auto`,G)}},[q?.navigation,G]),$e=u.get(`recordId`),et=Array.from(u.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),tt=(0,$.useMemo)(()=>{let e=[];return new URLSearchParams(et).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[et]),[nt]=(0,$.useState)(()=>xa(new URLSearchParams(window.location.search))),rt=(0,$.useCallback)(e=>{f(t=>ba(t,e),{replace:!0})},[f]),it=(0,$.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:C(G.name,q?.name??``,q?.label??``)||b(G)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,l,p.pathname,p.search,G,q?.name,q?.label,C,b]),at=D({navigation:Qe,objectName:G.name,onNavigate:it}),ot=()=>{at.close();let e=new URLSearchParams(u);e.delete(`recordId`),f(e)},st=(0,$.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){at.handleClick(e,t);return}if(at.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(u);e.set(`recordId`,String(t)),f(e);return}}at.handleClick(e,t)},[at,u,f]),lt=(0,$.useCallback)(()=>{let e=at.selectedRecord,t=e&&(e.id??e._id);t!=null&&(ot(),it(t))},[at.selectedRecord,it]);(0,$.useEffect)(()=>{$e&&!at.isOpen?at.open({id:$e}):!$e&&at.isOpen&&at.close()},[$e]);let ut=(0,$.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=pe+(i||0),o=`${s}-${q.id}-${a}`,c=q;if(c.type===`chart`){let e=c.chart||{};if(e.dataset){let n=Array.isArray(e.dimensions)?e.dimensions:[],r=Array.isArray(e.values)?e.values:[];return(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(Ws,{dataSource:t,schema:{type:`object-chart`,dataset:e.dataset,dimensions:n,values:r,chartType:e.chartType||`bar`,xAxisKey:n[0],series:r.map(e=>({dataKey:e,label:e})),config:e.config,className:`h-[400px] w-full`}})},o)}let n=e.xAxisField||`name`,r=Array.isArray(e.yAxisFields)&&e.yAxisFields[0]||`value`,i=e.aggregation||`count`,a=e.series&&e.series.length>0?e.series:[{dataKey:r,label:r}];return(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(Ws,{dataSource:t,schema:{type:`object-chart`,objectName:G.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},o)}return Rs(G.name,c.id||c.name||``,c,e),(0,Q.jsx)(Sa,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=Js(c.filter??e.filter,qe.id);return tt.length?[...Array.isArray(t)?t:[],...tt]:t})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{V(c.id,c,{densityMode:e})},onSortChange:e=>{V(c.id,c,{sort:e})},onFilterChange:e=>{V(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{V(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{V(c.id,c,{columnState:e})},inlineEdit:c.inlineEdit??c.editRecordsInline??e.inlineEdit,appearance:c.appearance?c.showDescription==null?c.appearance:{...c.appearance,showDescription:c.showDescription}:c.showDescription==null?e.appearance:{showDescription:c.showDescription},showViewSwitcher:((c.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,showSearch:c.showSearch??e.showSearch,showSort:c.showSort??e.showSort,showFilters:c.showFilters??e.showFilters,showHideFields:c.showHideFields??e.showHideFields,showGroup:c.showGroup??e.showGroup,showColor:c.showColor??e.showColor,showDensity:c.showDensity??e.showDensity,allowExport:c.allowExport??e.allowExport,exportOptions:c.allowExport===!1?void 0:c.exportOptions??e.exportOptions,striped:c.striped??e.striped,bordered:c.bordered??e.bordered,color:c.color??e.color,wrapHeaders:c.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:c.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:c.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:c.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:c.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:c.fieldTextColor??e.fieldTextColor,prefixField:c.prefixField??e.prefixField,showDescription:c.showDescription??e.showDescription,navigation:c.navigation??e.navigation,selection:c.selection??e.selection,pagination:c.pagination??e.pagination,searchableFields:c.searchableFields??e.searchableFields,filterableFields:c.filterableFields??e.filterableFields,resizable:c.resizable??e.resizable,rowActions:c.rowActions??e.rowActions,rowActionDefs:Array.isArray(G?.actions)?G.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:E(G.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:O(G.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:k(G.name,e.name,e.successMessage)}})):[],bulkActions:c.bulkActions??e.bulkActions,bulkActionDefs:c.bulkActionDefs??e.bulkActionDefs,sharing:c.sharing??e.sharing,addRecord:c.addRecord??e.addRecord,conditionalFormatting:c.conditionalFormatting??e.conditionalFormatting,quickFilters:void 0,userFilters:void 0,showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,virtualScroll:c.virtualScroll??e.virtualScroll,emptyState:w(G.name,c.name||c.id||``,c.emptyState??e.emptyState??Fs(G?.managedBy,v,G.name)),aria:c.aria??e.aria,...(()=>{let e=Js([...Array.isArray(c.filter)?c.filter:[],...tt],qe.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...c.sort?.length?{sort:c.sort}:{},options:{kanban:{groupBy:c.kanban?.groupByField||c.kanban?.groupField||`status`,groupField:c.kanban?.groupByField||c.kanban?.groupField||`status`,titleField:c.kanban?.titleField||G.titleField||`name`,cardFields:c.kanban?.columns},calendar:{startDateField:c.calendar?.startDateField||`due_date`,endDateField:c.calendar?.endDateField,titleField:c.calendar?.titleField||`name`,colorField:c.calendar?.colorField,allDayField:c.calendar?.allDayField,defaultView:c.calendar?.defaultView},timeline:{dateField:c.timeline?.dateField||`due_date`,titleField:c.timeline?.titleField||G.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||G.titleField||`name`,latitudeField:c.map?.latitudeField,longitudeField:c.map?.longitudeField,zoom:c.map?.zoom,center:c.map?.center},gallery:{...c.gallery||{},imageField:c.gallery?.imageField||c.gallery?.coverField||`image`,coverField:c.gallery?.coverField||c.gallery?.imageField,titleField:c.gallery?.titleField||G.titleField||`name`,subtitleField:c.gallery?.subtitleField},gantt:{...c.gantt||{},startDateField:c.gantt?.startDateField||`start_date`,endDateField:c.gantt?.endDateField||`end_date`,titleField:c.gantt?.titleField||`name`},tree:{...c.tree||{},labelField:c.tree?.labelField||c.tree?.titleField||G.titleField||`name`},chart:{chartType:c.chart?.chartType,xAxisField:c.chart?.xAxisField,yAxisFields:c.chart?.yAxisFields,aggregation:c.chart?.aggregation,series:c.chart?.series,config:c.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&Je.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Je.execute({type:`delete`,confirmText:v(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{st(e,t)},onSortChange:e=>{V(c.id,c,{sort:e})},onFilterChange:e=>{V(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{V(c.id,c,{hiddenFields:e})},onInlineEditChange:e=>{V(c.id,c,{inlineEdit:e})},onColumnStateChange:e=>{V(c.id,c,{columnState:e})},userFilterSelections:nt,onUserFilterSelectionsChange:rt,dataSource:t},o)},[q,G,s,pe,at,Je,V,tt,nt,rt]),ft=(0,$.useMemo)(()=>K.map(e=>e.id===Me&&ie&&ie.id===e.id?{...e,...ie}:e),[K,Me,ie]),pt=(0,$.useMemo)(()=>({type:`object-view`,objectName:G.name,layout:`page`,showSearch:q?.showSearch!==!1,showFilters:q?.showFilters!==!1,showSort:q?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:W,viewActions:W?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:p.pathname+(p.search||``),label:C(G.name,q?.name??``,q?.label??``)||b(G)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[G,n,q?.showSearch,q?.showFilters,q?.showSort,q?.name,q?.label,i,l,W,p.pathname,p.search,C,b]);return(0,Q.jsxs)(T,{...he.actionProviderProps,children:[(0,Q.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(cs,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:b(G)}),(0,Q.jsx)(Ra,{managedBy:G?.managedBy})]}),description:G.description?S(G):void 0,icon:(0,Q.jsx)(_i(G?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[s&&(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>ee({id:`object:${s}`,label:b(G),href:`/apps/${a}/${s}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":P(`object:${s}`),"aria-label":P(`object:${s}`)?v(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):v(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${s}`,children:P(`object:${s}`)?(0,Q.jsx)(fn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(zn,{className:`h-4 w-4`})}),xe.create&&fe(G.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,onClick:Je.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:v(`console.objectView.new`)})]}),xe.import&&fe(G.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>we(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:v(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Q.jsx)(dt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:v(`console.objectView.import`)})]}),G.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(ve?(0,Q.jsx)(Us,{actions:be,entitlements:ye,onUpgrade:he.openEntitlementDialog}):(0,Q.jsx)(x,{schema:{type:`action:bar`,location:`list_toolbar`,actions:be,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),xe.create&&fe(G.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:Je.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":v(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Q.jsx)(Y,{className:`h-5 w-5`})}),Se&&(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(Gs,{open:Se,onOpenChange:we,objectName:G.name,objectLabel:b(G),fields:Object.entries(G.fields||{}).filter(([,e])=>![`formula`,`summary`,`autonumber`].includes(e?.type)&&!e?.readonly&&e?.permissions?.write!==!1).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required,...t?.options?{options:t.options}:{}})),dataSource:e,onComplete:e=>{me(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(v(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(v(`console.objectView.importedToast`,{count:t}))}})}),K.length>=1&&(()=>{let e=K.map(e=>{let t=Te.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:C(G.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?v(`console.objectView.systemViewReadonly`)||`System view defined in code — read-only.`:void 0}});return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,Q.jsx)(Oa,{views:e,activeViewId:Me,onViewChange:Fe,viewTypeIcons:Ks,config:{reorderable:!1,showAddButton:W,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:W?Ke:void 0,onRenameView:W?Be:void 0,onDeleteView:W?Ve:void 0,onPinView:W?He:void 0,onSetDefaultView:W?Ue:void 0,onConfigView:W?Ge:void 0,onManageViews:W?()=>re(!0):void 0}),W&&(0,Q.jsx)(wa,{open:B,onOpenChange:re,views:e,activeViewId:Me,viewTypeIcons:Ks,onRename:Be,onDelete:Ve,onSetDefault:Ue,onSetPinned:He,onReorder:We,onAddView:Ke,onConfigView:Ge})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[at.mode===`split`&&at.isOpen?(0,Q.jsx)(ct,{...at,setIsOpen:e=>{e||ot()},title:b(G),onExpand:lt,expandLabel:v(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${G.name}`,mainContent:(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(Pa,{schema:pt,dataSource:e,views:ft,activeViewId:Me,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{st(e,t)},renderListView:ut,onCreateView:Le,hideNamedViewTabs:!0,onViewAction:Re})})}),typeof H==`number`&&(0,Q.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:v(`console.objectView.recordCount`,{count:H})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Oi,{dataSource:e,objects:t,onEdit:n,objectNameOverride:G.name,recordIdOverride:i,embedded:!0})}}):(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(Pa,{schema:pt,dataSource:e,views:ft,activeViewId:Me,onViewChange:Fe,onEdit:e=>n?.(e),onRowClick:(e,t)=>{st(e,t)},renderListView:ut,onCreateView:Le,hideNamedViewTabs:!0,onViewAction:Re})})})}),(0,Q.jsx)(ha,{open:m&&W,sections:[{title:`View Configuration`,data:q},{title:`Object Definition`,data:G}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${I&&W?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(As,{open:I&&W,onClose:()=>{L(!1),te(`edit`)},mode:R,activeView:q,objectDef:G,recordCount:H,onSave:ce,onViewUpdate:Pe,onCreate:le,metadataClient:F,onAfterChange:()=>me(e=>e+1)})}),(0,Q.jsx)(Ps,{open:z&&W,onOpenChange:ne,existingLabels:K.map(e=>e.label).filter(Boolean),objectDef:G,onCreate:e=>le(e)})]}),at.mode!==`split`&&(0,Q.jsx)(ct,{...at,setIsOpen:e=>{e||ot()},title:b(G),onExpand:lt,expandLabel:v(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${G.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Oi,{dataSource:e,objects:t,onEdit:n,objectNameOverride:G.name,recordIdOverride:i,embedded:!0})}})]}),he.dialogs]})}function Zs({appName:e,error:t,onRetry:n}){let{t:r}=A(),i=!!t;return(0,Q.jsx)(`div`,{className:`flex h-screen items-center justify-center`,"data-testid":`preview-draft-empty-state`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(pe,{className:`h-8 w-8`}):(0,Q.jsx)(kn,{className:`h-8 w-8`})}),(0,Q.jsx)(Te,{children:i?r(`preview.empty.loadFailedTitle`,{defaultValue:`Draft preview failed to load`}):e?r(`preview.empty.notReadyTitle`,{app:e,defaultValue:`“{{app}}” isn’t in the draft yet`}):r(`preview.empty.nothingTitle`,{defaultValue:`Nothing to preview yet`})}),(0,Q.jsx)(fe,{children:i?r(`preview.empty.loadFailedDescription`,{defaultValue:`The draft overlay could not be read. Retry, or check your connection.`}):r(`preview.empty.notReadyDescription`,{defaultValue:`The build may still be running, or it may have failed before this app was staged. Check the conversation for the build status — this pane refreshes as drafts land.`})}),(0,Q.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,Q.jsxs)(J,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(_e,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var Qs=(0,$.lazy)(()=>l(()=>import(`./RecordDetailView-BXq0yKAC.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),$s=(0,$.lazy)(()=>l(()=>import(`./DashboardView-DwORDYTI.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),ec=(0,$.lazy)(()=>l(()=>import(`./PageView-BfC2HLWA.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),tc=(0,$.lazy)(()=>l(()=>import(`./ReportView-C44qsTBA.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),nc=(0,$.lazy)(()=>l(()=>import(`./SearchResultsPage-CcZIaPuL.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),rc=(0,$.lazy)(()=>l(()=>import(`./RecordFormPage-BqNRd1-N.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),ic=(0,$.lazy)(()=>l(()=>import(`./ComponentNavView-BNkTx_gd.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),ac=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),oc=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),sc=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),cc=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),lc=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),uc=(0,$.lazy)(()=>l(()=>import(`./metadata-admin-B0y5-vc3.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),dc=(0,$.lazy)(()=>l(()=>import(`./index-gh_wl34E.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0,2]),import.meta.url)),fc=(0,$.lazy)(()=>l(()=>import(`./index-gh_wl34E.js`).then(e=>e.t).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0,2]),import.meta.url)),pc=(0,$.lazy)(()=>l(()=>import(`./index-gh_wl34E.js`).then(e=>e.t).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0,2]),import.meta.url)),mc=(0,$.lazy)(()=>l(()=>import(`./MarketplacePage-DIFzpvbl.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),hc=(0,$.lazy)(()=>l(()=>import(`./MarketplacePackagePage-DHsi6uiN.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),gc=(0,$.lazy)(()=>l(()=>import(`./MarketplaceInstalledPage-CK-HsgOu.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function _c({appName:e}){let{reviewSeq:t,reviewTarget:n}=_r(),r=h(),i=(0,$.useRef)(t);return(0,$.useEffect)(()=>{if(t===i.current||!n||!e)return;i.current=t;let{type:a,name:o}=n;r(`/apps/${e}/metadata/${encodeURIComponent(a)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,r]),null}function vc({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,a]=(0,$.useState)(`disconnected`),{user:s,getAuthConfig:l}=_(),u=S(),[d,f]=(0,$.useState)({});(0,$.useEffect)(()=>{let e=!1;return l().then(t=>{e||f(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[l]);let m=h(),g=c(),{appName:v}=o(),{apps:y,objects:b,loading:x,ensureType:T,error:E,refresh:D}=w(),k=dr(),{t:j}=A(),{objectLabel:M}=Ce(),[P,ee]=(0,$.useState)(!T);(0,$.useEffect)(()=>{if(!T){ee(!0);return}let e=!1;return Promise.all([T(`object`),T(`dashboard`),T(`report`),T(`page`)]).finally(()=>{e||ee(!0)}),()=>{e=!0}},[T]);let F=y.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),I=g.pathname.endsWith(`/create-app`),L=g.pathname.includes(`/system`),R=g.pathname.includes(`/metadata`),te=g.pathname===`/apps/setup`||g.pathname.startsWith(`/apps/setup/`),z=I||L||R||te,ne=ua(y,v),B=ne||(!v||z?F.find(e=>e.isDefault===!0)||F[0]:void 0),re=!!v&&!ne&&!z,[ie,ae]=(0,$.useState)(`idle`);(0,$.useEffect)(()=>{if(!re){ie!==`idle`&&ae(`idle`);return}ie===`idle`&&!x&&!k&&(ae(`checking`),Promise.resolve(D()).finally(()=>ae(`done`)))},[re,x,k,ie,D]),(0,$.useEffect)(()=>{if(!B?.name)return;let e=v??B.name,t=`/apps/${e}/metadata/package`;(g.pathname===t||g.pathname.startsWith(`${t}/`))&&m(`/apps/${e}/component/developer/packages`,{replace:!0})},[B?.name,v,g.pathname,m]);let[oe,se]=(0,$.useState)(!1),[V,ce]=(0,$.useState)(null),[le,H]=(0,$.useState)(0),{execute:ue,runner:U}=O();N({dataSource:u??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),H(e=>e+1)},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),H(e=>e+1)}}),(0,$.useEffect)(()=>{U.registerHandler(`crud_success`,async e=>(se(!1),H(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),U.registerHandler(`dialog_cancel`,async()=>(se(!1),{success:!0})),U.registerHandler(`navigate_create`,async e=>{let t=Hr({action:e,context:U.getContext?.()??{},defaultBaseUrl:`/apps/${v??``}`});return t.success?(m(t.url),{success:!0}):t}),U.registerHandler(`navigate_edit`,async e=>{let t=Ur({action:e,context:U.getContext?.()??{},defaultBaseUrl:`/apps/${v??``}`});return t.success?(m(t.url),{success:!0}):t})},[U,m,v]),(0,$.useEffect)(()=>{if(!u)return;let e=u.onConnectionStateChange(e=>{a(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return a(u.getConnectionState()),e},[u]);let de=g.pathname.split(`/`).filter(Boolean)[2];(de===`view`||de===`record`||de===`page`||de===`dashboard`||de===`design`)&&(de=``);let W=b.find(e=>e.name===de),G=(0,$.useCallback)(()=>{let e=W?M(W):j(`common.record`,{defaultValue:`Record`});ue({type:`crud_success`,params:{message:V?j(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):j(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[ue,V,W,M,j]),pe=(0,$.useCallback)(()=>{ue({type:`dialog_cancel`})},[ue]);Nr({pathname:g.pathname,appName:B?.name,objects:b});let me=e=>{let t=Vr({objectDef:W,baseUrl:v?`/apps/${v}`:B?.name?`/apps/${B.name}`:``,record:e});if(t.kind===`page`){m(t.url);return}ce(e),se(!0)},he=e=>{m(`/apps/${e}`)},ge=(0,$.useMemo)(()=>new C({user:s?{name:s.name,email:s.email,role:s.role??`user`}:{},app:B||{},data:V||{}}),[s,B,V]);return!u||x||!P?(0,Q.jsx)(ms,{}):k&&(re||!B)?(0,Q.jsx)(Zs,{appName:v,error:E,onRetry:()=>void D()}):re?ie===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:j(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(fe,{children:j(`empty.appNotAvailableDescription`,{defaultValue:`This app is not available yet — it may still be publishing. Try again in a moment.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{onClick:()=>ae(`idle`),"data-testid":`app-not-available-retry`,children:j(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(ms,{}):!B&&!I&&!L&&!R?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:j(`empty.noAppsConfigured`)}),(0,Q.jsx)(fe,{children:j(`empty.noAppsConfiguredDescription`)}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Q.jsx)(J,{onClick:()=>m(`/create-app`),"data-testid":`create-first-app-btn`,children:j(`empty.createFirstApp`)}),(0,Q.jsx)(J,{variant:`outline`,onClick:()=>m(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:j(`empty.systemSettings`)})]})]})}):!B&&(I||L||R)?(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(ms,{}),children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(p,{path:`create-app`,element:(0,Q.jsx)(dc,{})}),(0,Q.jsx)(p,{path:`system/marketplace`,element:(0,Q.jsx)(mc,{})}),(0,Q.jsx)(p,{path:`system/marketplace/installed`,element:(0,Q.jsx)(gc,{})}),(0,Q.jsx)(p,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(hc,{})}),(0,Q.jsx)(p,{path:`metadata`,element:(0,Q.jsx)(ac,{})}),(0,Q.jsx)(p,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(uc,{})}),(0,Q.jsx)(p,{path:`metadata/:type`,element:(0,Q.jsx)(sc,{})}),(0,Q.jsx)(p,{path:`metadata/:type/new`,element:(0,Q.jsx)(cc,{createMode:!0})}),(0,Q.jsx)(p,{path:`metadata/:type/:name`,element:(0,Q.jsx)(cc,{})}),(0,Q.jsx)(p,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(lc,{})}),t]})}):(0,Q.jsxs)(br,{user:s?{id:s.id,name:s.name,email:s.email,role:s.role??`user`,roles:s.roles,isPlatformAdmin:s.isPlatformAdmin??!1}:{name:`Anonymous`,email:``,role:`guest`,isPlatformAdmin:!1},app:B,data:{},features:d,children:[(0,Q.jsx)(Cr,{}),(0,Q.jsxs)(ss,{activeAppName:B.name,activeApp:B,onAppChange:he,objects:b,connectionState:n,userId:s?.id,children:[(0,Q.jsx)(ls,{apps:y,activeApp:B,objects:b,onAppChange:he,dataSource:u}),(0,Q.jsx)(ds,{}),(0,Q.jsx)(fs,{}),(0,Q.jsx)(_c,{appName:v}),(0,Q.jsx)(ws,{children:(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(ms,{}),children:(0,Q.jsx)(_s,{className:`h-full`,children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(p,{path:`/`,element:(()=>{let e=Sc(B,{currentUserId:s?.id??null});return e?(0,Q.jsx)(r,{to:e,replace:!0}):(0,Q.jsx)(oc,{})})()}),(0,Q.jsx)(p,{path:`metadata/package/*`,element:(0,Q.jsx)(r,{to:`/apps/${v??B.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(p,{path:`metadata`,children:[(0,Q.jsx)(p,{index:!0,element:(0,Q.jsx)(ac,{})}),(0,Q.jsx)(p,{path:`_diagnostics`,element:(0,Q.jsx)(uc,{})}),(0,Q.jsx)(p,{path:`:type`,element:(0,Q.jsx)(sc,{})}),(0,Q.jsx)(p,{path:`:type/new`,element:(0,Q.jsx)(cc,{createMode:!0})}),(0,Q.jsx)(p,{path:`:type/:name`,element:(0,Q.jsx)(cc,{})}),(0,Q.jsx)(p,{path:`:type/:name/history`,element:(0,Q.jsx)(lc,{})})]}),(0,Q.jsx)(p,{path:`:objectName`,element:(0,Q.jsx)(Ys,{dataSource:u,objects:b,onEdit:me,externalRefreshKey:le})}),(0,Q.jsx)(p,{path:`:objectName/new`,element:(0,Q.jsx)(rc,{mode:`create`})}),(0,Q.jsx)(p,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(Ys,{dataSource:u,objects:b,onEdit:me,externalRefreshKey:le})}),(0,Q.jsx)(p,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(Qs,{dataSource:u,objects:b,onEdit:me},le)}),(0,Q.jsx)(p,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(rc,{mode:`edit`})}),(0,Q.jsx)(p,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)($s,{dataSource:u})}),(0,Q.jsx)(p,{path:`report/:reportName`,element:(0,Q.jsx)(tc,{dataSource:u})}),(0,Q.jsx)(p,{path:`page/:pageName`,element:(0,Q.jsx)(ec,{})}),(0,Q.jsx)(p,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(ic,{})}),(0,Q.jsx)(p,{path:`component/metadata/directory`,element:(0,Q.jsx)(Tc,{mode:`directory`})}),(0,Q.jsx)(p,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(Tc,{mode:`resource`})}),(0,Q.jsx)(p,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(pc,{})}),(0,Q.jsx)(p,{path:`search`,element:(0,Q.jsx)(nc,{})}),(0,Q.jsx)(p,{path:`create-app`,element:(0,Q.jsx)(dc,{})}),(0,Q.jsx)(p,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(fc,{})}),(0,Q.jsx)(p,{path:`system/marketplace`,element:(0,Q.jsx)(mc,{})}),(0,Q.jsx)(p,{path:`system/marketplace/installed`,element:(0,Q.jsx)(gc,{})}),(0,Q.jsx)(p,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(hc,{})}),e,(0,Q.jsx)(p,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(Ec,{})}),(0,Q.jsx)(p,{path:`*`,element:(0,Q.jsx)(Dc,{})})]})})})}),W&&(0,Q.jsx)(lr,{schema:{type:`object-form`,formType:`modal`,objectName:W.name,mode:V?`edit`:`create`,recordId:V?.id,...Wr(W),title:j(V?`form.editTitle`:`form.createTitle`,{object:M(W)}),description:j(V?`form.editDescription`:`form.createDescription`,{object:M(W)}),open:oe,onOpenChange:se,layout:`vertical`,fields:W.fields?Array.isArray(W.fields)?W.fields.filter(e=>typeof e==`string`?!0:vr(e.visible,ge)).map(e=>typeof e==`string`?e:e.name):Object.entries(W.fields).filter(([e,t])=>vr(t.visible,ge)).map(([e])=>e):[],onSuccess:G,onCancel:pe,showSubmit:!0,showCancel:!0,submitText:V?j(`form.update`,{defaultValue:j(`common.save`,{defaultValue:`Save`})}):j(`form.create`,{defaultValue:j(`common.create`,{defaultValue:`Create`})}),cancelText:j(`common.cancel`)},dataSource:u},V?.id||`new`)]})]})}function yc(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=bc(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=yc(n.children,t);if(e!==``)return e}}return``}function bc(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Ai(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function xc(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=xc(n.children,t);if(e)return e}}}function Sc(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=bc(xc(r,n),t);if(e)return e}return yc(r,t)}var Cc=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function wc(e){return!e||Cc.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function Tc({mode:e}){let t=c(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Q.jsx)(r,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let i=new URLSearchParams(t.search).get(`type`)??``,a=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,Q.jsx)(r,{to:i?`${n}/metadata/${encodeURIComponent(i)}${a}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function Ec(){let{objectName:e,maybeRecordId:t}=o(),n=c();return e&&wc(t)?(0,Q.jsx)(r,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Q.jsx)(Dc,{})}function Dc(){let e=h(),{t}=A();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(fe,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Oc({children:e,userId:t}){let{setContext:n}=ki(),{t:r}=A(),{enabled:i}=di();return(0,$.useEffect)(()=>{n(`home`)},[n]),(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,Q.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,Q.jsx)(as,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,Q.jsx)(uo,{appLabel:r(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var kc=19,Ac=[`from-blue-500 to-indigo-600`,`from-violet-500 to-purple-600`,`from-pink-500 to-rose-600`,`from-amber-400 to-orange-500`,`from-emerald-500 to-teal-600`,`from-sky-500 to-cyan-600`,`from-fuchsia-500 to-pink-600`,`from-orange-500 to-red-600`,`from-indigo-500 to-blue-600`,`from-teal-500 to-green-600`],jc=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function Mc(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function Nc({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i}){let{t:a}=A(),{appLabel:o}=Ce(),[s,c]=(0,$.useState)(!1),l=(0,$.useMemo)(()=>new Set(t.filter(e=>e.id.startsWith(`app:`)).map(e=>e.id.slice(4))),[t]),u=(0,$.useMemo)(()=>[...e].sort((e,t)=>!!l.has(t.name)-+!!l.has(e.name)),[e,l]),d=u.length-kc,f=s?u:u.slice(0,kc);return(0,Q.jsxs)(`section`,{className:`mb-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-xl border border-border bg-muted text-muted-foreground`,children:(0,Q.jsx)(vt,{className:`h-4 w-4`})}),(0,Q.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:a(`home.yourApps`,{defaultValue:`Your apps`})}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:u.length}),i&&(0,Q.jsxs)(J,{variant:`ghost`,size:`sm`,className:`ml-auto h-8 text-muted-foreground`,onClick:r,"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(Fn,{className:`mr-1.5 h-4 w-4`}),a(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-4 gap-1 sm:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10`,children:[f.map(e=>{let t=_i(e.icon),r=o({name:e.name,label:fa(e.label,a)}),i=l.has(e.name),s=Ac[Mc(e.name)%Ac.length];return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`group relative flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`app-tile-${e.name}`,children:[(0,Q.jsxs)(`span`,{className:L(`relative inline-flex h-12 w-12 items-center justify-center rounded-[13px]`,`bg-gradient-to-br text-white transition-transform group-hover:scale-105`,jc,s),children:[(0,Q.jsx)(t,{className:`h-6 w-6`}),i&&(0,Q.jsx)(`span`,{className:`absolute -right-1 -top-1 inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 ring-2 ring-background`,children:(0,Q.jsx)(fn,{className:`h-2.5 w-2.5 fill-white text-white`})})]}),(0,Q.jsx)(`span`,{className:`w-full truncate text-xs font-medium`,children:r})]},e.name)}),!s&&d>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`group flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`apps-show-all`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex h-12 w-12 items-center justify-center rounded-[13px] border border-dashed border-border text-sm font-medium text-muted-foreground transition-colors group-hover:border-foreground/30 group-hover:text-foreground`,children:[`+`,d]}),(0,Q.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:a(`home.showMoreApps`,{defaultValue:`More`})})]})]}),s&&d>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`mt-2.5 text-xs text-primary hover:underline`,children:a(`home.showLess`,{defaultValue:`Show less`})})]})}function Pc(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 Fc({icon:e,title:t,count:n,accent:r,children:i}){return(0,Q.jsxs)(`section`,{className:`rounded-2xl bg-card/80 backdrop-blur-sm p-4 `+(r?`border border-primary/30`:`border border-border/70`),children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsx)(e,{className:`h-4 w-4 `+(r?`text-primary`:`text-muted-foreground`)}),(0,Q.jsx)(`h2`,{className:`flex-1 text-sm font-semibold tracking-tight`,children:t}),typeof n==`number`&&n>0&&(0,Q.jsx)(`span`,{className:`inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-medium text-primary-foreground tabular-nums`,children:n})]}),i]})}function Ic({icon:e,iconClass:t,label:n,meta:r,trailing:i,onClick:a,testId:o}){return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:a,"data-testid":o,className:`flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition hover:bg-muted/60 active:scale-[0.99]`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg `+t,children:(0,Q.jsx)(e,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:n}),r&&(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:r}),i]})})}function Lc({pendingApprovalsCount:e,notifications:t,onOpenApprovals:n,onOpenNotification:r,t:i}){let a=e+t.length;return(0,Q.jsx)(Fc,{icon:gn,accent:!0,count:a,title:i(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:a===0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(me,{className:`h-4 w-4 text-emerald-500`}),i(`home.actionCenter.empty`,{defaultValue:`You're all caught up`})]}):(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[e>0&&(0,Q.jsx)(Ic,{icon:gn,iconClass:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:i(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:e}),trailing:(0,Q.jsx)(Qe,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:n,testId:`home-action-approvals`}),t.map(e=>(0,Q.jsx)(Ic,{icon:wn,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:Pc(e.createdAt),onClick:()=>r(e)},e.id))]})})}var Rc={object:Nn,record:we,dashboard:wt,page:Be},zc={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`};function Bc({items:e,onOpen:t,t:n}){return(0,Q.jsx)(Fc,{icon:kt,title:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`}),children:e.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`home.continueEmpty`,{defaultValue:`Items you open will show up here.`})}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.map(e=>(0,Q.jsx)(Ic,{icon:Rc[e.type]||we,iconClass:zc[e.type]||`bg-muted text-muted-foreground`,label:e.label,meta:n(`home.recentApps.itemType.${e.type}`,{defaultValue:e.type}),onClick:()=>t(e.href)},e.id))})})}function Vc({items:e,onViewAll:t,t:n}){return(0,Q.jsxs)(Fc,{icon:sn,title:n(`sidebar.activityFeed`,{defaultValue:`Activity`}),children:[e.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:e.slice(0,5).map(e=>(0,Q.jsxs)(`li`,{className:`text-sm leading-snug`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description}),(0,Q.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Pc(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:`mt-3 inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[n(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`}),(0,Q.jsx)(Qe,{className:`h-3 w-3`})]})]})}function Hc(e=5){let t=S(),{user:n}=_(),[r,i]=(0,$.useState)(0),[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)([]),l=(0,$.useRef)(!0);return(0,$.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]),(0,$.useEffect)(()=>{if(!t)return;let n=!1;return Promise.resolve(t.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20})).then(t=>{n||!l.current||c((Array.isArray(t?.data)?t.data:[]).filter(e=>{if(!e||typeof e.type!=`string`||!(e.summary??``).toString().trim())return!1;let t=String(e.actor_name??``).trim();return t.length>0&&t.toLowerCase()!==`system`}).map(e=>{let t=e.timestamp;(!t||t===`NOW()`||Number.isNaN(Date.parse(t)))&&(t=e.created_at);let n=String(e.type),r=n===`commented`||n===`mentioned`?`comment`:n===`deleted`?`delete`:n===`created`?`create`:`update`;return{id:String(e.id),type:r,objectName:e.object_name??``,recordId:e.record_id??void 0,user:e.actor_name??`System`,description:e.summary??``,timestamp:t??``}}).slice(0,e))}).catch(()=>{}),()=>{n=!0}},[t,e]),(0,$.useEffect)(()=>{if(!t||!n?.id)return;let r=!1;return Promise.resolve(t.find(`sys_inbox_message`,{$filter:{user_id:n.id},$orderby:{created_at:`desc`},$top:e})).then(e=>{if(r||!l.current)return;let t=Array.isArray(e?.data)?e.data:[],n=new Set;o(t.filter(e=>e&&(e.title??``).toString().trim()).map(e=>({id:String(e.id),title:String(e.title),actionUrl:e.action_url??void 0,createdAt:e.created_at??void 0})).filter(e=>n.has(e.title)?!1:(n.add(e.title),!0)))}).catch(()=>{}),()=>{r=!0}},[t,n?.id,e]),(0,$.useEffect)(()=>{if(!n?.id)return;let e=``.replace(/\/$/,``),t=[];n.id&&t.push(n.id),n.email&&t.push(n.email);for(let e of n.roles||[])e&&t.push(`role:${e}`);if(t.length===0)return;let r=!1,a=new URLSearchParams({status:`pending`,approverId:t.join(`,`)});return fetch(`${e}/api/v1/approvals/requests?${a}`,{credentials:`include`}).then(async e=>{if(!e.ok)return;let t=await e.json().catch(()=>null),n=new Set;for(let e of t?.data||[])n.add(e.id);!r&&l.current&&i(n.size)}).catch(()=>{}),()=>{r=!0}},[n?.id]),{pendingApprovalsCount:r,notifications:a,activities:s}}function Uc(){let{agents:e}=Xr({apiBase:(0,$.useMemo)(()=>mi(),[])});return{aiEnabled:e.length>0,askAvailable:e.some(e=>Qr(e.name)),buildAvailable:e.some(e=>Zr(e.name))}}function Wc({askAvailable:e,buildAvailable:t,navigate:n,t:r,layout:i=`row`}){return!e&&!t?null:(0,Q.jsxs)(`div`,{className:i===`stack`?`mt-6 flex flex-col sm:flex-row items-center gap-3`:`flex shrink-0 items-center gap-2`,children:[t&&(0,Q.jsxs)(J,{onClick:()=>n(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(Kt,{className:`mr-2 h-4 w-4`}),r(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&(0,Q.jsxs)(J,{variant:t?`outline`:`default`,onClick:()=>n(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,Q.jsx)(I,{className:`mr-2 h-4 w-4`}),r(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function Gc(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Kc({t:e}){let t=qi(),[n,r]=(0,$.useState)([]),{publishAll:i,publishing:a}=fo(e),o=n.length;return(0,$.useEffect)(()=>{let e=!1;return Promise.resolve(t.listDrafts?.({})).then(t=>{e||!Array.isArray(t)||r(t.filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name})))}).catch(()=>{}),()=>{e=!0}},[t]),o<=0?null:(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Q.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-indigo-300/60 dark:border-indigo-700/50 bg-indigo-50 dark:bg-indigo-950/30 px-4 py-3`,children:[(0,Q.jsx)(en,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:o,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,Q.jsx)(J,{size:`sm`,onClick:async()=>{(await i()).ok&&(r([]),setTimeout(()=>{try{window.location.reload()}catch{}},700))},disabled:a,"data-testid":`pending-drafts-publish`,children:a?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function qc({t:e}){let t=h(),{hasLocalPassword:n,getAuthConfig:r}=_(),[i,a]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-dismissed`)===`1`)return;if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-first-seen`)!==`1`){try{localStorage.setItem(`os:recovery-pw-first-seen`,`1`)}catch{}return}let e=!1;return Promise.all([Promise.resolve(n?.()),Promise.resolve(r?.()).catch(()=>null)]).then(([t,n])=>{if(e)return;let r=n?.features?.ssoEnforced===!0||n?.emailPassword?.enabled===!1;t===!1&&!r&&a(!0)}).catch(()=>{}),()=>{e=!0}},[n,r]),i?(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Q.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-amber-300/60 dark:border-amber-700/50 bg-amber-50 dark:bg-amber-950/30 px-4 py-3`,children:[(0,Q.jsx)(Xn,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-amber-900 dark:text-amber-200`,children:e(`home.recoveryReminder.message`,{defaultValue:`Set a recovery password so you can still sign in if single sign-on is ever unavailable.`})}),(0,Q.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{try{localStorage.setItem(`os:recovery-pw-dismissed`,`1`)}catch{}a(!1)},"aria-label":e(`home.recoveryReminder.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded-md p-1 text-amber-700/70 hover:text-amber-900 dark:text-amber-300/70 dark:hover:text-amber-100`,children:(0,Q.jsx)(ln,{className:`h-4 w-4`})})]})})}):null}function Jc(){let e=h(),{t}=A(),{apps:n,loading:r}=w(),{recentItems:i}=Rr(),{favorites:a}=zr(),{user:o}=_(),s=g(),{pendingApprovalsCount:c,notifications:l,activities:u}=Hc(),{askAvailable:d,buildAvailable:f}=Uc(),p=n.filter(e=>e.active!==!1&&e.hidden!==!0),m=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),v=(0,$.useMemo)(()=>t(Gc(new Date().getHours()),{defaultValue:`Welcome`}),[t]),y=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):p.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Q.jsx)(Kc,{t}),(0,Q.jsx)(qc,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s?(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:t(`home.welcome`,{product:va().branding.productName,defaultValue:`Welcome to {{product}}`})}),(0,Q.jsx)(fe,{children:f?t(`home.welcomeAdminDescription`,{defaultValue:`Describe your business in one sentence — AI generates the objects, screens, APIs and agent tools. Or set things up yourself from the Administration menu on the left.`}):d?t(`home.welcomeAdminDescriptionNoBuild`,{defaultValue:`Set up your first application from the Administration menu on the left. Once you have data, the AI assistant can help you explore it.`}):t(`home.welcomeAdminDescriptionNoAi`,{defaultValue:`Set up your first application from the Administration menu on the left.`})}),(0,Q.jsx)(Wc,{askAvailable:d,buildAvailable:f,navigate:e,t,layout:`stack`})]}):(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(fe,{children:t(`home.noAppsDescription`,{defaultValue:`There are no applications available to you yet. Please contact your workspace administrator.`})})]})})]}):(0,Q.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Q.jsx)(Kc,{t}),(0,Q.jsx)(qc,{t}),(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-8 pb-16`,children:(0,Q.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Q.jsxs)(`div`,{className:`mb-7 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight text-pretty`,children:[(0,Q.jsxs)(`span`,{className:`text-foreground`,children:[v,y?`, `:``]}),y&&(0,Q.jsx)(`span`,{className:`text-primary`,children:y}),(0,Q.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm sm:text-base text-muted-foreground`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})})]}),(0,Q.jsx)(Wc,{askAvailable:d,buildAvailable:f,navigate:e,t})]}),s&&(0,Q.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>e(`/studio`),className:`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors hover:border-primary/50 hover:bg-muted/40`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Qt,{className:`h-4.5 w-4.5`})}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-semibold`,children:t(`home.build.title`,{defaultValue:`Build an app`})}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t(`home.build.subtitle`,{defaultValue:`Start from scratch — design objects, forms, automations and interfaces.`})})]})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>e(`/apps/setup/system/marketplace`),className:`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors hover:border-primary/50 hover:bg-muted/40`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Ee,{className:`h-4.5 w-4.5`})}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-semibold`,children:t(`home.template.title`,{defaultValue:`Start with a template`})}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t(`home.template.subtitle`,{defaultValue:`Install a template app from the marketplace and customize it.`})})]})]})]}),(0,Q.jsx)(Nc,{apps:p,favorites:a,onOpen:t=>e(`/apps/${da(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:s}),(0,Q.jsx)(`div`,{className:`mb-6`,children:(0,Q.jsx)(Lc,{pendingApprovalsCount:c,notifications:l,onOpenApprovals:()=>e(`/apps/setup/system/approvals`),onOpenNotification:t=>e(t.actionUrl||`/apps/setup/sys_inbox_message?view=mine`),t})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,Q.jsx)(Bc,{items:m,onOpen:t=>e(t),t}),(0,Q.jsx)(Vc,{items:u,onViewAll:()=>e(`/apps/setup/sys_activity`),t})]})]})})]})}function Yc({children:e}){let{setContext:t}=ki();return(0,$.useEffect)(()=>{t(`home`)},[t]),(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,Q.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,Q.jsx)(as,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function Xc(e){let t=await v()(`${_a()}/api/v1/cloud/environments`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({displayName:e.displayName??`Production`,organizationId:e.organizationId})});if(!t.ok){if(t.status===403||t.status===409)return{alreadyProvisioned:!0};throw Error(`Failed to provision production environment (status ${t.status})`)}let n=await t.json().catch(()=>({}));return n&&typeof n==`object`&&`data`in n&&n.data?n.data:n??{}}function Zc(e){let t=e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48);if(t)return t;let n=e.trim();if(!n)return``;let r=0;for(let e of n)r=Math.imul(r,31)+e.charCodeAt(0)>>>0;return`workspace-${r.toString(36).slice(0,6)}`}function Qc({open:e,onOpenChange:t,onCreated:n}){let{t:r}=A(),{createOrganization:i,getAuthConfig:a}=_(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[g,v]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||v(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,$.useEffect)(()=>{u||l(Zc(o))},[o,u]),(0,$.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)(ht,{open:e,onOpenChange:t,children:(0,Q.jsx)(G,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Q.jsxs)(`form`,{onSubmit:(0,$.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()});try{await Xc({organizationId:e.id,displayName:o.trim()})}catch(e){console.warn(`[CreateWorkspace] eager env provision failed; onboarding gate will provision lazily`,e)}n?.(e)}catch(e){h(e instanceof Error?e.message:`Failed to create workspace`)}finally{p(!1)}}},[o,c,g,r,i,n]),children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(xt,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(je,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(Ft,{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,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(Ft,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,Q.jsxs)(On,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function $c(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function el(){let{t:e}=A(),t=h(),[n]=d(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:a,activeOrganization:o,isOrganizationsLoading:s,switchOrganization:c,getAuthConfig:l}=_(),[u,f]=(0,$.useState)(``),[p,m]=(0,$.useState)(!1),[g,v]=(0,$.useState)(null),[y,b]=(0,$.useState)(!0);(0,$.useEffect)(()=>{let e=!1;return l().then(t=>{e||t?.features?.multiOrgEnabled===!1&&b(!1)}).catch(()=>{}),()=>{e=!0}},[l]);let x=a??[],S=(0,$.useMemo)(()=>{let e=u.trim().toLowerCase();return e?x.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):x},[x,u]),C=async e=>{v(e.id);try{e.id!==o?.id&&await c(e.id),window.location.href=Lo()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),v(null)}},w=e=>{m(!1),C(e)},T=(0,$.useRef)(!1);(0,$.useEffect)(()=>{T.current||s||i||x.length===1&&(T.current=!0,r?t(`/organizations/${x[0].slug}/members`,{replace:!0}):C(x[0]))},[s,x.length,r,i]);let E=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(s)return;let e=x.length===0&&y;(i||e)&&!E.current&&(E.current=!0,m(!0))},[i,x.length,y,s]);let D=!i&&!s&&x.length===1,O=!s&&x.length===0&&y&&!E.current;return s||D||O?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,Q.jsxs)(`div`,{className:`mb-8`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,Q.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,Q.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,Q.jsx)(cn,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Ft,{value:u,onChange:e=>f(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),y&&(0,Q.jsxs)(J,{onClick:()=>m(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),x.length===0?(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(fe,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),y&&(0,Q.jsxs)(J,{className:`mt-6`,onClick:()=>m(!0),children:[(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):S.length===0?(0,Q.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,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:S.map(n=>{let r=n.id===o?.id,i=g===n.id;return(0,Q.jsxs)(`button`,{onClick:()=>C(n),disabled:i,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,Q.jsxs)(Ln,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(pn,{src:n.logo,alt:n.name}),(0,Q.jsx)(Lt,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:$c(n.name)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,Q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:r?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,Q.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`})}),i&&(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Q.jsx)(Qc,{open:p,onOpenChange:m,onCreated:w})]})}function tl(){let{t:e}=A(),t=h(),{slug:n}=o(),{organizations:r,activeOrganization:i,isOrganizationsLoading:a,switchOrganization:c}=_(),{setContext:l}=ki();(0,$.useEffect)(()=>{l(`home`)},[l]);let d=(0,$.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,$.useEffect)(()=>{d&&i?.id!==d.id&&c(d.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[d,i,c]),a)return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!d)return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,Q.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,Q.jsx)(J,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let f=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,Q.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,Q.jsx)(as,{variant:`orgs`})}),(0,Q.jsx)(`div`,{className:`border-b`,children:(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(r??[]).length>1&&(0,Q.jsxs)(`button`,{onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:d.name}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d.slug})]})}),(0,Q.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:f.map(e=>(0,Q.jsx)(s,{to:e.to,end:!0,className:({isActive:e})=>`border-b-2 px-3 py-2 text-sm font-medium transition-colors ${e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e.label},e.to))})]})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,Q.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,Q.jsx)(u,{context:{org:d}})})})]})}function nl(){return a()}function rl(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function il({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=A(),{inviteMember:a}=_(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(`member`),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(null),[g,v]=(0,$.useState)(!1);(0,$.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),v(!1))},[t]);let y=(0,$.useCallback)(async t=>{if(t.preventDefault(),o.trim()){d(!0),p(null);try{let t=await a({organizationId:e,email:o.trim(),role:c});h(t),r?.(t)}catch(e){p(e instanceof Error?e.message:`Failed to invite member`)}finally{d(!1)}}},[o,c,e,a,r]),b=(0,$.useCallback)(async()=>{if(!m)return;let e=rl(m.id);try{await navigator.clipboard.writeText(e),v(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>v(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Q.jsx)(ht,{open:t,onOpenChange:n,children:(0,Q.jsx)(G,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(xt,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(je,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,Q.jsx)(Wt,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Ft,{readOnly:!0,value:rl(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,onClick:b,"aria-label":`Copy`,children:g?(0,Q.jsx)(gt,{className:`h-4 w-4`}):(0,Q.jsx)(mn,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:m.email,role:m.role})})]}),(0,Q.jsx)(On,{children:(0,Q.jsx)(J,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:y,children:[(0,Q.jsxs)(De,{children:[(0,Q.jsx)(xt,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(je,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(Ft,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(Me,{value:c,onValueChange:e=>l(e),children:[(0,Q.jsx)(Ct,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(bt,{})}),(0,Q.jsxs)(An,{children:[(0,Q.jsx)(Ae,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Q.jsx)(Ae,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Q.jsx)(Ae,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,Q.jsxs)(On,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function al(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function ol(){let{t:e}=A(),{org:t}=nl(),{getMembers:n,removeMember:r,updateMemberRole:i}=_(),[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)(!0),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(null),h=(0,$.useCallback)(async()=>{c(!0),u(null);try{o(await n(t.id))}catch(e){u(e instanceof Error?e.message:`Failed to load members`)}finally{c(!1)}},[t.id,n]);(0,$.useEffect)(()=>{h()},[h]);let g=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return s?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,Q.jsx)(J,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Q.jsx)(he,{}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,Q.jsxs)(Ln,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(pn,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(Lt,{className:`text-xs font-medium`,children:al(t.user?.name)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,Q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,Q.jsx)(Sn,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),t.createdAt&&(0,Q.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),(0,Q.jsxs)(En,{children:[(0,Q.jsx)($e,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Q.jsx)(yt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(_n,{align:`end`,children:[(0,Q.jsxs)(qt,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Q.jsx)(ae,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Q.jsxs)(qt,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Q.jsx)(ae,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Q.jsxs)(qt,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Q.jsx)(ae,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Q.jsxs)(qt,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Q.jsx)(ar,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)(Dn,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Q.jsxs)(Jt,{children:[(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(Nt,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(Ot,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:p?.user?.name??p?.userId??``})})]}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)($t,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(vn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,Q.jsx)(il,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function sl(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function cl(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function ll(){let{t:e}=A(),{org:t}=nl(),{listInvitations:n,cancelInvitation:r}=_(),[i,a]=(0,$.useState)([]),[o,s]=(0,$.useState)(!0),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(`all`),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(null),g=(0,$.useCallback)(async()=>{s(!0),l(null);try{a(await n(t.id))}catch(e){l(e instanceof Error?e.message:`Failed to load invitations`)}finally{s(!1)}},[t.id,n]);(0,$.useEffect)(()=>{g()},[g]);let v=async t=>{let n=sl(t.id);try{await navigator.clipboard.writeText(n),h(t.id),X.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{X.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},y=async()=>{if(f)try{await r(f.id),X.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){X.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},b=u===`all`?i:i.filter(e=>e.status===u),x={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,Q.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${u===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),x[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:x[t]})]},t))}),(0,Q.jsx)(he,{}),b.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:b.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Q.jsx)(Ln,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(Lt,{className:`text-xs`,children:(0,Q.jsx)(Se,{className:`h-4 w-4`})})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,Q.jsx)(Sn,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Q.jsx)(Sn,{variant:cl(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>v(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(gt,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(mn,{className:`h-4 w-4`})}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>p(t),"aria-label":`Cancel invitation`,children:(0,Q.jsx)(ln,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)(Dn,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(Jt,{children:[(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(Nt,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(Ot,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)($t,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(vn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:y,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function ul(){let{t:e}=A(),{org:t}=nl(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=_(),s=h(),[c,l]=(0,$.useState)(t.name),[u,d]=(0,$.useState)(t.slug??``),[f,p]=(0,$.useState)(t.logo??``),[m,g]=(0,$.useState)(!1),[v,y]=(0,$.useState)(!1),b=(0,$.useRef)(null),{upload:x}=qn(),[S,C]=(0,$.useState)(null),[w,T]=(0,$.useState)(!0),[E,D]=(0,$.useState)(!1),[O,k]=(0,$.useState)(!1),[j,M]=(0,$.useState)(``),[N,P]=(0,$.useState)(!1);(0,$.useEffect)(()=>{l(t.name),d(t.slug??``),p(t.logo??``)},[t]),(0,$.useEffect)(()=>{let e=!1;return T(!0),r(t.id).then(t=>{e||C(t.find(e=>e.userId===n?.id)?.role===`owner`)}).catch(()=>{e||C(!1)}).finally(()=>{e||T(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let ee=(0,$.useCallback)(async n=>{n.preventDefault(),g(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.trim()||void 0}),X.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{g(!1)}},[t.id,c,u,f,i,e]);return w?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,Q.jsx)(he,{className:`my-4`}),S?(0,Q.jsxs)(`form`,{onSubmit:ee,className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(Ft,{id:`org-name`,value:c,onChange:e=>l(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(Ft,{id:`org-slug`,value:u,onChange:e=>d(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Wt,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Ln,{className:`size-16 rounded-md`,children:[f?(0,Q.jsx)(pn,{src:f,alt:c,className:`object-cover`}):null,(0,Q.jsx)(Lt,{className:`rounded-md text-base`,children:(c||`O`).slice(0,2).toUpperCase()})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(b.current&&(b.current.value=``),n){y(!0);try{p((await x(n)).url),X.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{y(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:v,onClick:()=>b.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[v?(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(dt,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Q.jsx)(ln,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(Ft,{id:`org-logo`,type:`url`,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Q.jsxs)(J,{type:`submit`,disabled:m,"data-testid":`settings-save-btn`,children:[m&&(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,Q.jsx)(`div`,{className:`rounded-lg border bg-muted/50 p-4 text-sm text-muted-foreground`,children:e(`organization.settings.readOnlyNote`,{defaultValue:`Only owners can change settings.`})})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,Q.jsx)(he,{className:`my-4`}),(0,Q.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Q.jsx)(he,{}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>{M(``),k(!0)},disabled:!S,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(Dn,{open:E,onOpenChange:D,children:(0,Q.jsxs)(Jt,{children:[(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(Nt,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(Ot,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)($t,{disabled:N,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(vn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{P(!0);try{await o(t.id),X.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{P(!1)}},disabled:N,children:[N&&(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Q.jsx)(Dn,{open:O,onOpenChange:e=>{k(e),e||M(``)},children:(0,Q.jsxs)(Jt,{children:[(0,Q.jsxs)(nr,{children:[(0,Q.jsx)(Nt,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(Ot,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,Q.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,Q.jsx)(Wt,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,Q.jsx)(Ft,{id:`delete-confirm-slug`,className:`mt-2`,value:j,onChange:e=>M(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)($t,{disabled:N,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(vn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{P(!0);try{await a(t.id),X.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{P(!1)}},disabled:N||j!==t.slug,children:[N&&(0,Q.jsx)(z,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function dl(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Date.now()-n.getTime(),i=60*1e3,a=60*i,o=24*a;return r<i?t(`console.ai.justNow`):r<a?t(`console.ai.minutesAgo`,{count:Math.floor(r/i)}):r<o?t(`console.ai.hoursAgo`,{count:Math.floor(r/a)}):r<7*o?t(`console.ai.daysAgo`,{count:Math.floor(r/o)}):n.toLocaleDateString()}function fl(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var pl=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],ml={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function hl(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=1440*60*1e3,a=e=>{let t=new Date(e.updatedAt??e.createdAt??0).getTime();return Number.isNaN(t)?0:t},o={today:[],yesterday:[],previous7Days:[],previous30Days:[],older:[]};for(let t of[...e].sort((e,t)=>a(t)-a(e))){let e=a(t);e>=r?o.today.push(t):e>=r-i?o.yesterday.push(t):e>=r-7*i?o.previous7Days.push(t):e>=r-30*i?o.previous30Days.push(t):o.older.push(t)}return pl.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function gl({userId:e,apiBase:t,activeAgent:n,className:r,refreshKey:i,titleHints:a,onNavigate:s}){let{t:c}=A(),l=h(),{conversationId:u}=o(),{conversations:d,isLoading:f,error:p,remove:m,rename:g}=jr({userId:e,apiBase:t,refreshKey:i}),[_,v]=(0,$.useState)(``),[y,b]=(0,$.useState)(void 0),x=n?ei(n):void 0,S=(0,$.useMemo)(()=>n?new Set(ti(n)):void 0,[n]),C=(0,$.useMemo)(()=>d.map(e=>{let t=a?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[d,a]),w=(0,$.useMemo)(()=>S?C.filter(e=>!e.agentId||S.has(e.agentId)||e.id===u):C,[C,S,u]),T=(0,$.useMemo)(()=>{let e=_.trim().toLowerCase();return e?w.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):w},[w,_]),E=(0,$.useCallback)(e=>{let t=e.agentId?ei(e.agentId):x;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[x]),D=(0,$.useCallback)(()=>{l(x?`/ai/${x}?new=1`:`/ai?new=1`),s?.()},[l,x,s]),O=(0,$.useCallback)(async(e,t)=>{e.stopPropagation(),await m(t),t===u&&(l(x?`/ai/${x}`:`/ai`,{replace:!0}),s?.())},[m,u,l,x,s]),k=(0,$.useCallback)(async(e,t)=>{b(void 0);try{await g(e,t)}catch{}},[g]);return(0,Q.jsxs)(`aside`,{className:L(`flex h-full min-h-0 flex-col bg-muted/30`,r),"data-testid":`ai-conversations-sidebar`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:c(`console.ai.chats`)}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:D,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),c(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(cn,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Ft,{value:_,onChange:e=>v(e.target.value),placeholder:c(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Q.jsx)(Tt,{className:`flex-1 min-h-0`,children:f&&d.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:c(`common.loading`)}):p?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:p.message}):w.length===0?(0,Q.jsxs)(mt,{className:`px-3 py-8`,children:[(0,Q.jsx)(on,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(Te,{children:c(`console.ai.noChatsYet`)}),(0,Q.jsx)(fe,{children:c(`console.ai.noChatsDescription`)})]}):T.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:c(`console.ai.noMatchingChats`)}):(0,Q.jsx)(`div`,{className:`flex flex-col py-1`,children:hl(T).map(e=>(0,Q.jsxs)(`section`,{"data-testid":`ai-conversation-group-${e.key}`,children:[(0,Q.jsx)(`h3`,{className:`px-3 pb-1 pt-3 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:c(`console.ai.group.${e.key}`,{defaultValue:ml[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(vl,{conversation:e,query:_.trim(),active:e.id===u,renaming:e.id===y,onSelect:()=>{l(E(e)),s?.()},onDelete:t=>O(t,e.id),onStartRename:()=>b(e.id),onCancelRename:()=>b(void 0),onSubmitRename:t=>k(e.id,t)},e.id))})]},e.key))})})]})}function _l(e,t){if(!e)return e??null;let n=t?.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase(),i=[],a=0,o=0;for(;;){let t=r.indexOf(n,a);if(t===-1){i.push(e.slice(a));break}t>a&&i.push(e.slice(a,t)),i.push((0,Q.jsx)(`mark`,{className:`rounded-[2px] bg-primary/20 px-0.5 text-foreground`,children:e.slice(t,t+n.length)},o++)),a=t+n.length}return i}function vl({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=A(),u=e.title?.trim()||e.preview?.trim()||l(`console.ai.newConversation`),[d,f]=(0,$.useState)(u),p=(0,$.useRef)(null);return(0,$.useEffect)(()=>{r&&(f(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>p.current?.select(),0))},[r,e.title,e.preview]),r?(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:L(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,n?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,Q.jsx)(Ft,{ref:p,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),c(d)):e.key===`Escape`&&(e.preventDefault(),s())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":l(`console.ai.renameConversation`)}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(d),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":l(`console.ai.saveRename`),children:(0,Q.jsx)(gt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,Q.jsx)(ln,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:L(`group flex w-full items-start gap-2 border-l-2 border-transparent px-3 py-2 text-sm transition-colors hover:bg-accent/50`,n&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:_l(u,t)}),e.preview&&e.preview!==u?(0,Q.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:_l(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:fl(e.updatedAt??e.createdAt),children:dl(e.updatedAt??e.createdAt,l)})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-primary`,onClick:o,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":l(`console.ai.renameConversation`),children:(0,Q.jsx)(jn,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-destructive`,onClick:a,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":l(`console.ai.deleteConversation`),children:(0,Q.jsx)(K,{className:`h-3.5 w-3.5`})})]})]})})}function yl(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function bl(e,t){let n=`${yl()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function xl({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:a}=A(),o=(0,$.useRef)(null),s=t&&t.length?t:e;return(0,$.useEffect)(()=>{if(!o.current)return;let e=bl(s,n);try{o.current.getAttribute(`src`)!==e&&o.current.setAttribute(`src`,e)}catch{}},[s,n]),(0,$.useEffect)(()=>{if(r>0)try{o.current?.contentWindow?.location.reload()}catch{}},[r]),(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b bg-muted/30 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(kn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?a(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):a(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(ln,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:o,title:`Draft preview: ${e}`,src:bl(s,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}async function Sl(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}/debug`,{credentials:`include`});if(n.status===404||n.status===403||n.status===401)return null;if(!n.ok)throw Error(`GET build debug failed: ${n.status}`);return await n.json()}function Cl({apiBase:e,conversationId:t,open:n,onOpenChange:r}){let[i,a]=(0,$.useState)(null),[o,s]=(0,$.useState)(!1),[c,l]=(0,$.useState)(null);(0,$.useEffect)(()=>{if(!n||!t)return;let r=!1;return s(!0),l(null),a(null),Sl(e,t).then(e=>{r||(e?a(e):l(`Not available — the conversation was not found or you are not authorized.`))}).catch(e=>{r||l(e instanceof Error?e.message:String(e))}).finally(()=>{r||s(!1)}),()=>{r=!0}},[n,t,e]);let u=i?.reconciliation,d=u?u.orphaned.length+u.missing.length+u.errors.length:0;return(0,Q.jsx)(re,{open:n,onOpenChange:r,children:(0,Q.jsxs)(pt,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(st,{children:[(0,Q.jsxs)(_t,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Mn,{className:`h-4 w-4`}),` Build Doctor`]}),(0,Q.jsx)(xe,{children:`What the agent claimed vs what is actually live. Read-only diagnostic.`})]}),(0,Q.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm`,children:[o&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),` Reconciling…`]}),c&&!o&&(0,Q.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:c}),i&&!o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:i.title??`(untitled)`}),(0,Q.jsxs)(`div`,{className:`mt-1`,children:[i.summary.userTurns,` turn(s) · `,i.summary.messages,` msgs ·`,` `,i.summary.totalTokens.toLocaleString(),` tok ·`,` `,(i.summary.llmMs/1e3).toFixed(1),`s LLM`,i.summary.models.length?` · ${i.summary.models.join(`, `)}`:``]})]}),u&&(0,Q.jsxs)(`div`,{className:u.ok?`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:[u.ok?(0,Q.jsx)(Re,{className:`h-4 w-4`}):(0,Q.jsx)(pe,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:u.ok?`All ${u.liveCount} attempted change(s) are live — nothing evaporated.`:`${d} discrepancy(ies) — what the chat said doesn't match what's live.`})]}),u&&u.orphaned.length>0&&(0,Q.jsx)(wl,{icon:(0,Q.jsx)(H,{className:`h-4 w-4 text-destructive`}),title:`Proposed but never applied`,hint:`A confirm card the agent proposed but no later turn applied — the change silently evaporated.`,findings:u.orphaned,tone:`destructive`}),u&&u.missing.length>0&&(0,Q.jsx)(wl,{icon:(0,Q.jsx)(pe,{className:`h-4 w-4 text-amber-600`}),title:`Claimed but missing`,hint:`A tool result said it was applied, but the artifact isn't live in sys_metadata.`,findings:u.missing,tone:`amber`}),u&&u.errors.length>0&&(0,Q.jsx)(wl,{icon:(0,Q.jsx)(oe,{className:`h-4 w-4 text-destructive`}),title:`Tool errors`,hint:`Tool calls that returned an error during the build.`,findings:u.errors,tone:`destructive`}),i.verify&&(0,Q.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:`Build check (verify_build)`}),(0,Q.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[`Your app:`,` `,i.verify.userIssues.length===0?(0,Q.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:`0 issues`}):(0,Q.jsxs)(`span`,{className:`text-destructive`,children:[i.verify.userIssues.length,` issue(s)`]}),i.verify.platformNoise>0?` · ${i.verify.platformNoise} platform sys_* finding(s) hidden`:``]}),i.verify.userIssues.map((e,t)=>(0,Q.jsxs)(`div`,{className:`mt-1 text-destructive`,children:[`[`,e.severity,`] `,e.code,` `,e.artifact?`${e.artifact.type}:${e.artifact.name}`:``]},t))]}),i.pendingActions.length>0&&(0,Q.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:`Pending actions`}),i.pendingActions.map((e,t)=>(0,Q.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.tool??`?`,` · `,e.object??`-`,` · `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.status??`-`})]},t))]}),(0,Q.jsxs)(`details`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer font-medium text-foreground`,children:[`Timeline (`,i.timeline.length,`)`]}),(0,Q.jsx)(`div`,{className:`mt-2 space-y-1 font-mono text-[11px] leading-relaxed`,children:i.timeline.map((e,t)=>(0,Q.jsx)(Tl,{entry:e},t))})]})]})]})]})})}function wl({icon:e,title:t,hint:n,findings:r,tone:i}){return(0,Q.jsxs)(`div`,{className:`rounded-md border ${i===`destructive`?`border-destructive/30`:`border-amber-500/30`} p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-foreground`,children:[e,` `,t,` (`,r.length,`)`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:n}),(0,Q.jsx)(`div`,{className:`mt-2 space-y-1`,children:r.map((e,t)=>(0,Q.jsxs)(`div`,{className:`font-mono text-xs`,children:[e.t?`${e.t} · `:``,e.tool,` → `,e.artifact.type,`:`,e.artifact.name,(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.status,`)`]})]},t))})]})}function Tl({entry:e}){return e.kind===`user`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 👤 `,e.text]}):e.kind===`assistant-text`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 `,e.text]}):e.kind===`assistant-calls`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 →`,` `,e.calls.map(e=>e.name).join(`, `)]}):(0,Q.jsxs)(`div`,{className:e.isError?`text-destructive`:``,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` ↳ `,e.name,e.status?` (${e.status})`:``]})}var El=`/api/v1/ai`;function Dl(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function Ol(e){let t=Dl(e,`state`);switch(t){case`input-streaming`:case`input-available`:return`output-available`;case`approval-requested`:case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return t;default:return`output-available`}}function kl(e){return e.map(e=>{let t=[],n,r=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let r of e.parts){if(!r.type.startsWith(`tool-`))continue;let i=Dl(r,`toolName`)??r.type.slice(5),a=Dl(r,`toolCallId`)??`${e.id}-${i}`,o=Ol(r),s=r.output??r.result,c=ai(s),l=Gr(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...l?{proposedPlan:l}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=Jr(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function Al(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var jl={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function Ml(e,t,n){let r=t?jl[ei(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Nl(e,t){return Zr(t)?{title:e(`console.ai.empty.build.title`,{defaultValue:`Build with AI`}),description:e(`console.ai.empty.build.description`,{defaultValue:`Describe an app or workflow in plain language — I draft the objects, screens and automations, then you review and publish.`})}:Qr(t)?{title:e(`console.ai.empty.ask.title`,{defaultValue:`Ask your data`}),description:e(`console.ai.empty.ask.description`,{defaultValue:`Ask questions about your records — counts, lists, and summaries across the data you can access.`})}:{title:e(`console.ai.emptyTitle`,{defaultValue:`Start a conversation`}),description:e(`console.ai.emptyDescription`,{defaultValue:`Ask anything — the assistant has access to your current app context.`})}}function Pl(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(/\/$/,``)}${El}`}var Fl=`ai-chats-collapsed`;function Il(){let[e,t]=(0,$.useState)(()=>{try{return localStorage.getItem(Fl)===`1`}catch{return!1}}),n=(0,$.useRef)(!1);return{collapsed:e,toggle:(0,$.useCallback)(()=>{n.current=!1,t(e=>{let t=!e;try{localStorage.setItem(Fl,t?`1`:`0`)}catch{}return t})},[]),handleCanvasOpenChange:(0,$.useCallback)(e=>{e?t(e=>e||(n.current=!0,!0)):n.current&&(n.current=!1,t(!1))},[])}}var Ll=`ai-chat-pane-width`,Rl=480,zl=360,Bl=420,Vl=24;function Hl(e,t){let n=t.containerWidth>0?Math.max(t.min,t.containerWidth-t.previewMin):1/0;return Math.min(Math.max(e,t.min),n)}function Ul(e){let t=(0,$.useRef)(null),[n,r]=(0,$.useState)(()=>{try{let e=Number(localStorage.getItem(Ll));return Number.isFinite(e)&&e>0?e:Rl}catch{return Rl}}),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(e=>Hl(e,{min:zl,previewMin:Bl,containerWidth:t.current?.clientWidth??0}),[]),s=(0,$.useCallback)(e=>{try{localStorage.setItem(Ll,String(Math.round(e)))}catch{}},[]);return(0,$.useEffect)(()=>{if(!e)return;let n=t.current;if(!n||typeof ResizeObserver>`u`)return;let i=new ResizeObserver(()=>r(e=>o(e)));return i.observe(n),()=>i.disconnect()},[e,o]),{width:n,dragging:i,containerRef:t,onHandlePointerDown:(0,$.useCallback)(e=>{e.preventDefault();let t=e.clientX,i=n;a(!0);let c=e=>r(o(i+(e.clientX-t))),l=e=>{let n=o(i+(e.clientX-t));r(n),s(n),a(!1),window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l)};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},[o,s,n]),onHandleKeyDown:(0,$.useCallback)(e=>{let t=e.key===`ArrowLeft`?-24:e.key===`ArrowRight`?Vl:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,$.useCallback)(()=>{let e=o(Rl);r(e),s(e)},[o,s])}}function Wl(e){if(!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey)return null;switch(e.key.toLowerCase()){case`o`:return`new-chat`;case`s`:return`toggle-list`;default:return null}}function Gl(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i}=e,a=!!t;return(0,$.useEffect)(()=>{if(!a||!n)return;let e=r.current;e&&(r.current=null,i(e.content,e.files))},[a,n,r,i]),(0,$.useCallback)((e,t)=>{if(a&&!n){r.current={content:e,files:t};return}i(e,t)},[a,n,r,i])}function Kl({apiBase:e,defaultAgent:t}={}){let{user:n}=_(),{t:r}=A(),i=n?.id,{agent:a,conversationId:s}=o(),[c]=d(),l=c.toString(),u=c.get(`new`)!==null,f=c.get(`package`)?.trim()||void 0,p=h(),{setContext:m}=ki();(0,$.useEffect)(()=>{m(`home`)},[m]);let g=(0,$.useMemo)(()=>Pl(e),[e]),v={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:y,isLoading:b,error:x,refetch:S}=Xr({apiBase:g}),C=(0,$.useMemo)(()=>y.map(e=>e.name),[y]),w=!b&&y.length===0,T=(0,$.useMemo)(()=>{if(!a)return!1;if(y.length!==0)return ii(a,C)!==void 0},[a,y.length,C]),E=a?void 0:c.get(`agent`)??void 0,D=(0,$.useMemo)(()=>Yr(y,E??t??v),[y,E,t,v]),O=(0,$.useMemo)(()=>{if(y.length!==0)return a&&T?ii(a,C):D},[y.length,a,T,C,D]),k=O?ei(O):void 0,j=!!(a&&T===!1&&Kr(a)),M=a&&T===!1&&!j?a:void 0,N=O?`${g}/agents/${encodeURIComponent(O)}/chat`:void 0,{conversationId:P,conversationScope:ee,initialMessages:F}=Sr({userId:O?i:void 0,scope:O,apiBase:g,activeId:s??M,forceNew:u});(0,$.useEffect)(()=>{if(y.length===0||!O)return;let e=ei(O),t=new URLSearchParams(l);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!a){p(`/ai/${e}${n}`,{replace:!0});return}if(j){p(`/ai/${e}${n}`,{replace:!0});return}T&&a!==e&&p(`/ai/${e}${s?`/${encodeURIComponent(s)}`:``}${n}`,{replace:!0})},[y.length,O,a,T,j,s,l,p]),(0,$.useEffect)(()=>{if(M===void 0)return;let e=!1;return(async()=>{let t;try{t=(await xr(g,M))?.agentId??void 0}catch{}e||p(`/ai/${ei(ii(t??``,C)??O??`ask`)}/${encodeURIComponent(M)}`,{replace:!0})})(),()=>{e=!0}},[M,g,C,O,p]);let[I,R]=(0,$.useState)(0),[te,z]=(0,$.useState)({}),[ne,B]=(0,$.useState)(!1),[ie,ae]=(0,$.useState)(!1),[oe,se]=(0,$.useState)(!1),{collapsed:V,toggle:ce,handleCanvasOpenChange:le}=Il();(0,$.useEffect)(()=>{let e=e=>{let t=Wl(e);t&&(e.preventDefault(),t===`toggle-list`?ce():p(k?`/ai/${k}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[ce,p,k]);let H=(0,$.useMemo)(()=>g.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[g]),ue=(0,$.useMemo)(()=>{if(typeof window>`u`||typeof document>`u`)return;let e=``;try{let t=document.querySelector(`base`)?.getAttribute(`href`);t&&(e=new URL(t,window.location.origin).pathname.replace(/\/+$/,``))}catch{}return`${window.location.origin}${e}/s`},[]),U=(0,$.useRef)(null);u?U.current===null&&(U.current={id:P}):U.current=null,(0,$.useEffect)(()=>{!T||s||!P||!k||U.current&&U.current.id===P||ee===O&&p(`/ai/${k}/${P}`,{replace:!0})},[T,s,P,ee,O,k,p]);let de=(0,$.useRef)(new Set);(0,$.useEffect)(()=>{P&&F.length>0&&de.current.add(P)},[P,F.length]),(0,$.useEffect)(()=>{if(!P)return;let e=Al(F);e&&z(t=>t[P]===e?t:{...t,[P]:e})},[P,F]);let W=(0,$.useRef)(null),fe=(0,$.useCallback)(e=>{if(R(e=>e+1),e&&P&&z(t=>({...t,[P]:e})),!e||!P||de.current.has(P))return;de.current.add(P);let t=()=>R(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[P]);return(0,Q.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[!w&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>se(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(Rn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(as,{variant:`home`})})]}),w?(0,Q.jsx)(ql,{hasError:!!x,onRetry:S,onHome:()=>p(`/home`),t:r}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(re,{open:oe,onOpenChange:se,children:(0,Q.jsxs)(pt,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(st,{className:`sr-only`,children:[(0,Q.jsx)(_t,{children:r(`console.ai.chats`)}),(0,Q.jsx)(xe,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(gl,{userId:i,apiBase:g,activeAgent:O,refreshKey:I,titleHints:te,className:`h-full border-r-0`,onNavigate:()=>se(!1)})]})}),P&&(0,Q.jsx)(an,{open:ne,onOpenChange:B,objectName:`ai_conversations`,recordId:P,recordLabel:`this conversation`,apiBase:H,publicBaseUrl:ue}),P&&Zr(O)&&(0,Q.jsx)(Cl,{apiBase:g,conversationId:P,open:ie,onOpenChange:ae}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-background`,children:[(0,Q.jsxs)(`div`,{className:`hidden shrink-0 flex-col border-r md:flex`,children:[!V&&(0,Q.jsx)(gl,{userId:i,apiBase:g,activeAgent:O,refreshKey:I,titleHints:te,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,Q.jsx)(`div`,{className:L(`mt-auto p-2`,V?`w-12`:`w-72 border-t`),children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:ce,"aria-label":V?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:V?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":V,children:V?(0,Q.jsx)(Ut,{className:`h-4 w-4`}):(0,Q.jsx)(Cn,{className:`h-4 w-4`})})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Q.jsx)(Jl,{agents:y,agentsLoading:b,agentsError:x,activeAgent:O,chatApi:N,apiBase:g,conversationId:P,editPackageId:f,initialMessages:F,pendingFirstMessageRef:W,onSent:fe,onShare:()=>B(!0),onDebug:()=>ae(!0),showDebug:Zr(O),onCanvasOpenChange:le},`${N??`local`}:${P??`pending`}`)})]})]})]})}function ql({hasError:e,onRetry:t,onHome:n,t:r}){return(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,"data-testid":`ai-unavailable`,children:(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(Te,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,Q.jsx)(fe,{children:e?r(`console.ai.unavailableError`,{defaultValue:`Couldn't reach the AI service. It may be temporarily offline — try again, or head back home.`}):r(`console.ai.unavailableDescription`,{defaultValue:`This deployment doesn't have an AI assistant enabled. Everything else works as usual.`})}),(0,Q.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-3 sm:flex-row`,children:[e&&(0,Q.jsx)(J,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,Q.jsx)(J,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function Jl({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,chatApi:i,apiBase:a,conversationId:o,editPackageId:s,initialMessages:c,pendingFirstMessageRef:l,onSent:u,onShare:d,onDebug:f,showDebug:p,onCanvasOpenChange:m}){let{t:g}=A(),_=h(),v=e.length>1,[y,b]=(0,$.useState)(null),[x,S]=(0,$.useState)(0),C=(0,$.useRef)(null);(0,$.useEffect)(()=>()=>{C.current&&window.clearTimeout(C.current)},[]);let w=y!==null;(0,$.useEffect)(()=>{m?.(w)},[w,m]);let T=Ul(w),E=(0,$.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&b(e=>e??{name:n.name,segment:t,materialized:!1}),C.current&&window.clearTimeout(C.current),C.current=window.setTimeout(()=>S(e=>e+1),800)},[]),D=(0,$.useCallback)(e=>{b(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,$.useEffect)(()=>{b(null)},[o]);let O=(0,$.useMemo)(()=>Ml(g,r,e.find(e=>e.name===r)?.label??r??g(`console.ai.assistant`)),[e,r,g]),k=(0,$.useMemo)(()=>kl(c),[c]),j=(0,$.useMemo)(()=>{if(!(k.length>0))return Ql(r,O,g)},[k.length,r,O,g]),M=(0,$.useMemo)(()=>Nl(g,r),[g,r]),{errorSuppressed:N,handleChatError:P,setMessagesRef:ee,resetSuppression:F}=Mr({chatApi:i,conversationId:o}),{models:I,defaultModelId:R}=ri({apiBase:a}),[te,z]=(0,$.useState)(void 0),ne=te??R,{messages:B,isLoading:re,error:ie,sendMessage:ae,stop:oe,reload:se,clear:V,setMessages:ce}=oi({api:i,conversationId:o,model:ne,onError:P,body:{context:{activeApp:`AI`,agentName:r,autoPublishAiBuilds:va().features.autoPublishAiBuilds,...s?{packageId:s}:{}}},initialMessages:k,autoResponse:!i,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,$.useEffect)(()=>{ee.current=ce},[ce]),(0,$.useEffect)(()=>{Er(o,kr(B))},[o,B]);let le=(0,$.useRef)(!1);(0,$.useEffect)(()=>{le.current&&!re&&y&&S(e=>e+1),le.current=re},[re,y]);let H=ni({messages:B,apiBase:a,continueConversation:e=>{ae(e)}}),ue=Gl({chatApi:i,conversationId:o,pendingRef:l,doSend:(0,$.useCallback)((e,t)=>{F(),ae(e,t),u(e)},[F,ae,u])}),U=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6`,children:[(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:v?e.length<=3?(0,Q.jsx)(Rt,{value:r,onValueChange:e=>_(`/ai/${ei(e)}`),children:(0,Q.jsx)(Hn,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":g(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:e.map(e=>(0,Q.jsx)(Bt,{value:e.name,disabled:t,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:Ml(g,e.name,e.label)},e.name))})}):(0,Q.jsxs)(Me,{value:r,onValueChange:e=>_(`/ai/${ei(e)}`),disabled:t,children:[(0,Q.jsx)(Ct,{className:`h-7 w-auto min-w-0 border-0 bg-transparent px-1.5 text-xs shadow-none hover:bg-accent focus:ring-0 focus:ring-offset-0 focus-visible:ring-1 focus-visible:ring-border/80 focus-visible:ring-offset-0 sm:min-w-[160px]`,"data-testid":`ai-chat-agent-picker`,"aria-label":g(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,Q.jsx)(bt,{placeholder:g(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,Q.jsx)(An,{align:`start`,children:e.map(e=>(0,Q.jsxs)(Ae,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Ml(g,e.name,e.label)}),e.description?(0,Q.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}):(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground/85`,children:O})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[p&&f?(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:f,disabled:!o,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:o?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,Q.jsx)(Mn,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:d,disabled:!o,"aria-label":g(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:g(o?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(nt,{className:`h-3.5 w-3.5`})})]}),n?(0,Q.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:g(`console.ai.offlineDemoMode`)}):null]});return(0,Q.jsxs)(`div`,{ref:T.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[(0,Q.jsx)(`div`,{"data-chat-column":!0,className:y?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:y?{width:T.width}:void 0,children:(0,Q.jsx)($r,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(ga(),`_blank`,`noopener,noreferrer`),surface:`plain`,maxHeight:`100%`,headerSlot:U,messages:B,placeholder:r?ei(r)===`ask`?g(`console.ai.askAnything`):g(`console.ai.askAgent`,{agent:O}):g(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:M.title,emptyDescription:M.description,clear:g(`console.ai.clearConversation`),sendHint:g(`console.ai.sendHint`),agentActivity:g(`console.ai.agentActivity`),toolCompleted:g(`console.ai.toolCompleted`),toolRunning:g(`console.ai.toolRunning`),toolAwaitingApproval:g(`console.ai.toolAwaitingApproval`),toolFailed:g(`console.ai.toolFailed`),connectionWaiting:g(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:g(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:g(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:g(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[g(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),g(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),g(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),g(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),g(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),g(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),g(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),g(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),g(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),g(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:g(`console.ai.toolDetailsHidden`),copy:g(`console.ai.copy`),copied:g(`console.ai.copied`),regenerate:g(`console.ai.regenerate`),model:g(`console.ai.model`),submit:g(`console.ai.submit`),uploadFiles:g(`console.ai.uploadFiles`),stopResponse:g(`console.ai.stopResponse`),sendFailedRateLimited:g(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:g(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:g(`console.ai.trace`),viewTrace:g(`console.ai.viewTrace`)},models:I,selectedModelId:ne,onModelChange:z,suggestions:j,onSendMessage:ue,onClear:V,hideClearBar:!0,onStop:re?oe:void 0,onReload:se,isLoading:re,error:N?void 0:ie,enableMarkdown:!0,onToolApprove:H.decide,toolDecisions:H.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>_(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:g(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),fetchPendingDraftCount:Or,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(g(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):X.success(g(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),gr(),{ok:!0,health:qr(n)}}catch(e){return X.error(g(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:g(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:g(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:g(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:g(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:g(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:g(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:g(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:g(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:g(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:g(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:g(`console.ai.planBuilt`,{defaultValue:`Built`}),planReadyLabel:g(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:g(`console.ai.planApproveMessage`,{defaultValue:`Looks good — build it as proposed.`}),planApproveDefaultsMessage:g(`console.ai.planApproveDefaultsMessage`,{defaultValue:`Build it with your best assumptions; use sensible defaults for the open questions.`}),planAnswerMessage:(e,t)=>g(`console.ai.planAnswerMessage`,{question:e,option:t,defaultValue:`For "{{question}}", go with: {{option}}.`}),autoPublishDrafts:va().features.autoPublishAiBuilds,onDraftArtifacts:E,onPreviewDraftApp:(e,t)=>b({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),onBuildMaterialized:D,previewDraftLabel:g(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),y?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":g(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:T.onHandlePointerDown,onKeyDown:T.onHandleKeyDown,onDoubleClick:T.reset,"data-testid":`ai-chat-split-handle`,className:L(`group relative hidden w-1.5 shrink-0 cursor-col-resize touch-none select-none md:block`,`focus:outline-none`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:L(`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border transition-colors`,`group-hover:bg-primary/60 group-focus-visible:bg-primary`,T.dragging&&`bg-primary`)})]}),(0,Q.jsx)(xl,{appName:y.name,appSegment:y.segment,materialized:y.materialized,refreshKey:x,onClose:()=>b(null)}),T.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null]})}function Yl(e){return[e(`console.ai.suggestions.dataChat.userCount`,{defaultValue:`How many users are in the system? List their emails.`}),e(`console.ai.suggestions.dataChat.recentRecords`,{defaultValue:`List the 5 most recently created records.`}),e(`console.ai.suggestions.dataChat.recordCounts`,{defaultValue:`Count records for each object.`})]}function Xl(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a sales CRM — customers, contacts, and a deal pipeline I can total by stage.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project tracker — projects, tasks with owners and due dates, and a board by status.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a support desk — tickets with priority, a status workflow, and customer links.`}),e(`console.ai.suggestions.metadataAssistant.buildInventory`,{defaultValue:`Build an inventory app — products, stock levels, suppliers, and low-stock visibility.`}),e(`console.ai.suggestions.metadataAssistant.buildRecruiting`,{defaultValue:`Make an applicant tracker — candidates, open roles, interview stages, and notes.`})]}function Zl(e){return[e(`console.ai.suggestions.generic.help`,{defaultValue:`What can you help me with?`}),e(`console.ai.suggestions.generic.availableObjects`,{defaultValue:`List the available data objects.`}),e(`console.ai.suggestions.generic.recentActivity`,{defaultValue:`Summarize my recent activity.`})]}function Ql(e,t,n){if(Qr(e))return Yl(n);if(Zr(e))return Xl(n);let r=(e??t).toLowerCase();return r.includes(`data`)?Yl(n):r.includes(`metadata`)?Xl(n):Zl(n)}function $l(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function eu(e){return!$l(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function tu(e){if(!$l(e))return;let t=e.config;if($l(t)&&typeof t.type==`string`)return t.type;if(typeof e.type==`string`)return e.type;if(e.viewKind===`form`)return`form`;if(e.viewKind===`list`)return`list`}Ua({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:bi}),Ua({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:fi}),Ua({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:pi}),ci({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`}]}),ci({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`}]}),ci({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:vi,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`}]}),ci({type:`view`,label:`Views`,description:`Saved list / kanban / calendar / gantt configurations on top of an object.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`,render:(e,t)=>tu(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!eu(e)}),ci({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`}]}),ci({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`}]}),ci({type:`book`,label:`Documentation Books`,description:`Documentation navigation spine — ordered groups with membership derived over docs (glob/tag rules), plus an explicit pages override for curated order.`,domain:`system`,searchableFields:[`name`,`label`,`description`,`slug`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`audience`,label:`Audience`,width:`12%`,render:e=>e==null?`org`:typeof e==`object`&&e&&`profile`in e?`profile: ${e.profile}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var nu=`/api/v1/cloud-connection`;async function ru(e,t){let n=await fetch(e,{credentials:`same-origin`,headers:{"Content-Type":`application/json`},...t}),r=await n.json().catch(()=>({}));if(!n.ok&&r?.success!==!0){let e=r?.error?.message??r?.error?.code??r?.error??`HTTP ${n.status}`;throw Error(typeof e==`string`?e:JSON.stringify(e))}return r}function iu(){let[e,t]=(0,$.useState)({kind:`loading`}),[n,r]=(0,$.useState)(!1),[i,a]=(0,$.useState)(!1),o=(0,$.useRef)(null),s=(0,$.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null)},[]),c=(0,$.useCallback)(async()=>{try{let e=(await ru(`${nu}/status`))?.data??{environmentId:null,bound:!1,connection:null};t(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}},[]);(0,$.useEffect)(()=>(c(),s),[c,s]);let l=(0,$.useCallback)((e,n)=>{let r=Math.max(e.interval,2)*1e3,i=async()=>{if(Date.now()-n>e.expires_in*1e3){t({kind:`error`,message:`The request expired before it was approved. Start again.`});return}try{let n=await ru(`${nu}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:e.device_code})});if(n?.data?.pending){o.current=setTimeout(i,r);return}if(n?.data?.bound||n?.success){await c();return}t({kind:`error`,message:n?.error?.code??`Binding failed.`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}};o.current=setTimeout(i,r)},[c]),u=(0,$.useCallback)(async()=>{r(!0);try{let e=(await ru(`${nu}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!e?.device_code||!e?.user_code)throw Error(`Device code request failed.`);let n=e.verification_uri_complete??e.verification_uri,r=!1;if(n)try{r=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}t({kind:`waiting`,code:e,popupOpened:r}),l(e,Date.now())}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[l]),d=(0,$.useCallback)(async()=>{r(!0);try{await ru(`${nu}/unbind`,{method:`POST`,body:`{}`}),await c()}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[c]),f=(0,$.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),a(!0),setTimeout(()=>a(!1),1500)}catch{}},[]);if(e.kind===`loading`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border p-6 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` Checking connection…`]});if(e.kind===`error`)return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-destructive`,children:[(0,Q.jsx)(W,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,e.message]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Try again`})]});if(e.kind===`waiting`){let t=e.code.verification_uri_complete??e.code.verification_uri;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),e.popupOpened?`Approve the connection in the window that just opened — this page updates by itself.`:`Waiting for approval in the cloud console…`]}),!e.popupOpened&&t?(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,href:t,target:`_blank`,rel:`noreferrer`,children:[`Open the approval page `,(0,Q.jsx)(St,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`code`,{className:`rounded-md bg-muted px-4 py-2 text-2xl font-semibold tracking-[0.25em]`,children:e.code.user_code}),(0,Q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>void f(e.code.user_code),children:[(0,Q.jsx)(mn,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,i?`Copied`:`Copy`]})]}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The code is pre-filled on the approval page`,e.popupOpened&&t?(0,Q.jsxs)(Q.Fragment,{children:[` `,`— if the window did not appear,`,` `,(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline`,href:t,target:`_blank`,rel:`noreferrer`,children:[`open it here `,(0,Q.jsx)(St,{className:`h-3 w-3`,"aria-hidden":`true`})]}),`.`]}):`.`]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Cancel`})]})}if(e.kind===`bound`){let t=e.status.connection??{},r=t.runtime_id??e.status.runtimeId;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Re,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Connected to ObjectStack Cloud`})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[t.name?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime`}),(0,Q.jsx)(`dd`,{children:t.name})]}):null,t.organization_id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Organization`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:t.organization_id})]}):null,t.account_email?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Approved by`}),(0,Q.jsx)(`dd`,{children:t.account_email})]}):null,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime ID`}),(0,Q.jsx)(`dd`,{className:`font-mono text-xs`,children:r})]}):null,e.status.environmentId?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Environment`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:e.status.environmentId})]}):null,t.bound_at?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Since`}),(0,Q.jsx)(`dd`,{children:new Date(t.bound_at).toLocaleString()})]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your organization's private packages now appear in the Marketplace under “Your organization”.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void d(),children:[(0,Q.jsx)(be,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` Disconnect`]})]})}return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Yt,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Not connected`})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connect this runtime to an ObjectStack control plane to browse your organization's private packages and install them here. Approval is a single click in your cloud account — no ids or credentials are typed into this page.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void u(),children:[n?(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(yn,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}E.register(`cloud-connection:panel`,()=>(0,Q.jsx)(iu,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var au=`/api/v1/cloud/environments/production/sso-open`,ou=`/apps/cloud_control/sys_environment`;function su(e){return(typeof document<`u`&&document.documentElement.getAttribute(`lang`)||`en`).toLowerCase().startsWith(`zh`)?e.zh:e.en}function cu(e){let{activeOrganization:t}=_(),n=t?.id,r=(0,$.useMemo)(()=>v(),[]),[i,a]=(0,$.useState)({phase:`loading`});return(0,$.useEffect)(()=>{let t=!1,i=``.replace(/\/+$/,``),o=n?`?organizationId=${encodeURIComponent(n)}`:``;return(async()=>{try{let n=await r(`${i}/api/v1/cloud/environment-entitlements${o}`,{method:`GET`,credentials:`include`});if(!n.ok)throw Error(`entitlements ${n.status}`);let s=await n.json().catch(()=>null),c=s?.data??s;if(t)return;if(!c||typeof c!=`object`){a({phase:`unknown`});return}let l=c.hasProductionEnv===!0;a({phase:`ready`,hasProductionEnv:l}),l&&e&&r(`${i}${e}`,{method:`GET`,credentials:`include`}).catch(()=>{})}catch{t||a({phase:`unknown`})}})(),()=>{t=!0}},[r,n,e]),i}function lu(e){window.location.href=e}function uu({properties:e}){let t=h(),n=cu(e?.warmUrl),r=e?.openProductionUrl||au,i=e?.environmentsRoute||ou;if(n.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,"data-onboarding":`loading`,children:[(0,Q.jsx)(Xe,{className:`h-11 w-44 rounded-md`}),(0,Q.jsx)(Xe,{className:`h-11 w-44 rounded-md`})]});let a=n.phase===`ready`&&!n.hasProductionEnv?{en:`Spin up your first environment — a private workspace with its own URL, database, and plan. Building happens inside it.`,zh:`创建你的第一个环境——一个独立的工作区,有自己的网址、数据库和套餐。应用的搭建在里面进行。`}:{en:`Your production environment is ready. Open it to build and run your apps — that all happens inside the environment.`,zh:`你的生产环境已就绪。打开它来搭建和运行应用——这些都在环境内部进行。`},o=n.phase===`ready`&&!n.hasProductionEnv;return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,"data-onboarding":n.phase,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[o?(0,Q.jsxs)(J,{size:`lg`,onClick:()=>t(i),children:[(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4`}),su({en:`Create your environment`,zh:`创建你的环境`})]}):(0,Q.jsxs)(J,{size:`lg`,onClick:()=>lu(r),children:[(0,Q.jsx)(qe,{className:`mr-2 h-4 w-4`}),su({en:`Open Production`,zh:`打开生产环境`})]}),(0,Q.jsxs)(J,{size:`lg`,variant:`secondary`,onClick:()=>t(i),children:[(0,Q.jsx)(V,{className:`mr-2 h-4 w-4`}),su({en:`Manage environments`,zh:`管理环境`})]})]}),(0,Q.jsx)(`p`,{className:`max-w-xl text-center text-sm text-muted-foreground`,children:su(a)})]})}E.register(`cloud:onboarding-next`,e=>(0,Q.jsx)(uu,{...e}),{namespace:`app-shell`,label:`Cloud Onboarding Next-Step`,category:`plugin`,inputs:[]});function du(e){let t=e?.issues;return Array.isArray(t)?t:[]}function fu(e){return`• ${e.path&&e.path.length>0?e.path:`(root)`} — ${e.message}`}function pu(e){let t=du(e);return t.length>0?t.map(fu).join(`
|
|
3
|
-
`):e?.message??String(e)}function mu(e){return e.map(e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${fu(e)}`)].join(`
|
|
4
|
-
`)).join(`
|
|
5
|
-
`)}async function hu(e,t,n){let[r,i]=await Promise.all([e.list(t,{packageId:n}),e.listDrafts({packageId:n,type:t}).catch(()=>[])]),a=(r||[]).map(e=>({type:t,name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of i||[]){let n=String(e?.name??``);n&&!o.has(n)&&(a.push({type:t,name:n,label:n}),o.add(n))}return a}function gu(e,t,n){return{name:e,label:t,fields:{name:{type:`text`,label:n}}}}function _u(e,t,n,r){return{name:e,label:t,type:`autolaunched`,nodes:[{id:`start`,type:`start`,label:n},{id:`end`,type:`end`,label:r}],edges:[{id:`e1`,source:`start`,target:`end`}]}}function vu(e,t){return{name:e,label:t,active:!0,navigation:[]}}function yu(e,t){return{name:e,label:t,objects:{},fields:{}}}var bu=`__ungrouped__`,xu=e=>`g:${e}`,Su=e=>`f:${e}`,Cu=e=>e.slice(2),wu=e=>e.slice(2);function Tu({type:e}){let t=`mt-1 flex items-center rounded-md border bg-muted/30 px-2 text-[11px] text-muted-foreground`;switch(e){case`select`:case`radio`:case`lookup`:case`reference`:case`user`:case`multiselect`:return(0,Q.jsxs)(`div`,{className:`${t} h-7 justify-between`,children:[(0,Q.jsx)(`span`,{children:e===`lookup`||e===`reference`||e===`user`?`搜索…`:`请选择…`}),(0,Q.jsx)(`span`,{children:`▾`})]});case`textarea`:case`html`:case`markdown`:case`json`:case`code`:return(0,Q.jsx)(`div`,{className:`${t} h-14 items-start pt-1.5`,children:`…`});case`boolean`:case`checkbox`:case`switch`:return(0,Q.jsx)(`div`,{className:`mt-1 flex items-center`,children:(0,Q.jsx)(`span`,{className:`h-4 w-7 rounded-full bg-muted`})});case`number`:case`currency`:case`percent`:return(0,Q.jsx)(`div`,{className:`${t} h-7`,children:`0.00`});case`date`:case`datetime`:case`time`:return(0,Q.jsx)(`div`,{className:`${t} h-7`,children:`选择日期…`});default:return(0,Q.jsx)(`div`,{className:`${t} h-7`,children:`\xA0`})}}function Eu({entry:e,selected:t,onSelect:n}){let{attributes:r,listeners:i,setNodeRef:a,transform:o,transition:s,isDragging:c}=Vi({id:Su(e.name)}),l=String(e.def.type??`text`),u=String(e.def.label??e.name),d=!!e.def.required;return(0,Q.jsxs)(`div`,{ref:a,style:{transform:Ki.Transform.toString(o),transition:s},onClick:n,...r,...i,"aria-label":`${u} — 点选改属性,拖动排序`,className:`group relative flex cursor-grab touch-none select-none items-start gap-1.5 rounded-md border bg-background px-2 py-2 active:cursor-grabbing `+(t?`ring-2 ring-primary`:`hover:border-foreground/25`)+(c?` opacity-40`:``),children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,Q.jsx)(Dt,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-xs font-medium`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:u}),d&&(0,Q.jsx)(`span`,{className:`text-destructive`,children:`*`}),(0,Q.jsx)(`span`,{className:`ml-1 rounded bg-muted px-1 py-px text-[9px] uppercase text-muted-foreground`,children:l})]}),(0,Q.jsx)(Tu,{type:l})]})]})}function Du({containerId:e,title:t,fieldIds:n,isDeclared:r,canMoveUp:i,canMoveDown:a,entryByName:o,selectedField:s,onSelectField:c,onRename:l,onDelete:u,onMove:d}){let{setNodeRef:f,isOver:p}=Li({id:e});return(0,Q.jsxs)(`div`,{className:`rounded-lg border `+(p?`border-primary bg-primary/5`:`bg-muted/20`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[r?(0,Q.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},className:`min-w-0 flex-1 rounded bg-transparent px-1 py-0.5 text-[13px] font-medium outline-none hover:bg-muted focus:bg-background focus:ring-1 focus:ring-primary`}):(0,Q.jsx)(`span`,{className:`flex-1 px-1 text-[13px] font-medium text-muted-foreground`,children:t}),r&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!i,onClick:()=>d(-1),"aria-label":`上移分组`,className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(B,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>d(1),"aria-label":`下移分组`,className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(ot,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:u,"aria-label":`删除分组`,title:`删除分组(字段归为未分组)`,className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Q.jsx)(K,{className:`h-3.5 w-3.5`})})]})]}),(0,Q.jsx)(Ui,{items:n,strategy:Hi,children:(0,Q.jsxs)(`div`,{ref:f,className:`grid min-h-[52px] grid-cols-2 gap-2 p-2.5`,children:[n.length===0&&(0,Q.jsx)(`div`,{className:`col-span-2 flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:`拖字段到这里`}),n.map(e=>{let t=wu(e),n=o.get(t);return n?(0,Q.jsx)(Eu,{entry:n,selected:s===t,onSelect:()=>c(t)},e):null})]})})]})}function Ou({draft:e,systemFieldNames:t,onChange:n,selectedField:r,onSelectField:i,onAddField:a}){let o=$.useMemo(()=>$i(e.fields),[e.fields]),s=$.useMemo(()=>ea(e.fieldGroups),[e.fieldGroups]),c=$.useMemo(()=>new Map(o.entries.map(e=>[e.name,e])),[o]),l=$.useMemo(()=>[...s.map(e=>xu(e.key)),xu(bu)],[s]),u=$.useMemo(()=>{let e=new Map;for(let t of s)e.set(xu(t.key),t.label||t.key);return e.set(xu(bu),`未分组`),e},[s]),d=$.useMemo(()=>{let e={};for(let t of l)e[t]=[];for(let n of o.entries){if(t.has(n.name))continue;let r=typeof n.def.group==`string`?n.def.group:``;e[r&&e[xu(r)]?xu(r):xu(bu)].push(Su(n.name))}return e},[o.entries,l,t]),[f,p]=$.useState(d),[m,h]=$.useState(null);$.useEffect(()=>{m||p(d)},[d,m]);let g=$.useRef(f);$.useEffect(()=>{g.current=f},[f]);let _=Gi(Ni(Ii,{activationConstraint:{distance:4}}),Ni(Wi,{coordinateGetter:Pi})),v=$.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(f).find(t=>f[t].includes(e)),[f]),y=$.useCallback(e=>{let r=[];for(let t of l){let n=Cu(t);for(let i of e[t]??[]){let e=c.get(wu(i));if(!e)continue;let t={...e.def};n===bu?delete t.group:t.group=n,r.push({name:e.name,def:t})}}let i=o.entries.filter(e=>t.has(e.name));n({fields:na({shape:o.shape,entries:[...i,...r]})})},[l,c,o,t,n]),b=e=>h(String(e.active.id)),x=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=v(t),i=v(n);!r||!i||r===i||p(e=>{let a=e[r]??[],o=e[i]??[],s=n.startsWith(`g:`)?o.length:o.indexOf(n),c=s<0?o.length:s;return{...e,[r]:a.filter(e=>e!==t),[i]:[...o.slice(0,c),t,...o.slice(c)]}})},S=e=>{h(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=g.current,i=e=>e.startsWith(`g:`)&&e in r?e:Object.keys(r).find(t=>r[t].includes(e)),a=i(t),o=i(n);if(!a||!o)return;let s;if(a===o){let e=r[a],i=e.indexOf(t),o=n.startsWith(`g:`)?e.length-1:e.indexOf(n);if(i<0||o<0||i===o){y(r);return}s={...r,[a]:Bi(e,i,o)}}else{let e=r[a].filter(e=>e!==t),i=r[o],c=n.startsWith(`g:`)?i.length:i.indexOf(n),l=c<0?i.length:c;s={...r,[a]:e,[o]:[...i.slice(0,l),t,...i.slice(l)]}}p(s),y(s)},C=()=>n({fieldGroups:ra(s,`新分组`)}),w=(e,t)=>n({fieldGroups:Xi(s,e,t)}),T=(e,t)=>n({fieldGroups:Ji(s,e,t)}),E=e=>n({fieldGroups:ta(s,e),fields:na(Yi(o,e))}),D=m&&!m.startsWith(`g:`)?c.get(wu(m)):null;return(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(de,{className:`h-3.5 w-3.5`}),` 拖动字段排序 / 拖到其它分组 · 点选字段改属性`]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:C,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` 添加分组`]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` 添加字段`]})]}),(0,Q.jsxs)(Fi,{sensors:_,collisionDetection:Ri,onDragStart:b,onDragOver:x,onDragEnd:S,onDragCancel:()=>h(null),children:[(0,Q.jsx)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-3`,children:l.map(e=>{let t=e===xu(bu);if(t&&(f[e]?.length??0)===0&&s.length>0)return null;let n=s.findIndex(t=>xu(t.key)===e);return(0,Q.jsx)(Du,{containerId:e,title:u.get(e)??`未分组`,fieldIds:f[e]??[],isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<s.length-1,entryByName:c,selectedField:r,onSelectField:i,onRename:t=>w(Cu(e),t),onDelete:()=>E(Cu(e)),onMove:t=>T(Cu(e),t)},e)})}),(0,Q.jsx)(zi,{children:D?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border bg-background px-2 py-2 shadow-lg`,children:[(0,Q.jsx)(Dt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:String(D.def.label??D.name)})]}):null})]})]})}function ku(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function Au(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function ju({draft:e,onPatch:t,disabled:n}){let r=ku(e.validations),[i,a]=$.useState(null),o=$.useMemo(()=>$i(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`?e.def.label:void 0,hidden:e.def.hidden===!0})),[e.fields]),s=e=>t({validations:e}),c=(e,t)=>s(r.map(n=>n.name===e?{...n,...t}:n)),l=()=>{let e=Au(r.map(e=>e.name??``));s([...r,{type:`script`,name:e,message:``,condition:`false`,severity:`error`}]),a(e)},u=e=>{s(r.filter(t=>t.name!==e)),i===e&&a(null)},d=r.find(e=>e.name===i)??null;return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Xn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:`验证规则`}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,r.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:l,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Y,{className:`h-3 w-3`}),` 新增`]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:r.length===0?(0,Q.jsxs)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:[`还没有验证规则。`,(0,Q.jsx)(`br`,{}),`规则在保存记录时执行:条件为真 ⇒ 拒绝保存并提示消息。`]}):r.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(e.name??null),className:`flex w-full items-start gap-2 border-b px-3 py-2 text-left text-[12px] `+(i===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.label||e.name}),(0,Q.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.message||`(无消息)`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full px-1.5 py-0.5 text-[10px] `+(e.type===`script`?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),children:e.type??`script`})]},e.name))})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:d?d.type===`script`?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:`规则名(snake_case,唯一)`}),(0,Q.jsx)(`input`,{value:d.name??``,disabled:n,onChange:e=>{let t=e.target.value;c(d.name,{name:t}),a(t)},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:`错误消息(校验失败时展示给用户)`}),(0,Q.jsx)(`input`,{value:d.message??``,disabled:n,onChange:e=>c(d.name,{message:e.target.value}),placeholder:`例如:完成日期在状态为已完成时必填`,className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[`失败条件(CEL)—— 条件为 `,(0,Q.jsx)(`b`,{children:`真`}),` 时,拒绝保存并显示上面的消息;新规则默认`,` `,(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),`(永不触发),请改为真实条件`]}),(0,Q.jsx)(aa,{value:typeof d.condition==`string`?d.condition:``,onCommit:e=>c(d.name,{condition:e}),fields:o,disabled:n})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`严重度`}),(0,Q.jsxs)(`select`,{value:d.severity??`error`,disabled:n,onChange:e=>c(d.name,{severity:e.target.value}),className:`rounded border bg-background px-1.5 py-0.5 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:`error`,children:`error(拒绝保存)`}),(0,Q.jsx)(`option`,{value:`warning`,children:`warning`}),(0,Q.jsx)(`option`,{value:`info`,children:`info`})]})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:d.active!==!1,disabled:n,onChange:e=>c(d.name,{active:e.target.checked})}),`启用`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>u(d.name),className:`ml-auto inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-1 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,Q.jsx)(K,{className:`h-3 w-3`}),` 删除`]})]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,Q.jsxs)(`p`,{className:`text-[13px] font-medium`,children:[d.label||d.name,(0,Q.jsx)(`span`,{className:`ml-2 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:d.type})]}),(0,Q.jsxs)(`p`,{className:`text-[12px] leading-5 text-muted-foreground`,children:[`「`,d.type,`」类型的规则带有结构化配置(状态机转移表 / 格式约束等),暂不支持在此编辑 —— 请在代码包中维护。消息:`,d.message||`(无)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>u(d.name),className:`mt-auto inline-flex w-fit items-center gap-1 rounded border border-destructive/40 px-2 py-1 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,Q.jsx)(K,{className:`h-3 w-3`}),` 删除规则`]})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:`选择左侧的规则进行编辑,或点「新增」创建一条。`})})]})}function Mu({name:e,draft:t,onPatch:n,disabled:r,locale:i}){let a=si(`object`),o=$.useMemo(()=>$i(t.fields).entries,[t.fields]),s=o.filter(e=>(e.def.type??`text`)===`select`),c=typeof t.nameField==`string`?t.nameField:``,l=t.stageField,u=Array.isArray(t.highlightFields)?t.highlightFields.filter(e=>typeof e==`string`):[],d=o.filter(e=>e.def.hidden!==!0&&!u.includes(e.name));return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-auto`,children:[(0,Q.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(V,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:`基础信息`})]}),(0,Q.jsx)(`div`,{className:`max-w-xl p-3`,children:a?(0,Q.jsx)(a,{type:`object`,name:e,draft:t,onPatch:n,readOnly:!!r,locale:i}):(0,Q.jsx)(`p`,{className:`text-[12px] text-muted-foreground`,children:`未注册对象默认检查器。`})})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Kt,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:`语义角色`}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`跨表单 / 列表 / 详情统一生效(ADR-0085)`})]}),(0,Q.jsxs)(`div`,{className:`grid max-w-xl gap-4 p-3`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:`记录名称字段(nameField)—— 标题、链接、引用处显示的字段`}),(0,Q.jsxs)(`select`,{value:c,disabled:r,onChange:e=>n(e.target.value?{nameField:e.target.value}:{nameField:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:`(自动推导)`}),o.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:`生命周期字段(stageField)—— 详情页顶部进度条按它的选项渲染`}),(0,Q.jsxs)(`select`,{value:l===!1?`__none__`:l??``,disabled:r,onChange:e=>{let t=e.target.value;n({stageField:t===`__none__`?!1:t===``?void 0:t})},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:`(自动探测 status/stage 等字段名)`}),(0,Q.jsx)(`option`,{value:`__none__`,children:`无 —— 这个对象没有线性流程,不显示进度条`}),s.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:`重点字段(highlightFields)—— 默认列表列、卡片、详情顶栏取前 4;顺序即展示顺序`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[e,!r&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":`移除 ${e}`,onClick:()=>n({highlightFields:u.filter(t=>t!==e)}),className:`rounded-full hover:bg-primary/20`,children:(0,Q.jsx)(ln,{className:`h-3 w-3`})})]},e)),!r&&d.length>0&&(0,Q.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&n({highlightFields:[...u,e.target.value]})},className:`rounded border bg-background px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`option`,{value:``,children:`+ 添加字段…`}),d.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]}),u.length===0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`(未声明 —— 各处按启发式自动挑选)`})]})]})]})]})]})}function Nu(e){let t=e?.data??e,n=Array.isArray(t)?t:t?.packages??[],r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.manifest??{},n=String(t.id??e.id??``);if(!n)continue;let i=typeof t.scope==`string`?t.scope:``;i===`system`||i===`cloud`||r.push({id:n,name:String(t.name??n),writable:i!==`project`})}return r}async function Pu(){let e=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);return Nu(await e.json())}async function Fu(e,t){let n=await fetch(`/api/v1/packages`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({id:e,name:t})}),r=await n.json().catch(()=>null);if(!n.ok||r?.success===!1)throw Error(r?.error?.message||`HTTP ${n.status}`)}async function Iu(e,t,n){let r=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/duplicate`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({targetPackageId:t,...n?{targetName:n}:{}})}),i=await r.json().catch(()=>null);if(!r.ok||i?.success===!1)throw Error(i?.error?.message||`HTTP ${r.status}`)}var Lu=/^[a-z][a-z0-9_.-]*(\.[a-z0-9_-]+)+$/,Ru=[{key:`data`,label:`Data`,Icon:Nn},{key:`automations`,label:`Automations`,Icon:nn},{key:`interfaces`,label:`Interfaces`,Icon:wt},{key:`access`,label:`Access`,Icon:Qn}],zu={group:ce,page:we,object:Nn,dashboard:wt,report:Ge,view:At},Bu=e=>zu[e??``]??Vn;function Vu(e){let t=String(e.label??``);switch(e.type){case`page`:return e.pageName||e.page?{type:`page`,name:String(e.pageName||e.page),label:t}:null;case`object`:return e.objectName||e.object?{type:`object`,name:String(e.objectName||e.object),label:t}:null;case`dashboard`:return e.dashboardName||e.dashboard?{type:`dashboard`,name:String(e.dashboardName||e.dashboard),label:t}:null;case`report`:return e.reportName||e.report?{type:`report`,name:String(e.reportName||e.report),label:t}:null;case`view`:return e.viewName||e.view?{type:`view`,name:String(e.viewName||e.view),label:t}:null;default:return null}}function Hu(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function Uu({packageId:e,tab:t}){let n=h(),r=ca(),[i,a]=$.useState(!1),[o,s]=$.useState(null),[c,l]=$.useState(!1),[u,d]=$.useState(``),[f,p]=$.useState(``),[m,g]=$.useState(!1),[_,v]=$.useState(!1),[y,b]=$.useState(null);$.useEffect(()=>{let e=!1;return Pu().then(t=>{e||s(t)}).catch(()=>{}),()=>{e=!0}},[e]);let x=o?.find(t=>t.id===e)??null,S=$.useCallback(async()=>{let e=u.trim(),t=f.trim();if(!(!e||!Lu.test(t))){v(!0),b(null);try{await Fu(t,e),X.success(ia(`engine.studio.pkg.created`,r,{name:e})),a(!1),l(!1),d(``),p(``),g(!1),n(`/studio/${encodeURIComponent(t)}/data`)}catch(e){b(pu(e))}finally{v(!1)}}},[u,f,n]);return(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1.5 whitespace-nowrap rounded-md px-1.5 py-0.5 text-[13px] font-medium hover:bg-muted`,title:Z(`engine.studio.pkg.switchTitle`,r),children:[(0,Q.jsx)(Pn,{className:`h-4 w-4`}),` `,x?.name??e,x&&!x.writable&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] font-normal text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rr,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,r)]}),(0,Q.jsx)(ot,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>a(!1)}),(0,Q.jsxs)(`div`,{className:`absolute left-0 top-full z-50 mt-1 w-80 rounded-lg border bg-background p-1.5 shadow-lg`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.pkg.heading`,r)}),(0,Q.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[o===null&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,r)}),o?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,r)}),o?.map(i=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{a(!1),n(`/studio/${encodeURIComponent(i.id)}/${t}`)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(i.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,Q.jsx)(Pn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate`,children:i.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:i.id})]}),i.writable?(0,Q.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:Z(`engine.studio.pkg.writable`,r)}):(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rr,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,r)]})]},i.id))]}),(0,Q.jsx)(`div`,{className:`mt-1 border-t pt-1.5`,children:c?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-1 pb-1`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>{if(d(e.target.value),!m){let t=Qi(e.target.value).replace(/_/g,`-`);p(t?`com.example.${t}`:``)}},onKeyDown:e=>{e.key===`Enter`&&S(),e.key===`Escape`&&l(!1)},placeholder:Z(`engine.studio.pkg.namePlaceholder`,r),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:f,onChange:e=>{g(!0),p(e.target.value.toLowerCase().replace(/[^a-z0-9_.-]/g,``))},onKeyDown:e=>{e.key===`Enter`&&S(),e.key===`Escape`&&l(!1)},placeholder:Z(`engine.studio.pkg.idPlaceholder`,r),className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),y&&(0,Q.jsx)(`p`,{className:`text-[10px] text-destructive`,children:y}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void S(),disabled:_||!u.trim()||!Lu.test(f.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[_?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),Z(`engine.studio.pkg.createWritable`,r)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(!1),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,r)})]})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,r)]})})]})]})]})}function Wu({aiSlot:e}){let t=o(),n=t.packageId??`com.example.showcase`,r=t.tab??`interfaces`,i=ca(),[a,s]=$.useState(!1),[c,l]=$.useState(null),[u,d]=$.useState(!1),[p,m]=$.useState(0),[g,_]=$.useState(0),v=$.useCallback(async()=>{try{let e=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(n)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)return l(null);let t=await e.json();l((Array.isArray(t)?t:t?.drafts??[]).length)}catch{l(null)}},[n]);$.useEffect(()=>{v()},[v,p,g]);let y=$.useCallback(async()=>{d(!0);try{let e=await fetch(`/api/v1/packages/${encodeURIComponent(n)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),t=await e.json().catch(()=>null);if(!e.ok||t?.success===!1)throw Object.assign(Error(t?.error?.message||`HTTP ${e.status}`),{issues:t?.error?.details?.issues});let r=t?.data?.failed??[];r.length>0?X.error(mu(r)):(X.success(Z(`engine.studio.publishedAll`,i)),s(!1)),m(e=>e+1)}catch(e){X.error(pu(e))}finally{d(!1)}await v()},[n,v]),b=$.useCallback(()=>_(e=>e+1),[]),x=(c??0)>0,S=h(),C=qi(),[w,T]=$.useState(null),[E,D]=$.useState(!1),[O,k]=$.useState(``),[A,j]=$.useState(``),[M,N]=$.useState(!1),[P,ee]=$.useState(!1),[F,I]=$.useState(null),L=$.useCallback(async()=>{let e=O.trim(),t=Zi(A.trim()||e);if(!(!e||!t||t===`field`)){ee(!0);try{await C.save(`app`,t,vu(t,e),{mode:`draft`,packageId:n}),X.success(ia(`engine.studio.app.savedDraft`,i,{label:e})),I(e),D(!1),k(``),j(``),N(!1),_(e=>e+1)}catch(e){X.error(pu(e))}finally{ee(!1)}}},[O,A,C,n]);return $.useEffect(()=>{let e=!1;return(async()=>{try{let t=(await C.list(`app`,{packageId:n})||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name)[0];e||T(t??null)}catch{e||T(null)}})(),()=>{e=!0}},[C,n,p]),(0,Q.jsxs)(`div`,{className:`flex h-screen w-full overflow-hidden bg-background text-foreground`,children:[e?(0,Q.jsx)(`aside`,{className:`w-64 shrink-0 overflow-auto border-r bg-muted/40`,children:e}):null,(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-3 border-b px-3 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>S(`/home`),title:Z(`engine.studio.home`,i),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(Bn,{className:`h-4 w-4`})}),(0,Q.jsx)(Uu,{packageId:n,tab:r}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Q.jsx)(`nav`,{className:`flex gap-1`,children:Ru.map(e=>(0,Q.jsxs)(f,{to:`/studio/${n}/${e.key}`,className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(r===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,Q.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,i)]},e.key))}),(0,Q.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[w?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>window.open(`/apps/${encodeURIComponent(w.name)}`,`_blank`),title:ia(`engine.studio.app.openTitle`,i,{label:w.label}),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(St,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.open`,i)]}):F?(0,Q.jsx)(`span`,{title:Z(`engine.studio.app.willOpenAfterPublish`,i),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:ia(`engine.studio.app.pending`,i,{label:F})}):(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>D(e=>!e),title:Z(`engine.studio.app.noneTitle`,i),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,i)]}),E&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>D(!1)}),(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 flex w-72 flex-col gap-1.5 rounded-lg border bg-background p-2 shadow-lg`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:O,onChange:e=>{k(e.target.value),M||j(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&L(),e.key===`Escape`&&D(!1)},placeholder:Z(`engine.studio.app.namePlaceholder`,i),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:A,onChange:e=>{N(!0),j(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&L(),e.key===`Escape`&&D(!1)},placeholder:Z(`engine.studio.app.idPlaceholder`,i),className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void L(),disabled:P||!O.trim()||!Zi(A.trim()||O)||Zi(A.trim()||O)===`field`,className:`inline-flex items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[P?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),Z(`engine.studio.createDraft`,i)]})]})]})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(et,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,i),x?` · ${c}`:``]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:y,disabled:u||!x,title:Z(x?`engine.studio.publishTitle`:`engine.studio.publishNoneTitle`,i),className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[u?(0,Q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(qe,{className:`h-3.5 w-3.5`}),Z(`engine.studio.publish`,i)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:r===`data`?(0,Q.jsx)(Zu,{packageId:n,publishNonce:p,onDraftSaved:b}):r===`automations`?(0,Q.jsx)($u,{packageId:n,publishNonce:p,onDraftSaved:b}):r===`access`?(0,Q.jsx)(ed,{packageId:n,publishNonce:p,onDraftSaved:b}):(0,Q.jsx)(qu,{packageId:n,publishNonce:p,draftNonce:g,onDraftSaved:b,onCreateApp:()=>D(!0)})})]}),(0,Q.jsx)(ho,{open:a,onOpenChange:s,packageId:n})]})}function Gu({nodes:e,active:t,onPick:n}){return(0,Q.jsx)(Q.Fragment,{children:e.map((e,r)=>{if(e.type===`group`||Array.isArray(e.children)&&e.children.length)return(0,Q.jsxs)(`div`,{className:`mb-1`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 px-2 pb-1 pt-3 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(ce,{className:`h-3 w-3`}),` `,e.label]}),(0,Q.jsx)(`div`,{className:`pl-1.5`,children:(0,Q.jsx)(Gu,{nodes:e.children??[],active:t,onPick:n})})]},e.id??r);let i=Vu(e),a=Bu(e.type),o=!!i&&t?.type===i.type&&t?.name===i.name;return(0,Q.jsxs)(`button`,{onClick:()=>i&&n(i),disabled:!i,title:i?`${i.type} · ${i.name}`:e.label,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs disabled:opacity-40 `+(o?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(a,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),i&&i.type!==`page`&&(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1 py-px text-[9px] uppercase text-muted-foreground`,children:i.type})]},e.id??r)})})}function Ku({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=ca(),o=$.useMemo(()=>{let t=/^navigation\[(\d+)\]$/.exec(e);return t?Number(t[1]):-1},[e]),s=$.useMemo(()=>Array.isArray(t.navigation)?t.navigation:[],[t]),c=o>=0?s[o]:null;if(!c)return(0,Q.jsx)(`div`,{className:`px-2 py-10 text-center text-xs text-muted-foreground`,children:Z(`engine.studio.nav.selectItem`,a)});let l=e=>{r({navigation:s.map((t,n)=>n===o?{...t,...e}:t)})},u=String(c.object??c.objectName??``),d=String(c.label??c.title??c.name??``),f=!d||d===`New item`||d===Z(`engine.appNav.newItem`,a);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.label`,a)}),(0,Q.jsx)(`input`,{value:d,onChange:e=>l({label:e.target.value}),placeholder:Z(`engine.studio.nav.labelPlaceholder`,a),className:`w-full rounded border bg-background px-2 py-1 text-xs`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.linkObject`,a)}),(0,Q.jsxs)(`select`,{value:u,onChange:e=>{let t=e.target.value,r=n.find(e=>e.name===t);if(!t){l({type:void 0,objectName:void 0,object:void 0});return}l({id:c.id||`nav_${t}`,type:`object`,objectName:t,object:void 0,path:void 0,label:f&&r?r.label:d})},className:`w-full rounded border bg-background px-2 py-1 text-xs`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.nav.chooseObject`,a)}),n.map(e=>(0,Q.jsxs)(`option`,{value:e.name,children:[e.label,` (`,e.name,`)`]},e.name))]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:Z(u?`engine.studio.nav.boundHint`:`engine.studio.nav.unboundHint`,a)}),n.length===0&&(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:Z(`engine.studio.nav.noObjects`,a)})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-[11px] text-muted-foreground underline-offset-2 hover:underline`,children:Z(`engine.studio.deselect`,a)})]})}function qu({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i}){let a=qi(),o=ca(),[s,c]=$.useState(e),[l,u]=$.useState(null),[d,f]=$.useState({}),p=$.useMemo(()=>Array.isArray(d.navigation)?d.navigation:[],[d]),[m,h]=$.useState(!1),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,S]=$.useState(!1),[C,w]=$.useState(!1),[T,E]=$.useState(null),[D,O]=$.useState({}),[k,A]=$.useState(null),[j,M]=$.useState(!1),[N,P]=$.useState(!1),[ee,F]=$.useState(!1),[I,L]=$.useState(null),[R,te]=$.useState(`loading`),[ne,B]=$.useState([]);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([a.list(`object`,{packageId:e}),a.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let i=new Map;for(let e of[...n||[],...r||[]]){let t=e,n=String(t.name??``);!n||i.has(n)||i.set(n,{name:n,label:String(t.label??t.name??n)})}B([...i.values()])}catch{}})(),()=>{t=!0}},[a,e,t,n]),$.useEffect(()=>{let t=!1;return te(`loading`),(async()=>{try{let n=await a.list(`app`,{packageId:e});if(t)return;let r=n?.[0]?.name?String(n[0].name):null,i=n?.[0]?String(n[0].label??n[0].name??e):e;if(!r){let n=await a.listDrafts({packageId:e,type:`app`});if(t)return;let o=n?.[0];o?.name&&(r=String(o.name),i=String(o.name))}if(!r){te(`missing`);return}c(i),u(r);let[o,s]=await Promise.all([a.layered(`app`,r),a.getDraft(`app`,r).catch(()=>null)]);if(t)return;let l=o,d=l.effective??l.code??{},p=Hu(s),m=p?{...d,...p}:d;(typeof m.label==`string`||typeof m.name==`string`)&&c(String(m.label??m.name??i)),f(m),S(!!p),te(`ready`);let h=(function e(t){for(let n of t)if(n.type===`group`||n.children?.length){let t=e(n.children??[]);if(t)return t}else{let e=Vu(n);if(e)return e}return null})(Array.isArray(m.navigation)?m.navigation:[]);E(e=>e??h)}catch(e){t||(L(pu(e)),te(`missing`))}})(),()=>{t=!0}},[a,e,t,n]);let re=yi(T?.type??``),ie=gi(T?.type??``),ae=!!re&&T?.type!==`object`;$.useEffect(()=>{if(!T||!ae){O({}),F(!1);return}let e=!1;return M(!0),L(null),A(null),(async()=>{try{let[t,n]=await Promise.all([a.layered(T.type,T.name),a.getDraft(T.type,T.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=Hu(n);O(i?{...r,...i}:r),F(!!i)}catch(t){e||L(pu(t))}finally{e||M(!1)}})(),()=>{e=!0}},[a,T,ae,t]);let oe=$.useCallback(e=>O(t=>({...t,...e})),[]),se=$.useCallback(async()=>{if(T){P(`draft`);try{await a.save(T.type,T.name,D,{mode:`draft`,packageId:e}),F(!0),r?.()}catch(e){L(pu(e))}finally{P(!1)}}},[a,T,D,r]),V=$.useCallback(e=>{f(t=>({...t,...e})),y(!0)},[]),ce=$.useCallback(async()=>{if(l){w(`draft`);try{let t=(Array.isArray(d.navigation)?d.navigation:[]).filter(e=>e&&typeof e.type==`string`).map((e,t)=>{let n=e;return typeof n.id==`string`&&n.id?n:{...n,id:`nav_item_${t+1}`}});await a.save(`app`,l,{...d,navigation:t},{mode:`draft`,packageId:e}),S(!0),y(!1),r?.()}catch(e){L(pu(e))}finally{w(!1)}}},[a,l,d,r]);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[T?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:T.label}),(0,Q.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:[T.type,` · `,T.name]})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,o)}),ee&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,o)}),(0,Q.jsxs)(`button`,{onClick:se,disabled:!T||!ae||!!N,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[N===`draft`?(0,Q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,o)]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`nav`,{className:(m?`w-72`:`w-52`)+` flex shrink-0 flex-col border-r`,children:[(0,Q.jsxs)(`div`,{className:`shrink-0 border-b px-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-1`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[11px] font-medium text-muted-foreground`,children:ia(`engine.studio.if.navHeading`,o,{app:s})}),R===`ready`&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{h(e=>!e),_(null)},title:Z(m?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,o),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(m?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(gt,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,o)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(jn,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,o)]})})]}),m&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[b&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublished`,o)}),(0,Q.jsxs)(`button`,{onClick:ce,disabled:!v||!!C,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[C===`draft`?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ie,{className:`h-3 w-3`}),Z(`engine.studio.saveDraft`,o)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:R===`missing`&&!I?(0,Q.jsxs)(`div`,{className:`px-2 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.noApp`,o)}),i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`mt-2 inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Y,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,o)]})]}):m?(0,Q.jsx)(hi,{draft:d,rootKey:`navigation`,onPatch:V,selection:g,onSelectionChange:e=>_(e?{kind:e.kind,id:e.id}:null)}):p.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(I?`engine.studio.loadFailed`:R===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,o)}):(0,Q.jsx)(Gu,{nodes:p,active:T,onPick:E})})]}),(0,Q.jsxs)(`main`,{className:`min-w-0 flex-1 overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,Q.jsx)(kn,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.previewIsRuntime`,o)]}),T&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[T.type,` · `,T.name]})]}),I&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:I}),(0,Q.jsx)(`div`,{className:`rounded-lg border bg-background p-4`,children:R===`missing`&&!I?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,children:[(0,Q.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Q.jsx)(wt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.if.noAppTitle`,o)}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,o)})]}),i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,o)]})]}):T?j?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,o)]}):T.type===`object`?(0,Q.jsx)(x,{schema:{type:`object-view`,objectName:T.name}}):re?(0,Q.jsx)(re,{type:T.type,name:T.name,draft:D,editing:!0,selection:k,onSelectionChange:A,onPatch:oe,locale:o}):(0,Q.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:ia(`engine.studio.if.readonlyPreview`,o,{type:T.type})}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,o)})}),ae?(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.editHint`,o)]}):T?.type===`object`?(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Nn,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,o),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,o)]}):null]}),(0,Q.jsxs)(`aside`,{className:`w-72 shrink-0 overflow-auto border-l`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsx)(Wn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,o)}),k&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,o),children:(0,Q.jsx)(ln,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`p-3`,children:m&&g?(0,Q.jsx)(Ku,{navId:g.id,appDraft:d,objects:ne,onNavPatch:V,onClear:()=>_(null)}):k&&ie&&T?(0,Q.jsx)(ie,{type:T.type,name:T.name,draft:D,selection:k,onPatch:oe,onClearSelection:()=>A(null),onSelectionChange:A,readOnly:!1,locale:o}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,o),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,o)]})})]})]})]})}function Ju(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var Yu=new Set([`_id`,`id`,`organization_id`,`org_id`,`space_id`,`created_at`,`created_by`,`updated_at`,`updated_by`,`modified_at`,`modified_by`,`created_time`,`modified_time`,`updated_time`,`deleted_at`,`deleted_by`]);function Xu(e){let{schema:t,dataSource:n,onEdit:r,className:i,refreshKey:a}=e;return(0,Q.jsx)(Sa,{schema:{...t,viewType:`grid`,showSearch:!0,showSort:!0,showFilters:!0,showGroup:!0,showHideFields:!0,inlineEdit:!0,addDeleteRecordsInline:!0},dataSource:n,onEdit:r,className:i,refreshKey:a})}function Zu({packageId:e,publishNonce:t=0,onDraftSaved:n}){let r=qi(),i=S(),a=ca(),[o,s]=$.useState([]),[c,l]=$.useState(!1),[u,d]=$.useState(null),[f,p]=$.useState({}),[m,h]=$.useState(!1),[g,_]=$.useState(null),[v,y]=$.useState(null),[b,x]=$.useState(!1),[C,w]=$.useState(!1),[T,E]=$.useState(!1),[D,O]=$.useState(0),[k,A]=$.useState(`grid`),[j,N]=$.useState(`layout`),P=$.useRef(null),[ee,F]=$.useState(``),[I,L]=$.useState(!1),[R,te]=$.useState(``),[ne,B]=$.useState(``),[re,ie]=$.useState(!1),[ae,oe]=$.useState(!1),[se,V]=$.useState(!0);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,i]=await Promise.all([r.list(`object`,{packageId:e}),r.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let a=(n||[]).map(e=>({type:`object`,name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of i)e.name&&!o.has(e.name)&&a.push({type:`object`,name:e.name,label:e.name});s(a),d(e=>e??a[0]??null),a.length===0&&L(!0)}catch(e){t||_(pu(e))}finally{t||l(!0)}})(),()=>{t=!0}},[r,e]),$.useEffect(()=>{if(!u)return;let e=`${u.name}#${t}`;if(P.current===e)return;P.current=e;let n=!1;return h(!0),_(null),y(null),x(!1),(async()=>{try{let[e,t]=await Promise.all([r.layered(`object`,u.name),r.getDraft(`object`,u.name).catch(()=>null)]);if(n)return;let i=e,a=i.effective??i.code??{},o=Hu(t);p(o?{...a,...o}:a),w(!!o),V(!!(i.effective??i.code))}catch(e){n||_(pu(e))}finally{n||h(!1)}})(),()=>{n=!0}},[r,u,t]);let ce=$.useMemo(()=>$i(f.fields).entries.length,[f]),le=$.useCallback(e=>{p(t=>({...t,...e})),x(!0)},[]),H=$.useCallback(()=>{let e=$i(f.fields),t=Ju(e.entries.map(e=>e.name));e.entries.push(oa(t,`text`,Z(`engine.studio.data.newFieldLabel`,a))),p(t=>({...t,fields:na(e)})),x(!0),y({kind:`field`,id:t})},[f]),ue=$.useCallback(async()=>{let t=R.trim(),i=Zi(ne.trim()||t);if(!(!t||!i||i===`field`)){if(o.some(e=>e.name===i)){_(ia(`engine.studio.data.idExists`,a,{name:i}));return}oe(!0),_(null);try{let o=gu(i,t,Z(`engine.studio.data.nameFieldLabel`,a));await r.save(`object`,i,o,{mode:`draft`,packageId:e});let c={type:`object`,name:i,label:t};s(e=>[...e,c]),d(c),A(`form`),N(`layout`),L(!1),te(``),B(``),ie(!1),n?.()}catch(e){_(pu(e))}finally{oe(!1)}}},[R,ne,o,r,e,n]),U=$.useCallback(async()=>{if(u){E(`draft`),_(null);try{await r.save(`object`,u.name,f,{mode:`draft`,packageId:e}),w(!0),x(!1),n?.()}catch(e){_(pu(e))}finally{E(!1)}}},[r,u,f,n]),de=$.useCallback(async t=>{if(!u)return;let i=$i(f.fields),a=new Set(t),o=t.map(e=>i.entries.find(t=>t.name===e)).filter(e=>!!e),s=0,c=i.entries.map(e=>a.has(e.name)?o[s++]:e),l={...f,fields:na({...i,entries:c})};p(l),E(`draft`),_(null);try{await r.save(`object`,u.name,l,{mode:`draft`,packageId:e}),w(!0),x(!1),n?.(),O(e=>e+1)}catch(e){_(pu(e))}finally{E(!1)}},[r,u,f,n]),W=gi(`object`);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[u?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:u.label}),(0,Q.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:[`object · `,u.name]}),(0,Q.jsx)(`span`,{children:ia(`engine.studio.data.fieldCount`,a,{count:ce})})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,a)}),C&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,a)}),(0,Q.jsxs)(`button`,{onClick:U,disabled:!u||!b||!!T,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[T===`draft`?(0,Q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,a)]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`nav`,{className:`flex w-52 shrink-0 flex-col border-r`,children:[(0,Q.jsxs)(`div`,{className:`shrink-0 p-2 pb-1`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.data.objects`,a)}),(0,Q.jsx)(`input`,{value:ee,onChange:e=>F(e.target.value),placeholder:Z(`engine.studio.data.searchObjects`,a),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none placeholder:text-muted-foreground/70 focus:ring-1 focus:ring-primary`})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[o.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(g?`engine.studio.loadFailed`:c?`engine.studio.data.noObjects`:`engine.studio.loading`,a)}),o.filter(e=>!ee.trim()||e.label.toLowerCase().includes(ee.trim().toLowerCase())||e.name.toLowerCase().includes(ee.trim().toLowerCase())).map(e=>(0,Q.jsxs)(`button`,{onClick:()=>d(e),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(u?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(Nn,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},e.name))]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:I?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:R,onChange:e=>{te(e.target.value),re||B(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&L(!1)},placeholder:Z(`engine.studio.data.labelPlaceholder`,a),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:ne,onChange:e=>{ie(!0),B(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&L(!1)},placeholder:Z(`engine.studio.data.idPlaceholder`,a),className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void ue(),disabled:ae||!R.trim()||!Zi(ne.trim()||R)||Zi(ne.trim()||R)===`field`,className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[ae?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),Z(`engine.studio.createDraft`,a)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>L(!1),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,a)})]})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>L(!0),className:`inline-flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,a)]})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden p-4`,children:u?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex rounded-md border p-0.5 text-[11px]`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(`grid`),className:`rounded px-2.5 py-0.5 `+(k===`grid`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.tab.records`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(`form`),className:`rounded px-2.5 py-0.5 `+(k===`form`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.tab.form`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(`rules`),className:`rounded px-2.5 py-0.5 `+(k===`rules`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.tab.rules`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(`settings`),className:`rounded px-2.5 py-0.5 `+(k===`settings`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.tab.settings`,a)})]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,Q.jsx)(kn,{className:`h-3 w-3`}),` `,Z(k===`grid`?`engine.studio.data.badge.grid`:k===`rules`?`engine.studio.data.badge.rules`:k===`settings`?`engine.studio.data.badge.settings`:j===`layout`?`engine.studio.data.badge.formLayout`:`engine.studio.data.badge.formPreview`,a)]}),(k===`grid`||k===`form`)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:H,title:Z(`engine.studio.data.addFieldTitle`,a),className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,a)]})]}),g&&(0,Q.jsx)(`div`,{className:`mb-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:g}),k===`rules`?(0,Q.jsx)(ju,{draft:f,onPatch:le}):k===`settings`?(0,Q.jsx)(Mu,{name:u.name,draft:f,onPatch:le,locale:a}):k===`grid`&&!se?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.draftObjectTitle`,a)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.draftObjectHint`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{A(`form`),N(`layout`)},className:`mt-1 inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted`,children:Z(`engine.studio.data.goDesignFields`,a)})]}):k===`grid`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background`,children:(0,Q.jsx)(ze,{value:{onAddColumn:H,addColumnLabel:Z(`engine.studio.data.addField`,a),onEditColumn:e=>{$i(f.fields).entries.some(t=>t.name===e)&&y({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,a),onReorderFields:de},children:(0,Q.jsx)(M,{dataSource:i,children:(0,Q.jsx)(Pa,{schema:{type:`object-view`,objectName:u.name,table:{fields:$i(f.fields).entries.map(e=>e.name).filter(e=>!Yu.has(e))}},dataSource:i,renderListView:Xu},`${u.name}:${D}`)})})}),(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.data.gridHint`,a)]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex rounded-md border p-0.5 text-[11px]`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>N(`layout`),className:`rounded px-2.5 py-0.5 `+(j===`layout`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.layout`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>N(`preview`),className:`rounded px-2.5 py-0.5 `+(j===`preview`?`bg-muted font-medium`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.preview`,a)})]}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(j===`layout`?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.previewBadge`,a)}),j===`preview`&&(b||C)&&(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.data.form.previewWarn`,a)})]}),j===`layout`?(0,Q.jsx)(Ou,{draft:f,systemFieldNames:Yu,onChange:le,selectedField:v?.kind===`field`?v.id:null,onSelectField:e=>y({kind:`field`,id:e}),onAddField:H}):se?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`style`,{children:`
|
|
6
|
-
/* Design preview: the form is a click-to-select canvas, not a data-entry
|
|
7
|
-
* form. Disable interaction on field contents so a click anywhere on a
|
|
8
|
-
* field routes to its [data-field] wrapper (→ select), and neutralize the
|
|
9
|
-
* create/cancel footer so nothing is submittable here. */
|
|
10
|
-
.os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
|
|
11
|
-
.os-form-authoring [data-field] *{pointer-events:none;}
|
|
12
|
-
.os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
|
|
13
|
-
.os-form-authoring form > div:last-child:has(button){display:none;}
|
|
14
|
-
${v?.kind===`field`?`.os-form-authoring [data-field="${String(v.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
|
|
15
|
-
`}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-6`,children:(0,Q.jsx)(`div`,{className:`os-form-authoring mx-auto max-w-2xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&$i(f.fields).entries.some(e=>e.name===t)&&y({kind:`field`,id:t})},children:(0,Q.jsx)(M,{dataSource:i,children:(0,Q.jsx)(ur,{schema:{type:`object-form`,objectName:u.name,mode:`create`,fields:$i(f.fields).entries.map(e=>e.name).filter(e=>!Yu.has(e))},dataSource:i},`${u.name}:${D}:form`)})})}),(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.data.formHint`,a)]})]}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.form.noPublishedTitle`,a)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.form.noPublishedHint`,a)})]})]})]}):c&&o.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-16 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.firstObjectTitle`,a)}),(0,Q.jsx)(`p`,{className:`max-w-sm text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.firstObjectHint`,a)})]}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,a)})}),u&&v&&W&&(0,Q.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsx)(Wn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.fieldProps`,a)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.close`,a),children:(0,Q.jsx)(ln,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:$.createElement(W,{type:`object`,name:u.name,draft:f,selection:v,onPatch:le,onClearSelection:()=>y(null),onSelectionChange:y,readOnly:!1,locale:a})})]})]})]})}function Qu({state:e,locale:t}){if(!e)return null;let{enabled:n,bound:r}=e;return(0,Q.jsxs)(`span`,{title:Z(n?r?`engine.studio.auto.onBound`:`engine.studio.auto.onUnbound`:`engine.studio.auto.offTitle`,t),className:`inline-flex shrink-0 items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full `+(n?`bg-emerald-500`:`bg-muted-foreground/40`)}),(0,Q.jsx)(`span`,{className:`text-[10px] `+(n?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:Z(n?`engine.studio.auto.on`:`engine.studio.auto.off`,t)})]})}function $u({packageId:e,publishNonce:t=0,onDraftSaved:n}){let r=qi(),i=ca(),[a,o]=$.useState([]),[s,c]=$.useState(null),[l,u]=$.useState({}),[d,f]=$.useState(null),[p,m]=$.useState(!1),[h,g]=$.useState(!1),[_,v]=$.useState(!1),[y,b]=$.useState(null),[x,S]=$.useState(!1),[C,w]=$.useState(!1),[T,E]=$.useState(``),[D,O]=$.useState(``),[k,A]=$.useState(!1),j=yi(s?.type??``),M=gi(`flow`),N=!!j,[P,ee]=$.useState({});$.useEffect(()=>{let e=!1;return(async()=>{try{let t=await fetch(`/api/v1/automation/_status`,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)return;let n=await t.json().catch(()=>null),r=n?.data?.flows??n?.flows??[];if(e||!Array.isArray(r))return;let i={};for(let e of r)e?.name&&(i[e.name]={enabled:e.enabled!==!1,bound:!!e.bound});ee(i)}catch{}})(),()=>{e=!0}},[t]),$.useEffect(()=>{let t=!1;return(async()=>{try{let n=await hu(r,`flow`,e);if(t)return;o(n),c(e=>e??n[0]??null)}catch(e){t||b(pu(e))}finally{t||S(!0)}})(),()=>{t=!0}},[r,e,t]);let F=$.useCallback(async()=>{let t=T.trim(),a=Zi(D.trim()||t);if(!(!t||!a||a===`field`)){A(!0),b(null);try{let s=_u(a,t,Z(`engine.studio.auto.nodeStart`,i),Z(`engine.studio.auto.nodeEnd`,i));await r.save(`flow`,a,s,{mode:`draft`,packageId:e});let l={type:`flow`,name:a,label:t};o(e=>[...e.filter(e=>e.name!==a),l]),c(l),v(!0),w(!1),E(``),O(``),n?.(),X.success(ia(`engine.studio.auto.savedDraft`,i,{label:t}))}catch(e){b(pu(e))}finally{A(!1)}}},[T,D,r,e,n]);$.useEffect(()=>{if(!s)return;let e=!1;return m(!0),b(null),f(null),(async()=>{try{let[t,n]=await Promise.all([r.layered(`flow`,s.name),r.getDraft(`flow`,s.name).catch(()=>null)]);if(e)return;let i=t,a=i.effective??i.code??{},o=Hu(n);u(o?{...a,...o}:a),v(!!o)}catch(t){e||b(pu(t))}finally{e||m(!1)}})(),()=>{e=!0}},[r,s,t]);let I=$.useCallback(e=>u(t=>({...t,...e})),[]),L=$.useCallback(async()=>{if(s){g(`draft`),b(null);try{await r.save(`flow`,s.name,l,{mode:`draft`,packageId:e}),v(!0),n?.()}catch(e){b(pu(e))}finally{g(!1)}}},[r,s,l,n]),R=l.status!==`obsolete`&&l.status!==`invalid`,te=$.useCallback(async()=>{if(!s)return;let t=!(l.status!==`obsolete`&&l.status!==`invalid`),a={...l,status:t?`active`:`obsolete`};u(a),g(`draft`),b(null);try{await r.save(`flow`,s.name,a,{mode:`draft`,packageId:e}),v(!0),n?.(),X.success(Z(t?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,i))}catch(e){b(pu(e))}finally{g(!1)}},[r,s,l,e,n,i]);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,i)}),_&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,i)}),s&&(0,Q.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":R,onClick:te,disabled:!N||!!h,title:Z(R?`engine.studio.auto.disableTitle`:`engine.studio.auto.enableTitle`,i),className:`inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`relative inline-flex h-3.5 w-6 shrink-0 items-center rounded-full transition-colors `+(R?`bg-emerald-500`:`bg-muted-foreground/40`),children:(0,Q.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-white transition-transform `+(R?`translate-x-3`:`translate-x-0.5`)})}),Z(R?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,i)]}),(0,Q.jsxs)(`button`,{onClick:L,disabled:!s||!N||!!h,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[h===`draft`?(0,Q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,i)]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`nav`,{className:`flex w-52 shrink-0 flex-col overflow-auto border-r p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pb-1 pt-1`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.auto.heading`,i)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>w(e=>!e),title:Z(`engine.studio.auto.newTitle`,i),className:`inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Y,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),a.length>0&&a.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>c(e),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(s?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(nn,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,Q.jsx)(Qu,{state:P[e.name],locale:i})]},e.name)),a.length===0&&!C&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(y?`engine.studio.loadFailed`:x?`engine.studio.auto.none`:`engine.studio.loading`,i)}),C&&(0,Q.jsxs)(`div`,{className:`mt-1 space-y-1.5 rounded-md border bg-muted/30 p-2`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&w(!1)},placeholder:Z(`engine.studio.auto.namePlaceholder`,i),className:`w-full rounded border bg-background px-2 py-1 text-xs`}),(0,Q.jsx)(`input`,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&w(!1)},placeholder:Z(`engine.studio.auto.idPlaceholder`,i),className:`w-full rounded border bg-background px-2 py-1 font-mono text-[11px]`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void F(),disabled:!T.trim()||k,className:`inline-flex flex-1 items-center justify-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[k?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),Z(`engine.studio.createDraft`,i)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>w(!1),className:`rounded border px-2 py-1 text-[11px] hover:bg-muted`,children:Z(`engine.studio.cancel`,i)})]})]})]}),(0,Q.jsxs)(`main`,{className:`min-w-0 flex-1 overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,Q.jsx)(nn,{className:`h-3 w-3`}),` `,Z(`engine.studio.auto.canvasHint`,i)]}),s&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`flow · `,s.name]})]}),y&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:y}),(0,Q.jsx)(`div`,{className:`rounded-lg border bg-background p-4`,children:s?p?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,i)]}):j?$.createElement(j,{type:s.type,name:s.name,draft:l,editing:!0,selection:d,onSelectionChange:f,onPatch:I,locale:i}):(0,Q.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(l,null,2)}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.auto.pick`,i)})}),N&&(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.auto.editHint`,i)]})]}),(0,Q.jsxs)(`aside`,{className:`w-72 shrink-0 overflow-auto border-l`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsx)(Wn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,i)}),d&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,i),children:(0,Q.jsx)(ln,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`p-3`,children:d&&M&&s?$.createElement(M,{type:`flow`,name:s.name,draft:l,selection:d,onPatch:I,onClearSelection:()=>f(null),onSelectionChange:f,readOnly:!1,locale:i}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(Ze,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,i),(0,Q.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,i)]})})]})]})]})}function ed({packageId:e,publishNonce:t,onDraftSaved:n}){let r=qi(),i=ca(),[a,o]=$.useState([]),[s,c]=$.useState(!1),[l,u]=$.useState(null),[d,f]=$.useState(null),[p,m]=$.useState(``),[h,g]=$.useState(!1),[_,v]=$.useState(``),[y,b]=$.useState(``),[x,S]=$.useState(!1),[C,w]=$.useState(!1),T=$.useCallback(async()=>{try{let[t,n]=await Promise.all([r.list(`permission`,{packageId:e}),r.listDrafts({packageId:e,type:`permission`}).catch(()=>[])]),i=new Map;for(let e of t||[]){let t=String(e.name??e.id??``);t&&i.set(t,{name:t,label:String(e.label??e.name??``),isProfile:!!e.isProfile})}for(let e of n||[]){let t=String(e?.name??``);!t||i.has(t)||i.set(t,{name:t,label:t})}let a=[...i.values()];o(a),f(e=>e??a[0]?.name??null)}catch(e){u(pu(e))}finally{c(!0)}},[r,e]);$.useEffect(()=>{T()},[T,t]);let E=$.useCallback(async()=>{let t=_.trim(),a=Zi(y.trim()||t);if(!(!t||!a||a===`field`)){w(!0);try{await r.save(`permission`,a,yu(a,t),{mode:`draft`,packageId:e}),X.success(ia(`engine.studio.access.created`,i,{label:t})),g(!1),v(``),b(``),S(!1),n?.(),await T(),f(a)}catch(e){X.error(pu(e))}finally{w(!1)}}},[r,_,y,T,e,n,i]),D=a.filter(e=>!p.trim()||e.label.toLowerCase().includes(p.trim().toLowerCase())||e.name.toLowerCase().includes(p.trim().toLowerCase()));return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Qn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,i)}),(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,i)})]}),(0,Q.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,i),className:`ml-auto rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.access.banner`,i)})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`nav`,{className:`flex w-52 shrink-0 flex-col border-r`,children:[(0,Q.jsxs)(`div`,{className:`p-2 pb-0`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.heading`,i)}),(0,Q.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),placeholder:Z(`engine.studio.access.search`,i),className:`mb-1 h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[a.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(l?`engine.studio.loadFailed`:s?`engine.studio.access.none`:`engine.studio.loading`,i)}),D.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>f(e.name),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(d===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(Qn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isProfile&&(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1 py-px text-[9px] uppercase text-muted-foreground`,children:`profile`})]},e.name))]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:h?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:_,onChange:e=>{v(e.target.value),x||b(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&E(),e.key===`Escape`&&g(!1)},placeholder:Z(`engine.studio.access.labelPlaceholder`,i),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:y,onChange:e=>{S(!0),b(Qi(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&E(),e.key===`Escape`&&g(!1)},placeholder:Z(`engine.studio.access.idPlaceholder`,i),className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void E(),disabled:C||!_.trim()||!Zi(y.trim()||_)||Zi(y.trim()||_)===`field`,className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[C?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),Z(`engine.studio.create`,i)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,i)})]})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(!0),className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,i)]})})]}),(0,Q.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:d?(0,Q.jsx)(vi,{type:`permission`,name:d,packageId:e,publishNonce:t,onDraftSaved:n},d):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:s&&a.length===0?Z(`engine.studio.access.emptyMain`,i):Z(`engine.studio.access.pick`,i)})})]})]})}function td(){let e=h(),[t,n]=$.useState(null),[r,i]=$.useState(null),[a,o]=$.useState(!1),[s,c]=$.useState(``),[l,u]=$.useState(``),[d,f]=$.useState(!1),[p,m]=$.useState(!1);$.useEffect(()=>{let e=!1;return Pu().then(t=>{e||n(t)}).catch(t=>{e||i(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let g=t=>e(`/studio/${encodeURIComponent(t)}/data`),_=async()=>{let e=s.trim(),t=l.trim();if(!(!e||!Lu.test(t))){m(!0),i(null);try{await Fu(t,e),g(t)}catch(e){i(e instanceof Error?e.message:String(e))}finally{m(!1)}}},v=t?.filter(e=>e.writable)??[],y=t?.filter(e=>!e.writable)??[],[b,x]=$.useState(null),[S,C]=$.useState(``),[w,T]=$.useState(``),[E,D]=$.useState(!1),[O,k]=$.useState(null),A=e=>{x(e.id),C(`${e.name} 副本`),T(`${e.id}-copy`),k(null)},j=async()=>{if(!b)return;let e=w.trim(),t=S.trim();if(!(!Lu.test(e)||!t)){D(!0),k(null);try{await Iu(b,e,t),X.success(`已复制为可写软件包「${t}」`),g(e)}catch(e){k(e instanceof Error?e.message:String(e))}finally{D(!1)}}};return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(Qt,{className:`h-5 w-5 text-primary`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`应用构建`})]}),(0,Q.jsxs)(`p`,{className:`mb-5 text-xs leading-5 text-muted-foreground`,children:[`在一个`,(0,Q.jsx)(`b`,{children:`可写软件包`}),`里设计对象、表单、自动化与界面;编辑存为草稿,整包一次发布。 源码加载的软件包为只读(仅可浏览)。`]}),r&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive`,children:r}),(0,Q.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`我的软件包(可写)`}),(0,Q.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[t===null&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`加载中…`}),t!==null&&v.length===0&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`还没有可写软件包 — 从右侧新建一个开始。`}),v.map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border bg-background`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,Q.jsx)(Pn,{className:`h-4 w-4 shrink-0 text-primary`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]})]}),(0,Q.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:`可写`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b===e.id?x(null):A(e),title:`复制这个软件包为新的可写副本(Airtable 的 duplicate base)`,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(mn,{className:`h-3 w-3`}),` 复制`]})]}),b===e.id&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 border-t px-3 py-2.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&x(null)},placeholder:`副本名称`,className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:w,onChange:e=>T(e.target.value.toLowerCase().replace(/[^a-z0-9_.-]/g,``)),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&x(null)},placeholder:`副本包 ID`,className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),O&&(0,Q.jsx)(`p`,{className:`text-[10px] text-destructive`,children:O}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void j(),disabled:E||!S.trim()||!Lu.test(w.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[E?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(mn,{className:`h-3 w-3`}),`复制并进入构建器`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>x(null),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:`取消`})]})]})]},e.id)),a?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-lg border border-dashed bg-muted/20 px-3 py-2.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:s,onChange:e=>{if(c(e.target.value),!d){let t=Qi(e.target.value).replace(/_/g,`-`);u(t?`com.example.${t}`:``)}},onKeyDown:e=>{e.key===`Enter`&&_(),e.key===`Escape`&&o(!1)},placeholder:`名称(如:维修中心)`,className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(`input`,{value:l,onChange:e=>{f(!0),u(e.target.value.toLowerCase().replace(/[^a-z0-9_.-]/g,``))},onKeyDown:e=>{e.key===`Enter`&&_(),e.key===`Escape`&&o(!1)},placeholder:`包 ID(如:com.example.repairs)`,className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void _(),disabled:p||!s.trim()||!Lu.test(l.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[p?(0,Q.jsx)(z,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Y,{className:`h-3 w-3`}),`创建并开始构建`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:`取消`})]})]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(!0),className:`flex items-center justify-center gap-1.5 rounded-lg border border-dashed px-3 py-2.5 text-xs text-muted-foreground hover:border-primary/50 hover:text-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4`}),` 新建软件包`]})]}),y.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`已安装(只读 · 可浏览)`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:y.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(e.id),className:`flex items-center gap-2.5 rounded-lg border bg-muted/20 px-3 py-2.5 text-left hover:bg-muted/40`,children:[(0,Q.jsx)(Pn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px]`,children:e.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rr,{className:`h-2.5 w-2.5`}),` 只读`]})]},e.id))})]})]})}var nd=t({BuilderLanding:()=>td});export{so as C,ao as S,ms as _,kl as a,$a as b,ol as c,Yc as d,Jc as f,hs as g,bs as h,Kl as i,tl as l,vc as m,td as n,ul as o,Oc as p,Wu as r,ll as s,nd as t,el as u,no as v,oo as x,to as y};
|