@objectstack/console 16.0.0 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/dist/.objectui-sha +1 -1
  3. package/dist/assets/{AdapterProvider-C6zOh6HD.js → AdapterProvider-CqW7TSvk.js} +1 -1
  4. package/dist/assets/{AiPendingActionsPage-CnAw7P3v.js → AiPendingActionsPage-C-QNNI9k.js} +1 -1
  5. package/dist/assets/{ApiConsolePage-BI45__VZ.js → ApiConsolePage-DSvjQt5N.js} +1 -1
  6. package/dist/assets/{AppDocsIndex-f25vfEKO.js → AppDocsIndex-B4Vi3Lmx.js} +1 -1
  7. package/dist/assets/{AppManagementPage-Bg9uJgOg.js → AppManagementPage-l7bxl-aE.js} +1 -1
  8. package/dist/assets/{ApprovalsInboxPage-DNHuqeXG.js → ApprovalsInboxPage-BV4PlaEv.js} +1 -1
  9. package/dist/assets/{AuditLogPage-B7miw4yM.js → AuditLogPage-ChJYd7GY.js} +1 -1
  10. package/dist/assets/{ComponentNavView-hbkzWx99.js → ComponentNavView-C4OkKu2y.js} +1 -1
  11. package/dist/assets/{CreateViewDialog-C9MmF1EQ.js → CreateViewDialog-DwpQ8KvO.js} +1 -1
  12. package/dist/assets/{DashboardView-B5fvjbK1.js → DashboardView-CuDS84Jp.js} +1 -1
  13. package/dist/assets/{DeveloperHubPage-CLMxDfF8.js → DeveloperHubPage-CnVzl2hV.js} +1 -1
  14. package/dist/assets/{DocShell-Xat5mAFu.js → DocShell-D83T8iWF.js} +1 -1
  15. package/dist/assets/{ExpressionProvider-BrbZIz2M.js → ExpressionProvider-CyltvbX0.js} +1 -1
  16. package/dist/assets/{FlowRunsPage-D3geofgO.js → FlowRunsPage-BE8HeEGL.js} +1 -1
  17. package/dist/assets/{IntegrationsPage-BomrdGvC.js → IntegrationsPage-DI3vZb2A.js} +1 -1
  18. package/dist/assets/{InterfaceListPage-B-1CV8r_.js → InterfaceListPage-BL7sW-SC.js} +1 -1
  19. package/dist/assets/{ManagedByBadge-B6i8b85J.js → ManagedByBadge-D8aPzQJc.js} +1 -1
  20. package/dist/assets/{MarketplaceAccessDenied-CB0BqpZm.js → MarketplaceAccessDenied-B00hPOtj.js} +1 -1
  21. package/dist/assets/{MarketplaceInstalledPage-k4tMP5Il.js → MarketplaceInstalledPage-BdLyXA35.js} +1 -1
  22. package/dist/assets/{MarketplacePackagePage-DFu-NbiT.js → MarketplacePackagePage-By15SZoJ.js} +1 -1
  23. package/dist/assets/{MarketplacePage-hFFqWDhG.js → MarketplacePage-BKxIWeT_.js} +1 -1
  24. package/dist/assets/{MetadataInspector-GuDvqIYj.js → MetadataInspector-CcRGESLn.js} +1 -1
  25. package/dist/assets/{MetadataProvider-1pC12cNH.js → MetadataProvider-CjWp0ChY.js} +1 -1
  26. package/dist/assets/{ObjectDataPage-BXb8qS_O.js → ObjectDataPage-DiQJROyN.js} +1 -1
  27. package/dist/assets/{PageView-CJffWMXV.js → PageView-CJY74CxE.js} +1 -1
  28. package/dist/assets/{ProfilePage-giyDPnkE.js → ProfilePage-CjxWQMQA.js} +1 -1
  29. package/dist/assets/{PublicFormsPage-CvTGsvEk.js → PublicFormsPage-BVEV96-N.js} +1 -1
  30. package/dist/assets/{RecordDetailView-BWj_n2Xd.js → RecordDetailView-DpRJpP6t.js} +1 -1
  31. package/dist/assets/{RecordFormPage-DaAXyIFl.js → RecordFormPage-BMs8Sa4p.js} +1 -1
  32. package/dist/assets/{ReportDefaultInspector-nzEI_7uY.js → ReportDefaultInspector-BpXXGsGu.js} +2 -2
  33. package/dist/assets/{ReportView-BkvoSROz.js → ReportView-C0fP1MLd.js} +1 -1
  34. package/dist/assets/SearchResultsPage-CjSZ416m.js +1 -0
  35. package/dist/assets/{SettingsHub-CLEl9yB4.js → SettingsHub-DhWm94wF.js} +1 -1
  36. package/dist/assets/{SettingsView-D48FlZZ-.js → SettingsView-Dd0B_UlN.js} +1 -1
  37. package/dist/assets/{SystemHubPage-Bcedpt6c.js → SystemHubPage-C5Widsf0.js} +1 -1
  38. package/dist/assets/{createDerive-CoXOsdH9.js → createDerive-DGOUbVlZ.js} +1 -1
  39. package/dist/assets/{data-adapter-C-CzgrY8.js → data-adapter-Dz0aiaG6.js} +2 -2
  40. package/dist/assets/framework-BqSgd3ir.js +8 -0
  41. package/dist/assets/{getIcon-CHjgso2Q.js → getIcon-BZn0biL3.js} +1 -1
  42. package/dist/assets/{highlighted-body-OFNGDK62-iRcLhe8Y.js → highlighted-body-OFNGDK62-CDb4f2Sa.js} +1 -1
  43. package/dist/assets/{i18n-BBfFXbqS.js → i18n-SjY5NweX.js} +1 -1
  44. package/dist/assets/{index-DQKFSIRa.js → index-CgfL2xiq.js} +1 -1
  45. package/dist/assets/mermaid-GHXKKRXX-CWn_Hnds.js +1 -0
  46. package/dist/assets/{metadata-admin-DUDb4_-I.js → metadata-admin-BRw86sJ-.js} +4 -4
  47. package/dist/assets/{plugin-calendar-BwqRXov_.js → plugin-calendar-C4ZXapZt.js} +1 -1
  48. package/dist/assets/{plugin-charts-DFywQsyC.js → plugin-charts-D5Lb0q0u.js} +1 -1
  49. package/dist/assets/{plugin-chatbot-ChDQ0sZw.js → plugin-chatbot-dJq9DS4J.js} +3 -3
  50. package/dist/assets/{plugin-dashboard-LbTxdFyx.js → plugin-dashboard-Cr7jkjy7.js} +1 -1
  51. package/dist/assets/{plugin-form-B69IWc-v.js → plugin-form-D4kHsl47.js} +1 -1
  52. package/dist/assets/{plugin-gantt-DNfSxpfa.js → plugin-gantt-8LuVErg3.js} +1 -1
  53. package/dist/assets/{plugin-grid-D5ooeMq3.js → plugin-grid-CDpGckvD.js} +1 -1
  54. package/dist/assets/{plugin-kanban-CDv0cMku.js → plugin-kanban-Xwny03DA.js} +1 -1
  55. package/dist/assets/{plugin-map-CFb9fmBs.js → plugin-map-CVC4XDJz.js} +1 -1
  56. package/dist/assets/{plugin-markdown-BxslElNy.js → plugin-markdown-By5yxTCK.js} +1 -1
  57. package/dist/assets/{plugin-report-DEkf0Fe2.js → plugin-report-DwvPiTGE.js} +1 -1
  58. package/dist/assets/{plugin-timeline-DUw-qsiu.js → plugin-timeline-D2Sep4-I.js} +1 -1
  59. package/dist/assets/{plugin-tree-8wyez9hx.js → plugin-tree-Doah8whm.js} +1 -1
  60. package/dist/assets/{plugin-view-baVOQ3XC.js → plugin-view-DZXBuUS9.js} +1 -1
  61. package/dist/assets/{plugins-views-Bi6X55Wz.js → plugins-views-BGSw-KmQ.js} +1 -1
  62. package/dist/assets/{runtime-metadata-persistence-Clk8TRxl.js → runtime-metadata-persistence-CEZY_PIp.js} +1 -1
  63. package/dist/assets/{skeletons-D8fbNHVX.js → skeletons-D0Z3uPzj.js} +1 -1
  64. package/dist/assets/{src-IWc9jIui.js → src-DPHY2JFl.js} +1 -1
  65. package/dist/assets/src-RHOMTPFk.js +19 -0
  66. package/dist/assets/{src-DM9imiv_.js → src-YtGn_UVR.js} +1 -1
  67. package/dist/assets/{types-DwzGXr-7.js → types-BR_9hYa5.js} +1 -1
  68. package/dist/assets/{ui-components-BDIRZFoR.js → ui-components-Ci5ufF7g.js} +2 -2
  69. package/dist/assets/{ui-layout-ZABgadCW.js → ui-layout-D_8Fal4s.js} +1 -1
  70. package/dist/assets/{use-book-data-C4CaJKQX.js → use-book-data-CV2dCLgr.js} +1 -1
  71. package/dist/assets/{appRoute-C7XNGt8B.js → utils-CFdPTF34.js} +1 -1
  72. package/dist/index.html +3 -3
  73. package/package.json +4 -4
  74. package/dist/assets/SearchResultsPage-Badp3TZy.js +0 -1
  75. package/dist/assets/framework-brxTxzwx.js +0 -8
  76. package/dist/assets/mermaid-GHXKKRXX-o9V61CTW.js +0 -1
  77. package/dist/assets/src-BEYY1hUL.js +0 -19
  78. package/dist/assets/utils-Bxty7IIa.js +0 -1
@@ -1,5 +1,5 @@
1
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-DAXXjFlN.js";import{a as n,d as r,f as i,g as a,h as o,m as s,r as c,s as l,y as u}from"./vendor-react-BKSb6vFP.js";import{h as d,p as f}from"./infrastructure-C6pQBkbt.js";import{B as p,M as m,Qt as h,T as g,Tt as _,W as v,Yt as y,dt as b,ft as x,j as S,ut as C}from"./framework-brxTxzwx.js";import{C as w,E as T,J as E,S as D,c as O,g as k,l as A,u as ee,v as j,x as te,y as ne}from"./vendor-objectstack-CjHQG7Oa.js";import{$a as M,$n as re,$o as N,$r as ie,$s as ae,$t as oe,Ac as se,Ai as P,Ao as ce,Ar as le,Ba as ue,Bo as de,Co as F,Ct as fe,Dc as pe,Di as me,Do as he,Ec as ge,Ei as _e,Eo as ve,Es as ye,Fa as be,Fi as xe,Fr as Se,Fs as Ce,Gn as we,Gt as Te,Ha as Ee,Hn as De,Ho as Oe,Hr as ke,Hs as Ae,Ia as je,Ii as Me,Io as Ne,Ir as Pe,Ja as Fe,Ji as Ie,Jn as Le,Jo as Re,Jr as ze,Jt as Be,Ka as Ve,Ki as He,Kn as Ue,Ko as We,Kr as Ge,Ks as Ke,Li as qe,Lo as Je,Lr as Ye,Ma as Xe,Mc as I,Mo as Ze,Mr as Qe,Ms as $e,Na as et,Ni as tt,No as nt,Nr as rt,Ns as it,O as at,Oa as ot,Oi as st,Oo as ct,Or as L,Os as lt,Pa as ut,Pi as dt,Po as ft,Pr as pt,Ps as mt,Q as ht,Qa as gt,Qi as _t,Qn as vt,Qs as yt,Qt as bt,Ra as xt,Ri as St,Ro as Ct,Rs as wt,Sa as Tt,Si as Et,St as Dt,Ta as Ot,Ti as kt,To as At,Ts as jt,Tt as Mt,Ua as Nt,Ur as Pt,Us as Ft,Vi as It,Vo as Lt,Wi as Rt,Wn as zt,Wo as Bt,Ws as Vt,X as Ht,Xn as Ut,Xo as Wt,Xr as Gt,Xt as Kt,Yi as qt,Yr as Jt,Ys as Yt,Yt as Xt,Z as Zt,Zn as Qt,Zo as $t,Zr as R,Zs as en,Zt as tn,_a as nn,_i as rn,_t as an,aa as on,ac as sn,an as cn,ao as ln,ar as un,as as dn,at as fn,bc as pn,bi as mn,bo as hn,bs as gn,bt as _n,ca as vn,cc as yn,cs as bn,dc as xn,di as Sn,dn as Cn,ec as wn,ei as Tn,en as En,eo as Dn,er as On,es as kn,fa as An,fc as jn,fn as Mn,fo as Nn,fr as z,fs as Pn,ga as Fn,gs as In,gt as Ln,ha as Rn,hi as zn,ho as Bn,hs as Vn,ht as Hn,ia as Un,ii as Wn,io as Gn,ir as Kn,is as qn,jc as Jn,ji as Yn,jo as Xn,jr as Zn,k as Qn,ka as $n,kc as er,ko as tr,lc as nr,li as rr,ls as ir,ma as ar,mc as or,mi as sr,mn as B,ms as cr,mt as lr,na as ur,nc as dr,nn as fr,nr as pr,ns as mr,oc as hr,on as gr,oo as _r,os as vr,pn as yr,po as br,ps as xr,qa as V,qn as Sr,qs as Cr,qt as wr,ra as H,rc as Tr,ri as Er,rn as Dr,ro as Or,rr as kr,sn as Ar,so as jr,ta as Mr,tc as Nr,tn as Pr,tr as Fr,ts as Ir,tt as Lr,ua as Rr,uc as zr,ui as Br,uo as Vr,us as Hr,va as Ur,vn as U,vo as Wr,vt as Gr,wa as Kr,wc as qr,wi as Jr,ws as Yr,wt as Xr,xa as Zr,xc as Qr,xt as $r,yc as ei,yo as ti,yt as ni,za as ri,zc as ii,zi as ai,zs as oi}from"./ui-components-BDIRZFoR.js";import{r as si}from"./vendor-ui-utils-D-WJ115h.js";import"./AdapterProvider-C6zOh6HD.js";import"./MetadataProvider-1pC12cNH.js";import{n as ci,o as li}from"./assistantBus-CbDb2Mju.js";import{B as ui,H as di,L as fi,U as pi,a as mi,c as hi,l as gi,o as _i,s as vi,z as yi}from"./RecordDetailView-BWj_n2Xd.js";import{f as bi}from"./plugin-chatbot-ChDQ0sZw.js";import{n as xi}from"./ui-layout-ZABgadCW.js";import{t as Si}from"./getIcon-CHjgso2Q.js";import{a as Ci,i as wi,n as W,o as Ti,r as Ei,t as G}from"./i18n-BBfFXbqS.js";import{a as Di,i as Oi,n as ki,o as Ai,r as ji,s as Mi,t as Ni}from"./createDerive-CoXOsdH9.js";import{A as Pi,B as Fi,C as Ii,D as Li,E as K,F as Ri,G as zi,H as Bi,I as Vi,J as Hi,K as Ui,L as Wi,M as Gi,N as Ki,O as q,P as qi,R as Ji,S as Yi,T as Xi,U as Zi,V as Qi,W as $i,_ as ea,a as ta,b as na,c as ra,d as ia,f as aa,g as oa,h as sa,i as ca,j as la,k as ua,l as da,m as fa,n as pa,o as ma,p as ha,r as ga,s as _a,t as va,u as ya,v as ba,w as xa,x as J,y as Sa,z as Ca}from"./ReportDefaultInspector-nzEI_7uY.js";import{t as wa}from"./InterfaceListPage-B-1CV8r_.js";import{n as Ta}from"./plugins-views-Bi6X55Wz.js";import{r as Ea}from"./dist-B4b49_J4.js";var Y=c(),X=e(u(),1);function Da(){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_AI_BASE_URL;return t?t.replace(/\/$/,``):`${(e.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1/ai`}function Oa(){let{agents:e,isLoading:t}=bi({apiBase:Da()}),n=(0,X.useRef)(!1);t&&(n.current=!0);let r=e.length>0;return{enabled:r,isLoading:r?!1:t||!n.current}}var ka=`flow-palette-recents`,Aa=ka,ja=5;function Ma(){try{if(typeof localStorage>`u`)return[];let e=localStorage.getItem(Aa);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).slice(0,ja):[]}catch{return[]}}function Na(e){if(e)try{if(typeof localStorage>`u`)return;let t=[e,...Ma().filter(t=>t!==e)].slice(0,ja);localStorage.setItem(Aa,JSON.stringify(t))}catch{}}var Pa=ka;function Fa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).slice(0,5):[]}function Ia(e){try{let t=localStorage.getItem(ui(Pa,e));return t?Fa(JSON.parse(t)):[]}catch{return[]}}function La(e,t){try{localStorage.setItem(ui(Pa,t),JSON.stringify(e))}catch{}}function Ra(e,t){if(!t)return{list:e,didMigrate:!1};let n;try{n=localStorage.getItem(Pa)}catch{return{list:e,didMigrate:!1}}if(n==null)return{list:e,didMigrate:!1};let r=[];try{r=Fa(JSON.parse(n))}catch{}try{localStorage.removeItem(Pa)}catch{}if(r.length===0)return{list:e,didMigrate:!0};let i=[...e];for(let e of r)i.includes(e)||i.push(e);return{list:i.slice(0,5),didMigrate:!0}}var za=(0,X.createContext)(null);function Ba({children:e}){let{user:t}=f(),n=t?.id??null,r=pi(`flowPaletteRecents`),[i,a]=(0,X.useState)(()=>Ia(n));di(ui(Pa,n),e=>{a(Fa(e))});let o=(0,X.useMemo)(()=>yi(async e=>{r&&await r.save(e)},500),[r]);(0,X.useEffect)(()=>()=>void o.flush(),[o]);let s=(0,X.useCallback)(e=>{La(e,n),r&&o.schedule(e)},[n,r,o]),c=(0,X.useRef)(0);(0,X.useEffect)(()=>{let e=++c.current,t=!1;return(async()=>{let i=Ia(n),s=r?Fa(await r.load().catch(()=>[])):[];if(t||e!==c.current)return;let{list:l,didMigrate:u}=Ra(s.length?s:i,n);a(l),La(l,n),u&&r&&o.schedule(l)})(),()=>{t=!0}},[r,n,o]);let l=(0,X.useCallback)(e=>{e&&a(t=>{let n=[e,...t.filter(t=>t!==e)].slice(0,5);return s(n),n})},[s]),u=(0,X.useMemo)(()=>({recents:i,recordRecent:l}),[i,l]);return(0,Y.jsx)(za.Provider,{value:u,children:e})}function Va(){let e=(0,X.useContext)(za),[t,n]=(0,X.useState)(()=>Ma()),r=(0,X.useCallback)(e=>{Na(e),n(Ma())},[]);return e||{recents:t,recordRecent:r}}function Ha(e,t){if(!t)return!0;let n=t.toLowerCase();return e.value.toLowerCase().includes(n)||e.label.toLowerCase().includes(n)||(e.group?.toLowerCase().includes(n)??!1)}function Ua({label:e,value:t,onCommit:n,options:r,placeholder:i=`Select…`,searchPlaceholder:a=`Search or type…`,emptyText:o=`No match — keep typing to use a custom value.`,disabled:s,loading:c,allowCustom:l=!0,mono:u,className:d}){let[f,p]=X.useState(!1),[m,h]=X.useState(``),g=r.find(e=>e.value===t),_=g?g.label:t||(c?`Loading…`:i),v=X.useMemo(()=>r.filter(e=>Ha(e,m)),[r,m]),y=X.useMemo(()=>{let e=[],t=new Map;for(let n of v){let r=n.group??``;t.has(r)||(t.set(r,[]),e.push(r)),t.get(r).push(n)}return e.map(e=>({heading:e,items:t.get(e)}))},[v]),b=m.trim(),x=l&&!!b&&!r.some(e=>e.value===b),S=e=>{n(e),p(!1),h(``)},C=(0,Y.jsxs)(Cn,{open:f,onOpenChange:e=>{p(e),e||h(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":f,disabled:s,className:I(`h-8 w-full justify-between px-2 text-sm font-normal`,d),children:[(0,Y.jsx)(`span`,{className:I(`truncate`,u&&`font-mono`,!g&&!t&&`text-muted-foreground`),children:_}),(0,Y.jsx)(oi,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,Y.jsx)(Mn,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,Y.jsxs)(De,{shouldFilter:!1,children:[(0,Y.jsx)(Ue,{value:m,onValueChange:h,placeholder:a}),(0,Y.jsxs)(Le,{children:[!x&&v.length===0&&(0,Y.jsx)(zt,{children:o}),x&&(0,Y.jsx)(we,{children:(0,Y.jsx)(Sr,{value:`__custom__${b}`,onSelect:()=>S(b),children:(0,Y.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`“`,b,`”`]})]})})}),y.map((e,n)=>(0,Y.jsx)(we,{heading:e.heading||void 0,children:e.items.map(e=>(0,Y.jsxs)(Sr,{value:e.value,onSelect:()=>S(e.value),children:[(0,Y.jsx)(Cr,{className:I(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,Y.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,Y.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),C]}):C}var Wa=[`object`,`page`,`dashboard`,`report`,`url`,`group`],Ga=[`default`,`view`,`record`,`filters`],Ka={object:{targetKey:`objectName`,metaType:`object`},page:{targetKey:`pageName`,metaType:`page`},dashboard:{targetKey:`dashboardName`,metaType:`dashboard`},report:{targetKey:`reportName`,metaType:`report`},url:{targetKey:`url`},group:{}};function qa(e){return(e.pageType??e.type)!==`record`}var Ja=[`objectName`,`viewName`,`recordId`,`recordMode`,`filters`,`pageName`,`dashboardName`,`reportName`,`url`,`target`,`params`],Ya=[`path`,`kind`,`href`,`route`,`object`,`page`,`dashboard`,`report`],Xa={object:`object`,page:`page`,dashboard:`dashboard`,report:`report`,link:`url`,url:`url`,group:`group`};function Za(e){let t=e.type;if(typeof t==`string`&&Wa.includes(t))return t;let n=e.kind;if(typeof n==`string`&&Xa[n])return Xa[n];if(e.objectName||e.object)return`object`;if(e.pageName||e.page)return`page`;if(e.dashboardName||e.dashboard)return`dashboard`;if(e.reportName||e.report)return`report`;if(e.url||e.href)return`url`;if(Array.isArray(e.children)&&e.children.length>0)return`group`;let r=e.path;return typeof r==`string`&&/^https?:/i.test(r)?`url`:null}function Qa(e){if(e.recordId)return`record`;let t=e.filters;return t&&typeof t==`object`&&!Array.isArray(t)?`filters`:e.viewName?`view`:`default`}function $a(e=[]){let t={};for(let n of[...Ja,...Ya])e.includes(n)||(t[n]=void 0);return t}var eo={default:[`objectName`],view:[`objectName`,`viewName`],record:[`objectName`,`recordId`,`recordMode`],filters:[`objectName`,`filters`]};function to(e,t,n){let r=e.id;if(typeof r==`string`&&r)return r;let i=`nav_${(n??String(e.objectName??e.label??`item`)).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)||`item`}`,a=new Set(t.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean));if(!a.has(i))return i;let o=2;for(;a.has(`${i}_${o}`);)o++;return`${i}_${o}`}var no=[`nav`,`navigation`,`tabs`,`items`,`menu`];function ro(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function io(e,t){let n=e[t[0].key];if(!Array.isArray(n))return{parent:[],node:null,index:-1};let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r)return{parent:n,node:null,index:t[e].index};if(n=r[t[e].key],!Array.isArray(n))return{parent:[],node:null,index:-1};r=n[t[e].index]??null}return{parent:n,node:r,index:t[t.length-1].index}}function ao(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:la(i,t[0].index,n)};let a=i,o=[];for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}};o.push({arr:a,index:t[e].index,node:n});let r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let s=la(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function oo(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function so(e,t){let n=Ai(),[r,i]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){i({options:[],loading:!1});return}let r=!1;return i(e=>({...e,loading:!0})),n.list(e).then(e=>{if(r)return;let n=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).filter(e=>!t||t(e)).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));i({options:n,loading:!1})}).catch(()=>{r||i({options:[],loading:!1})}),()=>{r=!0}},[n,e,t]),r}var co={currentUserId:`{current_user_id}`,currentOrgId:`{current_org_id}`};function lo({objectName:e,filters:t,onCommit:n,disabled:r,locale:i}){let{fields:a}=Ki(e||void 0),o=X.useMemo(()=>a.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]),s=Object.entries(t),c=(e,t,r)=>{let i=s.slice();i[e]=[t,r],n(Object.fromEntries(i.filter(([e])=>e!==``)))},l=e=>{let t=s.slice();t.splice(e,1),n(Object.fromEntries(t))};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:G(`engine.inspector.appNav.filters`,i)}),s.map(([e,t],n)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ua,{value:e,onCommit:e=>c(n,e,t),options:o,placeholder:G(`engine.inspector.appNav.filtersField`,i),disabled:r,mono:!0})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`=`}),(0,Y.jsx)(`input`,{value:t,onChange:t=>c(n,e,t.target.value),placeholder:G(`engine.inspector.appNav.filtersValue`,i),disabled:r,className:`h-7 w-0 min-w-0 flex-1 rounded border bg-background px-2 font-mono text-xs`,"data-testid":`nav-filter-value-${e||`new`}`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(n),disabled:r,className:`rounded p-1 text-muted-foreground hover:bg-muted`,"aria-label":G(`engine.inspector.appNav.filtersRemove`,i),"data-testid":`nav-filter-remove-${e||`new`}`,children:(0,Y.jsx)(Se,{className:`h-3 w-3`})})]},`${e}-${n}`)),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n({...t,"":``}),disabled:r||Object.prototype.hasOwnProperty.call(t,``),className:`inline-flex items-center gap-1 rounded border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,"data-testid":`nav-filter-add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`engine.inspector.appNav.filtersAdd`,i)]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.appNav.filtersHint`,i)})]})}function uo({selection:e,draft:t,name:n,onPatch:r,onClearSelection:i,onSelectionChange:a,locale:o,readOnly:s}){let c=ro(e.id),{node:l,parent:u,index:d}=c?io(t,c):{node:null,parent:[],index:-1},f=l?Za(l):null,p=l?Qa(l):`default`,m=String(l?.objectName??l?.object??``),h=so(f===`object`?`object`:void 0),g=f&&f!==`object`?Ka[f].metaType:void 0,_=so(g,g===`page`?qa:void 0),v=so(f===`object`&&p===`view`?`view`:void 0),y=X.useMemo(()=>m?v.options.filter(e=>e.value.startsWith(`${m}.`)||!e.value.includes(`.`)):v.options,[v.options,m]);if(!c||!l)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.appNav.kind`,o),title:e.label??e.id,onClose:i,closeLabel:G(`engine.inspector.appNav.close`,o),children:(0,Y.jsx)(Yi,{message:e.id})});let b=l.label??l.title??l.name??e.id,x=e=>{let n=e.type??l.type??f??void 0;r(ao(t,c,{...l,id:to(l,u),...n?{type:n}:{},...e}))},S=e=>{let t=Ka[e].targetKey,n=e===`object`?eo.default:t?[t]:[];x({type:e,...$a(n)})},C=e=>{let t=$a(eo[e]);x(e===`filters`?{...t,objectName:m,filters:l.filters??{}}:{...t,objectName:m})},w=()=>{r(ao(t,c,null)),i()},T=e=>{let n=Pi(u,d,e);r(oo(t,c,n));let i=c.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),o=c[c.length-1].key,s=i?`${i}.${o}[${e}]`:`${o}[${e}]`;a?.({kind:`nav`,id:s,label:String(b)})},E=f&&f!==`group`?xi({...l,type:f},`/apps/${n||`app`}`,co).href:null,D=Ka[f??`group`];return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.appNav.kind`,o),title:String(b),onClose:i,closeLabel:G(`engine.inspector.appNav.close`,o),headerActions:(0,Y.jsx)(Xi,{index:d,total:u.length,onMove:T,upLabel:G(`engine.inspector.reorder.up`,o),downLabel:G(`engine.inspector.reorder.down`,o),disabled:s}),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.appNav.remove`,o),onClick:w,disabled:s}),children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.label`,o),value:String(l.label??l.title??l.name??``),onCommit:e=>x({label:e}),disabled:s}),(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.icon`,o),value:String(l.icon??``),onCommit:e=>x({icon:e}),disabled:s}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.typeField`,o),value:f??``,options:Wa.map(e=>({value:e,label:G(`engine.inspector.appNav.type.${e}`,o)})),onCommit:e=>S(e),disabled:s}),f===`object`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.object`,o),value:m,options:h.options,loading:h.loading,onCommit:e=>x({objectName:e,object:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.targetMode`,o),value:p,options:Ga.map(e=>({value:e,label:G(`engine.inspector.appNav.mode.${e}`,o)})),onCommit:e=>C(e),disabled:s||!m}),p===`view`&&(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.view`,o),value:String(l.viewName??``),options:y,loading:v.loading,onCommit:e=>x({viewName:e}),disabled:s,mono:!0}),p===`record`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.recordId`,o),value:String(l.recordId??``),onCommit:e=>x({recordId:e}),disabled:s,mono:!0}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.appNav.recordIdHint`,o)}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.recordMode`,o),value:String(l.recordMode??`view`),options:[{value:`view`,label:G(`engine.inspector.appNav.recordModeView`,o)},{value:`edit`,label:G(`engine.inspector.appNav.recordModeEdit`,o)}],onCommit:e=>x({recordMode:e}),disabled:s})]}),p===`filters`&&(0,Y.jsx)(lo,{objectName:m,filters:l.filters??{},onCommit:e=>x({filters:e}),disabled:s,locale:o})]}),f&&f!==`object`&&f!==`group`&&D.targetKey&&(D.metaType?(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.type.${f}`,o),value:String(l[D.targetKey]??``),options:_.options,loading:_.loading,onCommit:e=>x({[D.targetKey]:e}),disabled:s,mono:!0}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.url`,o),value:String(l.url??l.href??``),onCommit:e=>x({url:e,href:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.urlTarget`,o),value:String(l.target??`_self`),options:[{value:`_self`,label:G(`engine.inspector.appNav.urlTargetSelf`,o)},{value:`_blank`,label:G(`engine.inspector.appNav.urlTargetBlank`,o)}],onCommit:e=>x({target:e}),disabled:s})]})),E&&(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 px-2 py-1.5`,"data-testid":`nav-target-preview`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.appNav.preview`,o)}),(0,Y.jsx)(`div`,{className:`break-all font-mono text-[11px]`,children:E})]})]})}var fo=no;function po(e){if(!e||!e.startsWith(`nav:`))return null;let t=e.slice(4);return t.length>0?t:null}function mo(e){return`nav:${e}`}var ho=`surface`;function go(e){return`${e.type}:${e.name}`}function _o(e){if(!e)return null;let t=e.indexOf(`:`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n&&r?{type:n,name:r}:null}function vo(e,t){let n=(e,r)=>{for(let i=0;i<e.length;i++){let a=e[i];if(!a||typeof a!=`object`)continue;let o=`${r}[${i}]`;if(a.id===t){let e=a.label??a.title??a.name;return{selectionId:o,label:typeof e==`string`?e:void 0}}if(Array.isArray(a.children)){let e=n(a.children,`${o}.children`);if(e)return e}}return null};for(let t of fo){let r=e[t];if(!Array.isArray(r))continue;let i=n(r,t);if(i)return i}return null}function yo(e,t){let n=t.split(`.`),r;for(let t=0;t<n.length;t++){let i=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(n[t]);if(!i)return null;let a=i[1],o=Number(i[2]),s=t===0?e[a]:r?.[a];if(!Array.isArray(s)||(r=s[o],!r||typeof r!=`object`))return null}return typeof r?.id==`string`&&r.id?r.id:null}var bo=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function xo(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function So(e){let t=e.reference??e.reference_to??e.referenceTo??e.reference_to_object;if(typeof t==`string`&&t)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0];if(t&&typeof t==`object`){let e=t.object;if(typeof e==`string`&&e)return e}}function Co(e){switch(e){case`lookup`:case`master_detail`:case`masterDetail`:case`master-detail`:return`lookup`;case`date`:case`datetime`:case`time`:return`date`;case`number`:case`currency`:case`percent`:case`int`:case`integer`:case`float`:case`double`:case`autonumber`:return`number`;case`boolean`:case`toggle`:return`boolean`;default:return`string`}}function wo(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=xo(e.label,t),r=Qi(e.fields).entries.map(e=>({name:e.name,label:xo(e.def.label,e.name),type:typeof e.def.type==`string`?e.def.type:void 0,def:e.def}));return{label:n,fields:r,relationships:r.filter(e=>e.type&&bo.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:So(e.def)}))}}function To(e,t,n){let r=e,i=[];for(let e of t.split(`.`)){let t=r.relationships.find(t=>t.name===e);if(!t?.referenceTo)return;let a=n[t.referenceTo];if(!a)return;i.push(t.label),r=a}return{target:r,labels:i}}function Eo(e,t,n){let r=e.fields.map(t=>({value:t.name,label:t.label,type:t.type,group:e.label}));for(let i of t){let t=To(e,i,n);if(!t)continue;let a=[...t.labels,t.target.label].join(` → `);for(let e of t.target.fields)r.push({value:`${i}.${e.name}`,label:e.label,type:e.type,group:a})}return r}function Do(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Do(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t||Object.values(n).some(e=>e&&typeof e==`object`&&Do(e,t))}function Oo(){let e=Ai(),[t,n]=X.useState({options:[],loading:!0});return X.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{if(t)return;let r=(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:xo(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label));n({options:r,loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function ko(e,t){let n=Ai(),r=t.join(`\0`),[i,a]=X.useState({relationships:[],fieldOptions:[],loading:!!e});return X.useEffect(()=>{if(!e){a({relationships:[],fieldOptions:[],loading:!1});return}let t=!1;return a(e=>({...e,loading:!0})),(async()=>{try{let i=await n.get(`object`,e);if(t)return;let o=wo(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=wo(await n.get(`object`,e),e)}catch{t=wo(null,e)}return c[e]=t,t};for(let e of s){let t=o;for(let n of e.split(`.`)){let e=t.relationships.find(e=>e.name===n);if(!e?.referenceTo)break;t=await l(e.referenceTo)}}if(t)return;let u=[...o.relationships];for(let e of s){if(e.split(`.`).length>=3)continue;let t=To(o,e,c);if(t)for(let n of t.target.relationships)u.push({name:`${e}.${n.name}`,label:`${e}.${n.name}`,referenceTo:n.referenceTo})}a({relationships:u,fieldOptions:Eo(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Ao(e){let t=Ai(),[n,r]=X.useState({reports:0,dashboards:0,loading:!!e});return X.useEffect(()=>{if(!e){r({reports:0,dashboards:0,loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),(async()=>{let[i,a]=await Promise.all([t.list(`report`).catch(()=>[]),t.list(`dashboard`).catch(()=>[])]);n||r({reports:(Array.isArray(i)?i:[]).filter(t=>Do(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Do(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}function jo(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function Mo(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function No(e){let t=new Set;for(let n of e){let e=Mo(n);e&&t.add(e)}return t}function Po(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Fo(e,t){return e===t?null:e>t?e-1:e}function Io(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Lo({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=Ki(i||void 0,a),m=X.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=X.useState(null),[_,v]=X.useState(null),y=X.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=X.useCallback(t=>{let i=ua(n,Po(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),x=X.useCallback(t=>{let r=la(n,t,null);if(y(r),o!=null){let n=Fo(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:jo(r[n],n)})}},[n,y,o,e,l]),S=X.useCallback((t,r)=>{if(t===r)return;let i=Pi(n,t,r);if(y(i),o!=null){let n=Io(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:jo(i[n],n)})}},[n,y,o,e,l]),C=X.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:jo(n[t],t)})},[n,e,l]),w=No(n);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Y.jsx)(_a,{index:t,label:jo(e,t),fieldName:Mo(e),fieldType:m.get(Mo(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>C(t),onRemove:()=>x(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&S(h,t),g(null),v(null)}},t))}),u&&(0,Y.jsx)(ma,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var Ro=[`record`,`current_user`,`user`,`features`,`app`,`data`,`ctx`];function zo(e){if(e==null)return`null`;let t=typeof e;return t===`string`?JSON.stringify(e):t===`number`||t===`boolean`?String(e):Array.isArray(e)?`[${e.map(zo).join(`, `)}]`:JSON.stringify(String(e))}function Bo(e){if(!e.field||!e.operator)return``;let t=`record[${JSON.stringify(e.field)}]`;switch(e.operator){case`equals`:return`${t} == ${zo(e.value)}`;case`not_equals`:return`${t} != ${zo(e.value)}`;case`greater_than`:return`${t} > ${zo(e.value)}`;case`less_than`:return`${t} < ${zo(e.value)}`;case`contains`:return`${t}.contains(${zo(e.value)})`;case`in`:return`${t} in ${zo(Array.isArray(e.value)?e.value:[e.value])}`;default:return``}}function Vo(e){return typeof e.condition==`string`?e.condition:e.condition&&typeof e.condition==`object`&&typeof e.condition.source==`string`?e.condition.source:typeof e.expression==`string`?e.expression:Bo(e)}function Ho(e){let t=Vo(e),n={};if(e.style&&typeof e.style==`object`)for(let[t,r]of Object.entries(e.style))r!=null&&(n[t]=String(r));return e.backgroundColor&&(n.backgroundColor=String(e.backgroundColor)),e.textColor&&(n.color=String(e.textColor)),e.borderColor&&(n.borderColor=String(e.borderColor)),{condition:t,style:n}}function Uo({label:e,value:t,onChange:n,disabled:r}){return(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`input`,{type:`color`,value:/^#([0-9a-f]{6})$/i.test(t)?t:`#000000`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 w-8 shrink-0 rounded border border-input bg-background p-0.5 disabled:opacity-60`,"aria-label":e}),(0,Y.jsx)(B,{value:t,placeholder:`#RRGGBB`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 text-xs font-mono`})]})]})}function Wo({rules:e,onChange:t,objectName:n,fieldNames:r,disabled:i,t:a}){let o=X.useMemo(()=>Array.isArray(e)?e.map(Ho):[],[e]),s=e=>t(e),c=(e,t)=>{let n=o.map((n,r)=>r===e?{...n,...t}:n);s(n)},l=(e,t,n)=>{let r={...o[e].style};n?r[t]=n:delete r[t],c(e,{style:r})},u=()=>s([...o,{condition:``,style:{}}]),d=e=>s(o.filter((t,n)=>n!==e)),f=(e,t)=>{let n=e+t;if(n<0||n>=o.length)return;let r=o.slice();[r[e],r[n]]=[r[n],r[e]],s(r)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,"data-testid":`cf-editor`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:a(`engine.inspector.view.cf.title`)}),(0,Y.jsxs)(L,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs`,disabled:i,onClick:u,"data-testid":`cf-add`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a(`engine.inspector.view.cf.add`)]})]}),o.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:a(`engine.inspector.view.cf.empty`)}),o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border p-2 space-y-2`,"data-testid":`cf-rule-${t}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[a(`engine.inspector.view.cf.rule`),` `,t+1]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===0,onClick:()=>f(t,-1),"aria-label":a(`engine.inspector.view.cf.moveUp`),"data-testid":`cf-up-${t}`,children:(0,Y.jsx)(Ft,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===o.length-1,onClick:()=>f(t,1),"aria-label":a(`engine.inspector.view.cf.moveDown`),"data-testid":`cf-down-${t}`,children:(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6 text-destructive hover:text-destructive`,disabled:i,onClick:()=>d(t),"aria-label":a(`engine.inspector.view.cf.remove`),"data-testid":`cf-remove-${t}`,children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(ea,{label:a(`engine.inspector.view.cf.when`),value:e.condition,disabled:i,placeholder:`record.status == 'overdue'`,objectName:n,fieldNames:r,scope:`flattened`,roots:Ro,onChange:e=>c(t,{condition:e}),t:a,id:`cf-condition-${t}`}),(0,Y.jsxs)(`div`,{className:I(`grid gap-2 sm:grid-cols-3`),children:[(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.background`),value:e.style.backgroundColor??``,disabled:i,onChange:e=>l(t,`backgroundColor`,e)}),(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.text`),value:e.style.color??``,disabled:i,onChange:e=>l(t,`color`,e)}),(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.border`),value:e.style.borderColor??``,disabled:i,onChange:e=>l(t,`borderColor`,e)})]}),(0,Y.jsx)(`div`,{className:`rounded border border-dashed border-border px-2 py-1 text-xs`,style:e.style,"data-testid":`cf-preview-${t}`,children:a(`engine.inspector.view.cf.preview`)})]},t))]})}var Go={io:`input`,unrepresentable:`any`},Ko=new Set([`columns`,`data`,`name`]),qo,Jo=!1;function Yo(){if(qo||Jo)return qo;try{qo=E(te,Go)}catch(e){Jo=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return qo}function Xo(){return Yo()?.properties?.list}function Zo(){return Yo()?.properties?.form}var Qo,$o=!1;function es(){if(Qo||$o)return Qo;try{Qo=E(j,Go)}catch(e){$o=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Qo}var ts;function ns(){if(ts)return ts;if(!(!T||typeof T!=`object`)){try{let e=JSON.parse(JSON.stringify(T));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Ko.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),ts=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return ts}}var rs=new Set([`form`,`detail`]);function is(e){return rs.has(e)}function as(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function os(e,t){return typeof e==`string`&&rs.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&rs.has(t)?`form`:`list`}function ss(e){let t=e.config;return as(t)?[{storeKey:`config`,familyKey:os(e.viewKind,t.type),schema:t}]:[]}function cs(e){return ss(e)[0]}function ls(e,t){return cs(e)}function us({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){let{options:a,loading:o}=Oo();return(0,Y.jsx)(Ua,{label:e,value:t,onCommit:n,options:a.map(e=>({value:e.name,label:e.label})),loading:o,placeholder:r,searchPlaceholder:`Search objects…`,disabled:i,mono:!0})}var ds=new Set([`type`,`object`,`label`,`columns`,`conditionalFormatting`]),fs={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function ps(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?fs[e]??e:r}var ms=[`columns`,`data`,`name`];function hs(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function gs(e,t){return X.useMemo(()=>{let n=Xo()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:ps(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:ps(e,t)}),r},[e,t])}function _s({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=is(n??t),p=typeof d.type==`string`?d.type:`grid`,m=gs(p,l),h=hs(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=Ki(h.value||void 0,c),b=X.useCallback(e=>G(e,l),[l]),x=X.useMemo(()=>y.map(e=>e.name),[y]),S=Array.isArray(d.conditionalFormatting)?d.conditionalFormatting:[],C=X.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),w=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:T,form:E}=X.useMemo(()=>ta({bundledSchema:f?Zo():Xo(),bundledForm:f?void 0:ns(),serverSchema:w,excludeFields:ds,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,w,l]),D=e=>{i({[t]:{...d,...e}})};return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:G(`engine.inspector.view.close`,l),hideClose:r,children:[(0,Y.jsx)(q,{label:G(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:G(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,Y.jsx)(K,{label:G(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>D({type:e}),disabled:a}),(0,Y.jsx)(us,{label:G(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:G(`engine.inspector.view.objectPlaceholder`,l),disabled:a}),!f&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Lo,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),!f&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Wo,{rules:S,objectName:h.value||void 0,fieldNames:x,disabled:a,t:b,onChange:e=>D({conditionalFormatting:e.length>0?e:void 0})})}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:T?(0,Y.jsx)(ha,{schema:T,form:E,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:C,onChange:e=>{let n={...e};for(let e of ms)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.view.noSchema`,l)})})]})}function vs({appSlug:e}={}){let t=i(),n=Ai(),{entries:r}=Mi(n),[a,o]=X.useState(!1),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),[p,m]=X.useState(0),h=Ti();X.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),o(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),X.useEffect(()=>{if(!a||l!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||u(t)}finally{e||f(!1)}})(),()=>{e=!0}},[a,l,d,r,n]);let g=X.useMemo(()=>{let e=s.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||wi(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(l??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[s,r,l]);X.useEffect(()=>{m(0)},[s,a]);function _(n){o(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,Y.jsx)(Ut,{open:a,onOpenChange:o,children:(0,Y.jsxs)(Qt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(On,{className:`sr-only`,children:(0,Y.jsx)(Fr,{children:G(`engine.quickfind.title`,h)})}),(0,Y.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(B,{autoFocus:!0,placeholder:G(`engine.quickfind.placeholder`,h),value:s,onChange:e=>c(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Y.jsx)(Ht,{children:`esc`})]}),(0,Y.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,Y.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),G(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:G(`engine.quickfind.noMatches`,h)}),(0,Y.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate`,children:wi(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,Y.jsx)(Ve,{className:`h-3 w-3`})}),e.name,e.label&&(0,Y.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})})]})},e.kind===`type`?`t:${e.entry.type}`:`i:${e.type}:${e.name}`))})]}),(0,Y.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Ht,{children:`↑`}),` `,(0,Y.jsx)(Ht,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Ht,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(Ht,{children:`⌘`}),(0,Y.jsx)(Ht,{children:`⇧`}),(0,Y.jsx)(Ht,{children:`M`}),` toggle`]})]})]})})}var ys=new Set([`system`,`cloud`]);function bs(e){let t=(e??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!ys.has(e.scope));return t.sort((e,t)=>e.name.localeCompare(t.name)),t.map(e=>({id:e.id,name:e.name}))}var xs={data:ir,ui:ln,automation:Ye,ai:Et,system:tt,platform:tt,identity:P,security:P},Ss=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Cs=new Set([`field`,`package`]);function ws(){let e=Ai(),{loading:t,error:r,entries:i}=Mi(e),a=Ti(),[s,c]=X.useState(``),[l,u]=X.useState(`all`),[d,f]=X.useState(!1),[p,m]=o(),[h,g]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;g(bs(n))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=X.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);X.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Di(e,`warning`,v??void 0),E=X.useMemo(()=>i.filter(e=>Cs.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[i,v,w]),D=X.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(s){let t=s.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||wi(e.type,a,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=X.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=Ss.indexOf(e),r=Ss.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,Y.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:G(`engine.directory.loading`,a)}):r?(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[G(`engine.directory.loadFailed`,a),`: `,r]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:G(`engine.directory.title`,a)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:W(`engine.directory.description`,a,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.directory.search`,a),value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(L,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.total>0&&(0,Y.jsx)(L,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,Y.jsxs)(n,{to:`./_diagnostics`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5 mr-1`}),W(`engine.directory.diagnosticsLink`,a,{count:x.total})]})}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[G(`engine.directory.quickFind`,a),` `,(0,Y.jsx)(Ht,{children:`⌘`}),(0,Y.jsx)(Ht,{children:`⇧`}),(0,Y.jsx)(Ht,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(Ts,{domain:`all`,label:G(`engine.directory.all`,a),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),Ss.filter(e=>D[e]).map(e=>(0,Y.jsx)(Ts,{domain:e,label:Ei(e,a),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No project packages installed`}),(0,Y.jsx)(ht,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:G(`engine.directory.noMatches`,a)}),(0,Y.jsx)(ht,{children:G(`engine.directory.noMatchesHint`,a)})]}),A.map(([e,t])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,Y.jsx)(xs[e]??xn,{className:`h-3.5 w-3.5`}),Ei(e,a),` (`,t.length,`)`]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,Y.jsx)(Es,{entry:e,locale:a,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,Y.jsx)(vs,{})]})}function Ts({domain:e,label:t,active:n,count:r,onClick:i}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,Y.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Es({entry:e,locale:t,invalidCount:r=0,warnCount:i=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=wi(e.type,t,e.label);return(0,Y.jsxs)(n,{to:s?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(s)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(r>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[r>0&&(0,Y.jsx)(`span`,{title:W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),"aria-label":W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:(0,Y.jsx)(R,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),c]}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:W(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),r>0&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:r}),i>0&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:W(`engine.directory.warnTooltip`,t??`en`,{count:i}),children:i}),o>0&&(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${o} locked item${o===1?``:`s`} — see ADR-0010`,"aria-label":`${o} locked items`,children:[(0,Y.jsx)(Ve,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,t)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}function Ds(e){let t=e?.data??e,n=Array.isArray(t)?t:t?.packages??[],r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.manifest??{},n=String(t.id??e.id??``);if(!n)continue;let i=typeof t.scope==`string`?t.scope:``;if(i===`system`||i===`cloud`)continue;let a=typeof t.namespace==`string`&&t.namespace?t.namespace:A(n);r.push({id:n,name:String(t.name??n),writable:i!==`project`,namespace:a})}return r}async function Os(){let e=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);return Ds(await e.json())}async function ks(e,t,n){let r=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/duplicate`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({targetPackageId:t,...n?{targetName:n}:{}})}),i=await r.json().catch(()=>null);if(!r.ok||i?.success===!1)throw Error(i?.error?.message||`HTTP ${r.status}`)}var As=/^[a-z][a-z0-9_.-]*(\.[a-z0-9_-]+)+$/,js=/^[a-z][a-z0-9_]{1,19}$/;function Ms(e,t){return t&&ee(e,t)?`${t}_${e}`:e}function Ns(e){let t=e.toLowerCase().replace(/[^a-z0-9_.-]/g,``);return{value:t,stripped:t.length!==e.length}}var Ps={io:`input`,unrepresentable:`any`},Fs,Is=!1;function Ls(){if(Fs||Is)return Fs;try{Fs=E(O,Ps)}catch(e){Is=!0,typeof console<`u`&&console.warn(`[package-schema] failed to derive manifest JSONSchema from spec`,e)}return Fs}function Rs(e){return{type:`modal`,sections:[{label:G(`engine.packages.form.basics`,e),columns:1,fields:[{field:`name`,label:G(`engine.packages.create.name`,e),placeholder:`Acme CRM`},{field:`id`,label:G(`engine.packages.create.id`,e),placeholder:`com.acme.crm`,immutable:!0},{field:`namespace`,label:G(`engine.packages.create.namespace`,e),placeholder:`crm`,immutable:!0},{field:`version`,label:G(`engine.packages.create.version`,e),placeholder:`0.1.0`},{field:`type`,label:G(`engine.packages.detail.type`,e),immutable:!0},{field:`description`,label:G(`engine.packages.detail.description`,e)}]},{label:G(`engine.packages.form.advanced`,e),collapsible:!0,collapsed:!0,columns:1,fields:[{field:`defaultDatasource`,label:G(`engine.packages.form.defaultDatasource`,e),immutable:!0},{field:`scope`,label:G(`engine.packages.form.scope`,e),immutable:!0},{field:`dependencies`,label:G(`engine.packages.form.dependencies`,e),immutable:!0}]}]}}var zs=`/api/v1/packages`,Bs=/^\d+\.\d+\.\d+$/;async function Vs(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`,t=Error(typeof e==`string`?e:`Request failed (${n.status})`);throw t.status=n.status,t}return i?.data??i}function Hs(){try{window.dispatchEvent(new CustomEvent(`objectui:packages-changed`))}catch{}}function Us({mode:e,open:t,onOpenChange:n,manifest:r,onSaved:i}){let a=Ti(),o=X.useMemo(()=>Ls(),[]),s=X.useMemo(()=>Rs(a),[a]),c=e===`create`,l=e===`view`,[u,d]=X.useState({}),[f,p]=X.useState(!1),[m,h]=X.useState(null),g=X.useRef(!1);X.useEffect(()=>{t&&(g.current=!1,d(c?{version:`0.1.0`,type:`app`}:{...r??{}}),h(null),p(!1))},[t,c,r]);let _=X.useCallback(e=>{if(!c){d(e);return}d(t=>{let n=e.namespace;return n!==t.namespace&&(g.current=!0,n=String(n??``).toLowerCase().replace(/[^a-z0-9_]/g,``)),!g.current&&e.id!==t.id&&(n=A(String(e.id??``))??``),{...e,namespace:n}})},[c]),v=X.useMemo(()=>{if(l)return[];let e=O.safeParse(u);return e.success?[]:e.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))},[u,l]),y=!!String(u.name??``).trim(),b=String(u.version??``).trim(),x=c?Bs.test(b):!b||Bs.test(b),S=!c||!!String(u.id??``).trim(),C=!c||js.test(String(u.namespace??``).trim()),w=!l&&y&&x&&S&&C&&!f;async function T(){if(w){p(!0),h(null);try{let t;if(c){let n={...u,id:String(u.id??``).trim(),name:String(u.name??``).trim(),version:b,type:u.type??`app`},r=await Vs(zs,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:n})});t={id:String(r?.manifest?.id??n.id),mode:e,package:r}}else{let n=String(r?.id??u.id??``);t={id:n,mode:e,package:await Vs(`${zs}/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:String(u.name??``).trim(),description:String(u.description??``).trim(),version:b})})}}Hs(),i?.(t),n(!1)}catch(e){let t=e?.message??``;e?.status===409||/already exists/i.test(t)?h(G(`engine.packages.create.exists`,a)):h(t||G(c?`engine.packages.create.failed`:`engine.packages.edit.failed`,a))}finally{p(!1)}}}return(0,Y.jsx)(Ut,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Qt,{className:`max-h-[85vh] overflow-y-auto`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsx)(Fr,{children:G(e===`create`?`engine.packages.create.title`:e===`edit`?`engine.packages.edit.title`:`engine.packages.view.title`,a)}),e===`create`?(0,Y.jsx)(vt,{children:W(`engine.packages.create.description`,a,{example:`com.acme.crm`})}):(0,Y.jsx)(vt,{className:`font-mono text-xs`,children:String(r?.id??u.id??``)})]}),(0,Y.jsx)(`div`,{className:`py-1`,"data-testid":`package-form`,children:(0,Y.jsx)(ha,{schema:o,form:s,value:u,onChange:_,issues:v,readOnly:l,createMode:c})}),m&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:m})]}),(0,Y.jsx)(re,{children:l?(0,Y.jsx)(L,{variant:`outline`,onClick:()=>n(!1),children:G(`engine.close`,a)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`outline`,onClick:()=>n(!1),disabled:f,children:G(`engine.cancel`,a)}),(0,Y.jsx)(L,{onClick:T,disabled:!w,"data-testid":`package-form-submit`,children:G(f?c?`engine.packages.create.creating`:`engine.packages.edit.saving`:c?`engine.packages.create.submit`:`engine.packages.edit.save`,a)})]})})]})})}var Ws=`/api/v1/packages`;async function Gs(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function Ks({scope:e}){let t=Ti();if(!e)return(0,Y.jsx)(z,{className:`bg-emerald-400/15 text-emerald-600 hover:bg-emerald-400/15 dark:text-emerald-300`,children:G(`engine.packages.scope.writable`,t)});let n=e===`project`?`default`:e===`system`?`secondary`:`outline`,r=e===`project`?`engine.packages.scope.project`:e===`system`?`engine.packages.scope.system`:e===`cloud`?`engine.packages.scope.cloud`:``;return(0,Y.jsx)(z,{variant:n,children:r?G(r,t):e})}function qs({pkg:e}){let t=Ti(),n=e.enabled!==!1&&e.status!==`disabled`;return(0,Y.jsx)(z,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}function Js({open:e,onOpenChange:t,onCreated:n}){return(0,Y.jsx)(Us,{mode:`create`,open:e,onOpenChange:t,onSaved:e=>n(e.id)})}function Ys({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function Xs({pkg:e,open:t,onOpenChange:n,onSaved:r}){return(0,Y.jsx)(Us,{mode:`edit`,open:t,onOpenChange:n,manifest:e?.manifest??null,onSaved:t=>r(t.package??e)})}function Zs({pkg:e,appBase:t,open:r,onOpenChange:i,onChanged:a}){let o=Ti(),[s,c]=X.useState(null),[l,u]=X.useState(null),[d,f]=X.useState(null),[p,m]=X.useState(!1),[h,g]=X.useState(!1);if(X.useEffect(()=>{u(null),c(null)},[e?.manifest.id]),X.useEffect(()=>{let t=e?.manifest.id;if(!r||!t){f(null);return}let n=!1;return Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{n||f(e?.drafts??[])}).catch(()=>{n||f([])}),()=>{n=!0}},[r,e?.manifest.id]),!e)return null;let _=e.manifest.id,v=e.enabled!==!1&&e.status!==`disabled`,y=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function b(e,t,n){c(e),u(null);try{await t(),u({kind:`ok`,text:n}),a()}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.actionFailed`,o)})}finally{c(null)}}return(0,Y.jsx)(wr,{open:r,onOpenChange:i,children:(0,Y.jsxs)(Be,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Y.jsxs)(Kt,{children:[(0,Y.jsxs)(tn,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Kr,{className:`h-4 w-4`}),e.manifest.name||_]}),(0,Y.jsx)(Xt,{className:`font-mono text-xs`,children:_})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(Ys,{label:G(`engine.packages.col.version`,o),children:e.manifest.version||`—`}),(0,Y.jsx)(Ys,{label:G(`engine.packages.detail.type`,o),children:e.manifest.type||`—`}),(0,Y.jsx)(Ys,{label:G(`engine.packages.col.scope`,o),children:(0,Y.jsx)(Ks,{scope:e.manifest.scope})}),(0,Y.jsx)(Ys,{label:G(`engine.packages.col.status`,o),children:(0,Y.jsx)(qs,{pkg:e})}),e.manifest.description&&(0,Y.jsx)(Ys,{label:G(`engine.packages.detail.description`,o),children:e.manifest.description})]}),t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`my-4`}),(0,Y.jsxs)(n,{to:`${t}/metadata/object?package=${encodeURIComponent(_)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5`}),G(`engine.packages.detail.browseMetadata`,o)]})]}),d&&d.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`my-4`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[G(`engine.packages.detail.pendingChanges`,o),(0,Y.jsx)(z,{variant:`secondary`,children:d.length})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G(`engine.packages.detail.pendingHint`,o)}),!y&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(L,{size:`sm`,onClick:()=>b(`publish-drafts`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount){let t=Array.isArray(e.failed)?e.failed:[],n=t.find(e=>e?.code!==`batch_aborted`&&e?.error);throw t.some(e=>e?.code===`batch_aborted`)?Error(W(`engine.packages.detail.publishDraftsRolledBack`,o,{cause:n?`${n.type??`?`}/${n.name??`?`}: ${n.error}`:String(e.failedCount)})):Error(W(`engine.packages.detail.publishDraftsPartial`,o,{published:e.publishedCount??0,failed:e.failedCount}))}return e}),G(`engine.packages.detail.publishDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(ze,{className:`mr-1.5 h-3.5 w-3.5`}),s===`publish-drafts`?G(`engine.packages.detail.publishing`,o):W(`engine.packages.detail.publishApp`,o,{count:d.length})]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`discard-drafts`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(W(`engine.packages.detail.discardDraftsPartial`,o,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.discardDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),s===`discard-drafts`?G(`engine.packages.detail.discarding`,o):W(`engine.packages.detail.discardChanges`,o,{count:d.length})]})]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:d.map(e=>t?(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`):(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]},`${e.type}/${e.name}`))})]})]}),(0,Y.jsx)(bt,{className:`my-4`}),y?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.detail.kernelReadOnly`,o)}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.packages.detail.actions`,o)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>g(!0),disabled:!!s,children:[(0,Y.jsx)(N,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.viewInfo`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>m(!0),disabled:!!s,children:[(0,Y.jsx)(Rr,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.edit`,o)]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>b(`publish`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?W(`engine.packages.detail.publishBlocked`,o,{count:t}):e.validationErrors?.[0]?.message||G(`engine.packages.detail.nothingToPublish`,o))}return e}),G(`engine.packages.detail.published`,o)),disabled:!!s,children:[(0,Y.jsx)(ze,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`revert`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,o)),disabled:!!s,children:[(0,Y.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`toggle`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/${v?`disable`:`enable`}`,{method:`PATCH`}),G(v?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,o)),disabled:!!s,children:[v?(0,Y.jsx)(ur,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Y.jsx)(Mr,{className:`mr-1.5 h-3.5 w-3.5`}),G(v?`engine.packages.detail.disable`:`engine.packages.detail.enable`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`export`,async()=>{let e=await Gs(`${Ws}/${encodeURIComponent(_)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${_}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},G(`engine.packages.detail.exported`,o)),disabled:!!s,children:[(0,Y.jsx)(dn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{let t=window.prompt(G(`engine.packages.detail.duplicatePrompt`,o),`${_}-copy`);if(!(!t||!t.trim())){c(`duplicate`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({targetPackageId:t.trim(),targetName:`${e?.manifest.name??_} (copy)`})}),u({kind:`ok`,text:G(`engine.packages.detail.duplicated`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Duplicate failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(Pn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`duplicate`?`engine.packages.detail.duplicating`:`engine.packages.detail.duplicate`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(W(`engine.packages.detail.adoptConfirm`,o,{name:e?.manifest.name||_}))){c(`adopt`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}/adopt-orphans`,{method:`POST`}),u({kind:`ok`,text:G(`engine.packages.detail.adopted`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Adopt failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(br,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`adopt`?`engine.packages.detail.adopting`:`engine.packages.detail.adoptOrphans`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{if(!window.confirm(W(`engine.packages.detail.deleteConfirm`,o,{name:e?.manifest.name||_})))return;let t=window.confirm(G(`engine.packages.detail.deleteKeepData`,o))?``:`?keepData=true`;c(`delete`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}${t}`,{method:`DELETE`}),a(),i(!1)}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.deleteFailed`,o)})}finally{c(null)}},disabled:!!s,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,Y.jsx)(Tn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,o)]})]})]}),l&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text}),(0,Y.jsx)(Xs,{pkg:e,open:p,onOpenChange:m,onSaved:()=>{u({kind:`ok`,text:G(`engine.packages.edit.saved`,o)}),a()}}),(0,Y.jsx)(Us,{mode:`view`,open:h,onOpenChange:g,manifest:e?.manifest??null})]})})}function Qs(){let e=Ti(),{pathname:t}=r(),n=X.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[i,a]=X.useState([]),[o,s]=X.useState(!0),[c,l]=X.useState(null),[u,d]=X.useState(``),[f,p]=X.useState(!1),[m,h]=X.useState(!1),[g,_]=X.useState(null),[v,y]=X.useState(!1),b=X.useRef(null),[x,S]=X.useState(!1),[C,w]=X.useState(null),T=X.useCallback(async()=>{s(!0),l(null);try{let e=await Gs(Ws),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),a(t)}catch(t){l(t?.message??G(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);X.useEffect(()=>{T()},[T]),X.useEffect(()=>{if(!g)return;let e=i.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[i,g]);let E=X.useMemo(()=>{let e=u.trim().toLowerCase();return i.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:!e||t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e))},[i,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(G(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(G(`engine.packages.import.invalidPackage`,e));let i=await Gs(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})});w({kind:`ok`,text:W(`engine.packages.import.success`,e,{id:i?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??G(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=i.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,Y.jsx)(Kr,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:G(`engine.packages.title`,e)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.description`,e)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,Y.jsx)(qt,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),G(`engine.packages.refresh`,e)]}),(0,Y.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,Y.jsx)(Lt,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>h(!0),children:[(0,Y.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.new`,e)]})]})]}),C&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${C.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:C.text}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Mt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,Y.jsx)(U,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:W(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,Y.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,Y.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,Y.jsx)(Te,{className:`h-10 w-full`},e))}):c?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:c})]}):E.length===0?(0,Y.jsx)(`div`,{className:`p-8`,children:(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:G(`engine.packages.empty`,e)}),(0,Y.jsx)(ht,{children:i.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,Y.jsxs)(ni,{children:[(0,Y.jsx)(fe,{children:(0,Y.jsxs)(Xr,{children:[(0,Y.jsx)(Dt,{children:G(`engine.packages.col.name`,e)}),(0,Y.jsx)(Dt,{children:`ID`}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,Y.jsx)(_n,{children:E.map(e=>(0,Y.jsxs)(Xr,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,Y.jsx)($r,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Y.jsx)($r,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Y.jsx)($r,{children:e.manifest.version||`—`}),(0,Y.jsx)($r,{children:(0,Y.jsx)(Ks,{scope:e.manifest.scope})}),(0,Y.jsx)($r,{children:(0,Y.jsx)(qs,{pkg:e})})]},e.manifest.id))})]})}),(0,Y.jsx)(Js,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,Y.jsx)(Zs,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var $s=new Set([`field`,`package`]),ec={data:ir,ui:ln,automation:Ye,ai:Et,system:tt,platform:tt,identity:P,security:P},tc={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},nc=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],rc=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],ic={object:Sn,dashboard:Gn,page:Oe,report:Nr,record:xn,metadata:ln};function ac(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function oc(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function sc(){let e=Ai(),{loading:t,entries:r}=Mi(e),{recentItems:i}=fi(),a=Ti(),[s,c]=o(),[l,u]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;u(bs(n))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=s.get(`package`),f=X.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);X.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(s);e.set(`package`,l[0].id),c(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Di(e,`warning`,f??void 0),b=X.useMemo(()=>r.filter(e=>$s.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,r,v]),x=X.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=X.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(nc.indexOf(e)===-1?99:nc.indexOf(e))-(nc.indexOf(t)===-1?99:nc.indexOf(t)))},[b,_]),C=X.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return rc.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:G(`engine.home.loading`,a)}):(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,Y.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`max-w-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,Y.jsx)(Et,{className:`h-4 w-4`}),G(ac(),a)]}),(0,Y.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:G(`engine.home.subtitle`,a)}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Y.jsx)(L,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,Y.jsxs)(n,{to:m,children:[(0,Y.jsx)(ln,{className:`mr-1.5 h-4 w-4`}),G(`engine.home.browseAll`,a)]})}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white/90 backdrop-blur-sm`,children:[(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`}),G(`engine.directory.quickFind`,a),` ⌘⇧M`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsx)(cc,{value:b.length,label:G(`engine.home.statTypes`,a)}),(0,Y.jsx)(cc,{value:x.length,label:G(`engine.home.statWritable`,a)}),(0,Y.jsx)(cc,{value:l.length,label:G(`engine.home.statPackages`,a)})]})]})]}),(0,Y.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Y.jsx)(lc,{icon:ln,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,a),to_link:m}),(0,Y.jsx)(lc,{icon:Ce,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,a),to_link:m}),(0,Y.jsx)(lc,{icon:Kr,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:G(`engine.home.statPackages`,a),to_link:h}),(0,Y.jsxs)(n,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,Y.jsx)(Ce,{className:`h-5 w-5`}):(0,Y.jsx)(R,{className:`h-5 w-5`})}),(0,Y.jsx)(qr,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?G(`engine.home.allHealthy`,a):w}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,a)})]})]})]}),C.length>0&&(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(uc,{icon:H,title:G(`engine.home.quickActions`,a),hint:G(`engine.home.quickActionsHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,Y.jsx)(L,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-transparent bg-muted hover:bg-primary/10 hover:text-primary`,children:(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),W(`engine.home.newItem`,a,{label:wi(e.type,a,e.label)})]})},e.type))})]}),(0,Y.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,Y.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,Y.jsx)(uc,{icon:ln,title:G(`engine.home.explore`,a),hint:G(`engine.home.exploreHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,Y.jsx)(dc,{domain:e,group:t,countsByType:_,locale:a,packageSuffix:p},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(uc,{icon:gn,title:G(`engine.home.recent`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:i.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:G(`engine.home.recentEmpty`,a)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:i.slice(0,8).map(e=>{let t=ic[e.type]??xn;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,Y.jsx)(t,{className:`h-4 w-4`})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:oc(e.visitedAt,a)})]}),(0,Y.jsx)(qr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(vs,{})]})}function cc({value:e,label:t}){return(0,Y.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function lc({icon:e,from:t,to:r,value:i,label:a,to_link:o}){return(0,Y.jsxs)(n,{to:o,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${r} text-white shadow-sm`,children:(0,Y.jsx)(e,{className:`h-5 w-5`})}),(0,Y.jsx)(qr,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:i}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:a})]})]})}function uc({icon:e,title:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,Y.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,Y.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function dc({domain:e,group:t,countsByType:r,locale:i,packageSuffix:a}){let o=ec[e]??xn,s=tc[e]??tc.other,c=t.slice(0,6),l=t.length-c.length;return(0,Y.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${s.ring}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${s.from} ${s.to} text-white shadow-sm`,children:(0,Y.jsx)(o,{className:`h-[18px] w-[18px]`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ei(e,i)}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,G(`engine.home.typesLower`,i)]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[c.map(e=>(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}${a}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:wi(e.type,i,e.label)}),(0,Y.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:r[e.type]??0})]},e.type)),l>0&&(0,Y.jsxs)(n,{to:`metadata${a}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${s.text} hover:underline`,children:[`+`,l]})]})]})}function fc({entry:e,itemName:t,subtitle:i,stats:a,actions:o,embedded:s=!1,children:c}){let l=e?.type??``,u=Ti(),d=wi(l,u,e?.label),{pathname:f}=r(),p=X.useMemo(()=>{let e=f.indexOf(`/metadata`);return e>=0?f.slice(0,e+9):`/metadata`},[f]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[s?(0,Y.jsx)(`span`,{className:`shrink-0`,children:d}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(n,{to:p,className:`hover:text-foreground shrink-0`,children:G(`engine.breadcrumb.allTypes`,u)}),(0,Y.jsx)(Vt,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(n,{to:`${p}/${encodeURIComponent(l)}`,className:`hover:text-foreground shrink-0`,children:d})]}),(0,Y.jsx)(Vt,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ei(e.domain,u)}),e?.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,u)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:G(`engine.badge.readOnly`,u)})]}),i&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:i}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),o]})]}):(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[!s&&(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,Y.jsx)(n,{to:p,className:`hover:text-foreground`,children:G(`engine.breadcrumb.allTypes`,u)}),(0,Y.jsx)(Vt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:d})]}),(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:d}),(0,Y.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:l}),e?.domain&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ei(e.domain,u)}),e?.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,u)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,u)})]}),i&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:i}),!i&&e?.description&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),o]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:c})]})}var pc={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function mc(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function hc({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=X.useState(null),[o,s]=X.useState({open:!1,params:[]}),[c,l]=X.useState({open:!1}),u=X.useMemo(()=>d(),[]),f=X.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(f.length===0)return null;let p=(e,t)=>new Promise(n=>{s({open:!0,params:e,title:t,resolve:n})}),m=async e=>{let t=e.label??e.name;if(e.type!==`api`){si.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i;if(Array.isArray(e.params)&&e.params.length>0){let n=await p(e.params,t);if(n==null)return;i=n}else i=e.params??{};let o={recordId:n,origin:window.location.origin},s=mc(e.target??``,o,i);if(!s){si.error(`Action “${t}” has no target.`);return}let c=``.replace(/\/+$/,``),d=/^https?:\/\//i.test(s)?s:`${c}${s}`,f=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:f,headers:{"Content-Type":`application/json`},credentials:`include`};f!==`GET`&&f!==`DELETE`&&(n.body=JSON.stringify(i));let a=await u(d,n),o=null;try{o=await a.json()}catch{}if(!a.ok||o&&o.success===!1){let n=o?.error||o?.message||`HTTP ${a.status} ${a.statusText}`.trim();si.error(`${e.errorMessage?`${e.errorMessage}: `:``}${t}: ${n}`);return}if(e.resultDialog)l({open:!0,spec:e.resultDialog,data:o??{}});else{let n=e.successMessage||(typeof o?.message==`string`?o.message:`${t} ✓`);si.success(n)}e.refreshAfter&&r?.()}catch(e){si.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,Y.jsxs)(Y.Fragment,{children:[f.map(e=>{let t=e.icon?Si(e.icon):null,n=i===e.name;return(0,Y.jsxs)(L,{size:`sm`,variant:pc[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>m(e),title:e.label??e.name,children:[n?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,Y.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)}),(0,Y.jsx)(gi,{state:o,onOpenChange:e=>{e||(o.resolve?.(null),s({open:!1,params:[]}))}}),(0,Y.jsx)(hi,{state:c,onAcknowledge:()=>l({open:!1})})]})}function gc(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var _c=new Map;function vc(e){let t=_c.get(e.type);if(!t){_c.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);_c.set(e.type,n)}function yc(e){return _c.get(e)}function bc(e){let t=[];for(let n of _c.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function xc(e,t){let n=_c.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Sc(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function Cc({type:e}){let t=s(),n=e??t.type??``;if(n===`package`)return(0,Y.jsx)(l,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let r=yc(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(wc,{type:n,appName:t.appName})}function wc({type:e,appName:t}){let r=i(),a=Ai(),{entries:s}=Mi(a),c=s.find(t=>t.type===e),l=xc(e,c),[u,d]=X.useState([]),[f,p]=X.useState(!0),[m,h]=X.useState(null),[g,_]=X.useState(``),[v,y]=X.useState(`all`),[b,x]=o(),[S,C]=X.useState(0),[w,T]=X.useState(null);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`package`);if(e)return;T(bs(t))}catch{e||T([])}})(),()=>{e=!0}},[a]);let[E,D]=X.useState(null);X.useEffect(()=>{let e=!1;if(!t){D(null);return}return(async()=>{try{let n=await a.list(`app`);if(e)return;let r=(n??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).find(e=>e?.name===t||e?._packageId===t);D(r?._packageId??null)}catch{e||D(null)}})(),()=>{e=!0}},[a,t]);let O=b.get(`package`),k=X.useMemo(()=>{if(!w)return null;if(O&&w.some(e=>e.id===O))return O;if(w.length===0)return null;if(E&&w.some(e=>e.id===E))return E;let e=new Map;for(let t of u){let n=t.item?._packageId;n&&n!==`sys_metadata`&&e.set(n,(e.get(n)??0)+1)}let t=null,n=0;for(let r of w){let i=e.get(r.id)??0;i>n&&(t=r.id,n=i)}return t??w[0]?.id??null},[w,O,u,E]);X.useEffect(()=>{if(!w||w.length===0||O&&w.some(e=>e.id===O)||!(E&&w.some(e=>e.id===E))&&u.length===0||!k)return;let e=new URLSearchParams(b);e.set(`package`,k),x(e,{replace:!0})},[w,O,u,k,E]);let A=k?`?package=${encodeURIComponent(k)}`:``,[ee,j]=X.useState(!1),te=X.useCallback(()=>{let e=w??[];if(w!==null&&e.length===0){j(!0);return}if(e.length>0&&!k){r(`./new?package=${encodeURIComponent(e[0].id)}`);return}r(`./new${A}`)},[w,k,A,r]);X.useEffect(()=>{let t=!1;return p(!0),h(null),(async()=>{try{let n=await a.list(e);if(t)return;let r=(n??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Sc(t,e?.source),diagnostics:n}});d(r),p(!1)}catch(e){t||(h(e?.message??String(e)),p(!1))}})(),()=>{t=!0}},[a,e,S]);let ne=l.searchableFields??[`name`,`label`,`description`],M=X.useMemo(()=>u.filter(e=>l.listFilter&&!l.listFilter(e.item)||!k?!1:e.item?._packageId===k),[u,k,l]),re=M.filter(e=>!(!Oi(e.item,g,ne)||v!==`all`&&e.source!==v)),N=X.useMemo(()=>{let e={all:M.length,artifact:0,runtime:0};for(let t of M)e[t.source]++;return e},[M]),ie=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[M]),ae=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[M]),se=l.listColumns??Tc(l.primaryKey??`name`),P=Ti(),ce=wi(e,P,c?.label??e),le=e=>{let t=`engine.list.col.${e.key}`,n=G(t,P);return n===t?e.label:n};return(0,Y.jsx)(fc,{entry:c??{type:e,label:e},stats:[{label:G(`engine.list.items`,P),value:M.length},{label:G(`engine.list.filtered`,P),value:re.length},...ie>0?[{label:G(`engine.list.invalid`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(R,{className:`w-3.5 h-3.5`}),ie]})}]:[],...ae>0?[{label:G(`engine.list.warnings`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(R,{className:`w-3.5 h-3.5`}),ae]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(hc,{entry:c,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,P),children:(0,Y.jsx)(qt,{className:`h-4 w-4`})}),(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsxs)(L,{size:`sm`,variant:l.createFields?`default`:`outline`,onClick:te,title:l.createFields?W(`engine.list.createHint`,P,{type:ce}):void 0,children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,P)]})]}),children:(0,Y.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Y.jsx)(Js,{open:ee,onOpenChange:j,onCreated:e=>r(`./new?package=${encodeURIComponent(e)}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.list.search`,P),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(oe,{value:v,onValueChange:y,children:[(0,Y.jsx)(fr,{className:`w-[180px]`,children:(0,Y.jsx)(Dr,{})}),(0,Y.jsxs)(En,{children:[(0,Y.jsxs)(Pr,{value:`all`,children:[G(`engine.list.allSources`,P),` (`,N.all,`)`]}),(0,Y.jsxs)(Pr,{value:`artifact`,children:[G(`engine.list.source.artifact`,P),` (`,N.artifact,`)`]}),(0,Y.jsxs)(Pr,{value:`runtime`,children:[G(`engine.list.source.runtime`,P),` (`,N.runtime,`)`]})]})]})]}),(f||w===null)&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[G(`engine.edit.loading`,P),` `,e,`…`]}),m&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:m}),!f&&!m&&w!==null&&w.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No project packages installed`}),(0,Y.jsx)(ht,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!f&&!m&&w!==null&&w.length>0&&re.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:M.length===0?W(`engine.list.emptyType`,P,{type:ce}):W(`engine.list.emptyQuery`,P,{query:g})}),(0,Y.jsx)(ht,{children:l.emptyStateHint??(c?.allowOrgOverride||c?.allowRuntimeCreate?W(`engine.list.createHint`,P,{type:ce}):G(`engine.list.readOnlyHint`,P))}),M.length===0&&(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(L,{onClick:te,children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,P)]})})]}),!f&&re.length>0&&(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[se.map(e=>(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:le(e)},e.key)),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:G(`engine.list.col.source`,P)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:re.map((e,t)=>{let r=l.primaryKey??`name`,i=String(e.item[r]??`(unnamed-${t})`),a=e.item._packageId,o=a&&a!==`sys_metadata`?`?package=${encodeURIComponent(a)}`:A,s=e.diagnostics?.valid===!1,c=e.diagnostics?.errors??[],u=e.diagnostics?.warnings??[],d=!s&&u.length>0,f=s?c.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
2
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,d as r,f as i,g as a,h as o,m as s,r as c,s as l,y as u}from"./vendor-react-BKSb6vFP.js";import{h as d,p as f}from"./infrastructure-C6pQBkbt.js";import{B as p,M as m,Qt as h,T as g,Tt as _,W as v,Yt as y,dt as b,ft as x,j as S,ut as C}from"./framework-BqSgd3ir.js";import{C as w,E as T,J as E,S as D,c as O,g as k,l as A,u as ee,v as j,x as te,y as ne}from"./vendor-objectstack-CjHQG7Oa.js";import{$a as M,$n as re,$o as N,$r as ie,$s as ae,$t as oe,Ac as se,Ai as P,Ao as ce,Ar as le,Ba as ue,Bo as de,Co as F,Ct as fe,Dc as pe,Di as me,Do as he,Ec as ge,Ei as _e,Eo as ve,Es as ye,Fa as be,Fi as xe,Fr as Se,Fs as Ce,Gn as we,Gt as Te,Ha as Ee,Hn as De,Ho as Oe,Hr as ke,Hs as Ae,Ia as je,Ii as Me,Io as Ne,Ir as Pe,Ja as Fe,Ji as Ie,Jn as Le,Jo as Re,Jr as ze,Jt as Be,Ka as Ve,Ki as He,Kn as Ue,Ko as We,Kr as Ge,Ks as Ke,Li as qe,Lo as Je,Lr as Ye,Ma as Xe,Mc as I,Mo as Ze,Mr as Qe,Ms as $e,Na as et,Ni as tt,No as nt,Nr as rt,Ns as it,O as at,Oa as ot,Oi as st,Oo as ct,Or as L,Os as lt,Pa as ut,Pi as dt,Po as ft,Pr as pt,Ps as mt,Q as ht,Qa as gt,Qi as _t,Qn as vt,Qs as yt,Qt as bt,Ra as xt,Ri as St,Ro as Ct,Rs as wt,Sa as Tt,Si as Et,St as Dt,Ta as Ot,Ti as kt,To as At,Ts as jt,Tt as Mt,Ua as Nt,Ur as Pt,Us as Ft,Vi as It,Vo as Lt,Wi as Rt,Wn as zt,Wo as Bt,Ws as Vt,X as Ht,Xn as Ut,Xo as Wt,Xr as Gt,Xt as Kt,Yi as qt,Yr as Jt,Ys as Yt,Yt as Xt,Z as Zt,Zn as Qt,Zo as $t,Zr as R,Zs as en,Zt as tn,_a as nn,_i as rn,_t as an,aa as on,ac as sn,an as cn,ao as ln,ar as un,as as dn,at as fn,bc as pn,bi as mn,bo as hn,bs as gn,bt as _n,ca as vn,cc as yn,cs as bn,dc as xn,di as Sn,dn as Cn,ec as wn,ei as Tn,en as En,eo as Dn,er as On,es as kn,fa as An,fc as jn,fn as Mn,fo as Nn,fr as z,fs as Pn,ga as Fn,gs as In,gt as Ln,ha as Rn,hi as zn,ho as Bn,hs as Vn,ht as Hn,ia as Un,ii as Wn,io as Gn,ir as Kn,is as qn,jc as Jn,ji as Yn,jo as Xn,jr as Zn,k as Qn,ka as $n,kc as er,ko as tr,lc as nr,li as rr,ls as ir,ma as ar,mc as or,mi as sr,mn as B,ms as cr,mt as lr,na as ur,nc as dr,nn as fr,nr as pr,ns as mr,oc as hr,on as gr,oo as _r,os as vr,pn as yr,po as br,ps as xr,qa as V,qn as Sr,qs as Cr,qt as wr,ra as H,rc as Tr,ri as Er,rn as Dr,ro as Or,rr as kr,sn as Ar,so as jr,ta as Mr,tc as Nr,tn as Pr,tr as Fr,ts as Ir,tt as Lr,ua as Rr,uc as zr,ui as Br,uo as Vr,us as Hr,va as Ur,vn as U,vo as Wr,vt as Gr,wa as Kr,wc as qr,wi as Jr,ws as Yr,wt as Xr,xa as Zr,xc as Qr,xt as $r,yc as ei,yo as ti,yt as ni,za as ri,zc as ii,zi as ai,zs as oi}from"./ui-components-Ci5ufF7g.js";import{r as si}from"./vendor-ui-utils-D-WJ115h.js";import"./AdapterProvider-CqW7TSvk.js";import"./MetadataProvider-CjWp0ChY.js";import{n as ci,o as li}from"./assistantBus-CbDb2Mju.js";import{B as ui,H as di,L as fi,U as pi,a as mi,c as hi,l as gi,o as _i,s as vi,z as yi}from"./RecordDetailView-DpRJpP6t.js";import{f as bi}from"./plugin-chatbot-dJq9DS4J.js";import{n as xi}from"./ui-layout-D_8Fal4s.js";import{t as Si}from"./getIcon-BZn0biL3.js";import{a as Ci,i as wi,n as W,o as Ti,r as Ei,t as G}from"./i18n-SjY5NweX.js";import{a as Di,i as Oi,n as ki,o as Ai,r as ji,s as Mi,t as Ni}from"./createDerive-DGOUbVlZ.js";import{A as Pi,B as Fi,C as Ii,D as Li,E as K,F as Ri,G as zi,H as Bi,I as Vi,J as Hi,K as Ui,L as Wi,M as Gi,N as Ki,O as q,P as qi,R as Ji,S as Yi,T as Xi,U as Zi,V as Qi,W as $i,_ as ea,a as ta,b as na,c as ra,d as ia,f as aa,g as oa,h as sa,i as ca,j as la,k as ua,l as da,m as fa,n as pa,o as ma,p as ha,r as ga,s as _a,t as va,u as ya,v as ba,w as xa,x as J,y as Sa,z as Ca}from"./ReportDefaultInspector-BpXXGsGu.js";import{t as wa}from"./InterfaceListPage-BL7sW-SC.js";import{n as Ta}from"./plugins-views-BGSw-KmQ.js";import{r as Ea}from"./dist-B4b49_J4.js";var Y=c(),X=e(u(),1);function Da(){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_AI_BASE_URL;return t?t.replace(/\/$/,``):`${(e.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1/ai`}function Oa(){let{agents:e,isLoading:t}=bi({apiBase:Da()}),n=(0,X.useRef)(!1);t&&(n.current=!0);let r=e.length>0;return{enabled:r,isLoading:r?!1:t||!n.current}}var ka=`flow-palette-recents`,Aa=ka,ja=5;function Ma(){try{if(typeof localStorage>`u`)return[];let e=localStorage.getItem(Aa);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).slice(0,ja):[]}catch{return[]}}function Na(e){if(e)try{if(typeof localStorage>`u`)return;let t=[e,...Ma().filter(t=>t!==e)].slice(0,ja);localStorage.setItem(Aa,JSON.stringify(t))}catch{}}var Pa=ka;function Fa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).slice(0,5):[]}function Ia(e){try{let t=localStorage.getItem(ui(Pa,e));return t?Fa(JSON.parse(t)):[]}catch{return[]}}function La(e,t){try{localStorage.setItem(ui(Pa,t),JSON.stringify(e))}catch{}}function Ra(e,t){if(!t)return{list:e,didMigrate:!1};let n;try{n=localStorage.getItem(Pa)}catch{return{list:e,didMigrate:!1}}if(n==null)return{list:e,didMigrate:!1};let r=[];try{r=Fa(JSON.parse(n))}catch{}try{localStorage.removeItem(Pa)}catch{}if(r.length===0)return{list:e,didMigrate:!0};let i=[...e];for(let e of r)i.includes(e)||i.push(e);return{list:i.slice(0,5),didMigrate:!0}}var za=(0,X.createContext)(null);function Ba({children:e}){let{user:t}=f(),n=t?.id??null,r=pi(`flowPaletteRecents`),[i,a]=(0,X.useState)(()=>Ia(n));di(ui(Pa,n),e=>{a(Fa(e))});let o=(0,X.useMemo)(()=>yi(async e=>{r&&await r.save(e)},500),[r]);(0,X.useEffect)(()=>()=>void o.flush(),[o]);let s=(0,X.useCallback)(e=>{La(e,n),r&&o.schedule(e)},[n,r,o]),c=(0,X.useRef)(0);(0,X.useEffect)(()=>{let e=++c.current,t=!1;return(async()=>{let i=Ia(n),s=r?Fa(await r.load().catch(()=>[])):[];if(t||e!==c.current)return;let{list:l,didMigrate:u}=Ra(s.length?s:i,n);a(l),La(l,n),u&&r&&o.schedule(l)})(),()=>{t=!0}},[r,n,o]);let l=(0,X.useCallback)(e=>{e&&a(t=>{let n=[e,...t.filter(t=>t!==e)].slice(0,5);return s(n),n})},[s]),u=(0,X.useMemo)(()=>({recents:i,recordRecent:l}),[i,l]);return(0,Y.jsx)(za.Provider,{value:u,children:e})}function Va(){let e=(0,X.useContext)(za),[t,n]=(0,X.useState)(()=>Ma()),r=(0,X.useCallback)(e=>{Na(e),n(Ma())},[]);return e||{recents:t,recordRecent:r}}function Ha(e,t){if(!t)return!0;let n=t.toLowerCase();return e.value.toLowerCase().includes(n)||e.label.toLowerCase().includes(n)||(e.group?.toLowerCase().includes(n)??!1)}function Ua({label:e,value:t,onCommit:n,options:r,placeholder:i=`Select…`,searchPlaceholder:a=`Search or type…`,emptyText:o=`No match — keep typing to use a custom value.`,disabled:s,loading:c,allowCustom:l=!0,mono:u,className:d}){let[f,p]=X.useState(!1),[m,h]=X.useState(``),g=r.find(e=>e.value===t),_=g?g.label:t||(c?`Loading…`:i),v=X.useMemo(()=>r.filter(e=>Ha(e,m)),[r,m]),y=X.useMemo(()=>{let e=[],t=new Map;for(let n of v){let r=n.group??``;t.has(r)||(t.set(r,[]),e.push(r)),t.get(r).push(n)}return e.map(e=>({heading:e,items:t.get(e)}))},[v]),b=m.trim(),x=l&&!!b&&!r.some(e=>e.value===b),S=e=>{n(e),p(!1),h(``)},C=(0,Y.jsxs)(Cn,{open:f,onOpenChange:e=>{p(e),e||h(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":f,disabled:s,className:I(`h-8 w-full justify-between px-2 text-sm font-normal`,d),children:[(0,Y.jsx)(`span`,{className:I(`truncate`,u&&`font-mono`,!g&&!t&&`text-muted-foreground`),children:_}),(0,Y.jsx)(oi,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,Y.jsx)(Mn,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,Y.jsxs)(De,{shouldFilter:!1,children:[(0,Y.jsx)(Ue,{value:m,onValueChange:h,placeholder:a}),(0,Y.jsxs)(Le,{children:[!x&&v.length===0&&(0,Y.jsx)(zt,{children:o}),x&&(0,Y.jsx)(we,{children:(0,Y.jsx)(Sr,{value:`__custom__${b}`,onSelect:()=>S(b),children:(0,Y.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`“`,b,`”`]})]})})}),y.map((e,n)=>(0,Y.jsx)(we,{heading:e.heading||void 0,children:e.items.map(e=>(0,Y.jsxs)(Sr,{value:e.value,onSelect:()=>S(e.value),children:[(0,Y.jsx)(Cr,{className:I(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,Y.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,Y.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),C]}):C}var Wa=[`object`,`page`,`dashboard`,`report`,`url`,`group`],Ga=[`default`,`view`,`record`,`filters`],Ka={object:{targetKey:`objectName`,metaType:`object`},page:{targetKey:`pageName`,metaType:`page`},dashboard:{targetKey:`dashboardName`,metaType:`dashboard`},report:{targetKey:`reportName`,metaType:`report`},url:{targetKey:`url`},group:{}};function qa(e){return(e.pageType??e.type)!==`record`}var Ja=[`objectName`,`viewName`,`recordId`,`recordMode`,`filters`,`pageName`,`dashboardName`,`reportName`,`url`,`target`,`params`],Ya=[`path`,`kind`,`href`,`route`,`object`,`page`,`dashboard`,`report`],Xa={object:`object`,page:`page`,dashboard:`dashboard`,report:`report`,link:`url`,url:`url`,group:`group`};function Za(e){let t=e.type;if(typeof t==`string`&&Wa.includes(t))return t;let n=e.kind;if(typeof n==`string`&&Xa[n])return Xa[n];if(e.objectName||e.object)return`object`;if(e.pageName||e.page)return`page`;if(e.dashboardName||e.dashboard)return`dashboard`;if(e.reportName||e.report)return`report`;if(e.url||e.href)return`url`;if(Array.isArray(e.children)&&e.children.length>0)return`group`;let r=e.path;return typeof r==`string`&&/^https?:/i.test(r)?`url`:null}function Qa(e){if(e.recordId)return`record`;let t=e.filters;return t&&typeof t==`object`&&!Array.isArray(t)?`filters`:e.viewName?`view`:`default`}function $a(e=[]){let t={};for(let n of[...Ja,...Ya])e.includes(n)||(t[n]=void 0);return t}var eo={default:[`objectName`],view:[`objectName`,`viewName`],record:[`objectName`,`recordId`,`recordMode`],filters:[`objectName`,`filters`]};function to(e,t,n){let r=e.id;if(typeof r==`string`&&r)return r;let i=`nav_${(n??String(e.objectName??e.label??`item`)).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)||`item`}`,a=new Set(t.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean));if(!a.has(i))return i;let o=2;for(;a.has(`${i}_${o}`);)o++;return`${i}_${o}`}var no=[`nav`,`navigation`,`tabs`,`items`,`menu`];function ro(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function io(e,t){let n=e[t[0].key];if(!Array.isArray(n))return{parent:[],node:null,index:-1};let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r)return{parent:n,node:null,index:t[e].index};if(n=r[t[e].key],!Array.isArray(n))return{parent:[],node:null,index:-1};r=n[t[e].index]??null}return{parent:n,node:r,index:t[t.length-1].index}}function ao(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:la(i,t[0].index,n)};let a=i,o=[];for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}};o.push({arr:a,index:t[e].index,node:n});let r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let s=la(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function oo(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function so(e,t){let n=Ai(),[r,i]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){i({options:[],loading:!1});return}let r=!1;return i(e=>({...e,loading:!0})),n.list(e).then(e=>{if(r)return;let n=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).filter(e=>!t||t(e)).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));i({options:n,loading:!1})}).catch(()=>{r||i({options:[],loading:!1})}),()=>{r=!0}},[n,e,t]),r}var co={currentUserId:`{current_user_id}`,currentOrgId:`{current_org_id}`};function lo({objectName:e,filters:t,onCommit:n,disabled:r,locale:i}){let{fields:a}=Ki(e||void 0),o=X.useMemo(()=>a.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]),s=Object.entries(t),c=(e,t,r)=>{let i=s.slice();i[e]=[t,r],n(Object.fromEntries(i.filter(([e])=>e!==``)))},l=e=>{let t=s.slice();t.splice(e,1),n(Object.fromEntries(t))};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:G(`engine.inspector.appNav.filters`,i)}),s.map(([e,t],n)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ua,{value:e,onCommit:e=>c(n,e,t),options:o,placeholder:G(`engine.inspector.appNav.filtersField`,i),disabled:r,mono:!0})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`=`}),(0,Y.jsx)(`input`,{value:t,onChange:t=>c(n,e,t.target.value),placeholder:G(`engine.inspector.appNav.filtersValue`,i),disabled:r,className:`h-7 w-0 min-w-0 flex-1 rounded border bg-background px-2 font-mono text-xs`,"data-testid":`nav-filter-value-${e||`new`}`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(n),disabled:r,className:`rounded p-1 text-muted-foreground hover:bg-muted`,"aria-label":G(`engine.inspector.appNav.filtersRemove`,i),"data-testid":`nav-filter-remove-${e||`new`}`,children:(0,Y.jsx)(Se,{className:`h-3 w-3`})})]},`${e}-${n}`)),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n({...t,"":``}),disabled:r||Object.prototype.hasOwnProperty.call(t,``),className:`inline-flex items-center gap-1 rounded border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,"data-testid":`nav-filter-add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`engine.inspector.appNav.filtersAdd`,i)]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.appNav.filtersHint`,i)})]})}function uo({selection:e,draft:t,name:n,onPatch:r,onClearSelection:i,onSelectionChange:a,locale:o,readOnly:s}){let c=ro(e.id),{node:l,parent:u,index:d}=c?io(t,c):{node:null,parent:[],index:-1},f=l?Za(l):null,p=l?Qa(l):`default`,m=String(l?.objectName??l?.object??``),h=so(f===`object`?`object`:void 0),g=f&&f!==`object`?Ka[f].metaType:void 0,_=so(g,g===`page`?qa:void 0),v=so(f===`object`&&p===`view`?`view`:void 0),y=X.useMemo(()=>m?v.options.filter(e=>e.value.startsWith(`${m}.`)||!e.value.includes(`.`)):v.options,[v.options,m]);if(!c||!l)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.appNav.kind`,o),title:e.label??e.id,onClose:i,closeLabel:G(`engine.inspector.appNav.close`,o),children:(0,Y.jsx)(Yi,{message:e.id})});let b=l.label??l.title??l.name??e.id,x=e=>{let n=e.type??l.type??f??void 0;r(ao(t,c,{...l,id:to(l,u),...n?{type:n}:{},...e}))},S=e=>{let t=Ka[e].targetKey,n=e===`object`?eo.default:t?[t]:[];x({type:e,...$a(n)})},C=e=>{let t=$a(eo[e]);x(e===`filters`?{...t,objectName:m,filters:l.filters??{}}:{...t,objectName:m})},w=()=>{r(ao(t,c,null)),i()},T=e=>{let n=Pi(u,d,e);r(oo(t,c,n));let i=c.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),o=c[c.length-1].key,s=i?`${i}.${o}[${e}]`:`${o}[${e}]`;a?.({kind:`nav`,id:s,label:String(b)})},E=f&&f!==`group`?xi({...l,type:f},`/apps/${n||`app`}`,co).href:null,D=Ka[f??`group`];return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.appNav.kind`,o),title:String(b),onClose:i,closeLabel:G(`engine.inspector.appNav.close`,o),headerActions:(0,Y.jsx)(Xi,{index:d,total:u.length,onMove:T,upLabel:G(`engine.inspector.reorder.up`,o),downLabel:G(`engine.inspector.reorder.down`,o),disabled:s}),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.appNav.remove`,o),onClick:w,disabled:s}),children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.label`,o),value:String(l.label??l.title??l.name??``),onCommit:e=>x({label:e}),disabled:s}),(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.icon`,o),value:String(l.icon??``),onCommit:e=>x({icon:e}),disabled:s}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.typeField`,o),value:f??``,options:Wa.map(e=>({value:e,label:G(`engine.inspector.appNav.type.${e}`,o)})),onCommit:e=>S(e),disabled:s}),f===`object`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.object`,o),value:m,options:h.options,loading:h.loading,onCommit:e=>x({objectName:e,object:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.targetMode`,o),value:p,options:Ga.map(e=>({value:e,label:G(`engine.inspector.appNav.mode.${e}`,o)})),onCommit:e=>C(e),disabled:s||!m}),p===`view`&&(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.view`,o),value:String(l.viewName??``),options:y,loading:v.loading,onCommit:e=>x({viewName:e}),disabled:s,mono:!0}),p===`record`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.recordId`,o),value:String(l.recordId??``),onCommit:e=>x({recordId:e}),disabled:s,mono:!0}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.appNav.recordIdHint`,o)}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.recordMode`,o),value:String(l.recordMode??`view`),options:[{value:`view`,label:G(`engine.inspector.appNav.recordModeView`,o)},{value:`edit`,label:G(`engine.inspector.appNav.recordModeEdit`,o)}],onCommit:e=>x({recordMode:e}),disabled:s})]}),p===`filters`&&(0,Y.jsx)(lo,{objectName:m,filters:l.filters??{},onCommit:e=>x({filters:e}),disabled:s,locale:o})]}),f&&f!==`object`&&f!==`group`&&D.targetKey&&(D.metaType?(0,Y.jsx)(Ua,{label:G(`engine.inspector.appNav.type.${f}`,o),value:String(l[D.targetKey]??``),options:_.options,loading:_.loading,onCommit:e=>x({[D.targetKey]:e}),disabled:s,mono:!0}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(q,{label:G(`engine.inspector.appNav.url`,o),value:String(l.url??l.href??``),onCommit:e=>x({url:e,href:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(K,{label:G(`engine.inspector.appNav.urlTarget`,o),value:String(l.target??`_self`),options:[{value:`_self`,label:G(`engine.inspector.appNav.urlTargetSelf`,o)},{value:`_blank`,label:G(`engine.inspector.appNav.urlTargetBlank`,o)}],onCommit:e=>x({target:e}),disabled:s})]})),E&&(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 px-2 py-1.5`,"data-testid":`nav-target-preview`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.appNav.preview`,o)}),(0,Y.jsx)(`div`,{className:`break-all font-mono text-[11px]`,children:E})]})]})}var fo=no;function po(e){if(!e||!e.startsWith(`nav:`))return null;let t=e.slice(4);return t.length>0?t:null}function mo(e){return`nav:${e}`}var ho=`surface`;function go(e){return`${e.type}:${e.name}`}function _o(e){if(!e)return null;let t=e.indexOf(`:`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n&&r?{type:n,name:r}:null}function vo(e,t){let n=(e,r)=>{for(let i=0;i<e.length;i++){let a=e[i];if(!a||typeof a!=`object`)continue;let o=`${r}[${i}]`;if(a.id===t){let e=a.label??a.title??a.name;return{selectionId:o,label:typeof e==`string`?e:void 0}}if(Array.isArray(a.children)){let e=n(a.children,`${o}.children`);if(e)return e}}return null};for(let t of fo){let r=e[t];if(!Array.isArray(r))continue;let i=n(r,t);if(i)return i}return null}function yo(e,t){let n=t.split(`.`),r;for(let t=0;t<n.length;t++){let i=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(n[t]);if(!i)return null;let a=i[1],o=Number(i[2]),s=t===0?e[a]:r?.[a];if(!Array.isArray(s)||(r=s[o],!r||typeof r!=`object`))return null}return typeof r?.id==`string`&&r.id?r.id:null}var bo=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function xo(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function So(e){let t=e.reference??e.reference_to??e.referenceTo??e.reference_to_object;if(typeof t==`string`&&t)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0];if(t&&typeof t==`object`){let e=t.object;if(typeof e==`string`&&e)return e}}function Co(e){switch(e){case`lookup`:case`master_detail`:case`masterDetail`:case`master-detail`:return`lookup`;case`date`:case`datetime`:case`time`:return`date`;case`number`:case`currency`:case`percent`:case`int`:case`integer`:case`float`:case`double`:case`autonumber`:return`number`;case`boolean`:case`toggle`:return`boolean`;default:return`string`}}function wo(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=xo(e.label,t),r=Qi(e.fields).entries.map(e=>({name:e.name,label:xo(e.def.label,e.name),type:typeof e.def.type==`string`?e.def.type:void 0,def:e.def}));return{label:n,fields:r,relationships:r.filter(e=>e.type&&bo.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:So(e.def)}))}}function To(e,t,n){let r=e,i=[];for(let e of t.split(`.`)){let t=r.relationships.find(t=>t.name===e);if(!t?.referenceTo)return;let a=n[t.referenceTo];if(!a)return;i.push(t.label),r=a}return{target:r,labels:i}}function Eo(e,t,n){let r=e.fields.map(t=>({value:t.name,label:t.label,type:t.type,group:e.label}));for(let i of t){let t=To(e,i,n);if(!t)continue;let a=[...t.labels,t.target.label].join(` → `);for(let e of t.target.fields)r.push({value:`${i}.${e.name}`,label:e.label,type:e.type,group:a})}return r}function Do(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Do(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t||Object.values(n).some(e=>e&&typeof e==`object`&&Do(e,t))}function Oo(){let e=Ai(),[t,n]=X.useState({options:[],loading:!0});return X.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{if(t)return;let r=(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:xo(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label));n({options:r,loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function ko(e,t){let n=Ai(),r=t.join(`\0`),[i,a]=X.useState({relationships:[],fieldOptions:[],loading:!!e});return X.useEffect(()=>{if(!e){a({relationships:[],fieldOptions:[],loading:!1});return}let t=!1;return a(e=>({...e,loading:!0})),(async()=>{try{let i=await n.get(`object`,e);if(t)return;let o=wo(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=wo(await n.get(`object`,e),e)}catch{t=wo(null,e)}return c[e]=t,t};for(let e of s){let t=o;for(let n of e.split(`.`)){let e=t.relationships.find(e=>e.name===n);if(!e?.referenceTo)break;t=await l(e.referenceTo)}}if(t)return;let u=[...o.relationships];for(let e of s){if(e.split(`.`).length>=3)continue;let t=To(o,e,c);if(t)for(let n of t.target.relationships)u.push({name:`${e}.${n.name}`,label:`${e}.${n.name}`,referenceTo:n.referenceTo})}a({relationships:u,fieldOptions:Eo(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Ao(e){let t=Ai(),[n,r]=X.useState({reports:0,dashboards:0,loading:!!e});return X.useEffect(()=>{if(!e){r({reports:0,dashboards:0,loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),(async()=>{let[i,a]=await Promise.all([t.list(`report`).catch(()=>[]),t.list(`dashboard`).catch(()=>[])]);n||r({reports:(Array.isArray(i)?i:[]).filter(t=>Do(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Do(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}function jo(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function Mo(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function No(e){let t=new Set;for(let n of e){let e=Mo(n);e&&t.add(e)}return t}function Po(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Fo(e,t){return e===t?null:e>t?e-1:e}function Io(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Lo({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=Ki(i||void 0,a),m=X.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=X.useState(null),[_,v]=X.useState(null),y=X.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=X.useCallback(t=>{let i=ua(n,Po(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),x=X.useCallback(t=>{let r=la(n,t,null);if(y(r),o!=null){let n=Fo(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:jo(r[n],n)})}},[n,y,o,e,l]),S=X.useCallback((t,r)=>{if(t===r)return;let i=Pi(n,t,r);if(y(i),o!=null){let n=Io(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:jo(i[n],n)})}},[n,y,o,e,l]),C=X.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:jo(n[t],t)})},[n,e,l]),w=No(n);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Y.jsx)(_a,{index:t,label:jo(e,t),fieldName:Mo(e),fieldType:m.get(Mo(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>C(t),onRemove:()=>x(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&S(h,t),g(null),v(null)}},t))}),u&&(0,Y.jsx)(ma,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var Ro=[`record`,`current_user`,`user`,`features`,`app`,`data`,`ctx`];function zo(e){if(e==null)return`null`;let t=typeof e;return t===`string`?JSON.stringify(e):t===`number`||t===`boolean`?String(e):Array.isArray(e)?`[${e.map(zo).join(`, `)}]`:JSON.stringify(String(e))}function Bo(e){if(!e.field||!e.operator)return``;let t=`record[${JSON.stringify(e.field)}]`;switch(e.operator){case`equals`:return`${t} == ${zo(e.value)}`;case`not_equals`:return`${t} != ${zo(e.value)}`;case`greater_than`:return`${t} > ${zo(e.value)}`;case`less_than`:return`${t} < ${zo(e.value)}`;case`contains`:return`${t}.contains(${zo(e.value)})`;case`in`:return`${t} in ${zo(Array.isArray(e.value)?e.value:[e.value])}`;default:return``}}function Vo(e){return typeof e.condition==`string`?e.condition:e.condition&&typeof e.condition==`object`&&typeof e.condition.source==`string`?e.condition.source:typeof e.expression==`string`?e.expression:Bo(e)}function Ho(e){let t=Vo(e),n={};if(e.style&&typeof e.style==`object`)for(let[t,r]of Object.entries(e.style))r!=null&&(n[t]=String(r));return e.backgroundColor&&(n.backgroundColor=String(e.backgroundColor)),e.textColor&&(n.color=String(e.textColor)),e.borderColor&&(n.borderColor=String(e.borderColor)),{condition:t,style:n}}function Uo({label:e,value:t,onChange:n,disabled:r}){return(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`input`,{type:`color`,value:/^#([0-9a-f]{6})$/i.test(t)?t:`#000000`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 w-8 shrink-0 rounded border border-input bg-background p-0.5 disabled:opacity-60`,"aria-label":e}),(0,Y.jsx)(B,{value:t,placeholder:`#RRGGBB`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 text-xs font-mono`})]})]})}function Wo({rules:e,onChange:t,objectName:n,fieldNames:r,disabled:i,t:a}){let o=X.useMemo(()=>Array.isArray(e)?e.map(Ho):[],[e]),s=e=>t(e),c=(e,t)=>{let n=o.map((n,r)=>r===e?{...n,...t}:n);s(n)},l=(e,t,n)=>{let r={...o[e].style};n?r[t]=n:delete r[t],c(e,{style:r})},u=()=>s([...o,{condition:``,style:{}}]),d=e=>s(o.filter((t,n)=>n!==e)),f=(e,t)=>{let n=e+t;if(n<0||n>=o.length)return;let r=o.slice();[r[e],r[n]]=[r[n],r[e]],s(r)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,"data-testid":`cf-editor`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:a(`engine.inspector.view.cf.title`)}),(0,Y.jsxs)(L,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs`,disabled:i,onClick:u,"data-testid":`cf-add`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a(`engine.inspector.view.cf.add`)]})]}),o.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:a(`engine.inspector.view.cf.empty`)}),o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border p-2 space-y-2`,"data-testid":`cf-rule-${t}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[a(`engine.inspector.view.cf.rule`),` `,t+1]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===0,onClick:()=>f(t,-1),"aria-label":a(`engine.inspector.view.cf.moveUp`),"data-testid":`cf-up-${t}`,children:(0,Y.jsx)(Ft,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===o.length-1,onClick:()=>f(t,1),"aria-label":a(`engine.inspector.view.cf.moveDown`),"data-testid":`cf-down-${t}`,children:(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(L,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6 text-destructive hover:text-destructive`,disabled:i,onClick:()=>d(t),"aria-label":a(`engine.inspector.view.cf.remove`),"data-testid":`cf-remove-${t}`,children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(ea,{label:a(`engine.inspector.view.cf.when`),value:e.condition,disabled:i,placeholder:`record.status == 'overdue'`,objectName:n,fieldNames:r,scope:`flattened`,roots:Ro,onChange:e=>c(t,{condition:e}),t:a,id:`cf-condition-${t}`}),(0,Y.jsxs)(`div`,{className:I(`grid gap-2 sm:grid-cols-3`),children:[(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.background`),value:e.style.backgroundColor??``,disabled:i,onChange:e=>l(t,`backgroundColor`,e)}),(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.text`),value:e.style.color??``,disabled:i,onChange:e=>l(t,`color`,e)}),(0,Y.jsx)(Uo,{label:a(`engine.inspector.view.cf.border`),value:e.style.borderColor??``,disabled:i,onChange:e=>l(t,`borderColor`,e)})]}),(0,Y.jsx)(`div`,{className:`rounded border border-dashed border-border px-2 py-1 text-xs`,style:e.style,"data-testid":`cf-preview-${t}`,children:a(`engine.inspector.view.cf.preview`)})]},t))]})}var Go={io:`input`,unrepresentable:`any`},Ko=new Set([`columns`,`data`,`name`]),qo,Jo=!1;function Yo(){if(qo||Jo)return qo;try{qo=E(te,Go)}catch(e){Jo=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return qo}function Xo(){return Yo()?.properties?.list}function Zo(){return Yo()?.properties?.form}var Qo,$o=!1;function es(){if(Qo||$o)return Qo;try{Qo=E(j,Go)}catch(e){$o=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return Qo}var ts;function ns(){if(ts)return ts;if(!(!T||typeof T!=`object`)){try{let e=JSON.parse(JSON.stringify(T));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Ko.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),ts=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return ts}}var rs=new Set([`form`,`detail`]);function is(e){return rs.has(e)}function as(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function os(e,t){return typeof e==`string`&&rs.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&rs.has(t)?`form`:`list`}function ss(e){let t=e.config;return as(t)?[{storeKey:`config`,familyKey:os(e.viewKind,t.type),schema:t}]:[]}function cs(e){return ss(e)[0]}function ls(e,t){return cs(e)}function us({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){let{options:a,loading:o}=Oo();return(0,Y.jsx)(Ua,{label:e,value:t,onCommit:n,options:a.map(e=>({value:e.name,label:e.label})),loading:o,placeholder:r,searchPlaceholder:`Search objects…`,disabled:i,mono:!0})}var ds=new Set([`type`,`object`,`label`,`columns`,`conditionalFormatting`]),fs={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function ps(e,t){let n=`engine.inspector.view.type.${e}`,r=G(n,t);return r===n?fs[e]??e:r}var ms=[`columns`,`data`,`name`];function hs(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function gs(e,t){return X.useMemo(()=>{let n=Xo()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:ps(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:ps(e,t)}),r},[e,t])}function _s({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=is(n??t),p=typeof d.type==`string`?d.type:`grid`,m=gs(p,l),h=hs(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=Ki(h.value||void 0,c),b=X.useCallback(e=>G(e,l),[l]),x=X.useMemo(()=>y.map(e=>e.name),[y]),S=Array.isArray(d.conditionalFormatting)?d.conditionalFormatting:[],C=X.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),w=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:T,form:E}=X.useMemo(()=>ta({bundledSchema:f?Zo():Xo(),bundledForm:f?void 0:ns(),serverSchema:w,excludeFields:ds,sectionTitle:G(`engine.inspector.moreFields`,l)}),[f,w,l]),D=e=>{i({[t]:{...d,...e}})};return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:G(`engine.inspector.view.close`,l),hideClose:r,children:[(0,Y.jsx)(q,{label:G(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:G(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,Y.jsx)(K,{label:G(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>D({type:e}),disabled:a}),(0,Y.jsx)(us,{label:G(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:G(`engine.inspector.view.objectPlaceholder`,l),disabled:a}),!f&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Lo,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),!f&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Wo,{rules:S,objectName:h.value||void 0,fieldNames:x,disabled:a,t:b,onChange:e=>D({conditionalFormatting:e.length>0?e:void 0})})}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:T?(0,Y.jsx)(ha,{schema:T,form:E,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:C,onChange:e=>{let n={...e};for(let e of ms)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:G(`engine.inspector.view.noSchema`,l)})})]})}function vs({appSlug:e}={}){let t=i(),n=Ai(),{entries:r}=Mi(n),[a,o]=X.useState(!1),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),[p,m]=X.useState(0),h=Ti();X.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),o(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),X.useEffect(()=>{if(!a||l!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||u(t)}finally{e||f(!1)}})(),()=>{e=!0}},[a,l,d,r,n]);let g=X.useMemo(()=>{let e=s.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||wi(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(l??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[s,r,l]);X.useEffect(()=>{m(0)},[s,a]);function _(n){o(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,Y.jsx)(Ut,{open:a,onOpenChange:o,children:(0,Y.jsxs)(Qt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(On,{className:`sr-only`,children:(0,Y.jsx)(Fr,{children:G(`engine.quickfind.title`,h)})}),(0,Y.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(B,{autoFocus:!0,placeholder:G(`engine.quickfind.placeholder`,h),value:s,onChange:e=>c(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Y.jsx)(Ht,{children:`esc`})]}),(0,Y.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,Y.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),G(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:G(`engine.quickfind.noMatches`,h)}),(0,Y.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate`,children:wi(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,Y.jsx)(Ve,{className:`h-3 w-3`})}),e.name,e.label&&(0,Y.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})})]})},e.kind===`type`?`t:${e.entry.type}`:`i:${e.type}:${e.name}`))})]}),(0,Y.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Ht,{children:`↑`}),` `,(0,Y.jsx)(Ht,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Ht,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(Ht,{children:`⌘`}),(0,Y.jsx)(Ht,{children:`⇧`}),(0,Y.jsx)(Ht,{children:`M`}),` toggle`]})]})]})})}var ys=new Set([`system`,`cloud`]);function bs(e){let t=(e??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!ys.has(e.scope));return t.sort((e,t)=>e.name.localeCompare(t.name)),t.map(e=>({id:e.id,name:e.name}))}var xs={data:ir,ui:ln,automation:Ye,ai:Et,system:tt,platform:tt,identity:P,security:P},Ss=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Cs=new Set([`field`,`package`]);function ws(){let e=Ai(),{loading:t,error:r,entries:i}=Mi(e),a=Ti(),[s,c]=X.useState(``),[l,u]=X.useState(`all`),[d,f]=X.useState(!1),[p,m]=o(),[h,g]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;g(bs(n))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=X.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);X.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=Di(e,`warning`,v??void 0),E=X.useMemo(()=>i.filter(e=>Cs.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[i,v,w]),D=X.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(s){let t=s.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||wi(e.type,a,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=X.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=Ss.indexOf(e),r=Ss.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,Y.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:G(`engine.directory.loading`,a)}):r?(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[G(`engine.directory.loadFailed`,a),`: `,r]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:G(`engine.directory.title`,a)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:W(`engine.directory.description`,a,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.directory.search`,a),value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(L,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[G(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.total>0&&(0,Y.jsx)(L,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,Y.jsxs)(n,{to:`./_diagnostics`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5 mr-1`}),W(`engine.directory.diagnosticsLink`,a,{count:x.total})]})}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[G(`engine.directory.quickFind`,a),` `,(0,Y.jsx)(Ht,{children:`⌘`}),(0,Y.jsx)(Ht,{children:`⇧`}),(0,Y.jsx)(Ht,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(Ts,{domain:`all`,label:G(`engine.directory.all`,a),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),Ss.filter(e=>D[e]).map(e=>(0,Y.jsx)(Ts,{domain:e,label:Ei(e,a),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No project packages installed`}),(0,Y.jsx)(ht,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:G(`engine.directory.noMatches`,a)}),(0,Y.jsx)(ht,{children:G(`engine.directory.noMatchesHint`,a)})]}),A.map(([e,t])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,Y.jsx)(xs[e]??xn,{className:`h-3.5 w-3.5`}),Ei(e,a),` (`,t.length,`)`]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,Y.jsx)(Es,{entry:e,locale:a,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,Y.jsx)(vs,{})]})}function Ts({domain:e,label:t,active:n,count:r,onClick:i}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,Y.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Es({entry:e,locale:t,invalidCount:r=0,warnCount:i=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=wi(e.type,t,e.label);return(0,Y.jsxs)(n,{to:s?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(s)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(r>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[r>0&&(0,Y.jsx)(`span`,{title:W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),"aria-label":W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:(0,Y.jsx)(R,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),c]}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:W(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),r>0&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:W(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:r}),i>0&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:W(`engine.directory.warnTooltip`,t??`en`,{count:i}),children:i}),o>0&&(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${o} locked item${o===1?``:`s`} — see ADR-0010`,"aria-label":`${o} locked items`,children:[(0,Y.jsx)(Ve,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,t)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}function Ds(e){let t=e?.data??e,n=Array.isArray(t)?t:t?.packages??[],r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.manifest??{},n=String(t.id??e.id??``);if(!n)continue;let i=typeof t.scope==`string`?t.scope:``;if(i===`system`||i===`cloud`)continue;let a=typeof t.namespace==`string`&&t.namespace?t.namespace:A(n);r.push({id:n,name:String(t.name??n),writable:i!==`project`,namespace:a})}return r}async function Os(){let e=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);return Ds(await e.json())}async function ks(e,t,n){let r=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/duplicate`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({targetPackageId:t,...n?{targetName:n}:{}})}),i=await r.json().catch(()=>null);if(!r.ok||i?.success===!1)throw Error(i?.error?.message||`HTTP ${r.status}`)}var As=/^[a-z][a-z0-9_.-]*(\.[a-z0-9_-]+)+$/,js=/^[a-z][a-z0-9_]{1,19}$/;function Ms(e,t){return t&&ee(e,t)?`${t}_${e}`:e}function Ns(e){let t=e.toLowerCase().replace(/[^a-z0-9_.-]/g,``);return{value:t,stripped:t.length!==e.length}}var Ps={io:`input`,unrepresentable:`any`},Fs,Is=!1;function Ls(){if(Fs||Is)return Fs;try{Fs=E(O,Ps)}catch(e){Is=!0,typeof console<`u`&&console.warn(`[package-schema] failed to derive manifest JSONSchema from spec`,e)}return Fs}function Rs(e){return{type:`modal`,sections:[{label:G(`engine.packages.form.basics`,e),columns:1,fields:[{field:`name`,label:G(`engine.packages.create.name`,e),placeholder:`Acme CRM`},{field:`id`,label:G(`engine.packages.create.id`,e),placeholder:`com.acme.crm`,immutable:!0},{field:`namespace`,label:G(`engine.packages.create.namespace`,e),placeholder:`crm`,immutable:!0},{field:`version`,label:G(`engine.packages.create.version`,e),placeholder:`0.1.0`},{field:`type`,label:G(`engine.packages.detail.type`,e),immutable:!0},{field:`description`,label:G(`engine.packages.detail.description`,e)}]},{label:G(`engine.packages.form.advanced`,e),collapsible:!0,collapsed:!0,columns:1,fields:[{field:`defaultDatasource`,label:G(`engine.packages.form.defaultDatasource`,e),immutable:!0},{field:`scope`,label:G(`engine.packages.form.scope`,e),immutable:!0},{field:`dependencies`,label:G(`engine.packages.form.dependencies`,e),immutable:!0}]}]}}var zs=`/api/v1/packages`,Bs=/^\d+\.\d+\.\d+$/;async function Vs(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`,t=Error(typeof e==`string`?e:`Request failed (${n.status})`);throw t.status=n.status,t}return i?.data??i}function Hs(){try{window.dispatchEvent(new CustomEvent(`objectui:packages-changed`))}catch{}}function Us({mode:e,open:t,onOpenChange:n,manifest:r,onSaved:i}){let a=Ti(),o=X.useMemo(()=>Ls(),[]),s=X.useMemo(()=>Rs(a),[a]),c=e===`create`,l=e===`view`,[u,d]=X.useState({}),[f,p]=X.useState(!1),[m,h]=X.useState(null),g=X.useRef(!1);X.useEffect(()=>{t&&(g.current=!1,d(c?{version:`0.1.0`,type:`app`}:{...r??{}}),h(null),p(!1))},[t,c,r]);let _=X.useCallback(e=>{if(!c){d(e);return}d(t=>{let n=e.namespace;return n!==t.namespace&&(g.current=!0,n=String(n??``).toLowerCase().replace(/[^a-z0-9_]/g,``)),!g.current&&e.id!==t.id&&(n=A(String(e.id??``))??``),{...e,namespace:n}})},[c]),v=X.useMemo(()=>{if(l)return[];let e=O.safeParse(u);return e.success?[]:e.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))},[u,l]),y=!!String(u.name??``).trim(),b=String(u.version??``).trim(),x=c?Bs.test(b):!b||Bs.test(b),S=!c||!!String(u.id??``).trim(),C=!c||js.test(String(u.namespace??``).trim()),w=!l&&y&&x&&S&&C&&!f;async function T(){if(w){p(!0),h(null);try{let t;if(c){let n={...u,id:String(u.id??``).trim(),name:String(u.name??``).trim(),version:b,type:u.type??`app`},r=await Vs(zs,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:n})});t={id:String(r?.manifest?.id??n.id),mode:e,package:r}}else{let n=String(r?.id??u.id??``);t={id:n,mode:e,package:await Vs(`${zs}/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:String(u.name??``).trim(),description:String(u.description??``).trim(),version:b})})}}Hs(),i?.(t),n(!1)}catch(e){let t=e?.message??``;e?.status===409||/already exists/i.test(t)?h(G(`engine.packages.create.exists`,a)):h(t||G(c?`engine.packages.create.failed`:`engine.packages.edit.failed`,a))}finally{p(!1)}}}return(0,Y.jsx)(Ut,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Qt,{className:`max-h-[85vh] overflow-y-auto`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsx)(Fr,{children:G(e===`create`?`engine.packages.create.title`:e===`edit`?`engine.packages.edit.title`:`engine.packages.view.title`,a)}),e===`create`?(0,Y.jsx)(vt,{children:W(`engine.packages.create.description`,a,{example:`com.acme.crm`})}):(0,Y.jsx)(vt,{className:`font-mono text-xs`,children:String(r?.id??u.id??``)})]}),(0,Y.jsx)(`div`,{className:`py-1`,"data-testid":`package-form`,children:(0,Y.jsx)(ha,{schema:o,form:s,value:u,onChange:_,issues:v,readOnly:l,createMode:c})}),m&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:m})]}),(0,Y.jsx)(re,{children:l?(0,Y.jsx)(L,{variant:`outline`,onClick:()=>n(!1),children:G(`engine.close`,a)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`outline`,onClick:()=>n(!1),disabled:f,children:G(`engine.cancel`,a)}),(0,Y.jsx)(L,{onClick:T,disabled:!w,"data-testid":`package-form-submit`,children:G(f?c?`engine.packages.create.creating`:`engine.packages.edit.saving`:c?`engine.packages.create.submit`:`engine.packages.edit.save`,a)})]})})]})})}var Ws=`/api/v1/packages`;async function Gs(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function Ks({scope:e}){let t=Ti();if(!e)return(0,Y.jsx)(z,{className:`bg-emerald-400/15 text-emerald-600 hover:bg-emerald-400/15 dark:text-emerald-300`,children:G(`engine.packages.scope.writable`,t)});let n=e===`project`?`default`:e===`system`?`secondary`:`outline`,r=e===`project`?`engine.packages.scope.project`:e===`system`?`engine.packages.scope.system`:e===`cloud`?`engine.packages.scope.cloud`:``;return(0,Y.jsx)(z,{variant:n,children:r?G(r,t):e})}function qs({pkg:e}){let t=Ti(),n=e.enabled!==!1&&e.status!==`disabled`;return(0,Y.jsx)(z,{variant:n?`default`:`outline`,children:G(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}function Js({open:e,onOpenChange:t,onCreated:n}){return(0,Y.jsx)(Us,{mode:`create`,open:e,onOpenChange:t,onSaved:e=>n(e.id)})}function Ys({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function Xs({pkg:e,open:t,onOpenChange:n,onSaved:r}){return(0,Y.jsx)(Us,{mode:`edit`,open:t,onOpenChange:n,manifest:e?.manifest??null,onSaved:t=>r(t.package??e)})}function Zs({pkg:e,appBase:t,open:r,onOpenChange:i,onChanged:a}){let o=Ti(),[s,c]=X.useState(null),[l,u]=X.useState(null),[d,f]=X.useState(null),[p,m]=X.useState(!1),[h,g]=X.useState(!1);if(X.useEffect(()=>{u(null),c(null)},[e?.manifest.id]),X.useEffect(()=>{let t=e?.manifest.id;if(!r||!t){f(null);return}let n=!1;return Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{n||f(e?.drafts??[])}).catch(()=>{n||f([])}),()=>{n=!0}},[r,e?.manifest.id]),!e)return null;let _=e.manifest.id,v=e.enabled!==!1&&e.status!==`disabled`,y=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function b(e,t,n){c(e),u(null);try{await t(),u({kind:`ok`,text:n}),a()}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.actionFailed`,o)})}finally{c(null)}}return(0,Y.jsx)(wr,{open:r,onOpenChange:i,children:(0,Y.jsxs)(Be,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Y.jsxs)(Kt,{children:[(0,Y.jsxs)(tn,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Kr,{className:`h-4 w-4`}),e.manifest.name||_]}),(0,Y.jsx)(Xt,{className:`font-mono text-xs`,children:_})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(Ys,{label:G(`engine.packages.col.version`,o),children:e.manifest.version||`—`}),(0,Y.jsx)(Ys,{label:G(`engine.packages.detail.type`,o),children:e.manifest.type||`—`}),(0,Y.jsx)(Ys,{label:G(`engine.packages.col.scope`,o),children:(0,Y.jsx)(Ks,{scope:e.manifest.scope})}),(0,Y.jsx)(Ys,{label:G(`engine.packages.col.status`,o),children:(0,Y.jsx)(qs,{pkg:e})}),e.manifest.description&&(0,Y.jsx)(Ys,{label:G(`engine.packages.detail.description`,o),children:e.manifest.description})]}),t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`my-4`}),(0,Y.jsxs)(n,{to:`${t}/metadata/object?package=${encodeURIComponent(_)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5`}),G(`engine.packages.detail.browseMetadata`,o)]})]}),d&&d.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`my-4`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[G(`engine.packages.detail.pendingChanges`,o),(0,Y.jsx)(z,{variant:`secondary`,children:d.length})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G(`engine.packages.detail.pendingHint`,o)}),!y&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(L,{size:`sm`,onClick:()=>b(`publish-drafts`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount){let t=Array.isArray(e.failed)?e.failed:[],n=t.find(e=>e?.code!==`batch_aborted`&&e?.error);throw t.some(e=>e?.code===`batch_aborted`)?Error(W(`engine.packages.detail.publishDraftsRolledBack`,o,{cause:n?`${n.type??`?`}/${n.name??`?`}: ${n.error}`:String(e.failedCount)})):Error(W(`engine.packages.detail.publishDraftsPartial`,o,{published:e.publishedCount??0,failed:e.failedCount}))}return e}),G(`engine.packages.detail.publishDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(ze,{className:`mr-1.5 h-3.5 w-3.5`}),s===`publish-drafts`?G(`engine.packages.detail.publishing`,o):W(`engine.packages.detail.publishApp`,o,{count:d.length})]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`discard-drafts`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Gs(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(W(`engine.packages.detail.discardDraftsPartial`,o,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),G(`engine.packages.detail.discardDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),s===`discard-drafts`?G(`engine.packages.detail.discarding`,o):W(`engine.packages.detail.discardChanges`,o,{count:d.length})]})]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:d.map(e=>t?(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`):(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]},`${e.type}/${e.name}`))})]})]}),(0,Y.jsx)(bt,{className:`my-4`}),y?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.detail.kernelReadOnly`,o)}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.packages.detail.actions`,o)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>g(!0),disabled:!!s,children:[(0,Y.jsx)(N,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.viewInfo`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>m(!0),disabled:!!s,children:[(0,Y.jsx)(Rr,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.edit`,o)]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>b(`publish`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?W(`engine.packages.detail.publishBlocked`,o,{count:t}):e.validationErrors?.[0]?.message||G(`engine.packages.detail.nothingToPublish`,o))}return e}),G(`engine.packages.detail.published`,o)),disabled:!!s,children:[(0,Y.jsx)(ze,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`revert`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/revert`,{method:`POST`}),G(`engine.packages.detail.reverted`,o)),disabled:!!s,children:[(0,Y.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.detail.revert`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`toggle`,()=>Gs(`${Ws}/${encodeURIComponent(_)}/${v?`disable`:`enable`}`,{method:`PATCH`}),G(v?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,o)),disabled:!!s,children:[v?(0,Y.jsx)(ur,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Y.jsx)(Mr,{className:`mr-1.5 h-3.5 w-3.5`}),G(v?`engine.packages.detail.disable`:`engine.packages.detail.enable`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>b(`export`,async()=>{let e=await Gs(`${Ws}/${encodeURIComponent(_)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${_}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},G(`engine.packages.detail.exported`,o)),disabled:!!s,children:[(0,Y.jsx)(dn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{let t=window.prompt(G(`engine.packages.detail.duplicatePrompt`,o),`${_}-copy`);if(!(!t||!t.trim())){c(`duplicate`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({targetPackageId:t.trim(),targetName:`${e?.manifest.name??_} (copy)`})}),u({kind:`ok`,text:G(`engine.packages.detail.duplicated`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Duplicate failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(Pn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`duplicate`?`engine.packages.detail.duplicating`:`engine.packages.detail.duplicate`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(W(`engine.packages.detail.adoptConfirm`,o,{name:e?.manifest.name||_}))){c(`adopt`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}/adopt-orphans`,{method:`POST`}),u({kind:`ok`,text:G(`engine.packages.detail.adopted`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Adopt failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(br,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`adopt`?`engine.packages.detail.adopting`:`engine.packages.detail.adoptOrphans`,o)]}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:async()=>{if(!window.confirm(W(`engine.packages.detail.deleteConfirm`,o,{name:e?.manifest.name||_})))return;let t=window.confirm(G(`engine.packages.detail.deleteKeepData`,o))?``:`?keepData=true`;c(`delete`),u(null);try{await Gs(`${Ws}/${encodeURIComponent(_)}${t}`,{method:`DELETE`}),a(),i(!1)}catch(e){u({kind:`err`,text:e?.message??G(`engine.packages.detail.deleteFailed`,o)})}finally{c(null)}},disabled:!!s,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,Y.jsx)(Tn,{className:`mr-1.5 h-3.5 w-3.5`}),G(s===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,o)]})]})]}),l&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text}),(0,Y.jsx)(Xs,{pkg:e,open:p,onOpenChange:m,onSaved:()=>{u({kind:`ok`,text:G(`engine.packages.edit.saved`,o)}),a()}}),(0,Y.jsx)(Us,{mode:`view`,open:h,onOpenChange:g,manifest:e?.manifest??null})]})})}function Qs(){let e=Ti(),{pathname:t}=r(),n=X.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[i,a]=X.useState([]),[o,s]=X.useState(!0),[c,l]=X.useState(null),[u,d]=X.useState(``),[f,p]=X.useState(!1),[m,h]=X.useState(!1),[g,_]=X.useState(null),[v,y]=X.useState(!1),b=X.useRef(null),[x,S]=X.useState(!1),[C,w]=X.useState(null),T=X.useCallback(async()=>{s(!0),l(null);try{let e=await Gs(Ws),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),a(t)}catch(t){l(t?.message??G(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);X.useEffect(()=>{T()},[T]),X.useEffect(()=>{if(!g)return;let e=i.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[i,g]);let E=X.useMemo(()=>{let e=u.trim().toLowerCase();return i.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:!e||t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e))},[i,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(G(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(G(`engine.packages.import.invalidPackage`,e));let i=await Gs(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})});w({kind:`ok`,text:W(`engine.packages.import.success`,e,{id:i?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??G(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=i.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,Y.jsx)(Kr,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:G(`engine.packages.title`,e)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:G(`engine.packages.description`,e)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,Y.jsx)(qt,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),G(`engine.packages.refresh`,e)]}),(0,Y.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,Y.jsx)(Lt,{className:`mr-1.5 h-3.5 w-3.5`}),G(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>h(!0),children:[(0,Y.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),G(`engine.packages.new`,e)]})]})]}),C&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${C.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:C.text}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Mt,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,Y.jsx)(U,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:W(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,Y.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,Y.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,Y.jsx)(Te,{className:`h-10 w-full`},e))}):c?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:c})]}):E.length===0?(0,Y.jsx)(`div`,{className:`p-8`,children:(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:G(`engine.packages.empty`,e)}),(0,Y.jsx)(ht,{children:i.length===0?G(`engine.packages.emptyCreate`,e):G(`engine.packages.emptyFiltered`,e)})]})}):(0,Y.jsxs)(ni,{children:[(0,Y.jsx)(fe,{children:(0,Y.jsxs)(Xr,{children:[(0,Y.jsx)(Dt,{children:G(`engine.packages.col.name`,e)}),(0,Y.jsx)(Dt,{children:`ID`}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.version`,e)}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.scope`,e)}),(0,Y.jsx)(Dt,{className:`w-24`,children:G(`engine.packages.col.status`,e)})]})}),(0,Y.jsx)(_n,{children:E.map(e=>(0,Y.jsxs)(Xr,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,Y.jsx)($r,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Y.jsx)($r,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Y.jsx)($r,{children:e.manifest.version||`—`}),(0,Y.jsx)($r,{children:(0,Y.jsx)(Ks,{scope:e.manifest.scope})}),(0,Y.jsx)($r,{children:(0,Y.jsx)(qs,{pkg:e})})]},e.manifest.id))})]})}),(0,Y.jsx)(Js,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,Y.jsx)(Zs,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var $s=new Set([`field`,`package`]),ec={data:ir,ui:ln,automation:Ye,ai:Et,system:tt,platform:tt,identity:P,security:P},tc={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},nc=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],rc=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],ic={object:Sn,dashboard:Gn,page:Oe,report:Nr,record:xn,metadata:ln};function ac(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function oc(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function sc(){let e=Ai(),{loading:t,entries:r}=Mi(e),{recentItems:i}=fi(),a=Ti(),[s,c]=o(),[l,u]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;u(bs(n))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=s.get(`package`),f=X.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);X.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(s);e.set(`package`,l[0].id),c(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=Di(e,`warning`,f??void 0),b=X.useMemo(()=>r.filter(e=>$s.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,r,v]),x=X.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=X.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(nc.indexOf(e)===-1?99:nc.indexOf(e))-(nc.indexOf(t)===-1?99:nc.indexOf(t)))},[b,_]),C=X.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return rc.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:G(`engine.home.loading`,a)}):(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,Y.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`max-w-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,Y.jsx)(Et,{className:`h-4 w-4`}),G(ac(),a)]}),(0,Y.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:G(`engine.home.subtitle`,a)}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Y.jsx)(L,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,Y.jsxs)(n,{to:m,children:[(0,Y.jsx)(ln,{className:`mr-1.5 h-4 w-4`}),G(`engine.home.browseAll`,a)]})}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white/90 backdrop-blur-sm`,children:[(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`}),G(`engine.directory.quickFind`,a),` ⌘⇧M`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsx)(cc,{value:b.length,label:G(`engine.home.statTypes`,a)}),(0,Y.jsx)(cc,{value:x.length,label:G(`engine.home.statWritable`,a)}),(0,Y.jsx)(cc,{value:l.length,label:G(`engine.home.statPackages`,a)})]})]})]}),(0,Y.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Y.jsx)(lc,{icon:ln,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:G(`engine.home.statTypes`,a),to_link:m}),(0,Y.jsx)(lc,{icon:Ce,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:G(`engine.home.statWritable`,a),to_link:m}),(0,Y.jsx)(lc,{icon:Kr,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:G(`engine.home.statPackages`,a),to_link:h}),(0,Y.jsxs)(n,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,Y.jsx)(Ce,{className:`h-5 w-5`}):(0,Y.jsx)(R,{className:`h-5 w-5`})}),(0,Y.jsx)(qr,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?G(`engine.home.allHealthy`,a):w}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,a)})]})]})]}),C.length>0&&(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(uc,{icon:H,title:G(`engine.home.quickActions`,a),hint:G(`engine.home.quickActionsHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,Y.jsx)(L,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-transparent bg-muted hover:bg-primary/10 hover:text-primary`,children:(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),W(`engine.home.newItem`,a,{label:wi(e.type,a,e.label)})]})},e.type))})]}),(0,Y.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,Y.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,Y.jsx)(uc,{icon:ln,title:G(`engine.home.explore`,a),hint:G(`engine.home.exploreHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,Y.jsx)(dc,{domain:e,group:t,countsByType:_,locale:a,packageSuffix:p},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(uc,{icon:gn,title:G(`engine.home.recent`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:i.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:G(`engine.home.recentEmpty`,a)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:i.slice(0,8).map(e=>{let t=ic[e.type]??xn;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,Y.jsx)(t,{className:`h-4 w-4`})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:oc(e.visitedAt,a)})]}),(0,Y.jsx)(qr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(vs,{})]})}function cc({value:e,label:t}){return(0,Y.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function lc({icon:e,from:t,to:r,value:i,label:a,to_link:o}){return(0,Y.jsxs)(n,{to:o,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${r} text-white shadow-sm`,children:(0,Y.jsx)(e,{className:`h-5 w-5`})}),(0,Y.jsx)(qr,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:i}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:a})]})]})}function uc({icon:e,title:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,Y.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,Y.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function dc({domain:e,group:t,countsByType:r,locale:i,packageSuffix:a}){let o=ec[e]??xn,s=tc[e]??tc.other,c=t.slice(0,6),l=t.length-c.length;return(0,Y.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${s.ring}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${s.from} ${s.to} text-white shadow-sm`,children:(0,Y.jsx)(o,{className:`h-[18px] w-[18px]`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ei(e,i)}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,G(`engine.home.typesLower`,i)]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[c.map(e=>(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}${a}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:wi(e.type,i,e.label)}),(0,Y.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:r[e.type]??0})]},e.type)),l>0&&(0,Y.jsxs)(n,{to:`metadata${a}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${s.text} hover:underline`,children:[`+`,l]})]})]})}function fc({entry:e,itemName:t,subtitle:i,stats:a,actions:o,embedded:s=!1,children:c}){let l=e?.type??``,u=Ti(),d=wi(l,u,e?.label),{pathname:f}=r(),p=X.useMemo(()=>{let e=f.indexOf(`/metadata`);return e>=0?f.slice(0,e+9):`/metadata`},[f]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[s?(0,Y.jsx)(`span`,{className:`shrink-0`,children:d}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(n,{to:p,className:`hover:text-foreground shrink-0`,children:G(`engine.breadcrumb.allTypes`,u)}),(0,Y.jsx)(Vt,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(n,{to:`${p}/${encodeURIComponent(l)}`,className:`hover:text-foreground shrink-0`,children:d})]}),(0,Y.jsx)(Vt,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ei(e.domain,u)}),e?.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,u)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:G(`engine.badge.readOnly`,u)})]}),i&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:i}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),o]})]}):(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[!s&&(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,Y.jsx)(n,{to:p,className:`hover:text-foreground`,children:G(`engine.breadcrumb.allTypes`,u)}),(0,Y.jsx)(Vt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:d})]}),(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:d}),(0,Y.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:l}),e?.domain&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ei(e.domain,u)}),e?.allowOrgOverride?(0,Y.jsx)(z,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:G(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,Y.jsx)(z,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:G(`engine.badge.createOnly`,u)}):(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:G(`engine.badge.readOnly`,u)})]}),i&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:i}),!i&&e?.description&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),o]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:c})]})}var pc={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function mc(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function hc({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=X.useState(null),[o,s]=X.useState({open:!1,params:[]}),[c,l]=X.useState({open:!1}),u=X.useMemo(()=>d(),[]),f=X.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(f.length===0)return null;let p=(e,t)=>new Promise(n=>{s({open:!0,params:e,title:t,resolve:n})}),m=async e=>{let t=e.label??e.name;if(e.type!==`api`){si.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i;if(Array.isArray(e.params)&&e.params.length>0){let n=await p(e.params,t);if(n==null)return;i=n}else i=e.params??{};let o={recordId:n,origin:window.location.origin},s=mc(e.target??``,o,i);if(!s){si.error(`Action “${t}” has no target.`);return}let c=``.replace(/\/+$/,``),d=/^https?:\/\//i.test(s)?s:`${c}${s}`,f=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:f,headers:{"Content-Type":`application/json`},credentials:`include`};f!==`GET`&&f!==`DELETE`&&(n.body=JSON.stringify(i));let a=await u(d,n),o=null;try{o=await a.json()}catch{}if(!a.ok||o&&o.success===!1){let n=o?.error||o?.message||`HTTP ${a.status} ${a.statusText}`.trim();si.error(`${e.errorMessage?`${e.errorMessage}: `:``}${t}: ${n}`);return}if(e.resultDialog)l({open:!0,spec:e.resultDialog,data:o??{}});else{let n=e.successMessage||(typeof o?.message==`string`?o.message:`${t} ✓`);si.success(n)}e.refreshAfter&&r?.()}catch(e){si.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,Y.jsxs)(Y.Fragment,{children:[f.map(e=>{let t=e.icon?Si(e.icon):null,n=i===e.name;return(0,Y.jsxs)(L,{size:`sm`,variant:pc[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>m(e),title:e.label??e.name,children:[n?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,Y.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)}),(0,Y.jsx)(gi,{state:o,onOpenChange:e=>{e||(o.resolve?.(null),s({open:!1,params:[]}))}}),(0,Y.jsx)(hi,{state:c,onAcknowledge:()=>l({open:!1})})]})}function gc(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var _c=new Map;function vc(e){let t=_c.get(e.type);if(!t){_c.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);_c.set(e.type,n)}function yc(e){return _c.get(e)}function bc(e){let t=[];for(let n of _c.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function xc(e,t){let n=_c.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Sc(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function Cc({type:e}){let t=s(),n=e??t.type??``;if(n===`package`)return(0,Y.jsx)(l,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let r=yc(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(wc,{type:n,appName:t.appName})}function wc({type:e,appName:t}){let r=i(),a=Ai(),{entries:s}=Mi(a),c=s.find(t=>t.type===e),l=xc(e,c),[u,d]=X.useState([]),[f,p]=X.useState(!0),[m,h]=X.useState(null),[g,_]=X.useState(``),[v,y]=X.useState(`all`),[b,x]=o(),[S,C]=X.useState(0),[w,T]=X.useState(null);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`package`);if(e)return;T(bs(t))}catch{e||T([])}})(),()=>{e=!0}},[a]);let[E,D]=X.useState(null);X.useEffect(()=>{let e=!1;if(!t){D(null);return}return(async()=>{try{let n=await a.list(`app`);if(e)return;let r=(n??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).find(e=>e?.name===t||e?._packageId===t);D(r?._packageId??null)}catch{e||D(null)}})(),()=>{e=!0}},[a,t]);let O=b.get(`package`),k=X.useMemo(()=>{if(!w)return null;if(O&&w.some(e=>e.id===O))return O;if(w.length===0)return null;if(E&&w.some(e=>e.id===E))return E;let e=new Map;for(let t of u){let n=t.item?._packageId;n&&n!==`sys_metadata`&&e.set(n,(e.get(n)??0)+1)}let t=null,n=0;for(let r of w){let i=e.get(r.id)??0;i>n&&(t=r.id,n=i)}return t??w[0]?.id??null},[w,O,u,E]);X.useEffect(()=>{if(!w||w.length===0||O&&w.some(e=>e.id===O)||!(E&&w.some(e=>e.id===E))&&u.length===0||!k)return;let e=new URLSearchParams(b);e.set(`package`,k),x(e,{replace:!0})},[w,O,u,k,E]);let A=k?`?package=${encodeURIComponent(k)}`:``,[ee,j]=X.useState(!1),te=X.useCallback(()=>{let e=w??[];if(w!==null&&e.length===0){j(!0);return}if(e.length>0&&!k){r(`./new?package=${encodeURIComponent(e[0].id)}`);return}r(`./new${A}`)},[w,k,A,r]);X.useEffect(()=>{let t=!1;return p(!0),h(null),(async()=>{try{let n=await a.list(e);if(t)return;let r=(n??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Sc(t,e?.source),diagnostics:n}});d(r),p(!1)}catch(e){t||(h(e?.message??String(e)),p(!1))}})(),()=>{t=!0}},[a,e,S]);let ne=l.searchableFields??[`name`,`label`,`description`],M=X.useMemo(()=>u.filter(e=>l.listFilter&&!l.listFilter(e.item)||!k?!1:e.item?._packageId===k),[u,k,l]),re=M.filter(e=>!(!Oi(e.item,g,ne)||v!==`all`&&e.source!==v)),N=X.useMemo(()=>{let e={all:M.length,artifact:0,runtime:0};for(let t of M)e[t.source]++;return e},[M]),ie=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[M]),ae=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[M]),se=l.listColumns??Tc(l.primaryKey??`name`),P=Ti(),ce=wi(e,P,c?.label??e),le=e=>{let t=`engine.list.col.${e.key}`,n=G(t,P);return n===t?e.label:n};return(0,Y.jsx)(fc,{entry:c??{type:e,label:e},stats:[{label:G(`engine.list.items`,P),value:M.length},{label:G(`engine.list.filtered`,P),value:re.length},...ie>0?[{label:G(`engine.list.invalid`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(R,{className:`w-3.5 h-3.5`}),ie]})}]:[],...ae>0?[{label:G(`engine.list.warnings`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(R,{className:`w-3.5 h-3.5`}),ae]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(hc,{entry:c,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:G(`engine.list.refresh`,P),children:(0,Y.jsx)(qt,{className:`h-4 w-4`})}),(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsxs)(L,{size:`sm`,variant:l.createFields?`default`:`outline`,onClick:te,title:l.createFields?W(`engine.list.createHint`,P,{type:ce}):void 0,children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,P)]})]}),children:(0,Y.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Y.jsx)(Js,{open:ee,onOpenChange:j,onCreated:e=>r(`./new?package=${encodeURIComponent(e)}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,Y.jsx)(Me,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(B,{className:`pl-8`,placeholder:G(`engine.list.search`,P),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(oe,{value:v,onValueChange:y,children:[(0,Y.jsx)(fr,{className:`w-[180px]`,children:(0,Y.jsx)(Dr,{})}),(0,Y.jsxs)(En,{children:[(0,Y.jsxs)(Pr,{value:`all`,children:[G(`engine.list.allSources`,P),` (`,N.all,`)`]}),(0,Y.jsxs)(Pr,{value:`artifact`,children:[G(`engine.list.source.artifact`,P),` (`,N.artifact,`)`]}),(0,Y.jsxs)(Pr,{value:`runtime`,children:[G(`engine.list.source.runtime`,P),` (`,N.runtime,`)`]})]})]})]}),(f||w===null)&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[G(`engine.edit.loading`,P),` `,e,`…`]}),m&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:m}),!f&&!m&&w!==null&&w.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No project packages installed`}),(0,Y.jsx)(ht,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!f&&!m&&w!==null&&w.length>0&&re.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:M.length===0?W(`engine.list.emptyType`,P,{type:ce}):W(`engine.list.emptyQuery`,P,{query:g})}),(0,Y.jsx)(ht,{children:l.emptyStateHint??(c?.allowOrgOverride||c?.allowRuntimeCreate?W(`engine.list.createHint`,P,{type:ce}):G(`engine.list.readOnlyHint`,P))}),M.length===0&&(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(L,{onClick:te,children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),G(`engine.list.create`,P)]})})]}),!f&&re.length>0&&(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[se.map(e=>(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:le(e)},e.key)),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:G(`engine.list.col.source`,P)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:re.map((e,t)=>{let r=l.primaryKey??`name`,i=String(e.item[r]??`(unnamed-${t})`),a=e.item._packageId,o=a&&a!==`sys_metadata`?`?package=${encodeURIComponent(a)}`:A,s=e.diagnostics?.valid===!1,c=e.diagnostics?.errors??[],u=e.diagnostics?.warnings??[],d=!s&&u.length>0,f=s?c.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
3
3
  `)+(c.length>3?`\n+${c.length-3} more`:``):d?u.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
4
4
  `)+(u.length>3?`\n+${u.length-3} more`:``):``;return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(s?`bg-destructive/[0.04]`:d?`bg-amber-500/[0.05]`:``),children:[se.map((t,r)=>{let a=e.item[t.key],l=t.render?t.render(a,e.item):Ec(a);return(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:r===0?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":G(`engine.list.invalidTitle`,P),title:`${W(`engine.list.invalidCount`,P,{count:c.length})}\n${f}`,children:(0,Y.jsx)(R,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),d&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":G(`engine.list.warnTitle`,P),title:`${W(`engine.list.warnCount`,P,{count:u.length})}\n${f}`,children:(0,Y.jsx)(R,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,Y.jsx)(n,{to:`./${encodeURIComponent(i)}${o}`,className:`text-primary hover:underline font-mono`,children:l})]}):l},t.key)}),(0,Y.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,Y.jsx)(`span`,{className:`inline-flex items-center mr-1 text-amber-600 dark:text-amber-400`,title:e.item._lockReason??`_lock=${String(e.item._lock)}`,children:(0,Y.jsx)(Ve,{className:`h-3 w-3`})}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] `+(e.source===`artifact`?`border-sky-500/50 text-sky-700 dark:text-sky-300`:`border-emerald-500/50 text-emerald-700 dark:text-emerald-300`),title:e.source===`artifact`?`${G(`engine.list.source.artifactDesc`,P)}${e.item._packageId?` (${e.item._packageId})`:``}`:G(`engine.list.source.runtimeDesc`,P),children:G(`engine.list.source.${e.source}`,P)})]})]},i+t)})})]})})]})})}function Tc(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Ec(e){if(e==null||e===``)return(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,Y.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Dc={unchanged:{badge:`bg-muted text-muted-foreground border border-border`,row:``},modified:{badge:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,row:`bg-amber-50/50 dark:bg-amber-950/20`},added:{badge:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,row:`bg-emerald-50/50 dark:bg-emerald-950/20`},removed:{badge:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`,row:`bg-rose-50/50 dark:bg-rose-950/20`}};function Oc(e,t){let n=kc(e)?e:{},r=kc(t)?t:{},i=new Set([...Object.keys(n),...Object.keys(r)]),a=[];for(let e of i){let t=e in n,i=e in r,o=n[e],s=r[e],c;c=t&&!i?`removed`:!t&&i?`added`:Ac(o)===Ac(s)?`unchanged`:`modified`,a.push({key:e,status:c,codeValue:o,effectiveValue:s})}let o={modified:0,added:1,removed:2,unchanged:3};return a.sort((e,t)=>o[e.status]===o[t.status]?e.key.localeCompare(t.key):o[e.status]-o[t.status]),a}function kc(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ac(e){try{return JSON.stringify(e,(e,t)=>kc(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function jc(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function Mc(e,t){if(e==null)return 0;let n=0;for(let r of Oc(e,t))r.status!==`unchanged`&&(n+=1);return n}function Nc({layered:e,loading:t,locale:n}){if(t)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.edit.loading`,n)});if(!e)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,Y.jsxs)(Hn,{defaultValue:`diff`,className:`w-full`,children:[(0,Y.jsxs)(an,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(Gr,{value:`diff`,children:G(`engine.layers.diff`,n)}),(0,Y.jsxs)(Gr,{value:`code`,children:[G(`engine.layers.code`,n),(0,Y.jsx)(z,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Y.jsxs)(Gr,{value:`overlay`,children:[G(`engine.layers.overlay`,n),r?(0,Y.jsx)(z,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Y.jsx)(z,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Y.jsxs)(Gr,{value:`effective`,children:[G(`engine.layers.effective`,n),(0,Y.jsx)(z,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Y.jsx)(Ln,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(Pc,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(Ln,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(Ic,{payload:e.code,emptyHint:G(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(Ln,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(Ic,{payload:e.overlay,emptyHint:G(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(Ln,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(Ic,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Pc({code:e,effective:t,locale:n}){let[r,i]=X.useState(!1),a=X.useMemo(()=>e==null?[]:Oc(e,t),[e,t]),o=X.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]);if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noBaseline`,n)});let s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:W(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,Y.jsx)(Mt,{checked:r,onCheckedChange:i,"aria-label":G(`engine.layers.diff.showUnchanged`,n)}),G(`engine.layers.diff.showUnchanged`,n),(0,Y.jsx)(z,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:G(`engine.layers.diff.noChanges`,n)}):(0,Y.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] bg-muted/50 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.field`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.code`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.effective`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:G(`engine.layers.diff.status`,n)})]}),(0,Y.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Dc[e.status];return(0,Y.jsxs)(`div`,{className:I(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,Y.jsx)(Fc,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)(Fc,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:I(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:G(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function Fc({value:e,muted:t}){let n=jc(e);return(0,Y.jsx)(`div`,{className:I(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function Ic({payload:e,emptyHint:t}){if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,Y.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var Lc={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},Rc={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function zc(e,t){return G(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function Bc(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function Vc(e,t){let n=0;for(let r of Oc(e,t))r.status!==`unchanged`&&(n+=1);return n}function Hc({published:e,draft:t,locale:n,className:r}){let i=X.useMemo(()=>Oc(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:G(`designer.draftReview.empty`,n)}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${Rc[t]}`,children:[(0,Y.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${Lc[t]}`,children:zc(t,n)}),(0,Y.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Bc(e.effectiveValue)}):t===`removed`?(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Bc(e.codeValue)}):(0,Y.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Bc(e.codeValue)}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Bc(e.effectiveValue)})]})]},e.key)})})}function Uc({type:e,name:t,parentItem:n,onOpen:r}){let a=Ai(),o=i(),s=X.useMemo(()=>bc(e),[e]),[c,l]=X.useState([]),[u,d]=X.useState(``),[f,p]=X.useState({});if(X.useEffect(()=>{if(s.length===0){l([]);return}let e=!1,r=[...s].sort((e,t)=>(e.anchor.order??999)-(t.anchor.order??999)).map(e=>{if(e.anchor.source===`embedded`){let t=e.anchor.extract&&n?e.anchor.extract(n):[];return{childType:e.type,anchor:e.anchor,loading:!1,error:null,items:t.map(Wc)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return l(r),Promise.all(r.map(async n=>{if(n.anchor.source===`embedded`)return n;try{let r=await a.list(n.childType);if(e)return n;let i=n.anchor.match??(()=>!1),o=r.filter(e=>i(e,t)).map(e=>Wc(e));return{...n,loading:!1,items:o}}catch(t){return e?n:{...n,loading:!1,error:t instanceof Error?t.message:String(t)}}})).then(t=>{e||l(t)}),()=>{e=!0}},[a,e,t,s,n]),s.length===0)return(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No related metadata`}),(0,Y.jsxs)(ht,{children:[`No metadata types are configured to anchor at `,(0,Y.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let m=c.reduce((e,t)=>e+t.items.length,0),h=c.some(e=>e.loading),g=u.trim().toLowerCase();return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,Y.jsx)(Me,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(B,{placeholder:`Search related…`,value:u,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),c.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,a=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!a})),children:[(0,Y.jsx)(Vt,{className:I(`h-4 w-4 text-muted-foreground transition-transform`,!a&&`rotate-90`)}),(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>{if(n.anchor.source===`embedded`){if(typeof window<`u`){let e=new URL(window.location.href);e.searchParams.set(`tab`,`form`),e.searchParams.delete(`open`),window.location.assign(e.toString())}return}o(`../../${encodeURIComponent(n.childType)}/_new?anchor=${encodeURIComponent(`${e}:${t}`)}`)},title:n.anchor.source===`embedded`?`Edit in Form tab`:`New ${n.childType}`,children:(0,Y.jsx)(H,{className:`h-3.5 w-3.5`})})]}),!a&&(0,Y.jsxs)(`div`,{children:[n.loading&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:g?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,Y.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,Y.jsx)(`th`,{className:`w-8`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,Y.jsxs)(`tr`,{role:`button`,tabIndex:0,onClick:()=>r(n.anchor.source===`embedded`?{kind:`embedded`,parentType:e,parentName:t,groupLabel:n.anchor.groupLabel??n.childType,itemName:i.name,raw:i.raw,editAs:n.anchor.editAs,embeddedPath:n.anchor.embeddedPath}:{kind:`metadata`,type:n.childType,name:i.name}),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&e.currentTarget.click()},className:`hover:bg-accent/50 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,Y.jsx)(`td`,{className:`px-3 py-1.5 text-xs text-muted-foreground truncate max-w-0`,children:i.label&&i.label!==i.name?i.label:``}),(0,Y.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function Wc(e){return{name:Gc(e,[`name`,`id`,`key`])??`(unnamed)`,label:Gc(e,[`label`,`title`,`displayName`]),description:Gc(e,[`description`,`summary`]),raw:e}}function Gc(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function Kc({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=Ti(),c=Ai(),{entries:l}=Mi(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?Jc[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=X.useState(a),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState([]),[S,C]=X.useState(null);X.useEffect(()=>{h(a),y(null),x([]),C(null)},[a,r,e,t]);let w=u!=null&&!u.allowOrgOverride&&!u.allowRuntimeCreate;async function T(){if(!n){y(G(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=qc(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:Ci(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?G(`engine.validation.failedOne`,s):W(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,Y.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:G(`engine.embedded.saved`,s)}),w&&(0,Y.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:G(`engine.embedded.readOnlyParent`,s)}),(0,Y.jsx)(ha,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,Y.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,Y.jsxs)(L,{onClick:T,disabled:g||!n,children:[g?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(ai,{className:`h-4 w-4 mr-1`}),W(`engine.embedded.saveIntoParent`,s,{parentType:e})]})}),!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:G(`engine.embedded.readOnly`,s)}),(0,Y.jsx)(`div`,{children:G(`engine.embedded.noPathHint`,s)})]})]}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:W(`engine.embedded.noSchema`,s,{type:i??`this item`,target:`${e}/${t}.${n}.${r}`})}),(0,Y.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(m,null,2),onChange:e=>{try{h(JSON.parse(e.target.value)),y(null)}catch(e){y(`${G(`engine.form.invalidJson`,s)}: ${e.message}`)}}}),v&&(0,Y.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsxs)(L,{onClick:T,disabled:g||!n,children:[g?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(ai,{className:`h-4 w-4 mr-1`}),W(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function qc(e,t,n,r){let i=t.split(`.`),a=structuredClone(e),o=a;for(let e=0;e<i.length-1;e++)o[i[e]]??(o[i[e]]={}),o=o[i[e]];let s=i[i.length-1],c=o[s];if(Array.isArray(c)){let e=c.findIndex(e=>e&&typeof e==`object`&&e.name===n);e>=0?c[e]=r:c.push(r)}else if(c&&typeof c==`object`){let{name:e,...t}=r;c[n]=t}else{let{name:e,...t}=r;o[s]={[n]:t}}return a}var Jc={index:{schema:{type:`object`,required:[`fields`],properties:{name:{type:`string`,title:`Name`,description:`Synthesised from columns if omitted (e.g. idx_email).`},fields:{type:`array`,title:`Fields`,description:`Columns to index, in order.`,items:{type:`string`}},type:{type:`string`,title:`Algorithm`,enum:[`btree`,`hash`,`gin`,`gist`,`brin`],default:`btree`},unique:{type:`boolean`,title:`Unique`,description:`Enforce uniqueness across the indexed columns.`},where:{type:`string`,title:`Partial-index predicate`,description:`Optional WHERE clause for a partial index.`}}}}};function Yc({target:e,onClose:t,parentContext:n}){let r=i(),a=e?.kind===`metadata`,o=e?.kind===`embedded`,s=a?e.type:o?e.groupLabel:``,c=a?e.name:o?e.itemName:``;return(0,Y.jsx)(wr,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)(Be,{side:`right`,className:I(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(z,{variant:`outline`,className:`font-mono text-[10px]`,children:s}),(0,Y.jsx)(tn,{className:`font-mono text-base truncate`,children:c}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:a&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Y.jsxs)(Xt,{className:`text-xs`,children:[o?`Embedded in `:`Related to `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[a&&(0,Y.jsx)($l,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),o&&(0,Y.jsx)(Kc,{parentType:e.parentType,parentName:e.parentName,embeddedPath:e.embeddedPath,itemName:e.itemName,editAs:e.editAs,initialRaw:e.raw},`${e.parentType}/${e.parentName}/${e.embeddedPath}/${e.itemName}`)]})]})})}function Xc({type:e,name:t}){let n=s(),r=e??n.type??``,a=t??n.name??``,o=i(),c=Ai(),{entries:l}=Mi(c),u=l.find(e=>e.type===r),[d,f]=X.useState(0),[p,m]=X.useState(0);return(0,Y.jsx)(fc,{entry:u??{type:r,label:r},itemName:a,subtitle:`Version history`,stats:[{label:`Events`,value:p}],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,Y.jsx)(ge,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+1),children:(0,Y.jsx)(qt,{className:`h-4 w-4`})})]}),children:(0,Y.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Y.jsx)(Zc,{type:r,name:a,refreshKey:d,onCount:m,client:c,onRollback:()=>f(e=>e+1)})})})}function Zc({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=X.useState([]),[u,d]=X.useState(!0),[f,p]=X.useState(null),[m,h]=X.useState(null),[g,_]=X.useState(null),[v,y]=X.useState(0);X.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function b(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,Y.jsxs)(Y.Fragment,{children:[u&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:f}),!u&&!f&&c.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No history yet`}),(0,Y.jsx)(ht,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,Y.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:c.map((e,t)=>{let n=m===t,r=e.op??e.kind,i=e.ts??e.at,o=!!a&&typeof e.version==`number`&&r!==`delete`&&r!==`tombstone`;return(0,Y.jsxs)(`li`,{className:`relative`,children:[(0,Y.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>h(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&h(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Y.jsx)(z,{className:`text-[10px] `+(r===`delete`||r===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:r===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:r===`publish`?`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`:r===`revert`?`bg-amber-100 text-amber-900 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(r)}),e.actor&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:Qc(i)}),o&&(0,Y.jsx)(L,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),b(e.version)},children:g===e.version?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),n&&(0,Y.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:$c(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Qc(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function $c(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function el(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function tl(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:P},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:st},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:Yn}},n=t[e]??t.allowed;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${n.cls}`,children:[(0,Y.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function nl({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=X.useState(!1),[o,s]=X.useState(null),[c,l]=X.useState(null),u=X.useCallback(async()=>{a(!0),s(null);try{let r=await n.audit(e,t,{limit:100});l(r.events??[])}catch(e){s(String(e?.message??e)),l([])}finally{a(!1)}},[n,e,t]);return X.useEffect(()=>{u()},[u]),(0,Y.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,G(`engine.edit.auditCount`,r)]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:G(`engine.edit.refresh`,r),children:[i?(0,Y.jsx)(V,{className:`h-3 w-3 animate-spin`}):(0,Y.jsx)(qt,{className:`h-3 w-3`}),G(`engine.edit.refresh`,r)]})]}),o&&(0,Y.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,Y.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`mr-2 h-3 w-3 animate-spin`}),G(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Y.jsxs)(Zt,{className:`py-10`,children:[(0,Y.jsx)(Lr,{children:G(`engine.edit.auditEmptyTitle`,r)}),(0,Y.jsx)(ht,{children:G(`engine.edit.auditEmptyDescription`,r)})]}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColTime`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColActor`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOperation`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColOutcome`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColLock`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:G(`engine.edit.auditColNote`,r)})]})}),(0,Y.jsx)(`tbody`,{children:c.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:el(e.occurredAt)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:tl(e.outcome)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,Y.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,Y.jsx)(`td`,{className:`max-w-[28ch] truncate px-2 py-1.5 text-muted-foreground`,title:e.note??e.code,children:e.note??e.code})]},String(e.id)))})]})})]})}var rl=new Map;function il(e,t){rl.set(e,t)}function al(e){return rl.get(e)}var ol=new Map;function sl(e,t){ol.set(e,t)}function cl(e){return ol.get(e)}var ll=new Map;function ul(e,t){ll.set(e,t)}function dl(e){return ll.get(e)}function fl(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&hl(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&hl(e.charCodeAt(r)))for(r++;r<e.length&&hl(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&hl(e.charCodeAt(r))){for(r++;r<e.length&&hl(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
5
5
  `;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(ml(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(pl(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(pl(t));return o=15}if(ml(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
@@ -9,8 +9,8 @@ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,d as r,f
9
9
  `+` `.repeat(t)),Array(_l).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(_l).fill(0).map((e,t)=>`\r
10
10
  `+` `.repeat(t));var vl;(function(e){e.DEFAULT={allowTrailingComma:!1}})(vl||={});function yl(e,t=[],n=vl.DEFAULT){let r={type:`array`,offset:-1,length:-1,children:[],parent:void 0};function i(e){r.type===`property`&&(r.length=e-r.offset,r=r.parent)}function a(e){return r.children.push(e),e}xl(e,{onObjectBegin:e=>{r=a({type:`object`,offset:e,length:-1,parent:r,children:[]})},onObjectProperty:(e,t,n)=>{r=a({type:`property`,offset:t,length:-1,parent:r,children:[]}),r.children.push({type:`string`,value:e,offset:t,length:n,parent:r})},onObjectEnd:(e,t)=>{i(e+t),r.length=e+t-r.offset,r=r.parent,i(e+t)},onArrayBegin:(e,t)=>{r=a({type:`array`,offset:e,length:-1,parent:r,children:[]})},onArrayEnd:(e,t)=>{r.length=e+t-r.offset,r=r.parent,i(e+t)},onLiteralValue:(e,t,n)=>{a({type:Sl(e),offset:t,length:n,parent:r,value:e}),i(t+n)},onSeparator:(e,t,n)=>{r.type===`property`&&(e===`:`?r.colonOffset=t:e===`,`&&i(t))},onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n);let o=r.children[0];return o&&delete o.parent,o}function bl(e,t){if(!e)return;let n=e;for(let e of t)if(typeof e==`string`){if(n.type!==`object`||!Array.isArray(n.children))return;let t=!1;for(let r of n.children)if(Array.isArray(r.children)&&r.children[0].value===e&&r.children.length===2){n=r.children[1],t=!0;break}if(!t)return}else{let t=e;if(n.type!==`array`||t<0||!Array.isArray(n.children)||t>=n.children.length)return;n=n.children[t]}return n}function xl(e,t,n=vl.DEFAULT){let r=fl(e,!1),i=[],a=0;function o(e){return e?()=>a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function s(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function c(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function l(e){return e?()=>{a>0?a++:e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(a=1)}:()=>!0}function u(e){return e?()=>{a>0&&a--,a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}let d=l(t.onObjectBegin),f=c(t.onObjectProperty),p=u(t.onObjectEnd),m=l(t.onArrayBegin),h=u(t.onArrayEnd),g=c(t.onLiteralValue),_=s(t.onSeparator),v=o(t.onComment),y=s(t.onError),b=n&&n.disallowComments,x=n&&n.allowTrailingComma;function S(){for(;;){let e=r.scan();switch(r.getTokenError()){case 4:C(14);break;case 5:C(15);break;case 3:C(13);break;case 1:b||C(11);break;case 2:C(12);break;case 6:C(16);break}switch(e){case 12:case 13:b?C(10):v();break;case 16:C(1);break;case 15:case 14:break;default:return e}}}function C(e,t=[],n=[]){if(y(e),t.length+n.length>0){let e=r.getToken();for(;e!==17;){if(t.indexOf(e)!==-1){S();break}else if(n.indexOf(e)!==-1)break;e=S()}}}function w(e){let t=r.getTokenValue();return e?g(t):(f(t),i.push(t)),S(),!0}function T(){switch(r.getToken()){case 11:let e=r.getTokenValue(),t=Number(e);isNaN(t)&&(C(2),t=0),g(t);break;case 7:g(null);break;case 8:g(!0);break;case 9:g(!1);break;default:return!1}return S(),!0}function E(){return r.getToken()===10?(w(!1),r.getToken()===6?(_(`:`),S(),k()||C(4,[],[2,5])):C(5,[],[2,5]),i.pop(),!0):(C(3,[],[2,5]),!1)}function D(){d(),S();let e=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(e||C(4,[],[]),_(`,`),S(),r.getToken()===2&&x)break}else e&&C(6,[],[]);E()||C(4,[],[2,5]),e=!0}return p(),r.getToken()===2?S():C(7,[2],[]),!0}function O(){m(),S();let e=!0,t=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(t||C(4,[],[]),_(`,`),S(),r.getToken()===4&&x)break}else t&&C(6,[],[]);e?(i.push(0),e=!1):i[i.length-1]++,k()||C(4,[],[4,5]),t=!0}return h(),e||i.pop(),r.getToken()===4?S():C(8,[4],[]),!0}function k(){switch(r.getToken()){case 3:return O();case 1:return D();case 10:return w(!0);default:return T()}}return S(),r.getToken()===17?n.allowEmptyContent?!0:(C(4,[],[]),!1):k()?(r.getToken()!==17&&C(9,[],[]),!0):(C(4,[],[]),!1)}function Sl(e){switch(typeof e){case`boolean`:return`boolean`;case`number`:return`number`;case`string`:return`string`;case`object`:return e?Array.isArray(e)?`array`:`object`:`null`;default:return`null`}}var Cl;(function(e){e[e.None=0]=`None`,e[e.UnexpectedEndOfComment=1]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=2]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=3]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=4]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=5]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=6]=`InvalidCharacter`})(Cl||={});var wl;(function(e){e[e.OpenBraceToken=1]=`OpenBraceToken`,e[e.CloseBraceToken=2]=`CloseBraceToken`,e[e.OpenBracketToken=3]=`OpenBracketToken`,e[e.CloseBracketToken=4]=`CloseBracketToken`,e[e.CommaToken=5]=`CommaToken`,e[e.ColonToken=6]=`ColonToken`,e[e.NullKeyword=7]=`NullKeyword`,e[e.TrueKeyword=8]=`TrueKeyword`,e[e.FalseKeyword=9]=`FalseKeyword`,e[e.StringLiteral=10]=`StringLiteral`,e[e.NumericLiteral=11]=`NumericLiteral`,e[e.LineCommentTrivia=12]=`LineCommentTrivia`,e[e.BlockCommentTrivia=13]=`BlockCommentTrivia`,e[e.LineBreakTrivia=14]=`LineBreakTrivia`,e[e.Trivia=15]=`Trivia`,e[e.Unknown=16]=`Unknown`,e[e.EOF=17]=`EOF`})(wl||={});var Tl=yl,El=bl,Dl;(function(e){e[e.InvalidSymbol=1]=`InvalidSymbol`,e[e.InvalidNumberFormat=2]=`InvalidNumberFormat`,e[e.PropertyNameExpected=3]=`PropertyNameExpected`,e[e.ValueExpected=4]=`ValueExpected`,e[e.ColonExpected=5]=`ColonExpected`,e[e.CommaExpected=6]=`CommaExpected`,e[e.CloseBraceExpected=7]=`CloseBraceExpected`,e[e.CloseBracketExpected=8]=`CloseBracketExpected`,e[e.EndOfFileExpected=9]=`EndOfFileExpected`,e[e.InvalidCommentToken=10]=`InvalidCommentToken`,e[e.UnexpectedEndOfComment=11]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=12]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=13]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=14]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=15]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=16]=`InvalidCharacter`})(Dl||={});function Ol(e=4e3){let t=X.useRef(null),[n,r]=X.useState(!1);return X.useEffect(()=>{if(n)return;let e=!1,t=Ea?.init?.();return t&&typeof t.catch==`function`&&t.catch(()=>{e||r(!0)}),()=>{e=!0}},[n]),X.useEffect(()=>{if(n)return;let i=setTimeout(()=>{let e=t.current;(!e||!e.querySelector(`.view-line`))&&r(!0)},e);return()=>clearTimeout(i)},[n,e]),[n,t]}var kl=X.lazy(async()=>({default:(await a(()=>import(`./dist-B4b49_J4.js`).then(e=>e.n),[],import.meta.url)).default}));function Al(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function jl(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function Ml({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`,fallbackDelayMs:a=4e3}){let o=Ti(),[s,c]=X.useState(()=>Al(e)),[l,u]=X.useState(null),d=X.useRef(s),f=X.useRef(null),p=X.useRef(null),[m,h]=Ol(a),[g,_]=X.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>_(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let v=X.useCallback(()=>{let e=f.current,t=p.current;if(!e||!t)return;let n=e.getModel();if(!n)return;if(!r||r.length===0){t.editor.setModelMarkers(n,`objectui-diagnostics`,[]);return}let i;try{i=Tl(s)}catch{i=void 0}let a=r.map(e=>{let r=jl(e.path),a=1,o=1,s=1,c=2,l=i?El(i,r):void 0;if(l){let e=n.getPositionAt(l.offset),t=n.getPositionAt(l.offset+l.length);a=e.lineNumber,o=e.column,s=t.lineNumber,c=t.column}return{severity:e.severity===`warning`?t.MarkerSeverity.Warning:t.MarkerSeverity.Error,message:e.path?`${e.path}: ${e.message}`:e.message,startLineNumber:a,startColumn:o,endLineNumber:s,endColumn:c,source:`metadata`}});t.editor.setModelMarkers(n,`objectui-diagnostics`,a)},[r,s]);X.useEffect(()=>{v()},[v]),X.useEffect(()=>{let t=Al(e);t!==d.current&&(c(t),d.current=t,u(null))},[e]);let y=e=>{let n=e??``;c(n);try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)?(u(null),d.current=n,t(e)):u(G(`engine.form.rootJsonObject`,o))}catch(e){u(e?.message??G(`engine.form.invalidJson`,o))}};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{ref:h,"data-testid":`source-editor`,className:`border rounded overflow-hidden bg-background`,style:{height:typeof i==`number`?`${i}px`:i},children:m?(0,Y.jsx)(`textarea`,{value:s,onChange:e=>y(e.target.value),readOnly:n,spellCheck:!1,"aria-label":`JSON source`,className:`w-full h-full resize-none bg-background p-3 font-mono text-xs leading-relaxed outline-none`}):(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(Te,{className:`w-full h-full`}),children:(0,Y.jsx)(kl,{value:s,language:`json`,theme:g,onChange:y,onMount:(e,t)=>{f.current=e,p.current=t,setTimeout(v,0)},options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,renderLineHighlight:`line`,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),l&&(0,Y.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,Y.jsx)(`span`,{children:l})]})]})}var Nl={object:async()=>(await a(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await a(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await a(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await a(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await a(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await a(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await a(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await a(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await a(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await a(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await a(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.T);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await a(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.o);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await a(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.o);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await a(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.i);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await a(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.i);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await a(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.i);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await a(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await a(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await a(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.s);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,position:async()=>(await a(async()=>{let{PositionSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.n);return{PositionSchema:e}},[],import.meta.url)).PositionSchema,api:async()=>(await a(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.r);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},Pl=new Set([`approval`,`connector_action`]),Fl=/^nodes\.(\d+)\.type$/;function Il(e,t){let n=e?.nodes;if(!Array.isArray(n))return;let r=n[t];return typeof r?.type==`string`?r.type:void 0}var Ll=[`visibleWhen`,`readonlyWhen`,`requiredWhen`,`conditionalRequired`];function Rl(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.source==`string`){let t=e.dialect;if(t===void 0||t===`cel`)return e.source}return null}async function zl(e){let t=e,n=Qi(t?.fields);if(n.entries.length===0)return[];let r=typeof t?.name==`string`?t.name:void 0,i=n.entries.map(e=>e.name),a=[];for(let e=0;e<n.entries.length;e++){let t=n.entries[e],o=n.shape===`array`?String(e):t.name;for(let e of Ll){let n=Rl(t.def[e]);if(n==null||!n.trim())continue;let s=await ba(n,{objectName:r,fields:i,scope:`record`});for(let t of s)t.severity===`error`&&a.push({path:`fields.${o}.${e}`,message:t.message})}if(t.def.type===`formula`){let e=Rl(t.def.expression);if(e==null||!e.trim())continue;let n=await ba(e,{objectName:r,fields:i.filter(e=>e!==t.name),scope:`record`,role:`value`});for(let e of n)e.severity===`error`&&a.push({path:`fields.${o}.expression`,message:e.message})}}return a}var Bl=new Map;async function Vl(e){if(Bl.has(e))return Bl.get(e)??null;let t=Nl[e];if(!t)return Bl.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return Bl.set(e,r),r}catch{return Bl.set(e,null),null}}function Hl(e){return e in Nl}async function Ul(e,t,n){let r=await Vl(e);if(!r)return{ok:!0,issues:[]};let i=e===`object`?await zl(t):[],a=r.safeParse(t);if(a.success)return i.length>0?{ok:!1,issues:i}:{ok:!0,issues:[]};let o=a.error?.issues??[],s=Array.isArray(n?.required)?new Set(n.required.map(e=>String(e))):void 0;if(s&&t&&typeof t==`object`&&!Array.isArray(t)){let e=t;o=o.filter(t=>{let n=t.path??[];if(n.length!==1)return!0;let r=String(n[0]);return!((e[r]===void 0||e[r]===null)&&!s.has(r))})}return e===`flow`&&(o=o.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=Fl.exec(n);if(!r)return!0;let i=Il(t,Number(r[1]));return!(i&&Pl.has(i))})),o.length===0&&i.length===0?{ok:!0,issues:[]}:{ok:!1,issues:[...o.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message})),...i]}}function Wl(e,t,n){let r=t.split(`.`);if(r.length<=1)return e;let i=[e],a=Kl(n)?.[r[0]];for(let e=1;e<r.length;e++){let t=r[e];if(/^\d+$/.test(t)){let e=Number(t),n=Array.isArray(a)?a[e]:void 0;i.push(Gl(n)??`#${e+1}`),a=n}else i.push(t),a=Kl(a)?.[t]}return i.join(` → `)}function Gl(e){let t=Kl(e);if(t)for(let e of[`id`,`name`,`key`,`title`,`label`]){let n=t[e];if(typeof n==`string`&&n.trim())return n;let r=Kl(n);if(r){let e=r.defaultValue??r.key;if(typeof e==`string`&&e.trim())return e}}}function Kl(e){return e&&typeof e==`object`?e:void 0}function ql(e,t,n){return e.createBuildBody?e.createBuildBody(t):{...n??e.createDefaults??{},...t}}var Jl=Ar,Yl=new Set([`object`,`report`,`dataset`]),Xl={object:[`fields`,`fieldGroups`]};function Zl(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 Ql(e){return e.loadFailed?!1:e.hasDiag||e.hasClientValidator}function $l({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=s(),a=e??i.type??``,o=t??i.name??``,c=yc(a);if(c?.EditPage&&!n){let e=c.EditPage;return(0,Y.jsx)(e,{type:a,name:o})}if(c?.CreatePage&&n){let e=c.CreatePage;return(0,Y.jsx)(e,{type:a})}return(0,Y.jsx)(eu,{type:a,name:o,createMode:n,embedded:r})}function eu({type:e,name:t,createMode:n,embedded:r}){let a=i(),[s,c]=o(),l=s.get(`package`)??void 0,u=Ai(),{entries:d}=Mi(u),f=d.find(t=>t.type===e),p=xc(e,f),m=(n&&p.createSchema?p.createSchema:f?.schema)??p.defaultSchema,h=Ti(),[g,_]=X.useState(null),v=p.identityField??`name`,[y,b]=X.useState(()=>n?{...p.createDefaults??{},[v]:``}:{}),[x,S]=X.useState(null),[C,w]=X.useState(!n),[T,E]=X.useState(!1),[D,O]=X.useState(null),[k,A]=X.useState(!1),[ee,j]=X.useState([]),[te,ne]=X.useState(!1),ie=X.useCallback(e=>{b(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&(ne(!0),j(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)}))),n})},[]),[ae,oe]=X.useState(null),[se,ce]=X.useState(null),le=X.useCallback(e=>{ie(t=>({...t,...e}))},[ie]),{markTouched:de}=ji({rules:p.createDerive,draft:y,onPatch:le,enabled:!!n}),F=X.useMemo(()=>{if(n)return p.createFields&&p.createFields.length>0?p.createFields:Ni(m?.properties??void 0,m?.required??void 0)},[n,p.createFields,m]),fe=X.useMemo(()=>{let t=Xl[e]??[];if(!n||!F)return t.length===0?p.hiddenFields:Array.from(new Set([...p.hiddenFields??[],...t]));let r=m?.properties??{},i=new Set(F),a=Object.keys(r).filter(e=>!i.has(e));if(p.hiddenFields)for(let e of p.hiddenFields)a.includes(e)||a.push(e);for(let e of t)a.includes(e)||a.push(e);return a},[n,F,m,p.hiddenFields,e]),pe=X.useMemo(()=>n&&F?F:p.fieldOrder,[n,F,p.fieldOrder]),me=X.useCallback(e=>{if(n){let t=y,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||de(e)}ie(e)},[n,y,ie,de]);X.useEffect(()=>{if(!Hl(e))return;let t=!1,n=window.setTimeout(()=>{Ul(e,y,f?.schema).then(e=>{t||j(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,y,f?.schema]);let ge=X.useMemo(()=>n&&!te?[]:ee,[n,te,ee]),_e=X.useMemo(()=>{let t=g?._diagnostics,n=Hl(e)?ge.map(e=>({path:e.path,message:Ci(e.message,h)})):(t?.errors??[]).map(e=>({path:e.path,message:Ci(e.message,h)})),r=(t?.warnings??[]).map(e=>({path:e.path,message:Ci(e.message,h)}));return[...n.map(e=>({path:e.path||void 0,message:e.message,severity:`error`})),...r.map(e=>({path:e.path||void 0,message:e.message,severity:`warning`}))]},[g,ge,e,h]),[ve,ye]=X.useState(!1),[be,Ce]=X.useState(!1),[we,Te]=X.useState(0),[Ee,De]=X.useState(!!n),[Oe,ke]=X.useState(null);X.useEffect(()=>{ke(null)},[e,t]),X.useEffect(()=>{Ee||ke(null)},[Ee]);let Ae=po(s.get(`sel`)),je=X.useRef(null);X.useEffect(()=>{if(e!==`app`||!Ae||je.current===`${t}:${Ae}`||!y||Object.keys(y).length===0)return;let n=vo(y,Ae);n&&(je.current=`${t}:${Ae}`,De(!0),ke({kind:`nav`,id:n.selectionId,label:n.label}))},[e,t,Ae,y]),X.useEffect(()=>{if(e!==`app`)return;let t=Oe?.kind===`nav`?yo(y,Oe.id):null;c(e=>{let n=new URLSearchParams(e);return t?n.set(`sel`,mo(t)):n.delete(`sel`),n},{replace:!0})},[e,Oe]);let Me=X.useRef(null),[Ne,Pe]=X.useState(null),[Fe,Ie]=X.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null||e===`1`}catch{return!0}});X.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,Fe?`1`:`0`)}catch{}},[Fe]);let Le=X.useRef(null),[Re,ze]=X.useState([]),[He,Ue]=X.useState(!0);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await u.list(`object`);if(e)return;ze(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||ze([])}finally{e||Ue(!1)}})(),()=>{e=!0}},[u]);let We=y?.interfaceConfig?.source||y?.data?.object||y?.object||y?.objectName,[Ge,Ke]=X.useState([]),[qe,Je]=X.useState(!1),[Ye,Xe]=X.useState([]);X.useEffect(()=>{let e=!1;if(!We){Ke([]),Xe([]);return}return Je(!0),(async()=>{try{let t=await u.get(`object`,We);if(e)return;let n=t?.fields,r=Array.isArray(n)?n.map(e=>({name:e?.name,label:e?.label,type:e?.type})):n&&typeof n==`object`?Object.entries(n).map(([e,t])=>({name:e,label:t?.label,type:t?.type})):[];Ke(r.filter(e=>!!e.name));let i=t?.actions,a=Array.isArray(i)?i.map(e=>({name:e?.name,label:e?.label,locations:e?.locations})).filter(e=>!!e.name):[];e||Xe(a)}catch{e||(Ke([]),Xe([]))}finally{e||Je(!1)}})(),()=>{e=!0}},[u,We]);let[I,Ze]=X.useState([]),[Qe,$e]=X.useState(!1);X.useEffect(()=>{let e=!1;if(!We){Ze([]);return}return $e(!0),(async()=>{try{let t=await u.list(`view`);if(e)return;let n=(t||[]).filter(e=>(e?.objectName??e?.object??e?.object_name)===We),r=new Set,i=n.map(e=>({name:e?.name,label:e?.label||void 0})).filter(e=>!!e.name&&!r.has(e.name)&&r.add(e.name));Ze(i)}catch{e||Ze([])}finally{e||$e(!1)}})(),()=>{e=!0}},[u,We]);let et=X.useMemo(()=>e===`page`?sa(y):[],[e,y]),tt=X.useMemo(()=>({objectNames:Re,objectsLoading:He,objectFields:Ge,objectFieldsLoading:qe,objectViews:I,objectViewsLoading:Qe,objectActions:Ye,componentIds:et}),[Re,He,Ge,qe,I,Qe,Ye,et]);X.useEffect(()=>{if(n){w(!1);return}let r=!1;return w(!0),O(null),A(!1),(async()=>{try{let n=l?{packageId:l}:{},[i,a]=await Promise.all([u.layered(e,t,n),u.getDraft(e,t,n).catch(()=>null)]);if(r)return;_(i);let o=i?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?j(o.errors.map(e=>({path:e.path||``,message:e.message}))):j([]);let s=Zl(a),c=i.effective??i.code??{},d=s?{...c,...s}:c,f=p.toDraft?p.toDraft(d):d;b(f),Me.current=f,ye(!!s),w(!1)}catch(n){r||(A(!0),O(W(`engine.edit.loadFailed`,h,{type:e,name:t??``,message:n?.message??String(n)})),w(!1))}})(),()=>{r=!0}},[u,e,t,l,n,we,h]);let[nt,it]=X.useState(!1);async function at(){if(!(x!=null||nt)){it(!0);try{let n=await u.references(e,t);S(n)}catch(e){S([]),console.error(`references() failed`,e)}finally{it(!1)}}}let[ot,st]=X.useState(null),ct=X.useMemo(()=>!n&&!r&&bc(e).length>0,[e,n,r]),lt=X.useRef(null),[dt,ft]=X.useState(null),mt=s.get(`review`),ht=X.useRef(!1);X.useEffect(()=>{if(!(mt!==`1`||n)){if(!ht.current){ht.current=!0,Te(e=>e+1);return}if(!C){ve&&ft(`review`);let e=new URLSearchParams(s);e.delete(`review`),c(e,{replace:!0}),ht.current=!1}}},[mt,n,C,ve]);let[gt,_t]=X.useState(`properties`);X.useEffect(()=>{if(dt===`references`&&at(),typeof window<`u`&&!r){let e=new URL(window.location.href);dt?e.searchParams.set(`tab`,dt):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[dt,r]);let yt=`metadata-edit:inspector-collapsed`,bt=`metadata-edit:inspector-size`,[xt,St]=X.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(yt)===`1`),Ct=X.useRef(38);X.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(bt));Number.isFinite(e)&&e>=22&&e<=80&&(Ct.current=e)},[]);let wt=X.useRef(null),Tt=X.useCallback(()=>{St(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(yt,t?`1`:`0`),t})},[]);X.useEffect(()=>{let e=wt.current;if(e)if(xt)e.resize?.(`0%`);else{let t=Ct.current||38;e.resize?.(`${t}%`)}},[xt]);let[Et,Dt]=X.useState(!1),[Ot,kt]=X.useState(!1);X.useEffect(()=>{if(typeof document>`u`||!Ot)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[Ot]),X.useEffect(()=>{if(typeof window>`u`||!Ot)return;function e(e){e.key===`Escape`&&(e.preventDefault(),kt(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ot]);let At=X.useRef(null);X.useEffect(()=>{At.current=null},[e,t]),X.useEffect(()=>{if(n||r||C)return;let i=`${e}/${t??``}`;At.current!==i&&al(e)&&(g?.code!=null&&g.code?._packageId!==`sys_metadata`?f?.allowOrgOverride:f?.allowOrgOverride||f?.allowRuntimeCreate)&&(At.current=i,De(!0))},[e,t,n,r,C,f,g]),X.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),Tt())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Tt]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&ft(t),lt.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&st({kind:`metadata`,type:e,name:t})}},[]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);ot?.kind===`metadata`?e.searchParams.set(`open`,`${ot.type}:${ot.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[ot,r]);function jt(e){let t=e.split(`.`)[0];return t?Wl((()=>{let e=n&&p.createSchema?void 0:f?.form,r=Array.isArray(e?.sections)?e.sections:[];for(let e of r){let n=Array.isArray(e?.fields)?e.fields:[];for(let e of n)if(typeof e==`string`){if(e===t)return e}else if(e?.field===t)return String(e.label??t)}let i=m?.properties??{};return String(i[t]?.title??t)})(),e,y):e}async function Mt(r){E(!0),O(null),j([]);try{let i=f?.createSeed,o=n?ql(p,y,i):p.fromDraft?p.fromDraft(y):y;if(n&&p.createSeed)try{let e=await p.createSeed(y,{client:u});e&&typeof e==`object`&&(o={...o,...e})}catch{}let c=String(o[v]??y[v]??t),d=n?{...o,[v]:c}:o;if(!c){O(G(`engine.validation.nameRequired`,h)),E(!1);return}let m=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await u.save(e,c,d,{force:r,mode:`draft`,...m?{packageId:m}:{}});let g=l?{packageId:l}:{},[x,S]=await Promise.all([u.layered(e,c,g),u.getDraft(e,c,g).catch(()=>null)]);_(x);let C=Zl(S);ye(!!C);let w=x.effective??d,T=C?{...w,...C}:w,D=p.toDraft?p.toDraft(T):T;b(D),Me.current=D,Pe(new Date),Le.current=JSON.stringify(D),oe(null),ce(null);let k=!n&&!!al(e);if(!n&&!k&&De(!1),n){let e=s.toString();a(`../${encodeURIComponent(c)}${e?`?${e}`:``}`,{relative:`path`})}}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];oe(Array.isArray(t)?t:[]),ce(y)}else if(e?.code===`writable_package_required`)O(G(`engine.package.writableRequired`,h));else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:Ci(String(e.message??`Invalid`),h)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:Ci(e[2].trim(),h)}]:[{path:``,message:Ci(r,h)}]}j(n),n.length===1&&!n[0].path?O(n[0].message):n.length===1?O(`${jt(n[0].path)}: ${n[0].message}`):O(W(`engine.validation.failed`,h,{count:n.length}))}else O(e?.message??String(e))}finally{E(!1)}}async function Nt(){let r=!n&&g?.code!=null;if(confirm(W(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,h,{type:e,name:t??``}))){E(!0),O(null);try{if(await u.reset(e,t),r){let n=await u.layered(e,t);_(n);let r=n.effective??n.code??{};b(r),Me.current=r,al(e)?At.current=null:De(!1)}else a(`../`,{relative:`path`})}catch(e){O(e?.message??String(e))}finally{E(!1)}}}async function Pt(){Ce(!0),O(null);try{await u.publish(e,t);let[n,r]=await Promise.all([u.layered(e,t),u.getDraft(e,t).catch(()=>null)]);_(n);let i=Zl(r);ye(!!i);let a=n.effective??y,o=i?{...a,...i}:a;b(o),Me.current=o}catch(e){O(e?.message??String(e))}finally{Ce(!1)}}async function Ft(){if(confirm(W(`engine.edit.discardDraftConfirm`,h,{type:e,name:t??``}))){E(!0),O(null);try{await u.reset(e,t,{state:`draft`});let n=await u.layered(e,t);_(n);let r=n.effective??n.code??{};b(r),Me.current=r,ye(!1)}catch(e){O(e?.message??String(e))}finally{E(!1)}}}let It=X.useMemo(()=>{if(n)return Object.keys(y).length>0;let e=Me.current;if(!e)return!1;try{return JSON.stringify(y)!==JSON.stringify(e)}catch{return!1}},[y,n]),Lt=!n&&g?.code!=null&&g.code?._packageId!==`sys_metadata`,zt=g?.editable!==!1,Bt=g?.deletable!==!1,Vt=g?.resettable!==!1,Ht=g?.lockReason,Gt=g?.lock&&g.lock!==`none`,qt=(n?!!(f?.allowOrgOverride||f?.allowRuntimeCreate):Lt?!!f?.allowOrgOverride:!!(f?.allowOrgOverride||f?.allowRuntimeCreate))&&(n||zt),Yt=!qt&&!n,Zt=X.useRef(Mt);if(X.useEffect(()=>{Zt.current=Mt}),X.useEffect(()=>{if(!Fe||n||Yt||!Ee||!It||T)return;let e;try{e=JSON.stringify(y)}catch{return}if(e===Le.current)return;let t=window.setTimeout(()=>{Le.current=e,Zt.current(!1)},1500);return()=>window.clearTimeout(t)},[y,It,Ee,T,n,Yt,Fe]),X.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!qt||Yt||!Ee&&!n)return;e.preventDefault(),!T&&(n||It)&&Zt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[qt,Yt,Ee,n,T,It]),X.useEffect(()=>{if(!It)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[It]),X.useEffect(()=>{if(!It)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(G(`engine.edit.unsavedLeaveConfirm`,h))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[It,h]),li(X.useMemo(()=>{if(r)return null;let n=String(y.name??t??``);if(!n)return null;let i={type:e,name:n,label:typeof y.label==`string`?y.label:void 0};return e===`object`&&(i.fields=Qi(y.fields).entries.slice(0,60).map(e=>({name:e.name,type:typeof e.def.type==`string`?e.def.type:void 0,label:typeof e.def.label==`string`?e.def.label:void 0,required:!!e.def.required||void 0}))),i},[r,e,t,y])),C)return(0,Y.jsx)(fc,{entry:f,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let $t=Yt&&Lt&&!!f?.allowRuntimeCreate,en=Yl.has(e),rn=!r&&(!n||en)?al(e):void 0,an=cl(e),on=dl(e);function sn(){Me.current&&b(Me.current),j([]),O(null),De(!1)}let un=Yt||!Ee&&!n,dn=(0,Y.jsxs)(Y.Fragment,{children:[!n&&(0,Y.jsx)(hc,{entry:f,location:`record_header`,recordId:t,onAfter:()=>Te(e=>e+1)}),(!n||ct)&&(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`layers`),title:G(`engine.edit.layers`,h),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(ln,{className:`h-3.5 w-3.5`}),g?.overlay&&(()=>{let e=Mc(g.code,g.effective);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:G(`engine.layers.diff`,h),children:e}):null})()]}),!n&&ve&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`review`),title:G(`designer.draftReview.title`,h),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,Y.jsx)(he,{className:`h-3.5 w-3.5`}),(()=>{let e=Vc(g?.effective??null,y);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-amber-500 text-amber-50 text-[9px] leading-[14px] text-center font-medium`,title:W(`designer.draftReview.badge`,h,{n:e}),children:e}):null})()]}),!n&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`references`),title:G(`engine.edit.references`,h),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(M,{className:`h-3.5 w-3.5`}),x&&x.length>0&&(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:x.length})]}),ct&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`related`),title:G(`engine.edit.related`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(zr,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`history`),title:G(`engine.edit.history`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Wr,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>ft(`audit`),title:G(`engine.edit.auditTab`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(P,{className:`h-3.5 w-3.5`})})]}),!n&&qt&&g?.overlay&&(Lt?Vt:Bt)&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:Nt,disabled:T,title:G(Lt?`engine.edit.reset`:`engine.edit.delete`,h),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Lt?(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})}),qt&&!n&&!Ee&&!rn&&(0,Y.jsxs)(L,{size:`sm`,onClick:()=>De(!0),className:`h-7`,children:[(0,Y.jsx)(Rr,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]}),qt&&(Ee||n)&&(0,Y.jsx)(nu,{saving:T,isDirty:It,autoSaveEnabled:Fe,lastSavedAt:Ne,createMode:!!n,locale:h}),qt&&(Ee||n)&&!n&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>Ie(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:G(Fe?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,h),children:Fe?(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(pt,{className:`h-3.5 w-3.5`})}),qt&&!n&&Ee&&!rn&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:sn,disabled:T,className:`h-7 w-7 p-0`,title:G(`engine.cancel`,h),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})}),qt&&(Ee||n)&&(0,Y.jsxs)(L,{size:`sm`,onClick:()=>Mt(!1),disabled:T||!n&&!It,className:`h-7 w-7 p-0 relative`,title:T?G(`engine.edit.saving`,h):!n&&!It?G(`engine.edit.noChanges`,h):`${G(`engine.edit.save`,h)} (⌘S)`,children:[T?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(ai,{className:`h-3.5 w-3.5`}),It&&!T&&(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),qt&&!n&&ve&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:Ft,disabled:T||be,className:`h-7 w-7 p-0 text-muted-foreground`,title:G(`engine.edit.discardDraft`,h),children:(0,Y.jsx)(Jt,{className:`h-3.5 w-3.5`})}),qt&&!n&&ve&&(0,Y.jsx)(L,{size:`sm`,onClick:Pt,disabled:T||be||It,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:G(It?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),children:be?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(xe,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:G(`engine.edit.publish`,h)})]})})]});return(0,Y.jsxs)(fc,{entry:f??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?G(`engine.edit.createNew`,h):void 0,actions:rn?null:dn,children:[(0,Y.jsxs)(`div`,{className:rn?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(D||Yt||ve||Gt)&&(0,Y.jsxs)(`div`,{className:rn?`px-6 pt-4 space-y-3`:`space-y-3`,children:[D&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:D}),Gt&&(0,Y.jsxs)(`div`,{className:`text-xs text-amber-900 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-2.5`,children:[(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`font-medium`,children:[g?.lock===`full`&&G(`engine.edit.lockFull`,h),g?.lock===`no-overlay`&&G(`engine.edit.lockNoOverlay`,h),g?.lock===`no-delete`&&G(`engine.edit.lockNoDelete`,h)]}),Ht&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:Ht}),g?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:g.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[h===`zh-CN`?`查看文档`:`View docs`,` →`]}),g?.packageId&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Y.jsxs)(`code`,{className:`font-mono`,children:[g.packageId,g.packageVersion?`@${g.packageVersion}`:``]})})]}),$t&&(0,Y.jsx)(L,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>a(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]}),ve&&!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,Y.jsx)(xe,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:G(`engine.edit.draftPending`,h)}),qt&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{size:`sm`,variant:`ghost`,onClick:Ft,disabled:T||be,className:`h-7`,children:G(`engine.edit.discardDraft`,h)}),(0,Y.jsx)(L,{size:`sm`,onClick:Pt,disabled:T||be||It,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:be?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):G(`engine.edit.publish`,h)})]})]}),Yt&&!Gt&&(0,Y.jsxs)(`div`,{"data-testid":`readonly-banner`,className:`text-xs text-amber-800 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex-1`,children:$t?G(`engine.edit.artifactLockedBanner`,h).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Y.jsx)(X.Fragment,{children:t},n)):G(`engine.edit.readOnlyTypeBanner`,h).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Y.jsx)(X.Fragment,{children:t},n))}),$t&&(0,Y.jsx)(L,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>a(`../new`,{relative:`path`}),children:G(`engine.list.create`,h)})]})]}),(0,Y.jsx)(`div`,{className:rn?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:rn?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!rn&&un&&!Yt&&qt&&!n&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,Y.jsx)(`span`,{children:G(`engine.edit.readOnlyBanner`,h).split(/\{edit\}/).map((e,t,n)=>(0,Y.jsxs)(X.Fragment,{children:[e,t<n.length-1&&(0,Y.jsx)(`strong`,{children:G(`engine.edit.edit`,h)})]},t))}),(0,Y.jsxs)(L,{size:`sm`,variant:`outline`,onClick:()=>De(!0),children:[(0,Y.jsx)(Rr,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.edit.edit`,h)]})]}),(()=>{let t=g?._diagnostics,r=Hl(e)?ee.map(e=>({path:e.path,message:Ci(e.message,h)})):(t?.errors??[]).map(e=>({...e,message:Ci(e.message,h)})),i=Hl(e)?r.length===0:t?.valid!==!1;if(n&&!te||!Ql({loadFailed:k,hasDiag:!!t,hasClientValidator:Hl(e)}))return null;let a=r,o=t?.warnings??[],s=!i&&a.length>0,c=o.length>0;if(!s&&!c)return null;let l=(e,t)=>{let n=t.slice(0,3),r=Math.max(0,t.length-n.length),i=e===`error`?`border-destructive/40 bg-destructive/[0.06] text-destructive`:`border-amber-500/40 bg-amber-500/[0.08] text-amber-800 dark:text-amber-200`,a=e===`error`?`engine.edit.diagnostics.title`:`engine.edit.diagnostics.warnTitle`;return(0,Y.jsxs)(`div`,{"data-testid":e===`error`?`metadata-validation-banner`:void 0,className:`flex items-start gap-2 text-xs border rounded p-2.5 ${i}`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:W(a,h,{count:t.length})}),(0,Y.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`opacity-70`,children:e.path?jt(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,Y.jsx)(`li`,{className:`opacity-70`,children:W(`engine.edit.diagnostics.more`,h,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[s&&l(`error`,a),c&&l(`warning`,o)]})})(),rn?(0,Y.jsx)(`div`,{className:Ot?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(Jl,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(gr,{defaultSize:62,minSize:30,children:(0,Y.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b bg-background/95 backdrop-blur px-3 py-2 sticky top-0 z-10`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:qt&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":G(`engine.edit.designer`,h),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Et,onClick:()=>Dt(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Et?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:G(`engine.edit.designMode`,h),children:[(0,Y.jsx)($n,{className:`h-3.5 w-3.5`}),G(`engine.edit.designMode`,h)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Et,onClick:()=>Dt(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Et?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.previewMode`,h),children:[(0,Y.jsx)(N,{className:`h-3.5 w-3.5`}),G(`engine.edit.previewMode`,h)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[dn,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),rn&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:Tt,className:`h-7 w-7 p-0`,title:G(xt?`engine.edit.showInspector`:`engine.edit.hideInspector`,h)+` (⌘\\)`,children:xt?(0,Y.jsx)(Rn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(nn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>kt(e=>!e),className:`h-7 w-7 p-0`,title:G(Ot?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,h),children:Ot?(0,Y.jsx)(ut,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ue,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4 bg-[radial-gradient(circle_at_1px_1px,theme(colors.border)_1px,transparent_0)] [background-size:16px_16px] bg-muted/30`,children:(0,Y.jsx)(rn,{type:e,name:t,draft:y,baseline:n?void 0:g?.effective??void 0,editing:Ee&&!Et,selection:Et?null:Oe,onSelectionChange:ke,locale:h,diagnostics:_e,onPatch:e=>ie(t=>({...t,...e}))})})]})}),(0,Y.jsx)(cn,{withHandle:!0,className:xt?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(gr,{panelRef:wt,defaultSize:Ct.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Ct.current=t,typeof window<`u`&&window.localStorage.setItem(bt,String(Math.round(t)))),St(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(yt,n?`1`:`0`),n))},children:(0,Y.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,Y.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":gt===`properties`,onClick:()=>_t(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(gt===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.properties`,h),children:[(0,Y.jsx)(Jr,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.properties`,h)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":gt===`source`,onClick:()=>_t(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(gt===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:G(`engine.edit.inspector.source`,h),children:[(0,Y.jsx)(Wt,{className:`h-3.5 w-3.5`}),G(`engine.edit.inspector.source`,h)]})]}),It&&(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,Y.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),G(`engine.edit.unsaved`,h)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:gt===`source`?(0,Y.jsx)(Ml,{value:y,onChange:ie,readOnly:un,issues:ge.map(e=>({path:e.path??``,message:e.message}))}):Oe&&an?(0,Y.jsx)(an,{type:e,name:t,draft:y,selection:Oe,onPatch:e=>ie(t=>({...t,...e})),onClearSelection:()=>ke(null),onSelectionChange:ke,readOnly:un,locale:h}):!Oe&&on?(0,Y.jsx)(on,{type:e,name:t,draft:y,onPatch:e=>ie(t=>({...t,...e})),onSelectionChange:ke,readOnly:un,locale:h,serverSchema:f?.schema}):(0,Y.jsx)(ha,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:me,issues:ge,hiddenFields:fe,fieldOrder:pe,readOnly:un,createMode:n,widgetContext:tt})})]})})]})}):(0,Y.jsx)(ha,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:me,issues:ge,hiddenFields:fe,fieldOrder:pe,readOnly:un,createMode:n,widgetContext:tt})]})})]}),(0,Y.jsx)(wr,{open:dt===`layers`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:G(`engine.edit.layers`,h)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Nc,{layered:g,locale:h})})]})}),(0,Y.jsx)(wr,{open:dt===`review`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:G(`designer.draftReview.title`,h)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t,` · `,G(`designer.canvas.reviewVsPublished`,h)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Hc,{published:g?.effective??null,draft:y,locale:h})})]})}),(0,Y.jsx)(wr,{open:dt===`references`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(tn,{className:`text-base`,children:[G(`engine.edit.references`,h),x&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 text-[10px]`,children:x.length})]}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(tu,{refs:x,loading:nt})})]})}),ct&&(0,Y.jsx)(wr,{open:dt===`related`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:G(`engine.edit.related`,h)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Uc,{type:e,name:t,parentItem:y,onOpen:e=>st(e)})})]})}),!n&&(0,Y.jsx)(wr,{open:dt===`history`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:G(`engine.edit.history`,h)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Zc,{type:e,name:t,client:u,onRollback:()=>Te(e=>e+1),rollbackLabel:G(`engine.edit.rollback`,h),rollbackConfirm:e=>G(`engine.edit.rollbackConfirm`,h).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(wr,{open:dt===`audit`,onOpenChange:e=>!e&&ft(null),children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:G(`engine.edit.auditTab`,h)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(nl,{type:e,name:t,client:u,locale:h})})]})}),(0,Y.jsx)(Yc,{target:ot,onClose:()=>st(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(Ut,{open:ae!=null,onOpenChange:e=>{e||(oe(null),ce(null))},children:(0,Y.jsxs)(Qt,{children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(vt,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Y.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:ae?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Y.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Y.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Y.jsxs)(re,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>oe(null),children:`Cancel`}),(0,Y.jsx)(L,{variant:`destructive`,onClick:()=>Mt(!0),disabled:T,children:T?`Forcing…`:`Force save`})]})]})})]})}function tu({refs:e,loading:t}){return t||e==null?(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`No references found`}),(0,Y.jsx)(ht,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function nu({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=X.useReducer(e=>e+1,0);return X.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(V,{className:`h-3 w-3 animate-spin`}),G(`engine.edit.saving`,a)]}):t?i?null:(0,Y.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),G(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:W(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function ru({type:e}){let t=r(),[n]=o(),i=e??n.get(`type`)??``;if(!i)return(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`Missing metadata type`}),(0,Y.jsxs)(ht,{children:[`This page expects a `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,Y.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let a=iu(t.pathname),s=a.split(`/`).filter(Boolean);return s.length===0?(0,Y.jsx)(Cc,{type:i}):s[0]===`new`&&s.length===1?(0,Y.jsx)($l,{type:i,name:``,createMode:!0},`${i}:__new__`):s.length===2&&s[1]===`history`?(0,Y.jsx)(Xc,{type:i,name:decodeURIComponent(s[0])}):s.length===1?(0,Y.jsx)($l,{type:i,name:decodeURIComponent(s[0])},`${i}:${s[0]}`):(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:`Unknown sub-path`}),(0,Y.jsxs)(ht,{children:[`The path `,(0,Y.jsx)(`code`,{className:`font-mono`,children:a}),` isn't recognized. Valid forms are `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function iu(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function au(){let e=Ai(),t=Ti(),[r,i]=X.useState(`error`),{loading:a,error:o,summary:s,reload:c}=Di(e,r),{entries:l}=Mi(e),u=X.useMemo(()=>{let e={};for(let n of l)e[n.type]=wi(n.type,t,n.label);return e},[l,t]),d=X.useMemo(()=>{let e={};for(let t of s.entries)(e[t.type]??=[]).push(t);return Object.entries(e).sort(([,e],[,t])=>t.length-e.length)},[s]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,Y.jsxs)(n,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(ge,{className:`h-3 w-3`}),G(`engine.diagnostics.back`,t)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`h-5 w-5 text-destructive`}),G(`engine.diagnostics.title`,t)]}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:W(`engine.diagnostics.summary`,t,{count:s.total,items:s.scannedItems,types:s.scannedTypes})}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsx)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5 text-xs`,children:[`error`,`warning`].map(e=>(0,Y.jsx)(`button`,{role:`tab`,type:`button`,"aria-selected":r===e,onClick:()=>i(e),className:`px-2.5 py-1 rounded transition-colors `+(r===e?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),children:G(`engine.diagnostics.severity.${e}`,t)},e))}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,Y.jsx)(qt,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.diagnostics.refresh`,t)]})]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:G(`engine.diagnostics.description`,t)})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[a&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:G(`engine.diagnostics.loading`,t)}),!a&&o&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:W(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(Zt,{children:[(0,Y.jsx)(Lr,{children:G(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(ht,{children:W(`engine.diagnostics.cleanHint`,t,{items:s.scannedItems,types:s.scannedTypes})})]}),d.map(([e,i])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(n,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:u[e]??e}),(0,Y.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:i.length})]}),(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:G(`engine.diagnostics.col.name`,t)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:G(`engine.diagnostics.col.issues`,t)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:i.map(i=>{let a=i.diagnostics.errors??[],o=i.diagnostics.warnings??[],s=(r===`warning`&&a.length===0?o:a).slice(0,3),c=Math.max(0,(a.length||o.length)-s.length);return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,Y.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,Y.jsx)(n,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(i.name)}`,className:`text-primary hover:underline font-mono`,children:i.name}),a.length>0&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:W(`engine.diagnostics.errorN`,t,{count:a.length})}),o.length>0&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:W(`engine.diagnostics.warnN`,t,{count:o.length})})]}),(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,Y.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[s.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),c>0&&(0,Y.jsx)(`li`,{className:`text-muted-foreground`,children:W(`engine.diagnostics.more`,t,{count:c})})]})})]},i.name)})})]})})]},e))]})]})}function ou(e){let t=e.slice(0,20);if(t.length===0)return`{
11
11
  "id": "record-1"
12
- }`;let n={};for(let e of t)n[e]=null;return JSON.stringify(n,null,2)}var su=JSON.stringify({id:`user-1`,organization_id:`org-1`,positions:[`admin`]},null,2),cu=[];function lu({open:e,onOpenChange:t,policyName:n,objectName:r,fieldNames:i=cu,using:a,check:o,t:s}){let c=X.useMemo(()=>{let e=[];return a&&a.trim()&&e.push(`using`),o&&o.trim()&&e.push(`check`),e},[a,o]),[l,u]=X.useState(`using`),[d,f]=X.useState(`{}`),[p,m]=X.useState(su),[h,g]=X.useState(null),[_,v]=X.useState(null),[y,b]=X.useState(!1);X.useEffect(()=>{e&&(u(c[0]??`using`),f(ou(i)),m(su),g(null),v(null))},[e]);let x=l===`using`?a??``:o??``;async function S(){g(null),v(null);let e=uu(d,s(`perm.cel.test.record`));if(!e.ok)return v(e.error);let t=uu(p,s(`perm.cel.test.user`));if(!t.ok)return v(t.error);b(!0);try{g(await Sa(x,{record:e.value,currentUser:t.value}))}finally{b(!1)}}return(0,Y.jsx)(Ut,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Qt,{className:`sm:max-w-2xl`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Je,{className:`h-4 w-4 text-muted-foreground`}),s(`perm.cel.test.title`),n?(0,Y.jsxs)(`span`,{className:`text-muted-foreground font-normal`,children:[`· `,n]}):null]}),(0,Y.jsx)(vt,{children:s(`perm.cel.test.help`)})]}),c.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground italic py-4`,children:s(`perm.cel.test.noPredicate`)}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[c.length>1&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`tablist`,"aria-label":s(`perm.cel.test.clause`),children:c.map(e=>(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e,onClick:()=>{u(e),g(null)},className:I(`rounded-md border px-3 py-1 text-xs transition-colors`,l===e?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:s(e===`using`?`perm.rls.using`:`perm.rls.check`)},e))}),(0,Y.jsxs)(`div`,{className:`rounded-md border bg-muted/40 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase text-muted-foreground`,children:[s(l===`using`?`perm.rls.using`:`perm.rls.check`),r?` · ${r}`:``]}),(0,Y.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-xs`,children:x})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-record`,children:s(`perm.cel.test.record`)}),(0,Y.jsx)(lr,{id:`cel-test-record`,value:d,onChange:e=>f(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-user`,children:[s(`perm.cel.test.user`),` `,(0,Y.jsx)(`span`,{className:`font-mono normal-case`,children:`current_user`})]}),(0,Y.jsx)(lr,{id:`cel-test-user`,value:p,onChange:e=>m(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]})]}),_&&(0,Y.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-destructive`,children:[(0,Y.jsx)(wt,{className:`mt-[1px] h-3.5 w-3.5 shrink-0`}),_]}),h&&(0,Y.jsx)(du,{outcome:h,t:s})]}),(0,Y.jsxs)(re,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>t(!1),children:s(`engine.cancel`)}),(0,Y.jsxs)(L,{onClick:S,disabled:y||c.length===0,children:[(0,Y.jsx)(Je,{className:`h-4 w-4 mr-1`}),s(`perm.cel.test.run`)]})]})]})})}function uu(e,t){let n;try{n=JSON.parse(e||`{}`)}catch(e){return{ok:!1,error:`${t}: ${e.message}`}}return!n||typeof n!=`object`||Array.isArray(n)?{ok:!1,error:`${t}: expected a JSON object.`}:{ok:!0,value:n}}function du({outcome:e,t}){return e.status===`allow`?(0,Y.jsx)(pu,{tone:`allow`,icon:(0,Y.jsx)(P,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.allow`),children:t(`perm.cel.test.allowHint`)}):e.status===`deny`?(0,Y.jsx)(pu,{tone:`deny`,icon:(0,Y.jsx)(st,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.deny`),children:t(`perm.cel.test.denyHint`)}):e.status===`value`?(0,Y.jsxs)(pu,{tone:`warn`,icon:(0,Y.jsx)(R,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.nonBool`),children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(e.value)}),` — `,t(`perm.cel.test.nonBoolHint`)]}):e.status===`unavailable`?(0,Y.jsx)(pu,{tone:`warn`,icon:(0,Y.jsx)(R,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.unavailable`),children:t(`perm.cel.test.unavailableHint`)}):(0,Y.jsx)(pu,{tone:`error`,icon:(0,Y.jsx)(wt,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.error`),children:(0,Y.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-[11px]`,children:e.message})})}var fu={allow:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,deny:`border-destructive/40 bg-destructive/10 text-destructive`,warn:`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`,error:`border-destructive/40 bg-destructive/10 text-destructive`};function pu({tone:e,icon:t,title:n,children:r}){return(0,Y.jsxs)(`div`,{className:I(`rounded-md border px-3 py-2 text-xs`,fu[e]),role:`status`,"aria-live":`polite`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium`,children:[t,n]}),(0,Y.jsx)(`div`,{className:`mt-1 opacity-90`,children:r})]})}var mu=[`all`,`select`,`insert`,`update`,`delete`],hu=[`visible`,`hidden`,`default_on`,`default_off`];function gu(e){if(Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return[]}function _u(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return{}}var vu=`h-8 rounded-md border border-input bg-background px-2 text-sm disabled:opacity-50`;function yu({title:e,icon:t,count:n,children:r,defaultOpen:i}){let[a,o]=X.useState(!!i);return(0,Y.jsxs)(pr,{open:a,onOpenChange:o,className:`border-b`,children:[(0,Y.jsxs)(Kn,{className:`flex w-full items-center gap-2 px-6 py-2.5 text-left hover:bg-muted/40`,children:[(0,Y.jsx)(Vt,{className:I(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)}),t,(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n!=null&&n>0&&(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px]`,children:n})]}),(0,Y.jsx)(kr,{className:`px-6 pb-4 pt-1`,children:r})]})}function bu({draft:e,setDraft:t,writable:n,allSetNames:r,loadObjectFields:i,onCelErrorsChange:a,t:o}){let s=X.useMemo(()=>gu(e.rowLevelSecurity),[e.rowLevelSecurity]),c=X.useMemo(()=>_u(e.adminScope),[e.adminScope]),l=X.useMemo(()=>_u(e.tabPermissions),[e.tabPermissions]),[u,d]=X.useState({}),f=X.useRef(new Set),p=X.useCallback(e=>{let t=(e??``).trim();!t||t===`*`||!i||f.current.has(t)||(f.current.add(t),i(t).then(e=>d(n=>({...n,[t]:e}))).catch(()=>d(e=>({...e,[t]:[]}))))},[i]),m=e=>u[(e??``).trim()]??[],[h,g]=X.useState({}),_=X.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;g(t=>t[e]===n?t:{...t,[e]:n})},[]),[v,y]=X.useState(null);X.useEffect(()=>{s.forEach(e=>p(e.object)),g(e=>{let t=new Set;s.forEach((e,n)=>{t.add(`${n}:using`),t.add(`${n}:check`)});let n=!1,r={};for(let i of Object.keys(e))t.has(i)?r[i]=e[i]:n=!0;return n?r:e})},[s,p]);let b=X.useMemo(()=>Object.values(h).reduce((e,t)=>e+t,0),[h]),x=X.useRef(a);X.useEffect(()=>{x.current=a}),X.useEffect(()=>{x.current?.(b)},[b]);let S=v==null?void 0:s[v],C=e=>t(t=>({...t,rowLevelSecurity:e})),w=e=>t(t=>({...t,adminScope:{..._u(t.adminScope),...e}})),T=e=>t(t=>({...t,tabPermissions:e})),E=Object.entries(l);return(0,Y.jsxs)(`div`,{className:`border-b bg-muted/10`,children:[(0,Y.jsxs)(yu,{title:o(`perm.rls.title`),icon:(0,Y.jsx)(Ve,{className:`h-4 w-4 text-muted-foreground`}),count:s.length,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.rls.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[s.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2 bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(B,{value:e.name??``,disabled:!n,placeholder:o(`perm.rls.name`),onChange:n=>{let r=[...s];r[t]={...e,name:n.target.value},C(r)},className:`h-8 w-48`}),(0,Y.jsx)(B,{value:e.object??``,disabled:!n,placeholder:o(`perm.rls.object`),onChange:n=>{let r=[...s];r[t]={...e,object:n.target.value},C(r)},className:`h-8 w-40`}),(0,Y.jsx)(`select`,{value:e.operation??`all`,disabled:!n,onChange:n=>{let r=[...s];r[t]={...e,operation:n.target.value},C(r)},className:vu,children:mu.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(Mt,{checked:e.enabled!==!1,disabled:!n,onCheckedChange:n=>{let r=[...s];r[t]={...e,enabled:!!n},C(r)}}),o(`perm.rls.enabled`)]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 ml-auto text-xs text-muted-foreground`,onClick:()=>y(t),title:o(`perm.cel.test.title`),children:[(0,Y.jsx)(Je,{className:`h-3.5 w-3.5 mr-1`}),o(`perm.cel.test.run`)]}),n&&(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>C(s.filter((e,n)=>n!==t)),children:(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(ea,{label:o(`perm.rls.using`),value:e.using??``,disabled:!n,placeholder:`organization_id == current_user.organization_id`,objectName:e.object,fieldNames:m(e.object),clause:`using`,onLintChange:e=>_(`${t}:using`,e),onChange:n=>{let r=[...s];r[t]={...e,using:n},C(r)},t:o}),(0,Y.jsx)(ea,{label:o(`perm.rls.check`),value:e.check??``,disabled:!n,placeholder:o(`perm.rls.checkPlaceholder`),objectName:e.object,fieldNames:m(e.object),clause:`check`,onLintChange:e=>_(`${t}:check`,e),onChange:n=>{let r=[...s];r[t]={...e,check:n},C(r)},t:o})]})]},t)),s.length===0&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.rls.empty`)}),n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>C([...s,{name:``,object:`*`,operation:`all`,using:``,enabled:!0,priority:0}]),children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),` `,o(`perm.rls.add`)]})]})]}),(0,Y.jsx)(lu,{open:v!=null,onOpenChange:e=>y(e?v:null),policyName:S?.name||void 0,objectName:S?.object,fieldNames:m(S?.object),using:S?.using,check:S?.check,t:o}),(0,Y.jsxs)(yu,{title:o(`perm.tabs.title`),icon:(0,Y.jsx)(ar,{className:`h-4 w-4 text-muted-foreground`}),count:E.length,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.tabs.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[E.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(B,{value:e,disabled:!n,onChange:t=>{let n=t.target.value,r={};for(let[t,i]of E)r[t===e?n:t]=i;T(r)},className:`h-8 w-64`}),(0,Y.jsx)(`select`,{value:t,disabled:!n,onChange:t=>T({...l,[e]:t.target.value}),className:vu,children:hu.map(e=>(0,Y.jsx)(`option`,{value:e,children:o(`perm.tabs.vis.${e}`)},e))}),n&&(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>{let t={...l};delete t[e],T(t)},children:(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]},e)),E.length===0&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.tabs.empty`)}),n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>{l[``]===void 0&&T({...l,"":`visible`})},children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),` `,o(`perm.tabs.add`)]})]})]}),(0,Y.jsxs)(yu,{title:o(`perm.admin.title`),icon:(0,Y.jsx)(me,{className:`h-4 w-4 text-muted-foreground`}),count:c.businessUnit||(c.assignablePermissionSets?.length??0)?1:0,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.admin.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:o(`perm.admin.businessUnit`)}),(0,Y.jsx)(B,{value:c.businessUnit??``,disabled:!n,onChange:e=>w({businessUnit:e.target.value}),className:`h-8 w-64`})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs pb-1.5`,children:[(0,Y.jsx)(Mt,{checked:!!c.includeSubtree,disabled:!n,onCheckedChange:e=>w({includeSubtree:!!e})}),o(`perm.admin.includeSubtree`)]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[[`manageAssignments`,`perm.admin.manageAssignments`],[`manageBindings`,`perm.admin.manageBindings`],[`authorEnvironmentSets`,`perm.admin.authorEnvironmentSets`]].map(([e,t])=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(Mt,{checked:!!c[e],disabled:!n,onCheckedChange:t=>w({[e]:!!t})}),o(t)]},e))}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:o(`perm.admin.assignableSets`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[r.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o(`perm.admin.noSets`)}),r.map(e=>{let t=(c.assignablePermissionSets??[]).includes(e);return(0,Y.jsx)(`button`,{type:`button`,disabled:!n,"aria-pressed":t,onClick:()=>{let n=c.assignablePermissionSets??[],r=t?n.filter(t=>t!==e):[...n,e];w({assignablePermissionSets:r})},className:I(`rounded-full border px-3 py-1 text-xs transition-colors disabled:opacity-50`,t?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:e},e)})]})]})]})]})]})}function xu(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Su(e){return e instanceof Set?e:new Set(e)}function Cu(e,t){let n=Su(t),r={};for(let[t,i]of Object.entries(e.objects??{}))n.has(t)&&(r[t]=i);let i={};for(let[t,r]of Object.entries(e.fields??{}))n.has(xu(t))&&(i[t]=r);return{objects:r,fields:i}}function wu(e,t,n){let r=Su(n),i={};for(let[t,n]of Object.entries(e.objects??{}))r.has(t)||(i[t]=n);for(let[e,n]of Object.entries(t.objects??{}))r.has(e)&&(i[e]=n);let a={};for(let[t,n]of Object.entries(e.fields??{}))r.has(xu(t))||(a[t]=n);for(let[e,n]of Object.entries(t.fields??{}))r.has(xu(e))&&(a[e]=n);return{...e,name:t.name,label:t.label,isDefault:t.isDefault,objects:i,fields:a}}function Tu(e,t){let n={private:`perm.owd.private`,public_read:`perm.owd.public_read`,public_read_write:`perm.owd.public_read_write`,controlled_by_parent:`perm.owd.controlled_by_parent`};return n[t]?e(n[t]):t}function Eu(e){return[{key:`allowCreate`,short:`C`,tip:G(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:G(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:G(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:G(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:G(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:G(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:G(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:G(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:G(`perm.action.modifyAll`,e)}]}function Du({type:e,name:t,packageId:n,onDraftSaved:r,publishNonce:a,onOpenOwd:o,onDirtyChange:s,readOnly:c=!1,embedded:l=!1}){let u=i(),d=Ai(),f=S(),{entries:p}=Mi(d),m=p.find(t=>t.type===e),h=!!xc(e,m).allowOrgOverride&&!c,g=Ti(),_=X.useCallback(e=>G(e,g),[g]),v=X.useMemo(()=>Eu(g),[g]),[y,b]=X.useState({name:t,objects:{},fields:{}}),x=X.useRef(null),C=X.useCallback(e=>{try{x.current=JSON.stringify(e)}catch{x.current=null}b(e)},[]),[w,T]=X.useState([]),[E,D]=X.useState({}),[O,k]=X.useState(new Set),[A,ee]=X.useState(!0),[j,te]=X.useState(!1),[ne,M]=X.useState(null),[N,ie]=X.useState(null),[ae,oe]=X.useState(``),[se,P]=X.useState(!1),[ce,le]=X.useState(!1),[ue,de]=X.useState(!1),[F,fe]=X.useState(!1),[pe,me]=X.useState([]);X.useEffect(()=>{let e=!1;return d.list(`permission`,{}).then(t=>{e||me((t||[]).map(e=>e?.name).filter(e=>!!e))}).catch(()=>{}),()=>{e=!0}},[d]),X.useEffect(()=>{let r=!1;return ee(!0),(async()=>{try{let[i,a,o]=await Promise.all([d.layered(e,t).catch(()=>null),d.list(`object`,n?{packageId:n}:{}).catch(()=>[]),n?d.getDraft(e,t,{packageId:n}).catch(()=>null):Promise.resolve(null)]);if(r)return;let s=(o?o.item??o:null)??i?.effective??i?.code??{name:t,objects:{}},c=(a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label,accessDefault:t?.access?.default,owd:typeof t?.sharingModel==`string`?t.sharingModel:void 0,owdExternal:typeof t?.externalSharingModel==`string`?t.externalSharingModel:void 0}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));T(c);let l={...s,name:String(s?.name??t),objects:s?.objects??{},fields:s?.fields??{}};if(n){let e=Cu(l,c.map(e=>e.name));C({...l,objects:e.objects,fields:e.fields})}else C(l)}catch(e){M(e?.message??String(e))}finally{r||ee(!1)}})(),()=>{r=!0}},[d,e,t,n,a,C]);async function he(e){if(!E[e])try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>({name:String(e?.name??``),label:e?.label})):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>({name:String(t?.name??e),label:t?.label})):[]).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));D(t=>({...t,[e]:n}))}catch{D(t=>({...t,[e]:[]}))}}let ge=X.useCallback(async e=>{try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>String(e?.name??``)):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>String(t?.name??e)):[]).filter(Boolean);return Array.from(new Set(n)).sort((e,t)=>e.localeCompare(t))}catch{return[]}},[d]),[_e,ve]=X.useState(0),ye=X.useMemo(()=>{let e=x.current;if(e==null)return!1;try{return JSON.stringify(y)!==e}catch{return!1}},[y]),be=X.useRef(s);X.useEffect(()=>{be.current=s}),X.useEffect(()=>{be.current?.(ye)},[ye]),X.useEffect(()=>()=>{be.current?.(!1)},[]),X.useEffect(()=>{if(!ye)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ye]);function xe(e){k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),he(e)),n})}function Se(e,t,n){b(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function Ce(e,t){b(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(v.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function we(e,t,n,r){let i=`${e}.${t}`;b(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}function Te(e,t,n){n.length!==0&&b(r=>{let i={...r.fields??{}};for(let r of n){let n=`${e}.${r}`;t===`clear`?delete i[n]:t===`readable`?i[n]={readable:!0,editable:!1}:i[n]={readable:!0,editable:!0}}return{...r,fields:i}})}function Ee(e){if(!n)return e;let t=Cu(e,w.map(e=>e.name));return{...e,objects:t.objects,fields:t.fields}}async function De(t,i){let a=i??y;te(!0),M(null);try{let i=a;if(n){let t=w.map(e=>e.name);i=wu((await d.layered(e,a.name).catch(()=>null))?.effective??a,a,t)}if(await d.save(e,a.name,i,{force:t,...n?{mode:`draft`,packageId:n}:{}}),n)C(Ee(i)),r?.();else{let t=await d.layered(e,a.name);C(Ee(t.effective??i))}ie(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];ie({issues:Array.isArray(t)?t:[],pending:a})}else M(e?.message??String(e))}finally{te(!1)}}let Oe=X.useMemo(()=>{let e=ae.trim().toLowerCase();return w.filter(t=>{if(se){let e=y.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return!e||t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)})},[w,ae,se,y.objects]),ke=[{label:_(`perm.stat.objectsGranted`),value:Object.values(y.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:_(`perm.stat.fieldOverrides`),value:Object.keys(y.fields??{}).length}];return A?(0,Y.jsx)(fc,{entry:m,itemName:t,embedded:l,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` `,_(`perm.loading`).replace(`{name}`,t)]})}):(0,Y.jsxs)(fc,{entry:m??{type:e,label:e},itemName:t,subtitle:_(`perm.subtitle.set`),stats:ke,embedded:l,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>l?fe(!0):u(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(Wr,{className:`h-4 w-4 mr-1`}),` `,_(`engine.edit.history`)]}),h&&(0,Y.jsxs)(L,{size:`sm`,onClick:()=>De(!1),disabled:j||_e>0,title:_e>0?_(`perm.cel.saveBlocked`):void 0,children:[j?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(ai,{className:`h-4 w-4 mr-1`}),_(`engine.edit.save`)]})]}),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[ne&&(0,Y.jsxs)(`div`,{className:`m-4 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive flex items-start gap-2`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:ne})]}),(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>le(e=>!e),"aria-expanded":ce,className:`w-full px-6 py-2.5 flex items-center gap-2 text-left hover:bg-muted/50 transition-colors`,children:[ce?(0,Y.jsx)(Ke,{className:`h-4 w-4 shrink-0 text-muted-foreground`}):(0,Y.jsx)(Vt,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:y.label||y.name}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] shrink-0`,children:y.managedBy===`platform`?_(`perm.badge.platform`):y.managedBy===`package`||n?_(`perm.badge.package`):_(`perm.badge.custom`)}),!!y.isDefault&&(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px] shrink-0`,children:_(`perm.badge.default`)}),h&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:_(`perm.basics.editHint`)}),!h&&(0,Y.jsx)(z,{variant:`secondary`,className:`ml-auto shrink-0`,title:c?_(`engine.studio.pkg.readonlyHint`):void 0,children:_(c?`engine.studio.pkg.readonly`:`perm.readOnly`)})]}),ce&&(0,Y.jsxs)(`div`,{className:`px-6 pb-3 flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{htmlFor:`perm-name`,className:`text-xs`,children:_(`perm.field.name`)}),(0,Y.jsx)(B,{id:`perm-name`,value:y.name,disabled:!h,onChange:e=>b(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{htmlFor:`perm-label`,className:`text-xs`,children:_(`perm.field.label`)}),(0,Y.jsx)(B,{id:`perm-label`,value:y.label??``,disabled:!h,onChange:e=>b(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]})]})]}),h&&(y.systemPermissions??[]).length===0&&!ue?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:_(`perm.field.systemCapabilities`)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:_(`perm.cap.none`)}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>de(!0),children:[`+ `,_(`perm.cap.add`)]})]}):(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:_(`perm.field.systemCapabilities`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 mb-2`,children:_(`perm.field.systemCapabilitiesHelp`)}),(0,Y.jsx)(at,{value:JSON.stringify(y.systemPermissions??[]),onChange:e=>b(t=>({...t,systemPermissions:Qn(e)})),field:{name:`system_permissions`},dataSource:f,readonly:!h})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,Y.jsx)(B,{placeholder:_(`perm.filter.placeholder`),value:ae,onChange:e=>oe(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Mt,{id:`only-enabled`,checked:se,onCheckedChange:e=>P(!!e)}),(0,Y.jsx)(U,{htmlFor:`only-enabled`,className:`text-xs`,children:_(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[Oe.length,` / `,w.length,` `,_(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`px-6 py-2 border-b flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:v.map(e=>(0,Y.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:e.short}),` `,e.tip]},e.key))}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[(0,Y.jsx)(Ou,{objects:Oe,draft:y,expanded:O,fieldsByObject:E,writable:h,objectActions:v,t:_,onToggleExpand:xe,onObjectPerm:Se,onFieldPerm:we,onBulkSet:Ce,onFieldBulk:Te,onOpenOwd:o}),(0,Y.jsx)(bu,{draft:y,setDraft:b,writable:h,allSetNames:pe,loadObjectFields:ge,onCelErrorsChange:ve,t:_})]})]}),(0,Y.jsx)(Ut,{open:!!N,onOpenChange:e=>!e&&ie(null),children:(0,Y.jsxs)(Qt,{children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 text-amber-500`}),` `,_(`engine.edit.destructive`)]}),(0,Y.jsx)(vt,{children:_(`engine.edit.destructiveHint`)})]}),(0,Y.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:N?.issues.map((e,t)=>(0,Y.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,Y.jsx)(z,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Y.jsxs)(re,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>ie(null),children:_(`engine.cancel`)}),(0,Y.jsxs)(L,{variant:`destructive`,onClick:()=>N&&De(!0,N.pending),disabled:j,children:[j&&(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}),_(`engine.edit.forceSave`)]})]})]})}),l&&(0,Y.jsx)(wr,{open:F,onOpenChange:fe,children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:_(`engine.edit.history`)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:F&&(0,Y.jsx)(Zc,{type:e,name:t,client:d})})]})})]})}function Ou({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u,onFieldBulk:d,onOpenOwd:f}){return(0,Y.jsxs)(`table`,{className:`w-full min-w-[960px] text-sm`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,Y.jsxs)(`tbody`,{children:[e.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-4 py-8 text-center text-muted-foreground`,children:o(`perm.filter.empty`)})}),e.map(e=>{let p=t.objects[e.name]??{},m=n.has(e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 align-middle`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[m?(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Vt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]}),e.accessDefault===`private`&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 border-amber-500/50 text-amber-600 dark:text-amber-400 text-[10px] px-1.5 py-0 align-middle`,title:o(`perm.posture.private.tip`),children:o(`perm.posture.private`)}),(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`+(f?` cursor-pointer hover:text-foreground hover:border-foreground/40 focus:outline-none focus:ring-1 focus:ring-primary`:``),title:o(f?`perm.owd.editLink`:`perm.owd.tip`),...f?{role:`button`,tabIndex:0,"data-testid":`owd-badge-${e.name}`,onClick:()=>f(e.name),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),f(e.name))}}:{},children:`OWD ${e.owd?Tu(o,e.owd):o(`perm.owd.defaultPrivate`)}`}),e.owdExternal&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-1 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`,title:o(`perm.owd.ext.tip`),children:`Ext ${Tu(o,e.owdExternal)}`})]}),a.map(t=>(0,Y.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,Y.jsx)(un,{checked:!!p[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`read`),children:o(`perm.bulk.read`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`crud`),children:o(`perm.bulk.crud`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`all`),children:o(`perm.bulk.all`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),m&&(0,Y.jsx)(`tr`,{className:`bg-muted/10`,children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,Y.jsx)(ku,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l,onFieldBulk:d})})})]},e.name)})]})]})}function ku({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a,onFieldBulk:o}){let[s,c]=X.useState(``);if(!t)return(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]});if(t.length===0)return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)});let l=s.trim().toLowerCase(),u=l?t.filter(e=>e.name.toLowerCase().includes(l)||(e.label??``).toLowerCase().includes(l)):t,d=u.map(e=>e.name);return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t.length>6&&(0,Y.jsx)(B,{value:s,onChange:e=>c(e.target.value),placeholder:i(`perm.field.filter`),"aria-label":i(`perm.field.filter`),className:`h-7 w-44 text-xs`}),r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`readable`,d),children:i(`perm.field.bulk.readable`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`writable`,d),children:i(`perm.field.bulk.writable`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`clear`,d),children:i(`perm.field.bulk.clear`)})]}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[u.length,` / `,t.length]})]}),u.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.filterEmpty`)}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,Y.jsx)(`tbody`,{children:u.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,Y.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,Y.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(un,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(un,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]})]})}function Au(){vc({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>ju(e.fields),groupLabel:`Fields`,order:5}]}),vc({type:`__object_index`,label:`Index`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`index`,embeddedPath:`indexes`,extract:e=>{let t=e.indexes;return Array.isArray(t)?t.map((e,t)=>{let n=Array.isArray(e.fields)?e.fields.join(`,`):``;return{name:n?`idx_${n}`:`index_${t}`,...e}}):[]},groupLabel:`Indexes`,order:10}]}),vc({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>ju(e.validations),groupLabel:`Embedded Validations`,order:15}]}),vc({type:`hook`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable hook name.`},name:{type:`string`,title:`Name`,description:`Hook key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object whose row lifecycle (beforeInsert / afterUpdate / …) this hook runs on.`},description:{type:`string`,title:`Description`,description:`What this hook does.`}}},createDefaults:{events:[]}}),vc({type:`page`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`object`,`type`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`type`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable page title.`},name:{type:`string`,title:`Name`,description:`Page key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},type:{type:`string`,title:`Page type`,enum:[`list`,`record`,`home`,`app`,`utility`],default:`list`,description:`List / Interface page = a data view (Airtable-style: columns, filters, visualizations). Record page renders one object record.`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this page reads from — the data source for a list page, or the record object for a record page.`},kind:{type:`string`,title:`Kind`,enum:[`full`,`slotted`],default:`full`,description:`full = the whole page; slotted = override only named slots of the default.`}}},createDefaults:{type:`list`,kind:`full`,regions:[]},createSeed:async(e,{client:t})=>{if(e?.type===`list`)return e?.object?{interfaceConfig:{source:String(e.object)}}:{};if(e?.type!==`record`||!e?.object)return{};try{let n=await t.get(`object`,String(e.object));if(!n||typeof n!=`object`)return{};let{buildDefaultPageSchema:r}=await a(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-Bi6X55Wz.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),i=r(n),o={};return Array.isArray(i?.regions)&&i.regions.length&&(o.regions=i.regions),i?.template&&(o.template=i.template),o}catch{return{}}}}),vc({type:`view`,anchors:[{anchorType:`object`,match:gc([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`viewKind`,`kind`,`formType`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`viewKind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`View key (snake_case). Qualified to <object>.<key> on save.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this view displays.`},viewKind:{type:`string`,title:`View family`,enum:[`list`,`form`],default:`list`,description:`List views show many records as a collection (grid, kanban, …). Form views show one record as a field layout (simple, tabbed, …).`},kind:{type:`string`,title:`List layout`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'list'`},formType:{type:`string`,title:`Form layout`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`],default:`simple`,description:`Pick a starter form layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'form'`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``),r=n.includes(`.`)||!t?n:`${t}.${n}`,i=e.viewKind===`form`,a=i?{type:e.formType||`simple`,data:{provider:`object`,object:t},sections:[]}:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}};return{name:r,object:t,viewKind:i?`form`:`list`,label:e.label,config:a}}}),vc({type:`flow`,anchors:[{anchorType:`object`,match:gc([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`autolaunched`,nodes:[],edges:[]}}),vc({type:`validation`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Validations`,order:25}],createFields:[`label`,`name`,`message`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`message`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable rule name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},message:{type:`string`,title:`Error message`,description:`Shown to the user when the rule blocks save.`}}},createDefaults:{type:`script`,active:!0,events:[`insert`,`update`],priority:10,severity:`error`,condition:`false`}}),vc({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}],createFields:[`label`,`name`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),vc({type:`action`,anchors:[{anchorType:`object`,match:gc([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable action name.`},name:{type:`string`,title:`Name`,description:`Action key (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},objectName:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this action is bound to. Leave empty for a global / record-scoped action.`},icon:{type:`string`,title:`Icon`,widget:`icon`,description:`Optional icon shown on the action button.`}}},createDefaults:{type:`script`,body:{language:`js`,source:`return { success: true };`}}}),vc({type:`dashboard`,anchors:[{anchorType:`object`,match:gc([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),vc({type:`report`,anchors:[{anchorType:`object`,match:gc([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`summary`,drilldown:!0}}),vc({type:`object`,iconName:`database`,domain:`data`,createFields:[`label`,`pluralLabel`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0},{from:`label`,to:`pluralLabel`,transform:`plural-en`,untilUserEdits:!0}],createDefaults:{fields:{}},searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function ju(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Mu={name:{type:`string`,title:`Name`,description:`Machine name. snake_case, used as the URL path and DB key.`,pattern:`^[a-z_][a-z0-9_]*$`},label:{type:`string`,title:`Label`,description:`Human-readable display name.`},description:{type:`string`,title:`Description`,format:`multiline`}},Nu={position:{type:`object`,title:`Position`,required:[`name`],properties:{...Mu}},permission:{type:`object`,title:`Permission`,required:[`id`,`resource`,`actions`,`description`],properties:{id:{type:`string`,title:`ID`,description:`Stable identifier (e.g. crm.account.read).`},resource:{type:`string`,title:`Resource`,description:`What this permission applies to.`,enum:[`data.object`,`data.record`,`data.field`,`ui.view`,`ui.dashboard`,`ui.report`,`system.config`,`system.plugin`,`system.api`,`system.service`,`storage.file`,`storage.database`,`network.http`,`network.websocket`,`process.spawn`,`process.env`]},actions:{type:`array`,title:`Actions`,description:`Permitted operations on the resource.`,items:{type:`string`,enum:[`create`,`read`,`update`,`delete`,`execute`,`admin`,`manage`,`configure`,`import`,`export`,`share`]}},description:{type:`string`,title:`Description`,description:`Why this permission exists (shown in admin UIs).`},scope:{type:`string`,title:`Scope`,enum:[`tenant`,`user`,`plugin`,`global`,`resource`],default:`tenant`},required:{type:`boolean`,title:`Required`,description:`Must be present for the holder to function.`},justification:{type:`string`,title:`Justification`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...Mu.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Mu.label,description:Mu.description,locale:{type:`string`,title:`Locale`,description:`BCP-47 tag, e.g. en, zh-Hans, ja-JP.`},strings:{type:`object`,title:`Strings`,description:`Key → translated string map.`}}},tool:{type:`object`,title:`AI Tool`,required:[`name`],properties:{...Mu,kind:{type:`string`,title:`Kind`,enum:[`function`,`http`,`mcp`]},inputSchema:{type:`object`,title:`Input Schema (JSON Schema)`},outputSchema:{type:`object`,title:`Output Schema (JSON Schema)`}}},skill:{type:`object`,title:`AI Skill`,required:[`name`],properties:{...Mu,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}},surface:{type:`string`,title:`Surface`,description:`Agent surface this skill binds to (ADR-0063).`,enum:[`ask`,`build`,`both`]},triggerPhrases:{type:`array`,title:`Trigger Phrases`,description:`Natural-language phrases that activate this skill.`,items:{type:`string`}},triggerConditions:{type:`array`,title:`Trigger Conditions`,description:`Programmatic activation conditions (context field / operator / value). The activation-critical field — previously only hand-editable (#1878/#1895).`,items:{type:`object`,properties:{field:{type:`string`,title:`Field`},operator:{type:`string`,title:`Operator`,enum:[`eq`,`neq`,`in`,`not_in`,`contains`]},value:{type:`string`,title:`Value`}}}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Mu,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Mu,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Mu,type:{type:`string`,title:`View Type`,enum:[`grid`,`kanban`,`calendar`,`gantt`,`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]}}},dashboard:{type:`object`,title:`Dashboard`,required:[`name`],properties:{...Mu,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Mu,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...Mu,slug:{type:`string`,title:`Slug`,description:`Portal URL segment; defaults to the name without its package prefix.`},icon:{type:`string`,title:`Icon`},order:{type:`number`,title:`Order`,description:`Orders books within the portal.`},audience:{title:`Audience`,description:`Access audience. 'org' (default) inherits the package grant; 'public' is anonymously readable; { permissionSet } gates by a permission set the reader must hold (ADR-0090).`,oneOf:[{type:`string`,enum:[`org`,`public`]},{type:`object`,title:`Permission-set gated`,properties:{permissionSet:{type:`string`,title:`Permission set`}},required:[`permissionSet`]}]},groups:{type:`array`,title:`Groups (spine)`,description:`Ordered sections. Membership is derived from each group's include rule — edit the structure visually in the Preview tab.`,items:{type:`object`,required:[`key`,`label`],properties:{key:{type:`string`,title:`Key`,pattern:`^[a-z][a-z0-9_]*$`},label:{type:`string`,title:`Label`},order:{type:`number`,title:`Order`},include:{title:`Include rule`,description:`Glob over doc names (e.g. crm_guide_*) or { tag }.`},package:{type:`string`,title:`Package scope`},pages:{type:`array`,title:`Explicit pages (override)`,items:{}}}}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...Mu,category:{type:`string`,title:`Category`,enum:[`auth`,`notification`,`workflow`,`marketing`,`custom`],default:`custom`},locale:{type:`string`,title:`Locale`,default:`en-US`,description:`BCP-47 tag (en-US, zh-CN, …)`},subject:{type:`string`,title:`Subject`,description:`Supports {{var.path}} interpolation`},bodyHtml:{type:`string`,title:`HTML Body`,format:`multiline`},bodyText:{type:`string`,title:`Plain-Text Body`,format:`multiline`},variables:{type:`array`,title:`Variables`,items:{type:`object`}},fromOverride:{type:`object`,title:`From Override`},replyTo:{type:`string`,title:`Reply-To`},active:{type:`boolean`,title:`Active`,default:!0},isSystem:{type:`boolean`,title:`System Template`,default:!1}}}};function Pu(){for(let[e,t]of Object.entries(Nu))vc({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}var Fu=[{value:`managed`,label:`Managed (ObjectStack owns the schema)`},{value:`external`,label:`External (read existing schema as-is)`},{value:`validate-only`,label:`Validate only`}],Iu=``.replace(/\/+$/,``),Lu=e=>e.format===`password`;function Ru(e){let t=e?.configSchema?.properties??{},n={};for(let[e,r]of Object.entries(t))Lu(r)||r.default!==void 0&&(n[e]=r.default);return n}function zu(e){let t=X.useMemo(()=>d(),[]),n=Ai(),[r,i]=X.useState([]),[a,o]=X.useState(!0),[s,c]=X.useState(null),l=X.useCallback(async(e,n)=>{let r=await t(`${Iu}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`},...n}),i=await r.text(),a=i;try{a=JSON.parse(i)}catch{}if(!r.ok)throw Error(a&&(a.message||a.error)||`HTTP ${r.status}`);return a},[t]),u=X.useCallback(async()=>{o(!0);try{let e=await l(`/api/v1/datasources`);i(Array.isArray(e?.datasources)?e.datasources:[])}catch(e){si.error(`Load datasources: ${e.message}`),i([])}finally{o(!1)}},[l]);X.useEffect(()=>{u()},[u]);let f=async e=>{c(`test:${e}`);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/test`,{method:`POST`,body:`{}`});si.success(t?.ok===!1?`${e}: ${t?.error??`failed`}`:`${e}: connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`),u()}catch(t){si.error(`${e}: ${t.message}`)}finally{c(null)}},p=async e=>{if(window.confirm(`Delete datasource “${e}”? This cannot be undone.`)){c(`del:${e}`);try{await l(`/api/v1/datasources/${encodeURIComponent(e)}`,{method:`DELETE`}),si.success(`Deleted ${e}.`),u()}catch(t){si.error(`Delete ${e}: ${t.message}`)}finally{c(null)}}},[m,h]=X.useState([]),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState(null),[S,C]=X.useState(!1),[w,T]=X.useState(!1),[E,D]=X.useState(null),[O,k]=X.useState(!1),A=X.useCallback(async()=>{if(m.length)return m;try{let e=await l(`/api/v1/datasources/drivers`),t=Array.isArray(e?.drivers)?e.drivers:[];return h(t),t}catch(e){return si.error(`Load drivers: ${e.message}`),[]}},[l,m]),ee=X.useMemo(()=>m.find(e=>e.id===b?.driver),[m,b?.driver]),j=async()=>{let e=await A(),t=e.find(e=>e.id!==`memory`)??e[0];y(null),C(!1),D(null),x({name:``,label:``,driver:t?.id??``,schemaMode:`managed`,config:Ru(t),secret:``}),_(!0)},te=async e=>{let t=await A();c(`edit:${e.name}`);try{let n=(await l(`/api/v1/datasources/${encodeURIComponent(e.name)}`))?.datasource??{};y(e.name),C(!!n.hasSecret),D(null),x({name:n.name??e.name,label:n.label??``,driver:n.driver??e.driver??t[0]?.id??``,schemaMode:n.schemaMode??`managed`,config:{...n.config??{}},secret:``}),_(!0)}catch(t){si.error(`Open ${e.name}: ${t.message}`)}finally{c(null)}},ne=e=>{x(t=>t&&{...t,driver:e,config:Ru(m.find(t=>t.id===e)),secret:``}),D(null)},M=(e,t)=>x(n=>n&&{...n,config:{...n.config,[e]:t}}),N=e=>{let t={label:e.label||void 0,driver:e.driver,schemaMode:e.schemaMode,config:e.config};return e.secret&&(t.secret=e.secret),t},ie=async()=>{if(b){k(!0),D(null);try{let e=await l(`/api/v1/datasources/test`,{method:`POST`,body:JSON.stringify({driver:b.driver,config:b.config,...b.secret?{secret:b.secret}:{}})}),t=e?.result??e;t?.ok===!1?D({ok:!1,text:t?.error??`Connection failed`}):D({ok:!0,text:`Connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`})}catch(e){D({ok:!1,text:e.message})}finally{k(!1)}}},ae=async()=>{if(b){T(!0);try{v?(await l(`/api/v1/datasources/${encodeURIComponent(v)}`,{method:`PATCH`,body:JSON.stringify(N(b))}),si.success(`Updated ${v}.`)):(await l(`/api/v1/datasources`,{method:`POST`,body:JSON.stringify({name:b.name,...N(b)})}),si.success(`Created ${b.name}.`)),_(!1),u()}catch(e){si.error(`Save: ${e.message}`)}finally{T(!1)}}},se=v?!0:/^[a-z_][a-z0-9_]*$/.test(b?.name??``),P=!!b&&!!b.driver&&se&&!w,[ce,le]=X.useState(null),[ue,de]=X.useState(null),[F,fe]=X.useState(new Set),[pe,me]=X.useState(!1),he=async e=>{le(e),de(null),fe(new Set);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/remote-tables`);de(Array.isArray(t?.tables)?t.tables:[])}catch(t){si.error(`Introspect ${e}: ${t.message}`),de([])}},ge=e=>fe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),_e=async()=>{if(!ce||F.size===0)return;me(!0);let e=0,t=[];for(let r of F)try{let{draft:t}=await l(`/api/v1/datasources/${encodeURIComponent(ce)}/object-draft`,{method:`POST`,body:JSON.stringify({table:r})});await n.save(`object`,t.name,t.definition),e+=1}catch(e){t.push(`${r}: ${e.message}`)}me(!1),e&&si.success(`Synced ${e} object${e>1?`s`:``} from ${ce}.`),t.length&&si.error(`Failed: ${t.join(`; `)}`),le(null)},ve=(e,t)=>{let n=t.title||e,r=(ee?.configSchema?.required??[]).includes(e);if(Lu(t))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r&&!v?` *`:``]}),(0,Y.jsx)(B,{type:`password`,value:b?.secret??``,placeholder:v&&S?`•••••••• (leave blank to keep)`:``,onChange:e=>x(t=>t&&{...t,secret:e.target.value})}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e);let i=b?.config[e];if(t.type===`boolean`)return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(U,{className:`text-xs`,children:n}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]}),(0,Y.jsx)(Mt,{checked:!!i,onCheckedChange:t=>M(e,t)})]},e);if(Array.isArray(t.enum))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsxs)(oe,{value:i==null?``:String(i),onValueChange:t=>M(e,t),children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{placeholder:`Select…`})}),(0,Y.jsx)(En,{children:t.enum.map(e=>(0,Y.jsx)(Pr,{value:String(e),children:String(e)},String(e)))})]})]},e);let a=t.type===`number`||t.type===`integer`;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsx)(B,{type:a?`number`:`text`,value:i==null?``:String(i),onChange:t=>M(e,a?t.target.value===``?void 0:Number(t.target.value):t.target.value)}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e)};return(0,Y.jsxs)(`div`,{className:`mx-auto max-w-4xl px-6 py-8`,children:[(0,Y.jsxs)(`div`,{className:`mb-6 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold`,children:[(0,Y.jsx)(ir,{className:`h-5 w-5`}),` Datasources`]}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Connect external databases and sync their tables in as objects.`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:a,children:[(0,Y.jsx)(qt,{className:`mr-1.5 h-4 w-4`+(a?` animate-spin`:``)}),` Refresh`]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>void j(),children:[(0,Y.jsx)(H,{className:`mr-1.5 h-4 w-4`}),` New datasource`]})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading…`]}):r.length===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed bg-muted/20 py-16 text-center text-sm text-muted-foreground`,children:[`No datasources yet. Click `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`New datasource`}),` to connect one.`]}):(0,Y.jsx)(`div`,{className:`divide-y rounded-lg border bg-card`,children:r.map(e=>{let t=e.origin===`code`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-[11px] text-muted-foreground`,children:e.name})]}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:e.driver}),e.status&&(0,Y.jsxs)(`span`,{children:[`· `,e.status]}),e.origin&&(0,Y.jsxs)(`span`,{children:[`· `,e.origin]})]})]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,disabled:s===`test:${e.name}`,onClick:()=>void f(e.name),children:[s===`test:${e.name}`?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Un,{className:`mr-1.5 h-4 w-4`}),` Test`]}),(0,Y.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>void he(e.name),children:[(0,Y.jsx)(zr,{className:`mr-1.5 h-4 w-4`}),` Sync objects`]}),!t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,title:`Edit`,disabled:s===`edit:${e.name}`,onClick:()=>void te(e),children:s===`edit:${e.name}`?(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Rr,{className:`h-4 w-4`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,title:`Delete`,disabled:s===`del:${e.name}`,onClick:()=>void p(e.name),children:s===`del:${e.name}`?(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]})]},e.name)})}),(0,Y.jsx)(Ut,{open:g,onOpenChange:e=>{e||_(!1)},children:(0,Y.jsxs)(Qt,{className:`max-w-lg`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsx)(Fr,{children:v?`Edit “${v}”`:`New datasource`}),(0,Y.jsx)(vt,{children:v?`Update the connection. Leave the credential blank to keep the current one.`:`Connect an external database. Credentials are encrypted and never stored in metadata.`})]}),b&&(0,Y.jsxs)(`div`,{className:`max-h-[60vh] space-y-3 overflow-y-auto pr-1`,children:[!v&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Name *`}),(0,Y.jsx)(B,{value:b.name,placeholder:`my_database`,onChange:e=>x(t=>t&&{...t,name:e.target.value})}),!se&&b.name.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,children:`Lowercase letters, digits, and underscores; must not start with a digit.`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Label`}),(0,Y.jsx)(B,{value:b.label,placeholder:`Human-friendly name`,onChange:e=>x(t=>t&&{...t,label:e.target.value})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Driver *`}),(0,Y.jsxs)(oe,{value:b.driver,onValueChange:ne,disabled:!!v,children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{placeholder:`Choose a driver`})}),(0,Y.jsx)(En,{children:m.map(e=>(0,Y.jsx)(Pr,{value:e.id,children:e.label},e.id))})]}),ee?.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:ee.description})]}),Object.entries(ee?.configSchema?.properties??{}).map(([e,t])=>ve(e,t)),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Schema mode`}),(0,Y.jsxs)(oe,{value:b.schemaMode,onValueChange:e=>x(t=>t&&{...t,schemaMode:e}),children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{})}),(0,Y.jsx)(En,{children:Fu.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})]}),E&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs `+(E.ok?`text-emerald-600`:`text-destructive`),children:[E.ok?(0,Y.jsx)(Ce,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ye,{className:`h-3.5 w-3.5`}),E.text]})]}),(0,Y.jsxs)(re,{className:`gap-2 sm:justify-between`,children:[(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,disabled:!b?.driver||O,onClick:()=>void ie(),children:[O?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Un,{className:`mr-1.5 h-4 w-4`}),` Test connection`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,Y.jsxs)(L,{size:`sm`,disabled:!P,onClick:()=>void ae(),children:[w&&(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}),v?`Save changes`:`Create datasource`]})]})]})]})}),(0,Y.jsx)(Ut,{open:!!ce,onOpenChange:e=>{e||le(null)},children:(0,Y.jsxs)(Qt,{className:`max-w-lg`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{children:[`Sync objects from “`,ce,`”`]}),(0,Y.jsx)(vt,{children:`Pick the remote tables to import as objects. Each becomes an object definition.`})]}),ue==null?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Introspecting…`]}):ue.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No remote tables found on this datasource.`}):(0,Y.jsx)(`div`,{className:`max-h-[50vh] space-y-1 overflow-y-auto`,children:ue.map(e=>{let t=e.schema?`${e.schema}.${e.name}`:e.name;return(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:F.has(e.name),onChange:()=>ge(e.name),className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:t}),e.columnCount!=null&&(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.columnCount,` cols`]})]},t)})}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>le(null),children:`Cancel`}),(0,Y.jsxs)(L,{size:`sm`,disabled:pe||F.size===0,onClick:()=>void _e(),children:[pe?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(zr,{className:`mr-1.5 h-4 w-4`}),`Create `,F.size||``,` object`,F.size===1?``:`s`]})]})]})})]})}var Bu=!1;function Vu(){Bu||(Bu=!0,vc({type:`datasource`,label:`Datasources`,domain:`data`,ListPage:zu}))}function Z({toolbar:e,children:t}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,Y.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function Hu({tone:e=`info`,children:t}){return(0,Y.jsxs)(`div`,{className:`m-4 rounded border p-3 text-sm flex items-start gap-2 ${e===`warn`?`text-amber-800 bg-amber-50 border-amber-200`:e===`error`?`text-destructive bg-destructive/5 border-destructive/30`:`text-muted-foreground border-muted`}`,children:[e!==`info`&&(0,Y.jsx)(wt,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function Uu({icon:e,title:t,description:n,action:r,tone:i=`info`}){let a=i===`warn`?`text-amber-700 bg-amber-50/40 border-amber-200/60`:`text-muted-foreground border-dashed border-muted-foreground/25 bg-muted/10`,o=e??(0,Y.jsx)(br,{className:`h-8 w-8 opacity-50`});return(0,Y.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,Y.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border ${a} px-6 py-10 flex flex-col items-center gap-3 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,Y.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,Y.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Q=class extends X.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,Y.jsxs)(Hu,{tone:`error`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,Y.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,Y.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function Wu({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:I(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var Gu=X.lazy(async()=>({default:(await a(()=>import(`./dist-B4b49_J4.js`).then(e=>e.n),[],import.meta.url)).default}));function Ku(e){let t=e.languages.typescript;t.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.typescriptDefaults.setCompilerOptions({jsx:t.JsxEmit.React,target:t.ScriptTarget.Latest,allowNonTsExtensions:!0,allowJs:!0,noEmit:!0})}function qu({draft:e,onPatch:t,readOnly:n,fallbackDelayMs:r=4e3,mode:i=`split`}){let a=e.kind===`react`?`react`:`html`,o=typeof e.source==`string`?e.source:``,[s,c]=X.useState(o),l=X.useRef(o);X.useEffect(()=>{o!==l.current&&(c(o),l.current=o)},[o]);let[u,d]=Ol(r),[f,p]=X.useState(()=>typeof document<`u`&&document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>p(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let m=e=>{let n=e??``;c(n),l.current=n,t?.({source:n})},h=X.useMemo(()=>({...e,type:e.type??`page`}),[e]),g=(0,Y.jsx)(`div`,{ref:d,className:`h-full min-h-[260px] overflow-hidden bg-background`,children:u?(0,Y.jsx)(`textarea`,{value:s,onChange:e=>m(e.target.value),readOnly:n,spellCheck:!1,"aria-label":`Page source`,className:`h-full w-full resize-none bg-background p-3 font-mono text-xs leading-relaxed outline-none`}):(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(Te,{className:`h-full w-full`}),children:(0,Y.jsx)(Gu,{value:s,language:`typescript`,path:a===`react`?`page.tsx`:`page.html.tsx`,theme:f,beforeMount:Ku,onChange:m,options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),_=(0,Y.jsx)(`div`,{className:`h-full min-h-[260px] overflow-auto bg-muted/20`,children:(0,Y.jsx)(Q,{fallbackHint:`The page source threw while rendering — fix the code in the Source tab.`,children:(0,Y.jsx)(v,{schema:h})})});return i===`editor`?g:i===`preview`?(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:_}):(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:(0,Y.jsxs)(`div`,{className:`grid h-full grid-cols-1 divide-y divide-border lg:grid-cols-2 lg:divide-x lg:divide-y-0`,children:[g,_]})})}var Ju={grid:{label:`Grid`,category:`data`,Icon:Or},"object-grid":{label:`Table`,category:`data`,Icon:Br},"object-form":{label:`Form`,category:`data`,Icon:_t},"object-metric":{label:`Metric`,category:`data`,Icon:tr},"object-kanban":{label:`Kanban`,category:`data`,Icon:cr},"page:header":{label:`Header`,category:`layout`,Icon:ar},"page:footer":{label:`Footer`,category:`layout`,Icon:Zr},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Ur},"page:tabs":{label:`Tabs`,category:`layout`,Icon:Xn},"page:accordion":{label:`Accordion`,category:`layout`,Icon:oi},"page:card":{label:`Card`,category:`layout`,Icon:rn},"page:section":{label:`Section`,category:`layout`,Icon:ln},"record:details":{label:`Record details`,category:`record`,Icon:Oe},"record:highlights":{label:`Highlights`,category:`record`,Icon:rr},"record:related_list":{label:`Related list`,category:`record`,Icon:gt},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Jn},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:je},"record:path":{label:`Stage path`,category:`record`,Icon:xr},"record:alert":{label:`Alert banner`,category:`record`,Icon:R},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:rt},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:or},"record:history":{label:`History`,category:`record`,Icon:Wr},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:ri},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:xr},"global:search":{label:`Global search`,category:`navigation`,Icon:Me},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:jn},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:Et},"element:text":{label:`Text`,category:`element`,Icon:Gt},"element:number":{label:`Number`,category:`element`,Icon:ti},"element:image":{label:`Image`,category:`element`,Icon:Bn},"element:divider":{label:`Divider`,category:`element`,Icon:et},"element:button":{label:`Button`,category:`element`,Icon:ot},"element:definition-list":{label:`Definition list`,category:`element`,Icon:Fe},"element:repeater":{label:`Repeater`,category:`element`,Icon:It}},Yu={data:`Data`,layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Xu=(()=>{let e={data:[],layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Ju))e[n.category].push(t);return[`data`,`layout`,`record`,`element`,`navigation`,`ai`,`misc`].map(t=>({category:t,types:e[t]})).filter(e=>e.types.length>0)})(),Zu=xn,Qu={data:{icon:`text-emerald-500 dark:text-emerald-400`,badge:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300`},layout:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},record:{icon:`text-blue-500 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},navigation:{icon:`text-indigo-500 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},element:{icon:`text-teal-500 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},ai:{icon:`text-violet-500 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},misc:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function $u(e){return Qu[Ju[e]?.category??`misc`]}var ed={"object-grid":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`columns`,label:`Columns`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`pageSize`,label:`Page size`,kind:`number`,placeholder:`20`},{name:`striped`,label:`Striped rows`,kind:`boolean`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"object-form":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`mode`,label:`Mode`,kind:`select`,options:[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`view`,label:`View`}]},{name:`formType`,label:`Form type`,kind:`select`,options:[{value:`simple`,label:`Simple`},{value:`tabbed`,label:`Tabbed`},{value:`wizard`,label:`Wizard`},{value:`split`,label:`Split`},{value:`drawer`,label:`Drawer`},{value:`modal`,label:`Modal`}]},{name:`layout`,label:`Layout`,kind:`select`,options:[{value:`vertical`,label:`Vertical`},{value:`horizontal`,label:`Horizontal`},{value:`inline`,label:`Inline`},{value:`grid`,label:`Grid`}]},{name:`columns`,label:`Columns (grid layout)`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`description`,label:`Description`,kind:`text`}],"object-metric":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`label`,label:`Label`,kind:`text`},{name:`description`,label:`Description`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`colorVariant`,label:`Color`,kind:`color`,options:[{value:`default`,label:`Default`},{value:`blue`,label:`Blue`},{value:`teal`,label:`Teal`},{value:`orange`,label:`Orange`},{value:`purple`,label:`Purple`},{value:`success`,label:`Success`},{value:`warning`,label:`Warning`},{value:`danger`,label:`Danger`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"object-kanban":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`groupField`,label:`Group by field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`cardFields`,label:`Card fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`}],grid:[{name:`columns`,label:`Columns`,kind:`number`,placeholder:`3`},{name:`gap`,label:`Gap`,kind:`number`,placeholder:`4`}],"element:text":[{name:`content`,label:`Content`,kind:`text`,placeholder:`Text…`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`heading`,label:`Heading`},{value:`subheading`,label:`Subheading`},{value:`body`,label:`Body`},{value:`caption`,label:`Caption`}]},{name:`align`,label:`Align`,kind:`select`,options:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}],"element:image":[{name:`src`,label:`Source URL`,kind:`text`,placeholder:`https://…`},{name:`alt`,label:`Alt text`,kind:`text`},{name:`fit`,label:`Fit`,kind:`select`,options:[{value:`cover`,label:`Cover`},{value:`contain`,label:`Contain`},{value:`fill`,label:`Fill`}]}],"element:definition-list":[{name:`items`,label:`Items`,kind:`array`,addLabel:`Add item`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`value`,label:`Value`,kind:`text`}]},{name:`columns`,label:`Columns (1 or 2)`,kind:`number`,placeholder:`1`},{name:`inline`,label:`Inline (label · value)`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`},{name:`emptyText`,label:`Empty text`,kind:`text`},{name:`divided`,label:`Dividers between rows`,kind:`boolean`}],"element:number":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`field`,label:`Field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`Aggregate`,kind:`select`,options:[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"element:button":[{name:`label`,label:`Label`,kind:`text`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}]},{name:`size`,label:`Size`,kind:`select`,options:[{value:`small`,label:`Small`},{value:`medium`,label:`Medium`},{value:`large`,label:`Large`}]},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`}],"page:header":[{name:`title`,label:`Title`,kind:`text`},{name:`subtitle`,label:`Subtitle`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`breadcrumb`,label:`Show breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`Title`,kind:`text`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`Tabs`,kind:`array`,addLabel:`Add tab`,itemFields:[{name:`key`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"page:accordion":[{name:`title`,label:`Title`,kind:`text`},{name:`items`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`value`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`relationshipField`,label:`Relationship field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`}],"record:highlights":[{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`columns`,label:`Columns`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`Severity`,kind:`select`,options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`error`,label:`Error`},{value:`success`,label:`Success`}]},{name:`title`,label:`Title`,kind:`text`},{name:`body`,label:`Body`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`dismissible`,label:`Dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`Status field`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`Stages`,kind:`array`,addLabel:`Add stage`,itemFields:[{name:`value`,label:`Value`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`Action names`,kind:`string-list`,placeholder:`action name`},{name:`location`,label:`Location`,kind:`select`,options:[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record more menu`},{value:`record_section`,label:`Record section`},{value:`record_related`,label:`Record related`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List item`},{value:`global_nav`,label:`Global nav`}]}],"ai:chat_window":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}],"ai:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function td(e){return!!e&&Array.isArray(ed[e])&&ed[e].length>0}function nd(){let e=Ai(),[t,n]=X.useState([]),[r,i]=X.useState(!0);return X.useEffect(()=>{let t=!1;return i(!0),e.list(`object`).then(e=>{if(t)return;let r=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));n(r),i(!1)}).catch(()=>{t||(n([]),i(!1))}),()=>{t=!0}},[e]),{options:t,loading:r}}function rd(e){let{fields:t}=Ki(e);return X.useMemo(()=>t.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[t])}function id({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=nd();return i.length===0?(0,Y.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(K,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function ad({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=rd(t);return!t||a.length===0?(0,Y.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(K,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function od({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=rd(t),o=Array.isArray(n)?n:[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(oe,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,Y.jsx)(fr,{className:`h-8`,children:(0,Y.jsx)(Dr,{placeholder:`—`})}),(0,Y.jsx)(En,{children:a.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})}):(0,Y.jsx)(B,{className:`h-8 text-sm`,value:String(e??``),placeholder:`field name`,disabled:i,onChange:e=>{let n=[...o];n[t]=e.target.value,r(n)}}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":`Remove`,onClick:()=>r(o.filter((e,n)=>n!==t)),children:(0,Y.jsx)(Se,{className:`h-4 w-4`})})]},t)),!i&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}function sd(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return``}}function cd({label:e,value:t,onCommit:n,disabled:r}){let i=X.useMemo(()=>sd(t),[t]),[a,o]=X.useState(i),[s,c]=X.useState(null);return X.useEffect(()=>{o(i),c(null)},[i]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),onBlur:()=>{if(r)return;let e=a.trim();if(e===``){c(null),n(void 0);return}try{let t=JSON.parse(e);c(null),n(t)}catch{c(`Invalid JSON`)}},disabled:r,spellCheck:!1,rows:Math.min(12,Math.max(2,a.split(`
13
- `).length)),className:`w-full rounded border border-input bg-background px-2 py-1.5 text-xs font-mono outline-none focus:ring-1 focus:ring-primary resize-y disabled:opacity-60`}),s&&(0,Y.jsx)(`div`,{className:`text-[11px] text-destructive`,children:s})]})}function ld({name:e,value:t,onCommit:n,disabled:r}){return typeof t==`boolean`?(0,Y.jsx)(J,{label:e,value:t,onCommit:n,disabled:r}):typeof t==`number`?(0,Y.jsx)(Ii,{label:e,value:t,onCommit:e=>n(e),disabled:r}):t===null||typeof t==`string`?(0,Y.jsx)(q,{label:e,value:t??``,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(cd,{label:e,value:t,onCommit:n,disabled:r})}var ud=new Set([`children`,`body`]),dd=Symbol(`remove`);function fd(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)(?:\[(\d+)\])?$/.exec(e);if(!t)return null;n.push({key:t[1],index:t[2]==null?-1:Number(t[2])})}return n.length>0?n:null}function pd(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function md(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function hd(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return i.length===0?n===dd?t.splice(r,1):t[r]=n:t[r]=hd(t[r],i,n),t}let a={...e||{}};return i.length===0?n===dd?delete a[r]:a[r]=n:a[r]=hd(a[r],i,n),a}function gd(e,t){return md(e,pd(t))}function _d(e,t,n){let r=pd(t),i=hd(e,r,n===null?dd:n),a=r[0];return{[a]:i[a]}}function vd(e,t){let n=pd(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=md(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function yd(e,t,n){let r=pd(t),i=hd(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function bd({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),c=s?null:fd(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?fd(d):null,p=t.slots&&typeof t.slots==`object`?t.slots:{},m=s?Array.isArray(p[l])?p[l]:p[l]==null?[]:[p[l]]:[],h=s?m[u]??null:null,g=e=>n({slots:{...p,[l]:e}}),_=e=>g(e===null?m.filter((e,t)=>t!==u):m.map((t,n)=>n===u?e:t)),v=s?f?gd(h||{},f):h:c?gd(t,c):null,y=s?f?vd(h||{},f):{siblings:m,index:u}:c?vd(t,c):null;if(!s&&!c||!v)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),children:(0,Y.jsx)(Yi,{message:e.id})});let b=e=>s?_(f?{...h,..._d(h||{},f,{...v,...e})}:{...v,...e}):n(_d(t,c,{...v,...e})),x=v.properties||{},S=typeof t?.object==`string`?t.object:void 0,C=e=>e.objectFrom===`page`?S:e.objectProp!=null&&x[e.objectProp]!=null?String(x[e.objectProp]):void 0,w=e=>x[e]??v[e],T=(e,t)=>b({properties:{...x,[e]:t}}),E=new Set((td(v.type)?ed[v.type]:[]).map(e=>e.name)),D=Object.keys(x).filter(e=>!E.has(e)&&!ud.has(e)),O=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,Y.jsx)(Ii,{label:e.label,value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`boolean`:return(0,Y.jsx)(J,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`color`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(na,{value:t(e.name)==null?void 0:String(t(e.name)),onChange:t=>n(e.name,t),disabled:o,options:e.options})]},i);case`select`:return(0,Y.jsx)(K,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),options:e.options,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{className:`h-8 text-sm`,value:String(t??``),placeholder:e.placeholder,disabled:o,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:o,"aria-label":`Remove`,onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,Y.jsx)(Se,{className:`h-4 w-4`})})]},i)),!o&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]},i)}case`array`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:o,"aria-label":`Remove item`,onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>O(t,e=>s[e],(t,i)=>{let o=[...r];o[a]={...s,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!o&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,Y.jsx)(id,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-picker`:return(0,Y.jsx)(ad,{label:e.label,objectName:C(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-list`:return(0,Y.jsx)(od,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,Y.jsx)(q,{label:e.label,value:t(e.name)==null?``:String(t(e.name)),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i)}},k=()=>{s?_(f?{...h,..._d(h||{},f,null)}:null):n(_d(t,c,null)),r()},A=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,Y.jsx)(Xi,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=Pi(y.siblings,y.index,e);_({...h,...yd(h||{},f,t)});let n=A([...f.slice(0,-1),{key:f[f.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${l}:${u}.${n}`,label:String(v.id||v.type||e)})}else g(Pi(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}let r=Pi(y.siblings,y.index,e);n(yd(t,c,r));let a=A([...c.slice(0,-1),{key:c[c.length-1].key,index:e}]);i?.({kind:`block`,id:a,label:String(v.id||v.type||a)})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.pageBlock.remove`,a),onClick:k,disabled:o}),children:[(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(oa,{label:G(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e||void 0}),objectName:S,disabled:o}),td(v.type)&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.pageBlock.properties`,a)}),ed[v.type].map(e=>O(e,w,T))]}),D.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.pageBlock.advanced`,a)}),D.map(e=>(0,Y.jsx)(ld,{name:e,value:x[e],onCommit:t=>T(e,t),disabled:o},e))]})]})}var xd=new Set([`simple`,`tabbed`,`wizard`,`split`]),Sd=new Set([`drawer`,`modal`]);function Cd(e){return typeof e==`string`&&Sd.has(e)}function wd(e){return typeof e==`string`&&xd.has(e)?e:`simple`}function Td(e){let t={...e,type:String(e?.type??``)},n=t.properties&&typeof t.properties==`object`?t.properties:void 0;return Cd(n?.formType??t.formType)&&(n&&(t.properties={...n,formType:`simple`}),`formType`in t&&(t.formType=`simple`)),t}function Ed(e=`300px`){let t=X.useRef(null),[n,r]=X.useState(()=>typeof IntersectionObserver>`u`);return X.useEffect(()=>{if(n)return;let i=t.current;if(!i)return;let a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(r(!0),a.disconnect())},{rootMargin:e});return a.observe(i),()=>a.disconnect()},[n,e]),{ref:t,inView:n}}function Dd({block:e,maxHeightClass:t=`max-h-72`}){let n=String(e?.type??``),{ref:r,inView:i}=Ed();return(0,Y.jsx)(`div`,{ref:r,className:I(`pointer-events-none select-none overflow-hidden p-3`,t),children:i?(0,Y.jsx)(Q,{fallbackHint:`"${n}" can't render with its current configuration — check its Properties.`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:Td(e)})})}):(0,Y.jsx)(`div`,{className:`min-h-[64px] animate-pulse rounded bg-muted/40`,"aria-hidden":`true`})})}var Od={1:`grid-cols-1`,2:`grid-cols-2`,3:`grid-cols-3`,4:`grid-cols-4`,5:`grid-cols-5`,6:`grid-cols-6`};function kd(e){let t=e?.properties||{};switch(e?.type){case`page:tabs`:case`page:accordion`:return(Array.isArray(t.items)?t.items:[]).map((e,t)=>({label:e?.label||e?.key||`Item ${t+1}`,pathSuffix:`properties.items[${t}].children`,children:Array.isArray(e?.children)?e.children:[]}));case`page:card`:return Array.isArray(t.body)&&!Array.isArray(t.children)?[{label:`Body`,pathSuffix:`properties.body`,children:t.body}]:[{label:`Body`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];case`page:section`:case`grid`:return[{label:`Content`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];default:return Array.isArray(t.children)?[{label:`Content`,pathSuffix:`properties.children`,children:t.children}]:[]}}var Ad=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function jd(e){let t=e||{};return Ad.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function Md(e){let t={};for(let n of e){let e=Array.isArray(n.components)?n.components:[];e.length===0||!n.name||(t[n.name]=e)}return t}function Nd(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:jd(t),shape:`slots`};let n=e.regions;if(Array.isArray(n))return{regions:n,shape:`regions`};let r=e.children;return Array.isArray(r)?{regions:[{name:`children`,components:r}],shape:`children`}:{regions:[],shape:`regions`}}function Pd(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function Fd(e){return typeof e.label==`string`&&e.label||typeof e.title==`string`&&e.title||typeof e.id==`string`&&e.id||String(e.type??`block`)}var Id=`text/x-objectui-pageblock`;function Ld({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=X.useMemo(()=>Nd(e),[e]),s=n?.kind===`block`?String(n.id):null,c=X.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:Md(e)}):t?.({regions:e})},[t,o]),l=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),s=i[e.region]?.components;if(!s)return;let[l]=s.splice(e.comp,1);if(!l)return;let u=i[n.region]?.components;if(!u)return;let d=u.length;if(`appendEnd`in n)d=u.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,d=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,d=t}u.splice(d,0,l),c(i);let f=Pd(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:Fd(l)})},[t,r,a,c,o]),u=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]}));i[e]||(i[e]={name:`region_${e+1}`,components:[]});let s={type:n};i[e].components.push(s),c(i);let l=i[e].components.length-1;r?.({kind:`block`,id:Pd(o,e,l,i[e]?.name),label:Fd(s)})},[t,r,a,c,o]),d=X.useCallback((e,n,r)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e]?.components?.[n];o&&(i[e].components[n]={...o,label:r||void 0},c(i))},[t,a,c]),f=X.useCallback(()=>{if(!t)return;let e=[...a,{name:`region_${a.length+1}`,components:[]}];c(e)},[t,a,c]),p=X.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=fd(i);if(!s)return;let c=pd(s);if(o){let s=o[1],l=Number(o[2]),u=e.slots||{},d=u[s],f=Array.isArray(d)?[...d]:d==null?[]:[d],p=f[l];if(!p)return;let m=md(p,c)||[];f[l]=hd(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=fd(`${n}.${i}`);if(!o)return;let s=pd(o),c=md(e,s)||[],l=hd(e,s,[...c,{type:a}]);t({[s[0]]:l[s[0]]}),r?.({kind:`block`,id:`${n}.${i}[${c.length}]`,label:a})}},[t,e,r]),m=X.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`A Page is composed of regions (header / main / sidebar / …). Add a region to start dropping blocks into it.`}),!i&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,Y.jsx)(Rd,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:Pd(o,t,n,e.name),label:Fd(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>Pd(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function Rd({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c,onSelectId:l,onAddNested:u}){let d=Array.isArray(e.components)?e.components:[],[f,p]=X.useState(!1);return(0,Y.jsxs)(`section`,{className:I(`rounded-md transition-colors`,f&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(i)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(Id)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(!0))},onDragLeave:e=>{e.currentTarget===e.target&&p(!1)},onDrop:e=>{if(i||(p(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(Id);if(n)try{let e=JSON.parse(n);if(typeof e.region!=`number`||typeof e.comp!=`number`)return;o(e,{region:t,appendEnd:!0})}catch{}},children:[(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,Y.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:n===`slots`?`Inherited from the default page — add a block to override this slot.`:`Empty region — drop a block here or use the add button below.`}):d.map((s,d)=>{let f=Pd(n,t,d,e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsx)(zd,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,Y.jsx)(Bd,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(Vd,{onPick:e=>s(t,e)})})]})]})}function zd({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Ju[c]?.Icon??Zu,u=$u(c),d=Fd(e),f=!i,[p,m]=X.useState(null),h=e=>{e.dataTransfer.setData(Id,JSON.stringify({region:t,comp:n})),e.dataTransfer.effectAllowed=`move`},g=e=>{if(!f)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(Id))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();m(e.clientY-n.top<n.height/2?`before`:`after`)},_=()=>m(null),v=e=>{if(i)return;e.preventDefault(),e.stopPropagation();let r=p??`before`;m(null);let a=e.dataTransfer.getData(Id);if(a)try{let e=JSON.parse(a);if(e.region===t&&e.comp===n)return;o(e,r===`before`?{region:t,before:n}:{region:t,after:n})}catch{}},[y,b]=X.useState(!1),[x,S]=X.useState(d);X.useEffect(()=>{S(d)},[d]);let C=e=>{i||(e.preventDefault(),e.stopPropagation(),S(d),b(!0))},w=()=>{if(i){b(!1);return}let e=x.trim();e&&e!==d&&s(e),b(!1)},T=()=>{S(d),b(!1)},E=kd(e).length>0;return(0,Y.jsxs)(`div`,{className:I(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsx)(`div`,{className:I(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:E?(0,Y.jsxs)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:I(`flex w-full items-center justify-between gap-2 rounded-md px-3.5 py-2.5 text-left`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,Y.jsx)(l,{className:I(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,Y.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),w()):e.key===`Escape`&&(e.preventDefault(),T())},onBlur:w,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:I(`text-sm font-medium truncate`,!i&&`cursor-text`),onDoubleClick:C,title:i?void 0:`Double-click to rename`,children:d}),e.id&&e.id!==d&&(0,Y.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Dd,{block:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,"aria-label":`Select ${d}`,"aria-pressed":r,className:I(`absolute inset-0 z-10 rounded-md`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`)}),(0,Y.jsxs)(`div`,{className:I(`pointer-events-none absolute right-1.5 top-1.5 z-20 flex items-center gap-1 transition-opacity`,r?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:[f&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 text-muted-foreground/60`,"aria-hidden":`true`}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,u.badge),children:c})]})]})}),p===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function Bd({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=kd(e);if(o.length===0)return null;let s=Od[e?.type===`grid`?Math.min(6,Math.max(1,Number(e.properties?.columns)||1)):1]??`grid-cols-1`;return(0,Y.jsx)(`div`,{className:`ml-5 mt-1.5 space-y-2.5 border-l border-dashed border-border pl-3`,children:o.map((e,o)=>(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/40 py-2 px-3 text-[11px] text-muted-foreground`,children:`Empty — add a block.`}):(0,Y.jsx)(`div`,{className:I(`grid gap-2`,s),children:e.children.map((r,a)=>{let o=`${t}.${e.pathSuffix}[${a}]`,s=String(r?.type??``),c=o===n;return(0,Y.jsxs)(`div`,{className:I(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,c?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:[(0,Y.jsx)(Dd,{block:r,maxHeightClass:`max-h-56`}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,Fd(r))},"aria-label":`Select ${Fd(r)}`,"aria-pressed":c,className:`absolute inset-0 z-10 rounded-md cursor-pointer`}),(0,Y.jsx)(`div`,{className:I(`pointer-events-none absolute right-1.5 top-1.5 z-20 transition-opacity`,c?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,$u(s).badge),children:s})})]},a)})}),!r&&(0,Y.jsx)(Vd,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function Vd({onPick:e}){let[t,n]=X.useState(!1),[r,i]=X.useState(``),a=r.trim().toLowerCase(),o=X.useMemo(()=>a?Xu.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Ju[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Xu,[a]);return(0,Y.jsxs)(Cn,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(Mn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search block type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:Yu[t.category]}),t.types.map(t=>{let r=Ju[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent text-left`,children:[(0,Y.jsx)(a,{className:I(`h-3.5 w-3.5 shrink-0`,$u(t).icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function Hd({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=X.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=!!e?.interfaceConfig?.source,d=X.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),f=X.useMemo(()=>{if(d===`regions`){let t=e.regions,n=[];return t.forEach((e,t)=>{(Array.isArray(e.components)?e.components:[]).forEach((r,i)=>{n.push({id:`regions[${t}].components[${i}]`,label:r.id||r.type||`${e.name??`region ${t+1}`} · ${i+1}`})})}),n}return(Array.isArray(e.children)?e.children:[]).map((e,t)=>({id:`children[${t}]`,label:e.id||e.type||`block ${t+1}`}))},[e,d]),p=X.useCallback(()=>{if(!c)return;let t={type:`container`};if(d===`regions`){let n=Array.isArray(e.regions)?[...e.regions]:[],a=n.length-1;a<0&&(n.push({name:`main`,components:[]}),a=0);let o={...n[a]},s=Array.isArray(o.components)?[...o.components]:[];s.push(t),o.components=s,n[a]=o,i({regions:n}),r?.({kind:`block`,id:`regions[${a}].components[${s.length-1}]`,label:t.type});return}let n=[...Array.isArray(e.children)?e.children:[],t];i({children:n}),r?.({kind:`block`,id:`children[${n.length-1}]`,label:t.type})},[c,e,i,r,d]),m=e?.type===`record`||e?.pageType===`record`?e?.object:void 0,[_,y]=X.useState([]),[b,x]=X.useState(null),[S,C]=X.useState(null);X.useEffect(()=>{if(!m){y([]),x(null),C(null);return}let e=!1;return(async()=>{try{let t={headers:{accept:`application/json`},credentials:`include`},n=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(m)}`,t)).json().catch(()=>null),r=n?.item??n?.data??n,i=h(r?.fields),a=i.length>0?`?$top=50&$expand=${encodeURIComponent(i.join(`,`))}`:`?$top=50`,o=await(await fetch(`/api/v1/data/${encodeURIComponent(m)}${a}`,t)).json().catch(()=>null),s=Array.isArray(o?.records)?o.records:Array.isArray(o?.items)?o.items:Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[];if(e)return;y(s),x(r),C(e=>e??s[0]?.id??s[0]?._id??s[0]?.name??null)}catch{e||(y([]),x(null))}})(),()=>{e=!0}},[m]);let w=e=>e?.id??e?._id??e?.name,T=e=>String(e?.name??e?.title??e?.label??e?.subject??w(e)??`(record)`),E=X.useMemo(()=>_.length?_.find(e=>String(w(e))===String(S))??_[0]:null,[_,S]),D=e?.kind===`slotted`,O=X.useMemo(()=>{if(!D)return o;try{let t=e?.slots??{};return Ta(b??void 0,{slots:t})}catch{return o}},[D,o,e,b]),k=e=>!m||!E?e:(0,Y.jsxs)(g,{objectName:m,recordId:w(E),data:E,objectSchema:b??void 0,embedded:!0,children:[_.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b bg-muted/30 text-xs`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Preview record`}),(0,Y.jsx)(`select`,{className:`h-7 rounded-md border bg-background px-2 text-xs max-w-[260px]`,value:String(S??``),onChange:e=>C(e.target.value),children:_.map(e=>{let t=w(e);return(0,Y.jsx)(`option`,{value:String(t),children:T(e)},String(t))})}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground/70 shrink-0`,children:[_.length,` sample`,_.length===1?``:`s`]})]}),e]});if(u)return(0,Y.jsx)(Z,{hint:`page · interface`,children:(0,Y.jsx)(Q,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,Y.jsx)(wa,{page:e,onConfigChange:c?t=>i({interfaceConfig:{...e.interfaceConfig||{},...t}}):void 0})})});let A=e.kind;return A===`react`||A===`html`?(0,Y.jsx)(qu,{draft:e,onPatch:c?i:void 0,readOnly:!c}):!o||Object.keys(o).length<=1?(0,Y.jsxs)(Z,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,Y.jsx)(Ld,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(Wu,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:G(`engine.inspector.add.block`,a)}):null,!s&&(0,Y.jsx)(Hu,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,Y.jsx)(Z,{hint:`page · design`,children:k((0,Y.jsx)(Ld,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}))}):(0,Y.jsx)(Z,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(Q,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(Wu,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:G(`engine.inspector.add.block`,a)}),k((0,Y.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Y.jsx)(v,{schema:O})}))]})})}function Ud(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object];for(let e of n)if(typeof e==`string`&&e)return e}function Wd(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.name;return n?{...t,name:n,readOnly:t.readOnly??t.readonly}:t}return String(e)}function Gd(e,t){return{type:`object-form`,objectName:e,mode:`create`,formType:wd(typeof t.type==`string`?t.type:`simple`),sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(Wd):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function Kd({name:e,draft:t,editing:n}){let r=X.useMemo(()=>cs(t)?.schema,[t]),i=X.useMemo(()=>Ud(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=X.useMemo(()=>{if(!r)return{listViews:{},defaultViewId:void 0,defaultViewType:`grid`};let n=String(e)||`default`;return{listViews:{[n]:{...r,label:r.label??t.label??e}},defaultViewId:n,defaultViewType:r.type??`grid`}},[r,t,e]),l=X.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);if(!r&&t.type){let e={...t};return(0,Y.jsx)(Z,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:e})})})})})}if(!i)return(0,Y.jsx)(Z,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(Hu,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,Y.jsx)(`code`,{children:`Object`}),` in the right panel to fetch live data and field options.`]})});if(t.viewKind===`form`&&r){let e=String(r.type??`simple`),t=Gd(i,r);return(0,Y.jsx)(Z,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:t})})})})})}return(0,Y.jsx)(Z,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:l})})})})})}var qd={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:ti},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:ae},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:yt},line:{id:`line`,label:`Line chart`,category:`chart`,icon:wn},area:{id:`area`,label:`Area chart`,category:`chart`,icon:dr},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:en},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:vr},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Yt},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:ie},table:{id:`table`,label:`Data table`,category:`data`,icon:Sn},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:ir}},Jd={kpi:`Single value`,chart:`Charts`,data:`Tabular`},Yd=[`kpi`,`chart`,`data`].map(e=>({category:e,types:Object.values(qd).filter(t=>t.category===e)})),Xd=Jn;function Zd({onAdd:e,label:t=`Add widget`}){let[n,r]=X.useState(!1),[i,a]=X.useState(``),o=X.useRef(null),s=X.useMemo(()=>{let e=i.trim().toLowerCase();return e?Yd.map(t=>({category:t.category,types:t.types.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))})).filter(e=>e.types.length):Yd},[i]);return(0,Y.jsxs)(Cn,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),t]})}),(0,Y.jsxs)(Mn,{align:`end`,sideOffset:4,className:`w-72 p-0`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Y.jsx)(Me,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:o,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search widgets…`,className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground`})]}),(0,Y.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:s.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):s.map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:Jd[t.category]}),t.types.map(t=>(0,Y.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{e(t.id),r(!1)},children:[(0,Y.jsx)(qd[t.id]?.icon??Xd,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var Qd=X.lazy(()=>a(()=>import(`./plugin-dashboard-LbTxdFyx.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function $d({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=S(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=X.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=X.useCallback(e=>{n&&n({widgets:e})},[n]),p=X.useCallback(e=>{if(!l)return;let t=Gi(`widget`,s.map(e=>e?.id).filter(Boolean)),r=qd[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:t,type:e,title:a,...r?.defaults??{}};n({widgets:ua(s,o)}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),m=X.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),h=u?s.find(e=>e?.id===u)??null:null,g=l?(0,Y.jsx)(Zd,{onAdd:p,label:G(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(Z,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(Hu,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(Z,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(Q,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(ef,{widget:h,onRename:e=>m(h.id,e),onClose:()=>i?.(null)}):null,(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(`div`,{className:`min-w-[768px]`,children:(0,Y.jsx)(Qd,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function ef({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=X.useState(!1),[o,s]=X.useState(r),c=X.useRef(null);X.useEffect(()=>{s(r),a(!1)},[e.id,r]),X.useEffect(()=>{i&&c.current?.select()},[i]);let l=()=>{let e=o.trim();e&&e!==r&&t(e),a(!1)},u=()=>{s(r),a(!1)},d=qd[e.type]?.icon??null;return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-primary/5 px-3 py-1.5 text-xs`,children:[d?(0,Y.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,Y.jsx)(`span`,{className:`rounded bg-primary px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-foreground`,children:`Selected`}),i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`input`,{ref:c,value:o,onChange:e=>s(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),u())},className:`flex-1 min-w-0 rounded border bg-background px-2 py-0.5 text-xs outline-none focus:ring-1 focus:ring-primary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`flex-1 min-w-0 truncate text-left font-medium hover:underline`,title:`Click to rename`,children:r||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,Y.jsx)(Rr,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]})}var tf=X.lazy(()=>a(()=>import(`./plugin-report-DEkf0Fe2.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function nf({draft:e}){let t=S(),n=e,r=typeof n.dataset==`string`&&!!n.dataset,i=n.type===`joined`&&Array.isArray(n.blocks)&&n.blocks.some(e=>typeof e?.dataset==`string`&&!!e.dataset);if(r||i){let r=Array.isArray(n.rows)?n.rows.filter(Boolean):[];return(0,Y.jsx)(Z,{hint:i?`report · joined · ${n.blocks.length} block${n.blocks.length===1?``:`s`}`:`report · dataset "${n.dataset}"${r.length?` · by `+r.join(`, `):``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(tf,{schema:e,dataSource:t})})})})})}let a=n.type===`joined`;return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(ir,{className:`h-8 w-8`}),title:a?`Add a block to preview this joined report`:`Bind a dataset to preview this report`,description:a?`A joined report stacks dataset-bound blocks. Add a block and bind its dataset + measures in the right panel to start designing.`:`Since the 9.0 single-form cutover a report renders its dataset's measures (values) grouped by dimensions (rows). Choose a Dataset in the right panel to start designing.`})})}var rf=`text/x-objectui-nav`;function af(e){if(e.kind)return String(e.kind);if(e.object||e.objectName)return`object`;if(e.page||e.pageName)return`page`;if(e.dashboard)return`dashboard`;if(e.report)return`report`;if(Array.isArray(e.children)&&e.children.length)return`group`;let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&/^https?:/i.test(t)?`link`:`item`}function of(e){switch(e){case`object`:return ir;case`page`:return Oe;case`dashboard`:return Gn;case`report`:return Nr;case`link`:return Dn;case`group`:return Ze;default:return xr}}var sf={object:{icon:`text-blue-500`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},page:{icon:`text-violet-500`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},dashboard:{icon:`text-teal-500`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},report:{icon:`text-amber-500`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},link:{icon:`text-indigo-500`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},group:{icon:`text-slate-500`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},item:{icon:`text-zinc-500`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function cf(e){return sf[e]??sf.item}function lf(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function uf(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function df({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=Ti(),o=X.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),s=r&&r.kind===`nav`?r.id:null,[c,l]=X.useState(null),u=X.useCallback(e=>{n&&n({[t]:e})},[n,t]),d=X.useCallback(()=>{if(!n)return;let e=G(`engine.appNav.newItem`,a),r=new Set(o.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean)),s=`nav_item_${o.length+1}`;for(let e=o.length+2;r.has(s);e++)s=`nav_item_${e}`;let c=ua(o,{id:s,type:`object`,label:e});u(c),i?.({kind:`nav`,id:`${t}[${c.length-1}]`,label:e})},[n,o,u,t,i,a]),f=X.useCallback(e=>{if(!n)return;let r=la(o,e,null);u(r),s===`${t}[${e}]`&&i?.(null)},[n,o,u,t,s,i]),p=X.useCallback((e,r)=>{if(!n)return;let a={...o[e]??{},label:r},c=la(o,e,a);u(c),s===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r})},[n,o,u,t,s,i]),m=X.useCallback((e,r)=>{if(!n)return;let a=r;if(e<r&&(a=r-1),a===e)return;let s=Pi(o,e,a);u(s),i?.({kind:`nav`,id:`${t}[${a}]`,label:lf(s[a]??{},a)})},[n,o,u,t,i]);return(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.appNav.heading`,a)}),(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px]`,children:[o.length,` `,o.length===1?G(`engine.appNav.itemOne`,a):G(`engine.appNav.itemOther`,a)]})]}),n&&(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:d,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,G(`engine.appNav.addItem`,a)]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),c!=null&&(m(c,o.length),l(null)))},children:o.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:G(n?`engine.appNav.empty`:`engine.appNav.emptyReadonly`,a)}):o.map((e,r)=>(0,Y.jsx)(ff,{item:e,index:r,depth:0,path:`${t}[${r}]`,selectedId:s,canEdit:!!n,onClick:(e,t)=>i?.({kind:`nav`,id:e,label:t}),onRename:e=>p(r,e),onRemove:()=>f(r),onDragStart:()=>l(r),onDragEnd:()=>l(null),onDropBefore:()=>{c!=null&&(m(c,r),l(null))}},r))})]})}function ff({item:e,index:t,depth:n,path:r,selectedId:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(pf,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,lf(e,t)),onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}),Array.isArray(e.children)&&e.children.map((e,t)=>{let s=`${r}.children[${t}]`;return(0,Y.jsx)(ff,{item:e,index:t,depth:n+1,path:s,selectedId:i,canEdit:a,onClick:o,onRename:()=>void 0,onRemove:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onDropBefore:()=>void 0},t)})]})}function pf({item:e,index:t,depth:n,path:r,isSelected:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){let f=Ti(),p=af(e),m=of(p),h=cf(p),g=uf(e),[_,v]=X.useState(!1),[y,b]=X.useState(lf(e,t)),[x,S]=X.useState(!1),[C,w]=X.useState(null);return X.useEffect(()=>{_||b(lf(e,t))},[e,t,_]),(0,Y.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[C===`before`&&(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`button`,{type:`button`,draggable:a&&!_,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(rf,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.stopPropagation(),w(null),d())},onClick:o,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),"aria-pressed":i,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${i?`border-primary ring-1 ring-primary`:`border-border`} ${a&&!_?`cursor-grab active:cursor-grabbing`:``}`,children:[a?(0,Y.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,Y.jsx)(`span`,{className:`w-3.5`}),(0,Y.jsx)(m,{className:I(`h-3.5 w-3.5 shrink-0`,h.icon)}),_?(0,Y.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{v(!1);let n=y.trim();n&&n!==lf(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),b(lf(e,t)),v(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),v(!0))},children:lf(e,t)}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-medium`,h.badge),children:p}),g&&(0,Y.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:g}),a&&x&&!_&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":G(`engine.appNav.removeItem`,f),children:(0,Y.jsx)(Tn,{className:`h-3 w-3`})})]})]})}function mf(e){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let t=String(e.label??e.title??e.name??e.path??``).trim();if(!t&&!e.children)return null;let n=e.path??e.href??e.route??e.url??void 0,r;e.object||e.objectName?r=`object`:e.page||e.pageName?r=`page`:e.dashboard?r=`dashboard`:e.report?r=`report`:typeof n==`string`&&/^https?:/i.test(n)?r=`link`:Array.isArray(e.children)&&e.children.length&&(r=`group`);let i=Array.isArray(e.children)?mf(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function hf(e){switch(e){case`object`:return ir;case`page`:return Oe;case`dashboard`:return Gn;case`report`:return Nr;default:return xr}}function gf({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,c=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:l,navItems:u}=X.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:mf(n)};return{rootKey:null,navItems:[]}},[t]),d=l??`navigation`,f=!!(n&&i),p=f&&!!a,m=r&&r.kind===`nav`?r.id:null,h=f?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,g=o?`/apps/${encodeURIComponent(o)}/`:null;return(0,Y.jsx)(Z,{hint:`app`,toolbar:g&&(0,Y.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,Y.jsx)(df,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(Hu,{children:[`No top-level nav items. Add `,(0,Y.jsx)(`code`,{children:`nav`}),` / `,(0,Y.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,Y.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,Y.jsx)(_f,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function _f({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=hf(e.kind),s=vf(t,e.path);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40 ${i?`cursor-pointer`:``} ${a===r?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+n*16}px`},onClick:i?t=>{t.stopPropagation(),i(r,e)}:void 0,children:[(0,Y.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,Y.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(_f,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function vf(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function yf(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(bf,{...e,icon:t===`password`?(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(ei,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(ti,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.pickDate`,n)});case`time`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(gn,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,Y.jsx)(xf,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(Mt,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??G(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Y.jsx)(Sf,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(Sf,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(Cf,{...e});case`image`:case`avatar`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(Bn,{className:`h-4 w-4`}),label:G(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(An,{className:`h-4 w-4`}),label:W(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(An,{className:`h-4 w-4`}),label:G(`designer.stub.qrcode`,n)});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(Tt,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,Y.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,Y.jsx)(zn,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,Y.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(Ee,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.latLng`,n)});case`address`:return(0,Y.jsx)(xf,{...e,placeholder:e.placeholder??`Street
12
+ }`;let n={};for(let e of t)n[e]=null;return JSON.stringify(n,null,2)}var su=JSON.stringify({id:`user-1`,organization_id:`org-1`,positions:[`admin`]},null,2),cu=[];function lu({open:e,onOpenChange:t,policyName:n,objectName:r,fieldNames:i=cu,using:a,check:o,t:s}){let c=X.useMemo(()=>{let e=[];return a&&a.trim()&&e.push(`using`),o&&o.trim()&&e.push(`check`),e},[a,o]),[l,u]=X.useState(`using`),[d,f]=X.useState(`{}`),[p,m]=X.useState(su),[h,g]=X.useState(null),[_,v]=X.useState(null),[y,b]=X.useState(!1);X.useEffect(()=>{e&&(u(c[0]??`using`),f(ou(i)),m(su),g(null),v(null))},[e]);let x=l===`using`?a??``:o??``;async function S(){g(null),v(null);let e=uu(d,s(`perm.cel.test.record`));if(!e.ok)return v(e.error);let t=uu(p,s(`perm.cel.test.user`));if(!t.ok)return v(t.error);b(!0);try{g(await Sa(x,{record:e.value,currentUser:t.value}))}finally{b(!1)}}return(0,Y.jsx)(Ut,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Qt,{className:`sm:max-w-2xl`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Je,{className:`h-4 w-4 text-muted-foreground`}),s(`perm.cel.test.title`),n?(0,Y.jsxs)(`span`,{className:`text-muted-foreground font-normal`,children:[`· `,n]}):null]}),(0,Y.jsx)(vt,{children:s(`perm.cel.test.help`)})]}),c.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground italic py-4`,children:s(`perm.cel.test.noPredicate`)}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[c.length>1&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`tablist`,"aria-label":s(`perm.cel.test.clause`),children:c.map(e=>(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e,onClick:()=>{u(e),g(null)},className:I(`rounded-md border px-3 py-1 text-xs transition-colors`,l===e?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:s(e===`using`?`perm.rls.using`:`perm.rls.check`)},e))}),(0,Y.jsxs)(`div`,{className:`rounded-md border bg-muted/40 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase text-muted-foreground`,children:[s(l===`using`?`perm.rls.using`:`perm.rls.check`),r?` · ${r}`:``]}),(0,Y.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-xs`,children:x})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-record`,children:s(`perm.cel.test.record`)}),(0,Y.jsx)(lr,{id:`cel-test-record`,value:d,onChange:e=>f(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-user`,children:[s(`perm.cel.test.user`),` `,(0,Y.jsx)(`span`,{className:`font-mono normal-case`,children:`current_user`})]}),(0,Y.jsx)(lr,{id:`cel-test-user`,value:p,onChange:e=>m(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]})]}),_&&(0,Y.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-destructive`,children:[(0,Y.jsx)(wt,{className:`mt-[1px] h-3.5 w-3.5 shrink-0`}),_]}),h&&(0,Y.jsx)(du,{outcome:h,t:s})]}),(0,Y.jsxs)(re,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>t(!1),children:s(`engine.cancel`)}),(0,Y.jsxs)(L,{onClick:S,disabled:y||c.length===0,children:[(0,Y.jsx)(Je,{className:`h-4 w-4 mr-1`}),s(`perm.cel.test.run`)]})]})]})})}function uu(e,t){let n;try{n=JSON.parse(e||`{}`)}catch(e){return{ok:!1,error:`${t}: ${e.message}`}}return!n||typeof n!=`object`||Array.isArray(n)?{ok:!1,error:`${t}: expected a JSON object.`}:{ok:!0,value:n}}function du({outcome:e,t}){return e.status===`allow`?(0,Y.jsx)(pu,{tone:`allow`,icon:(0,Y.jsx)(P,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.allow`),children:t(`perm.cel.test.allowHint`)}):e.status===`deny`?(0,Y.jsx)(pu,{tone:`deny`,icon:(0,Y.jsx)(st,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.deny`),children:t(`perm.cel.test.denyHint`)}):e.status===`value`?(0,Y.jsxs)(pu,{tone:`warn`,icon:(0,Y.jsx)(R,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.nonBool`),children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(e.value)}),` — `,t(`perm.cel.test.nonBoolHint`)]}):e.status===`unavailable`?(0,Y.jsx)(pu,{tone:`warn`,icon:(0,Y.jsx)(R,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.unavailable`),children:t(`perm.cel.test.unavailableHint`)}):(0,Y.jsx)(pu,{tone:`error`,icon:(0,Y.jsx)(wt,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.error`),children:(0,Y.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-[11px]`,children:e.message})})}var fu={allow:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,deny:`border-destructive/40 bg-destructive/10 text-destructive`,warn:`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`,error:`border-destructive/40 bg-destructive/10 text-destructive`};function pu({tone:e,icon:t,title:n,children:r}){return(0,Y.jsxs)(`div`,{className:I(`rounded-md border px-3 py-2 text-xs`,fu[e]),role:`status`,"aria-live":`polite`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium`,children:[t,n]}),(0,Y.jsx)(`div`,{className:`mt-1 opacity-90`,children:r})]})}var mu=[`all`,`select`,`insert`,`update`,`delete`],hu=[`visible`,`hidden`,`default_on`,`default_off`];function gu(e){if(Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return[]}function _u(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return{}}var vu=`h-8 rounded-md border border-input bg-background px-2 text-sm disabled:opacity-50`;function yu({title:e,icon:t,count:n,children:r,defaultOpen:i}){let[a,o]=X.useState(!!i);return(0,Y.jsxs)(pr,{open:a,onOpenChange:o,className:`border-b`,children:[(0,Y.jsxs)(Kn,{className:`flex w-full items-center gap-2 px-6 py-2.5 text-left hover:bg-muted/40`,children:[(0,Y.jsx)(Vt,{className:I(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)}),t,(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n!=null&&n>0&&(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px]`,children:n})]}),(0,Y.jsx)(kr,{className:`px-6 pb-4 pt-1`,children:r})]})}function bu({draft:e,setDraft:t,writable:n,allSetNames:r,loadObjectFields:i,onCelErrorsChange:a,t:o}){let s=X.useMemo(()=>gu(e.rowLevelSecurity),[e.rowLevelSecurity]),c=X.useMemo(()=>_u(e.adminScope),[e.adminScope]),l=X.useMemo(()=>_u(e.tabPermissions),[e.tabPermissions]),[u,d]=X.useState({}),f=X.useRef(new Set),p=X.useCallback(e=>{let t=(e??``).trim();!t||t===`*`||!i||f.current.has(t)||(f.current.add(t),i(t).then(e=>d(n=>({...n,[t]:e}))).catch(()=>d(e=>({...e,[t]:[]}))))},[i]),m=e=>u[(e??``).trim()]??[],[h,g]=X.useState({}),_=X.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;g(t=>t[e]===n?t:{...t,[e]:n})},[]),[v,y]=X.useState(null);X.useEffect(()=>{s.forEach(e=>p(e.object)),g(e=>{let t=new Set;s.forEach((e,n)=>{t.add(`${n}:using`),t.add(`${n}:check`)});let n=!1,r={};for(let i of Object.keys(e))t.has(i)?r[i]=e[i]:n=!0;return n?r:e})},[s,p]);let b=X.useMemo(()=>Object.values(h).reduce((e,t)=>e+t,0),[h]),x=X.useRef(a);X.useEffect(()=>{x.current=a}),X.useEffect(()=>{x.current?.(b)},[b]);let S=v==null?void 0:s[v],C=e=>t(t=>({...t,rowLevelSecurity:e})),w=e=>t(t=>({...t,adminScope:{..._u(t.adminScope),...e}})),T=e=>t(t=>({...t,tabPermissions:e})),E=Object.entries(l);return(0,Y.jsxs)(`div`,{className:`border-b bg-muted/10`,children:[(0,Y.jsxs)(yu,{title:o(`perm.rls.title`),icon:(0,Y.jsx)(Ve,{className:`h-4 w-4 text-muted-foreground`}),count:s.length,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.rls.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[s.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2 bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(B,{value:e.name??``,disabled:!n,placeholder:o(`perm.rls.name`),onChange:n=>{let r=[...s];r[t]={...e,name:n.target.value},C(r)},className:`h-8 w-48`}),(0,Y.jsx)(B,{value:e.object??``,disabled:!n,placeholder:o(`perm.rls.object`),onChange:n=>{let r=[...s];r[t]={...e,object:n.target.value},C(r)},className:`h-8 w-40`}),(0,Y.jsx)(`select`,{value:e.operation??`all`,disabled:!n,onChange:n=>{let r=[...s];r[t]={...e,operation:n.target.value},C(r)},className:vu,children:mu.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(Mt,{checked:e.enabled!==!1,disabled:!n,onCheckedChange:n=>{let r=[...s];r[t]={...e,enabled:!!n},C(r)}}),o(`perm.rls.enabled`)]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 ml-auto text-xs text-muted-foreground`,onClick:()=>y(t),title:o(`perm.cel.test.title`),children:[(0,Y.jsx)(Je,{className:`h-3.5 w-3.5 mr-1`}),o(`perm.cel.test.run`)]}),n&&(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>C(s.filter((e,n)=>n!==t)),children:(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(ea,{label:o(`perm.rls.using`),value:e.using??``,disabled:!n,placeholder:`organization_id == current_user.organization_id`,objectName:e.object,fieldNames:m(e.object),clause:`using`,onLintChange:e=>_(`${t}:using`,e),onChange:n=>{let r=[...s];r[t]={...e,using:n},C(r)},t:o}),(0,Y.jsx)(ea,{label:o(`perm.rls.check`),value:e.check??``,disabled:!n,placeholder:o(`perm.rls.checkPlaceholder`),objectName:e.object,fieldNames:m(e.object),clause:`check`,onLintChange:e=>_(`${t}:check`,e),onChange:n=>{let r=[...s];r[t]={...e,check:n},C(r)},t:o})]})]},t)),s.length===0&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.rls.empty`)}),n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>C([...s,{name:``,object:`*`,operation:`all`,using:``,enabled:!0,priority:0}]),children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),` `,o(`perm.rls.add`)]})]})]}),(0,Y.jsx)(lu,{open:v!=null,onOpenChange:e=>y(e?v:null),policyName:S?.name||void 0,objectName:S?.object,fieldNames:m(S?.object),using:S?.using,check:S?.check,t:o}),(0,Y.jsxs)(yu,{title:o(`perm.tabs.title`),icon:(0,Y.jsx)(ar,{className:`h-4 w-4 text-muted-foreground`}),count:E.length,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.tabs.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[E.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(B,{value:e,disabled:!n,onChange:t=>{let n=t.target.value,r={};for(let[t,i]of E)r[t===e?n:t]=i;T(r)},className:`h-8 w-64`}),(0,Y.jsx)(`select`,{value:t,disabled:!n,onChange:t=>T({...l,[e]:t.target.value}),className:vu,children:hu.map(e=>(0,Y.jsx)(`option`,{value:e,children:o(`perm.tabs.vis.${e}`)},e))}),n&&(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>{let t={...l};delete t[e],T(t)},children:(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]},e)),E.length===0&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.tabs.empty`)}),n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>{l[``]===void 0&&T({...l,"":`visible`})},children:[(0,Y.jsx)(H,{className:`h-4 w-4 mr-1`}),` `,o(`perm.tabs.add`)]})]})]}),(0,Y.jsxs)(yu,{title:o(`perm.admin.title`),icon:(0,Y.jsx)(me,{className:`h-4 w-4 text-muted-foreground`}),count:c.businessUnit||(c.assignablePermissionSets?.length??0)?1:0,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.admin.help`)}),(0,Y.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:o(`perm.admin.businessUnit`)}),(0,Y.jsx)(B,{value:c.businessUnit??``,disabled:!n,onChange:e=>w({businessUnit:e.target.value}),className:`h-8 w-64`})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs pb-1.5`,children:[(0,Y.jsx)(Mt,{checked:!!c.includeSubtree,disabled:!n,onCheckedChange:e=>w({includeSubtree:!!e})}),o(`perm.admin.includeSubtree`)]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[[`manageAssignments`,`perm.admin.manageAssignments`],[`manageBindings`,`perm.admin.manageBindings`],[`authorEnvironmentSets`,`perm.admin.authorEnvironmentSets`]].map(([e,t])=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(Mt,{checked:!!c[e],disabled:!n,onCheckedChange:t=>w({[e]:!!t})}),o(t)]},e))}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:o(`perm.admin.assignableSets`)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[r.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o(`perm.admin.noSets`)}),r.map(e=>{let t=(c.assignablePermissionSets??[]).includes(e);return(0,Y.jsx)(`button`,{type:`button`,disabled:!n,"aria-pressed":t,onClick:()=>{let n=c.assignablePermissionSets??[],r=t?n.filter(t=>t!==e):[...n,e];w({assignablePermissionSets:r})},className:I(`rounded-full border px-3 py-1 text-xs transition-colors disabled:opacity-50`,t?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:e},e)})]})]})]})]})]})}function xu(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Su(e){return e instanceof Set?e:new Set(e)}function Cu(e,t){let n=Su(t),r={};for(let[t,i]of Object.entries(e.objects??{}))n.has(t)&&(r[t]=i);let i={};for(let[t,r]of Object.entries(e.fields??{}))n.has(xu(t))&&(i[t]=r);return{objects:r,fields:i}}function wu(e,t,n){let r=Su(n),i={};for(let[t,n]of Object.entries(e.objects??{}))r.has(t)||(i[t]=n);for(let[e,n]of Object.entries(t.objects??{}))r.has(e)&&(i[e]=n);let a={};for(let[t,n]of Object.entries(e.fields??{}))r.has(xu(t))||(a[t]=n);for(let[e,n]of Object.entries(t.fields??{}))r.has(xu(e))&&(a[e]=n);return{...e,name:t.name,label:t.label,isDefault:t.isDefault,objects:i,fields:a}}function Tu(e,t){let n={private:`perm.owd.private`,public_read:`perm.owd.public_read`,public_read_write:`perm.owd.public_read_write`,controlled_by_parent:`perm.owd.controlled_by_parent`};return n[t]?e(n[t]):t}function Eu(e){return[{key:`allowCreate`,short:`C`,tip:G(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:G(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:G(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:G(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:G(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:G(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:G(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:G(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:G(`perm.action.modifyAll`,e)}]}function Du({type:e,name:t,packageId:n,onDraftSaved:r,publishNonce:a,onOpenOwd:o,onDirtyChange:s,readOnly:c=!1,embedded:l=!1}){let u=i(),d=Ai(),f=S(),{entries:p}=Mi(d),m=p.find(t=>t.type===e),h=!!xc(e,m).allowOrgOverride&&!c,g=Ti(),_=X.useCallback(e=>G(e,g),[g]),v=X.useMemo(()=>Eu(g),[g]),[y,b]=X.useState({name:t,objects:{},fields:{}}),x=X.useRef(null),C=X.useCallback(e=>{try{x.current=JSON.stringify(e)}catch{x.current=null}b(e)},[]),[w,T]=X.useState([]),[E,D]=X.useState({}),[O,k]=X.useState(new Set),[A,ee]=X.useState(!0),[j,te]=X.useState(!1),[ne,M]=X.useState(null),[N,ie]=X.useState(null),[ae,oe]=X.useState(``),[se,P]=X.useState(!1),[ce,le]=X.useState(!1),[ue,de]=X.useState(!1),[F,fe]=X.useState(!1),[pe,me]=X.useState([]);X.useEffect(()=>{let e=!1;return d.list(`permission`,{}).then(t=>{e||me((t||[]).map(e=>e?.name).filter(e=>!!e))}).catch(()=>{}),()=>{e=!0}},[d]),X.useEffect(()=>{let r=!1;return ee(!0),(async()=>{try{let[i,a,o]=await Promise.all([d.layered(e,t).catch(()=>null),d.list(`object`,n?{packageId:n}:{}).catch(()=>[]),n?d.getDraft(e,t,{packageId:n}).catch(()=>null):Promise.resolve(null)]);if(r)return;let s=(o?o.item??o:null)??i?.effective??i?.code??{name:t,objects:{}},c=(a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label,accessDefault:t?.access?.default,owd:typeof t?.sharingModel==`string`?t.sharingModel:void 0,owdExternal:typeof t?.externalSharingModel==`string`?t.externalSharingModel:void 0}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));T(c);let l={...s,name:String(s?.name??t),objects:s?.objects??{},fields:s?.fields??{}};if(n){let e=Cu(l,c.map(e=>e.name));C({...l,objects:e.objects,fields:e.fields})}else C(l)}catch(e){M(e?.message??String(e))}finally{r||ee(!1)}})(),()=>{r=!0}},[d,e,t,n,a,C]);async function he(e){if(!E[e])try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>({name:String(e?.name??``),label:e?.label})):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>({name:String(t?.name??e),label:t?.label})):[]).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));D(t=>({...t,[e]:n}))}catch{D(t=>({...t,[e]:[]}))}}let ge=X.useCallback(async e=>{try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>String(e?.name??``)):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>String(t?.name??e)):[]).filter(Boolean);return Array.from(new Set(n)).sort((e,t)=>e.localeCompare(t))}catch{return[]}},[d]),[_e,ve]=X.useState(0),ye=X.useMemo(()=>{let e=x.current;if(e==null)return!1;try{return JSON.stringify(y)!==e}catch{return!1}},[y]),be=X.useRef(s);X.useEffect(()=>{be.current=s}),X.useEffect(()=>{be.current?.(ye)},[ye]),X.useEffect(()=>()=>{be.current?.(!1)},[]),X.useEffect(()=>{if(!ye)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ye]);function xe(e){k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),he(e)),n})}function Se(e,t,n){b(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function Ce(e,t){b(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(v.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function we(e,t,n,r){let i=`${e}.${t}`;b(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}function Te(e,t,n){n.length!==0&&b(r=>{let i={...r.fields??{}};for(let r of n){let n=`${e}.${r}`;t===`clear`?delete i[n]:t===`readable`?i[n]={readable:!0,editable:!1}:i[n]={readable:!0,editable:!0}}return{...r,fields:i}})}function Ee(e){if(!n)return e;let t=Cu(e,w.map(e=>e.name));return{...e,objects:t.objects,fields:t.fields}}async function De(t,i){let a=i??y;te(!0),M(null);try{let i=a;if(n){let t=w.map(e=>e.name);i=wu((await d.layered(e,a.name).catch(()=>null))?.effective??a,a,t)}if(await d.save(e,a.name,i,{force:t,...n?{mode:`draft`,packageId:n}:{}}),n)C(Ee(i)),r?.();else{let t=await d.layered(e,a.name);C(Ee(t.effective??i))}ie(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];ie({issues:Array.isArray(t)?t:[],pending:a})}else M(e?.message??String(e))}finally{te(!1)}}let Oe=X.useMemo(()=>{let e=ae.trim().toLowerCase();return w.filter(t=>{if(se){let e=y.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return!e||t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)})},[w,ae,se,y.objects]),ke=[{label:_(`perm.stat.objectsGranted`),value:Object.values(y.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:_(`perm.stat.fieldOverrides`),value:Object.keys(y.fields??{}).length}];return A?(0,Y.jsx)(fc,{entry:m,itemName:t,embedded:l,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` `,_(`perm.loading`).replace(`{name}`,t)]})}):(0,Y.jsxs)(fc,{entry:m??{type:e,label:e},itemName:t,subtitle:_(`perm.subtitle.set`),stats:ke,embedded:l,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>l?fe(!0):u(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(Wr,{className:`h-4 w-4 mr-1`}),` `,_(`engine.edit.history`)]}),h&&(0,Y.jsxs)(L,{size:`sm`,onClick:()=>De(!1),disabled:j||_e>0,title:_e>0?_(`perm.cel.saveBlocked`):void 0,children:[j?(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(ai,{className:`h-4 w-4 mr-1`}),_(`engine.edit.save`)]})]}),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[ne&&(0,Y.jsxs)(`div`,{className:`m-4 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive flex items-start gap-2`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:ne})]}),(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>le(e=>!e),"aria-expanded":ce,className:`w-full px-6 py-2.5 flex items-center gap-2 text-left hover:bg-muted/50 transition-colors`,children:[ce?(0,Y.jsx)(Ke,{className:`h-4 w-4 shrink-0 text-muted-foreground`}):(0,Y.jsx)(Vt,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:y.label||y.name}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px] shrink-0`,children:y.managedBy===`platform`?_(`perm.badge.platform`):y.managedBy===`package`||n?_(`perm.badge.package`):_(`perm.badge.custom`)}),!!y.isDefault&&(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px] shrink-0`,children:_(`perm.badge.default`)}),h&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:_(`perm.basics.editHint`)}),!h&&(0,Y.jsx)(z,{variant:`secondary`,className:`ml-auto shrink-0`,title:c?_(`engine.studio.pkg.readonlyHint`):void 0,children:_(c?`engine.studio.pkg.readonly`:`perm.readOnly`)})]}),ce&&(0,Y.jsxs)(`div`,{className:`px-6 pb-3 flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{htmlFor:`perm-name`,className:`text-xs`,children:_(`perm.field.name`)}),(0,Y.jsx)(B,{id:`perm-name`,value:y.name,disabled:!h,onChange:e=>b(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{htmlFor:`perm-label`,className:`text-xs`,children:_(`perm.field.label`)}),(0,Y.jsx)(B,{id:`perm-label`,value:y.label??``,disabled:!h,onChange:e=>b(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]})]})]}),h&&(y.systemPermissions??[]).length===0&&!ue?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:_(`perm.field.systemCapabilities`)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:_(`perm.cap.none`)}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>de(!0),children:[`+ `,_(`perm.cap.add`)]})]}):(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:_(`perm.field.systemCapabilities`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 mb-2`,children:_(`perm.field.systemCapabilitiesHelp`)}),(0,Y.jsx)(at,{value:JSON.stringify(y.systemPermissions??[]),onChange:e=>b(t=>({...t,systemPermissions:Qn(e)})),field:{name:`system_permissions`},dataSource:f,readonly:!h})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,Y.jsx)(B,{placeholder:_(`perm.filter.placeholder`),value:ae,onChange:e=>oe(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Mt,{id:`only-enabled`,checked:se,onCheckedChange:e=>P(!!e)}),(0,Y.jsx)(U,{htmlFor:`only-enabled`,className:`text-xs`,children:_(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[Oe.length,` / `,w.length,` `,_(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`px-6 py-2 border-b flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:v.map(e=>(0,Y.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:e.short}),` `,e.tip]},e.key))}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[(0,Y.jsx)(Ou,{objects:Oe,draft:y,expanded:O,fieldsByObject:E,writable:h,objectActions:v,t:_,onToggleExpand:xe,onObjectPerm:Se,onFieldPerm:we,onBulkSet:Ce,onFieldBulk:Te,onOpenOwd:o}),(0,Y.jsx)(bu,{draft:y,setDraft:b,writable:h,allSetNames:pe,loadObjectFields:ge,onCelErrorsChange:ve,t:_})]})]}),(0,Y.jsx)(Ut,{open:!!N,onOpenChange:e=>!e&&ie(null),children:(0,Y.jsxs)(Qt,{children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 text-amber-500`}),` `,_(`engine.edit.destructive`)]}),(0,Y.jsx)(vt,{children:_(`engine.edit.destructiveHint`)})]}),(0,Y.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:N?.issues.map((e,t)=>(0,Y.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,Y.jsx)(z,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Y.jsxs)(re,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>ie(null),children:_(`engine.cancel`)}),(0,Y.jsxs)(L,{variant:`destructive`,onClick:()=>N&&De(!0,N.pending),disabled:j,children:[j&&(0,Y.jsx)(V,{className:`h-4 w-4 mr-1 animate-spin`}),_(`engine.edit.forceSave`)]})]})]})}),l&&(0,Y.jsx)(wr,{open:F,onOpenChange:fe,children:(0,Y.jsxs)(Be,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Kt,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(tn,{className:`text-base`,children:_(`engine.edit.history`)}),(0,Y.jsxs)(Xt,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:F&&(0,Y.jsx)(Zc,{type:e,name:t,client:d})})]})})]})}function Ou({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u,onFieldBulk:d,onOpenOwd:f}){return(0,Y.jsxs)(`table`,{className:`w-full min-w-[960px] text-sm`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,Y.jsxs)(`tbody`,{children:[e.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-4 py-8 text-center text-muted-foreground`,children:o(`perm.filter.empty`)})}),e.map(e=>{let p=t.objects[e.name]??{},m=n.has(e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 align-middle`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[m?(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Vt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]}),e.accessDefault===`private`&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 border-amber-500/50 text-amber-600 dark:text-amber-400 text-[10px] px-1.5 py-0 align-middle`,title:o(`perm.posture.private.tip`),children:o(`perm.posture.private`)}),(0,Y.jsx)(z,{variant:`outline`,className:`ml-2 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`+(f?` cursor-pointer hover:text-foreground hover:border-foreground/40 focus:outline-none focus:ring-1 focus:ring-primary`:``),title:o(f?`perm.owd.editLink`:`perm.owd.tip`),...f?{role:`button`,tabIndex:0,"data-testid":`owd-badge-${e.name}`,onClick:()=>f(e.name),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),f(e.name))}}:{},children:`OWD ${e.owd?Tu(o,e.owd):o(`perm.owd.defaultPrivate`)}`}),e.owdExternal&&(0,Y.jsx)(z,{variant:`outline`,className:`ml-1 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`,title:o(`perm.owd.ext.tip`),children:`Ext ${Tu(o,e.owdExternal)}`})]}),a.map(t=>(0,Y.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,Y.jsx)(un,{checked:!!p[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`read`),children:o(`perm.bulk.read`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`crud`),children:o(`perm.bulk.crud`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`all`),children:o(`perm.bulk.all`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),m&&(0,Y.jsx)(`tr`,{className:`bg-muted/10`,children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,Y.jsx)(ku,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l,onFieldBulk:d})})})]},e.name)})]})]})}function ku({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a,onFieldBulk:o}){let[s,c]=X.useState(``);if(!t)return(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]});if(t.length===0)return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)});let l=s.trim().toLowerCase(),u=l?t.filter(e=>e.name.toLowerCase().includes(l)||(e.label??``).toLowerCase().includes(l)):t,d=u.map(e=>e.name);return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t.length>6&&(0,Y.jsx)(B,{value:s,onChange:e=>c(e.target.value),placeholder:i(`perm.field.filter`),"aria-label":i(`perm.field.filter`),className:`h-7 w-44 text-xs`}),r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`readable`,d),children:i(`perm.field.bulk.readable`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`writable`,d),children:i(`perm.field.bulk.writable`)}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`clear`,d),children:i(`perm.field.bulk.clear`)})]}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[u.length,` / `,t.length]})]}),u.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.filterEmpty`)}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,Y.jsx)(`tbody`,{children:u.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,Y.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,Y.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(un,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(un,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]})]})}function Au(){vc({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>ju(e.fields),groupLabel:`Fields`,order:5}]}),vc({type:`__object_index`,label:`Index`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`index`,embeddedPath:`indexes`,extract:e=>{let t=e.indexes;return Array.isArray(t)?t.map((e,t)=>{let n=Array.isArray(e.fields)?e.fields.join(`,`):``;return{name:n?`idx_${n}`:`index_${t}`,...e}}):[]},groupLabel:`Indexes`,order:10}]}),vc({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>ju(e.validations),groupLabel:`Embedded Validations`,order:15}]}),vc({type:`hook`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable hook name.`},name:{type:`string`,title:`Name`,description:`Hook key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object whose row lifecycle (beforeInsert / afterUpdate / …) this hook runs on.`},description:{type:`string`,title:`Description`,description:`What this hook does.`}}},createDefaults:{events:[]}}),vc({type:`page`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`object`,`type`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`type`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable page title.`},name:{type:`string`,title:`Name`,description:`Page key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},type:{type:`string`,title:`Page type`,enum:[`list`,`record`,`home`,`app`,`utility`],default:`list`,description:`List / Interface page = a data view (Airtable-style: columns, filters, visualizations). Record page renders one object record.`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this page reads from — the data source for a list page, or the record object for a record page.`},kind:{type:`string`,title:`Kind`,enum:[`full`,`slotted`],default:`full`,description:`full = the whole page; slotted = override only named slots of the default.`}}},createDefaults:{type:`list`,kind:`full`,regions:[]},createSeed:async(e,{client:t})=>{if(e?.type===`list`)return e?.object?{interfaceConfig:{source:String(e.object)}}:{};if(e?.type!==`record`||!e?.object)return{};try{let n=await t.get(`object`,String(e.object));if(!n||typeof n!=`object`)return{};let{buildDefaultPageSchema:r}=await a(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-BGSw-KmQ.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),i=r(n),o={};return Array.isArray(i?.regions)&&i.regions.length&&(o.regions=i.regions),i?.template&&(o.template=i.template),o}catch{return{}}}}),vc({type:`view`,anchors:[{anchorType:`object`,match:gc([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`viewKind`,`kind`,`formType`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`viewKind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`View key (snake_case). Qualified to <object>.<key> on save.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this view displays.`},viewKind:{type:`string`,title:`View family`,enum:[`list`,`form`],default:`list`,description:`List views show many records as a collection (grid, kanban, …). Form views show one record as a field layout (simple, tabbed, …).`},kind:{type:`string`,title:`List layout`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'list'`},formType:{type:`string`,title:`Form layout`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`],default:`simple`,description:`Pick a starter form layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'form'`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``),r=n.includes(`.`)||!t?n:`${t}.${n}`,i=e.viewKind===`form`,a=i?{type:e.formType||`simple`,data:{provider:`object`,object:t},sections:[]}:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}};return{name:r,object:t,viewKind:i?`form`:`list`,label:e.label,config:a}}}),vc({type:`flow`,anchors:[{anchorType:`object`,match:gc([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`autolaunched`,nodes:[],edges:[]}}),vc({type:`validation`,anchors:[{anchorType:`object`,match:gc(`object`),groupLabel:`Validations`,order:25}],createFields:[`label`,`name`,`message`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`message`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable rule name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},message:{type:`string`,title:`Error message`,description:`Shown to the user when the rule blocks save.`}}},createDefaults:{type:`script`,active:!0,events:[`insert`,`update`],priority:10,severity:`error`,condition:`false`}}),vc({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}],createFields:[`label`,`name`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),vc({type:`action`,anchors:[{anchorType:`object`,match:gc([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable action name.`},name:{type:`string`,title:`Name`,description:`Action key (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},objectName:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this action is bound to. Leave empty for a global / record-scoped action.`},icon:{type:`string`,title:`Icon`,widget:`icon`,description:`Optional icon shown on the action button.`}}},createDefaults:{type:`script`,body:{language:`js`,source:`return { success: true };`}}}),vc({type:`dashboard`,anchors:[{anchorType:`object`,match:gc([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),vc({type:`report`,anchors:[{anchorType:`object`,match:gc([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`summary`,drilldown:!0}}),vc({type:`object`,iconName:`database`,domain:`data`,createFields:[`label`,`pluralLabel`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0},{from:`label`,to:`pluralLabel`,transform:`plural-en`,untilUserEdits:!0}],createDefaults:{fields:{}},searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function ju(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Mu={name:{type:`string`,title:`Name`,description:`Machine name. snake_case, used as the URL path and DB key.`,pattern:`^[a-z_][a-z0-9_]*$`},label:{type:`string`,title:`Label`,description:`Human-readable display name.`},description:{type:`string`,title:`Description`,format:`multiline`}},Nu={position:{type:`object`,title:`Position`,required:[`name`],properties:{...Mu}},permission:{type:`object`,title:`Permission`,required:[`id`,`resource`,`actions`,`description`],properties:{id:{type:`string`,title:`ID`,description:`Stable identifier (e.g. crm.account.read).`},resource:{type:`string`,title:`Resource`,description:`What this permission applies to.`,enum:[`data.object`,`data.record`,`data.field`,`ui.view`,`ui.dashboard`,`ui.report`,`system.config`,`system.plugin`,`system.api`,`system.service`,`storage.file`,`storage.database`,`network.http`,`network.websocket`,`process.spawn`,`process.env`]},actions:{type:`array`,title:`Actions`,description:`Permitted operations on the resource.`,items:{type:`string`,enum:[`create`,`read`,`update`,`delete`,`execute`,`admin`,`manage`,`configure`,`import`,`export`,`share`]}},description:{type:`string`,title:`Description`,description:`Why this permission exists (shown in admin UIs).`},scope:{type:`string`,title:`Scope`,enum:[`tenant`,`user`,`plugin`,`global`,`resource`],default:`tenant`},required:{type:`boolean`,title:`Required`,description:`Must be present for the holder to function.`},justification:{type:`string`,title:`Justification`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...Mu.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Mu.label,description:Mu.description,locale:{type:`string`,title:`Locale`,description:`BCP-47 tag, e.g. en, zh-Hans, ja-JP.`},strings:{type:`object`,title:`Strings`,description:`Key → translated string map.`}}},tool:{type:`object`,title:`AI Tool`,required:[`name`],properties:{...Mu,kind:{type:`string`,title:`Kind`,enum:[`function`,`http`,`mcp`]},inputSchema:{type:`object`,title:`Input Schema (JSON Schema)`},outputSchema:{type:`object`,title:`Output Schema (JSON Schema)`}}},skill:{type:`object`,title:`AI Skill`,required:[`name`],properties:{...Mu,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}},surface:{type:`string`,title:`Surface`,description:`Agent surface this skill binds to (ADR-0063).`,enum:[`ask`,`build`,`both`]},triggerPhrases:{type:`array`,title:`Trigger Phrases`,description:`Natural-language phrases that activate this skill.`,items:{type:`string`}},triggerConditions:{type:`array`,title:`Trigger Conditions`,description:`Programmatic activation conditions (context field / operator / value). The activation-critical field — previously only hand-editable (#1878/#1895).`,items:{type:`object`,properties:{field:{type:`string`,title:`Field`},operator:{type:`string`,title:`Operator`,enum:[`eq`,`neq`,`in`,`not_in`,`contains`]},value:{type:`string`,title:`Value`}}}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Mu,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Mu,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Mu,type:{type:`string`,title:`View Type`,enum:[`grid`,`kanban`,`calendar`,`gantt`,`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]}}},dashboard:{type:`object`,title:`Dashboard`,required:[`name`],properties:{...Mu,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Mu,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...Mu,slug:{type:`string`,title:`Slug`,description:`Portal URL segment; defaults to the name without its package prefix.`},icon:{type:`string`,title:`Icon`},order:{type:`number`,title:`Order`,description:`Orders books within the portal.`},audience:{title:`Audience`,description:`Access audience. 'org' (default) inherits the package grant; 'public' is anonymously readable; { permissionSet } gates by a permission set the reader must hold (ADR-0090).`,oneOf:[{type:`string`,enum:[`org`,`public`]},{type:`object`,title:`Permission-set gated`,properties:{permissionSet:{type:`string`,title:`Permission set`}},required:[`permissionSet`]}]},groups:{type:`array`,title:`Groups (spine)`,description:`Ordered sections. Membership is derived from each group's include rule — edit the structure visually in the Preview tab.`,items:{type:`object`,required:[`key`,`label`],properties:{key:{type:`string`,title:`Key`,pattern:`^[a-z][a-z0-9_]*$`},label:{type:`string`,title:`Label`},order:{type:`number`,title:`Order`},include:{title:`Include rule`,description:`Glob over doc names (e.g. crm_guide_*) or { tag }.`},package:{type:`string`,title:`Package scope`},pages:{type:`array`,title:`Explicit pages (override)`,items:{}}}}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...Mu,category:{type:`string`,title:`Category`,enum:[`auth`,`notification`,`workflow`,`marketing`,`custom`],default:`custom`},locale:{type:`string`,title:`Locale`,default:`en-US`,description:`BCP-47 tag (en-US, zh-CN, …)`},subject:{type:`string`,title:`Subject`,description:`Supports {{var.path}} interpolation`},bodyHtml:{type:`string`,title:`HTML Body`,format:`multiline`},bodyText:{type:`string`,title:`Plain-Text Body`,format:`multiline`},variables:{type:`array`,title:`Variables`,items:{type:`object`}},fromOverride:{type:`object`,title:`From Override`},replyTo:{type:`string`,title:`Reply-To`},active:{type:`boolean`,title:`Active`,default:!0},isSystem:{type:`boolean`,title:`System Template`,default:!1}}}};function Pu(){for(let[e,t]of Object.entries(Nu))vc({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}var Fu=[{value:`managed`,label:`Managed (ObjectStack owns the schema)`},{value:`external`,label:`External (read existing schema as-is)`},{value:`validate-only`,label:`Validate only`}],Iu=``.replace(/\/+$/,``),Lu=e=>e.format===`password`;function Ru(e){let t=e?.configSchema?.properties??{},n={};for(let[e,r]of Object.entries(t))Lu(r)||r.default!==void 0&&(n[e]=r.default);return n}function zu(e){let t=X.useMemo(()=>d(),[]),n=Ai(),[r,i]=X.useState([]),[a,o]=X.useState(!0),[s,c]=X.useState(null),l=X.useCallback(async(e,n)=>{let r=await t(`${Iu}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`},...n}),i=await r.text(),a=i;try{a=JSON.parse(i)}catch{}if(!r.ok)throw Error(a&&(a.message||a.error)||`HTTP ${r.status}`);return a},[t]),u=X.useCallback(async()=>{o(!0);try{let e=await l(`/api/v1/datasources`);i(Array.isArray(e?.datasources)?e.datasources:[])}catch(e){si.error(`Load datasources: ${e.message}`),i([])}finally{o(!1)}},[l]);X.useEffect(()=>{u()},[u]);let f=async e=>{c(`test:${e}`);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/test`,{method:`POST`,body:`{}`});si.success(t?.ok===!1?`${e}: ${t?.error??`failed`}`:`${e}: connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`),u()}catch(t){si.error(`${e}: ${t.message}`)}finally{c(null)}},p=async e=>{if(window.confirm(`Delete datasource “${e}”? This cannot be undone.`)){c(`del:${e}`);try{await l(`/api/v1/datasources/${encodeURIComponent(e)}`,{method:`DELETE`}),si.success(`Deleted ${e}.`),u()}catch(t){si.error(`Delete ${e}: ${t.message}`)}finally{c(null)}}},[m,h]=X.useState([]),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState(null),[S,C]=X.useState(!1),[w,T]=X.useState(!1),[E,D]=X.useState(null),[O,k]=X.useState(!1),A=X.useCallback(async()=>{if(m.length)return m;try{let e=await l(`/api/v1/datasources/drivers`),t=Array.isArray(e?.drivers)?e.drivers:[];return h(t),t}catch(e){return si.error(`Load drivers: ${e.message}`),[]}},[l,m]),ee=X.useMemo(()=>m.find(e=>e.id===b?.driver),[m,b?.driver]),j=async()=>{let e=await A(),t=e.find(e=>e.id!==`memory`)??e[0];y(null),C(!1),D(null),x({name:``,label:``,driver:t?.id??``,schemaMode:`managed`,config:Ru(t),secret:``}),_(!0)},te=async e=>{let t=await A();c(`edit:${e.name}`);try{let n=(await l(`/api/v1/datasources/${encodeURIComponent(e.name)}`))?.datasource??{};y(e.name),C(!!n.hasSecret),D(null),x({name:n.name??e.name,label:n.label??``,driver:n.driver??e.driver??t[0]?.id??``,schemaMode:n.schemaMode??`managed`,config:{...n.config??{}},secret:``}),_(!0)}catch(t){si.error(`Open ${e.name}: ${t.message}`)}finally{c(null)}},ne=e=>{x(t=>t&&{...t,driver:e,config:Ru(m.find(t=>t.id===e)),secret:``}),D(null)},M=(e,t)=>x(n=>n&&{...n,config:{...n.config,[e]:t}}),N=e=>{let t={label:e.label||void 0,driver:e.driver,schemaMode:e.schemaMode,config:e.config};return e.secret&&(t.secret=e.secret),t},ie=async()=>{if(b){k(!0),D(null);try{let e=await l(`/api/v1/datasources/test`,{method:`POST`,body:JSON.stringify({driver:b.driver,config:b.config,...b.secret?{secret:b.secret}:{}})}),t=e?.result??e;t?.ok===!1?D({ok:!1,text:t?.error??`Connection failed`}):D({ok:!0,text:`Connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`})}catch(e){D({ok:!1,text:e.message})}finally{k(!1)}}},ae=async()=>{if(b){T(!0);try{v?(await l(`/api/v1/datasources/${encodeURIComponent(v)}`,{method:`PATCH`,body:JSON.stringify(N(b))}),si.success(`Updated ${v}.`)):(await l(`/api/v1/datasources`,{method:`POST`,body:JSON.stringify({name:b.name,...N(b)})}),si.success(`Created ${b.name}.`)),_(!1),u()}catch(e){si.error(`Save: ${e.message}`)}finally{T(!1)}}},se=v?!0:/^[a-z_][a-z0-9_]*$/.test(b?.name??``),P=!!b&&!!b.driver&&se&&!w,[ce,le]=X.useState(null),[ue,de]=X.useState(null),[F,fe]=X.useState(new Set),[pe,me]=X.useState(!1),he=async e=>{le(e),de(null),fe(new Set);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/remote-tables`);de(Array.isArray(t?.tables)?t.tables:[])}catch(t){si.error(`Introspect ${e}: ${t.message}`),de([])}},ge=e=>fe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),_e=async()=>{if(!ce||F.size===0)return;me(!0);let e=0,t=[];for(let r of F)try{let{draft:t}=await l(`/api/v1/datasources/${encodeURIComponent(ce)}/object-draft`,{method:`POST`,body:JSON.stringify({table:r})});await n.save(`object`,t.name,t.definition),e+=1}catch(e){t.push(`${r}: ${e.message}`)}me(!1),e&&si.success(`Synced ${e} object${e>1?`s`:``} from ${ce}.`),t.length&&si.error(`Failed: ${t.join(`; `)}`),le(null)},ve=(e,t)=>{let n=t.title||e,r=(ee?.configSchema?.required??[]).includes(e);if(Lu(t))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r&&!v?` *`:``]}),(0,Y.jsx)(B,{type:`password`,value:b?.secret??``,placeholder:v&&S?`•••••••• (leave blank to keep)`:``,onChange:e=>x(t=>t&&{...t,secret:e.target.value})}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e);let i=b?.config[e];if(t.type===`boolean`)return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(U,{className:`text-xs`,children:n}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]}),(0,Y.jsx)(Mt,{checked:!!i,onCheckedChange:t=>M(e,t)})]},e);if(Array.isArray(t.enum))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsxs)(oe,{value:i==null?``:String(i),onValueChange:t=>M(e,t),children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{placeholder:`Select…`})}),(0,Y.jsx)(En,{children:t.enum.map(e=>(0,Y.jsx)(Pr,{value:String(e),children:String(e)},String(e)))})]})]},e);let a=t.type===`number`||t.type===`integer`;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(U,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsx)(B,{type:a?`number`:`text`,value:i==null?``:String(i),onChange:t=>M(e,a?t.target.value===``?void 0:Number(t.target.value):t.target.value)}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e)};return(0,Y.jsxs)(`div`,{className:`mx-auto max-w-4xl px-6 py-8`,children:[(0,Y.jsxs)(`div`,{className:`mb-6 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold`,children:[(0,Y.jsx)(ir,{className:`h-5 w-5`}),` Datasources`]}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Connect external databases and sync their tables in as objects.`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:a,children:[(0,Y.jsx)(qt,{className:`mr-1.5 h-4 w-4`+(a?` animate-spin`:``)}),` Refresh`]}),(0,Y.jsxs)(L,{size:`sm`,onClick:()=>void j(),children:[(0,Y.jsx)(H,{className:`mr-1.5 h-4 w-4`}),` New datasource`]})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading…`]}):r.length===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed bg-muted/20 py-16 text-center text-sm text-muted-foreground`,children:[`No datasources yet. Click `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`New datasource`}),` to connect one.`]}):(0,Y.jsx)(`div`,{className:`divide-y rounded-lg border bg-card`,children:r.map(e=>{let t=e.origin===`code`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-[11px] text-muted-foreground`,children:e.name})]}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:e.driver}),e.status&&(0,Y.jsxs)(`span`,{children:[`· `,e.status]}),e.origin&&(0,Y.jsxs)(`span`,{children:[`· `,e.origin]})]})]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,disabled:s===`test:${e.name}`,onClick:()=>void f(e.name),children:[s===`test:${e.name}`?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Un,{className:`mr-1.5 h-4 w-4`}),` Test`]}),(0,Y.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>void he(e.name),children:[(0,Y.jsx)(zr,{className:`mr-1.5 h-4 w-4`}),` Sync objects`]}),!t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,title:`Edit`,disabled:s===`edit:${e.name}`,onClick:()=>void te(e),children:s===`edit:${e.name}`?(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Rr,{className:`h-4 w-4`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,title:`Delete`,disabled:s===`del:${e.name}`,onClick:()=>void p(e.name),children:s===`del:${e.name}`?(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`h-4 w-4`})})]})]},e.name)})}),(0,Y.jsx)(Ut,{open:g,onOpenChange:e=>{e||_(!1)},children:(0,Y.jsxs)(Qt,{className:`max-w-lg`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsx)(Fr,{children:v?`Edit “${v}”`:`New datasource`}),(0,Y.jsx)(vt,{children:v?`Update the connection. Leave the credential blank to keep the current one.`:`Connect an external database. Credentials are encrypted and never stored in metadata.`})]}),b&&(0,Y.jsxs)(`div`,{className:`max-h-[60vh] space-y-3 overflow-y-auto pr-1`,children:[!v&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Name *`}),(0,Y.jsx)(B,{value:b.name,placeholder:`my_database`,onChange:e=>x(t=>t&&{...t,name:e.target.value})}),!se&&b.name.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,children:`Lowercase letters, digits, and underscores; must not start with a digit.`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Label`}),(0,Y.jsx)(B,{value:b.label,placeholder:`Human-friendly name`,onChange:e=>x(t=>t&&{...t,label:e.target.value})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Driver *`}),(0,Y.jsxs)(oe,{value:b.driver,onValueChange:ne,disabled:!!v,children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{placeholder:`Choose a driver`})}),(0,Y.jsx)(En,{children:m.map(e=>(0,Y.jsx)(Pr,{value:e.id,children:e.label},e.id))})]}),ee?.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:ee.description})]}),Object.entries(ee?.configSchema?.properties??{}).map(([e,t])=>ve(e,t)),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs`,children:`Schema mode`}),(0,Y.jsxs)(oe,{value:b.schemaMode,onValueChange:e=>x(t=>t&&{...t,schemaMode:e}),children:[(0,Y.jsx)(fr,{children:(0,Y.jsx)(Dr,{})}),(0,Y.jsx)(En,{children:Fu.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})]}),E&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs `+(E.ok?`text-emerald-600`:`text-destructive`),children:[E.ok?(0,Y.jsx)(Ce,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(ye,{className:`h-3.5 w-3.5`}),E.text]})]}),(0,Y.jsxs)(re,{className:`gap-2 sm:justify-between`,children:[(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,disabled:!b?.driver||O,onClick:()=>void ie(),children:[O?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Un,{className:`mr-1.5 h-4 w-4`}),` Test connection`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,Y.jsxs)(L,{size:`sm`,disabled:!P,onClick:()=>void ae(),children:[w&&(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}),v?`Save changes`:`Create datasource`]})]})]})]})}),(0,Y.jsx)(Ut,{open:!!ce,onOpenChange:e=>{e||le(null)},children:(0,Y.jsxs)(Qt,{className:`max-w-lg`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{children:[`Sync objects from “`,ce,`”`]}),(0,Y.jsx)(vt,{children:`Pick the remote tables to import as objects. Each becomes an object definition.`})]}),ue==null?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Introspecting…`]}):ue.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No remote tables found on this datasource.`}):(0,Y.jsx)(`div`,{className:`max-h-[50vh] space-y-1 overflow-y-auto`,children:ue.map(e=>{let t=e.schema?`${e.schema}.${e.name}`:e.name;return(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:F.has(e.name),onChange:()=>ge(e.name),className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:t}),e.columnCount!=null&&(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.columnCount,` cols`]})]},t)})}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2`,children:[(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>le(null),children:`Cancel`}),(0,Y.jsxs)(L,{size:`sm`,disabled:pe||F.size===0,onClick:()=>void _e(),children:[pe?(0,Y.jsx)(V,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(zr,{className:`mr-1.5 h-4 w-4`}),`Create `,F.size||``,` object`,F.size===1?``:`s`]})]})]})})]})}var Bu=!1;function Vu(){Bu||(Bu=!0,vc({type:`datasource`,label:`Datasources`,domain:`data`,ListPage:zu}))}function Z({toolbar:e,children:t}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,Y.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function Hu({tone:e=`info`,children:t}){return(0,Y.jsxs)(`div`,{className:`m-4 rounded border p-3 text-sm flex items-start gap-2 ${e===`warn`?`text-amber-800 bg-amber-50 border-amber-200`:e===`error`?`text-destructive bg-destructive/5 border-destructive/30`:`text-muted-foreground border-muted`}`,children:[e!==`info`&&(0,Y.jsx)(wt,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function Uu({icon:e,title:t,description:n,action:r,tone:i=`info`}){let a=i===`warn`?`text-amber-700 bg-amber-50/40 border-amber-200/60`:`text-muted-foreground border-dashed border-muted-foreground/25 bg-muted/10`,o=e??(0,Y.jsx)(br,{className:`h-8 w-8 opacity-50`});return(0,Y.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,Y.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border ${a} px-6 py-10 flex flex-col items-center gap-3 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,Y.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,Y.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Q=class extends X.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,Y.jsxs)(Hu,{tone:`error`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,Y.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,Y.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function Wu({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:I(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var Gu=X.lazy(async()=>({default:(await a(()=>import(`./dist-B4b49_J4.js`).then(e=>e.n),[],import.meta.url)).default}));function Ku(e){let t=e.languages.typescript;t.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.typescriptDefaults.setCompilerOptions({jsx:t.JsxEmit.React,target:t.ScriptTarget.Latest,allowNonTsExtensions:!0,allowJs:!0,noEmit:!0})}function qu({draft:e,onPatch:t,readOnly:n,fallbackDelayMs:r=4e3,mode:i=`split`}){let a=e.kind===`react`?`react`:`html`,o=typeof e.source==`string`?e.source:``,[s,c]=X.useState(o),l=X.useRef(o);X.useEffect(()=>{o!==l.current&&(c(o),l.current=o)},[o]);let[u,d]=Ol(r),[f,p]=X.useState(()=>typeof document<`u`&&document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>p(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let m=e=>{let n=e??``;c(n),l.current=n,t?.({source:n})},h=X.useMemo(()=>({...e,type:e.type??`page`}),[e]),g=(0,Y.jsx)(`div`,{ref:d,className:`h-full min-h-[260px] overflow-hidden bg-background`,children:u?(0,Y.jsx)(`textarea`,{value:s,onChange:e=>m(e.target.value),readOnly:n,spellCheck:!1,"aria-label":`Page source`,className:`h-full w-full resize-none bg-background p-3 font-mono text-xs leading-relaxed outline-none`}):(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(Te,{className:`h-full w-full`}),children:(0,Y.jsx)(Gu,{value:s,language:`typescript`,path:a===`react`?`page.tsx`:`page.html.tsx`,theme:f,beforeMount:Ku,onChange:m,options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),_=(0,Y.jsx)(`div`,{className:`h-full min-h-[260px] overflow-auto bg-muted/20`,children:(0,Y.jsx)(Q,{fallbackHint:`The page source threw while rendering — fix the code in the Source tab.`,children:(0,Y.jsx)(v,{schema:h})})});return i===`editor`?g:i===`preview`?(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:_}):(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:(0,Y.jsxs)(`div`,{className:`grid h-full grid-cols-1 divide-y divide-border lg:grid-cols-2 lg:divide-x lg:divide-y-0`,children:[g,_]})})}var Ju={grid:{label:`Grid`,category:`data`,Icon:Or},"object-grid":{label:`Table`,category:`data`,Icon:Br},"object-form":{label:`Form`,category:`data`,Icon:_t},"object-metric":{label:`Metric`,category:`data`,Icon:tr},"object-kanban":{label:`Kanban`,category:`data`,Icon:cr},"page:header":{label:`Header`,category:`layout`,Icon:ar},"page:footer":{label:`Footer`,category:`layout`,Icon:Zr},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Ur},"page:tabs":{label:`Tabs`,category:`layout`,Icon:Xn},"page:accordion":{label:`Accordion`,category:`layout`,Icon:oi},"page:card":{label:`Card`,category:`layout`,Icon:rn},"page:section":{label:`Section`,category:`layout`,Icon:ln},"record:details":{label:`Record details`,category:`record`,Icon:Oe},"record:highlights":{label:`Highlights`,category:`record`,Icon:rr},"record:related_list":{label:`Related list`,category:`record`,Icon:gt},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Jn},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:je},"record:path":{label:`Stage path`,category:`record`,Icon:xr},"record:alert":{label:`Alert banner`,category:`record`,Icon:R},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:rt},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:or},"record:history":{label:`History`,category:`record`,Icon:Wr},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:ri},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:xr},"global:search":{label:`Global search`,category:`navigation`,Icon:Me},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:jn},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:Et},"element:text":{label:`Text`,category:`element`,Icon:Gt},"element:number":{label:`Number`,category:`element`,Icon:ti},"element:image":{label:`Image`,category:`element`,Icon:Bn},"element:divider":{label:`Divider`,category:`element`,Icon:et},"element:button":{label:`Button`,category:`element`,Icon:ot},"element:definition-list":{label:`Definition list`,category:`element`,Icon:Fe},"element:repeater":{label:`Repeater`,category:`element`,Icon:It}},Yu={data:`Data`,layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Xu=(()=>{let e={data:[],layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Ju))e[n.category].push(t);return[`data`,`layout`,`record`,`element`,`navigation`,`ai`,`misc`].map(t=>({category:t,types:e[t]})).filter(e=>e.types.length>0)})(),Zu=xn,Qu={data:{icon:`text-emerald-500 dark:text-emerald-400`,badge:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300`},layout:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},record:{icon:`text-blue-500 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},navigation:{icon:`text-indigo-500 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},element:{icon:`text-teal-500 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},ai:{icon:`text-violet-500 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},misc:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function $u(e){return Qu[Ju[e]?.category??`misc`]}var ed={"object-grid":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`columns`,label:`Columns`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`pageSize`,label:`Page size`,kind:`number`,placeholder:`20`},{name:`striped`,label:`Striped rows`,kind:`boolean`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"object-form":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`mode`,label:`Mode`,kind:`select`,options:[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`view`,label:`View`}]},{name:`formType`,label:`Form type`,kind:`select`,options:[{value:`simple`,label:`Simple`},{value:`tabbed`,label:`Tabbed`},{value:`wizard`,label:`Wizard`},{value:`split`,label:`Split`},{value:`drawer`,label:`Drawer`},{value:`modal`,label:`Modal`}]},{name:`layout`,label:`Layout`,kind:`select`,options:[{value:`vertical`,label:`Vertical`},{value:`horizontal`,label:`Horizontal`},{value:`inline`,label:`Inline`},{value:`grid`,label:`Grid`}]},{name:`columns`,label:`Columns (grid layout)`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`description`,label:`Description`,kind:`text`}],"object-metric":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`label`,label:`Label`,kind:`text`},{name:`description`,label:`Description`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`colorVariant`,label:`Color`,kind:`color`,options:[{value:`default`,label:`Default`},{value:`blue`,label:`Blue`},{value:`teal`,label:`Teal`},{value:`orange`,label:`Orange`},{value:`purple`,label:`Purple`},{value:`success`,label:`Success`},{value:`warning`,label:`Warning`},{value:`danger`,label:`Danger`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"object-kanban":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`groupField`,label:`Group by field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`cardFields`,label:`Card fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`}],grid:[{name:`columns`,label:`Columns`,kind:`number`,placeholder:`3`},{name:`gap`,label:`Gap`,kind:`number`,placeholder:`4`}],"element:text":[{name:`content`,label:`Content`,kind:`text`,placeholder:`Text…`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`heading`,label:`Heading`},{value:`subheading`,label:`Subheading`},{value:`body`,label:`Body`},{value:`caption`,label:`Caption`}]},{name:`align`,label:`Align`,kind:`select`,options:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}],"element:image":[{name:`src`,label:`Source URL`,kind:`text`,placeholder:`https://…`},{name:`alt`,label:`Alt text`,kind:`text`},{name:`fit`,label:`Fit`,kind:`select`,options:[{value:`cover`,label:`Cover`},{value:`contain`,label:`Contain`},{value:`fill`,label:`Fill`}]}],"element:definition-list":[{name:`items`,label:`Items`,kind:`array`,addLabel:`Add item`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`value`,label:`Value`,kind:`text`}]},{name:`columns`,label:`Columns (1 or 2)`,kind:`number`,placeholder:`1`},{name:`inline`,label:`Inline (label · value)`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`},{name:`emptyText`,label:`Empty text`,kind:`text`},{name:`divided`,label:`Dividers between rows`,kind:`boolean`}],"element:number":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`field`,label:`Field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`Aggregate`,kind:`select`,options:[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"element:button":[{name:`label`,label:`Label`,kind:`text`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}]},{name:`size`,label:`Size`,kind:`select`,options:[{value:`small`,label:`Small`},{value:`medium`,label:`Medium`},{value:`large`,label:`Large`}]},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`}],"page:header":[{name:`title`,label:`Title`,kind:`text`},{name:`subtitle`,label:`Subtitle`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`breadcrumb`,label:`Show breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`Title`,kind:`text`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`Tabs`,kind:`array`,addLabel:`Add tab`,itemFields:[{name:`key`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"page:accordion":[{name:`title`,label:`Title`,kind:`text`},{name:`items`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`value`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`relationshipField`,label:`Relationship field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`}],"record:highlights":[{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`columns`,label:`Columns`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`Severity`,kind:`select`,options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`error`,label:`Error`},{value:`success`,label:`Success`}]},{name:`title`,label:`Title`,kind:`text`},{name:`body`,label:`Body`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`dismissible`,label:`Dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`Status field`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`Stages`,kind:`array`,addLabel:`Add stage`,itemFields:[{name:`value`,label:`Value`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`Action names`,kind:`string-list`,placeholder:`action name`},{name:`location`,label:`Location`,kind:`select`,options:[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record more menu`},{value:`record_section`,label:`Record section`},{value:`record_related`,label:`Record related`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List item`},{value:`global_nav`,label:`Global nav`}]}],"ai:chat_window":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}],"ai:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function td(e){return!!e&&Array.isArray(ed[e])&&ed[e].length>0}function nd(){let e=Ai(),[t,n]=X.useState([]),[r,i]=X.useState(!0);return X.useEffect(()=>{let t=!1;return i(!0),e.list(`object`).then(e=>{if(t)return;let r=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));n(r),i(!1)}).catch(()=>{t||(n([]),i(!1))}),()=>{t=!0}},[e]),{options:t,loading:r}}function rd(e){let{fields:t}=Ki(e);return X.useMemo(()=>t.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[t])}function id({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=nd();return i.length===0?(0,Y.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(K,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function ad({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=rd(t);return!t||a.length===0?(0,Y.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(K,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function od({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=rd(t),o=Array.isArray(n)?n:[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(oe,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,Y.jsx)(fr,{className:`h-8`,children:(0,Y.jsx)(Dr,{placeholder:`—`})}),(0,Y.jsx)(En,{children:a.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})}):(0,Y.jsx)(B,{className:`h-8 text-sm`,value:String(e??``),placeholder:`field name`,disabled:i,onChange:e=>{let n=[...o];n[t]=e.target.value,r(n)}}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":`Remove`,onClick:()=>r(o.filter((e,n)=>n!==t)),children:(0,Y.jsx)(Se,{className:`h-4 w-4`})})]},t)),!i&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}function sd(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return``}}function cd({label:e,value:t,onCommit:n,disabled:r}){let i=X.useMemo(()=>sd(t),[t]),[a,o]=X.useState(i),[s,c]=X.useState(null);return X.useEffect(()=>{o(i),c(null)},[i]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),onBlur:()=>{if(r)return;let e=a.trim();if(e===``){c(null),n(void 0);return}try{let t=JSON.parse(e);c(null),n(t)}catch{c(`Invalid JSON`)}},disabled:r,spellCheck:!1,rows:Math.min(12,Math.max(2,a.split(`
13
+ `).length)),className:`w-full rounded border border-input bg-background px-2 py-1.5 text-xs font-mono outline-none focus:ring-1 focus:ring-primary resize-y disabled:opacity-60`}),s&&(0,Y.jsx)(`div`,{className:`text-[11px] text-destructive`,children:s})]})}function ld({name:e,value:t,onCommit:n,disabled:r}){return typeof t==`boolean`?(0,Y.jsx)(J,{label:e,value:t,onCommit:n,disabled:r}):typeof t==`number`?(0,Y.jsx)(Ii,{label:e,value:t,onCommit:e=>n(e),disabled:r}):t===null||typeof t==`string`?(0,Y.jsx)(q,{label:e,value:t??``,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(cd,{label:e,value:t,onCommit:n,disabled:r})}var ud=new Set([`children`,`body`]),dd=Symbol(`remove`);function fd(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)(?:\[(\d+)\])?$/.exec(e);if(!t)return null;n.push({key:t[1],index:t[2]==null?-1:Number(t[2])})}return n.length>0?n:null}function pd(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function md(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function hd(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return i.length===0?n===dd?t.splice(r,1):t[r]=n:t[r]=hd(t[r],i,n),t}let a={...e||{}};return i.length===0?n===dd?delete a[r]:a[r]=n:a[r]=hd(a[r],i,n),a}function gd(e,t){return md(e,pd(t))}function _d(e,t,n){let r=pd(t),i=hd(e,r,n===null?dd:n),a=r[0];return{[a]:i[a]}}function vd(e,t){let n=pd(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=md(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function yd(e,t,n){let r=pd(t),i=hd(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function bd({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),c=s?null:fd(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?fd(d):null,p=t.slots&&typeof t.slots==`object`?t.slots:{},m=s?Array.isArray(p[l])?p[l]:p[l]==null?[]:[p[l]]:[],h=s?m[u]??null:null,g=e=>n({slots:{...p,[l]:e}}),_=e=>g(e===null?m.filter((e,t)=>t!==u):m.map((t,n)=>n===u?e:t)),v=s?f?gd(h||{},f):h:c?gd(t,c):null,y=s?f?vd(h||{},f):{siblings:m,index:u}:c?vd(t,c):null;if(!s&&!c||!v)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),children:(0,Y.jsx)(Yi,{message:e.id})});let b=e=>s?_(f?{...h,..._d(h||{},f,{...v,...e})}:{...v,...e}):n(_d(t,c,{...v,...e})),x=v.properties||{},S=typeof t?.object==`string`?t.object:void 0,C=e=>e.objectFrom===`page`?S:e.objectProp!=null&&x[e.objectProp]!=null?String(x[e.objectProp]):void 0,w=e=>x[e]??v[e],T=(e,t)=>b({properties:{...x,[e]:t}}),E=new Set((td(v.type)?ed[v.type]:[]).map(e=>e.name)),D=Object.keys(x).filter(e=>!E.has(e)&&!ud.has(e)),O=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,Y.jsx)(Ii,{label:e.label,value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`boolean`:return(0,Y.jsx)(J,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`color`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(na,{value:t(e.name)==null?void 0:String(t(e.name)),onChange:t=>n(e.name,t),disabled:o,options:e.options})]},i);case`select`:return(0,Y.jsx)(K,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),options:e.options,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{className:`h-8 text-sm`,value:String(t??``),placeholder:e.placeholder,disabled:o,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:o,"aria-label":`Remove`,onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,Y.jsx)(Se,{className:`h-4 w-4`})})]},i)),!o&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]},i)}case`array`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:o,"aria-label":`Remove item`,onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>O(t,e=>s[e],(t,i)=>{let o=[...r];o[a]={...s,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!o&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,Y.jsx)(id,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-picker`:return(0,Y.jsx)(ad,{label:e.label,objectName:C(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-list`:return(0,Y.jsx)(od,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,Y.jsx)(q,{label:e.label,value:t(e.name)==null?``:String(t(e.name)),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i)}},k=()=>{s?_(f?{...h,..._d(h||{},f,null)}:null):n(_d(t,c,null)),r()},A=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:G(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,Y.jsx)(Xi,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=Pi(y.siblings,y.index,e);_({...h,...yd(h||{},f,t)});let n=A([...f.slice(0,-1),{key:f[f.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${l}:${u}.${n}`,label:String(v.id||v.type||e)})}else g(Pi(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}let r=Pi(y.siblings,y.index,e);n(yd(t,c,r));let a=A([...c.slice(0,-1),{key:c[c.length-1].key,index:e}]);i?.({kind:`block`,id:a,label:String(v.id||v.type||a)})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.pageBlock.remove`,a),onClick:k,disabled:o}),children:[(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(oa,{label:G(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e||void 0}),objectName:S,disabled:o}),td(v.type)&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.pageBlock.properties`,a)}),ed[v.type].map(e=>O(e,w,T))]}),D.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.pageBlock.advanced`,a)}),D.map(e=>(0,Y.jsx)(ld,{name:e,value:x[e],onCommit:t=>T(e,t),disabled:o},e))]})]})}var xd=new Set([`simple`,`tabbed`,`wizard`,`split`]),Sd=new Set([`drawer`,`modal`]);function Cd(e){return typeof e==`string`&&Sd.has(e)}function wd(e){return typeof e==`string`&&xd.has(e)?e:`simple`}function Td(e){let t={...e,type:String(e?.type??``)},n=t.properties&&typeof t.properties==`object`?t.properties:void 0;return Cd(n?.formType??t.formType)&&(n&&(t.properties={...n,formType:`simple`}),`formType`in t&&(t.formType=`simple`)),t}function Ed(e=`300px`){let t=X.useRef(null),[n,r]=X.useState(()=>typeof IntersectionObserver>`u`);return X.useEffect(()=>{if(n)return;let i=t.current;if(!i)return;let a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(r(!0),a.disconnect())},{rootMargin:e});return a.observe(i),()=>a.disconnect()},[n,e]),{ref:t,inView:n}}function Dd({block:e,maxHeightClass:t=`max-h-72`}){let n=String(e?.type??``),{ref:r,inView:i}=Ed();return(0,Y.jsx)(`div`,{ref:r,className:I(`pointer-events-none select-none overflow-hidden p-3`,t),children:i?(0,Y.jsx)(Q,{fallbackHint:`"${n}" can't render with its current configuration — check its Properties.`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:Td(e)})})}):(0,Y.jsx)(`div`,{className:`min-h-[64px] animate-pulse rounded bg-muted/40`,"aria-hidden":`true`})})}var Od={1:`grid-cols-1`,2:`grid-cols-2`,3:`grid-cols-3`,4:`grid-cols-4`,5:`grid-cols-5`,6:`grid-cols-6`};function kd(e){let t=e?.properties||{};switch(e?.type){case`page:tabs`:case`page:accordion`:return(Array.isArray(t.items)?t.items:[]).map((e,t)=>({label:e?.label||e?.key||`Item ${t+1}`,pathSuffix:`properties.items[${t}].children`,children:Array.isArray(e?.children)?e.children:[]}));case`page:card`:return Array.isArray(t.body)&&!Array.isArray(t.children)?[{label:`Body`,pathSuffix:`properties.body`,children:t.body}]:[{label:`Body`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];case`page:section`:case`grid`:return[{label:`Content`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];default:return Array.isArray(t.children)?[{label:`Content`,pathSuffix:`properties.children`,children:t.children}]:[]}}var Ad=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function jd(e){let t=e||{};return Ad.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function Md(e){let t={};for(let n of e){let e=Array.isArray(n.components)?n.components:[];e.length===0||!n.name||(t[n.name]=e)}return t}function Nd(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:jd(t),shape:`slots`};let n=e.regions;if(Array.isArray(n))return{regions:n,shape:`regions`};let r=e.children;return Array.isArray(r)?{regions:[{name:`children`,components:r}],shape:`children`}:{regions:[],shape:`regions`}}function Pd(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function Fd(e){return typeof e.label==`string`&&e.label||typeof e.title==`string`&&e.title||typeof e.id==`string`&&e.id||String(e.type??`block`)}var Id=`text/x-objectui-pageblock`;function Ld({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=X.useMemo(()=>Nd(e),[e]),s=n?.kind===`block`?String(n.id):null,c=X.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:Md(e)}):t?.({regions:e})},[t,o]),l=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),s=i[e.region]?.components;if(!s)return;let[l]=s.splice(e.comp,1);if(!l)return;let u=i[n.region]?.components;if(!u)return;let d=u.length;if(`appendEnd`in n)d=u.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,d=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,d=t}u.splice(d,0,l),c(i);let f=Pd(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:Fd(l)})},[t,r,a,c,o]),u=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]}));i[e]||(i[e]={name:`region_${e+1}`,components:[]});let s={type:n};i[e].components.push(s),c(i);let l=i[e].components.length-1;r?.({kind:`block`,id:Pd(o,e,l,i[e]?.name),label:Fd(s)})},[t,r,a,c,o]),d=X.useCallback((e,n,r)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e]?.components?.[n];o&&(i[e].components[n]={...o,label:r||void 0},c(i))},[t,a,c]),f=X.useCallback(()=>{if(!t)return;let e=[...a,{name:`region_${a.length+1}`,components:[]}];c(e)},[t,a,c]),p=X.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=fd(i);if(!s)return;let c=pd(s);if(o){let s=o[1],l=Number(o[2]),u=e.slots||{},d=u[s],f=Array.isArray(d)?[...d]:d==null?[]:[d],p=f[l];if(!p)return;let m=md(p,c)||[];f[l]=hd(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=fd(`${n}.${i}`);if(!o)return;let s=pd(o),c=md(e,s)||[],l=hd(e,s,[...c,{type:a}]);t({[s[0]]:l[s[0]]}),r?.({kind:`block`,id:`${n}.${i}[${c.length}]`,label:a})}},[t,e,r]),m=X.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`A Page is composed of regions (header / main / sidebar / …). Add a region to start dropping blocks into it.`}),!i&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,Y.jsx)(Rd,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:Pd(o,t,n,e.name),label:Fd(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>Pd(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function Rd({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c,onSelectId:l,onAddNested:u}){let d=Array.isArray(e.components)?e.components:[],[f,p]=X.useState(!1);return(0,Y.jsxs)(`section`,{className:I(`rounded-md transition-colors`,f&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(i)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(Id)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(!0))},onDragLeave:e=>{e.currentTarget===e.target&&p(!1)},onDrop:e=>{if(i||(p(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(Id);if(n)try{let e=JSON.parse(n);if(typeof e.region!=`number`||typeof e.comp!=`number`)return;o(e,{region:t,appendEnd:!0})}catch{}},children:[(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,Y.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:n===`slots`?`Inherited from the default page — add a block to override this slot.`:`Empty region — drop a block here or use the add button below.`}):d.map((s,d)=>{let f=Pd(n,t,d,e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsx)(zd,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,Y.jsx)(Bd,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(Vd,{onPick:e=>s(t,e)})})]})]})}function zd({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Ju[c]?.Icon??Zu,u=$u(c),d=Fd(e),f=!i,[p,m]=X.useState(null),h=e=>{e.dataTransfer.setData(Id,JSON.stringify({region:t,comp:n})),e.dataTransfer.effectAllowed=`move`},g=e=>{if(!f)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(Id))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();m(e.clientY-n.top<n.height/2?`before`:`after`)},_=()=>m(null),v=e=>{if(i)return;e.preventDefault(),e.stopPropagation();let r=p??`before`;m(null);let a=e.dataTransfer.getData(Id);if(a)try{let e=JSON.parse(a);if(e.region===t&&e.comp===n)return;o(e,r===`before`?{region:t,before:n}:{region:t,after:n})}catch{}},[y,b]=X.useState(!1),[x,S]=X.useState(d);X.useEffect(()=>{S(d)},[d]);let C=e=>{i||(e.preventDefault(),e.stopPropagation(),S(d),b(!0))},w=()=>{if(i){b(!1);return}let e=x.trim();e&&e!==d&&s(e),b(!1)},T=()=>{S(d),b(!1)},E=kd(e).length>0;return(0,Y.jsxs)(`div`,{className:I(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsx)(`div`,{className:I(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:E?(0,Y.jsxs)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:I(`flex w-full items-center justify-between gap-2 rounded-md px-3.5 py-2.5 text-left`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,Y.jsx)(l,{className:I(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,Y.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),w()):e.key===`Escape`&&(e.preventDefault(),T())},onBlur:w,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:I(`text-sm font-medium truncate`,!i&&`cursor-text`),onDoubleClick:C,title:i?void 0:`Double-click to rename`,children:d}),e.id&&e.id!==d&&(0,Y.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Dd,{block:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,"aria-label":`Select ${d}`,"aria-pressed":r,className:I(`absolute inset-0 z-10 rounded-md`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`)}),(0,Y.jsxs)(`div`,{className:I(`pointer-events-none absolute right-1.5 top-1.5 z-20 flex items-center gap-1 transition-opacity`,r?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:[f&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 text-muted-foreground/60`,"aria-hidden":`true`}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,u.badge),children:c})]})]})}),p===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function Bd({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=kd(e);if(o.length===0)return null;let s=Od[e?.type===`grid`?Math.min(6,Math.max(1,Number(e.properties?.columns)||1)):1]??`grid-cols-1`;return(0,Y.jsx)(`div`,{className:`ml-5 mt-1.5 space-y-2.5 border-l border-dashed border-border pl-3`,children:o.map((e,o)=>(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/40 py-2 px-3 text-[11px] text-muted-foreground`,children:`Empty — add a block.`}):(0,Y.jsx)(`div`,{className:I(`grid gap-2`,s),children:e.children.map((r,a)=>{let o=`${t}.${e.pathSuffix}[${a}]`,s=String(r?.type??``),c=o===n;return(0,Y.jsxs)(`div`,{className:I(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,c?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:[(0,Y.jsx)(Dd,{block:r,maxHeightClass:`max-h-56`}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,Fd(r))},"aria-label":`Select ${Fd(r)}`,"aria-pressed":c,className:`absolute inset-0 z-10 rounded-md cursor-pointer`}),(0,Y.jsx)(`div`,{className:I(`pointer-events-none absolute right-1.5 top-1.5 z-20 transition-opacity`,c?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,$u(s).badge),children:s})})]},a)})}),!r&&(0,Y.jsx)(Vd,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function Vd({onPick:e}){let[t,n]=X.useState(!1),[r,i]=X.useState(``),a=r.trim().toLowerCase(),o=X.useMemo(()=>a?Xu.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Ju[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Xu,[a]);return(0,Y.jsxs)(Cn,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(Mn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search block type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:Yu[t.category]}),t.types.map(t=>{let r=Ju[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent text-left`,children:[(0,Y.jsx)(a,{className:I(`h-3.5 w-3.5 shrink-0`,$u(t).icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function Hd({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=X.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=!!e?.interfaceConfig?.source,d=X.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),f=X.useMemo(()=>{if(d===`regions`){let t=e.regions,n=[];return t.forEach((e,t)=>{(Array.isArray(e.components)?e.components:[]).forEach((r,i)=>{n.push({id:`regions[${t}].components[${i}]`,label:r.id||r.type||`${e.name??`region ${t+1}`} · ${i+1}`})})}),n}return(Array.isArray(e.children)?e.children:[]).map((e,t)=>({id:`children[${t}]`,label:e.id||e.type||`block ${t+1}`}))},[e,d]),p=X.useCallback(()=>{if(!c)return;let t={type:`container`};if(d===`regions`){let n=Array.isArray(e.regions)?[...e.regions]:[],a=n.length-1;a<0&&(n.push({name:`main`,components:[]}),a=0);let o={...n[a]},s=Array.isArray(o.components)?[...o.components]:[];s.push(t),o.components=s,n[a]=o,i({regions:n}),r?.({kind:`block`,id:`regions[${a}].components[${s.length-1}]`,label:t.type});return}let n=[...Array.isArray(e.children)?e.children:[],t];i({children:n}),r?.({kind:`block`,id:`children[${n.length-1}]`,label:t.type})},[c,e,i,r,d]),m=e?.type===`record`||e?.pageType===`record`?e?.object:void 0,[_,y]=X.useState([]),[b,x]=X.useState(null),[S,C]=X.useState(null);X.useEffect(()=>{if(!m){y([]),x(null),C(null);return}let e=!1;return(async()=>{try{let t={headers:{accept:`application/json`},credentials:`include`},n=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(m)}`,t)).json().catch(()=>null),r=n?.item??n?.data??n,i=h(r?.fields),a=i.length>0?`?$top=50&$expand=${encodeURIComponent(i.join(`,`))}`:`?$top=50`,o=await(await fetch(`/api/v1/data/${encodeURIComponent(m)}${a}`,t)).json().catch(()=>null),s=Array.isArray(o?.records)?o.records:Array.isArray(o?.items)?o.items:Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[];if(e)return;y(s),x(r),C(e=>e??s[0]?.id??s[0]?._id??s[0]?.name??null)}catch{e||(y([]),x(null))}})(),()=>{e=!0}},[m]);let w=e=>e?.id??e?._id??e?.name,T=e=>String(e?.name??e?.title??e?.label??e?.subject??w(e)??`(record)`),E=X.useMemo(()=>_.length?_.find(e=>String(w(e))===String(S))??_[0]:null,[_,S]),D=e?.kind===`slotted`,O=X.useMemo(()=>{if(!D)return o;try{let t=e?.slots??{};return Ta(b??void 0,{slots:t})}catch{return o}},[D,o,e,b]),k=e=>!m||!E?e:(0,Y.jsxs)(g,{objectName:m,recordId:w(E),data:E,objectSchema:b??void 0,embedded:!0,children:[_.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b bg-muted/30 text-xs`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Preview record`}),(0,Y.jsx)(`select`,{className:`h-7 rounded-md border bg-background px-2 text-xs max-w-[260px]`,value:String(S??``),onChange:e=>C(e.target.value),children:_.map(e=>{let t=w(e);return(0,Y.jsx)(`option`,{value:String(t),children:T(e)},String(t))})}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground/70 shrink-0`,children:[_.length,` sample`,_.length===1?``:`s`]})]}),e]});if(u)return(0,Y.jsx)(Z,{hint:`page · interface`,children:(0,Y.jsx)(Q,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,Y.jsx)(wa,{page:e,onConfigChange:c?t=>i({interfaceConfig:{...e.interfaceConfig||{},...t}}):void 0})})});let A=e.kind;return A===`react`||A===`html`?(0,Y.jsx)(qu,{draft:e,onPatch:c?i:void 0,readOnly:!c}):!o||Object.keys(o).length<=1?(0,Y.jsxs)(Z,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,Y.jsx)(Ld,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(Wu,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:G(`engine.inspector.add.block`,a)}):null,!s&&(0,Y.jsx)(Hu,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,Y.jsx)(Z,{hint:`page · design`,children:k((0,Y.jsx)(Ld,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}))}):(0,Y.jsx)(Z,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(Q,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(Wu,{title:G(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:G(`engine.inspector.add.block`,a)}),k((0,Y.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Y.jsx)(v,{schema:O})}))]})})}function Ud(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object];for(let e of n)if(typeof e==`string`&&e)return e}function Wd(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.name;return n?{...t,name:n,readOnly:t.readOnly??t.readonly}:t}return String(e)}function Gd(e,t){return{type:`object-form`,objectName:e,mode:`create`,formType:wd(typeof t.type==`string`?t.type:`simple`),sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(Wd):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function Kd({name:e,draft:t,editing:n}){let r=X.useMemo(()=>cs(t)?.schema,[t]),i=X.useMemo(()=>Ud(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=X.useMemo(()=>{if(!r)return{listViews:{},defaultViewId:void 0,defaultViewType:`grid`};let n=String(e)||`default`;return{listViews:{[n]:{...r,label:r.label??t.label??e}},defaultViewId:n,defaultViewType:r.type??`grid`}},[r,t,e]),l=X.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);if(!r&&t.type){let e={...t};return(0,Y.jsx)(Z,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:e})})})})})}if(!i)return(0,Y.jsx)(Z,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(Hu,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,Y.jsx)(`code`,{children:`Object`}),` in the right panel to fetch live data and field options.`]})});if(t.viewKind===`form`&&r){let e=String(r.type??`simple`),t=Gd(i,r);return(0,Y.jsx)(Z,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:t})})})})})}return(0,Y.jsx)(Z,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(p,{children:(0,Y.jsx)(v,{schema:l})})})})})}var qd={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:ti},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:ae},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:yt},line:{id:`line`,label:`Line chart`,category:`chart`,icon:wn},area:{id:`area`,label:`Area chart`,category:`chart`,icon:dr},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:en},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:vr},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Yt},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:ie},table:{id:`table`,label:`Data table`,category:`data`,icon:Sn},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:ir}},Jd={kpi:`Single value`,chart:`Charts`,data:`Tabular`},Yd=[`kpi`,`chart`,`data`].map(e=>({category:e,types:Object.values(qd).filter(t=>t.category===e)})),Xd=Jn;function Zd({onAdd:e,label:t=`Add widget`}){let[n,r]=X.useState(!1),[i,a]=X.useState(``),o=X.useRef(null),s=X.useMemo(()=>{let e=i.trim().toLowerCase();return e?Yd.map(t=>({category:t.category,types:t.types.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))})).filter(e=>e.types.length):Yd},[i]);return(0,Y.jsxs)(Cn,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),t]})}),(0,Y.jsxs)(Mn,{align:`end`,sideOffset:4,className:`w-72 p-0`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,Y.jsx)(Me,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:o,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search widgets…`,className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground`})]}),(0,Y.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:s.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):s.map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:Jd[t.category]}),t.types.map(t=>(0,Y.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{e(t.id),r(!1)},children:[(0,Y.jsx)(qd[t.id]?.icon??Xd,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var Qd=X.lazy(()=>a(()=>import(`./plugin-dashboard-Cr7jkjy7.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function $d({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=S(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=X.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=X.useCallback(e=>{n&&n({widgets:e})},[n]),p=X.useCallback(e=>{if(!l)return;let t=Gi(`widget`,s.map(e=>e?.id).filter(Boolean)),r=qd[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:t,type:e,title:a,...r?.defaults??{}};n({widgets:ua(s,o)}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),m=X.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),h=u?s.find(e=>e?.id===u)??null:null,g=l?(0,Y.jsx)(Zd,{onAdd:p,label:G(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(Z,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,Y.jsx)(Hu,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(Z,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,Y.jsxs)(Q,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,Y.jsx)(ef,{widget:h,onRename:e=>m(h.id,e),onClose:()=>i?.(null)}):null,(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(`div`,{className:`min-w-[768px]`,children:(0,Y.jsx)(Qd,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function ef({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=X.useState(!1),[o,s]=X.useState(r),c=X.useRef(null);X.useEffect(()=>{s(r),a(!1)},[e.id,r]),X.useEffect(()=>{i&&c.current?.select()},[i]);let l=()=>{let e=o.trim();e&&e!==r&&t(e),a(!1)},u=()=>{s(r),a(!1)},d=qd[e.type]?.icon??null;return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-primary/5 px-3 py-1.5 text-xs`,children:[d?(0,Y.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,Y.jsx)(`span`,{className:`rounded bg-primary px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-foreground`,children:`Selected`}),i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`input`,{ref:c,value:o,onChange:e=>s(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),u())},className:`flex-1 min-w-0 rounded border bg-background px-2 py-0.5 text-xs outline-none focus:ring-1 focus:ring-primary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,Y.jsx)(Cr,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`flex-1 min-w-0 truncate text-left font-medium hover:underline`,title:`Click to rename`,children:r||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,Y.jsx)(Rr,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]})}var tf=X.lazy(()=>a(()=>import(`./plugin-report-DwvPiTGE.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function nf({draft:e}){let t=S(),n=e,r=typeof n.dataset==`string`&&!!n.dataset,i=n.type===`joined`&&Array.isArray(n.blocks)&&n.blocks.some(e=>typeof e?.dataset==`string`&&!!e.dataset);if(r||i){let r=Array.isArray(n.rows)?n.rows.filter(Boolean):[];return(0,Y.jsx)(Z,{hint:i?`report · joined · ${n.blocks.length} block${n.blocks.length===1?``:`s`}`:`report · dataset "${n.dataset}"${r.length?` · by `+r.join(`, `):``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(tf,{schema:e,dataSource:t})})})})})}let a=n.type===`joined`;return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(ir,{className:`h-8 w-8`}),title:a?`Add a block to preview this joined report`:`Bind a dataset to preview this report`,description:a?`A joined report stacks dataset-bound blocks. Add a block and bind its dataset + measures in the right panel to start designing.`:`Since the 9.0 single-form cutover a report renders its dataset's measures (values) grouped by dimensions (rows). Choose a Dataset in the right panel to start designing.`})})}var rf=`text/x-objectui-nav`;function af(e){if(e.kind)return String(e.kind);if(e.object||e.objectName)return`object`;if(e.page||e.pageName)return`page`;if(e.dashboard)return`dashboard`;if(e.report)return`report`;if(Array.isArray(e.children)&&e.children.length)return`group`;let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&/^https?:/i.test(t)?`link`:`item`}function of(e){switch(e){case`object`:return ir;case`page`:return Oe;case`dashboard`:return Gn;case`report`:return Nr;case`link`:return Dn;case`group`:return Ze;default:return xr}}var sf={object:{icon:`text-blue-500`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},page:{icon:`text-violet-500`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},dashboard:{icon:`text-teal-500`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},report:{icon:`text-amber-500`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},link:{icon:`text-indigo-500`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},group:{icon:`text-slate-500`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},item:{icon:`text-zinc-500`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function cf(e){return sf[e]??sf.item}function lf(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function uf(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function df({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=Ti(),o=X.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),s=r&&r.kind===`nav`?r.id:null,[c,l]=X.useState(null),u=X.useCallback(e=>{n&&n({[t]:e})},[n,t]),d=X.useCallback(()=>{if(!n)return;let e=G(`engine.appNav.newItem`,a),r=new Set(o.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean)),s=`nav_item_${o.length+1}`;for(let e=o.length+2;r.has(s);e++)s=`nav_item_${e}`;let c=ua(o,{id:s,type:`object`,label:e});u(c),i?.({kind:`nav`,id:`${t}[${c.length-1}]`,label:e})},[n,o,u,t,i,a]),f=X.useCallback(e=>{if(!n)return;let r=la(o,e,null);u(r),s===`${t}[${e}]`&&i?.(null)},[n,o,u,t,s,i]),p=X.useCallback((e,r)=>{if(!n)return;let a={...o[e]??{},label:r},c=la(o,e,a);u(c),s===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r})},[n,o,u,t,s,i]),m=X.useCallback((e,r)=>{if(!n)return;let a=r;if(e<r&&(a=r-1),a===e)return;let s=Pi(o,e,a);u(s),i?.({kind:`nav`,id:`${t}[${a}]`,label:lf(s[a]??{},a)})},[n,o,u,t,i]);return(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-muted-foreground`,children:G(`engine.appNav.heading`,a)}),(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px]`,children:[o.length,` `,o.length===1?G(`engine.appNav.itemOne`,a):G(`engine.appNav.itemOther`,a)]})]}),n&&(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:d,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,G(`engine.appNav.addItem`,a)]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),c!=null&&(m(c,o.length),l(null)))},children:o.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:G(n?`engine.appNav.empty`:`engine.appNav.emptyReadonly`,a)}):o.map((e,r)=>(0,Y.jsx)(ff,{item:e,index:r,depth:0,path:`${t}[${r}]`,selectedId:s,canEdit:!!n,onClick:(e,t)=>i?.({kind:`nav`,id:e,label:t}),onRename:e=>p(r,e),onRemove:()=>f(r),onDragStart:()=>l(r),onDragEnd:()=>l(null),onDropBefore:()=>{c!=null&&(m(c,r),l(null))}},r))})]})}function ff({item:e,index:t,depth:n,path:r,selectedId:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(pf,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,lf(e,t)),onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}),Array.isArray(e.children)&&e.children.map((e,t)=>{let s=`${r}.children[${t}]`;return(0,Y.jsx)(ff,{item:e,index:t,depth:n+1,path:s,selectedId:i,canEdit:a,onClick:o,onRename:()=>void 0,onRemove:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onDropBefore:()=>void 0},t)})]})}function pf({item:e,index:t,depth:n,path:r,isSelected:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){let f=Ti(),p=af(e),m=of(p),h=cf(p),g=uf(e),[_,v]=X.useState(!1),[y,b]=X.useState(lf(e,t)),[x,S]=X.useState(!1),[C,w]=X.useState(null);return X.useEffect(()=>{_||b(lf(e,t))},[e,t,_]),(0,Y.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[C===`before`&&(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`button`,{type:`button`,draggable:a&&!_,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(rf,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(rf)&&(e.preventDefault(),e.stopPropagation(),w(null),d())},onClick:o,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),"aria-pressed":i,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${i?`border-primary ring-1 ring-primary`:`border-border`} ${a&&!_?`cursor-grab active:cursor-grabbing`:``}`,children:[a?(0,Y.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,Y.jsx)(`span`,{className:`w-3.5`}),(0,Y.jsx)(m,{className:I(`h-3.5 w-3.5 shrink-0`,h.icon)}),_?(0,Y.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{v(!1);let n=y.trim();n&&n!==lf(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),b(lf(e,t)),v(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),v(!0))},children:lf(e,t)}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-medium`,h.badge),children:p}),g&&(0,Y.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:g}),a&&x&&!_&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":G(`engine.appNav.removeItem`,f),children:(0,Y.jsx)(Tn,{className:`h-3 w-3`})})]})]})}function mf(e){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let t=String(e.label??e.title??e.name??e.path??``).trim();if(!t&&!e.children)return null;let n=e.path??e.href??e.route??e.url??void 0,r;e.object||e.objectName?r=`object`:e.page||e.pageName?r=`page`:e.dashboard?r=`dashboard`:e.report?r=`report`:typeof n==`string`&&/^https?:/i.test(n)?r=`link`:Array.isArray(e.children)&&e.children.length&&(r=`group`);let i=Array.isArray(e.children)?mf(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function hf(e){switch(e){case`object`:return ir;case`page`:return Oe;case`dashboard`:return Gn;case`report`:return Nr;default:return xr}}function gf({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,c=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:l,navItems:u}=X.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:mf(n)};return{rootKey:null,navItems:[]}},[t]),d=l??`navigation`,f=!!(n&&i),p=f&&!!a,m=r&&r.kind===`nav`?r.id:null,h=f?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,g=o?`/apps/${encodeURIComponent(o)}/`:null;return(0,Y.jsx)(Z,{hint:`app`,toolbar:g&&(0,Y.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,Y.jsx)(df,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(Hu,{children:[`No top-level nav items. Add `,(0,Y.jsx)(`code`,{children:`nav`}),` / `,(0,Y.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,Y.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,Y.jsx)(_f,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function _f({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=hf(e.kind),s=vf(t,e.path);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40 ${i?`cursor-pointer`:``} ${a===r?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+n*16}px`},onClick:i?t=>{t.stopPropagation(),i(r,e)}:void 0,children:[(0,Y.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,Y.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(_f,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function vf(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function yf(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(bf,{...e,icon:t===`password`?(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(ei,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(ti,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.pickDate`,n)});case`time`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(gn,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,Y.jsx)(xf,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(Mt,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??G(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Y.jsx)(Sf,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(Sf,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(Cf,{...e});case`image`:case`avatar`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(Bn,{className:`h-4 w-4`}),label:G(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(An,{className:`h-4 w-4`}),label:W(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Y.jsx)(wf,{icon:(0,Y.jsx)(An,{className:`h-4 w-4`}),label:G(`designer.stub.qrcode`,n)});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(Tt,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,Y.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,Y.jsx)(zn,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,Y.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,Y.jsx)(bf,{...e,icon:(0,Y.jsx)(Ee,{className:`h-3.5 w-3.5`}),placeholder:G(`designer.stub.latLng`,n)});case`address`:return(0,Y.jsx)(xf,{...e,placeholder:e.placeholder??`Street
14
14
  City, State ZIP
15
15
  Country`});case`formula`:case`summary`:return(0,Y.jsx)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:e.formula?`ƒ ${e.formula}`:`ƒ ${G(`designer.stub.computed`,n)}`});case`composite`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:G(`designer.stub.composite`,n)});case`repeater`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:G(`designer.stub.repeater`,n)});case`vector`:return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:[`[0.124, 0.337, …] `,e.placeholder?`(${e.placeholder})`:``]});default:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(B,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function bf({placeholder:e,icon:t}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(B,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,Y.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function xf({placeholder:e,mono:t}){return(0,Y.jsx)(`textarea`,{disabled:!0,placeholder:e??``,className:`w-full min-h-[60px] text-sm rounded-md border bg-background px-2 py-1.5 disabled:opacity-100 `+(t?`font-mono text-xs`:``)})}function Sf({options:e,placeholder:t,single:n,locale:r}){let i=e??[],a=i.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:a[0]?.label||a[0]?.value||t||G(`designer.stub.select`,r)}),(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,Y.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[a.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||G(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,Y.jsx)(z,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function Cf({referenceTo:e,placeholder:t,locale:n}){let r=e?ia.lookup:null;return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,Y.jsx)(M,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?W(`designer.stub.searchRef`,n,{ref:e}):G(`designer.stub.chooseRelated`,n))}),e&&(0,Y.jsxs)(z,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Y.jsx)(Me,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function wf({icon:e,label:t}){return(0,Y.jsxs)(`div`,{className:`h-16 w-full border-2 border-dashed rounded flex flex-col items-center justify-center gap-1 text-muted-foreground bg-muted/20`,children:[e,(0,Y.jsx)(`span`,{className:`text-[11px]`,children:t})]})}var Tf=e=>(e??``).toLowerCase().startsWith(`zh`),Ef=(e,t)=>e?Tf(t)?e.labelZh:e.label:void 0,Df=(e,t)=>(Tf(t)?da:ra)[e];function Of({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,{enabled:c}=Oa(),l=X.useMemo(()=>Qi(t.fields),[t]),u=X.useMemo(()=>n?Vi(n.fields,t.fields):null,[n,t]),d=u?u.counts.added+u.counts.changed+u.counts.removed:0,[f,p]=X.useState(!1);X.useEffect(()=>{f&&d===0&&p(!1)},[f,d]);let m=f&&d>0,h=e=>m?u?.byName[e]?.status:void 0,g=e=>m?u?.byName[e]?.changedKeys??[]:[],_=X.useMemo(()=>Bi(t.fieldGroups),[t]),v=_.length>0,y=X.useMemo(()=>Wi(l,_,{includeEmptyDeclared:!s}),[l,_,s]),[b,x]=X.useState({}),S=e=>e??`__ungrouped__`,C=X.useCallback(e=>{let t=e??`__ungrouped__`;x(e=>({...e,[t]:!e[t]}))},[]),w=y.length>0&&y.every(e=>b[S(e.key)]),T=X.useCallback(e=>{x(()=>{let t={};for(let n of y)t[S(n.key)]=e;return t})},[y]),E=i?.kind===`field`?String(i.id):null,D=l.entries.filter(e=>!!e.def.required).length,O=X.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[k,A]=X.useState(()=>new Set),ee=X.useRef(null),j=X.useMemo(()=>y.flatMap(e=>e.entries.map(e=>e.name)),[y]);X.useEffect(()=>{A(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>l.entries.some(t=>t.name===e)));return t.size===e.size?e:t})},[l]);let te=X.useCallback((e,t)=>{let n=e.name;if(!s&&t&&(t.metaKey||t.ctrlKey)){A(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),ee.current=n;return}if(!s&&t&&t.shiftKey&&ee.current&&ee.current!==n){let e=j.indexOf(ee.current),t=j.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];A(new Set(j.slice(n,r+1)));return}}k.size&&A(new Set),ee.current=n,O(e)},[s,j,k,O]),ne=X.useCallback(()=>A(new Set),[]),M=X.useCallback(()=>{if(!r||k.size===0)return;let e=l.entries.filter(e=>!k.has(e.name));r({fields:Hi({shape:l.shape,entries:e})}),E&&k.has(E)&&a?.(null),A(new Set)},[r,k,l,E,a]),re=X.useCallback(e=>{if(!r||k.size===0)return;let t=l.entries.map(t=>k.has(t.name)?{name:t.name,def:{...t.def,group:e??void 0}}:t);r({fields:Hi({shape:l.shape,entries:t})})},[r,k,l]),N=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.map(e=>e.name),i=e===`select`?`status`:e,o=1,s=i;for(;n.includes(s);)o+=1,s=`${i}_${o}`;let c=Fi(s,e);t&&(c.def={...c.def,group:t});let u=l.entries.length;if(t){for(let e=l.entries.length-1;e>=0;--e)if(l.entries[e].def.group===t){u=e+1;break}}let d=l.entries.slice();d.splice(u,0,c),r({fields:Hi({shape:l.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(c.def.label??s)})},[r,a,l]),ie=X.useCallback(()=>{if(!r)return;let e=W(`designer.canvas.sectionN`,o,{n:_.length+1}),t=qi(_,e),n=t[t.length-1];r({fieldGroups:t}),x(e=>({...e,[n.key]:!1}))},[r,_,o]),ae=X.useCallback((e,t)=>{r&&r({fieldGroups:$i(_,e,t)})},[r,_]),oe=X.useCallback(e=>{if(!r)return;let t=Ri(l,e);r({fieldGroups:Zi(_,e),fields:Hi(t)})},[r,_,l]),se=X.useCallback((e,t)=>{r&&r({fieldGroups:Ca(_,e,t)})},[r,_]),P=X.useCallback((e,t,n)=>{if(!r||e===t)return;let i=l.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[o]=i.splice(a,1),s=i.findIndex(e=>e.name===t),c=s>=0?i[s]:void 0;if(c){let e=typeof c.def.group==`string`?c.def.group:void 0;e!==(typeof o.def.group==`string`?o.def.group:void 0)&&(o.def={...o.def,group:e})}s<0?i.push(o):i.splice(n===`before`?s:s+1,0,o),r({fields:Hi({shape:l.shape,entries:i})})},[r,l]),ce=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let a=typeof n[i].def.group==`string`?n[i].def.group:null,o=i+t;for(;o>=0&&o<n.length&&(typeof n[o].def.group==`string`?n[o].def.group:null)!==a;)o+=t;if(o<0||o>=n.length)return;let s=n[i];n[i]=n[o],n[o]=s,r({fields:Hi({shape:l.shape,entries:n})})},[r,l]),le=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let[a]=n.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){n.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let o=n.length;for(let e=n.length-1;e>=0;--e)if((typeof n[e].def.group==`string`?n[e].def.group:null)===t){o=e+1;break}n.splice(o,0,a),r({fields:Hi({shape:l.shape,entries:n})})},[r,l]),ue=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);r({fields:Hi({shape:l.shape,entries:n})})},[r,l]),de=X.useCallback(e=>{e.target===e.currentTarget&&E&&a?.(null)},[a,E]),F=l.entries.length===0,fe=v||y.length>1;return(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:de,"data-object-name":e,children:[!s&&k.size>0&&(0,Y.jsx)(Af,{count:k.size,groups:_,onMoveToGroup:re,onDelete:M,onClear:ne,locale:o}),(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:de,children:[!F&&(0,Y.jsx)(kf,{fieldCount:l.entries.length,requiredCount:D,sectionCount:_.length,allCollapsed:w,onToggleAll:fe?()=>T(!w):void 0,reviewAvailable:d>0,reviewing:m,diffCounts:u?.counts,onToggleReview:()=>p(e=>!e),locale:o}),F?(0,Y.jsx)(Ff,{onAdd:s?void 0:N,locale:o,aiEnabled:c}):(0,Y.jsx)(`div`,{className:`space-y-5`,children:y.map(e=>{let t=e.key?_.findIndex(t=>t.key===e.key):-1;return(0,Y.jsxs)(jf,{groupKey:e.key,label:e.key===null?G(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:fe,collapsed:!!b[S(e.key)],onToggleCollapse:()=>C(e.key),readOnly:s,locale:o,canMoveUp:t>0,canMoveDown:t>=0&&t<_.length-1,onRename:e.key?t=>ae(e.key,t):void 0,onRemove:e.key?()=>oe(e.key):void 0,onMove:e.key?t=>se(e.key,t):void 0,onAddField:s?void 0:t=>N(t,e.key),onDropField:s?void 0:le,children:[e.entries.map(e=>(0,Y.jsx)(Pf,{entry:e,selected:e.name===E,multiSelected:k.has(e.name),diffStatus:h(e.name),changedKeys:g(e.name),readOnly:s,locale:o,onClick:t=>te(e,t),onReorder:s?void 0:P,onRenameLabel:s?void 0:ue,onMoveOffset:s?void 0:t=>ce(e.name,t)},e.name)),e.entries.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:G(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),m&&u&&u.removed.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:G(`designer.canvas.diffRemoved`,o)}),u.removed.map(e=>(0,Y.jsx)(Nf,{entry:e,locale:o},e.name))]}),!F&&!s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(If,{onPick:e=>N(e),locale:o}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:ie,children:[(0,Y.jsx)(ft,{className:`h-3.5 w-3.5`}),G(`designer.canvas.addSection`,o)]}),c&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>ci(),children:[(0,Y.jsx)(Et,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAi`,o)]})]})]})]})}function kf({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,G(`designer.canvas.diffAdded`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,G(`designer.canvas.diffChanged`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,G(`designer.canvas.diffRemoved`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:G(`designer.canvas.reviewVsPublished`,l)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,G(`designer.canvas.fields`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,G(`designer.canvas.required`,l),n>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,G(`designer.canvas.sections`,l)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,Y.jsxs)(`button`,{type:`button`,onClick:c,className:I(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 transition-colors`,o?`bg-primary/10 text-primary hover:bg-primary/15`:`hover:bg-accent hover:text-foreground`),children:[(0,Y.jsx)(he,{className:`h-3 w-3`}),G(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:[r?(0,Y.jsx)(oi,{className:`h-3 w-3`}):(0,Y.jsx)(Ae,{className:`h-3 w-3`}),G(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function Af({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=X.useState(!1);return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-20 flex items-center gap-2 border-b border-primary/20 bg-primary/10 backdrop-blur px-6 py-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:W(`designer.canvas.bulkSelected`,a,{n:e})}),(0,Y.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:G(`designer.canvas.bulkHint`,a)}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,Y.jsxs)(Cn,{open:o,onOpenChange:s,children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,Y.jsx)(Ne,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkMoveTo`,a),(0,Y.jsx)(Ke,{className:`h-3 w-3`})]})}),(0,Y.jsxs)(Mn,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(null),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent`,children:G(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(e.key),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent truncate`,children:e.label||e.key},e.key))]})]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkDelete`,a)]}),(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`}),G(`designer.canvas.bulkClear`,a)]})]})]})}function jf({groupKey:e,label:t,count:n,showHeader:r,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,onRename:u,onRemove:d,onMove:f,onAddField:p,onDropField:m,children:h}){let[g,_]=X.useState(!1);return(0,Y.jsxs)(`section`,{className:I(`space-y-2.5 rounded-md transition-colors`,g&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!m)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(!0))},onDragLeave:e=>{e.currentTarget===e.target&&_(!1)},onDrop:t=>{if(!m)return;if(t.defaultPrevented){_(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);_(!1),n&&m(n,e)},children:[r&&(0,Y.jsx)(Mf,{label:t,count:n,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,dropActive:g,onRename:u,onRemove:d,onMove:f,onAddField:p}),!i&&(0,Y.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function Mf({label:e,count:t,collapsed:n,onToggleCollapse:r,readOnly:i,locale:a,canMoveUp:o,canMoveDown:s,dropActive:c,onRename:l,onRemove:u,onMove:d,onAddField:f}){let[p,m]=X.useState(!1),[h,g]=X.useState(e);X.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?Vt:Ke;return(0,Y.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-accent hover:text-foreground transition-colors shrink-0`,"aria-label":G(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,Y.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,Y.jsx)(`input`,{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`?(t.preventDefault(),_()):t.key===`Escape`&&(t.preventDefault(),g(e),m(!1))},onBlur:_,className:`text-[11px] font-medium uppercase tracking-wider px-1 py-0.5 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1 max-w-[220px]`}):(0,Y.jsx)(`span`,{className:I(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?G(`designer.canvas.renameHint`,a):void 0,children:e}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:G(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 opacity-0 group-hover/sec:opacity-100 focus-within:opacity-100 transition-opacity`,children:[f&&(0,Y.jsx)(If,{onPick:f,compact:!0,locale:a}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(-1),disabled:!o,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":G(`designer.canvas.moveSectionUp`,a),children:(0,Y.jsx)(Qr,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(1),disabled:!s,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":G(`designer.canvas.moveSectionDown`,a),children:(0,Y.jsx)(pe,{className:`h-3 w-3`})})]}),u&&(0,Y.jsx)(`button`,{type:`button`,onClick:u,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":G(`designer.canvas.removeSection`,a),title:G(`designer.canvas.removeSectionHint`,a),children:(0,Y.jsx)(Tn,{className:`h-3 w-3`})})]})]})}function Nf({entry:e,locale:t}){let n=e.def,r=ia[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-destructive/30 bg-destructive/[0.03] px-3.5 py-2.5 opacity-80`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[r&&(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,Y.jsx)(z,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:G(`designer.canvas.diffRemoved`,t)})]})})}function Pf({entry:e,selected:t,multiSelected:n,diffStatus:r,changedKeys:i,readOnly:a,locale:o,onClick:s,onReorder:c,onRenameLabel:l,onMoveOffset:u}){let d=e.def,f=typeof d.type==`string`?d.type:`text`,p=ia[f],m=p?.Icon,h=ya[p?.category??`advanced`],g=typeof d.label==`string`?d.label:e.name,_=!!d.required,v=typeof d.description==`string`?d.description:null,y=Array.isArray(d.options)?d.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,b=typeof d.reference==`string`?d.reference:void 0,x=d.expression,S=typeof x==`string`?x:x&&typeof x==`object`&&typeof x.source==`string`?x.source:typeof d.formula==`string`?d.formula:void 0,C=typeof d.placeholder==`string`?d.placeholder:void 0,[w,T]=X.useState(null),E=!!c,[D,O]=X.useState(!1),[k,A]=X.useState(g);X.useEffect(()=>{A(g)},[g]);let ee=e=>{l&&(e.preventDefault(),e.stopPropagation(),A(g),O(!0))},j=()=>{if(!l){O(!1);return}let t=k.trim();t&&t!==g&&l(e.name,t),O(!1)},te=()=>{A(g),O(!1)};return(0,Y.jsxs)(`div`,{className:I(`relative`,w===`before`&&`pt-1.5`),onDragOver:e=>{if(!E)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY-n.top<n.height/2?`before`:`after`;T(r)},onDragLeave:()=>T(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);T(null),n&&n!==e.name&&c(n,e.name,w??`before`)},children:[w===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:a?-1:0,onClick:s,onKeyDown:e=>{if(e.target===e.currentTarget){if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u&&(e.preventDefault(),u(e.key===`ArrowUp`?-1:1));return}(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s?.())}},draggable:E,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:I(`group block w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,t?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,n&&`border-primary/60 ring-2 ring-primary/40 bg-primary/[0.04]`,r===`added`&&`border-l-[3px] border-l-emerald-500`,r===`changed`&&`border-l-[3px] border-l-amber-500`,a&&`cursor-default`,E&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[n&&(0,Y.jsx)(mn,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),E&&!n&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,Y.jsx)(m,{className:I(`h-3.5 w-3.5 shrink-0`,h.icon)}),D?(0,Y.jsx)(`input`,{autoFocus:!0,value:k,onChange:e=>A(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),j()):e.key===`Escape`&&(e.preventDefault(),te())},onBlur:j,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:I(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:ee,title:l?G(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(0,Y.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,Y.jsx)(z,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:G(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,Y.jsx)(z,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?W(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:G(`designer.canvas.diffChanged`,o)}),(0,Y.jsx)(z,{variant:`outline`,className:I(`text-[10px] font-medium`,h.badge),children:Ef(p,o)??f})]})]}),v&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,Y.jsx)(yf,{type:f,label:g,placeholder:C,options:y,referenceTo:b,formula:S,locale:o})]}),w===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function Ff({onAdd:e,locale:t,aiEnabled:n}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:G(`designer.canvas.noFields`,t)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(`designer.canvas.noFieldsHint`,t)}),e&&(0,Y.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,Y.jsx)(If,{onPick:e,locale:t}),n&&(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>ci(),children:[(0,Y.jsx)(Et,{className:`h-3.5 w-3.5`}),G(`designer.canvas.askAiGenerate`,t)]})]})]})}function If({onPick:e,compact:t,locale:n}){let[r,i]=X.useState(!1),[a,o]=X.useState(``),s=a.trim().toLowerCase(),c=X.useMemo(()=>s?aa.map(e=>({category:e.category,types:e.types.filter(e=>{let t=ia[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):aa,[s,a]);return(0,Y.jsxs)(Cn,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,Y.jsx)(yr,{asChild:!0,children:t?(0,Y.jsx)(`button`,{type:`button`,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":G(`designer.canvas.addFieldToSection`,n),title:G(`designer.canvas.addFieldToSection`,n),children:(0,Y.jsx)(H,{className:`h-3 w-3`})}):(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(H,{className:`h-3.5 w-3.5`}),G(`designer.canvas.addField`,n)]})}),(0,Y.jsxs)(Mn,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:G(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:G(`designer.canvas.noMatchingTypes`,n)}):c.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:Df(t.category,n)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=ia[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),i(!1),o(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(a,{className:I(`h-3.5 w-3.5 shrink-0`,ya[r.category].icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:Ef(r,n)})]},t)})})]},t.category))})]})]})}function Lf({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,Y.jsx)(Z,{hint:`object · designer`,children:(0,Y.jsx)(Q,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Y.jsx)(Of,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,Y.jsx)(Z,{hint:`object`,children:(0,Y.jsx)(Hu,{children:G(`designer.canvas.nameToStart`,o)})})}function Rf(e){let t=new Set;for(let n of e.matchAll(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g))t.add(n[1]);for(let n of e.matchAll(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g))t.add(n[1]);return Array.from(t).sort()}function zf(e,t){return t[e]??``}function Bf(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>zf(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>zf(n,t))}function Vf({draft:e}){let t=String(e.subject??``),n=String(e.from??e.fromAddress??``),r=String(e.to??``),i=String(e.bodyHtml??e.html??e.body??``),a=String(e.bodyText??e.text??``),o=X.useMemo(()=>{let e=new Set;for(let n of Rf(t))e.add(n);for(let t of Rf(i))e.add(t);for(let t of Rf(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=X.useState({}),l=Bf(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
16
16
  html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
@@ -20,6 +20,6 @@ Country`});case`formula`:case`summary`:return(0,Y.jsx)(`div`,{className:`h-8 px-
20
20
  "tool": "${r}",
21
21
  "arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
22
22
  `)}
23
- }`})}),Ih(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Vh,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:xn,children:(0,Y.jsx)(Bh,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Bh({props:e,required:t}){let n=Object.keys(e);return(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:n.map(n=>{let r=e[n],i=t.has(n);return(0,Y.jsxs)(`tr`,{className:`align-top`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,Y.jsx)(Ce,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(Vt,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:Lh(r)}),(0,Y.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,Y.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function Vh({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Hh({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Uh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Wh=[{key:`allowCreate`,short:`C`,long:`Create`},{key:`allowRead`,short:`R`,long:`Read`},{key:`allowEdit`,short:`U`,long:`Edit`},{key:`allowDelete`,short:`D`,long:`Delete`},{key:`allowTransfer`,short:`T`,long:`Transfer`},{key:`allowRestore`,short:`Re`,long:`Restore`},{key:`allowPurge`,short:`P`,long:`Purge`,danger:!0},{key:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}];function Gh(e){let t=[];for(let[n,r]of Object.entries(e))r.allowEdit&&!r.allowRead&&t.push({object:n,message:`Edit granted without Read (record updates will fail).`}),r.allowDelete&&!r.allowRead&&t.push({object:n,message:`Delete granted without Read.`}),r.modifyAllRecords&&!r.viewAllRecords&&t.push({object:n,message:`Modify All without View All — modifications may target invisible records.`}),r.allowPurge&&!r.allowDelete&&t.push({object:n,message:`Purge (hard delete) granted without Delete.`});return t}function Kh({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isDefault,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=X.useMemo(()=>Object.keys(o).sort(),[o]),f=X.useMemo(()=>Gh(o),[o]),p=X.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,Y.jsx)(Z,{hint:`permission`,children:(0,Y.jsx)(Hu,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(Z,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,Y.jsx)(zn,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(P,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Default Permission Set`:`Permission Set`})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Xh,{icon:ln,label:`${d.length} objects`}),(0,Y.jsx)(Xh,{icon:rr,label:`${c.length} system perms`}),(0,Y.jsx)(Xh,{icon:N,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(Xh,{icon:Ve,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Yh,{title:`Object Permissions`,count:d.length,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),Wh.map(e=>(0,Y.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),Wh.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(qh,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Jh,{})]}),p.size>0&&(0,Y.jsx)(Yh,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,Y.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,Y.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded border bg-muted/30 px-1.5 py-0.5`,title:`readable=${t.readable!==!1}, editable=${!!t.editable}`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,Y.jsx)(Yh,{title:`System Permissions`,count:c.length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),Object.keys(l).length>0&&(0,Y.jsx)(Yh,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(`span`,{className:t===`hidden`?`text-[9px] uppercase text-red-700`:t===`visible`||t===`default_on`?`text-[9px] uppercase text-emerald-700`:`text-[9px] uppercase text-muted-foreground`,children:t})]},e))})}),f.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,Y.jsxs)(`li`,{className:`text-amber-900`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function qh({granted:e,danger:t}){return e?(0,Y.jsx)(Ce,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(jt,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Jh(){return(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ce,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ce,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(jt,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono`,children:`C R U D = CRUD · T Re P = Transfer/Restore/Purge · V* M* = View/Modify All`})]})}function Yh({title:e,count:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Xh({icon:e,label:t}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:t})]})}function Zh(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function Qh(e){switch(e){case`url`:return M;case`modal`:return Or;case`flow`:return Ye;case`api`:return At;case`form`:return Rr;default:return In}}function $h(e){switch(e){case`primary`:case`default`:case void 0:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:case`destructive`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function eg(e,t,n){if(!t&&!n)return`No handler bound yet.`;switch(e){case`url`:return`Navigate to ${t}`;case`flow`:return`Run flow ${t}`;case`modal`:return`Open modal ${t}`;case`api`:return`Call API endpoint ${t}`;case`form`:return`Open form view ${t} (/console/forms/${t??`?`})`;case`script`:return n?`Run inline script body (L1 expression or L2 sandboxed JS).`:`Run named script ${t}`;default:return`Invoke ${t}`}}function tg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Zh(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target??n.execute,c=n.variant||void 0,l=String(n.component??``),u=Array.isArray(n.locations)?n.locations:[],d=n.shortcut||void 0,f=!!n.bulkEnabled,p=!!n.refreshAfter,m=n.aiExposed,h=Zh(n.confirmText),g=Zh(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,x=n.visible,S=n.disabled,C=n.method||`POST`,w=n.bodyExtra,T=Qh(o),E=l===`action:icon`;return!r&&!i?(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Hu,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,Y.jsx)(ng,{label:i,icon:a,variant:c,iconOnly:E,disabled:!!S&&typeof S==`boolean`})}),(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(lg,{icon:T,label:`type: ${o}`}),b&&(0,Y.jsx)(lg,{icon:rn,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(lg,{label:`variant: ${c}`}),l&&(0,Y.jsx)(lg,{icon:mr,label:l}),d&&(0,Y.jsx)(lg,{icon:jr,label:d,mono:!0}),f&&(0,Y.jsx)(lg,{icon:St,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(lg,{icon:qt,label:`refresh after`}),m===!1&&(0,Y.jsx)(lg,{icon:jn,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(lg,{icon:Et,label:`AI: exposed`})]}),u.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e},e))]}),!!(typeof x==`string`||x&&typeof x==`object`)&&(0,Y.jsx)(sg,{label:`Visible when`,value:x,icon:N}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(sg,{label:`Disabled when`,value:S,icon:Ve})]}),(0,Y.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,Y.jsx)(T,{className:`h-3.5 w-3.5`}),` On click`]}),(0,Y.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:eg(o,s,!!y?.source)}),h&&(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[`First asks: `,(0,Y.jsx)(`em`,{children:h})]})]}),g&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,Y.jsx)(`em`,{children:g})]})]}),u.length>0&&(0,Y.jsx)(cg,{title:`Where it appears`,children:(0,Y.jsx)(dg,{locations:u,label:i,icon:a,variant:c,iconOnly:E})}),o===`api`&&!!s&&(0,Y.jsx)(cg,{title:`Test request`,icon:At,children:(0,Y.jsx)(fg,{target:s,method:C,bodyExtra:w,params:_})}),_.length>0&&(0,Y.jsx)(cg,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(ig,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(cg,{title:`Result Dialog`,icon:N,children:(0,Y.jsx)(og,{dialog:v})}),y?.source&&(0,Y.jsx)(cg,{title:`Script Body (${y.language??`expression`})`,icon:In,children:(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap max-h-[200px] overflow-auto`,children:y.source})})]})})})}function ng({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${$h(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(rg,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function rg({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=le[t===`Home`?`House`:t];return n?(0,Y.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,Y.jsx)(`span`,{className:`inline-flex h-4 min-w-4 items-center justify-center rounded bg-white/30 px-1 text-[9px] uppercase font-mono`,children:e.slice(0,3)})}function ig({title:e,params:t,variant:n}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,Y.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[Zh(e.label)||n,e.required&&(0,Y.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,Y.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),ag(e),e.helpText&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${$h(n||`primary`)}`,children:`OK`})]})]})}function ag(e){let t=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,n=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),r=e.defaultValue;return Array.isArray(e.options)&&e.options.length>0?(0,Y.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,Y.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,Y.jsx)(`option`,{value:e.value,children:Zh(e.label)},t))]}):e.type===`boolean`?(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,Y.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,Y.jsx)(`input`,{type:e.type===`number`||e.type===`integer`?`number`:e.type===`date`?`date`:`text`,className:t,placeholder:n,value:r==null?``:String(r),readOnly:!0})}function og({dialog:e}){let t=Zh(e.title)||`Result`,n=Zh(e.description),r=Zh(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,Y.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:Zh(t.label)||t.path}),(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded bg-primary text-primary-foreground pointer-events-none`,children:r})})]})}function sg({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,Y.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function cg({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function lg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function ug({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-muted-foreground/70`,children:e}),t]})}function dg({locations:e,label:t,icon:n,variant:r,iconOnly:i}){let a=(0,Y.jsx)(ng,{label:t,icon:n,variant:r,iconOnly:i});return(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[e.includes(`record_header`)&&(0,Y.jsx)(ug,{label:`record_header`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-6 w-6 rounded bg-muted`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Sample record`}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Record detail`})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…record body…`})]})}),e.includes(`list_toolbar`)&&(0,Y.jsx)(ug,{label:`list_toolbar`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Records`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[10px] text-muted-foreground`,children:`row 1 · row 2 · row 3`})]})}),e.includes(`list_item`)&&(0,Y.jsx)(ug,{label:`list_item`,children:(0,Y.jsx)(`div`,{className:`divide-y rounded border bg-background`,children:[0,1].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px]`,children:[`Row `,e+1]}),(0,Y.jsx)(`div`,{className:`origin-right scale-90`,children:a})]},e))})}),(e.includes(`record_section`)||e.includes(`record_related`))&&(0,Y.jsx)(ug,{label:e.includes(`record_related`)?`record_related`:`record_section`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:`Section`}),a]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…section content…`})]})}),e.includes(`record_more`)&&(0,Y.jsx)(ug,{label:`record_more`,children:(0,Y.jsxs)(`div`,{className:`w-52 rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-3 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(mr,{className:`h-3.5 w-3.5`}),` More`]}),(0,Y.jsx)(`div`,{className:`px-2 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})}),e.includes(`global_nav`)&&(0,Y.jsx)(ug,{label:`global_nav`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-muted-foreground`,children:`⌘K · Command palette`}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})})]})}function fg({target:e,method:t,bodyExtra:n,params:r}){let i=(t||`POST`).toUpperCase(),[a,o]=X.useState(null),[s,c]=X.useState(!1),l=n&&typeof n==`object`?n:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2 font-mono text-[11px] break-all`,children:[(0,Y.jsx)(`span`,{className:`font-semibold`,children:i}),` `,e]}),Object.keys(l).length>0&&(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-muted/30 p-2 text-[10px] font-mono whitespace-pre-wrap`,children:JSON.stringify(l,null,2)}),r.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`+ `,r.length,` user-supplied param`,r.length>1?`s`:``,` collected at runtime`]}),i!==`GET`&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-amber-700`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Sends a real `,i,` request to the live backend — may modify data.`]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:async()=>{c(!0),o(null);try{let t=typeof localStorage<`u`?localStorage.getItem(`auth-session-token`):null,n={"Content-Type":`application/json`};t&&(n.Authorization=`Bearer ${t}`);let r={method:i,headers:n,credentials:`include`};i!==`GET`&&i!==`HEAD`&&(r.body=JSON.stringify(l));let a=await fetch(e,r),s=await a.text(),c=s;try{c=JSON.parse(s)}catch{}o({status:a.status,ok:a.ok,body:c})}catch(e){o({status:0,ok:!1,error:e instanceof Error?e.message:String(e)})}finally{c(!1)}},disabled:s,className:`inline-flex items-center gap-1.5 rounded border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),` `,s?`Sending…`:`Send test request`]}),a&&(0,Y.jsxs)(`div`,{className:`rounded border p-2 `+(a.ok?`border-green-300 bg-green-50`:`border-red-300 bg-red-50`),children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[11px] font-medium`,children:a.error?`Network error`:`HTTP `+a.status+(a.ok?` OK`:``)}),(0,Y.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto text-[10px] font-mono whitespace-pre-wrap`,children:a.error??(typeof a.body==`string`?a.body:JSON.stringify(a.body,null,2))})]})]})}var pg={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function mg(e,t,n){let r={values:new Set,any:!1};if(e===`*`){for(let e=t;e<=n;e++)r.values.add(e);return r.any=!0,r}for(let i of e.split(`,`)){let e,a=i;if(i.includes(`/`)){let[t,n]=i.split(`/`);a=t,e=n}let o=e?Math.max(1,parseInt(e,10)||1):1,s=t,c=n;if(a!==`*`)if(a.includes(`-`)){let[e,t]=a.split(`-`).map(e=>parseInt(e,10));if(Number.isNaN(e)||Number.isNaN(t))return null;s=e,c=t}else{let e=parseInt(a,10);if(Number.isNaN(e))return null;s=e,c=e}for(let e=s;e<=c;e+=o)e>=t&&e<=n&&r.values.add(e)}return r}function hg(e){let t=(pg[e.trim()]??e.trim()).split(/\s+/);if(t.length!==5&&t.length!==6)return null;let[n,r,i,a,o]=t.length===6?t.slice(1):t,s=mg(n,0,59),c=mg(r,0,23),l=mg(i,1,31),u=mg(a,1,12),d=mg(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function gg(e,t,n){let r=hg(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+366*24*60*60*1e3;for(;i.length<n&&a.getTime()<=o;)r.minute.values.has(a.getMinutes())&&r.hour.values.has(a.getHours())&&r.month.values.has(a.getMonth()+1)&&(r.dom.any||r.dow.any?r.dom.values.has(a.getDate())&&r.dow.values.has(a.getDay()):r.dom.values.has(a.getDate())||r.dow.values.has(a.getDay()))&&i.push(new Date(a.getTime())),a.setMinutes(a.getMinutes()+1);return i}function _g(e){let t=/^(\d+)\s*(ms|s|m|h|d)$/.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;case`d`:return n*864e5;default:return null}}function vg(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function yg(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function bg(e){if(e.schedule&&typeof e.schedule==`object`){let t=e.schedule,n=String(t.type??``),r=t.timezone??e.timezone??e.tz;if(n===`cron`){let e=t.expression;return{cron:typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0,timezone:r}}if(n===`interval`){let e=Number(t.intervalMs);return{every:Number.isFinite(e)&&e>0?xg(e):void 0,timezone:r}}if(n===`once`)return{at:typeof t.at==`string`?t.at:void 0,timezone:r}}let t=typeof e.cron==`string`?e.cron:typeof e.schedule==`string`?e.schedule:void 0,n=e.every??e.interval;return{cron:t,every:typeof n==`string`?n:typeof n==`number`?xg(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function xg(e){return e%864e5==0?`${e/864e5}d`:e%36e5==0?`${e/36e5}h`:e%6e4==0?`${e/6e4}m`:e%1e3==0?`${e/1e3}s`:`${e}ms`}function Sg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,{cron:o,every:s,at:c,timezone:l}=bg(n),u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.retryPolicy,p=f?.maxRetries??n.maxRetries??n.retries,m=f?.backoffMs,h=n.timeout??n.timeoutMs,g=n.concurrency,_=s?_g(s):null,{nextFires:v,deltas:y}=X.useMemo(()=>{let e=new Date,t=[];if(o)t=gg(o,e,5);else if(_)t=vg(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Cg(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Hu,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(se,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Eg,{icon:Mr,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(Eg,{icon:qn,label:l,mono:!0}),p!=null&&(0,Y.jsx)(Eg,{icon:Rt,label:`retries: ${p}${m?` (${xg(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(Eg,{icon:Er,label:`timeout: ${xg(h)}`}),g!=null&&(0,Y.jsx)(Eg,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(Tg,{title:`Schedule`,icon:Tr,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(wg,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(wg,{label:`Every`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,Y.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,Y.jsx)(wg,{label:`At`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,Y.jsx)(Tg,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:gn,children:v.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:b?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,Y.jsx)(gn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:yg(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(Tg,{title:`Handler`,icon:In,children:u?(0,Y.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,Y.jsx)($e,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Cg(e){if(e<=0)return`now`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<48?`${r}h`:`${Math.round(r/24)}d`}function wg({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`break-all`,children:t})]})}function Tg({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Eg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Dg=[{key:`objects`,label:`Objects`,icon:gt,flat:!1},{key:`apps`,label:`Apps`,icon:er,flat:!1},{key:`messages`,label:`Messages`,icon:xt,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Yn,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Yr,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Gn,flat:!1},{key:`settings`,label:`Settings`,icon:dt,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:Oe,flat:!1}];function Og({name:e,draft:t}){let n=t,r=n.locale??n.language??`?`,i=n.label??n.name??e??``,a=n.description,o=n.data??n,s=Dg.map(e=>{let t=o?.[e.key];if(!t||typeof t!=`object`)return{...e,count:0,sample:[]};let n=Object.entries(t);return{...e,count:n.length,sample:n.slice(0,5)}}),c=s.reduce((e,t)=>e+t.count,0),l=s.filter(e=>e.count>0).length,u=Math.round(l/Dg.length*100);return c===0?(0,Y.jsx)(Z,{hint:`translation · ${r}`,children:(0,Y.jsx)(Hu,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(Z,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(_r,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[10px] font-mono text-emerald-800`,children:[(0,Y.jsx)(qn,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,Y.jsx)(tr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,Y.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,Dg.length,` (`,u,`%)`]}),(0,Y.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,Y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,Y.jsx)(kg,{cat:e},e.key))})]})})})}function kg({cat:e}){let t=e.icon;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,Y.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,Y.jsx)(`span`,{className:`truncate text-foreground/80`,children:Ag(n,e.flat)})]},t)),e.count>e.sample.length&&(0,Y.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function Ag(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function jg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``;return r?(0,Y.jsx)(Z,{hint:`position`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Pt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(P,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Positions don't grant data access on their own.`}),(0,Y.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,Y.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more`,` `,(0,Y.jsx)(`strong`,{children:`Permission Sets`}),` to control CRUD-VAMA, field access, and tab visibility. Record visibility comes from the business-unit tree and sharing rules, not from the position.`]})]})]})})]})})}):(0,Y.jsx)(Z,{hint:`position`,children:(0,Y.jsx)(Hu,{children:`Give the position a name to see the preview.`})})}function Mg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.instructions??``,s=Array.isArray(n.tools)?n.tools:[],c=Array.isArray(n.triggerPhrases)?n.triggerPhrases:[],l=Array.isArray(n.triggerConditions)?n.triggerConditions:[],u=Array.isArray(n.permissions)?n.permissions:[],d=n.active!==!1,f=n.model??void 0;return r?(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Et,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Pg,{icon:Mr,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(Pg,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(Pg,{icon:P,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(Ng,{title:`Instructions`,icon:or,children:o?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words max-h-64 overflow-auto`,children:o}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,Y.jsxs)(Ng,{title:`Tools (${s.length})`,icon:Pe,children:[s.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-mono border ${t?`border-amber-300 bg-amber-50 text-amber-900`:`border-border bg-muted/40`}`,children:[t&&(0,Y.jsx)(pn,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-amber-700`,children:`Wildcards expand to many tools at runtime — review the matching set in the agent before activating.`})]}),c.length>0&&(0,Y.jsx)(Ng,{title:`Trigger Phrases (${c.length})`,icon:be,children:(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,Y.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,Y.jsx)(Ng,{title:`Trigger Conditions (${l.length})`,icon:ce,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})}),u.length>0&&(0,Y.jsx)(Ng,{title:`Required Permissions`,icon:P,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})}):(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Hu,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Ng({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Pg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Fg=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Ig=d();function Lg(){return``.replace(/\/+$/,``)}function Rg(e){return`${Lg()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function zg(e){if(e.status===503){let t;try{t=await e.json()}catch{t=void 0}if((t&&typeof t==`object`&&`error`in t?String(t.error):``)===`external_service_unavailable`)throw new Fg}if(!e.ok){let t=`${e.status} ${e.statusText}`;try{let n=await e.json();n&&typeof n==`object`&&`error`in n&&(t=String(n.error))}catch{}throw Error(t)}return await e.json()}async function Bg(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await zg(await Ig(`${Rg(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Vg(e,t,n={}){return(await zg(await Ig(`${Rg(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Hg(e){return(await zg(await Ig(`${Rg(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Ug(e){return zg(await Ig(`${Rg(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Wg(e){await zg(await Ig(`${Lg()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Gg({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=X.useState(`loading`),[s,c]=X.useState(null),[l,u]=X.useState(null);X.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await Vg(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof Fg?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=X.useCallback(async()=>{if(s){o(`importing`),u(null);try{await Wg(s),o(`done`),i?.(s.name)}catch(e){u(e instanceof Error?e.message:String(e)),o(`ready`)}}},[s,i]),f=t?[t.schema,t.name].filter(Boolean).join(`.`):``;return(0,Y.jsx)(Ut,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Qt,{className:`max-w-2xl`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(vt,{children:[`Map remote table `,(0,Y.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Y.jsx)(Ce,{className:`h-8 w-8 text-emerald-500`}),(0,Y.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Review its binding and run validation to confirm it matches the remote table.`})]}),(a===`ready`||a===`importing`)&&s&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,Y.jsx)(`ul`,{className:`mt-1.5 space-y-1 text-[11px] text-amber-900/90 dark:text-amber-200/80`,children:s.review.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,Y.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(Wt,{className:`h-3 w-3`}),` Generated source`]}),(0,Y.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/30 p-2.5 text-[11px] leading-relaxed font-mono`,children:s.source})]})]}),(0,Y.jsx)(re,{children:a===`done`?(0,Y.jsx)(L,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(L,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Kg({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),p=X.useCallback(async()=>{n(`loading`),o(null);try{let t=await Bg(e);i(t),n(`loaded`)}catch(e){e instanceof Fg?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);X.useEffect(()=>{p()},[p]);let m=X.useMemo(()=>{let e=s.trim().toLowerCase();return e?r.filter(t=>[t.schema,t.name].filter(Boolean).join(`.`).toLowerCase().includes(e)):r},[r,s]),h=e=>{u(e),f(!0)};return t===`unavailable`?(0,Y.jsx)(qg,{}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(Me,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Filter tables…`,className:`w-full rounded border bg-background pl-7 pr-2 py-1.5 text-xs outline-none focus:ring-1 focus:ring-ring`})]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:a}),t===`loading`&&r.length===0&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,Y.jsx)(`div`,{className:`py-10 text-center text-sm text-muted-foreground`,children:r.length===0?`No remote tables found (check the datasource’s allowedSchemas).`:`No tables match the filter.`}),m.length>0&&(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,Y.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,Y.jsx)(Sn,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(cr,{className:`h-3 w-3`}),e.columnCount]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums text-muted-foreground`,children:typeof e.rowCountEstimate==`number`?e.rowCountEstimate.toLocaleString():`—`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(dn,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(Gg,{datasource:e,table:l,open:d,onOpenChange:f})]})}function qg(){return(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:[`Federation is not enabled on this server. The`,(0,Y.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var Jg={missing_table:`Missing table`,missing_column:`Missing column`,type_mismatch:`Type mismatch`,nullability_mismatch:`Nullability mismatch`,unmapped_column:`Unmapped column`,pk_mismatch:`Primary-key mismatch`};function Yg({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useCallback(async()=>{n(`running`),c(null);try{let t=await Ug(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof Fg?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,Y.jsx)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:`Federation is not enabled on this server, so validation is unavailable.`}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)($e,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:s}),t===`done`&&a!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded border p-2.5 text-sm ${a?`border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 text-emerald-800 dark:text-emerald-300`:`border-destructive/40 bg-destructive/5 text-destructive`}`,children:[a?(0,Y.jsx)(Ce,{className:`h-4 w-4`}):(0,Y.jsx)(Yn,{className:`h-4 w-4`}),a?`All ${r.length} object${r.length===1?``:`s`} match the remote schema.`:`${r.filter(e=>!e.ok).length} of ${r.length} object${r.length===1?``:`s`} diverge from the remote schema.`]}),t===`done`&&r.length===0&&(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No federated objects are bound to this datasource yet. Import a table from the Tables tab to get started.`}),r.length>0&&(0,Y.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsx)(Xg,{result:e},e.object))})]})}function Xg({result:e}){return(0,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,Y.jsx)(P,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(Yn,{className:`h-3.5 w-3.5 text-destructive`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[e.diffs.length,` diff`,e.diffs.length===1?``:`s`]})]}),e.diffs.length>0&&(0,Y.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,Y.jsx)(Zg,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Zg({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,Y.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-2.5 py-1.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`rounded px-1 py-0.5 font-medium uppercase tracking-wide text-[9px] ${e.severity===`error`?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:Jg[e.kind]??e.kind}),t&&(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function Qg({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=X.useState(null),[a,o]=X.useState(!1),[s,c]=X.useState(null),l=X.useCallback(async()=>{if(e){o(!0),c(null);try{let t=await Hg(e);i(t)}catch(e){c(e instanceof Fg?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,Y.jsx)(Hr,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:t??`external`}),(0,Y.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`:`bg-muted text-muted-foreground`}`,children:n?`writes allowed`:`read-only`}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(gn,{className:`h-3 w-3`}),`snapshot `,$g(r.snapshotAt)]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,Y.jsxs)(Hn,{defaultValue:`tables`,className:`p-3`,children:[(0,Y.jsxs)(an,{children:[(0,Y.jsx)(Gr,{value:`tables`,children:`Tables`}),(0,Y.jsx)(Gr,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(Ln,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(Kg,{datasource:e})}),(0,Y.jsx)(Ln,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(Yg,{datasource:e})})]})]}):(0,Y.jsx)(`div`,{className:`rounded border bg-muted/20 p-3 text-xs text-muted-foreground`,children:`Save the datasource first to browse its remote tables and validate federated objects.`})}function $g(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var e_=/pass|secret|key|token|credential|auth/i;function t_(e){return e_.test(e)}function n_(e){return e==null||e===``?`∅`:`••••••`}function r_(e){return e==null?`∅`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`[${e.length}]`:typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e)}function i_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=n.schemaMode??`managed`,_=g!==`managed`,v=!!(n.external??void 0)?.allowWrites,y=Object.entries(l);return!r&&y.length===0?(0,Y.jsx)(Z,{hint:`datasource`,children:(0,Y.jsx)(Hu,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(Z,{hint:`datasource · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,Y.jsx)(hn,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(s_,{icon:Mr,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(s_,{icon:zn,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(s_,{icon:Pn,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(Qg,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(o_,{title:`Connection`,icon:Ve,children:y.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=t_(e);return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:n_(t)}),(0,Y.jsx)(`span`,{className:`rounded bg-amber-50 border border-amber-200 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-800`,children:`redacted`})]}):r_(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(a_,{title:`Pool`,icon:Jn,value:u}),(0,Y.jsx)(a_,{title:`SSL`,icon:P,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)(a_,{title:`Retry Policy`,icon:Rt,value:f}),(0,Y.jsx)(a_,{title:`Health Check`,icon:Jn,value:p})]}),h.length>0&&(0,Y.jsx)(o_,{title:`Capabilities`,icon:P,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})})}function a_({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`dd`,{className:`font-mono truncate`,children:t_(e)?n_(t):r_(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function o_({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function s_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function c_(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function l_(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/40`,text:`text-red-700 dark:text-red-300`,icon:Ot};case`warning`:return{ring:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`,text:`text-amber-800 dark:text-amber-300`,icon:R};default:return{ring:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`,text:`text-blue-800 dark:text-blue-300`,icon:Nn}}}function u_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.type??`script`,s=n.object,c=n.message??``,l=n.severity??`error`,u=n.active!==!1,d=Array.isArray(n.events)?n.events:[],f=n.priority,p=Array.isArray(n.tags)?n.tags:[],m=l_(l);return r?(0,Y.jsx)(Z,{hint:`validation · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(m_,{icon:Mr,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(m_,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(m_,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(m_,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,Y.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,Y.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,Y.jsx)(d_,{type:o,d:n}),p.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})]})]})})}):(0,Y.jsx)(Z,{hint:`validation`,children:(0,Y.jsx)(Hu,{children:`Give the validation a name to see the preview.`})})}function d_({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(p_,{title:`Condition`,icon:In,children:(0,Y.jsx)(f_,{value:c_(t.condition)??c_(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=c_(t.scope)??c_(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(p_,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Ct,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,Y.jsx)(p_,{title:`Scope`,icon:_e,children:(0,Y.jsx)(f_,{value:n})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field;return(0,Y.jsx)(p_,{title:`Transitions${r?` on ${r}`:``}`,icon:Ye,children:n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(qr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:Array.isArray(t)&&t.length>0?t.join(` | `):`∅ (dead-end)`})]},e))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,Y.jsx)(p_,{title:`Format`,icon:Ie,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=c_(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(p_,{title:`Fields involved`,icon:_e,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e)),e.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,Y.jsx)(p_,{title:`Cross-field condition`,icon:In,children:(0,Y.jsx)(f_,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(p_,{title:`Async endpoint`,icon:qn,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,Y.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,Y.jsx)(p_,{title:`Custom handler`,icon:In,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,Y.jsx)(p_,{title:`Rule`,icon:Yn,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs text-muted-foreground italic`,children:[`Unknown rule type "`,e,`". Showing common fields only.`]})})}}function f_({value:e}){return e?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function p_({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function m_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var h_=X.lazy(()=>a(()=>import(`./plugin-charts-DFywQsyC.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function g_({draft:e}){let t=S(),{fieldLabel:n}=ii(),r=e.object,i=X.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=X.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),o=!!r&&i.length>0,[s,c]=X.useState({status:`idle`,rows:[]}),l=X.useCallback(async()=>{if(o){c({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:a,measures:i});c({status:`ok`,rows:Array.isArray(n?.rows)?n.rows:[],fields:Array.isArray(n?.fields)?n.fields:[],object:n?.object})}catch(e){c({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,a,i,o]),u=`${r??``}|${a.join(`,`)}|${i.join(`,`)}`;if(X.useEffect(()=>{o&&l()},[u]),!r)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(i.length===0)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`Add a measure`,description:`A dataset needs at least one measure (e.g. revenue = sum(amount)) to preview.`})});let{measureField:d,headerLabel:f}=C(s.status===`ok`?s.fields:void 0,s.status===`ok`?s.object:void 0,n),p=[...a,...i],m=e=>{let t=d(e)?.format;return typeof t==`string`&&t.includes(`%`)},h=i.filter(m),g=h.length>0&&h.length<i.length;return(0,Y.jsx)(Z,{hint:`dataset · ${r}${a.length?` · by `+a.join(`, `):``}`,children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void l(),disabled:s.status===`loading`,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[s.status===`loading`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Nr,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[i.length,` measure`,i.length===1?``:`s`,` · `,a.length,` dimension`,a.length===1?``:`s`]})]}),s.status===`error`&&(0,Y.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`break-words`,children:s.error})]}),s.status===`ok`&&s.rows.length===0&&(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),s.rows.length>0&&a.length>=1&&(0,Y.jsx)(Q,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`})}),children:(0,Y.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,Y.jsx)(h_,{schema:{data:s.rows,xAxisKey:a[0],chartType:g?`combo`:`bar`,series:i.map(e=>({dataKey:e,label:f(e),chartType:g&&m(e)?`line`:`bar`}))}}),g&&(0,Y.jsxs)(`p`,{className:`mt-1 px-1 text-[10px] text-muted-foreground`,children:[`Ratio measures (`,h.map(f).join(`, `),`) use the right axis.`]})]})})}),s.rows.length>0&&(0,Y.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Y.jsx)(`tr`,{children:p.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:f(e)},e))})}),(0,Y.jsx)(`tbody`,{children:s.rows.map((e,t)=>(0,Y.jsx)(`tr`,{className:`border-t`,children:p.map(t=>(0,Y.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:i.includes(t)?x(e[t],d(t)?.format,d(t)?.currency):b(e[t])},t))},t))})]})})]})})}function __(e){return Array.isArray(e)?e.map((e,t)=>{if(!e||typeof e!=`object`)return null;let n=String(e.key??``).trim(),r=String(e.label??n??``).trim();return!n&&!r?null:{g:{key:n||`(no key)`,label:r||n||`(unnamed)`,order:typeof e.order==`number`?e.order:void 0,include:v_(e.include),package:typeof e.package==`string`?e.package:void 0,pages:y_(e.pages)},i:t}}).filter(e=>e!==null).sort((e,t)=>(e.g.order??0)-(t.g.order??0)||e.i-t.i).map(e=>e.g):[]}function v_(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function y_(e){if(Array.isArray(e))return e.map(e=>typeof e==`string`?{literal:e}:e&&typeof e==`object`?{doc:typeof e.doc==`string`?e.doc:void 0,href:typeof e.href==`string`?e.href:void 0,label:typeof e.label==`string`?e.label:void 0,badge:typeof e.badge==`string`?e.badge:void 0,icon:typeof e.icon==`string`?e.icon:void 0}:null).filter(e=>e!==null)}function b_(e){return e===`public`?{icon:(0,Y.jsx)(At,{className:`h-3 w-3`}),label:`Public`,tone:`text-emerald-700 bg-emerald-50 border-emerald-200`}:e&&typeof e==`object`&&typeof e.permissionSet==`string`?{icon:(0,Y.jsx)(Ve,{className:`h-3 w-3`}),label:`Permission set: ${e.permissionSet}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,Y.jsx)(sn,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function x_({name:e,draft:t}){let n=t,r=String(n.name??e??``).trim(),i=String(n.label??r),a=typeof n.description==`string`?n.description:``,o=typeof n.slug==`string`?n.slug:``,s=X.useMemo(()=>__(n.groups),[n.groups]),c=b_(n.audience);return r?(0,Y.jsx)(Z,{hint:`book · spine`,toolbar:(0,Y.jsxs)(`a`,{href:`/meta/book/${encodeURIComponent(r)}/tree`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open the live-resolved navigation tree (actual docs per group)`,children:[`Resolved tree `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(or,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium ${c.tone}`,children:[c.icon,c.label]})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:r}),o&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Slug: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1.5`,children:a})]}),s.length===0?(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(nt,{className:`h-8 w-8 opacity-50`}),title:`No groups yet`,tone:`warn`,description:(0,Y.jsxs)(Y.Fragment,{children:[`A book needs at least one group in its `,(0,Y.jsx)(`code`,{children:`groups`}),` spine. Each group derives its members from an `,(0,Y.jsx)(`code`,{children:`include`}),` rule (a glob like`,` `,(0,Y.jsx)(`code`,{children:`crm_guide_*`}),` or a `,(0,Y.jsx)(`code`,{children:`{ tag }`}),`).`]})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:s.map((e,t)=>(0,Y.jsx)(S_,{group:e},`${e.key}-${t}`))})]})})}):(0,Y.jsx)(Z,{hint:`book`,children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(or,{className:`h-8 w-8 opacity-50`}),title:`Name your book`,description:`Enter a name in the Form tab to start authoring the documentation spine.`})})}function S_({group:e}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.key}),typeof e.order==`number`&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Order within the book`,children:[`#`,e.order]}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[e.package&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Membership rule is scoped to this package`,children:[(0,Y.jsx)(Kr,{className:`h-3 w-3`}),e.package]}),(0,Y.jsx)(C_,{include:e.include,hasOverride:!!e.pages?.length})]})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:e.pages?.length?(0,Y.jsx)(`ol`,{className:`space-y-1`,children:e.pages.map((e,t)=>(0,Y.jsx)(w_,{node:e},t))}):e.include==null?(0,Y.jsxs)(`div`,{className:`text-[11px] text-amber-700 italic`,children:[`No `,(0,Y.jsx)(`code`,{children:`include`}),` rule and no explicit `,(0,Y.jsx)(`code`,{children:`pages`}),` — this group matches nothing unless docs set `,(0,Y.jsxs)(`code`,{children:[`group: "`,e.key,`"`]}),`.`]}):(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Members derived from the rule above — resolved against the live doc set.`})})]})}function C_({include:e,hasOverride:t}){return e==null?t?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Curated order via explicit pages`,children:`curated`}):null:typeof e==`string`?(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,title:`Glob over doc names`,children:e}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[10px] text-foreground`,title:`Match by doc tag`,children:[(0,Y.jsx)(rr,{className:`h-3 w-3`}),e.tag]})}function w_({node:e}){if(e.literal===`---`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-wider text-muted-foreground/60`,children:[(0,Y.jsx)(et,{className:`h-3 w-3`}),`separator`]});if(e.literal===`...`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[11px] italic text-muted-foreground`,children:[(0,Y.jsx)(mr,{className:`h-3.5 w-3.5`}),`…rest (remaining matched docs, by order)`]});let t=!!e.href,n=e.literal??e.doc,r=e.label??n??e.href??`(empty)`;return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(Oe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:r}),!t&&n&&e.label&&(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n}),e.badge&&(0,Y.jsx)(`span`,{className:`rounded-full border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-foreground`,children:e.badge}),t&&(0,Y.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground truncate max-w-[40%]`,title:e.href,children:e.href})]})}function T_(){il(`page`,Hd),il(`view`,Kd),il(`dashboard`,$d),il(`report`,nf),il(`app`,gf),il(`action`,tg),il(`object`,Lf),il(`datasource`,i_),il(`validation`,u_),il(`dataset`,g_),il(`email_template`,Vf),il(`translation`,Og),il(`book`,x_),il(`flow`,wh),il(`job`,Sg),il(`agent`,Eh),il(`tool`,zh),il(`skill`,Mg),il(`permission`,Kh),il(`profile`,Kh),il(`position`,jg),il(`role`,jg)}var E_=[{value:`metric`,label:`KPI Metric`},{value:`bar`,label:`Bar Chart`},{value:`horizontal-bar`,label:`Horizontal Bar`},{value:`line`,label:`Line Chart`},{value:`area`,label:`Area Chart`},{value:`pie`,label:`Pie Chart`},{value:`donut`,label:`Donut Chart`},{value:`funnel`,label:`Funnel`},{value:`table`,label:`Table`},{value:`pivot`,label:`Pivot Table`}],D_=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function O_(e,t){let n=Array.isArray(e.widgets)?e.widgets:[],r=n.findIndex(e=>e?.id===t);return r<0?null:{widget:n[r],index:r}}function k_({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=Array.isArray(e.widgets)?e.widgets:[],c=t.kind===`widget`?t.id:void 0,l=c?O_(e,c):null,u=l?.widget??{},d=typeof u.dataset==`string`?u.dataset:``,f=Array.isArray(u.dimensions)?u.dimensions.filter(e=>typeof e==`string`):[],p=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],m=ga(),h=ca(d||void 0,m),g=X.useMemo(()=>{let e=m.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return d&&!e.some(e=>e.value===d)&&e.push({value:d,label:d}),e},[m.datasets,d]),v=X.useMemo(()=>h.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[h.measures]),y=X.useMemo(()=>h.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[h.dimensions]),b=X.useMemo(()=>h.dimensions.map(e=>({value:e.name,label:e.name,hint:e.type})),[h.dimensions]),x=X.useMemo(()=>_({globalFilters:e.globalFilters,dateRange:e.dateRange}),[e]);if(t.kind!==`widget`)return(0,Y.jsx)(j_,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,Y.jsx)(j_,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:S,index:C}=l;function w(e){let t=[...s];t[C]={...t[C],...e},n({widgets:t})}function T(e){n({widgets:Pi(s,C,e)}),S.id&&i?.({kind:`widget`,id:S.id,label:S.title??void 0})}return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.kind`,o)}),(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:S.title||t.label||`Widget ${C+1}`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(Xi,{index:C,total:s.length,onMove:T,upLabel:G(`engine.inspector.reorder.up`,o),downLabel:G(`engine.inspector.reorder.down`,o),disabled:a}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:G(`engine.inspector.widget.close`,o),"aria-label":G(`engine.inspector.widget.close`,o),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(A_,{id:`widget-title`,label:G(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(B,{id:`widget-title`,value:S.title??``,onChange:e=>w({title:e.target.value}),disabled:a})}),(0,Y.jsx)(A_,{id:`widget-type`,label:G(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(oe,{value:S.type??`metric`,onValueChange:e=>w({type:e}),disabled:a,children:[(0,Y.jsx)(fr,{id:`widget-type`,children:(0,Y.jsx)(Dr,{})}),(0,Y.jsx)(En,{children:E_.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.datasetSection`,o)}),(0,Y.jsxs)(A_,{id:`widget-dataset`,label:G(`engine.inspector.widget.dataset`,o),children:[(0,Y.jsx)(Ua,{value:d,onCommit:e=>w({dataset:e||void 0}),options:g,loading:m.loading,placeholder:G(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:G(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,Y.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:G(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(va,{label:G(`engine.inspector.widget.dimensions`,o),emptyText:G(`engine.inspector.widget.dimensionsHint`,o),names:f,options:y,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>w({dimensions:e})}),(0,Y.jsx)(va,{label:G(`engine.inspector.widget.values`,o),emptyText:G(`engine.inspector.widget.valuesHint`,o),names:p,options:v,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>w({values:e})})]})]}),x.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.filterBindingsSection`,o)}),(0,Y.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:G(`engine.inspector.widget.filterBindingsHint`,o)}),x.map(e=>{let t=S.filterBindings,n=t?.[e.name],r=n===!1,i=typeof n==`string`?n:``,s=n=>{let r={...t??{}};n===void 0?delete r[e.name]:r[e.name]=n,w({filterBindings:Object.keys(r).length>0?r:void 0})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,"data-testid":`widget-filter-binding-${e.name}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(U,{className:`text-xs font-medium text-muted-foreground truncate`,children:e.label||e.name}),(0,Y.jsx)(J,{label:G(`engine.inspector.widget.filterBindingApply`,o),value:!r,onCommit:e=>s(e?void 0:!1),disabled:a})]}),!r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ua,{value:i,onCommit:e=>s(e||void 0),options:b,placeholder:W(`engine.inspector.widget.filterBindingDefault`,o,{field:e.field}),searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),i&&!a&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 shrink-0 px-2 text-[10px] text-muted-foreground`,onClick:()=>s(void 0),children:G(`engine.inspector.widget.filterBindingReset`,o)})]})]},e.name)})]}),(0,Y.jsx)(A_,{id:`widget-color`,label:G(`engine.inspector.widget.color`,o),children:(0,Y.jsx)(na,{value:S.colorVariant??`default`,onChange:e=>w({colorVariant:e}),disabled:a,options:D_.map(e=>({value:e}))})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(A_,{id:`widget-w`,label:G(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(B,{id:`widget-w`,type:`number`,min:1,value:S.layout?.w??1,onChange:e=>w({layout:{...S.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,Y.jsx)(A_,{id:`widget-h`,label:G(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(B,{id:`widget-h`,type:`number`,min:1,value:S.layout?.h??1,onChange:e=>w({layout:{...S.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,Y.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Y.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:text-destructive`,onClick:()=>{let t=Array.isArray(e.widgets)?[...e.widgets]:[];t.splice(C,1),n({widgets:t}),r()},children:G(`engine.inspector.widget.remove`,o)})})]})}function A_({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function j_({message:e,onClose:t,locale:n}){return(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,Y.jsx)(`p`,{children:e}),(0,Y.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:G(`engine.inspector.widget.close`,n)})]})}var M_={io:`input`,unrepresentable:`any`},N_=new Set([`widgets`,`label`,`description`,`name`]),P_,F_=!1;function I_(){if(P_||F_)return P_;try{P_=E(k,M_)}catch(e){F_=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return P_}var L_;function R_(){if(L_)return L_;if(!(!D||typeof D!=`object`)){try{let e=JSON.parse(JSON.stringify(D));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!N_.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),L_=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return L_}}var z_=new Set([`name`,`label`,`description`,`widgets`]);function B_({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=X.useCallback(e=>G(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=X.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=Gi(`widget`,l.map(e=>e?.id).filter(Boolean)),r=qd[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:ua(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:la(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:Pi(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=X.useState(null),[g,_]=X.useState(null),{schema:v,form:y}=X.useMemo(()=>ta({bundledSchema:I_(),bundledForm:R_(),serverSchema:a,excludeFields:z_,sectionTitle:G(`engine.inspector.moreFields`,r)}),[a,r]);return(0,Y.jsxs)(Li,{kindLabel:o(`engine.inspector.dashboard.kind`),title:String(s||e.name||o(`engine.inspector.dashboard.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.dashboard.close`),hideClose:!0,children:[(0,Y.jsx)(q,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,Y.jsx)(q,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.widgetsEmpty`)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=qd[e?.type]?.icon??Xd;return(0,Y.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Y.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,Y.jsx)(Zd,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,Y.jsx)(ha,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.noSchema`)})})]})}var V_=new Set([`object`,`object-field`,`flow`,`org-membership-level`,`position`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function H_(e){let t=e.xRef;if(!t||typeof t!=`object`)return;let n=typeof t.objectSource==`string`&&t.objectSource?{objectSource:t.objectSource}:{};if(typeof t.kindFrom==`string`&&t.kindFrom&&t.map&&typeof t.map==`object`){let e={};for(let[n,r]of Object.entries(t.map))typeof r==`string`&&V_.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&V_.has(t.kind))return{kind:t.kind,...n}}function U_(e){let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim();return t?t.split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):e}function W_(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function G_(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`);if(typeof e.type==`string`)return e.type;if(Array.isArray(e.enum))return`string`;if(e.properties)return`object`;if(e.items)return`array`}function K_(e,t){let n=new Set((t??[]).filter(e=>typeof e==`string`));return e.filter(e=>typeof e==`string`).filter(e=>!n.has(e)).map(e=>({value:e,label:U_(e)}))}function q_(e){if(!(e.default===void 0||e.default===null)){if(typeof e.default==`boolean`||typeof e.default==`number`)return String(e.default);if(typeof e.default==`string`)return e.default}}function J_(e){return e.xExpression===`expression`||e.xExpression===`template`?e.xExpression:void 0}function Y_(e){if(Array.isArray(e.enum))return{kind:`select`};let t=G_(e);if(t===`boolean`)return{kind:`boolean`};if(t===`number`||t===`integer`)return{kind:`number`};if(t===`string`){let t=e.format===`multiline`,n=J_(e);return n===`expression`?t?{kind:`textarea`,refMode:`expression`}:{kind:`expression`}:n===`template`?t?{kind:`textarea`,refMode:`template`}:{kind:`expression`,refMode:`template`}:{kind:t?`textarea`:`text`}}}var X_=4;function Z_(e,t){let n=W_(e.items)?e.items:void 0,r=n?G_(n):void 0;return n&&r===`object`&&W_(n.properties)?t>=X_?null:{kind:`objectList`,columns:Q_(n,t+1)}:r===`string`?{kind:`stringList`}:r===`number`||r===`integer`?{kind:`numberList`}:null}function Q_(e,t=0){let n=e.properties??{},r=[];for(let[e,i]of Object.entries(n)){if(!W_(i))continue;let n=G_(i);if(n===`array`){let n=Z_(i,t);if(n){r.push({key:e,label:i.title||U_(e),kind:n.kind,...n.columns?{columns:n.columns}:{},...i.description?{placeholder:i.description}:{}});continue}}let a,o,s=H_(i);s?a=`reference`:Array.isArray(i.enum)?(a=`select`,o=K_(i.enum,i.xEnumDeprecated)):a=n===`boolean`?`boolean`:J_(i)===`expression`?`expression`:`text`,r.push({key:e,label:i.title||U_(e),kind:a,...o?{options:o}:{},...s?{ref:s}:{},...i.description?{placeholder:i.description}:{}})}return r}function $_(e,t){return{label:e.title||U_(t),...e.description?{help:e.description}:{},...q_(e)?{defaultValue:q_(e)}:{}}}function ev(e){if(!W_(e)||G_(e)!==`object`||!W_(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!W_(r))continue;let e=G_(r);if(e===`array`){let e=W_(r.items)?r.items:void 0,i=e?G_(e):void 0;e&&i===`object`&&W_(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:Q_(e),...$_(r,n)}):i===`string`?t.push({id:n,path:[`config`,n],kind:`stringList`,...$_(r,n)}):(i===`number`||i===`integer`)&&t.push({id:n,path:[`config`,n],kind:`numberList`,...$_(r,n)});continue}if(e===`object`&&W_(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>W_(e)),i=e.some(([e,t])=>e===`enabled`&&G_(t)===`boolean`);for(let[a,o]of e){let e=o,s=H_(e),c=s?void 0:Y_(e),l=s?`reference`:c?.kind;if(!l)continue;let u=`${n}.${a}`,d=i&&a===`enabled`,f={id:u,path:[`config`,n,a],kind:l,...d?{label:r.title||U_(n),...r.description?{help:r.description}:{},...q_(e)?{defaultValue:q_(e)}:{}}:$_(e,a),...s?{ref:s}:{},...c?.refMode?{refMode:c.refMode}:{},...l===`select`&&Array.isArray(e.enum)?{options:K_(e.enum,e.xEnumDeprecated)}:{},...i&&!d?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(f)}continue}if(e===`object`&&r.additionalProperties!==void 0&&r.additionalProperties!==!1){t.push({id:n,path:[`config`,n],kind:`keyValue`,...$_(r,n)});continue}let i=H_(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...$_(r,n)});continue}let a=Y_(r);a&&t.push({id:n,path:[`config`,n],kind:a.kind,...$_(r,n),...a.refMode?{refMode:a.refMode}:{},...a.kind===`select`&&Array.isArray(r.enum)?{options:K_(r.enum,r.xEnumDeprecated)}:{}})}return t}var tv=e=>ap(e),nv=e=>typeof e.expression==`string`?e.expression.trim():``,rv=e=>typeof e.label==`string`?e.label.trim():``,iv=e=>typeof e.target==`string`?e.target.trim():``,av=e=>{let t=nv(e);return t===``||t===`true`};function ov(e){return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&!Array.isArray(e)):[]}function sv(e,t){if(av(e))return t.isDefault===!0;let n=nv(e),r=tv(t.condition);if(n&&r===n)return!0;let i=rv(e);return i!==``&&t.label===i}var cv=e=>t=>t.source===e&&t.type!==`fault`&&t.type!==`back`;function lv(e,t){let n=nv(t),r=rv(t),i={...e};return r?i.label=r:delete i.label,n&&n!==`true`?(i.condition=n,delete i.isDefault):n===`true`?(i.isDefault=!0,delete i.condition):(delete i.condition,delete i.isDefault),i}function uv(e,t,n){let r=ov(t),i=cv(e),a=0;return n.map(e=>{if(!i(e))return e;let t=r[a++];return t?lv(e,t):e})}function dv(e,t,n){let r=ov(t);if(r.length===0)return r;let i=n.map((e,t)=>t).filter(t=>cv(e)(n[t])),a=new Set,o=new Map;return r.forEach((e,t)=>{let r=i.find(t=>!a.has(t)&&sv(e,n[t]));r!==void 0&&(a.add(r),o.set(t,r))}),r.forEach((e,t)=>{if(o.has(t))return;let n=i.find(e=>!a.has(e));n!==void 0&&(a.add(n),o.set(t,n))}),r.map((e,t)=>{let{target:r,...i}=e,a=o.get(t);return a===void 0?i:{...i,target:n[a].target}})}function fv(e,t,n){let r=ov(t),i=r.map(e=>{let{target:t,...n}=e;return n});if(!r.some(e=>iv(e)!==``))return{conditions:i,edges:uv(e,i,n)};let a=n.map((e,t)=>t).filter(t=>cv(e)(n[t])),o=new Set,s=new Map,c=[(e,t)=>t.target===iv(e)&&sv(e,t),(e,t)=>t.target===iv(e),(e,t)=>sv(e,t)];for(let e of c)r.forEach((t,r)=>{if(s.has(r)||iv(t)===``)return;let i=a.find(r=>!o.has(r)&&e(t,n[r]));i!==void 0&&(o.add(i),s.set(r,i))});let l=new Map,u=[],d=new Set;return r.forEach((t,r)=>{let i=iv(t);if(i===``){let e=a.find(e=>!o.has(e)&&sv(t,n[e]));e!==void 0&&(o.add(e),d.add(e));return}let c=s.get(r);c===void 0?u.push(lv({source:e,target:i},t)):l.set(c,lv({...n[c],target:i},t))}),{conditions:i,edges:n.map((e,t)=>d.has(t)?null:l.get(t)??e).filter(e=>e!==null).concat(u)}}function pv(e,t){return t===`template`?`{${e}}`:e}function mv(e,t,n,r,i){let a=pv(n,t),o=Math.min(Math.max(r,0),e.length),s=Math.min(Math.max(i,0),e.length),c=Math.min(o,s),l=Math.max(o,s);return{next:e.slice(0,c)+a+e.slice(l),caret:c+a.length}}var hv=`Insert a reference`,gv=`Search references…`,_v=`No matching references.`;function vv({value:e,onValueChange:t,onBlur:n,onKeyDown:r,mode:i,groups:a,placeholder:o,disabled:s,multiline:c,rows:l=4,mono:u,className:d}){let f=X.useRef(null),p=X.useRef({start:0,end:0}),[m,h]=X.useState(!1),g=e=>{f.current=e},_=()=>{let t=f.current;t&&(p.current={start:t.selectionStart??e.length,end:t.selectionEnd??e.length})},v=n=>{let{next:r,caret:a}=mv(e,i,n,p.current.start,p.current.end);t(r),h(!1),requestAnimationFrame(()=>{let e=f.current;if(e){e.focus();try{e.setSelectionRange(a,a)}catch{}p.current={start:a,end:a}}})},y=a.some(e=>e.refs.length>0),b={value:e,onChange:e=>t(e.target.value),onBlur:n,onKeyDown:r,onSelect:_,onKeyUp:_,onClick:_,placeholder:o,disabled:s};return(0,Y.jsxs)(`div`,{className:I(`relative`,d),children:[c?(0,Y.jsx)(`textarea`,{ref:g,...b,rows:l,className:`w-full rounded border bg-background px-2 py-1.5 pr-8 font-mono text-xs`}):(0,Y.jsx)(B,{ref:g,...b,className:I(`h-8 pr-8 text-sm`,u&&`font-mono`)}),y&&!s&&(0,Y.jsxs)(Cn,{open:m,onOpenChange:h,children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,"aria-label":hv,title:hv,onMouseDown:_,className:`absolute right-1 top-1 inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,Y.jsx)(nr,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(Mn,{align:`end`,className:`w-72 p-0`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,Y.jsxs)(De,{children:[(0,Y.jsx)(Ue,{placeholder:gv,className:`h-9`}),(0,Y.jsxs)(Le,{children:[(0,Y.jsx)(zt,{children:_v}),a.map(e=>(0,Y.jsx)(we,{heading:e.label,children:e.refs.map(t=>(0,Y.jsxs)(Sr,{value:`${t.token} ${t.label} ${t.detail??``}`,onSelect:()=>v(t.token),className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate font-mono text-xs`,children:pv(t.token,i)}),t.detail&&(0,Y.jsx)(`span`,{className:`shrink-0 truncate text-[10px] text-muted-foreground`,children:t.detail})]},`${e.id}:${t.token}`))},e.id))]})]})})]})]})}function yv({value:e,role:t,scopeGroups:n}){let r=t===`template`?null:sm(t,e);if(r)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:r.message});let i=n&&n.length>0?em(n.flatMap(e=>e.refs)):null,a=i?rm(e,t,i):[];return a.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(a)}):null}function bv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xv(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Sv(e){let t=e.trim();if(t===``)return``;if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function Cv(e){return Array.isArray(e)?e.filter(e=>bv(e)).map(e=>{let t=e.variable??e.name??e.key;return[typeof t==`string`?t:``,e.value]}):bv(e)?Object.entries(e):[]}function wv(e,t){let n=[...t];return Cv(e).map(([e,t])=>{let r=Gi(`kv`,n);return n.push(r),{id:r,key:e,raw:xv(t)}})}function Tv(e,t){let n=new Set;if(t){let t=[];for(let r of e){let e=r.key.trim();!e||n.has(e)||(n.add(e),t.push({variable:e,value:Sv(r.raw)}))}return t}let r={};for(let t of e){let e=t.key.trim();!e||n.has(e)||(n.add(e),r[e]=Sv(t.raw))}return r}function Ev(e){if(Array.isArray(e))return JSON.stringify(e);let t=e??{},n=Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{});return JSON.stringify(n)}function Dv({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l,scopeGroups:u}){let d=Array.isArray(t),f=X.useMemo(()=>Ev(Tv(wv(t,[]),d)),[t,d]),[p,m]=X.useState(()=>wv(t,[])),h=X.useRef(f);X.useEffect(()=>{f!==h.current&&(m(wv(t,[])),h.current=f)},[f,t]);let g=e=>{let t=Tv(e,d);h.current=Ev(t),n((Array.isArray(t)?t.length===0:Object.keys(t).length===0)?void 0:t)},_=(e,t)=>{m(n=>n.map(n=>n.id===e?{...n,...t}:n))},v=()=>{m(e=>[...e,{id:Gi(`kv`,e.map(e=>e.id)),key:``,raw:``}])},y=e=>{m(t=>{let n=t.filter(t=>t.id!==e);return g(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[p.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),p.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{value:e.key,onChange:t=>_(e.id,{key:t.target.value}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:r,className:`h-8 flex-1 font-mono text-xs`}),(0,Y.jsx)(vv,{mode:`template`,value:e.raw,onValueChange:t=>_(e.id,{raw:t}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:s,disabled:r,className:`flex-1`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>y(e.id),disabled:r,"aria-label":c,title:c,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(yv,{value:e.raw,role:`template`,scopeGroups:u})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function Ov(e,t){let n=[...t];return e.map(e=>{let t=Gi(`sl`,n);return n.push(t),{id:t,value:e}})}function kv(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Av({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=X.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=X.useState(()=>Ov(c,[])),d=X.useRef(JSON.stringify(c));X.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Ov(c,[])),d.current=e)},[c]);let f=e=>{let t=kv(e);d.current=JSON.stringify(t),n(t.length?t:void 0)},p=(e,t)=>{u(n=>n.map(n=>n.id===e?{...n,value:t}:n))},m=()=>{u(e=>[...e,{id:Gi(`sl`,e.map(e=>e.id)),value:``}])},h=e=>{u(t=>{let n=t.filter(t=>t.id!==e);return f(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{value:e.value,onChange:t=>p(e.id,t.target.value),onBlur:()=>f(l),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:a,disabled:r,className:`h-8 flex-1 text-xs`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(e.id),disabled:r,"aria-label":o,title:o,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var jv={object:`object`,flow:`flow`,position:`position`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`},Mv=[{value:`owner`,label:`Owner`},{value:`admin`,label:`Admin`},{value:`member`,label:`Member`}];function Nv(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource,connectorSource:e.connectorSource};if(e.kindFrom&&e.map){let n=t(e.kindFrom),r=typeof n==`string`?e.map[n]:void 0;if(r)return{kind:r,objectSource:e.objectSource,connectorSource:e.connectorSource}}}}function Pv(e,t){let n=e?.config;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[t];return typeof r==`string`&&r?r:void 0}function Fv(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Pv((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Pv(n.node,r)}function Iv(e,t,n){if(e!==`connector-action`)return;let r=n.node?.connectorConfig;if(!r||typeof r!=`object`||Array.isArray(r))return;let i=r[t||`connectorId`];return typeof i==`string`&&i?i:void 0}function Lv(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.key==`string`&&!!e.key).map(e=>({value:e.key,label:typeof e.label==`string`&&e.label&&e.label!==e.key?`${e.label} (${e.key})`:e.key})):[]}function Rv(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.name==`string`&&!!e.name).map(e=>{let t=typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name;return{value:e.name,label:e.origin===`declarative`?`${t} · declarative`:t}}):[]}function zv(e){let t=Ai(),[n,r]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{if(n)return;let t=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));r({options:t,loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}function Bv(e){let[t,n]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){n({options:[],loading:!1});return}let t=!1;return n(e=>({...e,loading:!0})),fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(r=>{if(t)return;let i=r?.data?.connectors??r?.connectors??[],a=Array.isArray(i)?i.find(t=>t?.name===e):void 0;n({options:Lv(a?.actions),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Vv(e){let[t,n]=X.useState({options:[]});return X.useEffect(()=>{if(!e){n({options:[]});return}let t=!1;return fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>{if(t)return;let r=e?.data?.connectors??e?.connectors??[];n({options:Rv(r)})}).catch(()=>{t||n({options:[]})}),()=>{t=!0}},[e]),t}function Hv({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=X.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?Fv(e.kind,e.objectSource,l):void 0,{fields:f}=Ki(u===`object-field`?d:void 0),p=e?Iv(e.kind,e.connectorSource,l):void 0,{options:m}=Bv(u===`connector-action`?p:void 0),{options:h}=Vv(u===`connector`),g=u&&u!==`object-field`&&u!==`node`&&u!==`connector-action`&&u!==`connector`?jv[u]:void 0,{options:_}=zv(g),v=X.useMemo(()=>{if(u===`object-field`)return f.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(u===`connector-action`)return m;if(u===`connector`)return h;if(u===`org-membership-level`)return Mv;if(u===`node`){let e=Array.isArray(l.draft.nodes)?l.draft.nodes:[],t=typeof l.node?.id==`string`?l.node.id:void 0;return e.filter(e=>typeof e?.id==`string`&&e.id&&e.id!==t).map(e=>{let t=String(e.id);return{value:t,label:typeof e.label==`string`&&e.label?`${e.label} (${t})`:t}})}return g?_:[]},[u,g,f,m,h,_,l.draft,l.node]),y=u===`object-field`&&!d,b=u===`connector-action`&&!p;return(0,Y.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,Y.jsx)(B,{list:v.length?c:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:a,disabled:i,className:`h-8 text-sm`}),v.length>0&&(0,Y.jsx)(`datalist`,{id:c,children:v.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&y&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`}),s&&u===`connector-action`&&p&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Actions of `,p,`.`]}),s&&b&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Choose a Connector above to list its actions.`})]})}function Uv({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Nv(e.ref,e=>Pv(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(Hv,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function Wv(e){return e===`stringList`||e===`numberList`||e===`objectList`}function Gv(e,t){let n=[];return e.map(e=>{let r=Gi(`ol`,n);n.push(r);let i={};for(let n of t){let t=e[n.key];n.kind===`boolean`?i[n.key]=t===!0:Wv(n.kind)?i[n.key]=Array.isArray(t)?t:[]:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function Kv(e,t){let n=[];for(let r of e){let e={},i=!1;for(let n of t){let t=r.values[n.key];n.kind===`boolean`?t===!0&&(e[n.key]=!0,i=!0):Wv(n.kind)?Array.isArray(t)&&t.length>0&&(e[n.key]=t,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function qv({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u}){let d=X.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[f,p]=X.useState(()=>Gv(d,t)),m=X.useRef(JSON.stringify(d));X.useEffect(()=>{let e=JSON.stringify(d);e!==m.current&&(p(Gv(d,t)),m.current=e)},[d,t]);let h=e=>{let n=Kv(e,t);m.current=JSON.stringify(n),r(n.length?n:void 0)},g=(e,t,n)=>{p(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},_=(e,t,n)=>{p(r=>{let i=r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r);return h(i),i})},v=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:Wv(n.kind)?[]:``;p(t=>[...t,{id:Gi(`ol`,t.map(e=>e.id)),values:e}])},y=e=>{p(t=>{let n=t.filter(t=>t.id!==e);return h(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[f.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),f.map(e=>(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>y(e.id),disabled:i,"aria-label":o,title:o,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>{if(t.kind===`stringList`||t.kind===`numberList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,Y.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,Y.jsx)(Av,{label:t.label,value:t.kind===`numberList`?r.map(e=>String(e)):r,onCommit:n=>{if(t.kind===`numberList`){let r=(n??[]).map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));_(e.id,t.key,r)}else _(e.id,t.key,n??[])},disabled:i,addLabel:a,itemLabel:c??t.label,removeLabel:o,emptyLabel:s})},t.key)}if(t.kind===`objectList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,Y.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,Y.jsx)(qv,{label:t.label,columns:t.columns??[],value:r,onCommit:n=>_(e.id,t.key,n??[]),disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u})},t.key)}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(un,{checked:e.values[t.key]===!0,onCheckedChange:n=>_(e.id,t.key,n===!0),disabled:i}):t.kind===`reference`?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(Hv,{resolved:Nv(t.ref,t=>e.values[t]),value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>g(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>h(f),placeholder:t.placeholder,disabled:i,context:l,showHint:!1})}):t.kind===`select`?(()=>{let n=typeof e.values[t.key]==`string`?e.values[t.key]:``,r=t.options??[],a=n&&!r.some(e=>e.value===n)?[...r,{value:n,label:`${n} (deprecated)`}]:r;return(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(oe,{value:n||void 0,onValueChange:n=>_(e.id,t.key,n),disabled:i,children:[(0,Y.jsx)(fr,{className:`h-8 w-full text-xs`,children:(0,Y.jsx)(Dr,{placeholder:t.placeholder??`—`})}),(0,Y.jsx)(En,{children:a.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})})})():t.kind===`expression`?(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(vv,{mode:`expression`,mono:!0,value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onValueChange:n=>g(e.id,t.key,n),onBlur:()=>h(f),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:t.placeholder,disabled:i}),(0,Y.jsx)(yv,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,role:`predicate`,scopeGroups:u})]}):(0,Y.jsx)(B,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>g(e.id,t.key,n.target.value),onBlur:()=>h(f),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:t.placeholder,disabled:i,className:`h-8 flex-1 text-xs`})]},t.key)})})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:i,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function Jv({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a,scopeGroups:o}){let s=e.refMode??(e.kind===`expression`?`expression`:`template`),c=(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(Uv,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(Dv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.kv.add`,i),keyLabel:G(`engine.inspector.flowNode.kv.key`,i),valueLabel:G(`engine.inspector.flowNode.kv.value`,i),removeLabel:G(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:G(`engine.inspector.flowNode.kv.empty`,i),scopeGroups:o});case`stringList`:return(0,Y.jsx)(Av,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i)});case`numberList`:return(0,Y.jsx)(Av,{label:e.label,value:Array.isArray(t)?t.map(e=>String(e)):t,onCommit:e=>{if(e==null)return n(void 0);let t=e.map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));n(t.length?t:void 0)},disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Y.jsx)(qv,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),context:a,scopeGroups:o});case`number`:return(0,Y.jsx)(Ii,{label:e.label,value:typeof t==`number`?t:t!=null&&t!==``?Number(t):void 0,placeholder:e.placeholder,onCommit:e=>n(e),disabled:r});case`boolean`:return(0,Y.jsx)(J,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(K,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(vv,{multiline:!0,rows:4,mode:s,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]});default:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(vv,{mode:s,mono:e.kind===`expression`,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]})}})(),l=s===`template`,u=e.kind===`expression`&&!l?sm(`predicate`,t):null,d=e.kind===`expression`?l?`template`:`predicate`:s===`template`&&(e.kind===`text`||e.kind===`textarea`)?`template`:null,f=!u&&d&&o&&o.length>0?rm(t,d,em(o.flatMap(e=>e.refs))):[];return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[c,u&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:u.message}),!u&&f.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(f)}),e.help&&!u&&f.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}var Yv=[`variables`,`outputs`,`loop`,`trigger`],Xv={variables:`Flow variables`,outputs:`Upstream outputs`,loop:`Loop item`,trigger:`Trigger record`};function Zv(e,t,n){let r=X.useMemo(()=>Xp(e??{},t),[e,t]),{fields:i,loading:a}=Ki(r.trigger?.objectName);return X.useMemo(()=>{let e=[...r.refs];n&&n.length&&e.push(...n),r.trigger&&e.push(...Zp(r.trigger,i));let t=new Set,o=e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0));return{groups:Yv.map(e=>({id:e,label:Xv[e],refs:o.filter(t=>t.group===e)})).filter(e=>e.refs.length>0),refs:o,loading:!!r.trigger&&a,isEmpty:o.length===0}},[r,i,a,n])}function Qv(e){return e.kind===`objectList`&&zp(e)===`conditions`&&(e.columns??[]).some(e=>e.key===`target`)}function $v(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function ey(e,t,n){let[r,...i]=t,a={...e};if(i.length===0)n==null||n===``?delete a[r]:a[r]=n;else{let e=a[r],t=ey(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function ty({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=X.useMemo(()=>Bm(t,e),[t,e]),s=o?.node??null,c=Op(),l=X.useMemo(()=>o?.nested&&o.container?Jp(o.container).filter(e=>e.group===`loop`):[],[o]),{groups:u}=Zv(t,o?.scopeAnchorId,l),d=X.useMemo(()=>{let e=s?.type?c[s.type]:void 0;return(e===void 0?null:ev(e))??Lp(s?.type)},[c,s?.type]),f=$v(s),p=d.filter(e=>Bp(e,s,d)),m=X.useMemo(()=>{let e=Array.isArray(t.variables)?t.variables:[],n={};for(let t of e)t&&typeof t.name==`string`&&(n[t.name]=t.defaultValue);return n},[t]),h=X.useMemo(()=>{let e=new Set;for(let t of d){let n=zp(t);n&&e.add(n),t.fallbackPath&&t.fallbackPath.length>=2&&t.fallbackPath[0]===`config`&&e.add(t.fallbackPath[1])}return e},[d]),g=X.useMemo(()=>{let e=Object.fromEntries(Object.entries(f).filter(([e])=>!h.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[s,h]),[_,v]=X.useState(g),[y,b]=X.useState(null),[x,S]=X.useState(g.trim()!==``),[C,w]=X.useState(!1);if(X.useEffect(()=>{v(g),b(null),S(g.trim()!==``),w(!1)},[g]),!s){let t=(e.kind===`nested-node`?Mm(e.id):null)?.nodeId??e.id;return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:e.label??t,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),children:(0,Y.jsx)(Yi,{message:t})})}let T=e=>{let t=o?.write({...s,...e});t&&n(t)},E=g.trim()!==``,D=s.type===`screen`||s.type===`user_task`,O=(e,r)=>{if(!o)return;let i=e.path,a=r,c;if(!o.nested){let n=Array.isArray(t.edges)?t.edges:[];if(Qv(e)){let e=fv(s.id,r,n);a=e.conditions.length?e.conditions:void 0,c=e.edges}else s.type===`decision`&&i.length===2&&i[0]===`config`&&i[1]===`conditions`&&(c=uv(s.id,r,n))}let l=ey(s,i,a);e.fallbackPath&&(l=ey(l,e.fallbackPath,void 0));let u=o.write(l);u&&(c&&(u.edges=c),n(u))},k=()=>{try{let e=_.trim()===``?{}:JSON.parse(_);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(f).filter(([e])=>h.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!h.has(e))),i={...t,...r};b(null);let a={...s};Object.keys(i).length===0?delete a.config:a.config=i;let c=o?.write(a);c&&n(c)}catch(e){b(String(e.message))}},A=()=>{let e=o?.write(null);e&&n(e),r()},ee=Vp.includes(s.type)?[...Vp]:[...Vp,s.type??``].filter(Boolean),j=!!o?.nested;return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:s.label||s.id,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),footer:j?void 0:(0,Y.jsx)(xa,{label:G(`engine.inspector.flowNode.remove`,i),onClick:A,disabled:a}),children:[j&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-[11px] text-muted-foreground`,"aria-label":`nested node location`,children:[(0,Y.jsx)(`span`,{className:`max-w-[45%] truncate font-medium`,children:o?.container?.label||o?.container?.id}),(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,Y.jsx)(`span`,{className:`truncate`,children:o?.regionLabel}),(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,Y.jsx)(`span`,{className:`max-w-[45%] truncate font-medium text-foreground`,children:s.label||s.id})]}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.id`,i),value:s.id,onCommit:e=>T({id:e}),disabled:a||j,mono:!0}),j&&(0,Y.jsx)(`p`,{className:`-mt-1 text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowNode.nestedIdHint`,i)}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.label`,i),value:s.label??``,onCommit:e=>T({label:e}),disabled:a}),(0,Y.jsx)(K,{label:G(`engine.inspector.flowNode.type`,i),value:s.type,options:ee.map(e=>({value:e,label:e})),onCommit:e=>T({type:e}),disabled:a}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.description`,i),value:s.description??``,onCommit:e=>T({description:e||void 0}),disabled:a}),d.length===0?(0,Y.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:G(`engine.inspector.flowNode.noConfig`,i)}):p.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowNode.configuration`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.map(e=>{let n=Qv(e),r=j&&n?{...e,columns:(e.columns??[]).filter(e=>e.key!==`target`)}:e;return(0,Y.jsx)(Jv,{field:r,value:n&&!j?dv(s.id,Rp(s,e),Array.isArray(t.edges)?t.edges:[]):Rp(s,r),onCommit:t=>O(e,t),disabled:a,locale:i,context:{draft:t,node:s},scopeGroups:u},e.id)}),D&&(0,Y.jsx)(eh,{node:s,variables:m,className:`mt-1`}),E||C?(0,Y.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:x,onToggle:e=>S(e.target.open),children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:G(`engine.inspector.flowNode.advanced`,i)}),(0,Y.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowNode.advancedHint`,i)}),(0,Y.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),onBlur:k,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),y&&(0,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:y})]})]}):!a&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{w(!0),S(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`engine.inspector.flowNode.advanced`,i)]})]})}function ny({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`div`,{className:`flex h-8 items-center rounded border bg-muted/30 px-2 font-mono text-sm text-muted-foreground`,children:t})]})}function ry({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.edges)?t.edges:[],s=o.findIndex((t,n)=>ip(t,n)===e.id),c=s>=0?o[s]:null,{groups:l}=Zv(t,c?.source);if(!c)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),children:(0,Y.jsx)(Yi,{message:G(`engine.inspector.flowEdge.missing`,i)})});let u=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}(t.type==="default"||t.type===``||t.type===void 0)&&delete t.type,n({edges:la(o,s,t)})},d=c.isDefault===!0,f=(Array.isArray(t.nodes)?t.nodes:[]).find(e=>e.id===c.source),p=f?.type===`decision`&&Array.isArray(f.config?.conditions)?f.config.conditions:[],m=e=>typeof e.expression==`string`?e.expression.trim():``,h=e=>typeof e.label==`string`?e.label.trim():``,g=(()=>{if(!p.length)return``;if(d){let e=p.findIndex(e=>{let t=m(e);return t===``||t===`true`});return e>=0?String(e):``}let e=ap(c.condition),t=e?p.findIndex(t=>m(t)===e):-1;return t<0&&c.label&&(t=p.findIndex(e=>h(e)===c.label)),t>=0?String(t):``})(),_=e=>{if(e===``)return;let t=p[Number(e)];if(!t)return;let n=m(t),r=h(t)||void 0;u(n===``||n===`true`?{isDefault:!0,condition:void 0,label:r}:{isDefault:!1,condition:n,label:r})},v=f?.type===`approval`,y=[`approve`,`reject`,`revise`],b=(()=>{let e=(c.label??``).trim().toLowerCase();return y.includes(e)?e:``})(),x=typeof c.type==`string`&&c.type||`default`;return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:la(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(ny,{label:G(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(ny,{label:G(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowEdge.routing`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.length>0&&(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.branch`,i),value:g,options:[...p.map((e,t)=>{let n=m(e),r=h(e)||`Branch ${t+1}`,i=n===``||n===`true`?` · default`:` \u00b7 ${n}`;return{value:String(t),label:`${r}${i}`}}),{value:``,label:`— Custom —`}],onCommit:_,disabled:a}),v&&(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.approvalBranch`,i),value:b,options:[{value:`approve`,label:G(`engine.inspector.flowEdge.branchApprove`,i)},{value:`reject`,label:G(`engine.inspector.flowEdge.branchReject`,i)},{value:`revise`,label:G(`engine.inspector.flowEdge.branchRevise`,i)},{value:``,label:G(`engine.inspector.flowEdge.branchCustom`,i)}],onCommit:e=>{e&&u({label:e})},disabled:a}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>u({label:e}),placeholder:G(`engine.inspector.flowEdge.labelHint`,i),disabled:a||d}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:G(`engine.inspector.flowEdge.condition`,i)}),(0,Y.jsx)(vv,{mode:`expression`,mono:!0,value:ap(c.condition)??``,onValueChange:e=>u({condition:e||void 0}),groups:l,placeholder:G(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||d})]}),(()=>{let e=d?null:sm(`predicate`,c.condition);if(e)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message});let t=d?[]:rm(ap(c.condition),`predicate`,em(l.flatMap(e=>e.refs)));return t.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(t)}):null})(),(0,Y.jsx)(J,{label:G(`engine.inspector.flowEdge.isDefault`,i),value:d,onCommit:e=>u(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowEdge.hint`,i)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowEdge.connection`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.type`,i),value:x,options:[{value:`default`,label:G(`engine.inspector.flowEdge.typeDefault`,i)},{value:`conditional`,label:G(`engine.inspector.flowEdge.typeConditional`,i)},{value:`fault`,label:G(`engine.inspector.flowEdge.typeFault`,i)},{value:`back`,label:G(`engine.inspector.flowEdge.typeBack`,i)}],onCommit:e=>u({type:e}),disabled:a}),c.type===`back`&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:G(`engine.inspector.flowEdge.backHint`,i)})]})}function iy(e){return e.selection.kind===`edge`?(0,Y.jsx)(ry,{...e}):(0,Y.jsx)(ty,{...e})}var ay=[`field`,`label`,`accessorKey`,`header`];function oy(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function sy(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function cy(e){return e.field??e.accessorKey??``}function ly(e){return e.label??e.header??cy(e)}function uy(e){return Object.keys(e).some(e=>!ay.includes(e))}function dy(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function fy({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=oy(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(sy),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=X.useMemo(()=>es(),[]),m=dy(c),{fields:h}=Ki(m||void 0),g=d?cy(d):``,_=X.useMemo(()=>{let e=h.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} · ${e.name}`:e.name}));return g&&!e.some(e=>e.value===g)&&e.unshift({value:g,label:`${g} (not in object)`}),e},[h,g]);if(!s||!d)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),children:(0,Y.jsx)(Yi,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=cy(e);return n&&!uy(e)&&!e.label&&!e.header&&r?r:e});n({[s.variant]:{...c,columns:t}})},y=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),v(la(u,s.index,{...d,...r}))};return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:ly(d)||e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(Xi,{index:s.index,total:u.length,onMove:e=>{v(Pi(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:ly(d)||`columns[${e}]`})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(la(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(Lo,{variantKey:s.variant,schema:c,columns:l,allStrings:l.length>0&&l.every(e=>typeof e==`string`),objectName:m||void 0,selectedIndex:s.index,readOnly:o,onPatch:n,onSelectionChange:i})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,Y.jsx)(K,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:cy(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(q,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:cy(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.viewColumn.header`,a),value:ly(d)===cy(d)?``:ly(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(ha,{schema:p,value:d,hiddenFields:ay,readOnly:o,onChange:e=>{v(la(u,s.index,e))}})}):null]})]})}function py(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(fy,{...e});let n=ls(e.draft,t.id||void 0)??cs(e.draft);return(0,Y.jsx)(_s,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function my(e){let t=cs(e.draft);return(0,Y.jsx)(_s,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var hy={io:`input`,unrepresentable:`any`},gy=new Set([`name`,`regions`,`children`]),_y,vy=!1;function yy(){if(_y||vy)return _y;try{_y=E(ne,hy)}catch(e){vy=!0,typeof console<`u`&&console.warn(`[page-schema] failed to derive Page JSONSchema from spec`,e)}return _y}var by;function xy(){if(by)return by;if(!(!w||typeof w!=`object`)){try{let e=JSON.parse(JSON.stringify(w));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!gy.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),by=e}catch(e){typeof console<`u`&&console.warn(`[page-schema] failed to prune Page authoring form from spec`,e),by=w}return by}}function Sy({draft:e,onPatch:t,readOnly:n,serverSchema:r,locale:i}){let{schema:a,form:o}=X.useMemo(()=>ta({bundledSchema:yy(),bundledForm:xy(),serverSchema:r,excludeFields:gy,sectionTitle:G(`engine.inspector.moreFields`,i)}),[r,i]);return a?(0,Y.jsx)(ha,{schema:a,form:o,value:e,hiddenFields:[...gy],readOnly:n,onChange:e=>t(e)}):(0,Y.jsx)(`p`,{className:`px-1 py-2 text-xs text-muted-foreground`,children:G(`engine.studio.inspector.noPageSchema`,i)})}var Cy=e=>(e??``).toLowerCase().startsWith(`zh`);function wy(e){let t=e.options;return Array.isArray(t)?t.map(e=>({value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0})):[]}function Ty(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Ey(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Dy(e){return e===`formula`||e===`summary`}function Oy(e){return e===`number`||e===`currency`||e===`percent`}function ky(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Ay(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}var jy=[`record`,`previous`,`parent`],My=[`record`];function Ny(e){return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:``}function Py(e,t){if(t.trim()){if(e&&typeof e==`object`&&!Array.isArray(e)){let n=e;return{...n,dialect:typeof n.dialect==`string`?n.dialect:`cel`,source:t}}return t}}function Fy(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?da:ra;return aa.flatMap(e=>e.types.map(r=>{let i=ia[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function Iy({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=X.useCallback(e=>G(e,o),[o]),c=X.useMemo(()=>Fy(o),[o]),l=X.useMemo(()=>Qi(t.fields),[t]),u=String(e.id),d=Ji(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=nb(),h=X.useRef(!1);if(X.useEffect(()=>{h.current=!1},[u]),!f)return(0,Y.jsx)(Li,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Y.jsx)(Yi,{message:s(`designer.field.missing`)})});let g=f.def,_=typeof g.type==`string`?g.type:`text`,v=ia[_],y=e=>{n({fields:Hi(e)})},b=e=>{let t=[...l.entries];t[d]={...f,def:{...g,...e}},y({shape:l.shape,entries:t})},x=e=>{let t=Ui(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},y({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(g.label??t)})},S=e=>{if(a)return null;let t=_===`select`?`status`:_;if(!(f.name===t||f.name.startsWith(`${t}_`)&&/^\d+$/.test(f.name.slice(t.length+1))||/^field_\d+$/.test(f.name)))return null;let n=Ui(e);return!n||n===f.name||l.entries.some((e,t)=>t!==d&&e.name===n)?null:n},C=()=>{let e=l.entries.filter((e,t)=>t!==d);y({shape:l.shape,entries:e}),r()},w=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof g.label==`string`&&g.label?g.label:``,o={name:n,def:{...g,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),y({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},T=e=>{let t={shape:l.shape,entries:Pi(l.entries,d,e)};y(t)},E=wy(g),D=e=>{let t=e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t});b({options:t})},O=(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:w,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,Y.jsx)(Pn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Xi,{index:d,total:l.entries.length,onMove:T,disabled:a})]}),k=(0,Y.jsx)(xa,{label:W(`designer.field.remove`,o,{label:typeof g.label==`string`?g.label:f.name}),onClick:C,disabled:a}),A=Cy(o)?v?.labelZh:v?.label;return(0,Y.jsxs)(Li,{kindLabel:s(`designer.field.kind`),title:typeof g.label==`string`&&g.label?g.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:O,footer:k,children:[(0,Y.jsxs)(Ly,{title:s(`designer.field.section.basic`),children:[(0,Y.jsx)(q,{label:s(`designer.field.apiName`),value:f.name,onCommit:x,disabled:a,mono:!0,testId:`field-apiname-input`}),(0,Y.jsx)(q,{label:s(`designer.field.label`),value:typeof g.label==`string`?g.label:``,onCommit:e=>{let t=S(e),n=[...l.entries];n[d]={...f,name:t??f.name,def:{...g,label:e}},y({shape:l.shape,entries:n}),t&&i?.({kind:`field`,id:t,label:e})},disabled:a,testId:`field-label-input`}),(0,Y.jsx)(K,{label:s(`designer.field.type`),value:_,options:c,onCommit:e=>b({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(J,{label:s(`designer.field.required`),value:!!g.required,onCommit:e=>b({required:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.unique`),value:!!g.unique,onCommit:e=>b({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(zy,{label:s(`designer.field.description`),value:typeof g.description==`string`?g.description:``,onCommit:e=>b({description:e||void 0}),disabled:a,rows:2}),Ay(_)&&(0,Y.jsx)(Ry,{kind:Ay(_),value:g.defaultValue,options:E,onCommit:e=>b({defaultValue:e}),disabled:a,locale:o}),(0,Y.jsx)(zy,{label:s(`designer.field.helpText`),value:typeof g.inlineHelpText==`string`?g.inlineHelpText:``,onCommit:e=>b({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(Ty(_)||Ey(_)||Dy(_)||Oy(_)||ky(_))&&(0,Y.jsxs)(Ly,{title:W(`designer.field.section.options`,o,{type:A??_}),children:[Ty(_)&&(0,Y.jsx)(Vy,{options:E,onChange:D,disabled:a,locale:o},f.name),Ey(_)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(By,{label:s(`designer.field.relatedObject`),value:typeof g.reference==`string`?g.reference:``,options:m,onCommit:e=>b({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(q,{label:s(`designer.field.relationshipName`),value:typeof g.relationshipName==`string`?g.relationshipName:``,onCommit:e=>b({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)}),(0,Y.jsx)(Gy,{def:g,patchDef:b,hostFieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),readOnly:a,locale:o})]}),_===`formula`&&(0,Y.jsx)(ea,{id:`field-formula-${f.name}`,label:s(`designer.field.formula`),value:Ny(g.expression??g.formula),onChange:e=>{h.current=!0,b({expression:Py(g.expression??g.formula,e),formula:void 0,...e.trim()?{}:{returnType:void 0}})},onInferredTypeChange:e=>{if(!h.current)return;let t=e&&e!==`unknown`?e:void 0;g.returnType!==t&&b({returnType:t})},disabled:a,placeholder:`record.amount * 0.2`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),scope:`record`,roots:My,role:`value`,t:s}),_===`summary`&&(0,Y.jsx)(tb,{def:g,patchDef:b,objectOptions:m,readOnly:a,locale:o}),Oy(_)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(Ii,{label:s(`designer.field.precision`),value:typeof g.precision==`number`?g.precision:void 0,onCommit:e=>b({precision:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.scale`),value:typeof g.scale==`number`?g.scale:void 0,onCommit:e=>b({scale:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.min`),value:typeof g.min==`number`?g.min:void 0,onCommit:e=>b({min:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.max`),value:typeof g.max==`number`?g.max:void 0,onCommit:e=>b({max:e}),disabled:a})]}),ky(_)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(Ii,{label:s(`designer.field.minLength`),value:typeof g.minLength==`number`?g.minLength:void 0,onCommit:e=>b({minLength:e}),disabled:a,placeholder:`0`}),(0,Y.jsx)(Ii,{label:s(`designer.field.maxLength`),value:typeof g.maxLength==`number`?g.maxLength:void 0,onCommit:e=>b({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,Y.jsxs)(Ly,{title:s(`designer.field.section.advanced`),children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(J,{label:s(`designer.field.readonly`),value:!!g.readonly,onCommit:e=>b({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.hidden`),value:!!g.hidden,onCommit:e=>b({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.indexed`),value:!!g.indexed,onCommit:e=>b({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.externalId`),value:!!g.externalId,onCommit:e=>b({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.trackHistory`),value:!!g.trackHistory,onCommit:e=>b({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(q,{label:s(`designer.field.placeholder`),value:typeof g.placeholder==`string`?g.placeholder:``,onCommit:e=>b({placeholder:e||void 0}),disabled:a}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:s(`designer.field.conditionalRules`)}),(0,Y.jsx)(ea,{id:`field-rule-visible-${f.name}`,label:s(`designer.field.visibleWhen`),value:Ny(g.visibleWhen),onChange:e=>b({visibleWhen:Py(g.visibleWhen,e)}),disabled:a,placeholder:`record.status != 'draft'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(ea,{id:`field-rule-readonly-${f.name}`,label:s(`designer.field.readonlyWhen`),value:Ny(g.readonlyWhen),onChange:e=>b({readonlyWhen:Py(g.readonlyWhen,e)}),disabled:a,placeholder:`record.status == 'closed'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(ea,{id:`field-rule-required-${f.name}`,label:s(`designer.field.requiredWhen`),value:Ny(g.requiredWhen??g.conditionalRequired),onChange:e=>b({requiredWhen:Py(g.requiredWhen??g.conditionalRequired,e),conditionalRequired:void 0}),disabled:a,placeholder:`record.amount > 10000`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRulesHint`)})]}),p.length>0&&(0,Y.jsx)(K,{label:s(`designer.field.group`),value:typeof g.group==`string`?g.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>b({group:e||void 0}),disabled:a})]})]})}function Ly({title:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:t})]})}function Ry({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=G(`designer.field.defaultValue`,a),s=G(`designer.field.defaultNone`,a);return e===`bool`?(0,Y.jsx)(K,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:G(`designer.field.true`,a)},{value:`false`,label:G(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Y.jsx)(Ii,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Y.jsx)(K,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,Y.jsx)(q,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function zy({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:t,disabled:r,rows:i,placeholder:o,onChange:e=>n(e.target.value),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary `+(a?`font-mono text-xs `:``)})]})}function By({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=X.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(B,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,Y.jsx)(`datalist`,{id:o,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Vy({options:e,onChange:t,disabled:n,locale:r}){let[i,a]=X.useState(()=>e.length>0?e:[{value:``,label:``}]),o=e=>{a(e),t(e.filter(e=>e.value.trim()!==``))},s=(e,t)=>{let n=[...i];n[e]={...n[e],...t},o(n)},c=e=>o(i.filter((t,n)=>n!==e)),l=(e,t)=>o(Pi(i,e,t));return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:G(`designer.field.picklistValues`,r)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:i.length})]}),i.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:G(`designer.field.noValues`,r)}):(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:i.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/60 p-1.5 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(B,{value:e.value,onChange:e=>s(t,{value:e.target.value}),placeholder:G(`designer.field.optValue`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs font-mono`}),(0,Y.jsx)(B,{value:e.label??``,onChange:e=>s(t,{label:e.target.value}),placeholder:G(`designer.field.optLabel`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`color`,value:e.color??`#cccccc`,onChange:e=>s(t,{color:e.target.value}),disabled:n,className:`h-6 w-6 rounded border bg-background cursor-pointer p-0.5`,title:G(`designer.field.optColor`,r)}),(0,Y.jsx)(`span`,{className:`flex-1`}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t-1),disabled:n||t===0,"aria-label":G(`designer.field.moveUp`,r),children:(0,Y.jsx)(Qr,{className:`h-3 w-3`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t+1),disabled:n||t===i.length-1,"aria-label":G(`designer.field.moveDown`,r),children:(0,Y.jsx)(pe,{className:`h-3 w-3`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,onClick:()=>c(t),disabled:n,"aria-label":G(`designer.field.removeValue`,r),children:(0,Y.jsx)(Se,{className:`h-3 w-3`})})]})]},t))}),!n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>o([...i,{value:``,label:``}]),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`designer.field.addValue`,r)]})]})}var Hy=[{value:`eq`,label:`= equals`},{value:`ne`,label:`≠ not equals`},{value:`gt`,label:`> greater than`},{value:`lt`,label:`< less than`},{value:`gte`,label:`≥ at least`},{value:`lte`,label:`≤ at most`},{value:`contains`,label:`contains`},{value:`in`,label:`in (any of)`},{value:`notIn`,label:`not in`}];function Uy(e){let t=e.lookupFilters??e.lookup_filters;return Array.isArray(t)?t:[]}function Wy(e){let t=e.dependsOn??e.depends_on;return Array.isArray(t)?t.map(e=>typeof e==`string`?e:e&&typeof e==`object`?e.field:void 0).filter(e=>!!e):[]}function Gy({def:e,patchDef:t,hostFieldNames:n,readOnly:r,locale:i}){let a=e=>G(e,i),o=typeof e.reference==`string`?e.reference:void 0,{fields:s,loading:c}=Ki(o),l=X.useMemo(()=>s.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[s]),u=X.useMemo(()=>n.map(e=>({value:e,label:e})),[n]),d=Uy(e),f=Wy(e),p=(e,n)=>t({lookupFilters:d.map((t,r)=>r===e?{...t,...n}:t)}),m=()=>t({lookupFilters:[...d,{field:``,operator:`eq`,value:``}]}),h=e=>{let n=d.filter((t,n)=>n!==e);t({lookupFilters:n.length?n:void 0})},g=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e),_=(e,t)=>e===`in`||e===`notIn`?t.split(`,`).map(e=>e.trim()).filter(Boolean):t,v=e=>{!e||f.includes(e)||t({dependsOn:[...f,e]})},y=e=>{let n=f.filter(t=>t!==e);t({dependsOn:n.length?n:void 0})},b=typeof e.displayField==`string`?e.displayField:``,x=typeof e.descriptionField==`string`?e.descriptionField:``,S=typeof e.lookupPageSize==`number`?e.lookupPageSize:void 0,C=e.allowCreate===!0,w=a(o?`designer.field.lookup.selectField`:`designer.field.lookup.setTargetFirst`);return(0,Y.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:a(`designer.field.lookup.pickerConfig`)}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.displayField`),value:b,onCommit:e=>t({displayField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.descriptionField`),value:x,onCommit:e=>t({descriptionField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.selectableRecords`)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),!r&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,a(`designer.field.lookup.addFilter`)]})]}),d.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.noFilter`,i,{ref:o||`related`})}):d.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":a(`designer.field.lookup.removeFilter`),className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>h(t),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>p(t,{field:e}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(K,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:Hy,onCommit:e=>p(t,{operator:e}),disabled:r}),(0,Y.jsx)(q,{label:a(`designer.field.lookup.filterValue`),value:g(e.value),onCommit:n=>p(t,{value:_(e.operator,n)}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t))]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.dependsOn`)}),f.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:f.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-0.5 text-[11px] font-mono`,children:[e,!r&&(0,Y.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>y(e),"aria-label":`Remove ${e}`,children:`×`})]},e))}),!r&&u.length>0&&(0,Y.jsx)(Ua,{value:``,onCommit:e=>v(e),options:u.filter(e=>!f.includes(e.value)),placeholder:a(`designer.field.lookup.addDependsOn`),searchPlaceholder:a(`designer.field.lookup.searchHostFields`),disabled:r,allowCustom:!1,mono:!0})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:[(0,Y.jsx)(Ii,{label:a(`designer.field.lookup.pageSize`),value:S,onCommit:e=>t({lookupPageSize:e}),placeholder:`10`,disabled:r}),(0,Y.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,Y.jsx)(J,{label:a(`designer.field.lookup.allowCreate`),value:C,onCommit:e=>t({allowCreate:e||void 0}),disabled:r})})]})]})}var Ky=[`count`,`sum`,`min`,`max`,`avg`];function qy(e){let t=e.summaryOperations;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}var Jy={ne:`$ne`,gt:`$gt`,lt:`$lt`,gte:`$gte`,lte:`$lte`,contains:`$contains`,in:`$in`,notIn:`$nin`},Yy={$eq:`eq`,$ne:`ne`,$gt:`gt`,$lt:`lt`,$gte:`gte`,$lte:`lte`,$contains:`contains`,$in:`in`,$nin:`notIn`},Xy=new Set([`number`,`currency`,`percent`,`rating`,`slider`,`autonumber`]);function Zy(e,t,n){let r=e=>{if(typeof e!=`string`)return e;let n=e.trim();if(t===`boolean`||t===`toggle`)return n===`true`||n===`1`;if(t&&Xy.has(t)){let t=Number(n);return n!==``&&Number.isFinite(t)?t:e}return e};return n?(Array.isArray(e)?e:String(e??``).split(`,`).map(e=>e.trim()).filter(Boolean)).map(r):r(e)}function Qy(e){if(!e||typeof e!=`object`||Array.isArray(e))return{rows:[],advanced:!1};let t=[],n=!1,r=e=>{for(let[i,a]of Object.entries(e)){if(i===`$and`&&Array.isArray(a)){for(let e of a)e&&typeof e==`object`&&!Array.isArray(e)?r(e):n=!0;continue}if(i.startsWith(`$`)){n=!0;continue}if(typeof a==`object`&&a&&!Array.isArray(a)){let e=Object.entries(a);if(e.length===0){n=!0;continue}for(let[r,a]of e){let e=Yy[r];e?t.push({field:i,operator:e,value:a}):n=!0}}else t.push({field:i,operator:`eq`,value:a})}};return r(e),{rows:t,advanced:n}}function $y(e,t){let n=e.filter(e=>e.field);if(n.length===0)return;let r=n.map(e=>{let n=e.operator===`in`||e.operator===`notIn`,r=Zy(e.value,t(e.field),n);return e.operator===`eq`?{[e.field]:r}:{[e.field]:{[Jy[e.operator]??`$eq`]:r}}});if(r.length===1)return r[0];let i=r.map(e=>Object.keys(e)[0]);return new Set(i).size===i.length?Object.assign({},...r):{$and:r}}var eb=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e);function tb({def:e,patchDef:t,objectOptions:n,readOnly:r,locale:i}){let a=e=>G(e,i),o=qy(e),s=typeof o.object==`string`?o.object:``,c=typeof o.function==`string`?o.function:``,{fields:l,loading:u}=Ki(s||void 0),d=e=>{let n={...o,...e};for(let e of Object.keys(n))(n[e]===void 0||n[e]===``)&&delete n[e];t({summaryOperations:Object.keys(n).length>0?n:void 0})},f=X.useMemo(()=>l.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),p=X.useMemo(()=>l.filter(e=>e.type===`lookup`||e.type===`master_detail`).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),m=a(s?`designer.field.lookup.selectField`:`designer.field.summary.setObjectFirst`),h=X.useCallback(e=>l.find(t=>t.name===e)?.type,[l]),{rows:g,advanced:_}=Qy(o.filter),v=e=>d({filter:$y(e,h)}),y=(e,t)=>v(g.map((n,r)=>r===e?{...n,...t}:n)),b=()=>v([...g,{field:f[0]?.value??``,operator:`eq`,value:``}]),x=e=>v(g.filter((t,n)=>n!==e));return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(By,{label:a(`designer.field.summary.object`),value:s,options:n,onCommit:e=>d({object:e||void 0}),disabled:r,placeholder:a(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(K,{label:a(`designer.field.summary.function`),value:c,options:[{value:``,label:a(`designer.field.defaultNone`)},...Ky.map(e=>({value:e,label:a(`designer.field.summary.fn.${e}`)}))],onCommit:e=>d({function:e||void 0}),disabled:r}),(0,Y.jsx)(Ua,{label:a(`designer.field.summary.field`),value:typeof o.field==`string`?o.field:``,onCommit:e=>d({field:e||void 0}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),c===`count`&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 px-0.5 -mt-1`,children:a(`designer.field.summary.countFieldHint`)}),(0,Y.jsx)(Ua,{label:a(`designer.field.summary.relationshipField`),value:typeof o.relationshipField==`string`?o.relationshipField:``,onCommit:e=>d({relationshipField:e||void 0}),options:p,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 border-t pt-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.summary.filterSection`)}),!_&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:g.length})]}),!r&&!_&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:b,disabled:f.length===0,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,a(`designer.field.summary.addFilter`)]})]}),_?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-[11px] text-muted-foreground`,children:a(`designer.field.summary.filterAdvanced`)}):g.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:a(`designer.field.summary.noFilter`)}):g.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":a(`designer.field.lookup.removeFilter`),className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>x(t),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>y(t,{field:e}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(K,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:Hy,onCommit:e=>y(t,{operator:e}),disabled:r}),(0,Y.jsx)(q,{label:a(`designer.field.lookup.filterValue`),value:eb(e.value),onCommit:e=>y(t,{value:e}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t)),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.filterHint`)})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.hint`)})]})}function nb(){let e=Ai(),[t,n]=X.useState([]);return X.useEffect(()=>{let t=!1;return Promise.all([e.list(`object`),e.listDrafts({type:`object`}).catch(()=>[])]).then(([e,r])=>{if(t)return;let i=new Map;for(let t of e??[])typeof t?.name==`string`&&t.name&&!i.has(t.name)&&i.set(t.name,{value:t.name,label:t.label?`${t.label} (${t.name})`:t.name});for(let e of r??[]){let t=e.name;typeof t==`string`&&t&&!i.has(t)&&i.set(t,{value:t,label:`${t} (草稿)`})}n([...i.values()].sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{t=!0}},[e]),t}function rb({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=X.useCallback(e=>G(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=X.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=ki(e)),n(t)},u=e=>{c.current=!0,n({name:Ui(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Y.jsxs)(Li,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:[(0,Y.jsxs)(lb,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Y.jsx)(ub,{hint:a(`designer.object.nameHint`),children:(0,Y.jsx)(q,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,testId:`object-name-input`,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Y.jsx)(q,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Y.jsx)(q,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,Y.jsx)(ub,{hint:a(`designer.object.iconHint`),children:(0,Y.jsx)(q,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,Y.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]}),(0,Y.jsx)(cb,{draft:t,onPatch:n,readOnly:r,tr:a})]})}var ib=[`read`,`create`,`update`,`delete`];function ab(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function ob(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).join(`, `):``}function sb(){let[e,t]=X.useState(!1);return X.useEffect(()=>{let e=!1;return a(()=>import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f).then(n=>{e||t(n?.ObjectRequiredPermissionsSchema!==void 0)}),[],import.meta.url).catch(()=>{}),()=>{e=!0}},[]),e}function cb({draft:e,onPatch:t,readOnly:n,tr:r}){let i=sb(),a=e.access?.default===`private`?`private`:`public`,o=e.requiredPermissions,s=!!o&&typeof o==`object`&&!Array.isArray(o),c=s?`perOp`:`all`,l=e=>{t({access:e===`private`?{default:`private`}:void 0})},u=e=>{let n=ab(e);t({requiredPermissions:n.length>0?n:void 0})},d=(e,n)=>{let r=s?{...o}:{},i=ab(n);i.length>0?r[e]=i:delete r[e],t({requiredPermissions:Object.keys(r).length>0?r:void 0})},f=e=>{if(e!==c)if(e===`perOp`){let e=Array.isArray(o)?o:[];t({requiredPermissions:e.length>0?{read:e,create:e,update:e,delete:e}:{}})}else{let e=s?o:{},n=[...new Set(ib.flatMap(t=>Array.isArray(e[t])?e[t]:[]))];t({requiredPermissions:n.length>0?n:void 0})}};return(0,Y.jsxs)(lb,{title:r(`designer.object.section.access`),hint:r(`designer.object.section.accessHint`),children:[(0,Y.jsx)(ub,{hint:r(a===`private`?`designer.object.posture.privateHint`:`designer.object.posture.publicHint`),children:(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:r(`designer.object.posture`)}),(0,Y.jsxs)(`select`,{value:a,disabled:n,onChange:e=>l(e.target.value),"data-testid":`object-access-posture`,className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Y.jsx)(`option`,{value:`public`,children:r(`designer.object.posture.public`)}),(0,Y.jsx)(`option`,{value:`private`,children:r(`designer.object.posture.private`)})]})]})}),(0,Y.jsx)(ub,{hint:r(`designer.object.reqPerms.hint`),children:(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:r(`designer.object.reqPerms`)}),i&&(0,Y.jsxs)(`div`,{className:`inline-flex rounded border text-[11px]`,role:`group`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`all`),className:`px-1.5 py-0.5 rounded-l ${c===`all`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.all`)}),(0,Y.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`perOp`),"data-testid":`object-reqperms-perop`,className:`px-1.5 py-0.5 rounded-r border-l ${c===`perOp`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.perOp`)})]})]}),c===`all`?(0,Y.jsx)(q,{label:``,value:ob(o),onCommit:u,disabled:n,mono:!0,testId:`object-reqperms-all`,placeholder:r(`designer.object.reqPerms.placeholder`)}):(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ib.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-14 shrink-0 text-[11px] text-muted-foreground capitalize`,children:r(`designer.object.reqPerms.op.${e}`)}),(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(q,{label:``,value:ob(o?.[e]),onCommit:t=>d(e,t),disabled:n,mono:!0,testId:`object-reqperms-${e}`,placeholder:r(`designer.object.reqPerms.placeholder`)})})]},e))})]})})]})}function lb({title:e,hint:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:n})]})}function ub({hint:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var db={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,after:`$gt`,before:`$lt`,contains:`$contains`,in:`$in`,notIn:`$nin`},fb={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$contains:`contains`,$in:`in`,$nin:`notIn`};function pb(e){let t=(e?.conditions??[]).filter(e=>e&&e.field),n=[];for(let e of t){if(e.operator===`isEmpty`){n.push({[e.field]:{$exists:!1}});continue}if(e.operator===`isNotEmpty`){n.push({[e.field]:{$exists:!0}});continue}let t=db[e.operator];if(!t)continue;let r=e.value;r==null||r===``||Array.isArray(r)&&r.length===0||n.push({[e.field]:{[t]:r}})}if(n.length!==0)return n.length===1?n[0]:{$and:n}}function mb(e){let t={id:`g`,logic:`and`,conditions:[]};if(e==null)return{group:t,representable:!0};if(typeof e!=`object`||Array.isArray(e)||`$or`in e)return{group:t,representable:!1};let n=Array.isArray(e.$and)?e.$and:[e],r=[];for(let e=0;e<n.length;e++){let i=n[e];if(!i||typeof i!=`object`||Array.isArray(i)||`$and`in i||`$or`in i)return{group:t,representable:!1};let a=Object.keys(i);if(a.length!==1)return{group:t,representable:!1};let o=a[0],s=i[o];if(s&&typeof s==`object`&&!Array.isArray(s)){let n=Object.keys(s);if(n.length!==1)return{group:t,representable:!1};let i=n[0];if(i===`$exists`)r.push({id:`c${e}`,field:o,operator:s.$exists?`isNotEmpty`:`isEmpty`,value:``});else{let n=fb[i];if(!n)return{group:t,representable:!1};r.push({id:`c${e}`,field:o,operator:n,value:s[i]})}}else r.push({id:`c${e}`,field:o,operator:`equals`,value:s})}return{group:{id:`g`,logic:`and`,conditions:r},representable:!0}}var hb=[{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`},{value:`count_distinct`,label:`count distinct`}],gb=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}],_b=[{value:``,label:`— none —`},{value:`day`,label:`day`},{value:`week`,label:`week`},{value:`month`,label:`month`},{value:`quarter`,label:`quarter`},{value:`year`,label:`year`}],vb=[{value:`ratio`,label:`ratio (a ÷ b)`},{value:`sum`,label:`sum (a + b)`},{value:`difference`,label:`difference (a − b)`},{value:`product`,label:`product (a × b)`}],yb=[{value:`raw`,label:`Raw number`},{value:`number`,label:`Number — 1,234.5`},{value:`currency`,label:`Currency — $1,234.50`},{value:`percent`,label:`Percent — 12.3%`}],bb=[{value:`0`,label:`0`},{value:`1`,label:`1`},{value:`2`,label:`2`}],xb=[{value:`USD`,label:`USD ($)`},{value:`EUR`,label:`EUR (€)`},{value:`GBP`,label:`GBP (£)`},{value:`CNY`,label:`CNY (¥)`},{value:`JPY`,label:`JPY (¥)`},{value:`INR`,label:`INR (₹)`},{value:`CAD`,label:`CAD ($)`},{value:`AUD`,label:`AUD ($)`}];function Sb({title:e,count:t,onAdd:n,addLabel:r}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,r]})]})}function Cb({children:e}){return(0,Y.jsxs)(`details`,{className:`group`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-[11px] text-muted-foreground hover:text-foreground`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(qr,{className:`h-3 w-3 transition-transform group-open:rotate-90`}),`Advanced`]})}),(0,Y.jsx)(`div`,{className:`mt-1.5 space-y-1.5 border-l pl-2.5`,children:e})]})}function wb(e,t){let n=(e??``).trim(),r=n.match(/\.(0+)/),i=r?Math.min(r[1].length,2):0;return t||/[$£€¥₹]/.test(n)?{kind:`currency`,decimals:i}:n.includes(`%`)?{kind:`percent`,decimals:i}:n?{kind:`number`,decimals:i}:{kind:`raw`,decimals:0}}function Tb(e,t,n){let r=t>0?`.`+`0`.repeat(t):``;switch(e){case`number`:return{format:`0,0${r}`,currency:void 0};case`currency`:return{format:`0,0${r}`,currency:n||`USD`};case`percent`:return{format:`0${r}%`,currency:void 0};default:return{format:void 0,currency:void 0}}}function Eb({measure:e,onPatch:t,disabled:n}){let{kind:r,decimals:i}=wb(e.format,e.currency),a=e.currency||`USD`,o=(e,n,r)=>t(Tb(e,n,r)),s=x(r===`percent`?.1234:1234.5,e.format,e.currency);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,Y.jsx)(K,{label:`Display format`,value:r,options:yb,onCommit:e=>o(e,i,a),disabled:n}),r!==`raw`&&(0,Y.jsx)(K,{label:`Decimals`,value:String(i),options:bb,onCommit:e=>o(r,parseInt(e,10)||0,a),disabled:n})]}),r===`currency`&&(0,Y.jsx)(K,{label:`Currency`,value:a,options:xb,onCommit:e=>o(r,i,e),disabled:n}),r!==`raw`&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Sample: `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:s})]})]})}function Db(e,t){if(!e||!e.includes(`.`))return null;let n=e.slice(0,e.lastIndexOf(`.`));return n&&!t.includes(n)?n:null}function Ob({rel:e,onAdd:t,disabled:n}){return(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Relationship `,(0,Y.jsx)(`code`,{className:`font-mono`,children:e}),` isn't in Included relationships.`]}),!n&&t&&(0,Y.jsx)(`button`,{type:`button`,className:`underline hover:no-underline`,onClick:t,children:`Add it`})]})}function kb({label:e,help:t,value:n,onCommit:r,fields:i,disabled:a}){let{group:o,representable:s}=mb(n),c=o.conditions.length;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),s?(0,Y.jsxs)(Cn,{children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,disabled:a,className:`h-8 w-full justify-between text-xs font-normal`,children:[(0,Y.jsx)(`span`,{className:`truncate text-left`,children:c?`${c} condition${c===1?``:`s`}`:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`+ Add filter…`})}),(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5 opacity-60 shrink-0`})]})}),(0,Y.jsx)(Mn,{align:`start`,className:`w-[440px] max-w-[90vw] p-3`,children:i.length===0?(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Pick a base object to add filter conditions.`}):(0,Y.jsx)(fn,{fields:i,value:o,onChange:e=>r(pb(e))})})]}):(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-2.5 py-1.5 text-[11px] text-muted-foreground`,children:[`Advanced filter (nested / OR) — edit it in the `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`Source`}),` tab.`]}),t&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Ab(e,t){return e===t?{object:e}:{object:e,include:[],dimensions:[],measures:[],filter:void 0}}function jb({draft:e,onPatch:t,readOnly:n,name:r}){let i=typeof e.label==`string`?e.label:``,a=typeof e.description==`string`?e.description:``,o=typeof e.object==`string`?e.object:``,s=Array.isArray(e.include)?e.include:[],c=Array.isArray(e.dimensions)?e.dimensions:[],l=Array.isArray(e.measures)?e.measures:[],u=typeof e.name==`string`?e.name:void 0,d=!r,f=X.useRef(!1),p=typeof e.name==`string`?e.name:``,{options:m,loading:h}=Oo(),{relationships:g,fieldOptions:_,loading:v}=ko(o,s),y=Ao(u),b=X.useMemo(()=>m.map(e=>({value:e.name,label:e.label})),[m]),x=X.useMemo(()=>g.map(e=>({value:e.name,label:e.label,hint:e.referenceTo?`→ ${e.referenceTo}`:void 0})),[g]),S=X.useMemo(()=>_.map(e=>({value:e.value,label:e.label,hint:e.type,group:e.group})),[_]),C=X.useMemo(()=>_.filter(e=>!e.value.includes(`.`)).map(e=>({value:e.value,label:e.label,type:e.type})),[_]),w=e.filter&&typeof e.filter==`object`?e.filter:void 0,T=b.find(e=>e.value===o)?.label??o,E=(e,n)=>t({dimensions:c.map((t,r)=>r===e?{...t,...n}:t)}),D=(e,n)=>t({measures:l.map((t,r)=>r===e?{...t,...n}:t)}),O=e=>e.includes(`.`)?e.split(`.`).pop()??e:e,k=(e,t)=>{let n=_.find(e=>e.value===t),r=n?.type?{field:t,type:Co(n.type)}:{field:t};c[e]?.name||(r.name=O(t)),E(e,r)},A=(e,t)=>{let n={field:t};l[e]?.name||(n.name=O(t)),D(e,n)};return(0,Y.jsxs)(Li,{kindLabel:`Dataset`,title:String(i||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[u&&!y.loading&&(0,Y.jsx)(`p`,{className:y.reports+y.dashboards>0?`rounded-md border border-amber-500/30 bg-amber-500/5 px-2.5 py-1.5 text-[11px] text-amber-700 dark:text-amber-300`:`text-[11px] text-muted-foreground`,children:y.reports+y.dashboards>0?`Bound by ${y.reports} report${y.reports===1?``:`s`} · ${y.dashboards} dashboard${y.dashboards===1?``:`s`} — changes affect them.`:`Not yet bound by any report or dashboard.`}),d&&(0,Y.jsx)(q,{label:`Name`,value:p,onCommit:e=>{f.current=!0,t({name:zi(e)})},placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(q,{label:`Label`,value:i,onCommit:e=>{let n={label:e};d&&!f.current&&(n.name=zi(e)),t(n)},disabled:n}),(0,Y.jsx)(q,{label:`Description`,value:a,onCommit:e=>t({description:e}),disabled:n}),(0,Y.jsx)(Ua,{label:`Base object`,value:o,onCommit:e=>t(Ab(e,o)),options:b,loading:h,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:n,mono:!0}),o&&(c.length>0||l.length>0||s.length>0||!!w)&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Changing the base object clears its dimensions, measures, joins & filters.`}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(Sb,{title:`Included relationships`,count:s.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:ua(s,``)})}),s.length===0?(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:[`No joins. Add a relationship (a lookup field on `,(0,Y.jsx)(`code`,{children:T||`the base object`}),`) to use `,(0,Y.jsx)(`code`,{children:`relationship.field`}),` dimensions/measures.`]}):s.map((e,r)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Ua,{value:e,onCommit:e=>t({include:s.map((t,n)=>n===r?e:t)}),options:x,loading:v,placeholder:`Select a relationship…`,searchPlaceholder:`Search relationships…`,disabled:n,mono:!0}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:la(s,r,null)}),"aria-label":`Remove relationship`,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},r)),o&&s.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-0.5 pt-0.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:T}),s.map((e,t)=>{let n=g.find(t=>t.name===e);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(qr,{className:`h-3 w-3 opacity-60`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[e,n?.referenceTo?` (${n.referenceTo})`:``]})]},t)})]})]}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(kb,{label:`Scope filter`,help:`Intrinsic scope, ANDed into every query (e.g. exclude soft-deleted records).`,value:w,onCommit:e=>t({filter:e}),fields:C,disabled:n})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Sb,{title:`Dimensions`,count:c.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:ua(c,{name:``,field:``,type:`string`})})}),c.map((e,r)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove dimension`,title:`Remove dimension`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({dimensions:la(c,r,null)}),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>E(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,Y.jsx)(Ua,{label:`Field`,value:e.field??``,onCommit:e=>k(r,e),options:S,loading:v,placeholder:`field or relationship.field`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=Db(e.field,s);return r?(0,Y.jsx)(Ob,{rel:r,disabled:n,onAdd:()=>t({include:ua(s,r)})}):null})(),(0,Y.jsx)(K,{label:`Type`,value:e.type,options:gb,onCommit:e=>E(r,{type:e}),disabled:n}),(0,Y.jsxs)(Cb,{children:[(0,Y.jsx)(q,{label:`Label (optional)`,value:e.label??``,onCommit:e=>E(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),e.type===`date`&&(0,Y.jsx)(K,{label:`Date bucket`,value:e.dateGranularity??``,options:_b,onCommit:e=>E(r,{dateGranularity:e||void 0}),disabled:n})]})]},r))]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Sb,{title:`Measures`,count:l.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:ua(l,{name:``,aggregate:`sum`,field:``})})}),l.map((e,r)=>{let i=l.filter((e,t)=>t!==r).map(e=>e.name).filter(e=>!!e),a=e.derived;return(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove measure`,title:`Remove measure`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({measures:la(l,r,null)}),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>D(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,Y.jsx)(K,{label:`Aggregate`,value:e.aggregate,options:hb,onCommit:e=>D(r,{aggregate:e}),disabled:n}),(0,Y.jsx)(Ua,{label:`Field`,value:e.field??``,onCommit:e=>A(r,e),options:S,loading:v,placeholder:`field (optional for count)`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=Db(e.field,s);return r?(0,Y.jsx)(Ob,{rel:r,disabled:n,onAdd:()=>t({include:ua(s,r)})}):null})(),(0,Y.jsxs)(Cb,{children:[(0,Y.jsx)(q,{label:`Label (optional)`,value:e.label??``,onCommit:e=>D(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),(0,Y.jsx)(Eb,{measure:e,onPatch:e=>D(r,e),disabled:n}),(0,Y.jsx)(kb,{label:`Filter (measure-scoped)`,help:`Only rows matching this filter feed this measure (e.g. won_amount = sum(amount) where stage = won).`,value:e.filter,onCommit:e=>D(r,{filter:e}),fields:C,disabled:n}),(0,Y.jsx)(J,{label:`Derived — computed from other measures`,value:!!a,onCommit:e=>D(r,{derived:e?{op:`ratio`,of:[]}:void 0}),disabled:n}),a&&(0,Y.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-dashed p-2`,children:[(0,Y.jsx)(K,{label:`Operation`,value:a.op,options:vb,onCommit:e=>D(r,{derived:{...a,op:e}}),disabled:n}),(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Operands (other measures)`}),(()=>{let e=a.op===`ratio`||a.op===`difference`?2:1;return(Array.isArray(a.of)?a.of.length:0)<e?(0,Y.jsxs)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,children:[`Select `,e===2?`exactly 2 measures`:`at least 1 measure`,` for `,a.op,`.`]}):null})(),i.length===0?(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:`Add other measures first.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,Y.jsx)(J,{label:e,value:Array.isArray(a.of)&&a.of.includes(e),disabled:n,onCommit:t=>{let n=Array.isArray(a.of)?a.of:[],i=t?[...n,e]:n.filter(t=>t!==e);D(r,{derived:{...a,of:i}})}},e))})]})]})]},r)})]})]})}function Mb(e){let t=Ai(),[n,r]=X.useState([]),[i,a]=X.useState(!!e);return X.useEffect(()=>{if(!e){r([]),a(!1);return}let n=!1;return a(!0),t.list(e).then(e=>{if(n)return;let t=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));r(t),a(!1)}).catch(()=>{n||(r([]),a(!1))}),()=>{n=!0}},[t,e]),{options:n,loading:i}}var Nb=[{value:`script`,label:`Script — run an expression / sandboxed JS`},{value:`api`,label:`API — call an endpoint`},{value:`flow`,label:`Flow — invoke a flow`},{value:`modal`,label:`Modal — open a modal/page`},{value:`form`,label:`Form — open a FormView`},{value:`url`,label:`URL — navigate to a link`}],Pb=[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}],Fb=[{value:`action:button`,label:`Button`},{value:`action:icon`,label:`Icon only`},{value:`action:menu`,label:`Menu item`},{value:`action:group`,label:`Button group`}],Ib=[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`delete`,label:`Delete`},{value:`custom`,label:`Custom`}],Lb=[{value:`POST`,label:`POST`},{value:`PATCH`,label:`PATCH`},{value:`PUT`,label:`PUT`},{value:`DELETE`,label:`DELETE`}],Rb=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],zb=[{value:`text`,label:`Text`},{value:`textarea`,label:`Long text`},{value:`number`,label:`Number`},{value:`boolean`,label:`Checkbox`},{value:`select`,label:`Select`},{value:`date`,label:`Date`},{value:`datetime`,label:`Date/time`},{value:`lookup`,label:`Lookup`}],Bb=[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record · more menu`},{value:`record_section`,label:`Record · section`},{value:`record_related`,label:`Record · related list`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List · row`},{value:`global_nav`,label:`Global nav / command palette`}],Vb={url:{label:`URL`,placeholder:"https://… or /path?x=${param.x}",hint:"Supports ${param.x} and ${ctx.x} interpolation."},flow:{label:`Flow name`,placeholder:`snake_case flow`,hint:`The flow to invoke when clicked.`},modal:{label:`Modal / page name`,placeholder:`snake_case page`,hint:`The modal or page to open.`},form:{label:`Form view name`,placeholder:`object.viewKey`,hint:`Opens /console/forms/<name>.`},api:{label:`API endpoint`,placeholder:`/api/v1/…`,hint:`Endpoint called with the request body below.`}},Hb={flow:`flow`,modal:`page`,form:`view`};function Ub({type:e,value:t,onCommit:n,cfg:r,readOnly:i}){let a=Hb[e]??null,{options:o}=Mb(a),s=!!a&&o.length>0,c=s&&t&&!o.some(e=>e.value===t)?[{value:t,label:`${t} (not found)`},...o]:o;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[s?(0,Y.jsx)(K,{label:`${r.label} *`,value:t||void 0,options:c,onCommit:n,disabled:i}):(0,Y.jsx)(q,{label:`${r.label} *`,value:t,onCommit:n,placeholder:r.placeholder,disabled:i,mono:!0}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:r.hint})]})}var Wb=[`name`,`label`,`objectName`,`icon`,`variant`,`component`,`type`,`target`,`execute`,`body`,`method`,`params`,`locations`,`bulkEnabled`,`confirmText`,`successMessage`,`errorMessage`,`refreshAfter`,`undoable`,`mode`,`shortcut`,`visible`,`disabled`,`aiExposed`,`aiDescription`];function Gb({title:e,hint:t}){return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function Kb(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function qb({label:e,value:t,onCommit:n,disabled:r,hint:i}){let{options:a}=nd();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[a.length===0?(0,Y.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(K,{label:e,value:t||void 0,options:[{value:``,label:`— None (global) —`},...a],onCommit:n,disabled:r}),i&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:i})]})}function Jb({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let{fields:a}=Ki(t),o=X.useMemo(()=>a.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]);return!t||o.length===0?(0,Y.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(K,{label:e,value:n||void 0,options:[{value:``,label:`—`},...o],onCommit:r,disabled:i})}function Yb({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=X.useCallback(e=>G(e,r),[r]),o=t=>typeof e[t]==`string`?e[t]:``,s=o(`type`)||`script`,c=o(`objectName`),l=e.body&&typeof e.body==`object`?e.body:{},u=Array.isArray(e.params)?e.params:[],d=Array.isArray(e.locations)?e.locations:[],f=e.aiExposed===!0,p=typeof e.aiDescription==`string`?e.aiDescription:``,m=e=>t({body:{...l,...e}}),h=(e,n)=>t({params:u.map((t,r)=>r===e?{...t,...n}:t)}),g=(e,n)=>{t({locations:n?[...new Set([...d,e])]:d.filter(t=>t!==e)})},_=Vb[s],v=i;return(0,Y.jsxs)(Li,{kindLabel:a(`engine.inspector.action.kind`),title:String(Kb(e.label)||e.name||a(`engine.inspector.action.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,Y.jsx)(Gb,{title:`Basics`}),(0,Y.jsx)(q,{label:`Label`,value:Kb(e.label),onCommit:e=>t({label:e}),placeholder:`Button text shown to users`,disabled:n}),(0,Y.jsx)(q,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(qb,{label:`Object`,value:c,onCommit:e=>t({objectName:e||void 0}),disabled:n,hint:c?`Bound action — surfaces in this object’s views per the placement below.`:`Empty = global action — must be referenced by a page’s quick actions, global nav, a flow, or AI to appear.`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Icon`}),(0,Y.jsx)(fa,{schema:{type:`string`},value:o(`icon`),onChange:e=>t({icon:e||void 0}),readOnly:n})]}),(0,Y.jsx)(K,{label:`Variant`,value:o(`variant`)||void 0,options:Pb,onCommit:e=>t({variant:e}),disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(Gb,{title:`Behavior`,hint:`What happens when the action is triggered.`}),(0,Y.jsx)(K,{label:`Type`,value:s,options:Nb,onCommit:e=>t({type:e}),disabled:n}),s===`script`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{label:`Script language`,value:(typeof l.language==`string`?l.language:void 0)||`expression`,options:Rb,onCommit:e=>m({language:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Script body`}),(0,Y.jsx)(lr,{value:typeof l.source==`string`?l.source:``,onChange:e=>m({source:e.target.value}),disabled:n,spellCheck:!1,rows:5,placeholder:`// (input, ctx) => result
23
+ }`})}),Ih(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Vh,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:xn,children:(0,Y.jsx)(Bh,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Bh({props:e,required:t}){let n=Object.keys(e);return(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:n.map(n=>{let r=e[n],i=t.has(n);return(0,Y.jsxs)(`tr`,{className:`align-top`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,Y.jsx)(Ce,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(Vt,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:Lh(r)}),(0,Y.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,Y.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function Vh({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Hh({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Uh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Wh=[{key:`allowCreate`,short:`C`,long:`Create`},{key:`allowRead`,short:`R`,long:`Read`},{key:`allowEdit`,short:`U`,long:`Edit`},{key:`allowDelete`,short:`D`,long:`Delete`},{key:`allowTransfer`,short:`T`,long:`Transfer`},{key:`allowRestore`,short:`Re`,long:`Restore`},{key:`allowPurge`,short:`P`,long:`Purge`,danger:!0},{key:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}];function Gh(e){let t=[];for(let[n,r]of Object.entries(e))r.allowEdit&&!r.allowRead&&t.push({object:n,message:`Edit granted without Read (record updates will fail).`}),r.allowDelete&&!r.allowRead&&t.push({object:n,message:`Delete granted without Read.`}),r.modifyAllRecords&&!r.viewAllRecords&&t.push({object:n,message:`Modify All without View All — modifications may target invisible records.`}),r.allowPurge&&!r.allowDelete&&t.push({object:n,message:`Purge (hard delete) granted without Delete.`});return t}function Kh({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isDefault,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=X.useMemo(()=>Object.keys(o).sort(),[o]),f=X.useMemo(()=>Gh(o),[o]),p=X.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,Y.jsx)(Z,{hint:`permission`,children:(0,Y.jsx)(Hu,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(Z,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,Y.jsx)(zn,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(P,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Default Permission Set`:`Permission Set`})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Xh,{icon:ln,label:`${d.length} objects`}),(0,Y.jsx)(Xh,{icon:rr,label:`${c.length} system perms`}),(0,Y.jsx)(Xh,{icon:N,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(Xh,{icon:Ve,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Yh,{title:`Object Permissions`,count:d.length,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),Wh.map(e=>(0,Y.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),Wh.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(qh,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Jh,{})]}),p.size>0&&(0,Y.jsx)(Yh,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,Y.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,Y.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded border bg-muted/30 px-1.5 py-0.5`,title:`readable=${t.readable!==!1}, editable=${!!t.editable}`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,Y.jsx)(Yh,{title:`System Permissions`,count:c.length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),Object.keys(l).length>0&&(0,Y.jsx)(Yh,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(`span`,{className:t===`hidden`?`text-[9px] uppercase text-red-700`:t===`visible`||t===`default_on`?`text-[9px] uppercase text-emerald-700`:`text-[9px] uppercase text-muted-foreground`,children:t})]},e))})}),f.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,Y.jsxs)(`li`,{className:`text-amber-900`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function qh({granted:e,danger:t}){return e?(0,Y.jsx)(Ce,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(jt,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Jh(){return(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ce,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ce,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(jt,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono`,children:`C R U D = CRUD · T Re P = Transfer/Restore/Purge · V* M* = View/Modify All`})]})}function Yh({title:e,count:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Xh({icon:e,label:t}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:t})]})}function Zh(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function Qh(e){switch(e){case`url`:return M;case`modal`:return Or;case`flow`:return Ye;case`api`:return At;case`form`:return Rr;default:return In}}function $h(e){switch(e){case`primary`:case`default`:case void 0:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:case`destructive`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function eg(e,t,n){if(!t&&!n)return`No handler bound yet.`;switch(e){case`url`:return`Navigate to ${t}`;case`flow`:return`Run flow ${t}`;case`modal`:return`Open modal ${t}`;case`api`:return`Call API endpoint ${t}`;case`form`:return`Open form view ${t} (/console/forms/${t??`?`})`;case`script`:return n?`Run inline script body (L1 expression or L2 sandboxed JS).`:`Run named script ${t}`;default:return`Invoke ${t}`}}function tg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Zh(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target??n.execute,c=n.variant||void 0,l=String(n.component??``),u=Array.isArray(n.locations)?n.locations:[],d=n.shortcut||void 0,f=!!n.bulkEnabled,p=!!n.refreshAfter,m=n.aiExposed,h=Zh(n.confirmText),g=Zh(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,x=n.visible,S=n.disabled,C=n.method||`POST`,w=n.bodyExtra,T=Qh(o),E=l===`action:icon`;return!r&&!i?(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Hu,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,Y.jsx)(ng,{label:i,icon:a,variant:c,iconOnly:E,disabled:!!S&&typeof S==`boolean`})}),(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(lg,{icon:T,label:`type: ${o}`}),b&&(0,Y.jsx)(lg,{icon:rn,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(lg,{label:`variant: ${c}`}),l&&(0,Y.jsx)(lg,{icon:mr,label:l}),d&&(0,Y.jsx)(lg,{icon:jr,label:d,mono:!0}),f&&(0,Y.jsx)(lg,{icon:St,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(lg,{icon:qt,label:`refresh after`}),m===!1&&(0,Y.jsx)(lg,{icon:jn,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(lg,{icon:Et,label:`AI: exposed`})]}),u.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e},e))]}),!!(typeof x==`string`||x&&typeof x==`object`)&&(0,Y.jsx)(sg,{label:`Visible when`,value:x,icon:N}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(sg,{label:`Disabled when`,value:S,icon:Ve})]}),(0,Y.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,Y.jsx)(T,{className:`h-3.5 w-3.5`}),` On click`]}),(0,Y.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:eg(o,s,!!y?.source)}),h&&(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[`First asks: `,(0,Y.jsx)(`em`,{children:h})]})]}),g&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,Y.jsx)(`em`,{children:g})]})]}),u.length>0&&(0,Y.jsx)(cg,{title:`Where it appears`,children:(0,Y.jsx)(dg,{locations:u,label:i,icon:a,variant:c,iconOnly:E})}),o===`api`&&!!s&&(0,Y.jsx)(cg,{title:`Test request`,icon:At,children:(0,Y.jsx)(fg,{target:s,method:C,bodyExtra:w,params:_})}),_.length>0&&(0,Y.jsx)(cg,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(ig,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(cg,{title:`Result Dialog`,icon:N,children:(0,Y.jsx)(og,{dialog:v})}),y?.source&&(0,Y.jsx)(cg,{title:`Script Body (${y.language??`expression`})`,icon:In,children:(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap max-h-[200px] overflow-auto`,children:y.source})})]})})})}function ng({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${$h(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(rg,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function rg({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=le[t===`Home`?`House`:t];return n?(0,Y.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,Y.jsx)(`span`,{className:`inline-flex h-4 min-w-4 items-center justify-center rounded bg-white/30 px-1 text-[9px] uppercase font-mono`,children:e.slice(0,3)})}function ig({title:e,params:t,variant:n}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,Y.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[Zh(e.label)||n,e.required&&(0,Y.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,Y.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),ag(e),e.helpText&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${$h(n||`primary`)}`,children:`OK`})]})]})}function ag(e){let t=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,n=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),r=e.defaultValue;return Array.isArray(e.options)&&e.options.length>0?(0,Y.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,Y.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,Y.jsx)(`option`,{value:e.value,children:Zh(e.label)},t))]}):e.type===`boolean`?(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,Y.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,Y.jsx)(`input`,{type:e.type===`number`||e.type===`integer`?`number`:e.type===`date`?`date`:`text`,className:t,placeholder:n,value:r==null?``:String(r),readOnly:!0})}function og({dialog:e}){let t=Zh(e.title)||`Result`,n=Zh(e.description),r=Zh(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,Y.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:Zh(t.label)||t.path}),(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded bg-primary text-primary-foreground pointer-events-none`,children:r})})]})}function sg({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,Y.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function cg({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function lg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function ug({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-muted-foreground/70`,children:e}),t]})}function dg({locations:e,label:t,icon:n,variant:r,iconOnly:i}){let a=(0,Y.jsx)(ng,{label:t,icon:n,variant:r,iconOnly:i});return(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[e.includes(`record_header`)&&(0,Y.jsx)(ug,{label:`record_header`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-6 w-6 rounded bg-muted`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Sample record`}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Record detail`})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…record body…`})]})}),e.includes(`list_toolbar`)&&(0,Y.jsx)(ug,{label:`list_toolbar`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Records`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[10px] text-muted-foreground`,children:`row 1 · row 2 · row 3`})]})}),e.includes(`list_item`)&&(0,Y.jsx)(ug,{label:`list_item`,children:(0,Y.jsx)(`div`,{className:`divide-y rounded border bg-background`,children:[0,1].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px]`,children:[`Row `,e+1]}),(0,Y.jsx)(`div`,{className:`origin-right scale-90`,children:a})]},e))})}),(e.includes(`record_section`)||e.includes(`record_related`))&&(0,Y.jsx)(ug,{label:e.includes(`record_related`)?`record_related`:`record_section`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:`Section`}),a]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…section content…`})]})}),e.includes(`record_more`)&&(0,Y.jsx)(ug,{label:`record_more`,children:(0,Y.jsxs)(`div`,{className:`w-52 rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-3 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(mr,{className:`h-3.5 w-3.5`}),` More`]}),(0,Y.jsx)(`div`,{className:`px-2 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})}),e.includes(`global_nav`)&&(0,Y.jsx)(ug,{label:`global_nav`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-muted-foreground`,children:`⌘K · Command palette`}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})})]})}function fg({target:e,method:t,bodyExtra:n,params:r}){let i=(t||`POST`).toUpperCase(),[a,o]=X.useState(null),[s,c]=X.useState(!1),l=n&&typeof n==`object`?n:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2 font-mono text-[11px] break-all`,children:[(0,Y.jsx)(`span`,{className:`font-semibold`,children:i}),` `,e]}),Object.keys(l).length>0&&(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-muted/30 p-2 text-[10px] font-mono whitespace-pre-wrap`,children:JSON.stringify(l,null,2)}),r.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`+ `,r.length,` user-supplied param`,r.length>1?`s`:``,` collected at runtime`]}),i!==`GET`&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-amber-700`,children:[(0,Y.jsx)(R,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Sends a real `,i,` request to the live backend — may modify data.`]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:async()=>{c(!0),o(null);try{let t=typeof localStorage<`u`?localStorage.getItem(`auth-session-token`):null,n={"Content-Type":`application/json`};t&&(n.Authorization=`Bearer ${t}`);let r={method:i,headers:n,credentials:`include`};i!==`GET`&&i!==`HEAD`&&(r.body=JSON.stringify(l));let a=await fetch(e,r),s=await a.text(),c=s;try{c=JSON.parse(s)}catch{}o({status:a.status,ok:a.ok,body:c})}catch(e){o({status:0,ok:!1,error:e instanceof Error?e.message:String(e)})}finally{c(!1)}},disabled:s,className:`inline-flex items-center gap-1.5 rounded border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[(0,Y.jsx)(At,{className:`h-3.5 w-3.5`}),` `,s?`Sending…`:`Send test request`]}),a&&(0,Y.jsxs)(`div`,{className:`rounded border p-2 `+(a.ok?`border-green-300 bg-green-50`:`border-red-300 bg-red-50`),children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[11px] font-medium`,children:a.error?`Network error`:`HTTP `+a.status+(a.ok?` OK`:``)}),(0,Y.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto text-[10px] font-mono whitespace-pre-wrap`,children:a.error??(typeof a.body==`string`?a.body:JSON.stringify(a.body,null,2))})]})]})}var pg={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function mg(e,t,n){let r={values:new Set,any:!1};if(e===`*`){for(let e=t;e<=n;e++)r.values.add(e);return r.any=!0,r}for(let i of e.split(`,`)){let e,a=i;if(i.includes(`/`)){let[t,n]=i.split(`/`);a=t,e=n}let o=e?Math.max(1,parseInt(e,10)||1):1,s=t,c=n;if(a!==`*`)if(a.includes(`-`)){let[e,t]=a.split(`-`).map(e=>parseInt(e,10));if(Number.isNaN(e)||Number.isNaN(t))return null;s=e,c=t}else{let e=parseInt(a,10);if(Number.isNaN(e))return null;s=e,c=e}for(let e=s;e<=c;e+=o)e>=t&&e<=n&&r.values.add(e)}return r}function hg(e){let t=(pg[e.trim()]??e.trim()).split(/\s+/);if(t.length!==5&&t.length!==6)return null;let[n,r,i,a,o]=t.length===6?t.slice(1):t,s=mg(n,0,59),c=mg(r,0,23),l=mg(i,1,31),u=mg(a,1,12),d=mg(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function gg(e,t,n){let r=hg(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+366*24*60*60*1e3;for(;i.length<n&&a.getTime()<=o;)r.minute.values.has(a.getMinutes())&&r.hour.values.has(a.getHours())&&r.month.values.has(a.getMonth()+1)&&(r.dom.any||r.dow.any?r.dom.values.has(a.getDate())&&r.dow.values.has(a.getDay()):r.dom.values.has(a.getDate())||r.dow.values.has(a.getDay()))&&i.push(new Date(a.getTime())),a.setMinutes(a.getMinutes()+1);return i}function _g(e){let t=/^(\d+)\s*(ms|s|m|h|d)$/.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;case`d`:return n*864e5;default:return null}}function vg(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function yg(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function bg(e){if(e.schedule&&typeof e.schedule==`object`){let t=e.schedule,n=String(t.type??``),r=t.timezone??e.timezone??e.tz;if(n===`cron`){let e=t.expression;return{cron:typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0,timezone:r}}if(n===`interval`){let e=Number(t.intervalMs);return{every:Number.isFinite(e)&&e>0?xg(e):void 0,timezone:r}}if(n===`once`)return{at:typeof t.at==`string`?t.at:void 0,timezone:r}}let t=typeof e.cron==`string`?e.cron:typeof e.schedule==`string`?e.schedule:void 0,n=e.every??e.interval;return{cron:t,every:typeof n==`string`?n:typeof n==`number`?xg(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function xg(e){return e%864e5==0?`${e/864e5}d`:e%36e5==0?`${e/36e5}h`:e%6e4==0?`${e/6e4}m`:e%1e3==0?`${e/1e3}s`:`${e}ms`}function Sg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,{cron:o,every:s,at:c,timezone:l}=bg(n),u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.retryPolicy,p=f?.maxRetries??n.maxRetries??n.retries,m=f?.backoffMs,h=n.timeout??n.timeoutMs,g=n.concurrency,_=s?_g(s):null,{nextFires:v,deltas:y}=X.useMemo(()=>{let e=new Date,t=[];if(o)t=gg(o,e,5);else if(_)t=vg(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Cg(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Hu,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(se,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Eg,{icon:Mr,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(Eg,{icon:qn,label:l,mono:!0}),p!=null&&(0,Y.jsx)(Eg,{icon:Rt,label:`retries: ${p}${m?` (${xg(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(Eg,{icon:Er,label:`timeout: ${xg(h)}`}),g!=null&&(0,Y.jsx)(Eg,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(Tg,{title:`Schedule`,icon:Tr,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(wg,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(wg,{label:`Every`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,Y.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,Y.jsx)(wg,{label:`At`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,Y.jsx)(Tg,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:gn,children:v.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:b?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,Y.jsx)(gn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:yg(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(Tg,{title:`Handler`,icon:In,children:u?(0,Y.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,Y.jsx)($e,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Cg(e){if(e<=0)return`now`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<48?`${r}h`:`${Math.round(r/24)}d`}function wg({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`break-all`,children:t})]})}function Tg({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Eg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Dg=[{key:`objects`,label:`Objects`,icon:gt,flat:!1},{key:`apps`,label:`Apps`,icon:er,flat:!1},{key:`messages`,label:`Messages`,icon:xt,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Yn,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Yr,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Gn,flat:!1},{key:`settings`,label:`Settings`,icon:dt,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:Oe,flat:!1}];function Og({name:e,draft:t}){let n=t,r=n.locale??n.language??`?`,i=n.label??n.name??e??``,a=n.description,o=n.data??n,s=Dg.map(e=>{let t=o?.[e.key];if(!t||typeof t!=`object`)return{...e,count:0,sample:[]};let n=Object.entries(t);return{...e,count:n.length,sample:n.slice(0,5)}}),c=s.reduce((e,t)=>e+t.count,0),l=s.filter(e=>e.count>0).length,u=Math.round(l/Dg.length*100);return c===0?(0,Y.jsx)(Z,{hint:`translation · ${r}`,children:(0,Y.jsx)(Hu,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(Z,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(_r,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[10px] font-mono text-emerald-800`,children:[(0,Y.jsx)(qn,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,Y.jsx)(tr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,Y.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,Dg.length,` (`,u,`%)`]}),(0,Y.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,Y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,Y.jsx)(kg,{cat:e},e.key))})]})})})}function kg({cat:e}){let t=e.icon;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,Y.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,Y.jsx)(`span`,{className:`truncate text-foreground/80`,children:Ag(n,e.flat)})]},t)),e.count>e.sample.length&&(0,Y.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function Ag(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function jg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``;return r?(0,Y.jsx)(Z,{hint:`position`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Pt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(P,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Positions don't grant data access on their own.`}),(0,Y.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,Y.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more`,` `,(0,Y.jsx)(`strong`,{children:`Permission Sets`}),` to control CRUD-VAMA, field access, and tab visibility. Record visibility comes from the business-unit tree and sharing rules, not from the position.`]})]})]})})]})})}):(0,Y.jsx)(Z,{hint:`position`,children:(0,Y.jsx)(Hu,{children:`Give the position a name to see the preview.`})})}function Mg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.instructions??``,s=Array.isArray(n.tools)?n.tools:[],c=Array.isArray(n.triggerPhrases)?n.triggerPhrases:[],l=Array.isArray(n.triggerConditions)?n.triggerConditions:[],u=Array.isArray(n.permissions)?n.permissions:[],d=n.active!==!1,f=n.model??void 0;return r?(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Et,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Pg,{icon:Mr,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(Pg,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(Pg,{icon:P,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(Ng,{title:`Instructions`,icon:or,children:o?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words max-h-64 overflow-auto`,children:o}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,Y.jsxs)(Ng,{title:`Tools (${s.length})`,icon:Pe,children:[s.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-mono border ${t?`border-amber-300 bg-amber-50 text-amber-900`:`border-border bg-muted/40`}`,children:[t&&(0,Y.jsx)(pn,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-amber-700`,children:`Wildcards expand to many tools at runtime — review the matching set in the agent before activating.`})]}),c.length>0&&(0,Y.jsx)(Ng,{title:`Trigger Phrases (${c.length})`,icon:be,children:(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,Y.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,Y.jsx)(Ng,{title:`Trigger Conditions (${l.length})`,icon:ce,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})}),u.length>0&&(0,Y.jsx)(Ng,{title:`Required Permissions`,icon:P,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})}):(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Hu,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Ng({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Pg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Fg=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Ig=d();function Lg(){return``.replace(/\/+$/,``)}function Rg(e){return`${Lg()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function zg(e){if(e.status===503){let t;try{t=await e.json()}catch{t=void 0}if((t&&typeof t==`object`&&`error`in t?String(t.error):``)===`external_service_unavailable`)throw new Fg}if(!e.ok){let t=`${e.status} ${e.statusText}`;try{let n=await e.json();n&&typeof n==`object`&&`error`in n&&(t=String(n.error))}catch{}throw Error(t)}return await e.json()}async function Bg(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await zg(await Ig(`${Rg(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Vg(e,t,n={}){return(await zg(await Ig(`${Rg(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Hg(e){return(await zg(await Ig(`${Rg(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Ug(e){return zg(await Ig(`${Rg(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Wg(e){await zg(await Ig(`${Lg()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Gg({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=X.useState(`loading`),[s,c]=X.useState(null),[l,u]=X.useState(null);X.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await Vg(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof Fg?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=X.useCallback(async()=>{if(s){o(`importing`),u(null);try{await Wg(s),o(`done`),i?.(s.name)}catch(e){u(e instanceof Error?e.message:String(e)),o(`ready`)}}},[s,i]),f=t?[t.schema,t.name].filter(Boolean).join(`.`):``;return(0,Y.jsx)(Ut,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Qt,{className:`max-w-2xl`,children:[(0,Y.jsxs)(On,{children:[(0,Y.jsxs)(Fr,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(vt,{children:[`Map remote table `,(0,Y.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Y.jsx)(Ce,{className:`h-8 w-8 text-emerald-500`}),(0,Y.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Review its binding and run validation to confirm it matches the remote table.`})]}),(a===`ready`||a===`importing`)&&s&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,Y.jsx)(`ul`,{className:`mt-1.5 space-y-1 text-[11px] text-amber-900/90 dark:text-amber-200/80`,children:s.review.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,Y.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(Wt,{className:`h-3 w-3`}),` Generated source`]}),(0,Y.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/30 p-2.5 text-[11px] leading-relaxed font-mono`,children:s.source})]})]}),(0,Y.jsx)(re,{children:a===`done`?(0,Y.jsx)(L,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(L,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Kg({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),p=X.useCallback(async()=>{n(`loading`),o(null);try{let t=await Bg(e);i(t),n(`loaded`)}catch(e){e instanceof Fg?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);X.useEffect(()=>{p()},[p]);let m=X.useMemo(()=>{let e=s.trim().toLowerCase();return e?r.filter(t=>[t.schema,t.name].filter(Boolean).join(`.`).toLowerCase().includes(e)):r},[r,s]),h=e=>{u(e),f(!0)};return t===`unavailable`?(0,Y.jsx)(qg,{}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(Me,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Filter tables…`,className:`w-full rounded border bg-background pl-7 pr-2 py-1.5 text-xs outline-none focus:ring-1 focus:ring-ring`})]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:a}),t===`loading`&&r.length===0&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,Y.jsx)(`div`,{className:`py-10 text-center text-sm text-muted-foreground`,children:r.length===0?`No remote tables found (check the datasource’s allowedSchemas).`:`No tables match the filter.`}),m.length>0&&(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,Y.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,Y.jsx)(Sn,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(cr,{className:`h-3 w-3`}),e.columnCount]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums text-muted-foreground`,children:typeof e.rowCountEstimate==`number`?e.rowCountEstimate.toLocaleString():`—`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(dn,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(Gg,{datasource:e,table:l,open:d,onOpenChange:f})]})}function qg(){return(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:[`Federation is not enabled on this server. The`,(0,Y.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var Jg={missing_table:`Missing table`,missing_column:`Missing column`,type_mismatch:`Type mismatch`,nullability_mismatch:`Nullability mismatch`,unmapped_column:`Unmapped column`,pk_mismatch:`Primary-key mismatch`};function Yg({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useCallback(async()=>{n(`running`),c(null);try{let t=await Ug(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof Fg?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,Y.jsx)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:`Federation is not enabled on this server, so validation is unavailable.`}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)($e,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:s}),t===`done`&&a!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded border p-2.5 text-sm ${a?`border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 text-emerald-800 dark:text-emerald-300`:`border-destructive/40 bg-destructive/5 text-destructive`}`,children:[a?(0,Y.jsx)(Ce,{className:`h-4 w-4`}):(0,Y.jsx)(Yn,{className:`h-4 w-4`}),a?`All ${r.length} object${r.length===1?``:`s`} match the remote schema.`:`${r.filter(e=>!e.ok).length} of ${r.length} object${r.length===1?``:`s`} diverge from the remote schema.`]}),t===`done`&&r.length===0&&(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No federated objects are bound to this datasource yet. Import a table from the Tables tab to get started.`}),r.length>0&&(0,Y.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsx)(Xg,{result:e},e.object))})]})}function Xg({result:e}){return(0,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,Y.jsx)(P,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(Yn,{className:`h-3.5 w-3.5 text-destructive`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[e.diffs.length,` diff`,e.diffs.length===1?``:`s`]})]}),e.diffs.length>0&&(0,Y.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,Y.jsx)(Zg,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Zg({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,Y.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-2.5 py-1.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`rounded px-1 py-0.5 font-medium uppercase tracking-wide text-[9px] ${e.severity===`error`?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:Jg[e.kind]??e.kind}),t&&(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function Qg({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=X.useState(null),[a,o]=X.useState(!1),[s,c]=X.useState(null),l=X.useCallback(async()=>{if(e){o(!0),c(null);try{let t=await Hg(e);i(t)}catch(e){c(e instanceof Fg?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,Y.jsx)(Hr,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:t??`external`}),(0,Y.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`:`bg-muted text-muted-foreground`}`,children:n?`writes allowed`:`read-only`}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(gn,{className:`h-3 w-3`}),`snapshot `,$g(r.snapshotAt)]}),(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,Y.jsxs)(Hn,{defaultValue:`tables`,className:`p-3`,children:[(0,Y.jsxs)(an,{children:[(0,Y.jsx)(Gr,{value:`tables`,children:`Tables`}),(0,Y.jsx)(Gr,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(Ln,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(Kg,{datasource:e})}),(0,Y.jsx)(Ln,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(Yg,{datasource:e})})]})]}):(0,Y.jsx)(`div`,{className:`rounded border bg-muted/20 p-3 text-xs text-muted-foreground`,children:`Save the datasource first to browse its remote tables and validate federated objects.`})}function $g(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var e_=/pass|secret|key|token|credential|auth/i;function t_(e){return e_.test(e)}function n_(e){return e==null||e===``?`∅`:`••••••`}function r_(e){return e==null?`∅`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`[${e.length}]`:typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e)}function i_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=n.schemaMode??`managed`,_=g!==`managed`,v=!!(n.external??void 0)?.allowWrites,y=Object.entries(l);return!r&&y.length===0?(0,Y.jsx)(Z,{hint:`datasource`,children:(0,Y.jsx)(Hu,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(Z,{hint:`datasource · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ir,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,Y.jsx)(hn,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(s_,{icon:Mr,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(s_,{icon:zn,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(s_,{icon:Pn,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(Qg,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(o_,{title:`Connection`,icon:Ve,children:y.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=t_(e);return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:n_(t)}),(0,Y.jsx)(`span`,{className:`rounded bg-amber-50 border border-amber-200 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-800`,children:`redacted`})]}):r_(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)(a_,{title:`Pool`,icon:Jn,value:u}),(0,Y.jsx)(a_,{title:`SSL`,icon:P,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)(a_,{title:`Retry Policy`,icon:Rt,value:f}),(0,Y.jsx)(a_,{title:`Health Check`,icon:Jn,value:p})]}),h.length>0&&(0,Y.jsx)(o_,{title:`Capabilities`,icon:P,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})})}function a_({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`dd`,{className:`font-mono truncate`,children:t_(e)?n_(t):r_(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function o_({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function s_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function c_(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function l_(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/40`,text:`text-red-700 dark:text-red-300`,icon:Ot};case`warning`:return{ring:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`,text:`text-amber-800 dark:text-amber-300`,icon:R};default:return{ring:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`,text:`text-blue-800 dark:text-blue-300`,icon:Nn}}}function u_({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.type??`script`,s=n.object,c=n.message??``,l=n.severity??`error`,u=n.active!==!1,d=Array.isArray(n.events)?n.events:[],f=n.priority,p=Array.isArray(n.tags)?n.tags:[],m=l_(l);return r?(0,Y.jsx)(Z,{hint:`validation · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(m_,{icon:Mr,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(m_,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(m_,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(m_,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,Y.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,Y.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,Y.jsx)(d_,{type:o,d:n}),p.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})]})]})})}):(0,Y.jsx)(Z,{hint:`validation`,children:(0,Y.jsx)(Hu,{children:`Give the validation a name to see the preview.`})})}function d_({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(p_,{title:`Condition`,icon:In,children:(0,Y.jsx)(f_,{value:c_(t.condition)??c_(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=c_(t.scope)??c_(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(p_,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Ct,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,Y.jsx)(p_,{title:`Scope`,icon:_e,children:(0,Y.jsx)(f_,{value:n})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field;return(0,Y.jsx)(p_,{title:`Transitions${r?` on ${r}`:``}`,icon:Ye,children:n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(qr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:Array.isArray(t)&&t.length>0?t.join(` | `):`∅ (dead-end)`})]},e))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,Y.jsx)(p_,{title:`Format`,icon:Ie,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=c_(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(p_,{title:`Fields involved`,icon:_e,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e)),e.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,Y.jsx)(p_,{title:`Cross-field condition`,icon:In,children:(0,Y.jsx)(f_,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(p_,{title:`Async endpoint`,icon:qn,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,Y.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,Y.jsx)(p_,{title:`Custom handler`,icon:In,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,Y.jsx)(p_,{title:`Rule`,icon:Yn,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs text-muted-foreground italic`,children:[`Unknown rule type "`,e,`". Showing common fields only.`]})})}}function f_({value:e}){return e?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function p_({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function m_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var h_=X.lazy(()=>a(()=>import(`./plugin-charts-D5Lb0q0u.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function g_({draft:e}){let t=S(),{fieldLabel:n}=ii(),r=e.object,i=X.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=X.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),o=!!r&&i.length>0,[s,c]=X.useState({status:`idle`,rows:[]}),l=X.useCallback(async()=>{if(o){c({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:a,measures:i});c({status:`ok`,rows:Array.isArray(n?.rows)?n.rows:[],fields:Array.isArray(n?.fields)?n.fields:[],object:n?.object})}catch(e){c({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,a,i,o]),u=`${r??``}|${a.join(`,`)}|${i.join(`,`)}`;if(X.useEffect(()=>{o&&l()},[u]),!r)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(i.length===0)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`Add a measure`,description:`A dataset needs at least one measure (e.g. revenue = sum(amount)) to preview.`})});let{measureField:d,headerLabel:f}=C(s.status===`ok`?s.fields:void 0,s.status===`ok`?s.object:void 0,n),p=[...a,...i],m=e=>{let t=d(e)?.format;return typeof t==`string`&&t.includes(`%`)},h=i.filter(m),g=h.length>0&&h.length<i.length;return(0,Y.jsx)(Z,{hint:`dataset · ${r}${a.length?` · by `+a.join(`, `):``}`,children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void l(),disabled:s.status===`loading`,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[s.status===`loading`?(0,Y.jsx)(V,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Nr,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[i.length,` measure`,i.length===1?``:`s`,` · `,a.length,` dimension`,a.length===1?``:`s`]})]}),s.status===`error`&&(0,Y.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`break-words`,children:s.error})]}),s.status===`ok`&&s.rows.length===0&&(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(Nr,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),s.rows.length>0&&a.length>=1&&(0,Y.jsx)(Q,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,Y.jsx)(V,{className:`h-4 w-4 animate-spin`})}),children:(0,Y.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,Y.jsx)(h_,{schema:{data:s.rows,xAxisKey:a[0],chartType:g?`combo`:`bar`,series:i.map(e=>({dataKey:e,label:f(e),chartType:g&&m(e)?`line`:`bar`}))}}),g&&(0,Y.jsxs)(`p`,{className:`mt-1 px-1 text-[10px] text-muted-foreground`,children:[`Ratio measures (`,h.map(f).join(`, `),`) use the right axis.`]})]})})}),s.rows.length>0&&(0,Y.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Y.jsx)(`tr`,{children:p.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:f(e)},e))})}),(0,Y.jsx)(`tbody`,{children:s.rows.map((e,t)=>(0,Y.jsx)(`tr`,{className:`border-t`,children:p.map(t=>(0,Y.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:i.includes(t)?x(e[t],d(t)?.format,d(t)?.currency):b(e[t])},t))},t))})]})})]})})}function __(e){return Array.isArray(e)?e.map((e,t)=>{if(!e||typeof e!=`object`)return null;let n=String(e.key??``).trim(),r=String(e.label??n??``).trim();return!n&&!r?null:{g:{key:n||`(no key)`,label:r||n||`(unnamed)`,order:typeof e.order==`number`?e.order:void 0,include:v_(e.include),package:typeof e.package==`string`?e.package:void 0,pages:y_(e.pages)},i:t}}).filter(e=>e!==null).sort((e,t)=>(e.g.order??0)-(t.g.order??0)||e.i-t.i).map(e=>e.g):[]}function v_(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function y_(e){if(Array.isArray(e))return e.map(e=>typeof e==`string`?{literal:e}:e&&typeof e==`object`?{doc:typeof e.doc==`string`?e.doc:void 0,href:typeof e.href==`string`?e.href:void 0,label:typeof e.label==`string`?e.label:void 0,badge:typeof e.badge==`string`?e.badge:void 0,icon:typeof e.icon==`string`?e.icon:void 0}:null).filter(e=>e!==null)}function b_(e){return e===`public`?{icon:(0,Y.jsx)(At,{className:`h-3 w-3`}),label:`Public`,tone:`text-emerald-700 bg-emerald-50 border-emerald-200`}:e&&typeof e==`object`&&typeof e.permissionSet==`string`?{icon:(0,Y.jsx)(Ve,{className:`h-3 w-3`}),label:`Permission set: ${e.permissionSet}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,Y.jsx)(sn,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function x_({name:e,draft:t}){let n=t,r=String(n.name??e??``).trim(),i=String(n.label??r),a=typeof n.description==`string`?n.description:``,o=typeof n.slug==`string`?n.slug:``,s=X.useMemo(()=>__(n.groups),[n.groups]),c=b_(n.audience);return r?(0,Y.jsx)(Z,{hint:`book · spine`,toolbar:(0,Y.jsxs)(`a`,{href:`/meta/book/${encodeURIComponent(r)}/tree`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open the live-resolved navigation tree (actual docs per group)`,children:[`Resolved tree `,(0,Y.jsx)(Ir,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(or,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium ${c.tone}`,children:[c.icon,c.label]})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:r}),o&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Slug: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1.5`,children:a})]}),s.length===0?(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(nt,{className:`h-8 w-8 opacity-50`}),title:`No groups yet`,tone:`warn`,description:(0,Y.jsxs)(Y.Fragment,{children:[`A book needs at least one group in its `,(0,Y.jsx)(`code`,{children:`groups`}),` spine. Each group derives its members from an `,(0,Y.jsx)(`code`,{children:`include`}),` rule (a glob like`,` `,(0,Y.jsx)(`code`,{children:`crm_guide_*`}),` or a `,(0,Y.jsx)(`code`,{children:`{ tag }`}),`).`]})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:s.map((e,t)=>(0,Y.jsx)(S_,{group:e},`${e.key}-${t}`))})]})})}):(0,Y.jsx)(Z,{hint:`book`,children:(0,Y.jsx)(Uu,{icon:(0,Y.jsx)(or,{className:`h-8 w-8 opacity-50`}),title:`Name your book`,description:`Enter a name in the Form tab to start authoring the documentation spine.`})})}function S_({group:e}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.key}),typeof e.order==`number`&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Order within the book`,children:[`#`,e.order]}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[e.package&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Membership rule is scoped to this package`,children:[(0,Y.jsx)(Kr,{className:`h-3 w-3`}),e.package]}),(0,Y.jsx)(C_,{include:e.include,hasOverride:!!e.pages?.length})]})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:e.pages?.length?(0,Y.jsx)(`ol`,{className:`space-y-1`,children:e.pages.map((e,t)=>(0,Y.jsx)(w_,{node:e},t))}):e.include==null?(0,Y.jsxs)(`div`,{className:`text-[11px] text-amber-700 italic`,children:[`No `,(0,Y.jsx)(`code`,{children:`include`}),` rule and no explicit `,(0,Y.jsx)(`code`,{children:`pages`}),` — this group matches nothing unless docs set `,(0,Y.jsxs)(`code`,{children:[`group: "`,e.key,`"`]}),`.`]}):(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Members derived from the rule above — resolved against the live doc set.`})})]})}function C_({include:e,hasOverride:t}){return e==null?t?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Curated order via explicit pages`,children:`curated`}):null:typeof e==`string`?(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,title:`Glob over doc names`,children:e}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[10px] text-foreground`,title:`Match by doc tag`,children:[(0,Y.jsx)(rr,{className:`h-3 w-3`}),e.tag]})}function w_({node:e}){if(e.literal===`---`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-wider text-muted-foreground/60`,children:[(0,Y.jsx)(et,{className:`h-3 w-3`}),`separator`]});if(e.literal===`...`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[11px] italic text-muted-foreground`,children:[(0,Y.jsx)(mr,{className:`h-3.5 w-3.5`}),`…rest (remaining matched docs, by order)`]});let t=!!e.href,n=e.literal??e.doc,r=e.label??n??e.href??`(empty)`;return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,Y.jsx)(Ir,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(Oe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:r}),!t&&n&&e.label&&(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n}),e.badge&&(0,Y.jsx)(`span`,{className:`rounded-full border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-foreground`,children:e.badge}),t&&(0,Y.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground truncate max-w-[40%]`,title:e.href,children:e.href})]})}function T_(){il(`page`,Hd),il(`view`,Kd),il(`dashboard`,$d),il(`report`,nf),il(`app`,gf),il(`action`,tg),il(`object`,Lf),il(`datasource`,i_),il(`validation`,u_),il(`dataset`,g_),il(`email_template`,Vf),il(`translation`,Og),il(`book`,x_),il(`flow`,wh),il(`job`,Sg),il(`agent`,Eh),il(`tool`,zh),il(`skill`,Mg),il(`permission`,Kh),il(`profile`,Kh),il(`position`,jg),il(`role`,jg)}var E_=[{value:`metric`,label:`KPI Metric`},{value:`bar`,label:`Bar Chart`},{value:`horizontal-bar`,label:`Horizontal Bar`},{value:`line`,label:`Line Chart`},{value:`area`,label:`Area Chart`},{value:`pie`,label:`Pie Chart`},{value:`donut`,label:`Donut Chart`},{value:`funnel`,label:`Funnel`},{value:`table`,label:`Table`},{value:`pivot`,label:`Pivot Table`}],D_=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function O_(e,t){let n=Array.isArray(e.widgets)?e.widgets:[],r=n.findIndex(e=>e?.id===t);return r<0?null:{widget:n[r],index:r}}function k_({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=Array.isArray(e.widgets)?e.widgets:[],c=t.kind===`widget`?t.id:void 0,l=c?O_(e,c):null,u=l?.widget??{},d=typeof u.dataset==`string`?u.dataset:``,f=Array.isArray(u.dimensions)?u.dimensions.filter(e=>typeof e==`string`):[],p=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],m=ga(),h=ca(d||void 0,m),g=X.useMemo(()=>{let e=m.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return d&&!e.some(e=>e.value===d)&&e.push({value:d,label:d}),e},[m.datasets,d]),v=X.useMemo(()=>h.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[h.measures]),y=X.useMemo(()=>h.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[h.dimensions]),b=X.useMemo(()=>h.dimensions.map(e=>({value:e.name,label:e.name,hint:e.type})),[h.dimensions]),x=X.useMemo(()=>_({globalFilters:e.globalFilters,dateRange:e.dateRange}),[e]);if(t.kind!==`widget`)return(0,Y.jsx)(j_,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,Y.jsx)(j_,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:S,index:C}=l;function w(e){let t=[...s];t[C]={...t[C],...e},n({widgets:t})}function T(e){n({widgets:Pi(s,C,e)}),S.id&&i?.({kind:`widget`,id:S.id,label:S.title??void 0})}return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.kind`,o)}),(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:S.title||t.label||`Widget ${C+1}`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(Xi,{index:C,total:s.length,onMove:T,upLabel:G(`engine.inspector.reorder.up`,o),downLabel:G(`engine.inspector.reorder.down`,o),disabled:a}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:G(`engine.inspector.widget.close`,o),"aria-label":G(`engine.inspector.widget.close`,o),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(A_,{id:`widget-title`,label:G(`engine.inspector.widget.title`,o),children:(0,Y.jsx)(B,{id:`widget-title`,value:S.title??``,onChange:e=>w({title:e.target.value}),disabled:a})}),(0,Y.jsx)(A_,{id:`widget-type`,label:G(`engine.inspector.widget.type`,o),children:(0,Y.jsxs)(oe,{value:S.type??`metric`,onValueChange:e=>w({type:e}),disabled:a,children:[(0,Y.jsx)(fr,{id:`widget-type`,children:(0,Y.jsx)(Dr,{})}),(0,Y.jsx)(En,{children:E_.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})}),(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.datasetSection`,o)}),(0,Y.jsxs)(A_,{id:`widget-dataset`,label:G(`engine.inspector.widget.dataset`,o),children:[(0,Y.jsx)(Ua,{value:d,onCommit:e=>w({dataset:e||void 0}),options:g,loading:m.loading,placeholder:G(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:G(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,Y.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:G(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(va,{label:G(`engine.inspector.widget.dimensions`,o),emptyText:G(`engine.inspector.widget.dimensionsHint`,o),names:f,options:y,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>w({dimensions:e})}),(0,Y.jsx)(va,{label:G(`engine.inspector.widget.values`,o),emptyText:G(`engine.inspector.widget.valuesHint`,o),names:p,options:v,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>w({values:e})})]})]}),x.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:G(`engine.inspector.widget.filterBindingsSection`,o)}),(0,Y.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:G(`engine.inspector.widget.filterBindingsHint`,o)}),x.map(e=>{let t=S.filterBindings,n=t?.[e.name],r=n===!1,i=typeof n==`string`?n:``,s=n=>{let r={...t??{}};n===void 0?delete r[e.name]:r[e.name]=n,w({filterBindings:Object.keys(r).length>0?r:void 0})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,"data-testid":`widget-filter-binding-${e.name}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(U,{className:`text-xs font-medium text-muted-foreground truncate`,children:e.label||e.name}),(0,Y.jsx)(J,{label:G(`engine.inspector.widget.filterBindingApply`,o),value:!r,onCommit:e=>s(e?void 0:!1),disabled:a})]}),!r&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ua,{value:i,onCommit:e=>s(e||void 0),options:b,placeholder:W(`engine.inspector.widget.filterBindingDefault`,o,{field:e.field}),searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),i&&!a&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 shrink-0 px-2 text-[10px] text-muted-foreground`,onClick:()=>s(void 0),children:G(`engine.inspector.widget.filterBindingReset`,o)})]})]},e.name)})]}),(0,Y.jsx)(A_,{id:`widget-color`,label:G(`engine.inspector.widget.color`,o),children:(0,Y.jsx)(na,{value:S.colorVariant??`default`,onChange:e=>w({colorVariant:e}),disabled:a,options:D_.map(e=>({value:e}))})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(A_,{id:`widget-w`,label:G(`engine.inspector.widget.width`,o),children:(0,Y.jsx)(B,{id:`widget-w`,type:`number`,min:1,value:S.layout?.w??1,onChange:e=>w({layout:{...S.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,Y.jsx)(A_,{id:`widget-h`,label:G(`engine.inspector.widget.height`,o),children:(0,Y.jsx)(B,{id:`widget-h`,type:`number`,min:1,value:S.layout?.h??1,onChange:e=>w({layout:{...S.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,Y.jsx)(`div`,{className:`pt-2 border-t`,children:(0,Y.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:text-destructive`,onClick:()=>{let t=Array.isArray(e.widgets)?[...e.widgets]:[];t.splice(C,1),n({widgets:t}),r()},children:G(`engine.inspector.widget.remove`,o)})})]})}function A_({id:e,label:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function j_({message:e,onClose:t,locale:n}){return(0,Y.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,Y.jsx)(`p`,{children:e}),(0,Y.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:G(`engine.inspector.widget.close`,n)})]})}var M_={io:`input`,unrepresentable:`any`},N_=new Set([`widgets`,`label`,`description`,`name`]),P_,F_=!1;function I_(){if(P_||F_)return P_;try{P_=E(k,M_)}catch(e){F_=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return P_}var L_;function R_(){if(L_)return L_;if(!(!D||typeof D!=`object`)){try{let e=JSON.parse(JSON.stringify(D));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!N_.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),L_=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return L_}}var z_=new Set([`name`,`label`,`description`,`widgets`]);function B_({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=X.useCallback(e=>G(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=X.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=Gi(`widget`,l.map(e=>e?.id).filter(Boolean)),r=qd[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:ua(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:la(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:Pi(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=X.useState(null),[g,_]=X.useState(null),{schema:v,form:y}=X.useMemo(()=>ta({bundledSchema:I_(),bundledForm:R_(),serverSchema:a,excludeFields:z_,sectionTitle:G(`engine.inspector.moreFields`,r)}),[a,r]);return(0,Y.jsxs)(Li,{kindLabel:o(`engine.inspector.dashboard.kind`),title:String(s||e.name||o(`engine.inspector.dashboard.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.dashboard.close`),hideClose:!0,children:[(0,Y.jsx)(q,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,Y.jsx)(q,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.widgetsEmpty`)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=qd[e?.type]?.icon??Xd;return(0,Y.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,Y.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Y.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,Y.jsx)(Zd,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,Y.jsx)(ha,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.noSchema`)})})]})}var V_=new Set([`object`,`object-field`,`flow`,`org-membership-level`,`position`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function H_(e){let t=e.xRef;if(!t||typeof t!=`object`)return;let n=typeof t.objectSource==`string`&&t.objectSource?{objectSource:t.objectSource}:{};if(typeof t.kindFrom==`string`&&t.kindFrom&&t.map&&typeof t.map==`object`){let e={};for(let[n,r]of Object.entries(t.map))typeof r==`string`&&V_.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&V_.has(t.kind))return{kind:t.kind,...n}}function U_(e){let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim();return t?t.split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):e}function W_(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function G_(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`);if(typeof e.type==`string`)return e.type;if(Array.isArray(e.enum))return`string`;if(e.properties)return`object`;if(e.items)return`array`}function K_(e,t){let n=new Set((t??[]).filter(e=>typeof e==`string`));return e.filter(e=>typeof e==`string`).filter(e=>!n.has(e)).map(e=>({value:e,label:U_(e)}))}function q_(e){if(!(e.default===void 0||e.default===null)){if(typeof e.default==`boolean`||typeof e.default==`number`)return String(e.default);if(typeof e.default==`string`)return e.default}}function J_(e){return e.xExpression===`expression`||e.xExpression===`template`?e.xExpression:void 0}function Y_(e){if(Array.isArray(e.enum))return{kind:`select`};let t=G_(e);if(t===`boolean`)return{kind:`boolean`};if(t===`number`||t===`integer`)return{kind:`number`};if(t===`string`){let t=e.format===`multiline`,n=J_(e);return n===`expression`?t?{kind:`textarea`,refMode:`expression`}:{kind:`expression`}:n===`template`?t?{kind:`textarea`,refMode:`template`}:{kind:`expression`,refMode:`template`}:{kind:t?`textarea`:`text`}}}var X_=4;function Z_(e,t){let n=W_(e.items)?e.items:void 0,r=n?G_(n):void 0;return n&&r===`object`&&W_(n.properties)?t>=X_?null:{kind:`objectList`,columns:Q_(n,t+1)}:r===`string`?{kind:`stringList`}:r===`number`||r===`integer`?{kind:`numberList`}:null}function Q_(e,t=0){let n=e.properties??{},r=[];for(let[e,i]of Object.entries(n)){if(!W_(i))continue;let n=G_(i);if(n===`array`){let n=Z_(i,t);if(n){r.push({key:e,label:i.title||U_(e),kind:n.kind,...n.columns?{columns:n.columns}:{},...i.description?{placeholder:i.description}:{}});continue}}let a,o,s=H_(i);s?a=`reference`:Array.isArray(i.enum)?(a=`select`,o=K_(i.enum,i.xEnumDeprecated)):a=n===`boolean`?`boolean`:J_(i)===`expression`?`expression`:`text`,r.push({key:e,label:i.title||U_(e),kind:a,...o?{options:o}:{},...s?{ref:s}:{},...i.description?{placeholder:i.description}:{}})}return r}function $_(e,t){return{label:e.title||U_(t),...e.description?{help:e.description}:{},...q_(e)?{defaultValue:q_(e)}:{}}}function ev(e){if(!W_(e)||G_(e)!==`object`||!W_(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!W_(r))continue;let e=G_(r);if(e===`array`){let e=W_(r.items)?r.items:void 0,i=e?G_(e):void 0;e&&i===`object`&&W_(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:Q_(e),...$_(r,n)}):i===`string`?t.push({id:n,path:[`config`,n],kind:`stringList`,...$_(r,n)}):(i===`number`||i===`integer`)&&t.push({id:n,path:[`config`,n],kind:`numberList`,...$_(r,n)});continue}if(e===`object`&&W_(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>W_(e)),i=e.some(([e,t])=>e===`enabled`&&G_(t)===`boolean`);for(let[a,o]of e){let e=o,s=H_(e),c=s?void 0:Y_(e),l=s?`reference`:c?.kind;if(!l)continue;let u=`${n}.${a}`,d=i&&a===`enabled`,f={id:u,path:[`config`,n,a],kind:l,...d?{label:r.title||U_(n),...r.description?{help:r.description}:{},...q_(e)?{defaultValue:q_(e)}:{}}:$_(e,a),...s?{ref:s}:{},...c?.refMode?{refMode:c.refMode}:{},...l===`select`&&Array.isArray(e.enum)?{options:K_(e.enum,e.xEnumDeprecated)}:{},...i&&!d?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(f)}continue}if(e===`object`&&r.additionalProperties!==void 0&&r.additionalProperties!==!1){t.push({id:n,path:[`config`,n],kind:`keyValue`,...$_(r,n)});continue}let i=H_(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...$_(r,n)});continue}let a=Y_(r);a&&t.push({id:n,path:[`config`,n],kind:a.kind,...$_(r,n),...a.refMode?{refMode:a.refMode}:{},...a.kind===`select`&&Array.isArray(r.enum)?{options:K_(r.enum,r.xEnumDeprecated)}:{}})}return t}var tv=e=>ap(e),nv=e=>typeof e.expression==`string`?e.expression.trim():``,rv=e=>typeof e.label==`string`?e.label.trim():``,iv=e=>typeof e.target==`string`?e.target.trim():``,av=e=>{let t=nv(e);return t===``||t===`true`};function ov(e){return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&!Array.isArray(e)):[]}function sv(e,t){if(av(e))return t.isDefault===!0;let n=nv(e),r=tv(t.condition);if(n&&r===n)return!0;let i=rv(e);return i!==``&&t.label===i}var cv=e=>t=>t.source===e&&t.type!==`fault`&&t.type!==`back`;function lv(e,t){let n=nv(t),r=rv(t),i={...e};return r?i.label=r:delete i.label,n&&n!==`true`?(i.condition=n,delete i.isDefault):n===`true`?(i.isDefault=!0,delete i.condition):(delete i.condition,delete i.isDefault),i}function uv(e,t,n){let r=ov(t),i=cv(e),a=0;return n.map(e=>{if(!i(e))return e;let t=r[a++];return t?lv(e,t):e})}function dv(e,t,n){let r=ov(t);if(r.length===0)return r;let i=n.map((e,t)=>t).filter(t=>cv(e)(n[t])),a=new Set,o=new Map;return r.forEach((e,t)=>{let r=i.find(t=>!a.has(t)&&sv(e,n[t]));r!==void 0&&(a.add(r),o.set(t,r))}),r.forEach((e,t)=>{if(o.has(t))return;let n=i.find(e=>!a.has(e));n!==void 0&&(a.add(n),o.set(t,n))}),r.map((e,t)=>{let{target:r,...i}=e,a=o.get(t);return a===void 0?i:{...i,target:n[a].target}})}function fv(e,t,n){let r=ov(t),i=r.map(e=>{let{target:t,...n}=e;return n});if(!r.some(e=>iv(e)!==``))return{conditions:i,edges:uv(e,i,n)};let a=n.map((e,t)=>t).filter(t=>cv(e)(n[t])),o=new Set,s=new Map,c=[(e,t)=>t.target===iv(e)&&sv(e,t),(e,t)=>t.target===iv(e),(e,t)=>sv(e,t)];for(let e of c)r.forEach((t,r)=>{if(s.has(r)||iv(t)===``)return;let i=a.find(r=>!o.has(r)&&e(t,n[r]));i!==void 0&&(o.add(i),s.set(r,i))});let l=new Map,u=[],d=new Set;return r.forEach((t,r)=>{let i=iv(t);if(i===``){let e=a.find(e=>!o.has(e)&&sv(t,n[e]));e!==void 0&&(o.add(e),d.add(e));return}let c=s.get(r);c===void 0?u.push(lv({source:e,target:i},t)):l.set(c,lv({...n[c],target:i},t))}),{conditions:i,edges:n.map((e,t)=>d.has(t)?null:l.get(t)??e).filter(e=>e!==null).concat(u)}}function pv(e,t){return t===`template`?`{${e}}`:e}function mv(e,t,n,r,i){let a=pv(n,t),o=Math.min(Math.max(r,0),e.length),s=Math.min(Math.max(i,0),e.length),c=Math.min(o,s),l=Math.max(o,s);return{next:e.slice(0,c)+a+e.slice(l),caret:c+a.length}}var hv=`Insert a reference`,gv=`Search references…`,_v=`No matching references.`;function vv({value:e,onValueChange:t,onBlur:n,onKeyDown:r,mode:i,groups:a,placeholder:o,disabled:s,multiline:c,rows:l=4,mono:u,className:d}){let f=X.useRef(null),p=X.useRef({start:0,end:0}),[m,h]=X.useState(!1),g=e=>{f.current=e},_=()=>{let t=f.current;t&&(p.current={start:t.selectionStart??e.length,end:t.selectionEnd??e.length})},v=n=>{let{next:r,caret:a}=mv(e,i,n,p.current.start,p.current.end);t(r),h(!1),requestAnimationFrame(()=>{let e=f.current;if(e){e.focus();try{e.setSelectionRange(a,a)}catch{}p.current={start:a,end:a}}})},y=a.some(e=>e.refs.length>0),b={value:e,onChange:e=>t(e.target.value),onBlur:n,onKeyDown:r,onSelect:_,onKeyUp:_,onClick:_,placeholder:o,disabled:s};return(0,Y.jsxs)(`div`,{className:I(`relative`,d),children:[c?(0,Y.jsx)(`textarea`,{ref:g,...b,rows:l,className:`w-full rounded border bg-background px-2 py-1.5 pr-8 font-mono text-xs`}):(0,Y.jsx)(B,{ref:g,...b,className:I(`h-8 pr-8 text-sm`,u&&`font-mono`)}),y&&!s&&(0,Y.jsxs)(Cn,{open:m,onOpenChange:h,children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,"aria-label":hv,title:hv,onMouseDown:_,className:`absolute right-1 top-1 inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,Y.jsx)(nr,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(Mn,{align:`end`,className:`w-72 p-0`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,Y.jsxs)(De,{children:[(0,Y.jsx)(Ue,{placeholder:gv,className:`h-9`}),(0,Y.jsxs)(Le,{children:[(0,Y.jsx)(zt,{children:_v}),a.map(e=>(0,Y.jsx)(we,{heading:e.label,children:e.refs.map(t=>(0,Y.jsxs)(Sr,{value:`${t.token} ${t.label} ${t.detail??``}`,onSelect:()=>v(t.token),className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate font-mono text-xs`,children:pv(t.token,i)}),t.detail&&(0,Y.jsx)(`span`,{className:`shrink-0 truncate text-[10px] text-muted-foreground`,children:t.detail})]},`${e.id}:${t.token}`))},e.id))]})]})})]})]})}function yv({value:e,role:t,scopeGroups:n}){let r=t===`template`?null:sm(t,e);if(r)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:r.message});let i=n&&n.length>0?em(n.flatMap(e=>e.refs)):null,a=i?rm(e,t,i):[];return a.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(a)}):null}function bv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xv(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Sv(e){let t=e.trim();if(t===``)return``;if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function Cv(e){return Array.isArray(e)?e.filter(e=>bv(e)).map(e=>{let t=e.variable??e.name??e.key;return[typeof t==`string`?t:``,e.value]}):bv(e)?Object.entries(e):[]}function wv(e,t){let n=[...t];return Cv(e).map(([e,t])=>{let r=Gi(`kv`,n);return n.push(r),{id:r,key:e,raw:xv(t)}})}function Tv(e,t){let n=new Set;if(t){let t=[];for(let r of e){let e=r.key.trim();!e||n.has(e)||(n.add(e),t.push({variable:e,value:Sv(r.raw)}))}return t}let r={};for(let t of e){let e=t.key.trim();!e||n.has(e)||(n.add(e),r[e]=Sv(t.raw))}return r}function Ev(e){if(Array.isArray(e))return JSON.stringify(e);let t=e??{},n=Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{});return JSON.stringify(n)}function Dv({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l,scopeGroups:u}){let d=Array.isArray(t),f=X.useMemo(()=>Ev(Tv(wv(t,[]),d)),[t,d]),[p,m]=X.useState(()=>wv(t,[])),h=X.useRef(f);X.useEffect(()=>{f!==h.current&&(m(wv(t,[])),h.current=f)},[f,t]);let g=e=>{let t=Tv(e,d);h.current=Ev(t),n((Array.isArray(t)?t.length===0:Object.keys(t).length===0)?void 0:t)},_=(e,t)=>{m(n=>n.map(n=>n.id===e?{...n,...t}:n))},v=()=>{m(e=>[...e,{id:Gi(`kv`,e.map(e=>e.id)),key:``,raw:``}])},y=e=>{m(t=>{let n=t.filter(t=>t.id!==e);return g(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[p.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),p.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{value:e.key,onChange:t=>_(e.id,{key:t.target.value}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:r,className:`h-8 flex-1 font-mono text-xs`}),(0,Y.jsx)(vv,{mode:`template`,value:e.raw,onValueChange:t=>_(e.id,{raw:t}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:s,disabled:r,className:`flex-1`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>y(e.id),disabled:r,"aria-label":c,title:c,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(yv,{value:e.raw,role:`template`,scopeGroups:u})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function Ov(e,t){let n=[...t];return e.map(e=>{let t=Gi(`sl`,n);return n.push(t),{id:t,value:e}})}function kv(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Av({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=X.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=X.useState(()=>Ov(c,[])),d=X.useRef(JSON.stringify(c));X.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Ov(c,[])),d.current=e)},[c]);let f=e=>{let t=kv(e);d.current=JSON.stringify(t),n(t.length?t:void 0)},p=(e,t)=>{u(n=>n.map(n=>n.id===e?{...n,value:t}:n))},m=()=>{u(e=>[...e,{id:Gi(`sl`,e.map(e=>e.id)),value:``}])},h=e=>{u(t=>{let n=t.filter(t=>t.id!==e);return f(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(B,{value:e.value,onChange:t=>p(e.id,t.target.value),onBlur:()=>f(l),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:a,disabled:r,className:`h-8 flex-1 text-xs`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(e.id),disabled:r,"aria-label":o,title:o,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var jv={object:`object`,flow:`flow`,position:`position`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`},Mv=[{value:`owner`,label:`Owner`},{value:`admin`,label:`Admin`},{value:`member`,label:`Member`}];function Nv(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource,connectorSource:e.connectorSource};if(e.kindFrom&&e.map){let n=t(e.kindFrom),r=typeof n==`string`?e.map[n]:void 0;if(r)return{kind:r,objectSource:e.objectSource,connectorSource:e.connectorSource}}}}function Pv(e,t){let n=e?.config;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[t];return typeof r==`string`&&r?r:void 0}function Fv(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Pv((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Pv(n.node,r)}function Iv(e,t,n){if(e!==`connector-action`)return;let r=n.node?.connectorConfig;if(!r||typeof r!=`object`||Array.isArray(r))return;let i=r[t||`connectorId`];return typeof i==`string`&&i?i:void 0}function Lv(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.key==`string`&&!!e.key).map(e=>({value:e.key,label:typeof e.label==`string`&&e.label&&e.label!==e.key?`${e.label} (${e.key})`:e.key})):[]}function Rv(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.name==`string`&&!!e.name).map(e=>{let t=typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name;return{value:e.name,label:e.origin===`declarative`?`${t} · declarative`:t}}):[]}function zv(e){let t=Ai(),[n,r]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{if(n)return;let t=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));r({options:t,loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}function Bv(e){let[t,n]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){n({options:[],loading:!1});return}let t=!1;return n(e=>({...e,loading:!0})),fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(r=>{if(t)return;let i=r?.data?.connectors??r?.connectors??[],a=Array.isArray(i)?i.find(t=>t?.name===e):void 0;n({options:Lv(a?.actions),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Vv(e){let[t,n]=X.useState({options:[]});return X.useEffect(()=>{if(!e){n({options:[]});return}let t=!1;return fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>{if(t)return;let r=e?.data?.connectors??e?.connectors??[];n({options:Rv(r)})}).catch(()=>{t||n({options:[]})}),()=>{t=!0}},[e]),t}function Hv({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=X.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?Fv(e.kind,e.objectSource,l):void 0,{fields:f}=Ki(u===`object-field`?d:void 0),p=e?Iv(e.kind,e.connectorSource,l):void 0,{options:m}=Bv(u===`connector-action`?p:void 0),{options:h}=Vv(u===`connector`),g=u&&u!==`object-field`&&u!==`node`&&u!==`connector-action`&&u!==`connector`?jv[u]:void 0,{options:_}=zv(g),v=X.useMemo(()=>{if(u===`object-field`)return f.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(u===`connector-action`)return m;if(u===`connector`)return h;if(u===`org-membership-level`)return Mv;if(u===`node`){let e=Array.isArray(l.draft.nodes)?l.draft.nodes:[],t=typeof l.node?.id==`string`?l.node.id:void 0;return e.filter(e=>typeof e?.id==`string`&&e.id&&e.id!==t).map(e=>{let t=String(e.id);return{value:t,label:typeof e.label==`string`&&e.label?`${e.label} (${t})`:t}})}return g?_:[]},[u,g,f,m,h,_,l.draft,l.node]),y=u===`object-field`&&!d,b=u===`connector-action`&&!p;return(0,Y.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,Y.jsx)(B,{list:v.length?c:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:a,disabled:i,className:`h-8 text-sm`}),v.length>0&&(0,Y.jsx)(`datalist`,{id:c,children:v.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&y&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`}),s&&u===`connector-action`&&p&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Actions of `,p,`.`]}),s&&b&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Choose a Connector above to list its actions.`})]})}function Uv({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Nv(e.ref,e=>Pv(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(Hv,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function Wv(e){return e===`stringList`||e===`numberList`||e===`objectList`}function Gv(e,t){let n=[];return e.map(e=>{let r=Gi(`ol`,n);n.push(r);let i={};for(let n of t){let t=e[n.key];n.kind===`boolean`?i[n.key]=t===!0:Wv(n.kind)?i[n.key]=Array.isArray(t)?t:[]:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function Kv(e,t){let n=[];for(let r of e){let e={},i=!1;for(let n of t){let t=r.values[n.key];n.kind===`boolean`?t===!0&&(e[n.key]=!0,i=!0):Wv(n.kind)?Array.isArray(t)&&t.length>0&&(e[n.key]=t,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function qv({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u}){let d=X.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[f,p]=X.useState(()=>Gv(d,t)),m=X.useRef(JSON.stringify(d));X.useEffect(()=>{let e=JSON.stringify(d);e!==m.current&&(p(Gv(d,t)),m.current=e)},[d,t]);let h=e=>{let n=Kv(e,t);m.current=JSON.stringify(n),r(n.length?n:void 0)},g=(e,t,n)=>{p(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},_=(e,t,n)=>{p(r=>{let i=r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r);return h(i),i})},v=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:Wv(n.kind)?[]:``;p(t=>[...t,{id:Gi(`ol`,t.map(e=>e.id)),values:e}])},y=e=>{p(t=>{let n=t.filter(t=>t.id!==e);return h(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[f.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),f.map(e=>(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>y(e.id),disabled:i,"aria-label":o,title:o,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>{if(t.kind===`stringList`||t.kind===`numberList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,Y.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,Y.jsx)(Av,{label:t.label,value:t.kind===`numberList`?r.map(e=>String(e)):r,onCommit:n=>{if(t.kind===`numberList`){let r=(n??[]).map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));_(e.id,t.key,r)}else _(e.id,t.key,n??[])},disabled:i,addLabel:a,itemLabel:c??t.label,removeLabel:o,emptyLabel:s})},t.key)}if(t.kind===`objectList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,Y.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,Y.jsx)(qv,{label:t.label,columns:t.columns??[],value:r,onCommit:n=>_(e.id,t.key,n??[]),disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u})},t.key)}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(un,{checked:e.values[t.key]===!0,onCheckedChange:n=>_(e.id,t.key,n===!0),disabled:i}):t.kind===`reference`?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(Hv,{resolved:Nv(t.ref,t=>e.values[t]),value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>g(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>h(f),placeholder:t.placeholder,disabled:i,context:l,showHint:!1})}):t.kind===`select`?(()=>{let n=typeof e.values[t.key]==`string`?e.values[t.key]:``,r=t.options??[],a=n&&!r.some(e=>e.value===n)?[...r,{value:n,label:`${n} (deprecated)`}]:r;return(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(oe,{value:n||void 0,onValueChange:n=>_(e.id,t.key,n),disabled:i,children:[(0,Y.jsx)(fr,{className:`h-8 w-full text-xs`,children:(0,Y.jsx)(Dr,{placeholder:t.placeholder??`—`})}),(0,Y.jsx)(En,{children:a.map(e=>(0,Y.jsx)(Pr,{value:e.value,children:e.label},e.value))})]})})})():t.kind===`expression`?(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(vv,{mode:`expression`,mono:!0,value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onValueChange:n=>g(e.id,t.key,n),onBlur:()=>h(f),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:t.placeholder,disabled:i}),(0,Y.jsx)(yv,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,role:`predicate`,scopeGroups:u})]}):(0,Y.jsx)(B,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>g(e.id,t.key,n.target.value),onBlur:()=>h(f),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:t.placeholder,disabled:i,className:`h-8 flex-1 text-xs`})]},t.key)})})]},e.id))]}),(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:i,children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function Jv({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a,scopeGroups:o}){let s=e.refMode??(e.kind===`expression`?`expression`:`template`),c=(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(Uv,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(Dv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.kv.add`,i),keyLabel:G(`engine.inspector.flowNode.kv.key`,i),valueLabel:G(`engine.inspector.flowNode.kv.value`,i),removeLabel:G(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:G(`engine.inspector.flowNode.kv.empty`,i),scopeGroups:o});case`stringList`:return(0,Y.jsx)(Av,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i)});case`numberList`:return(0,Y.jsx)(Av,{label:e.label,value:Array.isArray(t)?t.map(e=>String(e)):t,onCommit:e=>{if(e==null)return n(void 0);let t=e.map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));n(t.length?t:void 0)},disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Y.jsx)(qv,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:G(`engine.inspector.flowNode.list.add`,i),removeLabel:G(`engine.inspector.flowNode.list.remove`,i),emptyLabel:G(`engine.inspector.flowNode.list.empty`,i),itemLabel:G(`engine.inspector.flowNode.list.item`,i),context:a,scopeGroups:o});case`number`:return(0,Y.jsx)(Ii,{label:e.label,value:typeof t==`number`?t:t!=null&&t!==``?Number(t):void 0,placeholder:e.placeholder,onCommit:e=>n(e),disabled:r});case`boolean`:return(0,Y.jsx)(J,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(K,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(vv,{multiline:!0,rows:4,mode:s,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]});default:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(vv,{mode:s,mono:e.kind===`expression`,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]})}})(),l=s===`template`,u=e.kind===`expression`&&!l?sm(`predicate`,t):null,d=e.kind===`expression`?l?`template`:`predicate`:s===`template`&&(e.kind===`text`||e.kind===`textarea`)?`template`:null,f=!u&&d&&o&&o.length>0?rm(t,d,em(o.flatMap(e=>e.refs))):[];return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[c,u&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:u.message}),!u&&f.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(f)}),e.help&&!u&&f.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}var Yv=[`variables`,`outputs`,`loop`,`trigger`],Xv={variables:`Flow variables`,outputs:`Upstream outputs`,loop:`Loop item`,trigger:`Trigger record`};function Zv(e,t,n){let r=X.useMemo(()=>Xp(e??{},t),[e,t]),{fields:i,loading:a}=Ki(r.trigger?.objectName);return X.useMemo(()=>{let e=[...r.refs];n&&n.length&&e.push(...n),r.trigger&&e.push(...Zp(r.trigger,i));let t=new Set,o=e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0));return{groups:Yv.map(e=>({id:e,label:Xv[e],refs:o.filter(t=>t.group===e)})).filter(e=>e.refs.length>0),refs:o,loading:!!r.trigger&&a,isEmpty:o.length===0}},[r,i,a,n])}function Qv(e){return e.kind===`objectList`&&zp(e)===`conditions`&&(e.columns??[]).some(e=>e.key===`target`)}function $v(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function ey(e,t,n){let[r,...i]=t,a={...e};if(i.length===0)n==null||n===``?delete a[r]:a[r]=n;else{let e=a[r],t=ey(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function ty({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=X.useMemo(()=>Bm(t,e),[t,e]),s=o?.node??null,c=Op(),l=X.useMemo(()=>o?.nested&&o.container?Jp(o.container).filter(e=>e.group===`loop`):[],[o]),{groups:u}=Zv(t,o?.scopeAnchorId,l),d=X.useMemo(()=>{let e=s?.type?c[s.type]:void 0;return(e===void 0?null:ev(e))??Lp(s?.type)},[c,s?.type]),f=$v(s),p=d.filter(e=>Bp(e,s,d)),m=X.useMemo(()=>{let e=Array.isArray(t.variables)?t.variables:[],n={};for(let t of e)t&&typeof t.name==`string`&&(n[t.name]=t.defaultValue);return n},[t]),h=X.useMemo(()=>{let e=new Set;for(let t of d){let n=zp(t);n&&e.add(n),t.fallbackPath&&t.fallbackPath.length>=2&&t.fallbackPath[0]===`config`&&e.add(t.fallbackPath[1])}return e},[d]),g=X.useMemo(()=>{let e=Object.fromEntries(Object.entries(f).filter(([e])=>!h.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[s,h]),[_,v]=X.useState(g),[y,b]=X.useState(null),[x,S]=X.useState(g.trim()!==``),[C,w]=X.useState(!1);if(X.useEffect(()=>{v(g),b(null),S(g.trim()!==``),w(!1)},[g]),!s){let t=(e.kind===`nested-node`?Mm(e.id):null)?.nodeId??e.id;return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:e.label??t,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),children:(0,Y.jsx)(Yi,{message:t})})}let T=e=>{let t=o?.write({...s,...e});t&&n(t)},E=g.trim()!==``,D=s.type===`screen`||s.type===`user_task`,O=(e,r)=>{if(!o)return;let i=e.path,a=r,c;if(!o.nested){let n=Array.isArray(t.edges)?t.edges:[];if(Qv(e)){let e=fv(s.id,r,n);a=e.conditions.length?e.conditions:void 0,c=e.edges}else s.type===`decision`&&i.length===2&&i[0]===`config`&&i[1]===`conditions`&&(c=uv(s.id,r,n))}let l=ey(s,i,a);e.fallbackPath&&(l=ey(l,e.fallbackPath,void 0));let u=o.write(l);u&&(c&&(u.edges=c),n(u))},k=()=>{try{let e=_.trim()===``?{}:JSON.parse(_);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(f).filter(([e])=>h.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!h.has(e))),i={...t,...r};b(null);let a={...s};Object.keys(i).length===0?delete a.config:a.config=i;let c=o?.write(a);c&&n(c)}catch(e){b(String(e.message))}},A=()=>{let e=o?.write(null);e&&n(e),r()},ee=Vp.includes(s.type)?[...Vp]:[...Vp,s.type??``].filter(Boolean),j=!!o?.nested;return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.flowNode.kind`,i),title:s.label||s.id,onClose:r,closeLabel:G(`engine.inspector.flowNode.close`,i),footer:j?void 0:(0,Y.jsx)(xa,{label:G(`engine.inspector.flowNode.remove`,i),onClick:A,disabled:a}),children:[j&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-[11px] text-muted-foreground`,"aria-label":`nested node location`,children:[(0,Y.jsx)(`span`,{className:`max-w-[45%] truncate font-medium`,children:o?.container?.label||o?.container?.id}),(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,Y.jsx)(`span`,{className:`truncate`,children:o?.regionLabel}),(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,Y.jsx)(`span`,{className:`max-w-[45%] truncate font-medium text-foreground`,children:s.label||s.id})]}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.id`,i),value:s.id,onCommit:e=>T({id:e}),disabled:a||j,mono:!0}),j&&(0,Y.jsx)(`p`,{className:`-mt-1 text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowNode.nestedIdHint`,i)}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.label`,i),value:s.label??``,onCommit:e=>T({label:e}),disabled:a}),(0,Y.jsx)(K,{label:G(`engine.inspector.flowNode.type`,i),value:s.type,options:ee.map(e=>({value:e,label:e})),onCommit:e=>T({type:e}),disabled:a}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowNode.description`,i),value:s.description??``,onCommit:e=>T({description:e||void 0}),disabled:a}),d.length===0?(0,Y.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:G(`engine.inspector.flowNode.noConfig`,i)}):p.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowNode.configuration`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.map(e=>{let n=Qv(e),r=j&&n?{...e,columns:(e.columns??[]).filter(e=>e.key!==`target`)}:e;return(0,Y.jsx)(Jv,{field:r,value:n&&!j?dv(s.id,Rp(s,e),Array.isArray(t.edges)?t.edges:[]):Rp(s,r),onCommit:t=>O(e,t),disabled:a,locale:i,context:{draft:t,node:s},scopeGroups:u},e.id)}),D&&(0,Y.jsx)(eh,{node:s,variables:m,className:`mt-1`}),E||C?(0,Y.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:x,onToggle:e=>S(e.target.open),children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:G(`engine.inspector.flowNode.advanced`,i)}),(0,Y.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowNode.advancedHint`,i)}),(0,Y.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),onBlur:k,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),y&&(0,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:y})]})]}):!a&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{w(!0),S(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`engine.inspector.flowNode.advanced`,i)]})]})}function ny({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`div`,{className:`flex h-8 items-center rounded border bg-muted/30 px-2 font-mono text-sm text-muted-foreground`,children:t})]})}function ry({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.edges)?t.edges:[],s=o.findIndex((t,n)=>ip(t,n)===e.id),c=s>=0?o[s]:null,{groups:l}=Zv(t,c?.source);if(!c)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),children:(0,Y.jsx)(Yi,{message:G(`engine.inspector.flowEdge.missing`,i)})});let u=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}(t.type==="default"||t.type===``||t.type===void 0)&&delete t.type,n({edges:la(o,s,t)})},d=c.isDefault===!0,f=(Array.isArray(t.nodes)?t.nodes:[]).find(e=>e.id===c.source),p=f?.type===`decision`&&Array.isArray(f.config?.conditions)?f.config.conditions:[],m=e=>typeof e.expression==`string`?e.expression.trim():``,h=e=>typeof e.label==`string`?e.label.trim():``,g=(()=>{if(!p.length)return``;if(d){let e=p.findIndex(e=>{let t=m(e);return t===``||t===`true`});return e>=0?String(e):``}let e=ap(c.condition),t=e?p.findIndex(t=>m(t)===e):-1;return t<0&&c.label&&(t=p.findIndex(e=>h(e)===c.label)),t>=0?String(t):``})(),_=e=>{if(e===``)return;let t=p[Number(e)];if(!t)return;let n=m(t),r=h(t)||void 0;u(n===``||n===`true`?{isDefault:!0,condition:void 0,label:r}:{isDefault:!1,condition:n,label:r})},v=f?.type===`approval`,y=[`approve`,`reject`,`revise`],b=(()=>{let e=(c.label??``).trim().toLowerCase();return y.includes(e)?e:``})(),x=typeof c.type==`string`&&c.type||`default`;return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:G(`engine.inspector.flowEdge.close`,i),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:la(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(ny,{label:G(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(ny,{label:G(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowEdge.routing`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.length>0&&(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.branch`,i),value:g,options:[...p.map((e,t)=>{let n=m(e),r=h(e)||`Branch ${t+1}`,i=n===``||n===`true`?` · default`:` \u00b7 ${n}`;return{value:String(t),label:`${r}${i}`}}),{value:``,label:`— Custom —`}],onCommit:_,disabled:a}),v&&(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.approvalBranch`,i),value:b,options:[{value:`approve`,label:G(`engine.inspector.flowEdge.branchApprove`,i)},{value:`reject`,label:G(`engine.inspector.flowEdge.branchReject`,i)},{value:`revise`,label:G(`engine.inspector.flowEdge.branchRevise`,i)},{value:``,label:G(`engine.inspector.flowEdge.branchCustom`,i)}],onCommit:e=>{e&&u({label:e})},disabled:a}),(0,Y.jsx)(q,{label:G(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>u({label:e}),placeholder:G(`engine.inspector.flowEdge.labelHint`,i),disabled:a||d}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:G(`engine.inspector.flowEdge.condition`,i)}),(0,Y.jsx)(vv,{mode:`expression`,mono:!0,value:ap(c.condition)??``,onValueChange:e=>u({condition:e||void 0}),groups:l,placeholder:G(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||d})]}),(()=>{let e=d?null:sm(`predicate`,c.condition);if(e)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message});let t=d?[]:rm(ap(c.condition),`predicate`,em(l.flatMap(e=>e.refs)));return t.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:im(t)}):null})(),(0,Y.jsx)(J,{label:G(`engine.inspector.flowEdge.isDefault`,i),value:d,onCommit:e=>u(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:G(`engine.inspector.flowEdge.hint`,i)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:G(`engine.inspector.flowEdge.connection`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Y.jsx)(K,{label:G(`engine.inspector.flowEdge.type`,i),value:x,options:[{value:`default`,label:G(`engine.inspector.flowEdge.typeDefault`,i)},{value:`conditional`,label:G(`engine.inspector.flowEdge.typeConditional`,i)},{value:`fault`,label:G(`engine.inspector.flowEdge.typeFault`,i)},{value:`back`,label:G(`engine.inspector.flowEdge.typeBack`,i)}],onCommit:e=>u({type:e}),disabled:a}),c.type===`back`&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:G(`engine.inspector.flowEdge.backHint`,i)})]})}function iy(e){return e.selection.kind===`edge`?(0,Y.jsx)(ry,{...e}):(0,Y.jsx)(ty,{...e})}var ay=[`field`,`label`,`accessorKey`,`header`];function oy(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function sy(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function cy(e){return e.field??e.accessorKey??``}function ly(e){return e.label??e.header??cy(e)}function uy(e){return Object.keys(e).some(e=>!ay.includes(e))}function dy(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function fy({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=oy(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(sy),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=X.useMemo(()=>es(),[]),m=dy(c),{fields:h}=Ki(m||void 0),g=d?cy(d):``,_=X.useMemo(()=>{let e=h.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} · ${e.name}`:e.name}));return g&&!e.some(e=>e.value===g)&&e.unshift({value:g,label:`${g} (not in object)`}),e},[h,g]);if(!s||!d)return(0,Y.jsx)(Li,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),children:(0,Y.jsx)(Yi,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=cy(e);return n&&!uy(e)&&!e.label&&!e.header&&r?r:e});n({[s.variant]:{...c,columns:t}})},y=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),v(la(u,s.index,{...d,...r}))};return(0,Y.jsxs)(Li,{kindLabel:G(`engine.inspector.viewColumn.kind`,a),title:ly(d)||e.id,onClose:r,closeLabel:G(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(Xi,{index:s.index,total:u.length,onMove:e=>{v(Pi(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:ly(d)||`columns[${e}]`})},upLabel:G(`engine.inspector.reorder.up`,a),downLabel:G(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(xa,{label:G(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(la(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(Lo,{variantKey:s.variant,schema:c,columns:l,allStrings:l.length>0&&l.every(e=>typeof e==`string`),objectName:m||void 0,selectedIndex:s.index,readOnly:o,onPatch:n,onSelectionChange:i})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,Y.jsx)(K,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:cy(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(q,{label:G(`engine.inspector.viewColumn.accessorKey`,a),value:cy(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(q,{label:G(`engine.inspector.viewColumn.header`,a),value:ly(d)===cy(d)?``:ly(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(ha,{schema:p,value:d,hiddenFields:ay,readOnly:o,onChange:e=>{v(la(u,s.index,e))}})}):null]})]})}function py(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(fy,{...e});let n=ls(e.draft,t.id||void 0)??cs(e.draft);return(0,Y.jsx)(_s,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function my(e){let t=cs(e.draft);return(0,Y.jsx)(_s,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var hy={io:`input`,unrepresentable:`any`},gy=new Set([`name`,`regions`,`children`]),_y,vy=!1;function yy(){if(_y||vy)return _y;try{_y=E(ne,hy)}catch(e){vy=!0,typeof console<`u`&&console.warn(`[page-schema] failed to derive Page JSONSchema from spec`,e)}return _y}var by;function xy(){if(by)return by;if(!(!w||typeof w!=`object`)){try{let e=JSON.parse(JSON.stringify(w));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!gy.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),by=e}catch(e){typeof console<`u`&&console.warn(`[page-schema] failed to prune Page authoring form from spec`,e),by=w}return by}}function Sy({draft:e,onPatch:t,readOnly:n,serverSchema:r,locale:i}){let{schema:a,form:o}=X.useMemo(()=>ta({bundledSchema:yy(),bundledForm:xy(),serverSchema:r,excludeFields:gy,sectionTitle:G(`engine.inspector.moreFields`,i)}),[r,i]);return a?(0,Y.jsx)(ha,{schema:a,form:o,value:e,hiddenFields:[...gy],readOnly:n,onChange:e=>t(e)}):(0,Y.jsx)(`p`,{className:`px-1 py-2 text-xs text-muted-foreground`,children:G(`engine.studio.inspector.noPageSchema`,i)})}var Cy=e=>(e??``).toLowerCase().startsWith(`zh`);function wy(e){let t=e.options;return Array.isArray(t)?t.map(e=>({value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0})):[]}function Ty(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Ey(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Dy(e){return e===`formula`||e===`summary`}function Oy(e){return e===`number`||e===`currency`||e===`percent`}function ky(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Ay(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}var jy=[`record`,`previous`,`parent`],My=[`record`];function Ny(e){return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:``}function Py(e,t){if(t.trim()){if(e&&typeof e==`object`&&!Array.isArray(e)){let n=e;return{...n,dialect:typeof n.dialect==`string`?n.dialect:`cel`,source:t}}return t}}function Fy(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?da:ra;return aa.flatMap(e=>e.types.map(r=>{let i=ia[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function Iy({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=X.useCallback(e=>G(e,o),[o]),c=X.useMemo(()=>Fy(o),[o]),l=X.useMemo(()=>Qi(t.fields),[t]),u=String(e.id),d=Ji(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=nb(),h=X.useRef(!1);if(X.useEffect(()=>{h.current=!1},[u]),!f)return(0,Y.jsx)(Li,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Y.jsx)(Yi,{message:s(`designer.field.missing`)})});let g=f.def,_=typeof g.type==`string`?g.type:`text`,v=ia[_],y=e=>{n({fields:Hi(e)})},b=e=>{let t=[...l.entries];t[d]={...f,def:{...g,...e}},y({shape:l.shape,entries:t})},x=e=>{let t=Ui(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},y({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(g.label??t)})},S=e=>{if(a)return null;let t=_===`select`?`status`:_;if(!(f.name===t||f.name.startsWith(`${t}_`)&&/^\d+$/.test(f.name.slice(t.length+1))||/^field_\d+$/.test(f.name)))return null;let n=Ui(e);return!n||n===f.name||l.entries.some((e,t)=>t!==d&&e.name===n)?null:n},C=()=>{let e=l.entries.filter((e,t)=>t!==d);y({shape:l.shape,entries:e}),r()},w=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof g.label==`string`&&g.label?g.label:``,o={name:n,def:{...g,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),y({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},T=e=>{let t={shape:l.shape,entries:Pi(l.entries,d,e)};y(t)},E=wy(g),D=e=>{let t=e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t});b({options:t})},O=(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:w,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,Y.jsx)(Pn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Xi,{index:d,total:l.entries.length,onMove:T,disabled:a})]}),k=(0,Y.jsx)(xa,{label:W(`designer.field.remove`,o,{label:typeof g.label==`string`?g.label:f.name}),onClick:C,disabled:a}),A=Cy(o)?v?.labelZh:v?.label;return(0,Y.jsxs)(Li,{kindLabel:s(`designer.field.kind`),title:typeof g.label==`string`&&g.label?g.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:O,footer:k,children:[(0,Y.jsxs)(Ly,{title:s(`designer.field.section.basic`),children:[(0,Y.jsx)(q,{label:s(`designer.field.apiName`),value:f.name,onCommit:x,disabled:a,mono:!0,testId:`field-apiname-input`}),(0,Y.jsx)(q,{label:s(`designer.field.label`),value:typeof g.label==`string`?g.label:``,onCommit:e=>{let t=S(e),n=[...l.entries];n[d]={...f,name:t??f.name,def:{...g,label:e}},y({shape:l.shape,entries:n}),t&&i?.({kind:`field`,id:t,label:e})},disabled:a,testId:`field-label-input`}),(0,Y.jsx)(K,{label:s(`designer.field.type`),value:_,options:c,onCommit:e=>b({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(J,{label:s(`designer.field.required`),value:!!g.required,onCommit:e=>b({required:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.unique`),value:!!g.unique,onCommit:e=>b({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(zy,{label:s(`designer.field.description`),value:typeof g.description==`string`?g.description:``,onCommit:e=>b({description:e||void 0}),disabled:a,rows:2}),Ay(_)&&(0,Y.jsx)(Ry,{kind:Ay(_),value:g.defaultValue,options:E,onCommit:e=>b({defaultValue:e}),disabled:a,locale:o}),(0,Y.jsx)(zy,{label:s(`designer.field.helpText`),value:typeof g.inlineHelpText==`string`?g.inlineHelpText:``,onCommit:e=>b({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(Ty(_)||Ey(_)||Dy(_)||Oy(_)||ky(_))&&(0,Y.jsxs)(Ly,{title:W(`designer.field.section.options`,o,{type:A??_}),children:[Ty(_)&&(0,Y.jsx)(Vy,{options:E,onChange:D,disabled:a,locale:o},f.name),Ey(_)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(By,{label:s(`designer.field.relatedObject`),value:typeof g.reference==`string`?g.reference:``,options:m,onCommit:e=>b({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(q,{label:s(`designer.field.relationshipName`),value:typeof g.relationshipName==`string`?g.relationshipName:``,onCommit:e=>b({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)}),(0,Y.jsx)(Gy,{def:g,patchDef:b,hostFieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),readOnly:a,locale:o})]}),_===`formula`&&(0,Y.jsx)(ea,{id:`field-formula-${f.name}`,label:s(`designer.field.formula`),value:Ny(g.expression??g.formula),onChange:e=>{h.current=!0,b({expression:Py(g.expression??g.formula,e),formula:void 0,...e.trim()?{}:{returnType:void 0}})},onInferredTypeChange:e=>{if(!h.current)return;let t=e&&e!==`unknown`?e:void 0;g.returnType!==t&&b({returnType:t})},disabled:a,placeholder:`record.amount * 0.2`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),scope:`record`,roots:My,role:`value`,t:s}),_===`summary`&&(0,Y.jsx)(tb,{def:g,patchDef:b,objectOptions:m,readOnly:a,locale:o}),Oy(_)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(Ii,{label:s(`designer.field.precision`),value:typeof g.precision==`number`?g.precision:void 0,onCommit:e=>b({precision:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.scale`),value:typeof g.scale==`number`?g.scale:void 0,onCommit:e=>b({scale:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.min`),value:typeof g.min==`number`?g.min:void 0,onCommit:e=>b({min:e}),disabled:a}),(0,Y.jsx)(Ii,{label:s(`designer.field.max`),value:typeof g.max==`number`?g.max:void 0,onCommit:e=>b({max:e}),disabled:a})]}),ky(_)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(Ii,{label:s(`designer.field.minLength`),value:typeof g.minLength==`number`?g.minLength:void 0,onCommit:e=>b({minLength:e}),disabled:a,placeholder:`0`}),(0,Y.jsx)(Ii,{label:s(`designer.field.maxLength`),value:typeof g.maxLength==`number`?g.maxLength:void 0,onCommit:e=>b({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,Y.jsxs)(Ly,{title:s(`designer.field.section.advanced`),children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(J,{label:s(`designer.field.readonly`),value:!!g.readonly,onCommit:e=>b({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.hidden`),value:!!g.hidden,onCommit:e=>b({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.indexed`),value:!!g.indexed,onCommit:e=>b({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.externalId`),value:!!g.externalId,onCommit:e=>b({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(J,{label:s(`designer.field.trackHistory`),value:!!g.trackHistory,onCommit:e=>b({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(q,{label:s(`designer.field.placeholder`),value:typeof g.placeholder==`string`?g.placeholder:``,onCommit:e=>b({placeholder:e||void 0}),disabled:a}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:s(`designer.field.conditionalRules`)}),(0,Y.jsx)(ea,{id:`field-rule-visible-${f.name}`,label:s(`designer.field.visibleWhen`),value:Ny(g.visibleWhen),onChange:e=>b({visibleWhen:Py(g.visibleWhen,e)}),disabled:a,placeholder:`record.status != 'draft'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(ea,{id:`field-rule-readonly-${f.name}`,label:s(`designer.field.readonlyWhen`),value:Ny(g.readonlyWhen),onChange:e=>b({readonlyWhen:Py(g.readonlyWhen,e)}),disabled:a,placeholder:`record.status == 'closed'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(ea,{id:`field-rule-required-${f.name}`,label:s(`designer.field.requiredWhen`),value:Ny(g.requiredWhen??g.conditionalRequired),onChange:e=>b({requiredWhen:Py(g.requiredWhen??g.conditionalRequired,e),conditionalRequired:void 0}),disabled:a,placeholder:`record.amount > 10000`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:jy,t:s}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRulesHint`)})]}),p.length>0&&(0,Y.jsx)(K,{label:s(`designer.field.group`),value:typeof g.group==`string`?g.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>b({group:e||void 0}),disabled:a})]})]})}function Ly({title:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:t})]})}function Ry({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=G(`designer.field.defaultValue`,a),s=G(`designer.field.defaultNone`,a);return e===`bool`?(0,Y.jsx)(K,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:G(`designer.field.true`,a)},{value:`false`,label:G(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Y.jsx)(Ii,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Y.jsx)(K,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,Y.jsx)(q,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function zy({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:t,disabled:r,rows:i,placeholder:o,onChange:e=>n(e.target.value),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary `+(a?`font-mono text-xs `:``)})]})}function By({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=X.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(B,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,Y.jsx)(`datalist`,{id:o,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Vy({options:e,onChange:t,disabled:n,locale:r}){let[i,a]=X.useState(()=>e.length>0?e:[{value:``,label:``}]),o=e=>{a(e),t(e.filter(e=>e.value.trim()!==``))},s=(e,t)=>{let n=[...i];n[e]={...n[e],...t},o(n)},c=e=>o(i.filter((t,n)=>n!==e)),l=(e,t)=>o(Pi(i,e,t));return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:G(`designer.field.picklistValues`,r)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:i.length})]}),i.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:G(`designer.field.noValues`,r)}):(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:i.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/60 p-1.5 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(B,{value:e.value,onChange:e=>s(t,{value:e.target.value}),placeholder:G(`designer.field.optValue`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs font-mono`}),(0,Y.jsx)(B,{value:e.label??``,onChange:e=>s(t,{label:e.target.value}),placeholder:G(`designer.field.optLabel`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`color`,value:e.color??`#cccccc`,onChange:e=>s(t,{color:e.target.value}),disabled:n,className:`h-6 w-6 rounded border bg-background cursor-pointer p-0.5`,title:G(`designer.field.optColor`,r)}),(0,Y.jsx)(`span`,{className:`flex-1`}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t-1),disabled:n||t===0,"aria-label":G(`designer.field.moveUp`,r),children:(0,Y.jsx)(Qr,{className:`h-3 w-3`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t+1),disabled:n||t===i.length-1,"aria-label":G(`designer.field.moveDown`,r),children:(0,Y.jsx)(pe,{className:`h-3 w-3`})}),(0,Y.jsx)(L,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,onClick:()=>c(t),disabled:n,"aria-label":G(`designer.field.removeValue`,r),children:(0,Y.jsx)(Se,{className:`h-3 w-3`})})]})]},t))}),!n&&(0,Y.jsxs)(L,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>o([...i,{value:``,label:``}]),children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),G(`designer.field.addValue`,r)]})]})}var Hy=[{value:`eq`,label:`= equals`},{value:`ne`,label:`≠ not equals`},{value:`gt`,label:`> greater than`},{value:`lt`,label:`< less than`},{value:`gte`,label:`≥ at least`},{value:`lte`,label:`≤ at most`},{value:`contains`,label:`contains`},{value:`in`,label:`in (any of)`},{value:`notIn`,label:`not in`}];function Uy(e){let t=e.lookupFilters??e.lookup_filters;return Array.isArray(t)?t:[]}function Wy(e){let t=e.dependsOn??e.depends_on;return Array.isArray(t)?t.map(e=>typeof e==`string`?e:e&&typeof e==`object`?e.field:void 0).filter(e=>!!e):[]}function Gy({def:e,patchDef:t,hostFieldNames:n,readOnly:r,locale:i}){let a=e=>G(e,i),o=typeof e.reference==`string`?e.reference:void 0,{fields:s,loading:c}=Ki(o),l=X.useMemo(()=>s.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[s]),u=X.useMemo(()=>n.map(e=>({value:e,label:e})),[n]),d=Uy(e),f=Wy(e),p=(e,n)=>t({lookupFilters:d.map((t,r)=>r===e?{...t,...n}:t)}),m=()=>t({lookupFilters:[...d,{field:``,operator:`eq`,value:``}]}),h=e=>{let n=d.filter((t,n)=>n!==e);t({lookupFilters:n.length?n:void 0})},g=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e),_=(e,t)=>e===`in`||e===`notIn`?t.split(`,`).map(e=>e.trim()).filter(Boolean):t,v=e=>{!e||f.includes(e)||t({dependsOn:[...f,e]})},y=e=>{let n=f.filter(t=>t!==e);t({dependsOn:n.length?n:void 0})},b=typeof e.displayField==`string`?e.displayField:``,x=typeof e.descriptionField==`string`?e.descriptionField:``,S=typeof e.lookupPageSize==`number`?e.lookupPageSize:void 0,C=e.allowCreate===!0,w=a(o?`designer.field.lookup.selectField`:`designer.field.lookup.setTargetFirst`);return(0,Y.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:a(`designer.field.lookup.pickerConfig`)}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.displayField`),value:b,onCommit:e=>t({displayField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.descriptionField`),value:x,onCommit:e=>t({descriptionField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.selectableRecords`)}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),!r&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:m,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,a(`designer.field.lookup.addFilter`)]})]}),d.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.noFilter`,i,{ref:o||`related`})}):d.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":a(`designer.field.lookup.removeFilter`),className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>h(t),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>p(t,{field:e}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(K,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:Hy,onCommit:e=>p(t,{operator:e}),disabled:r}),(0,Y.jsx)(q,{label:a(`designer.field.lookup.filterValue`),value:g(e.value),onCommit:n=>p(t,{value:_(e.operator,n)}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t))]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.dependsOn`)}),f.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:f.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-0.5 text-[11px] font-mono`,children:[e,!r&&(0,Y.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>y(e),"aria-label":`Remove ${e}`,children:`×`})]},e))}),!r&&u.length>0&&(0,Y.jsx)(Ua,{value:``,onCommit:e=>v(e),options:u.filter(e=>!f.includes(e.value)),placeholder:a(`designer.field.lookup.addDependsOn`),searchPlaceholder:a(`designer.field.lookup.searchHostFields`),disabled:r,allowCustom:!1,mono:!0})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:[(0,Y.jsx)(Ii,{label:a(`designer.field.lookup.pageSize`),value:S,onCommit:e=>t({lookupPageSize:e}),placeholder:`10`,disabled:r}),(0,Y.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,Y.jsx)(J,{label:a(`designer.field.lookup.allowCreate`),value:C,onCommit:e=>t({allowCreate:e||void 0}),disabled:r})})]})]})}var Ky=[`count`,`sum`,`min`,`max`,`avg`];function qy(e){let t=e.summaryOperations;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}var Jy={ne:`$ne`,gt:`$gt`,lt:`$lt`,gte:`$gte`,lte:`$lte`,contains:`$contains`,in:`$in`,notIn:`$nin`},Yy={$eq:`eq`,$ne:`ne`,$gt:`gt`,$lt:`lt`,$gte:`gte`,$lte:`lte`,$contains:`contains`,$in:`in`,$nin:`notIn`},Xy=new Set([`number`,`currency`,`percent`,`rating`,`slider`,`autonumber`]);function Zy(e,t,n){let r=e=>{if(typeof e!=`string`)return e;let n=e.trim();if(t===`boolean`||t===`toggle`)return n===`true`||n===`1`;if(t&&Xy.has(t)){let t=Number(n);return n!==``&&Number.isFinite(t)?t:e}return e};return n?(Array.isArray(e)?e:String(e??``).split(`,`).map(e=>e.trim()).filter(Boolean)).map(r):r(e)}function Qy(e){if(!e||typeof e!=`object`||Array.isArray(e))return{rows:[],advanced:!1};let t=[],n=!1,r=e=>{for(let[i,a]of Object.entries(e)){if(i===`$and`&&Array.isArray(a)){for(let e of a)e&&typeof e==`object`&&!Array.isArray(e)?r(e):n=!0;continue}if(i.startsWith(`$`)){n=!0;continue}if(typeof a==`object`&&a&&!Array.isArray(a)){let e=Object.entries(a);if(e.length===0){n=!0;continue}for(let[r,a]of e){let e=Yy[r];e?t.push({field:i,operator:e,value:a}):n=!0}}else t.push({field:i,operator:`eq`,value:a})}};return r(e),{rows:t,advanced:n}}function $y(e,t){let n=e.filter(e=>e.field);if(n.length===0)return;let r=n.map(e=>{let n=e.operator===`in`||e.operator===`notIn`,r=Zy(e.value,t(e.field),n);return e.operator===`eq`?{[e.field]:r}:{[e.field]:{[Jy[e.operator]??`$eq`]:r}}});if(r.length===1)return r[0];let i=r.map(e=>Object.keys(e)[0]);return new Set(i).size===i.length?Object.assign({},...r):{$and:r}}var eb=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e);function tb({def:e,patchDef:t,objectOptions:n,readOnly:r,locale:i}){let a=e=>G(e,i),o=qy(e),s=typeof o.object==`string`?o.object:``,c=typeof o.function==`string`?o.function:``,{fields:l,loading:u}=Ki(s||void 0),d=e=>{let n={...o,...e};for(let e of Object.keys(n))(n[e]===void 0||n[e]===``)&&delete n[e];t({summaryOperations:Object.keys(n).length>0?n:void 0})},f=X.useMemo(()=>l.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),p=X.useMemo(()=>l.filter(e=>e.type===`lookup`||e.type===`master_detail`).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),m=a(s?`designer.field.lookup.selectField`:`designer.field.summary.setObjectFirst`),h=X.useCallback(e=>l.find(t=>t.name===e)?.type,[l]),{rows:g,advanced:_}=Qy(o.filter),v=e=>d({filter:$y(e,h)}),y=(e,t)=>v(g.map((n,r)=>r===e?{...n,...t}:n)),b=()=>v([...g,{field:f[0]?.value??``,operator:`eq`,value:``}]),x=e=>v(g.filter((t,n)=>n!==e));return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(By,{label:a(`designer.field.summary.object`),value:s,options:n,onCommit:e=>d({object:e||void 0}),disabled:r,placeholder:a(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(K,{label:a(`designer.field.summary.function`),value:c,options:[{value:``,label:a(`designer.field.defaultNone`)},...Ky.map(e=>({value:e,label:a(`designer.field.summary.fn.${e}`)}))],onCommit:e=>d({function:e||void 0}),disabled:r}),(0,Y.jsx)(Ua,{label:a(`designer.field.summary.field`),value:typeof o.field==`string`?o.field:``,onCommit:e=>d({field:e||void 0}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),c===`count`&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 px-0.5 -mt-1`,children:a(`designer.field.summary.countFieldHint`)}),(0,Y.jsx)(Ua,{label:a(`designer.field.summary.relationshipField`),value:typeof o.relationshipField==`string`?o.relationshipField:``,onCommit:e=>d({relationshipField:e||void 0}),options:p,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 border-t pt-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.field.summary.filterSection`)}),!_&&(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:g.length})]}),!r&&!_&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:b,disabled:f.length===0,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,a(`designer.field.summary.addFilter`)]})]}),_?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-[11px] text-muted-foreground`,children:a(`designer.field.summary.filterAdvanced`)}):g.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:a(`designer.field.summary.noFilter`)}):g.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:W(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":a(`designer.field.lookup.removeFilter`),className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>x(t),children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Ua,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>y(t,{field:e}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(K,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:Hy,onCommit:e=>y(t,{operator:e}),disabled:r}),(0,Y.jsx)(q,{label:a(`designer.field.lookup.filterValue`),value:eb(e.value),onCommit:e=>y(t,{value:e}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t)),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.filterHint`)})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.hint`)})]})}function nb(){let e=Ai(),[t,n]=X.useState([]);return X.useEffect(()=>{let t=!1;return Promise.all([e.list(`object`),e.listDrafts({type:`object`}).catch(()=>[])]).then(([e,r])=>{if(t)return;let i=new Map;for(let t of e??[])typeof t?.name==`string`&&t.name&&!i.has(t.name)&&i.set(t.name,{value:t.name,label:t.label?`${t.label} (${t.name})`:t.name});for(let e of r??[]){let t=e.name;typeof t==`string`&&t&&!i.has(t)&&i.set(t,{value:t,label:`${t} (草稿)`})}n([...i.values()].sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{t=!0}},[e]),t}function rb({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=X.useCallback(e=>G(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=X.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=ki(e)),n(t)},u=e=>{c.current=!0,n({name:Ui(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Y.jsxs)(Li,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:[(0,Y.jsxs)(lb,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Y.jsx)(ub,{hint:a(`designer.object.nameHint`),children:(0,Y.jsx)(q,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,testId:`object-name-input`,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Y.jsx)(q,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Y.jsx)(q,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,Y.jsx)(ub,{hint:a(`designer.object.iconHint`),children:(0,Y.jsx)(q,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,Y.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]}),(0,Y.jsx)(cb,{draft:t,onPatch:n,readOnly:r,tr:a})]})}var ib=[`read`,`create`,`update`,`delete`];function ab(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function ob(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).join(`, `):``}function sb(){let[e,t]=X.useState(!1);return X.useEffect(()=>{let e=!1;return a(()=>import(`./vendor-objectstack-CjHQG7Oa.js`).then(e=>e.f).then(n=>{e||t(n?.ObjectRequiredPermissionsSchema!==void 0)}),[],import.meta.url).catch(()=>{}),()=>{e=!0}},[]),e}function cb({draft:e,onPatch:t,readOnly:n,tr:r}){let i=sb(),a=e.access?.default===`private`?`private`:`public`,o=e.requiredPermissions,s=!!o&&typeof o==`object`&&!Array.isArray(o),c=s?`perOp`:`all`,l=e=>{t({access:e===`private`?{default:`private`}:void 0})},u=e=>{let n=ab(e);t({requiredPermissions:n.length>0?n:void 0})},d=(e,n)=>{let r=s?{...o}:{},i=ab(n);i.length>0?r[e]=i:delete r[e],t({requiredPermissions:Object.keys(r).length>0?r:void 0})},f=e=>{if(e!==c)if(e===`perOp`){let e=Array.isArray(o)?o:[];t({requiredPermissions:e.length>0?{read:e,create:e,update:e,delete:e}:{}})}else{let e=s?o:{},n=[...new Set(ib.flatMap(t=>Array.isArray(e[t])?e[t]:[]))];t({requiredPermissions:n.length>0?n:void 0})}};return(0,Y.jsxs)(lb,{title:r(`designer.object.section.access`),hint:r(`designer.object.section.accessHint`),children:[(0,Y.jsx)(ub,{hint:r(a===`private`?`designer.object.posture.privateHint`:`designer.object.posture.publicHint`),children:(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:r(`designer.object.posture`)}),(0,Y.jsxs)(`select`,{value:a,disabled:n,onChange:e=>l(e.target.value),"data-testid":`object-access-posture`,className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Y.jsx)(`option`,{value:`public`,children:r(`designer.object.posture.public`)}),(0,Y.jsx)(`option`,{value:`private`,children:r(`designer.object.posture.private`)})]})]})}),(0,Y.jsx)(ub,{hint:r(`designer.object.reqPerms.hint`),children:(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:r(`designer.object.reqPerms`)}),i&&(0,Y.jsxs)(`div`,{className:`inline-flex rounded border text-[11px]`,role:`group`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`all`),className:`px-1.5 py-0.5 rounded-l ${c===`all`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.all`)}),(0,Y.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`perOp`),"data-testid":`object-reqperms-perop`,className:`px-1.5 py-0.5 rounded-r border-l ${c===`perOp`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.perOp`)})]})]}),c===`all`?(0,Y.jsx)(q,{label:``,value:ob(o),onCommit:u,disabled:n,mono:!0,testId:`object-reqperms-all`,placeholder:r(`designer.object.reqPerms.placeholder`)}):(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ib.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-14 shrink-0 text-[11px] text-muted-foreground capitalize`,children:r(`designer.object.reqPerms.op.${e}`)}),(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(q,{label:``,value:ob(o?.[e]),onCommit:t=>d(e,t),disabled:n,mono:!0,testId:`object-reqperms-${e}`,placeholder:r(`designer.object.reqPerms.placeholder`)})})]},e))})]})})]})}function lb({title:e,hint:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:n})]})}function ub({hint:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var db={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,after:`$gt`,before:`$lt`,contains:`$contains`,in:`$in`,notIn:`$nin`},fb={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$contains:`contains`,$in:`in`,$nin:`notIn`};function pb(e){let t=(e?.conditions??[]).filter(e=>e&&e.field),n=[];for(let e of t){if(e.operator===`isEmpty`){n.push({[e.field]:{$exists:!1}});continue}if(e.operator===`isNotEmpty`){n.push({[e.field]:{$exists:!0}});continue}let t=db[e.operator];if(!t)continue;let r=e.value;r==null||r===``||Array.isArray(r)&&r.length===0||n.push({[e.field]:{[t]:r}})}if(n.length!==0)return n.length===1?n[0]:{$and:n}}function mb(e){let t={id:`g`,logic:`and`,conditions:[]};if(e==null)return{group:t,representable:!0};if(typeof e!=`object`||Array.isArray(e)||`$or`in e)return{group:t,representable:!1};let n=Array.isArray(e.$and)?e.$and:[e],r=[];for(let e=0;e<n.length;e++){let i=n[e];if(!i||typeof i!=`object`||Array.isArray(i)||`$and`in i||`$or`in i)return{group:t,representable:!1};let a=Object.keys(i);if(a.length!==1)return{group:t,representable:!1};let o=a[0],s=i[o];if(s&&typeof s==`object`&&!Array.isArray(s)){let n=Object.keys(s);if(n.length!==1)return{group:t,representable:!1};let i=n[0];if(i===`$exists`)r.push({id:`c${e}`,field:o,operator:s.$exists?`isNotEmpty`:`isEmpty`,value:``});else{let n=fb[i];if(!n)return{group:t,representable:!1};r.push({id:`c${e}`,field:o,operator:n,value:s[i]})}}else r.push({id:`c${e}`,field:o,operator:`equals`,value:s})}return{group:{id:`g`,logic:`and`,conditions:r},representable:!0}}var hb=[{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`},{value:`count_distinct`,label:`count distinct`}],gb=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}],_b=[{value:``,label:`— none —`},{value:`day`,label:`day`},{value:`week`,label:`week`},{value:`month`,label:`month`},{value:`quarter`,label:`quarter`},{value:`year`,label:`year`}],vb=[{value:`ratio`,label:`ratio (a ÷ b)`},{value:`sum`,label:`sum (a + b)`},{value:`difference`,label:`difference (a − b)`},{value:`product`,label:`product (a × b)`}],yb=[{value:`raw`,label:`Raw number`},{value:`number`,label:`Number — 1,234.5`},{value:`currency`,label:`Currency — $1,234.50`},{value:`percent`,label:`Percent — 12.3%`}],bb=[{value:`0`,label:`0`},{value:`1`,label:`1`},{value:`2`,label:`2`}],xb=[{value:`USD`,label:`USD ($)`},{value:`EUR`,label:`EUR (€)`},{value:`GBP`,label:`GBP (£)`},{value:`CNY`,label:`CNY (¥)`},{value:`JPY`,label:`JPY (¥)`},{value:`INR`,label:`INR (₹)`},{value:`CAD`,label:`CAD ($)`},{value:`AUD`,label:`AUD ($)`}];function Sb({title:e,count:t,onAdd:n,addLabel:r}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,Y.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,Y.jsx)(H,{className:`h-3 w-3`}),` `,r]})]})}function Cb({children:e}){return(0,Y.jsxs)(`details`,{className:`group`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-[11px] text-muted-foreground hover:text-foreground`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(qr,{className:`h-3 w-3 transition-transform group-open:rotate-90`}),`Advanced`]})}),(0,Y.jsx)(`div`,{className:`mt-1.5 space-y-1.5 border-l pl-2.5`,children:e})]})}function wb(e,t){let n=(e??``).trim(),r=n.match(/\.(0+)/),i=r?Math.min(r[1].length,2):0;return t||/[$£€¥₹]/.test(n)?{kind:`currency`,decimals:i}:n.includes(`%`)?{kind:`percent`,decimals:i}:n?{kind:`number`,decimals:i}:{kind:`raw`,decimals:0}}function Tb(e,t,n){let r=t>0?`.`+`0`.repeat(t):``;switch(e){case`number`:return{format:`0,0${r}`,currency:void 0};case`currency`:return{format:`0,0${r}`,currency:n||`USD`};case`percent`:return{format:`0${r}%`,currency:void 0};default:return{format:void 0,currency:void 0}}}function Eb({measure:e,onPatch:t,disabled:n}){let{kind:r,decimals:i}=wb(e.format,e.currency),a=e.currency||`USD`,o=(e,n,r)=>t(Tb(e,n,r)),s=x(r===`percent`?.1234:1234.5,e.format,e.currency);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,Y.jsx)(K,{label:`Display format`,value:r,options:yb,onCommit:e=>o(e,i,a),disabled:n}),r!==`raw`&&(0,Y.jsx)(K,{label:`Decimals`,value:String(i),options:bb,onCommit:e=>o(r,parseInt(e,10)||0,a),disabled:n})]}),r===`currency`&&(0,Y.jsx)(K,{label:`Currency`,value:a,options:xb,onCommit:e=>o(r,i,e),disabled:n}),r!==`raw`&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Sample: `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:s})]})]})}function Db(e,t){if(!e||!e.includes(`.`))return null;let n=e.slice(0,e.lastIndexOf(`.`));return n&&!t.includes(n)?n:null}function Ob({rel:e,onAdd:t,disabled:n}){return(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Relationship `,(0,Y.jsx)(`code`,{className:`font-mono`,children:e}),` isn't in Included relationships.`]}),!n&&t&&(0,Y.jsx)(`button`,{type:`button`,className:`underline hover:no-underline`,onClick:t,children:`Add it`})]})}function kb({label:e,help:t,value:n,onCommit:r,fields:i,disabled:a}){let{group:o,representable:s}=mb(n),c=o.conditions.length;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:e}),s?(0,Y.jsxs)(Cn,{children:[(0,Y.jsx)(yr,{asChild:!0,children:(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,disabled:a,className:`h-8 w-full justify-between text-xs font-normal`,children:[(0,Y.jsx)(`span`,{className:`truncate text-left`,children:c?`${c} condition${c===1?``:`s`}`:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`+ Add filter…`})}),(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5 opacity-60 shrink-0`})]})}),(0,Y.jsx)(Mn,{align:`start`,className:`w-[440px] max-w-[90vw] p-3`,children:i.length===0?(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Pick a base object to add filter conditions.`}):(0,Y.jsx)(fn,{fields:i,value:o,onChange:e=>r(pb(e))})})]}):(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-2.5 py-1.5 text-[11px] text-muted-foreground`,children:[`Advanced filter (nested / OR) — edit it in the `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`Source`}),` tab.`]}),t&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Ab(e,t){return e===t?{object:e}:{object:e,include:[],dimensions:[],measures:[],filter:void 0}}function jb({draft:e,onPatch:t,readOnly:n,name:r}){let i=typeof e.label==`string`?e.label:``,a=typeof e.description==`string`?e.description:``,o=typeof e.object==`string`?e.object:``,s=Array.isArray(e.include)?e.include:[],c=Array.isArray(e.dimensions)?e.dimensions:[],l=Array.isArray(e.measures)?e.measures:[],u=typeof e.name==`string`?e.name:void 0,d=!r,f=X.useRef(!1),p=typeof e.name==`string`?e.name:``,{options:m,loading:h}=Oo(),{relationships:g,fieldOptions:_,loading:v}=ko(o,s),y=Ao(u),b=X.useMemo(()=>m.map(e=>({value:e.name,label:e.label})),[m]),x=X.useMemo(()=>g.map(e=>({value:e.name,label:e.label,hint:e.referenceTo?`→ ${e.referenceTo}`:void 0})),[g]),S=X.useMemo(()=>_.map(e=>({value:e.value,label:e.label,hint:e.type,group:e.group})),[_]),C=X.useMemo(()=>_.filter(e=>!e.value.includes(`.`)).map(e=>({value:e.value,label:e.label,type:e.type})),[_]),w=e.filter&&typeof e.filter==`object`?e.filter:void 0,T=b.find(e=>e.value===o)?.label??o,E=(e,n)=>t({dimensions:c.map((t,r)=>r===e?{...t,...n}:t)}),D=(e,n)=>t({measures:l.map((t,r)=>r===e?{...t,...n}:t)}),O=e=>e.includes(`.`)?e.split(`.`).pop()??e:e,k=(e,t)=>{let n=_.find(e=>e.value===t),r=n?.type?{field:t,type:Co(n.type)}:{field:t};c[e]?.name||(r.name=O(t)),E(e,r)},A=(e,t)=>{let n={field:t};l[e]?.name||(n.name=O(t)),D(e,n)};return(0,Y.jsxs)(Li,{kindLabel:`Dataset`,title:String(i||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[u&&!y.loading&&(0,Y.jsx)(`p`,{className:y.reports+y.dashboards>0?`rounded-md border border-amber-500/30 bg-amber-500/5 px-2.5 py-1.5 text-[11px] text-amber-700 dark:text-amber-300`:`text-[11px] text-muted-foreground`,children:y.reports+y.dashboards>0?`Bound by ${y.reports} report${y.reports===1?``:`s`} · ${y.dashboards} dashboard${y.dashboards===1?``:`s`} — changes affect them.`:`Not yet bound by any report or dashboard.`}),d&&(0,Y.jsx)(q,{label:`Name`,value:p,onCommit:e=>{f.current=!0,t({name:zi(e)})},placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(q,{label:`Label`,value:i,onCommit:e=>{let n={label:e};d&&!f.current&&(n.name=zi(e)),t(n)},disabled:n}),(0,Y.jsx)(q,{label:`Description`,value:a,onCommit:e=>t({description:e}),disabled:n}),(0,Y.jsx)(Ua,{label:`Base object`,value:o,onCommit:e=>t(Ab(e,o)),options:b,loading:h,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:n,mono:!0}),o&&(c.length>0||l.length>0||s.length>0||!!w)&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Changing the base object clears its dimensions, measures, joins & filters.`}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(Sb,{title:`Included relationships`,count:s.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:ua(s,``)})}),s.length===0?(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:[`No joins. Add a relationship (a lookup field on `,(0,Y.jsx)(`code`,{children:T||`the base object`}),`) to use `,(0,Y.jsx)(`code`,{children:`relationship.field`}),` dimensions/measures.`]}):s.map((e,r)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Ua,{value:e,onCommit:e=>t({include:s.map((t,n)=>n===r?e:t)}),options:x,loading:v,placeholder:`Select a relationship…`,searchPlaceholder:`Search relationships…`,disabled:n,mono:!0}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:la(s,r,null)}),"aria-label":`Remove relationship`,children:(0,Y.jsx)(Se,{className:`h-3.5 w-3.5`})})]},r)),o&&s.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-0.5 pt-0.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:T}),s.map((e,t)=>{let n=g.find(t=>t.name===e);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(qr,{className:`h-3 w-3 opacity-60`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[e,n?.referenceTo?` (${n.referenceTo})`:``]})]},t)})]})]}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(kb,{label:`Scope filter`,help:`Intrinsic scope, ANDed into every query (e.g. exclude soft-deleted records).`,value:w,onCommit:e=>t({filter:e}),fields:C,disabled:n})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Sb,{title:`Dimensions`,count:c.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:ua(c,{name:``,field:``,type:`string`})})}),c.map((e,r)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove dimension`,title:`Remove dimension`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({dimensions:la(c,r,null)}),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>E(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,Y.jsx)(Ua,{label:`Field`,value:e.field??``,onCommit:e=>k(r,e),options:S,loading:v,placeholder:`field or relationship.field`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=Db(e.field,s);return r?(0,Y.jsx)(Ob,{rel:r,disabled:n,onAdd:()=>t({include:ua(s,r)})}):null})(),(0,Y.jsx)(K,{label:`Type`,value:e.type,options:gb,onCommit:e=>E(r,{type:e}),disabled:n}),(0,Y.jsxs)(Cb,{children:[(0,Y.jsx)(q,{label:`Label (optional)`,value:e.label??``,onCommit:e=>E(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),e.type===`date`&&(0,Y.jsx)(K,{label:`Date bucket`,value:e.dateGranularity??``,options:_b,onCommit:e=>E(r,{dateGranularity:e||void 0}),disabled:n})]})]},r))]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Sb,{title:`Measures`,count:l.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:ua(l,{name:``,aggregate:`sum`,field:``})})}),l.map((e,r)=>{let i=l.filter((e,t)=>t!==r).map(e=>e.name).filter(e=>!!e),a=e.derived;return(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove measure`,title:`Remove measure`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({measures:la(l,r,null)}),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>D(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,Y.jsx)(K,{label:`Aggregate`,value:e.aggregate,options:hb,onCommit:e=>D(r,{aggregate:e}),disabled:n}),(0,Y.jsx)(Ua,{label:`Field`,value:e.field??``,onCommit:e=>A(r,e),options:S,loading:v,placeholder:`field (optional for count)`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=Db(e.field,s);return r?(0,Y.jsx)(Ob,{rel:r,disabled:n,onAdd:()=>t({include:ua(s,r)})}):null})(),(0,Y.jsxs)(Cb,{children:[(0,Y.jsx)(q,{label:`Label (optional)`,value:e.label??``,onCommit:e=>D(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),(0,Y.jsx)(Eb,{measure:e,onPatch:e=>D(r,e),disabled:n}),(0,Y.jsx)(kb,{label:`Filter (measure-scoped)`,help:`Only rows matching this filter feed this measure (e.g. won_amount = sum(amount) where stage = won).`,value:e.filter,onCommit:e=>D(r,{filter:e}),fields:C,disabled:n}),(0,Y.jsx)(J,{label:`Derived — computed from other measures`,value:!!a,onCommit:e=>D(r,{derived:e?{op:`ratio`,of:[]}:void 0}),disabled:n}),a&&(0,Y.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-dashed p-2`,children:[(0,Y.jsx)(K,{label:`Operation`,value:a.op,options:vb,onCommit:e=>D(r,{derived:{...a,op:e}}),disabled:n}),(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Operands (other measures)`}),(()=>{let e=a.op===`ratio`||a.op===`difference`?2:1;return(Array.isArray(a.of)?a.of.length:0)<e?(0,Y.jsxs)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,children:[`Select `,e===2?`exactly 2 measures`:`at least 1 measure`,` for `,a.op,`.`]}):null})(),i.length===0?(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:`Add other measures first.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,Y.jsx)(J,{label:e,value:Array.isArray(a.of)&&a.of.includes(e),disabled:n,onCommit:t=>{let n=Array.isArray(a.of)?a.of:[],i=t?[...n,e]:n.filter(t=>t!==e);D(r,{derived:{...a,of:i}})}},e))})]})]})]},r)})]})]})}function Mb(e){let t=Ai(),[n,r]=X.useState([]),[i,a]=X.useState(!!e);return X.useEffect(()=>{if(!e){r([]),a(!1);return}let n=!1;return a(!0),t.list(e).then(e=>{if(n)return;let t=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));r(t),a(!1)}).catch(()=>{n||(r([]),a(!1))}),()=>{n=!0}},[t,e]),{options:n,loading:i}}var Nb=[{value:`script`,label:`Script — run an expression / sandboxed JS`},{value:`api`,label:`API — call an endpoint`},{value:`flow`,label:`Flow — invoke a flow`},{value:`modal`,label:`Modal — open a modal/page`},{value:`form`,label:`Form — open a FormView`},{value:`url`,label:`URL — navigate to a link`}],Pb=[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}],Fb=[{value:`action:button`,label:`Button`},{value:`action:icon`,label:`Icon only`},{value:`action:menu`,label:`Menu item`},{value:`action:group`,label:`Button group`}],Ib=[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`delete`,label:`Delete`},{value:`custom`,label:`Custom`}],Lb=[{value:`POST`,label:`POST`},{value:`PATCH`,label:`PATCH`},{value:`PUT`,label:`PUT`},{value:`DELETE`,label:`DELETE`}],Rb=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],zb=[{value:`text`,label:`Text`},{value:`textarea`,label:`Long text`},{value:`number`,label:`Number`},{value:`boolean`,label:`Checkbox`},{value:`select`,label:`Select`},{value:`date`,label:`Date`},{value:`datetime`,label:`Date/time`},{value:`lookup`,label:`Lookup`}],Bb=[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record · more menu`},{value:`record_section`,label:`Record · section`},{value:`record_related`,label:`Record · related list`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List · row`},{value:`global_nav`,label:`Global nav / command palette`}],Vb={url:{label:`URL`,placeholder:"https://… or /path?x=${param.x}",hint:"Supports ${param.x} and ${ctx.x} interpolation."},flow:{label:`Flow name`,placeholder:`snake_case flow`,hint:`The flow to invoke when clicked.`},modal:{label:`Modal / page name`,placeholder:`snake_case page`,hint:`The modal or page to open.`},form:{label:`Form view name`,placeholder:`object.viewKey`,hint:`Opens /console/forms/<name>.`},api:{label:`API endpoint`,placeholder:`/api/v1/…`,hint:`Endpoint called with the request body below.`}},Hb={flow:`flow`,modal:`page`,form:`view`};function Ub({type:e,value:t,onCommit:n,cfg:r,readOnly:i}){let a=Hb[e]??null,{options:o}=Mb(a),s=!!a&&o.length>0,c=s&&t&&!o.some(e=>e.value===t)?[{value:t,label:`${t} (not found)`},...o]:o;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[s?(0,Y.jsx)(K,{label:`${r.label} *`,value:t||void 0,options:c,onCommit:n,disabled:i}):(0,Y.jsx)(q,{label:`${r.label} *`,value:t,onCommit:n,placeholder:r.placeholder,disabled:i,mono:!0}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:r.hint})]})}var Wb=[`name`,`label`,`objectName`,`icon`,`variant`,`component`,`type`,`target`,`execute`,`body`,`method`,`params`,`locations`,`bulkEnabled`,`confirmText`,`successMessage`,`errorMessage`,`refreshAfter`,`undoable`,`mode`,`shortcut`,`visible`,`disabled`,`aiExposed`,`aiDescription`];function Gb({title:e,hint:t}){return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function Kb(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function qb({label:e,value:t,onCommit:n,disabled:r,hint:i}){let{options:a}=nd();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[a.length===0?(0,Y.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(K,{label:e,value:t||void 0,options:[{value:``,label:`— None (global) —`},...a],onCommit:n,disabled:r}),i&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:i})]})}function Jb({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let{fields:a}=Ki(t),o=X.useMemo(()=>a.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]);return!t||o.length===0?(0,Y.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(K,{label:e,value:n||void 0,options:[{value:``,label:`—`},...o],onCommit:r,disabled:i})}function Yb({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=X.useCallback(e=>G(e,r),[r]),o=t=>typeof e[t]==`string`?e[t]:``,s=o(`type`)||`script`,c=o(`objectName`),l=e.body&&typeof e.body==`object`?e.body:{},u=Array.isArray(e.params)?e.params:[],d=Array.isArray(e.locations)?e.locations:[],f=e.aiExposed===!0,p=typeof e.aiDescription==`string`?e.aiDescription:``,m=e=>t({body:{...l,...e}}),h=(e,n)=>t({params:u.map((t,r)=>r===e?{...t,...n}:t)}),g=(e,n)=>{t({locations:n?[...new Set([...d,e])]:d.filter(t=>t!==e)})},_=Vb[s],v=i;return(0,Y.jsxs)(Li,{kindLabel:a(`engine.inspector.action.kind`),title:String(Kb(e.label)||e.name||a(`engine.inspector.action.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,Y.jsx)(Gb,{title:`Basics`}),(0,Y.jsx)(q,{label:`Label`,value:Kb(e.label),onCommit:e=>t({label:e}),placeholder:`Button text shown to users`,disabled:n}),(0,Y.jsx)(q,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(qb,{label:`Object`,value:c,onCommit:e=>t({objectName:e||void 0}),disabled:n,hint:c?`Bound action — surfaces in this object’s views per the placement below.`:`Empty = global action — must be referenced by a page’s quick actions, global nav, a flow, or AI to appear.`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Icon`}),(0,Y.jsx)(fa,{schema:{type:`string`},value:o(`icon`),onChange:e=>t({icon:e||void 0}),readOnly:n})]}),(0,Y.jsx)(K,{label:`Variant`,value:o(`variant`)||void 0,options:Pb,onCommit:e=>t({variant:e}),disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(Gb,{title:`Behavior`,hint:`What happens when the action is triggered.`}),(0,Y.jsx)(K,{label:`Type`,value:s,options:Nb,onCommit:e=>t({type:e}),disabled:n}),s===`script`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(K,{label:`Script language`,value:(typeof l.language==`string`?l.language:void 0)||`expression`,options:Rb,onCommit:e=>m({language:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Script body`}),(0,Y.jsx)(lr,{value:typeof l.source==`string`?l.source:``,onChange:e=>m({source:e.target.value}),disabled:n,spellCheck:!1,rows:5,placeholder:`// (input, ctx) => result
24
24
  return { ok: true }`,className:`text-xs font-mono`}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:[`Runs in the sandbox as `,(0,Y.jsx)(`code`,{children:`(input, ctx) => Promise<output>`}),`.`]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[s===`api`&&(0,Y.jsx)(K,{label:`Method`,value:o(`method`)||`POST`,options:Lb,onCommit:e=>t({method:e}),disabled:n}),_&&(0,Y.jsx)(Ub,{type:s,value:o(`target`),onCommit:e=>t({target:e}),cfg:_,readOnly:n})]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Gb,{title:`Inputs`,hint:`Collected from the user in a dialog before the action runs.`}),u.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2.5 text-center text-[11px] text-muted-foreground`,children:`No inputs — the action runs immediately on click.`}):u.map((e,r)=>(0,Y.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`#`,r+1]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===0,"aria-label":`Move up`,onClick:()=>t({params:Pi(u,r,r-1)}),children:`↑`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===u.length-1,"aria-label":`Move down`,onClick:()=>t({params:Pi(u,r,r+1)}),children:`↓`}),(0,Y.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n,"aria-label":`Remove input`,onClick:()=>t({params:la(u,r,null)}),children:(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`})})]})]}),c?(0,Y.jsx)(Jb,{label:`Bind to field`,objectName:c,value:e.field,onCommit:e=>h(r,{field:e||void 0}),disabled:n}):null,!e.field&&(0,Y.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>h(r,{name:e}),placeholder:`request-body key`,disabled:n,mono:!0}),(0,Y.jsx)(q,{label:`Label`,value:Kb(e.label),onCommit:e=>h(r,{label:e}),disabled:n}),!e.field&&(0,Y.jsx)(K,{label:`Type`,value:e.type||void 0,options:zb,onCommit:e=>h(r,{type:e}),disabled:n}),(0,Y.jsx)(q,{label:`Placeholder`,value:e.placeholder??``,onCommit:e=>h(r,{placeholder:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,Y.jsx)(J,{label:`Required`,value:!!e.required,onCommit:e=>h(r,{required:e}),disabled:n}),(0,Y.jsx)(J,{label:`Pre-fill from row`,value:!!e.defaultFromRow,onCommit:e=>h(r,{defaultFromRow:e}),disabled:n})]})]},r)),!n&&(0,Y.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t({params:ua(u,{})}),children:[(0,Y.jsx)(H,{className:`mr-1 h-3.5 w-3.5`}),` Add input`]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Gb,{title:`Placement`,hint:`Where this action surfaces in the UI.`}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-1`,children:Bb.map(e=>(0,Y.jsx)(J,{label:e.label,value:d.includes(e.value),onCommit:t=>g(e.value,t),disabled:n},e.value))}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:(0,Y.jsx)(K,{label:`Component`,value:o(`component`)||void 0,options:Fb,onCommit:e=>t({component:e}),disabled:n})}),(0,Y.jsx)(J,{label:`Bulk — apply to multiple selected rows`,value:!!e.bulkEnabled,onCommit:e=>t({bulkEnabled:e}),disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Gb,{title:`Feedback`,hint:`Confirmation and post-run messaging.`}),(0,Y.jsx)(q,{label:`Confirm prompt`,value:Kb(e.confirmText),onCommit:e=>t({confirmText:e}),placeholder:`Ask before running (leave blank to skip)`,disabled:n}),(0,Y.jsx)(q,{label:`Success message`,value:Kb(e.successMessage),onCommit:e=>t({successMessage:e}),disabled:n}),(0,Y.jsx)(q,{label:`Error message`,value:Kb(e.errorMessage),onCommit:e=>t({errorMessage:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(K,{label:`Mode`,value:o(`mode`)||void 0,options:Ib,onCommit:e=>t({mode:e}),disabled:n}),(0,Y.jsx)(q,{label:`Shortcut`,value:o(`shortcut`),onCommit:e=>t({shortcut:e}),placeholder:`e.g. Ctrl+S`,disabled:n,mono:!0})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,Y.jsx)(J,{label:`Refresh view after`,value:!!e.refreshAfter,onCommit:e=>t({refreshAfter:e}),disabled:n}),(0,Y.jsx)(J,{label:`Offer undo`,value:!!e.undoable,onCommit:e=>t({undoable:e}),disabled:n})]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(Gb,{title:`Conditions`,hint:`No-code predicates over the record / user / ctx (compiled to CEL).`}),(0,Y.jsx)(oa,{label:`Visible when`,value:typeof e.visible==`string`?e.visible:``,onCommit:e=>t({visible:e||void 0}),objectName:c,disabled:n}),(0,Y.jsx)(oa,{label:`Disabled when`,value:typeof e.disabled==`string`?e.disabled:``,onCommit:e=>t({disabled:e||void 0}),objectName:c,disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(Gb,{title:`AI exposure`,hint:`Opt-in: expose this action to AI agents as a callable tool.`}),(0,Y.jsx)(J,{label:`Expose to AI agents`,value:f,onCommit:e=>t({aiExposed:e}),disabled:n}),f?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Tool description (required, ≥40 chars)`}),(0,Y.jsx)(lr,{value:p,onChange:e=>t({aiDescription:e.target.value}),disabled:n,rows:3,placeholder:`When and why an agent should call this action…`,className:`text-xs`}),p.length<40&&(0,Y.jsx)(`div`,{className:`text-[11px] text-destructive`,children:`A ≥40-character description is required while exposed.`})]}):null]}),v&&(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(Gb,{title:a(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,Y.jsx)(ha,{schema:v,value:e,hiddenFields:Wb,readOnly:n,onChange:e=>t(e)})]})]})}var Xb=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],Zb=[`beforeInsert`,`afterInsert`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`,`beforeUpdateMany`,`afterUpdateMany`,`beforeDeleteMany`,`afterDeleteMany`],Qb=[`beforeFind`,`afterFind`,`beforeFindOne`,`afterFindOne`,`beforeCount`,`afterCount`,`beforeAggregate`,`afterAggregate`],$b=`*`,ex=[`name`,`label`,`object`,`events`,`body`,`priority`,`async`,`condition`];function tx({title:e,hint:t}){return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function nx(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function rx(e){if(e===$b)return{all:!0,names:[]};if(typeof e==`string`)return{all:!1,names:e?[e]:[]};if(Array.isArray(e)){let t=e.filter(e=>typeof e==`string`&&e!==$b);return{all:e.includes($b),names:t}}return{all:!1,names:[]}}function ix(e,t){return e?$b:t.length===1?t[0]:t}function ax({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=X.useCallback(e=>G(e,r),[r]),o=t=>typeof e[t]==`string`?e[t]:``,s=e.body&&typeof e.body==`object`?e.body:{},c=Array.isArray(e.events)?e.events:[],{all:l,names:u}=rx(e.object),{options:d}=nd(),f=X.useMemo(()=>{let e=new Set(d.map(e=>e.value));return[...u.filter(t=>!e.has(t)).map(e=>({value:e,label:`${e} (not published)`})),...d]},[d,u]),p=e=>t({body:{...s,...e}}),m=(e,n)=>{t({object:ix(!1,n?[...new Set([...u,e])]:u.filter(t=>t!==e))})},h=(e,n)=>{t({events:n?[...new Set([...c,e])]:c.filter(t=>t!==e)})},g=!l&&u.length===1?u[0]:void 0,_=typeof s.language==`string`?s.language:`expression`,v=i;return(0,Y.jsxs)(Li,{kindLabel:a(`engine.inspector.hook.kind`),title:String(nx(e.label)||e.name||a(`engine.inspector.hook.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,Y.jsx)(tx,{title:`Basics`}),(0,Y.jsx)(q,{label:`Label`,value:nx(e.label),onCommit:e=>t({label:e||void 0}),placeholder:`Human-readable name`,disabled:n}),(0,Y.jsx)(q,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0,testId:`hook-name`}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,"data-testid":`hook-object-picker`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Object(s) this hook fires on`}),(0,Y.jsx)(J,{label:`All objects (*)`,value:l,onCommit:e=>t({object:e?$b:ix(!1,u)}),disabled:n}),!l&&(0,Y.jsx)(`div`,{className:`max-h-40 space-y-1 overflow-auto rounded-md border p-2`,children:f.length===0?(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`No objects found — publish an object, then pick it here.`}):f.map(e=>(0,Y.jsx)(J,{label:e.label,value:u.includes(e.value),onCommit:t=>m(e.value,t),disabled:n},e.value))}),!l&&u.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:`Pick at least one object (or All objects).`})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(tx,{title:`Events`,hint:`Which lifecycle events invoke this hook.`}),(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground/80`,children:`Write`}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:Zb.map(e=>(0,Y.jsx)(J,{label:e,value:c.includes(e),onCommit:t=>h(e,t),disabled:n},e))}),(0,Y.jsx)(`div`,{className:`pt-1 text-[11px] font-medium text-muted-foreground/80`,children:`Query`}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:Qb.map(e=>(0,Y.jsx)(J,{label:e,value:c.includes(e),onCommit:t=>h(e,t),disabled:n},e))}),c.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:`Select at least one event.`})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(tx,{title:`Function`,hint:`The handler that runs when the hook fires.`}),(0,Y.jsx)(K,{label:`Language`,value:_,options:Xb,onCommit:e=>p({language:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(U,{className:`text-xs text-muted-foreground`,children:`Handler body`}),(0,Y.jsx)(lr,{"data-testid":`hook-body-source`,value:typeof s.source==`string`?s.source:``,onChange:e=>p({source:e.target.value}),disabled:n,spellCheck:!1,rows:8,placeholder:_===`expression`?`record.amount >= 0`:`// (ctx) => { ... }
25
25
  return;`,className:`text-xs font-mono`}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:_===`expression`?`A single L1 expression evaluated against the record / ctx.`:`Runs in the sandbox as (ctx) => Promise<void>.`})]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(tx,{title:`Options`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsx)(Ii,{label:`Priority`,value:typeof e.priority==`number`?e.priority:void 0,onCommit:e=>t({priority:e}),placeholder:`100`,disabled:n}),(0,Y.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,Y.jsx)(J,{label:`Run asynchronously (after commit)`,value:e.async===!0,onCommit:e=>t({async:e}),disabled:n})})]}),(0,Y.jsx)(oa,{label:`Run only when (optional CEL)`,value:typeof e.condition==`string`?e.condition:``,onCommit:e=>t({condition:e||void 0}),objectName:g,disabled:n})]}),v&&(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(tx,{title:a(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,Y.jsx)(ha,{schema:v,value:e,hiddenFields:ex,readOnly:n,onChange:e=>t(e)})]})]})}function ox(){sl(`dashboard`,k_),ul(`dashboard`,B_),sl(`flow`,iy),sl(`app`,uo),sl(`view`,py),ul(`view`,my),sl(`page`,bd),ul(`page`,Sy),ul(`report`,pa),sl(`object`,Iy),ul(`object`,rb),ul(`dataset`,jb),ul(`action`,Yb),ul(`hook`,ax)}var sx=t({MetadataDiagnosticsPage:()=>au,MetadataDirectoryPage:()=>ws,MetadataResourceEditPage:()=>$l,MetadataResourceHistoryPage:()=>Xc,MetadataResourceListPage:()=>Cc,StudioHomePage:()=>sc});Au(),Pu(),Vu(),T_(),ox();export{Da as A,vo as C,po as D,yo as E,_o as O,ho as S,go as T,Ms as _,ru as a,_s as b,al as c,Zs as d,Qs as f,Os as g,ks as h,Du as i,Oa as j,Ba as k,vc as l,As as m,df as n,dl as o,Us as p,qu as r,cl as s,sx as t,Js as u,Ns as v,mo as w,is as x,ws as y};