@objectstack/console 17.1.0 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/dist/.objectstack-injection.json +2 -2
- package/dist/.objectui-sha +1 -1
- package/dist/assets/{AdapterProvider-3zTVoQKF.js → AdapterProvider-gULVLpjV.js} +1 -1
- package/dist/assets/AiPendingActionsPage-CyG11hX9.js +1 -0
- package/dist/assets/ApiConsolePage-DYuOp_W4.js +1 -0
- package/dist/assets/{AppDocsIndex-DVrJTsbv.js → AppDocsIndex-BXkNskk1.js} +1 -1
- package/dist/assets/AppManagementPage-BvSxDdA_.js +1 -0
- package/dist/assets/ApprovalsInboxPage-oep3a-Ek.js +1 -0
- package/dist/assets/AuditLogPage-BZZ6tzHu.js +1 -0
- package/dist/assets/ComponentNavView-Cq4wkNUa.js +1 -0
- package/dist/assets/{DashboardView-CTBV4_tx.js → DashboardView-C23ZCS2S.js} +1 -1
- package/dist/assets/{DeveloperHubPage-CWq2uYpr.js → DeveloperHubPage-KEpKc45V.js} +1 -1
- package/dist/assets/DocPage-Y4rWCZ3E.js +1 -0
- package/dist/assets/{DocShell-UFsFTSr-.js → DocShell-DMJHUgE5.js} +1 -1
- package/dist/assets/DocsIndex-Bb5OtPb3.js +1 -0
- package/dist/assets/DocsLayout-CoIVTMH_.js +1 -0
- package/dist/assets/DocsSlug-BARWHmXg.js +1 -0
- package/dist/assets/{ExpressionProvider-X1OAB_O-.js → ExpressionProvider-vGLngw8h.js} +1 -1
- package/dist/assets/FlowRunsPage-BeGa9_ge.js +1 -0
- package/dist/assets/{IntegrationsPage-DdKbqwGE.js → IntegrationsPage-DTXA-Nne.js} +2 -2
- package/dist/assets/{InterfaceListPage-FCdy-_Q-.js → InterfaceListPage-BMvedZyV.js} +1 -1
- package/dist/assets/{ManagedByBadge-Bap9_dqR.js → ManagedByBadge-mKmG0hP7.js} +1 -1
- package/dist/assets/MarketplaceAccessDenied-BBMyNu2w.js +1 -0
- package/dist/assets/{MarketplaceInstalledPage-Cv-qDRNA.js → MarketplaceInstalledPage-B4qrvb7w.js} +1 -1
- package/dist/assets/MarketplacePackagePage-BuVfVeBj.js +4 -0
- package/dist/assets/MarketplacePage-Cmltk5nG.js +1 -0
- package/dist/assets/{MetadataInspector-CNeJqkLQ.js → MetadataInspector-kVAu8vlh.js} +1 -1
- package/dist/assets/{MetadataProvider-DwMR1SMR.js → MetadataProvider-DyFZSNqq.js} +1 -1
- package/dist/assets/ObjectDataPage-BKHEYwXA.js +1 -0
- package/dist/assets/{PageView-XUBdr6tb.js → PageView-CTqS-VD9.js} +1 -1
- package/dist/assets/ProfilePage-CBUxXn5a.js +1 -0
- package/dist/assets/PublicFormsPage-B8Dk8fky.js +1 -0
- package/dist/assets/RecordDetailView-BBNqsNy9.js +11 -0
- package/dist/assets/{RecordFormPage-CLZcT8Z0.js → RecordFormPage-CeUmmc_n.js} +1 -1
- package/dist/assets/ReportDefaultInspector-CRjDi2Er.js +3 -0
- package/dist/assets/ReportView-Cwi_Po4H.js +2 -0
- package/dist/assets/{SearchResultsPage-lgNcs7l7.js → SearchResultsPage-Cg0oq2by.js} +1 -1
- package/dist/assets/{SettingsHub-TQOc7wH3.js → SettingsHub-B5_S9YgI.js} +1 -1
- package/dist/assets/{SettingsView-DAje5pDB.js → SettingsView-Csi1awf-.js} +1 -1
- package/dist/assets/SystemHubPage-CnDri9oU.js +1 -0
- package/dist/assets/{createDerive-xZXxMz1g.js → createDerive-B3AGnDaY.js} +1 -1
- package/dist/assets/dist-Ck19TqqJ.js +5 -0
- package/dist/assets/framework-BwfIhdyz.js +55 -0
- package/dist/assets/getIcon-1ZXs1v-a.js +1 -0
- package/dist/assets/{highlighted-body-OFNGDK62-DUQut-ZU.js → highlighted-body-OFNGDK62-CnGKNo0r.js} +1 -1
- package/dist/assets/i18n-rra-09wp.js +9 -0
- package/dist/assets/index-BLepsDd_.js +19 -0
- package/dist/assets/index-D26gl3rg.css +2 -0
- package/dist/assets/{infrastructure-CerjT_c2.js → infrastructure-BCTDJsqi.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-CR9PcY0X.js +1 -0
- package/dist/assets/metadata-admin-BE9_-F_f.js +25 -0
- package/dist/assets/plugin-calendar-BfY9ZunQ.js +1 -0
- package/dist/assets/plugin-charts-CmWL7Og-.js +7 -0
- package/dist/assets/plugin-chatbot-mxoQfkdx.js +120 -0
- package/dist/assets/plugin-dashboard-CzbAW1Rz.js +6 -0
- package/dist/assets/plugin-form-ItAwTFz-.js +1 -0
- package/dist/assets/plugin-gantt-DF5W5xkN.js +64 -0
- package/dist/assets/plugin-grid-B42Photo.js +9 -0
- package/dist/assets/plugin-kanban-Dh3HIJIm.js +1 -0
- package/dist/assets/{plugin-map-CQAe4Yh6.js → plugin-map-C1wSLqlB.js} +1 -1
- package/dist/assets/{plugin-markdown-7fyNN0UM.js → plugin-markdown-DNllWgPM.js} +1 -1
- package/dist/assets/{plugin-report-01bEGHuR.js → plugin-report-yfOfZPQg.js} +3 -3
- package/dist/assets/plugin-timeline-BpuaaqBd.js +1 -0
- package/dist/assets/{plugin-tree-DW0XC55y.js → plugin-tree-BrXE50se.js} +1 -1
- package/dist/assets/plugin-view-Jc0rkk7A.js +1 -0
- package/dist/assets/plugins-views-cOiN-mPq.js +4 -0
- package/dist/assets/{runtime-metadata-persistence-DpS5GXuQ.js → runtime-metadata-persistence-DTOJpVmd.js} +1 -1
- package/dist/assets/{skeletons-DVwGbFUS.js → skeletons-BwA1TSR2.js} +1 -1
- package/dist/assets/src-BLbFBP_B.js +1 -0
- package/dist/assets/{src-ClOOPIkS.js → src-DhAd4aY4.js} +1 -1
- package/dist/assets/ui-components-Dwq5utCl.js +42 -0
- package/dist/assets/ui-layout-DPFlQaQp.js +1 -0
- package/dist/assets/use-book-data-CZc8MJsb.js +1 -0
- package/dist/assets/{useActionModal-Z2yDiihK.js → useActionModal-DYiSBx1G.js} +1 -1
- package/dist/assets/usePackageL10n-D91-102Q.js +1 -0
- package/dist/assets/{useSettingsLabel-CvZKl8CQ.js → useSettingsLabel-CeZ36S4g.js} +1 -1
- package/dist/assets/vendor-objectstack-B1R3ym-9.js +264 -0
- package/dist/eager-closure.json +277 -0
- package/dist/index.html +54 -14
- package/package.json +1 -1
- package/dist/assets/AiPendingActionsPage-DD5DLXIK.js +0 -1
- package/dist/assets/ApiConsolePage-CSQNdOPN.js +0 -1
- package/dist/assets/AppManagementPage-vRCBT69X.js +0 -1
- package/dist/assets/ApprovalsInboxPage-Bft5QF0I.js +0 -1
- package/dist/assets/AuditLogPage-B-2e1YhN.js +0 -1
- package/dist/assets/ComponentNavView-BVbkfJfE.js +0 -1
- package/dist/assets/CreateViewDialog-CW0w7Nxc.js +0 -1
- package/dist/assets/FlowRunsPage-CUhBLwm-.js +0 -1
- package/dist/assets/MarketplaceAccessDenied-CrK7hygV.js +0 -1
- package/dist/assets/MarketplacePackagePage-CMS--SE2.js +0 -4
- package/dist/assets/MarketplacePage-njErv-tN.js +0 -1
- package/dist/assets/ObjectDataPage-BVV4yksz.js +0 -1
- package/dist/assets/ProfilePage-ClU0WVRr.js +0 -1
- package/dist/assets/PublicFormsPage-a_MNzdQw.js +0 -1
- package/dist/assets/RecordDetailView-uf81gH3J.js +0 -11
- package/dist/assets/ReportDefaultInspector-DU2azDYd.js +0 -3
- package/dist/assets/ReportView-oFhBKNBE.js +0 -2
- package/dist/assets/SystemHubPage-DUE-2-vc.js +0 -1
- package/dist/assets/componentRegistry-ByxoJqMW.js +0 -1
- package/dist/assets/dist-jor1XT9f.js +0 -5
- package/dist/assets/framework-LCCQTTcs.js +0 -47
- package/dist/assets/getIcon-Bnm_i39L.js +0 -1
- package/dist/assets/i18n-DGSduXFT.js +0 -9
- package/dist/assets/index-ZtYnn1PE.css +0 -2
- package/dist/assets/index-mpVXni3j.js +0 -2
- package/dist/assets/mermaid-GHXKKRXX-DQTMu5TJ.js +0 -1
- package/dist/assets/metadata-admin-C_DEFfDE.js +0 -25
- package/dist/assets/plugin-calendar-ClpbcK3u.js +0 -1
- package/dist/assets/plugin-charts-Cq0LpABN.js +0 -7
- package/dist/assets/plugin-chatbot-Cq7rZtnW.js +0 -120
- package/dist/assets/plugin-dashboard-C8Ohdrxi.js +0 -6
- package/dist/assets/plugin-form-B7CBtYvZ.js +0 -1
- package/dist/assets/plugin-gantt-ChkG9_UG.js +0 -64
- package/dist/assets/plugin-grid-D49BBhCX.js +0 -8
- package/dist/assets/plugin-kanban-BsTsRjoP.js +0 -1
- package/dist/assets/plugin-timeline-Dw4Lj2Rz.js +0 -1
- package/dist/assets/plugin-view-B9yCVdSX.js +0 -1
- package/dist/assets/plugins-views-BaBStVok.js +0 -4
- package/dist/assets/src-BA9h8a8o.js +0 -1
- package/dist/assets/src-Ctj_ivDh.js +0 -19
- package/dist/assets/ui-components-3mb69z8L.js +0 -42
- package/dist/assets/ui-layout-DpuFph25.js +0 -1
- package/dist/assets/use-book-data-BZg_051K.js +0 -1
- package/dist/assets/usePackageL10n-Cy-u65Zo.js +0 -1
- package/dist/assets/vendor-objectstack-DGpW4oR-.js +0 -158
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{_ as n,a as r,b as i,c as a,d as o,f as s,g as c,h as l,l as u,m as d,o as f,p,r as m,s as h,u as g}from"./vendor-react-CsWFRkED.js";import{S as _,_ as v,c as y,d as b,l as x,n as S,o as C,s as w,u as T,v as E,x as D}from"./infrastructure-CerjT_c2.js";import{Dn as O,En as k,It as A,Nn as j,Tn as M,Vt as N,cn as ee,sn as P,un as F,z as te}from"./vendor-objectstack-DGpW4oR-.js";import{A as I,Bt as ne,Ct as L,Dn as R,Dr as re,Et as z,F as ie,Ft as ae,Gr as oe,Ht as B,I as se,Ir as ce,Lt as le,M as ue,N as de,Qn as fe,S as pe,Sr as me,St as V,T as he,U as ge,V as _e,Xn as ve,_ as ye,_t as be,ar as xe,at as H,c as Se,dt as Ce,et as we,g as U,gt as Te,it as Ee,j as De,lt as W,p as Oe,s as ke,sr as G,ut as Ae,w as je,x as Me,xt as Ne,yr as Pe}from"./framework-LCCQTTcs.js";import{$a as Fe,$i as Ie,$o as Le,$t as Re,Aa as ze,An as Be,Ao as Ve,Ar as He,Bc as Ue,Cc as We,Cn as Ge,Cr as Ke,Dc as qe,Dn as Je,Ds as Ye,Ei as Xe,En as Ze,Es as Qe,Fi as $e,Fn as et,Fs as tt,Ga as nt,Gn as rt,Gr as it,Gs as at,Hc as ot,Hi as st,Hn as K,Hs as ct,Ht as lt,Ic as ut,Ii as dt,In as ft,Io as pt,Ir as mt,It as ht,Jn as gt,Jr as _t,Ka as vt,Ki as yt,Kn as bt,Kr as xt,Ks as St,La as Ct,Li as wt,Ln as Tt,Lr as Et,Mc as Dt,Mo as Ot,Nr as kt,O as At,On as jt,Os as Mt,Po as Nt,Pr as Pt,Pt as Ft,Q as It,Qc as Lt,Qn as Rt,Qr as q,Qs as zt,Rc as Bt,Ri as Vt,Rn as J,Rr as Ht,Rs as Ut,Si as Wt,Sn as Gt,Sr as Kt,Ti as qt,Tn as Jt,Tr as Yt,Ts as Xt,Ua as Zt,Un as Qt,Uo as $t,Ur as en,Us as tn,Ut as nn,V as rn,Vi as an,Vt as on,Wa as sn,Wn as cn,Wr as ln,Ws as un,Wt as dn,Xc as fn,Xi as pn,Xr as mn,Yi as hn,Yo as gn,Yr as _n,Za as vn,Zo as yn,_a as bn,_o as xn,_r as Sn,_t as Cn,aa as wn,ai as Tn,al as En,an as Dn,ao as On,at as kn,bc as An,bi as jn,bn as Mn,bo as Nn,br as Pn,ca as Fn,cc as In,ci as Ln,cn as Rn,dc as zn,dn as Bn,do as Vn,el as Hn,en as Un,es as Wn,fa as Gn,ga as Kn,gc as qn,gi as Jn,go as Yn,gr as Xn,ha as Zn,hc as Qn,hi as $n,hr as er,ia as tr,in as nr,io as rr,is as ir,jc as ar,jn as or,jo as sr,jr as cr,js as lr,kc as ur,kn as dr,ko as fr,li as pr,ln as mr,lo as hr,mi as gr,mo as _r,mr as vr,mt as yr,na as br,nc as xr,nn as Sr,nt as Cr,oa as wr,ol as Tr,ot as Er,pi as Dr,pl as Or,pn as kr,po as Ar,pr as jr,ps as Mr,pt as Nr,qa as Pr,qi as Fr,qn as Ir,qo as Lr,qr as Rr,ra as zr,ri as Br,rn as Vr,ro as Hr,rt as Ur,sc as Wr,si as Gr,ta as Kr,tc as qr,tn as Jr,tt as Yr,ua as Xr,uc as Zr,un as Qr,uo as $r,us as ei,vc as ti,vi as ni,vn as ri,vr as ii,vs as ai,vt as oi,wn as si,wr as ci,xa as li,xn as ui,xo as Y,xr as di,xt as fi,yc as pi,yi as mi,yn as hi,yo as gi,yr as _i,ys as vi,zo as yi,zr as bi,zs as xi}from"./ui-components-3mb69z8L.js";import{n as Si,r as X}from"./vendor-ui-utils-BFw4cGI6.js";import{r as Ci,t as wi}from"./AdapterProvider-3zTVoQKF.js";import{a as Ti,n as Ei,o as Di,s as Oi,t as ki}from"./plugin-form-B7CBtYvZ.js";import{a as Ai,i as ji,o as Mi,r as Ni,s as Pi,t as Fi}from"./MetadataProvider-DwMR1SMR.js";import{a as Ii,t as Li}from"./assistantBus-DNH-fDWN.js";import{n as Ri,r as zi,t as Bi}from"./ExpressionProvider-X1OAB_O-.js";import{C as Vi,D as Hi,E as Ui,F as Wi,H as Gi,L as Ki,O as qi,R as Ji,S as Yi,T as Xi,_ as Zi,a as Qi,b as $i,c as ea,d as ta,f as na,g as ra,h as ia,i as aa,l as oa,m as sa,o as ca,p as la,s as ua,t as da,u as fa,v as pa,x as ma,z as ha}from"./RecordDetailView-uf81gH3J.js";import{a as ga,i as _a,o as va,r as ya,s as ba,t as xa}from"./useActionModal-Z2yDiihK.js";import{a as Sa,i as Ca,n as wa,o as Ta,r as Ea,s as Da,t as Oa}from"./utils-CJ4UwXMF.js";import{C as ka,E as Aa,S as ja,T as Ma,_ as Na,b as Pa,d as Fa,f as Ia,g as La,h as Ra,i as za,l as Ba,m as Va,p as Ha,r as Ua,t as Wa,u as Ga,v as Ka,w as qa,x as Ja,y as Ya}from"./plugin-chatbot-Cq7rZtnW.js";import{A as Xa,C as Za,D as Qa,E as $a,O as eo,S as to,T as no,_ as ro,a as io,b as ao,c as oo,d as so,f as co,g as lo,h as uo,i as fo,j as po,k as mo,l as ho,m as go,n as _o,o as vo,p as yo,r as bo,s as xo,u as So,v as Co,w as wo,x as To,y as Eo}from"./metadata-admin-C_DEFfDE.js";import{C as Do,D as Oo,S as ko,r as Ao,x as jo,y as Mo}from"./MarketplaceAccessDenied-CrK7hygV.js";import{t as No}from"./preferLocal-CKqyhTP9.js";import{a as Po,i as Fo,n as Io,r as Lo,t as Ro}from"./ui-layout-DpuFph25.js";import{_ as zo,a as Bo,c as Vo,d as Ho,g as Uo,h as Wo,l as Go,n as Ko,o as qo,s as Jo,t as Yo,u as Xo,v as Zo,y as Qo}from"./vendor-dndkit-CkJ59XFL.js";import{n as $o}from"./plugin-grid-D49BBhCX.js";import{c as es,l as ts,o as ns,s as rs}from"./InterfaceListPage-FCdy-_Q-.js";import{t as is}from"./getIcon-Bnm_i39L.js";import{h as as,i as os,r as Z}from"./i18n-DGSduXFT.js";import{o as ss,s as cs}from"./createDerive-xZXxMz1g.js";import{G as ls,R as us,S as ds,U as fs,X as ps,Y as ms,Z as hs,ct as gs,dt as _s,ft as vs,gt as ys,ht as bs,it as xs,lt as Ss,mt as Cs,nt as ws,p as Ts,pt as Es,rt as Ds,st as Os,ut as ks,x as As}from"./ReportDefaultInspector-DU2azDYd.js";import{n as js,t as Ms}from"./CreateViewDialog-CW0w7Nxc.js";import{d as Ns}from"./plugins-views-BaBStVok.js";import{c as Ps,d as Fs,l as Is,u as Ls}from"./plugin-view-B9yCVdSX.js";import{n as Rs,t as zs}from"./MetadataInspector-CNeJqkLQ.js";import{o as Bs,r as Vs,t as Hs}from"./runtime-metadata-persistence-DpS5GXuQ.js";import{n as Us}from"./ReportView-oFhBKNBE.js";import{t as Ws}from"./ManagedByBadge-Bap9_dqR.js";import"./RecordFormPage-CLZcT8Z0.js";import"./DashboardView-CTBV4_tx.js";import"./PageView-XUBdr6tb.js";import"./SearchResultsPage-lgNcs7l7.js";import"./MarketplacePage-njErv-tN.js";import{n as Gs}from"./MarketplacePackagePage-CMS--SE2.js";import"./MarketplaceInstalledPage-Cv-qDRNA.js";import{n as Ks}from"./componentRegistry-ByxoJqMW.js";var Q=m(),$=e(i(),1);function qs({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let s=p(),{appName:c}=l(),{t:u}=I(),d=`/apps/${c}`,{execute:f,loading:m,error:h,runner:g}=V({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:a,onToast:o});return(0,$.useEffect)(()=>{g.registerHandler(`create`,async()=>(r?.(null),{success:!0})),g.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(X.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0,silent:!0}):(X.error(u(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:u(`objectActions.noRecordId`)};let s=!1;if(e===`sys_permission_set`)try{s=(r.params?.record?.managed_by===void 0?await n.findOne(e,o):r.params.record)?.managed_by===`package`}catch{}try{return await n.delete(e,o),i?.(),X.success(s?u(`objectActions.resetPackageSetSuccess`,{defaultValue:`Permission set reset to its shipped baseline`}):u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0,silent:!0}}catch(n){return X.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1}}}),g.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&s(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),g.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[g,e,n,r,i,s,d,u,t]),{execute:f,create:(0,$.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,$.useCallback)(async(t,n)=>{let r=e===`sys_permission_set`&&n?.managed_by===`package`;return f({type:`delete`,confirmText:r?u(`objectActions.resetPackageSetConfirm`,{defaultValue:`This permission set ships with an installed package and cannot be removed. Deleting resets it to the shipped baseline and discards your environment customization. Continue?`}):u(`objectActions.deleteConfirm`),params:n?{recordId:t,record:n}:{recordId:t}})},[f,u,e]),navigateToView:(0,$.useCallback)(t=>{s(`${d}/${e}/view/${t}`)},[s,d,e]),navigateToRecord:(0,$.useCallback)(t=>{s(`${d}/${e}/record/${encodeURIComponent(t)}`)},[s,d,e]),loading:m,error:h}}function Js(e){return e==null?[]:Array.isArray(e)?e:[e]}function Ys(e,t){let{alias:n,value:r=`1`,replace:i=!0}=t??{},[a,o]=c(),s=(0,$.useMemo)(()=>Js(n),[n]),l=(0,$.useCallback)(t=>t.get(e)===r||s.some(e=>t.get(e)===r),[e,r,s]),u=l(a),d=(0,$.useCallback)(t=>{if(t===l(a))return;let n=new URLSearchParams(a);if(t){n.set(e,r);for(let e of s)n.delete(e)}else{n.delete(e);for(let e of s)n.delete(e)}o(n,{replace:i})},[l,a,o,e,r,s,i]);return{open:u,setOpen:d,openOverlay:(0,$.useCallback)(()=>d(!0),[d]),closeOverlay:(0,$.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,$.useCallback)(()=>{o(t=>{let n=new URLSearchParams(t);if(l(n)){n.delete(e);for(let e of s)n.delete(e)}else{n.set(e,r);for(let e of s)n.delete(e)}return n},{replace:i})},[o,l,e,r,s,i])}}var Xs={info:(e,t)=>X.info(e,t),success:(e,t)=>X.success(e,t),warning:(e,t)=>X.warning(e,t),error:(e,t)=>X.error(e,t)};function Zs(e,t){let n=Xs[e.severity]??Xs.info,r=e.actions?.[0],i=ht(e.icon)?(0,Q.jsx)(Ft,{name:e.icon,className:`h-4 w-4`}):void 0,a=Ae(e,t),o=a?Er[a]:void 0;n(e.title,{description:e.message,duration:e.duration===0?1/0:e.duration,dismissible:e.dismissible,...i?{icon:i}:{},...o?{position:o}:{},...r?{action:{label:r.label,onClick:r.onClick}}:{}})}var Qs=(0,$.createContext)({theme:`system`,setTheme:()=>null});function $s({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===`auto`||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)(Qs.Provider,{...r,value:o,children:e})}var ec=()=>{let e=(0,$.useContext)(Qs);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function tc(){let e=((typeof document<`u`?document.documentElement.lang:``)||(typeof navigator<`u`?navigator.language:``)||`en`).toLowerCase().split(`-`)[0],t=De[e]?.console;return!t||t===de.console?de.console:{...de.console,...t,loadingSteps:{...de.console.loadingSteps,...t.loadingSteps},error:{...de.console.error,...t.error},actions:{...de.console.actions,...t.actions}}}function nc({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,$.useState)(0),o=tc(),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:jo()?(0,Q.jsx)(`img`,{src:jo(),alt:Do(),className:`h-10 w-10 object-contain`}):(0,Q.jsx)(tt,{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:Do()}),(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)(Zr,{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)(q,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(li,{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)(Nr,{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)(Wr,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Q.jsx)(Y,{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})]})]})})}var rc=Wi();function ic(){let{remediationRequired:e}=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)(oc,{message:e.message}):(0,Q.jsx)(cc,{message:e.message})})}):null}function ac(){let{signOut:e}=E(),{t}=I();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:t(`auth.remediation.signOut`)})}function oc({message:e}){let{changePassword:t,setRemediationRequired:n}=E(),{t:r}=I(),[i,a]=(0,$.useState)(``),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null);return(0,Q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),p(null),o!==c){p(r(`auth.remediation.password.mismatch`));return}d(!0);try{await t(i,o),n(null),window.location.reload()}catch(e){p(e instanceof Error?e.message:r(`auth.remediation.password.failed`)),d(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:r(`auth.remediation.password.title`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||r(`auth.remediation.password.fallbackMessage`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(K,{htmlFor:`rem-cur`,children:r(`auth.remediation.password.current`)}),(0,Q.jsx)(J,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(K,{htmlFor:`rem-new`,children:r(`auth.remediation.password.next`)}),(0,Q.jsx)(J,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(K,{htmlFor:`rem-conf`,children:r(`auth.remediation.password.confirm`)}),(0,Q.jsx)(J,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:c,onChange:e=>l(e.target.value),required:!0})]}),f?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:f}):null,(0,Q.jsx)(q,{type:`submit`,className:`w-full`,disabled:u,children:r(u?`auth.remediation.password.submitting`:`auth.remediation.password.submit`)}),(0,Q.jsx)(ac,{})]})}function sc({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,rc.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function cc({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=E(),{t:i}=I(),[a,o]=(0,$.useState)(`password`),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(``),[d,f]=(0,$.useState)(``),[p,m]=(0,$.useState)([]),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(null);return a===`password`?(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{let{totpURI:e,backupCodes:n}=await t(s);f(e),m(n??[]),o(`verify`)}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.enrollFailed`))}finally{g(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.title`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||i(`auth.remediation.mfa.fallbackMessage`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(K,{htmlFor:`rem-pw`,children:i(`auth.remediation.mfa.confirmPassword`)}),(0,Q.jsx)(J,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(q,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.preparing`:`auth.remediation.mfa.continue`)}),(0,Q.jsx)(ac,{})]}):(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{await n(l.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.invalidCode`)),g(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.scanTitle`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:i(`auth.remediation.mfa.scanBody`)})]}),d?(0,Q.jsx)(sc,{uri:d}):null,p.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:i(`auth.remediation.mfa.backupTitle`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:i(`auth.remediation.mfa.backupBody`)}),(0,Q.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:p.map(e=>(0,Q.jsx)(`span`,{children:e},e))})]}):null,(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(K,{htmlFor:`rem-code`,children:i(`auth.remediation.mfa.codeLabel`)}),(0,Q.jsx)(J,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:l,onChange:e=>u(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(q,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.verifying`:`auth.remediation.mfa.verify`)}),(0,Q.jsx)(ac,{})]})}function lc({children:e}){return o()?(0,Q.jsx)(uc,{children:e}):(0,Q.jsx)(Q.Fragment,{children:e})}function uc({children:e}){let t=p(),n=(0,$.useMemo)(()=>({navigate:(e,n)=>t(e,{replace:n?.replace??!1})}),[t]);return(0,Q.jsx)(ge,{value:n,children:e})}function dc(){let{user:e,session:t,refreshSession:n}=E(),{t:r}=I(),[i,a]=(0,$.useState)(!1),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(!1),u=(0,$.useMemo)(()=>D(),[]),d=t?.impersonatedBy,f=(0,$.useCallback)(async()=>{a(!0),s(null);try{let e=await u(`/api/v1/auth/admin/stop-impersonating`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:`{}`});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.message??`HTTP ${e.status}`)}await n()}catch(e){let t=e instanceof Error?e.message:String(e);s(t),X.error(r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:t}))}finally{l(!0),a(!1)}},[u,n,r]);if(!d)return null;let p=e?.name||e?.email||e?.id||``,m=c&&!i&&!o;return(0,Q.jsxs)(`div`,{role:`status`,"data-testid":`impersonation-banner`,className:`sticky top-0 z-50 flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-red-300/70 bg-red-50 px-4 py-2 text-sm text-red-900 dark:border-red-800/60 dark:bg-red-950/50 dark:text-red-100`,children:[(0,Q.jsx)(Jn,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:r(`impersonation.banner.message`,{defaultValue:`You are impersonating {{user}} — every action is recorded as them.`,user:p})}),` `,(0,Q.jsx)(`span`,{className:`opacity-80`,children:r(`impersonation.banner.startedBy`,{defaultValue:`Started by administrator {{admin}}.`,admin:d})})]}),(0,Q.jsx)(q,{size:`sm`,variant:`outline`,onClick:f,disabled:i,"data-testid":`impersonation-stop`,children:i?r(`impersonation.banner.stopping`,{defaultValue:`Stopping…`}):r(`impersonation.banner.stop`,{defaultValue:`Stop impersonating`})}),o?(0,Q.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-stop-error`,className:`w-full font-medium`,children:r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:o})}):null,m?(0,Q.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-not-restored`,className:`w-full font-medium`,children:r(`impersonation.banner.notRestored`,{defaultValue:`The server accepted the request but did not restore your administrator session — you are still impersonating {{user}}. Sign out and sign in again to end it.`,user:p})}):null]})}dc.displayName=`ImpersonationBanner`;function fc(){return(0,Q.jsx)(nc,{})}function pc({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=xa(e),i=Xi({dataSource:e});return(0,Q.jsxs)(Te,{context:i.actionProviderProps.context,onConfirm:i.actionProviderProps.onConfirm,onToast:i.actionProviderProps.onToast,onNavigate:i.actionProviderProps.onNavigate,onParamCollection:i.actionProviderProps.onParamCollection,onResultDialog:i.actionProviderProps.onResultDialog,onModal:n,handlers:{api:i.apiHandler,flow:i.flowHandler,script:i.serverActionHandler},children:[t,i.dialogs,r]})}function mc({children:e}){return(0,Q.jsx)(lc,{children:(0,Q.jsx)(hc,{children:e})})}function hc({children:e}){return(0,Q.jsx)($s,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(W,{config:{defaultDuration:4e3,maxVisible:4},onToast:Zs,children:(0,Q.jsx)(Yi,{children:(0,Q.jsx)(ha,{children:(0,Q.jsx)($i,{children:(0,Q.jsx)(Ki,{children:(0,Q.jsxs)(mo,{children:[(0,Q.jsx)(dc,{}),(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(fc,{}),children:e}),(0,Q.jsx)(ic,{}),(0,Q.jsx)(Cr,{}),(0,Q.jsx)(Yr,{})]})})})})})})})}function gc({children:e}){return(0,Q.jsx)(wi,{children:(0,Q.jsx)(Ai,{children:(0,Q.jsx)(vc,{children:e})})})}var _c=Ci(D({sameOriginOnly:!0}));function vc({children:e}){let t=Ee(),{language:n}=I(),{isLoading:r}=E(),i=(0,$.useRef)(null);return t&&i.current!==null&&i.current!==n&&t.clearCache?.(),t&&(i.current=n),!t||r?(0,Q.jsx)(fc,{}):(0,Q.jsx)(le,{dataSource:t,apiFetch:_c,children:(0,Q.jsxs)(Fi,{adapter:t,children:[(0,Q.jsx)(yc,{}),(0,Q.jsx)(pc,{dataSource:t,children:e})]},n)})}function yc(){let{user:e}=E(),t=Ee(),n=Gi();return(0,$.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null);return}let r=Se({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Se({dataSource:t,userId:e.id,key:`ui.recent`}),a=Se({dataSource:t,userId:e.id,key:`ui.flow.palette.recents`});return n(`favorites`,r),n(`recent`,i),n(`flowPaletteRecents`,a),()=>{n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null)}},[e?.id,t,n]),null}function bc({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r,getAuthConfig:i}=E(),[a,o]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let e=!1;return i().then(t=>{e||o(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||o(!1)}),()=>{e=!0}},[i]),r)return(0,Q.jsx)(fc,{});let s=n??[];if((s.length>0||t)&&!t)return(0,Q.jsx)(h,{to:`/organizations`,replace:!0});if(s.length===0&&!t){if(a===null)return(0,Q.jsx)(fc,{});if(a)return(0,Q.jsx)(h,{to:`/organizations`,replace:!0})}return(0,Q.jsx)(Q.Fragment,{children:e})}function xc({children:e,redirectTo:t=`/home`}){let{enabled:n,isLoading:r}=po();return r?(0,Q.jsx)(fc,{}):n?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(h,{to:t,replace:!0})}function Sc(){let e=s(),t=e.pathname.replace(/^\/system/,``),n=t?`/apps/setup/system${t}`:`/apps/setup/system`;return(0,Q.jsx)(h,{to:`${n}${e.search}${e.hash}`,replace:!0})}var Cc=`com.objectstack.setup`,wc=`setup`;function Tc(e){let t=e??[],n=t.find(e=>e?._packageId===`com.objectstack.setup`)??t.find(e=>e?.name===`setup`);return`/apps/${wa(n)??`com.objectstack.setup`}`}function Ec(){let{apps:e,loading:t}=H(),n=s();if(t)return(0,Q.jsx)(fc,{});let r=Tc(e);return(0,Q.jsx)(h,{to:`${r}${n.search}${n.hash}`,replace:!0})}function Dc({appLabel:e,onOpenDock:t}){let{t:n}=I(),{openSeq:r}=Ii(),i=(0,$.useRef)(r);return(0,$.useEffect)(()=>{r!==i.current&&(i.current=r,t())},[r,t]),(0,Q.jsx)(`button`,{type:`button`,"aria-label":n(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e}),onClick:t,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 Oc(e){let t=e?.issues;return Array.isArray(t)?t:[]}function kc(e){return`• ${e.path&&e.path.length>0?e.path:`(root)`} — ${e.message}`}function Ac(e){let t=Oc(e);return t.length>0?t.map(kc).join(`
|
|
3
|
-
`):e?.message??String(e)}var jc=`batch_aborted`;function Mc(e){let t=e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${kc(e)}`)].join(`
|
|
4
|
-
`),n=e.filter(e=>e.code===jc);if(n.length>0){let r=e.filter(e=>e.code!==jc);return[`Nothing was published — the batch rolled back (all-or-nothing).`,...r.length>0?r.map(t):n.slice(0,1).map(t),`(${n.length} other draft${n.length===1?``:`s`} aborted with it — fix the cause and publish again.)`].join(`
|
|
5
|
-
`)}return e.map(t).join(`
|
|
6
|
-
`)}var Nc=[`sys_`,`ai_`,`cloud_`],Pc=[`formula`,`summary`,`autonumber`];function Fc(e){let t=e?.fields??e?.data?.fields??e?.item?.fields??{};return(Array.isArray(t)?t.map(e=>[e?.name,e]):Object.entries(t)).map(([e,t])=>({name:t?.name??e,label:t?.label??t?.name??e,type:t?.type??`text`,required:!!t?.required,options:t?.options})).filter(e=>e.name&&!Pc.includes(e.type))}function Ic({file:e,dataSource:t,defaultObjectName:n,onDone:r}){let{t:i}=I(),a=(0,$.useMemo)(()=>D(),[]),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(n??``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1,t=``.replace(/\/+$/,``);return(async()=>{try{let r=await a(`${t}/api/v1/meta/object`,{method:`GET`,credentials:`include`});if(!r.ok)throw Error(String(r.status));let i=await r.json().catch(()=>null),o=i?.data?.items??i?.items??i?.data??(Array.isArray(i)?i:[]),u=(Array.isArray(o)?o:[]).map(e=>({name:e?.name,label:e?.label||e?.name})).filter(e=>e.name&&!Nc.some(t=>e.name.startsWith(t)));if(e)return;if(s(u),!c&&u.length){let e=n&&u.find(e=>e.name===n);l(e?n:u[0].name)}}catch{e||s([])}})(),()=>{e=!0}},[a,n]);async function g(){if(c){d(!0);try{let e=Fc(await t.getObjectSchema(c));if(!e.length){X.error(i(`excelImport.noImportableFields`));return}p(e),h(!0)}catch{X.error(i(`excelImport.schemaReadFailed`))}finally{d(!1)}}}let _=o?.find(e=>e.name===c)?.label??c;return m&&f?(0,Q.jsx)($o,{open:m,onOpenChange:e=>{h(e),e||r()},objectName:c,objectLabel:_,fields:f,dataSource:t,initialFile:e,onComplete:e=>{X.success(i(`excelImport.imported`,{count:e.importedRows,object:_}))}}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm`,"data-excel-import-bar":!0,children:[(0,Q.jsx)(mt,{variant:`secondary`,children:`CSV / Excel`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.importFrom`)}),(0,Q.jsx)(`code`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.into`)}),(0,Q.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:c,onChange:e=>l(e.target.value),disabled:!o||o.length===0,children:(o??[]).map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label},e.name))}),(0,Q.jsx)(q,{size:`sm`,onClick:g,disabled:!c||u,children:i(u?`excelImport.opening`:`excelImport.importAction`)}),(0,Q.jsx)(q,{size:`sm`,variant:`ghost`,onClick:r,children:i(`excelImport.dismiss`)})]})}function Lc(){let{theme:e,setTheme:t}=ec(),{t:n}=I();return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(wt,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(rr,{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)(cn,{align:`end`,children:[(0,Q.jsxs)(bt,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(wt,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(bt,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(rr,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(bt,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(On,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function Rc(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function zc(e){return e===void 0?Rc().toString():new URL(`.`,e).toString()}function Bc(e,t){return new URL(e.replace(/^\//,``),zc(t)).toString()}function Vc(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Hc({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:Vc(e)})}function Uc(){let{t:e}=I(),t=p(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:a}=E(),[o,s]=(0,$.useState)(!1),c=ts()===`group`;(0,$.useEffect)(()=>{let e=!1;return a?.().then(t=>{e||s(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[a]);let l=n??[],u=r??l[0]??null;if(!u||l.length<=1)return null;let d=async e=>{if(e.id!==u.id)try{await i(e.id),window.location.href=zc()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(Rt,{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)(Hc,{name:u.name}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:u.name}),(0,Q.jsx)(zn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,Q.jsxs)(cn,{align:`start`,className:`w-60`,children:[(0,Q.jsx)(Ir,{className:`text-xs text-muted-foreground`,children:c?e(`organization.switcher.groupLabel`,{defaultValue:`Working organization`}):e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),c&&(0,Q.jsx)(`p`,{className:`px-2 pb-1.5 text-xs font-normal leading-snug text-muted-foreground`,"data-testid":`workspace-switcher-group-hint`,children:e(`organization.switcher.groupHint`,{defaultValue:`New records are created here. Views show data from all your organizations.`})}),l.map(e=>(0,Q.jsxs)(bt,{onClick:()=>d(e),className:`cursor-pointer gap-2`,children:[(0,Q.jsx)(Hc,{name:e.name}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===u.id&&(0,Q.jsx)(pi,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,Q.jsx)(gt,{}),(0,Q.jsxs)(bt,{onClick:()=>t(`/organizations/${u.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,Q.jsx)(Dr,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!o&&(0,Q.jsxs)(bt,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,Q.jsx)(ze,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}function Wc(){let{t:e}=I(),{organizations:t,activeOrganization:n}=E(),r=ts();if(!es(r))return null;let i=t??[];if(i.length!==1)return null;let a=n??i[0]??null;if(!a)return null;let o=e(`organization.current.label`,{defaultValue:`Current organization`});return(0,Q.jsxs)(`span`,{"data-testid":`current-organization-indicator`,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`,title:`${o}: ${a.name}`,children:[(0,Q.jsx)(Hc,{name:a.name}),(0,Q.jsx)(`span`,{className:`sr-only`,children:o}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:a.name})]})}var Gc=new Map([[`en`,`English`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`de`,`Deutsch`],[`fr`,`Français`],[`es`,`Español`],[`pt`,`Português`],[`ru`,`Русский`],[`ar`,`العربية`]]);function Kc(e){let t=Gc.get(e);if(t)return t;try{let t=new Intl.DisplayNames([e],{type:`language`}).of(e);return!t||t===e?e:t.charAt(0).toLocaleUpperCase(e)+t.slice(1)}catch{return e}}function qc(){let{t:e,language:t,changeLanguage:n,offerableLanguages:r}=I();return r===null?null:(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(yn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(cn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:r.map(e=>(0,Q.jsxs)(bt,{onClick:()=>n(e),className:`gap-2`,children:[Kc(e),t===e&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e))})]})}var Jc={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Wr},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting…`,color:`text-yellow-500`,icon:Y},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting…`,color:`text-yellow-500`,icon:Y},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:Ln},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:Ln}};function Yc({state:e,className:t}){let n=Jc[e],{t:r}=I(),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:Tr(`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:Tr(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Xc(e,t){if(!e)return``;let n=new Date(e).getTime();return Number.isNaN(n)?``:C(n,t)}function Zc(e){let t=[],n=new Map;for(let r of e){let e=(r.type??``).trim(),i=(r.title??``).trim(),a=e||i?`${e}\u0000${i}`:`__row__${r.id}`,o=n.get(a);o||(o={key:a,type:r.type,title:r.title,items:[],unreadCount:0,latestCreatedAt:r.created_at},n.set(a,o),t.push(o)),o.items.push(r),r.is_read||(o.unreadCount+=1),r.created_at&&(!o.latestCreatedAt||r.created_at>o.latestCreatedAt)&&(o.latestCreatedAt=r.created_at)}return t}function Qc({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a,onMarkManyRead:o}){let{t:s,language:c}=I(),u=p(),d=l(),{currentAppName:f}=Vi(),{apps:m}=H(),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(`notifications`),[y,b]=(0,$.useState)(`unread`),[x,S]=(0,$.useState)(()=>new Set),C=(0,$.useMemo)(()=>Zc(e),[e]).reduce((e,t)=>e+ +(t.unreadCount>0),0),w=C+n,T=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),E=(0,$.useRef)(null),[D,O]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=E.current;if(e!==null&&w>e){O(!0);let e=window.setTimeout(()=>O(!1),1200);return()=>window.clearTimeout(e)}E.current=w},[w]),(0,$.useEffect)(()=>{D||(E.current=w)},[D,w]);let k=()=>{g(!1);let e=f??d.appName;u(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},A=Ta(m,f??d.appName),j=()=>{g(!1),u(`/apps/${A}/sys_inbox_message?view=mine`)},M=()=>{g(!1),u(`/apps/${A}/sys_activity`)},N=e=>{a(e.id);let t=Da(e.action_url,A);if(!t){j();return}if(g(!1),t.kind===`external`){window.open(t.url,`_blank`,`noopener,noreferrer`);return}u(t.path)},ee=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=e=>{let t=e.items.filter(e=>!e.is_read).map(e=>e.id);t.length!==0&&(o?o(t):t.forEach(a))},F=(e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>N(e),className:`w-full text-left ${t?`pl-9 pr-3 py-2`:`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:Xc(e.created_at,c)})]})]})});return(0,Q.jsxs)(et,{open:h,onOpenChange:g,children:[(0,Q.jsx)(Tt,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${D?`motion-safe:animate-bounce`:``}`,"aria-label":T,title:s(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,Q.jsx)(ot,{className:`h-4 w-4`}),w>0&&(0,Q.jsx)(`span`,{"data-testid":`inbox-bell-badge`,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:w>9?`9+`:w},w)]})}),(0,Q.jsxs)(ft,{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`})}),_===`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`})})]}),w>0&&(0,Q.jsxs)(`div`,{"data-testid":`inbox-badge-breakdown`,className:`flex flex-wrap items-center gap-x-2 gap-y-1 px-3 pb-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-total`,className:`font-medium text-foreground`,children:s(`notifications.badgeTotal`,{defaultValue:`{{total}} total`,total:w})}),(0,Q.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,Q.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-notifications`,children:s(`notifications.badgeNotifications`,{defaultValue:`{{unread}} notifications`,unread:C})}),(0,Q.jsx)(`span`,{"aria-hidden":!0,children:`+`}),(0,Q.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-approvals`,children:s(`notifications.badgeApprovals`,{defaultValue:`{{approvals}} pending approvals`,approvals:n})})]}),(0,Q.jsxs)(on,{value:_,onValueChange:e=>v(e),className:`w-full`,children:[(0,Q.jsxs)(nn,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(dn,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(ot,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),C>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:C>9?`9+`:C},`notif-${C}`)]}),(0,Q.jsxs)(dn,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Fr,{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)(dn,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(En,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity feed`})]})]}),(0,Q.jsxs)(lt,{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:()=>b(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${y===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),C>0&&(0,Q.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:C})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>b(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${y===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=y===`unread`?e.filter(e=>!e.is_read):e;if(t.length===0)return(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:y===`unread`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})});let n=Zc(t);return(0,Q.jsx)(`ul`,{className:`divide-y`,children:n.map((e,t)=>{let n={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`}};if(e.items.length===1)return(0,Q.jsx)(`li`,{...n,children:F(e.items[0],!1)},e.key);let r=x.has(e.key);return(0,Q.jsxs)(`li`,{...n,children:[(0,Q.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ee(e.key),"aria-expanded":r,className:`flex-1 min-w-0 text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.unreadCount>0?`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.unreadCount>0?`opacity-100`:`opacity-0`}`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),(0,Q.jsxs)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 text-[10px] font-medium leading-4 text-muted-foreground`,"aria-label":s(`notifications.groupCount`,{defaultValue:`{{count}} notifications`,count:e.items.length}),children:[`×`,e.items.length]})]}),e.items[0].body&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-1 mt-0.5`,children:e.items[0].body}),(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[Xc(e.latestCreatedAt,c),e.unreadCount>0&&(0,Q.jsxs)(`span`,{className:`ml-1`,children:[`·`,` `,s(`notifications.groupUnread`,{defaultValue:`{{count}} unread`,count:e.unreadCount})]})]})]}),(0,Q.jsx)(qn,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 ${r?`rotate-90`:``}`,"aria-hidden":!0})]})}),e.unreadCount>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>P(e),className:`shrink-0 px-2 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l`,title:s(`notifications.groupMarkReadTitle`,{defaultValue:`Mark all of this type read`}),children:s(`notifications.groupMarkRead`,{defaultValue:`Mark read`})})]}),r&&(0,Q.jsx)(`ul`,{className:`divide-y border-t bg-muted/20`,children:e.items.map(e=>(0,Q.jsx)(`li`,{children:F(e,!0)},e.id))})]},e.key)})})})(),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:j,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Q.jsx)(lt,{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)(Fr,{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)(q,{size:`sm`,className:`mt-3`,onClick:k,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:k,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Q.jsxs)(lt,{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:[Xc(e.timestamp,c),` · `,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:M,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function $c({activeAppName:e,onAppChange:t}){let{apps:n}=H(),{t:r}=I(),{appLabel:i}=je(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=Sa(o,e)||Sa(a.filter(e=>e.active!==!1),e)||o[0];if(!s)return null;let c=i({name:s.name,label:Oa(s.label,r)});return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`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:c}),(0,Q.jsx)(ti,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(cn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(Ir,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(gt,{}),o.map(e=>{let n=is(e.icon),a=i({name:e.name,label:Oa(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(bt,{onClick:()=>t(wa(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)(pi,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]})}var el=(0,$.createContext)(null);function tl({children:e}){let[t,n]=(0,$.useState)(null),r=(0,$.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(el.Provider,{value:r,children:e})}function nl(){return(0,$.useContext)(el)?.value??null}function rl(e){let t=(0,$.useContext)(el),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 il(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),[]);rl((0,$.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var al=(0,$.createContext)(null);function ol({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=Ys(Qi,{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)(al.Provider,{value:o,children:e})}function sl(){return(0,$.useContext)(al)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}var cl=3e4,ll=1e4,ul=6e4,dl=12e4,fl=3e4,pl=6e4,ml=[],hl=[],gl=class{empty;pollMs;snapshot;key=null;listeners=new Set;runner=null;consumers=0;inFlight=!1;unavailable=!1;retiredAt=0;probesLeft=3;fetchedAt=0;timer=null;backoffMs;visibilityBound=!1;constructor(e,t){this.empty=e,this.pollMs=t,this.snapshot={value:e,status:`idle`},this.idleSnapshot=this.snapshot,this.backoffMs=t}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;idleSnapshot;attach(e,t){return e!==this.key&&(this.key=e,this.unavailable=!1,this.retiredAt=0,this.probesLeft=3,this.fetchedAt=0,this.backoffMs=this.pollMs,this.publish(this.empty,`idle`)),this.runner=t,this.consumers+=1,this.consumers===1&&(this.bindVisibility(),this.schedule()),this.refresh(),()=>{this.consumers=Math.max(0,this.consumers-1),this.consumers===0&&(this.stopPolling(),this.unbindVisibility())}}async refresh(e=!1){let t=this.runner;if(!t||this.inFlight)return;let n=this.unavailable;if(n&&!this.mayProbe()||!e&&!n&&this.fetchedAt&&Date.now()-this.fetchedAt<fl)return;this.inFlight=!0,this.snapshot.status===`idle`&&this.publish(this.snapshot.value,`loading`);let r=!1;try{let e=await t({markUnavailable:()=>n?this.spendProbe():this.retire(),markFailed:()=>{r=!0}});e===void 0?r&&(n?this.spendProbe():this.fail()):(this.unavailable=!1,this.probesLeft=3,this.fetchedAt=Date.now(),this.backoffMs=this.pollMs,this.publish(e,`ready`))}catch{n?this.spendProbe():this.fail()}finally{this.inFlight=!1,this.consumers>0&&this.schedule()}}mayProbe(){return this.probesLeft>0&&Date.now()-this.retiredAt>=6e4}retire(){this.unavailable=!0,this.retiredAt=Date.now(),this.fetchedAt=Date.now(),this.stopPolling(),this.publish(this.snapshot.value,`ready`)}spendProbe(){this.probesLeft=Math.max(0,this.probesLeft-1),this.retiredAt=Date.now(),this.fetchedAt=Date.now(),this.stopPolling()}fail(){this.backoffMs=Math.min(Math.max(this.backoffMs,this.pollMs)*2,dl),this.publish(this.snapshot.value,`error`)}schedule(){if(this.timer)return;if(this.unavailable){if(this.probesLeft<=0)return;this.timer=setTimeout(()=>{this.timer=null,this.refresh(!0)},pl);return}if(this.pollMs<=0)return;let e=typeof document<`u`&&document.hidden?Math.max(ul,this.backoffMs):this.backoffMs;this.timer=setTimeout(()=>{this.timer=null,this.refresh(!0)},e)}onVisibilityChange=()=>{typeof document>`u`||document.hidden||this.consumers!==0&&(this.unavailable&&!this.mayProbe()||(this.stopPolling(),this.unavailable||(this.backoffMs=this.pollMs),this.refresh(!0)))};bindVisibility(){this.pollMs<=0||this.visibilityBound||typeof document>`u`||(document.addEventListener(`visibilitychange`,this.onVisibilityChange),this.visibilityBound=!0)}unbindVisibility(){!this.visibilityBound||typeof document>`u`||(document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.visibilityBound=!1)}stopPolling(){this.timer&&=(clearTimeout(this.timer),null)}publish(e,t){if(!(Object.is(e,this.snapshot.value)&&t===this.snapshot.status)){this.snapshot={value:e,status:t};for(let e of[...this.listeners])e()}}reset(){this.stopPolling(),this.unbindVisibility(),this.snapshot={value:this.empty,status:`idle`},this.key=null,this.runner=null,this.consumers=0,this.inFlight=!1,this.unavailable=!1,this.retiredAt=0,this.probesLeft=3,this.fetchedAt=0,this.backoffMs=this.pollMs}};function _l(e,t,n){let r=(0,$.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot),i=(0,$.useRef)(n);return(0,$.useEffect)(()=>{i.current=n}),(0,$.useEffect)(()=>{if(t)return e.attach(t,e=>i.current(e))},[e,t]),t?r:e.idleSnapshot}var vl=new gl(0,cl);function yl(e){let t=e,n=[];t?.id&&n.push(t.id),t?.email&&n.push(t.email);for(let e of t?.roles??[])e&&n.push(`role:${e}`);return n}function bl(){let{user:e}=E(),t=yl(e);return _l(vl,e?.id&&t.length>0?t.join(`,`):null,async({markUnavailable:e,markFailed:n})=>{let r=``.replace(/\/$/,``),i=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),a=await fetch(`${r}/api/v1/approvals/requests?${i}`,{credentials:`include`,headers:sa()});if(a.status===404){e();return}if(!a.ok){n();return}let o=await a.json().catch(()=>null),s=new Set;for(let e of o?.data||[])s.add(e.id);return s.size}).value}var xl=new gl(ml,0),Sl=new WeakMap,Cl=0;function wl(e){if(!e||typeof e!=`object`)return null;let t=Sl.get(e);return t||(t=`adapter@${++Cl}`,Sl.set(e,t)),t}function Tl(e){return e.filter(e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.type==`string`&&String(t.summary??``).trim().length>0}).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:String(e.object_name??``),recordId:e.record_id==null?void 0:String(e.record_id),user:String(e.actor_name??``),description:String(e.summary??``),timestamp:t??``}})}function El(e){let t=e;return t?.httpStatus===404||t?.status===404||ve(e,`OBJECT_NOT_FOUND`)}function Dl(){let e=Ee();return _l(xl,wl(e),async({markUnavailable:t,markFailed:n})=>{if(!e)return;let r=await Promise.resolve(e.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20})).catch(e=>(El(e)?t():n(),null));if(r)return Tl(Array.isArray(r.data)?r.data:[])}).value}function Ol(e){let t=Dl();return(0,$.useMemo)(()=>t.filter(e=>{let t=e.user.trim();return t.length>0&&t.toLowerCase()!==`system`}).slice(0,e),[t,e])}var kl=new gl(hl,ll),Al=new Set([`read`,`clicked`,`dismissed`]);function jl(e,t){let n=new Map;for(let e of t){let t=e,r=t?.notification_id==null?``:String(t.notification_id);if(!r)continue;let i=String(t?.state??``),a=n.get(r);(!a||!Al.has(a.state)&&Al.has(i))&&n.set(r,{id:String(t?.id),state:i})}return e.map(e=>{let t=e,r=t?.notification_id==null?null:String(t.notification_id),i=r?n.get(r):void 0;return{id:String(t.id),notification_id:r,receipt_id:i?.id??null,type:t.topic??`notification`,title:t.title??``,body:t.body_md??null,action_url:t.action_url??null,is_read:i?Al.has(i.state):!1,created_at:t.created_at}})}function Ml(){let e=Ee(),{user:t}=E(),n=t?.id,r=wl(e);return _l(kl,r&&n?`${r}:${n}`:null,async({markUnavailable:t,markFailed:r})=>{if(!(!e||!n))try{let[t,r]=await Promise.all([Promise.resolve(e.find(`sys_inbox_message`,{$filter:{user_id:n},$orderby:{created_at:`desc`},$top:20})),Promise.resolve(e.find(`sys_notification_receipt`,{$filter:{user_id:n,channel:`inbox`},$top:200})).catch(()=>({data:[]}))]);return jl(Array.isArray(t?.data)?t.data:[],Array.isArray(r?.data)?r.data:[])}catch(e){El(e)?t():r();return}})}var Nl=$.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=kr(),{t:s}=I(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(q,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:Tr(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(nt,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});Nl.displayName=`LocalizedSidebarTrigger`;function Pl({className:e}){let{t}=I(),n=ko();if(n!==`preview`&&n!==`beta`)return null;let r=n===`beta`?t(`topbar.stage.beta`,{defaultValue:`Beta`}):t(`topbar.stage.preview`,{defaultValue:`Preview`}),i=t(`topbar.stage.tooltip`,{defaultValue:`This platform is in preview — features may change.`});return(0,Q.jsx)(mt,{variant:`secondary`,title:i,"aria-label":i,"data-testid":`platform-preview-badge`,className:Tr(`shrink-0 cursor-default select-none rounded-md px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,e),children:r})}function Fl(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Il(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Ll=[],Rl=new Set;function zl({variant:e,appName:t,objects:n,connectionState:i,presenceUsers:a,activities:o,activeAppName:c,onAppChange:u}){let d=e??(t?`app`:`home`),f=d===`app`,m=s(),h=l(),g=p(),{isOnline:_}=se(),{openCommandPalette:y}=sl(),{openOverlay:x}=Ys(ca),{user:S,signOut:C,isAuthEnabled:w,organizations:T,activeOrganization:D,isOrganizationsLoading:O,getAuthConfig:k}=E(),A=Ee(),{enabled:j}=po(),M=v(),{t:N}=I(),{objectLabel:ee,dashboardLabel:P,pageLabel:F,reportLabel:te,viewLabel:ne,appLabel:L}=je(),{apps:R,dashboards:re,pages:z,reports:ie}=H(),{currentAppName:ae,recordTitle:oe}=Vi(),B=nl(),[ce,le]=(0,$.useState)(null),ue=(0,$.useCallback)(async()=>{if(ce===null)try{let e=A?.getClient?.();if(!e?.meta?.getItems){le([]);return}let t=await e.meta.getItems(`doc`),n=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[];le(n.map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{le([])}},[ce,A]),de=Dl(),{value:fe}=Ml(),[pe,me]=(0,$.useState)(Rl),V=(0,$.useMemo)(()=>pe.size===0?fe:fe.map(e=>pe.has(e.id)?{...e,is_read:!0}:e),[fe,pe]),he=bl(),ge=V.reduce((e,t)=>e+ +!t.is_read,0),_e=(0,$.useCallback)(async(e,t)=>{let n=``.replace(/\/$/,``);await fetch(`${n}/api/v1/notifications/${e}`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,...sa()},body:JSON.stringify(t?{ids:t}:{})})},[]),ve=(0,$.useCallback)(e=>{e.length!==0&&me(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})},[]),ye=(0,$.useCallback)(async e=>{let t=V.find(t=>t.id===e);if(ve([e]),t?.notification_id)try{await _e(`read`,[t.notification_id])}catch{}},[V,ve,_e]),be=(0,$.useCallback)(async()=>{if(V.filter(e=>!e.is_read).length){ve(V.map(e=>e.id));try{await _e(`read/all`)}catch{}}},[V,ve,_e]),xe=(0,$.useCallback)(async e=>{let t=new Set(e),n=V.filter(e=>t.has(e.id)&&!e.is_read).map(e=>e.notification_id).filter(e=>!!e);if(ve(e),n.length)try{await _e(`read`,n)}catch{}},[V,ve,_e]),Se=ia(),Ce=a??(Se.length>0?Se:Ll),we=o??de,U=O||(T??[]).length>0||!!D,[Te,De]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return k?.().then(t=>{e||De(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[k]);let W=m.pathname.split(`/`).filter(Boolean),Oe=h.appName||W[1],ke=W[2],G=`/apps/${Oe}`,Ae=n??[],Me=Sa(R||[],c||ae||Oe),Ne=new Set,Pe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ne.add(t.objectName),t.children&&Pe(t.children)};Pe(Me?.navigation||[]);for(let e of Me?.areas||[])Pe(e.navigation||[]);let Fe=Ne.size>0?Ae.filter(e=>Ne.has(e.name)):Ae.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Ie=Me?._packageId,Le=Ie?(ce??[]).filter(e=>e._packageId===Ie):[],Re=f?Ea(Me,M,{type:ke,name:W[3]}):null,Be=Fe.map(e=>({label:ee(e),href:`${G}/${e.name}`})),Ve=[];if(f){if(ke===`dashboard`){if(Ve.push({label:N(`console.breadcrumb.dashboards`),href:G}),W[3]){let e=W[3],t=No(re,e,Me?._packageId)?.label||Fl(e);Ve.push({label:P({name:e,label:t})})}}else if(ke===`page`){if(Ve.push({label:N(`console.breadcrumb.pages`),href:G}),W[3]){let e=W[3],t=No(z,e,Me?._packageId)?.label||Fl(e);Ve.push({label:F({name:e,label:t})})}}else if(ke===`report`){if(Ve.push({label:N(`console.breadcrumb.reports`),href:G}),W[3]){let e=W[3],t=No(ie,e,Me?._packageId)?.label||Fl(e);Ve.push({label:te({name:e,label:t})})}}else if(ke===`system`)Ve.push({label:N(`console.breadcrumb.system`)}),W[3]&&Ve.push({label:Fl(W[3])});else if(ke){let e=Ae.find(e=>e.name===ke);if(e){if(W[3]===`record`&&W[4]){let e=la(new URLSearchParams(m.search).get(ta));e.forEach((t,n)=>{let r=Ae.find(e=>e.name===t.o);Ve.push({label:r?ee(r):Fl(t.o),href:`${G}/${t.o}`});let i=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;Ve.push({label:t.t||`#${i}`,href:na(G,t,e.slice(0,n))})})}if(Ve.push({label:ee(e),href:`${G}/${ke}`,siblings:Be}),W[3]===`record`&&W[4]){let e=W[4].length>12?`${W[4].slice(0,8)}…`:W[4],t=oe?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Ve.push({label:n||`#${e}`})}else if(W[3]===`view`&&W[4]){let t=W[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Fl(t),i=ne(e.name,t,r);Ve.push({label:i})}}}}let He=Ve[Ve.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)(r,{to:`/home`,className:Tr(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors overflow-hidden`,f&&`hidden sm:flex`),title:Do(),children:jo()?(0,Q.jsx)(`img`,{src:jo(),alt:Do(),className:`h-full w-full object-contain`}):(0,Q.jsx)(Ot,{className:`h-4 w-4`})}),d===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:Do()}),(0,Q.jsx)(Pl,{className:`ml-2 hidden sm:inline-flex`}),(0,Q.jsx)(Uc,{}),(0,Q.jsx)(Wc,{}),d===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Il,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:N(`organizations.title`,{defaultValue:`Workspaces`})})]}),f&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Nl,{className:`lg:hidden shrink-0 ml-1`,"aria-label":N(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),c&&u?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Il,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)($c,{activeAppName:c,onAppChange:u})})]}):t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Il,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Ve.map((e,t)=>{let n=t===Ve.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(Il,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(Rt,{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)(ti,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(cn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(Ir,{className:`text-xs text-muted-foreground font-normal`,children:N(`topbar.switchObject`,{defaultValue:`Switch Object`})}),(0,Q.jsx)(gt,{}),e.siblings.map(e=>(0,Q.jsx)(bt,{asChild:!0,children:(0,Q.jsx)(r,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Q.jsx)(r,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,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)}),B&&B.views.length>0?B.views.length>1?(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Rt,{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":N(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Q.jsx)(`span`,{className:`truncate max-w-[180px]`,children:B.triggerLabel??B.views.find(e=>e.id===B.activeViewId)?.label??He}),(0,Q.jsx)(ti,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(cn,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:B.views.map(e=>{let t=e.id===B.activeViewId;return(0,Q.jsxs)(bt,{onSelect:()=>{t||B.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)(Nn,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(pi,{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:B.triggerLabel??B.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:He})]})]}),(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:[!_&&(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`}),N(`topbar.offline`,{defaultValue:`Offline`})]}),f&&i&&(0,Q.jsx)(Yc,{state:i}),f&&Ce.length>0&&(0,Q.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:N(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Q.jsx)(ra,{users:Ce,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":N(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:y,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)(Fn,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:N(`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)(q,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:y,"aria-label":N(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(Fn,{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)(Qc,{notifications:V,unreadCount:ge,pendingApprovalsCount:he,activities:we,onMarkAllRead:be,onMarkRead:ye,onMarkManyRead:xe}),Re&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"data-testid":`app-design-in-studio-button`,"aria-label":N(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:N(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,Q.jsx)(r,{to:Re,children:(0,Q.jsx)(Lr,{className:`h-4 w-4`})})}),j&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":N(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Q.jsx)(r,{to:`/ai`,children:(0,Q.jsx)(Bt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Qt,{onOpenChange:e=>{e&&ue()},children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":N(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Q.jsx)(xr,{className:`h-4 w-4`})})}),(0,Q.jsxs)(cn,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Le.length>0&&Ie?(0,Q.jsxs)(bt,{className:`cursor-pointer`,onClick:()=>g(Le.length===1?`/apps/${Ie}/docs/${Le[0].name}`:`/apps/${Ie}/docs`),children:[(0,Q.jsx)(Ue,{className:`mr-2 h-4 w-4`}),N(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(bt,{className:`cursor-pointer`,onClick:()=>g(`/docs`),children:[(0,Q.jsx)(Ot,{className:`mr-2 h-4 w-4`}),N(`help.allDocs`,{defaultValue:`All documentation`})]}),f?(0,Q.jsxs)(bt,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:x,children:[(0,Q.jsx)(Nt,{className:`mr-2 h-4 w-4`}),N(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,Q.jsx)(gt,{}),(0,Q.jsx)(bt,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(Ye,{className:`mr-2 h-4 w-4`}),N(`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)(Qt,{children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(Et,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(bi,{src:S?.image,alt:S?.name??`User`}),(0,Q.jsx)(Ht,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:b(S)})]})})}),(0,Q.jsxs)(cn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(Ir,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(Et,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(bi,{src:S?.image,alt:S?.name??`User`}),(0,Q.jsx)(Ht,{className:`rounded-lg bg-primary text-primary-foreground`,children:b(S)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:S?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:S?.email??``})]})]})}),(0,Q.jsx)(gt,{}),(0,Q.jsxs)(rt,{children:[(0,Q.jsxs)(bt,{onClick:()=>g(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(gr,{className:`mr-2 h-4 w-4`}),N(`user.profile`,{defaultValue:`Profile`})]}),U&&(0,Q.jsxs)(bt,{onClick:()=>g(`/organizations?manage=1`),className:`cursor-pointer`,"data-testid":`header-my-organizations`,children:[(0,Q.jsx)(ar,{className:`mr-2 h-4 w-4`}),N(`organizations.mine`,{defaultValue:`My Workspaces`})]}),U&&!Te&&(0,Q.jsxs)(bt,{onClick:()=>g(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,Q.jsx)(ze,{className:`mr-2 h-4 w-4`}),N(`organizations.create`,{defaultValue:`Create workspace`})]}),(R||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=is(e.icon),n=L({name:e.name,label:Oa(e.label,N)});return(0,Q.jsxs)(bt,{onClick:()=>g(`/apps/${wa(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)(gt,{}),(0,Q.jsx)(Ir,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:N(`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:N(`user.theme`,{defaultValue:`Theme`})}),(0,Q.jsx)(Lc,{})]}),(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:N(`user.language`,{defaultValue:`Language`})}),(0,Q.jsx)(qc,{})]}),w&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(gt,{}),(0,Q.jsxs)(bt,{className:`text-destructive focus:text-destructive`,onClick:()=>C(),children:[(0,Q.jsx)(gi,{className:`mr-2 h-4 w-4`}),N(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Bl=`ai-chat-dock-width`,Vl=`ai-chat-dock-expanded`,Hl=`ai-chat-studio-dock-expanded`,Ul=`ai-chat-studio-dock-width`;function Wl(e,t){let n=t>0?Math.max(340,t-520):1/0;return Math.min(Math.max(e,340),n)}function Gl(e){return Wl(e,e)}function Kl(e){return e===`1`||e!==`0`&&null}function ql(e,t){try{let n=Kl(window.sessionStorage.getItem(e));return n===null?t:n}catch{return t}}function Jl(e,t){try{window.sessionStorage.setItem(e,t?`1`:`0`)}catch{}}function Yl(){Jl(Vl,!0)}var Xl=`ai-chat-dock-return-to`;function Zl(e){try{window.sessionStorage.setItem(Xl,e)}catch{}}function Ql(){try{let e=window.sessionStorage.getItem(Xl);return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:void 0}catch{return}}function $l(e){return!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey?null:e.key.toLowerCase()===`i`?`toggle`:null}async function eu(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function tu(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{}}}function nu(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}var ru=`objectstack:ai-chat-conversation-id`,iu=`objectstack:ai-chat-messages`;function au(e,t){return t?`${ru}:${e}:${t}`:`${ru}:${e}`}function ou(e){try{return localStorage.getItem(e)??void 0}catch{return}}function su(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function cu(e){return`${iu}:${e}`}function lu(){try{let e=[];for(let t=0;t<localStorage.length;t+=1){let n=localStorage.key(t);n&&(n.startsWith(ru)||n.startsWith(iu))&&e.push(n)}e.forEach(e=>localStorage.removeItem(e))}catch{}}function uu(e){try{let t=localStorage.getItem(cu(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function du(e,t){if(e)try{if(t.length===0){localStorage.removeItem(cu(e));return}localStorage.setItem(cu(e),JSON.stringify(t))}catch{}}function fu(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.draftReview?tu(n.draftReview):n.proposedPlan?nu(n.proposedPlan):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function pu(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?pu(e.parts):[]}function mu(e,t){for(let n of pu(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function hu(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){mu(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=pu(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function gu(e){if(!(typeof e!=`string`||!e))try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function _u(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=gu(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=gu(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function vu(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function yu(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function bu(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function xu(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`,legacyScope:s,adoptLegacy:c}=e,l=(0,$.useRef)(c);l.current=c;let[u,d]=(0,$.useState)(void 0),[f,p]=(0,$.useState)([]),[m,h]=(0,$.useState)(!!t),g=(0,$.useRef)(!0),_=(0,$.useRef)(void 0),v=(0,$.useRef)(void 0),y=(0,$.useRef)(t);(0,$.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,$.useEffect)(()=>{let e=y.current;y.current=t,e&&e!==t&&lu()},[t]),(0,$.useEffect)(()=>{if(!t){d(void 0),p([]),h(!1),_.current=void 0,v.current=void 0;return}let e=v.current!==n;if(!i&&!a&&!e&&_.current===t&&u)return;let c=!1,f=au(t,n);return!i&&(a||e&&_.current===t)&&(d(void 0),p([])),h(!0),(async()=>{let e=i;try{if(i){let a=await vu(r,i);if(c)return;if(a){su(f,a.id),d(a.id);let e=hu(a.messages),r=e.length>0?e:uu(a.id);(r.length>0||a.id!==u)&&p(r),_.current=t,v.current=n;return}e=void 0,su(f,void 0),du(i,[])}else if(!a){let i=ou(f);if(e=i,!i&&s&&l.current){let e=ou(au(t,s));if(e){try{let i=await vu(r,e);if(c)return;if(i){let e=hu(i.messages),r=e.length>0?e:uu(i.id);if(l.current?.(r)){su(f,i.id),d(i.id),p(r),_.current=t,v.current=n;return}}}catch{}if(c)return}}if(i){let a=await vu(r,i);if(c)return;if(a){let r=hu(a.messages);if(o!==`fresh`||r.length===0){d(a.id),p(o===`fresh`?[]:r.length>0?r:uu(a.id)),_.current=t,v.current=n;return}e=void 0}else e=void 0,su(f,void 0),du(i,[])}}let m=await yu(r);if(c)return;su(f,m.id),d(m.id),p(hu(m.messages)),_.current=t,v.current=n}catch{if(c||e&&e===u)return;d(void 0),p([])}finally{c||h(!1)}})(),()=>{c=!0}},[t,n,r,i,a,o,s]);let b=(0,$.useCallback)(async()=>{if(!t)return;let e=au(t,n);h(!0);try{u&&await bu(r,u),du(u,[]),su(e,void 0);let t=await yu(r);if(su(e,t.id),du(t.id,[]),!g.current)return;d(t.id),p([])}catch{g.current&&(d(void 0),p([]))}finally{g.current&&h(!1)}},[u,t,n,r]),x=(0,$.useCallback)(async()=>{if(!t)return;let e=au(t,n);h(!0);try{let i=await yu(r);if(su(e,i.id),du(i.id,[]),!g.current)return;d(i.id),p([]),_.current=t,v.current=n}catch{}finally{g.current&&h(!1)}},[t,n,r]),S=(0,$.useCallback)(e=>{!t||!u||(su(au(t,e),u),_.current=t,v.current=e)},[t,u]);return{conversationId:u,conversationScope:v.current,initialMessages:f,isLoading:m,reset:b,startNew:x,rekeyScope:S}}function Su(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function Cu(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,$.useState)(!1),a=(0,$.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,$.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=hu((await vu(r,n))?.messages);if(Su(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,$.useCallback)(()=>i(!1),[])}}function wu(e){return e&&La(e)?`build`:`ask`}function Tu({appId:e,product:t}){return e?`app:${e}:${t}`:t}var Eu=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function Du(e){let t=e?.trim().toLowerCase();return!t||Eu.has(t)}function Ou(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=ku(n.content);if(e)return e}}let n=t[t.length-1];return ku(n?.content)}function ku(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return ku(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function Au(e){let t=e.title?.trim(),n=Ou(e)??ku(e.preview);return{id:e.id,title:Du(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function ju(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return Au(`conversation`in r&&r.conversation?r.conversation:r)}function Mu(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)(!!t),[l,u]=(0,$.useState)(void 0),[d,f]=(0,$.useState)(0),p=(0,$.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,$.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,$.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,$.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map(Au).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>ju(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}function Nu(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Date.now()-n.getTime(),i=6e4,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 Pu(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var Fu=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Iu={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function Lu(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=864e5,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 Fu.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function Ru({userId:e,apiBase:t,activeAgent:n,className:r,refreshKey:i,titleHints:a,onNavigate:o}){let{t:s}=I(),c=p(),{conversationId:u}=l(),{conversations:d,isLoading:f,error:m,remove:h,rename:g}=Mu({userId:e,apiBase:t,refreshKey:i}),[_,v]=(0,$.useState)(``),[y,b]=(0,$.useState)(void 0),x=n?Va(n):void 0,S=(0,$.useMemo)(()=>n?new Set(Ha(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?Va(e.agentId):x;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[x]),D=(0,$.useCallback)(()=>{c(x?`/ai/${x}?new=1`:`/ai?new=1`),o?.()},[c,x,o]),O=(0,$.useCallback)(async(e,t)=>{e.stopPropagation(),await h(t),t===u&&(c(x?`/ai/${x}`:`/ai`,{replace:!0}),o?.())},[h,u,c,x,o]),k=(0,$.useCallback)(async(e,t)=>{b(void 0);try{await g(e,t)}catch{}},[g]);return(0,Q.jsxs)(`aside`,{className:Tr(`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:s(`console.ai.chats`)}),(0,Q.jsxs)(q,{size:`sm`,variant:`outline`,onClick:D,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(ze,{className:`h-3.5 w-3.5`}),s(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Fn,{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)(J,{value:_,onChange:e=>v(e.target.value),placeholder:s(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Q.jsx)(or,{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:s(`common.loading`)}):m?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:m.message}):w.length===0?(0,Q.jsxs)(Cn,{className:`px-3 py-8`,children:[(0,Q.jsx)($r,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(fi,{children:s(`console.ai.noChatsYet`)}),(0,Q.jsx)(oi,{children:s(`console.ai.noChatsDescription`)})]}):T.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:s(`console.ai.noMatchingChats`)}):(0,Q.jsx)(`div`,{className:`flex flex-col py-1`,children:Lu(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:s(`console.ai.group.${e.key}`,{defaultValue:Iu[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(Bu,{conversation:e,query:_.trim(),active:e.id===u,renaming:e.id===y,onSelect:()=>{c(E(e)),o?.()},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 zu(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 Bu({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=I(),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:Tr(`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)(J,{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)(q,{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)(pi,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,Q.jsx)(Tn,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:Tr(`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:zu(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:zu(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:Pu(e.updatedAt??e.createdAt),children:Nu(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)(q,{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)(Ct,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(q,{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)(qt,{className:`h-3.5 w-3.5`})})]})]})})}function Vu(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function Hu(e,t){let n=`${Vu()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function Uu({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:a}=I(),o=p(),s=(0,$.useRef)(null),c=t&&t.length?t:e;return(0,$.useEffect)(()=>{if(!s.current)return;let e=Hu(c,n);try{s.current.getAttribute(`src`)!==e&&s.current.setAttribute(`src`,e)}catch{}},[c,n]),(0,$.useEffect)(()=>{if(r>0)try{s.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)(Xt,{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)`})}),t&&(0,Q.jsxs)(q,{size:`sm`,variant:`ghost`,onClick:()=>o(`/studio/${t}/interfaces`),"data-testid":`live-canvas-open-designer`,className:`gap-1.5`,title:a(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),"aria-label":a(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:[(0,Q.jsx)(Lr,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:a(`topbar.designInStudio`,{defaultValue:`Design in Studio`})})]}),(0,Q.jsx)(q,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:s,title:`Draft preview: ${e}`,src:Hu(c,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}function Wu(e,t,n){let r=`/studio/${encodeURIComponent(e)}/${t}`;return n?`${r}?${to}=${encodeURIComponent(no(n))}`:r}function Gu(e,t){if(!e)return null;let n=t.name?.trim();if(!n)return null;switch(t.type){case`object`:return Wu(e,`data`,{type:`object`,name:n});case`flow`:return Wu(e,`automations`,{type:`flow`,name:n});case`dashboard`:return Wu(e,`interfaces`,{type:`dashboard`,name:n});case`page`:return Wu(e,`interfaces`,{type:`page`,name:n});case`view`:{let t=n.indexOf(`.`);return Wu(e,`interfaces`,{type:`object`,name:t>0?n.slice(0,t):n})}case`app`:return Wu(e,`interfaces`);default:return null}}async function Ku(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 qu({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),Ku(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)(Mn,{open:n,onOpenChange:r,children:(0,Q.jsxs)(ui,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(si,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Dt,{className:`h-4 w-4`}),` Build Doctor`]}),(0,Q.jsx)(Gt,{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)(Y,{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)(Wr,{className:`h-4 w-4`}):(0,Q.jsx)(Wt,{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)(Ju,{icon:(0,Q.jsx)(qr,{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)(Ju,{icon:(0,Q.jsx)(Wt,{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)(Ju,{icon:(0,Q.jsx)(zt,{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)(Yu,{entry:e},t))})]})]})]})]})})}function Ju({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 Yu({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})`:``]})}function Xu(e){if(typeof e.content==`string`)return e.content;let t=e.parts;return Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`?String(e.text??``):``).join(` `):``}function Zu(e){if(Array.isArray(e))for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.role!==`user`)continue;let r=Xu(n);if(r.trim())return/[一-鿿]/.test(r)?`zh-CN`:void 0}}function Qu(e){return(Zu(e)??``).toLowerCase().startsWith(`zh`)}var $u={planApproveMessage:{zh:`确认,开始搭建。`,en:`Looks good — build it as proposed.`},planApproveDefaultsMessage:{zh:`确认搭建,未决问题按你的合理假设和默认处理。`,en:`Build it with your best assumptions; use sensible defaults for the open questions.`},planAnswerMessage:{zh:`关于「{{question}}」,我选择「{{option}}」。`,en:`For "{{question}}", go with: {{option}}.`},changesConfirmMessage:{zh:`确认修改,应用你刚才提议的改动。`,en:`Confirm — apply the change you just proposed.`}};function ed(e,t){let n=e?.console?.ai?.[t];return typeof n==`string`&&n.trim()!==``?n:void 0}function td(e,t){return t?e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>Object.prototype.hasOwnProperty.call(t,n)?t[n]:e):e}function nd(e,t,n){let r=e?`zh`:`en`;return td(ed(e?ue:de,t)??$u[t][r],n)}var rd=`/api/v1/ai`;function id(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function ad(e){let t=id(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 od(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=id(r,`toolName`)??r.type.slice(5),a=id(r,`toolCallId`)??`${e.id}-${i}`,o=ad(r),s=r.output??r.result,c=qa(s),l=Aa(s),u=ka(s),d=Ma(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...l?{proposedPlan:l}:{},...u?{builderHandoff:u}:{},...d?{proposedChanges:d}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=ja(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function sd(e,t){if(t)return t;let n;for(let t of e)for(let e of t.toolInvocations??[]){let t=e.draftReview?.packageId||e.builderHandoff?.packageId;t&&(n=t)}return n}var cd=`com.objectstack.`;function ld(e){return typeof e._packageId==`string`&&e._packageId.startsWith(cd)}function ud(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var dd={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function fd(e,t,n){let r=t?dd[Va(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function pd(e,t,n){return La(t)?n?{title:n.appLabel?e(`console.ai.empty.editApp.title`,{defaultValue:`Editing “{{app}}”`,app:n.appLabel}):e(`console.ai.empty.editApp.titleGeneric`,{defaultValue:`Edit this app`}),description:e(`console.ai.empty.editApp.description`,{defaultValue:`What would you like to change? I’ll modify this app in place — add a field, object, view or automation, or adjust what’s already there.`})}:{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.`})}:Ra(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 md(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(/\/$/,``)}${rd}`}var hd=`ai-chats-collapsed`;function gd(){let[e,t]=(0,$.useState)(()=>{try{return localStorage.getItem(hd)===`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(hd,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 _d=`ai-chat-pane-width`,vd=480,yd=360,bd=420,xd=24;function Sd(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 Cd(e){let t=(0,$.useRef)(null),[n,r]=(0,$.useState)(()=>{try{let e=Number(localStorage.getItem(_d));return Number.isFinite(e)&&e>0?e:vd}catch{return vd}}),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(e=>Sd(e,{min:yd,previewMin:bd,containerWidth:t.current?.clientWidth??0}),[]),s=(0,$.useCallback)(e=>{try{localStorage.setItem(_d,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`?xd:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,$.useCallback)(()=>{let e=o(vd);r(e),s(e)},[o,s])}}function wd(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 Td(e,t){return t||(typeof e==`number`&&e>0?-1:`/home`)}var Ed=[];function Dd(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i,pendingSignal:a,agentRoute:o}=e,s=!!t;return(0,$.useEffect)(()=>{if(!s||!n)return;let e=r.current;e&&(e.targetAgentRoute&&e.targetAgentRoute!==o||(r.current=null,i(e.content,e.files)))},[s,n,r,i,a,o]),(0,$.useCallback)((e,t)=>{if(s&&!n){r.current={content:e,files:t};return}i(e,t)},[s,n,r,i])}function Od({apiBase:e,defaultAgent:t}={}){let{user:n}=E(),{t:r}=I(),i=n?.id,{agent:a,conversationId:o}=l(),[s]=c(),u=s.toString(),d=s.get(`new`)!==null,f=s.get(`package`)?.trim()||void 0,m=s.get(`handoffPrompt`)?.trim()||void 0,h=s.get(`parentConversationId`)?.trim()||void 0,g=p(),{setContext:_}=Vi();(0,$.useEffect)(()=>{_(`home`)},[_]);let v=(0,$.useMemo)(()=>md(e),[e]),y={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:b,isLoading:x,error:S,refetch:C}=Ia({apiBase:v}),w=(0,$.useMemo)(()=>b.map(e=>e.name),[b]),T=!x&&b.length===0,D=(0,$.useMemo)(()=>{if(!a)return!1;if(b.length!==0)return Ka(a,w)!==void 0},[a,b.length,w]),O=a?void 0:s.get(`agent`)??void 0,k=(0,$.useMemo)(()=>Fa(b,O??t??y),[b,O,t,y]),A=(0,$.useMemo)(()=>{if(b.length!==0)return a&&D?Ka(a,w):k},[b.length,a,D,w,k]),j=A?Va(A):void 0,M=!!(a&&D===!1&&Na(a)),N=a&&D===!1&&!M?a:void 0,ee=A?`${v}/agents/${encodeURIComponent(A)}/chat`:void 0,P=A?Tu({appId:f,product:wu(A)}):void 0,F=A?wu(A):void 0,te=f&&F===`build`&&P!==F?F:void 0,ne=(0,$.useCallback)(e=>!!f&&sd(od(e),void 0)===f,[f]),{conversationId:L,conversationScope:R,initialMessages:re,rekeyScope:z}=xu({userId:A?i:void 0,scope:P,apiBase:v,activeId:o??N,forceNew:d,legacyScope:te,adoptLegacy:te?ne:void 0}),ie=R===P,ae=ie?L:void 0,oe=ie?re:Ed;(0,$.useEffect)(()=>{if(b.length===0||!A)return;let e=Va(A),t=new URLSearchParams(u);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!a){g(`/ai/${e}${n}`,{replace:!0});return}if(M){g(`/ai/${e}${n}`,{replace:!0});return}if(D&&a!==e){let t=o?`/${encodeURIComponent(o)}`:``;g(`/ai/${e}${t}${n}`,{replace:!0})}},[b.length,A,a,D,M,o,u,g]),(0,$.useEffect)(()=>{if(N===void 0)return;let e=!1;return(async()=>{let t;try{t=(await vu(v,N))?.agentId??void 0}catch{}if(e)return;let n=Ka(t??``,w),r=Va(n??A??`ask`);g(`/ai/${r}/${encodeURIComponent(N)}`,{replace:!0})})(),()=>{e=!0}},[N,v,w,A,g]);let[B,se]=(0,$.useState)(0),[ce,le]=(0,$.useState)({}),[ue,de]=(0,$.useState)(!1),[fe,pe]=(0,$.useState)(!1),[me,V]=(0,$.useState)(!1),{collapsed:he,toggle:ge,handleCanvasOpenChange:_e}=gd();(0,$.useEffect)(()=>{let e=e=>{let t=wd(e);t&&(e.preventDefault(),t===`toggle-list`?ge():g(j?`/ai/${j}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[ge,g,j]);let ve=(0,$.useMemo)(()=>v.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[v]),ye=(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`},[]),be=(0,$.useRef)(null);d?be.current===null&&(be.current={id:L}):be.current=null,(0,$.useEffect)(()=>{if(!D||o||!L||!j||be.current&&be.current.id===L||R!==P)return;let e=f?`?package=${encodeURIComponent(f)}`:``;g(`/ai/${j}/${L}${e}`,{replace:!0})},[D,o,L,R,P,j,f,g]);let xe=(0,$.useCallback)(e=>{!e||f||F!==`build`||!j||P===F&&R===P&&(!L||o!==L||(z(Tu({appId:e,product:F})),g(`/ai/${j}/${encodeURIComponent(L)}?package=${encodeURIComponent(e)}`,{replace:!0})))},[f,F,j,P,R,L,o,z,g]),H=(0,$.useRef)(new Set);(0,$.useEffect)(()=>{L&&re.length>0&&H.current.add(L)},[L,re.length]),(0,$.useEffect)(()=>{if(!L)return;let e=ud(re);e&&le(t=>t[L]===e?t:{...t,[L]:e})},[L,re]);let Se=(0,$.useRef)(null),[Ce,we]=(0,$.useState)(0),U=(0,$.useCallback)(e=>{Se.current=e,we(e=>e+1)},[]),Te=(0,$.useRef)(null);(0,$.useEffect)(()=>{!m||a!==`build`||Te.current!==m&&(Te.current=m,U({content:m,targetAgentRoute:`build`}))},[m,a,U]);let Ee=(0,$.useCallback)(e=>{if(se(e=>e+1),e&&L&&le(t=>({...t,[L]:e})),!e||!L||H.current.has(L))return;H.current.add(L);let t=()=>se(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[L]);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:[!T&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>V(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(nt,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(zl,{variant:`home`})}),!T&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"data-testid":`ai-chat-collapse-to-dock`,"aria-label":r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),title:r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),onClick:()=>{Yl();let e=Td(window.history.state?.idx,Ql());g(e===-1?-1:e)},children:(0,Q.jsx)(Zt,{className:`h-4 w-4`})})]}),T?(0,Q.jsx)(kd,{hasError:!!S,onRetry:C,onHome:()=>g(`/home`),t:r}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Mn,{open:me,onOpenChange:V,children:(0,Q.jsxs)(ui,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(Ge,{className:`sr-only`,children:[(0,Q.jsx)(si,{children:r(`console.ai.chats`)}),(0,Q.jsx)(Gt,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(Ru,{userId:i,apiBase:v,activeAgent:A,refreshKey:B,titleHints:ce,className:`h-full border-r-0`,onNavigate:()=>V(!1)})]})}),L&&(0,Q.jsx)(It,{open:ue,onOpenChange:de,objectName:`ai_conversations`,recordId:L,recordLabel:`this conversation`,apiBase:ve,publicBaseUrl:ye}),L&&Ga(b,A,`debug`)&&(0,Q.jsx)(qu,{apiBase:v,conversationId:L,open:fe,onOpenChange:pe}),(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:[!he&&(0,Q.jsx)(Ru,{userId:i,apiBase:v,activeAgent:A,refreshKey:B,titleHints:ce,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,Q.jsx)(`div`,{className:Tr(`mt-auto p-2`,he?`w-12`:`w-72 border-t`),children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:ge,"aria-label":he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":he,children:he?(0,Q.jsx)(vt,{className:`h-4 w-4`}):(0,Q.jsx)(Pr,{className:`h-4 w-4`})})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Q.jsx)(Ad,{agents:b,agentsLoading:x,agentsError:S,activeAgent:A,chatApi:ee,apiBase:v,conversationId:ae,editPackageId:f,onPackageBound:xe,canBind:!!o,parentHandoffConversationId:h,initialMessages:oe,pendingFirstMessageRef:Se,pendingFirstMessageSeq:Ce,onSent:Ee,onShare:()=>de(!0),onDebug:()=>pe(!0),showDebug:Ga(b,A,`debug`),onCanvasOpenChange:_e},`${ee??`local`}:${ae??`pending`}`)})]})]})]})}function kd({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)(Cn,{children:[(0,Q.jsx)(fi,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,Q.jsx)(oi,{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)(q,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,Q.jsx)(q,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function Ad({agents:e,agentsLoading:t,agentsError:r,activeAgent:i,chatApi:a,apiBase:o,conversationId:s,editPackageId:c,onPackageBound:l,canBind:u,parentHandoffConversationId:d,initialMessages:f,pendingFirstMessageRef:m,pendingFirstMessageSeq:h,onSent:g,onShare:_,onDebug:v,showDebug:y,onCanvasOpenChange:b}){let{t:x}=I(),S=p(),C=e.length>1,w=(0,$.useCallback)(e=>{let t=new URLSearchParams,n=e.packageId||c;n&&t.set(`package`,n),e.prompt&&t.set(`handoffPrompt`,e.prompt),s&&t.set(`parentConversationId`,s);let r=t.toString();S(`/ai/build${r?`?${r}`:``}`)},[S,c,s]),[T,E]=(0,$.useState)(null),[D,O]=(0,$.useState)(0),k=hi(),[A,j]=(0,$.useState)(!1);(0,$.useEffect)(()=>{T||j(!1)},[T]);let M=Ee(),[N,ee]=(0,$.useState)(null),P=(0,$.useRef)(null);(0,$.useEffect)(()=>()=>{P.current&&window.clearTimeout(P.current)},[]);let F=T!==null;(0,$.useEffect)(()=>{b?.(F)},[F,b]);let te=Cd(F),ne=(0,$.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&E(e=>e??{name:n.name,segment:t,materialized:!1}),P.current&&window.clearTimeout(P.current),P.current=window.setTimeout(()=>O(e=>e+1),800)},[]),L=(0,$.useCallback)(e=>{E(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,$.useEffect)(()=>{E(null)},[s]);let R=(0,$.useMemo)(()=>{let t=e.find(e=>e.name===i);return fd(x,i,t?.label??i??x(`console.ai.assistant`))},[e,i,x]),re=(0,$.useMemo)(()=>od(f),[f]),{errorSuppressed:z,handleChatError:ie,setMessagesRef:ae,resetSuppression:oe}=Cu({chatApi:a,conversationId:s}),{models:B,defaultModelId:se}=Ba({apiBase:o}),[ce,le]=(0,$.useState)(void 0),ue=ce??se,{messages:de,isLoading:fe,error:pe,sendMessage:me,stop:V,reload:he,clear:ge,setMessages:_e}=Pa({api:a,conversationId:s,parentConversationId:d,model:ue,onError:ie,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:Oo().features.autoPublishAiBuilds,...c?{packageId:c}:{}}},initialMessages:re,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,$.useEffect)(()=>{ae.current=_e},[_e]);let ve=(0,$.useMemo)(()=>Ja(de),[de]);(0,$.useEffect)(()=>{du(s,fu(ve))},[s,ve]);let ye=(0,$.useMemo)(()=>Qu(ve)||Qu(f),[ve,f]),be=(0,$.useCallback)((e,t)=>nd(ye,e,t),[ye]),xe=be(`planApproveMessage`),Se=be(`planApproveDefaultsMessage`),Ce=be(`changesConfirmMessage`),we=(0,$.useMemo)(()=>({create_object:x(`console.ai.changeVerb.createObject`,{defaultValue:`Create object`}),add_field:x(`console.ai.changeVerb.addField`,{defaultValue:`Add field`}),modify_field:x(`console.ai.changeVerb.modifyField`,{defaultValue:`Modify field`}),delete_field:x(`console.ai.changeVerb.deleteField`,{defaultValue:`Delete field`}),create_metadata:x(`console.ai.changeVerb.createMetadata`,{defaultValue:`Create`}),update_metadata:x(`console.ai.changeVerb.updateMetadata`,{defaultValue:`Modify`}),create_seed:x(`console.ai.changeVerb.createSeed`,{defaultValue:`Generate sample data`}),create_package:x(`console.ai.changeVerb.createPackage`,{defaultValue:`Create app package`})}),[x]),U=(0,$.useRef)(!1);(0,$.useEffect)(()=>{U.current&&!fe&&T&&O(e=>e+1),U.current=fe},[fe,T]);let Te=Wa({messages:ve,apiBase:o,continueConversation:e=>{me(e)}}),De=Dd({chatApi:a,conversationId:s,pendingRef:m,doSend:(0,$.useCallback)((e,t)=>{oe();let r=(t??[]).filter(e=>/\.(xlsx|xlsm|csv|tsv|txt)$/i.test(e.name));if(!r.length){if(t?.length){me(`${e}\n\n(用户上传了 ${t.length} 个附件:${t.map(e=>e.name).join(`、`)} — 当前仅支持读取表格类附件(Excel/CSV),这些文件的内容我没有读取。)`),g(e);return}me(e),g(e);return}ee(r[0]),(async()=>{let i=e=>e.length>40?`${e.slice(0,40)}…`:e,a=e=>e.slice(0,12).map(e=>i(String(e??``)).replace(/\s+/g,` `)).join(` | `),o=e;for(let e of r.slice(0,2))try{let{parseSpreadsheetFile:t}=await n(async()=>{let{parseSpreadsheetFile:e}=await import(`./plugin-grid-D49BBhCX.js`).then(e=>e.t);return{parseSpreadsheetFile:e}},__vite__mapDeps([0]),import.meta.url),r=await t(e),i=r[0]??[],s=r.slice(1,4);o+=[`\n\n[附件表格 ${e.name} — ${Math.max(0,r.length-1)} 数据行 × ${i.length} 列(控制台已在本地解析,文件本体未上传)]`,`表头: ${a(i)}`,...s.map((e,t)=>`样例${t+1}: ${a(e)}`)].join(`
|
|
7
|
-
`)}catch(t){o+=`\n\n[附件表格 ${e.name}] 解析失败(${t instanceof Error?t.message:`unknown`})— 请引导用户改用对象列表的 Import 上传该文件。`}r.length>2&&(o+=`\n\n(另有 ${r.length-2} 个表格附件未读取 — 一次最多读取 2 个。)`);let s=(t??[]).length-r.length;s>0&&(o+=`\n\n(另有 ${s} 个非表格附件,内容未读取。)`),me(o),g(o)})()},[oe,me,g]),pendingSignal:h,agentRoute:i?Va(i):void 0}),W=i?Va(i)===`build`:!1,{apps:Oe}=H(),ke=Oe,{appLabel:G}=je(),Ae=(0,$.useMemo)(()=>sd(ve,c),[ve,c]),Me=(0,$.useMemo)(()=>{if(!Ae)return;let e=(ke??[]).find(e=>e._packageId===Ae);return e?G({name:e.name,label:Oa(e.label,x)}):Ae},[Ae,ke,G,x]),Ne=(0,$.useMemo)(()=>{if(!c)return;let e=(ke??[]).find(e=>e._packageId===c);return e?G({name:e.name,label:Oa(e.label,x)}):void 0},[c,ke,G,x]),Pe=W&&!!c,Fe=(0,$.useMemo)(()=>{if(!(re.length>0))return Fd(i,R,x,Pe)},[re.length,i,R,x,Pe]),Ie=(0,$.useMemo)(()=>pd(x,i,Pe?{appLabel:Ne}:void 0),[x,i,Pe,Ne]);(0,$.useEffect)(()=>{!W||!u||!Ae||c||fe||l?.(Ae)},[W,u,Ae,c,fe,l]);let Le=(0,$.useMemo)(()=>{let e=new Map;for(let t of ke??[]){let n=t._packageId;!n||e.has(n)||ld(t)||e.set(n,G({name:t.name,label:Oa(t.label,x)}))}return Array.from(e,([e,t])=>({id:e,label:t}))},[ke,G,x]),Re=(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.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[C?e.length<=3?(0,Q.jsx)(on,{value:i,onValueChange:e=>S(`/ai/${Va(e)}`),children:(0,Q.jsx)(nn,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":x(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:e.map(e=>(0,Q.jsx)(dn,{value:e.name,disabled:t,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:fd(x,e.name,e.label)},e.name))})}):(0,Q.jsxs)(Ze,{value:i,onValueChange:e=>S(`/ai/${Va(e)}`),disabled:t,children:[(0,Q.jsx)(dr,{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":x(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,Q.jsx)(Be,{placeholder:x(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,Q.jsx)(Je,{align:`start`,children:e.map(e=>(0,Q.jsxs)(jt,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:fd(x,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:R}),W?(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(Rt,{"data-testid":`ai-build-package-chip`,title:Ae,"aria-label":x(`console.ai.switchApp`,{defaultValue:`Switch app`}),className:Tr(`inline-flex min-w-0 items-center gap-1 rounded-md border px-2 py-0.5 text-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border/80`,Ae?`bg-muted/40 text-foreground/80`:`border-dashed text-muted-foreground`),children:[Ae?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(vn,{className:`size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`max-w-[10rem] truncate`,children:Me})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(hn,{className:`size-3 shrink-0`}),x(`console.ai.newApp`,{defaultValue:`New app`})]}),(0,Q.jsx)(ti,{className:`size-3 shrink-0 opacity-60`})]}),(0,Q.jsxs)(cn,{align:`start`,className:`max-h-72 w-56 overflow-y-auto`,children:[(0,Q.jsx)(Ir,{className:`text-xs text-muted-foreground`,children:x(`console.ai.switchAppLabel`,{defaultValue:`Build conversations by app`})}),Le.map(e=>(0,Q.jsxs)(bt,{"data-testid":`ai-build-package-option-${e.id}`,className:`text-xs`,onSelect:()=>{e.id!==Ae&&S(`/ai/build?package=${encodeURIComponent(e.id)}`)},children:[(0,Q.jsx)(vn,{className:`size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.id===Ae?(0,Q.jsx)(pi,{className:`size-3 shrink-0`}):null]},e.id)),Le.length>0?(0,Q.jsx)(gt,{}):null,(0,Q.jsxs)(bt,{"data-testid":`ai-build-package-option-new`,className:`text-xs`,onSelect:()=>S(`/ai/build?new=1`),children:[(0,Q.jsx)(hn,{className:`size-3 shrink-0`}),x(`console.ai.newApp`,{defaultValue:`New app`})]})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[y&&v?(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:v,disabled:!s,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:s?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,Q.jsx)(Dt,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:_,disabled:!s,"aria-label":x(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:x(s?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(tr,{className:`h-3.5 w-3.5`})})]}),r?(0,Q.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:r.message,children:x(`console.ai.offlineDemoMode`)}):null]}),ze=T!==null&&!k;return(0,Q.jsxs)(`div`,{ref:te.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[N&&M?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute top-2 left-0 right-0 z-20 flex justify-center px-4`,children:(0,Q.jsx)(`div`,{className:`pointer-events-auto w-full max-w-3xl`,children:(0,Q.jsx)(Ic,{file:N,dataSource:M,defaultObjectName:T?.name,onDone:()=>ee(null)})})}):null,(0,Q.jsx)(`div`,{"data-chat-column":!0,className:ze?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:ze?{width:te.width}:void 0,children:(0,Q.jsx)(Ua,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(Ao(),`_blank`,`noopener,noreferrer`),onOpenBuilder:w,surface:`plain`,maxHeight:`100%`,headerSlot:Re,messages:ve,placeholder:i?Va(i)===`ask`?x(`console.ai.askAnything`):x(`console.ai.askAgent`,{agent:R}):x(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:Ie.title,emptyDescription:Ie.description,clear:x(`console.ai.clearConversation`),sendHint:x(`console.ai.sendHint`),agentActivity:x(`console.ai.agentActivity`),toolCompleted:x(`console.ai.toolCompleted`),toolRunning:x(`console.ai.toolRunning`),toolAwaitingApproval:x(`console.ai.toolAwaitingApproval`),toolFailed:x(`console.ai.toolFailed`),connectionWaiting:x(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:x(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:x(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:x(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[x(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),x(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),x(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),x(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),x(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),x(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),x(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),x(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),x(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),x(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:x(`console.ai.toolDetailsHidden`),copy:x(`console.ai.copy`),copied:x(`console.ai.copied`),regenerate:x(`console.ai.regenerate`),model:x(`console.ai.model`),submit:x(`console.ai.submit`),uploadFiles:x(`console.ai.uploadFiles`),stopResponse:x(`console.ai.stopResponse`),sendFailedRateLimited:x(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:x(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:x(`console.ai.trace`),viewTrace:x(`console.ai.viewTrace`)},models:B,selectedModelId:ue,onModelChange:le,suggestions:Fe,onSendMessage:De,onClear:ge,hideClearBar:!0,onStop:fe?V:void 0,onReload:he,isLoading:fe,error:z?void 0:pe,enableMarkdown:!0,onToolApprove:Te.decide,toolDecisions:Te.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>S(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:x(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),onDesignBuiltApp:(e,t)=>{let n=t??T?.segment;n&&S(`/studio/${encodeURIComponent(n)}/interfaces`)},designBuiltAppLabel:x(`console.ai.designBuiltApp`,{defaultValue:`Design in Studio`}),getArtifactAction:(e,t)=>{let n=Gu(t??T?.segment,e);return n?()=>S(n):null},fetchPendingDraftCount:eu,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){let e=n?.data?.failed??n?.failed??[];throw Error(e.length>0?Mc(e):String(r))}let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(x(`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(x(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),Li(),{ok:!0,health:za(n)}}catch(e){return X.error(x(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:x(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:x(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:x(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:x(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:x(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:x(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:x(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:x(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:x(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:x(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:x(`console.ai.planBuilt`,{defaultValue:`Built`}),planBuildingLabel:x(`console.ai.planBuilding`,{defaultValue:`Building…`}),planReadyLabel:x(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:xe,planApproveDefaultsMessage:Se,changesTitleLabel:x(`console.ai.changesTitle`,{defaultValue:`Confirm changes`}),changesConfirmedLabel:x(`console.ai.changesConfirmed`,{defaultValue:`Confirmed`}),changesConfirmLabel:x(`console.ai.changesConfirm`,{defaultValue:`Confirm`}),changesConfirmHintLabel:x(`console.ai.changesConfirmHint`,{defaultValue:`Reply to confirm or adjust this change.`}),changesConfirmMessage:Ce,changeVerbLabels:we,planAnswerMessage:(e,t)=>be(`planAnswerMessage`,{question:e,option:t}),autoPublishDrafts:Oo().features.autoPublishAiBuilds,onDraftArtifacts:ne,onPreviewDraftApp:(e,t)=>{E({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),k&&j(!0)},onBuildMaterialized:L,previewDraftLabel:x(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),ze?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":x(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:te.onHandlePointerDown,onKeyDown:te.onHandleKeyDown,onDoubleClick:te.reset,"data-testid":`ai-chat-split-handle`,className:Tr(`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:Tr(`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`,te.dragging&&`bg-primary`)})]}),(0,Q.jsx)(Uu,{appName:T.name,appSegment:T.segment,materialized:T.materialized,refreshKey:D,onClose:()=>E(null)}),te.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null,T&&k?(0,Q.jsx)(Q.Fragment,{children:A?(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-background`,"data-testid":`ai-chat-mobile-canvas`,children:(0,Q.jsx)(Uu,{appName:T.name,appSegment:T.segment,materialized:T.materialized,refreshKey:D,onClose:()=>j(!1)})}):(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-24 z-20 flex justify-center px-4`,children:(0,Q.jsxs)(q,{size:`sm`,onClick:()=>j(!0),"data-testid":`ai-chat-mobile-preview-open`,className:`pointer-events-auto gap-1.5 rounded-full shadow-lg`,children:[(0,Q.jsx)(Xt,{className:`h-4 w-4`}),x(`console.ai.previewApp`,{defaultValue:`Preview app`})]})})}):null]})}function jd(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 Md(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 Nd(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 Pd(e){return[e(`console.ai.suggestions.editApp.addField`,{defaultValue:`Add a field to one of the objects.`}),e(`console.ai.suggestions.editApp.addObject`,{defaultValue:`Add a new object and relate it to an existing one.`}),e(`console.ai.suggestions.editApp.addDashboard`,{defaultValue:`Add a dashboard for the key metrics.`}),e(`console.ai.suggestions.editApp.addAutomation`,{defaultValue:`Add an automation — an approval, a status flow, or a notification.`})]}function Fd(e,t,n,r=!1){if(Ra(e))return jd(n);if(La(e))return r?Pd(n):Md(n);let i=(e??t).toLowerCase();return i.includes(`data`)?jd(n):i.includes(`metadata`)?Md(n):Nd(n)}function Id(e){return!!e&&typeof e==`object`&&`fraction`in e}function Ld(e){let t=e?.meters;return!t||!Id(t.build)||!Id(t.dataChat)?null:{meters:{build:t.build,dataChat:t.dataChat}}}function Rd(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=$.useState(null),[a,o]=$.useState(!1),[s,c]=$.useState(void 0),[l,u]=$.useState(0),d=$.useCallback(()=>u(e=>e+1),[]),f=n&&!!t;return $.useEffect(()=>{if(!f){i(null),c(void 0),o(!1);return}if(typeof fetch!=`function`)return;let e=!1,n=`${t.replace(/\/$/,``)}/usage`;return o(!0),fetch(n,{method:`GET`,headers:{Accept:`application/json`},credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`Failed to load AI usage (${e.status})`);return e.json()}).then(t=>{e||(i(Ld(t)),c(void 0))}).catch(t=>{e||(i(null),c(t instanceof Error?t:Error(String(t))))}).finally(()=>{e||o(!1)}),()=>{e=!0}},[f,t,l]),$.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>d(),t=()=>{document.visibilityState===`visible`&&d()};return window.addEventListener(Ya,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(Ya,e),document.removeEventListener(`visibilitychange`,t)}},[f,d]),{usage:r,loading:a,error:s,refetch:d}}function zd(e){return e>=1?`full`:e>=.8?`low`:`ok`}function Bd(e){return e===`full`?`text-destructive`:e===`low`?`text-amber-500`:`text-primary`}function Vd({fraction:e,tone:t,size:n=16}){let r=(n-2)/2,i=2*Math.PI*r,a=i*Math.min(1,Math.max(0,e)),o=n/2;return(0,Q.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:Bd(t),"aria-hidden":`true`,focusable:`false`,children:[(0,Q.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,strokeWidth:2,className:`stroke-muted-foreground/25`}),(0,Q.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeDasharray:`${a} ${i}`,transform:`rotate(-90 ${o} ${o})`})]})}function Hd({apiBase:e,enabled:t=!0,className:n}){let{t:r}=I(),{usage:i}=Rd({apiBase:e,enabled:t}),a=$.useMemo(()=>{if(!i)return[];let e=[];return[`build`,`dataChat`].forEach(t=>{let n=i.meters[t];if(!n||n.unmetered||n.fraction==null)return;let r=n.fraction;e.push({key:t,meter:n,fraction:r,tone:zd(r)})}),e},[i]);if(!t||a.length===0)return null;let o=e=>e===`build`?r(`console.ai.usage.meterBuild`,{defaultValue:`Build`}):r(`console.ai.usage.meterAsk`,{defaultValue:`Ask`}),s=e=>e===`full`?r(`console.ai.usage.statusFull`,{defaultValue:`Limit reached`}):e===`low`?r(`console.ai.usage.statusLow`,{defaultValue:`Running low`}):r(`console.ai.usage.statusOk`,{defaultValue:`Plenty left`}),c=e=>e.resetKind===`daily`?r(`console.ai.usage.resetsDaily`,{defaultValue:`Resets tonight`}):r(`console.ai.usage.resetsMonthly`,{defaultValue:`Resets next cycle`}),l=a.reduce((e,t)=>t.fraction>e.fraction?t:e),u=l.tone!==`ok`;return(0,Q.jsxs)(et,{children:[(0,Q.jsx)(Tt,{asChild:!0,children:(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,"data-testid":`ai-usage-indicator`,className:Tr(`h-7 gap-1.5 px-1.5 text-muted-foreground hover:text-foreground`,n),"aria-label":r(`console.ai.usage.ariaLabel`,{defaultValue:`AI usage: {{status}}`,status:s(l.tone)}),children:[(0,Q.jsx)(`span`,{className:`flex items-center gap-1`,children:a.map(e=>(0,Q.jsx)(Vd,{fraction:e.fraction,tone:e.tone},e.key))}),u?(0,Q.jsx)(`span`,{className:Tr(`hidden text-xs font-medium sm:inline`,l.tone===`full`?`text-destructive`:`text-amber-600 dark:text-amber-500`),children:s(l.tone)}):null]})}),(0,Q.jsxs)(ft,{align:`end`,className:`w-64 p-3`,"data-testid":`ai-usage-popover`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-semibold text-foreground/80`,children:r(`console.ai.usage.title`,{defaultValue:`AI usage`})}),(0,Q.jsx)(`ul`,{className:`space-y-3`,children:a.map(({key:e,meter:t,fraction:n,tone:i})=>{let a=i!==`ok`&&(t.upgrade||t.topUp);return(0,Q.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,Q.jsx)(Vd,{fraction:n,tone:i,size:22}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o(e)}),(0,Q.jsx)(`span`,{className:Tr(`text-xs`,i===`full`?`text-destructive`:i===`low`?`text-amber-600 dark:text-amber-500`:`text-muted-foreground`),children:s(i)})]}),(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:c(t)}),a?(0,Q.jsx)(q,{variant:`link`,size:`sm`,className:`mt-1 h-auto p-0 text-xs`,"data-testid":`ai-usage-cta-${e}`,onClick:()=>window.open(Ao(),`_blank`,`noopener,noreferrer`),children:t.upgrade?r(`console.ai.usage.ctaUpgrade`,{defaultValue:`Upgrade to keep going`}):r(`console.ai.usage.ctaTopUp`,{defaultValue:`Add credits to continue`})}):null]})]},e)})})]})]})}function Ud(){let{execute:e}=be(),{getItem:t}=H();return(0,$.useCallback)(n=>{(async()=>{let r=n.actionDef,i=r?.actionName;if(!i){console.warn(`[nav] action item has no actionDef.actionName — nothing to dispatch`,n?.id),X.error(`This menu item is not configured to run an action.`);return}let a;try{a=await t(`action`,i)}catch(e){console.warn(`[nav] failed to resolve action '${i}'`,e),X.error(`Could not load action "${i}".`);return}if(!a){console.warn(`[nav] action '${i}' is not defined — nav item ${n?.id} cannot run`),X.error(`Action "${i}" is not defined.`);return}try{let{params:t,...n}=a,i={...n},o=Array.isArray(t)?t:[];o.length>0&&(i.actionParams=o),r?.params&&typeof r.params==`object`&&(i.params={...r.params}),await e(i)}catch(e){console.warn(`[nav] action '${i}' failed`,e),X.error(`Action "${i}" failed to run.`)}})()},[e,t])}var Wd=20;function Gd(e,t=``){let{href:n,external:r}=Po(e,t);return r?n:!n||n===`#`?``:n}function Kd(e){return`nav:${e}`}function qd(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=ma(),a=(0,$.useCallback)((e,i,a,o)=>{let s=Kd(e);i?(a&&t({id:s,label:a.label,href:Gd(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,$.useCallback)(e=>i.has(e),[i]),s=(0,$.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<Wd;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,$.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,$.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var Jd=0;function Yd(e=`nav`){return`${e}_${Date.now()}_${++Jd}`}function Xd(e,t){return[...e,t]}function Zd(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:Zd(e.children,t,n)}:e)}function Qd(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:Qd(i.children,t,n,r)}:i})}function $d(e,t){return e.length===t.length?e===t||JSON.stringify(e)===JSON.stringify(t):!1}function ef(e){return typeof e==`string`&&e.startsWith(`sys_`)}function tf(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`||ef(t.name)}function nf(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function rf(){let e=Ee(),{apps:t,refresh:n}=H(),{t:r}=I(),i=(0,$.useRef)(e);i.current=e;let a=(0,$.useRef)(n);a.current=n;let o=(0,$.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,$.useCallback)(e=>Sa(t,e),[t]),c=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Xd(a,{id:Yd(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Xd(a,{id:Yd(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,$.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Zd(i,`page`,t);if($d(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,$.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Zd(i,`dashboard`,t);if($d(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Qd(a,`page`,t,n);if($d(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Qd(a,`dashboard`,t,n);if($d(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!nf(r)||await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!nf(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,$.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!nf(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,$.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!nf(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!nf(r)||await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!nf(r)||await p(t,e,n)}},[t,p])}}function af(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=H(),i=Ee(),a=(0,$.useRef)(i);a.current=i;let o=Pi(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=rf(),d=(0,$.useRef)(null),f=(0,$.useRef)(null),p=(0,$.useRef)(0),m=(0,$.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,$.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!tf(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(!(!t||!nf(e))){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var of=768,sf=1024;function cf(){let{setOpen:e,isMobile:t}=kr(),n=(0,$.useRef)(e);(0,$.useEffect)(()=>{n.current=e},[e]),(0,$.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=of&&t<sf;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}var lf=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function uf(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function df(e){try{return decodeURIComponent(e)}catch{return e}}function ff({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=Ji(),o=(0,$.useRef)(n);o.current=n,(0,$.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${df(t)}`,label:df(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!lf.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:uf(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:uf(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:uf(c),href:`${l}/report/${c}`,type:`report`})}},[e,t,r,i])}var pf={"studio-build":`build`,default:`ask`};function mf(e,{agents:t,appDefaultAgent:n,aiStudioEnabled:r=!0}){let i=t.map(e=>e.name),a=(Na(n)?n:void 0)??pf[e]??pf.default,o=!r&&La(a)?`ask`:a;return Ka(o,i)??Fa(t)}function hf(e){try{let t=window.localStorage.getItem(e),n=t?Number.parseInt(t,10):NaN;return Number.isFinite(n)&&n>0?n:420}catch{return 420}}function gf(e){let{defaultExpanded:t=!1,persistExpandedKey:n,persistWidthKey:r=Bl}=e??{},[i,a]=$.useState(()=>n?ql(n,t):t),[o,s]=$.useState(()=>hf(r)),[c,l]=$.useState(!1),[u,d]=$.useState(!1),f=$.useRef(!1),p=$.useRef(null),m=$.useRef(o);m.current=o;let h=$.useCallback(e=>{a(t=>{let r=e(t);return n&&Jl(n,r),r})},[n]),g=$.useCallback(e=>{e.preventDefault(),f.current=!1,p.current=null,d(!1);let t=e.clientX,n=o;l(!0);let i=e=>{let r=Wl(n+(t-e.clientX),window.innerWidth);s(r)},a=e=>{let o=Wl(n+(t-e.clientX),window.innerWidth);try{window.localStorage.setItem(r,String(Math.round(o)))}catch{}l(!1),window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)},[o]),_=$.useCallback(()=>{f.current||(f.current=!0,p.current=m.current,s(Gl(window.innerWidth)),d(!0))},[]),v=$.useCallback(()=>{f.current&&(f.current=!1,s(p.current??hf(r)),p.current=null,d(!1))},[r]);return{expanded:i,width:o,dragging:c,maximized:u,toggle:$.useCallback(()=>h(e=>!e),[h]),expand:$.useCallback(()=>h(()=>!0),[h]),collapse:$.useCallback(()=>h(()=>!1),[h]),maximize:_,restore:v,onResizePointerDown:g}}function _f({userId:e,apiBase:t,defaultAgent:n,onCanvasOpenChange:r}){let{agents:i,isLoading:a,error:o}=Ia({apiBase:t}),s=$.useMemo(()=>mf(`default`,{agents:i,appDefaultAgent:n,aiStudioEnabled:Oo().features.aiStudio!==!1}),[i,n]),c=s?`${t}/agents/${encodeURIComponent(s)}/chat`:void 0,l=s?Tu({appId:void 0,product:wu(s)}):void 0,{conversationId:u,initialMessages:d}=xu({userId:s?e:void 0,scope:l,apiBase:t,activeId:void 0,forceNew:!1}),f=$.useRef(null);return!a&&i.length===0?null:(0,Q.jsx)(Ad,{agents:i,agentsLoading:a,agentsError:o,activeAgent:s,chatApi:c,apiBase:t,conversationId:u,initialMessages:d,pendingFirstMessageRef:f,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:r},`${c??`local`}:${u??`pending`}`)}function vf({dock:e,userId:t,apiBase:n,defaultAgent:r,title:i,onMaximize:a,children:o}){let{t:s}=I(),c=$.useMemo(()=>md(n),[n]),l=$.useCallback(t=>t?e.maximize():e.restore(),[e.maximize,e.restore]);return(0,Q.jsxs)(`aside`,{"data-testid":`chat-dock-panel`,style:{width:e.width},className:Tr(`relative hidden h-full shrink-0 flex-col border-l bg-background md:flex`,!e.dragging&&`transition-[width] duration-200 ease-out`),children:[(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`console.ai.dock.resize`,{defaultValue:`Resize chat`}),onPointerDown:e.onResizePointerDown,className:Tr(`absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize transition-colors hover:bg-primary/40`,e.dragging&&`bg-primary/50`)}),(0,Q.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between border-b px-3`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-semibold text-foreground/80`,children:[(0,Q.jsx)(hr,{className:`size-3.5`}),i??s(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(Hd,{apiBase:c}),a?(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:a,"aria-label":s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),title:s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-maximize`,children:(0,Q.jsx)(_r,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:e.collapse,"aria-label":s(`console.ai.dock.collapse`,{defaultValue:`Collapse chat`}),"data-testid":`chat-dock-collapse`,children:(0,Q.jsx)(sn,{className:`h-4 w-4`})})]})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:o??(0,Q.jsx)(_f,{userId:t,apiBase:c,defaultAgent:r,onCanvasOpenChange:l})})]})}function yf({open:e,onOpenChange:t,userId:n,apiBase:r,defaultAgent:i,title:a,onMaximize:o,children:s}){let{t:c}=I(),l=$.useMemo(()=>md(r),[r]),u=$.useRef(!1);return $.useEffect(()=>{!e&&u.current&&(u.current=!1,o?.())},[e,o]),(0,Q.jsx)(Mn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ui,{side:`bottom`,className:`flex h-[85svh] flex-col gap-0 p-0 md:hidden`,"data-testid":`chat-dock-mobile-sheet`,children:[(0,Q.jsxs)(Ge,{className:`shrink-0 border-b px-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 pr-8`,children:[(0,Q.jsxs)(si,{className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,Q.jsx)(hr,{className:`size-4`}),a??c(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,Q.jsx)(Hd,{apiBase:l}),o?(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-9 w-9 text-muted-foreground hover:text-foreground`,onClick:()=>{u.current=!0,t(!1)},"aria-label":c(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-mobile-maximize`,children:(0,Q.jsx)(_r,{className:`h-4 w-4`})}):null]}),(0,Q.jsx)(Gt,{className:`sr-only`,children:c(`console.ai.dock.description`,{defaultValue:`AI assistant chat`})})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:s??(0,Q.jsx)(_f,{userId:n,apiBase:l,defaultAgent:i})})]})})}function bf({onExpand:e,className:t}){let{t:n}=I();return(0,Q.jsx)(q,{variant:`outline`,size:`icon`,onClick:e,"data-testid":`chat-dock-launcher`,"aria-label":n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),title:n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),className:Tr(`fixed right-0 top-1/2 z-40 hidden h-16 w-7 -translate-y-1/2 rounded-l-md rounded-r-none border-r-0 bg-background shadow-md md:inline-flex`,t),children:(0,Q.jsx)(hr,{className:`size-4`})})}var xf=new Set([`object`,`app`,`action`]);async function Sf(){try{let e=await n(()=>import(`./dist-jor1XT9f.js`),[],import.meta.url);return typeof e?.validateCapabilityReferences==`function`?e.validateCapabilityReferences:null}catch{return null}}async function Cf(e,t,n){try{let r=n===void 0?await Sf():n;if(!r)return[];let i=t.filter(e=>xf.has(e.type));if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?t:null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=await(e.list?.(`permission`,{}))?.then(e=>Array.isArray(e)?e.map(a).filter(Boolean):[]).catch(()=>[])??[],c=await Promise.all(t.filter(e=>e.type===`permission`).map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null)));return r({objects:o.filter((e,t)=>e&&i[t].type===`object`),apps:o.filter((e,t)=>e&&i[t].type===`app`),actions:o.filter((e,t)=>e&&i[t].type===`action`),permissions:[...s,...c.filter(Boolean)]}).filter(e=>e&&e.severity===`warning`).map(e=>`${e.where}: ${e.message}`)}catch{return[]}}function wf(e){let t=ss(),[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=await Cf(t,n),i=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],a=n.filter(e=>e.packageId===null),o=[],s=[],c=0,l=e=>{if(e){e.seedError&&o.push(e.seedError),typeof e.seededRows==`number`&&(c+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&s.push(t.message)}};for(let e of i){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}`);l(za(n))}let u=[...a.filter(e=>e.type!==`seed`),...a.filter(e=>e.type===`seed`)];for(let e of u){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&o.push(n.error??`${e.name}: sample data failed to load`)}return s.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:s[0]}):o.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:o[0]}):X.success(c>0?e(`home.pendingDrafts.publishedVerified`,{count:c,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),r.length>0&&X.warning(e(`home.pendingDrafts.capabilityWarn`,{count:r.length,defaultValue:`Authoring check: {{count}} capability reference(s) resolve nowhere.`}),{description:r[0],duration:1e4}),{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 Tf(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:te(e.type),name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}))}async function Ef(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 Df(e){if(!e||typeof e!=`object`)return null;let t=e;return t.item&&typeof t.item==`object`?t.item:t}async function Of(e,t,n={}){let r=[];n.draft&&r.push(`state=draft`),n.packageId&&r.push(`package=${encodeURIComponent(n.packageId)}`);let i=r.length?`?${r.join(`&`)}`:``,a=await fetch(`/api/v1/meta/${encodeURIComponent(e)}/${encodeURIComponent(t)}${i}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(a.status===404)return null;if(!a.ok)throw Error(`HTTP ${a.status}`);return Df(await a.json())}function kf(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function Af(e,t){let n=e??{},r=t??{},i=null;if(n.fields!=null||r.fields!=null){let e=xs(n.fields,r.fields);i={added:Object.values(e.byName).filter(e=>e.status===`added`).map(e=>e.name).sort(),changed:Object.values(e.byName).filter(e=>e.status===`changed`).map(e=>({name:e.name,keys:e.changedKeys})).sort((e,t)=>e.name.localeCompare(t.name)),removed:e.removed.map(e=>e.name).sort()}}let a=new Set([...Object.keys(n),...Object.keys(r)]);a.delete(`fields`);let o=[...a].filter(e=>!kf(n[e],r[e])).sort();return{fields:i,changedKeys:o}}function jf({entry:e}){let{t}=I(),[n,r]=(0,$.useState)(null),[i,a]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let t=!1;return(async()=>{try{let[n,i]=await Promise.all([Of(e.type,e.name,{packageId:e.packageId}),Of(e.type,e.name,{draft:!0,packageId:e.packageId})]);t||r(Af(n,i))}catch(e){t||a(e.message)}})(),()=>{t=!0}},[e.type,e.name,e.packageId]),i)return(0,Q.jsxs)(`p`,{className:`px-2 py-1 text-xs text-destructive`,children:[t(`preview.changes.detailLoadFailed`,{defaultValue:`Could not load change detail:`}),` `,i]});if(!n)return(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}),t(`preview.changes.detailLoading`,{defaultValue:`Loading detail…`})]});let{fields:o,changedKeys:s}=n;return!(o&&(o.added.length>0||o.changed.length>0||o.removed.length>0))&&s.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-1 text-xs text-muted-foreground`,children:t(`preview.changes.detailNone`,{defaultValue:`No differences detected — the draft matches the published version.`})}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 px-2 py-1`,"data-testid":`draft-entry-detail`,children:[o?.added.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-emerald-700 dark:text-emerald-400`,children:[`+ `,e]},`+${e}`)),o?.changed.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-amber-700 dark:text-amber-400`,children:[`~ `,e.name,e.keys.length>0&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.keys.join(`, `)]})]},`~${e.name}`)),o?.removed.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-red-700 line-through dark:text-red-400`,children:[`− `,e]},`-${e}`)),s.length>0&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`preview.changes.detailChangedKeys`,{defaultValue:`Also changed:`}),` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:s.join(`, `)})]})]})}function Mf({open:e,onOpenChange:t,packageId:n,onPublish:r,publishing:i=!1}){let{t:a}=I(),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(new Set),f=(0,$.useCallback)(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),p=(0,$.useCallback)(async()=>{s(null),l(null);try{let e=await Tf(n);s(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await Ef(e)}catch{return}s(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){l(e.message)}},[n]);(0,$.useEffect)(()=>{e&&p()},[e,p]);let m=new Map;for(let e of o??[]){let t=m.get(e.type)??[];t.push(e),m.set(e.type,t)}return(0,Q.jsx)(Mn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ui,{side:`right`,className:`flex w-[420px] flex-col sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(Ge,{children:[(0,Q.jsx)(si,{children:a(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(Gt,{children:a(`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 min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6`,children:c?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[a(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,c]}):o===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),a(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):o.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...m.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=>{let t=`${e.type}:${e.name}`,n=u.has(t);return(0,Q.jsxs)(`li`,{className:`rounded-md border text-sm`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(t),"aria-expanded":n,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left hover:bg-muted/50`,"data-testid":`draft-entry-toggle`,children:[n?(0,Q.jsx)(ti,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Q.jsx)(qn,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),e.kind===`new`?(0,Q.jsx)(ai,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(vi,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Q.jsx)(Y,{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)(mt,{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`?a(`preview.changes.kindNew`,{defaultValue:`New`}):a(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]}),n&&(0,Q.jsx)(`div`,{className:`border-t bg-muted/20`,children:(0,Q.jsx)(jf,{entry:e})})]},t)})})]},e))}),r&&(o?.length??0)>0&&!c&&(0,Q.jsxs)(`div`,{className:`mt-auto flex flex-col gap-2 border-t px-4 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`preview.changes.confirmNote`,{count:o.length,defaultValue:`Publishing releases all {{count}} pending drafts of this package atomically.`})}),(0,Q.jsxs)(q,{size:`sm`,onClick:()=>void r(),disabled:i,"data-testid":`draft-changes-publish`,children:[i?(0,Q.jsx)(Y,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(bn,{className:`mr-1.5 h-3.5 w-3.5`}),a(`preview.changes.publishConfirm`,{defaultValue:`Publish all`})]})]})]})})}function Nf(){let e=Pi(),t=s(),n=p(),{t:r}=I(),{publishAll:i,publishing:a}=wf(r),[o,c]=(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=()=>{Mi();let e=new URLSearchParams(t.search);e.delete(Ni);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))},m=l===0;return(0,Q.jsxs)(`div`,{className:Tr(`sticky top-0 z-40 border-b`,m?`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)(Xt,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:m?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.`})}),!m&&(0,Q.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>c(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)(Le,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof l==`number`?` (${l})`:``]}),(0,Q.jsxs)(q,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,Q.jsx)(Tn,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!m&&(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)(hn,{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)(q,{onClick:f,disabled:a,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,Q.jsx)(bn,{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)(Mf,{open:o,onOpenChange:c})]})]})}var Pf=class extends Error{status;code;retryable;constructor(e,t){super(e),this.name=`CommitStoreError`,this.status=t.status,this.code=t.code??null,this.retryable=t.retryable}};function Ff(e){return typeof e==`object`&&!!e&&e.retryable===!0}function If(e){let t=e?.error;if(typeof t==`string`)return{code:null,message:t.trim()||null};if(!t||typeof t!=`object`)return{code:null,message:null};let n=t,r=e=>typeof e==`string`&&e.trim()?e:null;return{code:r(n.code),message:r(n.message)}}function Lf(e,t,n){let{code:r,message:i}=If(t),a=e===503||r===`SERVICE_UNAVAILABLE`;return new Pf(a?`Commit store temporarily unreachable (HTTP ${e}) — the request did not reach it.`:i??n,{status:e,code:r,retryable:a})}async function Rf(e){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok){let e=await t.json().catch(()=>null);throw Lf(t.status,e,`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 zf(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)throw Lf(n.status,r,`HTTP ${n.status}`)}function Bf(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 Vf({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=I(),[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 Rf(n))}catch(e){c({message:e.message,unreachable:Ff(e)})}},[n]);(0,$.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await zf(n,e),X.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){X.error(Ff(e)?i(`preview.history.revertUnavailable`,{defaultValue:`Commit store temporarily unreachable — the revert may not have been applied. Reopen this history to check before retrying.`}):`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,Q.jsx)(Mn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ui,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,Q.jsxs)(Ge,{children:[(0,Q.jsx)(si,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,Q.jsx)(Gt,{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.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`commit-history-error`,children:s.unreachable?i(`preview.history.loadFailedUnavailable`,{defaultValue:`Commit store temporarily unreachable — this read did not happen, so no history is shown. Retry in a moment.`}):`${i(`preview.history.loadFailed`,{defaultValue:`Could not load history:`})} ${s.message}`}):a===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{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)(Wn,{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)(mt,{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:[`· `,Bf(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,Q.jsx)(q,{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)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(jn,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function Hf(){let e=Pi(),{appName:t}=l(),n=s(),{apps:r,refresh:i}=H(),{t:a}=I(),[o,c]=(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=Sa(r??[],f);if(!p||p._unpublished!==!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)(Qe,{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)(q,{size:`sm`,variant:`outline`,onClick:()=>d(!0),"data-testid":`unpublished-app-history`,children:[(0,Q.jsx)(Kn,{className:`mr-1 h-3.5 w-3.5`}),a(`preview.history.button`,{defaultValue:`History`})]}):null,(0,Q.jsxs)(q,{size:`sm`,onClick:async()=>{c(!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,_unpublished:!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{c(!1)}},disabled:o,"data-testid":`unpublished-app-publish`,children:[(0,Q.jsx)(bn,{className:`mr-1 h-3.5 w-3.5`}),o?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),m?(0,Q.jsx)(Vf,{open:u,onOpenChange:d,packageId:m,onReverted:i}):null]})}function Uf(){return Ce()?(0,Q.jsx)(Ur,{}):null}Uf.displayName=`ConsoleNotificationBanners`;var Wf=`__all__`,Gf=`active_package`,Kf=new Map([[Gf,`package`]]);function qf(e){return Kf.get(e)??e}function Jf(e){return e.persist??`query`}function Yf(e,t){return`objectui-ctx-${e}-${t}`}function Xf(e,t){let n={};for(let r of t)if(Jf(r)===`session`)try{let t=sessionStorage.getItem(Yf(e,r.id));t&&(n[r.id]=t)}catch{}return n}function Zf(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Qf(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 $f(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Zf(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}}return!0}function ep(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=Qf(await e.json()),s=[],c=new Set;for(let e of t){if(!$f(e,o))continue;let t=Zf(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=Zf(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 tp(e,t,n){let r=Array.isArray(t)?t:[],i=p(),a=s(),o=new URLSearchParams(a.search),[c,l]=$.useState(()=>Xf(e,r));$.useEffect(()=>{let t=Xf(e,r);Object.keys(t).length!==0&&l(e=>{let n;for(let[r,i]of Object.entries(t))e[r]===void 0&&(n??={...e},n[r]=i);return n??e})},[e,r]);let u=$.useCallback((t,n)=>{let r=n===Wf?t.allValue??``:n,o=Jf(t);if(o!==`query`){if(l(e=>e[t.id]===r?e:{...e,[t.id]:r}),o===`session`)try{let n=Yf(e,t.id);r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}return}let s=new URLSearchParams(a.search),c=qf(t.id);r?s.set(c,r):s.delete(c),i({pathname:a.pathname,search:s.toString()},{replace:!0})},[e,a.pathname,a.search,i]);$.useEffect(()=>{},[r]);let d={};for(let e of r){let t=Jf(e)===`query`?o.get(qf(e.id))??``:c[e.id]??``;d[e.id]=t||(e.allValue??``)}return{contextValues:d,element:r.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Q.jsx)(np,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function np({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=ep(e),o=is(e.icon),s=Oa(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 $.useLayoutEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,Q.jsxs)(Ze,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,Q.jsx)(dr,{"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)(Be,{placeholder:l,className:`truncate`})]})}),(0,Q.jsx)(Je,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(jt,{value:e.value,children:e.label},e.value))})]})}function rp(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 ip(e){return e.componentRef===`metadata:directory`}function ap(e){return e.componentRef===`developer:packages`}function op(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 sp({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=kr(),i=s(),{t:a,language:o}=I(),{objectLabel:c,dashboardLabel:l,viewLabel:u}=je(),{context:d,currentAppName:f}=Vi(),{user:p,activeOrganization:m}=E(),h=v(),g=Ud();$.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:_}=Ji(),{favorites:y,removeFavorite:b}=ma(),{apps:x,objects:C}=H(),w=x||[],T=w.filter(e=>e.active!==!1&&e.hidden!==!0),D=Sa(w.filter(e=>e.active!==!1),e||f)||T[0],{applyOrder:O,handleReorder:k}=rp(D?.name||`home`),{togglePin:A,applyPins:j}=qd(),{evaluator:M}=zi(),ee=$.useCallback(e=>Ri(e,M),[M]),{can:P,hasCapabilities:F}=S(),te=$.useCallback(e=>e.every(e=>{let t=e.split(`:`);return t.length>=2?P(t[0],t[1]):F([e])||P(e,`read`)}),[P,F]),ne=$.useMemo(()=>new Set((C||[]).map(e=>e?.name).filter(Boolean)),[C]),L=$.useCallback((e,t)=>e!==`object`||ne.size===0||ne.has(t),[ne]),R=(D?.areas||[]).filter(e=>Fo(e.navigation,{evaluateVisibility:ee,checkPermission:te,checkCapability:L,hasActionHandler:!!g})),[re,z]=$.useState(()=>R.length>0?R[0].id:null),ie=R.map(e=>e.id).join(`,`);$.useEffect(()=>{R.length>0?z(e=>R.some(t=>t.id===e)?e:R[0].id):z(null)},[D?.name,ie]);let ae=R.find(e=>e.id===re)??R[0],oe=ae?.navigation||D?.navigation||[],{contextValues:B,element:se}=tp(D?.name||`home`,D?.contextSelectors,a),ce=$.useMemo(()=>{let e=[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`},{id:`docs`,label:a(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(h){let t=[{id:`sys-settings`,label:a(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup/system`,icon:`settings`},{id:`sys-apps`,label:a(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:a(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:a(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/metadata/object`,icon:`database`},{id:`sys-datasources`,label:a(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/metadata/datasource`,icon:`database`},{id:`sys-users`,label:a(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:a(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:a(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:a(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:a(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,expanded:!0,children:t})}return e},[a,h]),le=d===`home`?ce:oe,ue=d===`app`&&D?`/apps/${wa(D)}`:``,de=d===`app`&&D?.name===`studio`,fe=qf(Gf),pe=B[Gf],me=$.useMemo(()=>{if(!de)return``;let e=new URLSearchParams(i.search).get(fe)||pe;return e?`?${fe}=${encodeURIComponent(e)}`:``},[pe,de,i.search,fe]),V=$.useMemo(()=>{if(d!==`app`||D?.name!==`studio`)return le;let e=a(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(ip(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:ap(n)?[{...n,type:`url`,label:e,url:`${ue}/component/developer/packages${me}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(le).flatMap(e=>op(e)?e.children??[]:[e])},[D?.name,ue,d,le,me,a]),he=$.useMemo(()=>{let e=O(V);return j(e)},[V,O,j]),[ge,_e]=$.useState(!1),ve=de&&i.pathname.replace(/\/+$/,``)===ue;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(Re,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Q.jsx)(Dn,{className:`border-b p-1.5`,children:(0,Q.jsx)(Rn,{children:(0,Q.jsx)(Bn,{children:(0,Q.jsx)(Qr,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,Q.jsxs)(r,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Q.jsx)($t,{className:`h-5 w-5`}),(0,Q.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(Un,{className:`pt-2`,children:(0,Q.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&D?(0,Q.jsxs)(Q.Fragment,{children:[se&&(0,Q.jsx)(Sr,{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)(Vr,{children:se})})}),de&&(0,Q.jsx)(Sr,{children:(0,Q.jsx)(Vr,{children:(0,Q.jsx)(Rn,{children:(0,Q.jsx)(Bn,{children:(0,Q.jsx)(Qr,{asChild:!0,isActive:ve,tooltip:a(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(r,{to:{pathname:ue,search:me},children:[(0,Q.jsx)($t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})})}),R.length>1&&(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(nr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Ot,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(Vr,{children:(0,Q.jsx)(Rn,{children:R.map(e=>{let t=is(e.icon),n=e.id===ae?.id,r=N(e.label,o);return(0,Q.jsx)(Bn,{children:(0,Q.jsxs)(Qr,{isActive:n,tooltip:r,onClick:()=>z(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:r})]})},e.id)})})})]}),(0,Q.jsx)(Lo,{items:he,basePath:ue,evaluateVisibility:ee,checkPermission:te,checkCapability:L,enablePinning:!t,onPinToggle:A,enableReorder:!t,onReorder:k,resolveObjectLabel:(e,t)=>c({name:e,label:t}),resolveDashboardLabel:(e,t)=>l({name:e,label:t}),resolveViewLabel:(e,t,n)=>u(e,t,n),onAction:g,t:a,templateContext:{currentUserId:p?.id??null,currentOrgId:m?.id??null,contextValues:B}}),_.length>0&&(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(nr,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>_e(e=>!e),children:[(0,Q.jsx)(qn,{className:`h-3 w-3 transition-transform duration-150 ${ge?`rotate-90`:``}`}),(0,Q.jsx)(St,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),ge&&(0,Q.jsx)(Vr,{children:(0,Q.jsx)(Rn,{children:_.slice(0,5).map(e=>(0,Q.jsx)(Bn,{children:(0,Q.jsx)(Qr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(r,{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))})})]}),y.some(e=>e.type!==`nav`)&&(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(nr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(an,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(Vr,{children:(0,Q.jsx)(Rn,{children:y.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(Bn,{children:[(0,Q.jsx)(Qr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(r,{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)(mr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(st,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Lo,{items:ce,basePath:``,evaluateVisibility:ee,checkPermission:te,checkCapability:L,resolveObjectLabel:(e,t)=>c({name:e,label:t}),resolveDashboardLabel:(e,t)=>l({name:e,label:t}),resolveViewLabel:(e,t,n)=>u(e,t,n),onAction:g,t:a,templateContext:{currentUserId:p?.id??null,currentOrgId:m?.id??null,contextValues:B}}),y.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(nr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(an,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(Vr,{children:(0,Q.jsx)(Rn,{children:y.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(Bn,{children:[(0,Q.jsx)(Qr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(r,{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)(mr,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(st,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(Jr,{className:`border-t p-1`,children:(0,Q.jsx)(Nl,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function cp({children:e}){return cf(),(0,Q.jsx)(Q.Fragment,{children:e})}function lp({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let c=Oa(n?.label)||t,{enabled:l}=po(),{setContext:u,setCurrentAppName:d}=Vi(),f=gf({persistExpandedKey:Vl}),m=l,h=p(),g=s(),_=hi(),v=(0,$.useCallback)(()=>{Zl(`${g.pathname}${g.search}`),h(`/ai`)},[g.pathname,g.search,h]);return(0,$.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,$.useEffect)(()=>{if(!m)return;let e=e=>{$l(e)===`toggle`&&(e.preventDefault(),f.toggle())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[m,f]),(0,Q.jsx)(ol,{children:(0,Q.jsx)(tl,{children:(0,Q.jsxs)(Ro,{sidebar:(0,Q.jsx)(sp,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(zl,{variant:`app`,appName:c,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,rightRail:m&&f.expanded&&!_?(0,Q.jsx)(vf,{dock:f,userId:o,defaultAgent:n?.defaultAgent,onMaximize:v}):void 0,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,title:n.label?`${Oa(n.label)} — ${Do()}`:void 0}:void 0,children:[(0,Q.jsxs)(cp,{children:[(0,Q.jsx)(Nf,{}),(0,Q.jsx)(Hf,{}),(0,Q.jsx)(Uf,{}),e]}),l&&(0,Q.jsx)(Dc,{appLabel:c,onOpenDock:f.expand}),m&&_&&(0,Q.jsx)(yf,{open:f.expanded,onOpenChange:e=>e?f.expand():f.collapse(),userId:o,defaultAgent:n?.defaultAgent,onMaximize:v})]})})})}function up({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:a,setOpen:o}=sl(),[s,c]=(0,$.useState)(``),u=p(),{appName:d}=l(),{setTheme:f}=ec(),{evaluator:m}=zi(),{t:h}=I();(0,$.useEffect)(()=>{a||c(``)},[a]);let g=`/apps/${d||wa(t)}`,{user:_,activeOrganization:v}=E(),y=(0,$.useMemo)(()=>({currentUserId:_?.id??null,currentOrgId:v?.id??null}),[_?.id,v?.id]),b=(0,$.useCallback)(e=>{o(!1),e()},[]),x=dp(t?.navigation||[]).filter(e=>Ri(e.visible??e.visibleOn,m)),S=(0,$.useMemo)(()=>x.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,x.map(e=>e.objectName||``).join(`|`)]),{results:C,isSearching:w}=ye({query:s,objects:n,dataSource:i,objectNames:S,enabled:a&&!!i,getDisplayName:re}),{recentItems:T}=Ji(),D=(0,$.useMemo)(()=>T.filter(e=>e.type===`record`).slice(0,5),[T]),O=a&&s.trim().length===0&&D.length>0,k=(0,$.useMemo)(()=>{let e=new Map;for(let t of n||[])typeof t?.name==`string`&&e.set(t.name,t);return e},[n]),A=(0,$.useMemo)(()=>{let e=[],t=new Map;for(let n of C){let r=t.get(n.objectName);if(!r){let i=k.get(n.objectName);r={objectLabel:Oa(i?.label,h)||n.objectLabel,icon:n.icon,hits:[]},t.set(n.objectName,r),e.push(n.objectName)}r.hits.push(n)}return e.map(e=>({objectName:e,...t.get(e)}))},[C,k,h]);return(0,Q.jsxs)(jr,{open:a,onOpenChange:o,title:h(`console.commandPalette.title`,{defaultValue:`Command palette`}),description:h(`console.commandPalette.placeholder`),contentProps:{"data-testid":`overlay:command-palette`},children:[(0,Q.jsx)(Xn,{placeholder:h(`console.commandPalette.placeholder`),value:s,onValueChange:c}),(0,Q.jsxs)(ii,{children:[(0,Q.jsx)(vr,{children:w?(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`}),h(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):h(`console.commandPalette.noResults`)}),O&&(0,Q.jsx)(er,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:D.map(e=>(0,Q.jsxs)(Sn,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>u(e.href)),children:[(0,Q.jsx)(Fn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),A.map((e,t)=>{let n=is(e.icon);return(0,Q.jsx)(er,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e.objectLabel,w&&t===0&&(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:e.hits.map(e=>(0,Q.jsxs)(Sn,{value:`record ${s} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>u(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.display}),e.subtitle&&(0,Q.jsx)(`span`,{className:`ml-auto max-w-[45%] truncate text-xs text-muted-foreground`,children:e.subtitle})]},`${e.objectName}:${e.recordId}`))},`records:${e.objectName}`)}),x.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(er,{heading:h(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=is(e.icon);return(0,Q.jsxs)(Sn,{value:`object ${Oa(e.label,h)} ${e.objectName}`,onSelect:()=>b(()=>u(Po(e,g,y).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Oa(e.label,h)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(er,{heading:h(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(Sn,{value:`dashboard ${Oa(e.label,h)} ${e.dashboardName}`,onSelect:()=>b(()=>u(Po(e,g,y).href)),children:[(0,Q.jsx)(sr,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Oa(e.label,h)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(er,{heading:h(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(Sn,{value:`page ${Oa(e.label,h)} ${e.pageName}`,onSelect:()=>b(()=>u(Po(e,g,y).href)),children:[(0,Q.jsx)(Mr,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Oa(e.label,h)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(er,{heading:h(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(Sn,{value:`report ${Oa(e.label,h)} ${e.reportName}`,onSelect:()=>b(()=>u(Po(e,g,y).href)),children:[(0,Q.jsx)(qe,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Oa(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_i,{}),(0,Q.jsx)(er,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=is(e.icon);return(0,Q.jsxs)(Sn,{value:`app ${Oa(e.label,h)} ${e.name}`,onSelect:()=>b(()=>r(wa(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Oa(e.label,h)}),e.name===t?.name&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:h(`console.commandPalette.current`)})]},e.name)})})]}),(0,Q.jsx)(_i,{}),(0,Q.jsxs)(er,{heading:h(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(Sn,{value:`theme light`,onSelect:()=>b(()=>f(`light`)),children:[(0,Q.jsx)(wt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(Sn,{value:`theme dark`,onSelect:()=>b(()=>f(`dark`)),children:[(0,Q.jsx)(rr,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(Sn,{value:`theme system`,onSelect:()=>b(()=>f(`system`)),children:[(0,Q.jsx)(On,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(_i,{}),(0,Q.jsx)(er,{heading:h(`console.commandPalette.actions`),children:(0,Q.jsxs)(Sn,{value:`search all results full page`,onSelect:()=>b(()=>u(`${g}/search`)),children:[(0,Q.jsx)(Fn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function dp(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...dp(n.children)):t.push(n);return t}function fp(){let{t:e}=I(),{open:t,setOpen:n,toggleOverlay:r}=Ys(ca),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)(Pn,{open:t,onOpenChange:n,children:(0,Q.jsxs)(di,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,Q.jsxs)(ci,{children:[(0,Q.jsx)(Yt,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(Kt,{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 pp(){return null}function mp(e){let{theme:t=`system`}=ec(),{t:n}=I();return(0,Q.jsx)(Si,{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)(Wr,{className:`h-4 w-4`}),info:(0,Q.jsx)(yi,{className:`h-4 w-4`}),warning:(0,Q.jsx)(Wt,{className:`h-4 w-4`}),error:(0,Q.jsx)(Fe,{className:`h-4 w-4`}),loading:(0,Q.jsx)(Y,{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 hp=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function gp({children:e,className:t}){let n=s(),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(...hp),e.offsetWidth,e.classList.add(...hp))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...hp,t??``].filter(Boolean).join(` `),children:e})}var _p=null,vp=null;function yp(){return vp||(vp=(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||e.VITE_SENTRY_ENABLED===`false`)return!1;try{let r=await n(()=>import(`./vendor-sentry-B2ojA7qm.js`).then(e=>e.t),[],import.meta.url),i=Number(e.VITE_SENTRY_TRACES_SAMPLE_RATE??`0.1`);return r.init({dsn:t,environment:e.VITE_SENTRY_ENVIRONMENT||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:Number.isFinite(i)?i:.1,sendDefaultPii:e.VITE_SENTRY_SEND_DEFAULT_PII!==`false`,replaysSessionSampleRate:0,replaysOnErrorSampleRate:e.VITE_SENTRY_REPLAY===`true`?.1:0,integrations:[r.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=xp(e.data.url)),e}}),_p=r,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),vp)}function bp(e,t){if(_p)try{_p.captureException(e,t?{extra:t}:void 0)}catch{}}function xp(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 Sp({error:e,onReset:t}){let{t:n}=I();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)(Cn,{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)(Wt,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(fi,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(oi,{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)(q,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)(Zn,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)($t,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Cp=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),bp(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)(Sp,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},wp=`list-filters`;function Tp(e,t,n){if(!(!t||!n))return`${wp}:${e||`anon`}:${t}:${n}`}function Ep(e){return!e||!Array.isArray(e.conditions)||e.conditions.length===0}function Dp(e){return Ep(e.filters)&&!(e.search&&e.search.length>0)}function Op(e){if(!(!e||typeof localStorage>`u`))try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);return!n||typeof n!=`object`?void 0:n}catch{return}}var kp={},Ap={};function jp(e,t){!e||typeof localStorage>`u`||(kp[e]={...kp[e]??Op(e)??{},...t},Ap[e]&&clearTimeout(Ap[e]),Ap[e]=setTimeout(()=>{let t=kp[e]??{};delete kp[e],delete Ap[e];try{Dp(t)?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify(t))}catch{}},300))}var Mp=new Set([`form`,`detail`]);function Np(e){return typeof e==`string`&&Mp.has(e)}function Pp(e,t){let n=e.type||`grid`,r=Np(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 Fp(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function Ip(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 Lp({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,dataSource:l,onAfterChange:u}){let{t:d}=I(),f=(0,$.useRef)(null),p=as(),[m]=(0,$.useState)(()=>`view_${Date.now()}`),h=(0,$.useMemo)(()=>({id:m,label:d(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),g=n===`create`?`create`:r.id,_=(0,$.useMemo)(()=>Pp(n===`create`?h:r,i.name),[g,i.name]),[v,y]=(0,$.useState)(_),[b,x]=(0,$.useState)(!1),[S,C]=(0,$.useState)(0),w=(0,$.useRef)(v),T=(0,$.useRef)(_);T.current!==_&&(T.current=_,w.current=_,y(_),x(!1)),(0,$.useEffect)(()=>{w.current=v},[v]),(0,$.useEffect)(()=>{e&&f.current&&f.current.focus()},[e]);let E=(0,$.useMemo)(()=>Ip(i),[i.fields]),D=To(v.viewKind)?`form`:`list`,O=(0,$.useCallback)(e=>{let t={...w.current,...e};if(w.current=t,y(t),x(!0),a){let e=Fp(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),k=(0,$.useCallback)(()=>{let e=Fp(v);n===`create`?s?.(e):(o?.(e),C(e=>e+1)),x(!1)},[v,o,s,n]),A=(0,$.useCallback)(()=>{if(n===`edit`){if(a){let e=Fp(_),t=Fp(w.current),n=new Set([...Object.keys(t),...Object.keys(e)]);for(let t of n)t!==`id`&&a(t,e[t])}w.current=_,y(_),x(!1)}t()},[_,n,t,a]),j=(0,$.useCallback)(e=>{let t=Pp(e,i.name);w.current=t,y(t),x(!1)},[i.name]),M=d(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,Q.jsxs)(`div`,{ref:f,tabIndex:-1,role:`complementary`,"aria-label":M,"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)(ao,{type:`view`,name:v.name,draft:v,variantKey:`config`,familyKey:D,isHome:!0,readOnly:!1,locale:p,objectFieldsOverride:E,onPatch:O})}),(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)(Us,{type:`view`,name:r.id,metadataClient:c,dataSource:l,objectName:i.name,dirty:b,onResume:j,savedSignal:S,onAfterChange:u}),(0,Q.jsx)(q,{variant:`ghost`,size:`sm`,onClick:A,"data-testid":`view-config-discard`,children:d(`console.objectView.discard`)}),(0,Q.jsx)(q,{size:`sm`,onClick:k,disabled:n===`edit`&&!b,"data-testid":`view-config-save`,children:d(`console.objectView.save`)})]})]}):(0,Q.jsx)(`div`,{ref:f,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}var Rp=`sys_user`;function zp(e,t=500){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function Bp(e){let t=e.writeMode??`insert`;if(t===`update`)throw Error(`Identity import supports the insert and upsert write modes only.`);if(t===`insert`)return{mode:`insert`};let n=(e.matchFields??[])[0];if(n===`email`)return{mode:`upsert`,matchBy:`email`};if(n===`phone_number`)return{mode:`upsert`,matchBy:`phone`};throw Error(`Identity import matches existing users by "email" or "phone_number" only.`)}function Vp(e,t,n){let r=0,i=0,a=0,o=0,s=0,c=[],l=0;for(let n=0;n<e.length;n++){let{summary:u,rows:d}=e[n],f=t[n]??[];r+=u.total,i+=u.created,a+=u.updated,o+=u.skipped,s+=u.errors;for(let e of d){if(!e)continue;let t=f[e.row-1],n=[t?.email,t?.phone_number,t?.phoneNumber,t?.phone].find(e=>typeof e==`string`&&e.trim().length>0);c.push({row:l+e.row,ok:e.ok,action:e.action,...e.id?{id:e.id}:{},...e.field?{field:e.field}:{},...e.code?{code:e.code}:{},...e.error?{error:e.error}:{},...e.temporaryPassword?{temporaryPassword:e.temporaryPassword}:{},...n?{identity:n.trim()}:{}})}l+=f.length||u.total}return{object:Rp,dryRun:n.dryRun,writeMode:n.writeMode,total:r,ok:r-s,errors:s,created:i,updated:a,skipped:o,results:c}}function Hp(e){let{base:t,authFetch:n,baseUrl:r,getPasswordPolicy:i}=e,a=async(e,t)=>{let{mode:a,matchBy:o}=Bp(t),s=i(),c=Array.isArray(t.rows)?t.rows:[];if(c.length===0)throw Error(`Identity import needs mapped rows (rows[]) — file uploads are parsed client-side.`);let l=zp(c),u=[];for(let e of l){let i=await n(`${r}/api/v1/auth/admin/import-users`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({format:`json`,rows:e,mode:a,...o?{matchBy:o}:{},passwordPolicy:s,...t.dryRun?{dryRun:!0}:{},...t.mappingName?{mappingName:t.mappingName}:{},...t.trimWhitespace===void 0?{}:{trimWhitespace:t.trimWhitespace},...t.nullValues?{nullValues:t.nullValues}:{}})}),c=await i.json().catch(()=>null);if(!i.ok||!c?.success||!c.data){let e=c?.error?.message??`Identity import failed with status ${i.status}`;throw Error(e)}u.push(c.data)}return Vp(u,l,{dryRun:t.dryRun===!0,writeMode:a})};return{...t,importRecords:a,createImportJob:void 0,getImportJobProgress:void 0,getImportJobResults:void 0,listImportJobs:void 0,cancelImportJob:void 0,undoImportJob:void 0}}function Up(e){if(!e?.results)return[];let t=[];for(let n of e.results)n?.temporaryPassword&&t.push({row:n.row,identity:n.identity??`#${n.row}`,temporaryPassword:n.temporaryPassword});return t}function Wp(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,n=[`row,identity,temporary_password`];for(let r of e)n.push(`${r.row},${t(r.identity)},${t(r.temporaryPassword)}`);return n.join(`
|
|
8
|
-
`)}var Gp={auto:{label:`Automatic (recommended)`,hint:`Reachable users get an invitation (email or SMS); anyone we can't reach gets a one-time password, shown ONCE on the result screen. Works with or without an email/SMS service.`},invite:{label:`Send invitations`,hint:`Every created user gets a set-your-password email (or an invitation SMS for phone-only rows). Requires a configured email/SMS service — unreachable rows fail.`},temporary:{label:`Temporary passwords`,hint:`For deployments without email/SMS: every created user gets a one-time password, shown ONCE on the result screen. First sign-in forces a change.`},none:{label:`No password (identity only)`,hint:`Users first sign in with a phone OTP, magic link, or password-reset link, then set their own password.`}};function Kp({policy:e,onPolicyChange:t}){let n=Or();return(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 rounded-md border border-border p-3`,"data-testid":`identity-import-options`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(pt,{className:`h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(K,{className:`text-xs font-medium`,children:n(`console.identityImport.policyTitle`,`Sign-in setup for imported users`)})]}),(0,Q.jsxs)(Ze,{value:e,onValueChange:e=>t(e),children:[(0,Q.jsx)(dr,{className:`h-8 w-full sm:w-80`,"data-testid":`identity-import-policy`,children:(0,Q.jsx)(Be,{})}),(0,Q.jsx)(Je,{children:Object.keys(Gp).map(e=>(0,Q.jsx)(jt,{value:e,children:n(`console.identityImport.policy.${e}`,Gp[e].label)},e))})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`console.identityImport.policyHint.${e}`,Gp[e].hint)})]})}function qp({serverResult:e}){let t=Or(),n=(0,$.useMemo)(()=>Up(e),[e]);return n.length===0?null:(0,Q.jsxs)(`div`,{className:`mt-2 flex w-full flex-col gap-2 rounded-md border border-amber-500/50 bg-amber-500/5 p-3`,"data-testid":`identity-import-passwords`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-700 dark:text-amber-400`,children:[(0,Q.jsx)(zr,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`text-xs font-medium`,children:t(`console.identityImport.passwordsNote`,`Temporary passwords — shown once, never stored. Save them now; each user must change theirs at first sign-in.`)})]}),(0,Q.jsxs)(`div`,{className:`max-h-40 overflow-auto rounded border bg-background p-2 font-mono text-xs`,children:[n.slice(0,50).map(e=>(0,Q.jsxs)(`p`,{"data-testid":`identity-import-password-row-${e.row}`,children:[e.identity,`: `,e.temporaryPassword]},e.row)),n.length>50&&(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:t(`console.identityImport.passwordsMore`,`More entries omitted — use the download.`)})]}),(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>{let e=Wp(n),t=new Blob([e],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=`temporary-passwords.csv`,i.click(),URL.revokeObjectURL(r)},"data-testid":`identity-import-passwords-download`,children:[(0,Q.jsx)(lr,{className:`mr-1 h-4 w-4`}),t(`console.identityImport.passwordsDownload`,`Download CSV`),` (`,n.length,`)`]})})]})}function Jp(e){let t=(t,n)=>e?.[t]?.label||n;return[{name:`email`,label:t(`email`,`Email`),type:`text`},{name:`phone_number`,label:t(`phone_number`,`Phone Number`),type:`text`},{name:`name`,label:t(`name`,`Name`),type:`text`},{name:`role`,label:t(`role`,`Platform Role`),type:`text`}]}var Yp=new Set([`formula`,`summary`]);function Xp(e,t,n){let r=[];for(let[i,a]of Object.entries(t||{})){let t=Yp.has(a?.type),o=!t&&a?.type!==`autonumber`&&!a?.readonly&&(!n?.isLoaded||n.checkField(e,i,`write`)),s=!o&&!t&&(!n?.isLoaded||n.checkField(e,i,`read`));!o&&!s||r.push({name:i,label:a?.label||i,type:a?.type||`text`,required:o&&!!a?.required,...s?{matchOnly:!0}:{},...a?.options?{options:a.options}:{}})}return r}function Zp(e,t,n,r){switch(e){case`engine-owned`:return ce({managedBy:e,userActions:r}).create?void 0:{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.`})}:n===`sys_team`?{icon:`Users`,title:t(`list.managedBy.betterAuthTeam.title`,{defaultValue:`No teams yet`}),message:t(`list.managedBy.betterAuthTeam.message`,{defaultValue:`Teams group members within an organization. Create one with “Create Team”, or they arrive through your auth provider’s organization and SSO provisioning flows.`})}:{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 Qp(e,t){if(!t||typeof t!=`object`)return;let n=t.name;return typeof n==`string`&&n.startsWith(`${e}.`)?n:A(e,{list:t})[0]?.name}function $p(e){if(!e||typeof e!=`object`)return;let t=e;for(let e of[`name`,`id`,`_id`]){let n=t[e];if(typeof n==`string`&&n!==``)return n}}function em(e,t){return e.some(e=>$p(e)===t)}function tm(e,...t){let n={};for(let e of t)e&&typeof e==`object`&&Object.assign(n,e);return n.id=e,n}var nm=new Set;function rm(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.element===`tabs`||t.tabs!=null}function im(e,t,n,r){let i=[];if((n?.quickFilters??r?.quickFilters)!=null&&i.push(`quickFilters`),rm(n?.userFilters??r?.userFilters)&&i.push(`userFilters (element: "tabs")`),i.length===0)return!1;let a=`${e}.${t}`;return nm.has(a)||(nm.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0047 "views" mode — the view switcher owns the tab bar here). Use \`listViews\` for named presets, \`element: "dropdown"\` for value chips, or move them to a page list (InterfaceListPage "filters" mode).`)),!0}function am(e){let[t]=(0,$.useState)(()=>{try{let e=new URLSearchParams(window.location.search).get(Io);return e&&e!==``?e:null}catch{return null}}),n=(0,$.useRef)(!1),r=t!==null&&!n.current&&e(t);return(0,$.useEffect)(()=>{if(r){n.current=!0;try{let e=new URL(window.location.href);e.searchParams.delete(Io),window.history.replaceState(window.history.state,``,e)}catch{}}},[r]),r?t:null}function om(e,t){return t?`${e}${e.includes(`?`)?`&`:`?`}${Io}=${encodeURIComponent(t)}`:e}var sm=new Set([`archived`,`failed`]);function cm(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 lm(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=E(),s=o?.id,[c,l]=(0,$.useState)(null);return(0,$.useEffect)(()=>{if(!t){l(null);return}let e=!1,a=async()=>{try{let e=(i||``).replace(/\/+$/,``),t=s?`?organizationId=${encodeURIComponent(s)}`:``,n=await r(`${e}/api/v1/cloud/environment-entitlements${t}`,{method:`GET`,credentials:`include`});if(!n.ok)return null;let a=(await n.json().catch(()=>null))?.data;return!a||typeof a!=`object`?null:{ready:!0,hasProductionEnv:a.hasProductionEnv===!0,canCreateDevelopmentEnv:a.development?.canCreate,plan:a.plan,upgradeUrl:a.upgradeUrl||`/settings/billing`,contactSalesUrl:a.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=>!sm.has(String(e?.status??``))).some(e=>cm(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:Ui,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:Ui,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var um=`create_environment`;function dm(e,t){return am(n=>n===um&&e&&t!=null)!==null}function fm(e){return e.filter(e=>e?.name!==um)}function pm({actions:e}){return e.length===0?null:(0,Q.jsx)(z,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}})}function mm({actions:e,entitlements:t,onUpgrade:n}){let{t:r}=I(),i=Me(),a=(e||[]).filter(e=>fe(e,`list_toolbar`)&&i(e?.requiredPermissions)),o=a.some(e=>e?.name===um),s=t?.ready?Hi(t):null,c=dm(o,s);if((0,$.useEffect)(()=>{c&&s===`upgrade_for_development`&&t&&n(qi(t,r))},[c,s]),a.length===0)return null;if(t===null){let e=fm(a);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(pm,{actions:e}),o&&(0,Q.jsx)(ri,{className:`h-9 w-44 rounded-md`,"data-testid":`environment-create-cta-loading`})]})}if(s===`upgrade_for_development`)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(pm,{actions:fm(a)}),o&&(0,Q.jsxs)(q,{size:`sm`,onClick:()=>n(qi(t,r)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,Q.jsx)(ze,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:r(`environment.addEnvironment`)})]})]});let l=a.map(e=>e?.name!==um||s==null?e:s===`setup_production`?{...e,label:r(`environment.setUpProduction`),variant:`primary`,...c?{autoTrigger:!0}:{}}:{...e,label:r(`environment.addDevelopment`),...c?{autoTrigger:!0}:{}});return(0,Q.jsx)(z,{schema:{type:`action:bar`,location:`list_toolbar`,actions:l,size:`sm`,variant:`outline`}})}F();var hm=(0,$.lazy)(()=>n(()=>import(`./plugin-charts-Cq0LpABN.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),gm=(0,$.lazy)(()=>n(()=>import(`./plugin-grid-D49BBhCX.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),_m={grid:$e,kanban:yt,calendar:ur,gallery:Ve,timeline:En,gantt:We,map:Yn,chart:qe},vm={id:`current-user`,name:`Demo User`};function ym(e,t){return R(e,t)}function bm(e,t){let n=e?.timeline?.startDateField||e?.timeline?.dateField;return{...e?.timeline||{},...n?{startDateField:n}:{},titleField:e?.timeline?.titleField||t?.titleField||`name`,descriptionField:e?.timeline?.descriptionField}}function xm(e,t){return`${e.replace(/\/view\/.*$/,``)}/record/${encodeURIComponent(String(t))}`}var Sm=Object.freeze({});function Cm(e,t,n=()=>window.location.pathname){let r=(t,n)=>t===e&&n!=null&&n!==``;return{resolve:()=>Sm,recordHref:(e,t)=>r(e,t)?xm(n(),t):null,openRecord:(e,n)=>{r(e,n)&&t(n)}}}function wm(e,t=5,n){let r=t=>n?.orgAttribution&&e?.fields?.organization_id&&!t.includes(`organization_id`)?[...t,`organization_id`]:t,i=e?.highlightFields;if(Array.isArray(i)&&i.length>0)return r(i.filter(t=>e?.fields?.[t]));let a=e?.fields;return a&&typeof a==`object`?r(Object.entries(a).filter(([e,t])=>t&&!t.hidden&&!xe(e,t)).map(([e])=>e).slice(0,t)):[]}function Tm(e){if(!e||typeof e!=`object`)return e;let t=ke(e);if(t!==e)return t;if(!Array.isArray(e.filter))return e;let n=e.filter.filter(e=>{if(Array.isArray(e)){if(e.length<2)return!1;let[,t,n]=e;return fs.has(String(t))?!0:!(n==null||n===``||Array.isArray(n)&&n.length===0)}if(!e||typeof e!=`object`||typeof e.field!=`string`||e.field===``)return!1;if(fs.has(String(e.operator)))return!0;let t=e.value;return!(t==null||t===``||Array.isArray(t)&&t.length===0)});if(n.length===0){let{filter:t,...n}=e;return n}return n.length===e.filter.length?e:{...e,filter:n}}async function Em(e,t,n){if(typeof e?.listViewOverrides==`function`)try{let r=await e.listViewOverrides(t);if(r&&typeof r==`object`){let e={};for(let t of n)r[t]&&(e[t]=Tm(r[t]));return e}}catch{}if(typeof e?.getView!=`function`)return{};let r=await Promise.all(n.map(async n=>{try{return[n,await e.getView(t,n)]}catch{return[n,null]}})),i={};for(let[e,t]of r)t&&typeof t==`object`&&(i[e]=Tm(t));return i}function Dm({definedViews:e,primary:t,primaryId:n,savedViews:r,viewOverrides:i,fallbackTab:a}){let o=Object.entries(e||{}).map(([e,t])=>{let n=i[e];return tm(e,t,n,{type:n?.type||t?.type||`grid`})});if(n){let e=o.findIndex(e=>e.id===n);if(e>=0){let[t]=o.splice(e,1);o.unshift(tm(n,t,{isDefault:!0}))}else{let e=i[n];o.unshift(tm(n,t,e,{type:e?.type||t?.type||`grid`,isDefault:!0}))}}o.length===0&&o.push(a());let s=new Set(o.map(e=>e.id));for(let e of r){let t=$p(e);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},r={};for(let[e,t]of Object.entries(n))t!==void 0&&(r[e]=t);if(s.has(t)){let e=o.findIndex(e=>e.id===t);o[e]=tm(t,o[e],r)}else o.push(tm(t,r))}return o}function Om(e,t){let n=e.filter(e=>$p(e)!==t&&e.isDefault).map(e=>({viewId:$p(e),patch:{isDefault:!1}}));return n.push({viewId:t,patch:{isDefault:!0}}),n}function km(e,t){let n=new Set(e.map(e=>$p(e)));return t.filter(e=>n.has(e)).map((e,t)=>({viewId:e,patch:{sortOrder:t}}))}function Am(e,t,n){return n.map(({viewId:n,patch:r})=>e.updateView(t,n,r))}function jm({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=l(),{t:a}=I();return t.find(e=>e.name===i)?(0,Q.jsx)(Mm,{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)(Cn,{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)($e,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(fi,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(oi,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Mm({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=p(),{appName:a,objectName:o,viewId:u}=l(),[d,f]=c(),m=s(),{showDebug:h}=Rs(),{t:g}=I(),{objectLabel:_,objectDescription:y,viewLabel:b,viewEmptyState:x,actionParamText:C,fieldLabel:w,fieldOptionLabel:T}=je(),D=pe(),{isFavorite:O,toggleFavorite:k}=ma(),A=ts()===`group`,j=ss(),M=Pi(),[N,P]=(0,$.useState)(!1),[F,te]=(0,$.useState)(`edit`),[L,R]=(0,$.useState)(!1),[re,ie]=(0,$.useState)(!1),[oe,se]=(0,$.useState)(null),le=(0,$.useRef)({}),ue=(0,$.useRef)({}),de=(0,$.useRef)([]),V=(0,$.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!o||!t)return;let i=ue.current[t]||{};ue.current[t]={...i,...r};let a=le.current[t];a&&clearTimeout(a),le.current[t]=setTimeout(()=>{let r=ue.current[t]||{};delete ue.current[t],delete le.current[t];let i=em(de.current,t);Promise.resolve(e.updateViewConfig(o,t,{...n,...r},{isSavedView:i})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,o]),he=(0,$.useCallback)(t=>{se(t),De(e=>e+1);let n=t.id;j&&n?Vs(`view`,n,t,{metadataClient:j,dataSource:e,objectName:o}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[j,e,o]),ge=(0,$.useCallback)(async n=>{try{let r;if(j){let i=t?.find?.(e=>e.name===o),a=wm(i,5),s=Array.isArray(n.columns)&&n.columns.length>0?n.columns:a,c={...n,columns:s};if(n.type===`kanban`)c.kanban={...c.kanban||{},columns:s};else if(n.type===`gallery`){let e=c.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(c.gallery={...e,visibleFields:s})}let l=Bs(o,c,{name:n?.name,label:n.label});r=await Hs(`view`,l.name,l,{metadataClient:j,dataSource:e,objectName:o})}if(P(!1),te(`edit`),De(e=>e+1),r){let e=M?``:`?${Ni}=${ji}`;u?i(`../${r}${e}`,{relative:`path`}):i(`view/${r}${e}`)}}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,o,t,i,u,j,M]),[ve,ye]=(0,$.useState)(void 0),{user:be,activeOrganization:xe}=E(),H=v(),Se=S(),{can:Ce,getObjectApiOperations:we}=Se,U=t.find(e=>e.name===o),[Ee,De]=(0,$.useState)(0),W=Xi({dataSource:e,objects:t,objectName:U.name,onRefresh:()=>De(e=>e+1)}),{confirmHandler:Oe,toastHandler:ke}=W,Ae=U.name===`sys_environment`,Me=lm({enabled:Ae,dataSource:e,authFetch:W.authFetch,apiBase:``,refreshKey:Ee}),Pe=(0,$.useMemo)(()=>(U.actions||[]).map(e=>D(U.name,e)),[U,D]),Fe=am(e=>!Ae&&Pe.some(t=>t?.name===e&&fe(t,`list_toolbar`))),Ie=(0,$.useMemo)(()=>Fe===null?Pe:Pe.map(e=>e?.name===Fe?{...e,autoTrigger:!0}:e),[Pe,Fe]),Le=(0,$.useMemo)(()=>ce(U,we(U.name)),[U,we]);(0,$.useEffect)(()=>{r!==void 0&&r!==0&&De(e=>e+1)},[r]);let Re=Le.create&&Ce(U.name,`create`),Be=Re?Le.createPredicates:void 0,Ve=ae(Be?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:create:visibleWhen`}),He=ae(Be?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:create:disabledWhen`}),Ue=Be?.disabledWhen!=null&&He,We=Le.import&&Ce(U.name,`create`),Ge=We?Le.importPredicates:void 0,Ke=ae(Ge?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:import:visibleWhen`}),qe=ae(Ge?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:import:disabledWhen`}),Je=Ge?.disabledWhen!=null&&qe,[Ye,Xe]=(0,$.useState)(!1),{features:Ze}=zi(),Qe=U.name===`sys_user`&&Ze?.admin===!0&&H,[$e,et]=(0,$.useState)(`auto`),tt=(0,$.useRef)(`auto`);tt.current=$e;let nt=(0,$.useMemo)(()=>Qe?Hp({base:e,authFetch:W.authFetch,baseUrl:``,getPasswordPolicy:()=>tt.current}):void 0,[Qe,e,W.authFetch]),[rt,it]=(0,$.useState)([]);de.current=rt,(0,$.useEffect)(()=>{let t=!1;if(!o){it([]);return}return typeof e?.listViews==`function`?(e.listViews(o,{previewDrafts:M}).then(e=>{if(t)return;let n=(e||[]).map(e=>({...e,id:$p(e),objectName:e.objectName||e.object||o}));it(n)}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||it([])}),()=>{t=!0}):(it([]),()=>{t=!0})},[e,o,Ee,M]);let[at,ot]=(0,$.useState)({});(0,$.useEffect)(()=>{let t=!1;if(!e||!o){ot({});return}let n=U.listViews||U.list_views||{},r=Object.keys(n),i=Qp(U.name,U.list);if(i&&!r.includes(i)&&r.unshift(i),r.length===0){ot({});return}return Em(e,o,r).then(e=>{t||ot(e)}),()=>{t=!0}},[e,o,U.listViews,U.list_views,U.list,Ee]);let K=(0,$.useMemo)(()=>{let e=()=>wm(U,5,{orgAttribution:A}),t=Dm({definedViews:U.listViews||U.list_views||{},primary:U.list,primaryId:Qp(U.name,U.list),savedViews:rt,viewOverrides:at,fallbackTab:()=>({id:`all`,label:g(`console.objectView.allRecords`),type:`grid`,columns:e()})}),n=new Set([`grid`,`list`,`table`]);for(let r of t)n.has(r.type)&&(!Array.isArray(r.columns)||r.columns.length===0)&&(r.columns=e());let r=new Map(t.map((e,t)=>[e.id,t])),i=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${U.name}`):null;e&&(i=JSON.parse(e))}catch{}let a=new Map(i.map((e,t)=>[e,t]));return t.sort((e,t)=>{let n=a.get(e.id),i=a.get(t.id);if(n!==void 0&&i!==void 0)return n-i;if(n!==void 0)return-1;if(i!==void 0)return 1;let o=rt.find(t=>$p(t)===e.id),s=rt.find(e=>$p(e)===t.id),c=o&&typeof o.sortOrder==`number`,l=s&&typeof s.sortOrder==`number`;return c&&l?o.sortOrder===s.sortOrder?(o.created_at||``).localeCompare(s.created_at||``):o.sortOrder-s.sortOrder:c?-1:l?1:(r.get(e.id)??0)-(r.get(t.id)??0)}),t},[U,rt,at,g,A]),ct=(0,$.useMemo)(()=>K.find(e=>e.isDefault)?.id,[K]),lt=u||d.get(`view`)||void 0,ut=(0,$.useMemo)(()=>me(lt,K.map(e=>e.id),U.name),[lt,K,U.name]);(0,$.useEffect)(()=>{lt&&!ut&&console.warn(`[ObjectView] Requested view "${lt}" not found on object "${U.name}"; falling back to the default view. Known views: ${K.map(e=>e.id).join(`, `)}`)},[lt,ut,U.name,K]);let dt=ut||ct||K[0]?.id,ft=K.find(e=>e.id===dt)||K[0],pt=oe&&oe.id===ft?.id?{...ft,...oe}:ft,mt=(0,$.useCallback)((e,t)=>{se(n=>({...n||{},id:ft?.id,[e]:t}))},[ft?.id]),ht=e=>{let t=K.find(t=>t.id===e);t&&(t.id!==dt&&P(!1),u?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},gt=(0,$.useMemo)(()=>(K||[]).map(e=>{let t=_m[e.type];return{id:e.id,label:b(U.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,U.name,b]);il({views:gt,activeViewId:dt??``,onChange:ht,enabled:gt.length>0&&!!dt});let _t=(0,$.useCallback)(()=>{R(!0)},[]),vt=(0,$.useCallback)((e,t)=>{if(e===`settings`){let e=K.find(e=>e.type===t);e&&ht(e.id),te(`edit`),P(!0)}},[K,ht]),yt=(0,$.useCallback)(e=>em(rt,e),[rt]),bt=(0,$.useCallback)(async(t,n)=>{if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{label:n}),De(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(g(`objectViewActions.renameFailed`))}},[e,o,yt,g]),xt=(0,$.useCallback)(async t=>{if(!e)return;if(!yt(t)){X.error(g(`console.objectView.cannotDeleteMetaView`));return}let n=K.find(e=>e.id===t)?.label||t;if(await Oe(g(`console.objectView.deleteViewConfirm`,{name:n}),{title:g(`console.objectView.deleteViewTitle`),confirmText:g(`console.objectView.delete`),cancelText:g(`console.objectView.cancel`)}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(o,t),t===dt){let e=K.find(e=>e.id!==t);e&&i(u?`../${e.id}`:`view/${e.id}`,u?{relative:`path`}:void 0)}De(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(g(`objectViewActions.deleteFailed`))}},[e,yt,dt,K,u,i,g,Oe]),St=(0,$.useCallback)(async(t,n)=>{if(e){if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(o,t,{isPinned:n}),De(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,o,yt,g]),Ct=(0,$.useCallback)(async t=>{if(!(!e||!o)){if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{if(typeof e?.updateView!=`function`)return;await Promise.all(Am(e,o,Om(rt,t))),De(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,o,rt,yt,g]),wt=(0,$.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${o}`,JSON.stringify(t))}catch{}if(o&&typeof e?.updateView==`function`){let n=Am(e,o,km(rt,t));try{await Promise.all(n)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}De(e=>e+1)},[e,rt,o]),Tt=(0,$.useCallback)(e=>{if(!yt(e)){X.error(g(`console.objectView.cannotEditMetaView`));return}e!==dt&&ht(e),te(`edit`),P(!0)},[dt,ht,yt,g]),Et=(0,$.useCallback)(()=>{R(!0)},[]),Dt=be?{id:be.id,name:be.name,avatar:be.image}:vm,Ot=(0,$.useMemo)(()=>({currentUserId:Dt.id,currentOrgId:xe?.id??null}),[Dt.id,xe?.id]),kt=qs({objectName:U.name,objectLabel:U.label,dataSource:e,onEdit:n,onRefresh:()=>De(e=>e+1),onConfirm:Oe,onToast:ke}),{lastMessage:At}=pa({channel:`object:${U.name}`}),jt=U.name?`user-${U.name}`:`current-user`,{hasConflicts:Mt,resolveAllConflicts:Nt}=Zi(jt);(0,$.useEffect)(()=>{At&&(Mt&&Nt(`remote`),De(e=>e+1))},[At,Mt,Nt]),(0,$.useEffect)(()=>{e?.find&&U.name&&e.find(U.name,{limit:0}).then(e=>{typeof e?.total==`number`?ye(e.total):Array.isArray(e?.data)?ye(e.data.length):Array.isArray(e)&&ye(e.length)}).catch(()=>{})},[e,U.name,Ee]);let Pt=(0,$.useMemo)(()=>{let e=pt?.navigation??U.navigation;return e?e.mode===`page`?e:{...e,width:e.width??Fs(e.size,U)}:ee(U)===`page`?{mode:`page`}:{mode:`drawer`,width:Fs(`auto`,U)}},[pt?.navigation,U]),Ft=d.get(ua),It=Array.from(d.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),Lt=(0,$.useMemo)(()=>{let e=[];return new URLSearchParams(It).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[It]),[Rt]=(0,$.useState)(()=>rs(new URLSearchParams(window.location.search))),zt=(0,$.useCallback)(e=>{f(t=>ns(t,e),{replace:!0})},[f]),Bt=(0,$.useCallback)((e,t)=>{if(t===`new_window`){window.open(xm(window.location.pathname,e),`_blank`);return}let n={from:{pathname:m.pathname+(m.search||``),label:b(U.name,pt?.name??``,pt?.label??``)||_(U)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,u,m.pathname,m.search,U,pt?.name,pt?.label,b,_]),Vt=(0,$.useMemo)(()=>Cm(U.name,Bt),[U.name,Bt]),J=Ne({navigation:Pt,objectName:U.name,onNavigate:Bt}),Ht=()=>{J.close();let e=new URLSearchParams(d);e.delete(ua),f(e)},Ut=(0,$.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){J.handleClick(e,t);return}if(J.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(ua,String(t)),f(e);return}}J.handleClick(e,t)},[J,d,f]),Wt=(0,$.useCallback)(()=>{let e=J.selectedRecord,t=e&&(e.id??e._id);t!=null&&(Ht(),Bt(t))},[J.selectedRecord,Bt]);(0,$.useEffect)(()=>{Ft&&!J.isOpen?J.open({id:Ft}):!Ft&&J.isOpen&&J.close()},[Ft]);let Gt=(0,$.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=Ee+(i||0),s=`${o}-${pt.id}-${a}`,c=pt,l=Tp(be?.id,o,pt.id),u=Op(l);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)(hm,{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`}})},s)}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)(hm,{dataSource:t,schema:{type:`object-chart`,objectName:U.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},s)}im(U.name,c.id||c.name||``,c,e);let d={...e,label:c.label??e.label,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=c.filter??e.filter,n=Array.isArray(t)?t:t?[t]:[];return ym(Lt.length?[...n,...Lt]:t,Ot)})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{V(c.id,c,{rowHeight:ne[e]})},onSortChange:e=>{V(c.id,c,{sort: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,userActions:{...B(e??{}).userActions,...B(c??{}).userActions},allowExport:c.allowExport??e.allowExport,exportOptions:c.allowExport===!1?void 0:c.exportOptions??e.exportOptions,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,data:c.data??e.data,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(U?.actions)?U.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>D(U.name,e)):[],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:(()=>{let t=c.userFilters??e.userFilters;return t&&t.element!==`tabs`&&t.tabs==null?t:void 0})(),showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,emptyState:x(U.name,c.name||c.id||``,c.emptyState??e.emptyState??Zp(U?.managedBy,g,U.name,U?.userActions)),aria:c.aria??e.aria,...c.sort?.length?{sort:c.sort}:{},options:{kanban:{...(()=>{let e=c.kanban?.groupByField||c.kanban?.groupField||G(U)||void 0;return e?{groupBy:e,groupField:e}:{}})(),titleField:c.kanban?.titleField||U.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:bm(c,U),map:{locationField:c.map?.locationField,titleField:c.map?.titleField||U.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||U.titleField||`name`},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||U.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}}};return(0,Q.jsx)(Ns,{schema:d,className:r,onEdit:n,onDelete:e=>{e?.id!=null&&kt.deleteRecord(String(e.id),e)},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&kt.execute({type:`delete`,confirmText:g(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{Ut(e,t)},onSortChange:e=>{V(c.id,c,{sort:e})},onFilterChange:e=>{jp(l,{filters:e})},onSearchChange:e=>{jp(l,{search: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:Rt,onUserFilterSelectionsChange:zt,initialFilters:u?.filters,initialSearchTerm:u?.search,dataSource:t},s)},[pt,U,o,Ee,J,kt,V,Lt,Rt,zt,be?.id]),Kt=(0,$.useMemo)(()=>K.map(e=>e.id===dt&&oe&&oe.id===e.id?{...e,...oe}:e),[K,dt,oe]),qt=(0,$.useMemo)(()=>({type:`object-view`,objectName:U.name,layout:`page`,showSearch:pt?.showSearch!==!1,showFilters:pt?.showFilters!==!1,showSort:pt?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:H,viewActions:H?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:m.pathname+(m.search||``),label:b(U.name,pt?.name??``,pt?.label??``)||_(U)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[U,n,pt?.showSearch,pt?.showFilters,pt?.showSort,pt?.name,pt?.label,i,u,H,m.pathname,m.search,b,_]);return(0,Q.jsx)(Te,{...W.actionProviderProps,children:(0,Q.jsxs)(_e,{value:Vt,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)(js,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:_(U)}),(0,Q.jsx)(Ws,{managedBy:U?.managedBy})]}),description:U.description?y(U):void 0,icon:(()=>{let e=is(U?.icon);return(0,Q.jsx)(e,{className:`h-4 w-4`})})(),actions:(0,Q.jsxs)(Q.Fragment,{children:[o&&(0,Q.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>k({id:`object:${o}`,label:_(U),href:`/apps/${a}/${o}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":O(`object:${o}`),"aria-label":O(`object:${o}`)?g(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):g(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${o}`,children:O(`object:${o}`)?(0,Q.jsx)(an,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(st,{className:`h-4 w-4`})}),Re&&Ve&&(0,Q.jsxs)(q,{size:`sm`,onClick:kt.create,disabled:Ue,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`object-view-new-button`,children:[(0,Q.jsx)(ze,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),(Qe||We&&Ke)&&(0,Q.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>Xe(!0),disabled:Je,className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:g(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Q.jsx)(ni,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.import`)})]}),U.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(Ae?(0,Q.jsx)(mm,{actions:Pe,entitlements:Me,onUpgrade:W.openEntitlementDialog}):(0,Q.jsx)(z,{schema:{type:`action:bar`,location:`list_toolbar`,actions:Ie,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),Re&&Ve&&(0,Q.jsx)(`button`,{type:`button`,onClick:kt.create,disabled:Ue,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 disabled:opacity-50 disabled:pointer-events-none`,"aria-label":g(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Q.jsx)(ze,{className:`h-5 w-5`})}),Ye&&(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(gm,{open:Ye,onOpenChange:Xe,objectName:U.name,objectLabel:_(U),fields:Qe?Jp(U.fields):Xp(U.name,U.fields,Se),dataSource:nt??e,...Qe?{extraOptionsContent:(0,Q.jsx)(Kp,{policy:$e,onPolicyChange:et}),renderResultExtra:e=>(0,Q.jsx)(qp,{serverResult:e?.serverResult})}:{},onComplete:e=>{De(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(g(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(g(`console.objectView.importedToast`,{count:t}))}})}),K.length>=1&&(()=>{let e=K.map(e=>{let t=rt.find(t=>$p(t)===e.id),n=!t;return{id:e.id,label:b(U.name,e.name||e.id,e.label||e.name||e.id),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?g(`console.objectView.systemViewReadonly`):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)(Is,{views:e,activeViewId:dt,onViewChange:ht,viewTypeIcons:_m,config:{reorderable:!1,showAddButton:H,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:H?Et:void 0,onRenameView:H?bt:void 0,onDeleteView:H?xt:void 0,onPinView:H?St:void 0,onSetDefaultView:H?Ct:void 0,onConfigView:H?Tt:void 0,onManageViews:H?()=>ie(!0):void 0}),H&&(0,Q.jsx)(Ps,{open:re,onOpenChange:ie,views:e,activeViewId:dt,viewTypeIcons:_m,onRename:bt,onDelete:xt,onSetDefault:Ct,onSetPinned:St,onReorder:wt,onAddView:Et,onConfigView:Tt})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[J.mode===`split`&&J.isOpen?(0,Q.jsx)(yr,{...J,setIsOpen:e=>{e||Ht()},title:_(U),onExpand:Wt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.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)(Ls,{schema:qt,dataSource:e,views:Kt,activeViewId:dt,onViewChange:ht,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Ut(e,t)},renderListView:Gt,onCreateView:_t,hideNamedViewTabs:!0,onViewAction:vt})})}),typeof ve==`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:g(`console.objectView.recordCount`,{count:ve})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(da,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.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)(Ls,{schema:qt,dataSource:e,views:Kt,activeViewId:dt,onViewChange:ht,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Ut(e,t)},renderListView:Gt,onCreateView:_t,hideNamedViewTabs:!0,onViewAction:vt})})})}),(0,Q.jsx)(zs,{open:h&&H,sections:[{title:`View Configuration`,data:pt},{title:`Object Definition`,data:U}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${N&&H?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(Lp,{open:N&&H,onClose:()=>{P(!1),te(`edit`)},mode:F,activeView:pt,objectDef:U,recordCount:ve,onSave:he,onViewUpdate:mt,onCreate:ge,metadataClient:j,dataSource:e,onAfterChange:()=>De(e=>e+1)})}),(0,Q.jsx)(Ms,{open:L&&H,onOpenChange:R,existingLabels:K.map(e=>e.label).filter(Boolean),objectDef:U,onCreate:e=>ge(e)})]}),J.mode!==`split`&&(0,Q.jsx)(yr,{...J,setIsOpen:e=>{e||Ht()},title:_(U),onExpand:Wt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(da,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.name,recordIdOverride:i,embedded:!0})}})]}),W.dialogs]})})}function Nm({appName:e,error:t,onRetry:n}){let{t:r}=I(),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)(Cn,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(Wt,{className:`h-8 w-8`}):(0,Q.jsx)(Xt,{className:`h-8 w-8`})}),(0,Q.jsx)(fi,{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)(oi,{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)(q,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(li,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}F();var Pm=(0,$.lazy)(()=>n(()=>import(`./RecordDetailView-uf81gH3J.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),Fm=(0,$.lazy)(()=>n(()=>import(`./DashboardView-CTBV4_tx.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Im=(0,$.lazy)(()=>n(()=>import(`./PageView-XUBdr6tb.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),Lm=(0,$.lazy)(()=>n(()=>import(`./ReportView-oFhBKNBE.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),Rm=(0,$.lazy)(()=>n(()=>import(`./SearchResultsPage-lgNcs7l7.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),zm=(0,$.lazy)(()=>n(()=>import(`./RecordFormPage-CLZcT8Z0.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),Bm=(0,$.lazy)(()=>n(()=>import(`./ComponentNavView-BVbkfJfE.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Vm=(0,$.lazy)(()=>n(()=>import(`./ObjectDataPage-BVV4yksz.js`).then(e=>({default:e.ObjectDataPage})),__vite__mapDeps([0]),import.meta.url)),Hm=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Um=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Wm=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),Gm=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Km=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),qm=(0,$.lazy)(()=>n(()=>import(`./metadata-admin-C_DEFfDE.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Jm=(0,$.lazy)(()=>n(()=>import(`./src-BA9h8a8o.js`).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]),import.meta.url)),Ym=(0,$.lazy)(()=>n(()=>import(`./src-BA9h8a8o.js`).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0]),import.meta.url)),Xm=(0,$.lazy)(()=>n(()=>import(`./src-BA9h8a8o.js`).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0]),import.meta.url)),Zm=(0,$.lazy)(()=>n(()=>import(`./MarketplacePage-njErv-tN.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Qm=(0,$.lazy)(()=>n(()=>import(`./MarketplacePackagePage-CMS--SE2.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),$m=(0,$.lazy)(()=>n(()=>import(`./MarketplaceInstalledPage-Cv-qDRNA.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function eh({appName:e}){let{reviewSeq:t,reviewTarget:n}=Ii(),r=p(),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 th({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,$.useState)(`disconnected`),{user:i,getAuthConfig:a,activeOrganization:o}=E(),d=v(),f=Ee(),[m,_]=(0,$.useState)({});(0,$.useEffect)(()=>{let e=!1;return a().then(t=>{e||_(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[a]);let y=p(),b=s(),{appName:x}=l(),{apps:S,objects:C,loading:w,ensureType:T,error:D,refresh:O}=H(),k=Pi(),{t:A}=I(),{objectLabel:j}=je(),[M,N]=(0,$.useState)(!T);(0,$.useEffect)(()=>{if(!T){N(!0);return}let e=!1;return Promise.all([T(`object`),T(`dashboard`),T(`report`),T(`page`)]).finally(()=>{e||N(!0)}),()=>{e=!0}},[T]);let F=S.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),te=b.pathname.split(`/`),ne=b.pathname.endsWith(`/create-app`),R=te.includes(`system`),re=te.includes(`metadata`),z=b.pathname===`/apps/setup`||b.pathname.startsWith(`/apps/setup/`),ae=ne||R||re||z,oe=Sa(S,x),B=oe||(!x||ae?F.find(e=>e.isDefault===!0)||F[0]:void 0),se=!!x&&!oe&&!ae,[ce,le]=(0,$.useState)(null),ue=ce&&ce.app===x?ce.phase:`idle`;(0,$.useEffect)(()=>{if(!se){ce!==null&&le(null);return}if(ue===`idle`&&!w&&!k&&x){let e=x;le({app:e,phase:`checking`}),Promise.resolve(O()).finally(()=>le(t=>t?.app===e?{app:e,phase:`done`}:t))}},[se,w,k,ue,ce,x,O]);let[de,fe]=(0,$.useState)(null);(0,$.useEffect)(()=>{if(!se||k||ue!==`done`||!x){fe(e=>e===null?e:null);return}if(de?.app===x)return;let e=f?.probeAppAccess;if(typeof e!=`function`){fe({app:x,verdict:`unknown`});return}let t=!1,n=x;return Promise.resolve(e.call(f,n)).then(e=>{t||fe({app:n,verdict:e})}).catch(()=>{t||fe({app:n,verdict:`unknown`})}),()=>{t=!0}},[se,k,ue,x,de,f]);let pe=de&&de.app===x?de.verdict:null;(0,$.useEffect)(()=>{if(!B?.name)return;let e=x??B.name,t=`/apps/${e}/metadata/package`;(b.pathname===t||b.pathname.startsWith(`${t}/`))&&y(`/apps/${e}/component/developer/packages`,{replace:!0})},[B?.name,x,b.pathname,y]);let[me,he]=c(),ge=me.get(fa),_e=me.get(oa),ve=me.get(ea),ye=(0,$.useMemo)(()=>ge&&ge!==`new`?{id:ge}:null,[ge]),be=(0,$.useMemo)(()=>{if(!ve)return;let e=ve.indexOf(`:`);if(!(e<=0))return{[ve.slice(0,e)]:ve.slice(e+1)}},[ve]),[xe,Se]=(0,$.useState)(0),Ce=!!ge,we=(0,$.useCallback)(()=>{let e=new URLSearchParams(window.location.search);!e.has(`form`)&&!e.has(`formObject`)&&!e.has(`formLink`)||(e.delete(fa),e.delete(oa),e.delete(ea),he(e,{replace:!0}))},[he]),{execute:Te,runner:De}=V();U(f),ie({dataSource:f??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),Se(e=>e+1),e?.objectName&&Oe({objectName:e.objectName,recordId:e.recordId})},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),Se(e=>e+1),e?.objectName&&Oe({objectName:e.objectName,recordId:e.recordId})}}),(0,$.useEffect)(()=>{De.registerHandler(`crud_success`,async e=>(we(),Se(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),De.registerHandler(`dialog_cancel`,async()=>(we(),{success:!0})),De.registerHandler(`navigate_create`,async e=>{let t=De.getContext?.()??{},n=_a({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n}),De.registerHandler(`navigate_edit`,async e=>{let t=De.getContext?.()??{},n=ga({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n})},[De,y,x,we]),(0,$.useEffect)(()=>{if(!f)return;let e=f.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(f.getConnectionState()),e},[f]);let W=b.pathname.split(`/`).filter(Boolean)[2];(W===`view`||W===`record`||W===`page`||W===`dashboard`||W===`design`)&&(W=``);let ke=C.find(e=>e.name===W),G=_e?C.find(e=>e.name===_e):ke,Ae=!!_e&&_e!==ke?.name,Me=(0,$.useCallback)(()=>{let e=G?j(G):A(`common.record`,{defaultValue:`Record`});Te({type:`crud_success`,params:{message:ye?A(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):A(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[Te,ye,G,j,A]),Ne=(0,$.useCallback)(()=>{Te({type:`dialog_cancel`})},[Te]),Fe=(0,$.useCallback)(async e=>{if(Ae){let e=G?j(G):A(`common.record`,{defaultValue:`Record`});X.success(ye?A(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):A(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})),we();return}if(Me(),ye||!ke)return;let t=va({objectName:ke.name,baseUrl:x?`/apps/${x}`:B?.name?`/apps/${B.name}`:``,pathname:b.pathname,search:window.location.search,surface:ee(ke),recordId:e?.id??e?._id});if(t.kind!==`none`){if(t.kind===`detail-page`){let e=new URLSearchParams(window.location.search);e.delete(fa),e.delete(oa),e.delete(ea);let n=e.toString(),r=`${b.pathname}${n?`?${n}`:``}`,i=j(ke);y(t.url,{replace:!0,state:i?{from:{pathname:r,label:i}}:void 0});return}y(t.url,{replace:!0})}},[Me,Ae,G,ye,ke,x,B?.name,b.pathname,y,we,j,A]);ff({pathname:b.pathname,appName:B?.name,objects:C});let Ie=e=>{let t=ba({objectDef:ke,baseUrl:x?`/apps/${x}`:B?.name?`/apps/${B.name}`:``,record:e});if(t.kind===`page`){y(t.url);return}let n=e?.id??e?._id,r=new URLSearchParams(window.location.search);r.set(fa,n!=null&&n!==``?String(n):`new`),r.delete(oa),r.delete(ea),he(r)},Le=e=>{y(`/apps/${e}`)},Re=(0,$.useMemo)(()=>new Pe({user:i?{name:i.name,email:i.email,role:i.role??`user`}:{},app:B||{},data:ye||{}}),[i,B,ye]);if(!f||w||!M)return(0,Q.jsx)(nc,{});if(k&&(se||!B))return(0,Q.jsx)(Nm,{appName:x,error:D,onRetry:()=>void O()});if(se)return ue!==`done`||pe===null?(0,Q.jsx)(nc,{}):pe===`denied`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(Cn,{"data-testid":`app-access-denied`,children:[(0,Q.jsx)(fi,{children:A(`empty.appAccessDenied`,{defaultValue:`You don't have access to this app`})}),(0,Q.jsx)(oi,{children:A(`empty.appAccessDeniedDescription`,{defaultValue:`This app exists, but your account is not authorized to open it. Ask an administrator to grant you access.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(q,{onClick:()=>y(`/home`),"data-testid":`app-access-denied-home`,children:A(`empty.appAccessDeniedHome`,{defaultValue:`Back to home`})})})]})}):(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:A(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(oi,{children:A(`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)(q,{onClick:()=>le(null),"data-testid":`app-not-available-retry`,children:A(`common.retry`,{defaultValue:`Retry`})})})]})});if(!B&&!ne&&!R&&!re&&!d)return(0,Q.jsx)(h,{to:`/home`,replace:!0});if(!B&&!ne&&!R&&!re)return(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:A(`empty.noAppsConfigured`)}),(0,Q.jsx)(oi,{children:A(`empty.noAppsConfiguredDescription`)}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Q.jsx)(q,{onClick:()=>y(`/apps/${x}/create-app`),"data-testid":`create-first-app-btn`,children:A(`empty.createFirstApp`)}),(0,Q.jsx)(q,{variant:`outline`,onClick:()=>y(`/apps/setup/system`),"data-testid":`go-to-settings-btn`,children:A(`empty.systemSettings`)})]})]})});if(!B&&(ne||R||re))return(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(nc,{}),children:(0,Q.jsxs)(g,{children:[(0,Q.jsx)(u,{path:`create-app`,element:(0,Q.jsx)(Jm,{})}),(0,Q.jsx)(u,{path:`system/marketplace`,element:(0,Q.jsx)(Zm,{})}),(0,Q.jsx)(u,{path:`system/marketplace/installed`,element:(0,Q.jsx)($m,{})}),(0,Q.jsx)(u,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Qm,{})}),(0,Q.jsx)(u,{path:`metadata`,element:(0,Q.jsx)(Hm,{})}),(0,Q.jsx)(u,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(qm,{})}),(0,Q.jsx)(u,{path:`metadata/:type`,element:(0,Q.jsx)(Wm,{})}),(0,Q.jsx)(u,{path:`metadata/:type/new`,element:(0,Q.jsx)(Gm,{createMode:!0})}),(0,Q.jsx)(u,{path:`metadata/:type/:name`,element:(0,Q.jsx)(Gm,{})}),(0,Q.jsx)(u,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(Km,{})}),(0,Q.jsx)(u,{path:`component/metadata/directory`,element:(0,Q.jsx)(sh,{mode:`directory`})}),(0,Q.jsx)(u,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(sh,{mode:`resource`})}),t,(0,Q.jsx)(u,{path:`*`,element:(0,Q.jsx)(lh,{})})]})});let ze=i?{id:i.id,name:i.name,email:i.email,role:i.role??`user`,roles:i.roles,isPlatformAdmin:i.isPlatformAdmin??!1,positions:i.positions??[]}:{name:`Anonymous`,email:``,role:`guest`,isPlatformAdmin:!1,positions:[]};return(0,Q.jsx)(Bi,{user:ze,app:B,data:{},features:m,children:(0,Q.jsxs)(L,{currentUserId:i?.id??null,currentOrgId:o?.id??null,children:[(0,Q.jsx)(af,{}),(0,Q.jsxs)(lp,{activeAppName:B.name,activeApp:B,onAppChange:Le,objects:C,connectionState:n,userId:i?.id,children:[(0,Q.jsx)(up,{apps:S,activeApp:B,objects:C,onAppChange:Le,dataSource:f}),(0,Q.jsx)(fp,{}),(0,Q.jsx)(pp,{}),(0,Q.jsx)(eh,{appName:x}),(0,Q.jsx)(Cp,{children:(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(nc,{}),children:(0,Q.jsx)(gp,{className:`h-full`,children:(0,Q.jsxs)(g,{children:[(0,Q.jsx)(u,{path:`/`,element:(()=>{let e=ih(B,{currentUserId:i?.id??null});return e?(0,Q.jsx)(h,{to:e,replace:!0}):(0,Q.jsx)(Um,{})})()}),(0,Q.jsx)(u,{path:`metadata/package/*`,element:(0,Q.jsx)(h,{to:`/apps/${x??B.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(u,{path:`metadata`,children:[(0,Q.jsx)(u,{index:!0,element:(0,Q.jsx)(Hm,{})}),(0,Q.jsx)(u,{path:`_diagnostics`,element:(0,Q.jsx)(qm,{})}),(0,Q.jsx)(u,{path:`:type`,element:(0,Q.jsx)(Wm,{})}),(0,Q.jsx)(u,{path:`:type/new`,element:(0,Q.jsx)(Gm,{createMode:!0})}),(0,Q.jsx)(u,{path:`:type/:name`,element:(0,Q.jsx)(Gm,{})}),(0,Q.jsx)(u,{path:`:type/:name/history`,element:(0,Q.jsx)(Km,{})})]}),(0,Q.jsx)(u,{path:`:objectName`,element:(0,Q.jsx)(jm,{dataSource:f,objects:C,onEdit:Ie,externalRefreshKey:xe})}),(0,Q.jsx)(u,{path:`:objectName/new`,element:(0,Q.jsx)(zm,{mode:`create`})}),(0,Q.jsx)(u,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(jm,{dataSource:f,objects:C,onEdit:Ie,externalRefreshKey:xe})}),(0,Q.jsx)(u,{path:`:objectName/data`,element:(0,Q.jsx)(Vm,{dataSource:f,objects:C})}),(0,Q.jsx)(u,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(Pm,{dataSource:f,objects:C,onEdit:Ie})}),(0,Q.jsx)(u,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(zm,{mode:`edit`})}),(0,Q.jsx)(u,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(Fm,{dataSource:f})}),(0,Q.jsx)(u,{path:`report/:reportName`,element:(0,Q.jsx)(Lm,{dataSource:f})}),(0,Q.jsx)(u,{path:`page/:pageName`,element:(0,Q.jsx)(Im,{})}),(0,Q.jsx)(u,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(Bm,{})}),(0,Q.jsx)(u,{path:`component/metadata/directory`,element:(0,Q.jsx)(sh,{mode:`directory`})}),(0,Q.jsx)(u,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(sh,{mode:`resource`})}),(0,Q.jsx)(u,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(Xm,{})}),(0,Q.jsx)(u,{path:`search`,element:(0,Q.jsx)(Rm,{})}),(0,Q.jsx)(u,{path:`create-app`,element:(0,Q.jsx)(Jm,{})}),(0,Q.jsx)(u,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(Ym,{})}),(0,Q.jsx)(u,{path:`system/marketplace`,element:(0,Q.jsx)(Zm,{})}),(0,Q.jsx)(u,{path:`system/marketplace/installed`,element:(0,Q.jsx)($m,{})}),(0,Q.jsx)(u,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Qm,{})}),e,(0,Q.jsx)(u,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(ch,{})}),(0,Q.jsx)(u,{path:`*`,element:(0,Q.jsx)(lh,{})})]})})})}),G&&(0,Q.jsx)(Ei,{schema:{type:`object-form`,formType:`modal`,objectName:G.name,mode:ye?`edit`:`create`,recordId:ye?.id,...be&&!ye?{initialValues:be}:{},...P(G,Ae?ye?`child-edit`:`child-create`:ye?`edit`:`create`).size===`full`?{modalSize:`full`}:{},...ya(G),title:A(ye?`form.editTitle`:`form.createTitle`,{object:j(G)}),open:Ce,onOpenChange:e=>{e||we()},layout:`vertical`,fields:G.fields?Array.isArray(G.fields)?G.fields.filter(e=>typeof e==`string`||Ri(e.visible,Re)).map(e=>typeof e==`string`?e:e.name):Object.entries(G.fields).filter(([e,t])=>Ri(t.visible,Re)).map(([e])=>e):[],onSuccess:Fe,onCancel:Ne,showSubmit:!0,showCancel:!0,submitText:ye?A(`form.update`,{defaultValue:A(`common.save`,{defaultValue:`Save`})}):A(`form.create`,{defaultValue:A(`common.create`,{defaultValue:`Create`})}),cancelText:A(`common.cancel`)},dataSource:f},`${G.name}:${ye?.id||`new`}`)]})]})})}function nh(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=rh(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=nh(n.children,t);if(e!==``)return e}}return``}function rh(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Po(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function ih(e,t){return nh(e?.navigation||[],t)}var ah=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function oh(e){return!e||ah.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function sh({mode:e}){let t=s(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Q.jsx)(h,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,i=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``,a=r?`${n}/metadata/${encodeURIComponent(r)}${i}${t.hash}`:`${n}/metadata${t.hash}`;return(0,Q.jsx)(h,{to:a,replace:!0})}function ch(){let{objectName:e,maybeRecordId:t}=l(),n=s();if(e&&oh(t)){let e=`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`;return(0,Q.jsx)(h,{to:e,replace:!0})}return(0,Q.jsx)(lh,{})}function lh(){let e=p(),{t}=I();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(oi,{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)(q,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function uh({children:e}){let{setContext:t}=Vi(),{t:n}=I(),r=p(),i=s(),a=(0,$.useCallback)(()=>{Zl(`${i.pathname}${i.search}`),r(`/ai`)},[i.pathname,i.search,r]),{enabled:o}=po();return(0,$.useEffect)(()=>{t(`home`)},[t]),(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)(zl,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),o&&(0,Q.jsx)(Dc,{appLabel:n(`workspace.default`,{defaultValue:`My Workspace`}),onOpenDock:a})]})}var dh=19,fh=[`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`],ph=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function mh(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function hh({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i,canAuthorMetadata:a=!0}){let{t:o}=I(),{appLabel:s}=je(),[c,l]=(0,$.useState)(!1),u=(0,$.useMemo)(()=>new Set(t.filter(e=>e.id.startsWith(`app:`)).map(e=>e.id.slice(4))),[t]),d=(0,$.useMemo)(()=>[...e].sort((e,t)=>!!u.has(t.name)-+!!u.has(e.name)),[e,u]),f=d.length-dh,p=c?d:d.slice(0,dh);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)(Ve,{className:`h-4 w-4`})}),(0,Q.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:o(`home.yourApps`,{defaultValue:`Your apps`})}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:d.length}),i&&a&&(0,Q.jsxs)(q,{variant:`ghost`,size:`sm`,className:`ml-auto h-8 text-muted-foreground`,onClick:r,"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(Vt,{className:`mr-1.5 h-4 w-4`}),o(`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:[p.map(e=>{let t=is(e.icon),r=s({name:e.name,label:Oa(e.label,o)}),i=u.has(e.name),a=fh[mh(e.name)%fh.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:Tr(`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`,ph,a),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)(an,{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)}),!c&&f>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(!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:[`+`,f]}),(0,Q.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:o(`home.showMoreApps`,{defaultValue:`More`})})]})]}),c&&f>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(!1),className:`mt-2.5 text-xs text-primary hover:underline`,children:o(`home.showLess`,{defaultValue:`Show less`})})]})}function gh({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 _h({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 vh({pendingApprovalsCount:e,notifications:t,unreadTopicCount:n,notificationsStatus:r,onOpenApprovals:i,onOpenNotification:a,t:o}){let{language:s}=I(),c=e+n,l=r===`ready`;return(0,Q.jsxs)(gh,{icon:Fr,accent:!0,count:c,title:o(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:[!l&&(0,Q.jsx)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,"data-testid":`home-action-unanswered`,children:r===`error`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Zr,{className:`h-4 w-4 text-amber-500`}),o(`errors.unknown`,{defaultValue:`An unexpected error occurred.`})]}):o(`common.loading`,{defaultValue:`Loading…`})}),c===0?l&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(An,{className:`h-4 w-4 text-emerald-500`}),o(`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)(_h,{icon:Fr,iconClass:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:o(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:e}),trailing:(0,Q.jsx)(Lt,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:i,testId:`home-action-approvals`}),t.map(e=>(0,Q.jsx)(_h,{icon:ot,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:Xc(e.createdAt,s),onClick:()=>a(e)},e.id))]})]})}var yh={object:tt,record:Mr,dashboard:sr,page:ei},bh={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 xh({items:e,onOpen:t,t:n}){return(0,Q.jsx)(gh,{icon:St,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)(_h,{icon:yh[e.type]||Mr,iconClass:bh[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 Sh({items:e,onViewAll:t,t:n}){let{language:r}=I();return(0,Q.jsxs)(gh,{icon:En,title:n(`sidebar.activityFeed`,{defaultValue:`Activity feed`}),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:[Xc(e.timestamp,r),` · `,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)(Lt,{className:`h-3 w-3`})]})]})}function Ch(e=5){let t=bl(),n=Ol(e),{value:r,status:i}=Ml();return{pendingApprovalsCount:t,notifications:(0,$.useMemo)(()=>{let t=new Set;return r.filter(e=>!e.is_read).filter(e=>(e.title??``).trim().length>0).map(e=>({id:e.id,title:String(e.title),actionUrl:e.action_url??void 0,createdAt:e.created_at??void 0})).filter(e=>!t.has(e.title)&&(t.add(e.title),!0)).slice(0,e)},[r,e]),unreadTopicCount:(0,$.useMemo)(()=>Zc(r).reduce((e,t)=>e+ +(t.unreadCount>0),0),[r]),notificationsStatus:i,activities:n}}function wh(){let e=(0,$.useMemo)(()=>Xa(),[]),{agents:t}=Ia({apiBase:e});return{aiEnabled:t.length>0,askAvailable:t.some(e=>Ra(e.name)),buildAvailable:t.some(e=>Ga(t,e.name,`authoring`))}}var Th=`manage_metadata`;function Eh(){let{hasCapabilities:e}=S();return e([Th])}function Dh({icon:e,title:t,subtitle:n,onClick:r,disabled:i,disabledReason:a,testId:o}){return(0,Q.jsxs)(`button`,{type:`button`,disabled:i,title:i?a:void 0,onClick:i?void 0:r,"data-testid":o,className:[`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors`,i?`cursor-not-allowed opacity-60`:`hover:border-primary/50 hover:bg-muted/40`].join(` `),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)(e,{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}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:n})]})]})}function Oh({askAvailable:e,buildAvailable:t,canAuthorMetadata:n,navigate:r,t:i,layout:a=`row`}){let o=t&&n;return!e&&!o?null:(0,Q.jsxs)(`div`,{className:a===`stack`?`mt-6 flex flex-col sm:flex-row items-center gap-3`:`flex shrink-0 items-center gap-2`,children:[o&&(0,Q.jsxs)(q,{onClick:()=>r(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(hn,{className:`mr-2 h-4 w-4`}),i(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&(0,Q.jsxs)(q,{variant:o?`outline`:`default`,onClick:()=>r(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,Q.jsx)(Vn,{className:`mr-2 h-4 w-4`}),i(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function kh(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Ah({t:e}){let t=ss(),[n,r]=(0,$.useState)([]),{publishAll:i,publishing:a}=wf(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)(un,{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)(q,{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 jh({t:e}){let t=p(),{hasLocalPassword:n,getAuthConfig:r}=E(),[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)(zr,{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)(q,{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)(Tn,{className:`h-4 w-4`})})]})})}):null}function Mh(){let e=p(),{t}=I(),{apps:n,loading:r}=H(),{recentItems:i}=Ji(),{favorites:a}=ma(),{user:o}=E(),s=v(),{pendingApprovalsCount:c,notifications:l,unreadTopicCount:u,notificationsStatus:d,activities:f}=Ch(),{currentAppName:m}=Vi(),{askAvailable:h,buildAvailable:g}=wh(),_=Eh(),y=t(`home.build.noCapability`,{defaultValue:`Building apps isn't available in this workspace — it requires the “Manage Metadata” permission, which your account doesn't have.`}),b=Ca(n),x=Ta(b,m),S=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),C=(0,$.useMemo)(()=>t(kh(new Date().getHours()),{defaultValue:`Welcome`}),[t]),w=(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…`})})}):b.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Q.jsx)(Ah,{t}),(0,Q.jsx)(jh,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s&&!_?(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(oi,{"data-testid":`home-authoring-gate-reason-empty`,children:y}),(0,Q.jsx)(Oh,{askAvailable:h,buildAvailable:g,canAuthorMetadata:_,navigate:e,t,layout:`stack`})]}):s?(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:t(`home.welcome`,{defaultValue:`Build your business system with AI`})}),(0,Q.jsx)(oi,{children:g?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 menu on the left.`}):h?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)(Oh,{askAvailable:h,buildAvailable:g,canAuthorMetadata:_,navigate:e,t,layout:`stack`})]}):(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(oi,{children:t(`home.noAppsDescription`,{defaultValue:`Your workspace is being set up — apps your admin shares with you will show up here.`})})]})})]}):(0,Q.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Q.jsx)(Ah,{t}),(0,Q.jsx)(jh,{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:[C,w?`, `:``]}),w&&(0,Q.jsx)(`span`,{className:`text-primary`,children:w}),(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)(Oh,{askAvailable:h,buildAvailable:g,canAuthorMetadata:_,navigate:e,t})]}),s&&(0,Q.jsxs)(`div`,{className:`mb-6`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,Q.jsx)(Dh,{icon:Lr,title:t(`home.build.title`,{defaultValue:`Build an app`}),subtitle:t(`home.build.subtitle`,{defaultValue:`Start from scratch — design objects, forms, automations and interfaces.`}),onClick:()=>e(`/studio`),disabled:!_,disabledReason:y,testId:`home-build-app`}),(0,Q.jsx)(Dh,{icon:fr,title:t(`home.template.title`,{defaultValue:`Start with a template`}),subtitle:t(`home.template.subtitle`,{defaultValue:`Install a template app from the marketplace and customize it.`}),onClick:()=>e(`/apps/setup/system/marketplace`),disabled:!_,disabledReason:y,testId:`home-start-template`})]}),!_&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,"data-testid":`home-authoring-gate-reason`,children:y})]}),(0,Q.jsx)(hh,{apps:b,favorites:a,onOpen:t=>e(`/apps/${wa(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:s,canAuthorMetadata:_}),(0,Q.jsx)(`div`,{className:`mb-6`,children:(0,Q.jsx)(vh,{pendingApprovalsCount:c,notifications:l,unreadTopicCount:u,notificationsStatus:d,onOpenApprovals:()=>e(`/apps/${x}/system/approvals`),onOpenNotification:t=>{let n=Da(t.actionUrl,x);if(!n){e(`/apps/${x}/sys_inbox_message?view=mine`);return}if(n.kind===`external`){window.open(n.url,`_blank`,`noopener,noreferrer`);return}e(n.path)},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)(xh,{items:S,onOpen:t=>e(t),t}),(0,Q.jsx)(Sh,{items:f,onViewAll:()=>e(`/apps/${x}/sys_activity`),t})]})]})})]})}function Nh({children:e}){let{setContext:t}=Vi();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)(zl,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function Ph(e){let t=await D()(`${Mo()}/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(()=>null))?.data;if(!n||typeof n!=`object`)throw Error("Malformed control-plane response: expected a `{ success, data }` envelope from POST /cloud/environments");return n}var Fh={YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION:{key:`organization.errors.notAllowedToInvite`,defaultValue:`You are not allowed to invite users to this organization`},YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE:{key:`organization.errors.notAllowedToInviteWithRole`,defaultValue:`You are not allowed to invite a user with this role`},USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION:{key:`organization.errors.alreadyInvited`,defaultValue:`This user has already been invited to this organization`},ORGANIZATION_ALREADY_EXISTS:{key:`organization.errors.organizationExists`,defaultValue:`Organization already exists`},ORGANIZATION_SLUG_ALREADY_TAKEN:{key:`organization.errors.slugTaken`,defaultValue:`That URL slug is already taken`},YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION:{key:`organization.errors.notAllowedToCreate`,defaultValue:`You are not allowed to create a new organization`},YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION:{key:`organization.errors.notTheRecipient`,defaultValue:`You are not the recipient of the invitation`},INVITATION_NOT_FOUND:{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}},Ih={key:`organization.errors.unknown`,defaultValue:`Something went wrong. Please try again.`};function Lh(e){if(typeof e!=`object`||!e)return;let t=e.code;return typeof t==`string`&&t?t:void 0}function Rh(e,t,n){let r=Lh(e);if(r){let e=Fh[r];if(e)return t(e.key,{defaultValue:e.defaultValue})}let i=e instanceof Error?e.message:void 0;return typeof i==`string`&&i.trim()?i:n?t(n.key,{defaultValue:n.defaultValue}):t(Ih.key,{defaultValue:Ih.defaultValue})}function zh(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 Bh({open:e,onOpenChange:t,onCreated:n}){let{t:r}=I(),{createOrganization:i,getAuthConfig:a}=E(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[g,_]=(0,$.useState)(!1);(0,$.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,$.useEffect)(()=>{u||l(zh(o))},[o,u]),(0,$.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]);let v=(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 Ph({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(Rh(e,r,{key:`workspace.createFailed`,defaultValue:`Failed to create workspace`}))}finally{p(!1)}}},[o,c,g,r,i,n]);return(0,Q.jsx)(Pn,{open:e,onOpenChange:t,children:(0,Q.jsx)(di,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Q.jsxs)(`form`,{onSubmit:v,children:[(0,Q.jsxs)(ci,{children:[(0,Q.jsx)(Yt,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(Kt,{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)(K,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(J,{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)(K,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(J,{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)(Ke,{children:[(0,Q.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(q,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function Vh(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Hh(){let{t:e}=I(),t=p(),[n]=c(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:a,activeOrganization:o,isOrganizationsLoading:s,switchOrganization:l,getAuthConfig:u}=E(),[d,f]=(0,$.useState)(``),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(null),[v,y]=(0,$.useState)(!0);(0,$.useEffect)(()=>{let e=!1;return u().then(t=>{e||t?.features?.multiOrgEnabled===!1&&y(!1)}).catch(()=>{}),()=>{e=!0}},[u]);let b=a??[],x=(0,$.useMemo)(()=>{let e=d.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):b},[b,d]),S=async e=>{_(e.id);try{e.id!==o?.id&&await l(e.id),window.location.href=zc()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),_(null)}},C=e=>{h(!1),S(e)},w=(0,$.useRef)(!1);(0,$.useEffect)(()=>{w.current||s||i||b.length===1&&(w.current=!0,r?t(`/organizations/${b[0].slug}/members`,{replace:!0}):S(b[0]))},[s,b.length,r,i]);let T=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(s)return;let e=b.length===0&&v;(i||e)&&!T.current&&(T.current=!0,h(!0))},[i,b.length,v,s]);let D=!i&&!s&&b.length===1,O=!s&&b.length===0&&v&&!T.current;return s||D||O?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(Y,{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 Workspaces`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select a workspace 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)(Fn,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(J,{value:d,onChange:e=>f(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for a workspace`}),className:`pl-9`,"data-testid":`organizations-search`})]}),v&&(0,Q.jsxs)(q,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(ze,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}),b.length===0?(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(fi,{children:e(`organizations.emptyTitle`,{defaultValue:`No workspaces yet`})}),(0,Q.jsx)(oi,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first workspace to get started.`})}),v&&(0,Q.jsxs)(q,{className:`mt-6`,onClick:()=>h(!0),children:[(0,Q.jsx)(ze,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}):x.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 workspaces match your search.`})}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:x.map(n=>{let r=n.id===o?.id,i=g===n.id;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>S(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)(Et,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(bi,{src:n.logo,alt:n.name}),(0,Q.jsx)(Ht,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Vh(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 workspace`}):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)(Y,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Q.jsx)(Bh,{open:m,onOpenChange:h,onCreated:C})]})}function Uh(){let{t:e}=I(),t=p(),{slug:n}=l(),{organizations:r,activeOrganization:i,isOrganizationsLoading:o,switchOrganization:s}=E(),{setContext:c}=Vi();(0,$.useEffect)(()=>{c(`home`)},[c]);let u=(0,$.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,$.useEffect)(()=>{u&&i?.id!==u.id&&s(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,i,s]),o)return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)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)(q,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let d=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,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)(zl,{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`,{type:`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)(Hn,{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:u.name}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,Q.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:d.map(e=>(0,Q.jsx)(f,{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)(a,{context:{org:u}})})})]})}function Wh(){return d()}function Gh(e){return Object.prototype.hasOwnProperty.call(w,e)}function Kh(e,t){if(typeof e!=`string`)return``;let n=e.trim();if(!n)return``;if(!Gh(n))return n;let r=w[n];return t(r.key,{defaultValue:r.defaultValue})}function qh({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=I(),{inviteMember:a,describeDelegableScope:o,activeMember:s}=E(),c=x(s?.role),[l,u]=(0,$.useState)(``),[d,f]=(0,$.useState)(O),[p,m]=(0,$.useState)(!1),[h,g]=(0,$.useState)(null),[_,v]=(0,$.useState)(null),[y,b]=(0,$.useState)(!1),[S,C]=(0,$.useState)(null),[w,T]=(0,$.useState)(``),[D,k]=(0,$.useState)([]);(0,$.useEffect)(()=>{t&&(u(``),f(O),g(null),v(null),b(!1),T(``),k([]))},[t]),(0,$.useEffect)(()=>{if(!t)return;let e=!1;return o?.().then(t=>{e||C(t)}).catch(()=>{}),()=>{e=!0}},[t,o]);let A=!!S&&S.placeableBusinessUnitIds.length>0&&S.assignablePositions.length>0,j=(0,$.useCallback)(async t=>{if(t.preventDefault(),l.trim()){m(!0),g(null);try{let t=await a({organizationId:e,email:l.trim(),role:d,...A&&w&&D.length>0?{businessUnitId:w,positions:D}:{}});v(t),r?.(t)}catch(e){g(Rh(e,i,{key:`organization.invitations.inviteFailed`,defaultValue:`Failed to invite member`}))}finally{m(!1)}}},[l,d,e,a,r,A,w,D,i]),M=_?Bc(`accept-invitation/${_.id}`):null,N=(0,$.useCallback)(async()=>{if(M)try{await navigator.clipboard.writeText(M),b(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>b(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[M,i]);return(0,Q.jsx)(Pn,{open:t,onOpenChange:n,children:(0,Q.jsx)(di,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:_?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(ci,{children:[(0,Q.jsx)(Yt,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(Kt,{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)(K,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{readOnly:!0,value:M??``,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(q,{type:`button`,variant:`outline`,size:`icon`,onClick:N,"aria-label":i(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:y?(0,Q.jsx)(pi,{className:`h-4 w-4`}):(0,Q.jsx)(Ut,{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:_.email,role:Kh(_.role,i)})})]}),(0,Q.jsx)(Ke,{children:(0,Q.jsx)(q,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:j,children:[(0,Q.jsxs)(ci,{children:[(0,Q.jsx)(Yt,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(Kt,{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)(K,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(J,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:l,onChange:e=>u(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(K,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(Ze,{value:d,onValueChange:e=>f(e),children:[(0,Q.jsx)(dr,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(Be,{})}),(0,Q.jsx)(Je,{children:c.map(e=>(0,Q.jsx)(jt,{value:e,"data-testid":`invite-role-${e}`,children:Kh(e,i)},e))})]})]}),A&&(0,Q.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-dashed p-3`,"data-testid":`invite-placement-section`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,Q.jsx)(K,{className:`text-sm`,children:i(`organization.invitations.placementLabel`,{defaultValue:`Placement (optional)`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.placementDescription`,{defaultValue:`Applied when the invitation is accepted. Only units and positions you may delegate are listed.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(K,{htmlFor:`invite-business-unit`,className:`text-xs`,children:i(`organization.invitations.businessUnitLabel`,{defaultValue:`Business unit`})}),(0,Q.jsxs)(Ze,{value:w,onValueChange:T,children:[(0,Q.jsx)(dr,{id:`invite-business-unit`,"data-testid":`invite-business-unit-select`,children:(0,Q.jsx)(Be,{placeholder:i(`organization.invitations.businessUnitPlaceholder`,{defaultValue:`No placement`})})}),(0,Q.jsx)(Je,{children:S.placeableBusinessUnitIds.map(e=>(0,Q.jsx)(jt,{value:e,children:e},e))})]})]}),w&&(0,Q.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`invite-positions`,children:[(0,Q.jsx)(K,{className:`text-xs`,children:i(`organization.invitations.positionsLabel`,{defaultValue:`Positions`})}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:S.assignablePositions.map(e=>{let t=D.includes(e);return(0,Q.jsx)(q,{type:`button`,size:`sm`,variant:t?`default`:`outline`,"data-testid":`invite-position-${e}`,"aria-pressed":t,onClick:()=>k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),children:e},e)})})]})]}),h&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:h})]}),(0,Q.jsxs)(Ke,{children:[(0,Q.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:p,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(q,{type:`submit`,disabled:p||!l.trim(),"data-testid":`invite-submit`,children:[p&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}var Jh=T(M);function Yh(e){return typeof e==`string`?e.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]}function Xh(e){return T(e)>=Jh||Yh(e).includes(k)}function Zh(e){return T(e)>=Jh}function Qh(e){return T(e)>=Jh}function $h(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function eg(){let{t:e}=I(),{org:t}=Wh(),{getMembers:n,removeMember:r,updateMemberRole:i,activeMember:a}=E(),o=Xh(a?.role),s=Zh(a?.role),[c,l]=(0,$.useState)([]),[u,d]=(0,$.useState)(!0),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(null),v=(0,$.useCallback)(async()=>{d(!0),p(null);try{let e=await n(t.id);l(e)}catch(t){p(Rh(t,e,{key:`organization.members.loadFailed`,defaultValue:`Failed to load members`}))}finally{d(!1)}},[t.id,n,e]);(0,$.useEffect)(()=>{v()},[v]);let b=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),v()}catch(t){X.error(Rh(t,e,{key:`organization.members.roleUpdateFailed`,defaultValue:`Failed to update role`}))}};return u?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):f?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[f,(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:v,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`}),` (`,c.length,`)`]}),o?(0,Q.jsx)(q,{onClick:()=>h(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`invite-restricted-note`,children:e(`organization.members.inviteRestrictedNote`,{defaultValue:`Only organization admins can invite members.`})})]}),(0,Q.jsx)(Jt,{}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:c.map(t=>{let n=y(a?.role,t.role),r=n.length>0||s;return(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)(Et,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(bi,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(Ht,{className:`text-xs font-medium`,children:$h(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)(mt,{variant:`outline`,className:`shrink-0`,"data-testid":`member-role-badge-${t.id}`,children:Kh(t.role,e)}),t.createdAt&&(0,Q.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),r&&(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(Rt,{asChild:!0,children:(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":e(`organization.members.memberActions`,{defaultValue:`Member actions`}),children:(0,Q.jsx)(Mt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(cn,{align:`end`,children:[n.map(n=>(0,Q.jsxs)(bt,{onClick:()=>b(t,n),disabled:t.role===n,"data-testid":`member-role-${n}`,children:[(0,Q.jsx)(br,{className:`mr-2 h-4 w-4`}),e(w[n].key,{defaultValue:w[n].defaultValue})]},n)),s&&(0,Q.jsxs)(bt,{className:`text-destructive focus:text-destructive`,onClick:()=>_(t),children:[(0,Q.jsx)($n,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id)})}),(0,Q.jsx)(en,{open:!!g,onOpenChange:e=>!e&&_(null),children:(0,Q.jsxs)(xt,{children:[(0,Q.jsxs)(_n,{children:[(0,Q.jsx)(mn,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(Rr,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:g?.user?.name??g?.userId??``})})]}),(0,Q.jsxs)(_t,{children:[(0,Q.jsx)(it,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(ln,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(g)try{await r({organizationId:t.id,memberIdOrUserId:g.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),_(null),v()}catch(t){X.error(Rh(t,e,{key:`organization.members.removeFailed`,defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),o&&(0,Q.jsx)(qh,{organizationId:t.id,open:m,onOpenChange:h,onInvited:()=>v()})]})}function tg(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`}}function ng(){let{t:e}=I(),{org:t}=Wh(),{listInvitations:n,cancelInvitation:r,activeMember:i}=E(),a=Qh(i?.role),o=Xh(i?.role),[s,c]=(0,$.useState)([]),[l,u]=(0,$.useState)(!0),[d,f]=(0,$.useState)(null),[p,m]=(0,$.useState)(`all`),[h,g]=(0,$.useState)(null),[_,v]=(0,$.useState)(null),y=(0,$.useCallback)(async()=>{u(!0),f(null);try{let e=await n(t.id);c(e)}catch(t){f(Rh(t,e,{key:`organization.invitations.loadFailed`,defaultValue:`Failed to load invitations`}))}finally{u(!1)}},[t.id,n,e]);(0,$.useEffect)(()=>{y()},[y]);let b=async t=>{let n=Bc(`accept-invitation/${t.id}`);try{await navigator.clipboard.writeText(n),v(t.id),X.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>v(null),2e3)}catch{X.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},x=async()=>{if(h)try{await r(h.id),X.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),g(null),y()}catch(t){X.error(Rh(t,e,{key:`organization.invitations.cancelFailed`,defaultValue:`Failed to cancel invitation`}))}},S=p===`all`?s:s.filter(e=>e.status===p),C={all:s.length,pending:s.filter(e=>e.status===`pending`).length,accepted:s.filter(e=>e.status===`accepted`).length,rejected:s.filter(e=>e.status===`rejected`).length,canceled:s.filter(e=>e.status===`canceled`).length};return l?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):d?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[d,(0,Q.jsx)(q,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:y,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`,{type:`button`,onClick:()=>m(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${p===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),C[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:C[t]})]},t))}),(0,Q.jsx)(Jt,{}),S.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:S.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)(Et,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(Ht,{className:`text-xs`,children:(0,Q.jsx)(xn,{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)(mt,{variant:`outline`,className:`shrink-0`,"data-testid":`invitation-role-badge-${t.id}`,children:Kh(t.role,e)}),(0,Q.jsx)(mt,{variant:tg(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(o||a)&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[o&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>b(t),"aria-label":e(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:_===t.id?(0,Q.jsx)(pi,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(Ut,{className:`h-4 w-4`})}),a&&(0,Q.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>g(t),"aria-label":e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`}),children:(0,Q.jsx)(Tn,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)(en,{open:!!h,onOpenChange:e=>!e&&g(null),children:(0,Q.jsxs)(xt,{children:[(0,Q.jsxs)(_n,{children:[(0,Q.jsx)(mn,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(Rr,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:h?.email??``})})]}),(0,Q.jsxs)(_t,{children:[(0,Q.jsx)(it,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(ln,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:x,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function rg(){let{t:e}=I(),{org:t}=Wh(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=E(),s=p(),[c,l]=(0,$.useState)(t.name),[u,d]=(0,$.useState)(t.slug??``),[f,m]=(0,$.useState)(t.logo??``),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(!1),y=(0,$.useRef)(null),{upload:b}=At(),[x,S]=(0,$.useState)(null),[C,w]=(0,$.useState)(!0),[T,D]=(0,$.useState)(!1),[O,k]=(0,$.useState)(!1),[A,j]=(0,$.useState)(``),[M,N]=(0,$.useState)(!1);(0,$.useEffect)(()=>{l(t.name),d(t.slug??``),m(t.logo??``)},[t]),(0,$.useEffect)(()=>{let e=!1;return w(!0),r(t.id).then(t=>{if(e)return;let r=t.find(e=>e.userId===n?.id);S(r?.role===`owner`)}).catch(()=>{e||S(!1)}).finally(()=>{e||w(!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 C?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{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)(Jt,{className:`my-4`}),x?(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)(K,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(J,{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)(K,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(J,{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)(K,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Et,{className:`size-16 rounded-md`,children:[f?(0,Q.jsx)(bi,{src:f,alt:c,className:`object-cover`}):null,(0,Q.jsx)(Ht,{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:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{let t=await b(n);m(t.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{v(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:_,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[_?(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(ni,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Q.jsxs)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Q.jsx)(Tn,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(J,{id:`org-logo`,type:`url`,value:f,onChange:e=>m(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Q.jsxs)(q,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,Q.jsx)(Y,{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)(Jt,{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)(q,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Q.jsx)(Jt,{}),(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)(q,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(en,{open:T,onOpenChange:D,children:(0,Q.jsxs)(xt,{children:[(0,Q.jsxs)(_n,{children:[(0,Q.jsx)(mn,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(Rr,{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)(_t,{children:[(0,Q.jsx)(it,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(ln,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!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{N(!1)}},disabled:M,children:[M&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Q.jsx)(en,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Q.jsxs)(xt,{children:[(0,Q.jsxs)(_n,{children:[(0,Q.jsx)(mn,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(Rr,{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)(K,{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)(J,{id:`delete-confirm-slug`,className:`mt-2`,value:A,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Q.jsxs)(_t,{children:[(0,Q.jsx)(it,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(ln,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!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{N(!1)}},disabled:M||A!==t.slug,children:[M&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function ig(){let{t:e}=I(),t=p(),n=s(),{invitationId:r}=l(),{isAuthenticated:i,isLoading:a,getInvitation:o,acceptInvitation:c,rejectInvitation:u,switchOrganization:d}=E(),[f,m]=(0,$.useState)(null),[h,g]=(0,$.useState)(!0),[_,v]=(0,$.useState)(null),[y,b]=(0,$.useState)(!1),[x,S]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{!a&&!i&&t(`/login?redirect=`+encodeURIComponent(n.pathname+n.search))},[i,a,t,n.pathname,n.search]),(0,$.useEffect)(()=>{if(!r||!i)return;let t=!1;return g(!0),v(null),o(r).then(e=>{t||m(e)}).catch(n=>{t||v(Rh(n,e,{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}))}).finally(()=>{t||g(!1)}),()=>{t=!0}},[r,i,o,e]),a?(0,Q.jsx)(`div`,{className:`flex min-h-svh items-center justify-center`,children:(0,Q.jsx)(Y,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):i?(0,Q.jsx)(`div`,{className:`flex min-h-svh items-center justify-center px-4 py-12 bg-background`,children:(0,Q.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-8 shadow-sm`,"data-testid":`accept-invitation-page`,children:h?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8`,children:[(0,Q.jsx)(Y,{className:`h-8 w-8 animate-spin text-muted-foreground`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`organization.accept.loading`,{defaultValue:`Loading invitation…`})})]}):_?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,Q.jsx)(zt,{className:`h-10 w-10 text-destructive`}),(0,Q.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.accept.errorTitle`,{defaultValue:`Invitation unavailable`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_}),(0,Q.jsx)(q,{variant:`outline`,onClick:()=>t(`/organizations`),children:e(`organization.accept.goToOrgs`,{defaultValue:`Go to organizations`})})]}):f?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[(0,Q.jsx)(`div`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-primary/10`,children:(0,Q.jsx)(ar,{className:`h-7 w-7 text-primary`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-xl font-bold`,children:e(`organization.accept.title`,{defaultValue:`You have been invited`})}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.accept.description`,{defaultValue:`You have been invited to join {{orgName}} as {{role}}.`,orgName:f.organizationName??f.organizationId,role:Kh(f.role,e)})})]}),(0,Q.jsxs)(`div`,{className:`w-full rounded-lg border bg-muted/50 p-4 text-left space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.organization`,{defaultValue:`Organization`})}),(0,Q.jsx)(`span`,{className:`font-medium`,children:f.organizationName??f.organizationId})]}),(0,Q.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.role`,{defaultValue:`Role`})}),(0,Q.jsx)(`span`,{className:`font-medium`,"data-testid":`accept-invitation-role`,children:Kh(f.role,e)})]}),f.expiresAt&&(0,Q.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.expiresAt`,{defaultValue:`Expires`})}),(0,Q.jsx)(`span`,{className:`font-medium`,children:new Date(f.expiresAt).toLocaleDateString()})]})]}),(0,Q.jsxs)(`div`,{className:`flex w-full gap-3`,children:[(0,Q.jsxs)(q,{variant:`outline`,className:`flex-1`,onClick:async()=>{if(r){S(!0);try{await u(r),X.success(e(`organization.accept.declined`,{defaultValue:`Invitation declined`})),t(`/organizations`)}catch(t){X.error(Rh(t,e,{key:`organization.accept.declineFailed`,defaultValue:`Failed to decline invitation`})),S(!1)}}},disabled:x||y,children:[x&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.accept.decline`,{defaultValue:`Decline`})]}),(0,Q.jsxs)(q,{className:`flex-1`,onClick:async()=>{if(!(!f||!r)){b(!0);try{await c(r),await d(f.organizationId).catch(()=>null),X.success(e(`organization.accept.accepted`,{defaultValue:`Invitation accepted`})),t(`/home`)}catch(t){X.error(Rh(t,e,{key:`organization.accept.acceptFailed`,defaultValue:`Failed to accept invitation`})),b(!1)}}},disabled:y||x,children:[y&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),(0,Q.jsx)(In,{className:`mr-2 h-4 w-4`}),e(`organization.accept.accept`,{defaultValue:`Accept invitation`})]})]})]}):null})}):null}function ag(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function og(e){if(!ag(e))return;let t=e.config;if(ag(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`}Ks({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:Eo}),Ks({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:io}),Ks({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:co}),ho({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`}]}),ho({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`}]}),ho({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. The only capability container (ADR-0090); distributed to users via positions.`,domain:`security`,EditPage:fo,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`managedBy`,label:`Source`,width:`15%`,render:e=>e===`package`?`Package`:`Custom`}]}),ho({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)=>og(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!j(e)}),ho({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`}]}),ho({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`}]}),ho({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&&`permissionSet`in e?`permission set: ${e.permissionSet}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var sg=`/api/v1/cloud-connection`;async function cg(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 lg(){let{t:e,language:t}=I(),[n,r]=(0,$.useState)({kind:`loading`}),[i,a]=(0,$.useState)(!1),[o,s]=(0,$.useState)(!1),c=(0,$.useRef)(null),l=(0,$.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null)},[]),u=(0,$.useCallback)(async()=>{try{let e=(await cg(`${sg}/status`))?.data??{environmentId:null,bound:!1,connection:null};r(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){r({kind:`error`,message:e?.message??String(e)})}},[]);(0,$.useEffect)(()=>(u(),l),[u,l]);let d=(0,$.useCallback)((t,n)=>{let i=Math.max(t.interval,2)*1e3,a=async()=>{if(Date.now()-n>t.expires_in*1e3){r({kind:`error`,message:e(`cloudConnection.errors.expired`)});return}try{let n=await cg(`${sg}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:t.device_code})});if(n?.data?.pending){c.current=setTimeout(a,i);return}if(n?.data?.bound||n?.success){await u();return}r({kind:`error`,message:n?.error?.message??n?.error?.code??e(`cloudConnection.errors.bindFailed`)})}catch(e){r({kind:`error`,message:e?.message??String(e)})}};c.current=setTimeout(a,i)},[u,e]),f=(0,$.useCallback)(async()=>{a(!0);try{let t=(await cg(`${sg}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!t?.device_code||!t?.user_code)throw Error(e(`cloudConnection.errors.deviceCodeFailed`));let n=t.verification_uri_complete??t.verification_uri,i=!1;if(n)try{i=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}r({kind:`waiting`,code:t,popupOpened:i}),d(t,Date.now())}catch(e){r({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[d,e]),p=(0,$.useCallback)(async()=>{a(!0);try{await cg(`${sg}/unbind`,{method:`POST`,body:`{}`}),await u()}catch(e){r({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[u]),m=(0,$.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}},[]);if(n.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)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` `,e(`cloudConnection.checking`)]});if(n.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)(Zr,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,n.message]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:e(`cloudConnection.retry`)})]});if(n.kind===`waiting`){let t=n.code.verification_uri_complete??n.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)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),n.popupOpened?e(`cloudConnection.waiting.popupOpened`):e(`cloudConnection.waiting.polling`)]}),!n.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:[e(`cloudConnection.waiting.openApproval`),` `,(0,Q.jsx)(Ye,{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:n.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 m(n.code.user_code),children:[(0,Q.jsx)(Ut,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(o?`cloudConnection.waiting.copied`:`cloudConnection.waiting.copy`)]})]}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e(`cloudConnection.waiting.codePrefilled`),n.popupOpened&&t?(0,Q.jsxs)(Q.Fragment,{children:[` `,(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:[e(`cloudConnection.waiting.openItHere`),` `,(0,Q.jsx)(Ye,{className:`h-3 w-3`,"aria-hidden":`true`})]})]}):null]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:e(`cloudConnection.waiting.cancel`)})]})}if(n.kind===`bound`){let r=n.status.connection??{},a=r.runtime_id??n.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)(Wr,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.bound.title`)})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[r.name?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtime`)}),(0,Q.jsx)(`dd`,{children:r.name})]}):null,r.organization_id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.organization`)}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:r.organization_id})]}):null,r.account_email?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.approvedBy`)}),(0,Q.jsx)(`dd`,{children:r.account_email})]}):null,a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtimeId`)}),(0,Q.jsx)(`dd`,{className:`font-mono text-xs`,children:a})]}):null,n.status.environmentId?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.environment`)}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:n.status.environmentId})]}):null,r.bound_at?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.since`)}),(0,Q.jsx)(`dd`,{children:new Date(r.bound_at).toLocaleString(t)})]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.bound.privatePackages`)}),(0,Q.jsxs)(`button`,{type:`button`,disabled:i,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void p(),children:[(0,Q.jsx)(mi,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,e(`cloudConnection.bound.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)(at,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.unbound.title`)})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.unbound.body`)}),(0,Q.jsxs)(`button`,{type:`button`,disabled:i,className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void f(),children:[i?(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(tn,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`cloudConnection.unbound.connect`)]})]})}oe.register(`cloud-connection:panel`,()=>(0,Q.jsx)(lg,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var ug=``.replace(/\/$/,``);function dg(e){let t=_.get();return t?{...e,Authorization:`Bearer ${t}`}:e}function fg(e){let t=ug||(typeof window<`u`?window.location.origin:``);try{return new URL(e,t||void 0).toString()}catch{return e}}function pg({text:e,label:t}){let[n,r]=(0,$.useState)(!1);return(0,Q.jsxs)(q,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)}catch{}},children:[n?(0,Q.jsx)(pi,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(Ut,{className:`h-3.5 w-3.5`}),t?(0,Q.jsx)(`span`,{className:`ml-1`,children:t}):null]})}function mg({text:e}){return(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`pre`,{className:`flex-1 overflow-x-auto rounded-md bg-muted px-3 py-2 text-xs leading-relaxed`,children:(0,Q.jsx)(`code`,{children:e})}),(0,Q.jsx)(pg,{text:e})]})}function hg(){let{t:e}=I(),[t,n]=(0,$.useState)(!0),[r,i]=(0,$.useState)(null),[a,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null),[p,m]=(0,$.useState)(null);(0,$.useEffect)(()=>{(async()=>{try{let e=await(await fetch(`${ug}/api/v1/discovery`,{credentials:`include`})).json().catch(()=>({})),t=(e?.data??e)?.routes??{};i(typeof t.mcp==`string`?fg(t.mcp):null)}catch(e){o(e?.message??String(e))}finally{n(!1)}})()},[]);let h=r?`${r}/skill`:null,g=(0,$.useMemo)(()=>{if(!r)return null;let e=btoa(JSON.stringify({url:r}));return`cursor://anysphere.cursor-deeplink/mcp/install?name=objectstack&config=${encodeURIComponent(e)}`},[r]);return t?(0,Q.jsxs)(`div`,{className:`space-y-3 p-1`,children:[(0,Q.jsx)(ri,{className:`h-10 w-full`}),(0,Q.jsx)(ri,{className:`h-40 w-full`})]}):r?(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsxs)(Pt,{className:`flex items-center gap-2 text-base`,children:[(0,Q.jsx)(Bt,{className:`h-4 w-4`}),e(`connectAgent.url.title`)]})}),(0,Q.jsxs)(cr,{className:`space-y-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`connectAgent.url.body`)}),(0,Q.jsx)(mg,{text:r}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[h&&(0,Q.jsx)(q,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Q.jsxs)(`a`,{href:h,download:`SKILL.md`,children:[(0,Q.jsx)(lr,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.url.downloadSkill`)]})}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.url.skillHint`)})]})]})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsx)(Pt,{className:`text-base`,children:`Claude (claude.ai / Desktop)`})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claude.body`)}),(0,Q.jsx)(mg,{text:r}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.claude.reachability`)})]})]}),(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsx)(Pt,{className:`text-base`,children:`Claude Code`})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.body`)}),(0,Q.jsx)(mg,{text:`claude mcp add --transport http objectstack ${r}`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.plugin`)}),(0,Q.jsx)(mg,{text:`claude plugin marketplace add objectstack-ai/claude-plugin`})]})]}),(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsxs)(Pt,{className:`flex items-center justify-between text-base`,children:[`Cursor`,g&&(0,Q.jsx)(q,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Q.jsxs)(`a`,{href:g,children:[(0,Q.jsx)(Ye,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.cursor.addButton`)]})})]})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.cursor.body`)}),(0,Q.jsx)(mg,{text:JSON.stringify({mcpServers:{objectstack:{url:r}}},null,2)})]})]}),(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsx)(Pt,{className:`text-base`,children:`VS Code / Copilot`})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.vscode.body`)}),(0,Q.jsx)(mg,{text:JSON.stringify({servers:{objectstack:{type:`http`,url:r}}},null,2)})]})]}),(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsx)(Pt,{className:`text-base`,children:`Codex CLI`})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.codex.body`)}),(0,Q.jsx)(mg,{text:`[mcp_servers.objectstack]\nurl = "${r}"`})]})]}),(0,Q.jsxs)(He,{children:[(0,Q.jsx)(kt,{className:`pb-2`,children:(0,Q.jsxs)(Pt,{className:`flex items-center gap-2 text-base`,children:[(0,Q.jsx)(pt,{className:`h-4 w-4`}),e(`connectAgent.apiKey.title`),(0,Q.jsx)(mt,{variant:`secondary`,children:e(`connectAgent.apiKey.badge`)})]})}),(0,Q.jsxs)(cr,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.apiKey.body`)}),d?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-amber-600 dark:text-amber-400`,children:e(`connectAgent.apiKey.showOnce`,{name:d.name})}),(0,Q.jsx)(mg,{text:d.key}),(0,Q.jsx)(mg,{text:`x-api-key: ${d.key}`}),(0,Q.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>f(null),children:e(`connectAgent.apiKey.done`)})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{value:s,onChange:e=>c(e.target.value),placeholder:e(`connectAgent.apiKey.namePlaceholder`),className:`h-8 max-w-56`}),(0,Q.jsx)(q,{size:`sm`,onClick:async()=>{u(!0),m(null);try{let e=await fetch(`${ug}/api/v1/keys`,{method:`POST`,credentials:`include`,headers:dg({"content-type":`application/json`}),body:JSON.stringify({name:s.trim()||`agent-key`})}),t=await e.json().catch(()=>({}));if(!e.ok||t?.success===!1)throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`);let n=t?.data??t;f({name:n?.name??s,key:n?.key??``}),c(``)}catch(e){m(e?.message??String(e))}finally{u(!1)}},disabled:l,children:e(l?`connectAgent.apiKey.minting`:`connectAgent.apiKey.mint`)})]}),p&&(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-destructive`,children:[(0,Q.jsx)(Zr,{className:`h-3.5 w-3.5`}),` `,p]})]})]})]})]}):(0,Q.jsx)(He,{children:(0,Q.jsxs)(cr,{className:`flex items-center gap-3 py-8 text-muted-foreground`,children:[(0,Q.jsx)(Zr,{className:`h-5 w-5 shrink-0`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:e(`connectAgent.disabled.title`)}),(0,Q.jsx)(`div`,{className:`text-sm`,children:a||e(`connectAgent.disabled.body`)})]})]})})}oe.register(`mcp:connect-agent`,()=>(0,Q.jsx)(hg,{}),{namespace:`app-shell`,label:`Connect an Agent`,category:`plugin`,inputs:[]});var gg=`/api/v1/cloud/environments/production/sso-open`,_g=`/apps/cloud_control/sys_environment`,vg=`create_environment`;function yg(e){let{activeOrganization:t}=E(),n=t?.id,r=(0,$.useMemo)(()=>D(),[]),[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))?.data;if(t)return;if(!s||typeof s!=`object`){a({phase:`unknown`});return}let c=s.hasProductionEnv===!0;a({phase:`ready`,hasProductionEnv:c}),c&&e&&r(`${i}${e}`,{method:`GET`,credentials:`include`}).catch(()=>{})}catch{t||a({phase:`unknown`})}})(),()=>{t=!0}},[r,n,e]),i}function bg(e){window.location.href=e}function xg({properties:e}){let{t}=I(),n=p(),r=yg(e?.warmUrl),i=e?.openProductionUrl||gg,a=e?.environmentsRoute||_g,o=e?.createAction||vg;if(r.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,"data-onboarding":`loading`,children:[(0,Q.jsx)(ri,{className:`h-11 w-44 rounded-md`}),(0,Q.jsx)(ri,{className:`h-11 w-44 rounded-md`})]});let s=r.phase===`ready`&&!r.hasProductionEnv?t(`cloudOnboarding.hintCreate`):t(`cloudOnboarding.hintReady`),c=r.phase===`ready`&&!r.hasProductionEnv;return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,"data-onboarding":r.phase,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[c?(0,Q.jsxs)(q,{size:`lg`,onClick:()=>n(om(a,o)),children:[(0,Q.jsx)(ze,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.createEnvironment`)]}):(0,Q.jsxs)(q,{size:`lg`,onClick:()=>bg(i),children:[(0,Q.jsx)(bn,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.openProduction`)]}),(0,Q.jsxs)(q,{size:`lg`,variant:`secondary`,onClick:()=>n(a),children:[(0,Q.jsx)(wr,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.manageEnvironments`)]})]}),(0,Q.jsx)(`p`,{className:`max-w-xl text-center text-sm text-muted-foreground`,children:s})]})}oe.register(`cloud:onboarding-next`,e=>(0,Q.jsx)(xg,{...e}),{namespace:`app-shell`,label:`Cloud Onboarding Next-Step`,category:`plugin`,inputs:[]});var Sg=`/api/v1/ai/effective-model`;function Cg(e,t){return e===`code-default`?t(`aiModelStatus.sourceCodeDefault`):e===`inherits-conversational`?t(`aiModelStatus.sourceInherits`):e.startsWith(`env:`)?t(`aiModelStatus.sourcePinned`,{source:e.slice(4)}):e===`unknown`?t(`aiModelStatus.sourceUnknown`):e}function wg(e){return e.startsWith(`env:`)?`default`:`secondary`}function Tg(e){let t=(0,$.useMemo)(()=>D(),[]),[n,r]=(0,$.useState)({phase:`loading`});return(0,$.useEffect)(()=>{let n=!1,i=``.replace(/\/+$/,``);return(async()=>{try{let a=await t(`${i}${e}`,{method:`GET`,credentials:`include`});if(!a.ok){n||r({phase:`error`,status:a.status});return}let o=await a.json().catch(()=>null),s=o?.data??o;if(n)return;if(!s||typeof s!=`object`||!s.conversational){r({phase:`error`});return}r({phase:`ready`,report:s})}catch{n||r({phase:`error`})}})(),()=>{n=!0}},[t,e]),n}function Eg({label:e,model:t,source:n,t:r}){return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-2 border-b border-border last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`text-sm font-medium`,children:t??`—`}),(0,Q.jsx)(mt,{variant:wg(n),children:Cg(n,r)})]})]})}function Dg({properties:e}){let{t}=I(),n=Tg(e?.effectiveModelUrl||Sg);if(n.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`space-y-2`,"data-ai-model-status":`loading`,children:[(0,Q.jsx)(ri,{className:`h-5 w-3/4 rounded`}),(0,Q.jsx)(ri,{className:`h-10 w-full rounded`}),(0,Q.jsx)(ri,{className:`h-10 w-full rounded`})]});if(n.phase===`error`)return(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,"data-ai-model-status":`error`,children:n.status?t(`aiModelStatus.readFailedWithStatus`,{status:n.status}):t(`aiModelStatus.readFailed`)});let{report:r}=n,i=Object.entries(r.overrides).filter(([,e])=>e!=null),a=t(`aiModelStatus.modelUnknown`);return(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-ai-model-status":`ready`,children:[(0,Q.jsxs)(`p`,{className:`text-sm text-foreground`,"data-testid":`ai-model-summary`,children:[t(`aiModelStatus.summary`,{conversational:r.conversational.model??a,conversationalSource:Cg(r.conversational.source,t),structured:r.structured.model??a,structuredSource:Cg(r.structured.source,t)}),r.routing?(0,Q.jsxs)(Q.Fragment,{children:[` `,t(`aiModelStatus.summaryRouting`,{free:r.routing.free,paid:r.routing.paid})]}):null]}),(0,Q.jsxs)(`div`,{className:`rounded-md border border-border px-3`,children:[(0,Q.jsx)(Eg,{label:t(`aiModelStatus.rowConversational`),t,model:r.conversational.model,source:r.conversational.source}),(0,Q.jsx)(Eg,{label:t(`aiModelStatus.rowStructured`),t,model:r.structured.model,source:r.structured.source}),(0,Q.jsx)(Eg,{label:t(`aiModelStatus.rowReasoning`),t,model:r.reasoningEffort.effective,source:r.reasoningEffort.source})]}),(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:t(`aiModelStatus.overridesInEffect`)}),i.length===0?(0,Q.jsx)(`span`,{children:t(`aiModelStatus.noOverrides`)}):(0,Q.jsx)(`code`,{children:i.map(([e,t])=>`${e}=${t}`).join(` · `)})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`aiModelStatus.adapter`),(0,Q.jsxs)(`code`,{children:[r.adapter,r.provider?` / ${r.provider}`:``]})]})]})}oe.register(`cloud:ai-model-status`,e=>(0,Q.jsx)(Dg,{...e}),{namespace:`app-shell`,label:`Cloud AI Model Status`,category:`plugin`,inputs:[]});var Og=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}};oe.register(`attachments`,({schema:e,className:t,...n})=>{let r=we(),{user:i}=E(),{designer:a}=Og(n),o=r?.objectName,s=r?.recordId==null?``:String(r.recordId);return!o||!s?null:(0,Q.jsx)(`div`,{className:t,...a,children:(0,Q.jsx)(aa,{objectName:o,recordId:s,dataSource:r?.dataSource,currentUserId:i?.id})})},{namespace:`record`,skipFallback:!0,category:`record`,label:`Attachments`,icon:`Paperclip`,inputs:[{name:`className`,type:`string`,label:`CSS Class`}]});function kg({packageId:e,onCanvasOpenChange:t}){let{user:n}=E(),r=n?.id,i=$.useMemo(()=>md(),[]),{agents:a,isLoading:o,error:s}=Ia({apiBase:i}),c=$.useMemo(()=>mf(`studio-build`,{agents:a}),[a]),l=c?`${i}/agents/${encodeURIComponent(c)}/chat`:void 0,{conversationId:u,initialMessages:d}=xu({userId:c?r:void 0,scope:c?Tu({appId:e,product:wu(c)}):void 0,apiBase:i,activeId:void 0,forceNew:!1}),f=$.useRef(null);return!o&&a.length===0?null:(0,Q.jsx)(Ad,{agents:a,agentsLoading:o,agentsError:s,activeAgent:c,chatApi:l,apiBase:i,conversationId:u,editPackageId:e,initialMessages:d,pendingFirstMessageRef:f,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:t},`${l??`local`}:${u??`pending`}`)}function Ag({packageId:e,locale:t}){let n=p(),r=s(),i=$.useMemo(()=>md(),[]),a=gf({defaultExpanded:!0,persistExpandedKey:Hl,persistWidthKey:Ul}),o=hi(),[c,l]=$.useState(!1),{agents:u,isLoading:d}=Ia({apiBase:i}),f=$.useCallback(e=>e?a.maximize():a.restore(),[a.maximize,a.restore]),m=$.useCallback(()=>{Zl(`${r.pathname}${r.search}`),n(`/ai/build?package=${encodeURIComponent(e)}`)},[r.pathname,r.search,n,e]);return!d&&u.length===0?null:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(bf,{onExpand:()=>l(!0),className:`inline-flex md:hidden`}),(0,Q.jsx)(yf,{open:c,onOpenChange:l,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,Q.jsx)(kg,{packageId:e})})]}):a.expanded?(0,Q.jsx)(vf,{dock:a,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,Q.jsx)(kg,{packageId:e,onCanvasOpenChange:f})}):(0,Q.jsx)(bf,{onExpand:a.expand})}function jg(e,t,n){return!t&&n?`properties`:t&&!n?`canvas`:e}var Mg=1280;function Ng(){let[e,t]=$.useState(void 0);return $.useEffect(()=>{let e=window.matchMedia(`(min-width: ${Mg}px)`),n=()=>t(window.innerWidth>=Mg);return e.addEventListener(`change`,n),t(window.innerWidth>=Mg),()=>e.removeEventListener(`change`,n)},[]),!!e}var Pg=new Map;function Fg(e,t){Pg.set(e,t)}function Ig(e){return Pg.get(e)}function Lg({name:e}){return(0,Q.jsx)(z,{schema:{type:`object-view`,objectName:e}})}Fg(`object`,Lg);var Rg=[`read`,`create`,`update`,`delete`,`transfer`,`restore`,`purge`],zg={grants:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,denies:`border-destructive/40 bg-destructive/10 text-destructive`,narrows:`border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-300`,widens:`border-sky-400/50 bg-sky-400/10 text-sky-700 dark:text-sky-300`,neutral:`border-border bg-muted/40 text-muted-foreground`,not_applicable:`border-border bg-transparent text-muted-foreground/60`},Bg={admitted:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,excluded:`border-destructive/40 bg-destructive/10 text-destructive`,not_evaluated:`border-border bg-transparent text-muted-foreground/60`},Vg={admits:`bg-emerald-500`,excludes:`bg-destructive`,neutral:`bg-muted-foreground/40`},Hg=e=>{let t=e??{};return String(t.full_name||t.name||t.display_name||t.email||t.id||``)};function Ug({open:e,onOpenChange:t,defaultObject:n,packageId:r}){let i=as(),a=Ee(),o=ss(),s=$.useMemo(()=>D(),[]),[c,l]=$.useState(null);$.useEffect(()=>{if(!e||!r){l(null);return}let t=!1;return(async()=>{try{let e=(await o.list(`object`,{packageId:r})??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));t||l(e)}catch{t||l(null)}})(),()=>{t=!0}},[e,r,o]);let[u,d]=$.useState(n??``),[f,p]=$.useState(`read`),[m,h]=$.useState(null),[g,_]=$.useState(``),[v,y]=$.useState(!1),[b,x]=$.useState(!1),[S,C]=$.useState(!1),[w,T]=$.useState(null),[E,O]=$.useState(null);$.useEffect(()=>{n&&d(e=>e||n)},[n]);let k=$.useCallback(async()=>{let e=u.trim();if(e){C(!0),T(null),O(null);try{let t=``.replace(/\/+$/,``),n=await s(`${t}/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:f,...m?{userId:m.id}:{},...g.trim()?{recordId:g.trim()}:{}})}),r=null;try{r=await n.json()}catch{}if(n.status===403){T(Z(`engine.studio.access.explain.forbidden`,i));return}if(!n.ok){let e=r?.message||r?.error||`HTTP ${n.status} ${n.statusText}`.trim();T(e);return}O(r)}catch(e){T(e?.message??String(e))}finally{C(!1)}}},[s,u,f,m,g,i]),A=e=>Z(`engine.studio.access.explain.op.${e}`,i);return(0,Q.jsx)(Mn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ui,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(si,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Kr,{className:`h-4 w-4`}),` `,Z(`engine.studio.access.explain.title`,i)]}),(0,Q.jsx)(Gt,{children:Z(`engine.studio.access.explain.description`,i)})]}),(0,Q.jsxs)(`div`,{className:`mt-4 space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.user`,i)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border bg-background px-2 text-left text-xs hover:bg-muted/60`,children:[(0,Q.jsx)(gr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:m?m.label:Z(`engine.studio.access.explain.self`,i)}),(0,Q.jsx)(zn,{className:`h-3 w-3 shrink-0 text-muted-foreground/70`})]}),m&&(0,Q.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(null),"aria-label":Z(`engine.studio.access.explain.clearUser`,i),title:Z(`engine.studio.access.explain.clearUser`,i),children:(0,Q.jsx)(Tn,{className:`h-4 w-4`})})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-object`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.object`,i)}),c&&c.length>0?(0,Q.jsxs)(`select`,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.access.explain.objectSelect`,i)}),c.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]}):(0,Q.jsx)(J,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),placeholder:Z(`engine.studio.access.explain.objectPlaceholder`,i),className:`h-8 text-xs`})]}),(0,Q.jsxs)(`div`,{className:`w-32 shrink-0 space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-operation`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.operation`,i)}),(0,Q.jsx)(`select`,{id:`explain-operation`,value:f,onChange:e=>p(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:Rg.map(e=>(0,Q.jsx)(`option`,{value:e,children:A(e)},e))})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-record`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.record`,i)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{id:`explain-record`,value:g,onChange:e=>_(e.target.value),placeholder:Z(`engine.studio.access.explain.recordPlaceholder`,i),className:`h-8 min-w-0 flex-1 text-xs`}),(0,Q.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 gap-1 text-xs`,disabled:!u.trim(),onClick:()=>x(!0),title:Z(`engine.studio.access.explain.pickRecord`,i),children:[(0,Q.jsx)(zn,{className:`h-3 w-3`}),Z(`engine.studio.access.explain.pickRecord`,i)]}),g&&(0,Q.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>_(``),"aria-label":Z(`engine.studio.access.explain.clearRecord`,i),title:Z(`engine.studio.access.explain.clearRecord`,i),children:(0,Q.jsx)(Tn,{className:`h-4 w-4`})})]})]}),(0,Q.jsxs)(q,{size:`sm`,className:`h-8 gap-1.5 text-xs`,disabled:S||!u.trim(),onClick:()=>void k(),children:[S?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(xr,{className:`h-3.5 w-3.5`}),Z(S?`engine.studio.access.explain.running`:`engine.studio.access.explain.run`,i)]})]}),(0,Q.jsxs)(`div`,{className:`mt-5 space-y-4 text-sm`,children:[w&&!S&&(0,Q.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive`,children:[(0,Q.jsx)(Wt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Z(`engine.studio.access.explain.failed`,i)}),` — `,w]})]}),!E&&!w&&!S&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Z(`engine.studio.access.explain.empty`,i)}),E&&!S&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{"data-testid":`explain-verdict`,className:E.allowed?`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:[E.allowed?(0,Q.jsx)(Wr,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(zt,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:os(E.allowed?`engine.studio.access.explain.allowedLine`:`engine.studio.access.explain.deniedLine`,i,{operation:A(E.operation),object:E.object})})]}),E.record&&(0,Q.jsxs)(`div`,{"data-testid":`explain-record-verdict`,className:E.record.visible?`flex items-start gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 p-3 text-destructive`,children:[E.record.visible?(0,Q.jsx)(Wr,{className:`mt-0.5 h-4 w-4 shrink-0`}):(0,Q.jsx)(zt,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium`,children:os(E.record.visible?`engine.studio.access.explain.recordVisibleLine`:`engine.studio.access.explain.recordHiddenLine`,i,{recordId:E.record.recordId})}),E.record.decidedBy&&(0,Q.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.decidedBy`,i),`:`,` `,(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.layer.${E.record.decidedBy}`,i)})]})]})]}),(0,Q.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.principal`,i)}),E.principal.posture&&(0,Q.jsx)(mt,{variant:`outline`,"data-testid":`explain-posture`,className:`px-1.5 py-0 text-[10px] font-medium`,title:Z(`engine.studio.access.explain.postureHint`,i),children:Z(`engine.studio.access.explain.posture.${E.principal.posture}`,i)})]}),(0,Q.jsxs)(`p`,{className:`mt-1 truncate font-mono text-xs text-foreground`,children:[E.principal.userId??`(anonymous)`,E.principal.onBehalfOf?.userId?` ⇄ ${E.principal.onBehalfOf.userId}`:``]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.positions`,i),`:`]}),(E.principal.positions??[]).map(e=>(0,Q.jsx)(mt,{variant:`outline`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.permissionSets`,i),`:`]}),(E.principal.permissionSets??[]).map(e=>(0,Q.jsx)(mt,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.layers`,i)}),(0,Q.jsx)(`ol`,{className:`space-y-2`,children:E.layers.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-md border p-2.5`,"data-testid":`explain-layer-${e.layer}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium`,children:Z(`engine.studio.access.explain.layer.${e.layer}`,i)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${zg[e.verdict]??zg.neutral}`,children:Z(`engine.studio.access.explain.verdict.${e.verdict}`,i)}),e.kernelTier&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-border bg-muted/40 px-1.5 py-0.5 text-[9px] uppercase leading-none text-muted-foreground`,title:Z(`engine.studio.access.explain.kernelTierHint`,i),children:Z(`engine.studio.access.explain.kernelTier.${e.kernelTier}`,i)})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:e.detail}),(e.contributors??[]).length>0&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:[Z(`engine.studio.access.explain.contributors`,i),`:`]}),(e.contributors??[]).map((e,t)=>(0,Q.jsx)(mt,{variant:e.kind===`position`?`outline`:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,title:e.via?`${e.kind} · via ${e.via}`:e.kind,children:e.name},`${e.kind}:${e.name}:${t}`))]}),e.record&&(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded border border-dashed border-border/70 bg-muted/20 p-2`,"data-testid":`explain-record-${e.layer}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-muted-foreground/70`,children:Z(`engine.studio.access.explain.recordOutcome`,i)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${Bg[e.record.outcome]??Bg.not_evaluated}`,children:Z(`engine.studio.access.explain.outcome.${e.record.outcome}`,i)}),e.record.matchesRecord!=null&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:Z(e.record.matchesRecord?`engine.studio.access.explain.matches`:`engine.studio.access.explain.noMatch`,i)})]}),e.record.detail&&(0,Q.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:e.record.detail}),(e.record.rules??[]).length>0&&(0,Q.jsx)(`ul`,{className:`space-y-1`,children:(e.record.rules??[]).map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Vg[e.effect]??Vg.neutral}`,title:e.effect}),(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.ruleKind.${e.kind}`,i)}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,title:e.name,children:e.name}),e.grants&&(0,Q.jsx)(mt,{variant:`secondary`,className:`px-1 py-0 text-[9px] font-normal`,children:e.grants}),e.via&&(0,Q.jsxs)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground/70`,children:[`· `,e.via]})]},`${e.kind}:${e.name}:${t}`))}),e.record.rowFilter!==void 0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground/70`,children:Z(`engine.studio.access.explain.effectiveRowFilter`,i)}),(0,Q.jsx)(`pre`,{className:`mt-0.5 overflow-x-auto rounded border bg-background/60 p-1.5 font-mono text-[10px] leading-snug`,children:JSON.stringify(e.record.rowFilter,null,2)})]})]})]},e.layer))})]}),E.operation===`read`&&E.readFilter!==void 0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.readFilter`,i)}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-2 font-mono text-[11px] leading-snug`,children:JSON.stringify(E.readFilter,null,2)})]})]})]}),(0,Q.jsx)(rn,{open:v,onOpenChange:e=>y(e),dataSource:a,objectName:`sys_user`,title:Z(`engine.studio.access.explain.pickUserTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&h({id:String(t.id),label:Hg(t)}),y(!1)}}),u.trim()&&(0,Q.jsx)(rn,{open:b,onOpenChange:e=>x(e),dataSource:a,objectName:u.trim(),title:Z(`engine.studio.access.explain.pickRecordTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&_(String(t.id)),x(!1)}})]})})}async function Wg(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 Gg(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;case`action`:return e.actionDef?.actionName?{type:`action`,name:String(e.actionDef.actionName),label:t}:null;default:return null}}function Kg(e,t){for(let n of e)if(n.type===`group`||n.children?.length){let e=Kg(n.children??[],t);if(e)return e}else{let e=Gg(n);if(e&&e.type===t.type&&e.name===t.name)return e}return null}function qg(e){let[t,n]=c(),r=$.useRef(eo(t.get(to))),i=e?.type,a=e?.name;return $.useEffect(()=>{!i||!a||n(e=>{let t=new URLSearchParams(e);return t.set(to,no({type:i,name:a})),t},{replace:!0})},[i,a]),r.current}function Jg(e,t,n){if(!(!t||t.type!==n))return e.find(e=>e.name===t.name)}function Yg(e,t,n){return{name:e,label:t,fields:{name:{type:`text`,label:n}}}}function Xg(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 Zg(e,t,n=[]){return{name:e,label:t,active:!0,navigation:n.map(e=>({id:`nav_${e.name}`,type:`object`,label:e.label,objectName:e.name}))}}function Qg(e,t){return{name:e,label:t,objects:{},fields:{}}}function $g({open:e,onOpenChange:t,title:n,description:r,labelFieldLabel:i,labelPlaceholder:a,idFieldLabel:o,idPlaceholder:s,submitLabel:c,submittingLabel:l,busy:u=!1,error:d,locale:f,extra:p,onSubmit:m}){let[h,g]=$.useState(``),[_,v]=$.useState(``),[y,b]=$.useState(!1);$.useEffect(()=>{e&&(g(``),v(``),b(!1))},[e]);let x=Es((_.trim()||h).trim()),S=!!h.trim()&&!!x&&x!==`field`,C=()=>{!S||u||m({label:h.trim(),name:x})};return(0,Q.jsx)(Pn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(di,{children:[(0,Q.jsxs)(ci,{children:[(0,Q.jsx)(Yt,{children:n}),r&&(0,Q.jsx)(Kt,{children:r})]}),(0,Q.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(K,{children:i}),(0,Q.jsx)(J,{autoFocus:!0,value:h,onChange:e=>{g(e.target.value),y||v(Cs(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:a})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(K,{children:o}),(0,Q.jsx)(J,{className:`font-mono`,value:_,onChange:e=>{b(!0),v(Cs(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:s})]}),p,d&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,Q.jsxs)(Ke,{children:[(0,Q.jsx)(q,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:Z(`engine.studio.cancel`,f)}),(0,Q.jsx)(q,{onClick:C,disabled:!S||u,children:u?l??c:c})]})]})})}var e_=`__ungrouped__`,t_=e=>`g:${e}`,n_=e=>`f:${e}`,r_=e=>e.slice(2),i_=e=>e.slice(2);function a_({type:e}){let t=as(),n=`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:`${n} h-7 justify-between`,children:[(0,Q.jsx)(`span`,{children:Z(e===`lookup`||e===`reference`||e===`user`?`engine.studio.designer.search`:`engine.studio.designer.select`,t)}),(0,Q.jsx)(`span`,{children:`▾`})]});case`textarea`:case`html`:case`markdown`:case`json`:case`code`:return(0,Q.jsx)(`div`,{className:`${n} 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:`${n} h-7`,children:`0.00`});case`date`:case`datetime`:case`time`:return(0,Q.jsx)(`div`,{className:`${n} h-7`,children:Z(`engine.studio.designer.pickDate`,t)});default:return(0,Q.jsx)(`div`,{className:`${n} h-7`,children:`\xA0`})}}function o_({entry:e,label:t,columns:n,selected:r,onSelect:i}){let a=as(),{attributes:o,listeners:s,setNodeRef:c,transform:l,transition:u,isDragging:d}=qo({id:n_(e.name)}),f=String(e.def.type??`text`),p=!!e.def.required,m=n>1&&Oi(f);return(0,Q.jsxs)(`div`,{ref:c,style:{transform:Qo.Transform.toString(l),transition:u},onClick:i,...o,...s,"aria-label":os(`engine.studio.designer.fieldAria`,a,{label:t}),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 `+(m?`col-span-full `:``)+(r?`ring-2 ring-primary`:`hover:border-foreground/25`)+(d?` opacity-40`:``),children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,Q.jsx)(gn,{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:t}),p&&(0,Q.jsx)(`span`,{className:`text-destructive`,children:`*`}),(0,Q.jsx)(`span`,{className:`ml-1 text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:f})]}),(0,Q.jsx)(a_,{type:f})]})]})}function s_({containerId:e,title:t,fieldIds:n,columns:r,isDeclared:i,canMoveUp:a,canMoveDown:o,entryByName:s,fieldLabelOf:c,selectedField:l,onSelectField:u,selected:d=!1,onSelect:f,onRename:p,onDelete:m,onMove:h,readOnly:g=!1}){let _=as(),{setNodeRef:v,isOver:y}=Uo({id:e});return(0,Q.jsxs)(`div`,{className:`@container rounded-lg border `+(y?`border-primary bg-primary/5`:d?`border-primary/50 bg-primary/5 ring-2 ring-primary`:`bg-muted/20`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[i&&!g?(0,Q.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&p(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}),i&&f&&(0,Q.jsx)(`button`,{type:`button`,onClick:f,"aria-label":Z(`engine.studio.designer.group.settings`,_),title:Z(`engine.studio.designer.group.settings`,_),className:`rounded p-0.5 hover:bg-muted `+(d?`text-primary`:`text-muted-foreground hover:text-foreground`),children:(0,Q.jsx)(wr,{className:`h-3.5 w-3.5`})}),i&&!g&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>h(-1),"aria-label":Z(`engine.studio.designer.groupUp`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(Qn,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>h(1),"aria-label":Z(`engine.studio.designer.groupDown`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(ti,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:m,"aria-label":Z(`engine.studio.designer.groupDelete`,_),title:Z(`engine.studio.designer.groupDeleteTitle`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Q.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]}),(0,Q.jsx)(Yo,{items:n,strategy:Jo,children:(0,Q.jsxs)(`div`,{ref:v,className:`min-h-[52px] p-2.5 `+(Ti(r)??`grid grid-cols-1 gap-4`),children:[n.length===0&&(0,Q.jsx)(`div`,{className:`col-span-full flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:Z(`engine.studio.designer.dropHere`,_)}),n.map(e=>{let t=i_(e),n=s.get(t);return n?(0,Q.jsx)(o_,{entry:n,label:c(n),columns:r,selected:l===t,onSelect:()=>u(t)},e):null})]})})]})}function c_({draft:e,objectName:t,systemFieldNames:n,onChange:r,selectedField:i,onSelectField:a,onAddField:o,selectedGroup:s,onSelectGroup:c,readOnly:l=!1}){let u=as(),d=$.useMemo(()=>Ss(e.fields),[e.fields]),f=$.useMemo(()=>ks(e.fieldGroups),[e.fieldGroups]),p=$.useMemo(()=>new Map(d.entries.map(e=>[e.name,e])),[d]),{fieldLabel:m,sectionLabel:h}=he(),g=t||(typeof e.name==`string`?e.name:``),_=$.useCallback(e=>{let t=String(e.def.label??e.name);return g?m(g,e.name,t):t},[g,m]),v=$.useMemo(()=>Di(d.entries.filter(e=>!n.has(e.name)).length),[d.entries,n]),y=$.useMemo(()=>[...f.map(e=>t_(e.key)),t_(e_)],[f]),b=$.useMemo(()=>{let e=new Map;for(let t of f){let n=t.label||t.key;e.set(t_(t.key),g?h(g,t.key,n):n)}return e.set(t_(e_),Z(`engine.studio.designer.ungrouped`,u)),e},[f,u,g,h]),x=$.useMemo(()=>{let e={};for(let t of y)e[t]=[];for(let t of d.entries){if(n.has(t.name))continue;let r=typeof t.def.group==`string`?t.def.group:``;e[r&&e[t_(r)]?t_(r):t_(e_)].push(n_(t.name))}return e},[d.entries,y,n]),[S,C]=$.useState(x),[w,T]=$.useState(null);$.useEffect(()=>{w||C(x)},[x,w]);let E=$.useRef(S);$.useEffect(()=>{E.current=S},[S]);let D=Zo(zo(Ho,{activationConstraint:{distance:4}}),zo(Xo,{coordinateGetter:Bo})),O=$.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(S).find(t=>S[t].includes(e)),[S]),k=$.useCallback(e=>{let t=[];for(let n of y){let r=r_(n);for(let i of e[n]??[]){let e=p.get(i_(i));if(!e)continue;let n={...e.def};r===e_?delete n.group:n.group=r,t.push({name:e.name,def:n})}}let i=d.entries.filter(e=>n.has(e.name)),a={shape:d.shape,entries:[...i,...t]};r({fields:ys(a)})},[y,p,d,n,r]),A=e=>T(String(e.active.id)),j=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=O(t),i=O(n);!r||!i||r===i||C(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)]}})},M=e=>{T(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=E.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){k(r);return}s={...r,[a]:Ko(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)]}}C(s),k(s)},N=()=>r({fieldGroups:ws(f,Z(`engine.studio.designer.newGroup`,u))}),ee=(e,t)=>r({fieldGroups:vs(f,e,t)}),P=(e,t)=>r({fieldGroups:Os(f,e,t)}),F=e=>r({fieldGroups:_s(f,e),fields:ys(Ds(d,e))}),te=w&&!w.startsWith(`g:`)?p.get(i_(w)):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)(Gn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.hint`,u)]}),!l&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:N,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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.addGroup`,u)]}),o&&(0,Q.jsxs)(`button`,{type:`button`,onClick:o,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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,u)]})]})]}),(0,Q.jsxs)(Vo,{sensors:l?[]:D,collisionDetection:Wo,onDragStart:A,onDragOver:j,onDragEnd:M,onDragCancel:()=>T(null),children:[(0,Q.jsx)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-3`,children:y.map(e=>{let t=e===t_(e_);if(t&&(S[e]?.length??0)===0&&f.length>0)return null;let n=f.findIndex(t=>t_(t.key)===e);return(0,Q.jsx)(s_,{containerId:e,title:b.get(e)??Z(`engine.studio.designer.ungrouped`,u),fieldIds:S[e]??[],columns:v,isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<f.length-1,entryByName:p,fieldLabelOf:_,selectedField:i,onSelectField:a,selected:!t&&s===r_(e),onSelect:!t&&c?()=>c(r_(e)):void 0,onRename:t=>ee(r_(e),t),onDelete:()=>F(r_(e)),onMove:t=>P(r_(e),t),readOnly:l},e)})}),(0,Q.jsx)(Go,{children:te?(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)(gn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:_(te)})]}):null})]})]})}function l_({draft:e,groupKey:t,onPatch:n,onClose:r,readOnly:i=!1,locale:a}){let o=$.useCallback(e=>Z(e,a),[a]),s=$.useMemo(()=>ks(e.fieldGroups),[e.fieldGroups]),c=s.find(e=>e.key===t);if(!c)return(0,Q.jsx)(ps,{kindLabel:o(`engine.studio.designer.group.kind`),title:t,onClose:r,closeLabel:o(`engine.studio.close`),children:(0,Q.jsx)(ls,{message:o(`engine.studio.designer.group.missing`)})});let l=c.collapse??(c.collapsed?`collapsed`:c.collapsible?`expanded`:`none`),u=e=>n({fieldGroups:bs(s,c.key,{collapse:e===`none`?void 0:e,collapsible:void 0,collapsed:void 0,defaultExpanded:void 0})});return(0,Q.jsxs)(ps,{kindLabel:o(`engine.studio.designer.group.kind`),title:c.label||c.key,onClose:r,closeLabel:o(`engine.studio.close`),children:[(0,Q.jsx)(hs,{label:o(`engine.studio.designer.group.nameLabel`),value:c.label,onCommit:e=>n({fieldGroups:bs(s,c.key,{label:e})}),disabled:i,testId:`group-label`}),(0,Q.jsx)(ms,{label:o(`engine.studio.designer.group.collapseLabel`),value:l,onCommit:e=>u(e||`none`),disabled:i,options:[{value:`none`,label:o(`engine.studio.designer.group.collapseNone`)},{value:`expanded`,label:o(`engine.studio.designer.group.collapseExpanded`)},{value:`collapsed`,label:o(`engine.studio.designer.group.collapseCollapsed`)}]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:o(`engine.studio.designer.group.collapseHint`)})]})}var u_=[{value:`script`,labelKey:`engine.studio.rules.typeScript`},{value:`cross_field`,labelKey:`engine.studio.rules.typeCrossField`},{value:`state_machine`,labelKey:`engine.studio.rules.typeStateMachine`},{value:`format`,labelKey:`engine.studio.rules.typeFormat`},{value:`json_schema`,labelKey:`engine.studio.rules.typeJsonSchema`},{value:`conditional`,labelKey:`engine.studio.rules.typeConditional`}],d_=[`insert`,`update`,`delete`],f_=[``,`url`,`email`,`phone`,`json`];function p_(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function m_(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function h_(e,t,n){let r={name:t,message:``,severity:`error`,active:!0};switch(e){case`script`:return{...r,type:e,condition:`false`};case`cross_field`:return{...r,type:e,condition:`false`,fields:n?[n]:[]};case`state_machine`:return{...r,type:e,field:n??``,transitions:{}};case`format`:return{...r,type:e,field:n??``};case`json_schema`:return{...r,type:e,field:n??``,schema:{}};case`conditional`:return{...r,type:e,condition:`false`,then:{type:`script`,name:`${t}_then`,message:``,condition:`false`,severity:`error`}}}}function g_({label:e,value:t,onCommit:n,disabled:r,locale:i}){let a=$.useMemo(()=>{if(t==null)return``;try{return JSON.stringify(t,null,2)}catch{return``}},[t]),[o,s]=$.useState(a),[c,l]=$.useState(null);return $.useEffect(()=>{s(a),l(null)},[a]),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,Q.jsx)(`textarea`,{value:o,disabled:r,spellCheck:!1,rows:5,onChange:e=>s(e.target.value),onBlur:()=>{let e=o.trim();if(!e){l(null),n(void 0);return}try{n(JSON.parse(e)),l(null)}catch{l(Z(`engine.studio.rules.invalidJson`,i))}},className:`w-full rounded border bg-background px-2 py-1 font-mono text-[11px]`}),c&&(0,Q.jsx)(`span`,{className:`mt-1 block text-[11px] text-destructive`,children:c})]})}function __({transitions:e,onCommit:t,disabled:n,locale:r}){let i=Object.entries(e),a=(e,n,r)=>{let a={};i.forEach(([t,i],o)=>{o===e?n&&(a[n]=r):a[t]=i}),t(a)};return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.transitions`,r)}),i.map(([e,t],i)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`input`,{value:e,disabled:n,placeholder:Z(`engine.studio.rules.transitionFrom`,r),onChange:e=>a(i,e.target.value,t),className:`w-32 rounded border bg-background px-2 py-1 text-[12px]`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,Q.jsx)(`input`,{value:t.join(`, `),disabled:n,placeholder:Z(`engine.studio.rules.transitionTo`,r),onChange:t=>a(i,e,t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),className:`min-w-0 flex-1 rounded border bg-background px-2 py-1 text-[12px]`}),!n&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":Z(`engine.studio.rules.delete`,r),onClick:()=>a(i,``,[]),className:`rounded border border-destructive/40 p-1 text-destructive hover:bg-destructive/10`,children:(0,Q.jsx)(qt,{className:`h-3 w-3`})})]},i)),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>t({...e,"":[]}),disabled:``in e,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.addTransition`,r)]})]})}function v_({rule:e,fields:t,patch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=(e,n,a)=>(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,Q.jsxs)(`select`,{value:n??``,disabled:r,onChange:e=>a(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.rules.pickField`,i)}),t.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]})]}),s=(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[Z(`engine.studio.rules.celPre`,i),(0,Q.jsx)(`b`,{children:Z(`engine.studio.rules.celTrue`,i)}),Z(`engine.studio.rules.celMid`,i),(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),Z(`engine.studio.rules.celPost`,i)]}),(0,Q.jsx)(us,{value:As(e.condition),onCommit:t=>n({condition:ds(e.condition,t)}),fields:t,disabled:r,onBlockingIssuesChange:a})]});switch(e.type){case`script`:return s;case`cross_field`:{let a=Array.isArray(e.fields)?e.fields:[],o=(e,t)=>n({fields:t?[...new Set([...a,e])]:a.filter(t=>t!==e)});return(0,Q.jsxs)(Q.Fragment,{children:[s,(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.fields`,i)}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2 rounded border p-2`,children:[t.length===0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.noFields`,i)}),t.map(e=>(0,Q.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:a.includes(e.name),disabled:r,onChange:t=>o(e.name,t.target.checked)}),e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name]},e.name))]})]})]})}case`state_machine`:return(0,Q.jsxs)(Q.Fragment,{children:[o(Z(`engine.studio.rules.statusField`,i),e.field,e=>n({field:e})),(0,Q.jsx)(__,{transitions:e.transitions&&typeof e.transitions==`object`?e.transitions:{},onCommit:e=>n({transitions:e}),disabled:r,locale:i})]});case`format`:return(0,Q.jsxs)(Q.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.format`,i)}),(0,Q.jsx)(`select`,{value:typeof e.format==`string`?e.format:``,disabled:r,onChange:e=>n({format:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:f_.map(e=>(0,Q.jsx)(`option`,{value:e,children:e||Z(`engine.studio.rules.formatNone`,i)},e||`none`))})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.regex`,i)}),(0,Q.jsx)(`input`,{value:typeof e.regex==`string`?e.regex:``,disabled:r,placeholder:`^[A-Z]{2}\\\\d{4}$`,onChange:e=>n({regex:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 font-mono text-[12px]`})]})]});case`json_schema`:return(0,Q.jsxs)(Q.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,Q.jsx)(g_,{label:Z(`engine.studio.rules.jsonSchema`,i),value:e.schema,onCommit:e=>n({schema:e??{}}),disabled:r,locale:i})]});case`conditional`:return(0,Q.jsxs)(Q.Fragment,{children:[s,(0,Q.jsx)(g_,{label:Z(`engine.studio.rules.then`,i),value:e.then,onCommit:e=>n({then:e}),disabled:r,locale:i}),(0,Q.jsx)(g_,{label:Z(`engine.studio.rules.otherwise`,i),value:e.otherwise,onCommit:e=>n({otherwise:e}),disabled:r,locale:i})]});default:return null}}function y_({draft:e,onPatch:t,disabled:n,onBlockingIssuesChange:r}){let i=as(),a=$.useMemo(()=>p_(e.validations),[e.validations]),[o,s]=$.useState(null),[c,l]=$.useState(!1),u=a.some(e=>e.name===o)?o:a[0]?.name??null,d=$.useMemo(()=>Ss(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]),f=d.find(e=>!e.hidden)?.name??d[0]?.name,[p,m]=$.useState({}),h=$.useCallback((e,t)=>{m(n=>n[e]===t?n:{...n,[e]:t})},[]),g=$.useMemo(()=>new Set(a.map(e=>e.name??``)),[a]),_=$.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(p))g.has(t)&&(e+=n);return e},[p,g]),v=$.useRef(r);$.useEffect(()=>{v.current=r}),$.useEffect(()=>{v.current?.(_)},[_]);let y=e=>t({validations:e}),b=(e,t)=>y(a.map(n=>n.name===e?{...n,...t}:n)),x=e=>{let t=m_(a.map(e=>e.name??``));y([...a,h_(e,t,f)]),s(t)},S=e=>{y(a.filter(t=>t.name!==e)),o===e&&s(null)},C=a.find(e=>e.name===u)??null,w=typeof C?.type==`string`?C.type:`script`,T=(e,t)=>{let n=a.find(t=>t.name===e);if(!n)return;let r=h_(t,e,f);(t===`script`||t===`cross_field`||t===`conditional`)&&As(n.condition)&&(r.condition=n.condition);for(let e of[`label`,`description`,`message`,`severity`,`active`,`events`,`priority`])n[e]!==void 0&&(r[e]=n[e]);y(a.map(t=>t.name===e?r:t))};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)(zr,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.rules.title`,i)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,a.length,`)`]}),!n&&(0,Q.jsxs)(et,{open:c,onOpenChange:l,children:[(0,Q.jsx)(Tt,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,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)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i),(0,Q.jsx)(ti,{className:`h-3 w-3 text-muted-foreground`})]})}),(0,Q.jsxs)(ft,{align:`end`,sideOffset:4,className:`w-56 p-1`,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.rules.newType`,i)}),u_.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{x(e.value),l(!1)},className:`flex w-full items-center rounded-md px-2 py-1.5 text-left text-[12px] hover:bg-muted`,children:Z(e.labelKey,i)},e.value))]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:a.length===0?(0,Q.jsxs)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:[Z(`engine.studio.rules.none`,i),(0,Q.jsx)(`br`,{}),Z(`engine.studio.rules.explain`,i)]}):a.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name??null),className:`flex w-full items-start gap-2 border-b px-3 py-2 text-left text-[12px] `+(u===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||Z(`engine.studio.rules.noMessage`,i)})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e.type??`script`})]},e.name))})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:C?(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:Z(`engine.studio.rules.type`,i)}),(0,Q.jsx)(`select`,{value:w,disabled:n,onChange:e=>T(C.name,e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:u_.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.labelKey,i)},e.value))})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.nameLabel`,i)}),(0,Q.jsx)(`input`,{value:C.name??``,disabled:n,onChange:e=>{let t=e.target.value;b(C.name,{name:t}),s(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:Z(`engine.studio.rules.label`,i)}),(0,Q.jsx)(`input`,{value:C.label??``,disabled:n,onChange:e=>b(C.name,{label:e.target.value||void 0}),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:Z(`engine.studio.rules.messageLabel`,i)}),(0,Q.jsx)(`input`,{value:C.message??``,disabled:n,onChange:e=>b(C.name,{message:e.target.value}),placeholder:Z(`engine.studio.rules.messagePlaceholder`,i),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsx)(v_,{rule:C,fields:d,patch:e=>b(C.name,e),disabled:n,locale:i,onBlockingIssuesChange:e=>h(C.name,e)}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.events`,i)}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:d_.map(e=>{let t=Array.isArray(C.events)?C.events.includes(e):!1;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:t,disabled:n,onChange:t=>{let n=Array.isArray(C.events)?C.events:[],r=t.target.checked?[...new Set([...n,e])]:n.filter(t=>t!==e);b(C.name,{events:r})}}),Z(`engine.studio.rules.event.${e}`,i)]},e)})})]}),(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:Z(`engine.studio.rules.severity`,i)}),(0,Q.jsxs)(`select`,{value:C.severity??`error`,disabled:n,onChange:e=>b(C.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:Z(`engine.studio.rules.severityError`,i)}),(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)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.priority`,i)}),(0,Q.jsx)(`input`,{type:`number`,value:typeof C.priority==`number`?C.priority:``,disabled:n,onChange:e=>b(C.name,{priority:e.target.value===``?void 0:Number(e.target.value)}),className:`w-20 rounded border bg-background px-1.5 py-0.5 text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:C.active!==!1,disabled:n,onChange:e=>b(C.name,{active:e.target.checked})}),Z(`engine.studio.rules.enabled`,i)]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`rule-delete`,onClick:()=>S(C.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)(qt,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.delete`,i)]})]})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.rules.pick`,i)})})]})}function b_({name:e,draft:t,onPatch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=vo(`object`),s=$.useMemo(()=>Ss(t.fields).entries,[t.fields]),c=s.filter(e=>(e.def.type??`text`)===`select`),l=typeof t.nameField==`string`?t.nameField:``,u=t.stageField,d=Array.isArray(t.highlightFields)?t.highlightFields.filter(e=>typeof e==`string`):[],f=s.filter(e=>e.def.hidden!==!0&&!d.includes(e.name)),p=typeof t.sharingModel==`string`?t.sharingModel:``,m=p===`private`?`engine.studio.settings.sharingDescPrivate`:p===`public_read`?`engine.studio.settings.sharingDescPublicRead`:p===`public_read_write`?`engine.studio.settings.sharingDescPublicReadWrite`:p===`controlled_by_parent`?`engine.studio.settings.sharingDescControlledByParent`:`engine.studio.settings.sharingDescUnset`,h=t.enable&&typeof t.enable==`object`?t.enable:{},g=(e,t)=>n({enable:{...h,[e]:t}}),_=[{key:`trackHistory`,optIn:!0,labelKey:`engine.studio.settings.capTrackHistory`,descKey:`engine.studio.settings.capTrackHistoryDesc`},{key:`files`,optIn:!0,labelKey:`engine.studio.settings.capFiles`,descKey:`engine.studio.settings.capFilesDesc`},{key:`feeds`,optIn:!1,labelKey:`engine.studio.settings.capFeeds`,descKey:`engine.studio.settings.capFeedsDesc`},{key:`activities`,optIn:!1,labelKey:`engine.studio.settings.capActivities`,descKey:`engine.studio.settings.capActivitiesDesc`},{key:`searchable`,optIn:!1,labelKey:`engine.studio.settings.capSearchable`,descKey:`engine.studio.settings.capSearchableDesc`},{key:`clone`,optIn:!1,labelKey:`engine.studio.settings.capClone`,descKey:`engine.studio.settings.capCloneDesc`}],v=typeof t.externalSharingModel==`string`?t.externalSharingModel:``,y={private:0,public_read:1,public_read_write:2},b=v in y&&p in y&&y[v]>y[p];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)(wr,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.basics`,i)})]}),(0,Q.jsx)(`div`,{className:`max-w-xl p-3`,children:o?(0,Q.jsx)(o,{type:`object`,name:e,draft:t,onPatch:n,readOnly:!!r,locale:i,onBlockingIssuesChange:a}):(0,Q.jsx)(`p`,{className:`text-[12px] text-muted-foreground`,children:Z(`engine.studio.settings.noInspector`,i)})})]}),(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)(br,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.sharing`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingHint`,i)})]}),(0,Q.jsxs)(`div`,{className:`grid max-w-xl gap-2 p-3`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingModel`,i)}),(0,Q.jsxs)(`select`,{value:p,disabled:r,"data-testid":`owd-internal-select`,onChange:e=>n(e.target.value?{sharingModel:e.target.value}:{sharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,i)}),(0,Q.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,Q.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,Q.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,Q.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(m,i)}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingExternal`,i)}),(0,Q.jsxs)(`select`,{value:v,disabled:r,"data-testid":`owd-external-select`,onChange:e=>n(e.target.value?{externalSharingModel:e.target.value}:{externalSharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,i)}),(0,Q.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,Q.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,Q.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,Q.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,Q.jsx)(`p`,{"data-testid":`owd-external-desc`,className:b?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(b?`engine.studio.settings.sharingExternalWider`:`engine.studio.settings.sharingExternalDesc`,i)})]})]}),(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)(hn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.semanticRoles`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.semanticHint`,i)})]}),(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:Z(`engine.studio.settings.nameField`,i)}),(0,Q.jsxs)(`select`,{value:l,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:Z(`engine.studio.settings.autoDerive`,i)}),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)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.stageField`,i)}),(0,Q.jsxs)(`select`,{value:u===!1?`__none__`:u??``,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:Z(`engine.studio.settings.autoDetect`,i)}),(0,Q.jsx)(`option`,{value:`__none__`,children:Z(`engine.studio.settings.stageNone`,i)}),c.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:Z(`engine.studio.settings.highlightFields`,i)}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d.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":os(`engine.studio.settings.removeField`,i,{field:e}),onClick:()=>n({highlightFields:d.filter(t=>t!==e)}),className:`rounded-full hover:bg-primary/20`,children:(0,Q.jsx)(Tn,{className:`h-3 w-3`})})]},e)),!r&&f.length>0&&(0,Q.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&n({highlightFields:[...d,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:Z(`engine.studio.settings.addFieldOption`,i)}),f.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]}),d.length===0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.undeclared`,i)})]})]})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border`,"data-testid":`capabilities-section`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Xe,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.capabilities`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.capabilitiesHint`,i)})]}),(0,Q.jsx)(`div`,{className:`grid max-w-xl gap-3 p-3`,children:_.map(({key:e,optIn:t,labelKey:n,descKey:a})=>{let o=h[e];return(0,Q.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:t?o===!0:o!==!1,disabled:r,"data-testid":`cap-${e}`,onChange:t=>g(e,t.target.checked),className:`mt-0.5`}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-[12px]`,children:Z(n,i)}),(0,Q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(a,i)})]})]},e)})})]})]})}var x_={private:0,public_read:1,public_read_write:2};function S_(e,t){return!!t&&t in x_&&!!e&&e in x_&&x_[t]>x_[e]}function C_(e){for(let t of Ss(e).entries)if((t.def.type??``)===`master_detail`){let e=t.def.reference;if(typeof e==`string`&&e)return e}}function w_(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}var T_=[{value:`private`,key:`engine.studio.settings.sharingPrivate`},{value:`public_read`,key:`engine.studio.settings.sharingPublicRead`},{value:`public_read_write`,key:`engine.studio.settings.sharingPublicReadWrite`},{value:`controlled_by_parent`,key:`engine.studio.settings.sharingControlledByParent`}];function E_(e,t){if(!e)return Z(`engine.studio.settings.sharingUnset`,t);let n=T_.find(t=>t.value===e);return n?Z(n.key,t):e}function D_({client:e,packageId:t,publishNonce:n=0,onDraftSaved:r,readOnly:i=!1,locale:a,highlightObject:o,onDirtyChange:s}){let[c,l]=$.useState([]),[u,d]=$.useState({}),[f,p]=$.useState(!1),[m,h]=$.useState(null),[g,_]=$.useState(!1),[v,y]=$.useState(null),b=$.useCallback(async()=>{p(!1),h(null);try{let[n,r]=await Promise.all([e.list(`object`,{packageId:t}),e.listDrafts({packageId:t,type:`object`}).catch(()=>[])]),i=new Map,a=[],o=new Set;for(let e of n||[]){let t=e.item??e,n=String(t.name??``);!n||o.has(n)||(o.add(n),a.push(n),i.set(n,String(t.label??n)))}for(let e of r||[]){let t=String(e?.name??``);!t||o.has(t)||(o.add(t),a.push(t))}let s=await Promise.all(a.map(async t=>{let[n,r]=await Promise.all([e.layered(`object`,t).catch(()=>null),e.getDraft(`object`,t).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=w_(r),c=s?{...o,...s}:o,l=typeof c.sharingModel==`string`?c.sharingModel:``;return{name:t,label:String(c.label??i.get(t)??t),internal:l,external:typeof c.externalSharingModel==`string`?c.externalSharingModel:``,master:l===`controlled_by_parent`?C_(c.fields):void 0,hasDraft:!!s}}));s.sort((e,t)=>e.label.localeCompare(t.label)||e.name.localeCompare(t.name)),l(s),d(Object.fromEntries(s.map(e=>[e.name,{internal:e.internal,external:e.external}])))}catch(e){h(Ac(e))}finally{p(!0)}},[e,t]);$.useEffect(()=>{b()},[b,n]);let x=$.useRef({});$.useEffect(()=>{if(!o||!f)return;let e=x.current[o];e&&e.scrollIntoView({block:`center`,behavior:`smooth`})},[o,f]);let S=$.useCallback((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}}))},[]),C=$.useMemo(()=>c.map(e=>{let t=u[e.name]??{internal:e.internal,external:e.external};return{row:e,edit:t,dirty:t.internal!==e.internal||t.external!==e.external,invalid:S_(t.internal,t.external)}}),[c,u]),w=C.filter(e=>e.dirty).length,T=C.some(e=>e.invalid),E=w>0,D=$.useRef(s);$.useEffect(()=>{D.current=s}),$.useEffect(()=>{D.current?.(E)},[E]),$.useEffect(()=>()=>{D.current?.(!1)},[]);let O=$.useCallback(async()=>{let n=C.filter(e=>e.dirty&&!e.invalid);if(n.length!==0){_(!0),y(null);try{for(let r of n){let[n,i]=await Promise.all([e.layered(`object`,r.row.name).catch(()=>null),e.getDraft(`object`,r.row.name).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=w_(i),c={...o,...s??{}};r.edit.internal?c.sharingModel=r.edit.internal:delete c.sharingModel,r.edit.external?c.externalSharingModel=r.edit.external:delete c.externalSharingModel,await e.save(`object`,r.row.name,c,{mode:`draft`,packageId:t})}X.success(os(`engine.studio.owd.saved`,a,{count:n.length})),r?.(),await b()}catch(e){y(Ac(e))}finally{_(!1)}}},[C,e,t,r,b,a]),k=!i&&!g&&w>0&&!T;return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,"data-testid":`owd-overview`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-2.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(br,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:Z(`engine.studio.owd.title`,a)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.subtitle`,a)})]}),i?(0,Q.jsxs)(`span`,{title:Z(`engine.studio.pkg.readonlyHint`,a),className:`ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Nn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,a)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void O(),disabled:!k,"data-testid":`owd-save`,className:`ml-auto 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:[g?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3.5 w-3.5`}),w>0?os(`engine.studio.owd.save`,a,{count:w}):Z(`engine.studio.owd.saveNone`,a)]})]}),(0,Q.jsx)(`p`,{className:`border-b px-4 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.description`,a)}),T&&(0,Q.jsxs)(`p`,{"data-testid":`owd-invalid-banner`,className:`flex items-center gap-1.5 border-b bg-amber-400/10 px-4 py-2 text-[11px] text-amber-600 dark:text-amber-400`,children:[(0,Q.jsx)(Wt,{className:`h-3.5 w-3.5 shrink-0`}),Z(`engine.studio.owd.blockedSave`,a)]}),v&&(0,Q.jsx)(`p`,{className:`border-b bg-destructive/10 px-4 py-2 text-[11px] text-destructive`,children:v}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:f?m?(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.loadFailed`,a)}):c.length===0?(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.none`,a)}):(0,Q.jsxs)(`table`,{className:`w-full border-collapse text-[12px]`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colObject`,a)}),(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colInternal`,a)}),(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colExternal`,a)})]})}),(0,Q.jsx)(`tbody`,{children:C.map(({row:e,edit:t,dirty:n,invalid:r})=>{let s=t.internal===`controlled_by_parent`;return(0,Q.jsxs)(`tr`,{ref:t=>{x.current[e.name]=t},"data-testid":`owd-row-${e.name}`,className:`border-b align-top `+(o===e.name?`bg-primary/5`:``),children:[(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:(0,Q.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),n&&(0,Q.jsx)(`span`,{"data-testid":`owd-dirty-${e.name}`,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.owd.unsaved`,a)}),e.hasDraft&&!n&&(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:Z(`engine.studio.unpublishedDraft`,a)})]}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name})]})}),(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:i?(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:E_(t.internal,a)}):(0,Q.jsxs)(`select`,{value:t.internal,"data-testid":`owd-internal-${e.name}`,onChange:t=>S(e.name,{internal:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,a)}),T_.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]})}),(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:s?(0,Q.jsxs)(`span`,{"data-testid":`owd-master-${e.name}`,title:Z(`engine.studio.owd.masterTip`,a),className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(fn,{className:`h-3.5 w-3.5`}),e.master?os(`engine.studio.owd.byParent`,a,{master:e.master}):Z(`engine.studio.owd.byParentUnknown`,a)]}):i?(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:E_(t.external,a)}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`select`,{value:t.external,"data-testid":`owd-external-${e.name}`,onChange:t=>S(e.name,{external:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px] `+(r?`border-amber-500`:``),children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,a)}),T_.filter(e=>e.value!==`controlled_by_parent`).map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]}),r&&(0,Q.jsx)(`span`,{"data-testid":`owd-error-${e.name}`,className:`mt-1 block text-[11px] text-amber-600 dark:text-amber-500`,children:Z(`engine.studio.owd.widerError`,a)})]})})]},e.name)})})]}):(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.loading`,a)})})]})}var O_={GET:`bg-emerald-500/15 text-emerald-600 dark:text-emerald-300`,POST:`bg-sky-500/15 text-sky-600 dark:text-sky-300`,PATCH:`bg-amber-500/15 text-amber-600 dark:text-amber-300`,DELETE:`bg-destructive/15 text-destructive`};function k_(e){switch(e){case`number`:case`currency`:case`percent`:return 0;case`boolean`:return!0;case`date`:return`2024-01-01`;case`datetime`:return`2024-01-01T00:00:00Z`;case`lookup`:case`master_detail`:return`related_record_id`;default:return`string`}}function A_(e){let t=Ss(e).entries,n=new Set([`autonumber`,`formula`,`summary`]),r={};for(let e of t){let t=e.def;if(!n.has(String(t.type))&&t.readonly!==!0&&t.hidden!==!0&&(r[e.name]=k_(t.type),Object.keys(r).length>=8))break}return r}function j_({name:e,draft:t}){let n=as(),[r,i]=$.useState(null),a=typeof window<`u`?window.location.origin:`https://your-host`,o=`/api/v1/data/${e}`,s=$.useMemo(()=>A_(t.fields),[t.fields]),c=JSON.stringify(s,null,2),l=[{id:`list`,method:`GET`,path:o,desc:Z(`engine.studio.api.list`,n)},{id:`create`,method:`POST`,path:o,desc:Z(`engine.studio.api.create`,n),body:!0},{id:`get`,method:`GET`,path:`${o}/{id}`,desc:Z(`engine.studio.api.get`,n)},{id:`update`,method:`PATCH`,path:`${o}/{id}`,desc:Z(`engine.studio.api.update`,n),body:!0},{id:`delete`,method:`DELETE`,path:`${o}/{id}`,desc:Z(`engine.studio.api.delete`,n)}],u=e=>{let t=[`curl -X ${e.method} '${a}${e.path}'`,` -H 'Authorization: Bearer <token>'`];return e.body&&(t.push(` -H 'Content-Type: application/json'`),t.push(` -d '${JSON.stringify(s)}'`)),t.join(` \\
|
|
9
|
-
`)},d=(e,t)=>{navigator.clipboard?.writeText(t).then(()=>{i(e),setTimeout(()=>i(t=>t===e?null:t),1500)})};return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.api.subtitle`,n)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,Q.jsx)(`div`,{className:`rounded-lg border`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold `+O_[e.method],children:e.method}),(0,Q.jsx)(`code`,{className:`min-w-0 flex-1 truncate text-[12px]`,children:e.path}),(0,Q.jsx)(`span`,{className:`hidden shrink-0 text-[11px] text-muted-foreground sm:inline`,children:e.desc}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id,u(e)),title:Z(`engine.studio.api.copyCurl`,n),className:`inline-flex shrink-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[r===e.id?(0,Q.jsx)(pi,{className:`h-3 w-3 text-emerald-500`}):(0,Q.jsx)(Ut,{className:`h-3 w-3`}),r===e.id?Z(`engine.studio.api.copied`,n):`cURL`]})]})},e.id))}),Object.keys(s).length>0&&(0,Q.jsxs)(`div`,{className:`rounded-lg border`,children:[(0,Q.jsx)(`header`,{className:`border-b px-3 py-1.5 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.api.body`,n)}),(0,Q.jsx)(`pre`,{className:`overflow-auto px-3 py-2 text-[11px] leading-5`,children:c})]})]})}function M_(e){if(!e||typeof e!=`object`||!(`item`in e))return null;let t=e.item;return t&&typeof t==`object`&&Object.keys(t).length>0?t:null}function N_(e,t){let n=e.object;return n===`*`?!0:typeof n==`string`?n===t:Array.isArray(n)?n.includes(t)||n.includes(`*`):!1}function P_(e,t){let n=(e||`hook`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_hook_${i}`;for(;r.has(a);)a=`${n}_hook_${++i}`;return a}function F_({objectName:e,packageId:t,disabled:n,hookSchema:r}){let i=as(),a=ss(),o=vo(`hook`),[s,c]=$.useState([]),[l,u]=$.useState(!0),[d,f]=$.useState(null),[p,m]=$.useState(null),[h,g]=$.useState(null),[_,v]=$.useState(!1),[y,b]=$.useState(!1),[x,S]=$.useState(0),[C,w]=$.useState({hook:``,count:0}),T=String(h?.name??``),E=$.useCallback(e=>{w(t=>t.hook===T&&t.count===e?t:{hook:T,count:e})},[T]),D=C.hook===T?C.count:0;$.useEffect(()=>{let n=!1;return u(!0),f(null),(async()=>{try{let[r,i]=await Promise.all([a.list(`hook`,{packageId:t}),a.listDrafts({packageId:t,type:`hook`}).catch(()=>[])]),o=(i||[]).map(e=>String(e.name??``)).filter(Boolean),s=await Promise.all(o.map(e=>a.getDraft(`hook`,e).then(M_).catch(()=>null)));if(n)return;let l=new Map;for(let t of r||[])t?.name&&N_(t,e)&&l.set(String(t.name),t);o.forEach((t,n)=>{let r=s[n];r&&N_(r,e)&&l.set(t,r)}),c([...l.values()])}catch(e){n||f(Ac(e))}finally{n||u(!1)}})(),()=>{n=!0}},[a,t,e,x]),$.useEffect(()=>{let e=s.find(e=>e.name===p)??null;g(e?{...e}:null),v(!1)},[p,s]);let O=$.useCallback(async()=>{if(h?.name){b(!0),f(null);try{await a.save(`hook`,String(h.name),h,{mode:`draft`,packageId:t}),X.success(os(`engine.studio.hooks.saved`,i,{label:String(h.label||h.name)})),v(!1),S(e=>e+1)}catch(e){f(Ac(e))}finally{b(!1)}}},[a,h,t,i]),k=$.useCallback(async()=>{let n=P_(e,s.map(e=>String(e.name??``))),r={name:n,label:Z(`engine.studio.hooks.newLabel`,i),object:e,events:[`beforeInsert`],body:{language:`js`,source:`return;`},priority:100,async:!1};b(!0),f(null);try{await a.save(`hook`,n,r,{mode:`draft`,packageId:t}),S(e=>e+1),m(n)}catch(e){f(Ac(e))}finally{b(!1)}},[a,e,s,t,i]);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)(pr,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.hooks`,i)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,s.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:k,disabled:y,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:l?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}):s.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.hooks.none`,i)}):s.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(p===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsx)(pr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label||e.name}),e.async&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:Z(`engine.studio.hooks.async`,i)})]},String(e.name)))})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg border`,children:[d&&(0,Q.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:d}),h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-medium`,children:String(h.label||h.name)}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:O,disabled:!_||y||D>0,title:D>0?Z(`perm.cel.saveBlocked`,i):void 0,className:`inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[y?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3 w-3`}),Z(`engine.studio.hooks.save`,i)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o?(0,Q.jsx)(o,{type:`hook`,name:String(h.name??``),draft:h,onPatch:e=>{g(t=>({...t,...e})),v(!0)},readOnly:!!n,locale:i,serverSchema:r,onBlockingIssuesChange:E}):(0,Q.jsx)(`div`,{className:`p-3`,children:(0,Q.jsx)(Ts,{schema:r,value:h,onChange:e=>{g(e),v(!0)},readOnly:!!n})})})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.hooks.pick`,i)})]})]})}function I_(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function L_(e,t){let n=(e||`action`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_action_${i}`;for(;r.has(a);)a=`${n}_action_${++i}`;return a}function R_(e,t){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e;for(let e of[`default`,`en-US`,`en`,`zh-CN`])if(typeof t[e]==`string`)return t[e];let n=Object.values(t).find(e=>typeof e==`string`);if(typeof n==`string`)return n}return t}function z_({draft:e,onPatch:t,disabled:n,actionSchema:r,onBlockingIssuesChange:i}){let a=as(),o=$.useMemo(()=>I_(e.actions),[e.actions]),[s,c]=$.useState(null),l=o.some(e=>e.name===s)?s:o[0]?.name??null,u=o.find(e=>e.name===l)??null,d=vo(`action`),f=$.useCallback(e=>{u&&(t({actions:o.map(t=>t.name===u.name?{...t,...e}:t)}),typeof e.name==`string`&&e.name!==u.name&&c(e.name))},[o,u,t]),p=typeof e.name==`string`?e.name:``,[m,h]=$.useState({}),g=$.useCallback((e,t)=>{h(n=>n[e]===t?n:{...n,[e]:t})},[]),_=$.useMemo(()=>new Set(o.map(e=>String(e.name??``))),[o]),v=$.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(m))_.has(t)&&(e+=n);return e},[m,_]),y=$.useRef(i);$.useEffect(()=>{y.current=i}),$.useEffect(()=>{y.current?.(v)},[v]);let b=$.useCallback(()=>{let e=L_(p,o.map(e=>String(e.name??``))),n={name:e,label:Z(`engine.studio.actions.newLabel`,a),type:`script`,objectName:p,locations:[`record_header`],body:{language:`js`,source:`return { ok: true };`}};t({actions:[...o,n]}),c(e)},[o,p,t,a]),x=$.useCallback(e=>{t({actions:o.filter(t=>t.name!==e)}),c(null)},[o,t]);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)(Br,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.actions`,a)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,o.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:b,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)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.actions.none`,a)}):o.map(e=>{let t=is(typeof e.icon==`string`?e.icon:void 0),n=typeof e.type==`string`?e.type:``;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(l===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:R_(e.label,String(e.name??``))}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:n})]},String(e.name))})})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-auto rounded-lg border`,children:u?d?(0,Q.jsxs)(Q.Fragment,{children:[!n&&(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center justify-end border-b px-2 py-1`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>x(u.name),className:`inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-0.5 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,Q.jsx)(qt,{className:`h-3 w-3`}),` `,Z(`engine.studio.actions.delete`,a)]})}),(0,Q.jsx)(d,{type:`action`,name:String(u.name??``),draft:u,onPatch:f,readOnly:!!n,locale:a,serverSchema:r,onBlockingIssuesChange:e=>g(String(u.name??``),e)})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:R_(u.label,String(u.name??``))}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.actions.pick`,a)})})]})}var B_=[{key:`data`,label:`Data`,Icon:tt},{key:`automations`,label:`Automations`,Icon:Gr},{key:`interfaces`,label:`Interfaces`,Icon:sr},{key:`access`,label:`Access`,Icon:Ie}],V_={group:ir,page:Mr,object:tt,dashboard:sr,report:qe,view:dt,action:Hr},H_=e=>V_[e??``]??xi;function U_(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 W_({packageId:e,tab:t,beforeNavigate:n}){let r=p(),i=as(),[a,o]=$.useState(!1),[s,c]=$.useState(null),[l,u]=$.useState(!1),[d,f]=$.useState(null),[m,h]=$.useState(!1),[g,_]=$.useState(!1);$.useEffect(()=>{let e=!1,t=()=>{lo().then(t=>{e||c(t)}).catch(()=>{})};return t(),window.addEventListener(`objectui:packages-changed`,t),()=>{e=!0,window.removeEventListener(`objectui:packages-changed`,t)}},[e]);let v=s?.find(t=>t.id===e)??null,y=$.useCallback(async e=>{let t=await(await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`})).json(),n=t?.data??t;return(Array.isArray(n)?n:n?.packages??[]).find(t=>(t?.manifest?.id??t?.id)===e)??null},[]),b=$.useCallback(async e=>{o(!1),_(!0);try{f(await y(e)),h(!0)}catch(e){X.error(Ac(e))}finally{_(!1)}},[y]),x=$.useCallback(async()=>{let n=[];try{n=await lo(),c(n)}catch{}let i=d?.manifest.id;if(i){if(!n.some(e=>e.id===i)){if(i===e){let e=n[0];r(e?`/studio/${encodeURIComponent(e.id)}/${t}`:`/home`)}return}try{let e=await y(i);e&&f(e)}catch{}}},[d,e,t,r,y]);return(0,Q.jsxs)(et,{open:a,onOpenChange:o,children:[(0,Q.jsx)(Tt,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,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`,i),children:[(0,Q.jsx)(ut,{className:`h-4 w-4`}),` `,v?.name??e,v&&!v.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)(Nn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]}),(0,Q.jsx)(ti,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,Q.jsxs)(ft,{align:`start`,sideOffset:6,className:`w-80 rounded-lg p-1.5`,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`,i)}),(0,Q.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[s===null&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}),s?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,i)}),s?.map(a=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),a.id!==e&&(n&&!n()||r(`/studio/${encodeURIComponent(a.id)}/${t}`))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(a.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,Q.jsx)(ut,{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:a.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:a.id})]}),a.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`,i)}):(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)(Nn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]})]},a.id))]}),(0,Q.jsxs)(`div`,{className:`mt-1 space-y-0.5 border-t pt-1.5`,children:[v&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void b(e),disabled:g,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 disabled:opacity-50`,children:[g?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(wn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pkg.manage`,i)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),u(!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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,i)]})]})]}),(0,Q.jsx)(So,{open:l,onOpenChange:u,onCreated:e=>{n&&!n()||r(`/studio/${encodeURIComponent(e)}/data`)}}),(0,Q.jsx)(so,{pkg:d,open:m,onOpenChange:h,onChanged:x})]})}function G_({aiSlot:e}){let t=l(),n=t.packageId??`com.example.showcase`,i=t.tab??`interfaces`,a=as(),[o,s]=$.useState(null);$.useEffect(()=>{let e=!1;return s(null),lo().then(t=>{e||s(t.find(e=>e.id===n)?.writable??null)}).catch(()=>{}),()=>{e=!0}},[n]);let c=o===!1,[u,d]=$.useState(!1),f=$.useCallback(()=>!u||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,a)),[u,a]);$.useEffect(()=>{if(!u)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[u]);let[m,h]=$.useState(!1),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(0),[S,C]=$.useState(0),w=$.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 _(null);let t=await e.json(),r=Array.isArray(t)?t:t?.drafts??[];_(r.length)}catch{_(null)}},[n]);$.useEffect(()=>{w()},[w,b,S]);let T=$.useCallback(async()=>{y(!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(Mc(r)):(X.success(Z(`engine.studio.publishedAll`,a)),h(!1)),x(e=>e+1)}catch(e){X.error(Ac(e))}finally{y(!1)}await w()},[n,w]),E=$.useCallback(()=>C(e=>e+1),[]),D=(g??0)>0,O=p(),k=ss(),[A,j]=$.useState(null),[M,N]=$.useState(!1),[ee,P]=$.useState(!1),[F,te]=$.useState(null),[I,ne]=$.useState(null),[L,R]=$.useState(!0),re=$.useCallback(async()=>{let[e,t]=await Promise.all([k.list(`object`,{packageId:n}),k.listDrafts({packageId:n,type:`object`}).catch(()=>[])]),r=(e||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),i=new Set(r.map(e=>e.name));for(let e of t)e.name&&!i.has(e.name)&&r.push({name:e.name,label:e.name});return r},[k,n]),z=$.useCallback(async(e,t)=>{P(!0),te(null);try{let r=L?await re().catch(()=>[]):[];await k.save(`app`,t,Zg(t,e,r),{mode:`draft`,packageId:n}),X.success(os(`engine.studio.app.savedDraft`,a,{label:e})),ne(e),N(!1),C(e=>e+1)}catch(e){te(Ac(e))}finally{P(!1)}},[L,re,k,n,a]);$.useEffect(()=>{let e=!1;return(async()=>{try{let t=(await k.list(`app`,{packageId:n})||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name)[0];e||j(t??null)}catch{e||j(null)}})(),()=>{e=!0}},[k,n,b]);let ie=!e;return(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 overflow-x-auto border-b px-3 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{f()&&O(`/home`)},title:Z(`engine.studio.home`,a),className:`shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)($t,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(W_,{packageId:n,tab:i,beforeNavigate:f})}),(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`·`}),(0,Q.jsx)(`nav`,{className:`flex shrink-0 gap-1`,children:B_.map(e=>(0,Q.jsxs)(r,{to:`/studio/${n}/${e.key}`,onClick:t=>{i!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||f()||t.preventDefault())},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(i===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}`,a)]},e.key))}),(0,Q.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[A?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>window.open(Bc(`apps/${encodeURIComponent(A.name)}`),`_blank`),title:os(`engine.studio.app.openTitle`,a,{label:A.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)(Ye,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.open`,a)]}):I?(0,Q.jsx)(`span`,{title:Z(`engine.studio.app.willOpenAfterPublish`,a),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:os(`engine.studio.app.pending`,a,{label:I})}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),disabled:c,title:Z(c?`engine.studio.pkg.readonlyHint`:`engine.studio.app.noneTitle`,a),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 disabled:pointer-events-none disabled:opacity-50`,children:[(0,Q.jsx)(ze,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,a)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>h(!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)(Wn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,a),D?` · ${g}`:``]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),disabled:v||!D||c,title:Z(c?`engine.studio.pkg.readonlyHint`:D?`engine.studio.publishTitle`:`engine.studio.publishNoneTitle`,a),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:[v?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(bn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.publish`,a)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:i===`data`?(0,Q.jsx)(Q_,{packageId:n,publishNonce:b,onDraftSaved:E,readOnly:c}):i===`automations`?(0,Q.jsx)(ev,{packageId:n,publishNonce:b,onDraftSaved:E,readOnly:c}):i===`access`?(0,Q.jsx)(tv,{packageId:n,publishNonce:b,onDraftSaved:E,readOnly:c,onDirtyChange:d}):(0,Q.jsx)(J_,{packageId:n,publishNonce:b,draftNonce:S,onDraftSaved:E,onCreateApp:c?void 0:()=>N(!0),readOnly:c,foldInspector:ie,onDirtyChange:d})})]}),ie&&(0,Q.jsx)(Ag,{packageId:n,locale:a}),(0,Q.jsx)(Mf,{open:m,onOpenChange:h,packageId:n,onPublish:c?void 0:T,publishing:v}),(0,Q.jsx)($g,{open:M,onOpenChange:N,title:Z(`engine.studio.app.create`,a),labelFieldLabel:Z(`engine.studio.app.nameLabel`,a),labelPlaceholder:Z(`engine.studio.app.namePlaceholder`,a),idFieldLabel:Z(`engine.studio.app.idLabel`,a),idPlaceholder:Z(`engine.studio.app.idPlaceholder`,a),submitLabel:Z(`engine.studio.createDraft`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:ee,error:F,locale:a,onSubmit:({label:e,name:t})=>void z(e,t),extra:(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:L,onChange:e=>R(e.target.checked),className:`h-3.5 w-3.5 accent-primary`}),Z(`engine.studio.app.scaffoldNav`,a)]})})]})}function K_({nodes:e,active:t,onPick:n,objectIcons:r}){return(0,Q.jsx)(Q.Fragment,{children:e.map((e,i)=>{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)(ir,{className:`h-3 w-3`}),` `,e.label]}),(0,Q.jsx)(`div`,{className:`pl-1.5`,children:(0,Q.jsx)(K_,{nodes:e.children??[],active:t,onPick:n,objectIcons:r})})]},e.id??i);let a=Gg(e),o=a?.type===`object`?r?.[a.name]:void 0,s=e.icon?is(e.icon):o?is(o):H_(e.type),c=!!a&&t?.type===a.type&&t?.name===a.name;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a&&n(a),disabled:!a,title:a?`${a.type} · ${a.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 `+(c?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(s,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),a&&a.type!==`page`&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:a.type})]},e.id??i)})})}function q_({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=as(),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 J_({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i,readOnly:a=!1,foldInspector:o=!1,onDirtyChange:s}){let l=ss(),u=as(),d=hi(),[f,p]=$.useState(!1),[m,h]=$.useState(e),[g,_]=$.useState(null),[v,y]=$.useState({}),b=$.useMemo(()=>Array.isArray(v.navigation)?v.navigation:[],[v]),[x,S]=$.useState(!1),[C,w]=$.useState(null),[T,E]=c(),D=Qa(T.get(`sel`)),O=$.useRef(null);$.useEffect(()=>{if(!D||b.length===0||O.current===D)return;let e=Za({navigation:b},D);e&&(O.current=D,S(!0),w({kind:`nav`,id:e.selectionId}))},[D,b]),$.useEffect(()=>{let e=C?$a({navigation:b},C.id):null;E(t=>{let n=new URLSearchParams(t);return e?n.set(`sel`,wo(e)):n.delete(`sel`),n},{replace:!0})},[C]);let[k,A]=$.useState(!1),j=$.useRef(s);$.useEffect(()=>{j.current=s}),$.useEffect(()=>{j.current?.(k)},[k]),$.useEffect(()=>()=>{j.current?.(!1)},[]);let[M,N]=$.useState(!1),[ee,P]=$.useState(!1),[F,te]=$.useState(null),I=qg(F),[ne,L]=$.useState(`source`),[R,re]=$.useState({}),[z,ie]=$.useState(null),[ae,oe]=$.useState(`canvas`),B=Ng(),se=o&&!B,[ce,le]=$.useState(!1),ue=!se,de=!!(x&&C||z),fe=$.useRef(de);$.useEffect(()=>{if(!se)return;let e=fe.current;fe.current=de,oe(t=>jg(t,e,de))},[se,de]);let[pe,me]=$.useState(!1),[V,he]=$.useState(!1),[ge,_e]=$.useState(!1),[ve,ye]=$.useState(null),[be,xe]=$.useState(`loading`),[H,Se]=$.useState([]),Ce=$.useMemo(()=>Object.fromEntries(H.map(e=>[e.name,e.icon])),[H]);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([l.list(`object`,{packageId:e}),l.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),icon:t.icon?String(t.icon):void 0})}Se([...i.values()])}catch{}})(),()=>{t=!0}},[l,e,t,n]),$.useEffect(()=>{let t=!1;return xe(`loading`),(async()=>{try{let n=await l.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 l.listDrafts({packageId:e,type:`app`});if(t)return;let a=n?.[0];a?.name&&(r=String(a.name),i=String(a.name))}if(!r){xe(`missing`);return}h(i),_(r);let[a,o]=await Promise.all([l.layered(`app`,r),l.getDraft(`app`,r).catch(()=>null)]);if(t)return;let s=a,c=s.effective??s.code??{},u=U_(o),d=u?{...c,...u}:c;(typeof d.label==`string`||typeof d.name==`string`)&&h(String(d.label??d.name??i)),y(d),N(!!u),xe(`ready`);let f=Array.isArray(d.navigation)?d.navigation:[],p=(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=Gg(n);if(e)return e}return null})(f),m=I?Kg(f,I):null;te(e=>e??m??p)}catch(e){t||(ye(Ac(e)),xe(`missing`))}})(),()=>{t=!0}},[l,e,t,n]);let we=oo(F?.type??``),U=Ig(F?.type??``),Te=xo(F?.type??``),Ee=vo(F?.type??``),[De,W]=$.useState({key:``,count:0}),Oe=`${F?.type??``}:${F?.name??``}:${z?`${z.kind}:${z.id}`:`default`}`,ke=De.key===Oe?De.count:0,G=!!we&&!U,Ae=F?.type===`page`?R?.kind:void 0,je=Ae===`html`||Ae===`react`;$.useEffect(()=>{if(!F||!G){re({}),_e(!1);return}let e=!1;return me(!0),ye(null),ie(null),(async()=>{try{let[t,n]=await Promise.all([l.layered(F.type,F.name),l.getDraft(F.type,F.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=U_(n);re(i?{...r,...i}:r),_e(!!i)}catch(t){e||ye(Ac(t))}finally{e||me(!1)}})(),()=>{e=!0}},[l,F,G,t]);let Me=$.useCallback(e=>re(t=>({...t,...e})),[]),Ne=$.useCallback(async()=>{if(F){he(`draft`);try{await l.save(F.type,F.name,R,{mode:`draft`,packageId:e}),_e(!0),r?.()}catch(e){ye(Ac(e))}finally{he(!1)}}},[l,F,R,r]),Pe=$.useCallback(e=>{y(t=>({...t,...e})),A(!0)},[]),Fe=$.useCallback(async()=>{if(g){P(`draft`);try{let t=(Array.isArray(v.navigation)?v.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 l.save(`app`,g,{...v,navigation:t},{mode:`draft`,packageId:e}),N(!0),A(!1),r?.()}catch(e){ye(Ac(e))}finally{P(!1)}}},[l,g,v,r]),Ie=(0,Q.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex shrink-0 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)(Xt,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.previewIsRuntime`,u)]}),F&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[F.type,` · `,F.name]})]}),ve&&(0,Q.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:ve}),(0,Q.jsx)(`div`,{className:Tr(je?`min-h-0 flex-1 overflow-hidden`:`rounded-lg border bg-background p-4`),children:be===`missing`&&!ve?(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)(sr,{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`,u)}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,u)})]}),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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,u)]})]}):F?pe?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,u)]}):U?(0,Q.jsx)(U,{type:F.type,name:F.name,draft:R,locale:u}):je?(0,Q.jsx)(bo,{mode:`preview`,draft:R,readOnly:!0}):we?(0,Q.jsx)(we,{type:F.type,name:F.name,draft:R,editing:!0,selection:z,onSelectionChange:ie,onPatch:Me,locale:u}):(0,Q.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:os(`engine.studio.if.readonlyPreview`,u,{type:F.type})}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)})}),!G&&F?.type===`object`?(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(tt,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,u),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,u)]}):null]}),Le=(0,Q.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b bg-background/95 px-3 py-2`,children:[(0,Q.jsx)(pn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,u)}),(0,Q.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[z&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,u),children:(0,Q.jsx)(Tn,{className:`h-3.5 w-3.5`})}),ue&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>le(!0),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.collapse`,u),title:Z(`engine.studio.inspector.collapse`,u),children:(0,Q.jsx)(sn,{className:`h-3.5 w-3.5`})})]})]}),Re=(0,Q.jsxs)(`aside`,{className:`flex w-9 shrink-0 flex-col items-center gap-1.5 border-l bg-background py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>le(!1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.expand`,u),title:Z(`engine.studio.inspector.props`,u),children:(0,Q.jsx)(Zt,{className:`h-4 w-4`})}),(0,Q.jsx)(pn,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),Be=x&&C?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(q_,{navId:C.id,appDraft:v,objects:H,onNavPatch:Pe,onClear:()=>w(null)})}):z&&Te&&F?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Te,{type:F.type,name:F.name,draft:R,selection:z,onPatch:Me,onClearSelection:()=>ie(null),onSelectionChange:ie,onBlockingIssuesChange:e=>W({key:Oe,count:e}),readOnly:!1,locale:u})}):je?se?(0,Q.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 border-t`,children:(0,Q.jsx)(bo,{mode:`editor`,draft:R,onPatch:Me})}):(0,Q.jsxs)(on,{value:ne,onValueChange:e=>L(e===`props`?`props`:`source`),className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(nn,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,Q.jsxs)(dn,{value:`source`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.tabSource`,u)]}),(0,Q.jsx)(dn,{value:`props`,className:`text-xs`,children:Z(`engine.studio.inspector.tabProps`,u)})]}),(0,Q.jsx)(lt,{value:`source`,className:`mt-2 min-h-0 flex-1 border-t`,children:(0,Q.jsx)(bo,{mode:`editor`,draft:R,onPatch:Me})}),(0,Q.jsx)(lt,{value:`props`,className:`mt-0 min-h-0 flex-1 overflow-auto p-3`,children:(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)(ct,{className:`h-5 w-5`}),os(`engine.studio.inspector.sourcePageLine1`,u,{kind:Ae}),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.sourcePageLine2`,u)]})})]}):Ee&&F&&G?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Ee,{type:F.type,name:F.name,draft:R,onPatch:Me,onSelectionChange:ie,onBlockingIssuesChange:e=>W({key:Oe,count:e}),readOnly:!1,locale:u})}):(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(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)(Hr,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,u),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,u)]})});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)(`button`,{type:`button`,onClick:()=>p(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,u),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Ar,{className:`h-4 w-4`})}),F?(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:F.label}),(0,Q.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:[F.type,` · `,F.name]})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)}),ge&&(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`,u)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:Ne,disabled:!F||!G||!!V||a||ke>0,title:ke>0?Z(`perm.cel.saveBlocked`,u):a?Z(`engine.studio.pkg.readonlyHint`,u):void 0,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:[V===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,u)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[d&&f&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>p(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:Tr((x?`w-72`:`w-52`)+` flex shrink-0 flex-col border-r bg-background`,d&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,d&&!f&&`-translate-x-full`),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:os(`engine.studio.if.navHeading`,u,{app:m})}),be===`ready`&&!a&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{S(e=>!e),w(null)},title:Z(x?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,u),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(x?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:x?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(pi,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,u)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,u)]})})]}),x&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[M&&(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`,u)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:Fe,disabled:!k||!!ee,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[ee===`draft`?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3 w-3`}),Z(`engine.studio.saveDraft`,u)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:be===`missing`&&!ve?(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`,u)}),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)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,u)]})]}):x?(0,Q.jsx)(_o,{draft:v,rootKey:`navigation`,onPatch:Pe,selection:C,onSelectionChange:e=>w(e?{kind:e.kind,id:e.id}:null)}):b.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(ve?`engine.studio.loadFailed`:be===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,u)}):(0,Q.jsx)(K_,{nodes:b,active:F,objectIcons:Ce,onPick:e=>{te(e),d&&p(!1)}})})]}),o?B?(0,Q.jsxs)(Q.Fragment,{children:[Ie,ce?Re:(0,Q.jsxs)(`aside`,{"data-testid":`studio-folded-inspector`,className:Tr(`flex shrink-0 flex-col overflow-hidden border-l`,je&&!(z&&Te&&F)&&!(x&&C)?`w-[22rem] 2xl:w-[28rem]`:`w-72 2xl:w-80`),children:[Le,Be]})]}):(0,Q.jsxs)(on,{value:ae,onValueChange:e=>oe(e===`properties`?`properties`:`canvas`),className:`flex min-w-0 flex-1 flex-col`,"data-testid":`studio-center-tabs`,children:[(0,Q.jsxs)(nn,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,Q.jsxs)(dn,{value:`canvas`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(Xt,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.if.tabCanvas`,u)]}),(0,Q.jsxs)(dn,{value:`properties`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(pn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.props`,u)]})]}),(0,Q.jsx)(lt,{forceMount:!0,value:`canvas`,className:`mt-0 flex min-h-0 flex-1 flex-col data-[state=inactive]:hidden`,children:Ie}),(0,Q.jsxs)(lt,{value:`properties`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:[Le,Be]})]}):(0,Q.jsxs)(Q.Fragment,{children:[Ie,ce?Re:(0,Q.jsxs)(`aside`,{className:Tr(`flex shrink-0 flex-col overflow-hidden border-l`,je&&!(z&&Te&&F)&&!(x&&C)?`w-[24rem] xl:w-[30rem] 2xl:w-[36rem]`:`w-72`),children:[Le,Be]})]})]})]})}function Y_(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var X_=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 Z_(e){let{schema:t,dataSource:n,onEdit:r,className:i,onAddRecord:a}=e;return(0,Q.jsx)(Ns,{schema:{...t,viewType:`grid`,showSearch:!0,showSort:!0,showFilters:!0,showGroup:!0,showHideFields:!0,inlineEdit:!0,addDeleteRecordsInline:!0,addRecord:{enabled:!0}},dataSource:n,onEdit:r,onAddRecord:a,className:i})}function Q_({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=ss(),a=Ee(),o=as(),{entries:s}=cs(i),c=$.useMemo(()=>{let e={};for(let t of s)e[t.type]=t.schema;return e},[s]),l=hi(),[u,d]=$.useState(!1),[f,p]=$.useState([]),[m,h]=$.useState(!1),[g,_]=$.useState(null),v=qg(g),[y,b]=$.useState({}),[x,S]=$.useState(!1),[C,w]=$.useState(null),[T,E]=$.useState(null),[D,O]=$.useState({key:``,count:0}),k=T?`${g?.name??``}:${T.kind}:${T.id}`:``,A=D.key===k?D.count:0,[j,M]=$.useState({key:``,count:0}),[N,ee]=$.useState(!1),[P,F]=$.useState(!1),[te,I]=$.useState(!1),[ne,L]=$.useState(null),[R,re]=$.useState(0),[z,ie]=$.useState(`grid`),ae=`${g?.name??``}:${z}`,oe=j.key===ae?j.count:0,B=$.useCallback(e=>M({key:ae,count:e}),[ae]),se=A+oe,[ce,ue]=$.useState(`layout`),de=$.useRef(null),[fe,pe]=$.useState(``),[me,V]=$.useState(!1),[he,ge]=$.useState(!1),[_e,ve]=$.useState(!0),[ye,be]=$.useState(null);$.useEffect(()=>{let t=!1;return lo().then(n=>{t||be(n.find(t=>t.id===e)?.namespace??null)}).catch(()=>{}),()=>{t=!0}},[e]),$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([i.list(`object`,{packageId:e}),i.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??``),icon:e.icon?String(e.icon):void 0})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of r)e.name&&!o.has(e.name)&&a.push({type:`object`,name:e.name,label:e.name,icon:void 0});p(a);let s=Jg(a,v,`object`);_(e=>e??s??a[0]??null)}catch(e){t||w(Ac(e))}finally{t||h(!0)}})(),()=>{t=!0}},[i,e,r]),$.useEffect(()=>{if(!g)return;let e=`${g.name}#${t}`;if(de.current===e)return;de.current=e;let n=!1;return S(!0),w(null),E(null),ee(!1),(async()=>{try{let[e,t]=await Promise.all([i.layered(`object`,g.name),i.getDraft(`object`,g.name).catch(()=>null)]);if(n)return;let r=e,a=r.effective??r.code??{},o=U_(t);b(o?{...a,...o}:a),F(!!o),ve(!!(r.effective??r.code))}catch(e){n||w(Ac(e))}finally{n||S(!1)}})(),()=>{n=!0}},[i,g,t]);let xe=$.useMemo(()=>Ss(y.fields).entries.length,[y]),H=$.useMemo(()=>Ss(y.fields).entries.map(e=>e.name).filter(e=>!X_.has(e)&&e!==`actions`),[y.fields]),Se=$.useMemo(()=>Ss(y.fields).entries.map(e=>e.name).filter(e=>!X_.has(e)),[y.fields]),Ce=$.useCallback(e=>{b(t=>({...t,...e})),ee(!0)},[]),we=$.useCallback(()=>{if(r)return;let e=Ss(y.fields),t=Y_(e.entries.map(e=>e.name));e.entries.push(gs(t,`text`,Z(`engine.studio.data.newFieldLabel`,o))),b(t=>({...t,fields:ys(e)})),ee(!0),E({kind:`field`,id:t})},[y,r]),U=$.useCallback(async(t,a)=>{if(r)return;let s=ro(a,ye);if(f.some(e=>e.name===s)){w(os(`engine.studio.data.idExists`,o,{name:s}));return}ge(!0),w(null);try{let r=Yg(s,t,Z(`engine.studio.data.nameFieldLabel`,o));await i.save(`object`,s,r,{mode:`draft`,packageId:e});let a={type:`object`,name:s,label:t};p(e=>[...e,a]),_(a),ie(`form`),ue(`layout`),V(!1),n?.()}catch(e){w(Ac(e))}finally{ge(!1)}},[f,i,e,n,r,o,ye]),Te=$.useCallback(async()=>{if(g){I(`draft`),w(null);try{await i.save(`object`,g.name,y,{mode:`draft`,packageId:e}),F(!0),ee(!1),L(new Date),X.success(os(`engine.studio.data.savedDraft`,o,{label:g.label})),n?.()}catch(e){w(Ac(e))}finally{I(!1)}}},[i,g,y,n,e,o]),De=$.useCallback(async t=>{if(!g)return;let r=Ss(y.fields),a=new Set(t),o=t.map(e=>r.entries.find(t=>t.name===e)).filter(e=>!!e),s=0,c=r.entries.map(e=>a.has(e.name)?o[s++]:e),l={...y,fields:ys({...r,entries:c})};b(l),I(`draft`),w(null);try{await i.save(`object`,g.name,l,{mode:`draft`,packageId:e}),F(!0),ee(!1),n?.(),re(e=>e+1)}catch(e){w(Ac(e))}finally{I(!1)}},[i,g,y,n]),W=xo(`object`),Oe=[{key:`grid`,label:Z(`engine.studio.data.tab.records`,o)},{key:`form`,label:Z(`engine.studio.data.tab.form`,o)},{key:`rules`,label:Z(`engine.studio.data.tab.rules`,o)},{key:`hooks`,label:Z(`engine.studio.data.tab.hooks`,o)},{key:`actions`,label:Z(`engine.studio.data.tab.actions`,o)},{key:`api`,label:Z(`engine.studio.data.tab.api`,o)},{key:`settings`,label:Z(`engine.studio.data.tab.settings`,o)}],ke=is(typeof y.icon==`string`?y.icon:g?.icon);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-3 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Ar,{className:`h-4 w-4`})}),g?(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(ke,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:g.label}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:g.name}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:os(`engine.studio.data.fieldCount`,o,{count:xe})})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)}),P&&(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)}),ne&&!N&&(0,Q.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,"data-testid":`data-saved-at`,children:os(`engine.studio.data.lastSaved`,o,{time:ne.toLocaleTimeString(o,{hour:`2-digit`,minute:`2-digit`})})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:Te,disabled:!g||!N||!!te||r||se>0,title:se>0?Z(`perm.cel.saveBlocked`,o):r?Z(`engine.studio.pkg.readonlyHint`,o):void 0,className:(ne&&!N?``:`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:[te===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,o)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[l&&u&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>d(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:Tr(`flex w-52 shrink-0 flex-col border-r bg-background`,l&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,l&&!u&&`-translate-x-full`),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`,o)}),(0,Q.jsx)(`input`,{value:fe,onChange:e=>pe(e.target.value),placeholder:Z(`engine.studio.data.searchObjects`,o),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:[f.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(C?`engine.studio.loadFailed`:m?`engine.studio.data.noObjects`:`engine.studio.loading`,o)}),f.filter(e=>!fe.trim()||e.label.toLowerCase().includes(fe.trim().toLowerCase())||e.name.toLowerCase().includes(fe.trim().toLowerCase())).map(e=>{let t=is(e.icon);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{_(e),l&&d(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(g?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(t,{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:r?(0,Q.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Nn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{w(null),V(!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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden p-4`,children:g?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,children:Oe.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ie(e.key),"aria-pressed":z===e.key,className:`rounded-md px-3 py-1 text-[13px] transition-all `+(z===e.key?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.key))}),(z===`grid`||z===`form`)&&!r&&(0,Q.jsxs)(`button`,{type:`button`,onClick:we,title:Z(`engine.studio.data.addFieldTitle`,o),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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,o)]})]}),C&&(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:C}),z===`rules`?(0,Q.jsx)(y_,{draft:y,onPatch:Ce,disabled:r,onBlockingIssuesChange:B}):z===`settings`?(0,Q.jsx)(b_,{name:g.name,draft:y,onPatch:Ce,locale:o,disabled:r,onBlockingIssuesChange:B}):z===`hooks`?(0,Q.jsx)(F_,{objectName:g.name,packageId:e,disabled:r,hookSchema:c.hook}):z===`actions`?(0,Q.jsx)(z_,{draft:y,onPatch:Ce,disabled:r,actionSchema:c.action,onBlockingIssuesChange:B}):z===`api`?(0,Q.jsx)(j_,{name:g.name,draft:y}):z===`grid`&&!_e?(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`,o)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.draftObjectHint`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{ie(`form`),ue(`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`,o)})]}):z===`grid`?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background`,children:(0,Q.jsx)(kn,{value:{...r?{}:{onAddColumn:we,addColumnLabel:Z(`engine.studio.data.addField`,o),onReorderFields:De},onEditColumn:e=>{Ss(y.fields).entries.some(t=>t.name===e)&&E({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,o)},children:(0,Q.jsx)(le,{dataSource:a,children:(0,Q.jsx)(Ls,{schema:{type:`object-view`,objectName:g.name,showCreate:!1,table:{fields:H}},dataSource:a,renderListView:Z_},`${g.name}:${R}`)})})})}):(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 items-center gap-0.5 rounded-lg bg-muted p-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ue(`layout`),"aria-pressed":ce===`layout`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(ce===`layout`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.layout`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ue(`preview`),"aria-pressed":ce===`preview`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(ce===`preview`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.preview`,o)})]}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(ce===`layout`?N&&!r?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.layoutBadgeClean`:`engine.studio.data.form.previewBadge`,o)}),ce===`preview`&&(N||P)&&(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`,o)})]}),ce===`layout`?(0,Q.jsx)(c_,{draft:y,objectName:g.name,systemFieldNames:X_,onChange:Ce,selectedField:T?.kind===`field`?T.id:null,onSelectField:e=>E({kind:`field`,id:e}),selectedGroup:T?.kind===`group`?T.id:null,onSelectGroup:e=>E({kind:`group`,id:e}),onAddField:we,readOnly:r}):_e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`style`,{children:`
|
|
10
|
-
/* Design preview: the form is a click-to-select canvas, not a data-entry
|
|
11
|
-
* form. Disable interaction on field contents so a click anywhere on a
|
|
12
|
-
* field routes to its [data-field] wrapper (→ select), and neutralize the
|
|
13
|
-
* create/cancel footer so nothing is submittable here. */
|
|
14
|
-
.os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
|
|
15
|
-
.os-form-authoring [data-field] *{pointer-events:none;}
|
|
16
|
-
.os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
|
|
17
|
-
.os-form-authoring form > div:last-child:has(button){display:none;}
|
|
18
|
-
${T?.kind===`field`?`.os-form-authoring [data-field="${String(T.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
|
|
19
|
-
`}),(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-6xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&Ss(y.fields).entries.some(e=>e.name===t)&&E({kind:`field`,id:t})},children:(0,Q.jsx)(le,{dataSource:a,children:(0,Q.jsx)(ki,{schema:{type:`object-form`,objectName:g.name,mode:`create`,fields:Se},dataSource:a},`${g.name}:${R}:form`)})})})]}):(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`,o)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.form.noPublishedHint`,o)})]})]})]}):m&&f.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`,o)}),(0,Q.jsx)(`p`,{className:`max-w-sm text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.firstObjectHint`,o)}),!r&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`empty-state-new-object`,onClick:()=>{w(null),V(!0)},className:`mt-2 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[(0,Q.jsx)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})]}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)})}),g&&T&&(T.kind===`group`||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)(pn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(T.kind===`group`?`engine.studio.data.groupProps`:`engine.studio.data.fieldProps`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.close`,o),children:(0,Q.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T.kind===`group`?(0,Q.jsx)(l_,{draft:y,groupKey:T.id,onPatch:Ce,onClose:()=>E(null),readOnly:r,locale:o}):W&&$.createElement(W,{type:`object`,name:g.name,draft:y,selection:T,onPatch:Ce,onClearSelection:()=>E(null),onSelectionChange:E,onBlockingIssuesChange:e=>O({key:k,count:e}),readOnly:r,locale:o})})]})]}),(0,Q.jsx)($g,{open:me,onOpenChange:V,title:Z(`engine.studio.data.newObject`,o),labelFieldLabel:Z(`engine.studio.data.nameLabel`,o),labelPlaceholder:Z(`engine.studio.data.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.data.idLabel`,o),idPlaceholder:Z(`engine.studio.data.idPlaceholder`,o),submitLabel:Z(`engine.studio.createDraft`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:he,error:C,locale:o,onSubmit:({label:e,name:t})=>void U(e,t)})]})}function $_({state:e,locale:t}){if(!e)return null;let{enabled:n,bound:r}=e,i=Z(n?r?`engine.studio.auto.onBound`:`engine.studio.auto.onUnbound`:`engine.studio.auto.offTitle`,t);return(0,Q.jsxs)(`span`,{title:i,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 ev({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=ss(),a=as(),o=hi(),[s,c]=$.useState(!1),[l,u]=$.useState([]),[d,f]=$.useState(null),p=qg(d),[m,h]=$.useState({}),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(!1),[S,C]=$.useState(!1),[w,T]=$.useState(null),[E,D]=$.useState(!1),[O,k]=$.useState(!1),[A,j]=$.useState(!1),M=oo(d?.type??``),N=xo(`flow`),ee=!!M,[P,F]=$.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});F(i)}catch{}})(),()=>{e=!0}},[t]),$.useEffect(()=>{let t=!1;return(async()=>{try{let n=await Wg(i,`flow`,e);if(t)return;u(n);let r=Jg(n,p,`flow`);f(e=>e??r??n[0]??null)}catch(e){t||T(Ac(e))}finally{t||D(!0)}})(),()=>{t=!0}},[i,e,t]);let te=$.useCallback(async(t,r)=>{j(!0),T(null);try{let o=Xg(r,t,Z(`engine.studio.auto.nodeStart`,a),Z(`engine.studio.auto.nodeEnd`,a));await i.save(`flow`,r,o,{mode:`draft`,packageId:e});let s={type:`flow`,name:r,label:t};u(e=>[...e.filter(e=>e.name!==r),s]),f(s),C(!0),k(!1),n?.(),X.success(os(`engine.studio.auto.savedDraft`,a,{label:t}))}catch(e){T(Ac(e))}finally{j(!1)}},[i,e,n,a]);$.useEffect(()=>{if(!d)return;let e=!1;return y(!0),T(null),_(null),(async()=>{try{let[t,n]=await Promise.all([i.layered(`flow`,d.name),i.getDraft(`flow`,d.name).catch(()=>null)]);if(e)return;let r=t,a=r.effective??r.code??{},o=U_(n);h(o?{...a,...o}:a),C(!!o)}catch(t){e||T(Ac(t))}finally{e||y(!1)}})(),()=>{e=!0}},[i,d,t]);let I=$.useCallback(e=>h(t=>({...t,...e})),[]),ne=$.useCallback(async()=>{if(d){x(`draft`),T(null);try{await i.save(`flow`,d.name,m,{mode:`draft`,packageId:e}),C(!0),n?.()}catch(e){T(Ac(e))}finally{x(!1)}}},[i,d,m,n]),L=m.status!==`obsolete`&&m.status!==`invalid`,R=$.useCallback(async()=>{if(!d)return;let t=m.status===`obsolete`||m.status===`invalid`,r={...m,status:t?`active`:`obsolete`};h(r),x(`draft`),T(null);try{await i.save(`flow`,d.name,r,{mode:`draft`,packageId:e}),C(!0),n?.(),X.success(Z(t?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,a))}catch(e){T(Ac(e))}finally{x(!1)}},[i,d,m,e,n,a]);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)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,a),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Ar,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,a)}),S&&(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)}),d&&(0,Q.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":L,onClick:R,disabled:!ee||!!b,title:Z(L?`engine.studio.auto.disableTitle`:`engine.studio.auto.enableTitle`,a),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 `+(L?`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 `+(L?`translate-x-3`:`translate-x-0.5`)})}),Z(L?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,a)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:ne,disabled:!d||!ee||!!b||r,title:r?Z(`engine.studio.pkg.readonlyHint`,a):void 0,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:[b===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Xr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,a)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[o&&s&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>c(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:Tr(`flex w-52 shrink-0 flex-col overflow-auto border-r bg-background p-2`,o&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,o&&!s&&`-translate-x-full`),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`,a)}),!r&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{T(null),k(!0)},title:Z(`engine.studio.auto.newTitle`,a),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)(ze,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),l.length>0&&l.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{f(e),o&&c(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(d?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(Gr,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,Q.jsx)($_,{state:P[e.name],locale:a})]},e.name)),l.length===0&&!O&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(w?`engine.studio.loadFailed`:E?`engine.studio.auto.none`:`engine.studio.loading`,a)})]}),(0,Q.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex shrink-0 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)(Gr,{className:`h-3 w-3`}),` `,Z(`engine.studio.auto.canvasHint`,a)]}),d&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`flow · `,d.name]})]}),w&&(0,Q.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:w}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 rounded-lg border bg-background p-4`,children:d?v?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,a)]}):M?$.createElement(M,{type:d.type,name:d.name,draft:m,editing:!0,selection:g,onSelectionChange:_,onPatch:I,locale:a}):(0,Q.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(m,null,2)}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.auto.pick`,a)})})]}),(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)(pn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,a)}),g&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>_(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,a),children:(0,Q.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`p-3`,children:g&&N&&d?$.createElement(N,{type:`flow`,name:d.name,draft:m,selection:g,onPatch:I,onClearSelection:()=>_(null),onSelectionChange:_,readOnly:!1,locale:a}):(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)(Hr,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,a),(0,Q.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,a)]})})]})]}),(0,Q.jsx)($g,{open:O,onOpenChange:k,title:Z(`engine.studio.auto.newTitle`,a),labelFieldLabel:Z(`engine.studio.auto.nameLabel`,a),labelPlaceholder:Z(`engine.studio.auto.namePlaceholder`,a),idFieldLabel:Z(`engine.studio.auto.idLabel`,a),idPlaceholder:Z(`engine.studio.auto.idPlaceholder`,a),submitLabel:Z(`engine.studio.createDraft`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:A,error:w,locale:a,onSubmit:({label:e,name:t})=>void te(e,t)})]})}function tv({packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r=!1,onDirtyChange:i}){let a=ss(),o=as(),s=hi(),[c,l]=$.useState(!1),[u,d]=$.useState([]),[f,p]=$.useState(!1),[m,h]=$.useState(null),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(null),S=$.useRef(!1),C=qg($.useMemo(()=>v?{type:`owd`,name:`overview`}:g?{type:`permission`,name:g}:null,[v,g])),[w,T]=$.useState(``),[E,D]=$.useState(!1),[O,k]=$.useState(null),[A,j]=$.useState(!1),[M,N]=$.useState(!1),[ee,P]=$.useState(!1),[F,te]=$.useState(!1),I=ee||F,ne=$.useRef(i);$.useEffect(()=>{ne.current=i}),$.useEffect(()=>{ne.current?.(I)},[I]),$.useEffect(()=>()=>{ne.current?.(!1)},[]);let L=$.useCallback(()=>!I||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,o)),[I,o]),R=$.useCallback(async()=>{try{let[t,n]=await Promise.all([a.list(`permission`,{packageId:e}),a.listDrafts({packageId:e,type:`permission`}).catch(()=>[])]),r=new Map;for(let e of t||[]){let t=String(e.name??e.id??``);t&&r.set(t,{name:t,label:String(e.label??e.name??``),isDefault:!!e.isDefault})}for(let e of n||[]){let t=String(e?.name??``);!t||r.has(t)||r.set(t,{name:t,label:t})}let i=[...r.values()];d(i),!S.current&&C?.type===`owd`&&(S.current=!0,y(!0));let o=Jg(i,C,`permission`);_(e=>e??o?.name??i[0]?.name??null)}catch(e){h(Ac(e))}finally{p(!0)}},[a,e]);$.useEffect(()=>{R()},[R,t]);let re=$.useCallback(async(t,r)=>{j(!0),k(null);try{await a.save(`permission`,r,Qg(r,t),{mode:`draft`,packageId:e}),X.success(os(`engine.studio.access.created`,o,{label:t})),D(!1),n?.(),await R(),y(!1),_(r)}catch(e){k(Ac(e))}finally{j(!1)}},[a,R,e,n,o]),z=u.filter(e=>!w.trim()||e.label.toLowerCase().includes(w.trim().toLowerCase())||e.name.toLowerCase().includes(w.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.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Ar,{className:`h-4 w-4`})}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,o)}),(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,o)})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),className:`ml-auto flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Kr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.access.explain.open`,o)]}),(0,Q.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,o),className:`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`,o)})]}),!r&&(0,Q.jsx)(Gs,{packageId:e,className:`mx-3 mt-2`,strings:{describe:e=>os(e.anchor===`guest`?`engine.studio.access.suggestPromptGuest`:`engine.studio.access.suggestPromptEveryone`,o,{set:e.permission_set_name}),confirm:Z(`engine.studio.access.suggestConfirm`,o),confirming:Z(`engine.studio.access.suggestConfirming`,o),dismiss:Z(`engine.studio.access.suggestDismiss`,o),confirmedToast:e=>os(`engine.studio.access.suggestConfirmedToast`,o,{set:e.permission_set_name,anchor:e.anchor}),dismissedToast:e=>os(`engine.studio.access.suggestDismissedToast`,o,{set:e.permission_set_name})}}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[s&&c&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>l(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:Tr(`flex w-52 shrink-0 flex-col border-r bg-background`,s&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,s&&!c&&`-translate-x-full`),children:[(0,Q.jsx)(`div`,{className:`border-b p-2 pb-2`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(v){x(null),s&&l(!1);return}L()&&(y(!0),x(null),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(v?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(br,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:Z(`engine.studio.owd.railLabel`,o)})]})}),(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`,o)}),(0,Q.jsx)(`input`,{value:w,onChange:e=>T(e.target.value),placeholder:Z(`engine.studio.access.search`,o),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:[u.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(m?`engine.studio.loadFailed`:f?`engine.studio.access.none`:`engine.studio.loading`,o)}),z.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(!v&&g===e.name){s&&l(!1);return}L()&&(y(!1),_(e.name),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(!v&&g===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isDefault&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:`default`})]},e.name))]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,Q.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Nn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{L()&&(k(null),D(!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)(ze,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,o)]})})]}),(0,Q.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:v?(0,Q.jsx)(D_,{client:a,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,locale:o,highlightObject:b,onDirtyChange:te}):g?(0,Q.jsx)(fo,{type:`permission`,name:g,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,onDirtyChange:P,embedded:!0,onOpenOwd:e=>{L()&&(x(e||null),y(!0))}},g):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:f&&u.length===0?Z(`engine.studio.access.emptyMain`,o):Z(`engine.studio.access.pick`,o)})})]}),(0,Q.jsx)(Ug,{open:M,onOpenChange:N,packageId:e}),(0,Q.jsx)($g,{open:E,onOpenChange:D,title:Z(`engine.studio.access.new`,o),labelFieldLabel:Z(`engine.studio.access.nameLabel`,o),labelPlaceholder:Z(`engine.studio.access.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.access.idLabel`,o),idPlaceholder:Z(`engine.studio.access.idPlaceholder`,o),submitLabel:Z(`engine.studio.create`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:A,error:O,locale:o,onSubmit:({label:e,name:t})=>void re(e,t)})]})}function nv({value:e,onChange:t,onEnter:n,onEscape:r,placeholder:i,autoFocus:a,locale:o,testId:s}){let[c,l]=$.useState(!1),u=e.trim().length>0&&!go.test(e.trim());return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`input`,{autoFocus:a,value:e,onChange:e=>{let{value:n,stripped:r}=Co(e.target.value);l(r),t(n)},onKeyDown:e=>{e.key===`Enter`&&n?.(),e.key===`Escape`&&r?.()},placeholder:i,"data-testid":s,className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),c&&(0,Q.jsx)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,"data-testid":`pkg-id-stripped`,children:Z(`engine.studio.pkg.idStrippedNotice`,o)}),u&&(0,Q.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`pkg-id-format-hint`,children:Z(`engine.studio.pkg.idFormatHint`,o)})]})}function rv(){let e=p(),t=as(),[n,r]=$.useState(null),[i,a]=$.useState(null),[o,s]=$.useState(!1);$.useEffect(()=>{let e=!1;return lo().then(t=>{e||r(t)}).catch(t=>{e||a(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let c=t=>e(`/studio/${encodeURIComponent(t)}/data`),l=n?.filter(e=>e.writable)??[],u=n?.filter(e=>!e.writable)??[],[d,f]=$.useState(null),[m,h]=$.useState(``),[g,_]=$.useState(``),[v,y]=$.useState(!1),[b,x]=$.useState(null),S=e=>{f(e.id),h(os(`engine.studio.landing.dupDefaultName`,t,{name:e.name})),_(`${e.id}-copy`),x(null)},C=async()=>{if(!d)return;let e=g.trim(),n=m.trim();if(!(!go.test(e)||!n)){y(!0),x(null);try{await uo(d,e,n),X.success(os(`engine.studio.landing.dupCreated`,t,{name:n})),c(e)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Lr,{className:`h-4.5 w-4.5`})}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:Z(`engine.studio.landing.title`,t)})]}),(0,Q.jsx)(`p`,{className:`mb-5 max-w-2xl text-xs leading-5 text-muted-foreground`,children:Z(`engine.studio.landing.description`,t)}),i&&(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:i}),(0,Q.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.mineHeading`,t)}),(0,Q.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:[n===null&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,t)}),n!==null&&l.length===0&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.landing.noneWritable`,t)}),l.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:()=>c(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,Q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(ut,{className:`h-4 w-4`})}),(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:Z(`engine.studio.pkg.writable`,t)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d===e.id?f(null):S(e),title:Z(`engine.studio.landing.dupTitle`,t),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)(Ut,{className:`h-3 w-3`}),` `,Z(`engine.studio.landing.dup`,t)]})]}),d===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:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&f(null)},placeholder:Z(`engine.studio.landing.dupNamePlaceholder`,t),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)(nv,{value:g,onChange:_,onEnter:()=>void C(),onEscape:()=>f(null),placeholder:Z(`engine.studio.landing.dupIdPlaceholder`,t),locale:t,testId:`pkg-dup-id-input`}),b&&(0,Q.jsx)(`p`,{className:`text-[10px] text-destructive`,children:b}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void C(),disabled:v||!m.trim()||!go.test(g.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:[v?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ut,{className:`h-3 w-3`}),Z(`engine.studio.landing.dupGo`,t)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(null),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,t)})]})]})]},e.id)),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!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)(ze,{className:`h-4 w-4`}),` `,Z(`engine.studio.pkg.new`,t)]})]}),(0,Q.jsx)(yo,{mode:`create`,open:o,onOpenChange:s,onSaved:e=>c(e.id)}),u.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:Z(`engine.studio.landing.installedHeading`,t)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:u.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(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)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,Q.jsx)(ut,{className:`h-4 w-4`})}),(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)(Nn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,t)]})]},e.id))})]})]})}var iv=t({BuilderLanding:()=>rv,SETUP_APP_NAME:()=>wc,SETUP_APP_PACKAGE_ID:()=>Cc});export{xc as C,Ec as D,Cc as E,Sc as O,fc as S,wc as T,od as _,rg as a,gc as b,Uh as c,Mh as d,uh as f,Od as g,mp as h,ig as i,nc as k,Hh as l,yp as m,rv as n,ng as o,th as p,G_ as r,eg as s,iv as t,Nh as u,_u as v,bc as w,mc as x,hu as y};
|